Skip to content

Commit

Permalink
Create the IconRegistry (decidim#11982)
Browse files Browse the repository at this point in the history
* Create the IconRegistry

* Running linters

* Adding few test icons

* Apply review recommendation

* Register more assets

* Add more icons

* Swap to ActiveSupport::HashWithIndifferentAccess

* Add admin icons

* Add exception restriction

* Add more icons

* Add more icons

* Add more icons

* Add engine parameter to Icon registry

* Add more icons

* Move comment related assets to assets.rb

* Add missing icon in elections

* revert comment

* Remove unused icons

* Run linters

* Replace icons

* Fix some missing icons

* Icon fixes

* Add specs for icon registry

* Add election icons

* Fix more icons

* Refactor IconHelper

* Revert some icons

* Replace icon call

* patch resource_type_icon_key

* Refacotor method definition

* Apply suggestions from code review

Co-authored-by: Andrés Pereira de Lucena <[email protected]>

* Change the method description

* Fix the specs

* FIx social share icons

* Apply suggestions from code review

Co-authored-by: Andrés Pereira de Lucena <[email protected]>

* Fix social share icons

* Remove double declaration of asset

* Fix missing icon

---------

Co-authored-by: Andrés Pereira de Lucena <[email protected]>
  • Loading branch information
alecslupu and andreslucena authored Nov 21, 2023
1 parent 4ac2f4f commit 354f9bc
Show file tree
Hide file tree
Showing 54 changed files with 574 additions and 119 deletions.
8 changes: 8 additions & 0 deletions decidim-accountability/lib/decidim/accountability/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ class Engine < ::Rails::Engine
root to: "results#home"
end

initializer "decidim_accountability.register_icons" do
Decidim.icons.register(name: "Decidim::Accountability::Result", icon: "briefcase-2-line", description: "Result / project (Accountability)", category: "activity",
engine: :accountability)

Decidim.icons.register(name: "focus-2-line", icon: "focus-2-line", category: "system", description: "", engine: :accountability)
Decidim.icons.register(name: "briefcase-2-line", icon: "briefcase-2-line", category: "system", description: "", engine: :accountability)
end

initializer "decidim_accountability.view_hooks" do
Decidim.view_hooks.register(:participatory_space_highlighted_elements, priority: Decidim::ViewHooks::LOW_PRIORITY) do |view_context|
view_context.cell("decidim/accountability/highlighted_results", view_context.current_participatory_space)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<%= icon "delete-bin-line", role: "img", "aria-hidden": true %>
<% end %>
<% end %>
<%= icon "menu", role: "img", "aria-hidden": true %>
<%= icon "menu-line", role: "img", "aria-hidden": true %>
</div>
</div>
</li>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def reportable_author_name(reportable)
when User
content_tag :li do
link_to current_or_new_conversation_path_with(author), target: "_blank", rel: "noopener" do
"#{author.name} #{icon "envelope-closed"}".html_safe
"#{author.name} #{icon "mail-send-line"}".html_safe
end
end
when Decidim::Meetings::Meeting
Expand Down
27 changes: 27 additions & 0 deletions decidim-admin/lib/decidim/admin/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ class Engine < ::Rails::Engine
end
end

initializer "decidim_admin.register_icons" do |_app|
Decidim.icons.register(name: "layout-masonry-line", icon: "layout-masonry-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "service-line", icon: "service-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "fullscreen-line", icon: "fullscreen-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "lock-line", icon: "lock-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "download-line", icon: "download-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "mail-open-line", icon: "mail-open-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "forbid-2-line", icon: "forbid-2-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "key-2-line", icon: "key-2-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "arrow-go-back-line", icon: "arrow-go-back-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "computer-line", icon: "computer-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "arrow-right-s-line", icon: "arrow-right-s-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "arrow-up-line", icon: "arrow-up-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "arrow-down-line", icon: "arrow-down-line", category: "system", description: "", engine: :admin)

Decidim.icons.register(name: "attachment-2", icon: "attachment-2", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "spy-line", icon: "spy-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "refresh-line", icon: "refresh-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "zoom-in-line", icon: "zoom-in-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "add-line", icon: "add-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "upload-line", icon: "upload-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "settings-4-line", icon: "settings-4-line", category: "system", description: "", engine: :admin)

Decidim.icons.register(name: "folder-line", icon: "folder-line", category: "system", description: "", engine: :admin)
Decidim.icons.register(name: "attachment-line", icon: "attachment-line", category: "system", description: "", engine: :admin)
end

initializer "decidim_admin.mime_types" do |_app|
# Required for importer example downloads
Mime::Type.register Decidim::Admin::Import::Readers::XLSX::MIME_TYPE, :xlsx
Expand Down
7 changes: 7 additions & 0 deletions decidim-assemblies/lib/decidim/assemblies/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class Engine < ::Rails::Engine
end
end

initializer "decidim_assemblies.register_icons" do
Decidim.icons.register(name: "Decidim::Assembly", icon: "government-line", description: "Assembly", category: "activity", engine: :assemblies)
Decidim.icons.register(name: "assembly_type", icon: "group-2-line", description: "Type", category: "assemblies", engine: :assemblies)

Decidim.icons.register(name: "group-2-line", icon: "group-2-line", category: "system", description: "", engine: :assemblies)
end

initializer "decidim_assemblies.add_cells_view_paths" do
Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Assemblies::Engine.root}/app/cells")
Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Assemblies::Engine.root}/app/views") # for partials
Expand Down
5 changes: 5 additions & 0 deletions decidim-blogs/lib/decidim/blogs/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class Engine < ::Rails::Engine
get "/", to: redirect("posts", status: 301)
end

