author | Chloe Laisne <chloe.laisne@gmail.com> |
Mon, 17 Oct 2016 14:50:30 +0530 | |
changeset 344 | 70451a4dc9ae |
parent 204 | dd969e178944 |
child 392 | 4fbe94af93e8 |
permissions | -rw-r--r-- |
42
7d091abf82fd
add application adapter to simulate REST, using fixtures
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
1 |
import Ember from 'ember'; |
7d091abf82fd
add application adapter to simulate REST, using fixtures
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
2 |
|
7d091abf82fd
add application adapter to simulate REST, using fixtures
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
3 |
export default Ember.Route.extend({ |
194
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
4 |
|
344 | 5 |
page: 1, |
6 |
limit: 10, |
|
7 |
||
8 |
documents: [], |
|
9 |
model: Ember.observer('page', function() { |
|
10 |
var self = this; |
|
11 |
var promise = this.store.query('document', { |
|
12 |
page: this.get('page'), |
|
13 |
perpage: this.get('limit') |
|
14 |
}); |
|
15 |
promise.then(function(value) { |
|
16 |
if(self.controller) { |
|
17 |
self.controller.set('page', self.get('page')); |
|
18 |
self.controller.set('documents', self.get('documents')); |
|
19 |
} |
|
20 |
self.set('documents', value); |
|
21 |
}); |
|
22 |
return promise; |
|
23 |
}), |
|
194
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
24 |
|
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
25 |
serializeQueryParam: function(value, urlKey) { |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
26 |
if (urlKey === 'date') { |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
27 |
return value; |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
28 |
} |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
29 |
return '' + value; |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
30 |
}, |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
31 |
|
344 | 32 |
setupController: function(controller) { |
33 |
this._super(...arguments); |
|
34 |
controller.set('page', this.get('page')); |
|
35 |
controller.set('limit', this.get('limit')); |
|
36 |
controller.set('documents', this.get('documents')); |
|
37 |
}, |
|
38 |
||
194
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
39 |
deserializeQueryParam: function(value, urlKey) { |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
40 |
if (urlKey === 'date') { |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
201
diff
changeset
|
41 |
var array = []; |
194
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
42 |
for (var i = 0; i < value.length; i++) { |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
201
diff
changeset
|
43 |
array.push(value[i]); |
194
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
44 |
} |
203
2ee21302dc47
Set application date property and filter date property observer
Chloe Laisne <chloe.laisne@gmail.com>
parents:
201
diff
changeset
|
45 |
return array; |
194
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
46 |
} |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
47 |
return value; |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
48 |
}, |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
49 |
|
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
50 |
actions: { |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
51 |
|
344 | 52 |
setPageQueryparams: function(type) { |
53 |
var page = this.get('page'); |
|
54 |
if(type === 'previous') { |
|
55 |
page = page - 1; |
|
56 |
} else if(type === 'next') { |
|
57 |
page = page + 1; |
|
58 |
} |
|
59 |
this.propertyWillChange('page'); |
|
60 |
this.set('page', page); |
|
61 |
this.propertyDidChange('page'); |
|
62 |
}, |
|
63 |
||
194
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
64 |
willTransition: function() { |
199
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
65 |
// Prevent navigation from removing query parameters |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
66 |
var _this = this, |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
67 |
queryParams = {}; |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
68 |
this.controller.get('queryParams').map(function(parameter){ |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
69 |
if(typeof parameter === 'object') { |
204
dd969e178944
Fix linting, remove logs and dead code
Chloe Laisne <chloe.laisne@gmail.com>
parents:
203
diff
changeset
|
70 |
Object.keys(parameter).forEach(function(value) { |
199
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
71 |
queryParams[value] = _this.controller.get(value); |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
72 |
}); |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
73 |
} else { |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
74 |
queryParams[parameter] = _this.controller.get(parameter); |
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
75 |
} |
194
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
76 |
}); |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
77 |
this.transitionTo({ queryParams: queryParams }); |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
78 |
}, |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
79 |
|
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
80 |
didTransition: function() { |
199
b7c691c6179d
Set location filter label
Chloe Laisne <chloe.laisne@gmail.com>
parents:
194
diff
changeset
|
81 |
// Append body classname depending on the route |
194
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
82 |
Ember.$('body').removeClass((this.controller.get('currentPath') || '').replace(/\//g, '-').dasherize()); |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
83 |
Ember.run.once(this, function() { |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
84 |
Ember.$('body').addClass((this.controller.get('currentPath') ||'').replace(/\//g, '-').dasherize()); |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
85 |
}); |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
86 |
} |
02c6aa9a99d7
Linting errors / Parenthesis missing / Body classname
Chloe Laisne <chloe.laisne@gmail.com>
parents:
92
diff
changeset
|
87 |
|
81
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
74
diff
changeset
|
88 |
} |
848e4a5ad4d9
update date params to be an array of date instead of a string
nowmad@nowmads-macbook-pro.local
parents:
74
diff
changeset
|
89 |
|
42
7d091abf82fd
add application adapter to simulate REST, using fixtures
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
90 |
}); |