Skip to content

Commit

Permalink
feat(hal browser): use name and title from self link when not specifi…
Browse files Browse the repository at this point in the history
…ed in embedded resource
  • Loading branch information
bethesque committed Sep 15, 2017
1 parent 915a7ee commit 354374c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions vendor/hal-browser/js/hal/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ HAL.Models.Resource = Backbone.Model.extend({
initialize: function(representation) {
representation = representation || {};
this.links = representation._links;
this.title = representation.title;
this.name = representation.name;
this.title = this.buildTitle(representation);
this.name = this.buildName(representation);
if(representation._embedded !== undefined) {
this.embeddedResources = this.buildEmbeddedResources(representation._embedded);
}
Expand All @@ -12,6 +12,20 @@ HAL.Models.Resource = Backbone.Model.extend({
this.unset('_links', { silent: true });
},

buildName: function(representation) {
return representation.name ||
(representation._links
&& representation._links.self
&& representation._links.self.name);
},

buildTitle: function(representation) {
return representation.title ||
(representation._links
&& representation._links.self
&& representation._links.self.title);
},

buildEmbeddedResources: function(embeddedResources) {
var result = {};
_.each(embeddedResources, function(obj, rel) {
Expand Down

0 comments on commit 354374c

Please sign in to comment.