chore(examples): extend inbox example code to include sorting
This commit is contained in:
parent
c0b7bae9d3
commit
ea661fa10f
@ -11,7 +11,7 @@ import {
|
|||||||
import * as db from './data';
|
import * as db from './data';
|
||||||
import {ObservableWrapper, PromiseWrapper, Promise} from 'angular2/src/core/facade/async';
|
import {ObservableWrapper, PromiseWrapper, Promise} from 'angular2/src/core/facade/async';
|
||||||
import {ListWrapper} from 'angular2/src/core/facade/collection';
|
import {ListWrapper} from 'angular2/src/core/facade/collection';
|
||||||
import {isPresent} from 'angular2/src/core/facade/lang';
|
import {isPresent, DateWrapper} from 'angular2/src/core/facade/lang';
|
||||||
|
|
||||||
class InboxRecord {
|
class InboxRecord {
|
||||||
id: string = '';
|
id: string = '';
|
||||||
@ -20,7 +20,7 @@ class InboxRecord {
|
|||||||
email: string = '';
|
email: string = '';
|
||||||
firstName: string = '';
|
firstName: string = '';
|
||||||
lastName: string = '';
|
lastName: string = '';
|
||||||
date: string = '';
|
date: string;
|
||||||
draft: boolean = false;
|
draft: boolean = false;
|
||||||
|
|
||||||
constructor(data: {
|
constructor(data: {
|
||||||
@ -108,10 +108,21 @@ class InboxCmp {
|
|||||||
items: InboxRecord[] = [];
|
items: InboxRecord[] = [];
|
||||||
ready: boolean = false;
|
ready: boolean = false;
|
||||||
|
|
||||||
constructor(public router: Router, db: DbService) {
|
constructor(public router: Router, db: DbService, params: RouteParams) {
|
||||||
|
var sortType = params.get('sort');
|
||||||
|
var sortEmailsByDate = isPresent(sortType) && sortType == "date";
|
||||||
|
|
||||||
PromiseWrapper.then(db.emails(), emails => {
|
PromiseWrapper.then(db.emails(), emails => {
|
||||||
this.ready = true;
|
this.ready = true;
|
||||||
this.items = emails.map(data => new InboxRecord(data));
|
this.items = emails.map(data => new InboxRecord(data));
|
||||||
|
|
||||||
|
if (sortEmailsByDate) {
|
||||||
|
ListWrapper.sort(this.items,
|
||||||
|
(a, b) => DateWrapper.toMillis(DateWrapper.fromISOString(a.date)) <
|
||||||
|
DateWrapper.toMillis(DateWrapper.fromISOString(b.date)) ?
|
||||||
|
-1 :
|
||||||
|
1);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,4 +15,10 @@
|
|||||||
<span class="btn medium primary">
|
<span class="btn medium primary">
|
||||||
<a [router-link]="record.draft ? ['../Drafts'] : ['../Inbox']" class="back-button">Back</a>
|
<a [router-link]="record.draft ? ['../Drafts'] : ['../Inbox']" class="back-button">Back</a>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
<a [router-link]="['../Inbox', { sort: 'date'} ]" class="sort-button">
|
||||||
|
View Latest Messages
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user