Skip to content

Commit

Permalink
Delete PTV ServiceLocation from PTV site tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Deraen committed Dec 2, 2024
1 parent af6bcf0 commit 3da3c96
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
3 changes: 2 additions & 1 deletion webapp/src/clj/lipas/backend/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@
;; Note: if site status or something is updated in Lipas, so that the site is no longer candidate,
;; that doesn't trigger update if sync-enabled is false.
(if (and (not draft?)
(:sync-enabled (:ptv resp))
(or (:sync-enabled (:ptv resp))
(:delete-existing (:ptv resp)))
;; TODO: Check privilage :ptv/basic or such
(or (ptv-data/ptv-candidate? resp)
(ptv-data/is-sent-to-ptv? resp)))
Expand Down
6 changes: 4 additions & 2 deletions webapp/src/clj/lipas/backend/ptv/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@
:service-channel-ids [(:id ptv-resp)])
(cond->
archive? (dissoc :source-id
:service-channel-ids)))]
:service-channel-ids
:delete-existing)))]

(log/infof "Upserted (Lipas status: %s, updated: %s) service-location %s: %s" (:status site) (boolean id) data new-ptv-data)

Expand Down Expand Up @@ -205,7 +206,8 @@
;; a candidate, mark for it archival.
;; The other function will mark the document Deleted when archive flag is true
to-archive? (and previous-sent?
(not candidate-now?))
(or (not candidate-now?)
(:delete-existing ptv)))

type-code-changed? (not= type-code (:previous-type-code ptv))
ptv (if type-code-changed?
Expand Down
1 change: 1 addition & 0 deletions webapp/src/clj/lipas/backend/ptv/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
{:closed true}
[:org-id :string]
[:sync-enabled :boolean]
[:delete-existing {:optional true} :boolean]

;; These options aren't used now:
;; TODO: Remove
Expand Down
3 changes: 3 additions & 0 deletions webapp/src/cljc/lipas/schema/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,7 @@
(s/def :lipas.sports-site.ptv/last-sync string?)
(s/def :lipas.sports-site.ptv/org-id string?)
(s/def :lipas.sports-site.ptv/sync-enabled boolean?)
(s/def :lipas.sports-site.ptv/delete-existing boolean?)
(s/def :lipas.sports-site.ptv/source-id string?)
(s/def :lipas.sports-site.ptv/publishing-status string?)
(s/def :lipas.sports-site.ptv/previous-type-code int?)
Expand Down Expand Up @@ -1527,6 +1528,8 @@
:lipas.sports-site.ptv/service-ids
:lipas.sports-site.ptv/languages

:lipas.sports-site.ptv/delete-existing

;; Added on sync - removed when archived
:lipas.sports-site.ptv/source-id
:lipas.sports-site.ptv/service-channel-ids
Expand Down
34 changes: 23 additions & 11 deletions webapp/src/cljs/lipas/ui/ptv/site_view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@

;; _ (js/console.log edit-data sports-site)

{:keys [org-id sync-enabled last-sync publishing-status]} (:ptv site)
{:keys [org-id sync-enabled delete-existing last-sync publishing-status]} (:ptv site)
org-languages (ptv-data/org-id->languages org-id)

;; _ (js/console.log org-id)
Expand Down Expand Up @@ -233,12 +233,14 @@
(and previous-sent? candidate-now? ready?)
(if sync-enabled
($ Alert {:severity "success"} "PTV-integraatio on käytössä")
($ Alert {:severity "success"} "PTV-integraatio on käytössä, mutta liikuntapaikan synkronointi PTV:hen on kytketty pois päältä."))
(if delete-existing
($ Alert {:severity "success"} "Liikuntapaikka poistetaan PTV:stä tallennuksen yhteydessä")
($ Alert {:severity "success"} "PTV-integraatio on käytössä, mutta liikuntapaikan synkronointi PTV:hen on kytketty pois päältä.")))

(and previous-sent? (not candidate-now?))
($ Alert {:severity "warning"} "Liikuntapaikka on viety aiemmin PTV:hen, mutta tietoja on muutettu siten, että tietoja ei enää viedä. PTV-palvelupaikka tullaan arkistoimaan tallennuksen yhteydessä.")

(and candidate-now? ready?)
(and candidate-now? ready? sync-enabled)
($ Alert {:severity "info"} "Liikuntapaikkaa ei ole aiemmin viety PTV:hen. Uusi palvelupaikka tullaan luomaan tallennuksen yhteydessä.")

(and candidate-now? (not ready?))
Expand Down Expand Up @@ -274,14 +276,24 @@
:org-id org-id
:service (first missing-services)}))

($ FormControlLabel
{:label "Synkronoi PTV:hen"
:control ($ Switch
{:disabled read-only?
:checked sync-enabled
:on-change (fn [_e v]
(js/console.log _e v)
(rf/dispatch [:lipas.ui.sports-sites.events/edit-field lipas-id [:ptv :sync-enabled] v]))})})
($ Stack
{:direction "row"}
($ FormControlLabel
{:label "Synkronoi PTV:hen"
:control ($ Switch
{:disabled read-only?
:checked sync-enabled
:on-change (fn [_e v]
(rf/dispatch [:lipas.ui.sports-sites.events/edit-field lipas-id [:ptv :sync-enabled] v]))})})
(when (and (not sync-enabled)
previous-sent?)
($ FormControlLabel
{:label "Poista jo luotu paikka PTV:stä"
:control ($ Switch
{:disabled read-only?
:checked (or delete-existing false)
:on-change (fn [_e v]
(rf/dispatch [:lipas.ui.sports-sites.events/edit-field lipas-id [:ptv :delete-existing] v]))})})))

($ Stack
{:sx #js {:position "relative"}}
Expand Down
6 changes: 5 additions & 1 deletion webapp/src/cljs/lipas/ui/sports_sites/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
(let [org-langs (ptv-data/org-id->languages (:org-id v))]
(merge (:default-settings (:ptv db))
{:languages org-langs}
v)))))))
v))))

(and (:sync-enabled (:ptv sports-site))
(:delete-existing (:ptv sports-site)))
(update :ptv dissoc :delete-existing))))

(rf/reg-event-db ::calc-derived-fields
(fn [db [_ lipas-id sports-site]]
Expand Down

0 comments on commit 3da3c96

Please sign in to comment.