Files
doneit-web/src/app/pages/search/search.page.ts
T
2021-02-08 16:55:55 +01:00

354 lines
8.4 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 WordCloud from 'src/plugin/wordcloud2.js'
import { TopSearch } from 'src/app/models/top-search';
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;
showLoader: boolean;
height: number = 411;
width: number = 411;
data: CloudData[] = [
{text: 'Docents', weight: 0.1, color: '#ffaaee'},
{text: '1232', weight: 0.2, tooltip: 'display a tooltip'},
{text: 'Dcuments', weight: 0.1, color: '#ffaaee'},
{text: 'Cat', weight: 0.3, color: '#ffaaee'},
{text: 'Dogs', weight: 0.1, tooltip: 'display a tooltip'},
{text: 'cars', weight: 0.2, color: '#ffaaee'},
];
// See http://idangero.us/swiper/api/ for valid options.
slideOpts = {
slidesPerView: 3,
initialSlide: 0,
speed: 400,
}
list = []
constructor(private modalController: ModalController,
private search: SearchService) {
this.ordinance = "recent";
}
ngOnInit() {
this.search.mostSeachWord("10").subscribe(res=>{
let list = []
res.forEach(element => {
list.push(Object.values(element))
});
this.list = list
const elem = document.documentElement.querySelector('.most-searched-word-container');
WordCloud(
elem,
{
list: this.list,
Family: 'Times, serif',
gridSize: 15
},
);
});
}
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(){
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
const APPType = getCookie('searchModalAPPType');
if(APPType == '0'){
console.log('aplication type 0');
this.showLoader = true;
this.search.basicSearch(this.searchSubject, this.searchDocumentDate, this.searchSender
,this.searchOrganicEntiry, this.searchDocTypeId, '0').subscribe(res=>{
console.log(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
}
this.showLoader = false;
});
} else if (APPType == '8,361'){
console.log('aplication type 8,361');
this.showLoader = true;
this.search.basicSearch(this.searchSubject, this.searchDocumentDate, this.searchSender
,this.searchOrganicEntiry, this.searchDocTypeId, '8').subscribe(res=>{
console.log(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
}
});
this.search.basicSearch(this.searchSubject, this.searchDocumentDate, this.searchSender
,this.searchOrganicEntiry, this.searchDocTypeId, '361').subscribe(res=>{
console.log(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
}
this.showLoader = false;
});
} else if (APPType == '386'){
this.showLoader = true;
console.log('aplication type 386');
this.search.basicSearch(this.searchSubject, this.searchDocumentDate, this.searchSender
,this.searchOrganicEntiry, this.searchDocTypeId, '386').subscribe(res=>{
console.log(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
}
this.showLoader = 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;
}
}