add Switch Info page

This commit is contained in:
Cadey Ratio 2020-11-16 12:35:33 -05:00
parent aed355d920
commit c6b7c338d0
6 changed files with 127 additions and 54 deletions

View File

@ -2,6 +2,7 @@ use super::{Error, Result};
use crate::{models, paseto, schema, web::discord_webhook::Client as DiscordWebhook, MainDatabase}; use crate::{models, paseto, schema, web::discord_webhook::Client as DiscordWebhook, MainDatabase};
use diesel::prelude::*; use diesel::prelude::*;
use rocket::{ use rocket::{
http::Status,
request::Form, request::Form,
response::{self, Responder}, response::{self, Responder},
Request, Response, State, Request, Response, State,
@ -66,6 +67,7 @@ impl<'a> Responder<'a> for models::WebMention {
"Location", "Location",
format!("https://mi.christine.website/api/webmention/{}", self.id), format!("https://mi.christine.website/api/webmention/{}", self.id),
) )
.status(Status::Created)
.ok() .ok()
} }
} }

View File

@ -14,6 +14,7 @@ import Mi.WebMention
import Model exposing (Model, Msg(..), init) import Model exposing (Model, Msg(..), init)
import Page.Index import Page.Index
import Page.Login import Page.Login
import Page.SwitchInfo
import Page.Switches import Page.Switches
import Route exposing (Route(..), routeParser) import Route exposing (Route(..), routeParser)
import Url import Url
@ -143,6 +144,9 @@ view model =
SwitchLog -> SwitchLog ->
Page.Switches.view model Page.Switches.view model
SwitchID _ ->
Page.SwitchInfo.view model
_ -> _ ->
Layout.template "Oh noes" [ p [] [ text "todo: implement this 404 page" ] ] Layout.template "Oh noes" [ p [] [ text "todo: implement this 404 page" ] ]

View File

@ -37,7 +37,7 @@ switchURL =
idURL : String -> String idURL : String -> String
idURL id = idURL id =
UB.absolute UB.absolute
[ "api", "switches", "id", id ] [ "api", "switches", id ]
[] []

60
sina/src/Page.elm Normal file
View File

@ -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
]

View File

@ -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
]
]

View File

@ -7,6 +7,7 @@ import Html.Events exposing (onClick)
import Iso8601 import Iso8601
import Layout exposing (template) import Layout exposing (template)
import Model exposing (Model, Msg(..)) import Model exposing (Model, Msg(..))
import Page exposing (format)
import Time exposing (Month(..), utc) import Time exposing (Month(..), utc)
@ -43,58 +44,6 @@ view { front, switches, switchPage } =
, th [] [ text "End" ] , 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 = rowify data =
let let
ended_at = ended_at =
@ -108,7 +57,11 @@ view { front, switches, switchPage } =
tr tr
[] []
[ td [] [ img [ src data.img_url, width 16, height 16 ] [] ] [ 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 [] [ text data.who ]
, td [] [ format data.started_at ] , td [] [ format data.started_at ]
, td [] [ ended_at ] , td [] [ ended_at ]