Skip to content

Commit

Permalink
Merge pull request #5 from dwyl/initialise-api
Browse files Browse the repository at this point in the history
define structure api
  • Loading branch information
nelsonic authored Dec 6, 2018
2 parents 869205c + d31f9ff commit 9da528d
Show file tree
Hide file tree
Showing 9 changed files with 454 additions and 52 deletions.
35 changes: 35 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
sudo: false

language: node_js
node_js: node

cache:
directories:
- elm-stuff/build-artifacts
- elm-stuff/packages
- sysconfcpus
os:
- linux

env: ELM_VERSION=0.19.0

before_install:
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config

install:
- node --version
- npm --version
- npm install -g elm@$ELM_VERSION elm-test
# Faster compile on Travis.
- |
if [ ! -d sysconfcpus/bin ];
then
git clone https://github.com/obmarg/libsysconfcpus.git;
cd libsysconfcpus;
./configure --prefix=$TRAVIS_BUILD_DIR/sysconfcpus;
make && make install;
cd ..;
fi
script:
- $TRAVIS_BUILD_DIR/sysconfcpus/bin/sysconfcpus -n 1 elm-test
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# elm-criteria
[![Build Status](https://travis-ci.org/dwyl/elm-criteria.svg?branch=master)](https://travis-ci.org/dwyl/elm-criteria)

A reusable dropdown/filters Elm package

## Examples
Expand Down
1 change: 1 addition & 0 deletions docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"name":"Criteria","comment":" This package help you create a hierarchy of \"filters\"\ncontained in a dropdown\n\nHave a look at a live [exmpamle] and its [code]\n\n[example]: https://dwyl.github.io/elm-criteria/example.html\n[code]: https://github.com/dwyl/elm-criteria/blob/master/examples/Example.elm\n\n\n# View\n\n@docs view\n\n\n# Config\n\n@docs Config, config\n\n\n# State\n\n@docs State, init\n\n\n# Helpers\n\n@docs selectedIdFilters\n\n","unions":[{"name":"Config","comment":" Configuration for displaying the hierarchy of filters\n","args":["msg","filter"],"cases":[]},{"name":"State","comment":" Define if the hierarchy of filters is open and the set of the selected filters\n\n State False Set.empty\n\n","args":[],"cases":[]}],"aliases":[],"values":[{"name":"config","comment":" Create the configuation to pass in your view.\n\n - `title` — A string displayed for the button text\n - `toMsg` — The message which is responsible for updating the `Criteria.State` in your model\n - `toId` — A function taking a filter and returning a unique string which represent the filter\n - `tostring` — A function taking a filter and returning a string which will be used as label in the hierarchy\n - `getSubFilters` — A fuction taking a filter and returning the a list of its sub-filters\n\n","type":"{ title : String.String, toMsg : Criteria.State -> msg, toId : filter -> String.String, toString : filter -> String.String, getSubFilters : filter -> List.List filter } -> Criteria.Config msg filter"},{"name":"init","comment":" Initialise the state, ie filters are hidden and no filter selected yet\n\n import Criteria\n\n Criteria.init\n\n","type":"Criteria.State"},{"name":"selectedIdFilters","comment":" Return the set of the selected filters' id\n","type":"Criteria.State -> Set.Set String.String"},{"name":"view","comment":" The view function which take the configuration the state and a list of filters\n","type":"Criteria.Config msg filter -> Criteria.State -> List.List filter -> Html.Html msg"}],"binops":[]}]
31 changes: 17 additions & 14 deletions elm.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
"type": "package",
"name": "dwyl/elm-criteria",
"summary": "A reusable dropdown/filters Elm package",
"license": "BSD-3-Clause",
"version": "1.0.0",
"exposed-modules": [
"Criteria"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"elm/core": "1.0.0 <= v < 2.0.0",
"elm/json": "1.1.2 <= v < 2.0.0"
},
"test-dependencies": {}
"type": "package",
"name": "dwyl/elm-criteria",
"summary": "A reusable dropdown/filters Elm package",
"license": "BSD-3-Clause",
"version": "1.0.0",
"exposed-modules": [
"Criteria"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"elm/core": "1.0.0 <= v < 2.0.0",
"elm/html": "1.0.0 <= v < 2.0.0",
"elm/json": "1.1.2 <= v < 2.0.0"
},
"test-dependencies": {
"elm-explorations/test": "1.2.0 <= v < 2.0.0"
}
}
98 changes: 87 additions & 11 deletions examples/Example.elm
Original file line number Diff line number Diff line change
@@ -1,35 +1,111 @@
module Main exposing (main)

