mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
fix
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { PublicationFolderService } from './publication-folder.service';
|
||||
|
||||
describe('PublicationFolderService', () => {
|
||||
let service: PublicationFolderService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(PublicationFolderService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,82 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user