summaryrefslogtreecommitdiff
path: root/elm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-11-27 09:18:21 +0100
committerYorhel <git@yorhel.nl>2019-11-27 14:28:18 +0100
commit4067f0a73a55e898def7320976781a2b8bf6710b (patch)
treea334579a9e0389337238cf13e19851156c2b9fd2 /elm
parent9c4835a94263127f780c0b96db89aa25ceefd960 (diff)
ulist: Add column selection + voted, modified, release date & rating columns
It works pretty well, but Lists.pm is getting *really* ugly now. :(
Diffstat (limited to 'elm')
-rw-r--r--elm/ColSelect.elm85
-rw-r--r--elm/ColSelect.js5
-rw-r--r--elm/elm.json3
3 files changed, 92 insertions, 1 deletions
diff --git a/elm/ColSelect.elm b/elm/ColSelect.elm
new file mode 100644
index 00000000..d8be329b
--- /dev/null
+++ b/elm/ColSelect.elm
@@ -0,0 +1,85 @@
+-- Column selection dropdown for tables. Assumes that the currently selected
+-- columns are in the query string as the 'c' parameter, e.g.:
+--
+-- ?c=column_id&c=modified&...
+--
+-- Accepts a list of columns from Perl, e.g.:
+--
+-- [
+-- [ 'column_id', 'Column Label' ],
+-- [ 'modified', 'Date modified' ],
+-- ...
+-- ]
+module ColSelect exposing (main)
+
+import Html exposing (..)
+import Html.Attributes exposing (..)
+import Html.Events exposing (..)
+import Browser
+import Browser.Navigation exposing (load)
+import Set
+import Erl -- elm/url can't extract a full list of query parameters and hence can't be used to modify a parameter without removing all others.
+import Lib.DropDown as DD
+import Lib.Api as Api
+import Lib.Html exposing (..)
+
+
+main : Program (String, Columns) Model Msg
+main = Browser.element
+ { init = \e -> (init e, Cmd.none)
+ , view = view
+ , update = update
+ , subscriptions = \model -> DD.sub model.dd
+ }
+
+
+type alias Columns = List (String, String)
+
+type alias Model =
+ { cols : Columns
+ , url : Erl.Url -- Without the "c" parameter
+ , sel : Set.Set String
+ , dd : DD.Config Msg
+ }
+
+
+init : (String, Columns) -> Model
+init (u, c) =
+ { cols = c
+ , url = Erl.removeQuery "c" <| Erl.parse u
+ , sel = Set.fromList <| Erl.getQueryValuesForKey "c" <| Erl.parse u
+ , dd = DD.init "colselect" Open
+ }
+
+
+type Msg
+ = Open Bool
+ | Toggle String Bool
+ | Update
+
+
+update : Msg -> Model -> (Model, Cmd Msg)
+update msg model =
+ case msg of
+ Open b -> ({ model | dd = DD.toggle model.dd b }, Cmd.none)
+ Toggle s b -> ({ model | sel = if b then Set.insert s model.sel else Set.remove s model.sel }, Cmd.none)
+ Update -> (model, load <| Erl.toString <| List.foldl (\s u -> Erl.addQuery "c" s u) model.url <| Set.toList model.sel)
+
+
+view : Model -> Html Msg
+view model =
+ let
+ item (cid, cname) =
+ let selid = "colselect_" ++ cid
+ in
+ li [ class "linkradio" ]
+ [ inputCheck selid (Set.member cid model.sel) (Toggle cid)
+ , label [ for selid ] [ text cname ]
+ ]
+ in
+ DD.view model.dd Api.Normal
+ (text "Select columns")
+ (\_ -> [ ul []
+ <| List.map item model.cols
+ ++ [ li [ ] [ input [ type_ "button", class "submit", value "update", onClick Update ] [] ] ]
+ ])
diff --git a/elm/ColSelect.js b/elm/ColSelect.js
new file mode 100644
index 00000000..e6812fab
--- /dev/null
+++ b/elm/ColSelect.js
@@ -0,0 +1,5 @@
+var init = Elm.ColSelect.init;
+Elm.ColSelect.init = function(opt) {
+ opt.flags = [ location.href, opt.flags ];
+ return init(opt);
+};
diff --git a/elm/elm.json b/elm/elm.json
index 6867e2b1..3db9993a 100644
--- a/elm/elm.json
+++ b/elm/elm.json
@@ -6,6 +6,7 @@
"elm-version": "0.19.1",
"dependencies": {
"direct": {
+ "RomanErnst/erl": "2.1.1",
"elm/browser": "1.0.1",
"elm/core": "1.0.2",
"elm/file": "1.0.1",
@@ -13,13 +14,13 @@
"elm/http": "2.0.0",
"elm/json": "1.1.2",
"elm/regex": "1.0.0",
+ "elm/url": "1.0.0",
"justinmimbs/date": "3.1.2"
},
"indirect": {
"elm/bytes": "1.0.3",
"elm/parser": "1.1.0",
"elm/time": "1.0.0",
- "elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
},