
committed by
Miško Hevery

parent
ef9e40e82b
commit
14f0e9ada8
@ -9,9 +9,9 @@ import {
|
||||
RouteParams
|
||||
} from 'angular2/router';
|
||||
import * as db from './data';
|
||||
import {ObservableWrapper, PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {isPresent, DateWrapper} from 'angular2/src/facade/lang';
|
||||
import {PromiseCompleter} from 'angular2/src/facade/promise';
|
||||
|
||||
class InboxRecord {
|
||||
id: string = '';
|
||||
@ -60,31 +60,31 @@ class InboxRecord {
|
||||
@Injectable()
|
||||
class DbService {
|
||||
getData(): Promise<any[]> {
|
||||
var p = PromiseWrapper.completer();
|
||||
var p = new PromiseCompleter<any[]>();
|
||||
p.resolve(db.data);
|
||||
return p.promise;
|
||||
}
|
||||
|
||||
drafts(): Promise<any[]> {
|
||||
return PromiseWrapper.then(this.getData(), (data: any[]) => {
|
||||
return data.filter(record => isPresent(record['draft']) && record['draft'] == true);
|
||||
});
|
||||
return this.getData().then(
|
||||
(data: any[]): any[] =>
|
||||
data.filter(record => isPresent(record['draft']) && record['draft'] == true));
|
||||
}
|
||||
|
||||
emails(): Promise<any[]> {
|
||||
return PromiseWrapper.then(this.getData(), (data: any[]) => {
|
||||
return data.filter(record => !isPresent(record['draft']));
|
||||
});
|
||||
return this.getData().then((data: any[]): any[] =>
|
||||
data.filter(record => !isPresent(record['draft'])));
|
||||
}
|
||||
|
||||
email(id): Promise<any> {
|
||||
return PromiseWrapper.then(this.getData(), (data) => {
|
||||
return PromiseWrapper.then(this.getData(), (data: any[]) => {
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var entry = data[i];
|
||||
if (entry['id'] == id) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -109,16 +109,16 @@ class InboxCmp {
|
||||
var sortType = params.get('sort');
|
||||
var sortEmailsByDate = isPresent(sortType) && sortType == "date";
|
||||
|
||||
PromiseWrapper.then(db.emails(), emails => {
|
||||
PromiseWrapper.then(db.emails(), (emails: any[]) => {
|
||||
this.ready = true;
|
||||
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);
|
||||
this.items.sort((a: InboxRecord, b: InboxRecord) =>
|
||||
DateWrapper.toMillis(DateWrapper.fromISOString(a.date)) <
|
||||
DateWrapper.toMillis(DateWrapper.fromISOString(b.date)) ?
|
||||
-1 :
|
||||
1);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -131,7 +131,7 @@ class DraftsCmp {
|
||||
ready: boolean = false;
|
||||
|
||||
constructor(public router: Router, db: DbService) {
|
||||
PromiseWrapper.then(db.drafts(), (drafts) => {
|
||||
PromiseWrapper.then(db.drafts(), (drafts: any[]) => {
|
||||
this.ready = true;
|
||||
this.items = drafts.map(data => new InboxRecord(data));
|
||||
});
|
||||
|
Reference in New Issue
Block a user