diff options
Diffstat (limited to 'help')
-rw-r--r-- | help/README.md | 1 | ||||
-rw-r--r-- | help/Readme.md | 0 | ||||
-rw-r--r-- | help/app/controllers/tickets_controller.rb | 109 | ||||
-rw-r--r-- | help/app/views/tickets/_admin-nav.html.haml | 10 | ||||
-rw-r--r-- | help/app/views/tickets/_comment.html.haml | 34 | ||||
-rw-r--r-- | help/app/views/tickets/_edit_form.html.haml | 46 | ||||
-rw-r--r-- | help/app/views/tickets/_new_comment.html.haml | 4 | ||||
-rw-r--r-- | help/app/views/tickets/_new_comment_form.html.haml | 13 | ||||
-rw-r--r-- | help/app/views/tickets/_table-nav.html.haml | 3 | ||||
-rw-r--r-- | help/app/views/tickets/_ticket.html.haml | 20 | ||||
-rw-r--r-- | help/app/views/tickets/_ticket_data.html.haml | 35 | ||||
-rw-r--r-- | help/app/views/tickets/index.html.haml | 21 | ||||
-rw-r--r-- | help/app/views/tickets/new.html.haml | 10 | ||||
-rw-r--r-- | help/app/views/tickets/show.html.haml | 26 | ||||
-rw-r--r-- | help/config/locales/en.yml | 12 |
15 files changed, 186 insertions, 158 deletions
diff --git a/help/README.md b/help/README.md new file mode 100644 index 0000000..c9573e6 --- /dev/null +++ b/help/README.md @@ -0,0 +1 @@ +Implements a simple, clean, and easy to use help ticketing system.
\ No newline at end of file diff --git a/help/Readme.md b/help/Readme.md deleted file mode 100644 index e69de29..0000000 --- a/help/Readme.md +++ /dev/null diff --git a/help/app/controllers/tickets_controller.rb b/help/app/controllers/tickets_controller.rb index 6562048..d478da9 100644 --- a/help/app/controllers/tickets_controller.rb +++ b/help/app/controllers/tickets_controller.rb @@ -3,10 +3,9 @@ class TicketsController < ApplicationController respond_to :html, :json #has_scope :open, :type => boolean - before_filter :set_strings - before_filter :authorize, :only => [:index] before_filter :fetch_ticket, :only => [:show, :update, :destroy] # don't now have an edit method + before_filter :set_title def new @ticket = Ticket.new @@ -20,61 +19,68 @@ class TicketsController < ApplicationController @ticket.created_by = current_user.id if logged_in? @ticket.email = current_user.email_address if logged_in? and current_user.email_address - flash[:notice] = 'Ticket was successfully created.' if @ticket.save + if @ticket.save + flash[:notice] = t(:thing_was_successfully_created, :thing => t(:ticket)) + end # cannot set this until ticket has been saved, as @ticket.id will not be set - flash[:notice] += " " + t(:access_ticket_text, :full_url => ticket_url(@ticket.id)) if !logged_in? and flash[:notice] + if !logged_in? and flash[:notice] + flash[:notice] += " " + t(:access_ticket_text, :full_url => ticket_url(@ticket.id)) + end respond_with(@ticket) - - end - -=begin - def edit - @ticket.comments.build - # build ticket comments? end -=end def show @comment = TicketComment.new if !@ticket - redirect_to tickets_path, :alert => "No such ticket" + redirect_to tickets_path, :alert => t(:no_such_thing, :thing => t(:ticket)) return end end def update + if params[:commit] == t(:close) + @ticket.is_open = false + @ticket.save + redirect_to tickets_path + elsif params[:commit] == t(:open) + @ticket.is_open = true + @ticket.save + redirect_to @ticket + else + @ticket.attributes = cleanup_ticket_params(params[:ticket]) - if params[:post] #currently changes to title or is_open status - @ticket.attributes = params[:post] - # TODO: do we want to keep the history of title changes? one possibility was adding a comment that said something like 'user changed the title from a to b' + if params[:commit] == t(:reply_and_close) + @ticket.close + should_redirect = true + else + should_redirect = !logged_in? + end - else - params[:ticket][:comments_attributes] = nil if params[:ticket][:comments_attributes].values.first[:body].blank? #unset comments hash if no new comment was typed - @ticket.attributes = params[:ticket] #this will call comments_attributes= - @ticket.close if params[:commit] == @reply_close_str #this overrides is_open selection - # what if there is an update and no new comment? Confirm that there is a new comment to update posted_by: - @ticket.comments.last.posted_by = (current_user ? current_user.id : nil) if @ticket.comments_changed? #protecting posted_by isn't working, so this should protect it. - end - if @ticket.changed? and @ticket.save - flash[:notice] = 'Ticket was successfully updated.' - if @ticket.is_open || !logged_in? - respond_with @ticket - else #for closed tickets with authenticated users, redirect to index. - redirect_to tickets_path + if @ticket.comments_changed? + @ticket.comments.last.posted_by = (current_user ? current_user.id : nil) end - else - #redirect_to [:show, @ticket] # - flash[:alert] = 'Ticket has not been changed' - redirect_to @ticket - #respond_with(@ticket) # why does this go to edit?? redirect??? - end + if @ticket.changed? + if @ticket.save + flash[:notice] = t(:changes_saved) + if should_redirect + redirect_to tickets_path + else + redirect_to @ticket + end + else + respond_with @ticket + end + else + redirect_to @ticket + end + end end def index @all_tickets = Ticket.for_user(current_user, params, admin?) #for tests, useful to have as separate variable - @tickets = @all_tickets.page(params[:page]).per(10) + @tickets = @all_tickets.page(params[:page]).per(APP_CONFIG[:pagination_size]) end def destroy @@ -83,15 +89,26 @@ class TicketsController < ApplicationController redirect_to tickets_path end + protected + + def set_title + @title = t(:tickets) + end + private - def ticket_access? - @ticket and (admin? or !@ticket.created_by or (current_user and current_user.id == @ticket.created_by)) + # 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? + ticket[:comments_attributes] = nil + end + end + return ticket end - def set_strings - @post_reply_str = 'Post reply' #t :post_reply - @reply_close_str = 'Reply and close' #t :reply_and_close + def ticket_access? + @ticket and (admin? or !@ticket.created_by or (current_user and current_user.id == @ticket.created_by)) end def fetch_ticket @@ -102,13 +119,5 @@ class TicketsController < ApplicationController end access_denied unless ticket_access? end - # not using now, as we are using comment_attributes= from the Ticket model -=begin - def add_comment - comment = TicketComment.new(params[:comment]) - comment.posted_by = User.current.id if User.current #could be nil - comment.posted_at = Time.now # TODO: it seems strange to have this here, and not in model - @ticket.comments << comment - end -=end + end diff --git a/help/app/views/tickets/_admin-nav.html.haml b/help/app/views/tickets/_admin-nav.html.haml index 0e45c40..3e65e44 100644 --- a/help/app/views/tickets/_admin-nav.html.haml +++ b/help/app/views/tickets/_admin-nav.html.haml @@ -1,5 +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, :sort_order => order} - %li{:class => ("active" if admin == 'all')} - = link_to 'all tickets', {:admin_status => 'all', :open_status => status, :sort_order => order} +.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/_comment.html.haml b/help/app/views/tickets/_comment.html.haml index 501ceec..c02246c 100644 --- a/help/app/views/tickets/_comment.html.haml +++ b/help/app/views/tickets/_comment.html.haml @@ -1,20 +1,20 @@ -- # style is super ugly but just for now - if admin? or !comment.private # only show comment if user is admin or comment is not private %tr - %td - - if comment.posted_by_user - %b - = 'Posted by' + (comment.posted_by_user.is_admin? ? ' admin' : '') + ':' - = comment.posted_by_user.login - - else - %b - Unauthenticated post + %td.user + %div + %strong + - if comment.posted_by_user + = comment.posted_by_user.login + - else + = t(:unknown) + %div= comment.posted_at.to_s(:short) + - if comment.posted_by_user.is_admin? + %div + %span.label.label-inverse + = t(:admin) - if comment.private - (Private comment) - .pull-right - %b - Posted at: - = comment.posted_at.to_s(:short) - %br - = comment.body - + %div + %span.label.label-important + = t(:private) + %td.comment + = comment.body
\ 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 new file mode 100644 index 0000000..3d1d879 --- /dev/null +++ b/help/app/views/tickets/_edit_form.html.haml @@ -0,0 +1,46 @@ +- # created by user link +- if @ticket.created_by_user + - created_by = link_to(@ticket.created_by_user.login, user_overview_path(@ticket.created_by_user)) +- else + - created_by = t(:anonymous) + +- # regarding user link +- if admin? + - if @ticket.regarding_user_actual_user + - regarding_user_link = link_to @ticket.regarding_user_actual_user.login, user_overview_path(@ticket.regarding_user_actual_user) + - else + - regarding_user_link = "(#{t(:unknown)})" +- else + - regarding_user_link = '' + += form_for @ticket do |f| + %p.first + - if @ticket.is_open? + %span.label.label-info= t(:open) + - else + %span.label.label-success= t(:closed) + %span.label.label-clear= t(:created_by_on, :user => created_by, :time => @ticket.created_at.to_s(:short)).html_safe + = t(:subject) + %br + = f.text_field :title, :class => 'large full-width' + .row-fluid + .span4 + %div= t(:status) + = f.select :is_open, [[t(:open), "true"], [t(:closed), "false"]] + .span4 + %div= t(:email) + = f.text_field :email + .span4 + %div + = t(:regarding) + = regarding_user_link + = f.text_field :regarding_user + = f.submit t(:save), :class => 'btn' + - if @ticket.is_open? + = f.submit t(:close), :class => 'btn' + =# button_to t(:close), {:post => {:is_open => false}}, :method => :put, :class => 'btn' + - else + = f.submit t(:open), :class => 'btn' + =# button_to t(:open), {:post => {:is_open => true}}, :method => :put, :class => 'btn' + + diff --git a/help/app/views/tickets/_new_comment.html.haml b/help/app/views/tickets/_new_comment.html.haml deleted file mode 100644 index 96388ea..0000000 --- a/help/app/views/tickets/_new_comment.html.haml +++ /dev/null @@ -1,4 +0,0 @@ -= f.simple_fields_for :comments, @comment do |c| - = c.input :body, :label => 'Comment', :as => :text, :input_html => {:class => "span9", :rows=>4} - - if admin? - = c.input :private, :as => :boolean, :label => false, :inline_label => true diff --git a/help/app/views/tickets/_new_comment_form.html.haml b/help/app/views/tickets/_new_comment_form.html.haml new file mode 100644 index 0000000..b273503 --- /dev/null +++ b/help/app/views/tickets/_new_comment_form.html.haml @@ -0,0 +1,13 @@ +-# +-# for posting a new comment to an existing ticket. +-# += simple_form_for @ticket, :html => {:class => 'slim'} do |f| + = 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? + = c.input :private, :as => :boolean, :label => false, :inline_label => true + = f.button :submit, t(:post_reply), :class => 'btn-primary' + - if @ticket.is_open + = f.button :submit, t(:reply_and_close) + = link_to t(:destroy), ticket_path, :confirm => 'are you sure?', :method => :delete, :class => 'btn btn-danger' if admin? + = link_to t(:cancel), tickets_path, :class => :btn diff --git a/help/app/views/tickets/_table-nav.html.haml b/help/app/views/tickets/_table-nav.html.haml index 45ebfb2..a5cf8be 100644 --- a/help/app/views/tickets/_table-nav.html.haml +++ b/help/app/views/tickets/_table-nav.html.haml @@ -1,3 +1,6 @@ +- 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 7b37652..9a1e899 100644 --- a/help/app/views/tickets/_ticket.html.haml +++ b/help/app/views/tickets/_ticket.html.haml @@ -1,17 +1,5 @@ -- updated_at_text = 'updated: ' + ticket.updated_at.to_s(:long) %tr - %td - %b - = link_to ticket.title, ticket - - if params[:controller] == 'tickets' - %br - %small - created: - = ticket.created_at.to_s(:long) - = updated_at_text - %small.pull-right - comments by: - = ticket.commenters - - else - %small - = updated_at_text
\ No newline at end of file + %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= ticket.commenters diff --git a/help/app/views/tickets/_ticket_data.html.haml b/help/app/views/tickets/_ticket_data.html.haml deleted file mode 100644 index 6a1a896..0000000 --- a/help/app/views/tickets/_ticket_data.html.haml +++ /dev/null @@ -1,35 +0,0 @@ -.spam12 - %b - Created by: - - if @ticket.created_by_user - = link_to @ticket.created_by_user.login, user_path(@ticket.created_by_user) - - else - Unauthenticated ticket creator - - if @ticket.regarding_user - %b - Regarding user: - - if admin? - - if @ticket.regarding_user_actual_user - = link_to @ticket.regarding_user_actual_user.login, user_path(@ticket.regarding_user_actual_user) - - else - = @ticket.regarding_user + ' (no such user)' - - else # a non-admin is viewing the ticket, so they shouldn't see confirmation of whether the regarding_user exists or not. - = @ticket.regarding_user - - if @ticket.email - %b - email: - = @ticket.email - %b - Created at: - = @ticket.created_at.to_s(:short) - %b - Updated at: - = @ticket.updated_at.to_s(:short) - %b - = "Status:" - - if @ticket.is_open - = 'open' - = button_to 'Close', {:post => {:is_open => false}}, :method => :put, :class => 'btn btn-small' - - else - = 'closed' - = button_to 'Open', {:post => {:is_open => true}}, :method => :put, :class => 'btn btn-small' diff --git a/help/app/views/tickets/index.html.haml b/help/app/views/tickets/index.html.haml index a3cbfcf..f4597a7 100644 --- a/help/app/views/tickets/index.html.haml +++ b/help/app/views/tickets/index.html.haml @@ -1,12 +1,17 @@ -- if admin? - = render 'tickets/admin-nav' - = render 'tickets/table-nav' -%table.table-striped.table-bordered.table-hover - //{:style => "width:100%;"} +%table.table.table-striped.table-bordered + %thead + %tr + %th= t(:subject) + %th= t(:created) + %th= t(:updated) + %th= t(:voices) %tbody - = render @tickets.all -= paginate @tickets - + - if @tickets.any? + = render @tickets.all + - else + %tr + %td{:colspan=>4}= t(:none) += paginate @tickets diff --git a/help/app/views/tickets/new.html.haml b/help/app/views/tickets/new.html.haml index 5442910..acb9537 100644 --- a/help/app/views/tickets/new.html.haml +++ b/help/app/views/tickets/new.html.haml @@ -1,17 +1,17 @@ - -//%h2.first= t :new_ticket - = render 'tickets/table-nav' = simple_form_for @ticket, :validate => true, :html => {:class => 'form-horizontal'} do |f| - = f.input :title + = f.input :title, :label => t(:subject) - if user = f.input :email, input_html: {value: user.email_address} = f.input :regarding_user, input_html: {value: user.login} - else = f.input :email = f.input :regarding_user - = render :partial => 'new_comment', :locals => {:f => f} + = f.simple_fields_for :comments, @comment do |c| + = c.input :body, :label => t(:description), :as => :text, :input_html => {:class => "full-width", :rows=> 5} + - if admin? + = c.input :private, :as => :boolean, :label => false, :inline_label => true .form-actions = f.button :submit, :class => 'btn-primary' = link_to t(:cancel), tickets_path, :class => :btn diff --git a/help/app/views/tickets/show.html.haml b/help/app/views/tickets/show.html.haml index a69048b..ddd4e9f 100644 --- a/help/app/views/tickets/show.html.haml +++ b/help/app/views/tickets/show.html.haml @@ -1,18 +1,10 @@ -.spam12 - %h2 - %a#title.editable.editable-click{"data-name" => "title", "data-resource" => "post", "data-type" => "text", "data-url" => ticket_path(@ticket.id), "data-pk" => @ticket.id, :href => "#"} - = @ticket.title - = render 'tickets/ticket_data' - %table.table-striped.table-bordered.table-hover{:style => "width:100%;"} +.ticket + = render 'tickets/edit_form' + %table.table.table-striped.table-bordered %tbody - = render(:partial => "comment", :collection => @ticket.comments) - = #render @ticket.comments should work if view is in /app/views/comments/_comment - - = simple_form_for @ticket, :html => {:class => 'form-horizontal'} do |f| # don't need validations so long as this is so simple - = render :partial => 'new_comment', :locals => {:f => f} - .span10.offset3 - = f.button :submit, @post_reply_str, :class => 'btn-primary' - - if @ticket.is_open - = f.button :submit, @reply_close_str - = link_to t(:Destroy), ticket_path, :confirm => 'are you sure?', :method => :delete, :class => 'btn btn-danger' if admin? - = link_to t(:cancel), tickets_path, :class => :btn + = render :partial => 'tickets/comment', :collection => @ticket.comments + %tr + %td.user + = logged_in? ? current_user.login : t(:anonymous) + %td.comment + = render 'tickets/new_comment_form'
\ No newline at end of file diff --git a/help/config/locales/en.yml b/help/config/locales/en.yml index 2835e4e..901cd76 100644 --- a/help/config/locales/en.yml +++ b/help/config/locales/en.yml @@ -2,6 +2,16 @@ en: access_ticket_text: "You can later access this ticket at the url %{full_url}. You might want to bookmark this page to find it again. Anybody with this URL will be able to access this ticket, so if you are on a shared computer you might want to remove it from the browser history" support_tickets: "Support Tickets" all_tickets: "All Tickets" + my_tickets: "My Tickets" open_tickets: "Open Tickets" closed_tickets: "Closed Tickets" - new_ticket: "New Ticket"
\ No newline at end of file + new_ticket: "New Ticket" + tickets: "Tickets" + subject: "Subject" + destroy: "Destroy" + open: "Open" + closed: "Closed" + close: "Close" + post_reply: "Post Reply" + reply_and_close: "Reply and Close" + description: "Description"
\ No newline at end of file |