Avoid wpEditMode in Create Service

Inline creation doesn't use wpEditMode.
pull/4471/head
Oliver Günther 8 years ago committed by Alex Dik
parent 4af41a0350
commit efdc044a29
  1. 31
      frontend/app/components/wp-create/wp-create.controller.ts
  2. 51
      frontend/app/components/wp-create/wp-create.service.ts
  3. 4
      frontend/app/components/wp-edit/wp-edit-mode-state.service.ts

@ -32,6 +32,7 @@ import {WorkPackageResource} from "../api/api-v3/hal-resources/work-package-reso
import {WorkPackageCacheService} from "../work-packages/work-package-cache.service";
import {scopedObservable} from "../../helpers/angular-rx-utils";
import IRootScopeService = angular.IRootScopeService;
import {WorkPackageEditModeStateService} from "../wp-edit/wp-edit-mode-state.service";
export class WorkPackageCreateController {
public newWorkPackage:WorkPackageResource|any;
@ -53,11 +54,13 @@ export class WorkPackageCreateController {
protected NotificationsService,
protected loadingIndicator,
protected wpCreate:WorkPackageCreateService,
protected wpEditModeState:WorkPackageEditModeStateService,
protected wpCacheService:WorkPackageCacheService) {
scopedObservable($scope, wpCreate.createNewWorkPackage($state.params.projectPath))
.subscribe(wp => {
this.newWorkPackage = wp;
wpCacheService.updateWorkPackage(wp);
this.wpEditModeState.start();
if ($state.params.parent_id) {
scopedObservable($scope, wpCacheService.loadWorkPackage($state.params.parent_id))
@ -73,14 +76,24 @@ export class WorkPackageCreateController {
this.$state.go('work-packages.list', this.$state.params);
}
public saveWorkPackage(successState:string) {
this.wpCreate.saveWorkPackage().then(wp => {
this.loadingIndicator.mainPage = this.$state.go(successState, {workPackageId: wp.id})
.then(() => {
this.$rootScope.$emit('workPackagesRefreshInBackground');
this.notifySuccess();
});
});
public saveWorkPackage(successState:string): ng.IPromise<WorkPackageResource> {
if (this.wpEditModeState.active) {
return this.wpEditModeState.save().then(wp => {
this.newWorkPackage = null;
this.refreshAfterSave(wp, successState);
return wp;
});
}
return this.$q.reject();
}
private refreshAfterSave(wp, successState) {
this.loadingIndicator.mainPage = this.$state.go(successState, {workPackageId: wp.id})
.then(() => {
this.$rootScope.$emit('workPackagesRefreshInBackground');
this.notifySuccess();
});
}
private notifySuccess() {

@ -34,52 +34,27 @@ import {WorkPackageEditModeStateService} from "../wp-edit/wp-edit-mode-state.ser
import {WorkPackageCacheService} from "../work-packages/work-package-cache.service";
export class WorkPackageCreateService {
protected form:HalResource;
private _newWorkPackage:ng.IPromise<WorkPackageResource>;
constructor(protected $q:ng.IQService,
protected WorkPackageResource:typeof WorkPackageResource,
protected wpEditModeState:WorkPackageEditModeStateService,
protected wpCacheService:WorkPackageCacheService,
protected apiWorkPackages:ApiWorkPackagesService) {
protected form: HalResource;
constructor(protected $q: ng.IQService,
protected WorkPackageResource: typeof WorkPackageResource,
protected wpCacheService: WorkPackageCacheService,
protected apiWorkPackages: ApiWorkPackagesService) {
}
public createNewWorkPackage(projectIdentifier) {
if (!this._newWorkPackage) {
this._newWorkPackage = this.getForm(projectIdentifier).then(form => {
var wp = this.WorkPackageResource.fromCreateForm(form);
this.wpCacheService.updateWorkPackage(wp);
this.wpEditModeState.start();
var wp = this.getForm(projectIdentifier).then(form => {
var wp = this.WorkPackageResource.fromCreateForm(form);
return wp;
});
}
this.wpCacheService.updateWorkPackage(wp);
return Rx.Observable.fromPromise(this._newWorkPackage);
}
public saveWorkPackage() {
const deferred = this.$q.defer();
this._newWorkPackage.then(() => {
if (this.wpEditModeState.active) {
this.wpEditModeState.save().then(wp => {
this._newWorkPackage = null;
deferred.resolve(wp);
});
}
else {
deferred.reject();
}
return wp;
});
return deferred.promise;
return Rx.Observable.fromPromise(wp);
}
private getForm(projectIdentifier):ng.IPromise<HalResource> {
private getForm(projectIdentifier): ng.IPromise<HalResource> {
if (!this.form) {
this.form = this.apiWorkPackages.emptyCreateForm(projectIdentifier);
}

@ -34,7 +34,7 @@ export class WorkPackageEditModeStateService {
private _active: boolean = false;
constructor(protected $rootScope, protected $window, protected I18n) {
constructor(protected $rootScope, protected $window, protected $q, protected I18n) {
$rootScope.$on('$stateChangeStart', function (event, toState, toParams, fromState, fromParams) {
if (this.form && fromParams.workPackageId
@ -73,6 +73,8 @@ export class WorkPackageEditModeStateService {
return wp;
});
}
return this.$q.reject();
}
public register(form: WorkPackageEditFormController) {

Loading…
Cancel
Save