Replace space-localized service with global

pull/7042/head
Oliver Günther 6 years ago
parent 587b45b6ca
commit be9be53b0e
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 10
      frontend/src/app/components/modals/editor/macro-wp-button-modal/wp-button-macro.modal.ts
  2. 12
      frontend/src/app/components/work-packages/work-package-cache.service.spec.ts
  3. 9
      frontend/src/app/components/work-packages/work-package-cache.service.ts
  4. 13
      frontend/src/app/components/wp-new/wp-create.service.ts
  5. 8
      frontend/src/app/modules/hal/dm-services/work-package-dm.service.ts
  6. 3
      frontend/src/app/modules/hal/resources/work-package-resource.spec.ts
  7. 6
      frontend/src/app/modules/hal/resources/work-package-resource.ts
  8. 4
      frontend/src/app/modules/work_packages/openproject-work-packages.module.ts

@ -31,10 +31,9 @@ import {OpModalLocalsToken} from "core-components/op-modals/op-modal.service";
import {AfterViewInit, ChangeDetectorRef, Component, ElementRef, Inject, ViewChild} from "@angular/core";
import {OpModalLocalsMap} from "core-components/op-modals/op-modal.types";
import {I18nService} from "core-app/modules/common/i18n/i18n.service";
import {WorkPackageCreateService} from "core-components/wp-new/wp-create.service";
import {IWorkPackageCreateServiceToken} from "core-components/wp-new/wp-create.service.interface";
import {TypeResource} from "core-app/modules/hal/resources/type-resource";
import {CurrentProjectService} from "core-components/projects/current-project.service";
import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service";
@Component({
templateUrl: './wp-button-macro.modal.html'
@ -68,8 +67,8 @@ export class WpButtonMacroModal extends OpModalComponent implements AfterViewIni
constructor(readonly elementRef:ElementRef,
@Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,
@Inject(IWorkPackageCreateServiceToken) protected wpCreate:WorkPackageCreateService,
protected currentProject:CurrentProjectService,
readonly currentProject:CurrentProjectService,
readonly workPackageDmService:WorkPackageDmService,
readonly cdRef:ChangeDetectorRef,
readonly I18n:I18nService) {
@ -78,7 +77,8 @@ export class WpButtonMacroModal extends OpModalComponent implements AfterViewIni
this.classes = this.locals.classes;
this.buttonStyle = this.classes === 'button';
this.wpCreate.getEmptyForm(this.currentProject.identifier)
this.workPackageDmService
.emptyCreateForm({}, this.currentProject.identifier)
.then((form:any) => {
this.availableTypes = form.schema.type.allowedValues;
});

@ -34,7 +34,6 @@ import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper
import {OpenprojectHalModule} from 'core-app/modules/hal/openproject-hal.module';
import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';
import {ApiWorkPackagesService} from 'core-components/api/api-work-packages/api-work-packages.service';
import {OpenProjectFileUploadService} from 'core-components/api/op-file-upload/op-file-upload.service';
import {SchemaCacheService} from 'core-components/schemas/schema-cache.service';
import {States} from 'core-components/states.service';
@ -42,11 +41,12 @@ import {WorkPackageCacheService} from 'core-components/work-packages/work-packag
import {WorkPackageNotificationService} from 'core-components/wp-edit/wp-notification.service';
import {IWorkPackageCreateServiceToken} from 'core-components/wp-new/wp-create.service.interface';
import {take, takeWhile} from 'rxjs/operators';
import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service";
describe('WorkPackageCacheService', () => {
let injector:Injector;
let wpCacheService:WorkPackageCacheService;
let apiWorkPackagesService:ApiWorkPackagesService;
let workPackageDmService:WorkPackageDmService;
let schemaCacheService:SchemaCacheService;
let dummyWorkPackages:WorkPackageResource[] = [];
@ -60,7 +60,7 @@ describe('WorkPackageCacheService', () => {
HalResourceService,
WorkPackageCacheService,
SchemaCacheService,
ApiWorkPackagesService,
WorkPackageDmService,
{provide: PathHelperService, useValue: {}},
{provide: I18nService, useValue: {t: (...args:any[]) => 'translation'}},
{provide: WorkPackageResource, useValue: {}},
@ -74,10 +74,10 @@ describe('WorkPackageCacheService', () => {
injector = TestBed.get(Injector);
wpCacheService = TestBed.get(WorkPackageCacheService);
schemaCacheService = TestBed.get(SchemaCacheService);
apiWorkPackagesService = TestBed.get(ApiWorkPackagesService);
workPackageDmService = TestBed.get(WorkPackageDmService);
// sinon.stub(apiWorkPackagesService, 'loadWorkPackageById').returns(Promise.resolve(true));
spyOn(apiWorkPackagesService, 'loadWorkPackageById').and.returnValue(Promise.resolve(true));
// sinon.stub(WorkPackageDmService, 'loadWorkPackageById').returns(Promise.resolve(true));
spyOn(workPackageDmService, 'loadWorkPackageById').and.returnValue(Promise.resolve(true));
// sinon.stub(schemaCacheService, 'ensureLoaded').returns(Promise.resolve(true));
spyOn(schemaCacheService, 'ensureLoaded').and.returnValue(Promise.resolve(true));

@ -27,9 +27,7 @@
// ++
import {MultiInputState, State} from 'reactivestates';
import {ApiWorkPackagesService} from '../api/api-work-packages/api-work-packages.service';
import {States} from '../states.service';
import {WorkPackageNotificationService} from './../wp-edit/wp-notification.service';
import {StateCacheService} from '../states/state-cache.service';
import {SchemaCacheService} from './../schemas/schema-cache.service';
import {WorkPackageCollectionResource} from 'core-app/modules/hal/resources/wp-collection-resource';
@ -37,6 +35,7 @@ import {SchemaResource} from 'core-app/modules/hal/resources/schema-resource';
import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
import {Injectable} from '@angular/core';
import {debugLog} from "core-app/helpers/debug_output";
import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service";
function getWorkPackageId(id:number | string):string {
return (id || '__new_work_package__').toString();
@ -48,7 +47,7 @@ export class WorkPackageCacheService extends StateCacheService<WorkPackageResour
/*@ngInject*/
constructor(private states:States,
private schemaCacheService:SchemaCacheService,
private apiWorkPackages:ApiWorkPackagesService) {
private workPackageDmService:WorkPackageDmService) {
super();
}
@ -107,7 +106,7 @@ export class WorkPackageCacheService extends StateCacheService<WorkPackageResour
protected loadAll(ids:string[]) {
return new Promise<undefined>((resolve, reject) => {
this.apiWorkPackages
this.workPackageDmService
.loadWorkPackagesCollectionsFor(_.uniq(ids))
.then((pagedResults:WorkPackageCollectionResource[]) => {
_.each(pagedResults, (results) => {
@ -134,7 +133,7 @@ export class WorkPackageCacheService extends StateCacheService<WorkPackageResour
reject(error);
};
this.apiWorkPackages.loadWorkPackageById(id, true)
this.workPackageDmService.loadWorkPackageById(id, true)
.then((workPackage:WorkPackageResource) => {
this.schemaCacheService.ensureLoaded(workPackage).then(() => {
this.multiState.get(id).putValue(workPackage);

@ -26,8 +26,7 @@
// See doc/COPYRIGHT.rdoc for more details.
// ++
import {Injectable, Injector, Inject} from '@angular/core';
import {ApiWorkPackagesService} from '../api/api-work-packages/api-work-packages.service';
import {Inject, Injectable, Injector} from '@angular/core';
import {HalResource} from 'core-app/modules/hal/resources/hal-resource';
import {WorkPackageCacheService} from '../work-packages/work-package-cache.service';
import {Observable, Subject} from 'rxjs';
@ -39,8 +38,8 @@ import {HookService} from 'core-app/modules/plugins/hook-service';
import {WorkPackageFilterValues} from "core-components/wp-edit-form/work-package-filter-values";
import {IWorkPackageEditingServiceToken} from "core-components/wp-edit-form/work-package-editing.service.interface";
import {WorkPackageEditingService} from "core-components/wp-edit-form/work-package-editing-service";
import {WorkPackageTableFiltersService} from "core-components/wp-fast-table/state/wp-table-filters.service";
import {IsolatedQuerySpace} from "core-app/modules/work_packages/query-space/isolated-query-space";
import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service";
@Injectable()
export class WorkPackageCreateService implements IWorkPackageCreateService {
@ -55,7 +54,7 @@ export class WorkPackageCreateService implements IWorkPackageCreateService {
protected halResourceService:HalResourceService,
@Inject(IWorkPackageEditingServiceToken) protected readonly wpEditing:WorkPackageEditingService,
protected readonly querySpace:IsolatedQuerySpace,
protected apiWorkPackages:ApiWorkPackagesService) {
protected workPackageDmService:WorkPackageDmService) {
}
public newWorkPackageCreated(wp:WorkPackageResource) {
@ -74,7 +73,7 @@ export class WorkPackageCreateService implements IWorkPackageCreateService {
}
public createNewTypedWorkPackage(projectIdentifier:string|undefined|null, type:number) {
return this.apiWorkPackages.typedCreateForm(type, projectIdentifier).then(form => {
return this.workPackageDmService.typedCreateForm(type, projectIdentifier).then(form => {
return this.fromCreateForm(form);
});
}
@ -110,14 +109,14 @@ export class WorkPackageCreateService implements IWorkPackageCreateService {
public copyWorkPackage(copyFromForm:any, projectIdentifier?:string) {
let request = copyFromForm.payload.$source;
return this.apiWorkPackages.emptyCreateForm(request, projectIdentifier).then(form => {
return this.workPackageDmService.emptyCreateForm(request, projectIdentifier).then(form => {
return this.copyFrom(copyFromForm, form);
});
}
public getEmptyForm(projectIdentifier:string|null|undefined):Promise<HalResource> {
if (!this.form) {
this.form = this.apiWorkPackages.emptyCreateForm({}, projectIdentifier);
this.form = this.workPackageDmService.emptyCreateForm({}, projectIdentifier);
}
return this.form;

@ -27,16 +27,16 @@
//++
import {HalResource} from 'core-app/modules/hal/resources/hal-resource';
import {States} from '../../states.service';
import {buildApiV3Filter} from '../api-v3/api-v3-filter-builder';
import {HalResourceService} from 'core-app/modules/hal/services/hal-resource.service';
import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
import {WorkPackageCollectionResource} from 'core-app/modules/hal/resources/wp-collection-resource';
import {Inject, Injectable} from '@angular/core';
import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';
import {Injectable} from "@angular/core";
import {States} from "core-components/states.service";
import {buildApiV3Filter} from "core-components/api/api-v3/api-v3-filter-builder";
@Injectable()
export class ApiWorkPackagesService {
export class WorkPackageDmService {
constructor(protected halResourceService:HalResourceService,
protected pathHelper:PathHelperService,
protected states:States) {

@ -34,7 +34,6 @@ import {States} from 'core-components/states.service';
import {TypeDmService} from 'core-app/modules/hal/dm-services/type-dm.service';
import {WorkPackageResource} from 'core-app/modules/hal/resources/work-package-resource';
import {NotificationsService} from 'core-app/modules/common/notifications/notifications.service';
import {ApiWorkPackagesService} from 'core-components/api/api-work-packages/api-work-packages.service';
import {WorkPackageNotificationService} from 'core-components/wp-edit/wp-notification.service';
import {SchemaCacheService} from 'core-components/schemas/schema-cache.service';
import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';
@ -80,7 +79,7 @@ describe('WorkPackage', () => {
LoadingIndicatorService,
PathHelperService,
I18nService,
{ provide: ApiWorkPackagesService, useValue: {} },
{ provide: WorkPackageDmService, useValue: {} },
{ provide: IWorkPackageCreateServiceToken, useValue: {} },
{ provide: StateService, useValue: {} },
{ provide: SchemaCacheService, useValue: {} },

@ -38,13 +38,13 @@ import {
} from 'core-components/api/op-file-upload/op-file-upload.service';
import {SchemaResource} from 'core-app/modules/hal/resources/schema-resource';
import {States} from 'core-components/states.service';
import {ApiWorkPackagesService} from 'core-components/api/api-work-packages/api-work-packages.service';
import {WorkPackageCacheService} from 'core-components/work-packages/work-package-cache.service';
import {SchemaCacheService} from 'core-components/schemas/schema-cache.service';
import {WorkPackageNotificationService} from 'core-components/wp-edit/wp-notification.service';
import {PathHelperService} from 'core-app/modules/common/path-helper/path-helper.service';
import {NotificationsService} from 'core-app/modules/common/notifications/notifications.service';
import {Attachable} from 'core-app/modules/hal/resources/mixins/attachable-mixin';
import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service";
export interface WorkPackageResourceEmbedded {
activities:CollectionResource;
@ -125,7 +125,7 @@ export class WorkPackageBaseResource extends HalResource {
readonly I18n:I18nService = this.injector.get(I18nService);
readonly states:States = this.injector.get(States);
readonly apiWorkPackages:ApiWorkPackagesService = this.injector.get(ApiWorkPackagesService);
readonly workPackageDmService = this.injector.get(WorkPackageDmService);
readonly wpCacheService:WorkPackageCacheService = this.injector.get(WorkPackageCacheService);
readonly schemaCacheService:SchemaCacheService = this.injector.get(SchemaCacheService);
readonly NotificationsService:NotificationsService = this.injector.get(NotificationsService);
@ -273,7 +273,7 @@ export class WorkPackageBaseResource extends HalResource {
this['update'] = this.$links.update = form.$links.self;
// Use POST /work_packages for saving link
this['updateImmediately'] = this.$links.updateImmediately = (payload) => {
return this.apiWorkPackages.createWorkPackage(payload);
return this.workPackageDmService.createWorkPackage(payload);
};
}

@ -137,7 +137,6 @@ import {WorkPackageCacheService} from 'core-components/work-packages/work-packag
import {SchemaCacheService} from 'core-components/schemas/schema-cache.service';
import {WorkPackageWatchersService} from 'core-components/wp-single-view-tabs/watchers-tab/wp-watchers.service';
import {WorkPackagesActivityService} from 'core-components/wp-single-view-tabs/activity-panel/wp-activity.service';
import {ApiWorkPackagesService} from 'core-components/api/api-work-packages/api-work-packages.service';
import {WorkPackageNotificationService} from 'core-components/wp-edit/wp-notification.service';
import {KeepTabService} from 'core-components/wp-single-view-tabs/keep-tab/keep-tab.service';
import {QueryFormDmService} from 'core-app/modules/hal/dm-services/query-form-dm.service';
@ -155,6 +154,7 @@ import {WorkPackageFilterByTextInputComponent} from "core-components/filters/qui
import {QueryFiltersService} from "core-components/wp-query/query-filters.service";
import {WorkPackageCardViewComponent} from "core-components/wp-card-view/wp-card-view.component";
import {WorkPackageIsolatedQuerySpaceDirective} from "core-app/modules/work_packages/query-space/wp-isolated-query-space.directive";
import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service";
@NgModule({
imports: [
@ -198,7 +198,7 @@ import {WorkPackageIsolatedQuerySpaceDirective} from "core-app/modules/work_pack
KeepTabService,
WorkPackageNotificationService,
ApiWorkPackagesService,
WorkPackageDmService,
WorkPackagesActivityService,
WorkPackageWatchersService,

Loading…
Cancel
Save