AspectSelections style fixes

This commit is contained in:
cmrd Senya 2016-07-12 09:18:38 +00:00
parent d50ab83157
commit 06352b7809
No known key found for this signature in database
GPG key ID: 5FCC5BA680E67BFE
3 changed files with 60 additions and 58 deletions

View file

@ -3,7 +3,7 @@
app.collections.AspectSelections = Backbone.Collection.extend({ app.collections.AspectSelections = Backbone.Collection.extend({
model: app.models.AspectSelection, model: app.models.AspectSelection,
selectedAspects: function(attribute){ selectedGetAttribute: function(attribute) {
return _.pluck(_.filter(this.toJSON(), function(a) { return _.pluck(_.filter(this.toJSON(), function(a) {
return a.selected; return a.selected;
}), attribute); }), attribute);
@ -14,16 +14,18 @@ app.collections.AspectSelections = Backbone.Collection.extend({
}, },
selectAll: function() { selectAll: function() {
this.map(function(a){ a.set({ 'selected' : true })} ); this.map(function(a) { a.set({"selected": true}); });
}, },
deselectAll: function() { deselectAll: function() {
this.map(function(a){ a.set({ 'selected' : false })} ); this.map(function(a) { a.set({"selected": false}); });
}, },
toSentence: function() { toSentence: function() {
var separator = Diaspora.I18n.t("comma") + ' '; var separator = Diaspora.I18n.t("comma") + " ";
return this.selectedAspects('name').join(separator).replace(/,\s([^,]+)$/, ' ' + Diaspora.I18n.t("and") + ' $1') || Diaspora.I18n.t("my_aspects"); var pattern = new RegExp(Diaspora.I18n.t("comma") + "\\s([^" + Diaspora.I18n.t("comma") + "]+)$");
return this.selectedGetAttribute("name").join(separator).replace(pattern, " " + Diaspora.I18n.t("and") + " $1")
|| Diaspora.I18n.t("my_aspects");
} }
}); });
// @license-end // @license-end

View file

@ -142,7 +142,7 @@ app.Router = Backbone.Router.extend({
}, },
aspects_stream : function(){ aspects_stream : function(){
var ids = app.aspectSelections.selectedAspects("id"); var ids = app.aspectSelections.selectedGetAttribute("id");
app.stream = new app.models.StreamAspects([], { aspects_ids: ids }); app.stream = new app.models.StreamAspects([], { aspects_ids: ids });
app.stream.fetch(); app.stream.fetch();
this._initializeStreamView(); this._initializeStreamView();

View file

@ -1,18 +1,18 @@
describe("app.collections.AspectSelections", function() { describe("app.collections.AspectSelections", function() {
beforeEach(function() { beforeEach(function() {
var my_aspects = [ var myAspects = [
{ name: 'Work', selected: true }, {name: "Work", selected: true},
{ name: 'Friends', selected: false }, {name: "Friends", selected: false},
{ name: 'Acquaintances', selected: false } {name: "Acquaintances", selected: false}
]; ];
this.aspects = new app.collections.AspectSelections(my_aspects); this.aspects = new app.collections.AspectSelections(myAspects);
}); });
describe("#selectAll", function() { describe("#selectAll", function() {
it("selects every aspect in the collection", function() { it("selects every aspect in the collection", function() {
this.aspects.selectAll(); this.aspects.selectAll();
this.aspects.each(function(aspect) { this.aspects.each(function(aspect) {
expect(aspect.get('selected')).toBeTruthy(); expect(aspect.get("selected")).toBeTruthy();
}); });
}); });
}); });
@ -21,15 +21,15 @@ describe("app.collections.AspectSelections", function(){
it("deselects every aspect in the collection", function() { it("deselects every aspect in the collection", function() {
this.aspects.deselectAll(); this.aspects.deselectAll();
this.aspects.each(function(aspect) { this.aspects.each(function(aspect) {
expect(aspect.get('selected')).toBeFalsy(); expect(aspect.get("selected")).toBeFalsy();
}); });
}); });
}); });
describe("#allSelected", function() { describe("#allSelected", function() {
it("returns true if every aspect is selected", function() { it("returns true if every aspect is selected", function() {
this.aspects.at(1).set('selected', true); this.aspects.at(1).set("selected", true);
this.aspects.at(2).set('selected', true); this.aspects.at(2).set("selected", true);
expect(this.aspects.allSelected()).toBeTruthy(); expect(this.aspects.allSelected()).toBeTruthy();
}); });
@ -39,9 +39,9 @@ describe("app.collections.AspectSelections", function(){
}); });
describe("#toSentence", function() { describe("#toSentence", function() {
describe('without aspects', function(){ describe("without aspects", function() {
beforeEach(function() { beforeEach(function() {
this.aspects = new app.collections.AspectSelections([{ name: 'Work', selected: false }]); this.aspects = new app.collections.AspectSelections([{name: "Work", selected: false}]);
}); });
it("returns the name of the aspect", function() { it("returns the name of the aspect", function() {
@ -51,36 +51,36 @@ describe("app.collections.AspectSelections", function(){
describe("with one aspect", function() { describe("with one aspect", function() {
beforeEach(function() { beforeEach(function() {
this.aspects = new app.collections.AspectSelections([{ name: 'Work', selected: true }]); this.aspects = new app.collections.AspectSelections([{name: "Work", selected: true}]);
}); });
it("returns the name of the aspect", function() { it("returns the name of the aspect", function() {
expect(this.aspects.toSentence()).toEqual('Work'); expect(this.aspects.toSentence()).toEqual("Work");
}); });
}); });
describe("with three aspect", function() { describe("with three aspect", function() {
it("returns the name of the selected aspect", function() { it("returns the name of the selected aspect", function() {
expect(this.aspects.toSentence()).toEqual('Work'); expect(this.aspects.toSentence()).toEqual("Work");
}); });
it("returns the names of the two selected aspects", function() { it("returns the names of the two selected aspects", function() {
this.aspects.at(1).set('selected', true); this.aspects.at(1).set("selected", true);
expect(this.aspects.toSentence()).toEqual('Work and Friends'); expect(this.aspects.toSentence()).toEqual("Work and Friends");
}); });
it("returns the names of the selected aspects in a comma-separated sentence", function() { it("returns the names of the selected aspects in a comma-separated sentence", function() {
this.aspects.at(1).set('selected', true); this.aspects.at(1).set("selected", true);
this.aspects.at(2).set('selected', true); this.aspects.at(2).set("selected", true);
expect(this.aspects.toSentence()).toEqual('Work, Friends and Acquaintances'); expect(this.aspects.toSentence()).toEqual("Work, Friends and Acquaintances");
}); });
}); });
}); });
describe("#selectedAspects", function(){ describe("#selectedGetAttribute", function() {
describe("by name", function() { describe("by name", function() {
it("returns the names of the selected aspects", function() { it("returns the names of the selected aspects", function() {
expect(this.aspects.selectedAspects('name')).toEqual(["Work"]); expect(this.aspects.selectedGetAttribute("name")).toEqual(["Work"]);
}); });
}); });
}); });