Skip to content

Commit

Permalink
Improve layout of ishare explanations
Browse files Browse the repository at this point in the history
  • Loading branch information
Remco van 't Veer committed Jun 18, 2024
1 parent a004139 commit 6c2d38a
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 194 deletions.
12 changes: 7 additions & 5 deletions src/dil_demo/erp.clj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
@ishare-client/log-interceptor-atom]))

(defn- wrap-policy-deletion
"When a trip is added or deleted, retract existing policies in the AR"
"When a trip is deleted, retract existing policies in the AR."
[app]
(fn policy-deletion-wrapper
[{:keys [client-data ::store/store] :as req}]
Expand All @@ -55,9 +55,10 @@
commands)
(first)
(nth 2))]
(let [consignment (get-in store [:consignments id])
[result log] (ishare-ar! client-data "Deny" (otm/consignment->map consignment))]
(cond-> (assoc-in res [:flash :ishare-log] log)
(let [old-consignment (get-in store [:consignments id])
[result log] (ishare-ar! client-data "Deny" (otm/consignment->map old-consignment))]
(cond-> (update-in res [:flash :explanation] (fnil conj [])
["Verwijderen policy" log])
(not result) (assoc-in [:flash :error] "Verwijderen AR policy mislukt")))

res))))
Expand All @@ -73,7 +74,8 @@
(first))]
(if trip
(let [[result log] (ishare-ar! client-data "Permit" (otm/trip->map trip))]
(cond-> (assoc-in res [:flash :ishare-log] log)
(cond-> (update-in res [:flash :explanation] (fnil conj [])
["Toevoegen policy" log])
(not result) (assoc-in [:flash :error] "Aanmaken AR policy mislukt")))
res))))

Expand Down
64 changes: 29 additions & 35 deletions src/dil_demo/erp/web.clj
Original file line number Diff line number Diff line change
Expand Up @@ -59,50 +59,53 @@

(defn edit-consignment [consignment {:keys [carriers warehouses]}]
(let [{:keys [status ref load-date load-location load-remarks unload-location unload-date unload-remarks goods carrier-eori]}
(otm/consignment->map consignment)]
(otm/consignment->map consignment)

;; add empty option
carriers (into {nil nil} carriers)]
[:form {:method "POST"}
(w/anti-forgery-input)

[:section
(w/field {:name "status", :value status,
:label "Status", :type "select", :list otm/statuses})
(w/field {:name "ref", :value ref,
:label "Klantorder nr.", :type "number", :required true})]
:label "Status", :type "select",
:list otm/statuses})
(w/field {:name "ref", :value ref,
:label "Klantorder nr.", :type "number",
:required true})]
[:section
(w/field {:name "load-date", :type "date",
:label "Ophaaldatum", :value load-date})
(w/field {:name "load-location", :value load-location, ;; EORIs?!
:label "Ophaaladres", :type "select", :list warehouses, :required true})
(w/field {:name "load-location", :value load-location, ;; EORIs?!
:label "Ophaaladres", :type "select",
:list warehouses, :required true})
(w/field {:name "load-remarks", :value load-remarks,
:label "Opmerkingen", :type "textarea"})]
[:section
(w/field {:name "unload-date", :value unload-date,
:label "Afleverdatum", :type "date"})
(w/field {:name "unload-location", :value unload-location,
:label "Afleveradres", :type "text", :list (keys d/locations), :required true})
(w/field {:name "unload-location", :value unload-location,
:label "Afleveradres", :type "text",
:list (keys d/locations), :required true})
(w/field {:name "unload-remarks", :value unload-remarks,
:label "Opmerkingen", :type "textarea"})]
[:section
(w/field {:name "goods", :value goods,
:label "Goederen", :type "text", :list d/goods, :required true})
(w/field {:name "carrier-eori", :value carrier-eori,
:label "Vervoerder", :type "select", :list carriers, :required true})]
(w/field {:name "goods", :value goods,
:label "Goederen", :type "text",
:list d/goods, :required true})
(w/field {:name "carrier-eori", :value carrier-eori,
:label "Vervoerder", :type "select",
:list carriers, :required true})]
[:div.actions
[:button.button.button-primary {:type "submit"} "Bewaren"]
[:a.button {:href "."} "Annuleren"]]]))

