[frontend] commit all the things!!!!
This commit is contained in:
parent
c19a71eb2e
commit
90bbddf22d
5969
dist/bundle.js
vendored
Normal file
5969
dist/bundle.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
4
frontend/.gitignore
vendored
Normal file
4
frontend/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
node_modules/
|
||||
elm-stuff/
|
||||
bundle.js
|
||||
|
36
frontend/Makefile
Normal file
36
frontend/Makefile
Normal file
|
@ -0,0 +1,36 @@
|
|||
MAIN = src/Main.elm
|
||||
OUTJS = bundle.js
|
||||
|
||||
ELM = elm
|
||||
ELM_LIVE = elm-live
|
||||
ELMFLAGS =
|
||||
|
||||
.PHONY: default help clean clean-gitignore live
|
||||
|
||||
default: help
|
||||
|
||||
# -- END-USER RELEVANT -- #
|
||||
|
||||
build: $(OUTJS) ## Compiles the app.
|
||||
|
||||
# -- DEV TARGETS -- #
|
||||
|
||||
live: ## Runs an elm-live server for development.
|
||||
$(ELM_LIVE) $(MAIN) -- $(ELMFLAGS)
|
||||
|
||||
# -- THE TARGETS THAT ACTUALLY DO STUFF -- #
|
||||
|
||||
$(OUTJS): $(shell find src)
|
||||
$(ELM) make $(ELMFLAGS) $(MAIN) --output $(OUTJS)
|
||||
|
||||
# -- HELPERS -- #
|
||||
|
||||
help: # stolen from marmelab.com/blog/2016/02/29/auto-documented-makefile.html
|
||||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "%-10s %s\n", $$1, $$2}'
|
||||
|
||||
clean: ## Cleans generated files
|
||||
rm -rf elm-stuff/build-artifacts/
|
||||
rm -f $(OUTJS)
|
||||
|
||||
clean-all: clean-gitignore ## Cleans everything, including downloaded dependencies
|
||||
rm -rf $$(cat ./.gitignore | grep -v '^#')
|
9
frontend/README.md
Normal file
9
frontend/README.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
# front-end
|
||||
|
||||
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/evilham/prometheus-adlermanager/issues)
|
||||
|
||||
# Development Quick-Start
|
||||
|
||||
Requires `elm`. See [its docs](https://guide.elm-lang.org/install.html) for installation instructions.
|
||||
|
||||
`make run` will install dependencies and build the front-end. The result is a pile of static files.
|
30
frontend/elm.json
Normal file
30
frontend/elm.json
Normal file
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"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/http": "2.0.0",
|
||||
"elm/time": "1.0.0",
|
||||
"justinmimbs/time-extra": "1.1.0"
|
||||
},
|
||||
"indirect": {
|
||||
"elm/bytes": "1.0.7",
|
||||
"elm/file": "1.0.1",
|
||||
"elm/json": "1.1.2",
|
||||
"elm/parser": "1.1.0",
|
||||
"elm/url": "1.0.0",
|
||||
"elm/virtual-dom": "1.0.2",
|
||||
"justinmimbs/date": "3.1.2"
|
||||
}
|
||||
},
|
||||
"test-dependencies": {
|
||||
"direct": {},
|
||||
"indirect": {}
|
||||
}
|
||||
}
|
5988
frontend/index.html
Normal file
5988
frontend/index.html
Normal file
File diff suppressed because it is too large
Load diff
4
frontend/notes.txt
Normal file
4
frontend/notes.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
TODO:
|
||||
|
||||
- [ ] production build: like https://github.com/rtfeldman/elm-spa-example
|
||||
- [ ] think about server-side rendering
|
3
frontend/src/Config.elm
Normal file
3
frontend/src/Config.elm
Normal file
|
@ -0,0 +1,3 @@
|
|||
module Config exposing (..)
|
||||
|
||||
api_url = "/api"
|
15
frontend/src/Main.elm
Normal file
15
frontend/src/Main.elm
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Main exposing (main)
|
||||
|
||||
import Browser
|
||||
|
||||
import Model
|
||||
import Update
|
||||
import View
|
||||
import Subscriptions
|
||||
|
||||
main = Browser.document
|
||||
{ init = \flags -> (Model.init flags, Update.init)
|
||||
, update = Update.update
|
||||
, view = View.view
|
||||
, subscriptions = Subscriptions.subscriptions
|
||||
}
|
27
frontend/src/Model.elm
Normal file
27
frontend/src/Model.elm
Normal file
|
@ -0,0 +1,27 @@
|
|||
module Model exposing (Model, Msg(..), init)
|
||||
|
||||
import Http
|
||||
import Time
|
||||
|
||||
import Utils
|
||||
|
||||
type alias Model =
|
||||
{ loading : Bool
|
||||
, data : List String
|
||||
, now : Time.Posix
|
||||
, err : Maybe Http.Error
|
||||
}
|
||||
|
||||
type Msg = NewData (Result Http.Error (List String))
|
||||
| NewNow Time.Posix
|
||||
| RefreshWanted
|
||||
|
||||
-- INIT --
|
||||
|
||||
init : () -> Model
|
||||
init flags =
|
||||
{ loading = True
|
||||
, data = []
|
||||
, now = Utils.time_0
|
||||
, err = Nothing
|
||||
}
|
10
frontend/src/Subscriptions.elm
Normal file
10
frontend/src/Subscriptions.elm
Normal file
|
@ -0,0 +1,10 @@
|
|||
module Subscriptions exposing (subscriptions)
|
||||
|
||||
import Time
|
||||
|
||||
import Model exposing (Model, Msg(..))
|
||||
|
||||
subscriptions : Model -> Sub Msg
|
||||
subscriptions model = Sub.batch
|
||||
[ Time.every (30*1000) (always RefreshWanted)
|
||||
]
|
31
frontend/src/Update.elm
Normal file
31
frontend/src/Update.elm
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Update exposing (update, init)
|
||||
|
||||
import Task
|
||||
import Time
|
||||
|
||||
import Model exposing (Model, Msg(..))
|
||||
|
||||
update : Msg -> Model -> (Model, Cmd Msg)
|
||||
update msg model =
|
||||
case msg of
|
||||
NewData (Ok new) -> ({model | err = Nothing, data = new}, Cmd.none)
|
||||
NewData (Err err) -> ({model | err = Just err}, Cmd.none)
|
||||
NewNow date -> ({model | now = date}, Cmd.none)
|
||||
RefreshWanted -> ( model, refresh )
|
||||
|
||||
-- COMMANDS --
|
||||
|
||||
-- get_data : Cmd Msg
|
||||
-- get_data = Http.send NewData Tw.get_request
|
||||
|
||||
get_now : Cmd Msg
|
||||
get_now = Task.perform NewNow Time.now
|
||||
|
||||
refresh : Cmd Msg
|
||||
refresh = Cmd.batch [get_now]
|
||||
-- refresh = Cmd.batch [get_now, get_data]
|
||||
|
||||
-- INIT --
|
||||
|
||||
init : Cmd Msg
|
||||
init = refresh
|
13
frontend/src/Utils.elm
Normal file
13
frontend/src/Utils.elm
Normal file
|
@ -0,0 +1,13 @@
|
|||
module Utils exposing (..)
|
||||
|
||||
import Time exposing (Month(..), utc)
|
||||
import Time.Extra as Time
|
||||
|
||||
time_0 : Time.Posix
|
||||
time_0 = Time.Parts 1970 Jan 1 0 0 0 0 |> Time.partsToPosix utc
|
||||
|
||||
time_inf : Time.Posix -- TODO update by 2038 ;-)
|
||||
time_inf = Time.Parts 2038 Jan 1 0 0 0 0 |> Time.partsToPosix utc
|
||||
|
||||
just_time : Maybe Time.Posix -> Time.Posix
|
||||
just_time = Maybe.withDefault time_0
|
12
frontend/src/View.elm
Normal file
12
frontend/src/View.elm
Normal file
|
@ -0,0 +1,12 @@
|
|||
module View exposing (view)
|
||||
|
||||
import Browser
|
||||
import Html exposing (text)
|
||||
|
||||
import Model exposing (Model, Msg(..))
|
||||
|
||||
view : Model -> Browser.Document Msg
|
||||
view model =
|
||||
{ title = "Hello World"
|
||||
, body = [text "hello", text "world"]
|
||||
}
|
Loading…
Reference in a new issue