import Browser
import Html exposing (Html, button, div, h1, text)
import Html.Attributes exposing (..)
import Criteria
import Html exposing (Html, button, div, h1, p, text)
import Html.Attributes exposing (..)
import Set exposing (..)


main =
Browser.sandbox { init = init, update = update, view = view }
Browser.sandbox { init = init, update = update, view = view }



-- MODEL

type alias Model = String

type alias Model =
{ criteria : Criteria.State }


init : Model
init = "Hello"
init =
{ criteria = Criteria.init }


criteriaConfig : Criteria.Config Msg Filter
criteriaConfig =
Criteria.config
{ title = "My filters"
, toMsg = UpdateCriteria
, toId = getFilterId
, toString = getFilterName
, getSubFilters = getSubFilters
}



-- UPDATE

type Msg = None

type Msg
= UpdateCriteria Criteria.State



-- see "recursive types!" section of https://elm-lang.org/0.19.0/recursive-alias


type alias Filter =
( String, SubFilters )


type SubFilters
= SubFilters (List Filter)


update : Msg -> Model -> Model
update msg model =
case msg of
None -> model
case msg of
UpdateCriteria state ->
{ model | criteria = state }



-- VIEW


view : Model -> Html Msg
view model =
div []
[ h1 [] [text model]
, Criteria.view
div []
[ h1 [] [ text "Criteria Package" ]
, Criteria.view criteriaConfig model.criteria filters
, p [] [ text "this is the rest of the application content" ]
, p [] [ text "Filter selected:" ]
, p [] [ text <| showSelectedFilters model.criteria ]
]


showSelectedFilters : Criteria.State -> String
showSelectedFilters state =
let
f =
Criteria.selectedIdFilters state
in
Set.toList f |> String.join " "


filters : List Filter
filters =
[ ( "filter1", SubFilters [ ( "filter11", SubFilters [] ), ( "filter12", SubFilters [] ), ( "filter13", SubFilters [] ) ] )
, ( "filter2", SubFilters [ ( "filter21", SubFilters [ ( "filter 212", SubFilters [] ) ] ), ( "filter22", SubFilters [] ) ] )
, ( "filter3", SubFilters [] )
, ( "filter4", SubFilters [ ( "filter41", SubFilters [] ) ] )
, ( "filter2", SubFilters [] )
]


getFilterName : Filter -> String
getFilterName ( filter, _ ) =
filter


getFilterId : Filter -> String
getFilterId ( filter, _ ) =
"id:" ++ filter


getSubFilters : Filter -> List Filter
getSubFilters ( _, SubFilters subFilters ) =
subFilters
44 changes: 22 additions & 22 deletions examples/elm.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"type": "application",
"source-directories": [
".",
"../src"
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/browser": "1.0.1",
"elm/core": "1.0.2",
"elm/html": "1.0.0"
"type": "application",
"source-directories": [
".",
"../src"
],
"elm-version": "0.19.0",
"dependencies": {
"direct": {
"elm/browser": "1.0.1",
"elm/core": "1.0.2",
"elm/html": "1.0.0",
"elm/json": "1.1.2"
},
"indirect": {
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
},
"indirect": {
"elm/json": "1.1.2",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
"test-dependencies": {
"direct": {},
"indirect": {}
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}
}
Loading

0 comments on commit 9da528d

Please sign in to comment.