Mercurial > wikked
changeset 280:ca5a466412c1
Fix the wiki history page, better separation of concerns.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 26 Sep 2014 16:33:10 -0700 |
parents | b9c591b3a2c5 |
children | 163ba52e7b84 |
files | wikked/assets/css/wikked/main.less wikked/assets/js/wikked/models.js wikked/assets/js/wikked/views.js wikked/assets/tpl/special-changes.html wikked/views/history.py |
diffstat | 5 files changed, 80 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/wikked/assets/css/wikked/main.less Fri Sep 26 16:32:20 2014 -0700 +++ b/wikked/assets/css/wikked/main.less Fri Sep 26 16:33:10 2014 -0700 @@ -90,6 +90,32 @@ } } +.pure-dl-horizontal { + dt { + float: left; + clear: left; + width: 10em; + text-align: right; + font-weight: bold; + } + dd { + margin-left: 11em; + } + dd:before, dd:after { + display: table; + content: " "; + } + dd:after { + clear: both; + } +} + +.pure-ul-unstyled { + margin: 0; + padding-left: 0; + list-style: none outside none; +} + .wiki-icon { font-weight: bolder; }
--- a/wikked/assets/js/wikked/models.js Fri Sep 26 16:32:20 2014 -0700 +++ b/wikked/assets/js/wikked/models.js Fri Sep 26 16:33:10 2014 -0700 @@ -480,7 +480,31 @@ var SpecialChangesModel = exports.SpecialChangesModel = SpecialPageModel.extend({ title: "Wiki History", - url: '/api/history' + url: '/api/history', + initialize: function() { + SpecialChangesModel.__super__.initialize.apply(this, arguments); + this.on('change:history', this._onHistoryChanged); + }, + _onHistoryChanged: function(model, history) { + for (var i = 0; i < history.length; ++i) { + var rev = history[i]; + rev.collapsed = (rev.pages.length > 3); + for (var j = 0; j < rev.pages.length; ++j) { + var page = rev.pages[j]; + switch (page.action) { + case 'edit': + page.action_label = 'edit'; + break; + case 'add': + page.action_label = 'added'; + break; + case 'delete': + page.action_label = 'deleted'; + break; + } + } + } + } }); var SpecialOrphansModel = exports.SpecialOrphansModel = SpecialPageModel.extend({
--- a/wikked/assets/js/wikked/views.js Fri Sep 26 16:32:20 2014 -0700 +++ b/wikked/assets/js/wikked/views.js Fri Sep 26 16:33:10 2014 -0700 @@ -613,39 +613,23 @@ return; } - this.$('.history-list .page-details').hide(); - this.$('.history-list .page-details-toggler').click(function (e) { - index = $(this).attr('data-index'); - $('.history-list .page-details-' + index).toggle(); + this.$('.wiki-history .wiki-history-entry-details').hide(); + this.$('.wiki-history .wiki-history-entry-collapser').click(function(e) { + var btn = $(this); + index = btn.attr('data-index'); + var tgt = $('.wiki-history .wiki-history-entry-details-' + index); + tgt.toggle(); + if (tgt.is(':visible')) { + $('.glyphicon', btn).removeClass('glyphicon-chevron-down'); + $('.glyphicon', btn).addClass('glyphicon-chevron-up'); + $('small', btn).html('Hide'); + } else { + $('.glyphicon', btn).removeClass('glyphicon-chevron-up'); + $('.glyphicon', btn).addClass('glyphicon-chevron-down'); + $('small', btn).html('Show'); + } e.preventDefault(); }); - }, - _onModelChange: function() { - var history = this.model.get('history'); - if (history) { - for (var i = 0; i < history.length; ++i) { - var rev = history[i]; - rev.changes = []; - for (var j = 0; j < rev.pages.length; ++j) { - var page = rev.pages[j]; - switch (page.action) { - case 'edit': - rev.changes.push({ is_edit: true, url: page.url }); - break; - case 'add': - rev.changes.push({ is_add: true, url: page.url }); - break; - case 'delete': - rev.changes.push({ is_delete: true, url: page.url }); - break; - } - rev.pages[j] = page; - } - history[i] = rev; - } - this.model.set('history', history); - } - SpecialChangesView.__super__._onModelChange.apply(this, arguments); } });
--- a/wikked/assets/tpl/special-changes.html Fri Sep 26 16:32:20 2014 -0700 +++ b/wikked/assets/tpl/special-changes.html Fri Sep 26 16:33:10 2014 -0700 @@ -5,7 +5,7 @@ <section> <p>Here are the recent changes on this wiki.</p> <form> - <table class="table table-hover history-list"> + <table class="pure-table pure-table-bordered wiki-history"> <thead> <tr> <th>Revision</th> @@ -14,31 +14,32 @@ </thead> <tbody> {{#eachr history}} - <tr class='history-entry'> - <td>{{rev_name}}</td> + <tr class='wiki-history-entry'> + <td><code>{{rev_name}}</code></td> <td> - <dl class="dl-horizontal"> + <dl class="pure-dl-horizontal"> <dt>Date</dt> <dd>{{date_from_now timestamp}}</dd> <dt>Author</dt> <dd>{{author}}</dd> <dt>Pages ({{num_pages}})</dt> <dd> - {{#if make_collapsable}} - <button class="btn page-details-toggler" data-index="{{index}}">Show/Hide</button> - <div class="page-details page-details-{{index}}"> + {{#if collapsed}} + <button class="pure-button wiki-history-entry-collapser" data-index="{{index}}"> + <span class="glyphicon glyphicon-chevron-down"></span> + <small>Show</small> + </button> + <div class="wiki-history-entry-details wiki-history-entry-details-{{index}}"> {{/if}} - <ul class="unstyled"> - {{#each changes}} + <ul class="pure-ul-unstyled"> + {{#each pages}} <li> <a href="#/revision{{url}}/{{../rev_id}}">{{url}}</a> - {{#if is_edit}}(edit) {{/if}} - {{#if is_add}}(added) {{/if}} - {{#if is_delete}}(deleted) {{/if}} + {{action_label}} </li> {{/each}} </ul> - {{#if make_collapsable}} + {{#if collapsed}} </div> {{/if}} </dd>
--- a/wikked/views/history.py Fri Sep 26 16:32:20 2014 -0700 +++ b/wikked/views/history.py Fri Sep 26 16:33:10 2014 -0700 @@ -45,7 +45,6 @@ 'action': ACTION_NAMES[f['action']] }) rev_data['num_pages'] = len(rev_data['pages']) - rev_data['make_collapsable'] = len(rev_data['pages']) > 1 if len(rev_data['pages']) > 0: hist_data.append(rev_data) else: