From d1d4f8192da5a266cddb17bb8970b2b04387888c Mon Sep 17 00:00:00 2001 From: Shrey Date: Mon, 1 Jun 2015 21:28:14 +0530 Subject: [PATCH] DB changes + Related issues added --- app/assets/stylesheets/common.scss | 18 +++++++ app/controllers/issues_controller.rb | 8 +-- app/helpers/issues_helper.rb | 2 +- app/models/issue.rb | 6 ++- app/models/user.rb | 2 +- app/views/diary_entry/_diary_comment.html.erb | 2 +- app/views/diary_entry/_diary_entry.html.erb | 2 +- app/views/issues/_comments.html.erb | 5 +- app/views/issues/new.html.erb | 2 +- app/views/issues/show.html.erb | 50 ++++++++++++++----- app/views/user/view.html.erb | 2 +- config/locales/en-GB.yml | 1 + config/locales/en.yml | 1 + db/migrate/20150516073616_create_issues.rb | 14 ++++-- db/migrate/20150516075620_create_reports.rb | 7 +++ .../20150526130032_create_issue_comments.rb | 7 +++ ...50528113100_add_foreign_keys_for_issues.rb | 11 ---- .../20150528114520_add_indexes_for_issues.rb | 19 ------- db/structure.sql | 42 +++++++--------- 19 files changed, 119 insertions(+), 82 deletions(-) delete mode 100644 db/migrate/20150528113100_add_foreign_keys_for_issues.rb delete mode 100644 db/migrate/20150528114520_add_indexes_for_issues.rb diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index 24538ebfe..b658e4e32 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -2744,3 +2744,21 @@ input.richtext_title[type="text"] { background: #eee; opacity: 0.7; } + +.report-related-block { + display:inline-block; +} + +.report-block { + width:475px; + float:left; + margin-right:100px; +} + +.related-block{ + float:right; +} + +.issue-comments { + width:475px; +} \ No newline at end of file diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 752bcd236..c1c5dd4f3 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -14,12 +14,12 @@ class IssuesController < ApplicationController @read_reports = @issue.read_reports @unread_reports = @issue.unread_reports @comments = @issue.comments + @related_issues = @issue.user.issues end def new unless create_new_issue_params.blank? @issue = Issue.find_or_initialize_by(create_new_issue_params) - puts params[:user_id].to_s + "--------------" end end @@ -35,7 +35,7 @@ class IssuesController < ApplicationController @report = @issue.reports.build(report_params) @report.user_id = @user.id if @issue.save! - redirect_to root_path, notice: 'Issue was successfully created.' + redirect_to root_path, notice: 'Your report has been registered sucessfully.' else render :new end @@ -91,11 +91,11 @@ class IssuesController < ApplicationController end def create_new_issue_params - params.permit(:reportable_id, :reportable_type, :user_id) + params.permit(:reportable_id, :reportable_type, :reported_user_id) end def issue_params - params[:issue].permit(:reportable_id, :reportable_type,:user_id) + params[:issue].permit(:reportable_id, :reportable_type,:reported_user_id) end def report_params diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 109599be4..b063935ea 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -9,7 +9,7 @@ module IssuesHelper :display_name => reportable.user.display_name, :id => reportable.id when "User" - link_to reportable.display_name, :controller => reportable.class.name.underscore, + link_to reportable.display_name.to_s, :controller => reportable.class.name.underscore, :action => "view", :display_name => reportable.display_name when "DiaryComment" diff --git a/app/models/issue.rb b/app/models/issue.rb index 7a481fe6c..a9e2d2405 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1,10 +1,12 @@ class Issue < ActiveRecord::Base belongs_to :reportable, :polymorphic => true + belongs_to :user, :class_name => "User", :foreign_key => :reported_user_id + has_many :reports has_many :comments, :class_name => "IssueComment" + validates :reportable_id, :uniqueness => { :scope => [ :reportable_type ] } - belongs_to :user - validates :user_id, :presence => true + validates :reported_user_id, :presence => true # Check if more statuses are needed enum status: %w( open ignored resolved ) diff --git a/app/models/user.rb b/app/models/user.rb index 3d262fd25..866074766 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -26,7 +26,7 @@ class User < ActiveRecord::Base has_many :roles, :class_name => "UserRole" - has_many :issues + has_many :issues, :class_name => "Issue", :foreign_key => :reported_user_id has_many :issue_comments has_many :reports diff --git a/app/views/diary_entry/_diary_comment.html.erb b/app/views/diary_entry/_diary_comment.html.erb index 46aab6103..f53e30f45 100644 --- a/app/views/diary_entry/_diary_comment.html.erb +++ b/app/views/diary_entry/_diary_comment.html.erb @@ -5,5 +5,5 @@ <%= if_administrator(:span) do %> <%= link_to t('diary_entry.diary_comment.hide_link'), hide_diary_comment_path(:display_name => diary_comment.diary_entry.user.display_name, :id => diary_comment.diary_entry.id, :comment => diary_comment.id), :method => :post, :data=> { :confirm => t('diary_entry.diary_comment.confirm') } %> | <% end %> - <%= link_to 'Report', new_issue_url(reportable_id: diary_comment.id, reportable_type: diary_comment.class.name, user_id: diary_comment.user.id) %> + <%= link_to 'Report', new_issue_url(reportable_id: diary_comment.id, reportable_type: diary_comment.class.name, reported_user_id: diary_comment.user.id) %> diff --git a/app/views/diary_entry/_diary_entry.html.erb b/app/views/diary_entry/_diary_entry.html.erb index 8278e80b0..5b608c2d7 100644 --- a/app/views/diary_entry/_diary_entry.html.erb +++ b/app/views/diary_entry/_diary_entry.html.erb @@ -31,7 +31,7 @@ <%= link_to t('diary_entry.diary_entry.edit_link'), :action => 'edit', :display_name => diary_entry.user.display_name, :id => diary_entry.id %> <% end %> -
  • <%= link_to 'Report', new_issue_url(reportable_id: diary_entry.id, reportable_type: diary_entry.class.name, user_id: diary_entry.user.id) %>
  • +
  • <%= link_to 'Report', new_issue_url(reportable_id: diary_entry.id, reportable_type: diary_entry.class.name, reported_user_id: diary_entry.user.id) %>
  • <%= if_administrator(:li) do %> <%= link_to t('diary_entry.diary_entry.hide_link'), hide_diary_entry_path(:display_name => diary_entry.user.display_name, :id => diary_entry.id), :method => :post, :data => { :confirm => t('diary_entry.diary_entry.confirm') } %> diff --git a/app/views/issues/_comments.html.erb b/app/views/issues/_comments.html.erb index 3e236fb8e..de4989afd 100644 --- a/app/views/issues/_comments.html.erb +++ b/app/views/issues/_comments.html.erb @@ -1,3 +1,4 @@ +
    <% comments.each do |comment| %>
    @@ -10,9 +11,11 @@ On <%= l comment.created_at.to_datetime, :format => :long %>
    <% end %> +
    +
    <%= form_for :issue_comment, :url => { :action => 'comment', :id => @issue.id, :user_id => @user.id } do |f| %> - <%= richtext_area :issue_comment, :body, :cols => 80, :rows => 8 %> + <%= richtext_area :issue_comment, :body, :cols => 10, :rows => 8 %> <%= submit_tag 'Submit' %> <% end %>
    \ No newline at end of file diff --git a/app/views/issues/new.html.erb b/app/views/issues/new.html.erb index 2b26765b6..476e06be2 100644 --- a/app/views/issues/new.html.erb +++ b/app/views/issues/new.html.erb @@ -8,7 +8,7 @@
    <%= f.hidden_field :reportable_id %> <%= f.hidden_field :reportable_type %> - <%= f.hidden_field :user_id %> + <%= f.hidden_field :reported_user_id %>
    diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index abbe0fa98..84c52d077 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -4,30 +4,54 @@

    Issue type: <%= @issue.reportable_type %>

    - <%= @issue.reports.count %> reports | First reported: <%= l @issue.created_at.to_date, :format => :long %> | <%= "Last resolved at #{l(@issue.resolved_at.to_datetime, :format =>:long)}" if @issue.resolved? %> + <%= @issue.reports.count %> reports | First reported: <%= l @issue.created_at.to_date, :format => :long %> <%= "| Last resolved at #{l(@issue.resolved_at.to_datetime, :format =>:long)}" if @issue.resolved_at? %>

    <%= link_to "Resolve", resolve_issue_url(@issue), :method => :post if @issue.may_resolve? %>

    <%= link_to "Ignore", ignore_issue_url(@issue), :method => :post if @issue.may_ignore? %>

    <%= link_to "Reopen", reopen_issue_url(@issue), :method => :post if @issue.may_reopen? %>

    <% end %> -

    Reports under this issue:

    -<% if @read_reports.present? %> -
    -

    Read Reports:

    - <%= render 'reports',reports: @read_reports %> +