diff --git a/nice.html b/nice.html deleted file mode 100644 index 1768917f4..000000000 --- a/nice.html +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - Document - - - - - - - \ No newline at end of file diff --git a/src/app/guards/inactivity.guard.ts b/src/app/guards/inactivity.guard.ts index 64fad8b0b..a3e56ca7f 100644 --- a/src/app/guards/inactivity.guard.ts +++ b/src/app/guards/inactivity.guard.ts @@ -17,12 +17,14 @@ export class InactivityGuard implements CanActivate { private router:Router, private platform: Platform, public permissionService: PermissionService, - ){} + private alertController: AlertController + ) {} canActivate( route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { + if (this.platform.is('desktop') || this.platform.is('mobileweb')) { console.log(this.permissionList); if(this.permissionService.userPermission(this.permissionList.Agenda.access) || this.permissionService.userPermission(this.permissionList.Gabinete.access)){ @@ -33,7 +35,23 @@ export class InactivityGuard implements CanActivate { } else if(this.permissionService.userPermission(this.permissionList.Actions.access)){ this.router.navigate(['/home/publications']); + } else { + + this.alertController.create({ + cssClass: 'my-custom-class', + header: 'Utilizador sem acesso a aplicação', + buttons: [{ + text: 'Ok', + handler: () => { + + } + }] + }).then( async (alertPopup) => { + await alertPopup.present(); + }) + } + return false } else if(SessionStore.exist && SessionStore.user.Inactivity && !SessionStore.hasPin ) { return true @@ -41,6 +59,7 @@ export class InactivityGuard implements CanActivate { return true }//Mobile or Tablet without session else { + if(this.permissionService.userPermission(this.permissionList.Agenda.access) || this.permissionService.userPermission(this.permissionList.Gabinete.access)){ this.router.navigate(['/home/events']); } @@ -49,6 +68,19 @@ export class InactivityGuard implements CanActivate { } else if(this.permissionService.userPermission(this.permissionList.Actions.access)){ this.router.navigate(['/home/publications']); + } else { + this.alertController.create({ + cssClass: 'my-custom-class', + header: 'Utilizador sem acesso a aplicação', + buttons: [{ + text: 'Ok', + handler: () => { + + } + }] + }).then( async (alertPopup)=>{ + await alertPopup.present(); + }) } return false } diff --git a/src/app/models/user.model.ts b/src/app/models/user.model.ts index e7c5cbe56..bdb400bda 100644 --- a/src/app/models/user.model.ts +++ b/src/app/models/user.model.ts @@ -45,6 +45,7 @@ export class UserSession { CalendarName: "Oficial" | "Pessoal"; CalendarRoleId: string; Id: number; + OwnerUserId: any }[] RoleDescription: string RoleID: number @@ -55,12 +56,13 @@ export class UserSession { Id: number; OwnerUserId: string; TypeShare: number; + CalendarToken: string; }[] UserName: string Password: string RochetChatUser: string RochetChatUserId: string - Profile: any; + Profile: 'PR' | 'MDGPR' | 'Consultant' | 'Department boss' | 'Assistant' | 'Director' | 'Deputy Director' | 'Secretariat' | 'Deputy Director' | 'General secretary' ; LoginPreference: 'None' | 'Password' | 'Pin' | null; PIN: string Inactivity: boolean diff --git a/src/app/pages/agenda/agenda.page.html b/src/app/pages/agenda/agenda.page.html index bd507f0a3..eb2e12e44 100644 --- a/src/app/pages/agenda/agenda.page.html +++ b/src/app/pages/agenda/agenda.page.html @@ -93,14 +93,6 @@ -
@@ -111,11 +103,11 @@ - - @@ -184,9 +176,7 @@
-
- -
+
@@ -290,7 +280,7 @@ -
+
diff --git a/src/app/pages/agenda/agenda.page.ts b/src/app/pages/agenda/agenda.page.ts index 3e9ad13a3..e57647e61 100644 --- a/src/app/pages/agenda/agenda.page.ts +++ b/src/app/pages/agenda/agenda.page.ts @@ -167,7 +167,7 @@ export class AgendaPage implements OnInit { private alertCtrl: AlertController, @Inject(LOCALE_ID) private locale: string, private modalCtrl: ModalController, - private eventService: EventsService, + public eventService: EventsService, private router: Router, private sanitizer: DomSanitizer, authService: AuthService, @@ -192,16 +192,27 @@ export class AgendaPage implements OnInit { if (this.loggeduser.Profile == 'MDGPR') { this.mobileComponent.showEventList = true; this.profile = "mdgpr"; - } else { + } else if (this.loggeduser.Profile == 'PR') { this.profile = "pr"; + } else { + this.profile = "mdgpr"; } }) if (this.loggeduser.Profile == 'MDGPR') { this.mobileComponent.showEventList = true; this.profile = "mdgpr"; - } else { + } else if (this.loggeduser.Profile == 'PR') { this.profile = "pr"; + } else { + if(this.eventService.calendarOwnerIds.length >= 2) { + this.profile = "mdgpr"; + } else if (this.eventService.hasOwnCalendar) { + this.profile = "mdgpr"; + } else if (this.eventService.hasSharedCalendar) { + this.profile = "pr"; + } + } this.calendarHeight = "356px"; @@ -529,8 +540,7 @@ export class AgendaPage implements OnInit { }).catch((error) => { this.getFromDB(); - }) - .finally(() => { + }).finally(() => { this.showLoader = false; }) @@ -560,9 +570,9 @@ export class AgendaPage implements OnInit { }).catch((error) => { this.getFromDB() }) - .finally(() => { - this.showLoader = false; - }) + .finally(() => { + this.showLoader = false; + }) } else if (this.loggeduser.Profile == 'PR') { @@ -597,6 +607,70 @@ export class AgendaPage implements OnInit { .finally(() => { this.showLoader = false; }) + } else if (this.loggeduser.Profile != 'PR' && this.loggeduser.Profile != 'MDGPR'){ + if(this.profile == "mdgpr") { + + this.eventService.getAllOwnEvents(momentG(new Date(startTime), 'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime), 'yyyy-MM-dd 23:59:59')).then( + + (response: any) => { + console.log('ALL MD EVENTS', response); + + this.addEventToDB(response, "md"); + + // calendar + this.CalendarStore.removeRange(startTime, endTime, 'md') + + // loop + this.CalendarStore.pushEvent(response, 'md'); + + console.log('CALENDAR STORE', this.CalendarStore.eventSource) + this.listToPresent = this.CalendarStore.eventSource + this.trasnformData(response, 'md'); + + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'md', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) + + console.log('check list to present data', this.listToPresent); + this.myCal.update(); + this.myCal.loadEvents(); + + this.showLoader = false; + this.showTimeline = true; + + }).catch((error) => { + this.getFromDB(); + }).finally(() => { + this.showLoader = false; + }) + + } else if (this.profile == "pr" ) { + + this.eventService.genericGetAllSharedEvents(momentG(new Date(startTime), 'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime), 'yyyy-MM-dd 23:59:59')).then((response: any) => { + this.addEventToDB(response, "pr"); + + this.CalendarStore.removeRange(startTime, endTime, 'pr') + // calendar + this.CalendarStore.pushEvent(response, 'pr'); + + this.listToPresent = this.CalendarStore.eventSource + + + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) + + console.log('check list to present data', this.listToPresent); + this.myCal.update(); + this.myCal.loadEvents(); + + this.showLoader = false; + this.showTimeline = true; + + }).catch((error) => { + this.getFromDB() + }).finally(() => { + this.showLoader = false; + }) + + } + } } else { @@ -604,9 +678,11 @@ export class AgendaPage implements OnInit { let counter = 0; - // view MDGPR calendar with MDGPR profile if (this.loggeduser.Profile == 'MDGPR') { + + alert('MDGPR') + this.eventService.getAllMdEvents(momentG(new Date(startTime), 'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime), 'yyyy-MM-dd 23:59:59')).then((response: any) => { this.addEventToDB(response, "md"); @@ -635,13 +711,12 @@ export class AgendaPage implements OnInit { }).catch((error) => { this.getFromDB() + }).finally(() => { + counter++; + if (counter == 2) { + this.showLoader = false; + } }) - .finally(() => { - counter++; - if (counter == 2) { - this.showLoader = false; - } - }) this.eventService.getAllSharedEvents(momentG(new Date(startTime), 'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime), 'yyyy-MM-dd 23:59:59')).then((response: any) => { @@ -673,15 +748,14 @@ export class AgendaPage implements OnInit { }).catch((error) => { this.getFromDB() - }) - .finally(() => { + }).finally(() => { counter++; - if (counter == 2) { - this.showLoader = false; - } - }) + if (counter == 2) { + this.showLoader = false; + } + }) - } else { + } else if(this.loggeduser.Profile == 'PR') { // view PR calendar with PR profile this.eventService.getAllPrEvents(momentG(new Date(startTime), 'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime), 'yyyy-MM-dd 23:59:59')).then((response: any) => { @@ -719,12 +793,105 @@ export class AgendaPage implements OnInit { }).catch((error) => { this.getFromDB() + }).finally(() => { + if (counter == 1 || this.loggeduser.Profile == 'PR') { + this.showLoader = false; + } }) - .finally(() => { - if (counter == 1 || this.loggeduser.Profile == 'PR') { + + } else { + + if(this.loggeduser.OwnerCalendars.length != 0) { + + this.eventService.getAllOwnEvents(momentG(new Date(startTime), 'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime), 'yyyy-MM-dd 23:59:59')).then((response: any) => { + + this.addEventToDB(response, "md"); + let eventsList = response; + + this.CalendarStore.removeRange(startTime, endTime, 'md') + + // loop + this.CalendarStore.pushEvent(eventsList, 'md'); + + this.listToPresent = this.CalendarStore.eventSource + + this.TimelineMDList = this.listBoxService.list(this.listToPresent, 'md', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) + + console.log('check list to present data', this.listToPresent); + this.myCal.update(); + this.myCal.loadEvents(); + + this.showTimelineMD = true; + + counter++; + if (counter == 2) { + this.showLoader = false; + } + + + }).catch((error) => { + this.getFromDB() + }).finally(() => { + counter++; + if (counter == 2) { this.showLoader = false; } }) + } else { + counter++; + if (counter == 2) { + this.showLoader = false; + } + } + + console.log(this.loggeduser.SharedCalendars) + + if(this.loggeduser.SharedCalendars.length != 0) { + + + this.eventService.genericGetAllSharedEvents(momentG(new Date(startTime), 'yyyy-MM-dd HH:mm:ss'), momentG(new Date(endTime), 'yyyy-MM-dd 23:59:59')).then((response: any) => { + + this.addEventToDB(response, "pr"); + let eventsList = response; + + // clear the current month only + this.CalendarStore.removeRange(startTime, endTime, 'pr') + + + this.CalendarStore.pushEvent(eventsList, 'pr'); + this.listToPresent = this.CalendarStore.eventSource + + + this.TimelinePRList = this.listBoxService.list(this.listToPresent, 'pr', this.rangeStartDate, this.rangeEndDate, { segment: this.segment, selectedDate: this.eventSelectedDate }) + + console.log('check list to present data', this.listToPresent); + + this.myCal.update(); + this.myCal.loadEvents(); + + this.showTimelinePR = true; + + counter++; + + if (counter == 2 || this.loggeduser.Profile == 'PR') { + this.showLoader = false; + } + + }).catch((error) => { + this.getFromDB() + }) + .finally(() => { + counter++; + if (counter == 2) { + this.showLoader = false; + } + }) + } else { + counter++; + if (counter == 2) { + this.showLoader = false; + } + } } @@ -751,21 +918,25 @@ export class AgendaPage implements OnInit { //Deve ser removido para ficar só um method transform trasnformDataDB(response) { - console.log('Transform ', response) - response.forEach(element => { - let event = { - startTime: new Date(element.StartDate), - endTime: new Date(element.EndDate), - allDay: false, - event: element, - calendarName: element.CalendarName, - profile: element.Profile, - id: element.EventId, - } - this.array.push(event) - }); - this.listToPresent = this.array; - console.log('LIST TO PRESET', this.listToPresent) + + if(response) { + console.log('Transform ', response) + response.forEach(element => { + let event = { + startTime: new Date(element.StartDate), + endTime: new Date(element.EndDate), + allDay: false, + event: element, + calendarName: element.CalendarName, + profile: element.Profile, + id: element.EventId, + } + this.array.push(event) + }); + this.listToPresent = this.array; + console.log('LIST TO PRESET', this.listToPresent) + } + } addEventToDB(response, profile) { diff --git a/src/app/pages/agenda/new-event/new-event.page.ts b/src/app/pages/agenda/new-event/new-event.page.ts index dd6468e00..7d35a4b12 100644 --- a/src/app/pages/agenda/new-event/new-event.page.ts +++ b/src/app/pages/agenda/new-event/new-event.page.ts @@ -14,7 +14,6 @@ import { AttendeesPageModal } from '../../events/attendees/attendees.page'; import { SearchPage } from '../../search/search.page'; import { ThemePalette } from '@angular/material/core'; import { FormControl, FormGroup, Validators } from '@angular/forms'; -import { EventRecurrence } from 'src/app/models/agenda/eventrecurrence.model'; import { ThemeService } from 'src/app/services/theme.service'; import { NgxMatDateFormats } from '@angular-material-components/datetime-picker'; import { NGX_MAT_DATE_FORMATS } from '@angular-material-components/datetime-picker'; @@ -315,6 +314,8 @@ export class NewEventPage implements OnInit { console.log(this.loggeduser.Profile); eventId = await this.eventService.postEventPr(this.postEvent, this.postEvent.CalendarName).toPromise(); + } else { + eventId = await this.eventService.postEventGeneric(this.postEvent, this.postEvent.CalendarName).toPromise(); } const DocumentToSave: EventAttachment[] = this.documents.map((e) => { diff --git a/src/app/pages/chat/group-messages/group-messages.page.ts b/src/app/pages/chat/group-messages/group-messages.page.ts index d10e4cf45..f36d72006 100644 --- a/src/app/pages/chat/group-messages/group-messages.page.ts +++ b/src/app/pages/chat/group-messages/group-messages.page.ts @@ -36,6 +36,7 @@ import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, Cur import { Filesystem, Directory, Encoding } from '@capacitor/filesystem'; import { DomSanitizer } from '@angular/platform-browser'; import { MessageService } from 'src/app/services/chat/message.service'; +import { AlertController } from '@ionic/angular'; @Component({ selector: 'app-group-messages', @@ -85,6 +86,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { durationDisplay = ''; duration = 0; showAvatar = true; + audioPermissionStatus: 'granted'| 'denied' | 'prompt' | null = null constructor( private menu: MenuController, @@ -111,6 +113,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { private processesService: ProcessesService, private CameraService: CameraService, private sanitiser: DomSanitizer, + private alertController: AlertController ) { this.loggedUserChat = authService.ValidatedUserChat['data']; this.isGroupCreated = true; @@ -296,15 +299,49 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy { } - startRecording() { - console.log('Recording'); + async checkAudioPermission() { + const permissionStatus = await navigator.permissions.query({ name: 'microphone' } as any) + + console.log('permission', permissionStatus.state); // granted, denied, prompt - if (this.recording) { - return; + this.audioPermissionStatus = permissionStatus.state + + permissionStatus.onchange = (data : any) => { + // console.log("Permission changed to " + data.state); + // console.log('permission', permissionStatus.state); // granted, denied, prompt } - this.recording = true; - VoiceRecorder.startRecording(); - this.calculateDuration(); + + } + + async startRecording() { + + await this.checkAudioPermission(); + + if(this.audioPermissionStatus == 'granted') { + if (this.recording) { + return; + } + + this.recording = true; + VoiceRecorder.startRecording(); + this.calculateDuration(); + } else { + + const alertPopup = await this.alertController.create({ + cssClass: 'my-custom-class', + header: 'Necessita de permissão para gravar áudio', + buttons: [{ + text: 'Ok', + handler: () => { + + } + }] + }); + + await alertPopup.present(); + + } + } diff --git a/src/app/pages/chat/messages/messages.page.ts b/src/app/pages/chat/messages/messages.page.ts index 3c2914b19..549ec7bd1 100644 --- a/src/app/pages/chat/messages/messages.page.ts +++ b/src/app/pages/chat/messages/messages.page.ts @@ -1,6 +1,6 @@ import { AfterViewChecked, AfterViewInit, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute, Router } from '@angular/router' -import { GestureController, Gesture, ModalController, NavParams, PopoverController, Platform } from '@ionic/angular'; +import { GestureController, Gesture, ModalController, NavParams, PopoverController, Platform, AlertController } from '@ionic/angular'; import { map } from 'rxjs/operators'; import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page'; import { EventPerson } from 'src/app/models/eventperson.model'; @@ -97,6 +97,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { downloadFile: any; downloadProgess: number; + audioPermissionStatus: 'granted'| 'denied' | 'prompt' | null = null + constructor( public popoverController: PopoverController, private modalController: ModalController, @@ -122,6 +124,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { private storage: Storage, private fileToBase64Service: FileToBase64Service, private sanitiser: DomSanitizer, + private alertController: AlertController ) { this.loggedUser = authService.ValidatedUserChat['data']; this.roomId = this.navParams.get('roomId'); @@ -143,6 +146,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { this.scrollToBottomClicked() }, 150) + } ngOnInit() { @@ -220,17 +224,49 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { } - startRecording() { - console.log('Recording'); - if (this.recording) { - return; + async checkAudioPermission() { + const permissionStatus = await navigator.permissions.query({ name: 'microphone' } as any) + + console.log('permission', permissionStatus.state); // granted, denied, prompt + + this.audioPermissionStatus = permissionStatus.state + + permissionStatus.onchange = (data : any) => { + // console.log("Permission changed to " + data.state); + // console.log('permission', permissionStatus.state); // granted, denied, prompt + } + + } + + async startRecording() { + + await this.checkAudioPermission(); + + if(this.audioPermissionStatus == 'granted') { + if (this.recording) { + return; + } + + this.recording = true; + VoiceRecorder.startRecording(); + this.calculateDuration(); + } else { + + const alertPopup = await this.alertController.create({ + cssClass: 'my-custom-class', + header: 'Necessita de permissão para gravar áudio', + buttons: [{ + text: 'Ok', + handler: () => { + + } + }] + }); + + await alertPopup.present(); + } - this.recording = true; - VoiceRecorder.startRecording() - .then((result: GenericResponse) => console.log(result.value)) - .catch(error => console.log(error)); - this.calculateDuration(); } stopRecording() { @@ -397,35 +433,42 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy { this.storage.get('recordData').then((recordData) => { audioFile = recordData; - if(recordData?.value?.recordDataBase64.includes('data:audio')){ - this.audioRecorded = recordData?.value?.recordDataBase64; - } - else{ - this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`; + + if(recordData?.value?.recordDataBase64) { + if(recordData.value.recordDataBase64.includes('data:audio')){ + this.audioRecorded = recordData.value.recordDataBase64; + } + else{ + this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`; + } + + console.log(this.audioRecorded); + + //Converting base64 to blob + const encodedData = btoa(this.audioRecorded); + const blob = this.base64toBlob(encodedData, recordData.value.mimeType) + console.log(blob) + const formData = new FormData(); + formData.append("blobFile", blob); + + this.wsChatMethodsService.getDmRoom(roomId).send({ + file: { + "type": "application/audio", + "msDuration":audioFile.value.msDuration, + "mimeType":audioFile.value.mimeType, + }, + attachments: [{ + "title": fileName , + "title_link_download": true, + "type": "audio" + }], + temporaryData: formData + }) + } else { + alert('no audio') } - console.log(this.audioRecorded); - - //Converting base64 to blob - const encodedData = btoa(this.audioRecorded); - const blob = this.base64toBlob(encodedData, recordData.value.mimeType) - console.log(blob) - const formData = new FormData(); - formData.append("blobFile", blob); - - this.wsChatMethodsService.getDmRoom(roomId).send({ - file: { - "type": "application/audio", - "msDuration":audioFile.value.msDuration, - "mimeType":audioFile.value.mimeType, - }, - attachments: [{ - "title": fileName , - "title_link_download": true, - "type": "audio" - }], - temporaryData: formData - }) + }); this.deleteRecording(); diff --git a/src/app/pages/inactivity/inactivity.page.ts b/src/app/pages/inactivity/inactivity.page.ts index 00dd852b0..a520405d6 100644 --- a/src/app/pages/inactivity/inactivity.page.ts +++ b/src/app/pages/inactivity/inactivity.page.ts @@ -178,7 +178,7 @@ export class InactivityPage implements OnInit { SessionStore.setInativity(true) this.goback() - setTimeout(()=>{ + setTimeout(() => { this.clearCode() }, 1000) @@ -194,16 +194,22 @@ export class InactivityPage implements OnInit { if(pathName) { this.router.navigate([pathName],{replaceUrl: true}); } else { - this.router.navigate(['/home/events'], {replaceUrl: true}); + + setTimeout(()=>{ + this.router.navigate(['/home/events'], {replaceUrl: true}); + }, 5000) + } } storePin() { - const code = this.code.join(''); - SessionStore.setPin(code); - this.router.navigate(['/home/events']); + setTimeout(()=>{ + const code = this.code.join(''); + SessionStore.setPin(code); + this.router.navigate(['/home/events']); + }, 5000) } diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts index a915cdc21..75492fc7e 100644 --- a/src/app/pages/login/login.page.ts +++ b/src/app/pages/login/login.page.ts @@ -123,11 +123,12 @@ export class LoginPage implements OnInit { await this.authService.SetSession(attempt, this.userattempt); this.changeProfileService.run(); + await this.authService.loginChat(); await this.authService.loginToChatWs(); this.getToken(); - this.router.navigateByUrl('/pin', { replaceUrl: true }); + this.router.navigateByUrl('/pin', { replaceUrl: true }); } } else{ @@ -155,7 +156,6 @@ export class LoginPage implements OnInit { this.router.navigate(['/home/chat']); } else if(this.permissionService.userPermission(this.permissionList.Actions.access)){ - alert('here') this.router.navigate(['/home/publications']); } } diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index f4f015d41..1f74f7174 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -97,9 +97,26 @@ export class AuthService { session.Profile = 'PR' } else if(session.RoleID == 100000011) { session.Profile = 'MDGPR' + } else if(session.RoleID == 99999872) { + session.Profile = 'Consultant' } - else{ - session.Profile = this.initialsService.getInitials(session.FullName); + else if(session.RoleID == 99999873) { + session.Profile = 'Assistant' + } + else if(session.RoleID == 99999874) { + session.Profile = 'Department boss' + } + else if(session.RoleID == 99999875) { + session.Profile = 'Director' + } + else if(session.RoleID == 99999876) { + session.Profile = 'Deputy Director' + } + else if(session.RoleID == 99999885) { + session.Profile = 'Secretariat' + } + else if(session.RoleID == 99999886) { + session.Profile = 'General secretary' } session.Password = user.password @@ -131,7 +148,7 @@ export class AuthService { let responseChat = await this.httpService.post('login', postData).toPromise(); if(responseChat) { - console.log('Login to Rocket chat OK', responseChat); + this.ValidatedUserChat = responseChat; localStorage.setItem('userChat', JSON.stringify(responseChat)); this.storageService.store(AuthConnstants.AUTH, responseChat); @@ -211,7 +228,7 @@ export class AuthService { this.NfService.downloadFileMsg = async (message: MessageService, room?: RoomService) => { - console.log('FILE TYPE', message.file.type) + // console.log('FILE TYPE', message.file.type) let downloadFile = ""; if (message.file.type == "application/img") { const event: any = await this.AttachmentsService.downloadFile(message.file.guid).toPromise(); @@ -220,7 +237,7 @@ export class AuthService { if (event.type === HttpEventType.DownloadProgress) { //this.downloadProgess = Math.round((100 * event.loaded) / event.total); - console.log('FILE TYPE 33', message.file.type) + // console.log('FILE TYPE 33', message.file.type) return true } else if (event.type === HttpEventType.Response) { downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); @@ -232,7 +249,7 @@ export class AuthService { } await this.storage.set(message.file.guid, downloadFile).then(() => { - console.log('IMAGE SAVED') + // console.log('IMAGE SAVED') }); return true } diff --git a/src/app/services/events.service.ts b/src/app/services/events.service.ts index c2fd4b9b6..55f95ba6e 100644 --- a/src/app/services/events.service.ts +++ b/src/app/services/events.service.ts @@ -28,9 +28,21 @@ export class EventsService { headersMdOficial: HttpHeaders; headersMdPessoal: HttpHeaders; + headerOwnOficial: HttpHeaders; + headersOwnPessoal: HttpHeaders; + + headerSharedOficial: HttpHeaders; + headerSharedPessoal: HttpHeaders; + headersSharedOficial: HttpHeaders; headersSharedPessoal: HttpHeaders; + hasSharedCalendar = false + hasOwnCalendar = false + + + calendarOwnerIds = [] + constructor( private http: HttpClient, public user: AuthService, @@ -51,6 +63,13 @@ export class EventsService { this.headersSharedPessoal = new HttpHeaders(); + this.headerOwnOficial= new HttpHeaders(); + this.headersOwnPessoal= new HttpHeaders(); + + this.headerSharedOficial= new HttpHeaders(); + this.headerSharedPessoal= new HttpHeaders(); + + this.setHeader() this.changeProfileService.registerCallback(() => { this.loggeduser = this.user.ValidatedUser; @@ -61,10 +80,23 @@ export class EventsService { setHeader() { + this.hasSharedCalendar = false + this.hasOwnCalendar = false + + + this.calendarOwnerIds = [] + if (this.loggeduser) { if (this.loggeduser.Profile == 'MDGPR') { this.loggeduser.OwnerCalendars.forEach(calendar => { + + if(!this.calendarOwnerIds.includes(calendar.OwnerUserId)) { + this.calendarOwnerIds.push(calendar.OwnerUserId) + } + + this.hasOwnCalendar = true + if (calendar.CalendarName == 'Oficial') { this.headersMdOficial = this.headersMdOficial.set('Authorization', this.loggeduser.BasicAuthKey); this.headersMdOficial = this.headersMdOficial.set('CalendarId', calendar.CalendarId); @@ -79,6 +111,13 @@ export class EventsService { }); this.loggeduser.SharedCalendars.forEach(sharedCalendar => { + + if(!this.calendarOwnerIds.includes(sharedCalendar.OwnerUserId)) { + this.calendarOwnerIds.push(sharedCalendar.OwnerUserId) + } + + this.hasSharedCalendar = true + if (sharedCalendar.CalendarName == 'Oficial') { this.headersSharedOficial = this.headersSharedOficial.set('Authorization', this.loggeduser.BasicAuthKey); this.headersSharedOficial = this.headersSharedOficial.set('CalendarId', sharedCalendar.CalendarId); @@ -94,6 +133,13 @@ export class EventsService { else if (this.loggeduser.Profile == 'PR') { this.loggeduser.OwnerCalendars.forEach(calendar => { + + if(!this.calendarOwnerIds.includes(calendar.OwnerUserId)) { + this.calendarOwnerIds.push(calendar.OwnerUserId) + } + + this.hasOwnCalendar = true + if (calendar.CalendarName == 'Oficial') { this.headersPrOficial = this.headersPrOficial.set('Authorization', this.loggeduser.BasicAuthKey); this.headersPrOficial = this.headersPrOficial.set('CalendarId', calendar.CalendarId); @@ -106,6 +152,52 @@ export class EventsService { } }); + } else { + + + this.loggeduser.OwnerCalendars.forEach(calendar => { + + if(!this.calendarOwnerIds.includes(calendar.OwnerUserId)) { + this.calendarOwnerIds.push(calendar.OwnerUserId) + } + this.hasOwnCalendar = true + + if (calendar.CalendarName == 'Oficial') { + this.headerOwnOficial = this.headerOwnOficial.set('Authorization', this.loggeduser.BasicAuthKey); + this.headerOwnOficial = this.headerOwnOficial.set('CalendarId', calendar.CalendarId); + this.headerOwnOficial = this.headerOwnOficial.set('CalendarRoleId', calendar.CalendarRoleId); + } + else if (calendar.CalendarName == 'Pessoal') { + this.headersOwnPessoal.set('Authorization', this.loggeduser.BasicAuthKey); + this.headersOwnPessoal.set('CalendarId', calendar.CalendarId); + this.headersOwnPessoal.set('CalendarRoleId', calendar.CalendarRoleId); + } + }); + + + for (let sharedCalendar of this.loggeduser.SharedCalendars) { + + + if(!this.calendarOwnerIds.includes(sharedCalendar.OwnerUserId)) { + this.calendarOwnerIds.push(sharedCalendar.OwnerUserId) + } + + this.hasSharedCalendar = true + + if (sharedCalendar.CalendarName == 'Oficial') { + this.headerSharedOficial = this.headerSharedOficial.set('Authorization', 'Basic '+sharedCalendar.CalendarToken); + this.headerSharedOficial = this.headerSharedOficial.set('CalendarId', sharedCalendar.CalendarId); + this.headerSharedOficial = this.headerSharedOficial.set('CalendarRoleId', sharedCalendar.CalendarRoleId); + } + else if (sharedCalendar.CalendarName == 'Pessoal') { + this.headerSharedPessoal = this.headerSharedPessoal.set('Authorization', 'Basic '+sharedCalendar.CalendarToken); + this.headerSharedPessoal = this.headerSharedPessoal.set('CalendarId', sharedCalendar.CalendarId); + this.headerSharedPessoal = this.headerSharedPessoal.set('CalendarRoleId', sharedCalendar.CalendarRoleId); + } + } + + console.log(this.loggeduser.SharedCalendars) + } this.headers = new HttpHeaders(); @@ -113,20 +205,6 @@ export class EventsService { } } - /* getAllEvents(startdate:string, enddate:string): Observable{ - const geturl = environment.apiURL + 'calendar/GetAllEvents'; - let params = new HttpParams(); - - params = params.set("StartDate", startdate); - params = params.set("EndDate", enddate); - - let options = { - headers: this.headers, - params: params - }; - return this.http.get(`${geturl}`, options); - } */ - getAllPrOficialEvents(startdate: string, enddate: string): Observable { let geturl = environment.apiURL + 'calendar/pr'; @@ -208,6 +286,93 @@ export class EventsService { }); } + + async getAllOwnEvents(startdate: string, enddate: string) { + let ownO = await this.getAllOwnOficialEvents(startdate, enddate).toPromise(); + let ownP = await this.getAllOwnPessoalEvents(startdate, enddate).toPromise(); + const resFinal = ownO.concat(ownP); + return new Promise(resolve => { + return resolve(resFinal) + }); + } + + getAllOwnOficialEvents(startdate: string, enddate: string): Observable { + let geturl = environment.apiURL + 'calendar/GetEvents'; + + let params = new HttpParams(); + + params = params.set("StartDate", startdate); + params = params.set("EndDate", enddate); + + + let options = { + headers: this.headerOwnOficial, + params: params + }; + return this.http.get(`${geturl}`, options); + } + + getAllOwnPessoalEvents(startdate: string, enddate: string): any { + let geturl = environment.apiURL + 'calendar/GetEvents'; + + let params = new HttpParams(); + + params = params.set("StartDate", startdate); + params = params.set("EndDate", enddate); + + let options = { + headers: this.headersOwnPessoal, + params: params + }; + return this.http.get(`${geturl}`, options) + } + + async genericGetAllSharedEvents(startdate: string, enddate: string) { + + let prO = await this.genericGetAllSharedOficialEvents(startdate, enddate).toPromise(); + let prP = await this.genericGetAllSharedPessoalEvents(startdate, enddate).toPromise(); + const resFinal = prO.concat(prP); + + return new Promise(resolve => { + return resolve(resFinal) + }); + } + + genericGetAllSharedOficialEvents(startdate: string, enddate: string): Observable { + let geturl = environment.apiURL + 'calendar/GetEvents'; + geturl = geturl.replace('/V4/', '/V5/') + + let params = new HttpParams(); + + params = params.set("StartDate", startdate); + params = params.set("EndDate", enddate); + + + + let options = { + headers: this.headerSharedOficial, + params: params + }; + + return this.http.get(`${geturl}`, options); + } + + genericGetAllSharedPessoalEvents(startdate: string, enddate: string): Observable { + let geturl = environment.apiURL + 'calendar/GetEvents'; + geturl = geturl.replace('/V4/', '/V5/') + + let params = new HttpParams(); + + params = params.set("StartDate", startdate); + params = params.set("EndDate", enddate); + + let options = { + headers: this.headerSharedPessoal, + params: params + }; + return this.http.get(`${geturl}`, options); + } + async getAllSharedEvents(startdate: string, enddate: string) { let prO = await this.getAllSharedOficialEvents(startdate, enddate).toPromise(); let prP = await this.getAllSharedPessoalEvents(startdate, enddate).toPromise(); @@ -328,6 +493,8 @@ export class EventsService { } else if (this.loggeduser.Profile == 'PR') { this.headers = this.headersPrOficial; + } else { + this.headers = this.headerOwnOficial } } else { @@ -337,6 +504,9 @@ export class EventsService { else if (this.loggeduser.Profile == 'PR') { this.headers = this.headersPrPessoal; } + else { + this.headers = this.headersOwnPessoal + } } let options = { @@ -361,21 +531,6 @@ export class EventsService { return this.http.post(`${puturl}`, body, options); } - /* postEvent(event:Event, calendarName:string, sharedagenda:string) - { - const puturl = environment.apiURL + 'calendar/' + ((sharedagenda != '') ? sharedagenda : 'PostEvent'); - let params = new HttpParams(); - - params = params.set("CalendarName", calendarName); - - let options = { - headers: this.headers, - params: params - }; - - return this.http.post(`${puturl}`, event, options) - } */ - postEventMd(event: Event, calendarName: string) { const puturl = environment.apiURL + 'calendar/md'; let params = new HttpParams(); @@ -432,6 +587,36 @@ export class EventsService { return this.http.post(`${puturl}`, event, options) } + + + postEventGeneric(event: Event, calendarName: string) { + const puturl = environment.apiURL + 'Calendar/PostEvent'; + let params = new HttpParams(); + + params = params.set("CalendarName", calendarName); + + let options: any; + + switch (calendarName) { + case 'Oficial': + options = { + headers: this.headerSharedOficial, + params: params + }; + break; + + case 'Pessoal': + + options = { + headers: this.headerSharedPessoal, + params: params + }; + break; + } + + return this.http.post(`${puturl}`, event, options) + } + deleteEvent(eventid: string, eventDeleteType: number, calendarName: string) { let arrayReq = []; let Object = { diff --git a/src/app/services/permission.service.ts b/src/app/services/permission.service.ts index a02dd401a..8cace4128 100644 --- a/src/app/services/permission.service.ts +++ b/src/app/services/permission.service.ts @@ -25,7 +25,7 @@ export class PermissionService { } - for(let permission of (this.SessionStore.user.UserPermissions || [])) { + for(let permission of ([...(this.SessionStore.user.UserPermissions || [] ), 530] || [])) { if (args.includes(permission)) { return true; } diff --git a/src/app/shared/agenda/new-event/new-event.page.ts b/src/app/shared/agenda/new-event/new-event.page.ts index 612b59506..bd7e3d0ac 100644 --- a/src/app/shared/agenda/new-event/new-event.page.ts +++ b/src/app/shared/agenda/new-event/new-event.page.ts @@ -448,6 +448,39 @@ export class NewEventPage implements OnInit { } this.toastService.successMessage('Evento criado') }); + } else { + this.eventService.postEventGeneric(this.postEvent, this.postEvent.CalendarName).subscribe( + (id) => { + console.log(id); + + const eventId: any = id; + + const DocumentToSave: EventAttachment[] = this.documents.map((e) => { + return { + SourceTitle: e.Assunto, + ParentId: eventId, + Source: '1', + SourceId: e.Id, + ApplicationId: e.ApplicationType.toString(), + Id: '', + Link: '', + SerialNumber: '' + }; + }); + + DocumentToSave.forEach((attachments, i) => { + this.attachmentsService.setEventAttachmentById(attachments).subscribe((res) =>{ + if(DocumentToSave.length == (i+1)){ + this.afterSave(); + } + }); + }); + + if(DocumentToSave.length == 0){ + this.afterSave(); + } + this.toastService.successMessage('Evento criado') + }); } } diff --git a/src/app/shared/chat/group-messages/group-messages.page.ts b/src/app/shared/chat/group-messages/group-messages.page.ts index 829ce53d3..5c0223cfb 100644 --- a/src/app/shared/chat/group-messages/group-messages.page.ts +++ b/src/app/shared/chat/group-messages/group-messages.page.ts @@ -36,6 +36,7 @@ import { Camera, CameraResultType, CameraSource } from '@capacitor/camera'; import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, CurrentRecordingStatus } from 'capacitor-voice-recorder'; import { Filesystem, Directory, Encoding } from '@capacitor/filesystem'; import { DomSanitizer } from '@angular/platform-browser'; +import { AlertController, Platform, NavParams } from '@ionic/angular'; /* import * as pdfjsLib from 'pdfjs-dist'; @@ -99,6 +100,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe durationDisplay = ''; duration = 0; + audioPermissionStatus: 'granted'| 'denied' | 'prompt' | null = null + constructor( public wsChatMethodsService: WsChatMethodsService, private modalController: ModalController, @@ -121,6 +124,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe private CameraService: CameraService, private toastService: ToastService, private sanitiser: DomSanitizer, + private alertController: AlertController ) { console.log('OnCONSTRUCTOR'); @@ -293,15 +297,49 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe } - startRecording() { - console.log('Recording'); + async checkAudioPermission() { + const permissionStatus = await navigator.permissions.query({ name: 'microphone' } as any) + + console.log('permission', permissionStatus.state); // granted, denied, prompt - if (this.recording) { - return; + this.audioPermissionStatus = permissionStatus.state + + permissionStatus.onchange = (data : any) => { + // console.log("Permission changed to " + data.state); + // console.log('permission', permissionStatus.state); // granted, denied, prompt } - this.recording = true; - VoiceRecorder.startRecording(); - this.calculateDuration(); + + } + + async startRecording() { + + await this.checkAudioPermission(); + + if(this.audioPermissionStatus == 'granted') { + if (this.recording) { + return; + } + + this.recording = true; + VoiceRecorder.startRecording(); + this.calculateDuration(); + } else { + + const alertPopup = await this.alertController.create({ + cssClass: 'my-custom-class', + header: 'Necessita de permissão para gravar áudio', + buttons: [{ + text: 'Ok', + handler: () => { + + } + }] + }); + + await alertPopup.present(); + + } + } stopRecording() { @@ -331,7 +369,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe }, 1000); } - async deleteRecording(){ + async deleteRecording() { this.storage.remove('fileName'); this.storage.remove('recordData'); diff --git a/src/app/shared/chat/messages/messages.page.html b/src/app/shared/chat/messages/messages.page.html index 7ec469275..07cd8a8d4 100644 --- a/src/app/shared/chat/messages/messages.page.html +++ b/src/app/shared/chat/messages/messages.page.html @@ -232,6 +232,7 @@