(defn deleted-consignment [{:keys [ishare-log]}]
(defn deleted-consignment [{:keys [explanation]}]
[:div
[:section
[:div.actions
[:a.button {:href "."} "Terug naar overzicht"]]]
[:details.explanation
[:summary "Uitleg"]
[:ol
[:li
[:h3 "Autorisatie van vervoerder ingetrokken"]
[:p "API call naar " [:strong "AR van de Verlader"] " om een autorisatie te verwijderen"]]
(w/ishare-log-intercept-to-hiccup ishare-log)]]])
(w/explanation explanation)])

(defn publish-consignment [consignment {:keys [carriers warehouses warehouse-addresses]}]
(let [{:keys [status ref load-date load-location load-remarks unload-date unload-location unload-remarks goods carrier-eori]}
Expand Down Expand Up @@ -155,7 +158,7 @@

(defn published-consignment [consignment
{:keys [carriers warehouses]}
{:keys [ishare-log]}]
{:keys [explanation]}]
(let [{:keys [load-location carrier-eori]} (otm/consignment->map consignment)]
[:div
[:section
Expand All @@ -166,18 +169,9 @@
"."]
[:div.actions
[:a.button {:href "."} "Terug naar overzicht"]]]
[:details.explanation
[:summary "Uitleg"]
[:ol
[:li
[:details
[:summary "Stuur OTM Transportopdracht naar WMS van DC"]
[:pre.json (w/otm-to-json (otm/consignment->transport-order consignment))]]]
[:li
[:details
[:summary "Stuur OTM Trip naar TMS van Vervoerder"]
[:pre.json (w/otm-to-json (otm/consignment->trip consignment))]]]
(w/ishare-log-intercept-to-hiccup ishare-log)]]]))
(w/explanation (into [["Stuur OTM Transportopdracht naar WMS van DC"]
["Stuur OTM Trip naar TMS van Vervoerder"]]
explanation))]))



Expand Down Expand Up @@ -267,9 +261,9 @@
(assoc :flash {:success "Klantorder verwijderd"})
(assoc ::store/commands [[:delete! :consignments id]]))))

(GET "/deleted" {{:keys [ishare-log] :as flash} :flash}
(GET "/deleted" {:keys [flash]}
(render "Transportopdracht verwijderd"
(deleted-consignment {:ishare-log ishare-log})
(deleted-consignment flash)
flash))

(GET "/publish-:id" {:keys [flash master-data ::store/store]
Expand Down
6 changes: 4 additions & 2 deletions src/dil_demo/ishare/policies.clj
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@
(not= rules [{:effect "Permit"}]))
(conj (str "Geen toepasbare regels gevonden: " (pr-str rules)))

(< now (:notBefore delegation-evidence))
(and (:notBefore delegation-evidence)
(< now (:notBefore delegation-evidence)))
(conj (str "Mag niet voor " (epoch->str (:notBefore delegation-evidence))) )

(>= now (:notOnOrAfter delegation-evidence))
(and (:notOnOrAfter delegation-evidence)
(>= now (:notOnOrAfter delegation-evidence)))
(conj (str "Mag niet op of na " (epoch->str (:notOnOrAfter delegation-evidence))))

(empty? matching-policies) ;; FEEDBACK: should not happen?
Expand Down
37 changes: 16 additions & 21 deletions src/dil_demo/tms.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,24 @@
[dil-demo.ishare.client :as ishare-client]
[dil-demo.otm :as otm]))

(defn- append-in
"Insert `coll` into collection at `path` in `m`.
If there is not collection at `path` insert into empty vector."
[m path coll]
(update-in m path (fnil into []) coll))



