]> git.openstreetmap.org Git - rails.git/commitdiff
Merge pull request #5362 from AntonKhorev/color-mode-preference-map
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 11 Dec 2024 16:53:15 +0000 (16:53 +0000)
committerGitHub <noreply@github.com>
Wed, 11 Dec 2024 16:53:15 +0000 (16:53 +0000)
Map color mode preference

1  2 
app/assets/stylesheets/common.scss
app/controllers/application_controller.rb
config/locales/en.yml

index c5e2d14b1577a8a35e90747739616b5f56b6b672,d39535417e1d6868c8f2c7b6b3560568d9feac19..cabdfff493bac420e9daa5b1fe0b3cc3bc6570b9
@@@ -1,5 -1,6 +1,5 @@@
  @use "sass:map";
  @import "parameters";
 -@import "browse";
  @import "bootstrap";
  @import "rails_bootstrap_forms";
  
@@@ -216,10 -217,6 +216,10 @@@ body.small-nav 
      .search_forms {
        display: block;
      }
 +
 +    .username {
 +      max-width: unset;
 +    }
    }
  
    #sidebar .search_forms {
  }
  
  @include color-mode(dark) {
-   .leaflet-tile-container .leaflet-tile,
-   .mapkey-table-entry td:first-child > * {
-     filter: brightness(.8);
-   }
    .leaflet-container .leaflet-control-attribution a {
      color: var(--bs-link-color);
    }
    }
  }
  
+ @mixin dark-map-color-scheme {
+   .leaflet-tile-container .leaflet-tile,
+   .mapkey-table-entry td:first-child > * {
+     filter: brightness(.8);
+   }
+ }
+ body[data-map-theme="dark"] {
+   @include dark-map-color-scheme;
+ }
+ @include color-mode(dark) {
+   body:not([data-map-theme]) {
+     @include dark-map-color-scheme;
+   }
+ }
  /* Rules for attribution text under the main map shown on printouts */
  
  .donate-attr { color: darken($green, 10%) !important; }
