git pull made

This commit is contained in:
Eudes Inácio
2021-09-07 12:18:12 +01:00
148 changed files with 1885 additions and 2257 deletions
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { ListBoxService } from './list-box.service';
describe('ListBoxService', () => {
let service: ListBoxService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ListBoxService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -0,0 +1,205 @@
import { Injectable } from '@angular/core';
import { CustomCalendarEvent, EventListStore } from 'src/app/models/agenda/AgendaEventList';
import { DateService } from '../date.service';
@Injectable({
providedIn: 'root'
})
export class ListBoxService {
constructor(
private dateService: DateService
){}
filterProfile(eventSource: EventListStore[], profile: 'md' | 'pr' | 'all') {
return eventSource.filter((e) => e.profile == profile)
}
getEventInsideRange(eventSource: EventListStore[], rangeStartDate, randEndDate) {
return eventSource.filter((e)=> {
if(new Date(rangeStartDate).getTime() <= new Date(e.startTime).getTime() &&
new Date(randEndDate).getTime() >= new Date(e.endTime).getTime()) {
return true
}
return false
})
}
filterSegment(eventSource: EventListStore[], segment): EventListStore[] {
return eventSource.filter( data => data.calendarName == segment)
}
daysBetween(){ }
list(eventSource: EventListStore[], profile: 'md' | 'pr' | 'all', rangeStartDate, randEndDate, {segment = 'Combinado', selectedDate= null}) {
// filter range
if(selectedDate) {
eventSource = eventSource.filter(data =>
data.startTime.toLocaleDateString('pt')>= selectedDate.toLocaleDateString('pt') &&
data.endTime.toLocaleDateString('pt')>= selectedDate.toLocaleDateString('pt')
)
}
if(segment!='Combinado') {
eventSource = this.filterSegment(eventSource, segment)
}
if(profile != 'all') {
eventSource = this.filterProfile(eventSource, profile)
}
let newStracture:CustomCalendarEvent[];
if(profile == 'md') {
newStracture = this.encapsulation(eventSource, 'mdgpr');
} else {
newStracture = this.encapsulation(eventSource, 'pr');
}
return this.display(newStracture, profile, selectedDate)
}
display(list: CustomCalendarEvent[], profile, selectedDate) {
let days = {};
list.forEach( (event:CustomCalendarEvent, index)=> {
var startDate: any = new Date(event.start);
var endDate: any = this.dateService.EventEndDateTreatment({
startTime: startDate,
endTime: event.end
})
const day = this.dateService.getDay(event.start)
event['manyDays'] = false
event['todayOnly'] = this.dateService.isSameDate(event.start, event.end)
if(!days.hasOwnProperty(day)) {
days[day] = []
}
if (this.dateService.notSameDate(startDate, endDate)) {
const diffDays = this.dateService.deferenceBetweenDays(endDate, startDate)
if (diffDays <= 150 && !event.event.IsAllDayEvent ) {
if (diffDays >= 1) {
const StartEvent = this.transForm(event, {startMany: true,endMany: false, middle: false, profile})
if(this.push(event, selectedDate)) days[day].push(StartEvent)
let i = 1;
// create event between date
while (startDate.getFullYear() != endDate.getFullYear() ||
startDate.getMonth() != endDate.getMonth() ||
startDate.getDate() != endDate.getDate()) {
const newDate = startDate.setDate(startDate.getDate()+ i)
let otherDays = this.dateService.getDay(newDate)
event['other'] = true
event.start = newDate
if(!days.hasOwnProperty(otherDays)) {
days[otherDays] = []
}
if (!(startDate.getFullYear() != endDate.getFullYear() ||
startDate.getMonth() != endDate.getMonth() ||
startDate.getDate() != endDate.getDate())) {
// last push
const EndEvent = this.transForm(event, {startMany: false,endMany: true, middle: false, profile})
if(this.push(event, selectedDate)) days[otherDays].push(EndEvent)
} else {
const EndEvent = this.transForm(event, {startMany: false,endMany: true, middle: true, profile})
if(this.push(event, selectedDate)) days[otherDays].push(EndEvent)
}
}
} else {
if(this.push(event, selectedDate)) days[day].push(event)
}
} else {
if(this.push(event, selectedDate)) days[day].push(event)
}
}
if(this.push(event, selectedDate)) days[day].push(event)
})
// remove days that haven't event
Object.entries(days).forEach(([index, value]) => {
const _value: any = value
if(_value.length == 0) {
delete days[index]
}
})
return days
}
push(event: any, selectedDate: Date) {
return new Date(event.start).getMonth() == selectedDate.getMonth() &&
new Date(event.start).getFullYear() == selectedDate.getFullYear()
}
encapsulation(eventsList:EventListStore[], profile): CustomCalendarEvent[] {
// remove all event
let events: CustomCalendarEvent[] = [];
eventsList.forEach((element, eventIndex) => {
events.push({
start: new Date(element.startTime),
end: new Date(element.endTime),
id: element.id,
event: element.event,
});
});
return events;
}
transForm(event: CustomCalendarEvent, {startMany, endMany, middle, profile}) {
return Object.assign({}, {
start: event.start,
end: event.end,
id: event.id,
profile: profile,
event: {
Subject: event.event.Subject,
StartDate: event.event.StartDate,
EndDate: event.event.EndDate,
Location: event.event.Location,
EventId: event.event.EventId,
CalendarName: event.event.CalendarName
},
Subject: event.event.Subject,
startMany: false,
endMany: true,
middle: true
})
}
}
+1 -1
View File
@@ -41,7 +41,7 @@ export class AuthService {
}
async login(user: UserForm, saveSession = true): Promise<LoginUserRespose> {
async login(user: UserForm, {saveSession = true}): Promise<LoginUserRespose> {
user.BasicAuthKey = 'Basic ' + btoa(user.username + ':' + this.aesencrypt.encrypt(user.password,user.username ));
this.headers = this.headers.set('Authorization',user.BasicAuthKey);
+1 -1
View File
@@ -99,7 +99,7 @@ export class ChatService {
let opts = {
headers: this.headers,
params: params
params: params,
}
return this.http.get(environment.apiChatUrl+'im.history', opts);
}
+16
View File
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { DateService } from './date.service';
describe('DateService', () => {
let service: DateService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(DateService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
+46
View File
@@ -0,0 +1,46 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class DateService {
constructor() { }
deferenceBetweenDays(start: any, end: any) {
const diffTime = Math.abs(end - start);
return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
}
notSameDate(start: any, end: any): boolean {
return new Date(start).toLocaleDateString() != new Date(end).toLocaleDateString()
}
isSameDate(start: any, end: any): boolean {
return !this.notSameDate(start, end)
}
EventEndDateTreatment({startTime, endTime}) {
const startTimeSamp = new Date(startTime).toLocaleDateString()
const endTimeSamp = new Date(endTime).toLocaleDateString()
const endMinutes = new Date(endTime).getMinutes()
const endHours = new Date(endTime).getHours()
if (startTimeSamp < endTimeSamp && (endMinutes + endHours) == 0) {
endTime = new Date(endTime);
endTime.setSeconds(endTime.getSeconds() - 1);
return new Date(endTime)
} else {
return new Date(endTime)
}
}
getDay(date) {
return (((new Date (date)).getDate())).toString().padStart(2,'0')
}
}
+129 -107
View File
@@ -4,7 +4,8 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
import { AuthService } from '../services/auth.service';
import { LoginUserRespose } from '../models/user.model';
import { LoginUserRespose, UserSession } from '../models/user.model';
import { EventList } from '../models/agenda/AgendaEventList';
@Injectable({
@@ -13,7 +14,7 @@ import { LoginUserRespose } from '../models/user.model';
export class EventsService {
authheader = {};
loggeduser: LoginUserRespose;
loggeduser: UserSession;
headers: HttpHeaders;
headersPrOficial: HttpHeaders;
@@ -40,7 +41,7 @@ export class EventsService {
if(this.loggeduser){
if(this.loggeduser.Profile == 'MDGPR') {
this.loggeduser.OwnerCalendars.forEach(calendar => {
if(calendar.CalendarName == 'Oficial') {
this.headersMdOficial = this.headersMdOficial.set('Authorization', this.loggeduser.BasicAuthKey);
@@ -51,10 +52,10 @@ export class EventsService {
this.headersMdPessoal = this.headersMdPessoal.set('Authorization', this.loggeduser.BasicAuthKey);
this.headersMdPessoal = this.headersMdPessoal.set('CalendarId', calendar.CalendarId);
this.headersMdPessoal = this.headersMdPessoal.set('CalendarRoleId', calendar.CalendarRoleId);
}
});
this.loggeduser.SharedCalendars.forEach(sharedCalendar => {
if(sharedCalendar.CalendarName == 'Oficial') {
this.headersSharedOficial = this.headersSharedOficial.set('Authorization', this.loggeduser.BasicAuthKey);
@@ -69,7 +70,7 @@ export class EventsService {
});
}
else if(this.loggeduser.Profile == 'PR') {
this.loggeduser.OwnerCalendars.forEach(calendar =>{
if(calendar.CalendarName == 'Oficial'){
this.headersPrOficial = this.headersPrOficial.set('Authorization', this.loggeduser.BasicAuthKey);
@@ -80,11 +81,11 @@ export class EventsService {
this.headersPrPessoal = this.headersPrPessoal.set('Authorization', this.loggeduser.BasicAuthKey);
this.headersPrPessoal = this.headersPrPessoal.set('CalendarId', calendar.CalendarId);
this.headersPrPessoal = this.headersPrPessoal.set('CalendarRoleId', calendar.CalendarRoleId);
}
});
}
this.headers = new HttpHeaders();
this.headers = this.headers.set('Authorization', this.loggeduser.BasicAuthKey);
}
@@ -98,16 +99,16 @@ export class EventsService {
params = params.set("StartDate", startdate);
params = params.set("EndDate", enddate);
let options = {
headers: this.headers,
params: params
let options = {
headers: this.headers,
params: params
};
return this.http.get<Event[]>(`${geturl}`, options);
} */
getAllPrOficialEvents(startdate:string, enddate:string): Observable<Event[]>{
getAllPrOficialEvents(startdate:string, enddate:string): Observable<EventList[]>{
let geturl = environment.apiURL + 'calendar/pr';
geturl = geturl.replace('/V4/','/V5/')
@@ -115,15 +116,15 @@ export class EventsService {
params = params.set("Start", startdate);
params = params.set("End", enddate);
let options = {
headers: this.headersPrOficial,
params: params
let options = {
headers: this.headersPrOficial,
params: params
};
return this.http.get<Event[]>(`${geturl}`, options);
return this.http.get<EventList[]>(`${geturl}`, options);
}
getAllPrPessoalEvents(startdate:string, enddate:string): Observable<Event[]>{
getAllPrPessoalEvents(startdate:string, enddate:string): Observable<EventList[]>{
let geturl = environment.apiURL + 'calendar/pr';
geturl = geturl.replace('/V4/','/V5/')
@@ -131,15 +132,15 @@ export class EventsService {
params = params.set("Start", startdate);
params = params.set("End", enddate);
let options = {
headers: this.headersPrPessoal,
params: params
let options = {
headers: this.headersPrPessoal,
params: params
};
return this.http.get<Event[]>(`${geturl}`, options);
return this.http.get<EventList[]>(`${geturl}`, options);
}
async getAllPrEvents(startdate:string, enddate:string){
async getAllPrEvents(startdate:string, enddate:string): Promise<EventList[]>{
let prO = await this.getAllPrOficialEvents(startdate, enddate).toPromise();
let prP = await this.getAllPrPessoalEvents(startdate, enddate).toPromise();
const resFinal = prO.concat(prP);
@@ -148,32 +149,32 @@ export class EventsService {
})
}
getAllMdOficialEvents(startdate:string, enddate:string): any{
getAllMdOficialEvents(startdate:string, enddate:string): Observable<EventList[]>{
let geturl = environment.apiURL + 'calendar/md';
let params = new HttpParams();
params = params.set("Start", startdate);
params = params.set("End", enddate);
let options = {
headers: this.headersMdOficial,
params: params
let options = {
headers: this.headersMdOficial,
params: params
};
return this.http.get<any>(`${geturl}`, options);
return this.http.get<EventList[]>(`${geturl}`, options);
}
getAllMdPessoalEvents(startdate:string, enddate:string): any{
let geturl = environment.apiURL + 'calendar/md';
let params = new HttpParams();
params = params.set("Start", startdate);
params = params.set("End", enddate);
let options = {
headers: this.headersMdPessoal,
params: params
let options = {
headers: this.headersMdPessoal,
params: params
};
return this.http.get<any>(`${geturl}`, options)
}
@@ -191,7 +192,7 @@ export class EventsService {
let prO = await this.getAllSharedOficialEvents(startdate, enddate).toPromise();
let prP = await this.getAllSharedPessoalEvents(startdate, enddate).toPromise();
const resFinal = prO.concat(prP);
return new Promise(resolve =>{
return resolve(resFinal)
});
@@ -207,13 +208,13 @@ export class EventsService {
params = params.set("Start", startdate);
params = params.set("End", enddate);
let options = {
headers: this.headersSharedOficial,
params: params
let options = {
headers: this.headersSharedOficial,
params: params
};
console.log(options);
return this.http.get<Event[]>(`${geturl}`, options);
}
@@ -225,10 +226,10 @@ export class EventsService {
params = params.set("Start", startdate);
params = params.set("End", enddate);
let options = {
headers: this.headersSharedPessoal,
params: params
let options = {
headers: this.headersSharedPessoal,
params: params
};
return this.http.get<Event[]>(`${geturl}`, options);
}
@@ -237,8 +238,8 @@ export class EventsService {
getRecurrenceTypes(): any{
const geturl = environment.apiURL + 'Calendar/RecurrenceTypes';
let options = {
headers: this.headers,
let options = {
headers: this.headers,
};
return this.http.get<any>(`${geturl}`, options);
}
@@ -253,10 +254,10 @@ export class EventsService {
params = params.set("CalendarName", calendarname);
params = params.set("StartDate", startdate);
params = params.set("EndDate", enddate);
let options = {
headers: this.headers,
params: params
let options = {
headers: this.headers,
params: params
};
return this.http.get<Event[]>(`${geturl}`, options);
}
@@ -264,12 +265,12 @@ export class EventsService {
getEvent(eventid: string): Observable<Event>{
let geturl = environment.apiURL + 'calendar/GetEvent';
let params = new HttpParams();
params = params.set("EventId", eventid);
let options = {
headers: this.headers,
params: params
let options = {
headers: this.headers,
params: params
};
return this.http.get<Event>(`${geturl}`, options);
@@ -283,10 +284,10 @@ export class EventsService {
params = params.set("conflictResolutionMode", conflictResolutionMode.toString());
params = params.set("sendInvitationsOrCancellationsMode", sendInvitationsOrCancellationsMode.toString());
let options = {
headers: this.headers,
params: params
let options = {
headers: this.headers,
params: params
};
return this.http.put<Event>(`${puturl}`, event, options)
@@ -300,10 +301,31 @@ export class EventsService {
params = params.set("conflictResolutionMode", conflictResolutionMode.toString());
params = params.set("sendInvitationsOrCancellationsMode", sendInvitationsOrCancellationsMode.toString());
let options = {
headers: this.headers,
params: params
params.set('CalendarId', event.CalendarId)
params.set('CalendarName', event.CalendarName)
this.headers['CalendarId'] = event.CalendarId
this.headers['CalendarName'] = event.CalendarName
if(event.CalendarName == 'Oficial'){
if(this.loggeduser.Profile == 'MDGPR'){
this.headers = this.headersMdOficial;
}
else if(this.loggeduser.Profile == 'PR'){
this.headers = this.headersPrOficial;
}
}
else{
if(this.loggeduser.Profile == 'MDGPR'){
this.headers = this.headersMdPessoal;
}
else if(this.loggeduser.Profile == 'PR'){
this.headers = this.headersPrPessoal;
}
}
let options = {
headers: this.headers,
params: params
};
return this.http.put<Event>(`${puturl}`, event, options)
@@ -311,7 +333,7 @@ export class EventsService {
changeAgenda(body:any){
const puturl = environment.apiURL + 'Calendar/MoveEvent';
let options = {
let options = {
headers: this.headers,
};
return this.http.post<any>(`${puturl}`, body, options);
@@ -324,14 +346,14 @@ export class EventsService {
params = params.set("CalendarName", calendarName);
let options = {
headers: this.headers,
params: params
let options = {
headers: this.headers,
params: params
};
return this.http.post<Event>(`${puturl}`, event, options)
} */
postEventMd(event:Event, calendarName:string)
{
const puturl = environment.apiURL + 'calendar/md';
@@ -343,17 +365,17 @@ export class EventsService {
switch (calendarName) {
case 'Oficial':
console.log(calendarName);
options = {
headers: this.headersMdOficial,
params: params
options = {
headers: this.headersMdOficial,
params: params
};
break;
case 'Pessoal':
console.log(calendarName);
options = {
headers: this.headersMdPessoal,
params: params
options = {
headers: this.headersMdPessoal,
params: params
};
break;
}
@@ -372,21 +394,21 @@ export class EventsService {
switch (calendarName) {
case 'Oficial':
console.log(calendarName);
options = {
headers: this.headersPrOficial,
params: params
options = {
headers: this.headersPrOficial,
params: params
};
break;
case 'Pessoal':
console.log(calendarName);
options = {
headers: this.headersPrPessoal,
params: params
options = {
headers: this.headersPrPessoal,
params: params
};
break;
}
return this.http.post<string>(`${puturl}`, event, options)
}
@@ -399,11 +421,11 @@ export class EventsService {
// 0 for occurence and 1 for serie (delete all events)
params = params.set("eventDeleteType", eventDeleteType.toString());
let options = {
headers: this.headers,
params: params
let options = {
headers: this.headers,
params: params
};
return this.http.delete(`${puturl}`, options)
}
postExpedientEvent(docId:any, body:any, sharedagenda:string, serialNumber:any, applicationID:any){
@@ -418,29 +440,29 @@ export class EventsService {
switch (this.loggeduser.Profile) {
case 'MDGPR':
if(body.CalendarName == 'Pessoal'){
options = {
options = {
headers: this.headersMdPessoal,
params: params
params: params
};
}
else if(body.CalendarName == 'Oficial'){
options = {
options = {
headers: this.headersMdOficial,
params: params
params: params
};
}
break;
case 'PR':
if(body.CalendarName == 'Pessoal'){
options = {
options = {
headers: this.headersPrPessoal,
params: params
params: params
};
}
else if(body.CalendarName == 'Oficial'){
options = {
options = {
headers: this.headersPrOficial,
params: params
params: params
};
}
break;
@@ -459,29 +481,29 @@ export class EventsService {
switch (this.loggeduser.Profile) {
case 'MDGPR':
if(body.CalendarName == 'Pessoal'){
options = {
options = {
headers: this.headersMdPessoal,
params: params
params: params
};
}
else if(body.CalendarName == 'Oficial'){
options = {
options = {
headers: this.headersMdOficial,
params: params
params: params
};
}
break;
case 'PR':
if(body.CalendarName == 'Pessoal'){
options = {
options = {
headers: this.headersPrPessoal,
params: params
params: params
};
}
else if(body.CalendarName == 'Oficial'){
options = {
options = {
headers: this.headersPrOficial,
params: params
params: params
};
}
break;
@@ -492,7 +514,7 @@ export class EventsService {
postEventToApproveEdit(body: EventToApproveEdit) {
const geturl = environment.apiURL + 'Tasks/EditEventTask';
let options = {
let options = {
headers: this.headers,
};
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { TimeService } from './time.service';
describe('TimeService', () => {
let service: TimeService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(TimeService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -0,0 +1,47 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class TimeService {
constructor() { }
showDateDuration(start:any){
let end;
end = new Date();
start = new Date(start);
let customizedDate;
const totalSeconds = Math.floor((end - (start))/1000);;
const totalMinutes = Math.floor(totalSeconds/60);
const totalHours = Math.floor(totalMinutes/60);
const totalDays = Math.floor(totalHours/24);
const hours = totalHours - ( totalDays * 24 );
const minutes = totalMinutes - ( totalDays * 24 * 60 ) - ( hours * 60 );
const seconds = totalSeconds - ( totalDays * 24 * 60 * 60 ) - ( hours * 60 * 60 ) - ( minutes * 60 );
if(totalDays == 0){
if(start.getDate() == new Date().getDate()){
let time = start.getHours() + ":" + this.addZero(start.getUTCMinutes());
return time;
}
else{
return 'Ontem';
}
}
else{
let date = this.addZero(start.getDate()) + "/" + this.addZero(start.getMonth()+1) + "/" + start.getFullYear();
return date;
}
}
addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
}
+1 -1
View File
@@ -29,7 +29,7 @@ export class InativityService {
function resetTimer() {
clearTimeout(t);
t = setTimeout(userIsNotActive, 60000 * 5); // time is in milliseconds
t = setTimeout(userIsNotActive, 60000 * 15); // time is in milliseconds
}
}
}
+17
View File
@@ -0,0 +1,17 @@
self.addEventListener('install', function() {
self.skipWaiting();
});
self.addEventListener('activate', function(event) {
event.waitUntil(clients.claim());
});
self.addEventListener('notificationclick', function(event) {
// Close the notification when it is clicked
event.notification.close();
console.log(event)
});
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { WebNotificationPopupService } from './web-notification-popup.service';
describe('WebNotificationPopupService', () => {
let service: WebNotificationPopupService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(WebNotificationPopupService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -0,0 +1,81 @@
import { Injectable } from '@angular/core';
import { AlertController, Platform } from '@ionic/angular';
import { v4 as uuidv4 } from 'uuid'
@Injectable({
providedIn: 'root'
})
export class WebNotificationPopupService {
constructor( private platform: Platform) {
navigator.serviceWorker.register(new URL('./sw.js', import.meta.url));
}
askNotificationPermission() {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {}
else {return false}
// function to actually ask the permissions
function handlePermission(permission) {}
// Let's check if the browser supports notifications
if (!('Notification' in window)) {
console.log("This browser does not support notifications.");
} else {
if(this.checkNotificationPromise()) {
Notification.requestPermission()
.then((permission) => {
handlePermission(permission);
})
} else {
Notification.requestPermission(function(permission) {
handlePermission(permission);
});
}
}
}
private checkNotificationPromise() {
try {
Notification.requestPermission().then();
} catch(e) {
return false;
}
return true;
}
sendNotification(e) {
if (this.platform.is('desktop') || this.platform.is('mobileweb')) {}
else {return false}
Notification.requestPermission((result) => {
if (result === 'granted') {
navigator.serviceWorker.ready.then((registration)=> {
registration.showNotification(e.Object, {
body: e.Service,
icon: 'assets/icon/favicon.png',
requireInteraction: true,
tag: 'require-interaction'+uuidv4(),
// actions: [
// {action: 'like', title: 'Like', icon: 'https://example/like.png'},
// {action: 'reply', title: 'Reply', icon: 'https://example/reply.png'}
// ]
}).then(e =>{
console.log(e)
})
});
}
});
}
}
+32 -9
View File
@@ -14,7 +14,7 @@ import { ToastService } from '../services/toast.service';
import { Optional } from '@angular/core';
import { JsonStore } from './jsonStore.service';
import { synchro } from './socket/synchro.service';
import { v4 as uuidv4 } from 'uuid'
@Injectable({
providedIn: 'root'
})
@@ -27,10 +27,11 @@ export class NotificationsService {
callbacks: {
type: string,
funx: Function
id: string
}[] = []
constructor(
private http: HttpClient,
private http: HttpClient,
private storageService: StorageService,
private modalController: ModalController,
public modalCtrl: AlertController,
@@ -40,17 +41,39 @@ 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.storageService.get("Notifications").then((value) => {
}).catch(()=>{
this.storageService.store("Notifications",[])
})
this.callbacks.push({type, funx})
if(!object.hasOwnProperty('desktop') && object['desktop'] != false) {
synchro.registerCallback('Notification',funx, type)
}
}
registerCallback(type: string, funx: Function, object: any = {} ) {
const id = uuidv4()
this.callbacks.push({type, funx, id})
if(!object.hasOwnProperty('desktop') && object['desktop'] != false) {
synchro.registerCallback('Notification',funx, type)
}
return id;
}
deleteCallback(id) {
this.callbacks.forEach((e, index)=>{
if(e.id == id) {
if (index > -1) {
this.callbacks.splice(index, 1);
}
}
})
}
getTokenByUserIdAndId(user, userID) {
const geturl = environment.apiURL + 'notifications/user/' + userID;
+1
View File
@@ -71,6 +71,7 @@ export class ProcessesService {
};
return this.http.get<any>(`${geturl}`, options);
}
SetTaskToPending(serialNumber:string): Observable<any>{
const geturl = environment.apiURL + 'Tasks/SetTaskPending';
+21 -12
View File
@@ -79,13 +79,18 @@ class SynchroService {
private onopen = () =>{
this.BackgroundService.online()
this.callBacks.forEach((e)=>{
if(e.type == 'Online') {
e.funx()
}
})
if(!this.conected) {
this.BackgroundService.online()
this.callBacks.forEach((e)=>{
if(e.type == 'Online') {
e.funx()
}
})
}
console.log('open ======================= welcome to socket server')
this._connected = true
@@ -130,6 +135,7 @@ class SynchroService {
if(window['platform'].is('desktop') || this.platform.is('mobileweb')) {}
else return false
if(environment.production) return false
this.callBacks.forEach((e)=> {
@@ -169,13 +175,16 @@ class SynchroService {
console.log('[close] Connection died');
console.log('Reconnect')
this.BackgroundService.offline();
this.callBacks.forEach((e)=>{
if(e.type == 'Offline') {
e.funx()
}
})
if(this._connected) {
this.BackgroundService.offline();
this.callBacks.forEach((e)=>{
if(e.type == 'Offline') {
e.funx()
}
})
}
// status
this._connected = false
+27 -13
View File
@@ -1,33 +1,47 @@
import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage';
import { AnimationController, ModalController,Platform } from '@ionic/angular';
import { SHA1 } from 'crypto-js'
import { localstoreService } from '../store/localstore.service';
/* import { Plugins } from '@capacitor/core';
const { Storage } = Plugins; */
@Injectable({
providedIn: 'root'
})
export class StorageService {
constructor(private storage:Storage,) {}
private keyName: string;
constructor(private storage:Storage,
private platform: Platform
) {}
key(key:string): string {
return (SHA1('service'+this.constructor.name+key)).toString()
}
// Store the value
async store(key: string, value: any){
const encryptedValue = btoa(escape(JSON.stringify(value)));
await this.storage.set(key, encryptedValue);
async store(key: string, value: any) {
await localstoreService.set(this.key(key), value)
}
// Get the value
async get(key: string) {
const ret = await this.storage.get(key).then((val) => { return val; });
try {
return JSON.parse(unescape(atob(ret)));
} catch (error) {
return unescape(atob(ret))
}
async get(key: string): Promise<any> {
return new Promise((resolve, reject)=>{
const data = localstoreService.get(this.key(key), false)
if(data) resolve(data)
else reject(data)
})
}
async remove(key: string){
await this.storage.remove(key);
await localstoreService.delete(this.key(key))
}
/*
// Get the value
async get(storageKey: string) {
@@ -45,6 +45,31 @@ export class WebNotificationsService {
});
/* MFPPush.initialize({
appId: "com.gpr.gabinetedigital",
mfpContextRoot: "/mfp",
}); */
/* MFPPush.registerDevice()
.then((res) => {
console.log("WEB Successfully Registered Device...");
setTimeout(()=>{
MFPPush.registerDevice()
.then((res) => {
console.log("WEB Successfully Registered Device...");
})
.catch((err) => {
console.log("WEB Registration Failed" + err);
});
}, 1000)
})
.catch((err) => {
console.log("WEB Registration Failed" + err);
}); */
}
register(){