]> git.openstreetmap.org Git - rails.git/commitdiff
DB changes + Related issues added
authorShrey <shrey14099@iiitd.ac.in>
Mon, 1 Jun 2015 15:58:14 +0000 (21:28 +0530)
committerMatt Amos <zerebubuth@gmail.com>
Mon, 22 Aug 2016 15:16:31 +0000 (16:16 +0100)
19 files changed:
app/assets/stylesheets/common.scss
app/controllers/issues_controller.rb
app/helpers/issues_helper.rb
app/models/issue.rb
app/models/user.rb
app/views/diary_entry/_diary_comment.html.erb
app/views/diary_entry/_diary_entry.html.erb
app/views/issues/_comments.html.erb
app/views/issues/new.html.erb
app/views/issues/show.html.erb
app/views/user/view.html.erb
config/locales/en-GB.yml
config/locales/en.yml
db/migrate/20150516073616_create_issues.rb
db/migrate/20150516075620_create_reports.rb
db/migrate/20150526130032_create_issue_comments.rb
db/migrate/20150528113100_add_foreign_keys_for_issues.rb [deleted file]
db/migrate/20150528114520_add_indexes_for_issues.rb [deleted file]
db/structure.sql

index 24538ebfeb7d1dcaeb3e8a45f2af2cd92968cdd0..b658e4e325781d18b7d68f7ac610382498e08a77 100644 (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;
+}
\ No newline at end of file
index 752bcd236c4523b9c4244cf13bc738fcf75b53c3..c1c5dd4f3d41b25dd175144b208c1fa66f1ada81 100644 (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
index 109599be4d7a9ccb4291f4f20ac08621ca5a8d40..b063935ea3c851649b066269de5408013d28c652 100644 (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"
index 7a481fe6cc80e0594f51a7ff167075a0a983d22b..a9e2d240568e4c515be2ca5aaef64d8cb4e9f389 100644 (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 )
index 3d262fd254a4c14f782b12c7198b9889a4887e13..866074766e462c176c2c18a4b5814c1a9aba81b3 100644 (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
index 46aab61034c8ee06e2ba9c3f579efa16ce560b34..f53e30f45434b32efdbeb881b864b401ec741127 100644 (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>
index 8278e80b07d668817cad5848dee9a61231f830be..5b608c2d7716c8bd8a6d5e8358b1fd8c2ba11871 100644 (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') } %>
index 3e236fb8e6c9df2642cd5e386a841a33e5bf50ef..de4989afd1852e3de9ddda4025e4446a42db66cd 100644 (file)
@@ -1,3 +1,4 @@
+<div class="issue-comments">
 <% comments.each do |comment| %>
        <div class="comment">
                <div style="float:left">
        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>
\ No newline at end of file
index 2b26765b6345b1291011bfb8e7d32c4c6e5b2bce..476e06be2bfd2f5eb3494718923636c7c0601786 100644 (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>
index abbe0fa985fb3626aa1a9d3f99dacdbfeffaf2ee..84c52d077e89f2d9f07df87279e8177d397e629a 100644 (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 class="report-related-block">
+
+       <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 %>      
 
-<% if @unread_reports.any? %>
-       <div class="unread-reports">
-               <h4>New Reports:</h4>
-               <%= render 'reports',reports: @unread_reports %>
+       <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>
-<% end %>      
-<br/>
+
+</div>
+
 <h3>Comments on this issue:</h3>
        <div class="unread-reports">
                <%= render 'comments', comments: @comments %>
        </div>
+
index 7a422700d288bf3b918973cef1403f13ac0fddfc..41d7b0064213c819b62fa66486cbed77a4d16767 100644 (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>
index f3f2a6859b93cfba616636c624ec98be75addaed..e46cc3c26d62d9d82e26c6b6136d70b3ee899a1f 100644 (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
index 9a03a6a7f16aeca62dd87689bd3cc79101374e98..24a829625db310bac344d5c1a4c2c15715737237 100644 (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"
index 3a59c9eb09b0c75e47187a36d6052334430d09b4..32e9976a21e47b68f9b2e242ded28d6acd2efc7f 100644 (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
index bcdc3104ef42594060eaf13a337a17405efc1020..abae0f7050dffdc5c49223b35a2ac9ae98cea925 100644 (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
index 92b328f9ab4cd0e9685d5610ec1f0f2c80efd3da..63f6283541e7eef88d442a7c7212ad44c01bd093 100644 (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
diff --git a/db/migrate/20150528113100_add_foreign_keys_for_issues.rb b/db/migrate/20150528113100_add_foreign_keys_for_issues.rb
deleted file mode 100644 (file)
index 4d0d28e..0000000
+++ /dev/null
@@ -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
diff --git a/db/migrate/20150528114520_add_indexes_for_issues.rb b/db/migrate/20150528114520_add_indexes_for_issues.rb
deleted file mode 100644 (file)
index 071bf4f..0000000
+++ /dev/null
@@ -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
index f0a07adf5df13a0f5d7bf9091c9f5f98b42e8184..efabdbee696899a7057a785dd424b291eb40e711 100644 (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');