File Display size
This commit is contained in:
5
Modules/Website/CMakeLists.txt
Normal file
5
Modules/Website/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
add_custom_target(Website
|
||||||
|
ALL
|
||||||
|
elm make --optimize --output=${CMAKE_CURRENT_BINARY_DIR}/index.html src/Main.elm
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
14379
Modules/Website/index.html
Normal file
14379
Modules/Website/index.html
Normal file
File diff suppressed because it is too large
Load Diff
@@ -7,17 +7,25 @@ import Element.Font as Font
|
|||||||
import Element.Input as Input
|
import Element.Input as Input
|
||||||
import Element.Region as Region
|
import Element.Region as Region
|
||||||
import Http
|
import Http
|
||||||
import MainPage exposing (Msg)
|
import Json.Decode exposing (Decoder, int, list, string, succeed)
|
||||||
|
import Json.Decode.Pipeline exposing (required)
|
||||||
|
import String exposing (left)
|
||||||
|
import Debug exposing (toString)
|
||||||
|
|
||||||
|
|
||||||
type alias File =
|
type alias File =
|
||||||
{ name : String
|
{ name : String
|
||||||
|
, file_name : String
|
||||||
, source : String
|
, source : String
|
||||||
, id : Int
|
, id : Int
|
||||||
, status : String
|
, status : String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type alias FilesResponse =
|
||||||
|
{ queue : List File }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Model --
|
-- Model --
|
||||||
|
|
||||||
@@ -25,41 +33,147 @@ type alias File =
|
|||||||
type alias Model =
|
type alias Model =
|
||||||
{ files : List File
|
{ files : List File
|
||||||
, filter : String
|
, filter : String
|
||||||
|
, error : Maybe String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
initModel : Model
|
initModel : Model
|
||||||
initModel =
|
initModel =
|
||||||
{ files = []
|
{ files =
|
||||||
|
[]
|
||||||
, filter = ""
|
, filter = ""
|
||||||
|
, error = Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
init : ( Model, Cmd Msg )
|
||||||
|
init =
|
||||||
|
( initModel, queryFiles )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Messages --
|
-- Messages --
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= Reload
|
= Reload
|
||||||
|
| QueryRequestResult (Result Http.Error FilesResponse)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- | QueryRequestResult (Result Http.Error _)
|
|
||||||
-- Request --
|
-- Request --
|
||||||
|
|
||||||
|
|
||||||
|
fileDecoder : Decoder File
|
||||||
|
fileDecoder =
|
||||||
|
succeed File
|
||||||
|
|> required "name" string
|
||||||
|
|> required "file_name" string
|
||||||
|
|> required "source" string
|
||||||
|
|> required "id" int
|
||||||
|
|> required "status" string
|
||||||
|
|
||||||
|
|
||||||
|
queueDecoder : Decoder FilesResponse
|
||||||
|
queueDecoder =
|
||||||
|
succeed FilesResponse
|
||||||
|
|> required "queue" (list fileDecoder)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Update --
|
-- Update --
|
||||||
|
|
||||||
|
|
||||||
update : Msg -> Model -> ( Model, Cmd Msg )
|
update : Msg -> Model -> ( Model, Cmd Msg )
|
||||||
update msg model =
|
update msg model =
|
||||||
case msg of
|
case msg of
|
||||||
|
QueryRequestResult (Ok res) ->
|
||||||
|
( { model | files = res.queue }, Cmd.none )
|
||||||
|
|
||||||
|
QueryRequestResult (Err (Http.BadBody er)) ->
|
||||||
|
( { model | error = Just er }, Cmd.none )
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
( model, Cmd.none )
|
( model, Cmd.none )
|
||||||
|
|
||||||
|
|
||||||
|
queryFiles : Cmd Msg
|
||||||
|
queryFiles =
|
||||||
|
Http.get
|
||||||
|
{ url = "http://127.0.0.1/api/files"
|
||||||
|
, expect = Http.expectJson QueryRequestResult queueDecoder
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- View --
|
-- View --
|
||||||
|
|
||||||
|
|
||||||
|
shadow : Attr decorative msg
|
||||||
|
shadow =
|
||||||
|
Border.shadow
|
||||||
|
{ offset = ( 2, 2 )
|
||||||
|
, size = 2
|
||||||
|
, blur = 2
|
||||||
|
, color = rgb 0.5 0.5 0.5
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
viewFile : File -> Element Msg
|
||||||
|
viewFile file =
|
||||||
|
el
|
||||||
|
[ width fill
|
||||||
|
, Background.color (rgb 0.8 0.8 0.8)
|
||||||
|
, padding 10
|
||||||
|
, Border.rounded 3
|
||||||
|
, shadow
|
||||||
|
, height (px 110)
|
||||||
|
]
|
||||||
|
(Element.column
|
||||||
|
[ width fill
|
||||||
|
, spacing 6
|
||||||
|
]
|
||||||
|
[ Element.row
|
||||||
|
[ width fill ]
|
||||||
|
[ el
|
||||||
|
[ Region.heading 1
|
||||||
|
, alignLeft
|
||||||
|
, Font.size 24
|
||||||
|
]
|
||||||
|
(text file.name)
|
||||||
|
, el
|
||||||
|
[ Region.heading 1
|
||||||
|
, alignRight
|
||||||
|
, Font.color (rgba 0 0 0 0.6)
|
||||||
|
, Font.size 20
|
||||||
|
]
|
||||||
|
(text (String.concat [ "[", file.status, "]" ]))
|
||||||
|
]
|
||||||
|
, el
|
||||||
|
[ Region.heading 2
|
||||||
|
, Font.size 16
|
||||||
|
, spacingXY 0 10
|
||||||
|
]
|
||||||
|
(text (String.concat ["File name: ", file.file_name]))
|
||||||
|
,el
|
||||||
|
[ Region.heading 2
|
||||||
|
, Font.size 16
|
||||||
|
]
|
||||||
|
(text (String.concat ["Source: ", file.source]))
|
||||||
|
, download
|
||||||
|
[ Region.footer
|
||||||
|
, Font.color (rgb 0 0 0.8)
|
||||||
|
, Font.size 16
|
||||||
|
, alignBottom
|
||||||
|
, alignRight
|
||||||
|
]
|
||||||
|
{ url = String.concat ["http://127.0.0.1/api/file/", toString file.id ]
|
||||||
|
, label = text "Download"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Element Msg
|
view : Model -> Element Msg
|
||||||
view model =
|
view model =
|
||||||
Element.column
|
Element.column
|
||||||
@@ -71,8 +185,24 @@ view model =
|
|||||||
]
|
]
|
||||||
[ el
|
[ el
|
||||||
[ Region.heading 1
|
[ Region.heading 1
|
||||||
|
, width fill
|
||||||
, alignLeft
|
, alignLeft
|
||||||
, Font.size 36
|
, Font.size 36
|
||||||
]
|
]
|
||||||
(text "Files")
|
(text "Files")
|
||||||
|
, case model.error of
|
||||||
|
Just e ->
|
||||||
|
el
|
||||||
|
[ Font.color (rgb 1 0 0)
|
||||||
|
, Font.size 16
|
||||||
|
]
|
||||||
|
(text e)
|
||||||
|
|
||||||
|
Nothing ->
|
||||||
|
Element.column
|
||||||
|
[ width fill
|
||||||
|
, centerX
|
||||||
|
, spacing 10
|
||||||
|
]
|
||||||
|
(List.map viewFile model.files)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ initCurrentPage ( model, existingCmds ) =
|
|||||||
Route.Files ->
|
Route.Files ->
|
||||||
let
|
let
|
||||||
( pageModel, pageCmd ) =
|
( pageModel, pageCmd ) =
|
||||||
( Files.initModel, Cmd.none )
|
Files.init
|
||||||
in
|
in
|
||||||
( FilesPage pageModel, Cmd.map FilesPageMsg pageCmd )
|
( FilesPage pageModel, Cmd.map FilesPageMsg pageCmd )
|
||||||
in
|
in
|
||||||
|
|||||||
Reference in New Issue
Block a user