|
12 | 12 | [lipas.ui.components.buttons :as lui-btn] |
13 | 13 | [lipas.ui.components.forms :refer [->display-tf]] |
14 | 14 | [lipas.ui.components.text-fields :as lui-tf] |
| 15 | + [lipas.data.activities :as activities-data] |
15 | 16 | [lipas.ui.config :as config] |
16 | 17 | ["@mui/material/Button$default" :as Button] |
17 | 18 | ["@mui/material/Chip$default" :as Chip] |
|
891 | 892 | #{:arrival :rules :rules-structured :permits-rules-guidelines :highlights}) |
892 | 893 |
|
893 | 894 | (def ^:private itrs-field-ks |
894 | | - #{:itrs-endurance :itrs-wilderness}) |
| 895 | + #{:itrs-endurance :itrs-wilderness :itrs-technical-route}) |
895 | 896 |
|
896 | 897 | (defn route-form |
897 | | - [{:keys [tr locale lipas-id type-code route-props state read-only? edit-itrs? field-sorter]}] |
| 898 | + [{:keys [tr locale lipas-id type-code route-props state read-only? edit-itrs? field-sorter |
| 899 | + compute-itrs-technical]}] |
898 | 900 | [nice-form {:read-only? read-only?} |
899 | 901 | (doall |
900 | 902 | (for [[prop-k {:keys [field show]}] (sort-by field-sorter utils/reverse-cmp route-props) |
|
909 | 911 | field-read-only? (if itrs-field? |
910 | 912 | (or read-only? (not edit-itrs?)) |
911 | 913 | read-only?) |
| 914 | + set-field (fn [& args] |
| 915 | + (let [path (butlast args) |
| 916 | + v (last args)] |
| 917 | + (swap! state assoc-in path v))) |
912 | 918 | field-component [make-field |
913 | 919 | {:read-only? field-read-only? |
914 | 920 | :key prop-k |
|
917 | 923 | :edit-data @state |
918 | 924 | :display-data @state |
919 | 925 | :locale locale |
920 | | - :set-field (fn [& args] |
921 | | - (let [path (butlast args) |
922 | | - v (last args)] |
923 | | - (swap! state assoc-in path v))) |
| 926 | + :set-field set-field |
924 | 927 | :lipas-id lipas-id}]] |
925 | | - (if itrs-locked? |
| 928 | + (cond |
| 929 | + itrs-locked? |
926 | 930 | [mui/tooltip {:title (tr :lipas.sports-site/itrs-edit-requires-role)} |
927 | 931 | [:span field-component]] |
| 932 | + |
| 933 | + (and (= :itrs-technical-route prop-k) edit-itrs? (not read-only?) compute-itrs-technical) |
| 934 | + [mui/grid {:container true :alignItems "center" :spacing 1 :wrap "nowrap"} |
| 935 | + [mui/grid {:item true :xs true} |
| 936 | + field-component] |
| 937 | + [mui/grid {:item true} |
| 938 | + [mui/tooltip {:title (tr :map/compute-itrs-technical)} |
| 939 | + [mui/icon-button |
| 940 | + {:size "small" |
| 941 | + :on-click (fn [] |
| 942 | + (when-let [v (compute-itrs-technical)] |
| 943 | + (set-field :itrs-technical-route v)))} |
| 944 | + [mui/icon "calculate"]]]]] |
| 945 | + |
| 946 | + :else |
928 | 947 | field-component)))))]) |
929 | 948 |
|
930 | 949 | (defn single-route |
|
940 | 959 | (set-field [new-state])))] |
941 | 960 |
|
942 | 961 | (let [tr (<== [:lipas.ui.subs/translator]) |
943 | | - field-sorter (<== [::subs/field-sorter activity-k])] |
| 962 | + field-sorter (<== [::subs/field-sorter activity-k]) |
| 963 | + geoms (<== [::subs/geoms read-only?])] |
944 | 964 |
|
945 | 965 | [route-form |
946 | 966 | {:locale locale |
|
951 | 971 | :read-only? read-only? |
952 | 972 | :edit-itrs? edit-itrs? |
953 | 973 | :route-props route-props |
954 | | - :state route-form-state}]) |
| 974 | + :state route-form-state |
| 975 | + :compute-itrs-technical |
| 976 | + (fn [] |
| 977 | + (let [fids (set (:fids @route-form-state)) |
| 978 | + features (:features geoms) |
| 979 | + values (->> features |
| 980 | + (filter #(contains? fids (:id %))) |
| 981 | + (map #(get-in % [:properties :itrs-technical])))] |
| 982 | + (activities-data/itrs-technical-max values)))}]) |
955 | 983 |
|
956 | 984 | (finally |
957 | 985 | (remove-watch route-form-state :lol)))) |
|
968 | 996 | selected-route-id (<== [::subs/selected-route-id]) |
969 | 997 |
|
970 | 998 | field-sorter (<== [::subs/field-sorter activity-k]) |
| 999 | + geoms (<== [::subs/geoms read-only?]) |
971 | 1000 |
|
972 | 1001 | editing? (not read-only?)] |
973 | 1002 |
|
|
1032 | 1061 | :read-only? read-only? |
1033 | 1062 | :edit-itrs? edit-itrs? |
1034 | 1063 | :route-props route-props |
1035 | | - :state route-form-state}] |
| 1064 | + :state route-form-state |
| 1065 | + :compute-itrs-technical |
| 1066 | + (fn [] |
| 1067 | + (let [route-fids (set (:fids @route-form-state)) |
| 1068 | + features (:features geoms) |
| 1069 | + values (->> features |
| 1070 | + (filter #(contains? route-fids (:id %))) |
| 1071 | + (map #(get-in % [:properties :itrs-technical])))] |
| 1072 | + (activities-data/itrs-technical-max values)))}] |
1036 | 1073 |
|
1037 | 1074 | ;; Buttons |
1038 | 1075 | [:> Grid {:container true :spacing 1} |
|
0 commit comments