(defn- ishare-exec! [{:keys [client-data] :as req} cmd]
(defn- ishare-exec! [{:keys [client-data] :as req} title cmd]
(binding [ishare-client/log-interceptor-atom (atom [])]
(try
(let [result (:ishare/result (ishare-client/exec (merge client-data cmd)))]
(-> req
(append-in [:flash :ishare-log] @ishare-client/log-interceptor-atom)
(update-in [:flash :explanation] (fnil conj [])
[title @ishare-client/log-interceptor-atom])
(assoc :ishare/result result)))
(catch Exception ex
(log/error ex)
(-> req
(append-in [:flash :ishare-log] @ishare-client/log-interceptor-atom)
(update-in [:flash :explanation] (fnil conj [])
[title @ishare-client/log-interceptor-atom])
(assoc-in [:flash :error] (str "Fout bij uitvoeren van iShare commando " (:ishare/message-type ex))))))))



(defn- ->ar-type
(defn- ->ar-type
[{{:ishare/keys [authentication-registry-type]} :client-data} & _]
authentication-registry-type)

Expand All @@ -58,18 +51,20 @@
[{:keys [::store/store] :as req} {:keys [id] :as _trip} _subject]
(if-let [policy-id (get-in store [:trip-policies id :policy-id])]
(-> req
(ishare-exec! {:throw false ;; ignore HTTP errors for when
;; policy already deleted
(ishare-exec! "Verwijder policy voor trip"
{:throw false ;; ignore HTTP errors for when
;; policy already deleted

:ishare/message-type :poort8/delete-policy
:ishare/params {:policyId policy-id}})
(append-in [::store/commands]
[[:delete! :trip-policies id]]))
(update-in [::store/commands] (fnil conj [])
[:delete! :trip-policies id]))
req))

(defmethod delete-policy-for-trip! :ishare
[req trip subject]
(ishare-exec! req
"Verwijder policy voor trip"
(ishare-create-policy-command req subject trip "Deny")))

(defmulti create-policy-for-trip! ->ar-type)
Expand All @@ -83,16 +78,16 @@
{:consignment-ref (otm/trip-ref trip)
:date (otm/trip-load-date trip)
:subject subject})}
res (ishare-exec! req cmd)]
res (ishare-exec! req "Toevoegen policy voor trip" cmd)]

(if-let [policy-id (get-in res [:ishare/result "policyId"])]
(append-in res [::store/commands]
[[:put! :trip-policies {:id id, :policy-id policy-id}]])
(update-in res [::store/commands] (fnil conj [])
[:put! :trip-policies {:id id, :policy-id policy-id}])
res)))

(defmethod create-policy-for-trip! :ishare
[req trip subject]
(ishare-exec! req
(ishare-exec! req "Toevoegen policy voor trip"
(ishare-create-policy-command req subject trip "Permit")))

(defmulti delegation-effect!
Expand Down
65 changes: 21 additions & 44 deletions src/dil_demo/tms/web.clj
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
[:button.button-primary {:type "submit"} "Toewijzen"]
[:a.button {:href "."} "Annuleren"]]]))

(defn assigned-trip [trip {:keys [ishare-log]}]
(defn assigned-trip [trip {:keys [explanation]}]
[:div
[:section
[:p "Transportopdracht " [:q (otm/trip-ref trip)] " toegewezen."]
Expand All @@ -144,17 +144,7 @@

[:div.actions
[:a.button {:href "."} "Terug naar overzicht"]]]
[:details.explanation
[:summary "Uitleg"]
[:ol
[:li
[:h3 "Autoriseer de Chauffeur names de Vervoerder voor de Klantorder vervoerd met Kenteken"]
[:p "API call naar " [:strong "AR van de Vervoerder"] " om een autorisatie te registeren"]
[:ul [:li "Klantorder nr."] [:li "Rijbewijs (laatste 4 cijfers)"] [:li "Kenteken"]]]
[:li
[:h3 "OTM Trip"]
[:pre.json (w/to-json trip)]]
(w/ishare-log-intercept-to-hiccup ishare-log)]]])
(w/explanation explanation)])

