Skip to content

Commit

Permalink
merge any unknown labels into 'all labels' before opening editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Hallvord R. M. Steen committed Oct 29, 2015
1 parent 344b277 commit c04e67a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions webcompat/static/js/lib/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ issues.LabelEditorView = Backbone.View.extend({
},
template: _.template($('#label-editor-tmpl').html()),
render: function() {
// make sure no labels from this issue are lost
// even if they are not (yet) in our labels.json file
issues.allLabels.merge(this.issueView.issueLabels);
this.$el.html(this.template(this.model));
this.resizeEditorHeight();
_.defer(_.bind(function() {
Expand Down
27 changes: 27 additions & 0 deletions webcompat/static/js/lib/models/label-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,32 @@ issues.LabelList = Backbone.Model.extend({
toJSON: function(){
var labelsArray = _.pluck(this.get('labels'), 'name');
return issues.allLabels.toPrefixed(labelsArray);
},
has: function(label) {
if(typeof label === 'string') {
return this.toArray().indexOf(label) > -1;
} else { // we assume this is an object
return this.toArray().indexOf(label.name) > -1;
}
},
merge: function(inputArray){
if(!(inputArray instanceof issues.LabelList)) {
inputArray = new issues.LabelList({labels:inputArray});
}
var existingLabels = this.get('labels');
var newLabels = inputArray.get('labels');
for (var i = 0; i < newLabels.length; i++) {
if(!this.has(newLabels[i])) {
existingLabels.push(newLabels[i]);
}
};
var existingMap = this.get('namespaceMap');
var newMap = inputArray.get('namespaceMap');
for(var property in newMap) {
// we assume that the "old" map may have better data than the "new"
existingMap[property] = existingMap[property] || newMap[property];
}
this.set('labels', existingLabels);
this.set('namespaceMap', existingMap);
}
});

0 comments on commit c04e67a

Please sign in to comment.