Permalink
Browse files

Add switch.date_modified and FE imrovements using date modified and c…

…reated.

Summary:
* Add date_modified column.
* Add relative date since last modified/created.
* Update the UI to support filtering by date_[created,modified] and label.

Maniphest T268

Test Plan:
Fire up the front end and check it out.  Run the current tests to see
they don't break.

Reviewers: dcramer

Reviewed By: dcramer

CC: dcramer, jeff

Differential Revision: http://phabricator.local.disqus.net/D531
  • Loading branch information...
1 parent 1787036 commit 6edea9e676a98064566780d5b935ed1787fdad26 @Fluxx Fluxx committed Jan 26, 2012
View
@@ -4,3 +4,4 @@
dist/
build/
*.egg/
+.arcconfig
View
Binary file not shown.
@@ -27,6 +27,52 @@
float: right;
}
+#container div.toolbar ul.sort {
+ float: right;
+ list-style: none;
+ padding: 10px 20px 10px 0;
+ margin: 0 20px 0 0;
+ border-right: 1px solid #EAEAEA;
+}
+
+#container div.toolbar ul.sort li {
+ display: inline-block;
+}
+
+#container div.toolbar ul.sort li a {
+ color: #999;
+ display: block;
+}
+
+#container div.toolbar ul.sort li + li {
+ margin-left: 10px;
+}
+
+#container div.toolbar[data-sort=-label] ul.sort li.label a,
+#container div.toolbar[data-sort=-date_created] ul.sort li.date_created a,
+#container div.toolbar[data-sort=-date_modified] ul.sort li.date_modified a,
+#container div.toolbar[data-sort=label] ul.sort li.label a,
+#container div.toolbar[data-sort=date_created] ul.sort li.date_created a,
+#container div.toolbar[data-sort=date_modified] ul.sort li.date_modified a,
+#container div.toolbar[data-sort=""] ul.sort li.date_modified a {
+ color: #000;
+ font-weight: bold;
+}
+
+#container div.toolbar[data-sort=-label] ul.sort li.label a:after,
+#container div.toolbar[data-sort=-date_created] ul.sort li.date_created a:after,
+#container div.toolbar[data-sort=-date_modified] ul.sort li.date_modified a:after {
+ content: "";
+}
+
+#container div.toolbar[data-sort=label] ul.sort li.label a:after,
+#container div.toolbar[data-sort=date_created] ul.sort li.date_created a:after,
+#container div.toolbar[data-sort=date_modified] ul.sort li.date_modified a:after,
+#container div.toolbar[data-sort=""] ul.sort li.date_modified a:after {
+ content: "";
+}
+
+
#container div.toolbar span.search input {
width: 200px;
padding: 6px;
@@ -70,6 +116,13 @@
font-family: "Inconsolata", arial;
}
+#container table.switches td.name h5 {
+ color: #777;
+ font-size: 50%;
+ font-weight: normal;
+ margin: 0.5em 0 0 0;
+}
+
#container table.switches td.name p {
color: #666;
margin: 10px 0 0 0;
@@ -0,0 +1,34 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Adding field 'Switch.date_modified'
+ db.add_column('gargoyle_switch', 'date_modified', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now), keep_default=False)
+
+
+ def backwards(self, orm):
+
+ # Deleting field 'Switch.date_modified'
+ db.delete_column('gargoyle_switch', 'date_modified')
+
+
+ models = {
+ 'gargoyle.switch': {
+ 'Meta': {'object_name': 'Switch'},
+ 'date_created': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'date_modified': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'description': ('django.db.models.fields.TextField', [], {'null': 'True'}),
+ 'key': ('django.db.models.fields.CharField', [], {'max_length': '32', 'primary_key': 'True'}),
+ 'label': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True'}),
+ 'status': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '1'}),
+ 'value': ('jsonfield.fields.JSONField', [], {'default': "'{}'"})
+ }
+ }
+
+ complete_apps = ['gargoyle']
View
@@ -57,6 +57,7 @@ class Switch(models.Model):
value = JSONField(default="{}")
label = models.CharField(max_length=32, null=True)
date_created = models.DateTimeField(default=datetime.datetime.now)
+ date_modified = models.DateTimeField(default=datetime.datetime.now)
description = models.TextField(null=True)
status = models.PositiveSmallIntegerField(default=DISABLED, choices=STATUS_CHOICES)
@@ -99,6 +100,8 @@ def to_dict(self, manager):
'statusLabel': self.get_status_label(),
'label': self.label or self.key.title(),
'description': self.description,
+ 'date_modified': self.date_modified,
+ 'date_created': self.date_created,
'conditions': [],
}
View
@@ -12,7 +12,7 @@
from functools import wraps
from django.conf import settings
-from django.http import HttpResponse
+from django.http import HttpResponse, HttpResponseNotFound
from django.utils import simplejson
from gargoyle import gargoyle, autodiscover
@@ -101,11 +101,17 @@ def render_on_dashboard(self, request):
})
def index(self, request):
- switches = list(Switch.objects.all().order_by('label'))
+ sort_by = request.GET.get('by', '-date_modified')
+
+ if sort_by not in self.valid_sort_orders:
+ return HttpResponseNotFound('Invalid sort order.')
+
+ switches = list(Switch.objects.all().order_by(sort_by))
return self.render_to_response("gargoyle/index.html", {
"switches": [s.to_dict(gargoyle) for s in switches],
"all_conditions": list(gargoyle.get_all_conditions()),
+ "sorted_by": sort_by
}, request)
def add(self, request):
@@ -247,4 +253,9 @@ def remove_condition(self, request):
return switch.to_dict(gargoyle)
remove_condition = json(remove_condition)
+ @property
+ def valid_sort_orders(self):
+ fields = ['label', 'date_created', 'date_modified']
+ return fields + ['-' + f for f in fields]
+
nexus.site.register(GargoyleModule, 'gargoyle')
@@ -27,7 +27,7 @@
{% endblock %}
{% block content %}
- <div class="toolbar">
+ <div class="toolbar" data-sort="{{ sorted_by }}">
<button class="button addSwitch">Add a Switch</button>
<!--
@@ -39,6 +39,18 @@
<span class="search">
<input type="text" placeholder="search">
</span>
+
+ <ul class="sort">
+ <li class="date_created">
+ <a href="?by={{'date_created'|sort_by_key:sorted_by}}">Date Created</a>
+ </li>
+ <li class="date_modified">
+ <a href="?by={{'date_modified'|sort_by_key:sorted_by}}">Date Modified</a>
+ </li>
+ <li class="label">
+ <a href="?by={{'label'|sort_by_key:sorted_by}}">Label</a>
+ </li>
+ </ul>
</div>
<div class="noSwitches" {% if switches %}style="display:none;"{% endif %}>
@@ -50,6 +62,13 @@
<tr data-switch-key="{{ switch.key }}" data-switch-name="{{ switch.label }}" data-switch-desc="{{ switch.description }}" class="collapsed">
<td class="name">
<h4>{% if switch.label %}{{ switch.label }}{% else %}{{ switch.key|title }}{% endif %} <small class="command">({{ switch.key }})</small></h4>
+ <h5>
+ {% if sorted_by|sort_field == 'date_created' %}
+ Created {{ switch.date_created|timesince }} ago
+ {% else %}
+ Last modified {{ switch.date_created|timesince }} ago
+ {% endif %}
+ </h5>
<div class="inner">
{% if switch.description %}
<p>{{ switch.description }}</p>
@@ -40,3 +40,22 @@ def raw(parser, token):
def render_field(field, value=None):
return field.render(value)
render_field = register.filter(render_field)
+
+
+def sort_by_key(field, currently):
+ is_negative = currently.find('-') is 0
+ current_field = currently.lstrip('-')
+
+ if current_field == field and is_negative:
+ return field
+ elif current_field == field:
+ return '-' + field
+ else:
+ return field
+
+sort_by_key = register.filter(sort_by_key)
+
+def sort_field(sort_string):
+ return sort_string.lstrip('-')
+
+sort_field = register.filter(sort_field)

0 comments on commit 6edea9e

Please sign in to comment.