(defn outsource-trip [trip {:keys [carriers] :as master-data}]
[:form {:method "POST"}
Expand All @@ -163,43 +153,32 @@
(trip-details trip master-data)

[:section
(let [carriers (into {nil nil} carriers)]
(w/field {:label "Vervoerder"
:name "carrier-eori", :required true
:type "select", :list carriers}))]
(let [;; add empty option
carriers (into {nil nil} carriers)]
(w/field {:name "carrier-eori",
:label "Vervoerder", :type "select",
:list carriers, :required true}))]

[:div.actions
[:button.button-primary {:type "submit"} "Uitbesteden"]
[:a.button {:href "."} "Annuleren"]]])

(defn outsourced-trip [trip {:keys [ishare-log]}]
(defn outsourced-trip [trip {:keys [explanation]}]
(let [{:keys [ref]} (otm/trip->map trip)]
[:div
[:section
[:p "Transportopdracht " [:q ref] " uitbesteed."]

[:div.actions
[:a.button {:href "."} "Terug naar overzicht"]]]
[:details.explanation
[:summary "Uitleg"]
[:ol
(w/ishare-log-intercept-to-hiccup ishare-log)]]]))
(w/explanation explanation)]))

(defn deleted-trip [{:keys [ishare-log]}]
(defn deleted-trip [{:keys [explanation]}]
[:div
[:section
[:div.actions
[:a.button {:href "."} "Terug naar overzicht"]]]
[:details.explanation
[:summary "Uitleg"]
[:ol
[:li
[:h3 "Autorisatie van Chauffeur ingetrokken"]
[:p "API call naar " [:strong "AR van de Vervoerder"] " om een autorisatie te verwijderen"]
[:ul [:li "Klantorder nr."]
[:li "Rijbewijs (laatste 4 cijfers)"]
[:li "Kenteken"]]]
(w/ishare-log-intercept-to-hiccup ishare-log)]]])
(w/explanation explanation)])



Expand Down Expand Up @@ -249,9 +228,9 @@
(assoc :flash {:success "Transportopdracht verwijderd"})
(assoc ::store/commands [[:delete! :trips id]]))))

(GET "/deleted" {{:keys [ishare-log] :as flash} :flash}
(GET "/deleted" {:keys [flash]}
(render "Transportopdracht verwijderd"
(deleted-trip {:ishare-log ishare-log})
(deleted-trip flash)
flash))

(GET "/assign-:id" {:keys [flash master-data]
Expand All @@ -276,13 +255,12 @@
(assoc :flash {:success "Chauffeur en kenteken toegewezen"})
(assoc ::store/commands [[:put! :trips trip]])))))

(GET "/assigned-:id" {:keys [flash]
::store/keys [store]
{:keys [id]} :params
{:keys [ishare-log]} :flash}
(GET "/assigned-:id" {:keys [flash]
::store/keys [store]
{:keys [id]} :params}
(when-let [trip (get-trip store id)]
(render (str "Transportopdracht toegewezen")
(assigned-trip trip {:ishare-log ishare-log})
(assigned-trip trip flash)
flash)))

(GET "/outsource-:id" {:keys [flash master-data]
Expand All @@ -305,11 +283,10 @@
(assoc ::store/commands [[:put! :trips (otm/trip-status! trip otm/status-outsourced)]
[:publish! :trips carrier-eori trip]])))))

(GET "/outsourced-:id" {:keys [flash]
::store/keys [store]
{:keys [id]} :params
{:keys [ishare-log]} :flash}
(GET "/outsourced-:id" {:keys [flash]
::store/keys [store]
{:keys [id]} :params}
(when-let [trip (get-trip store id)]
(render "Transportopdracht uitbesteed"
(outsourced-trip trip {:ishare-log ishare-log})
(outsourced-trip trip flash)
flash))))))
Loading

0 comments on commit 6c2d38a

Please sign in to comment.