Skip to content

Commit

Permalink
Merge pull request #238 from IMASau/feature/isa-619-cql-filters-shoul…
Browse files Browse the repository at this point in the history
…d-be-accessible-from-an-alt-view-of-a-layer

ISA-619: Fix CQL filters with alternate views
  • Loading branch information
JoshGx2000 authored Dec 12, 2024
2 parents 3dc1773 + 340f58a commit 1ce36a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions frontend/src/cljs/imas_seamap/map/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -764,19 +764,19 @@

(defn rich-layer-get-cql-filter-values [{:keys [db]} [_ {:keys [id] :as _rich-layer}]]
(let [; Check if the new displayed layer is a rich layer, and if it has cql filter values that need to be fetched
{:keys [displayed-layer]} (enhance-rich-layer (first-where #(= (:id %) id) (get-in db [:map :rich-layers :rich-layers])) db)
{:keys [displayed-layer] :as rich-layer} (enhance-rich-layer (first-where #(= (:id %) id) (get-in db [:map :rich-layers :rich-layers])) db)
displayed-rich-layer (layer->rich-layer displayed-layer db)
has-cql-filter-values? (:values (first (get-in db [:map :rich-layers :async-datas (:id displayed-rich-layer) :controls])))]
has-cql-filter-values? (:values (first (get-in db [:map :rich-layers :async-datas (:id (or displayed-rich-layer rich-layer)) :controls])))]
(when-not has-cql-filter-values? ; If the displayed layer doesn't have cql filter values, fetch them
(if (seq (:controls displayed-rich-layer))
(if (seq (:controls (or displayed-rich-layer rich-layer)))
{:http-xhrio
{:method :get
:uri (get-in db [:config :urls :cql-filter-values-url])
:params {:rich-layer-id (:id displayed-rich-layer)}
:params {:rich-layer-id (:id (or displayed-rich-layer rich-layer))}
:response-format (ajax/json-response-format)
:on-success [:map.rich-layer/get-cql-filter-values-success displayed-rich-layer]
:on-success [:map.rich-layer/get-cql-filter-values-success (or displayed-rich-layer rich-layer)]
:on-failure [:ajax/default-err-handler]}}
{:dispatch [:map.rich-layer/get-cql-filter-values-success displayed-rich-layer {"values" {} "filter_combinations" []}]}))))
{:dispatch [:map.rich-layer/get-cql-filter-values-success (or displayed-rich-layer rich-layer) {"values" {} "filter_combinations" []}]}))))

(defn rich-layer-get-cql-filter-values-success [db [_ {:keys [id] :as _rich-layer} {:strs [values filter_combinations]}]]
(let [values (keywordize-keys values)]
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/cljs/imas_seamap/map/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,15 @@
(filterv #(= (get % cql-property) value) filter-combinations))
filter-combinations))

(defn- ->control [{:keys [cql-property] :as control} rich-layer {alternate-view-rich-layer-id :id :as alternate-view-rich-layer} db]
(let [values (get-in db [:map :rich-layers :async-datas alternate-view-rich-layer-id :controls cql-property :values])
(defn- ->control [{:keys [cql-property controller-type] :as control} {rich-layer-id :id :as rich-layer} {alternate-view-rich-layer-id :id :as alternate-view-rich-layer} db]
(let [values (get-in db [:map :rich-layers :async-datas (or alternate-view-rich-layer-id rich-layer-id) :controls cql-property :values])
value (control->value control rich-layer alternate-view-rich-layer db)
other-controls
(->>
(or (:controls alternate-view-rich-layer) (:controls rich-layer))
(remove #(= cql-property (:cql-property %)))
(map #(assoc % :value (control->value % rich-layer alternate-view-rich-layer db))))
filter-combinations (get-in db [:map :rich-layers :async-datas alternate-view-rich-layer-id :filter-combinations])
filter-combinations (get-in db [:map :rich-layers :async-datas (or alternate-view-rich-layer-id rich-layer-id) :filter-combinations])
valid-filter-combinations (reduce #(remove-incompatible-combinations %1 %2) filter-combinations other-controls)
valid-values (set (map #(get % cql-property) valid-filter-combinations))
values
Expand All @@ -486,7 +486,7 @@
:valid? (boolean (some #(= % value) valid-values))))
values)

values (if (and value (not (first-where #(= (:value %) value) values))) (conj values {:value value :valid? false}) values)]
values (if (and value (not= controller-type "multi-dropdown") (not (first-where #(= (:value %) value) values))) (conj values {:value value :valid? false}) values)]
(assoc
control
:values values
Expand Down

0 comments on commit 1ce36a0

Please sign in to comment.