Merge branch 'feature/31' into develop

This commit is contained in:
Simon Brooke 2017-09-10 22:56:58 +01:00
commit 656d503128
6 changed files with 39 additions and 21 deletions

View file

@ -75,6 +75,8 @@
:email-prompt "Email address" ;; text of the email widget prompt on edit user page
:file-or-directory "File or directory"
;; used in sanity check report
:file-summary-prompt "Description/what's changed"
;; prompt for the file upload summary input
:file-upload-link-text "You may link to this file using a link of the form"
;; Text introducing the link to an uploaded file
:file-upload-prompt "File to upload" ;; prompt string for the file upload widget

View file

@ -209,6 +209,10 @@ th {
display: block;
}
#uploaded-image {
float: right;
}
.change {
background-color: rgb( 223, 223, 223);
border: thin solid silver;

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View file

@ -3,12 +3,12 @@
<div id="content" class="auth">
{% if uploaded %}
{% if is-image %}
<img alt="Uploaded image" src="uploads/{{uploaded}}"/>
<p>
<img id="uploaded-image" alt="Uploaded image" src="content/uploads/{{uploaded}}"/>
{% i18n file-upload-link-text %}:
<code>![Uploaded image](uploads/{{uploaded}})</code>
<code>![Uploaded image](content/uploads/{{uploaded}})</code>
</p>
{% else %}
<p>
@ -24,6 +24,10 @@
<label for="upload">{% i18n file-upload-prompt %}</label>
<input name="upload" id="upload" type="file" required/>
</p>
<p class="widget">
<label for="summary">{% i18n file-summary-prompt %}</label>
<input name="summary" id="summary" type="text" required/>
</p>
<p class="widget">
<label for="submit">{% i18n save-prompt %}</label>
<input name="submit" id="submit" type="submit" class="action" value="{% i18n save-label %}"/>

View file

@ -156,9 +156,17 @@
"Render a form to allow the upload of a file."
[request]
(let [params (keywordize-keys (:params request))
data-path (str (io/resource-path) "/uploads/")
data-path (str (io/resource-path) "/content/uploads/")
git-repo (get-git-repo)
upload (:upload params)
uploaded (if upload (ul/store-upload params))]
uploaded (if upload (ul/store-upload params data-path))
user (session/get :user)
summary (format "%s: %s" user (or (:summary params) "no summary"))]
(if
uploaded
(do
(git/git-add git-repo uploaded)
(git/git-commit git-repo summary {:name user :email (auth/get-email user)})))
(layout/render "upload.html"
(merge (util/standard-params request)
{:title (util/get-message :file-upload-title request)

View file

@ -29,19 +29,20 @@
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn avoid-name-collisions
"Find a filename within this `path`, based on this `file-name`, that does not
reference an existing file. It is assumed that `path` ends with a path separator.
Returns a filename hwich does not currently reference a file within the path."
[path file-name]
(if (.exists (File. (str path file-name)))
(let [parts (cs/split file-name #"\.")
prefix (cs/join "." (butlast parts))
suffix (last parts)]
(first
(filter #(not (.exists (File. (str path %))))
(map #(str prefix "." % "." suffix) (range)))))
file-name))
;; No longer used as uploaded files now go into Git.
;; (defn avoid-name-collisions
;; "Find a filename within this `path`, based on this `file-name`, that does not
;; reference an existing file. It is assumed that `path` ends with a path separator.
;; Returns a filename hwich does not currently reference a file within the path."
;; [path file-name]
;; (if (.exists (File. (str path file-name)))
;; (let [parts (cs/split file-name #"\.")
;; prefix (cs/join "." (butlast parts))
;; suffix (last parts)]
;; (first
;; (filter #(not (.exists (File. (str path %))))
;; (map #(str prefix "." % "." suffix) (range)))))
;; file-name))
(defn store-upload
@ -49,11 +50,10 @@
The issue with storing an upload is moving it into place.
If `params` are passed as a map, it is expected that this is a map from
an HTTP POST operation of a form with type `multipart/form-data`."
[params]
[params path]
(let [upload (:upload params)
tmp-file (:tempfile upload)
path (str (io/resource-path) "uploads/")
filename (avoid-name-collisions path (:filename upload))]
filename (:filename upload)]
(timbre/info
(str "Storing upload file: " upload))
(if tmp-file