Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
replace biu with elm + sui messages
Browse files Browse the repository at this point in the history
  • Loading branch information
monty5811 committed Jan 20, 2017
1 parent dabd108 commit 926d678
Show file tree
Hide file tree
Showing 34 changed files with 282 additions and 170 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ All notable changes to this project will be documented in this file.

### Changed
- Move wrench menu out of top menu and into a "floating action button"
- Trim js/css payload

## [v1.14.0]
### Added
Expand Down
2 changes: 1 addition & 1 deletion apostello/static/css/apostello.min.css

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions apostello/static/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apostello/static/js/tour.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions apostello/static/js/vendor.js

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions assets/css/apostello.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@import "./../semantic/dist/semantic";
@import "./../node_modules/datetimepicker/dist/DateTimePicker";
@import "./../node_modules/biu.js/dist/biu";

// tour:
@import "./../node_modules/intro.js/introjs";
Expand All @@ -17,10 +16,6 @@
border: none !important;
box-shadow: none !important;
}
// biu
.biu-instance{
z-index: 11;
}
// fab:
.fabContainer{
position: fixed;
Expand Down
35 changes: 0 additions & 35 deletions assets/elm/Biu.elm

This file was deleted.

18 changes: 17 additions & 1 deletion assets/elm/Helpers.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import Dict
import Http
import Json.Decode as Decode
import Json.Encode as Encode
import Messages exposing (..)
import Models exposing (..)
import Updates.Notification exposing (createLoadingFailedNotification, createNotSavedNotification)
import Regex


Expand Down Expand Up @@ -53,7 +55,7 @@ determineLoadingStatus resp =



-- increase page size gor next response
-- increase page size for next response


increasePageSize : String -> String
Expand Down Expand Up @@ -89,3 +91,17 @@ addNewItems newItems existingItemsDict =
addItemToDic : { a | pk : Int } -> Dict.Dict Int { a | pk : Int } -> Dict.Dict Int { a | pk : Int }
addItemToDic item existingItems =
Dict.insert item.pk item existingItems



-- update model after http errors:


handleLoadingFailed : Model -> ( Model, Cmd Msg )
handleLoadingFailed model =
( { model | loadingStatus = Finished } |> createLoadingFailedNotification, Cmd.none )


handleNotSaved : Model -> ( Model, Cmd Msg )
handleNotSaved model =
( createNotSavedNotification model, Cmd.none )
7 changes: 7 additions & 0 deletions assets/elm/Messages.elm
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@ type Msg
| KeyRespTableMsg KeyRespTableMsg
| FirstRunMsg FirstRunMsg
| FabMsg FabMsg
| NotificationMsg NotificationMsg
| CurrentTime Time.Time


type NotificationMsg
= NewNotification NotificationType String
| RemoveNotification Notification
| CleanOldNotifications Time.Time


type FabMsg
= ArchiveItem
| ReceiveArchiveResp (Result Http.Error Bool)
Expand Down
21 changes: 19 additions & 2 deletions assets/elm/Models.elm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ type alias Model =
, keyRespTable : KeyRespTableModel
, firstRun : FirstRunModel
, fabModel : FabModel
, currentTime : Maybe Time.Time
, notifications : List Notification
, currentTime : Time.Time
}


Expand All @@ -53,8 +54,9 @@ initialModel csrftoken page incomingUrl fabFlags =
, keyRespTable = initialKeyRespModel
, firstRun = initialFirstRunModel
, fabModel = initialFabModel fabFlags
, notifications = []
, dataUrl = incomingUrl
, currentTime = Nothing
, currentTime = 0
}


Expand All @@ -79,6 +81,21 @@ type alias Flags =
}


type alias Notification =
{ type_ : NotificationType
, text : String
, id : Int
, created : Time.Time
}


type NotificationType
= InfoNotification
| SuccessNotification
| WarningNotification
| ErrorNotification


