From e14d57e57160edf19af3d860135aa2e21d3cfff2 Mon Sep 17 00:00:00 2001 From: Alex Dik Date: Wed, 27 Apr 2016 16:52:58 +0200 Subject: [PATCH] Get rid of op.HalResource type definition --- .../work-package-resource.service.ts | 16 +++++----- .../api-work-packages.service.ts | 29 ++++++++++--------- .../wp-edit-field/wp-edit-field.module.ts | 10 ++++--- frontend/app/typings/open-project.typings.ts | 13 --------- 4 files changed, 29 insertions(+), 39 deletions(-) diff --git a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts index 6377e9b10d..52ce4a8e52 100644 --- a/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts +++ b/frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts @@ -69,7 +69,7 @@ export default class WorkPackageResource extends HalResource { return !this[fieldName] && fieldSchema.writable && fieldSchema.required; } - public allowedValuesFor(field):ng.IPromise { + public allowedValuesFor(field):ng.IPromise { var deferred = $q.defer(); this.getForm().then(form => { const allowedValues = form.$embedded.schema[field].allowedValues; @@ -149,10 +149,11 @@ export default class WorkPackageResource extends HalResource { angular.extend(this, workPackage); wpCacheService.updateWorkPackageList([this]); deferred.resolve(this); - }).catch((error) => { + }) + .catch((error) => { deferred.reject(error); - }).finally(() => { - + }) + .finally(() => { // Restore the form for subsequent saves // e.g., due to changes in lockVersion. // Not needed for inline create. @@ -170,8 +171,7 @@ export default class WorkPackageResource extends HalResource { } public isParentOf(otherWorkPackage) { - return otherWorkPackage.parent.$links.self.$link.href === - this.$links.self.$link.href; + return otherWorkPackage.parent.$links.self.$link.href === this.$links.self.$link.href; } public get isEditable():boolean { @@ -181,9 +181,9 @@ export default class WorkPackageResource extends HalResource { protected saveResource(payload):ng.IPromise { if (this.isNew) { return apiWorkPackages.wpApiPath().post(payload); - } else { - return this.$links.updateImmediately(payload); } + + return this.$links.updateImmediately(payload); } } diff --git a/frontend/app/components/api/api-work-packages/api-work-packages.service.ts b/frontend/app/components/api/api-work-packages/api-work-packages.service.ts index 1109fc120f..162469a09b 100644 --- a/frontend/app/components/api/api-work-packages/api-work-packages.service.ts +++ b/frontend/app/components/api/api-work-packages/api-work-packages.service.ts @@ -26,13 +26,15 @@ // See doc/COPYRIGHT.rdoc for more details. //++ +import HalResource from '../api-v3/hal-resources/hal-resource.service'; + export class ApiWorkPackagesService { protected wpBaseApi; - constructor (protected DEFAULT_PAGINATION_OPTIONS, - protected $stateParams, - protected $q:ng.IQService, - protected apiV3:restangular.IService) { + constructor(protected DEFAULT_PAGINATION_OPTIONS, + protected $stateParams, + protected $q:ng.IQService, + protected apiV3:restangular.IService) { this.wpBaseApi = apiV3.service('work_packages'); } @@ -41,10 +43,7 @@ export class ApiWorkPackagesService { var workPackages = this.wpApiPath(query.projectId); return workPackages.getList( - this.queryAsV3Params(offset, pageSize, query), - { - caching: { enabled : false } - } + this.queryAsV3Params(offset, pageSize, query), {caching: {enabled: false}} ); } @@ -53,23 +52,25 @@ export class ApiWorkPackagesService { * * @returns An empty work package form resource. */ - public emptyCreateForm(projectIdentifier?:string):ng.IPromise { + public emptyCreateForm(projectIdentifier?:string):ng.IPromise { return this.wpApiPath(projectIdentifier).one('form').customPOST(); } /** * Returns a promise to GET `/api/v3/work_packages/available_projects`. */ - public availableProjects(projectIdentifier?:string):ng.IPromise { + public availableProjects(projectIdentifier?:string):ng.IPromise { return this.wpApiPath(projectIdentifier).one('available_projects').get(); } - public wpApiPath(projectIdentifier?: any) { + public wpApiPath(projectIdentifier?:any) { + const args = ['work_packages']; + if (!!projectIdentifier) { - return this.apiV3.service('work_packages', this.apiV3.one('projects', projectIdentifier)); - } else { - return this.apiV3.service('work_packages'); + args.push(this.apiV3.one('projects', projectIdentifier)); } + + return this.apiV3.service(...args); } protected queryAsV3Params(offset:number, pageSize:number, query:api.ex.Query) { diff --git a/frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.module.ts b/frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.module.ts index 3d60c9f178..54f7275906 100644 --- a/frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.module.ts +++ b/frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.module.ts @@ -26,6 +26,8 @@ // See doc/COPYRIGHT.rdoc for more details. // ++ +import HalResource from '../../api/api-v3/hal-resources/hal-resource.service'; + export class Field { public static type:string; public static $injector:ng.auto.IInjectorService; @@ -42,7 +44,7 @@ export class Field { return (this.constructor as typeof Field).$injector; } - constructor(public resource:op.HalResource, + constructor(public resource:HalResource, public name:string, public schema) { } @@ -53,14 +55,14 @@ export class FieldFactory { protected static fields = {}; - protected static classes: {[type:string]: typeof Field} = {}; + protected static classes:{[type:string]:typeof Field} = {}; - public static register(fieldClass: typeof Field, fields:string[] = []) { + public static register(fieldClass:typeof Field, fields:string[] = []) { fields.forEach(field => FieldFactory.fields[field] = fieldClass.type); FieldFactory.classes[fieldClass.type] = fieldClass; } - public static create(workPackage:op.HalResource, + public static create(workPackage:HalResource, fieldName:string, schema:op.FieldSchema):Field { let type = FieldFactory.getType(schema.type); diff --git a/frontend/app/typings/open-project.typings.ts b/frontend/app/typings/open-project.typings.ts index 63079a8cb0..c58127e046 100644 --- a/frontend/app/typings/open-project.typings.ts +++ b/frontend/app/typings/open-project.typings.ts @@ -197,18 +197,6 @@ declare namespace op { restangularized:boolean; } - class HalResource { - public $links; - public $embedded; - public $isHal; - public name:string; - public href:string; - - constructor($source: restangular.IElement, $loaded: boolean); - - public $plain(); - } - class HalLink { public href:string; public title:string; @@ -227,7 +215,6 @@ declare namespace op { } interface WorkPackage extends api.v3.WorkPackage, WorkPackageLinks { - getForm(); getSchema();