]> git.openstreetmap.org Git - rails.git/commitdiff
Merge branch 'anonymous-notes-counter'
authorAnton Khorev <tony29@yandex.ru>
Mon, 13 Jan 2025 11:50:26 +0000 (14:50 +0300)
committerAnton Khorev <tony29@yandex.ru>
Mon, 13 Jan 2025 11:50:26 +0000 (14:50 +0300)
app/assets/javascripts/index/new_note.js
app/controllers/concerns/session_methods.rb
app/controllers/confirmations_controller.rb
app/controllers/notes_controller.rb
app/views/notes/new.html.erb
config/locales/en.yml

index 885d7d2c994b22f5a35b27d1143b5df3254fa75e..4f38f8b55754267eab293788c51793df986a3064 100644 (file)
@@ -162,6 +162,10 @@ OSM.NewNote = function (map) {
       newNoteMarker.dragging.disable();
 
       createNote(location, text, (feature) => {
+        if (typeof OSM.user === "undefined") {
+          var anonymousNotesCount = Number(Cookies.get("_osm_anonymous_notes_count")) || 0;
+          Cookies.set("_osm_anonymous_notes_count", anonymousNotesCount + 1, { secure: true, expires: 30, path: "/", samesite: "lax" });
+        }
         content.find("textarea").val("");
         addCreatedNoteMarker(feature);
         OSM.router.route("/note/" + feature.properties.id);
index 2cfc4e82311e642635308ad32717fa3c0664ff63..4bbfac34f6dff3305b576e343a6e119e95784249 100644 (file)
@@ -39,6 +39,8 @@ module SessionMethods
     session[:fingerprint] = user.fingerprint
     session_expires_after 28.days if session[:remember_me]
 
+    cookies.delete :_osm_anonymous_notes_count
+
     target = referer || url_for(:controller => :site, :action => :index)
 
     # The user is logged in, so decide where to send them:
index 7bbb3a0937b538ef95abffd014c58bab7443418c..72c1955e039ebf225f862752dff681b978fc2e78 100644 (file)
@@ -30,6 +30,7 @@ class ConfirmationsController < ApplicationController
         user.email_valid = true
         flash[:notice] = gravatar_status_message(user) if gravatar_enable(user)
         user.save!
+        cookies.delete :_osm_anonymous_notes_count
         referer = safe_referer(params[:referer]) if params[:referer]
 
         pending_user = session.delete(:pending_user)
index c40e776b444074efc192c9e4ae496924a05dc640..4b4f3d6515f3698370e74d2c92cc96b779b642ac 100644 (file)
@@ -45,6 +45,7 @@ class NotesController < ApplicationController
   end
 
   def new
+    @anonymous_notes_count = request.cookies["_osm_anonymous_notes_count"].to_i || 0
     render :action => :new_readonly if api_status != "online"
   end
 end
index 4ae4a995da658be5da60b7053c2d02f509bc1228..5be707dfe38462acc700e9fd4a1c8449799ab801 100644 (file)
@@ -5,9 +5,17 @@
 <div class="note">
   <p class="alert alert-info"><%= t(".intro") %></p>
   <% if !current_user %>
-    <p class="alert alert-warning"><%= t ".anonymous_warning_html",
-                                         :log_in => link_to(t(".anonymous_warning_log_in"), login_path(:referer => new_note_path)),
-                                         :sign_up => link_to(t(".anonymous_warning_sign_up"), new_user_path) %></p>
+    <div class="alert alert-warning pb-0">
+      <p><%= t ".anonymous_warning_html",
+               :log_in => link_to(t(".anonymous_warning_log_in"), login_path(:referer => new_note_path)),
+               :sign_up => link_to(t(".anonymous_warning_sign_up"), new_user_path) %></p>
+    <% if @anonymous_notes_count >= 10 %>
+      <p><%= t ".counter_warning_html",
+               :x_anonymous_notes => t(".x_anonymous_notes", :count => @anonymous_notes_count),
+               :contribute_by_yourself => link_to(t(".counter_warning_guide_link.text"), t(".counter_warning_guide_link.url")),
+               :community_can_help => link_to(t(".counter_warning_forum_link.text"), t(".counter_warning_forum_link.url")) %></p>
+    <% end %>
+    </div>
   <% end %>
   <p class="alert alert-warning" id="new-note-zoom-warning" hidden><%= t "javascripts.site.createnote_disabled_tooltip" %></p>
   <form action="#">
index a62f4d34fc6b5ecf279701d8fb609a098bcd1056..d1faa7a50c2b428938565059e94388e63fd6d20b 100644 (file)
@@ -3087,9 +3087,19 @@ en:
     new:
       title: "New Note"
       intro: "Spotted a mistake or something missing? Let other mappers know so we can fix it. Move the marker to the correct position and type a note to explain the problem."
-      anonymous_warning_html: "You are not logged in. Please %{log_in} or %{sign_up} if you want to receive updates for your note."
+      anonymous_warning_html: "You are not logged in. Please %{log_in} or %{sign_up} to receive updates for your note and help mappers resolve it."
       anonymous_warning_log_in: "log in"
       anonymous_warning_sign_up: "sign up"
+      counter_warning_html: "You have already posted at least %{x_anonymous_notes}, that's great for the community, thank you! Now we encourage you to %{contribute_by_yourself}, it is not that complicated, and %{community_can_help}."
+      x_anonymous_notes:
+        one: "%{count} anonymous note"
+        other: "%{count} anonymous notes"
+      counter_warning_guide_link:
+        text: "contribute by yourself"
+        url: https://wiki.openstreetmap.org/wiki/Beginners%27_guide
+      counter_warning_forum_link:
+        text: "the community can help you"
+        url: https://community.openstreetmap.org/
       advice: "Your note is public and may be used to update the map, so don't enter personal information, or information from copyrighted maps or directory listings."
       add: Add Note
     new_readonly: