fix #603. Group context by hidden state in context view

This commit is contained in:
Reinier Balt 2009-04-07 21:18:23 +02:00
parent aeb9a1fda6
commit 183523f45a
5 changed files with 60 additions and 37 deletions

View file

@ -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