Skip to content

Commit

Permalink
Merge pull request #2116 from CSCfi/pdf-improvements-2114
Browse files Browse the repository at this point in the history
PDF improvements
  • Loading branch information
opqdonut authored Apr 20, 2020
2 parents 24debca + 6948560 commit 0628b49
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 119 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ have notable changes.

Changes since v2.11

### Changes
- Improvements to PDFs (#2114)
- show attachment file names
- list instead of table for events
- hide draft-saved events
- vertical space around form fields
- PDF button moved to Actions pane

### Fixes
- Long attachment filenames are now truncated in the UI (#2118)

Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[ch.qos.logback/logback-classic "1.2.3"]
[clj-commons/secretary "1.2.4"]
[clj-http "3.10.0"]
[clj-pdf "2.4.0"]
[clj-pdf "2.4.3"]
[clj-time "0.15.2"]
[cljs-ajax "0.8.0"]
[cljsjs/react "16.9.0-1"]
Expand Down
3 changes: 1 addition & 2 deletions resources/translations/en.edn
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,14 @@
:alert-disabled-resources "Resources no longer available:"
:application "Application"
:attachment-remove "Remove"
:attachments "Attachments"
:checkbox-checked "Yes"
:checkbox-unchecked "No"
:comment "Comment"
:copy-as-new "Copy as a new application"
:current-value "Current"
:date "Time"
:diff-hide "Hide changes"
:diff-show "Show changes"
:event "Event"
:events "Events"
:failed "Failed"
:has-accepted-licenses "Terms of use accepted."
Expand Down
3 changes: 1 addition & 2 deletions resources/translations/fi.edn
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,14 @@
:alert-disabled-resources "Resurssit eivät ole enää saatavilla:"
:application "Tiedot"
:attachment-remove "Poista"
:attachments "Liitteet"
:checkbox-checked "Kyllä"
:checkbox-unchecked "Ei"
:comment "Kommentti"
:copy-as-new "Kopioi uudeksi hakemukseksi"
:current-value "Nykyinen"
:date "Aika"
:diff-hide "Piilota muutokset"
:diff-show "Näytä muutokset"
:event "Tapahtuma"
:events "Tapahtumat"
:failed "Epäonnistui"
:has-accepted-licenses "Käyttöehdot hyväksytty."
Expand Down
3 changes: 1 addition & 2 deletions resources/translations/sv.edn
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,14 @@
:alert-disabled-resources "Resurser som inte längre är tillgängliga:"
:application "Ansökning"
:attachment-remove "Ta bort"
:attachments "Bilagor"
:checkbox-checked "Ja"
:checkbox-unchecked "Nej"
:comment "Komment"
:copy-as-new "Kopiera som nytt"
:current-value "Nuvarande"
:date "Datum"
:diff-hide "Dölja ändringar"
:diff-show "Visa ändringar"
:event "Händelse"
:events "Händelser"
:failed "Misslyckades"
:has-accepted-licenses "Har accepterat licenserna."
Expand Down
4 changes: 2 additions & 2 deletions src/clj/rems/db/test_data.clj
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
:actor actor
:time (or time (time/now))})

(defn fill-form! [{:keys [application-id actor field-value optional-fields] :as command}]
(defn fill-form! [{:keys [application-id actor field-value optional-fields attachment] :as command}]
(let [app (applications/get-application actor application-id)]
(command! (assoc (base-command command)
:type :application.command/save-draft
Expand All @@ -258,7 +258,7 @@
(:header :label) ""
:date "2002-03-04"
:email "user@example.com"
:attachment "" ;; don't know what to do for these
:attachment (str attachment)
(:option :multiselect) (:key (first (:field/options field)))
(or field-value "x"))})))))

Expand Down
135 changes: 80 additions & 55 deletions src/clj/rems/pdf.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"Rendering applications as pdf"
(:require [clj-pdf.core :refer :all]
[clj-time.core :as time]
[clojure.string :as str]
[rems.common.util :refer [build-index]]
[rems.text :refer [localized localize-event localize-state localize-time text with-language]]
[rems.util :refer [getx getx-in]])
Expand All @@ -18,75 +19,98 @@
(defn- render-header [application]
(let [state (getx application :application/state)
resources (getx application :application/resources)]
(concat
(list
[:heading heading-style
(str (text :t.applications/application)
" "
(get application :application/external-id
(getx application :application/id))
(when-let [description (get application :application/description)]
(str ": " description)))]
[:paragraph
(text :t.pdf/generated)
" "
(localize-time (time/now))]
[:paragraph
(text :t.applications/state)
(when state [:phrase ": " (localize-state state)])]
[:heading heading-style (text :t.applicant-info/applicants)]
[:paragraph (text :t.applicant-info/applicant) ": " (render-user (getx application :application/applicant))])
(seq
(list
[:heading heading-style
(str (text :t.applications/application)
" "
(get application :application/external-id
(getx application :application/id))
(when-let [description (get application :application/description)]
(str ": " description)))]
[:paragraph
(text :t.pdf/generated)
" "
(localize-time (time/now))]
[:paragraph
(text :t.applications/state)
(when state [:phrase ": " (localize-state state)])]
[:heading heading-style (text :t.applicant-info/applicants)]
[:paragraph (text :t.applicant-info/applicant) ": " (render-user (getx application :application/applicant))]
(doall
(for [member (getx application :application/members)]
[:paragraph (text :t.applicant-info/member) ": " (render-user member)]))
(list
[:heading heading-style (text :t.form/resources)]
(into
[:list]
[:heading heading-style (text :t.form/resources)]
[:list
(doall
(for [resource resources]
[:phrase
(localized (:catalogue-item/title resource))
" (" (:resource/ext-id resource) ")"]))))))
" (" (:resource/ext-id resource) ")"]))])))

(defn- attachment-filenames [application]
(build-index [:attachment/id] :attachment/filename (:application/attachments application)))

(defn- render-events [application]
(let [events (getx application :application/events)]
(let [filenames (attachment-filenames application)
events (getx application :application/events)]
(list
[:heading heading-style (text :t.form/events)]
(if (empty? events)
[:paragraph ""]
(into
[:table {:header [(text :t.form/date)
(text :t.form/event)
(text :t.form/comment)]}]
(for [event events]
[(localize-time (:event/time event))
(localize-event event)
(get event :application/comment "")]))))))

(defn- field-value [field]
(case (:field/type field)
(:option :multiselect)
(localized (get (build-index [:key] :label (:field/options field))
(:field/value field)))

(:field/value field)))

(defn- render-field [field]
[:list
(doall
(for [event events
:when (not (#{:application.event/draft-saved} (:event/type event)))]
[:phrase
(localize-time (:event/time event))
" "
(localize-event event)
(let [comment (get event :application/comment)]
(when-not (empty? comment)
(str "\n"
(text :t.form/comment)
": "
comment)))
(when-let [attachments (seq (get event :event/attachments))]
(str "\n"
(text :t.form/attachments)
": "
(str/join ", " (map (comp filenames :attachment/id) attachments))))]))]))))

(defn- field-value [filenames field]
(let [value (:field/value field)]
(case (:field/type field)
(:option :multiselect)
(localized (get (build-index [:key] :label (:field/options field)) value))

:attachment
(if (empty? value)
value
(get filenames (Integer/parseInt value)))

(:field/value field))))

(def label-field-style {:spacing-before 8})
(def header-field-style {:spacing-before 8 :style :bold :size 15})
(def field-style {:spacing-before 8 :style :bold})

(defn- render-field [filenames field]
(when (:field/visible field)
(list
[:paragraph (case (:field/type field)
:label {}
:header {:style :bold :size 15}
{:style :bold})
:label label-field-style
:header header-field-style
field-style)
(localized (:field/title field))]
[:paragraph (field-value field)])))
[:paragraph (field-value filenames field)])))

(defn- render-fields [application]
(apply concat
(list [:heading heading-style (text :t.form/application)])
(for [form (getx application :application/forms)
field (getx form :form/fields)]
(render-field field))))
(let [filenames (attachment-filenames application)]
(list [:heading heading-style (text :t.form/application)]
(doall
(for [form (getx application :application/forms)
field (getx form :form/fields)]
(render-field filenames field))))))

(defn- render-license [license]
;; TODO license text?
Expand All @@ -95,9 +119,10 @@
(localized (:license/title license))])

(defn- render-licenses [application]
(concat (list [:heading heading-style (text :t.form/licenses)])
(for [license (getx application :application/licenses)]
(render-license license))))
(list [:heading heading-style (text :t.form/licenses)]
(doall
(for [license (getx application :application/licenses)]
(render-license license)))))

(defn- render-application [application]
[{}
Expand Down
9 changes: 5 additions & 4 deletions src/cljs/rems/application.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,11 @@
:application.command/assign-external-id [assign-external-id-button]
:application.command/close [close-action-button]
:application.command/copy-as-new [copy-as-new-button]]]
(distinct (for [[command action] (partition 2 commands-and-actions)
:when (contains? (:application/permissions application) command)]
action))))
(concat (distinct (for [[command action] (partition 2 commands-and-actions)
:when (contains? (:application/permissions application) command)]
action))
(list [pdf-button (:application/id application)]))))


(defn- actions-form [application]
(let [app-id (:application/id application)
Expand Down Expand Up @@ -795,7 +797,6 @@
attachment-success @(rf/subscribe [::attachment-success])
userid (:userid @(rf/subscribe [:user]))]
[:div.container-fluid
[:div {:class "float-right"} [pdf-button (:application/id application)]]
[document-title (str (text :t.applications/application)
(when application
(str " " (application-list/format-application-id config application)))
Expand Down
Loading

0 comments on commit 0628b49

Please sign in to comment.