Files
doneit-web/src/app/pages/search/search.page.ts
T
tiago.kayaya 53e3908fff save
2021-04-07 09:32:17 +01:00

490 lines
12 KiB
TypeScript

import { Component, OnInit } from '@angular/core';
import { ModalController } from '@ionic/angular';
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 { 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 { ViewEventPage } from 'src/app/pages/agenda/view-event/view-event.page';
import { PublicationDetailPage } from '../publications/view-publications/publication-detail/publication-detail.page';
import { ExpedienteDetailPage } from '../gabinete-digital/expediente/expediente-detail/expediente-detail.page';
@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;
// See http://idangero.us/swiper/api/ for valid options.
slideOpts = {
slidesPerView: parseInt(`${window.innerWidth/147}`, 10),
initialSlide: 0,
speed: 400,
}
loadedAttachments:any;
list = []
windowWidth: number;
constructor(private modalController: ModalController,
private search: SearchService,
private modalCtrl: ModalController,) {
this.ordinance = "recent";
}
ngOnInit() {
this.wordCloud();
window.onresize = (event) => {
this.windowWidth = window.innerWidth
this.loadWordCloud()
};
this.windowWidth = window.innerWidth
window['dynamicSearch'] = (search:string) =>{
this.searchSubject = search;
}
window['searchTriger'] = () =>{
this.basicSearch();
}
}
wordCloud(){
this.search.mostSeachWord("15").subscribe(res=>{
const container = document.querySelector('.seach-wrapper');
// container.setAttribute('style',`width: ${window.innerWidth}px`);
const highest= res[0].Hits;
const lowest = res[res.length-1].Hits;
const range = highest - lowest;
const perPercent = range / 100;
let list = [];
// minimum font sixe
// Editable -----------------------------------
const minimumSize = 9;
// Editable ------------------------------------
// 64
const maximum = 64;
res.forEach(e => {
const array: any = Object.values(e);
array[1] = (((array[1] - lowest) / perPercent) * (maximum - minimumSize)/ 100 ) + minimumSize;
list.push(array)
});
this.list = list
console.log(this.list)
const elem = document.documentElement.querySelector('.most-searched-word-container');
setTimeout(()=>{
WordCloud(
elem,
{
list: this.list,
Family: 'Times, serif',
gridSize: 15
},
);
},300)
});
}
loadWordCloud(){
setTimeout(()=>{
const elem = document.documentElement.querySelector('.most-searched-word-container');
WordCloud(
elem,
{
list: this.list,
Family: 'Times, serif',
gridSize: 15
},
);
},100);
}
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(){
if(window.location.pathname == '/home/agenda'){
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;
this.loadWordCloud();
});
} else if (window.location.pathname =='/home/gabinete-digital'){
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.loadWordCloud();
});
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;
this.loadWordCloud();
});
} else if (window.location.pathname == '/home/publications'){
this.showLoader = true;
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;
this.loadWordCloud();
});
}
}
/**
* @description set empty value to searchSubject
*/
clearSearchInput(){
this.searchSubject = ""
this.searchCategories = [];
this.searchDocuments = [];
this.showDocuments = false;
this.wordCloud();
}
/**
* @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, j) => {
if(i != j){
e['Active'] = false;
}
})
if (this.searchCategories[i]['Active']){
this.searchCategories[i]['Active'] = false;
} else {
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() {
let classs;
if( window.innerWidth <= 1024){
classs = 'modal modal-desktop'
} else {
classs = 'search-desktop-modal search-submodal'
}
const modal = await this.modalController.create({
component: SenderPage,
cssClass: classs,
componentProps: {
}
});
await modal.present();
modal.onDidDismiss().then((data) => {
this.searchSender = data.data;
});
}
async openOrganicEntitySelection(){
let classs;
if( window.innerWidth <= 1024){
classs = 'modal modal-desktop'
} else {
classs = 'search-desktop-modal search-submodal'
}
const modal = await this.modalController.create({
component: OrganicEntityPage,
cssClass: classs,
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;
}
itemIcons(): string{
return window.location.pathname
}
viewDocument(){
const url: string = this.loadedAttachments.DocumentURL.replace("webTRIX.Viewer","webTRIX.Viewer.Branch1");
// const browser = this.iab.create(url,"_blank");
// browser.show();
}
async viewDetail(id:any) {
console.log(id);
if(window.location.pathname == '/home/agenda'){
const modal = await this.modalCtrl.create({
component: ViewEventPage,
componentProps:{
eventId: id
},
cssClass: 'modal modal-desktop',
});
await modal.present();
modal.onDidDismiss().then((res)=>{});
} else if(window.location.pathname == '/home/publications'){
this.viewPublicationDetail(id);
}
else if(window.location.pathname == '/home/gabinete-digital'){
console.log('OPEN DOC');
}
}
async viewPublicationDetail(publicationId:string) {
const modal = await this.modalController.create({
component: PublicationDetailPage,
componentProps:{
publicationId: publicationId,
},
cssClass: 'publication-detail modal modal-desktop ',
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then(()=>{});
}
async viewExpedientDetail(serialNumber:any) {
let classs;
if( window.innerWidth <= 800){
classs = 'modal modal-desktop'
} else {
classs = 'gabinete-digital-mobile-modal-to-Desktop'
}
const modal = await this.modalController.create({
component: ExpedienteDetailPage,
componentProps:{
serialNumber: serialNumber,
profile: 'mdgpr',
},
cssClass: classs,
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then((res)=>{
});
}
}