type alias FabFlags =
{ pageLinks : List PageLink
, archiveButton : Maybe ArchiveButton
Expand Down
19 changes: 10 additions & 9 deletions assets/elm/Subscriptions.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ import Time exposing (Time, second)
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.batch
[ queuedSmsTime model.page
, reloadData model.page model.loadingStatus
[ reloadData model.page model.loadingStatus
, getCurrentTime
, cleanOldNotifications
]


queuedSmsTime : Page -> Sub Msg
queuedSmsTime page =
case page of
ScheduledSmsTable ->
Time.every (10 * second) (\t -> CurrentTime t)
getCurrentTime : Sub Msg
getCurrentTime =
Time.every second (\t -> CurrentTime t)

_ ->
Sub.none

cleanOldNotifications : Sub Msg
cleanOldNotifications =
Time.every second (\t -> NotificationMsg (CleanOldNotifications t))


reloadData : Page -> LoadingStatus -> Sub Msg
Expand Down
6 changes: 5 additions & 1 deletion assets/elm/Update.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Updates.GroupTable
import Updates.InboundTable
import Updates.KeyRespTable
import Updates.KeywordTable
import Updates.Notification
import Updates.OutboundTable
import Updates.RecipientTable
import Updates.ScheduledSmsTable
Expand All @@ -30,6 +31,9 @@ update msg model =
FabMsg subMsg ->
Updates.Fab.update subMsg model

NotificationMsg subMsg ->
Updates.Notification.update subMsg model

FirstRunMsg subMsg ->
Updates.FirstRun.update subMsg model

Expand Down Expand Up @@ -74,4 +78,4 @@ update msg model =
( { model | filterRegex = (FT.textToRegex filterText) }, Cmd.none )

CurrentTime t ->
( { model | currentTime = Just t }, Cmd.none )
( { model | currentTime = t }, Cmd.none )
24 changes: 9 additions & 15 deletions assets/elm/Updates/ElvantoImport.elm
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
module Updates.ElvantoImport exposing (update)

import Actions exposing (determineRespCmd)
import Biu exposing (..)
import Decoders exposing (elvantogroupDecoder)
import DjangoSend exposing (post)
import Helpers exposing (mergeItems, determineLoadingStatus, encodeBody)
import Helpers exposing (..)
import Http
import Json.Decode as Decode
import Json.Encode as Encode
import Messages exposing (..)
import Models exposing (..)
import Updates.Notification exposing (createInfoNotification, createSuccessNotification)


update : ElvantoMsg -> Model -> ( Model, Cmd Msg )
Expand All @@ -24,7 +24,7 @@ update msg model =
)

LoadElvantoResp (Err _) ->
( { model | loadingStatus = Finished }, biuLoadingFailed )
handleLoadingFailed model

ToggleGroupSync group ->
( { model | elvantoImport = optToggleGroup group model.elvantoImport }
Expand All @@ -39,29 +39,23 @@ update msg model =
)

ReceiveToggleGroupSync (Err _) ->
( model, biuNotSaved )
handleNotSaved model

PullGroups ->
( model
, Cmd.batch
[ biuInfo "Groups are being imported, it may take a couple of minutes"
, pullGroups model.csrftoken
]
( createInfoNotification model "Groups are being imported, it may take a couple of minutes"
, pullGroups model.csrftoken
)

FetchGroups ->
( model
, Cmd.batch
[ biuSuccess "Groups are being fetched, it may take a couple of minutes"
, fetchGroups model.csrftoken
]
( createSuccessNotification model "Groups are being fetched, it may take a couple of minutes"
, fetchGroups model.csrftoken
)

ReceiveButtonResp (Ok _) ->
( model, Cmd.none )

ReceiveButtonResp (Err _) ->
( model, biuNotSaved )
handleNotSaved model


updateGroups : ElvantoImportModel -> ElvantoGroups -> ElvantoImportModel
Expand Down
5 changes: 2 additions & 3 deletions assets/elm/Updates/GroupComposer.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Updates.GroupComposer exposing (update)

import Biu exposing (..)
import Helpers exposing (mergeItems, determineLoadingStatus, encodeBody)
import Helpers exposing (..)
import Actions exposing (determineRespCmd)
import Dict
import Messages exposing (..)
Expand All @@ -20,7 +19,7 @@ update msg model =
)

LoadGroupComposerResp (Err _) ->
( { model | loadingStatus = Finished }, biuLoadingFailed )
handleLoadingFailed model

UpdateQueryString text ->
( { model | groupComposer = updateQueryString text model.groupComposer }, Cmd.none )
Expand Down
7 changes: 3 additions & 4 deletions assets/elm/Updates/GroupMemberSelect.elm
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module Updates.GroupMemberSelect exposing (update)

import Biu exposing (..)
import Decoders exposing (recipientgroupDecoder)
import DjangoSend exposing (post)
import Helpers exposing (encodeBody, getData)
import Helpers exposing (..)
import Http
import Json.Encode as Encode
import Messages exposing (..)
Expand All @@ -23,7 +22,7 @@ update msg model =
)

LoadGroupMemberSelectResp (Err _) ->
( { model | loadingStatus = Finished }, biuLoadingFailed )
handleLoadingFailed model

UpdateMemberFilter text ->
( { model | groupSelect = updateMemberFilter model.groupSelect text }, Cmd.none )
Expand All @@ -49,7 +48,7 @@ update msg model =
)

