diff --git a/app/components/groups/edit_page_header_component.html.erb b/app/components/groups/edit_page_header_component.html.erb new file mode 100644 index 00000000000..561131a2cde --- /dev/null +++ b/app/components/groups/edit_page_header_component.html.erb @@ -0,0 +1,71 @@ +<%#-- copyright +OpenProject is an open source project management software. +Copyright (C) 2012-2024 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. + +++#%> +<%= + render(Primer::OpenProject::PageHeader.new) do |header| + header.with_title { @group.name } + header.with_breadcrumbs(breadcrumb_items) + + header.with_action_button(tag: :a, + mobile_icon: :person, + mobile_label: t(:label_profile), + size: :medium, + href: show_group_path(@group), + aria: { label: I18n.t(:label_profile) }, + title: I18n.t(:label_profile)) do |button| + button.with_leading_visual_icon(icon: :person) + t(:label_profile) + end + + if @current_user.admin? + header.with_action_button(tag: :a, + scheme: :danger, + mobile_icon: :trash, + mobile_label: t(:button_delete), + size: :medium, + href: group_path(@group), + aria: { label: I18n.t(:button_delete) }, + data: { + confirm: t(:text_are_you_sure), + method: :delete, + }, + title: I18n.t(:button_delete)) do |button| + button.with_leading_visual_icon(icon: :trash) + t(:button_delete) + end + end + + header.with_tab_nav(label: nil) do |tab_nav| + @tabs.each do |tab| + tab_nav.with_tab(selected: selected_tab(@tabs) == tab, href: tab[:path]) do |t| + t.with_text { I18n.t("js.#{tab[:label]}") } + end + end + end if @tabs.present? + end +%> diff --git a/app/components/groups/edit_page_header_component.rb b/app/components/groups/edit_page_header_component.rb new file mode 100644 index 00000000000..eec2c78caa8 --- /dev/null +++ b/app/components/groups/edit_page_header_component.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +# -- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2010-2024 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. +# ++ + +module Groups + class EditPageHeaderComponent < ApplicationComponent + include OpPrimer::ComponentHelpers + include ApplicationHelper + include TabsHelper + + def initialize(group:, current_user:, tabs: nil) + super + @group = group + @tabs = tabs + @current_user = current_user + end + + def breadcrumb_items + [{ href: admin_index_path, text: t("label_administration") }, + { href: admin_settings_users_path, text: t(:label_user_and_permission) }, + { href: groups_path, text: t(:label_group_plural) }, + @group.name] + end + end +end diff --git a/app/components/groups/show_page_header_component.html.erb b/app/components/groups/show_page_header_component.html.erb new file mode 100644 index 00000000000..c1e4715af58 --- /dev/null +++ b/app/components/groups/show_page_header_component.html.erb @@ -0,0 +1,64 @@ +<%#-- copyright +OpenProject is an open source project management software. +Copyright (C) 2012-2024 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. + +++#%> +<%= + render(Primer::OpenProject::PageHeader.new) do |header| + header.with_title(test_selector: "groups--title") { @group.name } + header.with_breadcrumbs(breadcrumb_items) + + if @current_user.admin? + header.with_action_button(tag: :a, + mobile_icon: :pencil, + mobile_label: t(:button_edit), + size: :medium, + href: edit_group_path(@group), + aria: { label: I18n.t(:button_edit) }, + data: { "test-selector": "groups--edit-group-button" }, + title: I18n.t(:button_edit)) do |button| + button.with_leading_visual_icon(icon: :pencil) + t(:button_edit) + end + + header.with_action_button(tag: :a, + scheme: :danger, + mobile_icon: :trash, + mobile_label: t(:button_delete), + size: :medium, + href: group_path(@group), + aria: { label: I18n.t(:button_delete) }, + data: { + confirm: t(:text_are_you_sure), + method: :delete, + }, + title: I18n.t(:button_delete)) do |button| + button.with_leading_visual_icon(icon: :trash) + t(:button_delete) + end + end + end +%> diff --git a/app/components/groups/show_page_header_component.rb b/app/components/groups/show_page_header_component.rb new file mode 100644 index 00000000000..fd22e6c4347 --- /dev/null +++ b/app/components/groups/show_page_header_component.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +# -- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2010-2024 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. +# ++ + +module Groups + class ShowPageHeaderComponent < ApplicationComponent + include OpPrimer::ComponentHelpers + include ApplicationHelper + + def initialize(group:, current_user:) + super + @group = group + @current_user = current_user + end + + def breadcrumb_items + [{ href: groups_path, text: t(:label_group_plural) }, + @group.name] + end + end +end diff --git a/app/views/placeholder_users/_toolbar.html.erb b/app/components/placeholder_users/edit_page_header_component.html.erb similarity index 69% rename from app/views/placeholder_users/_toolbar.html.erb rename to app/components/placeholder_users/edit_page_header_component.html.erb index 2d5f18d9153..16a2da60815 100644 --- a/app/views/placeholder_users/_toolbar.html.erb +++ b/app/components/placeholder_users/edit_page_header_component.html.erb @@ -26,18 +26,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. See COPYRIGHT and LICENSE files for more details. ++#%> -<% title = @placeholder_user.new_record? ? t(:label_placeholder_user_new) : @placeholder_user.name %> -<% deletable = can_delete_placeholder_user?(@placeholder_user) %> <%= render(Primer::OpenProject::PageHeader.new) do |header| header.with_title { title } - header.with_breadcrumbs([{ href: admin_index_path, text: t("label_administration") }, - { href: admin_settings_users_path, text: t(:label_user_and_permission) }, - { href: placeholder_users_path, text: t(:label_placeholder_user_plural) }, - title]) + header.with_breadcrumbs(breadcrumb_items) - unless @placeholder_user.new_record? + unless new_record? header.with_action_button(tag: :a, mobile_icon: :person, mobile_label: t(:label_profile), @@ -54,24 +49,22 @@ See COPYRIGHT and LICENSE files for more details. mobile_icon: :trash, mobile_label: t(:button_delete), size: :medium, - disabled: !deletable, - href: deletable ? deletion_info_placeholder_user_path(@placeholder_user) : "#", + disabled: !deletable?, + href: delete_button_href, aria: { label: I18n.t(:button_delete) }, data: { "test-selector": "placeholder-user--delete-button" }, - title: deletable ? - I18n.t(:button_delete) : - I18n.t("placeholder_users.right_to_manage_members_missing")) do |button| + title: delete_button_title) do |button| button.with_leading_visual_icon(icon: :trash) t(:button_delete) end end header.with_tab_nav(label: nil) do |tab_nav| - tabs.each do |tab| - tab_nav.with_tab(selected: selected_tab(tabs) == tab, href: tab[:path]) do |t| + @tabs.each do |tab| + tab_nav.with_tab(selected: selected_tab(@tabs) == tab, href: tab[:path]) do |t| t.with_text { I18n.t("js.#{tab[:label]}") } end end - end if tabs.present? + end if @tabs.present? end %> diff --git a/app/components/placeholder_users/edit_page_header_component.rb b/app/components/placeholder_users/edit_page_header_component.rb new file mode 100644 index 00000000000..5033a47a678 --- /dev/null +++ b/app/components/placeholder_users/edit_page_header_component.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +# -- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2010-2024 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. +# ++ + +module PlaceholderUsers + class EditPageHeaderComponent < ApplicationComponent + include OpPrimer::ComponentHelpers + include ApplicationHelper + include TabsHelper + include PlaceholderUsersHelper + + def initialize(placeholder_user:, tabs: nil) + super + @placeholder_user = placeholder_user + @tabs = tabs + end + + def breadcrumb_items + [{ href: admin_index_path, text: t("label_administration") }, + { href: admin_settings_users_path, text: t(:label_user_and_permission) }, + { href: placeholder_users_path, text: t(:label_placeholder_user_plural) }, + title] + end + + def new_record? + @placeholder_user.new_record? + end + + def title + new_record? ? t(:label_placeholder_user_new) : @placeholder_user.name + end + + def deletable? + can_delete_placeholder_user?(@placeholder_user) + end + + def delete_button_href + if deletable? + deletion_info_placeholder_user_path(@placeholder_user) + else + "#" + end + end + + def delete_button_title + if deletable? + I18n.t(:button_delete) + else + I18n.t("placeholder_users.right_to_manage_members_missing") + end + end + end +end diff --git a/app/components/placeholder_users/show_page_header_component.html.erb b/app/components/placeholder_users/show_page_header_component.html.erb new file mode 100644 index 00000000000..da9b1bf4fe8 --- /dev/null +++ b/app/components/placeholder_users/show_page_header_component.html.erb @@ -0,0 +1,62 @@ +<%#-- copyright +OpenProject is an open source project management software. +Copyright (C) 2012-2024 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. + +++#%> +<%= + render(Primer::OpenProject::PageHeader.new) do |header| + header.with_title { "#{avatar @placeholder_user} #{h(@placeholder_user.name)}".html_safe } + header.with_breadcrumbs(breadcrumb_items) + + if @current_user.allowed_globally?(:manage_placeholder_user) + header.with_action_button(tag: :a, + mobile_icon: :pencil, + mobile_label: t(:button_edit), + size: :medium, + accesskey: accesskey(:edit), + href: edit_placeholder_user_path(@placeholder_user), + aria: { label: I18n.t(:button_edit) }, + title: I18n.t(:button_edit)) do |button| + button.with_leading_visual_icon(icon: :pencil) + t(:button_edit) + end + end + + header.with_action_button(tag: :a, + scheme: :danger, + mobile_icon: :trash, + mobile_label: t(:button_delete), + size: :medium, + disabled: !deletable?, + href: delete_button_href, + aria: { label: I18n.t(:button_delete) }, + data: { "test-selector": "placeholder-user--delete-button" }, + title: delete_button_title) do |button| + button.with_leading_visual_icon(icon: :trash) + t(:button_delete) + end + end +%> diff --git a/app/components/placeholder_users/show_page_header_component.rb b/app/components/placeholder_users/show_page_header_component.rb new file mode 100644 index 00000000000..b9847feb696 --- /dev/null +++ b/app/components/placeholder_users/show_page_header_component.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +# -- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2010-2024 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. +# ++ + +module PlaceholderUsers + class ShowPageHeaderComponent < ApplicationComponent + include OpPrimer::ComponentHelpers + include ApplicationHelper + include PlaceholderUsersHelper + include AvatarHelper + + def initialize(placeholder_user:, current_user:) + super + @placeholder_user = placeholder_user + @current_user = current_user + end + + def breadcrumb_items + [ + { href: placeholder_user_path, text: t(:label_placeholder_user_plural) }, + @placeholder_user.name + ] + end + + def deletable? + can_delete_placeholder_user?(@placeholder_user) + end + + def delete_button_href + if deletable? + deletion_info_placeholder_user_path(@placeholder_user) + else + "#" + end + end + + def delete_button_title + if deletable? + I18n.t(:button_delete) + else + I18n.t("placeholder_users.right_to_manage_members_missing") + end + end + end +end diff --git a/app/views/users/_toolbar.html.erb b/app/components/users/edit_page_header_component.html.erb similarity index 87% rename from app/views/users/_toolbar.html.erb rename to app/components/users/edit_page_header_component.html.erb index 73f462eaad5..0a364fc2d94 100644 --- a/app/views/users/_toolbar.html.erb +++ b/app/components/users/edit_page_header_component.html.erb @@ -29,10 +29,7 @@ See COPYRIGHT and LICENSE files for more details. <%= render(Primer::OpenProject::PageHeader.new) do |header| header.with_title { @user.name } - header.with_breadcrumbs([{ href: admin_index_path, text: t("label_administration") }, - { href: admin_settings_users_path, text: t(:label_user_and_permission) }, - { href: users_path, text: t(:label_user_plural) }, - @user.name]) + header.with_breadcrumbs(breadcrumb_items) header.with_action_button(tag: :a, mobile_icon: :person, @@ -45,7 +42,7 @@ See COPYRIGHT and LICENSE files for more details. t(:label_profile) end - if current_user.allowed_globally?(:create_user) + if @current_user.allowed_globally?(:create_user) header.with_action_button(tag: :a, mobile_icon: :mail, mobile_label: t(:label_send_invitation), @@ -59,8 +56,8 @@ See COPYRIGHT and LICENSE files for more details. end end - if current_user.admin? - unless current_user.id == @user.id + if @current_user.admin? + unless @current_user.id == @user.id iterate_user_statusses(@user) do |title, name| header.with_action_button(tag: :a, mobile_icon: change_user_status_icons[name], @@ -93,11 +90,11 @@ See COPYRIGHT and LICENSE files for more details. end header.with_tab_nav(label: nil) do |tab_nav| - tabs.each do |tab| - tab_nav.with_tab(selected: selected_tab(tabs) == tab, href: tab[:path]) do |t| + @tabs.each do |tab| + tab_nav.with_tab(selected: selected_tab(@tabs) == tab, href: tab[:path]) do |t| t.with_text { I18n.t("js.#{tab[:label]}") } end end - end if tabs.present? + end if @tabs.present? end %> diff --git a/app/components/users/edit_page_header_component.rb b/app/components/users/edit_page_header_component.rb new file mode 100644 index 00000000000..d8d219a6135 --- /dev/null +++ b/app/components/users/edit_page_header_component.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +# -- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2010-2024 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 Users::EditPageHeaderComponent < ApplicationComponent + include OpPrimer::ComponentHelpers + include ApplicationHelper + include TabsHelper + include UsersHelper + + def initialize(user:, current_user:, tabs: nil) + super + @user = user + @tabs = tabs + @current_user = current_user + end + + def breadcrumb_items + [{ href: admin_index_path, text: t("label_administration") }, + { href: admin_settings_users_path, text: t(:label_user_and_permission) }, + { href: users_path, text: t(:label_user_plural) }, + @user.name] + end +end diff --git a/app/components/users/index_page_header_component.html.erb b/app/components/users/index_page_header_component.html.erb new file mode 100644 index 00000000000..73f5aaf4244 --- /dev/null +++ b/app/components/users/index_page_header_component.html.erb @@ -0,0 +1,14 @@ +<%= + render(Primer::OpenProject::PageHeader.new) do |header| + header.with_title { t(:label_user_plural) } + header.with_breadcrumbs(breadcrumb_items) + header.with_description do %> + <%= t(:label_enterprise_active_users, current: OpenProject::Enterprise.active_user_count, limit: user_limit) %> + + <%= render(Primer::Beta::Button.new(scheme: :primary, + size: :small, + tag: :a, + href: OpenProject::Enterprise.upgrade_path, + title: t(:title_enterprise_upgrade))) { t(:button_upgrade) } %> + <% end if user_limit %> +<% end %> diff --git a/app/components/users/index_page_header_component.rb b/app/components/users/index_page_header_component.rb new file mode 100644 index 00000000000..0a9c7c0b8e7 --- /dev/null +++ b/app/components/users/index_page_header_component.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +# -- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2010-2024 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 Users::IndexPageHeaderComponent < ApplicationComponent + include OpPrimer::ComponentHelpers + include ApplicationHelper + + def breadcrumb_items + [{ href: admin_index_path, text: t("label_administration") }, + { href: admin_settings_users_path, text: t(:label_user_and_permission) }, + t(:label_user_plural)] + end + + def user_limit + token = OpenProject::Enterprise.token + limit = token && Hash(token.restrictions)[:active_user_count] + + limit if limit && limit > 0 + end +end diff --git a/app/components/users/index_sub_header_component.html.erb b/app/components/users/index_sub_header_component.html.erb new file mode 100644 index 00000000000..017de6e8cbb --- /dev/null +++ b/app/components/users/index_sub_header_component.html.erb @@ -0,0 +1,16 @@ +<%= + render(Primer::OpenProject::SubHeader.new) do |subheader| + subheader.with_action_button(scheme: :primary, + aria: { label: I18n.t(:label_user_new) }, + title: I18n.t(:label_user_new), + tag: :a, + href: new_user_path) do |button| + button.with_leading_visual_icon(icon: :plus) + t('activerecord.models.user') + end + + subheader.with_bottom_pane_component do + render Users::UserFilterComponent.new(@params, groups: @groups, status: @status) + end + end +%> diff --git a/app/components/users/index_sub_header_component.rb b/app/components/users/index_sub_header_component.rb new file mode 100644 index 00000000000..c43a86d2633 --- /dev/null +++ b/app/components/users/index_sub_header_component.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +# -- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2010-2024 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. +# ++ + +module Users + class IndexSubHeaderComponent < ApplicationComponent + include ApplicationHelper + + def initialize(groups:, status:, params:) + super + @groups = groups + @status = status + @params = params + end + end +end diff --git a/app/components/users/show_page_header_component.html.erb b/app/components/users/show_page_header_component.html.erb new file mode 100644 index 00000000000..fd70888b919 --- /dev/null +++ b/app/components/users/show_page_header_component.html.erb @@ -0,0 +1,61 @@ +<%#-- copyright +OpenProject is an open source project management software. +Copyright (C) 2012-2024 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. + +++#%> +<%= + render(Primer::OpenProject::PageHeader.new) do |header| + header.with_title { "#{avatar @user} #{h(@user.name)}".html_safe } + header.with_breadcrumbs(breadcrumb_items) + + if @current_user.allowed_globally?(:manage_user) + header.with_action_button(tag: :a, + mobile_icon: :pencil, + mobile_label: t(:button_edit), + size: :medium, + href: edit_user_path(@user), + aria: { label: I18n.t(:button_edit) }, + title: I18n.t(:button_edit)) do |button| + button.with_leading_visual_icon(icon: :pencil) + t(:button_edit) + end + end + + if @current_user.allowed_globally?(:create_user) && @current_user != @user + header.with_action_button(tag: :a, + mobile_icon: :mail, + mobile_label: t(:label_send_invitation), + size: :medium, + href: resend_invitation_user_path(@user), + data: { method: :post }, + aria: { label: I18n.t(:label_send_invitation) }, + title: I18n.t(:tooltip_resend_invitation)) do |button| + button.with_leading_visual_icon(icon: :mail) + t(:label_send_invitation) + end + end + end +%> diff --git a/app/components/users/show_page_header_component.rb b/app/components/users/show_page_header_component.rb new file mode 100644 index 00000000000..e2e732805d1 --- /dev/null +++ b/app/components/users/show_page_header_component.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +# -- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2010-2024 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 Users::ShowPageHeaderComponent < ApplicationComponent + include OpPrimer::ComponentHelpers + include ApplicationHelper + include AvatarHelper + + def initialize(user:, current_user:) + super + @user = user + @current_user = current_user + end + + def breadcrumb_items + [{ href: users_path, text: t(:label_user_plural) }, + @user.name] + end +end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index efe0e2795a4..e833fbea77e 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -89,7 +89,7 @@ module UsersHelper def build_change_user_status_action(user) result = "".html_safe iterate_user_statusses(user) do |title, name| - result << ((yield title, name) + " ".html_safe) + result << ((yield title, name) + " ") # rubocop:disable Style/StringConcatenation end result end diff --git a/app/views/groups/edit.html.erb b/app/views/groups/edit.html.erb index 6277a00b3e4..b6aa743cfaf 100644 --- a/app/views/groups/edit.html.erb +++ b/app/views/groups/edit.html.erb @@ -31,51 +31,6 @@ See COPYRIGHT and LICENSE files for more details. <% tabs = group_settings_tabs(@group) %> -<%= - render(Primer::OpenProject::PageHeader.new) do |header| - header.with_title { @group.name } - header.with_breadcrumbs([{ href: admin_index_path, text: t("label_administration") }, - { href: admin_settings_users_path, text: t(:label_user_and_permission) }, - { href: groups_path, text: t(:label_group_plural) }, - @group.name]) - - header.with_action_button(tag: :a, - mobile_icon: :person, - mobile_label: t(:label_profile), - size: :medium, - href: show_group_path(@group), - aria: { label: I18n.t(:label_profile) }, - title: I18n.t(:label_profile)) do |button| - button.with_leading_visual_icon(icon: :person) - t(:label_profile) - end - - if current_user.admin? - header.with_action_button(tag: :a, - scheme: :danger, - mobile_icon: :trash, - mobile_label: t(:button_delete), - size: :medium, - href: group_path(@group), - aria: { label: I18n.t(:button_delete) }, - data: { - confirm: t(:text_are_you_sure), - method: :delete, - }, - title: I18n.t(:button_delete)) do |button| - button.with_leading_visual_icon(icon: :trash) - t(:button_delete) - end - end - - header.with_tab_nav(label: nil) do |tab_nav| - tabs.each do |tab| - tab_nav.with_tab(selected: selected_tab(tabs) == tab, href: tab[:path]) do |t| - t.with_text { I18n.t("js.#{tab[:label]}") } - end - end - end if tabs.present? - end -%> +<%= render Groups::EditPageHeaderComponent.new(group: @group, current_user:, tabs: tabs) %> <%= render_tabs tabs, with_tab_nav: false %> diff --git a/app/views/groups/show.html.erb b/app/views/groups/show.html.erb index 2891a345637..7a90aafb08a 100644 --- a/app/views/groups/show.html.erb +++ b/app/views/groups/show.html.erb @@ -28,46 +28,7 @@ See COPYRIGHT and LICENSE files for more details. ++#%> <% html_title h(@group.name), t(:label_group_plural) -%> -<%= - render(Primer::OpenProject::PageHeader.new) do |header| - header.with_title(test_selector: "groups--title") { @group.name } - header.with_breadcrumbs( - [ - { href: groups_path, text: t(:label_group_plural) }, - @group.name - ]) - - if current_user.admin? - header.with_action_button(tag: :a, - mobile_icon: :pencil, - mobile_label: t(:button_edit), - size: :medium, - href: edit_group_path(@group), - aria: { label: I18n.t(:button_edit) }, - data: { "test-selector": "groups--edit-group-button" }, - title: I18n.t(:button_edit)) do |button| - button.with_leading_visual_icon(icon: :pencil) - t(:button_edit) - end - - header.with_action_button(tag: :a, - scheme: :danger, - mobile_icon: :trash, - mobile_label: t(:button_delete), - size: :medium, - href: group_path(@group), - aria: { label: I18n.t(:button_delete) }, - data: { - confirm: t(:text_are_you_sure), - method: :delete, - }, - title: I18n.t(:button_delete)) do |button| - button.with_leading_visual_icon(icon: :trash) - t(:button_delete) - end - end - end -%> +<%= render Groups::ShowPageHeaderComponent.new(group: @group, current_user:) %> <% if @group_users.any? %>