DB changes + Related issues added

This commit is contained in:
Shrey 2015-06-01 21:28:14 +05:30 committed by Matt Amos
parent bdc6adddbf
commit d1d4f8192d
19 changed files with 120 additions and 83 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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"

View file

@ -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 )

View file

@ -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

View file

@ -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) %>
</div>

View file

@ -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 %>
<li><%= link_to 'Report', new_issue_url(reportable_id: diary_entry.id, reportable_type: diary_entry.class.name, user_id: diary_entry.user.id) %></li>
<li><%= link_to 'Report', new_issue_url(reportable_id: diary_entry.id, reportable_type: diary_entry.class.name, reported_user_id: diary_entry.user.id) %></li>
<%= 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') } %>

View file

@ -1,3 +1,4 @@
<div class="issue-comments">
<% comments.each do |comment| %>
<div class="comment">
<div style="float:left">
@ -10,9 +11,11 @@
On <%= l comment.created_at.to_datetime, :format => :long %> </span>
<hr>
<% end %>
</div>
<br/>
<div class="comment">
<%= 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 %>
</div>

View file

@ -8,7 +8,7 @@
<div class='form-row'>
<%= f.hidden_field :reportable_id %>
<%= f.hidden_field :reportable_type %>
<%= f.hidden_field :user_id %>
<%= f.hidden_field :reported_user_id %>
</div>
<div class='form-row'>
<label class="standard-label"><%= t 'issue.new.message' -%></label>

View file

@ -4,30 +4,54 @@
<p>Issue type: <%= @issue.reportable_type %></p>
<p class="deemphasize">
<small>
<%= @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? %>
</small>
</p>
<p><%= link_to "Resolve", resolve_issue_url(@issue), :method => :post if @issue.may_resolve? %></p>
<p><%= link_to "Ignore", ignore_issue_url(@issue), :method => :post if @issue.may_ignore? %></p>
<p><%= link_to "Reopen", reopen_issue_url(@issue), :method => :post if @issue.may_reopen? %></p>
<% end %>
<h3>Reports under this issue:</h3>
<% if @read_reports.present? %>
<div class="read-reports">
<h4>Read Reports:</h4>
<%= render 'reports',reports: @read_reports %>
</div>
<% end %>
<div class="report-related-block">
<% if @unread_reports.any? %>
<div class="unread-reports">
<h4>New Reports:</h4>
<%= render 'reports',reports: @unread_reports %>
<div class="report-block">
<h3>Reports under this issue:</h3>
<% if @read_reports.present? %>
<div class="read-reports">
<h4>Read Reports:</h4>
<%= render 'reports',reports: @read_reports %>
</div>
<% end %>
<% if @unread_reports.any? %>
<div class="unread-reports">
<h4>New Reports:</h4>
<%= render 'reports',reports: @unread_reports %>
</div>
<% end %>
<br/>
</div>
<% end %>
<br/>
<div class="related-block">
<h3> Other issues against this user: </h3>
<div class="unread-reports">
<% if @related_issues.count > 1 %>
<% @related_issues.each do |issue| %>
<% if issue.id != @issue.id %>
<%= link_to "#{issue.reportable_type} ##{issue.reportable_id}", issue %>
<% end %>
<% end %>
<% else %>
<p>No other reports against this user!</p>
<% end %>
</div>
</div>
</div>
<h3>Comments on this issue:</h3>
<div class="unread-reports">
<%= render 'comments', comments: @comments %>
</div>

View file

@ -82,7 +82,7 @@
<% end %>
</li>
<li>
<%= link_to 'Report', new_issue_url(reportable_id: @this_user.id, reportable_type: @this_user.class.name, user_id: @this_user.id) %>
<%= link_to t('user.view.report'), new_issue_url(reportable_id: @this_user.id, reportable_type: @this_user.class.name, reported_user_id: @this_user.id) %>
</li>
<% if @this_user.blocks.exists? %>
<li>

View file

@ -1972,6 +1972,7 @@ en-GB:
friends_diaries: friends' diary entries
nearby_changesets: nearby user changesets
nearby_diaries: nearby user diary entries
report: Report User
popup:
your location: Your location
nearby mapper: Nearby mapper

View file

@ -1891,6 +1891,7 @@ en:
friends_diaries: "friends' diary entries"
nearby_changesets: "nearby user changesets"
nearby_diaries: "nearby user diary entries"
report: "Report User"
popup:
your location: "Your location"
nearby mapper: "Nearby mapper"

View file

@ -1,9 +1,11 @@
require "migrate"
class CreateIssues < ActiveRecord::Migration
def change
create_table :issues do |t|
t.string :reportable_type
t.integer :reportable_id
t.integer :user_id
t.string :reportable_type, :null => false
t.integer :reportable_id, :null => false
t.integer :reported_user_id, :null => false
t.integer :status
t.datetime :resolved_at
t.integer :resolved_by
@ -12,5 +14,11 @@ class CreateIssues < ActiveRecord::Migration
t.timestamps null: false
end
add_foreign_key :issues, :users, :column => :reported_user_id,:name => "issues_reported_user_id_fkey"
add_index :issues, :reported_user_id,
add_index :issues, [:reportable_id, :reportable_type]
end
end

View file

@ -9,5 +9,12 @@ class CreateReports < ActiveRecord::Migration
t.timestamps null: false
end
add_foreign_key :reports, :issues, :name => "reports_issue_id_fkey"
add_foreign_key :reports, :users, :name => "reports_user_id_fkey"
add_index :reports, :issue_id
add_index :reports, :user_id
end
end

View file

@ -8,5 +8,12 @@ class CreateIssueComments < ActiveRecord::Migration
t.timestamps null: false
end
add_foreign_key :issue_comments, :issues, :name => "issue_comments_issue_id_fkey"
add_foreign_key :issue_comments, :users, :name => "issue_comments_user_id"
add_index :issue_comments, :user_id
add_index :issue_comments, :issue_id
end
end

View file

@ -1,11 +0,0 @@
require "migrate"
class AddForeignKeysForIssues < ActiveRecord::Migration
def change
add_foreign_key :issues, :users, :name => "issues_user_id_fkey"
add_foreign_key :reports, :issues, :name => "reports_issue_id_fkey"
add_foreign_key :reports, :users, :name => "reports_user_id_fkey"
add_foreign_key :issue_comments, :issues, :name => "issue_comments_issue_id_fkey"
add_foreign_key :issue_comments, :users, :name => "issue_comments_user_id"
end
end

View file

@ -1,19 +0,0 @@
class AddIndexesForIssues < ActiveRecord::Migration
def self.up
add_index :issues, :user_id
add_index :issues, [:reportable_id, :reportable_type]
add_index :reports, :issue_id
add_index :reports, :user_id
add_index :issue_comments, :user_id
add_index :issue_comments, :issue_id
end
def self.down
remove_index :issues, :user_id
remove_index :issues, [:reportable_id, :reportable_type]
remove_index :reports, :issue_id
remove_index :reports, :user_id
remove_index :issue_comments, :user_id
remove_index :issue_comments, :issue_id
end
end

View file

@ -702,9 +702,9 @@ ALTER SEQUENCE issue_comments_id_seq OWNED BY issue_comments.id;
CREATE TABLE issues (
id integer NOT NULL,
reportable_type character varying,
reportable_id integer,
user_id integer,
reportable_type character varying NOT NULL,
reportable_id integer NOT NULL,
reported_user_id integer NOT NULL,
status integer,
resolved_at timestamp without time zone,
resolved_by integer,
@ -1989,20 +1989,6 @@ CREATE INDEX index_issue_comments_on_issue_id ON issue_comments USING btree (iss
CREATE INDEX index_issue_comments_on_user_id ON issue_comments USING btree (user_id);
--
-- Name: index_issues_on_reportable_id_and_reportable_type; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_issues_on_reportable_id_and_reportable_type ON issues USING btree (reportable_id, reportable_type);
--
-- Name: index_issues_on_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX index_issues_on_user_id ON issues USING btree (user_id);
--
-- Name: index_note_comments_on_body; Type: INDEX; Schema: public; Owner: -
--
@ -2150,6 +2136,20 @@ CREATE INDEX relations_changeset_id_idx ON relations USING btree (changeset_id);
CREATE INDEX relations_timestamp_idx ON relations USING btree ("timestamp");
--
-- Name: reportable_object_idx; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX reportable_object_idx ON issues USING btree (reportable_id, reportable_type);
--
-- Name: reported_user_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE INDEX reported_user_id_idx ON issues USING btree (reported_user_id);
--
-- Name: unique_schema_migrations; Type: INDEX; Schema: public; Owner: -
--
@ -2458,11 +2458,11 @@ ALTER TABLE ONLY issue_comments
--
-- Name: issues_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: issues_reported_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY issues
ADD CONSTRAINT issues_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id);
ADD CONSTRAINT issues_reported_user_id_fkey FOREIGN KEY (reported_user_id) REFERENCES users(id);
--
@ -2789,10 +2789,6 @@ INSERT INTO schema_migrations (version) VALUES ('20150516075620');
INSERT INTO schema_migrations (version) VALUES ('20150526130032');
INSERT INTO schema_migrations (version) VALUES ('20150528113100');
INSERT INTO schema_migrations (version) VALUES ('20150528114520');
INSERT INTO schema_migrations (version) VALUES ('21');
INSERT INTO schema_migrations (version) VALUES ('22');