ReceiveToggleMembership (Err _) ->
( { model | loadingStatus = Finished }, biuLoadingFailed )
handleNotSaved model


updateMemberFilter : GroupMemberSelectModel -> String -> GroupMemberSelectModel
Expand Down
10 changes: 6 additions & 4 deletions assets/elm/Updates/GroupTable.elm
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module Updates.GroupTable exposing (update)

import Actions exposing (determineRespCmd)
import Biu exposing (..)
import Decoders exposing (recipientgroupDecoder)
import DjangoSend exposing (post)
import Helpers exposing (mergeItems, determineLoadingStatus, encodeBody)
import Helpers exposing (..)
import Http
import Json.Encode as Encode
import Messages exposing (..)
Expand All @@ -23,16 +22,19 @@ update msg model =
)

LoadGroupTableResp (Err _) ->
( { model | loadingStatus = Finished }, biuLoadingFailed )
handleLoadingFailed model

ToggleGroupArchive isArchived pk ->
( { model | groupTable = optArchiveGroup model.groupTable pk }
, toggleRecipientGroupArchive model.csrftoken isArchived pk
)

ReceiveToggleGroupArchive recipient ->
ReceiveToggleGroupArchive (Ok _) ->
( model, Cmd.none )

ReceiveToggleGroupArchive (Err _) ->
handleNotSaved model


updateGroups : GroupTableModel -> ApostelloResponse RecipientGroup -> GroupTableModel
updateGroups model resp =
Expand Down
9 changes: 4 additions & 5 deletions assets/elm/Updates/InboundTable.elm
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module Updates.InboundTable exposing (update)

import Actions exposing (determineRespCmd)
import Biu exposing (..)
import Decoders exposing (smsinboundDecoder)
import DjangoSend exposing (post)
import Helpers exposing (mergeItems, determineLoadingStatus, encodeBody)
import Helpers exposing (..)
import Http
import Json.Encode as Encode
import Messages exposing (..)
Expand All @@ -22,8 +21,8 @@ update msg model =
, determineRespCmd InboundTable resp
)

LoadInboundTableResp (Err e) ->
( { model | loadingStatus = Finished }, biuWarning (toString e) )
LoadInboundTableResp (Err _) ->
handleLoadingFailed model

ReprocessSms pk ->
( model, reprocessSms model.csrftoken pk )
Expand All @@ -32,7 +31,7 @@ update msg model =
( { model | inboundTable = updateSms model.inboundTable [ sms ] }, Cmd.none )

ReceiveReprocessSms (Err _) ->
( model, biuNotSaved )
handleNotSaved model


updateSms : InboundTableModel -> SmsInbounds -> InboundTableModel
Expand Down

0 comments on commit 926d678

Please sign in to comment.