OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Extract `AddButtonComponent`s into base `ViewComponent`
Aaron Contrerasc953d76f5d43
diff --git a/modules/meeting/app/components/meetings/add_button_component.html.erb b/app/components/add_button_component.html.erbsimilarity index 100%rename from modules/meeting/app/components/meetings/add_button_component.html.erbrename to app/components/add_button_component.html.erbdiff --git a/app/components/add_button_component.rb b/app/components/add_button_component.rbnew file mode 100644index 00000000000..5f267b1ad66--- /dev/null+++ b/app/components/add_button_component.rb@@ -0,0 +1,80 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2023 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+# +++#++class AddButtonComponent < ApplicationComponent+ options :current_project++ def render?+ raise 'Implement the conditions for which the component should render or not'+ end++ def dynamic_path+ raise "Implement the path for this component's href"+ end++ def id+ raise "Implement the id for this component"+ end++ def li_css_class+ 'toolbar-item'+ end++ def title+ accessibility_label_text+ end++ def label+ content_tag(:span,+ label_text,+ class: 'button--text')+ end++ def aria_label+ accessibility_label_text+ end++ def accessibility_label_text+ raise "Specify the aria label and title text to be used for this component"+ end++ def label_text+ raise "Specify the label text to be used for this component"+ end++ def link_css_class+ 'button -alt-highlight'+ end++ def icon+ helpers.op_icon('button--icon icon-add')+ end+enddiff --git a/modules/calendar/app/components/calendar/add_button_component.rb b/modules/calendar/app/components/calendar/add_button_component.rbindex c005925d4c9..cfcd5587e0e 100644--- a/modules/calendar/app/components/calendar/add_button_component.rb+++ b/modules/calendar/app/components/calendar/add_button_component.rb@@ -30,9 +30,7 @@#module Calendar- class AddButtonComponent < ::ApplicationComponent- options :current_project-+ class AddButtonComponent < ::AddButtonComponentdef render?if current_projectUser.current.allowed_to?(:manage_calendars, current_project)@@ -41,10 +39,6 @@ module Calendarendend- def li_css_class- 'toolbar-item'- end-def dynamic_pathif current_projectnew_project_calendars_path(current_project)@@ -57,26 +51,12 @@ module Calendar'add-calendar-button'end- def title+ def accessibility_label_textI18n.t('js.calendar.create_new')end- def aria_label+ def label_textI18n.t(:label_calendar)end-- def link_css_class- 'button -alt-highlight'- end-- def label- content_tag(:span,- I18n.t(:label_calendar),- class: 'button--text')- end-- def icon- helpers.op_icon('button--icon icon-add')- endendenddiff --git a/modules/meeting/app/components/meetings/add_button_component.rb b/modules/meeting/app/components/meetings/add_button_component.rbindex 5b635f3bd57..ec1855ccdfa 100644--- a/modules/meeting/app/components/meetings/add_button_component.rb+++ b/modules/meeting/app/components/meetings/add_button_component.rb@@ -30,9 +30,7 @@#module Meetings- class AddButtonComponent < ::ApplicationComponent- options :current_project-+ class AddButtonComponent < ::AddButtonComponentdef render?if current_projectUser.current.allowed_to?(:create_meetings, current_project)@@ -41,10 +39,6 @@ module Meetingsendend- def li_css_class- 'toolbar-item'- end-def dynamic_pathpolymorphic_path([:new, current_project, :meeting])end@@ -53,26 +47,12 @@ module Meetings'add-meeting-button'end- def title- I18n.t(:label_meeting_new)- end-- def aria_label+ def accessibility_label_textI18n.t(:label_meeting_new)end- def link_css_class- 'button -alt-highlight'- end-- def label- content_tag(:span,- I18n.t(:label_meeting),- class: 'button--text')- end-- def icon- helpers.op_icon('button--icon icon-add')+ def label_text+ I18n.t(:label_meeting)endendenddiff --git a/modules/team_planner/app/components/team_planner/add_button_component.html.erb b/modules/team_planner/app/components/team_planner/add_button_component.html.erbdeleted file mode 100644index 662ee1417f2..00000000000--- a/modules/team_planner/app/components/team_planner/add_button_component.html.erb+++ /dev/null@@ -1,9 +0,0 @@-<li class="<%= li_css_class %>">- <%= link_to dynamic_path,- class: link_css_class,- title: title,- aria_label: aria_label do %>- <%= icon %>- <%= label %>- <% end %>-</li>diff --git a/modules/team_planner/app/components/team_planner/add_button_component.rb b/modules/team_planner/app/components/team_planner/add_button_component.rbindex 13a982ed0d9..632e9707db4 100644--- a/modules/team_planner/app/components/team_planner/add_button_component.rb+++ b/modules/team_planner/app/components/team_planner/add_button_component.rb@@ -30,9 +30,7 @@#module TeamPlanner- class AddButtonComponent < ::ApplicationComponent- options :current_project-+ class AddButtonComponent < ::AddButtonComponentdef render?if current_projectUser.current.allowed_to?(:manage_team_planner, current_project)@@ -45,30 +43,16 @@ module TeamPlannerpolymorphic_path([:new, current_project, :team_planners])end- def title- I18n.t('team_planner.label_create_new_team_planner')+ def id+ 'add-team-planner-button'end- def aria_label+ def accessibility_label_textI18n.t('team_planner.label_create_new_team_planner')end- def li_css_class- 'toolbar-item'- end-- def link_css_class- 'button -alt-highlight'- end-- def label- content_tag(:span,- t(:'team_planner.label_team_planner'),- class: 'button--text')- end-- def icon- helpers.op_icon('button--icon icon-add')+ def label_text+ t(:'team_planner.label_team_planner')endendend