Controllers + a few tests + new notification added. Work pending on the notification view
This commit is contained in:
parent
5add3cf671
commit
453f758f91
14 changed files with 201 additions and 0 deletions
3
app/assets/javascripts/issues.coffee
Normal file
3
app/assets/javascripts/issues.coffee
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://coffeescript.org/
|
3
app/assets/stylesheets/issues.scss
Normal file
3
app/assets/stylesheets/issues.scss
Normal file
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the issues controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
85
app/controllers/issues_controller.rb
Normal file
85
app/controllers/issues_controller.rb
Normal file
|
@ -0,0 +1,85 @@
|
|||
class IssuesController < ApplicationController
|
||||
layout "site"
|
||||
|
||||
before_action :find_issue, only: [:show, :resolve, :reopen, :ignore]
|
||||
|
||||
def index
|
||||
@issues = Issue.all
|
||||
end
|
||||
|
||||
def show
|
||||
@read_reports = @issue.read_reports
|
||||
@unread_reports = @issue.unread_reports
|
||||
end
|
||||
|
||||
def new
|
||||
unless create_new_issue_params.blank?
|
||||
@issue = Issue.find_or_initialize_by(create_new_issue_params)
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@issue = Issue.find_by_reportable_id_and_reportable_type(params[:reportable_id],params[:reportable_type])
|
||||
if !@issue
|
||||
@issue = Issue.find_or_initialize_by(issue_params)
|
||||
@admins = UserRole.where(role: "administrator")
|
||||
@admins.each do |user|
|
||||
Notifier.new_issue_notification(User.find(user.user_id)).deliver_now
|
||||
end
|
||||
end
|
||||
|
||||
@report = @issue.reports.build(report_params)
|
||||
|
||||
if @issue.save
|
||||
redirect_to @issue, notice: 'Issue was successfully created.'
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
# Status Transistions
|
||||
def resolve
|
||||
if @issue.resolve
|
||||
@issue.save!
|
||||
redirect_to @issue, notice: "Issue status has been set to: 'Resolved'"
|
||||
else
|
||||
render :show
|
||||
end
|
||||
end
|
||||
|
||||
def ignore
|
||||
if @issue.ignore
|
||||
@issue.save!
|
||||
redirect_to @issue, notice: "Issue status has been set to: 'Ignored'"
|
||||
else
|
||||
render :show
|
||||
end
|
||||
end
|
||||
|
||||
def reopen
|
||||
if @issue.reopen
|
||||
@issue.save!
|
||||
redirect_to @issue, notice: "Issue status has been set to: 'Open'"
|
||||
else
|
||||
render :show
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_issue
|
||||
@issue = Issue.find(params[:id])
|
||||
end
|
||||
|
||||
def create_new_issue_params
|
||||
params.permit(:reportable_id, :reportable_type, :user_id)
|
||||
end
|
||||
|
||||
def issue_params
|
||||
params[:issue].permit(:reportable_id, :reportable_type,:user_id)
|
||||
end
|
||||
|
||||
def report_params
|
||||
params[:report].permit(:details)
|
||||
end
|
||||
end
|
2
app/helpers/issues_helper.rb
Normal file
2
app/helpers/issues_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module IssuesHelper
|
||||
end
|
|
@ -2,6 +2,7 @@ class Issue < ActiveRecord::Base
|
|||
belongs_to :reportable, :polymorphic => true
|
||||
has_many :reports
|
||||
validates :reportable_id, :uniqueness => { :scope => [ :reportable_type ] }
|
||||
belongs_to :user_id
|
||||
|
||||
# Check if more statuses are needed
|
||||
enum status: %w( open ignored resolved )
|
||||
|
|
|
@ -172,6 +172,13 @@ class Notifier < ActionMailer::Base
|
|||
end
|
||||
end
|
||||
|
||||
def new_issue_notification(recipient)
|
||||
with_recipient_locale recipient do
|
||||
subject = I18n.t("notifier.new_issue_notification.subject")
|
||||
mail :to => recipient.email, :subject => subject
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def with_recipient_locale(recipient)
|
||||
|
@ -187,4 +194,5 @@ class Notifier < ActionMailer::Base
|
|||
EMAIL_FROM
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
2
app/views/issues/index.html.erb
Normal file
2
app/views/issues/index.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
|||
<h1>Issues#index</h1>
|
||||
<p>Find me in app/views/issues/index.html.erb</p>
|
2
app/views/issues/new.html.erb
Normal file
2
app/views/issues/new.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
|||
<h1>Issues#new</h1>
|
||||
<p>Find me in app/views/issues/new.html.erb</p>
|
2
app/views/issues/show.html.erb
Normal file
2
app/views/issues/show.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
|||
<h1>Issues#show</h1>
|
||||
<p>Find me in app/views/issues/show.html.erb</p>
|
5
app/views/notifier/new_issue_notification.html.erb
Normal file
5
app/views/notifier/new_issue_notification.html.erb
Normal file
|
@ -0,0 +1,5 @@
|
|||
<p><%= t("notifier.new_issue_notification.greeting") %></p>
|
||||
|
||||
<p><%= t("notifier.new_issue_notification.new_issue") %></p>
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue