Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort filters 157855828 #140

Merged
merged 3 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,13 @@ <h4 title="men casual shirts" class="q">Showing {{productsCount}} of {{productsT
<li data-sortkey=":high">High</li>
</label>
</ul> -->

<form>
<select [(ngModel)]="selectedOption" name="Relevance" (click)="sortFilter()">
<option *ngFor="let opt of options">
{{opt.name}}
</option>
</select>
</form>
</div>
</div>
47 changes: 46 additions & 1 deletion src/app/home/content/content-header/content-header.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Router } from '@angular/router';
import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';

@Component({
Expand All @@ -11,9 +12,19 @@ export class ContentHeaderComponent implements OnInit {
@Input() productsCount;
@Input() productsTotal_count;

options = [
{ name: 'Relevance', value: 0 },
{ name: 'Newest', value: 1 },
{ name: 'A To Z', value: 2 },
{ name: 'Z To A', value: 3 }
]

selectedOption: string;
printedOption: string;

selectedSize = 'COZY';
searchKeyword = ''
constructor() { }
constructor(private routernomal: Router) { }

ngOnInit() {

Expand All @@ -32,4 +43,38 @@ export class ContentHeaderComponent implements OnInit {
return this.selectedSize === 'COMPACT';
}

sortFilter() {
if (this.selectedOption === 'Newest') {
const urlTree = this.routernomal.createUrlTree([], {
queryParams: { 'q[s]': 'updated_at+asc' },
queryParamsHandling: 'merge',
preserveFragment: true
});
this.routernomal.navigateByUrl(urlTree);
}
if (this.selectedOption === 'Relevance') {
const urlTree = this.routernomal.createUrlTree([], {
queryParams: { 'q[s]': '' },
queryParamsHandling: 'merge',
preserveFragment: true
});
this.routernomal.navigateByUrl(urlTree);
}
if (this.selectedOption === 'A To Z') {
const urlTree = this.routernomal.createUrlTree([], {
queryParams: { 'q[s]': 'name+asc' },
queryParamsHandling: 'merge',
preserveFragment: true
});
this.routernomal.navigateByUrl(urlTree);
}
if (this.selectedOption === 'Z To A') {
const urlTree = this.routernomal.createUrlTree([], {
queryParams: { 'q[s]': 'name+desc' },
queryParamsHandling: 'merge',
preserveFragment: true
});
this.routernomal.navigateByUrl(urlTree);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const queryMap = {
    Newest: 'updated_at+asc'
...}

sortFilter() {
       const urlTree = this.routernomal.createUrlTree([], {
         queryParams: { 'q[s]':  queryMap[this.selectedOption]},
         queryParamsHandling: 'merge',
         preserveFragment: true
       });
       this.routernomal.navigateByUrl(urlTree);
}

}
1 change: 1 addition & 0 deletions src/app/home/sidebar/categories/categories.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h4> Catgeories</h4>

<div *ngIf="isFilterOn">
<ul class="list-group" *ngIf="taxonomiList; let child_taxonomy">
<p>{{taxonomiList.pretty_name}}</p>
<h4 *ngIf="categoryLevel.length > 0"> Catgeories</h4>
<li *ngIf="categoryLevel.length > 0">
<i class="fa fa-chevron-left" aria-hidden="true"></i>
Expand Down
2 changes: 1 addition & 1 deletion src/app/home/sidebar/categories/categories.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ActivatedRoute } from '@angular/router';
import { AppState } from './../../../interfaces';
import { Store } from '@ngrx/store';
import { SearchActions } from './../../reducers/search.actions';
import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
import { Component, OnInit, Input, EventEmitter, Output, OnChanges } from '@angular/core';
import { URLSearchParams } from '@angular/http'
import { getChildTaxons } from '../../reducers/selectors';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,22 @@ export class HeaderSearchComponent implements OnInit {
keyword = keyword.trim();
const search = new URLSearchParams();
search.set('q[name_cont]', keyword)

if ('page' in this.queryParams) {
search.set('page', this.queryParams.page)
}
if ('q[s]' in this.queryParams) {
search.set('q[s]', this.queryParams['q[s]'])
}
this.store.dispatch(this.searchActions.getproductsByKeyword(search.toString()));
this.router.navigate(['/search'], { queryParams: { 'q[name_cont_all]': keyword, 'page': this.queryParams.page } });
this.router.navigate(
['/search'], {
queryParams: {
'q[name_cont_all]': keyword,
'page': this.queryParams.page,
'q[s]': this.queryParams['q[s]']
}
});
this.store.dispatch(this.searchActions.clearCategeoryLevel());
}
}
Expand All @@ -53,6 +64,9 @@ export class HeaderSearchComponent implements OnInit {
const search = new URLSearchParams();
search.set('id', this.queryParams.id);
search.set('page', this.queryParams.page)
if ('q[s]' in this.queryParams) {
search.set('q[s]', this.queryParams['q[s]'])
}
this.store.dispatch(this.searchActions.getProducsByTaxon(search.toString()));
}

Expand All @@ -65,8 +79,14 @@ export class HeaderSearchComponent implements OnInit {

if ('id' in this.queryParams && 'page' in this.queryParams) {
this.catgeoryFilter()
} else if ('id' in this.queryParams && 'q[s]' in this.queryParams) {
this.catgeoryFilter()
} else if ('id' in this.queryParams) {
this.catgeoryFilter()
}

if ('q[s]' in this.queryParams && 'q[name_cont_all]' in this.queryParams) {
this.onSearch(this.queryParams['q[name_cont_all]'])
}
}
}
2 changes: 0 additions & 2 deletions src/app/layout/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ export class HeaderComponent implements OnInit {
this.isAuthenticated = this.store.select(getAuthStatus);
this.totalCartItems = this.store.select(getTotalCartItems);
this.screenwidth = window.outerWidth;



this.test()
}
Expand Down