Skip to content

Commit

Permalink
Merge pull request #44 from tapglue/console-cleanup
Browse files Browse the repository at this point in the history
Console cleanup
  • Loading branch information
xla authored Jun 9, 2017
2 parents 2767bf7 + 876ed7b commit dff044c
Show file tree
Hide file tree
Showing 13 changed files with 537 additions and 518 deletions.
24 changes: 0 additions & 24 deletions cmd/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,30 +77,6 @@ var (
loginUrl: "{{.LoginURL}}",
zone: "{{.Zone}}"
});
app.ports.askRuleActivate.subscribe(function(id) {
var answer = window.confirm("Do you want to activate this Rule?");
if (answer) {
app.ports.confirmRuleActivate.send(id);
}
})
app.ports.askRuleDeactivate.subscribe(function(id) {
var answer = window.confirm("Do you want to deactivate this Rule?");
if (answer) {
app.ports.confirmRuleDeactivate.send(id);
}
});
app.ports.askRuleDelete.subscribe(function(id) {
var answer = window.confirm("Do you really want to delete this Rule?");
if (answer) {
app.ports.confirmRuleDelete.send(id);
}
})
</script>
</body>
</html>`
Expand Down
5 changes: 1 addition & 4 deletions cmd/console/src/Action.elm
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ type Msg
| NewApp (WebData App)
| RuleActivate (Result Http.Error String)
| RuleActivateAsk String
| RuleActivateConfirm String
| RuleDeactivate (Result Http.Error String)
| RuleDeactivateAsk String
| RuleDeactivateConfirm String
| RuleDeleteAsk String
| RuleDeleteConfirm String
| RuleDelete (WebData Bool)
| RuleDelete (Result Http.Error ())
| Tick Time
| TokenPersist String
27 changes: 0 additions & 27 deletions cmd/console/src/Ask.elm

This file was deleted.

8 changes: 8 additions & 0 deletions cmd/console/src/Confirm.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Confirm exposing (dialog)

import Native.Confirm


dialog : String -> Result () Bool
dialog question =
Native.Confirm.dialog
4 changes: 0 additions & 4 deletions cmd/console/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Main exposing (main)
import AnimationFrame
import Navigation
import Action exposing (Msg(..))
import Ask exposing (confirmRuleActivate, confirmRuleDeactivate, confirmRuleDelete)
import Model exposing (Flags, Model, init)
import Update exposing (update)
import View exposing (view)
Expand All @@ -27,7 +26,4 @@ subscriptions : Model -> Sub Msg
subscriptions model =
Sub.batch
[ AnimationFrame.times Tick
, confirmRuleActivate RuleActivateConfirm
, confirmRuleDeactivate RuleDeactivateConfirm
, confirmRuleDelete RuleDeleteConfirm
]
9 changes: 9 additions & 0 deletions cmd/console/src/Native/Confirm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var _tapglue$snaas$Native_Confirm = function() {
function dialog(question) {
return _elm_lang$core$Result$Ok(window.confirm(question));
}

return {
dialog: dialog
};
}();
12 changes: 6 additions & 6 deletions cmd/console/src/Rule/Api.elm
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ deactivateRule msg appId ruleId =
|> Http.send msg


deleteRule : String -> String -> Cmd (WebData Bool)
deleteRule appId ruleId =
deleteRule : (Result Http.Error () -> msg) -> String -> String -> Cmd msg
deleteRule msg appId ruleId =
Http.request
{ body = Http.emptyBody
, expect = expectEmpty
Expand All @@ -52,7 +52,7 @@ deleteRule appId ruleId =
, url = ruleUrl appId ruleId
, withCredentials = False
}
|> sendRequest
|> Http.send msg


getRule : String -> String -> Cmd (WebData Rule)
Expand All @@ -67,15 +67,15 @@ listRules appId =
|> sendRequest


expectEmpty : Http.Expect Bool
expectEmpty : Http.Expect ()
expectEmpty =
Http.expectStringResponse readEmpty


readEmpty : Http.Response String -> Result String Bool
readEmpty : Http.Response String -> Result String ()
readEmpty response =
if response.status.code == 204 then
Ok True
Ok ()
else
Err response.status.message

Expand Down
2 changes: 1 addition & 1 deletion cmd/console/src/Rule/Model.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Rule.Model exposing (Entity(..), Rule, decode, decodeList, targetString)
module Rule.Model exposing (Entity(..), Recipient, Rule, Target, decode, decodeList, targetString)

import Dict exposing (Dict)
import Json.Decode as Decode
Expand Down
185 changes: 128 additions & 57 deletions cmd/console/src/Rule/View.elm
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
module Rule.View exposing (viewRuleDescription, viewRuleItem, viewRuleTable)

import Html exposing (Html, a, div, h2, h3, section, span, strong, table, tbody, td, text, th, thead, tr)
module Rule.View exposing (viewRule, viewRuleItem, viewRuleTable)

import Dict
import Html
exposing
( Html
, a
, div
, h2
, h3
, h4
, pre
, section
, span
, strong
, table
, tbody
, td
, text
, th
, thead
, tr
)
import Html.Attributes exposing (class, title)
import Html.Events exposing (onClick)
import Rule.Model exposing (Rule)
import Rule.Model exposing (Entity(..))
import Rule.Model exposing (Entity(..), Recipient, Rule, Target)


viewActivated : Bool -> Html msg
Expand All @@ -15,8 +34,24 @@ viewActivated active =
span [ class "nc-icon-outline ui-1_circle-remove" ] []


viewEcosystem : Int -> Html msg
viewEcosystem ecosystem =
viewEcosystemButton : Int -> Html msg
viewEcosystemButton ecosystem =
case ecosystem of
1 ->
div [ class "icon", title "iOS" ]
[ span [ class "nc-icon-outline design-2_apple" ] []
, span [] [ text "iOS" ]
]

_ ->
div [ class "icon", title "Unknown" ]
[ span [ class "nc-icon-outline ui-2_alert" ] []
, span [] [ text "Unknown" ]
]


viewEcosystemIcon : Int -> Html msg
viewEcosystemIcon ecosystem =
case ecosystem of
1 ->
span [ class "nc-icon-outline design-2_apple", title "iOS" ] []
Expand All @@ -25,8 +60,8 @@ viewEcosystem ecosystem =
span [ class "nc-icon-outline ui-2_alert", title "unknown" ] []


viewEntity : Entity -> Html msg
viewEntity entity =
viewEntityIcon : Entity -> Html msg
viewEntityIcon entity =
case entity of
Connection ->
span [ class "nc-icon-outline arrows-2_conversion", title "Connection" ] []
Expand All @@ -44,72 +79,80 @@ viewEntity entity =
span [ class "nc-icon-outline ui-2_alert", title "Unknown" ] []


viewRuleDescription : Rule -> Html msg
viewRuleDescription rule =
viewEntityButton : Entity -> Html msg
viewEntityButton entity =
let
ecosystem =
case rule.ecosystem of
1 ->
div [ class "icon", title "iOS" ]
[ span [ class "nc-icon-outline design-2_apple" ] []
, span [] [ text "iOS" ]
]

_ ->
div [ class "icon", title "Unknown" ]
[ span [ class "nc-icon-outline ui-2_alert" ] []
, span [] [ text "Unknown" ]
]

entity =
case rule.entity of
( name, icon ) =
case entity of
Connection ->
div [ class "icon", title "Connections" ]
[ span [ class "nc-icon-outline arrows-2_conversion" ] []
, span [] [ text "Connections" ]
]
( "Connections", "arrows-2_conversion" )

Event ->
div [ class "icon", title "Events" ]
[ span [ class "nc-icon-outline ui-1_bell-53" ] []
, span [] [ text "Events" ]
]
( "Events", "ui-1_bell-53" )

Object ->
div [ class "icon", title "Objects" ]
[ span [ class "nc-icon-outline ui-1_database" ] []
, span [] [ text "Objects" ]
]
( "Objects", "ui-1_database" )

Reaction ->
div [ class "icon", title "Reactions" ]
[ span [ class "nc-icon-outline ui-2_like" ] []
, span [] [ text "Reactions" ]
]
( "Reactions", "ui-2_like" )

UnknownEntity ->
div [ class "icon", title "Unknown" ]
[ span [ class "nc-icon-outline ui-2_alert" ] []
, span [] [ text "Unknown" ]
]
( "Unknown", "ui-2_alert" )
in
h3 []
[ span [] [ text "A rule for" ]
, entity
, span [] [ text "called" ]
, strong [] [ text rule.name ]
, span [] [ text "targeting the" ]
, ecosystem
, span [] [ text "platform." ]
div [ class "icon", title name ]
[ span [ class ("nc-icon-outline " ++ icon) ] []
, span [] [ text "Connections" ]
]


viewRecipient : Recipient -> Html msg
viewRecipient recipient =
div [ class "recipient" ]
[ div [ class "meta" ]
((List.map viewTarget recipient.targets)
++ [ div [ class "urn" ]
[ span [] [ text "URN: " ]
, pre [] [ text recipient.urn ]
]
]
)
, div [ class "templates" ]
[ viewTemplates recipient.templates
]
]


viewRule : Rule -> Html msg
viewRule rule =
div []
[ viewRuleDescription rule
, h4 []
[ span [ class "icon nc-icon-outline users_mobile-contact" ] []
, span [] [ text "Recipients" ]
]
, div [ class "recipients" ] (List.map viewRecipient rule.recipients)
]


viewRuleDescription : Rule -> Html msg
viewRuleDescription rule =
h3 []
[ span [] [ text "A rule for" ]
, viewEntityButton rule.entity
, span [] [ text "called" ]
, strong [] [ text rule.name ]
, span [] [ text "targeting the" ]
, viewEcosystemButton rule.ecosystem
, span [] [ text "platform." ]
]


viewRuleItem : msg -> Rule -> Html msg
viewRuleItem msg rule =
tr [ onClick msg ]
[ td [ class "icon" ] [ viewActivated rule.active ]
, td [ class "icon" ] [ viewEcosystem rule.ecosystem ]
, td [ class "icon" ] [ viewEntity rule.entity ]
, td [ class "icon" ] [ viewEcosystemIcon rule.ecosystem ]
, td [ class "icon" ] [ viewEntityIcon rule.entity ]
, td [ class "icon" ] [ text (toString (List.length rule.recipients)) ]
, td [] [ text rule.name ]
]
Expand All @@ -135,6 +178,34 @@ viewRuleTable item rules =
]


viewTarget : Target -> Html msg
viewTarget target =
div [ class "target" ]
[ span [] [ text "Target: " ]
, strong [] [ text (Rule.Model.targetString target) ]
]


viewTemplate : ( String, String ) -> Html msg
viewTemplate ( lang, template ) =
tr []
[ td [] [ text lang ]
, td [] [ text template ]
]


viewTemplates templates =
table []
[ thead []
[ tr []
[ th [] [ text "lang" ]
, th [] [ text "template" ]
]
]
, tbody [] (List.map viewTemplate (Dict.toList templates))
]


sortByEntity : Rule -> Rule -> Order
sortByEntity a b =
case ( a.entity, b.entity ) of
Expand Down
Loading

0 comments on commit dff044c

Please sign in to comment.