-
Notifications
You must be signed in to change notification settings - Fork 74
Remove SvgJSON data type #1720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove SvgJSON data type #1720
Changes from 4 commits
cf3fa1a
e0e621a
f102d1c
513399d
4b7b469
b5e73bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,11 +19,12 @@ straightforward. | |
|
|
||
| module Database.Tables where | ||
|
|
||
| import Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON), genericToJSON, withObject, (.!=), (.:), | ||
| (.:?)) | ||
| import Data.Aeson.Types (Options (..), Parser, Value (Object), defaultOptions) | ||
| import Data.Aeson (FromJSON (parseJSON), ToJSON (toJSON), decode, genericToJSON, withObject, | ||
| (.!=), (.:), (.:?)) | ||
| import Data.Aeson.Types (Options (..), Parser, Value (Object), defaultOptions, parseMaybe) | ||
| import Data.Char (toLower) | ||
| import qualified Data.Text as T | ||
| import qualified Data.ByteString.Lazy as L | ||
| import Data.Time.Clock (UTCTime) | ||
| import Database.DataType | ||
| import Database.Persist.Sqlite (Key, SqlPersistM, entityVal, selectFirst, (==.)) | ||
|
|
@@ -161,13 +162,6 @@ SchemaVersion | |
|
|
||
| -- ** TODO: Remove these extra types and class instances | ||
|
|
||
| -- | JSON SVG data | ||
| data SvgJSON = | ||
| SvgJSON { texts :: [Text], | ||
| shapes :: [Shape], | ||
| paths :: [Path] | ||
| } deriving (Show, Generic) | ||
|
|
||
| data Time' = | ||
| Time' { weekDay' :: Double, | ||
| startHour' :: Double, | ||
|
|
@@ -211,10 +205,6 @@ instance ToJSON Time | |
| instance ToJSON MeetTime' | ||
| instance ToJSON Building | ||
|
|
||
| -- instance FromJSON required so that tables can be parsed into JSON, | ||
| -- not necessary otherwise. | ||
| instance FromJSON SvgJSON | ||
|
|
||
| instance ToJSON Meeting where | ||
| toJSON = genericToJSON defaultOptions { | ||
| fieldLabelModifier = | ||
|
|
@@ -278,6 +268,17 @@ parseInstr (Object io) = do | |
| return (T.concat [firstName, ". ", lastName]) | ||
| parseInstr _ = return "" | ||
|
|
||
| -- | Parse the JSON representation of a graph into its texts, shapes, and paths components. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename to |
||
| parseGraphJSON :: L.ByteString -> Maybe ([Text], [Shape], [Path]) | ||
| parseGraphJSON jsonStr = do | ||
| obj <- decode jsonStr | ||
| parseMaybe (\o -> do | ||
| texts <- o .: "texts" | ||
| shapes <- o .: "shapes" | ||
| paths <- o .: "paths" | ||
| return (texts, shapes, paths) | ||
| ) obj | ||
|
|
||
| -- | Converts the miliseconds time into hourly time | ||
| -- | Assumes times are rounded to the nearest hour | ||
| getHourVal :: Int -> Double | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ import Database.DataType (ShapeType (BoolNode, Hybrid, Node)) | |
| import Database.Persist.Sqlite (Entity, PersistEntity, PersistValue (PersistInt64), SqlPersistM, | ||
| deleteWhere, entityKey, entityVal, insert, insert_, insertMany_, keyToValues, | ||
| selectFirst, selectList, (<-.), (==.)) | ||
| import Database.Tables hiding (paths, shapes, texts) | ||
| import Database.Tables | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update the |
||
| import Svg.Builder (buildEllipses, buildPath, buildRect) | ||
| import Util.Helpers | ||
|
|
||
|
|
@@ -55,10 +55,10 @@ getGraph graphName = runDb $ do | |
|
|
||
| -- | Insert a new graph into the database, given its SVG JSON. | ||
| -- | Return Nothing. | ||
| insertGraph :: T.Text -- ^ The title of the graph being inserted. | ||
| -> SvgJSON -- ^ The SVG JSON data of the inserted graph (texts, shapes, paths). | ||
| -> SqlPersistM () -- ^ Return Nothing. | ||
| insertGraph nameStr_ (SvgJSON texts shapes paths) = do | ||
| insertGraph :: T.Text -- ^ The title of the graph being inserted. | ||
| -> ([Text], [Shape], [Path]) -- ^ The parsed JSON data of the inserted graph. | ||
| -> SqlPersistM () -- ^ Return Nothing. | ||
| insertGraph nameStr_ (texts, shapes, paths) = do | ||
| gId <- insert $ Graph nameStr_ 256 256 False | ||
| insertMany_ $ map (\text -> text {textGraph = gId}) texts | ||
| insertMany_ $ map (\shape -> shape {shapeGraph = gId}) shapes | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename
svgintocomponents