Advertisement
Guest User

Untitled

a guest
Nov 17th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     filterProducts(currentFilters) {
  2.         var products = this.productsFiltering;
  3.  
  4.         if (currentFilters.gradeArray.length > 0) {
  5.             products = products.filter(p => currentFilters.gradeArray.indexOf(p.grade) > -1);
  6.         }
  7.  
  8.         if (currentFilters.levelArray.length > 0) {
  9.             products = products.filter(p => currentFilters.levelArray.indexOf(p.level) > -1);
  10.         }
  11.  
  12.         if (currentFilters.genre !== "all") {
  13.             products = products.filter(p => p.genreId === +currentFilters.genre);
  14.         }
  15.  
  16.         if (currentFilters.subgenre !== "all") {
  17.             products = products.filter(p => p.subGenreId === +currentFilters.subgenre);
  18.         }
  19.  
  20.         if (currentFilters.set !== "all") {
  21.             products = products.filter(p => p.setId === +currentFilters.set);
  22.         }
  23.  
  24.         if (currentFilters.keyword !== "all") {
  25.             products = products.filter(p => p.keywords.includes(currentFilters.keyword));
  26.         }
  27.  
  28.         products = products.filter(p =>
  29.             p.title != null && p.title.toLowerCase().includes(currentFilters.search) ||
  30.             p.summary != null && p.summary.toLowerCase().includes(currentFilters.search) ||
  31.             p.messages != null && p.messages.toLowerCase().includes(currentFilters.search) ||
  32.             p.illustrator != null && p.illustrator.toLowerCase().includes(currentFilters.search) ||
  33.             p.author != null && p.author.toLowerCase().includes(currentFilters.search) ||
  34.             p.bookNumber != null && p.bookNumber.toLowerCase().includes(currentFilters.search) ||
  35.             p.keywords.includes(currentFilters.search) ||
  36.             p.genre != null && p.genre.name.toLowerCase().includes(currentFilters.search) ||
  37.             p.subGenre != null && p.subGenre.name.toLowerCase().includes(currentFilters.search)
  38.         );
  39.  
  40.         this.products = products;
  41.  
  42.         if (currentFilters.type === "grade") {
  43.  
  44.             this.filterLevels();
  45.             this.filterSets();
  46.             this.filterGenres();
  47.             this.filterSubgenres();
  48.             this.filterKeywords();
  49.         }
  50.  
  51.         if (currentFilters.type === 'level') {
  52.  
  53.             this.filterGrades();
  54.             this.filterSets();
  55.             this.filterGenres();
  56.             this.filterSubgenres();
  57.             this.filterKeywords();
  58.         }
  59.  
  60.         if (currentFilters.type === 'set') {
  61.  
  62.             this.filterGrades();
  63.             this.filterLevels();
  64.             this.filterGenres();
  65.             this.filterSubgenres();
  66.             this.filterKeywords();
  67.         }
  68.  
  69.         if (currentFilters.type === 'genre') {
  70.  
  71.             this.filterGrades();
  72.             this.filterLevels();
  73.             this.filterSets();
  74.             this.filterSubgenres();
  75.             this.filterKeywords();
  76.         }
  77.  
  78.         if (currentFilters.type === 'subGenre') {
  79.  
  80.             this.filterGrades();
  81.             this.filterLevels();
  82.             this.filterSets();
  83.             this.filterGenres();
  84.             this.filterKeywords();
  85.         }
  86.  
  87.         if (currentFilters.type === 'keyword') {
  88.  
  89.             this.filterGrades();
  90.             this.filterLevels();
  91.             this.filterSets();
  92.             this.filterGenres();
  93.             this.filterSubgenres();
  94.         }
  95.  
  96.         if (currentFilters.type === '') {
  97.  
  98.             this.filterGrades();
  99.             this.filterLevels();
  100.             this.filterSets();
  101.             this.filterGenres();
  102.             this.filterSubgenres();
  103.             this.filterKeywords();
  104.         }
  105.         sessionStorage.setItem("filter", JSON.stringify(currentFilters));
  106.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement