Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixes #983

Merged
merged 9 commits into from Mar 5, 2019
3 changes: 2 additions & 1 deletion src/clj/rems/api/catalogue_items.clj
Expand Up @@ -21,7 +21,8 @@
(s/optional-key :state) (s/maybe s/Str)})

(s/defschema CreateCatalogueItemResponse
CatalogueItem)
{:success s/Bool
:id s/Num})

(s/defschema CreateCatalogueItemLocalizationCommand
{:id s/Num
Expand Down
3 changes: 2 additions & 1 deletion src/clj/rems/api/forms.clj
Expand Up @@ -58,7 +58,8 @@
:items [FormField]})

(s/defschema CreateFormResponse
{:id s/Num})
{:success s/Bool
:id s/Num})

(def forms-api
(context "/forms" []
Expand Down
3 changes: 2 additions & 1 deletion src/clj/rems/api/licenses.clj
Expand Up @@ -37,7 +37,8 @@
(throw (rems.InvalidRequestException. (str "Unsupported content-type: " content-type)))))

(s/defschema CreateLicenseResponse
{:id s/Num})
{:success s/Bool
:id s/Num})

(def licenses-api
(context "/licenses" []
Expand Down
3 changes: 2 additions & 1 deletion src/clj/rems/api/workflows.clj
Expand Up @@ -85,7 +85,8 @@
:actors [UserId]}]})

(s/defschema CreateWorkflowResponse
{:id s/Num})
{:success s/Bool
:id s/Num})

; TODO: deduplicate or decouple with /api/applications/reviewers API?
(s/defschema AvailableActor User)
Expand Down
3 changes: 2 additions & 1 deletion src/clj/rems/db/catalogue.clj
Expand Up @@ -36,7 +36,8 @@

(defn create-catalogue-item! [command]
(let [id (:id (db/create-catalogue-item! (select-keys command [:title :form :resid :wfid :state])))]
(get-localized-catalogue-item id)))
{:success (not (nil? id))
:id id}))

(defn create-catalogue-item-localization! [command]
(let [return {:success (not (nil? (:id (db/create-catalogue-item-localization! (select-keys command [:id :langcode :title])))))}]
Expand Down
3 changes: 2 additions & 1 deletion src/clj/rems/db/form.clj
Expand Up @@ -40,4 +40,5 @@
:user user-id}))]
(doseq [[index item] (map-indexed vector items)]
(create-form-item! user-id form-id index item))
{:id form-id}))
{:success (not (nil? form-id))
:id form-id}))
3 changes: 2 additions & 1 deletion src/clj/rems/db/licenses.clj
Expand Up @@ -96,7 +96,8 @@
:title (:title localization)
:textcontent (:textcontent localization)
:attachmentId (:attachment-id localization)}))
{:id licid}))
{:success (not (nil? licid))
:id licid}))

(defn create-license-attachment! [{:keys [tempfile filename content-type]} user-id]
(let [byte-array (with-open [input (FileInputStream. tempfile)
Expand Down
11 changes: 7 additions & 4 deletions src/clj/rems/db/workflow.clj
Expand Up @@ -58,7 +58,10 @@
{:id wfid}))

(defn create-workflow! [command]
(case (:type command)
:auto-approve (create-auto-approve-workflow! command)
:dynamic (create-dynamic-workflow! command)
:rounds (create-rounds-workflow! command)))
(let [result (case (:type command)
:auto-approve (create-auto-approve-workflow! command)
:dynamic (create-dynamic-workflow! command)
:rounds (create-rounds-workflow! command))]
(merge
result
{:success (not (nil? (:id result)))})))
7 changes: 3 additions & 4 deletions src/cljs/rems/administration/create_catalogue_item.cljs
Expand Up @@ -61,11 +61,10 @@
request))

(defn- create-catalogue-item! [_ [_ request]]
(status-modal/set-pending! {:title (text :t.administration/create-catalogue-item)})
(status-modal/common-pending-handler! (text :t.administration/create-catalogue-item))
(post! "/api/catalogue-items/create" {:params (create-request-with-state request)
:handler (fn [_]
(status-modal/set-success! {:on-close #(dispatch! "#/administration/catalogue-items")}))
:error-handler #(status-modal/set-error! {:result {:error %}})})
:handler (partial status-modal/common-success-handler! #(dispatch! "#/administration/catalogue-items"))
:error-handler status-modal/common-error-handler!})
{})

(rf/reg-event-fx ::create-catalogue-item create-catalogue-item!)
Expand Down
17 changes: 8 additions & 9 deletions src/cljs/rems/administration/create_license.cljs
Expand Up @@ -59,15 +59,14 @@
(when (valid-request? request languages)
(localize-item request default-language))))

(defn- create-license! [_ [_ request]]
(status-modal/set-pending! {:title (text :t.administration/create-license)})
(post! "/api/licenses/create" {:params request
:handler (fn [result]
(status-modal/set-success! {:on-close #(dispatch! "/#/administration/licenses")}))
:error-handler #(status-modal/set-error! {:result {:error %}})})
{})

(rf/reg-event-fx ::create-license create-license!)
(rf/reg-event-fx
::create-license
(fn [_ [_ request]]
(status-modal/common-pending-handler! (text :t.administration/create-license))
(post! "/api/licenses/create" {:params request
:handler (partial status-modal/common-success-handler! #(dispatch! "/#/administration/licenses"))
:error-handler status-modal/common-error-handler!})
{}))

(defn- save-attachment [language form-data]
(post! (str "api/licenses/add_attachment")
Expand Down
14 changes: 6 additions & 8 deletions src/cljs/rems/catalogue.cljs
Expand Up @@ -18,7 +18,7 @@
::enter-page
(fn [{:keys [db]} _]
(if (roles/is-logged-in? (get-in db [:identity :roles]))
{:db (assoc db ::loading-catalogue? true)
{:db (assoc db ::catalogue nil)
::fetch-catalogue nil
::fetch-drafts nil}
(unauthorized!))))
Expand All @@ -41,11 +41,8 @@
(rf/reg-event-db
::fetch-catalogue-result
(fn [db [_ catalogue]]
(-> db
(assoc ::catalogue catalogue)
(dissoc ::loading-catalogue?))))
(assoc db ::catalogue catalogue)))

(rf/reg-sub ::loading-catalogue? (fn [db _] (::loading-catalogue? db)))
(rf/reg-sub ::catalogue (fn [db _] (::catalogue db)))


Expand Down Expand Up @@ -115,17 +112,18 @@
:items drafts}]]))

(defn catalogue-page []
(let [language (rf/subscribe [:language])]
(let [language (rf/subscribe [:language])
items @(rf/subscribe [::catalogue])]
[:div
[:h2 (text :t.catalogue/catalogue)]
(if @(rf/subscribe [::loading-catalogue?])
(if (empty? items)
Macroz marked this conversation as resolved.
Show resolved Hide resolved
[spinner/big]
[:div
[draft-application-list @(rf/subscribe [::draft-applications]) @language]
[:h4 (text :t.catalogue/apply-resources)]
[cart/cart-list-container @language]
[catalogue-list
{:items @(rf/subscribe [::catalogue])
{:items items
:language @language
:sorting (assoc @(rf/subscribe [::sorting]) :set-sorting #(rf/dispatch [::set-sorting %]))
:filtering (assoc @(rf/subscribe [::filtering]) :set-filtering #(rf/dispatch [::set-filtering %]))
Expand Down