Skip to content

Commit

Permalink
Add rule listing
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Simmerl committed Feb 22, 2017
1 parent a307baa commit 8b13216
Show file tree
Hide file tree
Showing 19 changed files with 26,177 additions and 60 deletions.
2 changes: 2 additions & 0 deletions cmd/console/Action.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Time exposing (Time)

import App.Model exposing (App)
import Route exposing (Route)
import Rule.Model exposing (Rule)

type Msg
= AppFormBlur String
Expand All @@ -15,6 +16,7 @@ type Msg
| AppFormUpdate String String
| FetchApp (WebData App)
| FetchApps (WebData (List App))
| FetchRules (WebData (List Rule))
| ListApps
| LocationChange Location
| Navigate Route
Expand Down
38 changes: 4 additions & 34 deletions cmd/console/App/View.elm
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
module App.View exposing (viewAppItem, viewAppsContext, viewAppsTable)
module App.View exposing (viewAppItem, viewAppsTable)

import Html exposing (Html, a, div, h2, input, nav, section, small, span, table, tbody, td, th, thead, tr, text)
import Html.Attributes exposing (class, id, placeholder, title, type_, value)
import Html.Events exposing (onClick, onInput)
import RemoteData exposing (RemoteData(Success), WebData)

import App.Model exposing (App)
import Container

viewAppsContext : msg -> WebData App -> Html msg
viewAppsContext msg app =
let
( sectionClass, info ) =
case app of
Success app ->
( "selected", viewAppSelected app )

_ ->
( "selected", span [] [] )
in
Container.view (section [ class sectionClass, id "context" ])
[ h2 []
[ a [ onClick msg ]
[ span [ class "icon nc-icon-glyph ui-2_layers" ] []
, span [] [ text "Apps" ]
]
]
, info
]

viewAppItem : msg -> App -> Html msg
viewAppItem msg app =
Expand All @@ -37,29 +15,21 @@ viewAppItem msg app =
span [ class "nc-icon-glyph ui-1_check-circle-07" ] []
else
span [ class "nc-icon-glyph ui-1_circle-remove" ] []

