From a0c06ddc5797a1a36451471b3507effac3bb4607 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 18 Jun 2018 13:47:17 +0200 Subject: [PATCH] Fix closing split-view when saving through inline-create --- frontend/src/app/angular4-modules.ts | 1 - .../handlers/op-types-context-menu.directive.ts | 5 +++-- .../wp-edit-field-group.directive.ts | 15 ++++++++++++++- .../app/components/wp-new/wp-create.controller.ts | 3 ++- .../hal/resources/work-package-resource.ts | 3 ++- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/frontend/src/app/angular4-modules.ts b/frontend/src/app/angular4-modules.ts index 4b690b9161..9dd2d42fd6 100644 --- a/frontend/src/app/angular4-modules.ts +++ b/frontend/src/app/angular4-modules.ts @@ -280,7 +280,6 @@ import {WorkPackageEmbeddedTableEntryComponent} from "core-components/wp-table/e WorkPackageTableFocusService, WorkPackageTableSelection, - WorkPackageCreateService, // Provide both serves with tokens to avoid tight dependency cycles { provide: IWorkPackageCreateServiceToken, useClass: WorkPackageCreateService }, { provide: IWorkPackageEditingServiceToken, useClass: WorkPackageEditingService }, diff --git a/frontend/src/app/components/op-context-menu/handlers/op-types-context-menu.directive.ts b/frontend/src/app/components/op-context-menu/handlers/op-types-context-menu.directive.ts index bcccb72503..6752f2927e 100644 --- a/frontend/src/app/components/op-context-menu/handlers/op-types-context-menu.directive.ts +++ b/frontend/src/app/components/op-context-menu/handlers/op-types-context-menu.directive.ts @@ -29,11 +29,12 @@ import {WorkPackageCreateService} from '../../wp-new/wp-create.service'; import {StateService} from '@uirouter/core'; import {OPContextMenuService} from "core-components/op-context-menu/op-context-menu.service"; -import {Directive, ElementRef, Input} from "@angular/core"; +import {Directive, ElementRef, Inject, Input} from "@angular/core"; import {LinkHandling} from "core-app/modules/common/link-handling/link-handling"; import {OpContextMenuTrigger} from "core-components/op-context-menu/handlers/op-context-menu-trigger.directive"; import {TypeResource} from 'core-app/modules/hal/resources/type-resource'; import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource'; +import {IWorkPackageCreateServiceToken} from "core-components/wp-new/wp-create.service.interface"; @Directive({ selector: '[opTypesCreateDropdown]' @@ -47,7 +48,7 @@ export class OpTypesContextMenuDirective extends OpContextMenuTrigger { constructor(readonly elementRef:ElementRef, readonly opContextMenu:OPContextMenuService, readonly $state:StateService, - protected wpCreate:WorkPackageCreateService) { + @Inject(IWorkPackageCreateServiceToken) protected wpCreate:WorkPackageCreateService) { super(elementRef, opContextMenu); } diff --git a/frontend/src/app/components/wp-edit/wp-edit-field/wp-edit-field-group.directive.ts b/frontend/src/app/components/wp-edit/wp-edit-field/wp-edit-field-group.directive.ts index 045357ebc1..2c280f7607 100644 --- a/frontend/src/app/components/wp-edit/wp-edit-field/wp-edit-field-group.directive.ts +++ b/frontend/src/app/components/wp-edit/wp-edit-field/wp-edit-field-group.directive.ts @@ -44,6 +44,7 @@ import {WorkPackageNotificationService} from '../wp-notification.service'; import {WorkPackageCreateService} from './../../wp-new/wp-create.service'; import {I18nService} from "core-app/modules/common/i18n/i18n.service"; import {IWorkPackageEditingServiceToken} from "../../wp-edit-form/work-package-editing.service.interface"; +import {IWorkPackageCreateServiceToken} from "core-components/wp-new/wp-create.service.interface"; @Component({ selector: 'wp-edit-field-group,[wp-edit-field-group]', @@ -61,7 +62,7 @@ export class WorkPackageEditFieldGroupComponent implements OnInit, OnDestroy { constructor(protected states:States, protected injector:Injector, - protected wpCreate:WorkPackageCreateService, + @Inject(IWorkPackageCreateServiceToken) protected wpCreate:WorkPackageCreateService, @Inject(IWorkPackageEditingServiceToken) protected wpEditing:WorkPackageEditingService, protected wpNotificationsService:WorkPackageNotificationService, protected wpTableSelection:WorkPackageTableSelection, @@ -117,6 +118,18 @@ export class WorkPackageEditFieldGroupComponent implements OnInit, OnDestroy { if (this.inEditMode) { this.start(); } + + // Stop editing whenever a work package was saved + if (this.inEditMode && this.workPackage.isNew) { + this.wpCreate.onNewWorkPackage() + .pipe( + takeUntil(componentDestroyed(this)) + ) + .subscribe((wp:WorkPackageResource) => { + this.form.editMode = false; + this.stopEditingAndLeave(wp, true); + }); + } } public get editMode() { diff --git a/frontend/src/app/components/wp-new/wp-create.controller.ts b/frontend/src/app/components/wp-new/wp-create.controller.ts index cda6015f87..12110932da 100644 --- a/frontend/src/app/components/wp-new/wp-create.controller.ts +++ b/frontend/src/app/components/wp-new/wp-create.controller.ts @@ -47,6 +47,7 @@ import {I18nService} from "core-app/modules/common/i18n/i18n.service"; import { IWorkPackageEditingServiceToken } from "../wp-edit-form/work-package-editing.service.interface"; +import {IWorkPackageCreateServiceToken} from "core-components/wp-new/wp-create.service.interface"; @Injectable() @@ -69,7 +70,7 @@ export class WorkPackageCreateController implements OnInit, OnDestroy { readonly injector:Injector, protected wpNotificationsService:WorkPackageNotificationService, protected states:States, - protected wpCreate:WorkPackageCreateService, + @Inject(IWorkPackageCreateServiceToken) protected wpCreate:WorkPackageCreateService, protected wpTableFilters:WorkPackageTableFiltersService, protected wpCacheService:WorkPackageCacheService, protected pathHelper:PathHelperService, diff --git a/frontend/src/app/modules/hal/resources/work-package-resource.ts b/frontend/src/app/modules/hal/resources/work-package-resource.ts index 5cded5d569..afe6451e43 100644 --- a/frontend/src/app/modules/hal/resources/work-package-resource.ts +++ b/frontend/src/app/modules/hal/resources/work-package-resource.ts @@ -46,6 +46,7 @@ import {WorkPackageNotificationService} from 'core-components/wp-edit/wp-notific import {WorkPackageCreateService} from 'core-components/wp-new/wp-create.service'; import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service'; import {NotificationsService} from 'core-app/modules/common/notifications/notifications.service'; +import {IWorkPackageCreateServiceToken} from "core-components/wp-new/wp-create.service.interface"; interface WorkPackageResourceEmbedded { activities:CollectionResource; @@ -131,7 +132,7 @@ export class WorkPackageResource extends HalResource { readonly NotificationsService:NotificationsService = this.injector.get(NotificationsService); readonly wpNotificationsService:WorkPackageNotificationService = this.injector.get( WorkPackageNotificationService); - readonly wpCreate:WorkPackageCreateService = this.injector.get(WorkPackageCreateService); + readonly wpCreate:WorkPackageCreateService = this.injector.get(IWorkPackageCreateServiceToken); readonly pathHelper:PathHelperService = this.injector.get(PathHelperService); readonly opFileUpload:OpenProjectFileUploadService = this.injector.get(OpenProjectFileUploadService);