Skip to content

Instantly share code, notes, and snippets.

@gergely-marko
Created March 6, 2018 07:00
Show Gist options
  • Save gergely-marko/267b2688034f697a5ad0fb0dc10c6be0 to your computer and use it in GitHub Desktop.
Save gergely-marko/267b2688034f697a5ad0fb0dc10c6be0 to your computer and use it in GitHub Desktop.
General report helper functions
module Report exposing (..)
import Date exposing (Date)
import Helpers
import Html.String as Html exposing (Html, b, br, div, h1, h2, h3, img, table, td, text, th, tr)
import Html.String.Attributes exposing (..)
import Localization
import Location exposing (Location)
import Position exposing (Position)
import Project exposing (Project)
import Sample exposing (CoreSample)
import Style
page : List (Html msg) -> Html msg
page components =
div
[ class "page" ]
components
header : Html msg
header =
div
[ class "header" ]
[ div
[ class "strong-border-bottom" ]
[ img [ src "img/report_header.jpg", style [ ( "width", "100%" ) ] ] [] ]
, h3 [] [ text "A NAT által NAT-1-157/2013 számon akkreditált vizsgálólaboratórium" ]
]
measurement_header : Project -> Location -> Position -> CoreSample -> Maybe ( String, String ) -> Html msg
measurement_header project location position core_sample layer_info =
header_table <|
List.concat
[ [ measurement_top_header_row ]
, project_header_rows project
, core_sample_header_rows location position core_sample layer_info
]
investigation_header : Project -> Location -> Position -> CoreSample -> Int -> Maybe ( String, String ) -> Html msg
investigation_header project location position core_sample report_index layer_info =
header_table <|
List.concat
[ [ investigation_top_header_row report_index project.header.code ]
, project_header_rows project
, core_sample_header_rows location position core_sample layer_info
]
measurement_title : List String -> Html msg
measurement_title rows =
h2 [] <| measurement_title_helper rows []
measurement_title_helper : List String -> List (Html msg) -> List (Html msg)
measurement_title_helper rows acc =
case rows of
[] ->
acc
row :: [] ->
measurement_title_helper []
(acc ++ [ text row ])
row :: tail ->
measurement_title_helper tail
(acc ++ [ text row, br [] [] ])
header_table : List (Html msg) -> Html msg
header_table rows =
table
[ class "strong-border full-width" ]
rows
header_row : ( String, String ) -> ( String, String ) -> Html msg
header_row ( label1, value1 ) ( label2, value2 ) =
tr
[]
[ td
[ class "light-border-bottom" ]
[ text label1 ]
, td
[ class "light-border-bottom light-border-right" ]
[ b [] [ text value1 ] ]
, td
[ class "light-border-bottom" ]
[ text label2 ]
, td
[ class "light-border-bottom" ]
[ b [] [ text value2 ] ]
]
project_header_rows : Project -> List (Html msg)
project_header_rows project =
[ header_row ( "Projekt:", project.header.name ) ( "Azonosító:", project.header.code )
, header_row ( "Megrendelő:", project.header.partner ) ( "Azonosító a megrendelőnél:", project.header.code_at_partner )
]
core_sample_header_rows : Location -> Position -> Sample.CoreSample -> Maybe ( String, String ) -> List (Html msg)
core_sample_header_rows location position core_sample layer_info =
[ layer_info
|> Maybe.map
(\( layer_id, layer_name ) ->
String.join ", " [ "Fúrt minta", layer_id ++ ". réteg", layer_name ]
)
|> Maybe.withDefault "Fúrt minta"
|> (\sample_description ->
header_row ( "Minta megnevezése:", sample_description ) ( "Érkezési naplószám:", core_sample.recorded_with_id )
)
, tr []
[ td
[ class "nowrap" ]
[ text "Mintavétel helye:" ]
, td
[ class "light-border-right" ]
[ b []
[ text <|
String.concat
[ location.name
, if String.length location.description > 0 then
" (" ++ location.description ++ ")"
else
""
]
]
]
, td
[ class "light-border-bottom nowrap" ]
[ text "Mintavétel dátuma:" ]
, td
[ class "light-border-bottom nowrap" ]
[ b [] [ text <| Style.format_date_only core_sample.sampled_at ] ]
]
, tr []
[ td [ class "light-border-bottom" ] []
, td
[ class "light-border-bottom light-border-right" ]
[ b []
[ text <|
case position of
Position.SimplePosition p ->
p.description
Position.RoadSection p ->
String.concat
[ Helpers.format_section p.section
, ", "
, Position.localize_side p.side
, ", "
, Position.localize_lane p.lane True
, ", "
, Position.localize_position_inside_lane p.position_inside_lane True
]
]
]
, td
[ class "light-border-bottom nowrap" ]
[ text "Érkezés dátuma:" ]
, td
[ class "nowrap" ]
[ b [] [ text <| Style.format_date_only core_sample.recorded_at ] ]
]
]
measurement_top_header_row : Html msg
measurement_top_header_row =
tr []
[ td
[ colspan 4
, class "light-border-bottom report-title"
]
[ text Localization.measurement_report ]
]
investigation_top_header_row : Int -> String -> Html msg
investigation_top_header_row report_index project_code =
tr []
[ td
[ colspan 2
, class "light-border-bottom light-border-right report-title"
]
[ text Localization.investigation_report ]
, td
[ class "light-border-bottom" ]
[ text <| "Jegyzőkönyv azonosító:" ]
, td
[ class "light-border-bottom report-id" ]
[ text <| Helpers.format_report_index project_code report_index ]
]
comment_block : String -> Html msg
comment_block comment =
table
[ class "full-width" ]
[ tr
[]
[ td
[]
[ text <| "Megjegyzés a vizsgálattal kapcsolatban: "
, b [] [ text comment ]
]
]
]
measurement_footer : Date -> String -> String -> Int -> Int -> Html msg
measurement_footer measured_at measured_by verified_by page_number page_count =
footer measured_at measured_by verified_by "Vizsgálatot végezte" "Ellenőrizte" page_number page_count
investigation_footer : Date -> String -> String -> Int -> Int -> Html msg
investigation_footer measured_at measured_by leader page_number page_count =
footer measured_at measured_by leader "Vizsgálatot végezte" Localization.leader page_number page_count
footer : Date -> String -> String -> String -> String -> Int -> Int -> Html msg
footer measured_at first_signer_name second_signer_name first_signer_role second_signer_role page_number page_count =
div
[ class "footer" ]
(List.concat
[ if page_number == page_count then
[ table
[ class "full-width" ]
[ tr
[]
[ td
[ colspan 2 ]
[ text <| "Budapest, " ++ Style.format_date_only measured_at ]
]
, tr
[]
[ td
[]
[ div
[ class "sign-div" ]
[ text first_signer_role
, br [] []
, text first_signer_name
]
]
, td
[]
[ div
[ class "sign-div" ]
[ text second_signer_role
, br [] []
, text second_signer_name
]
]
]
]
]
else
[]
, [ footer_box page_number page_count ]
]
)
footer_box : Int -> Int -> Html msg
footer_box page_number page_count =
table
[ class "full-width strong-border" ]
[ tr
[]
[ td
[ style [ ( "text-align", "left" ), ( "padding", "1mm" ) ] ]
[ text "Az eredmények csak a vizsgált egyedekre vonatkoznak."
]
, td
[ style [ ( "text-align", "right" ), ( "padding", "1mm" ) ] ]
[ text "oldal" ]
, td
[ style [ ( "text-align", "center" ), ( "padding", "0mm" ) ] ]
[ text "/" ]
, td
[ style [ ( "text-align", "left" ), ( "padding", "1mm" ) ] ]
[ text "összes" ]
]
, tr
[]
[ td
[ style [ ( "text-align", "left" ), ( "padding", "1mm" ) ] ]
[ text "A jegyzőkönyv csak teljes terjedelmében, a kibocsátó írásbeli hozzájárulásával másolható." ]
, td
[ style [ ( "text-align", "right" ), ( "padding", "1mm" ) ] ]
[ text <| toString page_number ]
, td
[ style [ ( "text-align", "center" ), ( "padding", "0mm" ) ] ]
[ text "/" ]
, td
[ style [ ( "text-align", "left" ), ( "padding", "1mm" ) ] ]
[ text <| toString page_count ]
]
]
-- Table helpers ------------------------------------------------------------------------------------------------------
first_row : List { data | code : String } -> String -> List (Html msg)
first_row disc_data label =
[ tr [] <|
List.concat
[ [ th [ class "strong-border-bottom", colspan 3 ] [ text label ] ]
, List.map (\data -> th [ class "strong-border-bottom light-border-left" ] [ text data.code ]) disc_data
]
]
eq_row : List data -> String -> List (Html msg) -> String -> (data -> Html msg) -> String -> List (Html msg)
eq_row disc_data label eq unit map_data cell_class =
[ tr []
(List.concat
[ [ td [ class "light-border-bottom nowrap" ] [ text label ]
, td [ class "light-border-bottom eq-cell" ] eq
, td [ class "light-border-bottom unit-cell" ] [ text unit ]
]
, disc_data
|> List.map
(\data ->
td
[ class <| "light-border-bottom light-border-left numeric-cell " ++ cell_class ]
[ map_data data ]
)
]
)
]
eq_rows : List data -> String -> List (Html msg) -> String -> (data -> Html msg) -> String -> List (Html msg)
eq_rows disc_data label eq unit map_data cell_class =
[ tr []
(List.concat
[ [ td [ class "nowrap" ] [ text label ], td [ colspan 2 ] [] ]
, disc_data
|> List.map
(\data ->
td
[ class <| "light-border-bottom light-border-left numeric-cell " ++ cell_class, rowspan 2 ]
[ map_data data ]
)
]
)
, tr []
[ td [ class "light-border-bottom eq-cell", colspan 2 ] eq
, td [ class "light-border-bottom unit-cell" ] [ text unit ]
]
]
sum_row : List data -> String -> List (Html msg) -> String -> Html msg -> String -> List (Html msg)
sum_row disc_data label eq unit cell_value cell_class =
[ tr []
[ td [ class "nowrap" ] [ text label ]
, td [ colspan 2 ] []
, td
[ class <| "light-border-bottom light-border-left align-center " ++ cell_class, rowspan 2, colspan <| List.length disc_data ]
[ cell_value ]
]
, tr []
[ td [ class "light-border-bottom eq-cell", colspan 2 ] eq
, td [ class "light-border-bottom unit-cell" ] [ text unit ]
]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment