2022-02-01 22:33:58 +00:00
|
|
|
module Main exposing (main)
|
|
|
|
|
|
|
|
import Browser
|
2022-02-04 01:46:55 +00:00
|
|
|
import Sort.Set as Set exposing (Set)
|
2022-02-06 00:20:09 +00:00
|
|
|
import Html exposing (Html, button, div, h2, h3, input, label, p, section, text, span, h3)
|
2022-02-03 00:51:31 +00:00
|
|
|
import Html.Events exposing (onCheck, onClick)
|
2022-02-02 19:31:07 +00:00
|
|
|
import Html.Attributes exposing (class, type_, id)
|
2022-02-03 00:51:31 +00:00
|
|
|
import Html.Attributes exposing (attribute)
|
2022-02-01 22:33:58 +00:00
|
|
|
|
2022-02-04 01:46:55 +00:00
|
|
|
import License exposing (License, DownloadType (..))
|
|
|
|
import License.Hippocratic as Hippocratic
|
|
|
|
import License.NPL as NPL
|
|
|
|
|
2022-02-01 22:33:58 +00:00
|
|
|
main: Program () Model Msg
|
|
|
|
main =
|
2022-02-03 00:51:31 +00:00
|
|
|
Browser.element
|
|
|
|
{ init = init
|
|
|
|
, update = update
|
|
|
|
, view = view
|
|
|
|
, subscriptions = subscriptions
|
|
|
|
}
|
|
|
|
|
|
|
|
subscriptions : Model -> Sub Msg
|
|
|
|
subscriptions _ = Sub.none
|
2022-02-01 22:33:58 +00:00
|
|
|
|
|
|
|
-- INIT + Model
|
|
|
|
|
2022-02-04 01:46:55 +00:00
|
|
|
type SelectedLicense
|
|
|
|
= Hippocratic
|
|
|
|
| NPL
|
2022-02-05 23:55:21 +00:00
|
|
|
availableLicenses : List SelectedLicense
|
|
|
|
availableLicenses = [ Hippocratic, NPL ]
|
2022-02-01 22:33:58 +00:00
|
|
|
|
|
|
|
type alias Model =
|
2022-02-04 01:46:55 +00:00
|
|
|
{ selected : SelectedLicense
|
|
|
|
, hippocratic : License Hippocratic.Module
|
|
|
|
, npl : License NPL.Module
|
2022-02-01 22:33:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-05 23:55:21 +00:00
|
|
|
selectedInfo : SelectedLicense -> License.LicenseDescriptors
|
|
|
|
selectedInfo selected =
|
|
|
|
case selected of
|
|
|
|
Hippocratic -> Hippocratic.info.descriptors
|
|
|
|
NPL -> NPL.info.descriptors
|
|
|
|
|
2022-02-03 00:51:31 +00:00
|
|
|
init : () -> (Model, Cmd Msg)
|
|
|
|
init () =
|
2022-02-04 01:46:55 +00:00
|
|
|
(
|
|
|
|
{ selected = Hippocratic
|
|
|
|
, hippocratic = License.empty Hippocratic.info
|
|
|
|
, npl = License.empty NPL.info
|
|
|
|
}
|
2022-02-03 00:51:31 +00:00
|
|
|
, Cmd.none
|
|
|
|
)
|
2022-02-01 22:33:58 +00:00
|
|
|
|
|
|
|
-- UPDATE
|
|
|
|
|
|
|
|
type Msg
|
2022-02-04 01:46:55 +00:00
|
|
|
= SwitchLicense SelectedLicense
|
|
|
|
| ToggleModule AnyModule Bool
|
|
|
|
| Download License.DownloadType
|
|
|
|
|
|
|
|
type AnyModule
|
|
|
|
= HippocraticMod Hippocratic.Module
|
|
|
|
| NPLMod NPL.Module
|
2022-02-01 22:33:58 +00:00
|
|
|
|
2022-02-04 01:46:55 +00:00
|
|
|
type alias ModuleWrapper mtype = mtype -> AnyModule
|
2022-02-01 22:33:58 +00:00
|
|
|
|
2022-02-03 00:51:31 +00:00
|
|
|
update : Msg -> Model -> (Model, Cmd Msg)
|
2022-02-01 22:33:58 +00:00
|
|
|
update msg model =
|
|
|
|
case msg of
|
2022-02-04 01:46:55 +00:00
|
|
|
SwitchLicense newLicense ->
|
|
|
|
( { model | selected = newLicense }
|
|
|
|
, Cmd.none
|
|
|
|
)
|
2022-02-01 22:33:58 +00:00
|
|
|
ToggleModule mod enabled ->
|
2022-02-04 01:46:55 +00:00
|
|
|
( case mod of
|
|
|
|
HippocraticMod modu ->
|
|
|
|
{ model | hippocratic = License.toggleModule enabled modu model.hippocratic }
|
|
|
|
NPLMod modu ->
|
|
|
|
{ model | npl = License.toggleModule enabled modu model.npl }
|
2022-02-03 00:51:31 +00:00
|
|
|
, Cmd.none
|
|
|
|
)
|
|
|
|
Download dtype ->
|
2022-02-04 01:46:55 +00:00
|
|
|
( model
|
|
|
|
, case model.selected of
|
|
|
|
Hippocratic -> License.download dtype model.hippocratic
|
|
|
|
NPL -> License.download dtype model.npl
|
|
|
|
)
|
2022-02-01 22:33:58 +00:00
|
|
|
|
|
|
|
-- VIEW
|
|
|
|
|
2022-02-04 01:46:55 +00:00
|
|
|
view_module_button : ModuleWrapper moduleType -> (moduleType -> License.ModuleInfo) -> Set moduleType -> moduleType -> Html Msg
|
|
|
|
view_module_button wrapModule moduleInfo enabled mod =
|
2022-02-01 22:33:58 +00:00
|
|
|
label
|
2022-02-02 23:27:11 +00:00
|
|
|
(class "module-button"
|
2022-02-04 01:46:55 +00:00
|
|
|
:: (if Set.memberOf enabled mod then [class "active"] else [])
|
2022-02-02 23:27:11 +00:00
|
|
|
)
|
|
|
|
[ div []
|
|
|
|
[ div [class "cooler-checkbox"]
|
|
|
|
[ input
|
|
|
|
[ type_ "checkbox"
|
2022-02-04 01:46:55 +00:00
|
|
|
, onCheck (ToggleModule (wrapModule mod))
|
2022-02-02 23:27:11 +00:00
|
|
|
] []
|
|
|
|
]
|
2022-02-04 01:46:55 +00:00
|
|
|
, h3 [] [ text (.name (moduleInfo mod)) ]
|
|
|
|
, Html.map never (p [] (.desc (moduleInfo mod)))
|
2022-02-02 23:27:11 +00:00
|
|
|
]
|
2022-02-01 22:33:58 +00:00
|
|
|
]
|
|
|
|
|
2022-02-05 23:55:21 +00:00
|
|
|
viewLicenseChooser : SelectedLicense -> Html Msg
|
|
|
|
viewLicenseChooser selected =
|
|
|
|
div
|
|
|
|
[ id "license-chooser" ]
|
|
|
|
[ selected
|
|
|
|
|> selectedInfo
|
|
|
|
|> viewLicenseInfo
|
|
|
|
|> Html.map never
|
|
|
|
, div [ id "available-licenses" ]
|
|
|
|
( availableLicenses
|
|
|
|
|> List.map (selectableLicense selected)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
|
|
|
|
viewLicenseInfo : License.LicenseDescriptors -> Html Never
|
|
|
|
viewLicenseInfo info =
|
|
|
|
div [ id "selected-license" ]
|
|
|
|
[ h2 [] [text info.name]
|
|
|
|
, p [] [text info.desc]
|
|
|
|
]
|
|
|
|
|
|
|
|
selectableLicense : SelectedLicense -> SelectedLicense -> Html Msg
|
|
|
|
selectableLicense currentlySelected license =
|
|
|
|
button
|
|
|
|
( [ onClick (SwitchLicense license)
|
|
|
|
, class "selectable-license"
|
|
|
|
]
|
|
|
|
++ if currentlySelected == license then [class "active"] else []
|
|
|
|
)
|
|
|
|
[ span []
|
|
|
|
[ text (.slug (selectedInfo license))
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
2022-02-04 01:46:55 +00:00
|
|
|
view_modules : ModuleWrapper moduleType -> License moduleType -> Html Msg
|
|
|
|
view_modules wrap license =
|
2022-02-03 00:51:31 +00:00
|
|
|
section [id "modules"] (
|
2022-02-04 01:46:55 +00:00
|
|
|
license.info.availableModules
|
|
|
|
|> List.map (view_module_button wrap license.info.moduleInfo license.activeModules)
|
2022-02-01 22:33:58 +00:00
|
|
|
)
|
2022-02-03 00:51:31 +00:00
|
|
|
|
|
|
|
view_cooler_button : String -> msg -> Html msg
|
|
|
|
view_cooler_button name message =
|
2022-02-05 23:56:00 +00:00
|
|
|
button
|
2022-02-03 00:51:31 +00:00
|
|
|
[ class "cool-button"
|
|
|
|
, onClick message
|
|
|
|
]
|
|
|
|
[ div
|
|
|
|
[ class "bevel"
|
|
|
|
, class "tr"
|
|
|
|
, attribute "aria-hidden" "true"
|
|
|
|
] []
|
|
|
|
, div [] [ text name ]
|
|
|
|
, div
|
|
|
|
[ class "bevel"
|
|
|
|
, class "bl"
|
|
|
|
, attribute "aria-hidden" "true"
|
|
|
|
] []
|
|
|
|
]
|
|
|
|
|
|
|
|
view_download_button : (String, DownloadType) -> Html Msg
|
|
|
|
view_download_button (name, dtype) =
|
|
|
|
view_cooler_button name (Download dtype)
|
|
|
|
|
|
|
|
downloads : Html Msg
|
|
|
|
downloads =
|
|
|
|
section [id "downloads"]
|
|
|
|
( List.map view_download_button
|
|
|
|
[ ("Markdown", Markdown)
|
2022-02-06 15:58:13 +00:00
|
|
|
--, ("Plaintext", Plain)
|
|
|
|
--, ("HTML", Html)
|
2022-02-03 00:51:31 +00:00
|
|
|
]
|
|
|
|
)
|
|
|
|
|
2022-02-06 00:20:09 +00:00
|
|
|
divider : String -> Html Never
|
|
|
|
divider sectionName =
|
|
|
|
div [class "divider"]
|
|
|
|
[ div [] []
|
|
|
|
, h3 [] [text sectionName]
|
|
|
|
, div [] []
|
|
|
|
]
|
2022-02-03 00:51:31 +00:00
|
|
|
|
|
|
|
view : Model -> Html Msg
|
|
|
|
view model =
|
|
|
|
div [id "elm-area"]
|
2022-02-05 23:55:21 +00:00
|
|
|
[ viewLicenseChooser model.selected
|
2022-02-06 00:20:09 +00:00
|
|
|
, Html.map never (divider "Customize")
|
2022-02-05 23:55:21 +00:00
|
|
|
, case model.selected of
|
2022-02-04 01:46:55 +00:00
|
|
|
Hippocratic -> view_modules HippocraticMod model.hippocratic
|
|
|
|
NPL -> view_modules NPLMod model.npl
|
2022-02-06 00:20:09 +00:00
|
|
|
, Html.map never (divider "Download")
|
2022-02-03 00:51:31 +00:00
|
|
|
, downloads
|
|
|
|
]
|