mirror of
https://github.com/richard-loafle/fuse-angular.git
synced 2025-01-10 04:25:08 +00:00
Filtering updated for mail, todo app.
This commit is contained in:
parent
2d459864f1
commit
1f8b1a3f27
|
@ -3,6 +3,11 @@ export class FuseUtils
|
||||||
|
|
||||||
public static filterArrayByString(mainArr, searchText)
|
public static filterArrayByString(mainArr, searchText)
|
||||||
{
|
{
|
||||||
|
if ( searchText === '' )
|
||||||
|
{
|
||||||
|
return mainArr;
|
||||||
|
}
|
||||||
|
|
||||||
searchText = searchText.toLowerCase();
|
searchText = searchText.toLowerCase();
|
||||||
|
|
||||||
return mainArr.filter(itemObj => {
|
return mainArr.filter(itemObj => {
|
||||||
|
|
|
@ -16,15 +16,12 @@ export class MailComponent implements OnInit, OnDestroy
|
||||||
folders: any[];
|
folders: any[];
|
||||||
filters: any[];
|
filters: any[];
|
||||||
labels: any[];
|
labels: any[];
|
||||||
mails: any[];
|
|
||||||
searchInput: FormControl;
|
searchInput: FormControl;
|
||||||
|
|
||||||
onSelectedMailsChanged: Subscription;
|
onSelectedMailsChanged: Subscription;
|
||||||
onFoldersChanged: Subscription;
|
onFoldersChanged: Subscription;
|
||||||
onFiltersChanged: Subscription;
|
onFiltersChanged: Subscription;
|
||||||
onLabelsChanged: Subscription;
|
onLabelsChanged: Subscription;
|
||||||
onMailsChanged: Subscription;
|
|
||||||
|
|
||||||
|
|
||||||
constructor(private mailService: MailService)
|
constructor(private mailService: MailService)
|
||||||
{
|
{
|
||||||
|
@ -33,12 +30,6 @@ export class MailComponent implements OnInit, OnDestroy
|
||||||
|
|
||||||
ngOnInit()
|
ngOnInit()
|
||||||
{
|
{
|
||||||
// Subscribe to update mails on changes
|
|
||||||
this.onMailsChanged =
|
|
||||||
this.mailService.onMailsChanged
|
|
||||||
.subscribe(mails => {
|
|
||||||
this.mails = mails;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.onSelectedMailsChanged =
|
this.onSelectedMailsChanged =
|
||||||
this.mailService.onSelectedMailsChanged
|
this.mailService.onSelectedMailsChanged
|
||||||
|
@ -73,15 +64,7 @@ export class MailComponent implements OnInit, OnDestroy
|
||||||
.debounceTime(300)
|
.debounceTime(300)
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.subscribe(searchText => {
|
.subscribe(searchText => {
|
||||||
if ( searchText !== '' )
|
this.mailService.onSearchTextChanged.next(searchText);
|
||||||
{
|
|
||||||
const newArr = FuseUtils.filterArrayByString(this.mails, searchText);
|
|
||||||
this.mailService.onMailsChanged.next(newArr);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.mailService.getMails();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { Observable } from 'rxjs/Observable';
|
||||||
import { Http } from '@angular/http';
|
import { Http } from '@angular/http';
|
||||||
import { Mail } from './mail.model';
|
import { Mail } from './mail.model';
|
||||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||||
|
import { FuseUtils } from "app/core/fuseUtils";
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class MailService implements Resolve<any>
|
export class MailService implements Resolve<any>
|
||||||
|
@ -11,6 +12,7 @@ export class MailService implements Resolve<any>
|
||||||
mails: Mail[];
|
mails: Mail[];
|
||||||
selectedMails: Mail[];
|
selectedMails: Mail[];
|
||||||
currentMail: Mail;
|
currentMail: Mail;
|
||||||
|
searchText = '';
|
||||||
|
|
||||||
folders: any[];
|
folders: any[];
|
||||||
filters: any[];
|
filters: any[];
|
||||||
|
@ -24,10 +26,9 @@ export class MailService implements Resolve<any>
|
||||||
onFoldersChanged: BehaviorSubject<any> = new BehaviorSubject([]);
|
onFoldersChanged: BehaviorSubject<any> = new BehaviorSubject([]);
|
||||||
onFiltersChanged: BehaviorSubject<any> = new BehaviorSubject([]);
|
onFiltersChanged: BehaviorSubject<any> = new BehaviorSubject([]);
|
||||||
onLabelsChanged: BehaviorSubject<any> = new BehaviorSubject([]);
|
onLabelsChanged: BehaviorSubject<any> = new BehaviorSubject([]);
|
||||||
|
onSearchTextChanged: BehaviorSubject<any> = new BehaviorSubject('');
|
||||||
|
|
||||||
constructor(
|
constructor(private http: Http)
|
||||||
private http: Http
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
this.selectedMails = [];
|
this.selectedMails = [];
|
||||||
}
|
}
|
||||||
|
@ -59,6 +60,19 @@ export class MailService implements Resolve<any>
|
||||||
this.setCurrentMail(null);
|
this.setCurrentMail(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.onSearchTextChanged.subscribe(searchText => {
|
||||||
|
if ( searchText !== '' )
|
||||||
|
{
|
||||||
|
this.searchText = searchText;
|
||||||
|
this.getMails();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.searchText = searchText;
|
||||||
|
this.getMails();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
},
|
},
|
||||||
reject
|
reject
|
||||||
|
@ -154,6 +168,8 @@ export class MailService implements Resolve<any>
|
||||||
return new Mail(mail);
|
return new Mail(mail);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.mails = FuseUtils.filterArrayByString(this.mails, this.searchText);
|
||||||
|
|
||||||
this.onMailsChanged.next(this.mails);
|
this.onMailsChanged.next(this.mails);
|
||||||
|
|
||||||
resolve(this.mails);
|
resolve(this.mails);
|
||||||
|
@ -179,6 +195,8 @@ export class MailService implements Resolve<any>
|
||||||
return new Mail(mail);
|
return new Mail(mail);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.mails = FuseUtils.filterArrayByString(this.mails, this.searchText);
|
||||||
|
|
||||||
this.onMailsChanged.next(this.mails);
|
this.onMailsChanged.next(this.mails);
|
||||||
|
|
||||||
resolve(this.mails);
|
resolve(this.mails);
|
||||||
|
@ -207,6 +225,8 @@ export class MailService implements Resolve<any>
|
||||||
return new Mail(mail);
|
return new Mail(mail);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.mails = FuseUtils.filterArrayByString(this.mails, this.searchText);
|
||||||
|
|
||||||
this.onMailsChanged.next(this.mails);
|
this.onMailsChanged.next(this.mails);
|
||||||
|
|
||||||
resolve(this.mails);
|
resolve(this.mails);
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { Subscription } from 'rxjs/Subscription';
|
||||||
import { TodoService } from './todo.service';
|
import { TodoService } from './todo.service';
|
||||||
import { FormControl } from '@angular/forms';
|
import { FormControl } from '@angular/forms';
|
||||||
import { Todo } from './todo.model';
|
import { Todo } from './todo.model';
|
||||||
import { FuseUtils } from '../../../core/fuseUtils';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector : 'fuse-todo',
|
selector : 'fuse-todo',
|
||||||
|
@ -14,12 +13,10 @@ export class TodoComponent implements OnInit, OnDestroy
|
||||||
{
|
{
|
||||||
hasSelectedTodos: boolean;
|
hasSelectedTodos: boolean;
|
||||||
isIndeterminate: boolean;
|
isIndeterminate: boolean;
|
||||||
todos: Todo[];
|
|
||||||
filters: any[];
|
filters: any[];
|
||||||
tags: any[];
|
tags: any[];
|
||||||
searchInput: FormControl;
|
searchInput: FormControl;
|
||||||
|
|
||||||
onTodosChanged: Subscription;
|
|
||||||
onSelectedTodosChanged: Subscription;
|
onSelectedTodosChanged: Subscription;
|
||||||
onFiltersChanged: Subscription;
|
onFiltersChanged: Subscription;
|
||||||
onTagsChanged: Subscription;
|
onTagsChanged: Subscription;
|
||||||
|
@ -31,12 +28,6 @@ export class TodoComponent implements OnInit, OnDestroy
|
||||||
|
|
||||||
ngOnInit()
|
ngOnInit()
|
||||||
{
|
{
|
||||||
// Subscribe to update todos on changes
|
|
||||||
this.onTodosChanged =
|
|
||||||
this.todoService.onTodosChanged
|
|
||||||
.subscribe(todos => {
|
|
||||||
this.todos = todos;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.onSelectedTodosChanged =
|
this.onSelectedTodosChanged =
|
||||||
this.todoService.onSelectedTodosChanged
|
this.todoService.onSelectedTodosChanged
|
||||||
|
@ -64,15 +55,7 @@ export class TodoComponent implements OnInit, OnDestroy
|
||||||
.debounceTime(300)
|
.debounceTime(300)
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.subscribe(searchText => {
|
.subscribe(searchText => {
|
||||||
if ( searchText !== '' )
|
this.todoService.onSearchTextChanged.next(searchText);
|
||||||
{
|
|
||||||
const newArr = FuseUtils.filterArrayByString(this.todos, searchText);
|
|
||||||
this.todoService.onTodosChanged.next(newArr);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this.todoService.getTodos();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ import { Observable } from 'rxjs/Observable';
|
||||||
import { Http } from '@angular/http';
|
import { Http } from '@angular/http';
|
||||||
import { Todo } from './todo.model';
|
import { Todo } from './todo.model';
|
||||||
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
||||||
|
import { Subscription } from 'rxjs/Subscription';
|
||||||
|
import { FuseUtils } from '../../../core/fuseUtils';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TodoService implements Resolve<any>
|
export class TodoService implements Resolve<any>
|
||||||
|
@ -11,6 +13,7 @@ export class TodoService implements Resolve<any>
|
||||||
todos: Todo[];
|
todos: Todo[];
|
||||||
selectedTodos: Todo[];
|
selectedTodos: Todo[];
|
||||||
currentTodo: Todo;
|
currentTodo: Todo;
|
||||||
|
searchText = '';
|
||||||
|
|
||||||
filters: any[];
|
filters: any[];
|
||||||
tags: any[];
|
tags: any[];
|
||||||
|
@ -22,6 +25,7 @@ export class TodoService implements Resolve<any>
|
||||||
|
|
||||||
onFiltersChanged: BehaviorSubject<any> = new BehaviorSubject([]);
|
onFiltersChanged: BehaviorSubject<any> = new BehaviorSubject([]);
|
||||||
onTagsChanged: BehaviorSubject<any> = new BehaviorSubject([]);
|
onTagsChanged: BehaviorSubject<any> = new BehaviorSubject([]);
|
||||||
|
onSearchTextChanged: BehaviorSubject<any> = new BehaviorSubject('');
|
||||||
|
|
||||||
constructor(private http: Http)
|
constructor(private http: Http)
|
||||||
{
|
{
|
||||||
|
@ -55,6 +59,18 @@ export class TodoService implements Resolve<any>
|
||||||
this.setCurrentTodo(null);
|
this.setCurrentTodo(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.onSearchTextChanged.subscribe(searchText => {
|
||||||
|
if ( searchText !== '' )
|
||||||
|
{
|
||||||
|
this.searchText = searchText;
|
||||||
|
this.getTodos();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.searchText = searchText;
|
||||||
|
this.getTodos();
|
||||||
|
}
|
||||||
|
});
|
||||||
resolve();
|
resolve();
|
||||||
},
|
},
|
||||||
reject
|
reject
|
||||||
|
@ -129,6 +145,8 @@ export class TodoService implements Resolve<any>
|
||||||
return new Todo(todo);
|
return new Todo(todo);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.todos = FuseUtils.filterArrayByString(this.todos, this.searchText);
|
||||||
|
|
||||||
this.onTodosChanged.next(this.todos);
|
this.onTodosChanged.next(this.todos);
|
||||||
|
|
||||||
resolve(this.todos);
|
resolve(this.todos);
|
||||||
|
@ -160,6 +178,8 @@ export class TodoService implements Resolve<any>
|
||||||
return new Todo(todo);
|
return new Todo(todo);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.todos = FuseUtils.filterArrayByString(this.todos, this.searchText);
|
||||||
|
|
||||||
this.onTodosChanged.next(this.todos);
|
this.onTodosChanged.next(this.todos);
|
||||||
|
|
||||||
resolve(this.todos);
|
resolve(this.todos);
|
||||||
|
@ -188,6 +208,8 @@ export class TodoService implements Resolve<any>
|
||||||
return new Todo(todo);
|
return new Todo(todo);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.todos = FuseUtils.filterArrayByString(this.todos, this.searchText);
|
||||||
|
|
||||||
this.onTodosChanged.next(this.todos);
|
this.onTodosChanged.next(this.todos);
|
||||||
|
|
||||||
resolve(this.todos);
|
resolve(this.todos);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user