Files
doneit-web/src/app/pages/search/search.page.ts
T

496 lines
12 KiB
TypeScript
Raw Normal View History

2020-08-05 15:39:16 +01:00
import { Component, OnInit } from '@angular/core';
2021-01-07 10:57:42 +01:00
import { ModalController } from '@ionic/angular';
2021-02-08 16:55:55 +01:00
import { SearchService } from "../../services/search.service";
2021-01-08 11:04:36 +01:00
import { SearchCategory } from "src/app/models/search-category";
import { SearchDocument } from "src/app/models/search-document";
import { formatDate } from '@angular/common';
2021-01-16 17:45:09 +01:00
import { SenderPage } from 'src/app/pages/search/sender/sender.page';
2021-01-19 16:44:39 +01:00
import { OrganicEntityPage } from 'src/app/pages/search/organic-entity/organic-entity.page';
2021-02-18 12:44:35 +01:00
import WordCloud from 'src/plugin/wordcloud2.js';
2021-02-11 14:42:10 +01:00
import { ViewEventPage } from 'src/app/pages/agenda/view-event/view-event.page';
2021-02-11 15:18:27 +01:00
import { PublicationDetailPage } from '../publications/view-publications/publication-detail/publication-detail.page';
2021-04-07 09:32:17 +01:00
import { ExpedienteDetailPage } from '../gabinete-digital/expediente/expediente-detail/expediente-detail.page';
2021-04-09 04:34:21 +01:00
import { DocumentDetailPage } from 'src/app/modals/document-detail/document-detail.page';
2020-08-05 15:39:16 +01:00
@Component({
selector: 'app-search',
templateUrl: './search.page.html',
styleUrls: ['./search.page.scss'],
})
export class SearchPage implements OnInit {
2021-01-08 11:04:36 +01:00
// https params
2021-01-24 23:40:03 +01:00
searchSubject: string;
searchDocumentDate: string;
searchSender: string;
searchOrganicEntiry: string;
searchDocTypeId: string;
ordinance: string;
2021-01-08 11:04:36 +01:00
2021-04-09 05:46:01 +01:00
searchCategories: SearchCategory[] = [];
showSearchDocuments: SearchDocument[] = [];
2021-01-18 14:59:09 +01:00
showCategory: string;
2021-04-09 05:46:01 +01:00
searchDocuments: SearchDocument[] =[];
2021-01-18 14:59:09 +01:00
2021-01-15 08:16:36 +01:00
showDocuments = false;
showAdvanceSearch = false;
2021-01-29 17:13:15 +01:00
showLoader: boolean;
2021-01-16 17:45:09 +01:00
// See http://idangero.us/swiper/api/ for valid options.
slideOpts = {
2021-02-26 10:05:00 +01:00
slidesPerView: parseInt(`${window.innerWidth/147}`, 10),
2021-01-16 17:45:09 +01:00
initialSlide: 0,
speed: 400,
}
2021-02-11 14:31:43 +01:00
loadedAttachments:any;
2021-02-08 12:27:45 +01:00
list = []
2021-02-26 10:05:00 +01:00
windowWidth: number;
2021-01-08 11:04:36 +01:00
constructor(private modalController: ModalController,
2021-02-11 14:42:10 +01:00
private search: SearchService,
private modalCtrl: ModalController,) {
2021-01-19 16:44:39 +01:00
this.ordinance = "recent";
2021-01-08 11:04:36 +01:00
}
2020-08-05 15:39:16 +01:00
ngOnInit() {
2021-02-08 12:27:45 +01:00
2021-02-26 10:05:00 +01:00
this.wordCloud();
window.onresize = (event) => {
this.windowWidth = window.innerWidth
this.loadWordCloud()
};
this.windowWidth = window.innerWidth
2021-03-05 14:54:10 +01:00
window['dynamicSearch'] = (search:string) =>{
this.searchSubject = search;
}
2021-03-05 16:04:15 +01:00
2021-03-05 14:54:10 +01:00
window['searchTriger'] = () =>{
this.basicSearch();
}
2021-02-11 11:06:56 +01:00
}
wordCloud(){
2021-02-11 14:31:43 +01:00
2021-02-12 10:16:27 +01:00
this.search.mostSeachWord("15").subscribe(res=>{
2021-02-08 12:27:45 +01:00
2021-02-26 10:05:00 +01:00
const container = document.querySelector('.seach-wrapper');
2021-02-11 14:31:43 +01:00
2021-02-26 10:05:00 +01:00
// container.setAttribute('style',`width: ${window.innerWidth}px`);
2021-02-12 11:08:03 +01:00
2021-02-12 10:16:27 +01:00
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 ------------------------------------
2021-03-05 16:04:15 +01:00
// 64
2021-02-12 16:56:26 +01:00
const maximum = 64;
2021-02-12 10:16:27 +01:00
res.forEach(e => {
const array: any = Object.values(e);
2021-02-12 16:56:26 +01:00
array[1] = (((array[1] - lowest) / perPercent) * (maximum - minimumSize)/ 100 ) + minimumSize;
2021-02-12 10:16:27 +01:00
list.push(array)
2021-02-08 12:27:45 +01:00
});
this.list = list
2021-02-12 10:16:27 +01:00
2021-03-05 16:04:15 +01:00
console.log(this.list)
2021-02-08 12:27:45 +01:00
const elem = document.documentElement.querySelector('.most-searched-word-container');
2021-02-26 10:05:00 +01:00
setTimeout(()=>{
WordCloud(
elem,
{
list: this.list,
Family: 'Times, serif',
gridSize: 15
},
);
},300)
});
}
loadWordCloud(){
setTimeout(()=>{
const elem = document.documentElement.querySelector('.most-searched-word-container');
2021-02-08 12:27:45 +01:00
WordCloud(
elem,
{
list: this.list,
Family: 'Times, serif',
gridSize: 15
},
);
2021-02-26 10:05:00 +01:00
},100);
2020-08-05 15:39:16 +01:00
}
2021-01-20 10:41:38 +01:00
2021-01-07 10:57:42 +01:00
close(){
this.modalController.dismiss();
}
2020-08-05 15:39:16 +01:00
2021-01-18 09:52:33 +01:00
2021-01-20 10:41:38 +01:00
reorderList(orderBy: string){
this.ordinance = orderBy;
if(this.ordinance == 'recent'){
this.showSearchDocuments = this.sortArrayISODate(this.searchDocuments).reverse();
2021-01-20 13:52:25 +01:00
} else {
this.showSearchDocuments = this.sortArrayISODate(this.searchDocuments)
2021-01-20 10:41:38 +01:00
}
2021-01-19 16:44:39 +01:00
}
2021-01-18 14:59:09 +01:00
sortArrayISODate(myArray: any){
return myArray.sort(function(a, b) {
return (a.Data < b.Data) ? -1 : ((a.Data > b.Data) ? 1 : 0);
});
}
2021-01-08 11:43:47 +01:00
/**
2021-01-15 08:16:36 +01:00
* @description Basic search
2021-01-08 11:43:47 +01:00
*/
2021-04-13 10:35:43 +01:00
basicSearch(){
2021-01-15 08:16:36 +01:00
2021-02-10 16:07:18 +01:00
if(window.location.pathname == '/home/agenda'){
2021-01-29 16:25:03 +01:00
2021-01-29 17:13:15 +01:00
this.showLoader = true;
2021-01-29 16:25:03 +01:00
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
}
2021-01-29 17:13:15 +01:00
this.showLoader = false;
2021-02-26 10:05:00 +01:00
this.loadWordCloud();
2021-01-29 16:25:03 +01:00
});
2021-02-10 16:07:18 +01:00
} else if (window.location.pathname =='/home/gabinete-digital'){
2021-01-29 16:25:03 +01:00
2021-01-29 17:13:15 +01:00
this.showLoader = true;
2021-01-29 16:25:03 +01:00
2021-04-13 10:35:43 +01:00
this.searchCategories = [];
this.searchDocuments = [];
this.showSearchDocuments = [];
2021-01-29 16:25:03 +01:00
this.search.basicSearch(this.searchSubject, this.searchDocumentDate, this.searchSender
,this.searchOrganicEntiry, this.searchDocTypeId, '8').subscribe(res=>{
res.Categories.forEach( e => {
e['Active'] = false;
2021-04-08 22:53:31 +01:00
this.searchCategories.push(e)
2021-01-29 16:25:03 +01:00
});
// bind respose
2021-04-08 22:53:31 +01:00
this.sortArrayISODate(res.Documents).forEach(e => {
this.searchDocuments.push(e)
});
2021-01-29 16:25:03 +01:00
this.reorderList(this.ordinance);
// hide show document
if(this.searchDocuments.length >= 1){
this.showDocuments = true;
} else {
this.showDocuments = false
}
2021-02-26 10:05:00 +01:00
this.loadWordCloud();
2021-01-29 16:25:03 +01:00
});
this.search.basicSearch(this.searchSubject, this.searchDocumentDate, this.searchSender
,this.searchOrganicEntiry, this.searchDocTypeId, '361').subscribe(res=>{
res.Categories.forEach( e => {
e['Active'] = false;
2021-04-08 22:53:31 +01:00
this.searchCategories.push(e)
2021-01-29 16:25:03 +01:00
});
2021-04-08 22:53:31 +01:00
this.sortArrayISODate(res.Documents).forEach(e => {
this.searchDocuments.push(e)
});
2021-01-29 16:25:03 +01:00
this.reorderList(this.ordinance);
// hide show document
if(this.searchDocuments.length >= 1){
this.showDocuments = true;
} else {
this.showDocuments = false
}
2021-01-29 17:13:15 +01:00
this.showLoader = false;
2021-02-26 10:05:00 +01:00
this.loadWordCloud();
2021-01-29 16:25:03 +01:00
});
2021-04-13 10:35:43 +01:00
2021-02-10 16:07:18 +01:00
} else if (window.location.pathname == '/home/publications'){
2021-01-29 16:25:03 +01:00
2021-01-29 17:13:15 +01:00
this.showLoader = true;
2021-01-18 09:52:33 +01:00
this.search.basicSearch(this.searchSubject, this.searchDocumentDate, this.searchSender
2021-01-29 14:13:31 +01:00
,this.searchOrganicEntiry, this.searchDocTypeId, '386').subscribe(res=>{
console.log(res);
2021-01-08 11:43:47 +01:00
2021-01-20 10:41:38 +01:00
res.Categories.forEach( e => {
e['Active'] = false;
});
2021-01-08 12:29:59 +01:00
// bind respose
2021-01-08 11:43:47 +01:00
this.searchCategories = res.Categories;
2021-01-20 10:41:38 +01:00
2021-01-18 14:59:09 +01:00
this.searchDocuments = this.sortArrayISODate(res.Documents);
2021-01-08 11:43:47 +01:00
2021-01-20 13:52:25 +01:00
this.reorderList(this.ordinance);
2021-01-08 12:29:59 +01:00
// hide show document
if(this.searchDocuments.length >= 1){
this.showDocuments = true;
} else {
this.showDocuments = false
}
2021-01-29 17:13:15 +01:00
this.showLoader = false;
2021-02-26 10:05:00 +01:00
this.loadWordCloud();
2021-01-08 11:43:47 +01:00
});
2021-01-29 16:25:03 +01:00
}
2021-01-08 11:43:47 +01:00
}
2021-01-08 12:29:59 +01:00
/**
* @description set empty value to searchSubject
*/
clearSearchInput(){
this.searchSubject = ""
2021-02-11 11:06:56 +01:00
this.searchCategories = [];
this.searchDocuments = [];
this.showDocuments = false;
this.wordCloud();
2021-01-08 12:29:59 +01:00
}
2021-01-08 11:04:36 +01:00
/**
* @param isoDate String Iso date
2021-01-08 13:00:34 +01:00
* @returns date in format dd/MM/yyyy
2021-01-08 12:29:59 +01:00
* @description convert Iso date to dd/MM/yyyy
2021-01-08 11:04:36 +01:00
*/
formateIsoDate(isoDate:string): string{
const date = new Date(isoDate);
return formatDate(date, 'dd/MM/yyyy', 'pt');
}
2021-01-20 13:52:25 +01:00
activeCategoty(i){
2021-02-10 16:55:27 +01:00
this.searchCategories.forEach((e, j) => {
if(i != j){
e['Active'] = false;
}
2021-01-20 13:52:25 +01:00
})
2021-02-10 16:55:27 +01:00
if (this.searchCategories[i]['Active']){
this.searchCategories[i]['Active'] = false;
} else {
this.searchCategories[i]['Active'] = true
}
2021-01-20 13:52:25 +01:00
}
2021-01-18 14:59:09 +01:00
clearInputRemetente(){
this.searchSender = "";
}
clearInputDocumentDate(){
this.searchDocumentDate = "";
}
clearInputOrganicEntity(){
this.searchOrganicEntiry = "";
}
2021-01-15 08:16:36 +01:00
/**
* @description Clean inputs
*/
showHideAdvanceSearch(show:boolean) {
this.showAdvanceSearch = show;
}
2021-01-16 17:45:09 +01:00
async openAdvanceSearchSelection() {
2021-03-11 10:31:46 +01:00
let classs;
if( window.innerWidth <= 1024){
classs = 'modal modal-desktop'
} else {
classs = 'search-desktop-modal search-submodal'
}
2021-01-16 17:45:09 +01:00
const modal = await this.modalController.create({
component: SenderPage,
2021-03-11 10:31:46 +01:00
cssClass: classs,
2021-01-16 17:45:09 +01:00
componentProps: {
}
});
2021-01-19 16:44:39 +01:00
await modal.present();
modal.onDidDismiss().then((data) => {
this.searchSender = data.data;
});
}
async openOrganicEntitySelection(){
2021-03-11 10:31:46 +01:00
let classs;
if( window.innerWidth <= 1024){
classs = 'modal modal-desktop'
} else {
classs = 'search-desktop-modal search-submodal'
}
2021-01-19 16:44:39 +01:00
const modal = await this.modalController.create({
component: OrganicEntityPage,
2021-03-11 10:31:46 +01:00
cssClass: classs,
2021-01-19 16:44:39 +01:00
componentProps: {
}
});
await modal.present();
modal.onDidDismiss().then((data) => {
this.searchOrganicEntiry = data.data;
});
2021-01-16 17:45:09 +01:00
}
2021-01-18 14:59:09 +01:00
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;
}
2021-02-11 14:31:43 +01:00
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();
}
2021-02-11 15:18:27 +01:00
async viewDetail(id:any) {
2021-04-07 09:32:17 +01:00
console.log(id);
2021-02-11 14:42:10 +01:00
2021-02-11 14:46:34 +01:00
if(window.location.pathname == '/home/agenda'){
2021-02-11 15:18:27 +01:00
2021-02-11 14:46:34 +01:00
const modal = await this.modalCtrl.create({
component: ViewEventPage,
componentProps:{
2021-02-11 15:18:27 +01:00
eventId: id
2021-02-11 14:46:34 +01:00
},
2021-03-04 15:14:09 +01:00
cssClass: 'modal modal-desktop',
2021-02-11 14:46:34 +01:00
});
await modal.present();
modal.onDidDismiss().then((res)=>{});
2021-02-11 15:18:27 +01:00
} else if(window.location.pathname == '/home/publications'){
this.viewPublicationDetail(id);
2021-02-11 14:46:34 +01:00
}
2021-04-07 09:32:17 +01:00
else if(window.location.pathname == '/home/gabinete-digital'){
console.log('OPEN DOC');
2021-04-09 04:34:21 +01:00
this.viewDocumentDetail(id,'');
2021-04-07 09:32:17 +01:00
}
2021-02-11 14:42:10 +01:00
2021-02-11 14:46:34 +01:00
}
2021-02-11 14:42:10 +01:00
2021-02-11 15:18:27 +01:00
async viewPublicationDetail(publicationId:string) {
const modal = await this.modalController.create({
component: PublicationDetailPage,
componentProps:{
publicationId: publicationId,
},
2021-03-11 10:31:46 +01:00
cssClass: 'publication-detail modal modal-desktop ',
2021-02-11 15:18:27 +01:00
backdropDismiss: false
});
await modal.present();
modal.onDidDismiss().then(()=>{});
}
2021-04-07 09:32:17 +01:00
2021-04-09 04:34:21 +01:00
async viewDocumentDetail(docId:string, applicationId:string) {
2021-04-07 09:32:17 +01:00
let classs;
if( window.innerWidth <= 800){
2021-04-09 04:34:21 +01:00
classs = 'modal'
2021-04-07 09:32:17 +01:00
} else {
2021-04-09 04:34:21 +01:00
classs = 'modal modal-desktop showAsideOptions'
2021-04-07 09:32:17 +01:00
}
2021-04-09 04:34:21 +01:00
2021-04-07 09:32:17 +01:00
const modal = await this.modalController.create({
2021-04-09 04:34:21 +01:00
component: DocumentDetailPage,
2021-04-07 09:32:17 +01:00
componentProps:{
2021-04-09 04:34:21 +01:00
docId: docId,
applicationId: applicationId,
2021-04-07 09:32:17 +01:00
},
cssClass: classs,
});
await modal.present();
modal.onDidDismiss().then((res)=>{
});
}
2021-02-11 15:18:27 +01:00
}