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

Extract multiple-user-display-field to be reused for share cell

Oliver Güntherf196c5d55f8a
diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml
index 54e17e71b3a..94fc4ddefc9 100644
--- a/config/locales/js-en.yml
+++ b/config/locales/js-en.yml
@@ -1109,6 +1109,7 @@ en:
sharing:
share: 'Share'
title: "Share work package"
+ show_all_users: "Show all shared users"
selected_count: "%{count} selected"
selection:
mixed: "Mixed"
diff --git a/frontend/src/app/features/work-packages/components/wp-fast-table/builders/share-cell-builder.ts b/frontend/src/app/features/work-packages/components/wp-fast-table/builders/share-cell-builder.ts
index 86e5464f1ca..bf540988693 100644
--- a/frontend/src/app/features/work-packages/components/wp-fast-table/builders/share-cell-builder.ts
+++ b/frontend/src/app/features/work-packages/components/wp-fast-table/builders/share-cell-builder.ts
@@ -4,9 +4,22 @@ import { QueryColumn } from '../../wp-query/query-column';
import { tdClassName } from './cell-builder';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';
+import { PrincipalRendererService } from 'core-app/shared/components/principal/principal-renderer.service';
+import {
+ WorkPackageShareModalComponent,
+} from 'core-app/features/work-packages/components/wp-share-modal/wp-share.modal';
+import { OpModalService } from 'core-app/shared/components/modal/modal.service';
+import { I18nService } from 'core-app/core/i18n/i18n.service';
export class ShareCellbuilder {
@InjectField(IsolatedQuerySpace) isolatedQuerySpace:IsolatedQuerySpace;
+
+ @InjectField(PrincipalRendererService) principalRenderer:PrincipalRendererService;
+
+ @InjectField(OpModalService) opModalService:OpModalService;
+
+ @InjectField(I18nService) I18n:I18nService;
+
constructor(public readonly injector:Injector) {
}
@@ -15,14 +28,30 @@ export class ShareCellbuilder {
td.classList.add(tdClassName, column.id);
td.dataset.columnId = column.id;
- const relevantShares = this.isolatedQuerySpace.workPackageSharesCache.get(workPackage.id!).getValueOr([]);
+ const relevantShares = this
+ .isolatedQuerySpace
+ .workPackageSharesCache
+ .get(workPackage.id as string)
+ .getValueOr([]);
if (relevantShares.length === 0) {
td.innerHTML = '-';
} else {
- td.innerHTML = relevantShares.map((share) => share.principal.name).join(', ');
+ this
+ .principalRenderer
+ .renderAbbreviated(
+ td,
+ relevantShares.map((share) => share.principal),
+ );
+
+ td.setAttribute('title', this.I18n.t('js.work_packages.sharing.show_all_users'));
+ td.addEventListener('click', this.showShareModal.bind(this, workPackage));
}
return td;
}
+
+ private showShareModal(workPackage:WorkPackageResource) {
+ this.opModalService.show(WorkPackageShareModalComponent, 'global', { workPackage });
+ }
}
diff --git a/frontend/src/app/shared/components/fields/display/field-types/multiple-user-display-field.module.ts b/frontend/src/app/shared/components/fields/display/field-types/multiple-user-display-field.module.ts
index bb5a46e9790..86249a0e14a 100644
--- a/frontend/src/app/shared/components/fields/display/field-types/multiple-user-display-field.module.ts
+++ b/frontend/src/app/shared/components/fields/display/field-types/multiple-user-display-field.module.ts
@@ -26,59 +26,23 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-import { UserResource } from 'core-app/features/hal/resources/user-resource';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
import { PrincipalRendererService } from 'core-app/shared/components/principal/principal-renderer.service';
-import { cssClassCustomOption } from 'core-app/shared/components/fields/display/display-field.module';
import { ResourcesDisplayField } from './resources-display-field.module';
+import { HalResource } from 'core-app/features/hal/resources/hal-resource';
export class MultipleUserFieldModule extends ResourcesDisplayField {
@InjectField() principalRenderer:PrincipalRendererService;
- public render(element:HTMLElement, displayText:string):void {
- const names = this.value;
+ public render(element:HTMLElement):void {
+ const users = this.value as HalResource[];
element.innerHTML = '';
- element.setAttribute('title', names.join(', '));
+ element.setAttribute('title', users.map((el) => el.name).join(', '));
- if (names.length === 0) {
+ if (users.length === 0) {
this.renderEmpty(element);
} else {
- this.renderValues(this.attribute, element);
+ this.principalRenderer.renderAbbreviated(element, users);
}
}
-
- /**
- * Renders at most the first two values, followed by a badge indicating
- * the total count.
- */
- protected renderValues(values:UserResource[], element:HTMLElement) {
- const content = document.createDocumentFragment();
- const divContainer = document.createElement('div');
- divContainer.classList.add(cssClassCustomOption);
- content.appendChild(divContainer);
-
- this.renderAbridgedValues(divContainer, values);
-
- if (values.length > 2) {
- const dots = document.createElement('span');
- dots.innerHTML = '... ';
- divContainer.appendChild(dots);
-
- const badge = this.optionDiv(values.length.toString(), 'badge', '-secondary');
- content.appendChild(badge);
- }
-
- element.appendChild(content);
- }
-
- public renderAbridgedValues(element:HTMLElement, values:UserResource[]) {
- const valueForDisplay = _.take(values, 2);
- this.principalRenderer.renderMultiple(
- element,
- valueForDisplay,
- { hide: false, link: false },
- { hide: false, size: 'medium' },
- false,
- );
- }
}
diff --git a/frontend/src/app/shared/components/principal/principal-list.component.html b/frontend/src/app/shared/components/principal/principal-list.component.html
deleted file mode 100644
index 2f08999129d..00000000000
--- a/frontend/src/app/shared/components/principal/principal-list.component.html
+++ /dev/null
@@ -1,8 +0,0 @@
-<op-principal
- class="op-principal-list--principal"
- *ngFor="let principal of principals"
- [hideName]="true"
- [principal]="principal"
- [link]="false"
- size="mini"
-></op-principal>
diff --git a/frontend/src/app/shared/components/principal/principal-list.component.ts b/frontend/src/app/shared/components/principal/principal-list.component.ts
deleted file mode 100644
index f4ad56bec12..00000000000
--- a/frontend/src/app/shared/components/principal/principal-list.component.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import {
- ChangeDetectionStrategy,
- Component,
- Input,
- HostBinding,
-} from '@angular/core';
-import { PrincipalLike } from 'core-app/shared/components/principal/principal-types';
-
-@Component({
- selector: 'op-principal-list',
- templateUrl: './principal-list.component.html',
- styleUrls: [],
- changeDetection: ChangeDetectionStrategy.OnPush,
-})
-export class OpPrincipalListComponent {
- @HostBinding('class.op-principal-list') className = true;
-
- @Input() principals:PrincipalLike[];
-}
diff --git a/frontend/src/app/shared/components/principal/principal-renderer.service.ts b/frontend/src/app/shared/components/principal/principal-renderer.service.ts
index 6ee5b03ebaf..7d549530cc6 100644
--- a/frontend/src/app/shared/components/principal/principal-renderer.service.ts
+++ b/frontend/src/app/shared/components/principal/principal-renderer.service.ts
@@ -1,15 +1,11 @@
import { Injectable } from '@angular/core';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-import { ColorsService, colorModes } from 'core-app/shared/components/colors/colors.service';
+import { colorModes, ColorsService } from 'core-app/shared/components/colors/colors.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import idFromLink from 'core-app/features/hal/helpers/id-from-link';
import { IPrincipal } from 'core-app/core/state/principals/principal.model';
import { PrincipalLike } from './principal-types';
-import {
- PrincipalType,
- hrefFromPrincipal,
- typeFromHref,
-} from './principal-helper';
+import { hrefFromPrincipal, PrincipalType, typeFromHref } from './principal-helper';
export type AvatarSize = 'default'|'medium'|'mini';
@@ -33,16 +29,44 @@ export class PrincipalRendererService {
) {
}
+ renderAbbreviated(
+ container:HTMLElement,
+ users:(PrincipalLike|IPrincipal)[],
+ maxCount = 2,
+ name:NameOptions = { hide: false, link: false },
+ avatar:AvatarOptions = { hide: false, size: 'medium' },
+ ):void {
+ const wrapper = document.createElement('div');
+ const principals = document.createElement('div');
+ wrapper.classList.add('op-principal-list');
+ principals.classList.add('op-principal-list--principals');
+ wrapper.appendChild(principals);
+ container.appendChild(wrapper);
+
+ const valueForDisplay = _.take(users, maxCount);
+ this.renderMultiple(
+ principals,
+ valueForDisplay,
+ name,
+ avatar,
+ false,
+ );
+
+ if (users.length > maxCount) {
+ const badge = document.createElement('span');
+ badge.classList.add('op-principal-list--badge', 'badge', '-secondary');
+ badge.textContent = users.length.toString();
+ wrapper.appendChild(badge);
+ }
+ }
+
renderMultiple(
container:HTMLElement,
- users:PrincipalLike[]|IPrincipal[],
+ users:(PrincipalLike|IPrincipal)[],
name:NameOptions = { hide: false, link: false },
avatar:AvatarOptions = { hide: false, size: 'default' },
multiLine = false,
):void {
- container.classList.add('op-principal');
- const list = document.createElement('span');
-
for (let i = 0; i < users.length; i++) {
const userElement = document.createElement('span');
if (multiLine) {
@@ -51,16 +75,15 @@ export class PrincipalRendererService {
this.render(userElement, users[i], name, avatar);
- list.appendChild(userElement);
+ container.appendChild(userElement);
if (!multiLine && i < users.length - 1) {
const sep = document.createElement('span');
sep.textContent = ', ';
- list.appendChild(sep);
+ sep.classList.add('op-principal-list--separator');
+ container.appendChild(sep);
}
}
-
- container.appendChild(list);
}
render(
diff --git a/frontend/src/app/shared/components/principal/principal-rendering.module.ts b/frontend/src/app/shared/components/principal/principal-rendering.module.ts
index 78ebec35e85..18573122c0e 100644
--- a/frontend/src/app/shared/components/principal/principal-rendering.module.ts
+++ b/frontend/src/app/shared/components/principal/principal-rendering.module.ts
@@ -1,7 +1,6 @@
import { Injector, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { OpPrincipalComponent } from './principal.component';
-import { OpPrincipalListComponent } from './principal-list.component';
import { PrincipalRendererService } from './principal-renderer.service';
@NgModule({
@@ -10,14 +9,12 @@ import { PrincipalRendererService } from './principal-renderer.service';
],
exports: [
OpPrincipalComponent,
- OpPrincipalListComponent,
],
providers: [
PrincipalRendererService,
],
declarations: [
OpPrincipalComponent,
- OpPrincipalListComponent,
],
})
export class OpenprojectPrincipalRenderingModule {
diff --git a/frontend/src/global_styles/content/_badges.sass b/frontend/src/global_styles/content/_badges.sass
index 6b7a827897a..81b4737cece 100644
--- a/frontend/src/global_styles/content/_badges.sass
+++ b/frontend/src/global_styles/content/_badges.sass
@@ -27,13 +27,11 @@
//++
$badge-diameter: 1.25rem
-$badge-fontsize: 1rem
$badge-background: var(--primary-color)
$badge-secondary-background: #F1F1F1
$badge-color: var(--font-color-on-primary)
-@mixin badge-layout($fontsize: $badge-fontsize, $diameter: $badge-diameter)
- font-size: $fontsize
+@mixin badge-layout($diameter: $badge-diameter)
width: $diameter
height: $diameter
diff --git a/frontend/src/global_styles/content/_principal-list.sass b/frontend/src/global_styles/content/_principal-list.sass
index 464ffb1bfe4..46c57e6929f 100644
--- a/frontend/src/global_styles/content/_principal-list.sass
+++ b/frontend/src/global_styles/content/_principal-list.sass
@@ -1,5 +1,21 @@
+@import "helpers"
+
.op-principal-list
display: flex
+ align-items: center
+
+ &--principals
+ display: flex
+ overflow: hidden
+
+ .op-principal
+ @include text-shortener
+
+ &:first-child
+ flex-shrink: 0
+
+ &--separator
+ margin-right: 0.5rem
- &--principal:not(:first-child)
- margin-left: -12px
+ &--badge
+ flex: 0
diff --git a/frontend/src/global_styles/content/_user.sass b/frontend/src/global_styles/content/_user.sass
index 33d3fc32c34..1bd6a737469 100644
--- a/frontend/src/global_styles/content/_user.sass
+++ b/frontend/src/global_styles/content/_user.sass
@@ -30,9 +30,6 @@ h1, h2, h3, h4
.op-principal
vertical-align: middle
margin-right: 5px
-
-tr .op-principal
- margin-right: 5px
.user-link
display: inline-block
diff --git a/spec/features/work_packages/share/share_spec.rb b/spec/features/work_packages/share/share_spec.rb
index 181f96e2f92..ee19642e923 100644
--- a/spec/features/work_packages/share/share_spec.rb
+++ b/spec/features/work_packages/share/share_spec.rb
@@ -77,6 +77,10 @@ RSpec.describe 'Work package sharing',
let(:work_package_page) { Pages::FullWorkPackage.new(work_package) }
let(:share_modal) { Components::WorkPackages::ShareModal.new(work_package) }
let(:members_page) { Pages::Members.new project.identifier }
+ let(:wp_table) { Pages::WorkPackagesTable.new(project) }
+ let(:columns) { Components::WorkPackages::Columns.new }
+ let(:wp_modal) { Components::WorkPackages::TableConfigurationModal.new }
+
current_user { create(:user, firstname: 'Signed in', lastname: 'User') }
@@ -286,6 +290,28 @@ RSpec.describe 'Work package sharing',
expect(members_page).not_to have_user comment_user.name
expect(members_page).not_to have_user view_user.name
end
+
+ aggregate_failures 'Showing the shared users in the table' do
+ wp_table.visit!
+
+ wp_modal.open!
+ wp_modal.switch_to 'Columns'
+
+ columns.assume_opened
+ columns.uncheck_all save_changes: false
+ columns.add 'ID', save_changes: false
+ columns.add 'Subject', save_changes: false
+ columns.add 'Shared users', save_changes: false
+ columns.apply
+
+
+ wp_row = wp_table.row(work_package)
+ expect(wp_row).to have_css('.wp-table--cell-td.sharedWithUsers .badge', text: '7')
+ wp_row.find('.wp-table--cell-td.sharedWithUsers .badge').click
+
+ share_modal.expect_title(I18n.t('js.work_packages.sharing.title'))
+ share_modal.expect_shared_count_of(7)
+ end
end
it "lets the sharer know a user needs to be selected to share the work package with them" do