Browse Source

Create templates for browser resources; move main routes to separate
blueprint.

Stefano Cossu 6 years ago
parent
commit
8ca5f45f38

+ 29 - 0
lakesuperior/endpoints/main.py

@@ -0,0 +1,29 @@
+import logging
+
+from flask import Blueprint, render_template
+
+logger = logging.getLogger(__name__)
+
+# Blueprint for main pages. Not much here.
+
+main = Blueprint('main', __name__, template_folder='templates',
+        static_folder='../../static')
+
+## GENERIC ROUTES ##
+
+@main.route('/', methods=['GET'])
+def index():
+    '''
+    Homepage.
+    '''
+    return render_template('index.html')
+
+
+@main.route('/debug', methods=['GET'])
+def debug():
+    '''
+    Debug page.
+    '''
+    raise RuntimeError()
+
+

+ 24 - 0
lakesuperior/endpoints/templates/base.html

@@ -0,0 +1,24 @@
+<!doctype html>
+<html>
+    <head>
+        {% block head %}
+            <meta charset="utf-8">
+            <meta http-equiv="X-UA-Compatible" content="IE=edge">
+            <meta name="viewport" content="width=device-width, initial-scale=1">
+
+            <title>{% block title %}{% endblock %} :: LAKEsuperior</title>
+
+            <link href="{{url_for('ldp.static', filename='assets/css/bootstrap.min.css')}}" rel="stylesheet">
+        {% endblock %}
+    </head>
+    <body>
+        <div class="container">
+            <h1>{{ self.title() }}</h1>
+            {% block content %}{% endblock %}
+        </div>
+        <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
+        <script src="{{url_for('ldp.static', filename='assets/js/jquery-3.2.1.min.js')}}"></script>
+        <!-- Include all compiled plugins (below), or include individual files as needed -->
+        <script src="{{url_for('ldp.static', filename='assets/js/bootstrap.min.js')}}"></script>
+    </body>
+</html>

+ 8 - 0
lakesuperior/endpoints/templates/index.html

@@ -0,0 +1,8 @@
+{% extends 'base.html' %}
+{% block title %}LAKEsuperior :: Homepage{% endblock %}
+{% block content %}
+    <ul>
+        <li><a href='/ldp'>LDP REST endpoint</a></li>
+        <li><a href='/query'>Query endpoint</a></li>
+    </ul>
+{% endblock %}

+ 70 - 0
lakesuperior/endpoints/templates/resource.html

@@ -0,0 +1,70 @@
+{% extends 'base.html' %}
+{% block title %}{{ rsrc.identifier }}{% endblock %}
+{% block content %}
+<h2>Namespaces</h2>
+ <button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#nslist" aria-expanded="false" aria-controls="nsList">
+    Expand/Collapse
+</button>
+<div class="collapse" id="nslist">
+    <div class="card card-body">
+        <table class="table table-striped">
+            <thead>
+                <tr>
+                    <td>Prefix</td>
+                    <td>URI</td>
+                </tr>
+            </thead>
+            <tbody>
+            {% for ns in nsm.namespaces() | sort %}
+                <tr>
+                    <td>{{ ns[0] }}</td>
+                    <td>{{ ns[1] }}</td>
+                </tr>
+            {% endfor %}
+            </tbody>
+        </table>
+    </div>
+</div>
+<h2>Resource</h2>
+<table class="table table-striped">
+    <thead>
+        <tr>
+            <!--
+            <td>Subject</td>
+            -->
+            <td>Predicate</td>
+            <td>Object</td>
+        </tr>
+    </thead>
+    <tbody>
+    {% for t in rsrc.graph | sort %}
+        <tr>
+            <!--
+            <td>
+                <a href="{{ t[0] }}">
+                    {{ t[0].n3(namespace_manager=nsm) }}
+                </a>
+            </td>
+            -->
+            <td>
+                <a href="{{ t[1] }}">
+                    {{ t[1].n3(namespace_manager=nsm) }}
+                </a>
+            </td>
+            <td>
+            {% if 'Literal' in t[2].__class__.__name__ %}
+            "{{ t[2] }}"
+            {% if t[2].datatype %}
+            <span class="label label-primary">{{ t[2].datatype.n3(namespace_manager=nsm) }}</span>
+            {% endif %}
+            {% else %}
+                <a href="{{ t[2] }}">
+                    {{ t[2].n3(namespace_manager=nsm) }}
+                </a>
+            {% endif %}
+            </td>
+        </tr>
+    {% endfor %}
+    </tbody>
+</table>
+{% endblock %}

+ 0 - 2
lakesuperior/store_layouts/ldp_rs/simple_layout.py

@@ -1,8 +1,6 @@
 from copy import deepcopy
 from pprint import pformat
 
-import arrow
-
 from flask import current_app, request
 from rdflib import Graph
 from rdflib.namespace import RDF, XSD