From c6b7c338d0b8a0fa38fe87940510ab3cd592baf8 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Mon, 16 Nov 2020 12:35:33 -0500 Subject: [PATCH] add Switch Info page --- backend/src/api/webmention.rs | 2 ++ sina/src/Main.elm | 4 +++ sina/src/Mi/Switch.elm | 2 +- sina/src/Page.elm | 60 +++++++++++++++++++++++++++++++++++ sina/src/Page/SwitchInfo.elm | 54 +++++++++++++++++++++++++++++++ sina/src/Page/Switches.elm | 59 ++++------------------------------ 6 files changed, 127 insertions(+), 54 deletions(-) create mode 100644 sina/src/Page.elm create mode 100644 sina/src/Page/SwitchInfo.elm diff --git a/backend/src/api/webmention.rs b/backend/src/api/webmention.rs index da0cfc6..33efd19 100644 --- a/backend/src/api/webmention.rs +++ b/backend/src/api/webmention.rs @@ -2,6 +2,7 @@ use super::{Error, Result}; use crate::{models, paseto, schema, web::discord_webhook::Client as DiscordWebhook, MainDatabase}; use diesel::prelude::*; use rocket::{ + http::Status, request::Form, response::{self, Responder}, Request, Response, State, @@ -66,6 +67,7 @@ impl<'a> Responder<'a> for models::WebMention { "Location", format!("https://mi.christine.website/api/webmention/{}", self.id), ) + .status(Status::Created) .ok() } } diff --git a/sina/src/Main.elm b/sina/src/Main.elm index 2ef9b96..5cb1df4 100644 --- a/sina/src/Main.elm +++ b/sina/src/Main.elm @@ -14,6 +14,7 @@ import Mi.WebMention import Model exposing (Model, Msg(..), init) import Page.Index import Page.Login +import Page.SwitchInfo import Page.Switches import Route exposing (Route(..), routeParser) import Url @@ -143,6 +144,9 @@ view model = SwitchLog -> Page.Switches.view model + SwitchID _ -> + Page.SwitchInfo.view model + _ -> Layout.template "Oh noes" [ p [] [ text "todo: implement this 404 page" ] ] diff --git a/sina/src/Mi/Switch.elm b/sina/src/Mi/Switch.elm index fa1ffb7..55e4c46 100644 --- a/sina/src/Mi/Switch.elm +++ b/sina/src/Mi/Switch.elm @@ -37,7 +37,7 @@ switchURL = idURL : String -> String idURL id = UB.absolute - [ "api", "switches", "id", id ] + [ "api", "switches", id ] [] diff --git a/sina/src/Page.elm b/sina/src/Page.elm new file mode 100644 index 0000000..0ff4cee --- /dev/null +++ b/sina/src/Page.elm @@ -0,0 +1,60 @@ +module Page exposing (format) + +import Html exposing (Html, span, text) +import Time exposing (Month(..), Posix, utc) + + +formatMonth : Month -> String +formatMonth month = + case month of + Jan -> + "Jan" + + Feb -> + "Feb" + + Mar -> + "Mar" + + Apr -> + "Apr" + + May -> + "May" + + Jun -> + "Jun" + + Jul -> + "Jul" + + Aug -> + "Aug" + + Sep -> + "Sep" + + Oct -> + "Oct" + + Nov -> + "Nov" + + Dec -> + "Dec" + + +format : Posix -> Html msg +format time = + span + [] + [ text <| String.pad 2 '0' <| String.fromInt <| Time.toHour utc time + , text ":" + , text <| String.pad 2 '0' <| String.fromInt <| Time.toMinute utc time + , text " " + , text <| formatMonth <| Time.toMonth utc time + , text " " + , text <| String.pad 2 '0' <| String.fromInt <| Time.toDay utc time + , text " " + , text <| String.fromInt <| Time.toYear utc time + ] diff --git a/sina/src/Page/SwitchInfo.elm b/sina/src/Page/SwitchInfo.elm new file mode 100644 index 0000000..ead9d6e --- /dev/null +++ b/sina/src/Page/SwitchInfo.elm @@ -0,0 +1,54 @@ +module Page.SwitchInfo exposing (view) + +import Browser exposing (Document) +import Browser.Navigation as Nav +import Html exposing (a, br, button, h2, img, p, span, table, td, text, th, tr) +import Html.Attributes exposing (href, src, style) +import Html.Events exposing (onClick) +import Layout exposing (template) +import Model exposing (Model, Msg(..)) +import Page exposing (format) +import Time exposing (Month(..), utc) + + +view : Model -> Document Msg +view { switchByID } = + case switchByID of + Nothing -> + template "Loading" [ text "Please wait..." ] + + Just switch -> + let + title = + "Switch Details" + + ended_at = + case switch.ended_at of + Nothing -> + span [] [] + + Just time -> + span [] + [ text "Ended at: " + , format + time + , br [] [] + ] + in + template title + [ p + [] + [ img [ src switch.img_url ] [] + , br [] [] + , text "ID: " + , text switch.id + , br [] [] + , text "Name: " + , text switch.who + , br [] [] + , text "Started At: " + , format switch.started_at + , br [] [] + , ended_at + ] + ] diff --git a/sina/src/Page/Switches.elm b/sina/src/Page/Switches.elm index 5b905ad..b4fd3dc 100644 --- a/sina/src/Page/Switches.elm +++ b/sina/src/Page/Switches.elm @@ -7,6 +7,7 @@ import Html.Events exposing (onClick) import Iso8601 import Layout exposing (template) import Model exposing (Model, Msg(..)) +import Page exposing (format) import Time exposing (Month(..), utc) @@ -43,58 +44,6 @@ view { front, switches, switchPage } = , th [] [ text "End" ] ] - formatMonth month = - case month of - Jan -> - "Jan" - - Feb -> - "Feb" - - Mar -> - "Mar" - - Apr -> - "Apr" - - May -> - "May" - - Jun -> - "Jun" - - Jul -> - "Jul" - - Aug -> - "Aug" - - Sep -> - "Sep" - - Oct -> - "Oct" - - Nov -> - "Nov" - - Dec -> - "Dec" - - format time = - span - [] - [ text <| String.pad 2 '0' <| String.fromInt <| Time.toHour utc time - , text ":" - , text <| String.pad 2 '0' <| String.fromInt <| Time.toMinute utc time - , text " " - , text <| formatMonth <| Time.toMonth utc time - , text " " - , text <| String.pad 2 '0' <| String.fromInt <| Time.toDay utc time - , text " " - , text <| String.fromInt <| Time.toYear utc time - ] - rowify data = let ended_at = @@ -108,7 +57,11 @@ view { front, switches, switchPage } = tr [] [ td [] [ img [ src data.img_url, width 16, height 16 ] [] ] - , td [] [ a [ href <| "/switches/" ++ data.id ] [ text <| String.slice 0 10 data.id ] ] + , td [] + [ a + [ href <| "/switches/" ++ data.id, onClick <| FetchSwitch data.id ] + [ text <| String.slice 0 10 data.id ] + ] , td [] [ text data.who ] , td [] [ format data.started_at ] , td [] [ ended_at ]