Use errors from API

pull/4159/head
Oliver Günther 9 years ago
parent 9ebe0e4c13
commit 7e732b25ed
  1. 2
      frontend/app/components/api/api-v3/hal/hal-resource.service.ts
  2. 21
      frontend/app/components/api/api-v3/hal/work-package-resource.service.ts
  3. 3
      frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.directive.ts
  4. 18
      frontend/app/components/wp-edit/wp-edit-form.directive.ts

@ -95,7 +95,7 @@ function halResource(halTransform, HalLink, $q) {
element._links = {};
linked.forEach(linkName => {
if (this[linkName] && !angular.isFunction(this[linkName])) {
if (typeof(this[linkName]) === 'object' && this[linkName].$links && !angular.isFunction(this[linkName])) {
element._links[linkName] = element[linkName].$links.self.$link;
}

@ -26,13 +26,16 @@
// See doc/COPYRIGHT.rdoc for more details.
//++
function wpResource(HalResource: typeof op.HalResource) {
function wpResource(HalResource: typeof op.HalResource, NotificationsService:any) {
class WorkPackageResource extends HalResource {
private form;
getForm() {
if (!this.form) {
this.form = this.$links.update(this);
this.form.catch(error => {
NotificationsService.addError(error.data.message);
});
}
return this.form;
}
@ -63,17 +66,17 @@ function wpResource(HalResource: typeof op.HalResource) {
delete plain.updatedAt;
return this.getForm().then(form => {
var plain_payload = form.embedded.payload.data();
var schema = form.embedded.schema;
var plain_payload = form.payload.$source;
var schema = form.$embedded.schema;
for (property in data) {
if (data[property] && schema[property] && schema[property]['writable'] === true) {
plain_payload[property] = data[property];
for (property in plain) {
if (plain[property] && schema.hasOwnProperty(property) && schema[property] && schema[property]['writable'] === true) {
plain_payload[property] = plain[property];
}
}
for (property in data._links) {
if (data._links[property] && schema[property] && schema[property]['writable'] === true) {
plain_payload._links[property] = data._links[property];
for (property in plain._links) {
if (plain._links[property] && schema.hasOwnProperty(property) && schema[property] && schema[property]['writable'] === true) {
plain_payload._links[property] = plain._links[property];
}
}

@ -50,8 +50,7 @@ export class WorkPackageEditFieldController {
}
public submit() {
this.deactivate();
this.formCtrl.updateWorkPackage();
this.formCtrl.updateWorkPackage().then(this.deactivate);
}
public activate() {

@ -29,7 +29,7 @@
export class WorkPackageEditFormController {
public workPackage;
constructor(protected NotificationsService) {
constructor(protected NotificationsService, protected $q) {
}
public loadSchema() {
@ -37,9 +37,21 @@ export class WorkPackageEditFormController {
}
public updateWorkPackage() {
this.workPackage.save().catch(error => {
this.NotificationsService.addError('There was an error ...');
var deferred = this.$q.defer();
this.workPackage.save()
.then(deferred.resolve)
.catch(error => {
if (error && error.data && error.data.message) {
this.NotificationsService.addError(error.data.message);
} else {
this.NotificationsService.addError("An internal error has occcurred.");
}
return deferred.reject();
});
return deferred.promise;
}
}

Loading…
Cancel
Save