Files
doneit-web/src/app/pages/search/search.page.ts
T
2021-01-25 00:26:04 +01:00

211 lines
5.0 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { ProcessesService } from 'src/app/services/processes.service';
import { SearchService } from "../../services/search.service";
import { SearchCategory } from "src/app/models/search-category";
import { SearchDocument } from "src/app/models/search-document";
import { formatDate } from '@angular/common';
/* import { CloudData, CloudOptions } from 'angular-tag-cloud-module'; */
import { SenderPage } from 'src/app/pages/search/sender/sender.page';
import { OrganicEntityPage } from 'src/app/pages/search/organic-entity/organic-entity.page';
import { NgModel } from '@angular/forms';
@Component({
selector: 'app-search',
templateUrl: './search.page.html',
styleUrls: ['./search.page.scss'],
})
export class SearchPage implements OnInit {
// https params
searchSubject: string;
searchDocumentDate: string;
searchSender: string;
searchOrganicEntiry: string;
searchDocTypeId: string;
ordinance: string;
searchCategories: SearchCategory[];
showSearchDocuments: SearchDocument[];
showCategory: string;
searchDocuments: SearchDocument[];
showDocuments = false;
showAdvanceSearch = false;
/* options: CloudOptions = {
// if width is between 0 and 1 it will be set to the width of the upper element multiplied by the value
width: 1000,
// if height is between 0 and 1 it will be set to the height of the upper element multiplied by the value
height: 400,
overflow: false,
}; */
/* data: CloudData[] = [
{text: 'Weight-8-link-color', weight: 8, link: 'https://google.com', color: '#ffaaee'},
{text: 'Weight-10-link', weight: 10, link: 'https://google.com', tooltip: 'display a tooltip'},
// ...
]; */
// See http://idangero.us/swiper/api/ for valid options.
slideOpts = {
slidesPerView: 3,
initialSlide: 0,
speed: 400,
}
constructor(private modalController: ModalController,
private search: SearchService) {
this.ordinance = "recent";
}
ngOnInit() {
}
close(){
this.modalController.dismiss();
}
reorderList(orderBy: string){
this.ordinance = orderBy;
if(this.ordinance == 'recent'){
this.showSearchDocuments = this.sortArrayISODate(this.searchDocuments).reverse();
} else {
this.showSearchDocuments = this.sortArrayISODate(this.searchDocuments)
}
}
sortArrayISODate(myArray: any){
return myArray.sort(function(a, b) {
return (a.Data < b.Data) ? -1 : ((a.Data > b.Data) ? 1 : 0);
});
}
/**
* @description Basic search
*/
basicSearch(){
this.search.basicSearch(this.searchSubject, this.searchDocumentDate, this.searchSender
,this.searchOrganicEntiry, this.searchDocTypeId).subscribe(res=>{
res.Categories.forEach( e => {
e['Active'] = false;
});
// bind respose
this.searchCategories = res.Categories;
this.searchDocuments = this.sortArrayISODate(res.Documents);
this.reorderList(this.ordinance);
// hide show document
if(this.searchDocuments.length >= 1){
this.showDocuments = true;
} else {
this.showDocuments = false
}
});
}
/**
* @description set empty value to searchSubject
*/
clearSearchInput(){
this.searchSubject = ""
}
/**
* @param isoDate String Iso date
* @returns date in format dd/MM/yyyy
* @description convert Iso date to dd/MM/yyyy
*/
formateIsoDate(isoDate:string): string{
const date = new Date(isoDate);
return formatDate(date, 'dd/MM/yyyy', 'pt');
}
activeCategoty(i){
this.searchCategories.forEach((e) => {
e['Active'] = false;
})
this.searchCategories[i]['Active'] = true;
}
clearInputRemetente(){
this.searchSender = "";
}
clearInputDocumentDate(){
this.searchDocumentDate = "";
}
clearInputOrganicEntity(){
this.searchOrganicEntiry = "";
}
/**
* @description Clean inputs
*/
showHideAdvanceSearch(show:boolean) {
this.showAdvanceSearch = show;
}
async openAdvanceSearchSelection() {
const modal = await this.modalController.create({
component: SenderPage,
cssClass: 'sender',
componentProps: {
}
});
await modal.present();
modal.onDidDismiss().then((data) => {
this.searchSender = data.data;
});
}
async openOrganicEntitySelection(){
const modal = await this.modalController.create({
component: OrganicEntityPage,
cssClass: 'organicEnity',
componentProps: {
}
});
await modal.present();
modal.onDidDismiss().then((data) => {
this.searchOrganicEntiry = data.data;
});
}
async filterDocList(categoryName:string){
// show all category
if(this. showCategory == categoryName ){
this.showSearchDocuments = this.searchDocuments;
} else { // filter category
this.showSearchDocuments = this.searchDocuments.filter((e) => e.DocTypeDesc == categoryName);
}
this.showCategory = categoryName;
}
}