Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc6710fb

Browse files
committed
Fixes#213.
Stable Version 1.4.1.
1 parent0e2c5e4 commitc6710fb

File tree

8 files changed

+155
-57
lines changed

8 files changed

+155
-57
lines changed

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#####1.4.1 - 11 November 2014
2+
3+
######Backwards compatible bug fixes
4+
-#213 - multiple orderBy does not work
5+
16
#####1.4.0 - 09 November 2014
27

38
######Backwards compatible API changes

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Unlike Backbone and Ember Models, angular-data does not require the use of gette
88

99
Supporting relations, computed properties, model lifecycle control and a slew of other features, angular-data is the tool for giving your data the respect it deserves.
1010

11-
__Latest Release:__[1.4.0](https://github.com/jmdobry/angular-data/releases/tag/1.4.0)
11+
__Latest Release:__[1.4.1](https://github.com/jmdobry/angular-data/releases/tag/1.4.1)
1212

1313
Angular-data is finally 1.0.!
1414

‎bower.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author":"Jason Dobry",
33
"name":"angular-data",
44
"description":"Data store for Angular.js.",
5-
"version":"1.4.0",
5+
"version":"1.4.1",
66
"homepage":"http://angular-data.pseudobry.com/",
77
"repository": {
88
"type":"git",

‎dist/angular-data.js‎

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4089,6 +4089,42 @@ function lifecycleNoop(resourceName, attrs, cb) {
40894089
cb(null,attrs);
40904090
}
40914091

4092+
functioncompare(DSUtils,orderBy,index,a,b){
4093+
vardef=orderBy[index];
4094+
varcA=a[def[0]],cB=b[def[0]];
4095+
if(DSUtils.isString(cA)){
4096+
cA=DSUtils.upperCase(cA);
4097+
}
4098+
if(DSUtils.isString(cB)){
4099+
cB=DSUtils.upperCase(cB);
4100+
}
4101+
if(def[1]==='DESC'){
4102+
if(cB<cA){
4103+
return-1;
4104+
}elseif(cB>cA){
4105+
return1;
4106+
}else{
4107+
if(index<orderBy.length-1){
4108+
returncompare(DSUtils,orderBy,index+1,a,b);
4109+
}else{
4110+
return0;
4111+
}
4112+
}
4113+
}else{
4114+
if(cA<cB){
4115+
return-1;
4116+
}elseif(cA>cB){
4117+
return1;
4118+
}else{
4119+
if(index<orderBy.length-1){
4120+
returncompare(DSUtils,orderBy,index+1,a,b);
4121+
}else{
4122+
return0;
4123+
}
4124+
}
4125+
}
4126+
}
4127+
40924128
functionDefaults(){
40934129
}
40944130

@@ -4214,9 +4250,10 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
42144250

42154251
// Apply 'orderBy'
42164252
if(orderBy){
4217-
angular.forEach(orderBy,function(def){
4253+
varindex=0;
4254+
angular.forEach(orderBy,function(def,i){
42184255
if(_this.utils.isString(def)){
4219-
def=[def,'ASC'];
4256+
orderBy[i]=[def,'ASC'];
42204257
}elseif(!_this.utils.isArray(def)){
42214258
thrownew_this.errors.IllegalArgumentError('DS.filter(resourceName[, params][, options]): '+JSON.stringify(def)+': Must be a string or an array!',{
42224259
params:{
@@ -4228,30 +4265,7 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
42284265
});
42294266
}
42304267
filtered=_this.utils.sort(filtered,function(a,b){
4231-
varcA=a[def[0]],cB=b[def[0]];
4232-
if(_this.utils.isString(cA)){
4233-
cA=_this.utils.upperCase(cA);
4234-
}
4235-
if(_this.utils.isString(cB)){
4236-
cB=_this.utils.upperCase(cB);
4237-
}
4238-
if(def[1]==='DESC'){
4239-
if(cB<cA){
4240-
return-1;
4241-
}elseif(cB>cA){
4242-
return1;
4243-
}else{
4244-
return0;
4245-
}
4246-
}else{
4247-
if(cA<cB){
4248-
return-1;
4249-
}elseif(cA>cB){
4250-
return1;
4251-
}else{
4252-
return0;
4253-
}
4254-
}
4268+
returncompare(_this.utils,orderBy,index,a,b);
42554269
});
42564270
});
42574271
}

‎dist/angular-data.min.js‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name":"angular-data",
33
"description":"Data store for Angular.js.",
4-
"version":"1.4.0",
4+
"version":"1.4.1",
55
"homepage":"http://angular-data.pseudobry.com",
66
"repository": {
77
"type":"git",

‎src/datastore/index.js‎

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,42 @@ function lifecycleNoop(resourceName, attrs, cb) {
44
cb(null,attrs);
55
}
66

7+
functioncompare(DSUtils,orderBy,index,a,b){
8+
vardef=orderBy[index];
9+
varcA=a[def[0]],cB=b[def[0]];
10+
if(DSUtils.isString(cA)){
11+
cA=DSUtils.upperCase(cA);
12+
}
13+
if(DSUtils.isString(cB)){
14+
cB=DSUtils.upperCase(cB);
15+
}
16+
if(def[1]==='DESC'){
17+
if(cB<cA){
18+
return-1;
19+
}elseif(cB>cA){
20+
return1;
21+
}else{
22+
if(index<orderBy.length-1){
23+
returncompare(DSUtils,orderBy,index+1,a,b);
24+
}else{
25+
return0;
26+
}
27+
}
28+
}else{
29+
if(cA<cB){
30+
return-1;
31+
}elseif(cA>cB){
32+
return1;
33+
}else{
34+
if(index<orderBy.length-1){
35+
returncompare(DSUtils,orderBy,index+1,a,b);
36+
}else{
37+
return0;
38+
}
39+
}
40+
}
41+
}
42+
743
functionDefaults(){
844
}
945

@@ -129,9 +165,10 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
129165

130166
// Apply 'orderBy'
131167
if(orderBy){
132-
angular.forEach(orderBy,function(def){
168+
varindex=0;
169+
angular.forEach(orderBy,function(def,i){
133170
if(_this.utils.isString(def)){
134-
def=[def,'ASC'];
171+
orderBy[i]=[def,'ASC'];
135172
}elseif(!_this.utils.isArray(def)){
136173
thrownew_this.errors.IllegalArgumentError('DS.filter(resourceName[, params][, options]): '+JSON.stringify(def)+': Must be a string or an array!',{
137174
params:{
@@ -143,30 +180,7 @@ Defaults.prototype.defaultFilter = function (collection, resourceName, params, o
143180
});
144181
}
145182
filtered=_this.utils.sort(filtered,function(a,b){
146-
varcA=a[def[0]],cB=b[def[0]];
147-
if(_this.utils.isString(cA)){
148-
cA=_this.utils.upperCase(cA);
149-
}
150-
if(_this.utils.isString(cB)){
151-
cB=_this.utils.upperCase(cB);
152-
}
153-
if(def[1]==='DESC'){
154-
if(cB<cA){
155-
return-1;
156-
}elseif(cB>cA){
157-
return1;
158-
}else{
159-
return0;
160-
}
161-
}else{
162-
if(cA<cB){
163-
return-1;
164-
}elseif(cA>cB){
165-
return1;
166-
}else{
167-
return0;
168-
}
169-
}
183+
returncompare(_this.utils,orderBy,index,a,b);
170184
});
171185
});
172186
}

‎test/integration/datastore/sync_methods/filter.test.js‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,69 @@ describe('DS.filter(resourceName[, params][, options])', function () {
364364

365365
assert.deepEqual(angular.toJson(DS.filter('Comment',params)),angular.toJson([p1,p2]),'should keep p1 and p2');
366366
});
367+
it('should work with multiple orderBy',function(){
368+
varitems=[
369+
{id:1,test:1,test2:1},
370+
{id:2,test:2,test2:2},
371+
{id:3,test:3,test2:3},
372+
{id:4,test:1,test2:4},
373+
{id:5,test:2,test2:5},
374+
{id:6,test:3,test2:6},
375+
{id:7,test:1,test2:1},
376+
{id:8,test:2,test2:2},
377+
{id:9,test:3,test2:3},
378+
{id:10,test:1,test2:4},
379+
{id:11,test:2,test2:5},
380+
{id:12,test:3,test2:6}
381+
];
382+
varparams={};
383+
384+
Post.inject(items);
385+
386+
params.orderBy=[
387+
['test','DESC'],
388+
['test2','ASC'],
389+
['id','ASC']
390+
];
391+
392+
varposts=Post.filter(params);
393+
394+
assert.deepEqual(JSON.stringify(posts),JSON.stringify([
395+
items[2],
396+
items[8],
397+
items[5],
398+
items[11],
399+
items[1],
400+
items[7],
401+
items[4],
402+
items[10],
403+
items[0],
404+
items[6],
405+
items[3],
406+
items[9]
407+
]));
408+
409+
params.orderBy=[
410+
['test','DESC'],
411+
['test2','ASC'],
412+
['id','DESC']
413+
];
414+
415+
posts=Post.filter(params);
416+
417+
assert.deepEqual(JSON.stringify(posts),JSON.stringify([
418+
items[8],
419+
items[2],
420+
items[11],
421+
items[5],
422+
items[7],
423+
items[1],
424+
items[10],
425+
items[4],
426+
items[6],
427+
items[0],
428+
items[9],
429+
items[3]
430+
]));
431+
});
367432
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp