Skip to content

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

Primerize relations tab contents

Aaron Contrerasc4f0d23b8e7f
diff --git a/app/components/work_package_relations_tab/index_component.html.erb b/app/components/work_package_relations_tab/index_component.html.erb
index 3f15fde0121..dbc070bab64 100644
--- a/app/components/work_package_relations_tab/index_component.html.erb
+++ b/app/components/work_package_relations_tab/index_component.html.erb
@@ -1,31 +1,63 @@
-<%= 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
+<%= component_wrapper(tag: "turbo-frame") do %>
+ <%=
+ flex_layout(justify_content: :space_between, align_items: :center, mb: 4) do |action_bar|
+ action_bar.with_column do
+ render(Primer::Beta::Text.new(color: :muted)) do
+ "Add relations to other work packages to create a link between them."
+ end
+ end
+ action_bar.with_column do
+ render(Primer::Alpha::ActionMenu.new(menu_id: "relations-list-action-menu")) do |menu|
+ menu.with_show_button do |button|
+ button.with_leading_visual_icon(icon: :"plus")
+
+ button.with_trailing_action_icon(icon: :"triangle-down")
+ "Relation"
+ end
+ Relation::TYPES.values.each do |type_configuration_hash|
+ menu.with_item(label: t(type_configuration_hash[:name]).capitalize) do |item|
+ item.with_description.with_content("blugh")
+ end
+ end
+ end
+ end
+ end
+ %>
+ <%=
+ if relations.any?
+ flex_layout(classes: "work-package-relations-tab--list-container") do |flex|
+ relations.group_by(&:relation_type).each do |relation_type, relations_of_type|
+ flex.with_row do
+ render(border_box_container(padding: :condensed)) do |border_box|
+ border_box.with_header(py: 3) do
+ flex_layout(align_items: :center) do |flex|
+ flex.with_column(mr: 2) do
+ render(Primer::Beta::Text.new(font_size: :normal, font_weight: :bold)) do
+ t(relations_of_type.first.label_for(work_package)).capitalize
+ end
+ end
+ flex.with_column do
+ render(Primer::Beta::Counter.new(count: relations_of_type.size,
+ round: true,
+ scheme: :primary))
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
+ relations_of_type.each do |relation|
+ border_box.with_row(style: "padding-top: 12px; padding-bottom: 12px;") do
+ render(WorkPackageRelationsTab::RelationComponent.new(work_package: relation.to))
end
end
end
- end %>
- <% end %>
- <% end %>
- <% end %>
+ end
+ end
+ end
+ else
+ render Primer::Beta::Blankslate.new(border: true) do |component|
+ component.with_visual_icon(icon: "package-dependents")
+ component.with_heading(tag: :h2).with_content("No relations")
+ component.with_description { "This work package does not yet have any relations." }
+ end
+ end
+ %>
<% end %>
diff --git a/app/components/work_package_relations_tab/index_component.rb b/app/components/work_package_relations_tab/index_component.rb
index 211e26d8523..b771da97621 100644
--- a/app/components/work_package_relations_tab/index_component.rb
+++ b/app/components/work_package_relations_tab/index_component.rb
@@ -1,7 +1,13 @@
+# frozen_string_literal: true
+
class WorkPackageRelationsTab::IndexComponent < ApplicationComponent
+ FRAME_ID = "work-package-relations-tab-content"
include ApplicationHelper
include OpPrimer::ComponentHelpers
include Turbo::FramesHelper
+ include OpTurbo::Streamable
+
+ attr_reader :work_package, :relations
def initialize(work_package:, relations:)
super()
@@ -9,4 +15,8 @@ class WorkPackageRelationsTab::IndexComponent < ApplicationComponent
@work_package = work_package
@relations = relations
end
+
+ def self.wrapper_key
+ FRAME_ID
+ end
end
diff --git a/app/components/work_package_relations_tab/index_component.sass b/app/components/work_package_relations_tab/index_component.sass
index 48e6592c188..439628c939c 100644
--- a/app/components/work_package_relations_tab/index_component.sass
+++ b/app/components/work_package_relations_tab/index_component.sass
@@ -1,3 +1,8 @@
.work-package-relations-tab
&--list-container
gap: 1.5rem
+
+// We reference an ID as one is required to be specified for the action menu list.
+// It can't be nested inside the BEM model as it's placed as a #top-layer element.
+#relations-list-action-menu-list
+ max-height: 300px
diff --git a/app/components/work_package_relations_tab/relation_component.html.erb b/app/components/work_package_relations_tab/relation_component.html.erb
new file mode 100644
index 00000000000..8ace8af5eb2
--- /dev/null
+++ b/app/components/work_package_relations_tab/relation_component.html.erb
@@ -0,0 +1,69 @@
+<%= flex_layout(direction: :column, style: "gap: 0.25rem;") do |flex|
+ flex.with_row(flex_layout: true,
+ justify_content: :flex_start,
+ align_items: :center,
+ style: "gap: 0.5rem;") do |meta_information_row|
+ meta_information_row.with_column do
+ render(Primer::Beta::Text.new(font_size: :small,
+ font_weight: :bold,
+ color: :muted)) { "#{work_package.type.name.upcase}" }
+ end
+
+ meta_information_row.with_column do
+ render(Primer::Beta::Text.new(font_size: :small,
+ color: :muted)) { "##{work_package.id}" }
+ end
+ meta_information_row.with_column do
+ render(Primer::Beta::Text.new(classes: "__hl_inline_status_#{work_package.status.id}")) do
+ work_package.status.name
+ end
+ end
+ end
+
+ flex.with_row(flex_layout: true, justify_content: :space_between, align_items: :center) do |subject_line_row|
+ subject_line_row.with_column do
+ render(Primer::Beta::Link.new(href: work_package_path(work_package),
+ color: :default,
+ underline: false,
+ font_size: :normal,
+ font_weight: :bold,
+ target: "_blank")) { work_package.subject }
+ end
+
+ subject_line_row.with_column do
+ render(Primer::Alpha::ActionMenu.new) do |menu|
+ menu.with_show_button(icon: "kebab-horizontal",
+ 'aria-label': I18n.t(:label_agenda_item_actions),
+ scheme: :invisible,
+ ml: 2,
+ test_selector: 'op-meeting-agenda-actions')
+ menu.with_item(label: "Edit relation",
+ href: "#",
+ content_arguments: {
+ data: { "turbo-stream": true }
+ }) do |item|
+ item.with_leading_visual_icon(icon: :pencil)
+ end
+ menu.with_item(label: "Delete relation",
+ scheme: :danger,
+ href: "#",
+ form_arguments: {
+ method: :delete, data: { confirm: t("text_are_you_sure"), "turbo-stream": true }
+ }) do |item|
+ item.with_leading_visual_icon(icon: :trash)
+ end
+ end
+ end
+ end
+
+ if work_package.description.present?
+ flex.with_row(flex_layout: true, justify_content: :flex_start) do |description_row|
+ description_row.with_column do
+ render(Primer::Beta::Text.new(font_size: :small,
+ color: :muted)) do
+ format_text(work_package, :description)
+ end
+ end
+ end
+ end
+end %>
diff --git a/app/components/work_package_relations_tab/relation_component.rb b/app/components/work_package_relations_tab/relation_component.rb
new file mode 100644
index 00000000000..0a71843dab4
--- /dev/null
+++ b/app/components/work_package_relations_tab/relation_component.rb
@@ -0,0 +1,12 @@
+class WorkPackageRelationsTab::RelationComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+
+ attr_reader :work_package
+
+ def initialize(work_package:)
+ super()
+
+ @work_package = work_package
+ end
+end
diff --git a/app/controllers/work_package_relations_tab_controller.rb b/app/controllers/work_package_relations_tab_controller.rb
index 175cf547fce..8de82799fb6 100644
--- a/app/controllers/work_package_relations_tab_controller.rb
+++ b/app/controllers/work_package_relations_tab_controller.rb
@@ -38,15 +38,25 @@ class WorkPackageRelationsTabController < ApplicationController
@relations = @work_package
.relations
.includes(:to, :from)
- .visible
-
- render(
- WorkPackageRelationsTab::IndexComponent.new(
- work_package: @work_package,
- relations: @relations
- ),
- layout: false
- )
+
+ respond_to do |format|
+ format.html do
+ render(
+ WorkPackageRelationsTab::IndexComponent.new(
+ work_package: @work_package,
+ relations: @relations
+ ),
+ layout: false
+ )
+ end
+ format.turbo_stream do
+ replace_via_turbo_stream(component: WorkPackageRelationsTab::IndexComponent.new(
+ work_package: @work_package,
+ relations: @relations
+ ))
+ render turbo_stream: turbo_streams
+ end
+ end
end
# def count
diff --git a/app/views/work_package_relations_tab/_index.html.erb b/app/views/work_package_relations_tab/_index.html.erb
new file mode 100644
index 00000000000..43c920b1591
--- /dev/null
+++ b/app/views/work_package_relations_tab/_index.html.erb
@@ -0,0 +1,6 @@
+<%= render(
+ WorkPackageRelationsTab::IndexComponent.new(
+ work_package: @work_package,
+ relations: @relations
+ )
+) %>
diff --git a/frontend/src/app/features/work-packages/components/wp-fast-table/handlers/row/wp-state-links-handler.ts b/frontend/src/app/features/work-packages/components/wp-fast-table/handlers/row/wp-state-links-handler.ts
index 4eb6bcceadd..f566f71a38a 100644
--- a/frontend/src/app/features/work-packages/components/wp-fast-table/handlers/row/wp-state-links-handler.ts
+++ b/frontend/src/app/features/work-packages/components/wp-fast-table/handlers/row/wp-state-links-handler.ts
@@ -48,7 +48,6 @@ export class WorkPackageStateLinksHandler implements TableEventHandler {
}
// Locate the details link from event
- // debugger;
const target = evt.target as HTMLElement;
const element = target.closest(this.SELECTOR) as HTMLElement & { dataset:DOMStringMap };
const state = element.dataset.wpState;
diff --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.ts
index 080b946e9b2..1f86f8b6c4f 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
@@ -27,7 +27,7 @@
//++
import {
- ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit,
+ ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit, ViewChild, ElementRef,
} from '@angular/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
@@ -40,6 +40,12 @@ import { RelationResource } from 'core-app/features/hal/resources/relation-resou
import { RelationsStateValue, WorkPackageRelationsService } from './wp-relations.service';
import { RelatedWorkPackagesGroup } from './wp-relations.interfaces';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
+import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';
+import { renderStreamMessage } from '@hotwired/turbo';
+
+interface TurboFrameElement extends HTMLElement {
+ src:string;
+}
@Component({
selector: 'wp-relations',
@@ -51,6 +57,8 @@ export class WorkPackageRelationsComponent extends UntilDestroyedMixin implement
public relationGroups:RelatedWorkPackagesGroup = {};
+ @ViewChild('#work-package-relations-tab-content') readonly relationTurboFrame:TurboFrameElement;
+
public relationGroupKeys:string[] = [];
public relationsPresent = false;
@@ -74,6 +82,7 @@ export class WorkPackageRelationsComponent extends UntilDestroyedMixin implement
private cdRef:ChangeDetectorRef,
private apiV3Service:ApiV3Service,
private PathHelper:PathHelperService,
+ private turboRequests:TurboRequestsService,
) {
super();
}
@@ -90,6 +99,14 @@ export class WorkPackageRelationsComponent extends UntilDestroyedMixin implement
)
.subscribe((relations:RelationsStateValue) => {
this.loadedRelations(relations);
+ // Refresh the turbo frame
+ // eslint-disable-next-line no-self-assign
+ this.relationTurboFrame.src = this.relationTurboFrame.src;
+ void this.turboRequests.requestStream(this.turboFrameSrc)
+ .then((html) => {
+ // eslint-disable-next-line no-self-assign
+ renderStreamMessage(html);
+ });
});
this.wpRelations.require(this.workPackage.id!);
@@ -105,6 +122,11 @@ export class WorkPackageRelationsComponent extends UntilDestroyedMixin implement
)
.subscribe((wp:WorkPackageResource) => {
this.workPackage = wp;
+ void this.turboRequests.requestStream(this.turboFrameSrc)
+ .then((html) => {
+ // eslint-disable-next-line no-self-assign
+ renderStreamMessage(html);
+ });
});
}
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.html
index 975371a795c..42f371d7bf2 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
@@ -10,7 +10,7 @@
</op-content-loader>
</turbo-frame>
-<div style="background-color: orangered; height: 10px;"></div>
+<div style="margin-top: 30px; background-color: orangered; height: 10px;"></div>
<div
class="loading-indicator--location"
data-indicator-name="relation-groups"