• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Courseography / courseography / 03a26a0d-fd82-4460-a109-48470a9a147e

17 Jun 2025 06:56PM UTC coverage: 32.165%. Remained the same
03a26a0d-fd82-4460-a109-48470a9a147e

Pull #1571

circleci

akarki2005
Merge branch 'master' of https://github.com/Courseography/courseography into make-nav-bar-react
Pull Request #1571: Refactor NavBar into a React Component

21 of 140 branches covered (15.0%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

640 of 1915 relevant lines covered (33.42%)

26.37 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

10.34
/app/Controllers/Graph.hs
1
module Controllers.Graph (graphResponse, index, getGraphJSON, graphImageResponse, saveGraphJSON) where
2

3
import Control.Monad.IO.Class (liftIO)
4
import Data.Aeson (decode, object, (.=))
5
import Data.Maybe (fromMaybe)
6
import Happstack.Server (Response, ServerPart, look, lookBS, lookText', ok, toResponse)
7
import MasterTemplate (masterTemplate)
8
import Scripts (graphScripts)
9
import Text.Blaze ((!))
10
import qualified Text.Blaze.Html5 as H
11
import qualified Text.Blaze.Html5.Attributes as A
12

13
import Config (runDb)
14
import Database.Persist.Sqlite (Entity, SelectOpt (Asc), SqlPersistM, selectList, (==.))
15
import Database.Tables as Tables (EntityField (GraphDynamic, GraphTitle), Graph, SvgJSON, Text)
16
import Export.GetImages (getActiveGraphImage)
17
import Models.Graph (getGraph, insertGraph)
18
import Response.Image (returnImageData)
19
import Util.Happstack (createJSONResponse)
20

21
graphResponse :: ServerPart Response
22
graphResponse =
23
   ok $ toResponse $
×
24
    masterTemplate "Courseography - Graph"
×
25
                []
×
26
                (do
×
NEW
27
                    H.div ! A.id "navbar" $ ""
×
28
                    H.div ! A.id "container" $ ""
×
29
                )
30
                graphScripts
×
31

32

33
index :: ServerPart Response
34
index = liftIO $ runDb $ do
3✔
35
    graphsList :: [Entity Graph] <- selectList [GraphDynamic ==. False] [Asc GraphTitle]
1✔
36
    return $ createJSONResponse graphsList :: SqlPersistM Response
3✔
37

38

39
-- | Looks up a graph using its title then gets the Shape, Text and Path elements
40
-- for rendering graph (returned as JSON).
41
getGraphJSON :: ServerPart Response
42
getGraphJSON = do
×
43
    graphName <- lookText' "graphName"
×
44
    response <- liftIO $ getGraph graphName
×
45
    return $ createJSONResponse $ fromMaybe (object ["texts" .= ([] :: [Text]),
×
46
                                                    "shapes" .= ([] :: [Text]),
×
47
                                                    "paths" .= ([] :: [Text])]) response
×
48

49

50
-- | Returns an image of the graph requested by the user, given graphInfo stored in local storage.
51
graphImageResponse :: ServerPart Response
52
graphImageResponse = do
×
53
    graphInfo <- look "JsonLocalStorageObj"
×
54
    (svgFilename, imageFilename) <- liftIO $ getActiveGraphImage graphInfo
×
55
    liftIO $ returnImageData svgFilename imageFilename
×
56

57
-- | Inserts SVG graph data into Texts, Shapes, and Paths tables
58
saveGraphJSON :: ServerPart Response
59
saveGraphJSON = do
×
60
    jsonStr <- lookBS "jsonData"
×
61
    nameStr <- lookText' "nameData"
×
62
    let jsonObj = decode jsonStr :: Maybe SvgJSON
×
63
    case jsonObj of
×
64
        Nothing -> return $ toResponse ("Error" :: String)
×
65
        Just svg -> do
×
66
            _ <- liftIO $ runDb $ insertGraph nameStr svg
×
67
            return $ toResponse ("Success" :: String)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc