From be479d2c55d502c6e4303700b68e0a619f646834 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 27 Nov 2012 10:01:07 +0100 Subject: bunch of refactoring for the ticket index * using different partials for different parts of the view * using render @tickets.all to iterate over the tickets. #all is necessary because of CouchRest Model * using helpers for easier querying for the open_status and admin_status params * using helper for avoiding duplication when linking to status --- help/app/helpers/tickets_helper.rb | 15 +++++++++++ help/app/views/tickets/_admin-nav.html.haml | 5 ++++ help/app/views/tickets/_order-nav.html.haml | 7 ++++++ help/app/views/tickets/_status-nav.html.haml | 7 ++++++ help/app/views/tickets/_table-nav.html.haml | 5 ++++ help/app/views/tickets/_ticket.html.haml | 13 ++++++++++ help/app/views/tickets/index.html.haml | 37 +++------------------------- 7 files changed, 56 insertions(+), 33 deletions(-) create mode 100644 help/app/helpers/tickets_helper.rb create mode 100644 help/app/views/tickets/_admin-nav.html.haml create mode 100644 help/app/views/tickets/_order-nav.html.haml create mode 100644 help/app/views/tickets/_status-nav.html.haml create mode 100644 help/app/views/tickets/_table-nav.html.haml create mode 100644 help/app/views/tickets/_ticket.html.haml diff --git a/help/app/helpers/tickets_helper.rb b/help/app/helpers/tickets_helper.rb new file mode 100644 index 0000000..c683be3 --- /dev/null +++ b/help/app/helpers/tickets_helper.rb @@ -0,0 +1,15 @@ +module TicketsHelper + + def status + params[:open_status] || 'open' + end + + def admin + params[:admin_status] || 'all' + end + + def link_to_status(new_status) + label = new_status + ' issues' + link_to label, :open_status => new_status, :admin_status => admin + end +end diff --git a/help/app/views/tickets/_admin-nav.html.haml b/help/app/views/tickets/_admin-nav.html.haml new file mode 100644 index 0000000..acd45d7 --- /dev/null +++ b/help/app/views/tickets/_admin-nav.html.haml @@ -0,0 +1,5 @@ +%ul.nav.nav-pills.nav-stacked + %li{:class => ("active" if admin == 'mine')} + = link_to 'tickets i admin', {:admin_status => 'mine', :open_status => status} + %li{:class => ("active" if admin_status == 'all')} + = link_to 'all tickets', {:admin_status => 'all', :open_status => status} diff --git a/help/app/views/tickets/_order-nav.html.haml b/help/app/views/tickets/_order-nav.html.haml new file mode 100644 index 0000000..176acdc --- /dev/null +++ b/help/app/views/tickets/_order-nav.html.haml @@ -0,0 +1,7 @@ +%ul.nav.nav-pills.pull-right + %li + = link_to 'created at' + %li{:class=> ("active" if true)} + = link_to do + %i.icon-arrow-up + updated at diff --git a/help/app/views/tickets/_status-nav.html.haml b/help/app/views/tickets/_status-nav.html.haml new file mode 100644 index 0000000..69f4248 --- /dev/null +++ b/help/app/views/tickets/_status-nav.html.haml @@ -0,0 +1,7 @@ +%ul.nav.nav-tabs + %li{:class => ("active" if status == 'open')} + = link_to_status 'open' + %li{:class => ("active" if status == 'closed')} + = link_to_status 'closed' + %li{:class => ("active" if status == 'all')} + = link_to_status 'all' diff --git a/help/app/views/tickets/_table-nav.html.haml b/help/app/views/tickets/_table-nav.html.haml new file mode 100644 index 0000000..635b59b --- /dev/null +++ b/help/app/views/tickets/_table-nav.html.haml @@ -0,0 +1,5 @@ +.row + .span6 + = render 'tickets/status-nav' + .span4 + = render 'tickets/order-nav' diff --git a/help/app/views/tickets/_ticket.html.haml b/help/app/views/tickets/_ticket.html.haml new file mode 100644 index 0000000..3edfa8b --- /dev/null +++ b/help/app/views/tickets/_ticket.html.haml @@ -0,0 +1,13 @@ +%tr + %td + %b + = link_to ticket.title, ticket + %br + %small + created: + = ticket.created_at.to_s(:short) + updated: + = ticket.updated_at.to_s(:short) + %small.pull-right + comments by: + = ticket.commenters diff --git a/help/app/views/tickets/index.html.haml b/help/app/views/tickets/index.html.haml index 7f8fa34..fdbeec5 100644 --- a/help/app/views/tickets/index.html.haml +++ b/help/app/views/tickets/index.html.haml @@ -7,41 +7,12 @@ Create a .row .span2 - if admin? - %h4 whose tickets - %ul.nav.nav-pills.nav-stacked - %li{:class => ("active" if params[:admin_status] == 'mine')} - = link_to 'tickets i admin', {:admin_status => 'mine', :open_status => params[:open_status]} - %li{:class => ("active" if params[:admin_status] != 'mine')} - = link_to 'all tickets', {:admin_status => 'all', :open_status => params[:open_status]} + = render 'tickets/admin-nav' .span10 - .row - .span6 - %ul.nav.nav-tabs - %li{:class => ("active" if params[:open_status] != 'closed' and params[:open_status] != 'all')} - = link_to 'open issues', {:open_status => 'open', :admin_status => params[:admin_status]} - %li{:class => ("active" if params[:open_status] == 'closed')} - = link_to 'closed issues', {:open_status => 'closed', :admin_status => params[:admin_status]} - = #%a{:href => "#"} closed issue - %li{:class => ("active" if params[:open_status] == 'all')} - = link_to 'open & closed issues', {:open_status => 'all', :admin_status => params[:admin_status]} - .span4 - %ul.nav.nav-pills.pull-right - %li - = link_to 'created at' - %li{:class=> ("active" if true)} - = link_to 'updated at' - %table.table-striped.table-bordered.table-hover + = render 'tickets/table-nav' + %table.table-striped.table-bordered.table-hover{:style => "width:100%;"} %tbody - - @tickets.each do |ticket| - %tr - %td - = link_to ticket.title, ticket - created: - = ticket.created_at.to_s(:short) - updated: - = ticket.updated_at.to_s(:short) - comments by: - = ticket.commenters + = render @tickets.all = paginate @tickets %div{"data-pjax-container" => ""} -- cgit v1.2.3