Get rid of op.HalResource type definition

pull/4338/head
Alex Dik 9 years ago
parent ac328d5ed1
commit e14d57e571
  1. 16
      frontend/app/components/api/api-v3/hal-resources/work-package-resource.service.ts
  2. 29
      frontend/app/components/api/api-work-packages/api-work-packages.service.ts
  3. 10
      frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.module.ts
  4. 13
      frontend/app/typings/open-project.typings.ts

@ -69,7 +69,7 @@ export default class WorkPackageResource extends HalResource {
return !this[fieldName] && fieldSchema.writable && fieldSchema.required;
}
public allowedValuesFor(field):ng.IPromise<op.HalResource[]> {
public allowedValuesFor(field):ng.IPromise<HalResource[]> {
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<any> {
if (this.isNew) {
return apiWorkPackages.wpApiPath().post(payload);
} else {
return this.$links.updateImmediately(payload);
}
return this.$links.updateImmediately(payload);
}
}

@ -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<op.HalResource> {
public emptyCreateForm(projectIdentifier?:string):ng.IPromise<HalResource> {
return this.wpApiPath(projectIdentifier).one('form').customPOST();
}
/**
* Returns a promise to GET `/api/v3/work_packages/available_projects`.
*/
public availableProjects(projectIdentifier?:string):ng.IPromise<op.HalResource> {
public availableProjects(projectIdentifier?:string):ng.IPromise<HalResource> {
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) {

@ -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);

@ -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();

Loading…
Cancel
Save