bugs before presantation

This commit is contained in:
Eudes Inácio
2024-01-31 17:13:07 +01:00
parent 07939149ee
commit 5fee98c235
10 changed files with 198 additions and 178 deletions
+47 -30
View File
@@ -10,8 +10,8 @@ import { PublicationPipe } from 'src/app/pipes/publication.pipe';
})
export class PublicationFolderService {
publicationList: {[key: string]: Publication[] } = {};
FolderDetails: {[key: string]: PublicationFolder } = {};
publicationList: { [key: string]: Publication[] } = {};
FolderDetails: { [key: string]: PublicationFolder } = {};
restoreFolder: {} = {}
@@ -25,14 +25,14 @@ export class PublicationFolderService {
constructor(
private storage: Storage,
private publications: PublicationsService,
) {}
) { }
createPublicationList(folderId) {
if(!this.publicationList[folderId]) {
if (!this.publicationList[folderId]) {
this.publicationList[folderId] = []
}
if(!this.FolderDetails[folderId]) {
if (!this.FolderDetails[folderId]) {
this.FolderDetails[folderId] = new PublicationFolder();
}
}
@@ -40,13 +40,13 @@ export class PublicationFolderService {
getFromDB(folderId: any) {
if(!this.restoreFolder[folderId]) {
if (!this.restoreFolder[folderId]) {
this.storage.get(folderId).then((viewPublications) => {
this.publicationList[folderId] = viewPublications
})
this.storage.get(folderId+"name").then((viewPublications) => {
this.storage.get(folderId + "name").then((viewPublications) => {
this.FolderDetails[folderId] = viewPublications
})
}
@@ -56,29 +56,30 @@ export class PublicationFolderService {
updateFolderDetails(folderId, res) {
this.FolderDetails[folderId] = res
this.storage.set(folderId+"name", res)
this.storage.set(folderId + "name", res)
}
save(folderId) {
this.storage.set(folderId+"name", this.FolderDetails)
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 )
return this.publicationList[folderId].find(e => e.DocumentId == publicationId)
}
publicationFind(publicationId, folderId) {
return this.publicationList[folderId].find( e => e.DocumentId == publicationId )
return this.publicationList[folderId].find(e => e.DocumentId == publicationId)
}
publicationFindIndex(publicationId, folderId) {
return this.publicationList[folderId].findIndex( e => e.DocumentId == publicationId )
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) {
if (!found) {
this.publicationList[folderId].push(Publication)
this.revertPublicationOrder(folderId);
} else {
this.publicationList[folderId][findIndex] = Publication
}
@@ -86,9 +87,9 @@ export class PublicationFolderService {
deletePost(folderId: any, DocumentId: any) {
if(this.publicationList[folderId]) {
if (this.publicationList[folderId]) {
this.publicationList[folderId] = this.publicationList[folderId].filter( e => e.DocumentId != DocumentId)
this.publicationList[folderId] = this.publicationList[folderId].filter(e => e.DocumentId != DocumentId)
this.save(folderId)
}
@@ -99,7 +100,7 @@ export class PublicationFolderService {
this.publications.GetPresidentialAction(folderId).subscribe(res => {
this.FolderDetails[folderId] = res
this.storage.set(folderId+"name", res)
this.storage.set(folderId + "name", res)
}, (error) => {
this.showLoader = false;
// this.httpErroHandle.httpStatusHandle(error)
@@ -118,7 +119,7 @@ export class PublicationFolderService {
let loadLater = []
for (let publicationId of publicationIds) {
if(!this.publicationIsPresent(publicationId, folderId)) {
if (!this.publicationIsPresent(publicationId, folderId)) {
await this.loadPublication(publicationId, folderId)
} else {
@@ -126,7 +127,7 @@ export class PublicationFolderService {
}
}
for( let publicationId of loadLater) {
for (let publicationId of loadLater) {
await this.loadPublication(publicationId, folderId)
}
@@ -134,7 +135,7 @@ export class PublicationFolderService {
this.storage.set(folderId, this.publicationList[folderId]);
this.getpublication = this.publicationList[folderId];
} catch(error) {
} catch (error) {
this.showLoader = false;
}
@@ -147,17 +148,18 @@ export class PublicationFolderService {
const findIndex = this.publicationFindIndex(publicationId, folderId)
const found = this.publicationIsPresent(publicationId, folderId)
if(!found) {
if (!found) {
this.publicationList[folderId].push(publicationDetails)
this.revertPublicationOrder(folderId);
} else {
let a: any = Object.assign({},this.publicationList[folderId][findIndex])
let a: any = Object.assign({}, this.publicationList[folderId][findIndex])
let b: any = Object.assign({}, publicationDetails)
a.Files = a.Files.length
b.Files = b.Files.length
if(JSON.stringify(a) != JSON.stringify(b)) {
if (JSON.stringify(a) != JSON.stringify(b)) {
// console.log({a, b})
this.publicationList[folderId][findIndex] = publicationDetails
@@ -171,9 +173,10 @@ export class PublicationFolderService {
async CreatePublication(folderId, publication: Publication) {
const response = await this.publications.CreatePublication(folderId, publication).toPromise()
const response = await this.publications.CreatePublication(folderId, publication).toPromise()
let publicationDetails: Publication = this.publicationPipe.itemList(response)
this.publicationList[folderId].push(publicationDetails)
this.revertPublicationOrder(folderId)
return publicationDetails
}
@@ -182,8 +185,9 @@ export class PublicationFolderService {
const findIndex = this.publicationFindIndex(publicationId, folderId)
const found = this.publicationIsPresent(publicationId, folderId)
if(!found) {
if (!found) {
this.publicationList[folderId].push(publicationDetails)
this.revertPublicationOrder(folderId)
} else {
this.publicationList[folderId][findIndex] = publicationDetails
}
@@ -196,8 +200,10 @@ export class PublicationFolderService {
const findIndex = this.publicationFindIndex(publicationId, folderId)
const found = this.publicationIsPresent(publicationId, folderId)
if(!found) {
if (!found) {
this.publicationList[folderId].push(publicationDetails)
this.revertPublicationOrder(folderId);
} else {
return this.publicationList[folderId][findIndex]
}
@@ -205,10 +211,10 @@ export class PublicationFolderService {
}
getLocalPublication (folderId, DocumentId) {
getLocalPublication(folderId, DocumentId) {
if(this.publicationList[folderId]) {
return this.publicationList[folderId].find( e => e.DocumentId == DocumentId )
if (this.publicationList[folderId]) {
return this.publicationList[folderId].find(e => e.DocumentId == DocumentId)
} else {
}
@@ -217,11 +223,22 @@ export class PublicationFolderService {
PublicationHasImage(Publication: Publication) {
return Publication?.Files?.[0]?.FileBase64 != '' && Publication?.Files?.[0]?.FileBase64 != "data:image/jpg;base64,null"
return Publication?.Files?.[0]?.FileBase64 != '' && Publication?.Files?.[0]?.FileBase64 != "data:image/jpg;base64,null"
}
hasCapturedImage(Publication: Publication) {
return Publication?.Files?.[0]?.FileBase64 != '' && Publication?.Files?.[0]?.FileBase64 != "data:image/jpg;base64,null"
return Publication?.Files?.[0]?.FileBase64 != '' && Publication?.Files?.[0]?.FileBase64 != "data:image/jpg;base64,null"
}
revertPublicationOrder(folderId) {
//Revert order of the list
if (this.publicationList[folderId]) {
this.publicationList[folderId] = this.publicationList[folderId].sort((a, b) => {
const dateA = new Date(a.DatePublication).getTime();
const dateB = new Date(b.DatePublication).getTime();
return dateB - dateA; // Revertendo a ordem aqui
})
}
}
}