]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/5575'
authorTom Hughes <tom@compton.nu>
Wed, 29 Jan 2025 18:41:43 +0000 (18:41 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 29 Jan 2025 18:41:43 +0000 (18:41 +0000)
app/assets/javascripts/index/layers/data.js
app/assets/javascripts/index/layers/notes.js
app/assets/javascripts/leaflet.map.js
app/assets/stylesheets/common.scss
app/controllers/issues_controller.rb
app/views/issues/_page.html.erb
config/locales/en.yml
test/system/issues_test.rb
test/system/note_layer_test.rb [new file with mode: 0644]

index 3cc8f61357d9b99c5c040978dd6012081ca9f8a8..dc522af418d809f6e16c90ccf5b91a67bf211494 100644 (file)
@@ -73,10 +73,8 @@ OSM.initializeDataLayer = function (map) {
             $("<button type='button' class='btn-close'>")
               .attr("aria-label", I18n.t("javascripts.close"))
               .click(close))),
-        $("<div>").append(
-          $("<div class='d-flex'>").append(
-            $("<p class='alert alert-warning'>")
-              .text(I18n.t("browse.start_rjs.feature_error", { message: message }))))));
+        $("<p class='alert alert-warning'>")
+          .text(I18n.t("browse.start_rjs.feature_error", { message: message }))));
   }
 
   function getData() {
index c0ba35d7e1b0d6f7c2e3819af78f1a7aada91f6f..24bf969b3380581e9e3b07f35873b36a9fe6a170 100644 (file)
@@ -1,6 +1,7 @@
 OSM.initializeNotesLayer = function (map) {
-  var noteLayer = map.noteLayer,
-      notes = {};
+  let noteLoader;
+  const noteLayer = map.noteLayer;
+  let notes = {};
 
   var noteIcons = {
     "new": L.icon({
@@ -25,6 +26,8 @@ OSM.initializeNotesLayer = function (map) {
     map.on("moveend", loadNotes);
     map.fire("overlayadd", { layer: noteLayer });
   }).on("remove", () => {
+    if (noteLoader) noteLoader.abort();
+    noteLoader = null;
     map.off("moveend", loadNotes);
     noteLayer.clearLayers();
     notes = {};
@@ -40,9 +43,16 @@ OSM.initializeNotesLayer = function (map) {
     if (marker) {
       marker.setIcon(noteIcons[feature.properties.status]);
     } else {
+      let title;
+      const description = feature.properties.comments[0];
+
+      if (description?.action === "opened") {
+        title = description.text;
+      }
+
       marker = L.marker(feature.geometry.coordinates.reverse(), {
         icon: noteIcons[feature.properties.status],
-        title: feature.properties.comments[0].text,
+        title,
         opacity: 0.8,
         interactive: true
       });
@@ -56,8 +66,6 @@ OSM.initializeNotesLayer = function (map) {
     return marker.id;
   };
 
-  var noteLoader;
-
   function loadNotes() {
     var bounds = map.getBounds();
     var size = bounds.getSize();
index bdc8532d15a890522734d01ea0c803b1deb65434..10ce9471580b038c776c232c3a953c6d499c5559 100644 (file)
@@ -115,19 +115,18 @@ L.OSM.Map = L.Map.extend({
   },
 
   updateLayers: function (layerParam) {
-    var layers = layerParam || "M";
+    const oldBaseLayer = this.getMapBaseLayer();
+    let newBaseLayer;
 
-    for (let i = this.baseLayers.length - 1; i >= 0; i--) {
-      if (layers.indexOf(this.baseLayers[i].options.code) === -1) {
-        this.removeLayer(this.baseLayers[i]);
+    for (const layer of this.baseLayers) {
+      if (!newBaseLayer || layerParam.includes(layer.options.code)) {
+        newBaseLayer = layer;
       }
     }
 
-    for (let i = this.baseLayers.length - 1; i >= 0; i--) {
-      if (layers.indexOf(this.baseLayers[i].options.code) >= 0 || i === 0) {
-        this.addLayer(this.baseLayers[i]);
-        return;
-      }
+    if (newBaseLayer !== oldBaseLayer) {
+      if (oldBaseLayer) this.removeLayer(oldBaseLayer);
+      if (newBaseLayer) this.addLayer(newBaseLayer);
     }
   },
 
index 098370689a0ec29215550527b4c08f0f58352a13..92b9f72409caebbe20fadaad52e55e5f26fc4ded 100644 (file)
@@ -816,6 +816,14 @@ tr.turn {
   }
 }
 
+/* Rules for the issues page */
+
+.issues.issues-index {
+  td.reporter_users {
+    max-width: 5rem;
+  }
+}
+
 /* Rules for the account confirmation page */
 
 .accounts-terms-show {
index 5cedb3c705b5eeaeb42647057cb8de3c3cec7c8b..298f7c37450a6376cd43e95013cebba99442c2a5 100644 (file)
@@ -44,6 +44,15 @@ class IssuesController < ApplicationController
     end
 
     @issues, @newer_issues_id, @older_issues_id = get_page_items(@issues, :limit => @params[:limit])
+
+    @unique_reporters = @issues.each_with_object({}) do |issue, reporters|
+      user_ids = issue.reports.order(:created_at => :desc).pluck(:user_id).uniq
+      reporters[issue.id] = {
+        :count => user_ids.size,
+        :users => User.in_order_of(:id, user_ids.first(3))
+      }
+    end
+
     render :partial => "page" if turbo_frame_request_id == "pagination"
   end
 
index f625f0e0434ece3dcf3e8f244f65cfd50e6c30ab..6b291e58d082708362d28e32d05861c0d893c76f 100644 (file)
@@ -13,6 +13,7 @@
           <th><%= t ".reports" %></th>
           <th><%= t ".reported_item" %></th>
           <th><%= t ".reported_user" %></th>
+          <th class="reporter_users"><%= t ".reporter_users" %></th>
           <th><%= t ".last_updated" %></th>
         </tr>
       </thead>
             <td class="text-nowrap"><%= link_to t(".reports_count", :count => issue.reports_count), issue %></td>
             <td><%= link_to reportable_title(issue.reportable), reportable_url(issue.reportable) %></td>
             <td><%= link_to issue.reported_user.display_name, issue.reported_user if issue.reported_user %></td>
+            <td class="reporter_users text-truncate">
+              <% @unique_reporters[issue.id][:users].each do |reporter| %>
+                <%= link_to reporter.display_name, reporter, :class => "d-block text-truncate", :title => reporter.display_name %>
+              <% end %>
+              <% if @unique_reporters[issue.id][:count] > 3 %>
+                <p class="m-0"><%= t ".more_reporters", :count => @unique_reporters[issue.id][:count] - 3 %></p>
+              <% end %>
+            </td>
             <td>
               <% if issue.user_updated %>
                 <%= t ".last_updated_time_ago_user_html", :user => link_to(issue.user_updated.display_name, issue.user_updated),
index 38b810d1f6768fd64a2b00d2619e48920ba8315c..172c6618232aedb1927e280e0cc55cd504e0aa18 100644 (file)
@@ -1512,9 +1512,11 @@ en:
       reports: Reports
       last_updated: Last Updated
       last_updated_time_ago_user_html: "%{time_ago} by %{user}"
+      reporter_users: Reporter Users
       reports_count:
         one: "%{count} Report"
         other: "%{count} Reports"
+      more_reporters: "and %{count} more"
       reported_item: Reported Item
       states:
         ignored: Ignored
index 327b888bc4e980f7076b67b69af7f4e98ce12170..a961ea80f7a54099597920e2073c0055a573cad9 100644 (file)
@@ -204,4 +204,48 @@ class IssuesTest < ApplicationSystemTestCase
       assert_no_content(/extra_#{n}[^\d]/i)
     end
   end
+
+  def test_single_issue_reporters
+    sign_in_as(create(:moderator_user))
+    issue = create(:issue, :assigned_role => "moderator")
+    issue.reports << create(:report, :user => create(:user, :display_name => "Test Name"))
+
+    visit issues_path
+    assert_content issue.reported_user.display_name
+    assert_content issue.reports.first.user.display_name
+  end
+
+  def test_multiple_issue_reporters
+    sign_in_as(create(:moderator_user))
+    issue = create(:issue, :assigned_role => "moderator")
+
+    create_list(:report, 5, :issue => issue)
+
+    visit issues_path
+    0.upto(1).each do |n|
+      assert_no_content issue.reports[n].user.display_name
+    end
+    2.upto(4).each do |n|
+      assert_content issue.reports[n].user.display_name
+    end
+  end
+
+  def test_ordering_issue_reporters
+    sign_in_as(create(:moderator_user))
+    issue = create(:issue, :assigned_role => "moderator")
+
+    create_list(:report, 5, :issue => issue)
+
+    4.downto(0).each do |n|
+      issue.reports << create(:report, :user => issue.reports[n].user)
+    end
+
+    visit issues_path
+    0.upto(2).each do |n|
+      assert_content issue.reports[n].user.display_name
+    end
+    3.upto(4).each do |n|
+      assert_no_content issue.reports[n].user.display_name
+    end
+  end
 end
diff --git a/test/system/note_layer_test.rb b/test/system/note_layer_test.rb
new file mode 100644 (file)
index 0000000..792c341
--- /dev/null
@@ -0,0 +1,40 @@
+require "application_system_test_case"
+
+class NoteLayerTest < ApplicationSystemTestCase
+  test "note marker should have description as a title" do
+    position = (1.1 * GeoRecord::SCALE).to_i
+    create(:note, :latitude => position, :longitude => position) do |note|
+      create(:note_comment, :note => note, :body => "Note description")
+    end
+
+    visit root_path(:anchor => "map=18/1.1/1.1&layers=N")
+    all "img.leaflet-marker-icon", :count => 1 do |marker|
+      assert_equal "Note description", marker["title"]
+    end
+  end
+
+  test "note marker should not have a title if the note has no visible description" do
+    position = (1.1 * GeoRecord::SCALE).to_i
+    create(:note, :latitude => position, :longitude => position) do |note|
+      create(:note_comment, :note => note, :body => "Note description is hidden", :visible => false)
+      create(:note_comment, :note => note, :body => "Note comment visible", :event => "commented")
+    end
+
+    visit root_path(:anchor => "map=18/1.1/1.1&layers=N")
+    all "img.leaflet-marker-icon", :count => 1 do |marker|
+      assert_equal "", marker["title"]
+    end
+  end
+
+  test "note marker should not have a title if the note has no visible description and comments" do
+    position = (1.1 * GeoRecord::SCALE).to_i
+    create(:note, :latitude => position, :longitude => position) do |note|
+      create(:note_comment, :note => note, :body => "Note description is hidden", :visible => false)
+    end
+
+    visit root_path(:anchor => "map=18/1.1/1.1&layers=N")
+    all "img.leaflet-marker-icon", :count => 1 do |marker|
+      assert_equal "", marker["title"]
+    end
+  end
+end