From 166cd04e4b28770ede854dafc9ae30eae64102fe Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 28 Mar 2016 17:51:14 +0200 Subject: Create an empty but reachable user page --- src/client/elm/LoggedIn/View/Date.elm | 59 ------------------- src/client/elm/LoggedIn/View/Expand.elm | 25 -------- src/client/elm/LoggedIn/View/Paging.elm | 100 -------------------------------- src/client/elm/LoggedIn/View/Price.elm | 38 ------------ src/client/elm/LoggedIn/View/Table.elm | 96 ------------------------------ 5 files changed, 318 deletions(-) delete mode 100644 src/client/elm/LoggedIn/View/Date.elm delete mode 100644 src/client/elm/LoggedIn/View/Expand.elm delete mode 100644 src/client/elm/LoggedIn/View/Paging.elm delete mode 100644 src/client/elm/LoggedIn/View/Price.elm delete mode 100644 src/client/elm/LoggedIn/View/Table.elm (limited to 'src/client/elm/LoggedIn/View') diff --git a/src/client/elm/LoggedIn/View/Date.elm b/src/client/elm/LoggedIn/View/Date.elm deleted file mode 100644 index 62c8be5..0000000 --- a/src/client/elm/LoggedIn/View/Date.elm +++ /dev/null @@ -1,59 +0,0 @@ -module LoggedIn.View.Date - ( renderShortDate - , renderLongDate - ) where - -import Date exposing (..) -import String - -import Model.Translations exposing (..) - -renderShortDate : Date -> Translations -> String -renderShortDate date translations = - let params = - [ String.pad 2 '0' (toString (Date.day date)) - , String.pad 2 '0' (toString (getMonthNumber (Date.month date))) - , toString (Date.year date) - ] - in getParamMessage params "ShortDate" translations - -renderLongDate : Date -> Translations -> String -renderLongDate date translations = - let params = - [ toString (Date.day date) - , (getMessage (getMonthKey (Date.month date)) translations) - , toString (Date.year date) - ] - in getParamMessage params "LongDate" translations - -getMonthNumber : Month -> Int -getMonthNumber month = - case month of - Jan -> 1 - Feb -> 2 - Mar -> 3 - Apr -> 4 - May -> 5 - Jun -> 6 - Jul -> 7 - Aug -> 8 - Sep -> 9 - Oct -> 10 - Nov -> 11 - Dec -> 12 - -getMonthKey : Month -> String -getMonthKey month = - case month of - Jan -> "January" - Feb -> "February" - Mar -> "March" - Apr -> "April" - May -> "May" - Jun -> "June" - Jul -> "July" - Aug -> "August" - Sep -> "September" - Oct -> "October" - Nov -> "November" - Dec -> "December" diff --git a/src/client/elm/LoggedIn/View/Expand.elm b/src/client/elm/LoggedIn/View/Expand.elm deleted file mode 100644 index 1055c1b..0000000 --- a/src/client/elm/LoggedIn/View/Expand.elm +++ /dev/null @@ -1,25 +0,0 @@ -module LoggedIn.View.Expand - ( expand - , ExpandType(..) - ) where - -import Html exposing (..) -import Html.Attributes exposing (..) - -import View.Icon exposing (renderIcon) - -type ExpandType = ExpandUp | ExpandDown - -expand : ExpandType -> Bool -> Html -expand expandType isExpanded = - div - [ class "expand" ] - [ renderIcon (chevronIcon expandType isExpanded) ] - -chevronIcon : ExpandType -> Bool -> String -chevronIcon expandType isExpanded = - case (expandType, isExpanded) of - (ExpandUp, True) -> "chevron-down" - (ExpandUp, False) -> "chevron-up" - (ExpandDown, True) -> "chevron-up" - (ExpandDown, False) -> "chevron-down" diff --git a/src/client/elm/LoggedIn/View/Paging.elm b/src/client/elm/LoggedIn/View/Paging.elm deleted file mode 100644 index 0a149e9..0000000 --- a/src/client/elm/LoggedIn/View/Paging.elm +++ /dev/null @@ -1,100 +0,0 @@ -module LoggedIn.View.Paging - ( paymentsPaging - ) where - -import Signal exposing (Address) - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) - -import LoggedIn.Action as LoggedInAction -import LoggedIn.Model as LoggedInModel - -import Action exposing (..) -import Model.Payment exposing (perPage) - -import View.Icon exposing (renderIcon) - -showedPages : Int -showedPages = 5 - -paymentsPaging : Address Action -> LoggedInModel.Model -> Html -paymentsPaging address loggedInModel = - let maxPage = ceiling (toFloat loggedInModel.paymentsCount / toFloat perPage) - pages = truncatePages loggedInModel.currentPage [1..maxPage] - in if maxPage == 1 - then - text "" - else - div - [ class "pages" ] - ( ( if loggedInModel.currentPage > 1 - then [ firstPage address, previousPage address loggedInModel ] - else [] - ) - ++ ( List.map (paymentsPage address loggedInModel) pages) - ++ ( if loggedInModel.currentPage < maxPage - then [ nextPage address loggedInModel, lastPage address maxPage ] - else [] - ) - ) - -truncatePages : Int -> List Int -> List Int -truncatePages currentPage pages = - let totalPages = List.length pages - showedLeftPages = ceiling ((toFloat showedPages - 1) / 2) - showedRightPages = floor ((toFloat showedPages - 1) / 2) - truncatedPages = - if currentPage < showedLeftPages then - [1..showedPages] - else if currentPage > totalPages - showedRightPages then - [(totalPages - showedPages)..totalPages] - else - [(currentPage - showedLeftPages)..(currentPage + showedRightPages)] - in List.filter (flip List.member pages) truncatedPages - -firstPage : Address Action -> Html -firstPage address = - button - [ class "page" - , onClick address (UpdateLoggedIn (LoggedInAction.UpdatePage 1)) - ] - [ renderIcon "fast-backward" ] - -previousPage : Address Action -> LoggedInModel.Model -> Html -previousPage address loggedInModel = - button - [ class "page" - , onClick address (UpdateLoggedIn (LoggedInAction.UpdatePage (loggedInModel.currentPage - 1))) - ] - [ renderIcon "backward" ] - -nextPage : Address Action -> LoggedInModel.Model -> Html -nextPage address loggedInModel = - button - [ class "page" - , onClick address (UpdateLoggedIn (LoggedInAction.UpdatePage (loggedInModel.currentPage + 1))) - ] - [ renderIcon "forward" ] - -lastPage : Address Action -> Int -> Html -lastPage address maxPage = - button - [ class "page" - , onClick address (UpdateLoggedIn (LoggedInAction.UpdatePage maxPage)) - ] - [ renderIcon "fast-forward" ] - -paymentsPage : Address Action -> LoggedInModel.Model -> Int -> Html -paymentsPage address loggedInModel page = - let onCurrentPage = page == loggedInModel.currentPage - in button - [ classList - [ ("page", True) - , ("current", onCurrentPage) - ] - , onClick address <| - if onCurrentPage then Action.NoOp else UpdateLoggedIn (LoggedInAction.UpdatePage page) - ] - [ text (toString page) ] diff --git a/src/client/elm/LoggedIn/View/Price.elm b/src/client/elm/LoggedIn/View/Price.elm deleted file mode 100644 index e8b4c58..0000000 --- a/src/client/elm/LoggedIn/View/Price.elm +++ /dev/null @@ -1,38 +0,0 @@ -module LoggedIn.View.Price - ( price - ) where - -import String exposing (..) - -import Model exposing (Model) -import Model.Translations exposing (getMessage) - -price : Model -> Int -> String -price model amount = - ( formatInt amount - ++ " " - ++ model.conf.currency - ) - -formatInt : Int -> String -formatInt n = - abs n - |> toString - |> toList - |> List.reverse - |> group 3 - |> List.intersperse [' '] - |> List.concat - |> List.reverse - |> fromList - |> append (if n < 0 then "-" else "") - -group : Int -> List a -> List (List a) -group n xs = - if List.length xs <= n - then - [xs] - else - let take = List.take n xs - drop = List.drop n xs - in take :: (group n drop) diff --git a/src/client/elm/LoggedIn/View/Table.elm b/src/client/elm/LoggedIn/View/Table.elm deleted file mode 100644 index 57167be..0000000 --- a/src/client/elm/LoggedIn/View/Table.elm +++ /dev/null @@ -1,96 +0,0 @@ -module LoggedIn.View.Table - ( paymentsTable - ) where - -import Dict exposing (..) -import Date exposing (Date) -import Signal exposing (Address) -import String exposing (append) - -import Html exposing (..) -import Html.Attributes exposing (..) -import Html.Events exposing (..) - -import LoggedIn.Action as LoggedInAction -import LoggedIn.Model as LoggedInModel -import LoggedIn.View.Date exposing (..) -import LoggedIn.View.Price exposing (price) - -import Model exposing (Model) -import Model.User exposing (getUserName) -import Model.Payment exposing (..) -import Model.Translations exposing (getMessage) -import Action exposing (..) - -import View.Icon exposing (renderIcon) - -paymentsTable : Address Action -> Model -> LoggedInModel.Model -> Html -paymentsTable address model loggedInModel = - div - [ class "table" ] - ( headerLine model :: paymentLines address model loggedInModel) - -headerLine : Model -> Html -headerLine model = - div - [ class "header" ] - [ div [ class "cell category" ] [ renderIcon "shopping-cart" ] - , div [ class "cell cost" ] [ text model.conf.currency ] - , div [ class "cell user" ] [ renderIcon "user" ] - , div [ class "cell date" ] [ renderIcon "calendar" ] - , div [ class "cell" ] [] - ] - -paymentLines : Address Action -> Model -> LoggedInModel.Model -> List Html -paymentLines address model loggedInModel = - loggedInModel.payments - |> List.sortBy (Date.toTime << .creation) - |> List.reverse - |> List.drop ((loggedInModel.currentPage - 1) * perPage) - |> List.take perPage - |> List.map (paymentLine address model loggedInModel) - -paymentLine : Address Action -> Model -> LoggedInModel.Model -> Payment -> Html -paymentLine address model loggedInModel payment = - a - [ classList - [ ("row", True) - , ("edition", loggedInModel.paymentEdition == Just payment.id) - ] - , onClick address (UpdateLoggedIn (LoggedInAction.ToggleEdit payment.id)) - ] - [ div [ class "cell category" ] [ text payment.name ] - , div - [ classList - [ ("cell cost", True) - , ("refund", payment.cost < 0) - ] - ] - [ text (price model payment.cost) ] - , div - [ class "cell user" ] - [ payment.userId - |> getUserName loggedInModel.users - |> Maybe.withDefault "−" - |> text - ] - , div - [ class "cell date" ] - [ span - [ class "shortDate" ] - [ text (renderShortDate payment.creation model.translations) ] - , span - [ class "longDate" ] - [ text (renderLongDate payment.creation model.translations) ] - ] - , if loggedInModel.account.me == payment.userId - then - div - [ class "cell delete" ] - [ button - [ onClick address (UpdateLoggedIn <| LoggedInAction.DeletePayment payment Punctual)] - [ renderIcon "times" ] - ] - else - div [ class "cell" ] [] - ] -- cgit v1.2.3