Advertisement
Guest User

component ts

a guest
Oct 16th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. import { Component, OnInit } from '@angular/core';
  2. import { Router, ActivatedRoute } from '@angular/router';
  3. import { ModalService } from './modal.service';
  4. import { UsersComponent } from '../users/usersdetail.component';
  5.  
  6. @Component({
  7. selector: 'app-filter-and-sorting',
  8. templateUrl: './filterAndSorting.component.html',
  9. styleUrls: ['./filterAndSorting.component.css']
  10. })
  11. export class FilterAndSortingComponent implements OnInit {
  12.  
  13. static text = '';
  14.  
  15. role: number = 0;
  16. filtersOn: boolean = false;
  17. orderBy: string ='dasid';
  18. sortDirection: string ='ASC'; // '_' significa que será ascendente
  19.  
  20. name = '';
  21. dasid = '';
  22. surname = '';
  23. email = '';
  24. location = '';
  25. status = '';
  26.  
  27. constructor(private router: Router,
  28. public modalService: ModalService,
  29. private userDetails: UsersComponent) { }
  30.  
  31. ngOnInit() {
  32. }
  33.  
  34. closeModal(){
  35. this.modalService.closeModal();
  36. }
  37.  
  38. applyFilters() {
  39. FilterAndSortingComponent.text = this.getFilterUrl();
  40.  
  41. if(this.role && this.role != 0) {
  42. this.userDetails.getUsersByRole();
  43. } else {
  44. this.userDetails.getUsers();
  45. }
  46. this.filtersOn = true;
  47. this.closeModal();
  48.  
  49. }
  50.  
  51. getFilterUrl(): string {
  52. let filterUrl: string;
  53.  
  54. let lname: string = this.getFilterName(this.name);
  55. let ldasid: string = this.getFilterName(this.dasid);
  56. let lsurname: string = this.getFilterName(this.surname);
  57. let lemail: string = this.getFilterName(this.email);
  58. let llocation: string = this.getFilterName(this.location);
  59. let lstatus: string = this.getFilterName(this.status);
  60.  
  61. filterUrl = '?name=' + lname + '&dasid=' + ldasid + '&surname='
  62. + lsurname + '&email=' + lemail + '&location=' + llocation + '&status=' + lstatus;
  63.  
  64. if (this.role) {
  65. filterUrl += '&role=' + this.role;
  66. }
  67.  
  68. if (this.orderBy) {
  69. filterUrl += '&sortBy=' + this.orderBy;
  70. console.log(filterUrl);
  71. }
  72.  
  73. if(this.sortDirection !== 'ASC') {
  74. filterUrl += '&sortDirection=' + this.sortDirection;
  75. }
  76.  
  77. return filterUrl;
  78. }
  79.  
  80. getFilterName(fieldName: string): string {
  81. if (fieldName === '') {
  82. return '_';
  83. } else {
  84. return fieldName;
  85. }
  86.  
  87. }
  88.  
  89. setSortDirectionAsc(): void {
  90. this.sortDirection = 'ASC';
  91. }
  92.  
  93. setSortDirectionDesc(): void {
  94. this.sortDirection = 'DESC';
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement