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
Use API to fetch total count
Oliver Günther3544aeed098e
diff --git a/frontend/src/app/features/work-packages/components/wp-buttons/wp-share-button/wp-share-button.component.ts b/frontend/src/app/features/work-packages/components/wp-buttons/wp-share-button/wp-share-button.component.tsindex bfb996e4934..27d061859f2 100644--- a/frontend/src/app/features/work-packages/components/wp-buttons/wp-share-button/wp-share-button.component.ts+++ b/frontend/src/app/features/work-packages/components/wp-buttons/wp-share-button/wp-share-button.component.ts@@ -27,17 +27,21 @@//++import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';-import {- ChangeDetectionStrategy,- ChangeDetectorRef,- Component,- Input,-} from '@angular/core';+import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit } from '@angular/core';import { I18nService } from 'core-app/core/i18n/i18n.service';import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';import { OpModalService } from 'core-app/shared/components/modal/modal.service';-import { WorkPackageShareModalComponent } from 'core-app/features/work-packages/components/wp-share-modal/wp-share.modal';+import {+ WorkPackageShareModalComponent,+} from 'core-app/features/work-packages/components/wp-share-modal/wp-share.modal';import { BannersService } from 'core-app/core/enterprise/banners.service';+import { ApiV3FilterBuilder } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';+import { filter, map, startWith, switchMap } from 'rxjs/operators';+import { Observable } from 'rxjs';+import { ActionsService } from 'core-app/core/state/actions/actions.service';+import { shareModalUpdated } from 'core-app/features/work-packages/components/wp-share-modal/sharing.actions';+import { CollectionResource } from 'core-app/features/hal/resources/collection-resource';@Component({// eslint-disable-next-line @angular-eslint/component-selector@@ -45,11 +49,13 @@ import { BannersService } from 'core-app/core/enterprise/banners.service';templateUrl: './wp-share-button.html',changeDetection: ChangeDetectionStrategy.OnPush,})-export class WorkPackageShareButtonComponent extends UntilDestroyedMixin {+export class WorkPackageShareButtonComponent extends UntilDestroyedMixin implements OnInit {@Input() public workPackage:WorkPackageResource;showEnterpriseIcon = this.bannersService.eeShowBanners;+ shareCount$:Observable<number>;+public text = {share: this.I18n.t('js.work_packages.sharing.share'),};@@ -59,11 +65,41 @@ export class WorkPackageShareButtonComponent extends UntilDestroyedMixin {readonly opModalService:OpModalService,readonly cdRef:ChangeDetectorRef,readonly bannersService:BannersService,+ readonly apiV3Service:ApiV3Service,+ readonly actions$:ActionsService,) {super();}+ ngOnInit() {+ this.shareCount$ = this+ .actions$+ .ofType(shareModalUpdated)+ .pipe(+ map((action) => action.workPackageId),+ filter((id) => id === this.workPackage.id?.toString()),+ startWith(null),+ switchMap(() => this.countShares()),+ );+ }+openModal():void {this.opModalService.show(WorkPackageShareModalComponent, 'global', { workPackage: this.workPackage });}++ private countShares():Observable<number> {+ const filters = new ApiV3FilterBuilder()+ .add('entityType', '=', ['WorkPackage'])+ .add('entityId', '=', [this.workPackage.id as string]);++ return this+ .apiV3Service+ .shares+ .filtered(filters, { pageSize: '0 ' })+ .get()+ .pipe(+ map((collection:CollectionResource) => collection.total),+ filter((count) => count > 0),+ );+ }}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 6a56660e431..2ca3ec2a5c2 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@@ -1,5 +1,6 @@<buttonclass="button toolbar-icon"+ data-test-selector="op-wp-share-button"(click)="openModal()"><svg@@ -7,7 +8,12 @@class="button--icon"size="small"></svg>- <span class="button--text" [textContent]="text.share"></span>+ <span class="button--text">+ {{ text.share }}+ <span *ngIf="(shareCount$ | async) as shareCount"+ class="badge -secondary"+ [textContent]="shareCount"></span>+ </span><svg*ngIf="showEnterpriseIcon"@@ -15,4 +21,5 @@class="button--icon upsale-colored"size="small"></svg>+</button>diff --git a/frontend/src/app/features/work-packages/components/wp-share-modal/sharing.actions.ts b/frontend/src/app/features/work-packages/components/wp-share-modal/sharing.actions.tsnew file mode 100644index 00000000000..c51436c3ab7--- /dev/null+++ b/frontend/src/app/features/work-packages/components/wp-share-modal/sharing.actions.ts@@ -0,0 +1,6 @@+import { action, props } from 'ts-action';++export const shareModalUpdated = action(+ '[Sharing] Share modal closed or updated',+ props<{ workPackageId:string }>(),+);diff --git a/frontend/src/app/features/work-packages/components/wp-share-modal/wp-share.modal.ts b/frontend/src/app/features/work-packages/components/wp-share-modal/wp-share.modal.tsindex b811f5b8bbf..d80d971a871 100644--- a/frontend/src/app/features/work-packages/components/wp-share-modal/wp-share.modal.ts+++ b/frontend/src/app/features/work-packages/components/wp-share-modal/wp-share.modal.ts@@ -1,17 +1,12 @@-import {- ChangeDetectionStrategy,- ChangeDetectorRef,- Component,- ElementRef,- Inject,- OnInit,-} from '@angular/core';+import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, Inject, OnInit } from '@angular/core';import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';import { OpModalComponent } from 'core-app/shared/components/modal/modal.component';import { OpModalLocalsToken } from 'core-app/shared/components/modal/modal.service';import { I18nService } from 'core-app/core/i18n/i18n.service';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';+import { ActionsService } from 'core-app/core/state/actions/actions.service';+import { shareModalUpdated } from 'core-app/features/work-packages/components/wp-share-modal/sharing.actions';@Component({templateUrl: './wp-share.modal.html',@@ -32,7 +27,8 @@ export class WorkPackageShareModalComponent extends OpModalComponent implementsreadonly cdRef:ChangeDetectorRef,readonly I18n:I18nService,readonly elementRef:ElementRef,- protected pathHelper:PathHelperService,+ readonly pathHelper:PathHelperService,+ readonly actions$:ActionsService,) {super(locals, cdRef, elementRef);@@ -43,4 +39,9 @@ export class WorkPackageShareModalComponent extends OpModalComponent implementsngOnInit() {super.ngOnInit();}++ onClose():boolean {+ this.actions$.dispatch(shareModalUpdated({ workPackageId: this.workPackage.id as string }));+ return super.onClose();+ }}diff --git a/spec/features/work_packages/share/share_spec.rb b/spec/features/work_packages/share/share_spec.rbindex 0253dc5b0b7..181f96e2f92 100644--- a/spec/features/work_packages/share/share_spec.rb+++ b/spec/features/work_packages/share/share_spec.rb@@ -95,6 +95,7 @@ RSpec.describe 'Work package sharing',# Clicking on the share button opens a modal which lists all of the users a work package# is explicitly shared with.# Project members are not listed unless the work package is also shared with them explicitly.+ work_package_page.expect_share_button_count(6)work_package_page.click_share_buttonaggregate_failures "Initial shares list" do@@ -226,6 +227,7 @@ RSpec.describe 'Work package sharing',endshare_modal.close+ work_package_page.expect_share_button_count(7)work_package_page.click_share_buttonaggregate_failures "Re-opening the modal after changes performed" dodiff --git a/spec/support/pages/work_packages/full_work_package.rb b/spec/support/pages/work_packages/full_work_package.rbindex 76d83d4f915..8ec2fe034c3 100644--- a/spec/support/pages/work_packages/full_work_package.rb+++ b/spec/support/pages/work_packages/full_work_package.rb@@ -50,6 +50,12 @@ module Pagesendend+ def expect_share_button_count(count)+ page.within_test_selector('op-wp-share-button') do+ expect(page).to have_css('.badge', text: count, wait: 10)+ end+ end+privatedef container