2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
2020-05-19 12:08:49 -07:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-06-23 09:47:54 -07:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
2016-09-27 17:12:25 -07:00
|
|
|
|
2016-04-28 17:50:03 -07:00
|
|
|
import {Component, Injectable} from '@angular/core';
|
2016-07-27 09:54:19 -07:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2016-08-05 09:56:53 -07:00
|
|
|
|
2015-08-12 13:03:28 -07:00
|
|
|
import * as db from './data';
|
2015-07-09 10:25:58 -07:00
|
|
|
|
2016-06-21 23:06:35 -07:00
|
|
|
export class InboxRecord {
|
2015-07-09 10:25:58 -07:00
|
|
|
id: string = '';
|
|
|
|
|
subject: string = '';
|
|
|
|
|
content: string = '';
|
|
|
|
|
email: string = '';
|
|
|
|
|
firstName: string = '';
|
|
|
|
|
lastName: string = '';
|
2015-10-09 16:42:00 -07:00
|
|
|
date: string;
|
2015-07-09 10:25:58 -07:00
|
|
|
draft: boolean = false;
|
|
|
|
|
|
2015-10-06 19:05:09 -07:00
|
|
|
constructor(data: {
|
|
|
|
|
id: string,
|
|
|
|
|
subject: string,
|
|
|
|
|
content: string,
|
|
|
|
|
email: string,
|
|
|
|
|
firstName: string,
|
|
|
|
|
lastName: string,
|
2020-04-13 16:40:21 -07:00
|
|
|
date: string,
|
|
|
|
|
draft?: boolean
|
2015-10-06 19:05:09 -07:00
|
|
|
} = null) {
|
2016-10-23 16:21:18 +02:00
|
|
|
if (data) {
|
2015-07-09 10:25:58 -07:00
|
|
|
this.setData(data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-06 19:05:09 -07:00
|
|
|
setData(record: {
|
|
|
|
|
id: string,
|
|
|
|
|
subject: string,
|
|
|
|
|
content: string,
|
|
|
|
|
email: string,
|
|
|
|
|
firstName: string,
|
|
|
|
|
lastName: string,
|
2020-04-13 16:40:21 -07:00
|
|
|
date: string,
|
|
|
|
|
draft?: boolean
|
2015-10-06 19:05:09 -07:00
|
|
|
}) {
|
2016-10-23 16:21:18 +02:00
|
|
|
this.id = record.id;
|
|
|
|
|
this.subject = record.subject;
|
|
|
|
|
this.content = record.content;
|
|
|
|
|
this.email = record.email;
|
|
|
|
|
this.firstName = record.firstName;
|
|
|
|
|
this.lastName = record.lastName;
|
|
|
|
|
this.date = record.date;
|
|
|
|
|
this.draft = record.draft === true;
|
2015-07-09 10:25:58 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
2016-06-21 23:06:35 -07:00
|
|
|
export class DbService {
|
2016-10-23 16:21:18 +02:00
|
|
|
getData(): Promise<InboxRecord[]> {
|
|
|
|
|
return Promise.resolve(db.data.map((entry: {[key: string]: any}) => new InboxRecord({
|
|
|
|
|
id: entry['id'],
|
|
|
|
|
subject: entry['subject'],
|
|
|
|
|
content: entry['content'],
|
|
|
|
|
email: entry['email'],
|
|
|
|
|
firstName: entry['first-name'],
|
|
|
|
|
lastName: entry['last-name'],
|
|
|
|
|
date: entry['date'],
|
|
|
|
|
draft: entry['draft'],
|
|
|
|
|
})));
|
|
|
|
|
}
|
2015-07-09 10:25:58 -07:00
|
|
|
|
2016-10-23 16:21:18 +02:00
|
|
|
drafts(): Promise<InboxRecord[]> {
|
|
|
|
|
return this.getData().then((data) => data.filter(record => record.draft));
|
2015-07-09 10:25:58 -07:00
|
|
|
}
|
|
|
|
|
|
2016-10-23 16:21:18 +02:00
|
|
|
emails(): Promise<InboxRecord[]> {
|
|
|
|
|
return this.getData().then((data) => data.filter(record => !record.draft));
|
2015-07-09 10:25:58 -07:00
|
|
|
}
|
|
|
|
|
|
2016-10-23 16:21:18 +02:00
|
|
|
email(id: string): Promise<InboxRecord> {
|
|
|
|
|
return this.getData().then((data) => data.find((entry) => entry.id == id));
|
2015-07-09 10:25:58 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-01 14:27:13 +01:00
|
|
|
@Component({selector: 'inbox', templateUrl: './inbox.html'})
|
2016-06-21 23:06:35 -07:00
|
|
|
export class InboxCmp {
|
2019-02-01 14:27:13 +01:00
|
|
|
items: InboxRecord[] = [];
|
2016-06-21 23:06:35 -07:00
|
|
|
private ready: boolean = false;
|
|
|
|
|
|
|
|
|
|
constructor(public router: Router, db: DbService, route: ActivatedRoute) {
|
|
|
|
|
route.params.forEach(p => {
|
2016-10-23 16:21:18 +02:00
|
|
|
const sortEmailsByDate = p['sort'] === 'date';
|
2016-06-21 23:06:35 -07:00
|
|
|
|
2016-10-23 16:21:18 +02:00
|
|
|
db.emails().then((emails) => {
|
2016-06-21 23:06:35 -07:00
|
|
|
this.ready = true;
|
2016-10-23 16:21:18 +02:00
|
|
|
this.items = emails;
|
2016-06-21 23:06:35 -07:00
|
|
|
|
|
|
|
|
if (sortEmailsByDate) {
|
2016-08-05 09:56:53 -07:00
|
|
|
this.items.sort(
|
2016-10-23 16:21:18 +02:00
|
|
|
(a, b) => new Date(a.date).getTime() < new Date(b.date).getTime() ? -1 : 1);
|
2016-06-21 23:06:35 -07:00
|
|
|
}
|
|
|
|
|
});
|
2015-07-09 10:25:58 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-02-01 14:27:13 +01:00
|
|
|
@Component({selector: 'drafts', templateUrl: './drafts.html'})
|
2016-06-21 23:06:35 -07:00
|
|
|
export class DraftsCmp {
|
2019-02-01 14:27:13 +01:00
|
|
|
items: InboxRecord[] = [];
|
2016-06-21 23:06:35 -07:00
|
|
|
private ready: boolean = false;
|
2015-07-09 10:25:58 -07:00
|
|
|
|
2016-06-21 23:06:35 -07:00
|
|
|
constructor(private router: Router, db: DbService) {
|
2016-10-23 16:21:18 +02:00
|
|
|
db.drafts().then((drafts) => {
|
2015-07-09 10:25:58 -07:00
|
|
|
this.ready = true;
|
2016-10-23 16:21:18 +02:00
|
|
|
this.items = drafts;
|
2015-07-09 10:25:58 -07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 23:06:35 -07:00
|
|
|
export const ROUTER_CONFIG = [
|
2016-08-16 13:40:28 -07:00
|
|
|
{path: '', pathMatch: 'full', redirectTo: 'inbox'}, {path: 'inbox', component: InboxCmp},
|
2016-08-05 09:56:53 -07:00
|
|
|
{path: 'drafts', component: DraftsCmp}, {path: 'detail', loadChildren: 'app/inbox-detail.js'}
|
2016-06-21 23:06:35 -07:00
|
|
|
];
|
|
|
|
|
|
2019-02-01 14:27:13 +01:00
|
|
|
@Component({selector: 'inbox-app', templateUrl: './inbox-app.html'})
|
2016-08-05 09:56:53 -07:00
|
|
|
export class InboxApp {
|
|
|
|
|
}
|