mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
Merge remote-tracking branch 'origin/feature/pushNotifications' into developer
This commit is contained in:
+152
-28
@@ -3,10 +3,16 @@ import { EventsService } from '../services/events.service';
|
||||
import { formatDate } from '@angular/common';
|
||||
import { Event } from '../models/event.model';
|
||||
import { ProcessesService } from '../services/processes.service';
|
||||
import { StorageService } from 'src/app/services/storage.service';
|
||||
import { ModalController } from '@ionic/angular';
|
||||
import { PublicationDetailPage } from '../../app/pages/publications/view-publications/publication-detail/publication-detail.page';
|
||||
import { ViewPublicationsPage } from '../../app/pages/publications/view-publications/view-publications.page';
|
||||
|
||||
import { Plugins, PushNotification,PushNotificationToken,PushNotificationActionPerformed} from '@capacitor/core';
|
||||
import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed, Modals } from '@capacitor/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { MethodCall } from '@angular/compiler';
|
||||
|
||||
const { PushNotifications } = Plugins;
|
||||
const { PushNotifications, LocalNotifications } = Plugins;
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
@@ -18,61 +24,179 @@ export class HomePage implements OnInit {
|
||||
prEventList: Event[];
|
||||
mdEventList: Event[];
|
||||
|
||||
totalEvent=0;
|
||||
totalExpediente=0;
|
||||
profile:string;
|
||||
totalEvent = 0;
|
||||
totalExpediente = 0;
|
||||
profile: string;
|
||||
|
||||
constructor(private eventService: EventsService, private processesbackend:ProcessesService) { }
|
||||
constructor(private eventService: EventsService, private processesbackend: ProcessesService, private router: Router, private modalController: ModalController,) { }
|
||||
|
||||
ngOnInit() {
|
||||
//Initialize profile as mdgpr
|
||||
this.profile = "mdgpr";
|
||||
if(this.profile == "mdgpr"){
|
||||
if (this.profile == "mdgpr") {
|
||||
this.eventService.getAllMdEvents(formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss', 'pt'), formatDate(new Date(), 'yyyy-MM-dd', 'pt') + ' 23:59:59').subscribe(res => {
|
||||
this.eventsList = res;
|
||||
this.totalEvent = this.eventsList.length;
|
||||
});
|
||||
});
|
||||
}
|
||||
else{
|
||||
else {
|
||||
this.eventService.getAllPrEvents(formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss', 'pt'), formatDate(new Date(), 'yyyy-MM-dd', 'pt') + ' 23:59:59').subscribe(res => {
|
||||
this.eventsList = res;
|
||||
this.totalEvent = this.eventsList.length;
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
this.processesbackend.GetTasksList("Expediente", true).subscribe(result =>{
|
||||
this.processesbackend.GetTasksList("Expediente", true).subscribe(result => {
|
||||
this.totalExpediente = result;
|
||||
});
|
||||
/*
|
||||
(PushNotifications as any).requestPermission().then(result => {
|
||||
PushNotifications.register();
|
||||
});
|
||||
|
||||
PushNotifications.addListener(
|
||||
'registration',
|
||||
(token: PushNotificationToken) => {
|
||||
alert('Push registration success, token: ' + token.value);
|
||||
console.log('FIREBASE: ', token.value)
|
||||
this.storageService.store(this.username,token.value);
|
||||
},
|
||||
);
|
||||
|
||||
console.log(this.storageService.get(this.username)) */
|
||||
|
||||
(PushNotifications as any).requestPermission().then(result => {
|
||||
PushNotifications.register();
|
||||
});
|
||||
|
||||
PushNotifications.addListener(
|
||||
'registration',
|
||||
(token: PushNotificationToken) => {
|
||||
/* alert('Push registration success, token: ' + token.value); */
|
||||
console.log('FIREBASE: ', token.value)
|
||||
},
|
||||
);
|
||||
|
||||
PushNotifications.addListener('registrationError', (error: any) => {
|
||||
alert('Error on registration: ' + JSON.stringify(error));
|
||||
});
|
||||
|
||||
|
||||
PushNotifications.addListener(
|
||||
'pushNotificationReceived',
|
||||
(notification: PushNotification) => {
|
||||
alert('Push received: ' + JSON.stringify(notification));
|
||||
//alert('Push received: ' + JSON.stringify(notification));
|
||||
//this.localNotificationPresent(notification);
|
||||
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
PushNotifications.addListener(
|
||||
'pushNotificationActionPerformed',
|
||||
(notification: PushNotificationActionPerformed) => {
|
||||
alert('Push action performed: ' + JSON.stringify(notification));
|
||||
let service = notification.notification.data.service;
|
||||
|
||||
let object = notification.notification.data.object;
|
||||
let idObject = notification.notification.data.idObject;
|
||||
let folder = notification.notification.data.folder;
|
||||
let publicationId = notification.notification.data.publicationId;
|
||||
let processId = notification.notification.data.processId;
|
||||
|
||||
console.log('FOLDER PROCESS', folder.ProcessId)
|
||||
|
||||
if (service != null) {
|
||||
|
||||
if (service === "events") {
|
||||
this.router.navigate(['/home/', service, idObject, 'home']);
|
||||
} else if (service === "agenda") {
|
||||
this.router.navigate(['/home/', service, idObject, 'home']);
|
||||
} else if (service === "gabinete-digital") {
|
||||
this.router.navigate(['/home/', service]);
|
||||
} else if (service === "gabinete-digital-expediente") {
|
||||
this.router.navigate(['/home/gabinete-digital/', object, idObject]);
|
||||
}
|
||||
} else {
|
||||
|
||||
if (processId || publicationId != null) {
|
||||
this.viewPublicationDetail(processId, publicationId)
|
||||
}
|
||||
|
||||
if (notification.notification.data.folder.ProcessId != null) {
|
||||
this.viewPublications(folder)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*switch (service) {
|
||||
case "events":
|
||||
this.router.navigate(['/home/', service, idObject, 'home']);
|
||||
break;
|
||||
case "agenda":
|
||||
this.router.navigate(['/home/', service, idObject, 'home']);
|
||||
break;
|
||||
case "gabinete-digital":
|
||||
this.router.navigate(['/home/', service]);
|
||||
break;
|
||||
case "gabinete-digital-expediente":
|
||||
this.router.navigate(['/home/gabinete-digital/', object, idObject, 'home']);
|
||||
break;
|
||||
case "": {
|
||||
|
||||
if(publicationId && processId != null) {
|
||||
this.viewPublicationDetail(publicationId,processId)
|
||||
}
|
||||
if (folder.ProcessId != null) {
|
||||
this.viewPublications(folder)
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
this.router.navigate(['/home/']);
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async localNotificationPresent(notification) {
|
||||
|
||||
LocalNotifications.schedule({
|
||||
notifications: [
|
||||
{
|
||||
title: notification.title,
|
||||
body: notification.body,
|
||||
id: 1,
|
||||
schedule: { at: new Date(Date.now() + 1000) },
|
||||
sound: null,
|
||||
attachments: null,
|
||||
actionTypeId: "",
|
||||
extra: null
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
async viewPublicationDetail(processId: string, publicationId: string) {
|
||||
const modal = await this.modalController.create({
|
||||
component: PublicationDetailPage,
|
||||
componentProps: {
|
||||
publicationId: publicationId,
|
||||
folderId: processId,
|
||||
},
|
||||
cssClass: 'publication-detail',
|
||||
backdropDismiss: false
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss();
|
||||
}
|
||||
|
||||
async viewPublications(folder) {
|
||||
|
||||
const modal = await this.modalController.create({
|
||||
component: ViewPublicationsPage,
|
||||
/* enterAnimation,
|
||||
leaveAnimation, */
|
||||
componentProps: {
|
||||
item: folder,
|
||||
},
|
||||
cssClass: 'new-action',
|
||||
backdropDismiss: false
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
export class Token {
|
||||
UserId: number;
|
||||
TokenId: string;
|
||||
Status: number;
|
||||
Service: number
|
||||
}
|
||||
@@ -8,6 +8,14 @@ import { AlertController } from '@ionic/angular';
|
||||
import { StorageService } from 'src/app/services/storage.service';
|
||||
import { AuthConnstants } from 'src/app/config/auth-constants';
|
||||
import { PhotoService } from 'src/app/services/photo.service';
|
||||
import { NotificationsService } from 'src/app/services/notifications.service';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { Token } from '../../models/token.model';
|
||||
|
||||
import { Plugins, PushNotification, PushNotificationToken, PushNotificationActionPerformed } from '@capacitor/core';
|
||||
|
||||
const { PushNotifications } = Plugins;
|
||||
|
||||
|
||||
|
||||
@Component({
|
||||
@@ -23,7 +31,9 @@ export class LoginPage implements OnInit {
|
||||
userattempt: User;
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private http: HttpClient,
|
||||
private notificatinsservice: NotificationsService,
|
||||
private router: Router,
|
||||
private authService: AuthService,
|
||||
private storageService: StorageService,
|
||||
private toastService: ToastService,
|
||||
@@ -31,17 +41,17 @@ export class LoginPage implements OnInit {
|
||||
public alertController: AlertController) { }
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
|
||||
}
|
||||
//Function to validade the login inputs
|
||||
validateInput(){
|
||||
validateInput() {
|
||||
return (
|
||||
this.username.trim().length > 0
|
||||
this.username.trim().length > 0
|
||||
&& this.password.trim().length > 0
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
async presentAlert(message:string) {
|
||||
async presentAlert(message: string) {
|
||||
const alert = await this.alertController.create({
|
||||
cssClass: 'my-custom-class',
|
||||
header: 'Mensagem do sistema',
|
||||
@@ -52,54 +62,89 @@ export class LoginPage implements OnInit {
|
||||
await alert.present();
|
||||
}
|
||||
|
||||
loginRocketChat(user:any){
|
||||
|
||||
loginRocketChat(user: any) {
|
||||
|
||||
let postData = {
|
||||
"user": user.username,
|
||||
"password": user.password,
|
||||
}
|
||||
this.authService.loginChat(postData).subscribe((res: any) =>{
|
||||
this.authService.loginChat(postData).subscribe((res: any) => {
|
||||
console.log(res.data);
|
||||
this.storageService.store(AuthConnstants.AUTH, res.data);
|
||||
console.log('Login to Rocket chat OK');
|
||||
},(error:any) =>{
|
||||
}, (error: any) => {
|
||||
console.log('Network error');
|
||||
this.presentAlert('Network error '+error);
|
||||
this.presentAlert('Network error ' + error);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
async Login(){
|
||||
try {
|
||||
//Go to our home in home/feed.
|
||||
//this.router.navigate(['/home/events']);
|
||||
if(this.validateInput()){
|
||||
this.userattempt = {
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
domainName: environment.domain,
|
||||
BasicAuthKey: ""
|
||||
}
|
||||
if (await this.authService.login(this.userattempt)){
|
||||
console.log(this.userattempt);
|
||||
|
||||
this.loginRocketChat(this.userattempt);
|
||||
this.router.navigate(['/home/events']);
|
||||
}
|
||||
else
|
||||
{
|
||||
//this.toastService.presentToast('Não foi possível fazer login"');
|
||||
this.presentAlert('O nome de utilizador e palavra-passe estão incorretas ou verifique a sua conexão com a internet e volte a tentar.');
|
||||
}
|
||||
storeUserIdANdToken() {
|
||||
|
||||
(PushNotifications as any).requestPermission().then(result => {
|
||||
PushNotifications.register();
|
||||
});
|
||||
|
||||
PushNotifications.addListener(
|
||||
'registration',
|
||||
(token: PushNotificationToken) => {
|
||||
console.log('FIREBASE TOKEN', token.value)
|
||||
this.storageService.store(this.username, token.value);
|
||||
this.storageService.get(this.username).then(value => {
|
||||
console.log('STORAGE TOKEN', value)
|
||||
this.storageService.get(AuthConnstants.USER).then(res => {
|
||||
console.log('USERID', res);
|
||||
const headers = { 'Authorization': 'Basic cGF1bG8ucGludG9AZ2FiaW5ldGVkaWdpdGFsLmxvY2FsOnRhYnRlc3RlQDAwNg==' };
|
||||
const body = { UserId: res,
|
||||
TokenId: token.value,
|
||||
Status: 1,
|
||||
Service: 1 };
|
||||
|
||||
this.http.post<Token>('https://equilibrium.dyndns.info/GabineteDigital.Services/V4/api/notifications/token', body,{headers}).subscribe(data => {
|
||||
console.log('TOKEN USER MIDLE', data);
|
||||
})
|
||||
/*this.http.get<Token>('http://gpr-dev-01.gabinetedigital.local/GabineteDigital.Services/V4/api/notifications/user/'+res).subscribe(data => {
|
||||
console.log('TOKEN USER MIDLE',data);
|
||||
})*/
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
},
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
async Login() {
|
||||
/* try { */
|
||||
//Go to our home in home/feed.
|
||||
//this.router.navigate(['/home/events']);
|
||||
if (this.validateInput()) {
|
||||
this.userattempt = {
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
domainName: environment.domain,
|
||||
BasicAuthKey: ""
|
||||
}
|
||||
if (await this.authService.login(this.userattempt)) {
|
||||
/* this.loginRocketChat(); */
|
||||
this.storeUserIdANdToken()
|
||||
|
||||
this.router.navigate(['/home/events']);
|
||||
}
|
||||
else {
|
||||
//this.toastService.presentToast('Não foi possível fazer login"');
|
||||
this.presentAlert('O nome de utilizador e palavra-passe estão incorretas ou verifique a sua conexão com a internet e volte a tentar.');
|
||||
}
|
||||
else{
|
||||
//this.toastService.presentToast('Preencha todos campos');
|
||||
this.presentAlert('Por favor, insira o seu nome de utilizador e palavra-passe.');
|
||||
}
|
||||
} catch (error) {
|
||||
error
|
||||
this.presentAlert('Ocorreu um erro ao fazer login. Contacte o administrador de sistema. ');
|
||||
}
|
||||
else {
|
||||
//this.toastService.presentToast('Preencha todos campos');
|
||||
this.presentAlert('Por favor, insira o seu nome de utilizador e palavra-passe.');
|
||||
}
|
||||
/* } catch (error) {
|
||||
error
|
||||
this.presentAlert('Ocorreu um erro ao fazer login. Contacte o administrador de sistema. '+ error);
|
||||
} */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NotificationsService } from './notifications.service';
|
||||
|
||||
describe('NotificationsService', () => {
|
||||
let service: NotificationsService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(NotificationsService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||
import { environment } from 'src/environments/environment';
|
||||
import { Token } from '../models/token.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class NotificationsService {
|
||||
|
||||
constructor(private http: HttpClient,) { }
|
||||
|
||||
getTokenByUserIdAndId(user, userID) {
|
||||
const geturl = environment.apiURL + 'notifications/user/' + userID;
|
||||
|
||||
return this.http.get<Token[]>(`${geturl}`);
|
||||
}
|
||||
|
||||
postToken(userId, token) {
|
||||
const geturl = environment.apiURL + 'notifications/token';
|
||||
|
||||
let data = {
|
||||
UserId: userId,
|
||||
TokenId: token,
|
||||
Status: 1,
|
||||
Service: 2
|
||||
}
|
||||
return this.http.post<Token[]>(`${geturl}`,data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user