Skip to content

Commit

Permalink
[DSW-1691] Fix document template detail in registry
Browse files Browse the repository at this point in the history
  • Loading branch information
janslifka committed Feb 8, 2023
1 parent ec0f764 commit bb0b9b3
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 85 deletions.
20 changes: 13 additions & 7 deletions engine-registry/elm/Registry.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Registry exposing (Model, Msg, PageModel, main)

import Browser exposing (Document, UrlRequest)
import Browser.Navigation as Nav
import Browser.Navigation as Nav exposing (load)
import Gettext exposing (gettext)
import Html exposing (Html, a, div, img, li, text, ul)
import Html.Attributes exposing (class, classList, href, src)
Expand All @@ -11,6 +11,8 @@ import Json.Encode as E
import Registry.Common.AppState as AppState exposing (AppState)
import Registry.Common.Credentials as Credentials exposing (Credentials)
import Registry.Common.View.Page as Page
import Registry.Pages.DocumentTemplateDetail as TemplateDetail
import Registry.Pages.DocumentTemplates as Templates
import Registry.Pages.ForgottenToken as ForgottenToken
import Registry.Pages.ForgottenTokenConfirmation as ForgottenTokenConfirmation
import Registry.Pages.Index as Index
Expand All @@ -21,8 +23,6 @@ import Registry.Pages.Login as Login
import Registry.Pages.Organization as Organization
import Registry.Pages.Signup as Signup
import Registry.Pages.SignupConfirmation as SignupConfirmation
import Registry.Pages.TemplateDetail as TemplateDetail
import Registry.Pages.Templates as Templates
import Registry.Ports as Ports
import Registry.Routing as Routing
import Registry.Utils exposing (dispatch)
Expand Down Expand Up @@ -302,7 +302,7 @@ initChildModel model =
, Cmd.map SignupConfirmationMsg signupConfirmationCmd
)

Routing.Templates ->
Routing.DocumentTemplates ->
let
( templatesModel, templatesCmd ) =
Templates.init model.appState
Expand All @@ -311,7 +311,7 @@ initChildModel model =
, Cmd.map TemplatesMsg templatesCmd
)

Routing.TemplateDetail templateId ->
Routing.DocumentTemplateDetail templateId ->
let
( templateDetailModel, templateDetailCmd ) =
TemplateDetail.init model.appState templateId
Expand All @@ -338,6 +338,12 @@ initChildModel model =
, Cmd.map LocaleDetailMsg localeDetailCmd
)

Routing.DeprecatedTemplates ->
( model, load (Routing.toString Routing.DocumentTemplates) )

Routing.DeprecatedTemplateDetail templateId ->
( model, load (Routing.toString (Routing.DocumentTemplateDetail templateId)) )

Routing.NotFound ->
( { model | pageModel = NotFoundModel }
, Cmd.none
Expand Down Expand Up @@ -448,9 +454,9 @@ header model =
]
, li
[ class "nav-item"
, classList [ ( "active", model.route == Routing.Templates ) ]
, classList [ ( "active", model.route == Routing.DocumentTemplates ) ]
]
[ a [ href <| Routing.toString Routing.Templates, class "nav-link" ]
[ a [ href <| Routing.toString Routing.DocumentTemplates, class "nav-link" ]
[ text (gettext "Document Templates" appState.locale) ]
]
, li
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Registry.Common.Entities.Template exposing
( Template
module Registry.Common.Entities.DocumentTemplate exposing
( DocumentTemplate
, decoder
)

Expand All @@ -9,7 +9,7 @@ import Registry.Common.Entities.OrganizationInfo as OrganizationInfo exposing (O
import Version exposing (Version)


type alias Template =
type alias DocumentTemplate =
{ id : String
, name : String
, templateId : String
Expand All @@ -19,9 +19,9 @@ type alias Template =
}


decoder : Decoder Template
decoder : Decoder DocumentTemplate
decoder =
D.succeed Template
D.succeed DocumentTemplate
|> D.required "id" D.string
|> D.required "name" D.string
|> D.required "templateId" D.string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Registry.Common.Entities.TemplateDetail exposing
( TemplateDetail
module Registry.Common.Entities.DocumentTemplateDetail exposing
( DocumentTemplateDetail
, decoder
)

Expand All @@ -9,7 +9,7 @@ import Registry.Common.Entities.OrganizationInfo as OrganizationInfo exposing (O
import Version exposing (Version)


type alias TemplateDetail =
type alias DocumentTemplateDetail =
{ id : String
, name : String
, templateId : String
Expand All @@ -23,9 +23,9 @@ type alias TemplateDetail =
}


decoder : Decoder TemplateDetail
decoder : Decoder DocumentTemplateDetail
decoder =
D.succeed TemplateDetail
D.succeed DocumentTemplateDetail
|> D.required "id" D.string
|> D.required "name" D.string
|> D.required "templateId" D.string
Expand Down
24 changes: 12 additions & 12 deletions engine-registry/elm/Registry/Common/Requests.elm
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Registry.Common.Requests exposing
( ToMsg
, getDocumentTemplate
, getDocumentTemplates
, getLocale
, getLocales
, getOrganization
, getPackage
, getPackages
, getTemplate
, getTemplates
, getToken
, postForgottenTokenActionKey
, postOrganization
Expand All @@ -19,13 +19,13 @@ import Http
import Json.Decode as D exposing (Decoder)
import Json.Encode as E
import Registry.Common.AppState exposing (AppState)
import Registry.Common.Entities.DocumentTemplate as DocumentTemplate exposing (DocumentTemplate)
import Registry.Common.Entities.DocumentTemplateDetail as DocumentTemplateDetail exposing (DocumentTemplateDetail)
import Registry.Common.Entities.Locale as Locale exposing (Locale)
import Registry.Common.Entities.LocaleDetail as LocaleDetail exposing (LocaleDetail)
import Registry.Common.Entities.OrganizationDetail as OrganizationDetail exposing (OrganizationDetail)
import Registry.Common.Entities.Package as Package exposing (Package)
import Registry.Common.Entities.PackageDetail as PackageDetail exposing (PackageDetail)
import Registry.Common.Entities.Template as Template exposing (Template)
import Registry.Common.Entities.TemplateDetail as TemplateDetail exposing (TemplateDetail)
import Shared.Error.ApiError exposing (ApiError(..))


Expand Down Expand Up @@ -210,19 +210,19 @@ getPackage appState pkgId msg =
}


getTemplates : AppState -> ToMsg (List Template) msg -> Cmd msg
getTemplates appState msg =
getDocumentTemplates : AppState -> ToMsg (List DocumentTemplate) msg -> Cmd msg
getDocumentTemplates appState msg =
Http.get
{ url = appState.apiUrl ++ "/templates"
, expect = expectJson msg (D.list Template.decoder)
{ url = appState.apiUrl ++ "/document-templates"
, expect = expectJson msg (D.list DocumentTemplate.decoder)
}


getTemplate : AppState -> String -> ToMsg TemplateDetail msg -> Cmd msg
getTemplate appState templateId msg =
getDocumentTemplate : AppState -> String -> ToMsg DocumentTemplateDetail msg -> Cmd msg
getDocumentTemplate appState templateId msg =
Http.get
{ url = appState.apiUrl ++ "/templates/" ++ templateId
, expect = expectJson msg TemplateDetail.decoder
{ url = appState.apiUrl ++ "/document-templates/" ++ templateId
, expect = expectJson msg DocumentTemplateDetail.decoder
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Registry.Pages.TemplateDetail exposing
module Registry.Pages.DocumentTemplateDetail exposing
( Model
, Msg
, init
Expand All @@ -12,8 +12,8 @@ import Html exposing (Html, a, br, code, div, h5, li, p, span, strong, text, ul)
import Html.Attributes exposing (class, href, target, title)
import Html.Events exposing (onClick)
import Registry.Common.AppState exposing (AppState)
import Registry.Common.Entities.DocumentTemplateDetail exposing (DocumentTemplateDetail)
import Registry.Common.Entities.OrganizationInfo exposing (OrganizationInfo)
import Registry.Common.Entities.TemplateDetail exposing (TemplateDetail)
import Registry.Common.Requests as Requests
import Registry.Common.View.ItemIcon as ItemIcon
import Registry.Common.View.Page as Page
Expand All @@ -27,10 +27,10 @@ import Version

init : AppState -> String -> ( Model, Cmd Msg )
init appState templateId =
( { template = Loading
( { documentTemplate = Loading
, copied = False
}
, Requests.getTemplate appState templateId GetTemplateCompleted
, Requests.getDocumentTemplate appState templateId GetDocumentTemplateCompleted
)


Expand All @@ -39,34 +39,34 @@ init appState templateId =


type alias Model =
{ template : ActionResult TemplateDetail
{ documentTemplate : ActionResult DocumentTemplateDetail
, copied : Bool
}


setTemplate : ActionResult TemplateDetail -> Model -> Model
setTemplate template model =
{ model | template = template }
setDocumentTemplate : ActionResult DocumentTemplateDetail -> Model -> Model
setDocumentTemplate template model =
{ model | documentTemplate = template }



-- UPDATE


type Msg
= GetTemplateCompleted (Result ApiError TemplateDetail)
| CopyTemplateId String
= GetDocumentTemplateCompleted (Result ApiError DocumentTemplateDetail)
| CopyDocumentTemplateId String


update : Msg -> AppState -> Model -> ( Model, Cmd msg )
update msg appState model =
case msg of
GetTemplateCompleted result ->
( ActionResult.apply setTemplate (ApiError.toActionResult appState (gettext "Unable to get the template." appState.locale)) result model
GetDocumentTemplateCompleted result ->
( ActionResult.apply setDocumentTemplate (ApiError.toActionResult appState (gettext "Unable to get the template." appState.locale)) result model
, Cmd.none
)

CopyTemplateId templateId ->
CopyDocumentTemplateId templateId ->
( { model | copied = True }, Copy.copyToClipboard templateId )


Expand All @@ -76,11 +76,11 @@ update msg appState model =

view : AppState -> Model -> Html Msg
view appState model =
Page.actionResultView (viewDetail appState model) model.template
Page.actionResultView (viewDetail appState model) model.documentTemplate


viewDetail : AppState -> Model -> TemplateDetail -> Html Msg
viewDetail appState model template =
viewDetail : AppState -> Model -> DocumentTemplateDetail -> Html Msg
viewDetail appState model documentTemplate =
let
viewTemplateIdCopied =
if model.copied then
Expand All @@ -93,36 +93,36 @@ viewDetail appState model template =
[ h5 [] [ text (gettext "Template ID" appState.locale) ]
, p []
[ code
[ onClick (CopyTemplateId template.id)
[ onClick (CopyDocumentTemplateId documentTemplate.id)
, title (gettext "Click to copy Template ID" appState.locale)
, class "entity-id"
]
[ text template.id ]
[ text documentTemplate.id ]
, viewTemplateIdCopied
]
]

viewPublishedBy =
[ h5 [] [ text (gettext "Published by" appState.locale) ]
, viewOrganization template.organization
, viewOrganization documentTemplate.organization
]

viewLicense =
[ h5 [] [ text (gettext "License" appState.locale) ]
, p []
[ a [ href <| "https://spdx.org/licenses/" ++ template.license ++ ".html", target "_blank" ]
[ text template.license ]
[ a [ href <| "https://spdx.org/licenses/" ++ documentTemplate.license ++ ".html", target "_blank" ]
[ text documentTemplate.license ]
]
]

viewCurrentVersion =
[ h5 [] [ text (gettext "Version" appState.locale) ]
, p [] [ text <| Version.toString template.version ]
, p [] [ text <| Version.toString documentTemplate.version ]
]

otherVersions =
template.versions
|> List.filter ((/=) template.version)
documentTemplate.versions
|> List.filter ((/=) documentTemplate.version)
|> List.sortWith Version.compare
|> List.reverse

Expand All @@ -139,19 +139,19 @@ viewDetail appState model template =

viewVersion version =
li []
[ a [ href <| Routing.toString <| Routing.TemplateDetail (template.organization.organizationId ++ ":" ++ template.templateId ++ ":" ++ Version.toString version) ]
[ a [ href <| Routing.toString <| Routing.DocumentTemplateDetail (documentTemplate.organization.organizationId ++ ":" ++ documentTemplate.templateId ++ ":" ++ Version.toString version) ]
[ text <| Version.toString version ]
]

viewSupportedMetamodel =
[ h5 [] [ text (gettext "Metamodel version" appState.locale) ]
, p [] [ text <| String.fromInt template.metamodelVersion ]
, p [] [ text <| String.fromInt documentTemplate.metamodelVersion ]
]
in
div [ class "Detail" ]
[ div [ class "row" ]
[ div [ class "col-12 col-md-8" ]
[ Markdown.toHtml [] template.readme ]
[ Markdown.toHtml [] documentTemplate.readme ]
, div [ class "Detail__Panel col-12 col-md-4" ]
(viewTemplateId
++ viewPublishedBy
Expand Down
Loading

0 comments on commit bb0b9b3

Please sign in to comment.