Provide a name attribute that uses the self link's title

This is useful when the resource is not loaded, but the
name attribute is needed. Usually the name attribute is
the title attribute of the link.
pull/4159/head
Alex Dik 9 years ago
parent 7d3fa423ba
commit ede7f165bf
  1. 29
      frontend/app/components/api/api-v3/hal/hal-resource.service.test.ts
  2. 10
      frontend/app/components/api/api-v3/hal/hal-resource.service.ts

@ -88,6 +88,7 @@ describe('halTransform service', () => {
},
self: {
href: '/api/v3/hello',
title: 'some title'
}
}
};
@ -103,14 +104,36 @@ describe('halTransform service', () => {
expect(transformedElement.$halTransformed).to.be.true;
});
describe('when returning back the plain object', () => {
describe('when the self link has a title attribute', () => {
beforeEach(() => {
transformedElement = halTransform({
_links: {
self: {
href: '/api/hello',
title: 'some title'
}
}
});
});
it('should have a name attribute that is equal to the title of the self link', () => {
expect(transformedElement.name).to.eq('some title');
});
it('should have a writable name attribute', () => {
transformedElement.name = 'some name';
expect(transformedElement.name).to.eq('some name');
});
});
//TODO: Fix
describe.skip('when returning back the plain object', () => {
var element;
beforeEach(() => {
element = transformedElement.$plain();
});
//TODO: Fix
it.skip('should be the same as the source element', () => {
it('should be the same as the source element', () => {
expect(element).to.eql(plainElement);
});
});

@ -32,10 +32,20 @@ function halResource(halTransform, HalLink, $q) {
public $embedded;
public $halTransformed: boolean = true;
private _name:string;
protected static fromLink(link) {
return new HalResource({_links: {self: link}}, false);
}
public get name():string {
return this._name || this.$links.self.$link.title || '';
}
public set name(name:string) {
this._name = name;
}
constructor(protected $source, public $loaded = true) {
var source = $source.restangularized ? $source.plain() : angular.copy($source);

Loading…
Cancel
Save