mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
Bug fix offline actions
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@
|
||||
<name>gabinete digital</name>
|
||||
<description>An awesome Ionic/Cordova app.</description>
|
||||
<author email="hi@ionicframework.com" href="http://ionicframework.com/">Ionic Framework Team</author>
|
||||
<content src="index.html" />
|
||||
<content original-src="index.html" src="http://localhost:8100" />
|
||||
<access origin="*" />
|
||||
<allow-navigation href="*" />
|
||||
<allow-navigation href="*" />
|
||||
|
||||
@@ -6,6 +6,8 @@ import { ToastService } from 'src/app/services/toast.service';
|
||||
import { ImageModalPage } from '../gallery/image-modal/image-modal.page';
|
||||
import { NewPublicationPage } from '../new-publication/new-publication.page';
|
||||
import { Location } from '@angular/common';
|
||||
import { SqliteService } from 'src/app/services/sqlite.service';
|
||||
import { synchro } from 'src/app/services/socket/synchro.service';
|
||||
|
||||
|
||||
@Component({
|
||||
@@ -25,7 +27,8 @@ export class PublicationDetailPage implements OnInit {
|
||||
private publications:PublicationsService,
|
||||
private animationController: AnimationController,
|
||||
private toastService: ToastService,
|
||||
private location: Location ) {
|
||||
private location: Location,
|
||||
private sqliteservice: SqliteService ) {
|
||||
|
||||
this.publicationId = this.navParams.get('publicationId');
|
||||
/* this.folderId = this.navParams.get('folderIdId'); */
|
||||
@@ -77,6 +80,14 @@ export class PublicationDetailPage implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
getFromDB() {
|
||||
if(synchro.connected === true) {
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
this.location.back()
|
||||
|
||||
|
||||
@@ -122,7 +122,6 @@ export class PublicationsPage implements OnInit {
|
||||
this.publications.GetPublicationFolderList().subscribe(res => {
|
||||
|
||||
console.log('accoes', res)
|
||||
this.sqliteservice.addactions(res);
|
||||
|
||||
this.publicationsEventFolderList = new Array();
|
||||
this.publicationsTravelFolderList = new Array();
|
||||
@@ -137,10 +136,14 @@ export class PublicationsPage implements OnInit {
|
||||
ActionType: data.ActionType,
|
||||
}
|
||||
|
||||
this.sqliteservice.addactions(folder);
|
||||
|
||||
if (data.ActionType == "Evento") {
|
||||
console.log('Evento', folder)
|
||||
this.publicationsEventFolderList.push(folder);
|
||||
}
|
||||
else {
|
||||
console.log('Viagem', folder)
|
||||
this.publicationsTravelFolderList.push(folder);
|
||||
}
|
||||
this.showLoader = false;
|
||||
@@ -168,6 +171,8 @@ export class PublicationsPage implements OnInit {
|
||||
} else {
|
||||
this.sqliteservice.getAllActions().then((actions: any[]) => {
|
||||
|
||||
console.log('offline publi', actions)
|
||||
|
||||
this.publicationsEventFolderList = new Array();
|
||||
this.publicationsTravelFolderList = new Array();
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
<ion-list>
|
||||
<!-- [routerLink]="['/home/publications/view-publications/publication-detail', publication.publicationId]" -->
|
||||
<div class="post-item"
|
||||
*ngFor="let publication of publicationListStorage.documents[folderId]"
|
||||
*ngFor="let publication of getpublication"
|
||||
(click)="goToPublicationDetail(publication.DocumentId)"
|
||||
>
|
||||
<div *ngIf="publication.FileBase64.length > 30" class="post-img">
|
||||
|
||||
@@ -24,7 +24,7 @@ export class ViewPublicationsPage implements OnInit {
|
||||
|
||||
publicationList: Publication[] = new Array();
|
||||
item: PublicationFolder;
|
||||
folderId:string;
|
||||
folderId: string;
|
||||
error: any;
|
||||
|
||||
publicationListStorage = PublicationListStorage
|
||||
@@ -33,6 +33,9 @@ export class ViewPublicationsPage implements OnInit {
|
||||
publicationTravelFolderService = PublicationTravelFolderStore
|
||||
|
||||
publicationPipe = new PublicationPipe()
|
||||
publicationDitails: any;
|
||||
getpublication = [];
|
||||
|
||||
|
||||
constructor(
|
||||
private modalController: ModalController,
|
||||
@@ -45,7 +48,7 @@ export class ViewPublicationsPage implements OnInit {
|
||||
this.activatedRoute.paramMap.subscribe(params => {
|
||||
console.log(params);
|
||||
|
||||
if(params["params"]) {
|
||||
if (params["params"]) {
|
||||
this.folderId = params["params"].folderId;
|
||||
// console.log(params["params"]);
|
||||
}
|
||||
@@ -56,20 +59,17 @@ export class ViewPublicationsPage implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
if(typeof(this.folderId) == 'object') {
|
||||
if (typeof (this.folderId) == 'object') {
|
||||
this.folderId = this.folderId['ProcessId']
|
||||
}
|
||||
|
||||
this.getPublicationDetail();
|
||||
setTimeout(() => {
|
||||
this.getPublications();
|
||||
}, 5000);
|
||||
this.getFromDB();
|
||||
|
||||
}
|
||||
|
||||
ngOnChanges() {
|
||||
|
||||
if(typeof(this.folderId) == 'object') {
|
||||
if (typeof (this.folderId) == 'object') {
|
||||
this.folderId = this.folderId['ProcessId']
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ export class ViewPublicationsPage implements OnInit {
|
||||
this.getPublications();
|
||||
}
|
||||
|
||||
doRefresh =(event) => {
|
||||
doRefresh = (event) => {
|
||||
setTimeout(() => {
|
||||
this.getPublicationDetail();
|
||||
this.getPublications();
|
||||
@@ -99,7 +99,8 @@ export class ViewPublicationsPage implements OnInit {
|
||||
|
||||
setTimeout(() => {
|
||||
let allActions = this.publicationEventFolderStorage.list.concat(this.publicationTravelFolderService.list)
|
||||
this.item = allActions.find((e)=> e.ProcessId == this.folderId);
|
||||
this.item = allActions.find((e) => e.ProcessId == this.folderId);
|
||||
this.publicationDitails = this.item
|
||||
console.log('item', this.item)
|
||||
}, 100);
|
||||
|
||||
@@ -108,47 +109,86 @@ export class ViewPublicationsPage implements OnInit {
|
||||
getPublications() {
|
||||
this.showLoader = true;
|
||||
const folderId = this.folderId
|
||||
this.publications.GetPublications(this.folderId).subscribe(res=>{
|
||||
this.publications.GetPublications(this.folderId).subscribe(res => {
|
||||
console.log(this.folderId)
|
||||
console.log('getPublications',res)
|
||||
this.sqliteservice.updateactions(this.folderId, res);
|
||||
|
||||
this.publicationList = new Array();
|
||||
|
||||
|
||||
res.forEach(element => {
|
||||
console.log('getPublications', element)
|
||||
let item: Publication = this.publicationPipe.itemList(element)
|
||||
this.publicationList.push(item);
|
||||
});
|
||||
this.sqliteservice.updateactions(this.folderId, JSON.stringify(this.publicationList));
|
||||
|
||||
|
||||
this.publicationListStorage.add(folderId, this.publicationList)
|
||||
this.getpublication = this.publicationList;
|
||||
|
||||
this.showLoader = false;
|
||||
},
|
||||
(error)=>{
|
||||
if(error.status == '404'){
|
||||
this.error = 'Sem publicações disponíveis!';
|
||||
this.publicationList= [];
|
||||
this.publicationListStorage.add(folderId, this.publicationList)
|
||||
}
|
||||
(error) => {
|
||||
if (error.status == '404') {
|
||||
this.error = 'Sem publicações disponíveis!';
|
||||
this.publicationList = [];
|
||||
this.publicationListStorage.add(folderId, this.publicationList)
|
||||
}
|
||||
|
||||
this.showLoader = false;
|
||||
this.showLoader = false;
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
getFromDB() {
|
||||
if(synchro.connected === true) {
|
||||
if (synchro.connected === true) {
|
||||
this.getPublicationDetail();
|
||||
setTimeout(() => {
|
||||
this.getPublications();
|
||||
}, 5000);
|
||||
|
||||
} else {
|
||||
|
||||
this.sqliteservice.getActionById(this.folderId).then((publications) => {
|
||||
console.log('publications', publications)
|
||||
let item = {
|
||||
ActionType: publications[0].ActionType,
|
||||
DateBegin: publications[0].DateBegin,
|
||||
DateEnd: publications[0].DateEnd,
|
||||
Description: publications[0].Description,
|
||||
Detail: publications[0].Detail,
|
||||
ProcessId: publications[0].ProcessId
|
||||
}
|
||||
this.publicationDitails = item;
|
||||
|
||||
let publicationArray = [];
|
||||
JSON.parse(publications[0].publications).forEach(element => {
|
||||
let publicationlis = {
|
||||
DateIndex: element.DateIndex,
|
||||
DatePublication: element.DatePublication,
|
||||
DocumentId: element.DocumentId,
|
||||
FileBase64: element.FileBase64,
|
||||
FileExtension: element.FileExtension,
|
||||
Message: element.Message,
|
||||
OrganicEntityId: element.OrganicEntityId,
|
||||
OriginalFileName: element.OriginalFileName,
|
||||
ProcessId: element.ProcessId
|
||||
}
|
||||
publicationArray.push(publicationlis);
|
||||
|
||||
});
|
||||
|
||||
this.getpublication = publicationArray;
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
async AddPublication(publicationType:any, folderId:any) {
|
||||
async AddPublication(publicationType: any, folderId: any) {
|
||||
const modal = await this.modalController.create({
|
||||
component: NewPublicationPage,
|
||||
componentProps:{
|
||||
componentProps: {
|
||||
publicationType: publicationType,
|
||||
folderId: folderId,
|
||||
},
|
||||
@@ -156,19 +196,19 @@ export class ViewPublicationsPage implements OnInit {
|
||||
backdropDismiss: false
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss().then(()=>{
|
||||
modal.onDidDismiss().then(() => {
|
||||
this.doRefresh(event);
|
||||
});
|
||||
}
|
||||
|
||||
goToPublicationDetail(publicationId:string){
|
||||
goToPublicationDetail(publicationId: string) {
|
||||
this.router.navigate(['/home/publications/view-publications', this.folderId, publicationId]);
|
||||
}
|
||||
|
||||
async viewPublicationDetail(publicationId:string) {
|
||||
async viewPublicationDetail(publicationId: string) {
|
||||
const modal = await this.modalController.create({
|
||||
component: PublicationDetailPage,
|
||||
componentProps:{
|
||||
componentProps: {
|
||||
publicationId: publicationId,
|
||||
folderId: this.folderId,
|
||||
},
|
||||
@@ -176,7 +216,7 @@ export class ViewPublicationsPage implements OnInit {
|
||||
// backdropDismiss: false
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss().then(()=>{
|
||||
modal.onDidDismiss().then(() => {
|
||||
this.getPublications();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -115,15 +115,7 @@ export class SqliteService {
|
||||
DateEnd varchar(255),
|
||||
Detail varchar(255),
|
||||
Description varchar(255),
|
||||
DateIndex varchar(255),
|
||||
DatePublication varchar(255),
|
||||
DocumentId INTERGER,
|
||||
FileBase64 Text,
|
||||
FileExtension varchar(255),
|
||||
Message varchar(255),
|
||||
OrganicEntityId INTERGER,
|
||||
OriginalFileName varchar(255),
|
||||
Title varchar(255)
|
||||
publications Text
|
||||
)`, [])
|
||||
.then((res) => {
|
||||
console.log("Sucess action Table created: ", res)
|
||||
@@ -136,10 +128,10 @@ export class SqliteService {
|
||||
|
||||
//addactions
|
||||
public addactions(data) {
|
||||
console.log('Action insert', data)
|
||||
this.dbInstance.executeSql(`
|
||||
INSERT OR IGNORE INTO ${this.actions} (ActionType,DateBegin,DateEnd,Description,Detail,ProcessId,DateIndex,DatePublication,DocumentId,FileBase64,FileExtension,Message,OrganicEntityId,OriginalFileName,Title)
|
||||
VALUES ('${data.ActionType}','${data.DateBegin}', '${data.DateEnd}','${data.Description}','${data.Detail}','${data.ProcessId}','${data.DateIndex}','${data.DatePublication},'${data.DocumentId}',
|
||||
'${data.FileBase64}','${data.FileExtension}','${data.Message}','${data.OrganicEntityId}','${data.OriginalFileName}','${data.Title}')`, [])
|
||||
INSERT OR IGNORE INTO ${this.actions} (ActionType,DateBegin,DateEnd,Description,Detail,ProcessId,publications)
|
||||
VALUES ('${data.ActionType}','${data.DateBegin}', '${data.DateEnd}','${data.Description}','${data.Detail}','${data.ProcessId}','${data.publications}')`, [])
|
||||
.then(() => {
|
||||
console.log("action add with Success");
|
||||
|
||||
@@ -192,8 +184,9 @@ export class SqliteService {
|
||||
|
||||
//updateActions
|
||||
public updateactions(id,data) {
|
||||
console.log("update action data", data )
|
||||
this.dbInstance.executeSql(`
|
||||
UPDATE ${this.actions} SET DateIndex = ?, DatePublication = ?,DocumentId = ?,FileBase64 = ?,FileExtension = ?,Message = ?,OrganicEntityId = ?,OriginalFileName = ?,Title = ? WHERE ProcessId = ${id}`,data)
|
||||
UPDATE ${this.actions} SET publications = ? WHERE ProcessId = ${id}`,[data])
|
||||
.then(() => {
|
||||
console.log("action update with Success");
|
||||
|
||||
@@ -403,6 +396,21 @@ export class SqliteService {
|
||||
});
|
||||
}
|
||||
|
||||
//getActionById
|
||||
getActionById(id) {
|
||||
return this.dbInstance.executeSql(`SELECT * FROM ${this.actions} WHERE ProcessId = ? `, [id]).then((res) => {
|
||||
this.ALLACTIONS = [];
|
||||
if (res.rows.length > 0) {
|
||||
for (var i = 0; i < res.rows.length; i++) {
|
||||
this.ALLACTIONS.push(res.rows.item(i))
|
||||
}
|
||||
return this.ALLACTIONS;
|
||||
}
|
||||
}, (e) => {
|
||||
console.log(" Get actions by processId error", JSON.stringify(e));
|
||||
});
|
||||
}
|
||||
|
||||
//getEventBy id
|
||||
getEventById(id) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user