Merge with peter changes

This commit is contained in:
Eudes Inácio
2021-08-30 15:00:44 +01:00
37 changed files with 560 additions and 208 deletions
-31
View File
@@ -1,31 +0,0 @@
import { Injectable } from '@angular/core';
import { Network } from '@ionic-native/network/ngx';
import { Platform } from '@ionic/angular';
import { fromEvent, merge, of, Observable } from 'rxjs';
import { mapTo } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class NetworkService {
constructor(
private network: Network) { }
checkNetworkConnection(){
this.network.onConnect().subscribe((value) => {
document.body.style.setProperty(`--color`, "#0782C9");
console.log('network connected!',value);
});
}
checkNetworkDisconnection(){
this.network.onDisconnect().subscribe((value) => {
document.body.style.setProperty(`--color`, "#eeeb30");
console.log('network was disconnected :-('),value;
});
}
}
+18 -8
View File
@@ -13,6 +13,7 @@ import { NavigationExtras,Router } from '@angular/router';
import { ToastService } from '../services/toast.service';
import { Optional } from '@angular/core';
import { JsonStore } from './jsonStore.service';
import { synchro } from './socket/synchro.service';
@Injectable({
providedIn: 'root'
@@ -39,15 +40,17 @@ export class NotificationsService {
private toastService: ToastService,
private zone: NgZone,
private activeroute: ActivatedRoute,
private jsonstore: JsonStore) {
private jsonstore: JsonStore) { }
registerCallback(type: string, funx: Function, object: any = {} ) {
this.callbacks.push({type, funx})
if(!object.hasOwnProperty('desktop') && object['desktop'] != false) {
synchro.registerCallback('Notification',funx, type)
}
}
registerCallback(type: string, funx: Function ) {
this.callbacks.push({type, funx})
}
getTokenByUserIdAndId(user, userID) {
const geturl = environment.apiURL + 'notifications/user/' + userID;
@@ -168,9 +171,13 @@ export class NotificationsService {
console.log('Push notification recived: failure ' + error.responseText);
console.log(JSON.stringify(error));
}
);
)
} else {
console.log('not called')
}
}
} else {
console.log('not called')
}
}
@@ -216,6 +223,9 @@ export class NotificationsService {
console.log(message);
var data = JSON.parse(message.payload);
synchro.$send(data)
console.log('data.Service', data.Service); // module
console.log('data.IdObject', data.IdObject); // Object id
console.log('data.Object', data.Object); // details
@@ -1,16 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { NetworkService } from './network.service';
import { ObjectQueryService } from './object-query.service';
describe('NavigationService', () => {
let service: NetworkService;
describe('ObjectQueryService', () => {
let service: ObjectQueryService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(NetworkService);
service = TestBed.inject(ObjectQueryService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
});
+60
View File
@@ -0,0 +1,60 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class ObjectQueryService {
data : any[] = []
save: Function = () =>{}
constructor() {}
Update(select:Function, update:Function, data: any[] = this.data ) {
let changes = 0
data.forEach((e)=> {
if(select(e)) {
changes++
update(e)
}
})
if(changes != 0) {
this.save()
}
}
select(select:Function, data: any[] = this.data ) {
return data.filter((e)=>{
return select(e)
})
}
Delete(select:Function, data: any[] = this.data) {
let changes = 0
data.forEach((e, index)=>{
if(select(e)) {
if (index > -1) {
changes++
data.splice(index, 1);
}
}
})
if(changes != 0) this.save()
}
Insert(inert:any, data: any[] = this.data ) {
data.push(inert)
}
print() {
console.log(this.data)
}
}
+3 -2
View File
@@ -8,6 +8,7 @@ import { DocumentSetUpMeeting } from '../models/CallMeeting';
import { Excludetask } from '../models/Excludetask';
import { ExpedienteFullTask } from '../models/Expediente';
import { GetTasksListType } from '../models/GetTasksListType';
import { fullTaskList } from '../models/dailyworktask.model';
@Injectable({
providedIn: 'root'
@@ -24,7 +25,7 @@ export class ProcessesService {
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
}
GetTasksList(processname: typeof GetTasksListType, onlycount:boolean): Observable<any>
GetTasksList(processname: typeof GetTasksListType, onlycount:boolean): Observable<fullTaskList[]>
{
const geturl = environment.apiURL + 'tasks/List';
let params = new HttpParams();
@@ -37,7 +38,7 @@ export class ProcessesService {
params: params
};
return this.http.get<any>(`${geturl}`, options);
return this.http.get<fullTaskList[]>(`${geturl}`, options);
}
GetTaskListExpediente(onlycount1): Observable<ExpedienteFullTask[]> {
+69 -13
View File
@@ -1,6 +1,8 @@
import { Injectable } from '@angular/core';
import { SessionStore } from 'src/app/store/session.service';
import { v4 as uuidv4 } from 'uuid'
import { BackgroundService } from '../background.service';
import { environment } from 'src/environments/environment';
export interface wss{
@@ -17,7 +19,7 @@ export interface wss{
@Injectable({
providedIn: 'root'
})
export class SynchroService {
class SynchroService {
[x: string]: any;
private connection!: WebSocket;
@@ -27,10 +29,12 @@ export class SynchroService {
callback = function(){}
private _connected = false;
private BackgroundService = new BackgroundService()
private callBacks: {
type: 'Offline' | 'Online'
callBacks: {
type: 'Offline' | 'Online' | 'Onmessage' | 'Chat' | 'Notification' | 'Notifications' | '',
object?: string
funx: Function
}[] = []
private msgQueue = []
constructor(){}
@@ -55,10 +59,11 @@ export class SynchroService {
this.url = `${wss.url}${wss.header.id}/${wss.header.jwt}/${wss.header.bluePrint}/${this.id}/`
}
registerCallback(type: 'Offline' | 'Online', funx: Function) {
registerCallback(type: 'Offline' | 'Online' | 'Onmessage' | 'Chat' | 'Notifications' | 'Notification', funx: Function, object='') {
this.callBacks.push({
type,
funx
funx,
object
})
}
@@ -85,22 +90,72 @@ export class SynchroService {
console.log('open ======================= welcome to socket server')
this._connected = true
// send all saved data due to internet connection
this.msgQueue.forEach((item, index, object) => {
this.$send(item);
object.splice(index, 1);
})
}
public $send(object: any) {
let message = {
message: '{"person.adress.country":"1Angola"}',
username: '',
idConnection: this.id
if(!this._connected) { // save data to send when back online
this.msgQueue.push(object)
}
let sendData = JSON.stringify(Object.assign({}, message));
let payload = {
message: JSON.stringify(object) || '{"person.adress.country":"1Angola"}',
username: SessionStore.user.FullName,
idConnection: this.id
}
let sendData = JSON.stringify(payload);
console.log(sendData)
this.connection.send(sendData);
}
private onmessage = async (event: any)=> {
let data = JSON.parse(event.data)
let payload = JSON.parse(data.message)
payload.message = JSON.parse(payload.message)
const idConnection = payload.idConnection
const username = payload.username
if(idConnection != this.id ) {
if(window['platform'].is('desktop') || this.platform.is('mobileweb')) {}
else return false
if(environment.production) return false
this.callBacks.forEach((e)=> {
if(payload.message[0]) {
if(payload.message[0].Service && payload.message[0].Object && payload.message[0].IdObject) {
if(e.type == '' && !e.object) {
if(username == SessionStore.user.FullName) {
e.funx(payload.message, data)
}
}
if(e.type == 'Notifications' ) {
e.funx(payload.message, data)
}
}
} else if(payload.message.Service && payload.message.Object && payload.message.IdObject) {
if(e.type == 'Notification' && e.object == payload.message.Object || e.type == 'Notification' && e.object == 'any' ) {
e.funx(payload.message, data)
}
}
})
}
this.callback()
}
@@ -137,7 +192,8 @@ export class SynchroService {
}
export const connection = new SynchroService()
connection.setUrl()
connection.connect()
export const synchro = new SynchroService()
synchro.setUrl()
synchro.connect()
window['synchro'] = synchro