initializer "decidim_blogs.register_icons" do
Decidim.icons.register(name: "Decidim::Blogs::Post", icon: "pen-nib-line", description: "Blogs post", category: "activity", engine: :core)
Decidim.icons.register(name: "list-check", icon: "list-check", category: "system", description: "", engine: :blogs)
end

initializer "decidim_blogs.add_cells_view_paths" do
Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Blogs::Engine.root}/app/cells")
Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Blogs::Engine.root}/app/views") # for partials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def show

def hint
contents = []
contents << icon("check", role: "img", "aria-hidden": true)
contents << icon("check-line", role: "img", "aria-hidden": true)
contents << " "
contents << t("decidim.budgets.projects.project.you_voted")
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<% if project.selected? %>
<%= content_tag :strong, t("projects.index.selected", scope: "decidim.budgets.admin"), class: "text-success" %>
<% else %>
<%= content_tag :span, "x", class: "text-muted" %>
<%= content_tag :span, "close-line", class: "text-muted" %>
<% end %>
</td>
<td class="table-list__actions">
Expand Down
9 changes: 9 additions & 0 deletions decidim-budgets/lib/decidim/budgets/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ class Engine < ::Rails::Engine
get "/", to: redirect("budgets", status: 301)
end

initializer "decidim_budgets.register_icons" do
Decidim.icons.register(name: "Decidim::Budgets::Budget", icon: "coin-line", description: "Budget", category: "activity", engine: :budgets)
Decidim.icons.register(name: "Decidim::Budgets::Project", icon: "coin-line", description: "Project (Budgets)", category: "activity", engine: :budgets)
Decidim.icons.register(name: "Decidim::Budgets::Order", icon: "check-double-fill", description: "Budget voting", category: "activity", engine: :budgets)

Decidim.icons.register(name: "git-pull-request-line", icon: "git-pull-request-line", category: "system", description: "", engine: :budgets)
Decidim.icons.register(name: "list-check", icon: "list-check", category: "system", description: "", engine: :budgets)
end

