import { Subject } from 'rxjs';
import { Component, OnInit } from '@angular/core';
import { IPaginate } from 'App/_shared/interfaces/paginate.interface';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { ComplianceMattersService } from 'App/msc-compliance/services/compliance-matters.service';
import { FormBuilder, FormGroup } from '@angular/forms';
@Component({
templateUrl: './compliance-matter-list.component.html',
})
export class ComplianceMatterListComponent implements OnInit {
page: number = 1;
limit: number = 50;
paginateMeta: IPaginate = null;
filter_form: FormGroup;
state = {
compliance_matters: [],
activities: [
{title: 'Exemption Of Relocation', id: 1},
{title: 'Reduction Of Office Space', id: 2},
{title: 'Extension Of Relocation', id: 3},
{title: 'MSC Surrendering', id: 4},
]
};
meta = {
isLoading: false,
isLoadingError: false,
};
constructor(
private route: ActivatedRoute,
private router: Router,
private fb: FormBuilder,
private complianceMatterService: ComplianceMattersService,
) {
}
ngOnInit(): void {
this.filter_form = this.fb.group({
search: [''],
activity_type_id: [''],
});
this.route.queryParams
.subscribe(params => {
const api_params = {...params, limit: this.limit};
this.complianceMatterService.getComplianceMatters(api_params).subscribe(
res => {
this.state.compliance_matters = res.data;
this.paginateMeta = res.meta;
}
);
});
}
filter(form: FormGroup) {
const search = form.value.search;
const activity_type_id = form.value.activity_type_id;
// change route parameter
const queryParams = {...this.route.snapshot.queryParams};
// set the query params value
queryParams['search'] = search;
queryParams['activity_type_id'] = activity_type_id;
this.router.navigate(
[],
{
relativeTo: this.route,
queryParams: queryParams
});
}
pageChange(page: number): void {
// change route parameter
const queryParams = {...this.route.snapshot.queryParams};
// set the filter query params
queryParams['page'] = page;
this.router.navigate(
[],
{
relativeTo: this.route,
queryParams: queryParams
});
}
}