Repository: CSCfi/rems
Pull request #1441 (2019-08-01 09:35:33)

fix error modal header styling
when setting the title-class for a modal, the margin fix got thrown
away which resulted in white space above the header


Patch:
diff --git a/src/clj/rems/api/applications.clj b/src/clj/rems/api/applications.clj
index 6130ab622..da8637d1f 100644
--- a/src/clj/rems/api/applications.clj
+++ b/src/clj/rems/api/applications.clj
@@ -55,6 +55,10 @@
 (s/defschema Deciders
   [Decider])
 
+(s/defschema Command
+  {:type s/Keyword
+   s/Any s/Any})
+
 (s/defschema AcceptInvitationResult
   {:success s/Bool
    (s/optional-key :application-id) s/Int
diff --git a/src/clj/rems/api/schema.clj b/src/clj/rems/api/schema.clj
index 57d07184d..d85acb73f 100644
--- a/src/clj/rems/api/schema.clj
+++ b/src/clj/rems/api/schema.clj
@@ -42,6 +42,21 @@
 
 (s/defschema ResourceLicense License)
 
+(s/defschema ApplicationLicense
+  (merge License
+         {:type (s/eq "license") ;; TODO this is pretty redundant
+          :approved s/Bool}))
+
+(s/defschema Item
+  {:id s/Int
+   :localizations {s/Keyword {:title s/Str :inputprompt (s/maybe s/Str)}}
+   :optional s/Bool
+   :options [{:key s/Str :label {s/Keyword s/Str}}]
+   :maxlength (s/maybe s/Int)
+   :type s/Str
+   :value (s/maybe s/Str)
+   :previous-value (s/maybe s/Str)})
+
 (s/defschema Event
   (assoc events/EventBase
          s/Keyword s/Any))
@@ -95,6 +110,11 @@
 
 (def UserId s/Str)
 
+(s/defschema Actor
+  {:actoruserid UserId
+   :round s/Int
+   :role (s/enum "approver" "reviewer")})
+
 (s/defschema WorkflowLicense
   {:type s/Str
    :start DateTime
@@ -102,20 +122,26 @@
    :localizations [s/Any]
    :end (s/maybe DateTime)})
 
-(s/defschema Workflow
+(s/defschema WorkflowDB ; TODO: unify workflow schemas
   {:id s/Int
    :organization s/Str
    :owneruserid UserId
    :modifieruserid UserId
    :title s/Str
    :workflow s/Any
-   :licenses [WorkflowLicense]
+   :licenses s/Any
    :start DateTime
    :end (s/maybe DateTime)
    :expired s/Bool
    :enabled s/Bool
    :archived s/Bool})
 
+(s/defschema Workflow
+  (-> WorkflowDB
+      (dissoc :licenses)
+      (assoc :actors [Actor]
+             :licenses [WorkflowLicense])))
+
 (def not-neg? (partial <= 0))
 
 (s/defschema FieldTemplate
diff --git a/src/clj/rems/api/workflows.clj b/src/clj/rems/api/workflows.clj
index 6ce90b00e..67b4fd585 100644
--- a/src/clj/rems/api/workflows.clj
+++ b/src/clj/rems/api/workflows.clj
@@ -30,7 +30,7 @@
       (assoc :end (parse-db-time (:end license)))))
 
 (defn- format-workflow
-  [{:keys [id organization owneruserid modifieruserid title workflow start end expired enabled archived licenses]}]
+  [{:keys [id organization owneruserid modifieruserid title workflow start end expired enabled archived licenses actors]}]
   {:id id
    :organization organization
    :owneruserid owneruserid
@@ -42,7 +42,8 @@
    :expired expired
    :enabled enabled
    :archived archived
-   :licenses (mapv format-license licenses)})
+   :licenses (mapv format-license licenses)
+   :actors actors})
 
 (s/defschema CreateWorkflowCommand
   {:organization s/Str
diff --git a/src/clj/rems/css/styles.clj b/src/clj/rems/css/styles.clj
index 3be819f17..7228ac9cd 100644
--- a/src/clj/rems/css/styles.clj
+++ b/src/clj/rems/css/styles.clj
@@ -599,9 +599,9 @@
    [:.license-panel {:display :inline-block
                      :width "inherit"}]
    [:.card-header.clickable {:cursor "pointer"}]
+   [:.rems-card-margin-fix {:margin (u/px -1)}]  ; make sure header overlaps container border
    [:.rems-card-header {:color (util/get-theme-attribute :table-heading-color "#fff")
-                        :background-color (util/get-theme-attribute :table-heading-bgcolor :color3)
-                        :margin (u/px -1)}] ; make sure header overlaps container border
+                        :background-color (util/get-theme-attribute :table-heading-bgcolor :color3)}]
    [(s/descendant :.card-header :a) {:color :inherit}]
    [:.application-resources
     [:.application-resource {:margin-bottom (u/rem 1)
diff --git a/src/clj/rems/db/user_settings.clj b/src/clj/rems/db/user_settings.clj
index 4d35a10bf..5779cdc0e 100644
--- a/src/clj/rems/db/user_settings.clj
+++ b/src/clj/rems/db/user_settings.clj
@@ -1,6 +1,7 @@
 (ns rems.db.user-settings
   (:require [rems.config :refer [env]]
             [rems.db.core :as db]
+            [clojure.tools.logging :as log]
             [rems.json :as json]))
 
 (defn- default-settings []
diff --git a/src/cljs/rems/collapsible.cljs b/src/cljs/rems/collapsible.cljs
index 0b993529f..fd47b4005 100644
--- a/src/cljs/rems/collapsible.cljs
+++ b/src/cljs/rems/collapsible.cljs
@@ -5,7 +5,7 @@
 
 (defn- header
   [title title-class]
-  [:h2.card-header {:class (or title-class "rems-card-header")} title])
+  [:h2.card-header {:class ["rems-card-margin-fix" (or title-class "rems-card-header")]} title])
 
 (defn- show-more-button
   [id expanded callback]
diff --git a/src/cljs/rems/extra_pages.cljs b/src/cljs/rems/extra_pages.cljs
index f1fc147e2..f932ab9c9 100644
--- a/src/cljs/rems/extra_pages.cljs
+++ b/src/cljs/rems/extra_pages.cljs
@@ -26,29 +26,19 @@
        (dissoc ::loading?))))
 
 (rf/reg-sub ::page-id (fn [db _] (::page-id db)))
+(rf/reg-sub ::title (fn [db _] (let [page-id (::page-id db)
+                                     language (:language db)]
+                                 (->> db
+                                      :config
+                                      :extra-pages
+                                      (filter #(= page-id (:id %)))
+                                      first
+                                      :translations
+                                      language
+                                      :title))))
 (rf/reg-sub ::content (fn [db _] (::content db)))
 (rf/reg-sub ::loading? (fn [db _] (::loading? db)))
 
-(rf/reg-sub
- ::page
- (fn [db _]
-   (let [page-id (::page-id db)]
-     (->> db
-          :config
-          :extra-pages
-          (filter #(= page-id (:id %)))
-          first))))
-
-(rf/reg-sub
- ::title
- (fn [_ _]
-   [(rf/subscribe [::page]) (rf/subscribe [:language])])
- (fn [[page language] _]
-   (->> page
-        :translations
-        language
-        :title)))
-
 ;;;; Entry point
 
 (defn extra-pages []
diff --git a/src/cljs/rems/language.cljs b/src/cljs/rems/language.cljs
index bfba6e424..af0f9b4fc 100644
--- a/src/cljs/rems/language.cljs
+++ b/src/cljs/rems/language.cljs
@@ -6,7 +6,7 @@
  :language
  (fn [db _]
    (or (get-in db [:user-settings :language])
-       (:non-user-language db) ; for when the user is not logged in
+       (:language db)
        (:default-language db))))
 
 (reg-sub
@@ -21,6 +21,15 @@
  (fn [db _]
    (:default-language db)))
 
+(reg-event-fx
+ ::set-language
+ (fn [{:keys [db]} [_ language]]
+   (let [user-id (get-in db [:identity :user :eppn])]
+     (if user-id
+       (rf/dispatch [:rems.user-settings/update-user-settings user-id {:language language}])
+       (do (update-language language)
+           {:db (assoc db :language language)})))))
+
 (defn- update-css [language]
   (let [localized-css (str "/css/" (name language) "/screen.css")]
     ;; Figwheel replaces the linked stylesheet
@@ -32,12 +41,3 @@
 (defn update-language [language]
   (set! (.. js/document -documentElement -lang) (name language))
   (update-css language))
-
-(reg-event-fx
- ::set-language
- (fn [{:keys [db]} [_ language]]
-   (let [user-id (get-in db [:identity :user :eppn])]
-     (if user-id
-       (rf/dispatch [:rems.user-settings/update-user-settings {:language language}])
-       (do (update-language language)
-           {:db (assoc db :non-user-language language)})))))
diff --git a/src/cljs/rems/user_settings.cljs b/src/cljs/rems/user_settings.cljs
index 8f829ddf2..08e7b70f3 100644
--- a/src/cljs/rems/user_settings.cljs
+++ b/src/cljs/rems/user_settings.cljs
@@ -1,10 +1,10 @@
 (ns rems.user-settings
-  (:require [re-frame.core :as rf]
+  (:require [re-frame.core :as rf :refer [reg-event-fx reg-event-db]]
             [rems.language :as language]
             [rems.status-modal :as status-modal]
             [rems.util :refer [fetch put!]]))
 
-(rf/reg-event-fx
+(reg-event-fx
  :loaded-user-settings
  (fn [{:keys [db]} [_ user-settings]]
    (language/update-language (:language user-settings))
@@ -13,11 +13,10 @@
 (defn fetch-user-settings! []
   (fetch "/api/user-settings" {:handler #(rf/dispatch [:loaded-user-settings %])}))
 
-(rf/reg-event-fx
+(reg-event-fx
  ::update-user-settings
- (fn [_ [_ settings]]
+ (fn [{:keys [db]} [_ user-id settings]]
    (put! "/api/user-settings"
          {:params settings
           :handler (fn [_] (fetch-user-settings!))
-          :error-handler status-modal/common-error-handler!})
-   nil))
+          :error-handler status-modal/common-error-handler!})))


Test patch:
diff --git a/test/clj/rems/application/test_model.clj b/test/clj/rems/application/test_model.clj
index 5148dacbb..2877e2d36 100644
--- a/test/clj/rems/application/test_model.clj
+++ b/test/clj/rems/application/test_model.clj
@@ -194,7 +194,7 @@
   (doseq [[description schema dummies] [["form template" schema/FormTemplate get-form-template]
                                         ["catalogue item" schema/CatalogueItem get-catalogue-item]
                                         ["license" schema/License get-license]
-                                        ["workflow" schema/Workflow get-workflow]]]
+                                        ["workflow" schema/WorkflowDB get-workflow]]]
     (doseq [[id dummy] dummies]
       (testing (str description " " id)
         (is (s/validate schema dummy))))))