initializer "decidim_budgets.add_cells_view_paths" do
Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Budgets::Engine.root}/app/cells")
Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Budgets::Engine.root}/app/views") # for partials
Expand Down
13 changes: 13 additions & 0 deletions decidim-comments/lib/decidim/comments/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ class Engine < ::Rails::Engine
end
end

initializer "decidim_comments.register_icons" do
common_parameters = { category: "action", engine: :comments }

Decidim.icons.register(name: "Decidim::Comments::Comment", icon: "chat-1-line", description: "Comment", category: "activity", engine: :comments)
Decidim.icons.register(name: "comments_count", icon: "wechat-line", description: "Comments Count", category: "activity", engine: :comments)

Decidim.icons.register(name: "thumb-up-line", icon: "thumb-up-line", description: "Upvote comment button", **common_parameters)
Decidim.icons.register(name: "thumb-up-fill", icon: "thumb-up-fill", description: "User upvoted comment", **common_parameters)
Decidim.icons.register(name: "thumb-down-line", icon: "thumb-down-line", description: "Downvote comment button", **common_parameters)
Decidim.icons.register(name: "thumb-down-fill", icon: "thumb-down-fill", description: "User downvoted comment", **common_parameters)
Decidim.icons.register(name: "edit-line", icon: "edit-line", description: "Edit comment button", **common_parameters)
end

initializer "decidim_comments.register_metrics" do
Decidim.metrics_registry.register(:comments) do |metric_registry|
metric_registry.manager_class = "Decidim::Comments::Metrics::CommentsMetricManage"
Expand Down
10 changes: 10 additions & 0 deletions decidim-conferences/lib/decidim/conferences/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ class Engine < ::Rails::Engine
end
end

initializer "decidim_conferences.register_icons" do
Decidim.icons.register(name: "Decidim::Conference", icon: "mic-line", description: "Conference", category: "activity", engine: :conferences)
Decidim.icons.register(name: "conference_speaker", icon: "user-voice-line", description: "Speaker", category: "conferences", engine: :conferences)

Decidim.icons.register(name: "film-line", icon: "film-line", category: "system", description: "", engine: :conferences)
Decidim.icons.register(name: "ticket-line", icon: "ticket-line", category: "system", description: "", engine: :conferences)
Decidim.icons.register(name: "user-follow-line", icon: "user-follow-line", category: "system", description: "", engine: :conferences)
Decidim.icons.register(name: "link-m", icon: "link-m", category: "system", description: "", engine: :conferences)
end

initializer "decidim_conferences.add_cells_view_paths" do
Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Conferences::Engine.root}/app/cells")
Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Conferences::Engine.root}/app/views") # for partials
Expand Down
2 changes: 1 addition & 1 deletion decidim-core/app/cells/decidim/author/endorsements.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= link_to "#{resource_locator(from_context).path}#list-of-endorsements", title: t("decidim.author.endorsements", count: from_context.endorsements_count), class: "author__metadata" do %>
<%= icon "heart-add-line" if show_icons? %>
<%= icon "like" if show_icons? %>
<%= from_context.endorsements_count %> <%= t("decidim.author.endorsements", count: from_context.endorsements_count) %>
<% end %>
2 changes: 1 addition & 1 deletion decidim-core/app/cells/decidim/author/withdraw.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= action_authorized_link_to :withdraw, withdraw_path, method: :put, class: "title-action__action button small hollow", title: t("withdraw_btn_hint", scope: resource_i18n_scope ), data: { confirm: t("withdraw_confirmation_html", scope: resource_i18n_scope ) } do %>
<%= t("withdraw_#{resource_name}", scope: resource_i18n_scope) %>
<%= icon "x", role: "img", "aria-hidden": true %>
<%= icon "close-line", role: "img", "aria-hidden": true %>
<% end %>
2 changes: 1 addition & 1 deletion decidim-core/app/cells/decidim/date_range/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<%= l start_time, format: "%H:%M" %>
</div>
</div>
<%= icon "arrow-thin-right" %>
<%= icon "arrow-right-line" %>
<div>
<div class="extra__date">
<%= l end_time, format: "%d" %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<% if wizard_aside_back_url %>
<div class="m-bottom">
<%= link_to wizard_aside_back_url do %>
<%= icon "chevron-left", class: "icon--small", role: "img", "aria-hidden": true %>
<%= icon "arrow-left-s-line", class: "icon--small", role: "img", "aria-hidden": true %>
<%= i18n_wizard_aside_back %>
<% end %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def flash_icon(alert_class)
secondary: "information-line",
alert: "alert-line",
warning: "alert-line",
success: "checkbox-circle-line"
success: "checkbox-circle-line",
info: "information-line",
notice: "checkbox-circle-line",
primary: "checkbox-circle-line",
error: "alert-line"
}

content_tag(:div, class: "flash__icon") do
Expand Down
2 changes: 1 addition & 1 deletion decidim-core/app/helpers/decidim/decidim_form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def base_error_messages(record)
return unless record.respond_to?(:errors)
return unless record.errors[:base].any?

alert_box(record.errors.full_messages_for(:base).join(","), "alert", false)
alert_box(record.errors.full_messages_for(:base).join(","), :alert, false)
end

# Handle which collection to pass to Decidim::FilterFormBuilder.areas_select
Expand Down
72 changes: 6 additions & 66 deletions decidim-core/app/helpers/decidim/icon_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,6 @@ module Decidim
module IconHelper
include Decidim::LayoutHelper

DEFAULT_RESOURCE_TYPE_ICONS = {
"Decidim::Proposals::CollaborativeDraft" => { icon: "draft-line", description: "Collaborative draft", category: "activity" },
"Decidim::Proposals::Proposal" => { icon: "chat-new-line", description: "Proposal", category: "activity" },
"Decidim::Amendment" => { icon: "git-branch-line", description: "Amendment", category: "activity" },
"Decidim::ParticipatoryProcess" => { icon: "treasure-map-line", description: "Participatory Process", category: "activity" },
"Decidim::Budgets::Budget" => { icon: "coin-line", description: "Budget", category: "activity" },
"Decidim::Budgets::Project" => { icon: "coin-line", description: "Project (Budgets)", category: "activity" },
"Decidim::Accountability::Result" => { icon: "briefcase-2-line", description: "Result / project (Accountability)", category: "activity" },
"Decidim::Initiative" => { icon: "lightbulb-flash-line", description: "Initiative", category: "activity" },
"Decidim::Blogs::Post" => { icon: "pen-nib-line", description: "Blogs post", category: "activity" },
"Decidim::Assembly" => { icon: "government-line", description: "Assembly", category: "activity" },
"Decidim::Budgets::Order" => { icon: "check-double-fill", description: "Budget voting", category: "activity" },
"Decidim::Debates::Debate" => { icon: "discuss-line", description: "Debate", category: "activity" },
"Decidim::Meetings::Meeting" => { icon: "map-pin-line", description: "Meeting", category: "activity" },
"Decidim::Conference" => { icon: "mic-line", description: "Conference", category: "activity" },
"Decidim::Votings::Voting" => { icon: "check-double-fill", description: "Voting", category: "activity" },
"Decidim::Elections::Election" => { icon: "chat-poll-line", description: "Election", category: "activity" },
"Decidim::Comments::Comment" => { icon: "chat-1-line", description: "Comment", category: "activity" },
"Decidim::Category" => { icon: "price-tag-3-line", description: "Category", category: "activity" },
"Decidim::Scope" => { icon: "scan-line", description: "Scope", category: "activity" },
"Decidim::User" => { icon: "user-line", description: "User", category: "activity" },
"Decidim::UserGroup" => { icon: "group-line", description: "User Group", category: "activity" },
"comments_count" => { icon: "wechat-line", description: "Comments Count", category: "activity" },

"like" => { icon: "heart-add-line", description: "Like", category: "action" },
"dislike" => { icon: "dislike-line", description: "Dislike", category: "action" },
"follow" => { icon: "notification-3-line", description: "Follow", category: "action" },
"unfollow" => { icon: "notification-3-fill", description: "Unfollow", category: "action" },
"share" => { icon: "share-line", description: "Share", category: "action" },

"nickname" => { icon: "account-pin-circle-line", description: "Nickname", category: "profile" },
"badges" => { icon: "award-line", description: "Badges", category: "profile" },
"profile" => { icon: "team-line", description: "Groups", category: "profile" },
"user_group" => { icon: "team-line", description: "Groups", category: "profile" },
"link" => { icon: "link", description: "web / URL", category: "profile" },
"following" => { icon: "eye-2-line", description: "Following", category: "profile" },
"activity" => { icon: "bubble-chart-line", description: "Activity", category: "profile" },
"followers" => { icon: "group-line", description: "Followers", category: "profile" },

"documents" => { icon: "file-text-line", description: "Document", category: "documents" },
"folder_open" => { icon: "folder-open-line", description: "Folder open", category: "documents" },
"folder_close" => { icon: "folder-line", description: "Folder close", category: "documents" },
"document_weight" => { icon: "scales-2-line", description: "Doc. weight (kb/mb)", category: "documents" },
"document_download" => { icon: "download-line", description: "Download", category: "documents" },
"images" => { icon: "image-line", description: "Images", category: "documents" },

"all" => { icon: "apps-2-line", description: "All", category: "other" },
"other" => { icon: "question-line", description: "Other", category: "other" },

# Modules

"in_person" => { icon: "community-line", description: "In person", category: "meetings" },
"online" => { icon: "webcam-line", description: "Online", category: "meetings" },
"hybrid" => { icon: "home-wifi-line", description: "Hybrid", category: "meetings" },

"assembly_type" => { icon: "group-2-line", description: "Type", category: "assemblies" },

"conference_speaker" => { icon: "user-voice-line", description: "Speaker", category: "conferences" },

"participatory_texts_item" => { icon: "bookmark-line", description: "Index item", category: "participatory_texts" }
}.freeze

