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
Add userAutocompleter inside a Form which can be submitted and then refreshes the modal content
Henriette Darge249afabd32eb
diff --git a/app/components/work_packages/share/invite_user_form_component.html.erb b/app/components/work_packages/share/invite_user_form_component.html.erbnew file mode 100644index 00000000000..43ea976263b--- /dev/null+++ b/app/components/work_packages/share/invite_user_form_component.html.erb@@ -0,0 +1,25 @@+<%=+ if allowed_to_share?+ primer_form_with(+ model: @member,+ method: @method,+ url: @submit_path+ ) do |form|+ flex_layout do |new_user_row|+ new_user_row.with_column(flex: :auto, mr: 2) do+ render(WorkPackages::Share::Invitee.new(form))+ end++ new_user_row.with_column(mr: 2) do+ render(WorkPackages::Share::PermissionButtonComponent.new(shown_value: I18n.t('work_package.sharing.permissions.comment')))+ end++ new_user_row.with_column do+ render(Primer::Beta::Button.new(scheme: :primary, type: :submit)) { I18n.t('work_package.sharing.invite') }+ end+ end+ end+ else+ render(Primer::Beta::Flash.new(icon: :info)) { I18n.t('work_package.sharing.permissions.denied') }+ end+%>diff --git a/app/components/work_packages/share/invite_user_form_component.rb b/app/components/work_packages/share/invite_user_form_component.rbnew file mode 100644index 00000000000..69299497071--- /dev/null+++ b/app/components/work_packages/share/invite_user_form_component.rb@@ -0,0 +1,50 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-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.+#++++module WorkPackages+ module Share+ class InviteUserFormComponent < ApplicationComponent+ include ApplicationHelper+ include OpTurbo::Streamable+ include OpPrimer::ComponentHelpers++ def initialize(member:, work_package:, method:, submit_path:)+ super++ @member = member+ @work_package = work_package+ @method = method+ @submit_path = submit_path+ end++ def allowed_to_share?+ User.current.allowed_to?(:share_work_packages, @work_package.project)+ end+ end+ end+enddiff --git a/app/components/work_packages/share/modal_component.html.erb b/app/components/work_packages/share/modal_component.html.erbindex fd0e73bb6ef..303250b489e 100644--- a/app/components/work_packages/share/modal_component.html.erb+++ b/app/components/work_packages/share/modal_component.html.erb@@ -1,48 +1,42 @@<%=+ # Todo: doubled ID+ component_wrapper do# The identifier is a magic key also found in the wp-share modal template.- turbo_frame_tag "work_package_share_list" do- flex_layout(data: { turbo: true }) do |modal_content|- modal_content.with_row do- # Todo: Wrap in Form-- flex_layout do |new_user_row|- new_user_row.with_column(mr: 2) do- # Todo: Show user autocompleter- end-- new_user_row.with_column(mr: 2) do- render(WorkPackages::Share::PermissionButtonComponent.new(shown_value: I18n.t('work_package.sharing.permissions.comment')))- end-- new_user_row.with_column do- render(Primer::Beta::Button.new(scheme: :primary)) { I18n.t('work_package.sharing.invite') }- end+ turbo_frame_tag "work_package_share_list" do+ flex_layout(data: { turbo: true }) do |modal_content|+ modal_content.with_row do+ # Todo: Simplify attributes+ render(WorkPackages::Share::InviteUserFormComponent.new(+ member: Member.new(entity: @work_package),+ work_package: @work_package,+ method: :post,+ submit_path: shares_work_package_path(@work_package)))end- end- if @shared_users.empty?- # Todo: show empty state?- else- modal_content.with_row(mt: 3) do- render(Primer::Beta::BorderBox.new) do |invited_user_list|- invited_user_list.with_header(color: :subtle) do- I18n.t('work_package.sharing.count', count: @shared_users.count)- end+ if shared_users.empty?+ # Todo: show empty state?+ else+ modal_content.with_row(mt: 3) do+ render(Primer::Beta::BorderBox.new) do |invited_user_list|+ invited_user_list.with_header(color: :subtle) do+ I18n.t('work_package.sharing.count', count: shared_users.count)+ end- @shared_users.each do |user|- invited_user_list.with_row do- flex_layout(align_items: :center) do |user_row_container|- user_row_container.with_column(flex: :auto) do- render(Users::AvatarComponent.new(user: user, size: :medium))- end+ shared_users.each do |user|+ invited_user_list.with_row do+ flex_layout(align_items: :center) do |user_row_container|+ user_row_container.with_column(flex: :auto) do+ render(Users::AvatarComponent.new(user: user, size: :medium))+ end- user_row_container.with_column(color: :subtle, style: "width: 150px;") do- # ToDo: real permission- render(WorkPackages::Share::PermissionButtonComponent.new(shown_value: I18n.t('work_package.sharing.permissions.comment')))- end+ user_row_container.with_column(color: :subtle, style: "width: 150px;") do+ # ToDo: real permission+ render(WorkPackages::Share::PermissionButtonComponent.new(shown_value: I18n.t('work_package.sharing.permissions.comment')))+ end- user_row_container.with_column(text_align: :right, style: "width: 100px;") do- render(Primer::Beta::Button.new(scheme: :invisible)) { I18n.t('work_package.sharing.remove') }+ user_row_container.with_column(text_align: :right, style: "width: 100px;") do+ render(Primer::Beta::Button.new(scheme: :invisible)) { I18n.t('work_package.sharing.remove') }+ endendendenddiff --git a/app/components/work_packages/share/modal_component.rb b/app/components/work_packages/share/modal_component.rbindex 236bb759f30..6ed59683fcd 100644--- a/app/components/work_packages/share/modal_component.rb+++ b/app/components/work_packages/share/modal_component.rb@@ -31,13 +31,23 @@ module WorkPackagesclass ModalComponent < ApplicationComponentinclude ApplicationHelperinclude Turbo::FramesHelper+ include OpTurbo::Streamableinclude OpPrimer::ComponentHelpersdef initialize(work_package:)super@work_package = work_package- @shared_users = User.having_entity_membership(@work_package)+ end++ def self.wrapper_key+ "work_package_share_list"+ end++ private++ def shared_users+ @shared_users ||= User.having_entity_membership(@work_package)endendenddiff --git a/app/components/work_packages/share/permission_button_component.rb b/app/components/work_packages/share/permission_button_component.rbindex 053090f6be8..8d9e47d3663 100644--- a/app/components/work_packages/share/permission_button_component.rb+++ b/app/components/work_packages/share/permission_button_component.rb@@ -35,17 +35,18 @@ module WorkPackagesdef initialize(shown_value:)super+ # Todo: Connect value with options+@shown_value = shown_valueendprivatedef options- # Todo: Real values[- { label: I18n.t('work_package.sharing.permissions.comment'), value: '' },- { label: I18n.t('work_package.sharing.permissions.edit'), value: '' },- { label: I18n.t('work_package.sharing.permissions.view'), value: '' }+ { label: I18n.t('work_package.sharing.permissions.comment'), value: Role::BUILTIN_WORK_PACKAGE_COMMENTER },+ { label: I18n.t('work_package.sharing.permissions.edit'), value: Role::BUILTIN_WORK_PACKAGE_EDITOR },+ { label: I18n.t('work_package.sharing.permissions.view'), value: Role::BUILTIN_WORK_PACKAGE_VIEWER }]endenddiff --git a/app/controllers/work_packages/shares_controller.rb b/app/controllers/work_packages/shares_controller.rbindex cb8c79c7ba9..dad14ac2b65 100644--- a/app/controllers/work_packages/shares_controller.rb+++ b/app/controllers/work_packages/shares_controller.rb@@ -27,9 +27,29 @@# ++class WorkPackages::SharesController < ApplicationController+ include OpTurbo::ComponentStream++ # Todo: access control+def index@work_package = WorkPackage.find(params[:id])render WorkPackages::Share::ModalComponent.new(work_package: @work_package), layout: nilend++ def create+ @work_package = WorkPackage.find(params[:id])+ # Todo: Role selection, validation, error handling?+ Member.create(entity: @work_package,+ user_id: params[:member][:user_id],+ roles: Role.where(builtin: Role::BUILTIN_WORK_PACKAGE_VIEWER))++ replace_via_turbo_stream(+ component: WorkPackages::Share::ModalComponent.new(work_package: @work_package)+ )++ respond_with_turbo_streams+ end++ # Todo: Deleteenddiff --git a/app/forms/work_packages/share/invitee.rb b/app/forms/work_packages/share/invitee.rbnew file mode 100644index 00000000000..dfe805e9380--- /dev/null+++ b/app/forms/work_packages/share/invitee.rb@@ -0,0 +1,53 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-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.+#+++module WorkPackages::Share+ class Invitee < ApplicationForm+ form do |user_invite_form|+ user_invite_form.autocompleter(+ name: :user_id,+ label: 'Todo',+ visually_hide_label: true,+ autocomplete_options: {+ id: "op-share-wp-user-autocomplete",+ data: {+ 'test-selector': 'op-share-wp-user-autocomplete'+ },+ resource: 'principals',+ searchKey: 'any_name_attribute',+ focusDirectly: true,+ disabled: @disabled+ }+ )+ end++ def initialize(disabled: false)+ super()+ @disabled = disabled+ end+ end+enddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex f9ac7c9b06e..0356a018285 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -3156,6 +3156,7 @@ en:invite: "Invite"permissions:comment: "Comment"+ denied: "You don't have permissions to share work packages."edit: "Edit"view: "View"remove: "Remove"diff --git a/config/routes.rb b/config/routes.rbindex 04c6f62078b..7fb6bf27e03 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -458,7 +458,9 @@ OpenProject::Application.routes.draw doget 'details/*state' => 'work_packages#index', on: :collection, as: :details# Rails managed sharing route+ # Todo: Resource extractingget '/shares' => 'work_packages/shares#index', on: :member+ post '/shares' => 'work_packages/shares#create', on: :member# states managed by client-side (angular) routing on work_package#showget '/' => 'work_packages#index', on: :collection, as: 'index'diff --git a/frontend/src/app/features/work-packages/components/wp-buttons/wp-share-button/wp-share-button.html b/frontend/src/app/features/work-packages/components/wp-buttons/wp-share-button/wp-share-button.htmlindex 15cb43f3932..ddf751d5607 100644--- a/frontend/src/app/features/work-packages/components/wp-buttons/wp-share-button/wp-share-button.html+++ b/frontend/src/app/features/work-packages/components/wp-buttons/wp-share-button/wp-share-button.html@@ -2,6 +2,6 @@class="button toolbar-icon"(click)="openModal()">- <!-- <svg share-android></svg> -->+ <!-- Todo: <svg share-android></svg> --><span class="button--text" [textContent]="text.share"></span></button>diff --git a/frontend/src/app/features/work-packages/components/wp-share-modal/wp-share.modal.html b/frontend/src/app/features/work-packages/components/wp-share-modal/wp-share.modal.htmlindex 68e23a61b39..f4f7c6b326e 100644--- a/frontend/src/app/features/work-packages/components/wp-share-modal/wp-share.modal.html+++ b/frontend/src/app/features/work-packages/components/wp-share-modal/wp-share.modal.html@@ -7,6 +7,7 @@<div class="spot-modal--body spot-container"><turbo-frame id="work_package_share_list" src="{{this.frameSrc}}">+ <!-- Todo: Loading animation --></turbo-frame></div></div>