-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pipeliner.elm
381 lines (309 loc) · 8.13 KB
/
Pipeliner.elm
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
module Pipeliner (..) where
import Array exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import Signal exposing (Address)
import Json.Decode exposing (Decoder, decodeValue, object5, (:=), int, string, list, maybe)
-- PORTS
port currentCode : Signal ( String, Json.Decode.Value )
-- MODEL
type alias Annotation =
{ row : Int
, column : Maybe Int
, errorType : String
, raw : String
, text : String
}
annotationsDecoder : Decoder (List Annotation)
annotationsDecoder =
Json.Decode.list
(object5
Annotation
("row" := int)
(maybe ("column" := int))
("errorType" := string)
("raw" := string)
("text" := string)
)
type Status
= Running
| Failed
| Success
| Waiting
type alias Step =
{ code : String
, status : Status
, title : String
, description : String
, icon : String
, id : Int
}
step : String -> String -> Int -> String -> Status -> Step
step title description id icon status =
{ code = ""
, status = status
, title = title
, description = description
, icon = icon
, id = id
}
type alias Model =
{ title : String
, description : String
, code : String
, annotations : List Annotation
, steps : List Step
}
initialModel : Model
initialModel =
{ title = "Hello Pipelines!"
, description = "Example description"
, code = ""
, annotations = []
, steps =
[ step "Build" "Compile & Unit tests" 1 "" Waiting
, step "Deployment DEV" "via SSH to DEV" 2 "send" Waiting
, step "Testing DEV" "Running automated tests" 3 "unhide" Waiting
, step "Deployment SIT" "Running automated User Acceptance Tests" 4 "warning" Waiting
]
}
mapStatusToCss : Status -> String
mapStatusToCss status =
case status of
Waiting ->
"grey"
Running ->
"yellow"
Failed ->
"red"
Success ->
"green"
mapStatusToIcon : Status -> String -> String
mapStatusToIcon status icon =
case status of
Running ->
"setting loading icon"
Failed ->
"red warning icon"
_ ->
""
stepItem : Address Action -> Step -> Html
stepItem address entry =
let
icon =
(mapStatusToIcon entry.status entry.icon)
status =
(mapStatusToCss entry.status) ++ " card"
in
a
[ class status ]
[ div
[ class "content" ]
[ div
[ class "header", contenteditable True ]
[ text ((toString entry.id) ++ " " ++ entry.title)
, i [ class icon ] []
]
, div
[ class "meta" ]
[ span
[ class "right floated time" ]
[ text "Last build: 2 days ago"
]
, span
[ class "category" ]
[ text "Waiting"
]
]
, div
[ class "description", contenteditable True ]
[ p [] [ text entry.description ]
, a
[ class "ui right corner label" ]
[ i [ class "info icon" ] []
]
]
, div
[ class "extra content", contenteditable True ]
[ text "Add description"
, div
[ class "right floated author" ]
[ text "Author"
]
]
]
]
stepList : Address Action -> List Step -> Html
stepList address steps =
let
stepItems =
List.map (stepItem address) steps
in
div
[ id "builds", class "eleven wide column" ]
[ div [ class "ui three cards" ] stepItems
, text " "
, button
[ class "circular ui icon button", onClick address Add ]
[ i [ class "icon plus" ] []
]
, button
[ class "circular ui icon button", onClick address Remove ]
[ i [ class "icon minus" ] []
]
]
sideBar : Bool -> Html
sideBar pipelineRunning =
let
buttonClass =
case pipelineRunning of
True ->
"ui button loading"
_ ->
"ui green button inverted"
in
div
[ class "five wide column" ]
[ div
[ class "pipeline-sidebar" ]
[ div [ id "editor", class "pipeline-sidebar__editor" ] []
, button [ id "commit", class buttonClass, disabled pipelineRunning ] [ text "Commit" ]
]
]
statusLog: Html
statusLog =
div [ class "ui info message" ]
[ div [ class "header"]
[ text "Info Log Output"]
, ul [ class "list" ]
[ li [] [ text "it's good"]
, li [] [ text "it's better"]
]
]
-- UPDATE
type Action
= NoOp
| Add
| CommitCode ( String, Json.Decode.Value )
| Remove
| Sort
startPipeline : String -> List Step -> List Step
startPipeline code steps =
case steps of
[] ->
[]
s :: steps ->
{ code = code
, status = Running
, title = s.title
, description = s.description
, icon = s.icon
, id = s.id
}
:: steps
update : Action -> Model -> Model
update action model =
case action of
NoOp ->
model
Sort ->
{ model | steps = List.sortBy .id model.steps }
Remove ->
{ model
| code = ""
, steps = Array.toList (Array.slice 0 -1 (Array.fromList model.steps))
}
Add ->
let
currentId =
List.maximum (List.map .id model.steps)
newId =
(Maybe.withDefault 0 currentId) + 1
entryToAdd =
step ("Job" ++ (toString newId)) "" newId "setting" Waiting
in
{ model
| code = ""
, steps = Array.toList (Array.push entryToAdd (Array.fromList model.steps))
}
CommitCode ( code, annotationsJson ) ->
{ model
| code = code
, annotations = Result.withDefault [] (decodeValue annotationsDecoder annotationsJson)
, steps = startPipeline code model.steps
}
-- VIEW
view : Address Action -> Model -> Html
view address model =
div
[]
[ h1
[ class "ui header" ]
[ i [ class "settings icon" ] []
, div
[ class "content", contenteditable True ]
[ text model.title
, div
[ class "sub header", contenteditable True ]
[ text model.description
]
]
]
, hr [] []
, div
[ class "ui two column divided grid" ]
[ div
[ class "row" ]
[ sideBar (List.any (\s -> s.status == Running) model.steps)
, stepList address model.steps
]
]
, div
[ class "ui top attached tabular menu" ]
[ a [ class "item", attribute "data-tab" "first" ]
[ text "System Log" ]
, a [ class "item", attribute "data-tab" "second" ]
[ text "Build log" ]
, a [ class "item active", attribute "data-tab" "third" ]
[ text "Site Preview" ]
]
, div
[ class "ui bottom attached tab segment", attribute "data-tab" "first" ]
[ pre []
[ text "[INFO] Pipeline up and running."
, br [] []
, text "[INFO] Jobs waiting for action."
, br [] []
, text "[INFO] Code commited to Build."
]
]
, div
[ class "ui bottom attached tab segment", attribute "data-tab" "second" ]
[ pre []
[ text "[INFO] Waiting."
]
]
, div
[ class "ui bottom attached tab segment active", attribute "data-tab" "third" ]
[ iframe
[ style [ ("backgroundColor", "red")
, ("height", "190px")
, ("width", "100%")
] , srcdoc "<div>Website preview inside iframe</div><h1>No code has been deployed yet. Keep it coming!</h1>" ]
[]
]
]
-- SIGNALS
inbox : Signal.Mailbox Action
inbox =
Signal.mailbox NoOp
actions : Signal Action
actions =
Signal.merge inbox.signal (Signal.map CommitCode currentCode)
model : Signal Model
model =
Signal.foldp update initialModel actions
main : Signal Html
main =
Signal.map (view inbox.address) model