diff options
author | elijah <elijah@riseup.net> | 2013-07-03 11:11:10 -0700 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2013-07-04 04:12:59 -0700 |
commit | 0cd386e0144601f5478f90bbdb401d55c019c828 (patch) | |
tree | e5a1eb9bf6e8031d9367c869f46ba717f2906c9c | |
parent | 179a6457d4e56052664a6895bb9ab5b721b57352 (diff) |
better ticket view navigation: tickets are now either global in scope (for admins) or stay as a nested resource for a particular user (for normal users and when you visit the tickets list of a particular user).
-rw-r--r-- | app/assets/stylesheets/leap.scss | 9 | ||||
-rw-r--r-- | app/views/layouts/_navigation.html.haml | 11 | ||||
-rw-r--r-- | help/app/controllers/tickets_controller.rb | 41 | ||||
-rw-r--r-- | help/app/helpers/auto_tickets_path_helper.rb | 51 | ||||
-rw-r--r-- | help/app/helpers/tickets_helper.rb | 41 | ||||
-rw-r--r-- | help/app/views/tickets/_admin-nav.html.haml | 5 | ||||
-rw-r--r-- | help/app/views/tickets/_edit_form.html.haml | 3 | ||||
-rw-r--r-- | help/app/views/tickets/_new_comment_form.html.haml | 3 | ||||
-rw-r--r-- | help/app/views/tickets/_order-nav.html.haml | 4 | ||||
-rw-r--r-- | help/app/views/tickets/_status-nav.html.haml | 8 | ||||
-rw-r--r-- | help/app/views/tickets/_table-nav.html.haml | 3 | ||||
-rw-r--r-- | help/app/views/tickets/_ticket.html.haml | 7 | ||||
-rw-r--r-- | help/app/views/tickets/index.html.haml | 2 | ||||
-rw-r--r-- | help/app/views/tickets/new.html.haml | 7 | ||||
-rw-r--r-- | help/app/views/tickets/show.html.haml | 2 | ||||
-rw-r--r-- | help/config/routes.rb | 7 |
16 files changed, 152 insertions, 52 deletions
diff --git a/app/assets/stylesheets/leap.scss b/app/assets/stylesheets/leap.scss index 4a3ca03..792aa3c 100644 --- a/app/assets/stylesheets/leap.scss +++ b/app/assets/stylesheets/leap.scss @@ -105,6 +105,15 @@ input, textarea { background-image: url(/assets/glyphicons-halflings.png) !important; } +// override stupid bootstrap behavior of making the active tab appear non-clickable +// and links not being underline +.nav-tabs > li > a:hover, .sidenav > li > a:hover { + text-decoration: underline; +} +.nav-tabs > .active > a:hover { + cursor: pointer; +} + // // TICKETS // diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index 7cd0f38..cbe6d3a 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -1,13 +1,6 @@ -//= link_to "Leap Web", root_path, :class => 'brand' -//%ul.nav -// // = render '/tickets/nav' -// -//%ul.nav.pull-right -// = render '/sessions/nav' - %ul.nav.sidenav = link_to_navigation t(:overview), user_overview_path(user), :active => controller?(:overviews) = link_to_navigation t(:account_settings), edit_user_path(user), :active => controller?(:users) - =# link_to_navigation t(:email_settings), edit_email_path(user), :active => controller?(:emails) - = link_to_navigation t(:support_tickets), tickets_path, :active => controller?(:tickets) + = link_to_navigation t(:email_settings), edit_user_email_settings_path(user), :active => controller?(:email_settings) + = link_to_navigation t(:support_tickets), auto_tickets_path(user), :active => controller?(:tickets) = link_to_navigation t(:logout), logout_path, :method => :delete diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb index 3be7d10..6fc4024 100644 --- a/help/app/controllers/tickets_controller.rb +++ b/help/app/controllers/tickets_controller.rb @@ -1,10 +1,12 @@ class TicketsController < ApplicationController + include AutoTicketsPathHelper respond_to :html, :json #has_scope :open, :type => boolean before_filter :authorize, :only => [:index] before_filter :fetch_ticket, :only => [:show, :update, :destroy] # don't now have an edit method + before_filter :fetch_user before_filter :set_title def new @@ -27,13 +29,13 @@ class TicketsController < ApplicationController if !logged_in? and flash[:notice] flash[:notice] += " " + t(:access_ticket_text, :full_url => ticket_url(@ticket.id)) end - respond_with(@ticket) + respond_with(@ticket, :location => auto_ticket_path(@ticket)) end def show @comment = TicketComment.new if !@ticket - redirect_to tickets_path, :alert => t(:no_such_thing, :thing => t(:ticket)) + redirect_to auto_tickets_path, :alert => t(:no_such_thing, :thing => t(:ticket)) return end end @@ -46,7 +48,7 @@ class TicketsController < ApplicationController elsif params[:commit] == t(:open) @ticket.is_open = true @ticket.save - redirect_to @ticket + redirect_to auto_ticket_path(@ticket) elsif params[:commit] == t(:cancel) redirect_to_tickets else @@ -68,20 +70,20 @@ class TicketsController < ApplicationController respond_with @ticket end else - redirect_to @ticket + redirect_to auto_ticket_path(@ticket) end end end def index - @all_tickets = Ticket.for_user(current_user, params, admin?) #for tests, useful to have as separate variable + @all_tickets = Ticket.search(search_options(params)) @tickets = @all_tickets.page(params[:page]).per(APP_CONFIG[:pagination_size]) end def destroy # should we allow non-admins to delete their own tickets? i don't think necessary. @ticket.destroy if admin? - redirect_to tickets_path + redirect_to auto_tickets_path end protected @@ -99,17 +101,19 @@ class TicketsController < ApplicationController def redirect_to_tickets if logged_in? if params[:commit] == t(:reply_and_close) - redirect_to tickets_url + redirect_to auto_tickets_path else - redirect_to @ticket + redirect_to auto_ticket_path(@ticket) end else # if we are not logged in, there is no index to view - redirect_to @ticket + redirect_to auto_ticket_path(@ticket) end end + # # unset comments hash if no new comment was typed + # def cleanup_ticket_params(ticket) if ticket && ticket[:comments_attributes] if ticket[:comments_attributes].values.first[:body].blank? @@ -126,10 +130,27 @@ class TicketsController < ApplicationController def fetch_ticket @ticket = Ticket.find(params[:id]) if !@ticket and admin? - redirect_to tickets_path, :alert => t(:no_such_thing, :thing => 'ticket') + redirect_to auto_tickets_path, :alert => t(:no_such_thing, :thing => 'ticket') return end access_denied unless ticket_access? end + def fetch_user + if params[:user_id] + @user = User.find_by_param(params[:user_id]) + end + end + + # + # clean up params for ticket search + # + def search_options(params) + params.merge( + :admin_status => params[:user_id] ? 'mine' : 'all', + :user_id => @user ? @user.id : current_user.id, + :is_admin => admin? + ) + end + end diff --git a/help/app/helpers/auto_tickets_path_helper.rb b/help/app/helpers/auto_tickets_path_helper.rb new file mode 100644 index 0000000..bb71260 --- /dev/null +++ b/help/app/helpers/auto_tickets_path_helper.rb @@ -0,0 +1,51 @@ +# +# These "auto" forms of the normal ticket path route helpers allow us to do two things automatically: +# +# (1) include the user in the path if appropriate. +# (2) retain the sort params, if appropriate. +# +# Tickets views with a user_id are limited to that user. For admins, they don't need a user_id for any ticket action. +# +# This is available both to the views and the tickets_controller. +# +module AutoTicketsPathHelper + + protected + + def auto_tickets_path(options={}) + options = ticket_view_options.merge options + if @user + user_tickets_path(@user, options) + else + tickets_path(options) + end + end + + def auto_ticket_path(ticket, options={}) + options = ticket_view_options.merge options + if @user + user_ticket_path(@user, ticket, options) + else + ticket_path(ticket, options) + end + end + + def auto_new_ticket_path(options={}) + options = ticket_view_options.merge options + if @user + new_user_ticket_path(@user, options) + else + new_ticket_path(options) + end + end + + private + + def ticket_view_options + hsh = {} + hsh[:open_status] = params[:open_status] if params[:open_status] && !params[:open_status].empty? + hsh[:sort_order] = params[:sort_order] if params[:sort_order] && !params[:sort_order].empty? + hsh + end + +end
\ No newline at end of file diff --git a/help/app/helpers/tickets_helper.rb b/help/app/helpers/tickets_helper.rb index 8b4ff71..7af50d6 100644 --- a/help/app/helpers/tickets_helper.rb +++ b/help/app/helpers/tickets_helper.rb @@ -1,18 +1,39 @@ module TicketsHelper + # + # FORM HELPERS + # - def status - params[:open_status] + # + # hidden fields that should be added to ever ticket form. + # these are use for proper redirection after successful actions. + # + def hidden_ticket_fields + haml_concat hidden_field_tag('open_status', params[:open_status]) + haml_concat hidden_field_tag('sort_order', params[:sort_order]) + haml_concat hidden_field_tag('user_id', params[:user_id]) + "" end - def admin - # do we not want this set for non-admins? the param will be viewable in the url - params[:admin_status] || 'all' + # + # PARAM HELPERS + # + + def search_status + if action?(:index) + params[:open_status] || 'open' + else + nil + end end - def order + def search_order params[:sort_order] || 'updated_at_desc' end + # + # LINK HELPERS + # + def link_to_status(new_status) if new_status == "open" label = t(:open_tickets) @@ -21,13 +42,13 @@ module TicketsHelper elsif new_status == "all" label = t(:all_tickets) end - link_to label, tickets_path(:open_status => new_status, :admin_status => admin, :sort_order => order) + link_to label, auto_tickets_path(:open_status => new_status, :sort_order => search_order) end def link_to_order(order_field) - if order.start_with?(order_field) + if search_order.start_with?(order_field) # link for currently-filtered field. Link to other direction of this field. - if order.end_with? 'asc' + if search_order.end_with? 'asc' direction = 'desc' icon_direction = 'up' else @@ -47,7 +68,7 @@ module TicketsHelper label = t(:created) end - link_to :sort_order => order_field + '_at_' + direction, :open_status => status, :admin_status => admin do + link_to auto_tickets_path(:sort_order => order_field + '_at_' + direction, :open_status => search_status) do arrow + label end end diff --git a/help/app/views/tickets/_admin-nav.html.haml b/help/app/views/tickets/_admin-nav.html.haml deleted file mode 100644 index 3e65e44..0000000 --- a/help/app/views/tickets/_admin-nav.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -.btn-group - %span.btn.disabled= t(:admin) + ':' - = link_to t(:my_tickets), {:admin_status => 'mine', :open_status => status, :sort_order => order}, :class => ['btn', ("active" if admin == 'mine')].join(' ') - = link_to t(:all_tickets), {:admin_status => 'all', :open_status => status, :sort_order => order}, :class => ['btn', ("active" if admin == 'all')].join(' ') -%br
\ No newline at end of file diff --git a/help/app/views/tickets/_edit_form.html.haml b/help/app/views/tickets/_edit_form.html.haml index 151d6f1..9c981a3 100644 --- a/help/app/views/tickets/_edit_form.html.haml +++ b/help/app/views/tickets/_edit_form.html.haml @@ -14,6 +14,7 @@ - regarding_user_link = '' = form_for @ticket do |f| + = hidden_ticket_fields %p.first - if @ticket.is_open? %span.label.label-info= t(:open) @@ -40,5 +41,5 @@ - else = f.submit t(:open), :class => 'btn' - if admin? - = link_to t(:destroy), ticket_path, :confirm => 'are you sure?', :method => :delete, :class => 'btn' + = link_to t(:destroy), auto_ticket_path(@ticket), :confirm => t(:are_you_sure), :method => :delete, :class => 'btn' diff --git a/help/app/views/tickets/_new_comment_form.html.haml b/help/app/views/tickets/_new_comment_form.html.haml index de54259..ff136f3 100644 --- a/help/app/views/tickets/_new_comment_form.html.haml +++ b/help/app/views/tickets/_new_comment_form.html.haml @@ -2,6 +2,7 @@ -# for posting a new comment to an existing ticket. -# = simple_form_for @ticket, :html => {:class => 'slim'} do |f| + = hidden_ticket_fields = f.simple_fields_for :comments, @comment, :wrapper => :none, :html => {:class => 'slim'} do |c| = c.input :body, :label => false, :as => :text, :input_html => {:class => "full-width", :rows=> 5} - if admin? @@ -9,4 +10,4 @@ = f.button :submit, t(:post_reply), :class => 'btn-primary' - if logged_in? && @ticket.is_open = f.button :submit, t(:reply_and_close) - = link_to t(:cancel), tickets_path, :class => :btn + = link_to t(:cancel), auto_tickets_path, :class => :btn diff --git a/help/app/views/tickets/_order-nav.html.haml b/help/app/views/tickets/_order-nav.html.haml index a2ddb72..b235350 100644 --- a/help/app/views/tickets/_order-nav.html.haml +++ b/help/app/views/tickets/_order-nav.html.haml @@ -1,5 +1,5 @@ %ul.nav.nav-pills.pull-right{:style => 'margin-bottom: 0'} - %li{:class=> ("active" if order.start_with? 'created_at' )} + %li{:class=> ("active" if search_order.start_with? 'created_at' )} = link_to_order('created') - %li{:class=> ("active" if order.start_with? 'updated_at' )} + %li{:class=> ("active" if search_order.start_with? 'updated_at' )} = link_to_order('updated') diff --git a/help/app/views/tickets/_status-nav.html.haml b/help/app/views/tickets/_status-nav.html.haml index c8279ed..8e51497 100644 --- a/help/app/views/tickets/_status-nav.html.haml +++ b/help/app/views/tickets/_status-nav.html.haml @@ -1,10 +1,10 @@ %ul.nav.nav-tabs - if logged_in? - %li{:class => ("active" if status == 'open')} + %li{:class => ("active" if search_status == 'open')} = link_to_status 'open' - %li{:class => ("active" if status == 'closed')} + %li{:class => ("active" if search_status == 'closed')} = link_to_status 'closed' - %li{:class => ("active" if status == 'all')} + %li{:class => ("active" if search_status == 'all')} = link_to_status 'all' %li{:class => ("active" if action?(:new))} - = link_to icon(:plus, :black) + t(:new_ticket), new_ticket_path + = link_to icon(:plus, :black) + t(:new_ticket), auto_new_ticket_path diff --git a/help/app/views/tickets/_table-nav.html.haml b/help/app/views/tickets/_table-nav.html.haml index a5cf8be..45ebfb2 100644 --- a/help/app/views/tickets/_table-nav.html.haml +++ b/help/app/views/tickets/_table-nav.html.haml @@ -1,6 +1,3 @@ -- if admin? - = render 'tickets/admin-nav' - - unless action?(:new) = render 'tickets/order-nav' = render 'tickets/status-nav' diff --git a/help/app/views/tickets/_ticket.html.haml b/help/app/views/tickets/_ticket.html.haml index 9a1e899..a064c4e 100644 --- a/help/app/views/tickets/_ticket.html.haml +++ b/help/app/views/tickets/_ticket.html.haml @@ -1,5 +1,6 @@ +- url = auto_ticket_path(ticket) %tr - %td= link_to ticket.title, ticket - %td= link_to ticket.created_at.to_s(:short), ticket - %td= link_to ticket.updated_at.to_s(:short), ticket + %td= link_to ticket.title, url + %td= link_to ticket.created_at.to_s(:short), url + %td= link_to ticket.updated_at.to_s(:short), url %td= ticket.commenters diff --git a/help/app/views/tickets/index.html.haml b/help/app/views/tickets/index.html.haml index f4597a7..1b32dc1 100644 --- a/help/app/views/tickets/index.html.haml +++ b/help/app/views/tickets/index.html.haml @@ -1,3 +1,5 @@ +- @show_navigation = !params[:user_id].nil? + = render 'tickets/table-nav' %table.table.table-striped.table-bordered diff --git a/help/app/views/tickets/new.html.haml b/help/app/views/tickets/new.html.haml index 7d3f76c..04b091c 100644 --- a/help/app/views/tickets/new.html.haml +++ b/help/app/views/tickets/new.html.haml @@ -1,6 +1,9 @@ +- @show_navigation = !params[:user_id].nil? + = render 'tickets/table-nav' = simple_form_for @ticket, :validate => true, :html => {:class => 'form-horizontal'} do |f| + = hidden_ticket_fields = f.input :title, :label => t(:subject) - if user = f.input :email, input_html: {value: user.email_address} @@ -15,4 +18,6 @@ .form-actions = f.button :submit, :class => 'btn-primary' - if logged_in? - = link_to t(:cancel), tickets_path, :class => :btn + = link_to t(:cancel), auto_tickets_path, :class => :btn + - else + = link_to t(:cancel), root_path, :class => 'btn'
\ No newline at end of file diff --git a/help/app/views/tickets/show.html.haml b/help/app/views/tickets/show.html.haml index ddd4e9f..bfdb773 100644 --- a/help/app/views/tickets/show.html.haml +++ b/help/app/views/tickets/show.html.haml @@ -1,3 +1,5 @@ +- @show_navigation = !params[:user_id].nil? + .ticket = render 'tickets/edit_form' %table.table.table-striped.table-bordered diff --git a/help/config/routes.rb b/help/config/routes.rb index 86a9201..8f3241c 100644 --- a/help/config/routes.rb +++ b/help/config/routes.rb @@ -1,5 +1,6 @@ Rails.application.routes.draw do - - resources :tickets, :only => [:new, :create, :index, :show, :update, :destroy] - #resources :ticket, :only => [:show] + resources :tickets, :except => :edit + resources :users do + resources :tickets, :except => :edit + end end |