Merge pull request #1825 from C-Otto/sort-containers

Sort containers
This commit is contained in:
Matt Rogers 2015-08-07 20:35:54 -04:00
commit 50421fc19b
8 changed files with 63 additions and 13 deletions

View file

@ -184,5 +184,21 @@ var TracksPages = {
/* fade flashes and alerts in automatically */
$(".alert").fadeOut(8000);
}, sort_container: function(container) {
function comparator(a, b) {
var contentA = $(a).attr('data-sort') || '';
var contentB = $(b).attr('data-sort') || '';
if (contentA > contentB) {
return 1;
}
if (contentB > contentA) {
return -1;
}
return 0;
}
var unsortedActions = container.children();
var sortedChildren = unsortedActions.sort(comparator);
container.append(sortedChildren);
}
};

View file

@ -365,6 +365,18 @@ module TodosHelper
text_field_tag name, value, {"size" => 12, "id" => id, "class" => "Date", "autocomplete" => "off"}.update(options.stringify_keys)
end
def sort_key(todo)
# actions are sorted using {order("todos.due IS NULL, todos.due ASC, todos.created_at ASC")}
# the JavaScript frontend sorts using unicode/ascii
format = "%Y%m%d%H%M%S%L"
if todo.due?
sort_by_due = todo.due.strftime format
else
sort_by_due = "Z" * 17 # length of format string
end
sort_by_due + todo.created_at.strftime(format)
end
# === helpers for default layout
def default_contexts_for_autocomplete

View file

@ -12,7 +12,7 @@ parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
# also make different caches per source_view to handle difference in showing [C] and [P]
cache [todo, current_user.date.strftime("%Y%m%d"), @source_view, current_user.prefs.verbose_action_descriptors] do
%>
<div id="<%= dom_id(todo) %>" class="item-container">
<div id="<%= dom_id(todo) %>" class="item-container" data-sort="<%= sort_key(todo) %>">
<div id="<%= dom_id(todo, 'line') %>" class="item-show">
<%= remote_star_icon(todo) %>
<%= remote_toggle_checkbox(todo) %>

View file

