@@ -5,7 +5,7 @@ import Affjax (URL) -- TODO introduce URL alias in Client so we can abstract Aff
5
5
import Control.Comonad.Cofree ((:<))
6
6
import Data.AdjacencySpace as AdjacencySpace
7
7
import Data.AdjacencySpace (AdjacencySpace )
8
- import Data.Array (cons )
8
+ import Data.Array (cons , last )
9
9
import Data.Foldable (foldMap , foldr , length )
10
10
import Data.FoldableWithIndex (foldMapWithIndex )
11
11
import Data.FunctorWithIndex (mapWithIndex )
@@ -80,112 +80,111 @@ render state =
80
80
main =
81
81
[ div []
82
82
[ div [ classes $ ClassName <$> [ " container" ] <> guard showSidebar [ " is-fluid" ] ] $
83
- resolveRoute state.route state
84
- # maybe [ text " Couldn't find project/net/diagram." ] \resolved ->
85
- [ routeBreadcrumbs state.route resolved
86
- , contentView state.apiUrl resolved
87
- ]
83
+ resolveRoute state.route state # \resolved ->
84
+ [ routeBreadcrumbs state.route resolved
85
+ , contentView state.apiUrl resolved
86
+ ]
88
87
]
89
88
]
90
89
91
90
contentView :: ∀ m . MonadAff m => URL -> ResolvedRoute -> ComponentHTML Action ChildSlots m
92
- contentView apiUrl route = case route of
93
- ResolvedHome projects ->
94
- div []
95
- [ projectsDashboard projects
96
- ]
91
+ contentView apiUrl route = last route # maybe (text " Couldn't find project/net/diagram." ) view
92
+ where
93
+ view = case _ of
94
+ ResolvedHome projects ->
95
+ div []
96
+ [ projectsDashboard projects
97
+ ]
97
98
98
- ResolvedTxHome projects ->
99
- div []
100
- [ homeForm apiUrl
101
- ]
99
+ ResolvedTxHome projects ->
100
+ div []
101
+ [ homeForm apiUrl
102
+ ]
102
103
103
- ResolvedProject project ->
104
- div []
105
- [ p_ [ text $ " Project '" <> project.name <> " '" ]
106
- , p_ [ button [ onClick \_ -> Just $ CRUDKDMonCat $ CreateAction mempty ]
107
- [ text " Create new KDMonCat diagram" ]
108
- ]
109
- ]
104
+ ResolvedProject project ->
105
+ div []
106
+ [ p_ [ text $ " Project '" <> project.name <> " '" ]
107
+ , p_ [ button [ onClick \_ -> Just $ CRUDKDMonCat $ CreateAction mempty ]
108
+ [ text " Create new KDMonCat diagram" ]
109
+ ]
110
+ ]
110
111
111
- ResolvedTypes project ->
112
- TypedefsEditor .typedefsTreeView project.types
113
-
114
- ResolvedAuths project ->
115
- RolesEditor .roleInfosHtml project.roleInfos
116
-
117
- ResolvedNet netInfo ->
118
- slot _petrinetEditor unit (PetrinetEditor .ui (Just " main_net" )) netInfo (Just <<< HandlePetrinetEditorMsg )
119
-
120
- ResolvedDiagram diagramInfo nodeMaybe ->
121
- div [ classes [ ClassName " has-columns" ] ]
122
- [ div []
123
- [ slot _diagramEditor unit DiagramEditor .ui diagramInfo.ops (Just <<< HandleDiagramEditorMsg ) ]
124
- , div []
125
- [ slot _kdmoncatBricks unit KDMonCat.Bricks .bricksView bricksInput (Just <<< HandleKDMonCatBricksMsg diagramInfo)
126
- , case nodeMaybe of
127
- Just (NetNode netInfo) -> slot _petrinetEditor unit (PetrinetEditor .ui (Just " diagram_node" )) netInfo (Just <<< HandlePetrinetEditorMsg )
128
- Just (DiagramNode diagramInfo2) -> text " TODO viewing internal diagrams is not supported yet."
129
- Nothing -> text " Click a node to show the corresponding net or diagram."
130
- ]
131
- ]
132
- where
133
- bricksInput =
134
- (KDMonCat.App .toBricksInput (DiagramV2 .fromOperators diagramInfo.ops) zero)
135
- { renderBoxContent = \name bid ->
136
- (KDMonCat.Bricks .defaultRenderBoxContent name bid)
137
- { className = if maybeSelectedBid == Just bid then " selected" else " " } }
138
- maybeSelectedBid = case nodeMaybe of
139
- Just (NetNode netInfo) -> DiagramV2 .toPixel diagramInfo.ops (\{ identifier } -> netInfo.name == identifier)
140
- _ -> Nothing
112
+ ResolvedTypes project ->
113
+ TypedefsEditor .typedefsTreeView project.types
114
+
115
+ ResolvedAuths project ->
116
+ RolesEditor .roleInfosHtml project.roleInfos
117
+
118
+ ResolvedNet netInfo ->
119
+ slot _petrinetEditor unit (PetrinetEditor .ui (Just " main_net" )) netInfo (Just <<< HandlePetrinetEditorMsg )
120
+
121
+ ResolvedDiagram diagramInfo nodeMaybe ->
122
+ div [ classes [ ClassName " has-columns" ] ]
123
+ [ div []
124
+ [ slot _diagramEditor unit DiagramEditor .ui diagramInfo.ops (Just <<< HandleDiagramEditorMsg ) ]
125
+ , div []
126
+ [ slot _kdmoncatBricks unit KDMonCat.Bricks .bricksView bricksInput (Just <<< HandleKDMonCatBricksMsg diagramInfo)
127
+ , case nodeMaybe of
128
+ Just (NetNode netInfo) -> slot _petrinetEditor unit (PetrinetEditor .ui (Just " diagram_node" )) netInfo (Just <<< HandlePetrinetEditorMsg )
129
+ Just (DiagramNode diagramInfo2) -> text " TODO viewing internal diagrams is not supported yet."
130
+ Nothing -> text " Click a node to show the corresponding net or diagram."
131
+ ]
132
+ ]
133
+ where
134
+ bricksInput =
135
+ (KDMonCat.App .toBricksInput (DiagramV2 .fromOperators diagramInfo.ops) zero)
136
+ { renderBoxContent = \name bid ->
137
+ (KDMonCat.Bricks .defaultRenderBoxContent name bid)
138
+ { className = if maybeSelectedBid == Just bid then " selected" else " " } }
139
+ maybeSelectedBid = case nodeMaybe of
140
+ Just (NetNode netInfo) -> DiagramV2 .toPixel diagramInfo.ops (\{ identifier } -> netInfo.name == identifier)
141
+ _ -> Nothing
141
142
142
- ResolvedKDMonCat kdmoncatInput ->
143
- div [ classes [ ClassName " w-full" , ClassName " pl-4" ] ]
144
- [ slot _kdmoncatApp unit KDMonCat.App .appView kdmoncatInput (Just <<< HandleKDMonCatAppMsg ) ]
143
+ ResolvedKDMonCat kdmoncatInput ->
144
+ div [ classes [ ClassName " w-full" , ClassName " pl-4" ] ]
145
+ [ slot _kdmoncatApp unit KDMonCat.App .appView kdmoncatInput (Just <<< HandleKDMonCatAppMsg ) ]
145
146
146
- ResolvedUberRoot url ->
147
- text $ " Service über-root " <> url
147
+ ResolvedUberRoot url ->
148
+ text $ " Service über-root " <> url
148
149
149
- ResolvedNamespace hash ->
150
- text $ " Namespace " <> hash
150
+ ResolvedNamespace hash ->
151
+ text $ " Namespace " <> hash
151
152
152
- ResolvedWiring wfi wiringTx ->
153
- wiringTxView wfi wiringTx
153
+ ResolvedWiring wfi wiringTx ->
154
+ wiringTxView wfi wiringTx
154
155
155
- ResolvedFiring wfi firingTx executionTraceE ->
156
- firingTxView wfi firingTx executionTraceE
156
+ ResolvedFiring wfi firingTx executionTraceE ->
157
+ firingTxView wfi firingTx executionTraceE
157
158
158
159
routeBreadcrumbs :: ∀ m . Route -> ResolvedRoute -> ComponentHTML Action ChildSlots m
159
160
routeBreadcrumbs route resolvedRoute =
160
161
nav [ classes [ ClassName " stbx-breadcrumbs" ] ]
161
- [ ol [] $
162
- crumb <$> case route /\ resolvedRoute of
163
- Home /\ _ -> [ " Home" ]
164
- TxHome _ /\ _ -> [ " Home" ]
165
- ProjectRoute _ pr /\ ResolvedProject project -> [ " Home" , project.name ] <> projectRouteBreadcrumbs pr
166
- ApiRoute apiRoute endpointUrl /\ _ -> apiRouteBreadcrumbs endpointUrl apiRoute
167
- _ -> []
168
- ]
162
+ [ ol [] $ toBreadcrumb <$> resolvedRoute ]
169
163
where
170
- crumb str = li [] [ a [ href " #" ] [ text str ] ]
171
-
172
- projectRouteBreadcrumbs :: ProjectRoute -> Array _
173
- projectRouteBreadcrumbs = case _ of
174
- ProjectHome -> []
175
- Types -> [ " Types" ]
176
- Auths -> [ " Authorisation" ]
177
- Net name -> [ name ]
178
- Diagram name _ -> [ name ]
179
- KDMonCatR name -> [ name ]
180
-
181
- apiRouteBreadcrumbs :: URL -> ApiRoute -> Array _
182
- apiRouteBreadcrumbs endpointUrl = case _ of
183
- UberRootR -> [ " über-namespace" , endpointUrl ]
184
- NamespaceR hash -> [ " namespace" , shortHash hash ]
185
- WiringR x -> [ endpointUrl, " wiring " <> shortHash x ]
186
- FiringR x -> [ endpointUrl, shortHash x ]
187
- DiagramR hash ix name -> [ shortHash hash, " diagram " <> show ix <> " " <> name ]
188
- NetR hash ix name -> [ shortHash hash, " net " <> show ix <> " " <> name ]
164
+ crumb r str = li [] [ a [ onClick \_ -> Just (SelectRoute r) ] [ text str ] ]
165
+
166
+ sub = case route of
167
+ Home -> Home
168
+ TxHome h -> TxHome h
169
+ ProjectRoute id _ -> ProjectRoute id ProjectHome
170
+ ApiRoute _ url -> ApiRoute UberRootR url
171
+
172
+ toBreadcrumb = case _ of
173
+ ResolvedHome _ -> crumb Home " Home"
174
+ ResolvedTxHome _ -> crumb (TxHome Nothing ) " Home"
175
+
176
+ ResolvedProject p -> crumb sub p.name
177
+ ResolvedTypes p -> crumb route " Types"
178
+ ResolvedAuths p -> crumb route " Authorisation"
179
+
180
+ ResolvedNet n -> crumb route n.name
181
+ ResolvedDiagram d _ -> crumb route d.name
182
+ ResolvedKDMonCat k -> crumb route " TODO"
183
+
184
+ ResolvedUberRoot u -> crumb sub u
185
+ ResolvedNamespace h -> crumb route $ shortHash h
186
+ ResolvedWiring w _ -> crumb route $ " wiring " <> shortHash w.hash
187
+ ResolvedFiring f _ _ -> crumb route $ " firing " <> shortHash f.hash
189
188
190
189
navBar :: ∀ m . String -> Array (String /\ Maybe Route ) -> ComponentHTML Action ChildSlots m
191
190
navBar title menuItems =
@@ -283,7 +282,7 @@ projectsDashboard projects =
283
282
[ ul [ classes [ ClassName " stbx-cards" ] ] $
284
283
(projects # foldMapWithIndex mkProjectLink) <>
285
284
[ li [ classes [ ClassName " stbx-add-card" ] ]
286
- [ button [ onClick \_ -> Just $ CRUDProject $ CreateAction $ emptyProject { name = " Untitled (TODO)" } ]
285
+ [ button [ onClick $ Just <<< StopEvent ( Just $ CRUDProject $ CreateAction $ emptyProject { name = " Untitled (TODO)" }) <<< toEvent ]
287
286
[ text " Create new project" ]
288
287
]
289
288
]
@@ -300,7 +299,7 @@ projectsDashboard projects =
300
299
]
301
300
, div [ classes [ ClassName " hover-controls" ] ]
302
301
[ button [ onClick $ Just <<< StopEvent (Just $ CRUDProject $ DeleteAction projectId) <<< toEvent ]
303
- [ text " Delete" ]
302
+ [ text " Delete" ]
304
303
]
305
304
]
306
305
0 commit comments