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
Allow users to add viewpoints on create
Oliver Günthere25b4299c4d9
diff --git a/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.component.ts b/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.component.tsindex a922736150e..04126d5256e 100644--- a/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.component.ts+++ b/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.component.ts@@ -229,6 +229,13 @@ export class WorkPackageSingleViewComponent extends UntilDestroyedMixin implemenreturn elem.name;}+ /**+ * Allow other modules to register groups to insert into the single view+ */+ public prependedAttributeGroupComponents() {+ return this.hook.call('prependedAttributeGroups', this.workPackage);+ }+public attributeGroupComponent(group:GroupDescriptor) {// we take the last registered group component which means that// plugins will have their say if they register for it.diff --git a/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.html b/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.htmlindex 01e9703b4e2..0e613c0e96b 100644--- a/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.html+++ b/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.html@@ -71,7 +71,11 @@</div></div>- <bcf-wp-single-view [workPackage]="workPackage"></bcf-wp-single-view>+ <ng-container *ngFor="let component of prependedAttributeGroupComponents()">+ <ndc-dynamic [ndcDynamicComponent]="component"+ [ndcDynamicInputs]="{ workPackage: workPackage }">+ </ndc-dynamic>+ </ng-container><div class="attributes-group description-group"><div class="attributes-group--header">diff --git a/frontend/src/app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.interface.ts b/frontend/src/app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.interface.tsindex e2579f10a72..b2330187a53 100644--- a/frontend/src/app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.interface.ts+++ b/frontend/src/app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.interface.ts@@ -5,4 +5,5 @@ export interface BcfViewpointInterface {bitmaps:unknown[];orthogonal_camera?:unknown;perspective_camera?:unknown;+ snapshot:{ snapshot_type:string, snapshot_data:string };}diff --git a/frontend/src/app/modules/bim/bcf/bcf-wp-attribute-group/bcf-new-wp-attribute-group.component.ts b/frontend/src/app/modules/bim/bcf/bcf-wp-attribute-group/bcf-new-wp-attribute-group.component.tsnew file mode 100644index 00000000000..075565600f3--- /dev/null+++ b/frontend/src/app/modules/bim/bcf/bcf-wp-attribute-group/bcf-new-wp-attribute-group.component.ts@@ -0,0 +1,75 @@+import {ChangeDetectionStrategy, Component} from "@angular/core";+import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";+import {take} from "rxjs/operators";+import {BcfWpAttributeGroupComponent} from "core-app/modules/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component";++@Component({+ templateUrl: './bcf-wp-attribute-group.component.html',+ styleUrls: ['./bcf-wp-attribute-group.component.sass'],+ changeDetection: ChangeDetectionStrategy.OnPush+})+export class BcfNewWpAttributeGroupComponent extends BcfWpAttributeGroupComponent {++ ngAfterViewInit():void {+ super.ngAfterViewInit();++ // Save any leftover viewpoints when saving the work package+ if (this.workPackage.isNew) {+ this.observeCreation();+ }+ }++ // Disable show viewpoint functionality+ showViewpoint(index:number) {+ return;+ }++ deleteViewpoint(index:number) {+ this.setViewpoints(+ this.viewpoints.filter((_, i) => i !== index)+ );+ return;+ }++ async saveCurrentAsViewpoint() {+ const viewpoint = await this.viewerBridge!.getViewpoint();++ this.setViewpoints([+ ...this.viewpoints,+ {+ snapshotURL: viewpoint.snapshot.snapshot_data,+ viewpoint: viewpoint+ }+ ]);++ // Select the last created viewpoint and show it+ this.showIndex = this.viewpoints.length - 1;+ this.selectViewpointInGallery();+ }++ private observeCreation() {+ this.wpCreate+ .onNewWorkPackage()+ .pipe(+ take(1)+ )+ .subscribe(async (wp:WorkPackageResource) => {+ this.workPackage = wp;+ for (let el of this.viewpoints) {+ if (!el.href && el.viewpoint) {+ await this.persistViewpoint(el.viewpoint!);+ }+ }++ this.showIndex = this.viewpoints.length - 1;+ this.wpCache.require(this.workPackage.id!, true);+ });+ }++ protected actions() {+ // Show only delete button+ return super+ .actions()+ .filter(el => el.icon === 'icon-delete');+ }+}diff --git a/frontend/src/app/modules/bim/bcf/bcf-wp-single-view/bcf-wp-single-view.component.html b/frontend/src/app/modules/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.htmlsimilarity index 100%rename from frontend/src/app/modules/bim/bcf/bcf-wp-single-view/bcf-wp-single-view.component.htmlrename to frontend/src/app/modules/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.htmldiff --git a/frontend/src/app/modules/bim/bcf/bcf-wp-single-view/bcf-wp-single-view.component.sass b/frontend/src/app/modules/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.sasssimilarity index 100%rename from frontend/src/app/modules/bim/bcf/bcf-wp-single-view/bcf-wp-single-view.component.sassrename to frontend/src/app/modules/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.sassdiff --git a/frontend/src/app/modules/bim/bcf/bcf-wp-single-view/bcf-wp-single-view.component.ts b/frontend/src/app/modules/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.tssimilarity index 68%rename from frontend/src/app/modules/bim/bcf/bcf-wp-single-view/bcf-wp-single-view.component.tsrename to frontend/src/app/modules/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.tsindex 6ab045d33f9..3e431283568 100644--- a/frontend/src/app/modules/bim/bcf/bcf-wp-single-view/bcf-wp-single-view.component.ts+++ b/frontend/src/app/modules/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component.ts@@ -9,7 +9,7 @@ import {} from "@angular/core";import {StateService} from "@uirouter/core";import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";-import {NgxGalleryComponent, NgxGalleryImage, NgxGalleryOptions} from '@kolkov/ngx-gallery';+import {NgxGalleryComponent, NgxGalleryOptions} from '@kolkov/ngx-gallery';import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service";import {HalLink} from "core-app/modules/hal/hal-link/hal-link";import {BcfApiService} from "core-app/modules/bim/bcf/api/bcf-api.service";@@ -20,16 +20,24 @@ import {ViewerBridgeService} from "core-app/modules/bim/bcf/bcf-viewer-bridge/viimport {WorkPackageCacheService} from "core-components/work-packages/work-package-cache.service";import {UntilDestroyedMixin} from "core-app/helpers/angular/until-destroyed.mixin";import {NotificationsService} from "core-app/modules/common/notifications/notifications.service";--export type ViewPoint = { snapshotId:string, snapshotFullPath:string };+import {BcfViewpointInterface} from "core-app/modules/bim/bcf/api/viewpoints/bcf-viewpoint.interface";+import {WorkPackageCreateService} from "core-components/wp-new/wp-create.service";++export interface ViewpointItem {+ /** The URL of the viewpoint, if persisted */+ href?:string;+ /** URL (persisted or data) to the snapshot */+ snapshotURL:string;+ /** The loaded snapshot, if exists */+ viewpoint?:BcfViewpointInterface;+}@Component({- selector: 'bcf-wp-single-view',- templateUrl: './bcf-wp-single-view.component.html',- styleUrls: ['./bcf-wp-single-view.component.sass'],+ templateUrl: './bcf-wp-attribute-group.component.html',+ styleUrls: ['./bcf-wp-attribute-group.component.sass'],changeDetection: ChangeDetectionStrategy.OnPush})-export class BcfWpSingleViewComponent extends UntilDestroyedMixin implements AfterViewInit, OnDestroy {+export class BcfWpAttributeGroupComponent extends UntilDestroyedMixin implements AfterViewInit, OnDestroy {@Input() workPackage:WorkPackageResource;@ViewChild(NgxGalleryComponent) gallery:NgxGalleryComponent;@@ -44,19 +52,6 @@ export class BcfWpSingleViewComponent extends UntilDestroyedMixin implements Aftnotice_successful_delete: this.I18n.t('js.notice_successful_delete'),};- actions = [- {- icon: 'icon-watched',- onClick: (evt:any, index:number) => this.showViewpoint(index),- titleText: this.text.show_viewpoint- },- {- icon: 'icon-delete',- onClick: (evt:any, index:number) => this.deleteViewpoint(index),- titleText: this.text.delete_viewpoint- }- ];-galleryOptions:NgxGalleryOptions[] = [{width: '100%',@@ -87,8 +82,8 @@ export class BcfWpSingleViewComponent extends UntilDestroyedMixin implements AftarrowNextIcon: 'icon-arrow-right2',closeIcon: 'icon-close',downloadIcon: 'icon-download',- thumbnailActions: this.actions,- actions: this.actions,+ thumbnailActions: this.actions(),+ actions: this.actions(),},// max-width 800{@@ -107,19 +102,23 @@ export class BcfWpSingleViewComponent extends UntilDestroyedMixin implements Aft}];- galleryImages:NgxGalleryImage[] = [];+ viewpoints:ViewpointItem[] = [];++ galleryImages:any[] = [];++ // Remember the topic UUID, which we might just create+ topicUUID:string|undefined;// Currently, this is static. Need observable if this changes over timeviewerVisible = this.viewerBridge.viewerVisible();- viewpoints:ViewPoint[] = [];-constructor(readonly state:StateService,readonly pathHelper:PathHelperService,readonly currentProject:CurrentProjectService,readonly bcfApi:BcfApiService,readonly viewerBridge:ViewerBridgeService,readonly wpCache:WorkPackageCacheService,+ readonly wpCreate:WorkPackageCreateService,readonly notifications:NotificationsService,readonly cdRef:ChangeDetectorRef,readonly I18n:I18nService) {@@ -127,20 +126,8 @@ export class BcfWpSingleViewComponent extends UntilDestroyedMixin implements Aft}ngAfterViewInit():void {- this.wpCache- .observe(this.workPackage.id!)- .pipe(- this.untilDestroyed()- )- .subscribe(wp => {- this.workPackage = wp;-- if (wp.bcfViewpoints) {- this.setViewpoints();- this.loadViewpointFromRoute();- this.cdRef.detectChanges();- }- });+ // Observe changes on the work package to update the viewpoints+ this.observeChanges();}showViewpoint(index:number) {@@ -148,8 +135,7 @@ export class BcfWpSingleViewComponent extends UntilDestroyedMixin implements Aft.viewpointFromIndex(index).get().subscribe(data => {- if (this.viewerVisible- ) {+ if (this.viewerVisible) {this.viewerBridge.showViewpoint(data);} else {window.location.href = this.pathHelper.bimDetailsPath(@@ -179,19 +165,13 @@ export class BcfWpSingleViewComponent extends UntilDestroyedMixin implements Aftasync saveCurrentAsViewpoint() {const viewpoint = await this.viewerBridge!.getViewpoint();- const uuid = this.topicUUID || await this.createBcfTopic();- this.bcfApi- .projects.id(this.workPackage.project.idFromLink)- .topics.id(uuid)- .viewpoints- .post(viewpoint)- .subscribe((result) => {- // Update the work package to reload the viewpoint- this.notifications.addSuccess(this.text.notice_successful_create);- this.showIndex = this.viewpoints.length;- this.wpCache.require(this.workPackage.id!, true);- });+ await this.persistViewpoint(viewpoint);++ // Update the work package to reload the viewpoint+ this.notifications.addSuccess(this.text.notice_successful_create);+ this.showIndex = this.viewpoints.length;+ this.wpCache.require(this.workPackage.id!, true);}galleryPreviewOpen():void {@@ -203,34 +183,63 @@ export class BcfWpSingleViewComponent extends UntilDestroyedMixin implements Aft}selectViewpointInGallery() {- setTimeout(() => this.gallery.show(this.showIndex), 250);+ setTimeout(() => this.gallery?.show(this.showIndex), 250);}onGalleryChanged(event:{ index:number }) {this.showIndex = event.index;}- private set showIndex(value:number) {+ protected observeChanges() {+ this.wpCache+ .observe(this.workPackage.id!)+ .pipe(+ this.untilDestroyed()+ )+ .subscribe(wp => {+ this.workPackage = wp;+ this.setTopicUUIDFromWorkPackage();++ if (wp.bcfViewpoints) {+ this.setViewpoints(wp.bcfViewpoints.map((el:HalLink) => {+ return { href: el.href, snapshotURL: `${el.href}/snapshot` };+ }));+ this.loadViewpointFromRoute();+ this.cdRef.detectChanges();+ }+ });+ }++ protected async persistViewpoint(viewpoint:BcfViewpointInterface) {+ this.topicUUID = this.topicUUID || await this.createBcfTopic();++ return this.bcfApi+ .projects.id(this.workPackage.project.idFromLink)+ .topics.id(this.topicUUID)+ .viewpoints+ .post(viewpoint)+ .toPromise();+ }++ protected set showIndex(value:number) {const options = [...this.galleryOptions];options[0].startIndex = value;this.galleryOptions = options;}- private get showIndex():number {+ protected get showIndex():number {return this.galleryOptions[0].startIndex!;}- private get topicUUID():string|null {+ protected setTopicUUIDFromWorkPackage() {const topicHref:string|undefined = this.workPackage.bcfTopic?.href;if (topicHref) {- return this.bcfApi.parse<BcfViewpointPaths>(topicHref)!.id as string;+ this.topicUUID = this.bcfApi.parse<BcfViewpointPaths>(topicHref)!.id as string;}-- return null;}- private async createBcfTopic():Promise<string> {+ protected async createBcfTopic():Promise<string> {return this.bcfApi.projects.id(this.workPackage.project.idFromLink).topics@@ -239,8 +248,8 @@ export class BcfWpSingleViewComponent extends UntilDestroyedMixin implements Aft.then(resource => resource.guid);}- private setViewpoints() {- const length = this.workPackage.bcfViewpoints.length;+ protected setViewpoints(viewpoints:ViewpointItem[]) {+ const length = viewpoints.length;if (this.showIndex < 0 || length < 1) {this.showIndex = 0;@@ -248,30 +257,23 @@ export class BcfWpSingleViewComponent extends UntilDestroyedMixin implements Aftthis.showIndex = length - 1;}- this.viewpoints = this.workPackage.bcfViewpoints.map((vp:HalLink) => {- const viewpointResource = this.bcfApi.parse<BcfViewpointPaths>(vp.href!);-+ this.viewpoints = viewpoints;+ this.galleryImages = viewpoints.map(viewpoint => {return {- snapshotId: viewpointResource.id,- snapshotFullPath: `${vp.href}/snapshot`- } as ViewPoint;- });-- this.galleryImages = this.viewpoints.map(viewpoint => {- return {- small: viewpoint.snapshotFullPath,- medium: viewpoint.snapshotFullPath,- big: viewpoint.snapshotFullPath,+ small: viewpoint.snapshotURL,+ medium: viewpoint.snapshotURL,+ big: viewpoint.snapshotURL};});+ this.cdRef.detectChanges();}- private viewpointFromIndex(index:number):BcfViewpointPaths {+ protected viewpointFromIndex(index:number):BcfViewpointPaths {let viewpointHref = this.workPackage.bcfViewpoints[index].href;return this.bcfApi.parse<BcfViewpointPaths>(viewpointHref);}- private loadViewpointFromRoute() {+ protected loadViewpointFromRoute() {if (typeof (this.state.params.viewpoint) === 'number') {const index = this.state.params.viewpoint;this.showViewpoint(index);@@ -280,4 +282,19 @@ export class BcfWpSingleViewComponent extends UntilDestroyedMixin implements Aftthis.state.go('.', { ...this.state.params, viewpoint: undefined }, { reload: false });}}++ protected actions() {+ return [+ {+ icon: 'icon-watched',+ onClick: (evt:any, index:number) => this.showViewpoint(index),+ titleText: this.text.show_viewpoint+ },+ {+ icon: 'icon-delete',+ onClick: (evt:any, index:number) => this.deleteViewpoint(index),+ titleText: this.text.delete_viewpoint+ }+ ];+ }}diff --git a/frontend/src/app/modules/bim/bcf/openproject-bcf.module.ts b/frontend/src/app/modules/bim/bcf/openproject-bcf.module.tsindex 69a075666ff..b01c1ab7f05 100644--- a/frontend/src/app/modules/bim/bcf/openproject-bcf.module.ts+++ b/frontend/src/app/modules/bim/bcf/openproject-bcf.module.ts@@ -31,7 +31,6 @@ import {OpenprojectCommonModule} from "core-app/modules/common/openproject-commoimport {NgxGalleryModule} from "@kolkov/ngx-gallery";import {DisplayFieldService} from "core-app/modules/fields/display/display-field.service";import {BcfThumbnailDisplayField} from "core-app/modules/bim/bcf/fields/display/bcf-thumbnail-field.module";-import {BcfWpSingleViewComponent} from "core-app/modules/bim/bcf/bcf-wp-single-view/bcf-wp-single-view.component";import {HTTP_INTERCEPTORS} from "@angular/common/http";import {OpenProjectHeaderInterceptor} from "core-app/modules/hal/http/openproject-header-interceptor";import {BcfDetectorService} from "core-app/modules/bim/bcf/helper/bcf-detector.service";@@ -41,6 +40,10 @@ import {BcfExportButtonComponent} from "core-app/modules/bim/ifc_models/toolbar/import {RevitBridgeService} from "core-app/modules/bim/bcf/bcf-viewer-bridge/revit-bridge.service";import {IFCViewerService} from "core-app/modules/bim/ifc_models/ifc-viewer/ifc-viewer.service";import {ViewerBridgeService} from "core-app/modules/bim/bcf/bcf-viewer-bridge/viewer-bridge.service";+import {HookService} from "core-app/modules/plugins/hook-service";+import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource";+import {BcfWpAttributeGroupComponent} from "core-app/modules/bim/bcf/bcf-wp-attribute-group/bcf-wp-attribute-group.component";+import {BcfNewWpAttributeGroupComponent} from "core-app/modules/bim/bcf/bcf-wp-attribute-group/bcf-new-wp-attribute-group.component";/*** Determines based on the current user agent whether@@ -72,22 +75,48 @@ export const viewerBridgeServiceFactory = (injector:Injector) => {BcfPathHelperService],declarations: [- BcfWpSingleViewComponent,+ BcfWpAttributeGroupComponent,+ BcfNewWpAttributeGroupComponent,BcfImportButtonComponent,BcfExportButtonComponent,],exports: [- BcfWpSingleViewComponent,BcfImportButtonComponent,BcfExportButtonComponent,]})export class OpenprojectBcfModule {- constructor(injector:Injector, displayFieldService:DisplayFieldService) {+ static bootstrapCalled = false;++ constructor(injector:Injector) {+ OpenprojectBcfModule.bootstrap(injector);+ }++ // The static property prevents running the function+ // multiple times. This happens e.g. when the module is included+ // into a plugin's module.+ public static bootstrap(injector:Injector) {+ if (this.bootstrapCalled) {+ return;+ }++ this.bootstrapCalled = true;++ const displayFieldService = injector.get(DisplayFieldService);displayFieldService.addFieldType(BcfThumbnailDisplayField, 'bcfThumbnail', ['BCF Thumbnail']);+++ const hookService = injector.get(HookService);+ hookService.register('prependedAttributeGroups', (workPackage:WorkPackageResource) => {+ if (workPackage.isNew) {+ return BcfNewWpAttributeGroupComponent;+ } else {+ return BcfWpAttributeGroupComponent;+ }+ });}}