# Public: Returns an icon given an instance of a Component. It defaults to
# a question mark when no icon is found.
#
Expand Down Expand Up @@ -103,15 +41,15 @@ def manifest_icon(manifest, options = {})
# Returns an HTML tag with the icon.
def resource_icon(resource, options = {})
if resource.instance_of?(Decidim::Comments::Comment)
icon "comment-square", options
icon "chat-1-line", options
elsif resource.respond_to?(:component) && resource.component.present?
component_icon(resource.component, options)
elsif resource.respond_to?(:manifest) && resource.manifest.present?
manifest_icon(resource.manifest, options)
elsif resource.is_a?(Decidim::User)
icon "person", options
icon "user-line", options
else
icon "bell", options
icon "notification-3-line", options
end
end

Expand All @@ -120,7 +58,9 @@ def resource_type_icon(resource_type, options = {})
end

def resource_type_icon_key(resource_type)
DEFAULT_RESOURCE_TYPE_ICONS.dig(resource_type.to_s, :icon) || DEFAULT_RESOURCE_TYPE_ICONS["other"][:icon]
return resource_type.to_s if Decidim.icons.all[resource_type.to_s]

"other"
end

def text_with_resource_icon(resource_name, text)
Expand Down
2 changes: 2 additions & 0 deletions decidim-core/app/helpers/decidim/layout_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def legacy_favicon
#
# Returns a String.
def icon(name, options = {})
name = Decidim.icons.find(name)["icon"] unless options[:ignore_missing]

default_html_properties = {
"width" => "1em",
"height" => "1em",
Expand Down
Loading

0 comments on commit 354f9bc

Please sign in to comment.