|
7 | 7 | [lipas.ui.components.buttons :as lui-btn] |
8 | 8 | [lipas.ui.components.forms :refer [->display-tf]] |
9 | 9 | [lipas.ui.components.text-fields :as lui-tf] |
| 10 | + [lipas.data.activities :as activities-data] |
10 | 11 | [lipas.ui.config :as config] |
11 | 12 | [lipas.ui.mui :as mui] |
12 | 13 | [lipas.ui.sports-sites.activities.events :as events] |
|
871 | 872 | #{:arrival :rules :rules-structured :permits-rules-guidelines :highlights}) |
872 | 873 |
|
873 | 874 | (def ^:private itrs-field-ks |
874 | | - #{:itrs-endurance :itrs-wilderness}) |
| 875 | + #{:itrs-endurance :itrs-wilderness :itrs-technical-route}) |
875 | 876 |
|
876 | 877 | (defn route-form |
877 | | - [{:keys [tr locale lipas-id type-code route-props state read-only? edit-itrs? field-sorter]}] |
| 878 | + [{:keys [tr locale lipas-id type-code route-props state read-only? edit-itrs? field-sorter |
| 879 | + compute-itrs-technical]}] |
878 | 880 | [nice-form {:read-only? read-only?} |
879 | 881 | (doall |
880 | 882 | (for [[prop-k {:keys [field show]}] (sort-by field-sorter utils/reverse-cmp route-props) |
|
889 | 891 | field-read-only? (if itrs-field? |
890 | 892 | (or read-only? (not edit-itrs?)) |
891 | 893 | read-only?) |
| 894 | + set-field (fn [& args] |
| 895 | + (let [path (butlast args) |
| 896 | + v (last args)] |
| 897 | + (swap! state assoc-in path v))) |
892 | 898 | field-component [make-field |
893 | 899 | {:read-only? field-read-only? |
894 | 900 | :key prop-k |
|
897 | 903 | :edit-data @state |
898 | 904 | :display-data @state |
899 | 905 | :locale locale |
900 | | - :set-field (fn [& args] |
901 | | - (let [path (butlast args) |
902 | | - v (last args)] |
903 | | - (swap! state assoc-in path v))) |
| 906 | + :set-field set-field |
904 | 907 | :lipas-id lipas-id}]] |
905 | | - (if itrs-locked? |
| 908 | + (cond |
| 909 | + itrs-locked? |
906 | 910 | [mui/tooltip {:title (tr :lipas.sports-site/itrs-edit-requires-role)} |
907 | 911 | [:span field-component]] |
| 912 | + |
| 913 | + (and (= :itrs-technical-route prop-k) edit-itrs? (not read-only?) compute-itrs-technical) |
| 914 | + [mui/grid {:container true :alignItems "center" :spacing 1 :wrap "nowrap"} |
| 915 | + [mui/grid {:item true :xs true} |
| 916 | + field-component] |
| 917 | + [mui/grid {:item true} |
| 918 | + [mui/tooltip {:title (tr :map/compute-itrs-technical)} |
| 919 | + [mui/icon-button |
| 920 | + {:size "small" |
| 921 | + :on-click (fn [] |
| 922 | + (when-let [v (compute-itrs-technical)] |
| 923 | + (set-field :itrs-technical-route v)))} |
| 924 | + [mui/icon "calculate"]]]]] |
| 925 | + |
| 926 | + :else |
908 | 927 | field-component)))))]) |
909 | 928 |
|
910 | 929 | (defn single-route |
|
920 | 939 | (set-field [new-state])))] |
921 | 940 |
|
922 | 941 | (let [tr (<== [:lipas.ui.subs/translator]) |
923 | | - field-sorter (<== [::subs/field-sorter activity-k])] |
| 942 | + field-sorter (<== [::subs/field-sorter activity-k]) |
| 943 | + geoms (<== [::subs/geoms read-only?])] |
924 | 944 |
|
925 | 945 | [route-form |
926 | 946 | {:locale locale |
|
931 | 951 | :read-only? read-only? |
932 | 952 | :edit-itrs? edit-itrs? |
933 | 953 | :route-props route-props |
934 | | - :state route-form-state}]) |
| 954 | + :state route-form-state |
| 955 | + :compute-itrs-technical |
| 956 | + (fn [] |
| 957 | + (let [fids (set (:fids @route-form-state)) |
| 958 | + features (:features geoms) |
| 959 | + values (->> features |
| 960 | + (filter #(contains? fids (:id %))) |
| 961 | + (map #(get-in % [:properties :itrs-technical])))] |
| 962 | + (activities-data/itrs-technical-max values)))}]) |
935 | 963 |
|
936 | 964 | (finally |
937 | 965 | (remove-watch route-form-state :lol)))) |
|
948 | 976 | selected-route-id (<== [::subs/selected-route-id]) |
949 | 977 |
|
950 | 978 | field-sorter (<== [::subs/field-sorter activity-k]) |
| 979 | + geoms (<== [::subs/geoms read-only?]) |
951 | 980 |
|
952 | 981 | editing? (not read-only?)] |
953 | 982 |
|
|
1012 | 1041 | :read-only? read-only? |
1013 | 1042 | :edit-itrs? edit-itrs? |
1014 | 1043 | :route-props route-props |
1015 | | - :state route-form-state}] |
| 1044 | + :state route-form-state |
| 1045 | + :compute-itrs-technical |
| 1046 | + (fn [] |
| 1047 | + (let [route-fids (set (:fids @route-form-state)) |
| 1048 | + features (:features geoms) |
| 1049 | + values (->> features |
| 1050 | + (filter #(contains? route-fids (:id %))) |
| 1051 | + (map #(get-in % [:properties :itrs-technical])))] |
| 1052 | + (activities-data/itrs-technical-max values)))}] |
1016 | 1053 |
|
1017 | 1054 | ;; Buttons |
1018 | 1055 | [mui/grid {:container true :spacing 1} |
|
0 commit comments