changeset 177:397404473430

Polish and extend activity view to show activity per day.
author Daniele Nicolodi <daniele@grinta.net>
date Mon, 07 Nov 2011 01:45:20 +0100
parents 6b5fa909bce3
children 73e6b7bdd173
files src/ltpdarepo/static/style.css src/ltpdarepo/templates/activity.html src/ltpdarepo/views/browse.py
diffstat 3 files changed, 62 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/ltpdarepo/static/style.css	Mon Nov 07 01:45:16 2011 +0100
+++ b/src/ltpdarepo/static/style.css	Mon Nov 07 01:45:20 2011 +0100
@@ -295,8 +295,8 @@
 
 .activity {
     border: 1px solid #CCC;
+    margin: 0;
     padding: 2px;
-    margin: 0;
     box-shadow: 0px 0px 2px #DDD;
     -moz-box-shadow: 0px 0px 2px #DDD;
     -webkit-box-shadow: 0px 0px 2px #DDD;
@@ -304,38 +304,37 @@
 
 .activity table {
     width: 100%;
-    border-collapse: collapse;
 }
 
 .activity td {
-    margin: 0;
-    padding: 4px 0;
     border: none;
     font-size: 90%;
+    padding: 4px 0;
 }
 
-.activity td span.num {
+.activity .bars span {
     display: inline-block;
-    width: 2em;
-    visibility: hidden;
     font-size: 90%;
     padding: 2px 0;
+    visibility: hidden;
+    width: 2em;
 }
 
-.activity td:hover span.num {
+.activity td:hover span {
     visibility: visible;
-    color: red;
 }
 
-.activity td.bars {
+.activity .bars {
     padding: 0 1px;
     margin: 0;
     vertical-align: bottom;
 }
 
-.activity td div {
+.activity .bars a {
     background: #DDD;
     border-bottom: 2px solid #DDD;
+    cursor: default;
+    display: block;
     width: 100%;
 }
 
--- a/src/ltpdarepo/templates/activity.html	Mon Nov 07 01:45:16 2011 +0100
+++ b/src/ltpdarepo/templates/activity.html	Mon Nov 07 01:45:20 2011 +0100
@@ -2,28 +2,40 @@
 {% block title %}{{ database.id }}{% endblock %}
 {% block body %}
 <h2>Database &#x00AB;{{ database.id }}&#x00BB;</h2>
-<p class="discrete">{{ database.description }}</p>
-<p class="discrete">Objects submitted per day in <em>{{ curr.strftime('%B %Y') }}</em></p>
-<div class="wrapper">
-  <div class="monthes wrapper">
-    <a href="{{ url_for('browse.activity', database=database.id, date=prev) }}" title="{{ prev.strftime('%B %Y') }}">prev</a>
-    <a href="{{ url_for('browse.activity', database=database.id, date=next) }}" title="{{ next.strftime('%B %Y') }}">next</a>
+<p>{{ database.description }}</p>
+<p>&nbsp;</p>
+
+<div class="pagination wrapper">
+  <div class="count">
+    {% if span == 'MONTH' %}
+    {% set frmt = '%d' %}
+    <span>{{ curr.strftime('%B %Y') }}</span>
+    {% else %}
+    {% set frmt = '%H' %}
+    <span>{{ curr.strftime('%A %d %B %Y') }}</span>
+    <a href="{{ url_for('browse.activity', database=database.id, when=curr.strftime('%Y-%m')) }}">view month</a>
+    {% endif %}
+  </div>
+  <div class="monthes">
+    <a href="{{ url_for('browse.activity', database=database.id, when=prev) }}">prev</a>
+    <a href="{{ url_for('browse.activity', database=database.id, when=next) }}">next</a>
     <a href="{{ url_for('browse.activity', database=database.id) }}">today</a>
   </div>
 </div>
 <div class="activity" style="">
   <table>
     <tr>
-      {% for day, num in activity %}
-      {% set height = num * 300 / nmax %} 
+      {% for when, num in activity %}
+      {% set height = num * 300 / nmax %}
       <td class="bars" style="height: 300px;">
-        <span class="num">{{ num }}</span><div style="height: {{height}}px;">&nbsp;</div>
+        <span>{{ num }}</span><a href="{{ url_for('browse.activity', database=database.id, when=when.strftime('%Y-%m-%d')) }}" style="height: {{height}}px;"></a>
       </td>
       {% endfor %}
     </tr>
     <tr>
       {% for when, num in activity %}
-      <td><a class="day" href="{{ url_for('browse.query', database=database.id, field=('submitted', 'submitted'), operator=('>', '<'), value=(when, when + dt)) }}">{{ when.strftime('%d') }}</a></td>
+      {% set url = url_for('browse.query', database=database.id, field=('submitted', 'submitted'), operator=('>', '<'), value=(when, when + dt)) %}
+      <td><a class="day" href="{{ url }}">{{ when.strftime(frmt) }}</a></td>
       {% endfor %}
     </tr>
   </table>
--- a/src/ltpdarepo/views/browse.py	Mon Nov 07 01:45:16 2011 +0100
+++ b/src/ltpdarepo/views/browse.py	Mon Nov 07 01:45:20 2011 +0100
@@ -656,28 +656,48 @@
 
 
 @app.route('/<database>/activity')
+@app.route('/<database>/activity/<when>')
 @require('user')
-def activity(database, date=None):
+def activity(database, when=None):
     with view('database', database):
         db = Database().load(database)
         if db is None:
             # not found
             abort(404)
 
+        # defaults
         today = datetime.today().date()
-        date = request.args.get('date')
-        if date is not None:
-            today = datetime.strptime(date, '%Y-%m-%d').date()
+        span = 'MONTH'
+
+        if when is not None:
+            if when.count('-') == 2:
+                span = 'DAY'
+                today = datetime.strptime(when, '%Y-%m-%d').date()
+            if when.count('-') == 1:
+                span = 'MONTH'
+                today = datetime.strptime(when, '%Y-%m').date()
+                
 
-        begin = today + relativedelta(day=1)
-        end = begin + relativedelta(months=1, days=-1)
-        prev = begin + relativedelta(months=-1)
-        next = begin + relativedelta(months=+1)
+        if span == 'MONTH':
+            begin = today + relativedelta(day=1)
+            end = begin + relativedelta(months=1, days=-1)
+            prev = (begin + relativedelta(months=-1)).strftime('%Y-%m')
+            next = (begin + relativedelta(months=+1)).strftime('%Y-%m')
+            increment = 'DAY'
+            dt = relativedelta(days=1)
+            
+        if span == 'DAY':
+            begin = today + relativedelta(hour=0)
+            end = begin + relativedelta(hour=0, days=1)
+            prev = (begin + relativedelta(days=-1)).strftime('%Y-%m-%d')
+            next = (begin + relativedelta(days=+1)).strftime('%Y-%m-%d')
+            increment = 'HOUR'
+            dt = relativedelta(hours=1)
 
         curs = g.db.cursor()
 
         # prepare timeintervals table with proper intervals
-        curs.execute("""CALL makeintervals(%s, %s, 1, 'DAY')""", (begin, end))
+        curs.execute("""CALL makeintervals(%s, %s, 1, %s)""", (begin, end, increment))
 
         # collect number of objects for each interval
         curs.execute("""SELECT ts.begin AS date, COUNT(objmeta.obj_id) AS count
@@ -694,7 +714,7 @@
         nmax = ceil(nmax / base)*base
 
         return render_template('activity.html', database=db, activity=activity, nmax=nmax,
-                               curr=today, prev=prev, next=next, dt=relativedelta(days=1))
+                               curr=today, prev=prev, next=next, span=span, dt=dt)
 
 
 module = app