update tickets
following #13 - tickets have no more master - tickets are commentables
This commit is contained in:
parent
6dd89038d3
commit
a769142d2f
24
README.md
24
README.md
|
@ -16,8 +16,6 @@ I want a simple application, that I __understand__, and that I __need__. By __si
|
|||
- A pluggable application, with many __REST API__. Because tasks and reports are usefull.
|
||||
- Generic items. I prefere __ONE kind of Bills + Tags__ than __4 ou 5 kinds of Bills__ (for example).
|
||||
|
||||
I would like money, contributions, critics, etc.
|
||||
|
||||
<img alt="Tickets Desktop view" src="http://i.imgur.com/e004zBZ.png" width="500" />
|
||||
|
||||
|
||||
|
@ -32,18 +30,18 @@ I would like money, contributions, critics, etc.
|
|||
1. [Contributors](#21-contributors)
|
||||
2. [How to contribute](#22-how-to-contribute-)
|
||||
3. [License](#23-license)
|
||||
3. [Architecture](#3-architecture)
|
||||
1. [Modelisation](#31-modelisation)
|
||||
|
||||
|
||||
|
||||
# 1. Installation
|
||||
|
||||
## 1.1. Requirements
|
||||
|
||||
- Ruby 2.0 or greater.
|
||||
- Postgresql server 9 or greater running with creditentials.
|
||||
|
||||
## 1.2. Initialization
|
||||
|
||||
Start by pasting this script in your shell:
|
||||
```bash
|
||||
cd MorningPeak/
|
||||
|
@ -57,7 +55,6 @@ rake db:seed # will generate default data. Not on production ;)
|
|||
```
|
||||
|
||||
## 1.3. Configuration
|
||||
|
||||
- You can create a file ``.env`` to save your locals cvars without pollute your global env.
|
||||
- You can also create ``.env.production`` etc. for environement specifics cvars
|
||||
- A ``.env`` file looks like:
|
||||
|
@ -71,7 +68,6 @@ LOCALE: fr
|
|||
- COMPANY
|
||||
|
||||
## 1.4. First start
|
||||
|
||||
When you done with the configuration of the database (editing ``config/database.yml``),
|
||||
you can run the server by the following command :
|
||||
```
|
||||
|
@ -100,7 +96,6 @@ Checkout for [rails minidoc](RailsMinidoc.md) for a resume of rails.
|
|||
<img alt="Look at this cute face" src="https://pbs.twimg.com/media/CJ_ErJ2W8AAdev3.jpg" width="200" height="150" />
|
||||
|
||||
## 2.2. How to contribute ?
|
||||
|
||||
You can contribute to this project by Merge Request on the gitlab repository [here](https://gitlab.com/poulet_a/MorningPeak).
|
||||
The best pratices are to create short commits, and short Merge Requests. Respect the git commit nomage convention as possible with:
|
||||
|
||||
|
@ -121,3 +116,18 @@ It is under:
|
|||
```text
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
```
|
||||
|
||||
# 3. Architecture
|
||||
|
||||
## 3.1 Modelisation
|
||||
|
||||
### Creation and belongs
|
||||
- User has a Client (which is created when the user is created)
|
||||
- Client has many Contacts and Bills
|
||||
- User/Admin has many Tickets and Comments
|
||||
|
||||
### Permissions
|
||||
- Admin can Comment, Read, Edit, Delete, and Create everything
|
||||
- User can open Ticket, Anwser and Close them.
|
||||
- User can Read every Bills wich is associated to him
|
||||
- User can not read his client informations (like notes, ...)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
class ClientTicketsController < ApplicationController
|
||||
include CommentableForm
|
||||
|
||||
before_action :set_ticket, only: [:show, :edit, :update, :destroy]
|
||||
before_action :set_ticket_custom_route, only: [:close, :open, :respond]
|
||||
before_action :looks_ticket, only: [:show, :edit, :update, :close, :open]
|
||||
|
@ -7,13 +9,13 @@ class ClientTicketsController < ApplicationController
|
|||
# GET /tickets
|
||||
# GET /tickets.json
|
||||
def index
|
||||
@tickets = current_user.tickets.heads.order('state DESC')
|
||||
@tickets = current_user.tickets.order('state DESC')
|
||||
end
|
||||
|
||||
def close
|
||||
respond_to do |format|
|
||||
if @ticket.close
|
||||
@ticket.update(admin_view_at: Time.now)
|
||||
@ticket.update(admin_view_at: Time.now) # add comment ?
|
||||
format.html { redirect_to client_ticket_url(@ticket), notice: 'Ticket was successfully closed.' }
|
||||
format.json { render :show, status: :ok, location: client_tickets_url(@ticket) }
|
||||
else
|
||||
|
@ -26,7 +28,7 @@ class ClientTicketsController < ApplicationController
|
|||
def open
|
||||
respond_to do |format|
|
||||
if @ticket.open
|
||||
@ticket.update(admin_view_at: nil)
|
||||
@ticket.update(admin_view_at: nil) # add comment ?
|
||||
format.html { redirect_to client_ticket_url(@ticket), notice: 'Ticket was successfully reopened.' }
|
||||
format.json { render :show, status: :ok, location: client_tickets_url(@ticket) }
|
||||
else
|
||||
|
@ -36,25 +38,10 @@ class ClientTicketsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def respond
|
||||
session[:user_ticket_respond_parent_id] = @ticket.id
|
||||
@head = @ticket.head
|
||||
@ticket = Ticket.new(ticket_id: @head.id,
|
||||
creator: current_user,
|
||||
title: @ticket.title)
|
||||
if @ticket.close? or @head.close?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to client_ticket_url(@head), alert: 'The ticket is closed' }
|
||||
format.json { render json: {ticket: 'The ticket is closed'}, status: :unprocessable_entity }
|
||||
end
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
# GET /tickets/1
|
||||
# GET /tickets/1.json
|
||||
def show
|
||||
prepare_comment_for @ticket
|
||||
end
|
||||
|
||||
# GET /tickets/new
|
||||
|
@ -70,15 +57,10 @@ class ClientTicketsController < ApplicationController
|
|||
# POST /tickets.json
|
||||
def create
|
||||
@ticket = Ticket.new(ticket_params)
|
||||
if session[:user_ticket_respond_parent_id]
|
||||
@head = Ticket.find(session[:user_ticket_respond_parent_id]).head
|
||||
@ticket.ticket_id = @head.id
|
||||
end
|
||||
@ticket.creator = current_user
|
||||
|
||||
respond_to do |format|
|
||||
if @ticket.save
|
||||
@ticket.close_head if @ticket.close?
|
||||
format.html { redirect_to client_ticket_url(@ticket), notice: 'Ticket was successfully created.' }
|
||||
format.json { render :show, status: :created, location: client_tickets_url(@ticket) }
|
||||
else
|
||||
|
@ -93,7 +75,6 @@ class ClientTicketsController < ApplicationController
|
|||
def update
|
||||
respond_to do |format|
|
||||
if @ticket.update(ticket_params)
|
||||
@ticket.close_head if @ticket.close?
|
||||
format.html { redirect_to @ticket, notice: 'Ticket was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: client_tickets_url(@ticket) }
|
||||
else
|
||||
|
@ -116,11 +97,11 @@ class ClientTicketsController < ApplicationController
|
|||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_ticket
|
||||
@ticket = Ticket.find(params[:id])
|
||||
@ticket = nil if not @ticket.creator == current_user and not @ticket.head.creator == current_user
|
||||
@ticket = Ticket.find_by(id: params[:id], creator: current_user)
|
||||
@ticket
|
||||
end
|
||||
|
||||
# TODO: remove
|
||||
def set_ticket_custom_route
|
||||
params[:id] = params[:client_ticket_id]
|
||||
set_ticket
|
||||
|
@ -132,12 +113,7 @@ class ClientTicketsController < ApplicationController
|
|||
end
|
||||
|
||||
def looks_ticket
|
||||
if @ticket.head.head_creator_view_at.nil?
|
||||
@ticket.head.update(head_creator_view_at: Time.now)
|
||||
end
|
||||
Ticket.where(creator: current_user, head_creator_view_at: nil, ticket: @ticket.head).each do |t|
|
||||
t.update(head_creator_view_at: Time.now)
|
||||
end
|
||||
@ticket.set_view_by('User')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@ class CommentsController < ApplicationController
|
|||
before_action :set_client, only: [:index, :about, :new]
|
||||
before_action :set_contact, only: [:index, :about, :new]
|
||||
before_action :set_bill, only: [:index, :about, :new]
|
||||
before_action :set_ticket, only: [:index, :about, :new]
|
||||
|
||||
# GET /comments
|
||||
# GET /comments.json
|
||||
|
@ -96,5 +97,8 @@ class CommentsController < ApplicationController
|
|||
def set_bill
|
||||
@commentable ||= Bill.find_by_id(params[:bill_id])
|
||||
end
|
||||
def set_ticket
|
||||
@commentable ||= Ticket.find_by_id(params[:ticket_id])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -8,8 +8,8 @@ class HomeController < ApplicationController
|
|||
@next_bills = current_user.bills.next.count
|
||||
@old_bills = current_user.bills.old.count
|
||||
@bills_count = current_user.bills.count
|
||||
@ticket_closed = current_user.tickets.heads.close.count
|
||||
@ticket_opened = current_user.tickets.heads.open.count
|
||||
@ticket_closed = current_user.tickets.close.count
|
||||
@ticket_opened = current_user.tickets.open.count
|
||||
@ticket_waiting = current_user.tickets_unview.count
|
||||
end
|
||||
|
||||
|
@ -22,8 +22,8 @@ class HomeController < ApplicationController
|
|||
@next_bills = Bill.next.count
|
||||
@old_bills = Bill.old.count
|
||||
@bills_count = Bill.count
|
||||
@ticket_closed = Ticket.heads.close.count
|
||||
@ticket_opened = Ticket.heads.open.count
|
||||
@ticket_closed = Ticket.close.count
|
||||
@ticket_opened = Ticket.open.count
|
||||
@ticket_waiting = current_admin.tickets_unview.count
|
||||
end
|
||||
|
||||
|
|
|
@ -1,19 +1,21 @@
|
|||
class TicketsController < ApplicationController
|
||||
include CommentableForm
|
||||
|
||||
before_action :set_ticket, only: [:show, :edit, :update, :destroy]
|
||||
before_action :set_ticket_custom_route, only: [:close, :open, :respond]
|
||||
before_action :set_ticket_custom_route, only: [:close, :open]
|
||||
before_action :looks_ticket, only: [:show, :edit, :update, :close, :open]
|
||||
before_action :authenticate_admin!
|
||||
|
||||
# GET /tickets
|
||||
# GET /tickets.json
|
||||
def index
|
||||
@tickets = Ticket.heads.order('state DESC')
|
||||
@tickets = Ticket.order('state DESC')
|
||||
end
|
||||
|
||||
def close
|
||||
respond_to do |format|
|
||||
if @ticket.close
|
||||
@ticket.update(admin_view_at: Time.now)
|
||||
@ticket.update(admin_view_at: Time.now) # add comment ?
|
||||
format.html { redirect_to ticket_url(@ticket), notice: 'Ticket was successfully closed.' }
|
||||
format.json { render :show, status: :ok, location: @ticket }
|
||||
else
|
||||
|
@ -26,7 +28,7 @@ class TicketsController < ApplicationController
|
|||
def open
|
||||
respond_to do |format|
|
||||
if @ticket.open
|
||||
@ticket.update(head_creator_view_at: nil)
|
||||
@ticket.update(creator_view_at: nil) # add comment ?
|
||||
format.html { redirect_to ticket_url(@ticket), notice: 'Ticket was successfully reopened.' }
|
||||
format.json { render :show, status: :ok, location: @ticket }
|
||||
else
|
||||
|
@ -36,24 +38,10 @@ class TicketsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def respond
|
||||
@head = @ticket.head
|
||||
@ticket = Ticket.new(ticket_id: @head.id,
|
||||
creator: current_admin,
|
||||
title: @ticket.title)
|
||||
if @ticket.close? or @head.close?
|
||||
respond_to do |format|
|
||||
format.html { redirect_to ticket_url(@head), alert: 'the ticket is closed' }
|
||||
format.json { render json: {ticket: 'the ticket is closed'}, status: :unprocessable_entity }
|
||||
end
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
# GET /tickets/1
|
||||
# GET /tickets/1.json
|
||||
def show
|
||||
prepare_comment_for @ticket
|
||||
end
|
||||
|
||||
# GET /tickets/new
|
||||
|
@ -88,7 +76,6 @@ class TicketsController < ApplicationController
|
|||
def update
|
||||
respond_to do |format|
|
||||
if @ticket.update(ticket_params)
|
||||
@ticket.close_head if @ticket.close?
|
||||
format.html { redirect_to @ticket, notice: 'Ticket was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @ticket }
|
||||
else
|
||||
|
@ -124,12 +111,7 @@ class TicketsController < ApplicationController
|
|||
end
|
||||
|
||||
def looks_ticket
|
||||
if @ticket.head.admin_view_at.nil?
|
||||
@ticket.head.update(admin_view_at: Time.now)
|
||||
end
|
||||
Ticket.where(creator: current_admin, admin_view_at: nil, ticket: @ticket.head).each do |t|
|
||||
t.update(admin_view_at: Time.now)
|
||||
end
|
||||
@ticket.set_view_by('Admin')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -12,7 +12,7 @@ class Admin < ActiveRecord::Base
|
|||
has_many :comments, as: :creator
|
||||
|
||||
def tickets_unview
|
||||
Ticket.all.heads.where(admin_view_at: nil)
|
||||
Ticket.all.where(admin_view_at: nil)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class Client < ActiveRecord::Base
|
||||
acts_as_commentable
|
||||
|
||||
has_many :contacts
|
||||
has_many :bills
|
||||
has_many :tickets, through: :user
|
||||
|
|
|
@ -3,7 +3,7 @@ class Comment < ActiveRecord::Base
|
|||
|
||||
belongs_to :commentable, :polymorphic => true
|
||||
|
||||
default_scope -> { order('created_at ASC') }
|
||||
default_scope -> { order('created_at DESC') }
|
||||
|
||||
# NOTE: install the acts_as_votable plugin if you
|
||||
# want user to vote on the quality of comments.
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# coding: utf-8
|
||||
class Ticket < ActiveRecord::Base
|
||||
acts_as_commentable
|
||||
|
||||
# WARNING ! IT REVERSE LAST / FIRST
|
||||
default_scope { order('created_at DESC') }
|
||||
|
||||
|
@ -16,12 +18,8 @@ class Ticket < ActiveRecord::Base
|
|||
belongs_to :creator, polymorphic: true
|
||||
delegate :name, to: :creator, prefix: true
|
||||
|
||||
belongs_to :ticket
|
||||
has_many :tickets
|
||||
|
||||
scope :heads, -> { where(ticket_id: nil) }
|
||||
scope :open, -> { heads.where(state: OPEN) }
|
||||
scope :close, -> { heads.where(state: CLOSE) }
|
||||
scope :open, -> { where(state: OPEN) }
|
||||
scope :close, -> { where(state: CLOSE) }
|
||||
|
||||
before_save :check_creator
|
||||
def check_creator
|
||||
|
@ -30,39 +28,35 @@ class Ticket < ActiveRecord::Base
|
|||
raise ActiveRecord::RecordInvalid.new(self)
|
||||
end
|
||||
|
||||
after_create :looks_views
|
||||
def looks_views
|
||||
after_create :set_view_init
|
||||
def set_view_init
|
||||
set_view_by(creator_type)
|
||||
end
|
||||
|
||||
def set_view_by(viewer_type)
|
||||
if creator_type == 'Admin'
|
||||
# Entre admin pas de soucis
|
||||
if head.creator_type == 'Admin'
|
||||
update(admin_view_at: Time.now, head_creator_view_at: Time.now)
|
||||
# Réponse à un client, mise a jour pour notification
|
||||
else
|
||||
update(admin_view_at: Time.now, head_creator_view_at: nil)
|
||||
head.update(admin_view_at: Time.now, head_creator_view_at: nil)
|
||||
if viewer_type == 'Admin'
|
||||
update(admin_view_at: Time.now, creator_view_at: Time.now)
|
||||
end
|
||||
else
|
||||
# Reponse client, mise a jour pour notification
|
||||
if head?
|
||||
update(admin_view_at: nil, head_creator_view_at: Time.now)
|
||||
else
|
||||
update(admin_view_at: nil, head_creator_view_at: Time.now)
|
||||
head.update(admin_view_at: nil, head_creator_view_at: Time.now)
|
||||
elsif creator_type == 'User'
|
||||
if viewer_type == 'User'
|
||||
update(creator_view_at: Time.now)
|
||||
elsif viewer_type == 'Admin'
|
||||
update(admin_view_at: Time.now)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def last_response
|
||||
head.tickets.last
|
||||
end
|
||||
|
||||
def head
|
||||
return self if head?
|
||||
return ticket.head
|
||||
end
|
||||
|
||||
def head?
|
||||
ticket.nil?
|
||||
def set_unview_by(viewer_type)
|
||||
if creator_type == 'Admin'
|
||||
return # ... ?
|
||||
elsif creator_type == 'User'
|
||||
if viewer_type == 'User'
|
||||
update(admin_view_at: nil)
|
||||
elsif viewer_type == 'Admin'
|
||||
update(creator_view_at: nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def close
|
||||
|
@ -70,15 +64,7 @@ class Ticket < ActiveRecord::Base
|
|||
errors[:base] << "Already close"
|
||||
return false
|
||||
end
|
||||
head.update(state: Ticket::CLOSE) && update(state: Ticket::CLOSE)
|
||||
end
|
||||
|
||||
def close_head
|
||||
if head.close?
|
||||
errors[:base] << "Already close"
|
||||
return false
|
||||
end
|
||||
head.update(state: Ticket::CLOSE)
|
||||
update(state: Ticket::CLOSE)
|
||||
end
|
||||
|
||||
def open
|
||||
|
@ -86,7 +72,7 @@ class Ticket < ActiveRecord::Base
|
|||
errors[:base] << "Already open"
|
||||
return false
|
||||
end
|
||||
head.update(state: Ticket::OPEN) && update(state: Ticket::OPEN)
|
||||
update(state: Ticket::OPEN)
|
||||
end
|
||||
|
||||
def open?
|
||||
|
@ -98,11 +84,7 @@ class Ticket < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def short_description
|
||||
if description.size > 100
|
||||
description[0..97] + "..."
|
||||
else
|
||||
description
|
||||
end
|
||||
description.to_s.first(100)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -16,11 +16,13 @@ class User < ActiveRecord::Base
|
|||
|
||||
after_create :create_client
|
||||
def create_client
|
||||
update(client: Client.create(name: email.gsub(/@.+/, '')))
|
||||
if self.client_id.nil?
|
||||
update_attributes(client: Client.create(name: email.tr('@.-_', ' ')))
|
||||
end
|
||||
end
|
||||
|
||||
def tickets_unview
|
||||
tickets.heads.where(head_creator_view_at: nil)
|
||||
tickets.where(creator_view_at: nil)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -4,7 +4,6 @@ table.table.table-condensed
|
|||
thead
|
||||
tr
|
||||
th ID
|
||||
th = t ".creator"
|
||||
th = t ".title"
|
||||
th = t ".description"
|
||||
th = t ".state"
|
||||
|
@ -13,25 +12,21 @@ table.table.table-condensed
|
|||
th
|
||||
th
|
||||
th
|
||||
th
|
||||
|
||||
tbody
|
||||
- @tickets.each do |ticket|
|
||||
tr class="#{ticket.head_creator_view_at.nil? ? 'bg-warning' : ''}"
|
||||
tr class="#{ticket.creator_view_at.nil? ? 'bg-warning' : ''}"
|
||||
td = link_to("##{ticket.id}", client_ticket_path(ticket))
|
||||
td = link_to_creator(ticket)
|
||||
td = link_to ticket.title, client_ticket_path(ticket)
|
||||
td = ticket.tickets.empty? ? ticket.description : ticket.tickets.first.description
|
||||
td = ticket.short_description
|
||||
- if ticket.state == Ticket::CLOSE
|
||||
td.bg-danger = t ".states.close"
|
||||
- else
|
||||
td.bg-success = t ".states.open"
|
||||
td = ticket.updated_at.to_s(:long)
|
||||
td = ticket.last_response ? distance_of_time_in_words_to_now(ticket.last_response.updated_at) : "never"
|
||||
td = ticket.comments.empty? ? "never" : distance_of_time_in_words_to_now(ticket.comments.last.updated_at)
|
||||
td = link_to (t "show"), ticket
|
||||
td = link_to (t "edit"), edit_client_ticket_path(ticket)
|
||||
/ td = link_to 'Destroy', ticket, data: {:confirm => 'Are you sure?'}, :method => :delete
|
||||
td = link_to (t "respond"), client_ticket_respond_path(ticket) if ticket.open?
|
||||
- if ticket.open?
|
||||
td = link_to (t "close"), client_ticket_close_path(ticket), data: {:confirm => 'Are you sure?'}, :method => :patch
|
||||
- elsif ticket.close?
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
h1.page-header = "Ticket: #{@ticket.head.title}"
|
||||
h1.page-header = "Ticket: #{@ticket.title}"
|
||||
|
||||
p
|
||||
strong
|
||||
| Id: #
|
||||
= @ticket.id
|
||||
p
|
||||
strong = t ".respond_to"
|
||||
strong = t ".title"
|
||||
|:
|
||||
= link_to @ticket.head.title, client_ticket_path(@ticket.head)
|
||||
= link_to @ticket.title, client_ticket_path(@ticket)
|
||||
|
||||
p
|
||||
strong = t ".state"
|
||||
|:
|
||||
- if @ticket.head.state == Ticket::CLOSE
|
||||
- if @ticket.state == Ticket::CLOSE
|
||||
td.bg-danger = t ".states.close"
|
||||
- else
|
||||
td.bg-success = t ".states.open"
|
||||
|
@ -31,38 +31,15 @@ p
|
|||
.container-fluid.ticket-description
|
||||
= descriptionize @ticket.description
|
||||
|
||||
- if not @ticket.tickets.empty?
|
||||
table.table.table-condensed
|
||||
thead
|
||||
tr
|
||||
th = t ".creator"
|
||||
th = t ".title"
|
||||
th = t ".description"
|
||||
th = t ".state"
|
||||
th = t ".last_update"
|
||||
th
|
||||
/ th
|
||||
|
||||
tbody
|
||||
- @ticket.tickets.each do |ticket|
|
||||
tr
|
||||
td = link_to_creator(ticket)
|
||||
td = link_to ticket.title, client_ticket_path(ticket)
|
||||
td = ticket.short_description
|
||||
- if ticket.state == Ticket::CLOSE
|
||||
td.bg-danger = ticket.state
|
||||
- else
|
||||
td.bg-success = ticket.state
|
||||
td = ticket.updated_at.to_s(:long)
|
||||
td = link_to (t "show"), client_ticket_path(ticket)
|
||||
td = link_to (t "edit"), edit_client_ticket_path(ticket)
|
||||
/= render partial: "/comments/thread", locals {commentable: @ticket, type: 'client'}
|
||||
|
||||
br
|
||||
|
||||
- if @ticket.open?
|
||||
= link_to (t 'respond'), client_ticket_respond_path(@ticket), class: 'btn btn-sm btn-default'
|
||||
= link_to (t 'close'), client_ticket_close_path(@ticket), method: :patch, class: 'btn btn-sm btn-success'
|
||||
- else
|
||||
= link_to (t 'reopen'), client_ticket_open_path(@ticket), method: :patch, class: 'btn btn-sm btn-danger'
|
||||
= link_to (t 'edit'), edit_client_ticket_path(@ticket), class: 'btn btn-sm btn-default'
|
||||
= link_to (t 'back'), client_tickets_path, class: 'btn btn-sm btn-default'
|
||||
|
||||
== render partial: "/comments/thread", locals: {commentable: @ticket, type: 'user'}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
table.table.table-condensed
|
||||
table.table.table-condensed
|
||||
tr
|
||||
th Creator
|
||||
th Title
|
||||
th Content
|
||||
th
|
||||
- commentable.comments.each do |c|
|
||||
tr
|
||||
th Title
|
||||
th Content
|
||||
th
|
||||
- commentable.comments.each do |c|
|
||||
tr
|
||||
td = c.title
|
||||
td = c.comment
|
||||
td
|
||||
= link_to "/comments/#{c.id}.json", remote: true, data: {:confirm => 'Are you sure?'}, method: :delete, class: "close remove-comment", type: "button", "aria-label" => "Close" do
|
||||
span aria-hidden="true" ×
|
||||
|
||||
td = c.creator_type
|
||||
td = c.title
|
||||
td = c.comment
|
||||
td
|
||||
= link_to "/comments/#{c.id}.json", remote: true, data: {:confirm => 'Are you sure?'}, method: :delete, class: "close remove-comment", type: "button", "aria-label" => "Close" do
|
||||
span aria-hidden="true" ×
|
||||
|
|
10
app/views/comments/_about_client.html.slim
Normal file
10
app/views/comments/_about_client.html.slim
Normal file
|
@ -0,0 +1,10 @@
|
|||
table.table.table-condensed
|
||||
tr
|
||||
th Creator
|
||||
th Title
|
||||
th Content
|
||||
- commentable.comments.each do |c|
|
||||
tr
|
||||
td = c.creator_type
|
||||
td = c.title
|
||||
td = c.comment
|
4
app/views/comments/_thread.html.slim
Normal file
4
app/views/comments/_thread.html.slim
Normal file
|
@ -0,0 +1,4 @@
|
|||
#comments.container-fluid
|
||||
h2.page-header Comments
|
||||
= render partial: "/comments/form"
|
||||
= render partial: "/comments/about#{type == 'user' ? '_client' : '' }", locals: {commentable: commentable}
|
|
@ -1,4 +1 @@
|
|||
h2 = "Comments"
|
||||
|
||||
== render partial: 'about', locals: {commentable: @commentable}
|
||||
== render partial: '/comments/form'
|
||||
== render partial: 'thread', locals: {commentable: @commentable, type: 'admin'}
|
||||
|
|
1
app/views/comments/about_client.html.slim
Normal file
1
app/views/comments/about_client.html.slim
Normal file
|
@ -0,0 +1 @@
|
|||
== render partial: 'thread', locals: {commentable: @commentable, type: 'user'}
|
|
@ -14,7 +14,6 @@ table.table.table-condensed.
|
|||
th
|
||||
th
|
||||
th
|
||||
th
|
||||
|
||||
tbody
|
||||
- @tickets.each do |ticket|
|
||||
|
@ -22,17 +21,16 @@ table.table.table-condensed.
|
|||
td = link_to("##{ticket.id}", ticket)
|
||||
td = link_to_creator(ticket)
|
||||
td = link_to ticket.title, ticket
|
||||
td = ticket.tickets.empty? ? ticket.description : ticket.tickets.first.description
|
||||
td = ticket.short_description
|
||||
- if ticket.state == Ticket::CLOSE
|
||||
td.bg-danger = ticket.state
|
||||
- else
|
||||
td.bg-success = ticket.state
|
||||
td = ticket.updated_at.to_s(:long)
|
||||
td = ticket.last_response ? distance_of_time_in_words_to_now(ticket.last_response.updated_at) : "never"
|
||||
td = ticket.comments.empty? ? "never" : distance_of_time_in_words_to_now(ticket.comments.last.updated_at)
|
||||
td = link_to 'Show', ticket
|
||||
td = link_to 'Edit', edit_ticket_path(ticket)
|
||||
td = link_to 'Destroy', ticket, data: {:confirm => 'Are you sure?'}, :method => :delete
|
||||
td = link_to 'Respond', ticket_respond_path(ticket) if ticket.open?
|
||||
- if ticket.open?
|
||||
td = link_to 'Close', ticket_close_path(ticket), data: {:confirm => 'Are you sure?'}, :method => :patch
|
||||
- elsif ticket.close?
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
h1.page-header = "Show ticket: #{@ticket.head.title}"
|
||||
h1.page-header = "Show ticket: #{@ticket.title}"
|
||||
|
||||
p
|
||||
strong
|
||||
| Id: #
|
||||
= @ticket.id
|
||||
p
|
||||
strong Réponse à:
|
||||
= link_to @ticket.head.title, @ticket.head
|
||||
|
||||
p
|
||||
strong State:
|
||||
- if @ticket.head.state == Ticket::CLOSE
|
||||
td.bg-danger = @ticket.head.state
|
||||
- if @ticket.state == Ticket::CLOSE
|
||||
td.bg-danger = @ticket.state
|
||||
- else
|
||||
td.bg-success = @ticket.head.state
|
||||
td.bg-success = @ticket.state
|
||||
|
||||
p
|
||||
strong Creator:
|
||||
|
@ -29,38 +26,13 @@ p
|
|||
strong State:
|
||||
= @ticket.state
|
||||
|
||||
table.table.table-condensed.
|
||||
thead
|
||||
tr
|
||||
th Creator
|
||||
th Title
|
||||
th Description
|
||||
th Last update
|
||||
th
|
||||
th
|
||||
th
|
||||
|
||||
tbody
|
||||
- @ticket.tickets.each do |ticket|
|
||||
tr
|
||||
td = link_to_creator(ticket)
|
||||
td = link_to ticket.title, ticket
|
||||
td = ticket.description
|
||||
- if ticket.state == Ticket::CLOSE
|
||||
td.bg-danger = ticket.state
|
||||
- else
|
||||
td.bg-success = ticket.state
|
||||
td = ticket.updated_at.to_s(:long)
|
||||
td = link_to 'Show', ticket
|
||||
td = link_to 'Edit', edit_ticket_path(ticket)
|
||||
td = link_to 'Destroy', ticket, data: {:confirm => 'Are you sure?'}, :method => :delete
|
||||
|
||||
br
|
||||
|
||||
- if @ticket.open?
|
||||
= link_to 'Respond', ticket_respond_path(@ticket), class: 'btn btn-sm btn-default'
|
||||
= link_to 'Close', ticket_close_path(@ticket), method: :patch, class: 'btn btn-sm btn-success'
|
||||
- else
|
||||
= link_to 'Reopen', ticket_open_path(@ticket), method: :patch, class: 'btn btn-sm btn-danger'
|
||||
= link_to 'Edit', edit_ticket_path(@ticket), class: 'btn btn-sm btn-default'
|
||||
= link_to 'Back', tickets_path, class: 'btn btn-sm btn-default'
|
||||
|
||||
== render partial: "/comments/thread", locals: {commentable: @ticket, type: 'admin'}
|
||||
|
|
|
@ -9,7 +9,11 @@ Rails.application.routes.draw do
|
|||
resources :tickets do
|
||||
patch :close
|
||||
patch :open
|
||||
get :respond
|
||||
resources :comments do
|
||||
collection do
|
||||
get 'about'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
@ -55,7 +59,6 @@ Rails.application.routes.draw do
|
|||
resources :client_tickets, path: '/client/tickets' do
|
||||
patch :close
|
||||
patch :open
|
||||
get :respond
|
||||
end
|
||||
resources :client_bills, path: '/client/bills'
|
||||
|
||||
|
|
8
db/migrate/20160131000119_update_tickets.rb
Normal file
8
db/migrate/20160131000119_update_tickets.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
class UpdateTickets < ActiveRecord::Migration
|
||||
def change
|
||||
|
||||
rename_column :tickets, :head_creator_view_at, :creator_view_at
|
||||
remove_column :tickets, :ticket_id
|
||||
|
||||
end
|
||||
end
|
15
db/schema.rb
15
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150725193246) do
|
||||
ActiveRecord::Schema.define(version: 20160131000119) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -41,7 +41,7 @@ ActiveRecord::Schema.define(version: 20150725193246) do
|
|||
t.text "description"
|
||||
t.integer "amount"
|
||||
t.boolean "paid", default: false, null: false
|
||||
t.date "emission_date", default: '2015-07-24', null: false
|
||||
t.date "emission_date", default: '2016-01-30', null: false
|
||||
t.date "due_date", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
|
@ -96,18 +96,16 @@ ActiveRecord::Schema.define(version: 20150725193246) do
|
|||
create_table "tickets", force: :cascade do |t|
|
||||
t.integer "creator_id"
|
||||
t.string "creator_type"
|
||||
t.integer "ticket_id"
|
||||
t.string "title"
|
||||
t.text "description"
|
||||
t.string "state", default: "open", null: false
|
||||
t.string "state", default: "open", null: false
|
||||
t.time "admin_view_at"
|
||||
t.time "head_creator_view_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.time "creator_view_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_index "tickets", ["creator_type", "creator_id"], name: "index_tickets_on_creator_type_and_creator_id", using: :btree
|
||||
add_index "tickets", ["ticket_id"], name: "index_tickets_on_ticket_id", using: :btree
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "email", default: "", null: false
|
||||
|
@ -129,5 +127,4 @@ ActiveRecord::Schema.define(version: 20150725193246) do
|
|||
|
||||
add_foreign_key "bills", "clients"
|
||||
add_foreign_key "contacts", "clients"
|
||||
add_foreign_key "tickets", "tickets"
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user