-
Notifications
You must be signed in to change notification settings - Fork 1
/
Model.hs
98 lines (80 loc) · 3.07 KB
/
Model.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{-# LANGUAGE TemplateHaskell,TypeFamilies,EmptyDataDecls,DeriveDataTypeable,GADTs #-}
module Model where
import Prelude
import Yesod
import Data.Text (Text)
import Database.Persist.Quasi
import Database.Persist.MongoDB hiding (master)
import Language.Haskell.TH.Syntax
import Data.Typeable (Typeable)
import Data.Maybe
import qualified Data.Text as T
import Data.ByteString (ByteString)
import Data.Time.Clock
import qualified Parser.Paper as P
import Parser.JSON
import Model.Defs
import Data.Data
{-
import Database.Persist.Quasi
import Database.Persist.MongoDB hiding (master)
import Language.Haskell.TH.Syntax
import Data.Aeson.TH
import qualified Parser.Paper as P
-- import Database.Persist.Store
-}
-- sqlType _ = SqlInt32
-- isNullable _ = False
-- You can define all of your database entities in the entities file.
-- You can find more information on persistent and how to declare entities
-- at:
-- http://www.yesodweb.com/book/persistent/
let mongoSettings = (mkPersistSettings (ConT ''MongoBackend))
{ mpsGeneric = False
}
in share [mkPersist mongoSettings]
$(persistFileWith lowerCaseSettings "config/models")
-- This is a general summary function. cf. summaryEx in Handler.PaperListW2UI
-- This just returns a pair, so that you can add or delete elements before applying object.
-- Caution: you need to apply object to get a dictionary type, otherwise, this will generate an array.
paperSummary :: PaperId -> Paper -> [(Text,Value)]
paperSummary pid p
= ["id" .= toPathPiece pid, "doi" .= paperDoi p, "url" .= paperUrl p, "title" .= citationTitle c,
"tags" .= (paperTags p), "note" .= paperNote p , "citation" .= toJSON c
, "cittxt" .= mkCitTxt c]
where
c = paperCitation p
mkCitTxt c = T.concat
["<i>"
, fromMaybe "" (citationJournal c)
, "</i>, "
, maybe "" (\v -> T.concat["<b>",v,"</b>"]) (citationVolume c)
, ", "
, fromMaybe "" (citationPageFrom c)
, maybe "" (\to -> "-" `T.append` to) (citationPageTo c)
, maybe "" (\y -> T.pack $ " (" ++ show y ++ ")") (citationYear c)
]
paperSummary' :: Entity Paper -> Value
paperSummary' (Entity pid p) = object $ paperSummary pid p
{-
-- default values
emptyCitation :: Citation
emptyCitation = Citation Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing [] Nothing Nothing
-}
emptyMisc :: ByteString
emptyMisc = ""
emptyRefs :: [Reference]
emptyRefs = []
defaultTime :: UTCTime
defaultTime = read "1970-01-01 01:01:01 +0000"
{-
emptyPaper :: Paper
emptyPaper = Paper
"" "" -- doi and url
"" Nothing Nothing -- html, abs, main
emptyCitation emptyRefs [] [] -- cit ref fig res
Nothing [] Nothing emptyMisc -- toc tags note misc
Nothing P.SUndecidable --- parserInfo, supportLevel
(ResourceAvailability False False False False False False)
Nothing defaultTime -- email, time
-}