Skip to content

Commit

Permalink
Order By Ascending and Descending option for favorite
Browse files Browse the repository at this point in the history
  • Loading branch information
arjunrkr committed Oct 12, 2017
1 parent 5ec78e8 commit 4daaf39
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/app/home-fav.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ <h2>This is Cinema Paradiso</h2>
</div>
<div class="breadcrumb">
<label class='active'>Favorites</label>
<div *ngIf="movies.length > 0" class='active' style='float:right;'>Sort By
<a (click)="sortBy('release_date')">Year <i class='glyphicon glyphicon-sort-by-attributes'></i></a> |
<a (click)="sortBy('vote_average')">Rating <i class='glyphicon glyphicon-sort-by-attributes'></i></a> |
<a (click)="sortBy('title')">Name <i class='glyphicon glyphicon-sort-by-attributes'></i></a>
<div *ngIf="movies.length > 0" class='active' style='float:right;'>Sort By:
Year <a (click)="orderBy('release_date','asc')"><i class='glyphicon glyphicon-sort-by-attributes'></i></a>
<a (click)="orderBy('release_date','desc')"><i class='glyphicon glyphicon-sort-by-attributes-alt'></i></a> |
Rating <a (click)="orderBy('vote_average','asc')"><i class='glyphicon glyphicon-sort-by-attributes'></i></a>
<a (click)="orderBy('vote_average','desc')"><i class='glyphicon glyphicon-sort-by-attributes-alt'></i></a> |
Name <a (click)="orderBy('title','asc')"><i class='glyphicon glyphicon-sort-by-attributes'></i></a>
<a (click)="orderBy('title','desc')"><i class='glyphicon glyphicon-sort-by-attributes-alt'></i></a>
</div>
</div>

Expand Down
4 changes: 2 additions & 2 deletions src/app/home-fav.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export class HomeFavComponent implements OnInit {
isFav(id: number): string {
return this.apiSerivce.isFavMovie(id);
}
sortBy(srtval: string): void {
orderBy(srtval: string, order: string): void {
// return '';
this.movies = this.apiSerivce.sortByService(srtval);
this.movies = this.apiSerivce.orderByService(srtval, order);
}
showInfo(msg: string) {
this.toastr.info(msg, null, { positionClass: 'toast-bottom-right', animate: 'flyRight' });
Expand Down
4 changes: 2 additions & 2 deletions src/app/movies.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export class MovieService {
return JSON.parse(localStorage.getItem('FavMovies'));
}

sortByService(srtVal): any {
orderByService(srtVal, order): any {
let data = [];
data = JSON.parse(localStorage.getItem('FavMovies')) || [];
data = _.sortBy(data, [srtVal]);
data = _.orderBy(data, [srtVal], [order]);
// localStorage.setItem('FavMovies', JSON.stringify(data));
return data;
}
Expand Down

0 comments on commit 4daaf39

Please sign in to comment.