update actions

This commit is contained in:
Peter Maquiran
2023-03-10 14:30:50 +01:00
parent e11a66d9c2
commit 5b06064203
3 changed files with 105 additions and 46 deletions
@@ -48,10 +48,7 @@ export class ViewPublicationsPage implements OnInit {
public p:PermissionService,
private httpErrorHandle: HttpErrorHandle
) {
if(!this.publicationList[this.folderId]) {
this.publicationList[this.folderId] = []
this.publicationItem[this.folderId] = new PublicationFolder();
}
this.createPublicationList()
}
ngOnInit() {
@@ -59,10 +56,7 @@ export class ViewPublicationsPage implements OnInit {
this.folderId = this.folderId['ProcessId']
}
if(!this.publicationList[this.folderId]) {
this.publicationList[this.folderId] = []
this.publicationItem[this.folderId] = new PublicationFolder();
}
this.createPublicationList()
window['app-view-publications-page-doRefresh'] = this.doRefresh
@@ -76,10 +70,11 @@ export class ViewPublicationsPage implements OnInit {
}
if(!this.publicationList[this.folderId]) {
this.publicationList[this.folderId] = []
this.publicationItem[this.folderId] = new PublicationFolder();
}
this.createPublicationList()
this.getFromDB();
this.getPublicationDetail();
@@ -88,6 +83,17 @@ export class ViewPublicationsPage implements OnInit {
}
createPublicationList(folderId = this.folderId) {
if(!this.publicationList[this.folderId]) {
this.publicationList[this.folderId] = []
}
if(!this.publicationItem[this.folderId]) {
this.publicationItem[this.folderId] = new PublicationFolder();
}
}
doRefresh =(event) => {
this.getPublicationDetail();
@@ -118,18 +124,22 @@ export class ViewPublicationsPage implements OnInit {
try {
const publicationIds = await this.publications.GetPublicationsList(folderId).toPromise();
this.createPublicationList(folderId)
let loadLater = []
for (let publicationId of publicationIds) {
let Publication = await this.publications.GetPublicationById(publicationId).toPromise();
let publicationDetails: Publication = this.publicationPipe.itemList(Publication)
const found = this.publicationList[folderId].find( e => e.DocumentId == publicationId )
if(!found) {
/* PublicationModel.create(publicationDetails) */
this.publicationList[folderId].push(publicationDetails)
if(!this.publicationIsPresent(publicationId, folderId)) {
await this.loadPublication(publicationId, folderId)
} else {
loadLater.push(publicationId)
}
}
for( let publicationId of loadLater) {
await this.loadPublication(publicationId, folderId)
}
this.showLoader = false;
@@ -139,7 +149,30 @@ export class ViewPublicationsPage implements OnInit {
this.showLoader = false;
}
}
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 )
}
async loadPublication(publicationId, folderId) {
let Publication = await this.publications.GetPublicationById(publicationId).toPromise();
let publicationDetails: Publication = this.publicationPipe.itemList(Publication)
const findIndex = this.publicationFindIndex(publicationId, folderId)
const found = this.publicationIsPresent(publicationId, folderId)
if(!found) {
this.publicationList[folderId].push(publicationDetails)
} else {
this.publicationList[folderId][findIndex] = publicationDetails
}
}
getFromDB() {