mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-17 06:35:28 +01:00
fix #603. Group context by hidden state in context view
This commit is contained in:
parent
aeb9a1fda6
commit
183523f45a
5 changed files with 60 additions and 37 deletions
|
|
@ -10,7 +10,11 @@ class ContextsController < ApplicationController
|
|||
session :off, :only => :index, :if => Proc.new { |req| ['rss','atom','txt'].include?(req.parameters[:format]) }
|
||||
|
||||
def index
|
||||
@contexts = current_user.contexts(true) #true is passed here to force an immediate load so that size and empty? checks later don't result in separate SQL queries
|
||||
# #true is passed here to force an immediate load so that size and empty?
|
||||
# checks later don't result in separate SQL queries
|
||||
@active_contexts = current_user.contexts.active(true)
|
||||
@hidden_contexts = current_user.contexts.hidden(true)
|
||||
@count = @active_contexts.size + @hidden_contexts.size
|
||||
init_not_done_counts(['context'])
|
||||
respond_to do |format|
|
||||
format.html &render_contexts_html
|
||||
|
|
@ -44,7 +48,7 @@ class ContextsController < ApplicationController
|
|||
# -u username:password
|
||||
# -d '<request><context><name>new context_name</name></context></request>'
|
||||
# http://our.tracks.host/contexts
|
||||
#
|
||||
#
|
||||
def create
|
||||
if params[:format] == 'application/xml' && params['exception']
|
||||
render_failure "Expected post format is valid xml like so: <request><context><name>context name</name></context></request>.", 400
|
||||
|
|
@ -75,16 +79,21 @@ class ContextsController < ApplicationController
|
|||
end
|
||||
|
||||
# Edit the details of the context
|
||||
#
|
||||
#
|
||||
def update
|
||||
params['context'] ||= {}
|
||||
success_text = if params['field'] == 'name' && params['value']
|
||||
params['context']['id'] = params['id']
|
||||
params['context']['name'] = params['value']
|
||||
end
|
||||
|
||||
@original_context_hidden = @context.hidden?
|
||||
@context.attributes = params["context"]
|
||||
|
||||
if @context.save
|
||||
if boolean_param('wants_render')
|
||||
@context_state_changed = (@orgininal_context_hidden != @context.hidden?)
|
||||
@new_state = (@context.hidden? ? "hidden" : "active") if @context_state_changed
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -113,9 +122,10 @@ class ContextsController < ApplicationController
|
|||
end
|
||||
|
||||
# Methods for changing the sort order of the contexts in the list
|
||||
#
|
||||
#
|
||||
def order
|
||||
params["list-contexts"].each_with_index do |id, position|
|
||||
list = params["list-contexts-hidden"] || params["list-contexts-active"]
|
||||
list.each_with_index do |id, position|
|
||||
current_user.contexts.update(id, :position => position + 1)
|
||||
end
|
||||
render :nothing => true
|
||||
|
|
@ -126,8 +136,10 @@ class ContextsController < ApplicationController
|
|||
def render_contexts_html
|
||||
lambda do
|
||||
@page_title = "TRACKS::List Contexts"
|
||||
@no_contexts = @contexts.empty?
|
||||
@count = @contexts.size
|
||||
@no_active_contexts = @active_contexts.empty?
|
||||
@no_hidden_contexts = @hidden_contexts.empty?
|
||||
@active_count = @active_contexts.size
|
||||
@hidden_count = @hidden_contexts.size
|
||||
render
|
||||
end
|
||||
end
|
||||
|
|
|
|||
9
app/views/contexts/_context_state_group.rhtml
Normal file
9
app/views/contexts/_context_state_group.rhtml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<div class="list-stategroup-contexts-container">
|
||||
<h2><span id="<%= state %>-contexts-count" class="badge"><%= context_state_group.length %></span><%= state.titlecase %> Contexts</h2>
|
||||
<div id="<%= state%>-contexts-empty-nd" style="<%= no_contexts ? 'display:block' : 'display:none'%>">
|
||||
<div class="message"><p>Currently there are no <%= state %> contexts</p></div>
|
||||
</div>
|
||||
<div id="list-contexts-<%= state %>">
|
||||
<%= render :partial => 'context_listing', :collection => context_state_group %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -1,44 +1,38 @@
|
|||
<div id="display_box">
|
||||
<div id="list-contexts-container">
|
||||
<div id="contexts-empty-nd" style="<%= @no_contexts ? 'display:block' : 'display:none'%>">
|
||||
<div class="message"><p>Currently there are no contexts</p></div>
|
||||
</div>
|
||||
<div id="list-contexts">
|
||||
<%= render :partial => 'context_listing', :collection => @contexts %>
|
||||
</div>
|
||||
</div>
|
||||
<%= render :partial => 'context_state_group', :object => @active_contexts, :locals => { :state => 'active', :no_contexts => @no_active_contexts} %>
|
||||
<%= render :partial => 'context_state_group', :object => @hidden_contexts, :locals => { :state => 'hidden', :no_contexts => @no_hidden_contexts} %>
|
||||
</div>
|
||||
|
||||
<div id="input_box">
|
||||
<div id="context_new_container">
|
||||
|
||||
|
||||
<div id="toggle_context_new" class="hide_form">
|
||||
<a title="Hide new context form" accesskey="n">« Hide form</a>
|
||||
<% apply_behavior '#toggle_context_new a:click', :prevent_default => true do |page|
|
||||
page << "TracksForm.toggle('toggle_context_new', 'context_new', 'context-form',
|
||||
'« Hide form', 'Hide new context form',
|
||||
'Create a new context »', 'Add a context');"
|
||||
end
|
||||
%>
|
||||
page << "TracksForm.toggle('toggle_context_new', 'context_new', 'context-form',
|
||||
'« Hide form', 'Hide new context form',
|
||||
'Create a new context »', 'Add a context');"
|
||||
end
|
||||
%>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="context_new" class="context_new" style="display:block">
|
||||
<% form_remote_tag(
|
||||
:url => contexts_path,
|
||||
:method => :post,
|
||||
:url => contexts_path,
|
||||
:method => :post,
|
||||
:html=> { :id => 'context-form', :name => 'context', :class => 'inline-form'},
|
||||
:before => "$('context_new_submit').startWaiting()",
|
||||
:complete => "$('context_new_submit').stopWaiting()",
|
||||
:condition => "!$('context_new_submit').isWaiting()") do -%>
|
||||
|
||||
|
||||
<div id="status"><%= error_messages_for('context') %></div>
|
||||
|
||||
<label for="context_name">Context name</label><br />
|
||||
|
||||
<label for="context_name">Context name</label><br />
|
||||
<%= text_field( "context", "name" ) %><br />
|
||||
|
||||
|
||||
<label for="context_hide">Hide from front page?</label>
|
||||
<%= check_box( "context", "hide" ) %><br />
|
||||
|
||||
|
||||
<div class="submit_box">
|
||||
<div class="widgets">
|
||||
<button type="submit" class="positive" id="context_new_submit">
|
||||
|
|
@ -46,16 +40,17 @@
|
|||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<br/><br/>
|
||||
<br/><br/>
|
||||
<% end -%>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<%
|
||||
sortable_element 'list-contexts', get_listing_sortable_options
|
||||
sortable_element 'list-contexts-active', get_listing_sortable_options
|
||||
sortable_element 'list-contexts-hidden', get_listing_sortable_options
|
||||
-%>
|
||||
<script type="text/javascript">
|
||||
window.onload=function(){
|
||||
Nifty("div#context_new_container","normal");
|
||||
}
|
||||
window.onload=function(){
|
||||
Nifty("div#context_new_container","normal");
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,12 @@
|
|||
status_message = 'Context saved'
|
||||
page.notify :notice, status_message, 5.0
|
||||
page.replace_html dom_id(@context, 'container'), :partial => 'context_listing', :object => @context
|
||||
page.sortable "list-contexts", get_listing_sortable_options
|
||||
if @context_state_changed
|
||||
page << "jQuery('##{dom_id(@context, 'edit')}').hide();"
|
||||
page.insert_html :bottom, "list-contexts-#{@new_state}", :partial => 'context_listing', :object => @context
|
||||
else
|
||||
page.replace_html dom_id(@context, 'container'), :partial => 'context_listing', :object => @context
|
||||
end
|
||||
page.sortable "list-contexts-active", get_listing_sortable_options
|
||||
page.sortable "list-contexts-hidden", get_listing_sortable_options
|
||||
|
||||
page.hide "busy"
|
||||
|
|
@ -697,7 +697,8 @@ div#list-active-projects, div#list-hidden-projects, div#list-completed-projects,
|
|||
clear:right;
|
||||
border: 1px solid #999;
|
||||
}
|
||||
.project-state-group h2 {
|
||||
|
||||
.project-state-group h2, .list-stategroup-contexts-container h2 {
|
||||
margin:20px 0px 8px 13px;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue