]> git.ipfire.org Git - ipfire.org.git/commitdiff
wiki: Add detail page for files
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 19 Nov 2018 15:49:10 +0000 (15:49 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 19 Nov 2018 15:49:10 +0000 (15:49 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/backend/wiki.py
src/scss/style.scss
src/templates/wiki/files/detail.html [new file with mode: 0644]
src/templates/wiki/files/index.html
src/web/wiki.py

index 1e5d43cfc3681e80bc4e4a78a3dab9cc282f0332..0a9f77278f9c8b8b52405a103162ab5290a404fa 100644 (file)
@@ -268,6 +268,7 @@ templates_wiki_DATA = \
 templates_wikidir = $(templatesdir)/wiki
 
 templates_wiki_files_DATA = \
+       src/templates/wiki/files/detail.html \
        src/templates/wiki/files/index.html
 
 templates_wiki_filesdir = $(templates_wikidir)/files
index 3d105f7290fd25ef4ec8c7e498726e7918494dca..6defecbc202dc721f6bd50c3c90bf4c0e165f542 100644 (file)
@@ -328,6 +328,18 @@ class File(misc.Object):
        def size(self):
                return self.data.size
 
+       @lazy_property
+       def author(self):
+               if self.data.author_uid:
+                       return self.backend.accounts.get_by_uid(self.data.author_uid)
+
+       @property
+       def created_at(self):
+               return self.data.created_at
+
+       def is_pdf(self):
+               return self.mimetype in ("application/pdf", "application/x-pdf")
+
        def is_image(self):
                return self.mimetype.startswith("image/")
 
index 04e05d7dcb5538ab10bf8f7b6e9d1ceaa6d0decb..04d3ae822de5507338df950e979ae4b229cef831 100644 (file)
@@ -296,3 +296,8 @@ hr.divider {
                width: 100%;
        }
 }
+
+.pdf-viewer {
+       width: 100%;
+       min-height: 32rem;
+}
diff --git a/src/templates/wiki/files/detail.html b/src/templates/wiki/files/detail.html
new file mode 100644 (file)
index 0000000..f712d9f
--- /dev/null
@@ -0,0 +1,41 @@
+{% extends "../base.html" %}
+
+{% block title %}{{ file.filename }}{% end block %}
+
+{% block main %}
+       <div class="card mb-4">
+               <div class="card-body">
+                       {% if file.is_image() %}
+                               <img class="img-fluid img-thumbnail" src="{{ file.url }}?s=768" alt="{{ file.filename }}">
+                       {% elif file.is_pdf() %}
+                               <object class="pdf-viewer" data="{{ file.url }}"
+                                               title="{{ file.filename }}" type="{{ file.mimetype }}">
+                                       <p>
+                                               {{ _("This PDF attachment could not be displayed.") }}
+                                               <a href="{{ file.url }}">{{ _("Click here to download") }}</a>
+                                       </p>
+                               </object>
+                       {% end %}
+
+                       <a class="btn btn-primary btn-lg btn-block my-3" href="{{ file.url }}">
+                               <span class="fas fa-file-download"></span>
+                               {{ _("Download") }} ({{ format_size(file.size) }})
+                       </a>
+
+                       <dl class="row mb-0">
+                               <dt class="col-sm-3">{{ _("Filename") }}</dt>
+                               <dd class="col-sm-9">{{ file.filename }}</dd>
+
+                               {% if file.author %}
+                                       <dt class="col-sm-3">{{ _("Author") }}</dt>
+                                       <dd class="col-sm-9">
+                                               <a href="/users/{{ file.author.uid }}">{{ file.author }}</a>
+                                       </dd>
+                               {% end %}
+
+                               <dt class="col-sm-3">{{ _("Uploaded at") }}</dt>
+                               <dd class="col-sm-9">{{ locale.format_date(file.created_at) }}</dd>
+                       </dl>
+               </div>
+       </div>
+{% end block %}
index fa9c976ddeb386064aa29d3a984893ca17e05ff7..7f69724751e8c5f09091e337a24ae530c6308eeb 100644 (file)
                                                {% if f.is_image() %}
                                                        <div class="col-sm-6 col-md-4">
                                                                <figure class="figure">
-                                                                       <img class="figure-img img-fluid img-thumbnail" src="{{ f.url }}?s=256" alt="{{ f.filename }}">
-                                                                       <figcaption class="figure-caption">{{ f.filename }}</figcaption>
+                                                                       <a href="{{ f.url }}?action=detail">
+                                                                               <img class="figure-img img-fluid img-thumbnail" src="{{ f.url }}?s=256" alt="{{ f.filename }}">
+                                                                               <figcaption class="figure-caption">{{ f.filename }}</figcaption>
+                                                                       </a>
                                                                </figure>     
                                                        </div>
                                                {% end %}
@@ -39,7 +41,7 @@
                                                                        <span class="fas fa-file fa-fw"></span>
                                                                {% end %}
 
-                                                               <a href="{{ f.url }}">{{ f.filename }}</a>
+                                                               <a href="{{ f.url }}?action=detail">{{ f.filename }}</a>
                                                        </li>
                                                {% end %}
                                        {% end %}
index b8058427d6302c277ac4b4a676d58a11131e21e2..f02fce552b2336a706b650d2807857b411923ee4 100644 (file)
@@ -36,11 +36,20 @@ class FilesHandler(auth.CacheMixin, base.BaseHandler):
 
 
 class FileHandler(auth.CacheMixin, base.BaseHandler):
+       @property
+       def action(self):
+               return self.get_argument("action", None)
+
        def get(self, path):
                file = self.backend.wiki.get_file_by_path(path)
                if not file:
                        raise tornado.web.HTTPError(404, "Could not find %s" % path)
 
+               # Render detail page
+               if self.action == "detail":
+                       self.render("wiki/files/detail.html", file=file)
+                       return
+
                size = self.get_argument_int("s", None)
 
                # Check if image should be resized