fuse-angular/src/app/main/apps/mail/mail-list/mail-list.component.ts
Sercan Yemen b9569a5ba8 mail..
2017-07-19 17:58:36 +03:00

77 lines
2.1 KiB
TypeScript

import { Component, Input, OnInit } from '@angular/core';
import { Mail } from '../mail.model';
import { ActivatedRoute } from '@angular/router';
import { MailService } from '../mail.service';
import { Location } from '@angular/common';
@Component({
selector : 'fuse-mail-list',
templateUrl: './mail-list.component.html',
styleUrls : ['./mail-list.component.scss']
})
export class MailListComponent implements OnInit
{
mails: Mail[];
@Input('selectedMail') public selectedMail: Mail;
search: string;
constructor(
private route: ActivatedRoute,
private mailService: MailService,
private location: Location
)
{
}
ngOnInit()
{
// Get mails for the first time
this.mails = this.mailService.mails;
// Subscribe to update mails on changes
this.mailService.onMailsUpdated
.subscribe(mails => {
this.mails = mails;
});
this.mailService.onSelectedMailUpdated
.subscribe(selectedMail => {
if ( !selectedMail )
{
const labelHandle = this.route.snapshot.params.labelHandle,
folderHandle = this.route.snapshot.params.folderHandle;
if ( labelHandle )
{
this.location.go('apps/mail/label/' + labelHandle);
}
else
{
this.location.go('apps/mail/' + folderHandle);
}
}
});
}
selectMail(mailId)
{
const labelHandle = this.route.snapshot.params.labelHandle,
folderHandle = this.route.snapshot.params.folderHandle;
if ( labelHandle )
{
this.location.go('apps/mail/label/' + labelHandle + '/' + mailId);
}
else
{
this.location.go('apps/mail/' + folderHandle + '/' + mailId);
}
// Set selected mail
this.mailService.setSelectedMail(mailId);
}
}