@ -29,7 +29,9 @@ remove_todo: function(next_steps) {
});
},
add_to_existing_container: function(next_steps) {
$('#<%= item_container_id(@todo) %>_items').append(<%=object_name%>.html_for_todo());
var container = $('#<%= item_container_id(@todo) %>_items');
container.append(<%=object_name%>.html_for_todo());
TracksPages.sort_container(container);
<% if source_view_is_one_of(:calendar) -%>
next_steps.go();
<% if (@target_context_count==1) || ( (@todo.deferred? || @todo.pending?) && @remaining_deferred_or_pending_count == 1) -%>
@ -55,7 +57,8 @@ add_to_existing_container: function(next_steps) {
<% end -%>
},
replace_todo: function(next_steps) {
$('#<%= dom_id(@todo) %>').html(<%=object_name%>.html_for_todo());
$('#<%= dom_id(@todo) %>').replaceWith(<%=object_name%>.html_for_todo());
TracksPages.sort_container($('#<%= item_container_id(@todo) %>_items'));
next_steps.go();
},
hide_container: function(next_steps) {

View file

@ -49,7 +49,10 @@
function add_todo_to_existing_container(next_steps) {
$('#<%= empty_container_msg_div_id %>').hide();
$('#<%= item_container_id(@todo) %>_items').append(html_for_new_todo());
var container = $('#<%= item_container_id(@todo) %>_items');
container.append(html_for_new_todo());
TracksPages.sort_container(container);
$('#<%= item_container_id(@todo) %>').slideDown(500, function() {
$('#<%= dom_id(@todo) %>').effect('highlight', {}, 2000 );
next_steps.go();

View file

@ -54,7 +54,9 @@ function show_new_todo_if_todo_was_recurring() {
<% if @todo.from_recurring_todo? -%>
<% unless @new_recurring_todo.nil? || @new_recurring_todo.deferred? -%>
TodoItemsContainer.ensureVisibleWithEffectAppear("<%=item_container_id(@new_recurring_todo)%>");
$('#<%=item_container_id(@new_recurring_todo)%>_items').append(html_for_new_recurring_todo());
var container = $('#<%=item_container_id(@new_recurring_todo)%>_items');
container.append(html_for_new_recurring_todo());
TracksPages.sort_container(container);
$('#<%= dom_id(@new_recurring_todo, 'line')%>').effect('highlight', {}, 2000 );
TracksPages.page_inform("<%=t('todos.recurring_action_deleted')%>");
<% else -%>
@ -75,11 +77,15 @@ function activate_pending_todos() {
if source_view_is_one_of(:project,:tag) -%>
$('#<%= dom_id(t) %>').fadeOut(400, function() {
$('#<%= dom_id(t) %>').remove();
$('#<%= item_container_id(t) %>_items').append("<%= html %>");
var container = $('#<%= item_container_id(t) %>_items');
container.append("<%= html %>");
TracksPages.sort_container(container);
<%= "$('#deferred_pending_container-empty-d').show();".html_safe if @remaining_deferred_or_pending_count==0 -%>
});
<% else -%>
$('#<%= item_container_id(t) %>_items').append("<%= html%>");
var container = $('#<%= item_container_id(t) %>_items');
container.append("<%= html%>");
TracksPages.sort_container(container);
<% end -%>
TodoItems.highlight_todo('#<%= dom_id(t, 'line')%>');
<% end -%>

View file

@ -10,7 +10,7 @@
<% end -%>
function replace_updated_predecessor() {
$('#<%= dom_id(@predecessor) %>').html( html_for_predecessor() );
$('#<%= dom_id(@predecessor) %>').replaceWith( html_for_predecessor() );
}
function regenerate_predecessor_family() {
@ -33,7 +33,9 @@ function update_successor() {
$('#c<%= @successor.context_id %>').fadeIn(500, function() {});
$('#no_todos_in_view').slideUp(100);
<% end -%>
$('#<%=item_container_id(@successor)%>').append(html_for_new_successor());
var container = $('#<%=item_container_id(@successor)%>_items');
container.append(html_for_new_successor());
TracksPages.sort_container(container);
$('#<%= dom_id(@successor, 'line')%>').effect('highlight', {}, 2000 ); <%
elsif @successor.deferred? -%>
$('#<%= dom_id(@successor)%>').html(html_for_new_successor()); <%

View file

@ -64,7 +64,9 @@ var <%= object_name %> = {
next_steps.go();
},
add_todo_to_container: function(next_steps) {
$('#<%= item_container_id(@todo) %>_items').append(<%=object_name%>.html_for_todo());
var container = $('#<%= item_container_id(@todo) %>_items');
container.append(<%=object_name%>.html_for_todo());
TracksPages.sort_container(container);
<% if should_make_context_visible -%>
$('#<%= item_container_id(@todo) %>').slideDown(500, function() {
$("#<%= empty_container_msg_div_id %>").slideUp(100);
@ -82,7 +84,9 @@ var <%= object_name %> = {
<% # show new todo if the completed todo was recurring
if @todo.from_recurring_todo?
unless @new_recurring_todo.nil? || (@new_recurring_todo.deferred? && !source_view_is(:deferred)) -%>
$('#<%= item_container_id(@new_recurring_todo) %>_items').append(<%=object_name%>.html_for_recurring_todo());
var container = $('#<%= item_container_id(@new_recurring_todo) %>_items');
conainer.append(<%=object_name%>.html_for_recurring_todo());
TracksPages.sort_container(container);
$('#c<%= @new_recurring_todo.context_id %>').slideDown(500, function() {
<%=object_name%>.highlight_updated_recurring_todo(next_steps);
});
@ -123,11 +127,15 @@ var <%= object_name %> = {
if source_view_is_one_of(:project,:tag) -%>
$('#<%= dom_id(t) %>').slideUp(400, function() {
$('#<%= dom_id(t) %>').remove();
$('#<%= item_container_id(t) %>_items').append("<%= html %>");
var container = $('#<%= item_container_id(t) %>_items');
container.append("<%= html %>");
TracksPages.sort_container(container);
<%= "$('#deferred_pending_container-empty-d').show();".html_safe if @remaining_deferred_or_pending_count==0 -%>
});
<% else -%>
$('#<%= item_container_id(t) %>_items').append("<%= html%>");
var container = $('#<%= item_container_id(t) %>_items');
container.append("<%= html%>");
TracksPages.sort_container(container);
<% end -%>
TodoItems.highlight_todo('#<%= dom_id(t)%>');
<% end -%>