Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- filterProducts(currentFilters) {
- var products = this.productsFiltering;
- if (currentFilters.gradeArray.length > 0) {
- products = products.filter(p => currentFilters.gradeArray.indexOf(p.grade) > -1);
- }
- if (currentFilters.levelArray.length > 0) {
- products = products.filter(p => currentFilters.levelArray.indexOf(p.level) > -1);
- }
- if (currentFilters.genre !== "all") {
- products = products.filter(p => p.genreId === +currentFilters.genre);
- }
- if (currentFilters.subgenre !== "all") {
- products = products.filter(p => p.subGenreId === +currentFilters.subgenre);
- }
- if (currentFilters.set !== "all") {
- products = products.filter(p => p.setId === +currentFilters.set);
- }
- if (currentFilters.keyword !== "all") {
- products = products.filter(p => p.keywords.includes(currentFilters.keyword));
- }
- products = products.filter(p =>
- p.title != null && p.title.toLowerCase().includes(currentFilters.search) ||
- p.summary != null && p.summary.toLowerCase().includes(currentFilters.search) ||
- p.messages != null && p.messages.toLowerCase().includes(currentFilters.search) ||
- p.illustrator != null && p.illustrator.toLowerCase().includes(currentFilters.search) ||
- p.author != null && p.author.toLowerCase().includes(currentFilters.search) ||
- p.bookNumber != null && p.bookNumber.toLowerCase().includes(currentFilters.search) ||
- p.keywords.includes(currentFilters.search) ||
- p.genre != null && p.genre.name.toLowerCase().includes(currentFilters.search) ||
- p.subGenre != null && p.subGenre.name.toLowerCase().includes(currentFilters.search)
- );
- this.products = products;
- if (currentFilters.type === "grade") {
- this.filterLevels();
- this.filterSets();
- this.filterGenres();
- this.filterSubgenres();
- this.filterKeywords();
- }
- if (currentFilters.type === 'level') {
- this.filterGrades();
- this.filterSets();
- this.filterGenres();
- this.filterSubgenres();
- this.filterKeywords();
- }
- if (currentFilters.type === 'set') {
- this.filterGrades();
- this.filterLevels();
- this.filterGenres();
- this.filterSubgenres();
- this.filterKeywords();
- }
- if (currentFilters.type === 'genre') {
- this.filterGrades();
- this.filterLevels();
- this.filterSets();
- this.filterSubgenres();
- this.filterKeywords();
- }
- if (currentFilters.type === 'subGenre') {
- this.filterGrades();
- this.filterLevels();
- this.filterSets();
- this.filterGenres();
- this.filterKeywords();
- }
- if (currentFilters.type === 'keyword') {
- this.filterGrades();
- this.filterLevels();
- this.filterSets();
- this.filterGenres();
- this.filterSubgenres();
- }
- if (currentFilters.type === '') {
- this.filterGrades();
- this.filterLevels();
- this.filterSets();
- this.filterGenres();
- this.filterSubgenres();
- this.filterKeywords();
- }
- sessionStorage.setItem("filter", JSON.stringify(currentFilters));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement