Skip to content

Commit

Permalink
🚧 Printouts page: QR code only
Browse files Browse the repository at this point in the history
Why:
- Continuing the migration from SPA to SSR.
  • Loading branch information
luontola committed Jul 11, 2024
1 parent e2c05e6 commit 0be5fb8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/territory_bro/ui/printout_templates.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@
[:div {:class (:content styles)}
content]])))

(defn territory-qr-code [territory]
(h/html
[:div {:hx-target "this"
:hx-swap "outerHTML"
:hx-trigger "load"
:hx-get (str html/*page-path* "/qr-code/" (:id territory))}]))


(defn territory-card [{:keys [territory congregation-boundary enclosing-region enclosing-minimap-viewport map-raster print-date]}]
(let [styles (:TerritoryCard (css/modules))]
Expand Down Expand Up @@ -70,11 +77,7 @@
:printout true}])]

[:div {:class (:addresses styles)}
[:div {:class (:qrCode styles)}
[:div {:hx-target "this"
:hx-swap "outerHTML"
:hx-trigger "load"
:hx-get (str html/*page-path* "/qr-code/" (:id territory))}]]
[:div {:class (:qrCode styles)} (territory-qr-code territory)]
(:addresses territory)]

[:div {:class (:footer styles)} (i18n/t "TerritoryCard.footer")]]))))
Expand Down Expand Up @@ -105,11 +108,7 @@
:map-raster map-raster
:printout true}])]

[:div {:class (:qrCode styles)}
[:div {:hx-target "this"
:hx-swap "outerHTML"
:hx-trigger "load"
:hx-get (str html/*page-path* "/qr-code/" (:id territory))}]]
[:div {:class (:qrCode styles)} (territory-qr-code territory)]

[:div {:class (:footer styles)} (i18n/t "TerritoryCard.footer")]]))))

Expand Down Expand Up @@ -139,11 +138,15 @@
:map-raster map-raster
:printout true}])]

[:div {:class (:qrCode styles)}
[:div {:hx-target "this"
:hx-swap "outerHTML"
:hx-trigger "load"
:hx-get (str html/*page-path* "/qr-code/" (:id territory))}]]]))))
[:div {:class (:qrCode styles)} (territory-qr-code territory)]]))))

(defn qr-code-only [{:keys [territory]}]
(let [styles (:QrCodeOnly (css/modules))]
(h/html
[:div {:class (:cropArea styles)}
[:div {:class (:root styles)}
[:div {:class (:number styles)} (:number territory)]
[:div {:class (:qrCode styles)} (territory-qr-code territory)]]])))

(defn neighborhood-card [{:keys [territory map-raster]}]
(let [styles (:NeighborhoodCard (css/modules))]
Expand Down
1 change: 1 addition & 0 deletions src/territory_bro/ui/printouts_page.clj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
:fn printout-templates/rural-territory-card
:type :territory}
{:id "QrCodeOnly"
:fn printout-templates/qr-code-only
:type :territory}
{:id "RegionPrintout"
:fn printout-templates/region-printout
Expand Down
10 changes: 10 additions & 0 deletions test/territory_bro/ui/printout_templates_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@
(is (str/includes? html "territory-location=\"MULTIPOLYGON(territory)\""))
(is (str/includes? html "map-raster=\"osmhd\"")))))

(deftest qr-code-only-test
(testing "no data"
(is (= "" (-> (printout-templates/qr-code-only nil)
html/visible-text))))

(testing "full data"
(let [html (printout-templates/qr-code-only territory-printout-model)]
(is (= "123" (html/visible-text html)))
(is (str/includes? html "hx-get=\"page-url/qr-code/00000000-0000-0000-0000-000000000001\"")))))

(deftest region-printout-test
(testing "no data"
(is (= "Printed with TerritoryBro.com"
Expand Down

0 comments on commit 0be5fb8

Please sign in to comment.