in
tr [ onClick msg ]
[ td [ class "status" ] [ enabled ]
[ td [ class "icon" ] [ enabled ]
, td [] [ text app.name ]
, td [] [ text app.description ]
, td [] [ text app.token ]
]

viewAppSelected : App -> Html msg
viewAppSelected app =
nav []
[ a []
[ span [] [ text app.name ]
, span [ class "icon nc-icon-outline arrows-2_skew-down" ] []
]
]

viewAppsTable : (App -> Html msg) -> List App -> Html msg
viewAppsTable item apps =
table []
[ thead []
[ tr []
[ th [ class "status" ] [ text "status" ]
[ th [ class "icon" ] [ text "status" ]
, th [] [ text "name" ]
, th [] [ text "description" ]
, th [] [ text "token" ]
Expand Down
27 changes: 21 additions & 6 deletions cmd/console/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import App.Api exposing (getApp, getApps)
import App.Model exposing (App, initAppForm)
import Formo exposing (Form)
import Route exposing (Route, parse)
import Rule.Api exposing (listRules)
import Rule.Model exposing (Rule)

type alias Flags =
{ zone : String
Expand All @@ -18,9 +20,12 @@ type alias Model =
{ app : WebData App
, apps : WebData (List App)
, appForm : Form
, appId : String
, focus : String
, newApp : WebData App
, route : Maybe Route
, rule : WebData Rule
, rules : WebData (List Rule)
, startTime : Time
, time : Time
, zone : String
Expand All @@ -35,14 +40,24 @@ init { zone } location =
in
case route of
Just (Route.App id) ->
( (model Loading NotAsked), Cmd.map FetchApp (getApp id) )
( (model Loading NotAsked id), Cmd.map FetchApp (getApp id) )

Just (Route.Apps) ->
( (model NotAsked Loading), Cmd.map FetchApps getApps )
( (model NotAsked Loading ""), Cmd.map FetchApps getApps )

Just (Route.Rules appId) ->
let
cmds =
Cmd.batch
[ Cmd.map FetchApp (getApp appId)
, Cmd.map FetchRules (listRules appId)
]
in
( (model Loading NotAsked appId), cmds )

_ ->
( (model NotAsked NotAsked), Cmd.none)
( (model NotAsked NotAsked ""), Cmd.none)

initModel : String -> Maybe Route -> WebData App -> WebData (List App) -> Model
initModel zone route app apps =
Model app apps initAppForm "" NotAsked route 0 0 zone
initModel : String -> Maybe Route -> WebData App -> WebData (List App) -> String -> Model
initModel zone route app apps appId =
Model app apps initAppForm appId "" NotAsked route NotAsked NotAsked 0 0 zone
14 changes: 12 additions & 2 deletions cmd/console/Route.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type Route
| Apps
| Dashboard
| Members
| Rule String String
| Rules String


-- HELPER
Expand All @@ -24,11 +26,17 @@ construct route =
Apps ->
"/apps"

Dashboard ->
"/"

Members ->
"/members"

Dashboard ->
"/"
Rule appId ruleId ->
"/apps/" ++ appId ++ "/rules/" ++ ruleId

Rules appId ->
"/apps/" ++ appId ++ "/rules"


navigate : Route -> Cmd msg
Expand All @@ -48,4 +56,6 @@ routes =
, map App (s "apps" </> string)
, map Apps (s "apps")
, map Members (s "members")
, map Rule (s "apps" </> string </> s "rules" </> string)
, map Rules (s "apps" </> string </> s "rules")
]
11 changes: 11 additions & 0 deletions cmd/console/Rule/Api.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Rule.Api exposing (listRules)

import Http
import RemoteData exposing (WebData, sendRequest)

import Rule.Model exposing (Rule, decodeList)

listRules : String -> Cmd (WebData (List Rule))
listRules appId =
Http.get ("/api/apps/" ++ appId ++ "/rules") decodeList
|> sendRequest
49 changes: 49 additions & 0 deletions cmd/console/Rule/Model.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module Rule.Model exposing (Rule, decodeList)

import Dict exposing (Dict)
import Json.Decode as Decode

-- MODEL


type alias Recipient =
{ query : Dict String String
, templates : Dict String String
, urn : String
}

type alias Rule =
{ active : Bool
, deleted : Bool
, ecosystem : Int
, entity : Int
, id : String
, name : String
, recipients : List Recipient
}


-- DECODERS


decode : Decode.Decoder Rule
decode =
Decode.map7 Rule
(Decode.field "active" Decode.bool)
(Decode.field "deleted" Decode.bool)
(Decode.field "ecosystem" Decode.int)
(Decode.field "entity" Decode.int)
(Decode.field "id" Decode.string)
(Decode.field "name" Decode.string)
(Decode.field "recipients" (Decode.list decodeRecipient))

decodeList : Decode.Decoder (List Rule)
decodeList =
Decode.at [ "rules" ] (Decode.list decode)

decodeRecipient : Decode.Decoder Recipient
decodeRecipient =
Decode.map3 Recipient
(Decode.field "query" (Decode.dict Decode.string))
(Decode.field "templates" (Decode.dict Decode.string))
(Decode.field "urn" Decode.string)
65 changes: 65 additions & 0 deletions cmd/console/Rule/View.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module Rule.View exposing (viewRuleItem, viewRuleTable)

import Html exposing (Html, a, h2, section, span, table, tbody, td, text, th, thead, tr)
import Html.Attributes exposing (class, title)
import Html.Events exposing (onClick)

import Rule.Model exposing (Rule)


viewRuleItem : msg -> Rule -> Html msg
viewRuleItem msg rule =
let
activated =
if rule.active then
span [ class "nc-icon-glyph ui-1_check-circle-07" ] []
else
span [ class "nc-icon-glyph ui-1_circle-remove" ] []

ecosystem =
case rule.ecosystem of
1 ->
span [ class "nc-icon-outline design-2_apple", title "iOS" ] []
_ ->
span [ class "nc-icon-outline ui-2_alert", title "unknown" ] []

entity =
case rule.entity of
0 ->
span [ class "nc-icon-outline arrows-2_conversion", title "Connection" ] []
1 ->
span [ class "nc-icon-outline ui-1_bell-53", title "event" ] []
2 ->
span [ class "nc-icon-outline ui-1_database", title "Object" ] []
3 ->
span [ class "nc-icon-outline ui-2_like", title "Reaction" ] []
_ ->
span [ class "nc-icon-outline ui-2_alert", title "Unknown" ] []

in
tr [ onClick msg ]
[ td [ class "icon" ] [ activated ]
, td [ class "icon" ] [ ecosystem ]
, td [ class "icon" ] [ entity ]
, td [ class "icon" ] [ text (toString (List.length rule.recipients)) ]
, td [] [ text rule.name ]
]

viewRuleTable : (Rule -> Html msg) -> List Rule -> Html msg
viewRuleTable item rules =
let
list =
List.sortBy .entity rules
in
table []
[ thead []
[ tr []
[ th [ class "icon" ] [ text "active" ]
, th [ class "icon" ] [ text "ecosystem" ]
, th [ class "icon" ] [ text "entity" ]
, th [ class "icon" ] [ text "recipients" ]
, th [] [ text "name" ]
]
]
, tbody [] (List.map item list)
]
3 changes: 3 additions & 0 deletions cmd/console/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ update msg model =
FetchApps response ->
( { model | app = NotAsked, apps = response }, Cmd.none )

FetchRules response ->
( { model | rules = response }, Cmd.none )

ListApps ->
( model, Cmd.map LocationChange (Route.navigate Route.Apps) )

Expand Down
Loading

0 comments on commit 8b13216

Please sign in to comment.