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
Render relations tab via server-side rendered turbo frame
Aaron Contrerase762f0249cd6
diff --git a/app/components/_index.sass b/app/components/_index.sassindex a14f1dce5db..45a89e33bc3 100644--- a/app/components/_index.sass+++ b/app/components/_index.sass@@ -17,3 +17,4 @@@import "projects/row_component"@import "op_primer/border_box_table_component"@import "work_packages/exports/modal_dialog_component"+@import "work_package_relations_tab/index_component"diff --git a/app/components/work_package_relations_tab/index_component.html.erb b/app/components/work_package_relations_tab/index_component.html.erbnew file mode 100644index 00000000000..3f15fde0121--- /dev/null+++ b/app/components/work_package_relations_tab/index_component.html.erb@@ -0,0 +1,31 @@+<%= turbo_frame_tag "work-package-relations-tab-content" do %>+ <%= flex_layout(classes: "work-package-relations-tab--list-container") do |flex| %>+ <% @relations.group_by(&:relation_type).each do |relation_type, relations| %>+ <%= flex.with_row do %>+ <%= render(border_box_container(padding: :condensed)) do |border_box|+ border_box.with_header do+ flex_layout do |flex|+ flex.with_column(mr: 2) do+ render(Primer::Beta::Text.new(font_size: :normal, color: :muted)) do+ t(relations.first.label_for(@work_package)).capitalize+ end+ end+ flex.with_column do+ render(Primer::Beta::Counter.new(count: relations.size,+ round: true,+ scheme: :primary))+ end+ end+ end+ relations.each do |relation|+ border_box.with_row do+ render(Primer::Beta::Text.new(font_size: :normal, color: :muted)) do+ relation.to.subject.to_s+ end+ end+ end+ end %>+ <% end %>+ <% end %>+ <% end %>+<% end %>diff --git a/app/components/work_package_relations_tab/index_component.rb b/app/components/work_package_relations_tab/index_component.rbnew file mode 100644index 00000000000..211e26d8523--- /dev/null+++ b/app/components/work_package_relations_tab/index_component.rb@@ -0,0 +1,12 @@+class WorkPackageRelationsTab::IndexComponent < ApplicationComponent+ include ApplicationHelper+ include OpPrimer::ComponentHelpers+ include Turbo::FramesHelper++ def initialize(work_package:, relations:)+ super()++ @work_package = work_package+ @relations = relations+ end+enddiff --git a/app/components/work_package_relations_tab/index_component.sass b/app/components/work_package_relations_tab/index_component.sassnew file mode 100644index 00000000000..48e6592c188--- /dev/null+++ b/app/components/work_package_relations_tab/index_component.sass@@ -0,0 +1,3 @@+.work-package-relations-tab+ &--list-container+ gap: 1.5remdiff --git a/app/controllers/work_package_relations_tab_controller.rb b/app/controllers/work_package_relations_tab_controller.rbnew file mode 100644index 00000000000..175cf547fce--- /dev/null+++ b/app/controllers/work_package_relations_tab_controller.rb@@ -0,0 +1,149 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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 WorkPackageRelationsTabController < ApplicationController+ include OpTurbo::ComponentStream+ # include OpTurbo::DialogStreamHelper+ # include Meetings::WorkPackageMeetingsTabComponentStreams++ before_action :set_work_package+ before_action :authorize_global++ def index+ @relations = @work_package+ .relations+ .includes(:to, :from)+ .visible++ render(+ WorkPackageRelationsTab::IndexComponent.new(+ work_package: @work_package,+ relations: @relations+ ),+ layout: false+ )+ end++ # def count+ # count = Meeting.visible.where(id: @work_package.meetings.select(:id)).count+ # render json: { count: }+ # end++ # def add_work_package_to_meeting_dialog+ # respond_with_dialog WorkPackageMeetingsTab::AddWorkPackageToMeetingDialogComponent.new(work_package: @work_package)+ # end++ # def add_work_package_to_meeting+ # call = ::MeetingAgendaItems::CreateService+ # .new(user: current_user)+ # .call(+ # add_work_package_to_meeting_params.merge(+ # work_package_id: @work_package.id,+ # presenter_id: current_user.id,+ # item_type: MeetingAgendaItem::ITEM_TYPES[:work_package]+ # )+ # )++ # meeting_agenda_item = call.result++ # if call.success?+ # set_agenda_items(:upcoming) # always switch back to the upcoming tab after adding the work package to a meeting++ # # update the whole index component as we need to update the counters in the tabbed nav as well+ # update_index_component_via_turbo_stream(+ # direction: :upcoming,+ # agenda_items_grouped_by_meeting: @agenda_items_grouped_by_meeting,+ # upcoming_meetings_count: @upcoming_meetings_count,+ # past_meetings_count: @past_meetings_count+ # )++ # replace_tab_counter_via_turbo_stream(work_package: @work_package)++ # # TODO: show success message?+ # else+ # # show errors in form+ # update_add_to_meeting_form_component_via_turbo_stream(meeting_agenda_item:, base_errors: call.errors[:base])+ # end++ # respond_with_turbo_streams+ # end++ private++ def set_work_package+ @work_package = WorkPackage.find(params[:work_package_id])+ @project = @work_package.project # required for authorization via before_action+ rescue ActiveRecord::RecordNotFound+ render_404+ end++ # def add_work_package_to_meeting_params+ # params.require(:meeting_agenda_item).permit(:meeting_id, :notes)+ # end++ # def set_agenda_items(direction)+ # upcoming_agenda_items_grouped_by_meeting = get_grouped_agenda_items(:upcoming)+ # past_agenda_items_grouped_by_meeting = get_grouped_agenda_items(:past)++ # @upcoming_meetings_count = upcoming_agenda_items_grouped_by_meeting.count+ # @past_meetings_count = past_agenda_items_grouped_by_meeting.count++ # @agenda_items_grouped_by_meeting = case direction+ # when :upcoming+ # upcoming_agenda_items_grouped_by_meeting+ # when :past+ # past_agenda_items_grouped_by_meeting+ # end+ # end++ # def get_grouped_agenda_items(direction)+ # get_agenda_items_of_work_package(direction).group_by(&:meeting)+ # end++ # def get_agenda_items_of_work_package(direction)+ # agenda_items = MeetingAgendaItem+ # .includes(:meeting)+ # .where(meeting_id: Meeting.visible(current_user))+ # .where(work_package_id: @work_package.id)+ # .reorder(sort_clause(direction))++ # comparison = direction == :past ? "<" : ">="+ # agenda_items.where("meetings.start_time + (interval '1 hour' * meetings.duration) #{comparison} ?", Time.zone.now)+ # end++ # def sort_clause(direction)+ # case direction+ # when :upcoming+ # "meetings.start_time ASC"+ # when :past+ # "meetings.start_time DESC"+ # else+ # raise ArgumentError, "Invalid direction: #{direction}. Must be one of :upcoming or :past."+ # end+ # end+enddiff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rbindex 51b4d6184a4..9305f8f0b75 100644--- a/config/initializers/permissions.rb+++ b/config/initializers/permissions.rb@@ -224,7 +224,8 @@ Rails.application.reloader.to_prepare do"work_packages/reports": %i[report report_details],"work_packages/activities_tab": %i[index update_streams update_sorting update_filter],"work_packages/menus": %i[show],- "work_packages/hover_card": %i[show]+ "work_packages/hover_card": %i[show],+ work_package_relations_tab: %i[index]},permissible_on: %i[work_package project],contract_actions: { work_packages: %i[read] }diff --git a/config/routes.rb b/config/routes.rbindex 02699c02574..5a5862103b4 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -602,6 +602,7 @@ Rails.application.routes.draw docontroller: "work_packages/progress",as: :work_package_progressend+ resources :relations_tab, only: %i[index], controller: "work_package_relations_tab"get "/export_dialog" => "work_packages#export_dialog", on: :collection, as: "export_dialog"get :show_conflict_flash_message, on: :collection # we don't need a specific work package for thisdiff --git a/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.component.ts b/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.component.tsindex 8666214892d..080b946e9b2 100644--- a/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.component.ts+++ b/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.component.ts@@ -39,6 +39,7 @@ import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';import { RelationResource } from 'core-app/features/hal/resources/relation-resource';import { RelationsStateValue, WorkPackageRelationsService } from './wp-relations.service';import { RelatedWorkPackagesGroup } from './wp-relations.interfaces';+import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';@Component({selector: 'wp-relations',@@ -65,14 +66,20 @@ export class WorkPackageRelationsComponent extends UntilDestroyedMixin implementpublic currentRelations:WorkPackageResource[] = [];- constructor(private I18n:I18nService,+ turboFrameSrc:string;++ constructor(+ private I18n:I18nService,private wpRelations:WorkPackageRelationsService,private cdRef:ChangeDetectorRef,- private apiV3Service:ApiV3Service) {+ private apiV3Service:ApiV3Service,+ private PathHelper:PathHelperService,+) {super();}ngOnInit() {+ this.turboFrameSrc = `${this.PathHelper.staticBase}/work_packages/${this.workPackage.id}/relations_tab`;this.canAddRelation = !!this.workPackage.addRelation;this.wpRelations@@ -126,14 +133,16 @@ export class WorkPackageRelationsComponent extends UntilDestroyedMixin implementreturn;}- this.relationGroups = <RelatedWorkPackagesGroup>_.groupBy(this.currentRelations,+ this.relationGroups = <RelatedWorkPackagesGroup>_.groupBy(+this.currentRelations,(wp:WorkPackageResource) => {if (this.groupByWorkPackageType) {return wp.type.name;}const normalizedType = (wp.relatedBy as RelationResource).normalizedType(this.workPackage);return this.I18n.t(`js.relation_labels.${normalizedType}`);- });+ },+);this.relationGroupKeys = _.keys(this.relationGroups);this.relationsPresent = _.size(this.relationGroups) > 0;this.cdRef.detectChanges();diff --git a/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.template.html b/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.template.htmlindex ca7f5f4106e..975371a795c 100644--- a/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.template.html+++ b/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.template.html@@ -1,3 +1,16 @@+<turbo-frame [src]="turboFrameSrc" id="work-package-relations-tab-content">+ <op-content-loader viewBox="0 0 100 100">+ <svg:rect x="0" y="0" width="70" height="5" rx="1" />++ <svg:rect x="75" y="0" width="25" height="5" rx="1" />++ <svg:rect x="0" y="10" width="100" height="8" rx="1" />++ <svg:rect x="0" y="25" width="100" height="12" rx="1" />+ </op-content-loader>+</turbo-frame>++<div style="background-color: orangered; height: 10px;"></div><divclass="loading-indicator--location"data-indicator-name="relation-groups"