mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
83 lines
2.3 KiB
TypeScript
83 lines
2.3 KiB
TypeScript
|
|
import { Injectable } from '@angular/core';
|
||
|
|
import { PublicationFolder } from '../models/publicationfolder';
|
||
|
|
import { Storage } from '@ionic/storage';
|
||
|
|
import { Publication } from '../models/publication';
|
||
|
|
|
||
|
|
@Injectable({
|
||
|
|
providedIn: 'root'
|
||
|
|
})
|
||
|
|
export class PublicationFolderService {
|
||
|
|
|
||
|
|
publicationList: {[key: string]: Publication[] } = {};
|
||
|
|
FolderDetails: {[key: string]: PublicationFolder } = {};
|
||
|
|
|
||
|
|
keyName: string
|
||
|
|
|
||
|
|
constructor(
|
||
|
|
private storage: Storage,
|
||
|
|
) {}
|
||
|
|
|
||
|
|
|
||
|
|
getFromDB(folderId: any) {
|
||
|
|
|
||
|
|
if(!this.publicationList[folderId]) {
|
||
|
|
this.publicationList[folderId] = []
|
||
|
|
}
|
||
|
|
if(!this.FolderDetails[folderId]) {
|
||
|
|
this.FolderDetails[folderId] = new PublicationFolder();
|
||
|
|
}
|
||
|
|
|
||
|
|
this.storage.get(folderId).then((viewPublications) => {
|
||
|
|
this.publicationList[folderId] = viewPublications
|
||
|
|
})
|
||
|
|
this.storage.get(folderId+"name").then((viewPublications) => {
|
||
|
|
this.FolderDetails[folderId] = viewPublications
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
updateFolderDetails(folderId, res) {
|
||
|
|
this.FolderDetails[folderId] = res
|
||
|
|
this.storage.set(folderId+"name", res)
|
||
|
|
}
|
||
|
|
|
||
|
|
save(folderId) {
|
||
|
|
this.storage.set(folderId+"name", this.FolderDetails)
|
||
|
|
this.storage.set(folderId, this.publicationList[folderId]);
|
||
|
|
}
|
||
|
|
|
||
|
|
publicationIsPresent(publicationId, folderId) {
|
||
|
|
return this.publicationList[folderId].find( e => e.DocumentId == publicationId )
|
||
|
|
}
|
||
|
|
publicationFind(publicationId, folderId) {
|
||
|
|
return this.publicationList[folderId].find( e => e.DocumentId == publicationId )
|
||
|
|
}
|
||
|
|
publicationFindIndex(publicationId, folderId) {
|
||
|
|
return this.publicationList[folderId].findIndex( e => e.DocumentId == publicationId )
|
||
|
|
}
|
||
|
|
|
||
|
|
PublicationAddOrUpdate(folderId, publicationId, Publication: Publication) {
|
||
|
|
const findIndex = this.publicationFindIndex(publicationId, folderId)
|
||
|
|
const found = this.publicationIsPresent(publicationId, folderId)
|
||
|
|
if(!found) {
|
||
|
|
console.log('push',folderId, Publication)
|
||
|
|
this.publicationList[folderId].push(Publication)
|
||
|
|
} else {
|
||
|
|
|
||
|
|
console.log('update',folderId, Publication)
|
||
|
|
this.publicationList[folderId][findIndex] = Publication
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
deletePost(publicationId: any, folderId) {
|
||
|
|
|
||
|
|
for (let i = 0; i <= this.publicationList[folderId].length; i++) {
|
||
|
|
if(this.publicationList[folderId][i].DocumentId == publicationId) {
|
||
|
|
this.publicationList[folderId].splice(i, 1)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|