2017-07-20 15:12:09 +00:00
|
|
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
2017-07-18 16:34:12 +00:00
|
|
|
import { MailService } from './mail.service';
|
2017-07-20 15:12:09 +00:00
|
|
|
import { Subscription } from 'rxjs/Subscription';
|
2017-07-28 08:29:29 +00:00
|
|
|
import { FormControl } from '@angular/forms';
|
2017-08-16 12:19:26 +00:00
|
|
|
import { Mail } from './mail.model';
|
2017-07-08 16:12:52 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector : 'fuse-mail',
|
|
|
|
templateUrl: './mail.component.html',
|
|
|
|
styleUrls : ['./mail.component.scss']
|
|
|
|
})
|
2017-08-18 11:50:19 +00:00
|
|
|
export class FuseMailComponent implements OnInit, OnDestroy
|
2017-07-08 16:12:52 +00:00
|
|
|
{
|
2017-07-20 15:12:09 +00:00
|
|
|
hasSelectedMails: boolean;
|
|
|
|
isIndeterminate: boolean;
|
|
|
|
folders: any[];
|
2017-07-26 09:43:45 +00:00
|
|
|
filters: any[];
|
2017-07-20 15:12:09 +00:00
|
|
|
labels: any[];
|
2017-07-28 08:29:29 +00:00
|
|
|
searchInput: FormControl;
|
2017-08-16 12:19:26 +00:00
|
|
|
currentMail: Mail;
|
2017-07-20 15:12:09 +00:00
|
|
|
|
|
|
|
onSelectedMailsChanged: Subscription;
|
2017-07-26 09:43:45 +00:00
|
|
|
onFoldersChanged: Subscription;
|
|
|
|
onFiltersChanged: Subscription;
|
|
|
|
onLabelsChanged: Subscription;
|
2017-08-16 12:19:26 +00:00
|
|
|
onCurrentMailChanged: Subscription;
|
2017-07-28 08:29:29 +00:00
|
|
|
|
|
|
|
constructor(private mailService: MailService)
|
2017-07-08 16:12:52 +00:00
|
|
|
{
|
2017-07-28 08:29:29 +00:00
|
|
|
this.searchInput = new FormControl('');
|
2017-07-08 16:12:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit()
|
|
|
|
{
|
2017-07-20 15:12:09 +00:00
|
|
|
this.onSelectedMailsChanged =
|
|
|
|
this.mailService.onSelectedMailsChanged
|
|
|
|
.subscribe(selectedMails => {
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
this.hasSelectedMails = selectedMails.length > 0;
|
|
|
|
this.isIndeterminate = (selectedMails.length !== this.mailService.mails.length && selectedMails.length > 0);
|
|
|
|
}, 0);
|
|
|
|
});
|
2017-07-26 09:43:45 +00:00
|
|
|
|
|
|
|
this.onFoldersChanged =
|
|
|
|
this.mailService.onFoldersChanged
|
|
|
|
.subscribe(folders => {
|
|
|
|
this.folders = this.mailService.folders;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.onFiltersChanged =
|
|
|
|
this.mailService.onFiltersChanged
|
|
|
|
.subscribe(folders => {
|
|
|
|
this.filters = this.mailService.filters;
|
|
|
|
});
|
|
|
|
|
|
|
|
this.onLabelsChanged =
|
|
|
|
this.mailService.onLabelsChanged
|
|
|
|
.subscribe(labels => {
|
|
|
|
this.labels = this.mailService.labels;
|
|
|
|
});
|
2017-07-28 08:29:29 +00:00
|
|
|
|
2017-08-16 12:19:26 +00:00
|
|
|
this.onCurrentMailChanged =
|
|
|
|
this.mailService.onCurrentMailChanged
|
|
|
|
.subscribe(currentMail => {
|
|
|
|
if ( !currentMail )
|
|
|
|
{
|
|
|
|
this.currentMail = null;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.currentMail = currentMail;
|
|
|
|
}
|
|
|
|
});
|
2017-07-28 08:29:29 +00:00
|
|
|
|
2017-08-14 14:09:00 +00:00
|
|
|
/*this.searchInput.valueChanges
|
2017-07-28 08:29:29 +00:00
|
|
|
.debounceTime(300)
|
|
|
|
.distinctUntilChanged()
|
|
|
|
.subscribe(searchText => {
|
2017-07-28 09:26:56 +00:00
|
|
|
this.mailService.onSearchTextChanged.next(searchText);
|
2017-08-14 14:09:00 +00:00
|
|
|
});*/
|
2017-07-20 15:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy()
|
|
|
|
{
|
|
|
|
this.onSelectedMailsChanged.unsubscribe();
|
2017-07-26 09:43:45 +00:00
|
|
|
this.onFoldersChanged.unsubscribe();
|
|
|
|
this.onFiltersChanged.unsubscribe();
|
|
|
|
this.onLabelsChanged.unsubscribe();
|
2017-08-16 12:19:26 +00:00
|
|
|
this.onCurrentMailChanged.unsubscribe();
|
|
|
|
|
2017-07-20 15:12:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
toggleSelectAll()
|
|
|
|
{
|
|
|
|
this.mailService.toggleSelectAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
selectMails(filterParameter?, filterValue?)
|
|
|
|
{
|
|
|
|
this.mailService.selectMails(filterParameter, filterValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
deselectMails()
|
|
|
|
{
|
|
|
|
this.mailService.deselectMails();
|
|
|
|
}
|
2017-07-17 15:11:34 +00:00
|
|
|
|
2017-08-16 12:19:26 +00:00
|
|
|
deSelectCurrentMail()
|
|
|
|
{
|
|
|
|
this.mailService.onCurrentMailChanged.next(null);
|
|
|
|
}
|
|
|
|
|
2017-07-20 15:12:09 +00:00
|
|
|
toggleLabelOnSelectedMails(labelId)
|
|
|
|
{
|
|
|
|
this.mailService.toggleLabelOnSelectedMails(labelId);
|
|
|
|
}
|
|
|
|
|
|
|
|
setFolderOnSelectedMails(folderId)
|
|
|
|
{
|
|
|
|
this.mailService.setFolderOnSelectedMails(folderId);
|
2017-07-16 18:41:01 +00:00
|
|
|
}
|
2017-07-08 16:12:52 +00:00
|
|
|
}
|