@@@ -935,18 -944,13 +947,18 @@@ div.secondary-actions 
    }
  }
  
 -/* Rules for block pages */
 +/* Rules for tables with usernames */
  
 +.messages-table .username,
  #block_list .username {
    max-width: 20em;
  }
  
 -/* Rules for tabs inside secondary background sections */
 +/* Rules for navigation tabs */
 +
 +.nav-tabs .username {
 +  max-width: 20em;
 +}
  
  .bg-body-secondary .nav-tabs {
    --bs-border-color: var(--bs-secondary-border-subtle);
@@@ -969,20 -973,34 +981,20 @@@ img.trace_image 
  
  /* Rules for map sidebar icons */
  
 -.browse-section {
 -  .node::before,
 -  .way::before,
 -  .relation::before {
 -    display: inline-block;
 -    width: 25px;
 -    margin-left: -25px;
 -  }
 +.browse-section .browse-element-list {
 +  line-height: 1.25rem;
  
 -  .node, .way, .relation {
 -    margin-left: 25px;
 +  .browse-icon {
 +    height: 1.25rem;
    }
  
 -  .node::before     { content: image-url('browse/node.svg'); }
 -  .way::before      { content: image-url('browse/way.svg'); }
 -  .relation::before { content: image-url('browse/relation.svg'); }
 -}
 -
 -@each $class, $item in $map-sidebar-icons {
 -  .browse-section #{$class}::before {
 -    content: image-url('browse/#{map.get($item, "filename")}');
 +  .d-flex > .browse-icon {
 +    height: max(20px, 1.25rem);
    }
  
 -  @if map.get($item, "invert") {
 -    @include color-mode(dark) {
 -      .browse-section #{$class}::before {
 -        filter: invert(.8) hue-rotate(180deg);
 -      }
 +  @include color-mode(dark) {
 +    .browse-icon-invertible {
 +      filter: invert(.8) hue-rotate(180deg);
      }
    }
  }
index bde7e028765c81b5426a5eed2e8c74957abee4b2,5bfec4ab62f219ac3cad9d114ee8d4606d84e6ae..32b53bad71c3f431d79234d65e354f6cafcf13c9
@@@ -21,7 -21,7 +21,7 @@@ class ApplicationController < ActionCon
  
    def self.allow_thirdparty_images(**options)
      content_security_policy(options) do |policy|
 -      policy.img_src("*")
 +      policy.img_src("*", :data)
      end
    end
  
    def map_layout
      policy = request.content_security_policy.clone
  
 -    policy.child_src(*policy.child_src, "http://127.0.0.1:8111", "https://127.0.0.1:8112")
 -    policy.frame_src(*policy.frame_src, "http://127.0.0.1:8111", "https://127.0.0.1:8112")
 -    policy.connect_src(*policy.connect_src, Settings.nominatim_url, Settings.overpass_url, Settings.fossgis_osrm_url, Settings.graphhopper_url, Settings.fossgis_valhalla_url)
 +    policy.connect_src(*policy.connect_src, "http://127.0.0.1:8111", Settings.nominatim_url, Settings.overpass_url, Settings.fossgis_osrm_url, Settings.graphhopper_url, Settings.fossgis_valhalla_url)
      policy.form_action(*policy.form_action, "render.openstreetmap.org")
      policy.style_src(*policy.style_src, :unsafe_inline)
  
      end
    end
  
-   helper_method :preferred_editor
+   def preferred_color_scheme(subject)
+     if current_user
+       current_user.preferences.find_by(:k => "#{subject}.color_scheme")&.v || "auto"
+     else
+       "auto"
+     end
+   end
+   helper_method :preferred_editor, :preferred_color_scheme
  
    def update_totp
      if Settings.key?(:totp_key)
diff --combined config/locales/en.yml
index c3a0c5aed0802f2afe1c8acaf4eafee1f5c7e8e4,770e8e40ac09faa4235437495012fc99fb6b00bf..94fc77247b8cadc74f8f433dbbc18a05ddedf1a2
@@@ -59,7 -59,6 +59,7 @@@ en
        message: "Message"
        node: "Node"
        node_tag: "Node Tag"
 +      note: "Note"
        old_node: "Old Node"
        old_node_tag: "Old Node Tag"
        old_relation: "Old Relation"
          way: "Way"
          relation: "Relation"
      containing_relation:
 -      entry_html: "Relation %{relation_name}"
 -      entry_role_html: "Relation %{relation_name} (as %{relation_role})"
 +      entry_role_html: "%{relation_name} (as %{relation_role})"
      not_found:
        title: Not Found
        sorry: "Sorry, %{type} #%{id} could not be found."
          open: Open
          resolved: Resolved
      show:
 -      title: "%{status} Issue #%{issue_id}"
 +      title:
 +        open: "Open Issue #%{issue_id}"
 +        ignored: "Ignored Issue #%{issue_id}"
 +        resolved: "Resolved Issue #%{issue_id}"
        reports:
          one: "%{count} report"
          other: "%{count} reports"
        title: My Preferences
        preferred_editor: Preferred Editor
        preferred_languages: Preferred Languages
+       preferred_site_color_scheme: Preferred Website Color Scheme
+       site_color_schemes:
+         auto: Auto
+         light: Light
+         dark: Dark
+       preferred_map_color_scheme: Preferred Map Color Scheme
+       map_color_schemes:
+         auto: Auto
+         light: Light
+         dark: Dark
        edit_preferences: Edit Preferences
      edit:
        title: Edit Preferences
        upload_trace: "Upload a trace"
        all_traces: "All Traces"
        my_traces: "My Traces"
 -      traces_from: "Public Traces from %{user}"
 +      traces_from_html: "Public Traces from %{user}"
        remove_tag_filter: "Remove Tag Filter"
      destroy:
        scheduled_for_deletion: "Trace scheduled for deletion"
          years:
            one: "%{count} year"
            other: "%{count} years"
 +      short:
 +        ended: "ended"
 +        revoked_html: "revoked by %{name}"
 +        active: "active"
 +        active_unread: "active unread"
 +        expired_unread: "expired unread"
 +        read_html: "read at %{time}"
 +        time_in_future_title: "%{time_absolute}; in %{time_relative}"
 +        time_in_past_title: "%{time_absolute}; %{time_relative}"
      blocks_on:
        title: "Blocks on %{name}"
        heading_html: "List of Blocks on %{name}"
        reason: "Reason for block:"
        revoker: "Revoker:"
      block:
 -      not_revoked: "(not revoked)"
        show: "Show"
        edit: "Edit"
      page:
        display_name: "Blocked User"
        creator_name: "Creator"
        reason: "Reason for block"
 +      start: "Start"
 +      end: "End"
        status: "Status"
 -      revoker_name: "Revoked by"
      navigation:
        all_blocks: "All Blocks"
        blocks_on_me: "Blocks on Me"
 -      blocks_on_user: "Blocks on %{user}"
 +      blocks_on_user_html: "Blocks on %{user}"
        blocks_by_me: "Blocks by Me"
 -      blocks_by_user: "Blocks by %{user}"
 +      blocks_by_user_html: "Blocks by %{user}"
        block: "Block #%{id}"
        new_block: "New Block"
    user_mutes: