diff --git a/src/app/pages/gabinete-digital/expediente/expediente.page.ts b/src/app/pages/gabinete-digital/expediente/expediente.page.ts
index 385f3b67a..75fc01b42 100644
--- a/src/app/pages/gabinete-digital/expediente/expediente.page.ts
+++ b/src/app/pages/gabinete-digital/expediente/expediente.page.ts
@@ -4,6 +4,9 @@ import { ProcessesService } from 'src/app/services/processes.service';
import { ToastService } from 'src/app/services/toast.service';
import { ExpedienteGdStore } from 'src/app/store/expedientegd-store.service';
import { ExpedienteTaskPipe } from 'src/app/pipes/expediente-task.pipe';
+import { SqliteService } from 'src/app/services/sqlite.service';
+import { Platform } from '@ionic/angular';
+import { synchro } from '../../../services/socket/synchro.service';
@Component({
selector: 'app-expediente',
@@ -12,22 +15,25 @@ import { ExpedienteTaskPipe } from 'src/app/pipes/expediente-task.pipe';
})
export class ExpedientePage implements OnInit {
- segment:string;
+ segment: string;
skeletonLoader = true
//profile:string;
- showLoader:boolean;
+ showLoader: boolean;
taskslist = [];
- serialNumber:string;
+ serialNumber: string;
expedienteGdStore = ExpedienteGdStore
expedienteTaskPipe = new ExpedienteTaskPipe()
-
+ listToPresent;
+ synch = synchro
constructor(
- private processes:ProcessesService,
+ private processes: ProcessesService,
private router: Router,
- private toastService: ToastService
- ) {}
+ private toastService: ToastService,
+ public platform: Platform,
+ private sqliteservice: SqliteService,
+ ) { }
ngOnInit() {
@@ -35,17 +41,19 @@ export class ExpedientePage implements OnInit {
const pathname = location.pathname + location.search
this.LoadList()
-
+
this.router.events.forEach((event) => {
if (event instanceof NavigationStart && event.url.startsWith(pathname)) {
- if(window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) {
+ if (window.location.pathname.split('/').length >= 4 && window.location.pathname.startsWith('/home/gabinete-digital')) {
this.refreshing()
} else {
this.LoadList()
}
}
});
-
+
+ this.getEventsFromLocalDb();
+
}
async LoadList() {
@@ -54,16 +62,17 @@ export class ExpedientePage implements OnInit {
try {
const expediente: object[] = await this.processes.GetTaskListExpediente(false).toPromise()
const result = expediente
-
+
this.taskslist = new Array();
let res = result.reverse().filter((data: any) => data.workflowInstanceDataFields.Status == "Active");
res.forEach((element: any) => {
- let task = this.expedienteTaskPipe.transform(element)
+ let task = this.expedienteTaskPipe.transform(element)
this.taskslist.push(task);
});
-
+
+ this.SqliteAddExpediente(this.taskslist)
this.expedienteGdStore.reset(this.taskslist);
} catch (error) {
@@ -92,9 +101,56 @@ export class ExpedientePage implements OnInit {
this.router.navigate(['/home/gabinete-digital']);
}
- goToExpediente(serialNumber:any){
+ goToExpediente(serialNumber: any) {
//console.log('ABRE');
- this.router.navigate(['/home/gabinete-digital/expediente',serialNumber,'gabinete-digital']);
+ this.router.navigate(['/home/gabinete-digital/expediente', serialNumber, 'gabinete-digital']);
+ }
+
+ SqliteAddExpediente(list) {
+ list.forEach((expediente) => {
+ let data = {
+ serialNumber: expediente.serialNumber,
+ workflowInstanceFolio: expediente.workflowInstanceFolio,
+ Documents: expediente.Documents,
+ actions: expediente.actions,
+ activityInstanceName: expediente.activityInstanceName,
+ formURL: expediente.formURL,
+ originator: expediente.originator,
+ taskStartDate: expediente.taskStartDate,
+ totalDocuments: expediente.totalDocuments,
+ workflowDisplayName: expediente.workflowDisplayName,
+ workflowID: expediente.workflowID,
+ workflowInstanceDataFields: expediente.workflowInstanceDataFields,
+ workflowInstanceID: expediente.workflowInstanceID,
+ workflowName: expediente.workflowName
+ }
+
+ this.sqliteservice.addExpediente(data);
+ })
+
+ }
+
+ getEventsFromLocalDb() {
+
+
+
+ synchro.registerCallback('Online', () => {
+ this.listToPresent = this.expedienteGdStore.list;
+ console.log('Onlineee')
+
+ })
+
+
+ synchro.registerCallback('Offline', () => {
+ this.platform.ready().then(() => {
+ this.sqliteservice.getAllExpedientes().then((expediente) => {
+ this.listToPresent = expediente
+ console.log("All expedientes from local,", expediente)
+ })
+ console.log('Offlineee')
+ })
+
+ })
}
}
diff --git a/src/app/pages/login/login.page.ts b/src/app/pages/login/login.page.ts
index b453225dc..aaae9fe0e 100644
--- a/src/app/pages/login/login.page.ts
+++ b/src/app/pages/login/login.page.ts
@@ -7,6 +7,7 @@ import { environment } from 'src/environments/environment';
import { AlertController } from '@ionic/angular';
import { NotificationsService } from 'src/app/services/notifications.service';
import { SessionStore } from 'src/app/store/session.service';
+import { SqliteService } from '../../services/sqlite.service';
@Component({
selector: 'app-login',
@@ -31,11 +32,14 @@ export class LoginPage implements OnInit {
private router: Router,
private authService: AuthService,
private toastService: ToastService,
- public alertController: AlertController
+ public alertController: AlertController,
+ private sqliteservice: SqliteService
) {
}
- ngOnInit() {}
+ ngOnInit() {
+
+ }
//Function to validade the login inputs
validateUsername() {
@@ -83,9 +87,9 @@ export class LoginPage implements OnInit {
if (attempt.UserId == SessionStore.user.UserId) {
await this.authService.SetSession(attempt, this.userattempt);
- await this.authService.loginChat(this.userattempt);
+ //await this.authService.loginChat(this.userattempt);
this.getToken();
- SessionStore.setInativity(true)
+ SessionStore.setInativity(true);
this.goback()
} else {
diff --git a/src/app/services/notifications.service.ts b/src/app/services/notifications.service.ts
index 69a023564..44d7c344d 100644
--- a/src/app/services/notifications.service.ts
+++ b/src/app/services/notifications.service.ts
@@ -14,7 +14,8 @@ 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'
+import { v4 as uuidv4 } from 'uuid';
+import { EventTrigger } from '../services/eventTrigger.service';
@Injectable({
providedIn: 'root'
})
@@ -41,7 +42,8 @@ export class NotificationsService {
private toastService: ToastService,
private zone: NgZone,
private activeroute: ActivatedRoute,
- private jsonstore: JsonStore) {
+ private jsonstore: JsonStore,
+ private eventtrigger: EventTrigger) {
this.storageService.get("Notifications").then((value) => {
@@ -168,6 +170,9 @@ export class NotificationsService {
this.storageService.store("Notifications",this.DataArray)
console.log(message);
+ this.eventtrigger.publishSomeData({
+ notification: "recive"
+ })
var data = JSON.parse(message.payload);
synchro.$send(data)
diff --git a/src/app/services/socket/synchro.service.ts b/src/app/services/socket/synchro.service.ts
index dd19ac1f2..649e34dfd 100644
--- a/src/app/services/socket/synchro.service.ts
+++ b/src/app/services/socket/synchro.service.ts
@@ -3,6 +3,7 @@ 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';
+import { EventTrigger } from '../eventTrigger.service'
export interface wss{
@@ -28,6 +29,7 @@ class SynchroService {
private url: string = ''
callback = function(){}
private _connected = false;
+ private eventtrigger: EventTrigger;
private BackgroundService = new BackgroundService()
callBacks: {
type: 'Offline' | 'Online' | 'Onmessage' | 'Chat' | 'Notification' | 'Notifications' | '',
@@ -81,7 +83,7 @@ class SynchroService {
- if(!this.conected) {
+ //if(!this._connected) {
this.BackgroundService.online()
this.callBacks.forEach((e)=>{
@@ -90,9 +92,13 @@ class SynchroService {
}
})
- }
+ //}
console.log('open ======================= welcome to socket server')
+ this.eventtrigger.publishSomeData({
+ internet: "online"
+ })
+
this._connected = true
// send all saved data due to internet connection
@@ -177,14 +183,15 @@ class SynchroService {
- if(this._connected) {
+ // if(this._connected){
this.BackgroundService.offline();
this.callBacks.forEach((e)=>{
if(e.type == 'Offline') {
e.funx()
}
})
- }
+ //}
+
// status
this._connected = false
diff --git a/src/app/services/sqlite.service.spec.ts b/src/app/services/sqlite.service.spec.ts
new file mode 100644
index 000000000..033257edb
--- /dev/null
+++ b/src/app/services/sqlite.service.spec.ts
@@ -0,0 +1,16 @@
+import { TestBed } from '@angular/core/testing';
+
+import { SqliteService } from './sqlite.service';
+
+describe('SqliteService', () => {
+ let service: SqliteService;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({});
+ service = TestBed.inject(SqliteService);
+ });
+
+ it('should be created', () => {
+ expect(service).toBeTruthy();
+ });
+});
diff --git a/src/app/services/sqlite.service.ts b/src/app/services/sqlite.service.ts
new file mode 100644
index 000000000..33df215da
--- /dev/null
+++ b/src/app/services/sqlite.service.ts
@@ -0,0 +1,254 @@
+import { Injectable } from '@angular/core';
+import { Platform } from '@ionic/angular';
+import { SQLite, SQLiteObject } from '@ionic-native/sqlite/ngx';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class SqliteService {
+
+ private dbInstance: SQLiteObject;
+ readonly db_name: string = "gabinetedigital.db";
+ readonly events: string = "Events";
+ readonly expedientes: string = "Expedientes";
+ EVENTS: Array
;
+ EXPEDIENTES: Array;
+
+ constructor(private platform: Platform,
+ private sqlite: SQLite) {
+ this.databaseConn();
+ }
+
+ databaseConn() {
+ this.platform.ready().then(async () => {
+ await this.sqlite.create({
+ name: this.db_name,
+ location: 'default'
+ }).then(async (sqLite: SQLiteObject) => {
+ this.dbInstance = sqLite;
+ await sqLite.executeSql(`
+ CREATE TABLE IF NOT EXISTS ${this.events} (
+ EventId varchar(255) PRIMARY KEY,
+ Subject varchar(255),
+ HasAttachments BIT,
+ Location varchar(255),
+ CalendarId varchar(255),
+ CalendarName varchar(255),
+ StartDate varchar(255),
+ EndDate varchar(255),
+ EventType varchar(255),
+ Attendees Text,
+ IsMeeting BIT,
+ IsRecurring BIT,
+ IsAllDayEvent BIT,
+ AppointmentState INTERGER,
+ TimeZone varchar(255),
+ Organizer Text,
+ Category varchar(255),
+ EventRecurrence Text,
+ Attachments Text,
+ Body Text
+ )`, [])
+ .then((res) => {
+ console.log("Sucess Events Table created: ", res)
+ })
+ .catch((error) => console.log(JSON.stringify(error)));
+
+ await sqLite.executeSql(`
+ CREATE TABLE IF NOT EXISTS ${this.expedientes} (
+ serialNumber varchar(255) PRIMARY KEY,
+ workflowInstanceFolio varchar(255),
+ Documents Text,
+ actions Text,
+ activityInstanceName varchar(255),
+ formURL varchar(255),
+ originator Text,
+ taskStartDate varchar(255),
+ totalDocuments INTERGER,
+ workflowDisplayName varchar(255),
+ workflowID INTERGER,
+ workflowInstanceDataFields Text,
+ workflowInstanceID INTERGER,
+ workflowName varchar(255)
+ )`, [])
+ .then((res) => {
+ console.log("Sucess Espedientes Table created: ", res)
+ })
+ .catch((error) => console.log(JSON.stringify(error)));
+ })
+ .catch((error) => console.log(JSON.stringify(error)));
+ });
+ }
+
+ //addEvent
+ public addEvent(data) {
+ this.dbInstance.executeSql(`
+ INSERT OR REPLACE INTO ${this.events} (EventId,Subject,HasAttachments,Location,CalendarId,CalendarName,StartDate,EndDate,EventType,Attendees,IsMeeting,IsRecurring,IsAllDayEvent,AppointmentState,TimeZone,Organizer,Category,EventRecurrence,Attachments,Body )
+ VALUES ('${data.EventId}','${data.Subject}', '${data.HasAttachments}','${data.Location}','${data.CalendarId}','${data.CalendarName}','${data.StartDate}','${data.EndDate}','${data.EventType}','${data.Attendees}','${data.IsMeeting}','${data.IsRecurring}',
+ '${data.IsAllDayEvent}','${data.AppointmentState}','${data.TimeZone}','${data.Organizer}','${data.Category}','${data.EventRecurrence}','${data.Attachments}','${data.Body}')`, [])
+ .then(() => {
+ console.log("event add with Success");
+
+ }, (e) => {
+ console.log(JSON.stringify(e.err));
+ });
+ }
+
+ //addExpediente
+ public addExpediente(data) {
+ this.dbInstance.executeSql(`
+ INSERT OR REPLACE INTO ${this.expedientes} (serialNumber,workflowInstanceFolio,Documents,actions,activityInstanceName,formURL,originator,taskStartDate,totalDocuments,workflowDisplayName,workflowID,workflowInstanceDataFields,workflowInstanceID,workflowName)
+ VALUES ('${data.serialNumber}','${data.workflowInstanceFolio}', '${data.Documents}','${data.actions}','${data.activityInstanceName}','${data.formURL}','${data.originator}','${data.taskStartDate}','${data.totalDocuments}','${data.workflowDisplayName}','${data.workflowID}',
+ '${data.workflowInstanceDataFields}','${data.workflowInstanceID}','${data.workflowName}')`, [])
+ .then(() => {
+ console.log("expediente add with Success");
+
+ }, (e) => {
+ console.log(JSON.stringify(e.err));
+ });
+ }
+ //getAllEvents
+ getAllEvents() {
+ var hashattachment = false;
+ var ismeeting = false;
+ var isrecurring = false;
+ var isallday = false;
+ return this.dbInstance.executeSql(`SELECT * FROM ${this.events}`, []).then((res) => {
+ this.EVENTS = [];
+ if (res.rows.length > 0) {
+ for (var i = 0; i < res.rows.length; i++) {
+ if (res.rows.item(i).HasAttachments === "true") {
+ hashattachment = true
+ }
+ if (res.rows.item(i).IsMeeting === "true") {
+ ismeeting = true
+ }
+ if (res.rows.item(i).IsRecurring === "true") {
+ isrecurring = true
+ }
+ if (res.rows.item(i).IsAllDayEvent === "true") {
+ isallday = true
+ }
+ let event = {
+ EventId: res.rows.item(i).EventId,
+ HasAttachments: hashattachment,
+ Subject: res.rows.item(i).Subject,
+ Location: res.rows.item(i).Location,
+ CalendarId: res.rows.item(i).CalendarId,
+ CalendarName: res.rows.item(i).CalendarName,
+ StartDate: res.rows.item(i).StartDate,
+ EndDate: res.rows.item(i).EndDate,
+ EventType: res.rows.item(i).EventType,
+ Attendees: res.rows.item(i).Attendees,
+ IsMeeting: ismeeting,
+ IsRecurring: isrecurring,
+ IsAllDayEvent: isallday,
+ AppointmentState: res.rows.item(i).AppointmentState,
+ TimeZone: res.rows.item(i).TimeZone,
+ Organizer: res.rows.item(i).Organizer,
+ Category: res.rows.item(i).Category,
+ EventRecurrence: res.rows.item(i).EventRecurrence,
+ Attachments: res.rows.item(i).Attachments
+ }
+ this.EVENTS.push(event);
+ }
+
+ return this.EVENTS;
+ }
+ }, (e) => {
+ console.log(" Get all events error", JSON.stringify(e));
+ });
+ }
+
+ getAllExpedientes() {
+ return this.dbInstance.executeSql(`SELECT * FROM ${this.expedientes}`, []).then((res) => {
+ this.EXPEDIENTES = [];
+ if (res.rows.length > 0) {
+ for (var i = 0; i < res.rows.length; i++) {
+ this.EXPEDIENTES.push(res.rows.item(i));
+ }
+ return this.EXPEDIENTES;
+ }
+ }, (e) => {
+ console.log(" Get all expedientes error", JSON.stringify(e));
+ });
+ }
+
+ //getEventBy id
+ getEventById(id) {
+
+ var hashattachment = false;
+ var ismeeting = false;
+ var isrecurring = false;
+ var isallday = false;
+ var body;
+ var attendes;
+ var organizer;
+ var eventrecurrence;
+ var attachment;
+
+ return this.dbInstance.executeSql(`SELECT * FROM ${this.events} WHERE EventId = ? `, [id]).then((res) => {
+ this.EVENTS = [];
+ if (res.rows.length > 0) {
+ for (var i = 0; i < res.rows.length; i++) {
+ if (res.rows.item(i).HasAttachments === "true") {
+ hashattachment = true
+ }
+ if (res.rows.item(i).IsMeeting === "true") {
+ ismeeting = true
+ }
+ if (res.rows.item(i).IsRecurring === "true") {
+ isrecurring = true
+ }
+ if (res.rows.item(i).IsAllDayEvent === "true") {
+ isallday = true
+ }
+ /* if (res.rows.item(i).Body != "") {
+ body = JSON.parse(res.rows.item(i).Body);
+ }
+ if (res.rows.item(i).Attendees !="") {
+ attendes = JSON.parse(res.rows.item(i).Attendees);
+ }
+ if(res.rows.item(i).Organizer !=""){
+ organizer = JSON.parse(res.rows.item(i).Organizer);
+ }
+ if(res.row.item(i).EventRecurrence != ""){
+ eventrecurrence = JSON.parse(res.row.item(i).EventRecurrence);
+ }
+ if(res.row.item(i).Attachments != ""){
+ attachment = JSON.parse(res.row.item(i).Attachments);
+ }
+ */
+
+ let event = {
+ EventId: res.rows.item(i).EventId,
+ HasAttachments: hashattachment,
+ Subject: res.rows.item(i).Subject,
+ Location: res.rows.item(i).Location,
+ CalendarId: res.rows.item(i).CalendarId,
+ CalendarName: res.rows.item(i).CalendarName,
+ StartDate: res.rows.item(i).StartDate,
+ EndDate: res.rows.item(i).EndDate,
+ EventType: res.rows.item(i).EventType,
+ Attendees: res.rows.item(i).Attendees,
+ IsMeeting: ismeeting,
+ IsRecurring: isrecurring,
+ IsAllDayEvent: isallday,
+ Body: res.rows.item(i).Body,
+ AppointmentState: res.rows.item(i).AppointmentState,
+ TimeZone: res.rows.item(i).TimeZone,
+ Organizer: res.rows.item(i).Organizer,
+ Category: res.rows.item(i).Category,
+ EventRecurrence: res.rows.item(i).EventRecurrence,
+ Attachments: res.rows.item(i).Attachments
+ }
+ this.EVENTS.push(event);
+ }
+
+ return this.EVENTS;
+ }
+ }, (e) => {
+ console.log(" Get events by id error", JSON.stringify(e));
+ });
+ }
+}