Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Component, OnInit } from '@angular/core';
- import { Router, ActivatedRoute } from '@angular/router';
- import { ModalService } from './modal.service';
- import { UsersComponent } from '../users/usersdetail.component';
- @Component({
- selector: 'app-filter-and-sorting',
- templateUrl: './filterAndSorting.component.html',
- styleUrls: ['./filterAndSorting.component.css']
- })
- export class FilterAndSortingComponent implements OnInit {
- static text = '';
- role: number = 0;
- filtersOn: boolean = false;
- orderBy: string ='dasid';
- sortDirection: string ='ASC'; // '_' significa que será ascendente
- name = '';
- dasid = '';
- surname = '';
- email = '';
- location = '';
- status = '';
- constructor(private router: Router,
- public modalService: ModalService,
- private userDetails: UsersComponent) { }
- ngOnInit() {
- }
- closeModal(){
- this.modalService.closeModal();
- }
- applyFilters() {
- FilterAndSortingComponent.text = this.getFilterUrl();
- if(this.role && this.role != 0) {
- this.userDetails.getUsersByRole();
- } else {
- this.userDetails.getUsers();
- }
- this.filtersOn = true;
- this.closeModal();
- }
- getFilterUrl(): string {
- let filterUrl: string;
- let lname: string = this.getFilterName(this.name);
- let ldasid: string = this.getFilterName(this.dasid);
- let lsurname: string = this.getFilterName(this.surname);
- let lemail: string = this.getFilterName(this.email);
- let llocation: string = this.getFilterName(this.location);
- let lstatus: string = this.getFilterName(this.status);
- filterUrl = '?name=' + lname + '&dasid=' + ldasid + '&surname='
- + lsurname + '&email=' + lemail + '&location=' + llocation + '&status=' + lstatus;
- if (this.role) {
- filterUrl += '&role=' + this.role;
- }
- if (this.orderBy) {
- filterUrl += '&sortBy=' + this.orderBy;
- console.log(filterUrl);
- }
- if(this.sortDirection !== 'ASC') {
- filterUrl += '&sortDirection=' + this.sortDirection;
- }
- return filterUrl;
- }
- getFilterName(fieldName: string): string {
- if (fieldName === '') {
- return '_';
- } else {
- return fieldName;
- }
- }
- setSortDirectionAsc(): void {
- this.sortDirection = 'ASC';
- }
- setSortDirectionDesc(): void {
- this.sortDirection = 'DESC';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement