This commit is contained in:
Peter Maquiran
2024-02-23 12:39:59 +01:00
29 changed files with 1742 additions and 877 deletions
@@ -40,19 +40,23 @@
<ion-img *ngIf="checkFileType.checkFileType(seleted.FileExtension) == 'image'" [(ngModel)]="capturedImage"
name="image" ngDefaultControl [src]="'data:image/jpg;base64,' + seleted.FileBase64"
name="image" ngDefaultControl [src]="'data:image/jpg;base64,' + seleted.Base64"
(click)="imageSize(capturedImage)" style="height: 69px;"></ion-img>
<video *ngIf="checkFileType.checkFileType(seleted.FileExtension) == 'video'" width="70" height="70"
<video class="55" *ngIf="checkFileType.checkFileType(seleted.FileExtension) == 'video' && publicationTitle == ActionType.edit" width="70" height="70"
controls="controls" preload="metadata" autoplay="autoplay" webkit-playsinline="webkit-playsinline">
<source type="video/mp4" [src]="seleted.FileBase64">
<source type="video/mp4" [src]="'data:video/mp4;base64,' + seleted.Base64">
</video>
<video class="src" *ngIf="checkFileType.checkFileType(seleted.FileExtension) == 'video' && publicationTitle != ActionType.edit" width="70" height="70"
controls="controls" preload="metadata" autoplay="autoplay" webkit-playsinline="webkit-playsinline">
<source type="video/mp4" [src]="seleted.url">
</video>
</div>
<!-- Display the blurred image and count if there are more images -->
<ion-thumbnail *ngIf="seletedContent.length > displayLimit" lot="start">
<ion-img [src]="'data:image/jpg;base64,' + seletedContent[displayLimit - 1].base64"
<ion-img [src]="'data:image/jpg;base64,' + seletedContent[displayLimit - 1].Base64"
style="filter: blur(5px);"></ion-img>
<p>mais {{ seletedContent.length - displayLimit }}</p>
@@ -22,7 +22,6 @@ import { HttpErrorHandle } from 'src/app/services/http-error-handle.service';
import { PublicationFolderService } from 'src/app/store/publication-folder.service';
import { RouteService } from 'src/app/services/route.service';
import { FileService } from 'src/app/services/functions/file.service';
import { readAndCompressImage } from 'browser-image-resizer';
import { FilePicker } from '@capawesome/capacitor-file-picker';
import { CapacitorVideoPlayer } from 'capacitor-video-player';
import { CaptureError, CaptureImageOptions, MediaCapture, MediaFile } from '@awesome-cordova-plugins/media-capture/ngx';
@@ -31,9 +30,7 @@ import { File } from '@ionic-native/file/ngx';
import { Media } from '@ionic-native/media/ngx';
import { checkFileTypeService } from 'src/app/services/checkFileType.service';
import { FileValidatorService } from "src/app/services/file/file-validator.service"
import { App } from '@capacitor/app';
import { Router } from '@angular/router';
import { PublicationAttachmentEntity } from 'src/app/shared/publication/upload/upload-streaming.service';
const config = {
quality: 0.5,
maxWidth: 800,
@@ -95,6 +92,13 @@ export class NewPublicationPage implements OnInit {
publicationTitle: string;
imgUrl: any;
ActionType = {
newRapid : "1",
new: "2",
edit: "3"
}
Defaultimage: any = '';
photo: SafeResourceUrl;
@@ -115,7 +119,7 @@ export class NewPublicationPage implements OnInit {
photoOrVideo: boolean = false;
fileType = "";
filecontent: boolean;
seletedContent: any[] = []
seletedContent: PublicationAttachmentEntity[] = []
// Set a limit for the number of images to display
displayLimit = 4;
filesSizeSum = 0;
@@ -136,8 +140,7 @@ export class NewPublicationPage implements OnInit {
public FileService: FileService,
private mediaCapture: MediaCapture,
public checkFileType: checkFileTypeService,
private FileValidatorService: FileValidatorService,
private router: Router,
private FileValidatorService: FileValidatorService
) {
this.publicationType = this.navParams.get('publicationType');
@@ -146,6 +149,18 @@ export class NewPublicationPage implements OnInit {
if (this.publication) {
this.seletedContent = this.publication.Files;
this.filecontent = true;
this.seletedContent = this.publication.Files.map(e => {
return new PublicationAttachmentEntity(
{
base64: e.FileBase64,
extension: e.FileExtension,
OriginalFileName: e.OriginalFileName,
FileType: this.checkFileType.checkFileType(e.FileExtension) as any
}
)
})
}
console.log('Edit', this.publication)
this.publicationTitle = 'Nova Publicação';
@@ -165,12 +180,16 @@ export class NewPublicationPage implements OnInit {
recursive: true
});
document.addEventListener("click", clickOutside, false);
function clickOutside(e) {
const inside = document.getElementById('container-multiselect').contains(e.target);
this.photoOrVideo = false;
console.log(this.photoOrVideo)
}
try {
document.addEventListener("click", clickOutside, false);
function clickOutside(e) {
const inside = document.getElementById('container-multiselect').contains(e.target);
this.photoOrVideo = false;
console.log(this.photoOrVideo)
}
} catch (error) {}
}
// in use
@@ -197,11 +216,14 @@ export class NewPublicationPage implements OnInit {
console.log('take picture', this.removeTextBeforeSlash(picture, ','),)
this.filecontent = true;
this.photoOrVideo = false;
let fileObject = {
FileBase64: this.removeTextBeforeSlash(picture, ','),
FileExtension: capturedImage.format,
const fileObject = new PublicationAttachmentEntity({
base64: this.removeTextBeforeSlash(picture, ','),
extension: capturedImage.format,
FileType: 'image',
OriginalFileName: 'image'
}
})
this.seletedContent.push(fileObject)
@@ -255,11 +277,14 @@ export class NewPublicationPage implements OnInit {
.then(async (content) => {
this.filecontent = true;
let fileObject = {
FileBase64: 'data:video/mp4;base64,' + content.data,
FileExtension: 'mp4',
OriginalFileName: 'video'
}
let fileObject = new PublicationAttachmentEntity({
base64: 'data:video/mp4;base64,'+content.data,
extension: 'mp4',
OriginalFileName: 'record',
FileType: 'video'
})
this.seletedContent.push(fileObject)
})
.catch((err) => console.error(err));
@@ -282,7 +307,7 @@ export class NewPublicationPage implements OnInit {
({
multiple: true,
});
console.log(result.files)
console.log(result.files)
result.files.forEach(element => {
this.filesSizeSum = this.filesSizeSum + element.size
@@ -297,18 +322,29 @@ export class NewPublicationPage implements OnInit {
console.log(content)
this.filecontent = true;
let fileObject;
if (this.removeTextBeforeSlash(element.mimeType, '/') == "mp4") {
fileObject = {
FileBase64: 'data:video/mp4;base64,' + content.data,
FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'),
OriginalFileName: 'video'
}
if(this.removeTextBeforeSlash(element.mimeType, '/') == "mp4") {
const extension = this.removeTextBeforeSlash(element.mimeType, '/')
fileObject = new PublicationAttachmentEntity({
base64: content.data,
extension: extension,
OriginalFileName: 'video',
FileType: 'video'
})
} else {
fileObject = {
FileBase64: content.data,
FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'),
OriginalFileName: 'image'
}
const extension = this.removeTextBeforeSlash(element.mimeType, '/')
fileObject = new PublicationAttachmentEntity({
base64: content.data,
extension: extension,
OriginalFileName: 'image',
FileType: 'image'
})
}
this.seletedContent.push(fileObject)
@@ -357,24 +393,24 @@ export class NewPublicationPage implements OnInit {
/* // in use
async laodPicture() {
const capturedImage = await Camera.getPhoto({
quality: 90,
// allowEditing: true,
resultType: CameraResultType.Uri,
source: CameraSource.Photos
});
const response = await fetch(capturedImage.webPath!);
const blob = await response.blob();
this.convertBlobToBase64Worker.postMessage(blob);
this.convertBlobToBase64Worker.onmessage = async (oEvent)=> {
this.capturedImage = oEvent.data
this.capturedImageTitle = 'foto'
}
} */
@@ -409,52 +445,51 @@ export class NewPublicationPage implements OnInit {
if (this.Form.invalid) return false
if (this.seletedContent.length != 0) {
if (this.publicationType == '3') {
const loader = this.toastService.loading()
if (this.publicationType == '3') {
const loader = this.toastService.loading()
// has file
if (this.PublicationFolderService.PublicationHasImage(this.publication)) {
this.publication = {
DateIndex: this.publication.DateIndex,
DocumentId: this.publication.DocumentId,
ProcessId: this.publication.ProcessId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: this.publication.DatePublication,
OriginalFileName: this.publication.OriginalFileName,
Files: this.seletedContent,
}
// has file
if (this.PublicationFolderService.PublicationHasImage(this.publication)) {
this.publication = {
DateIndex: this.publication.DateIndex,
DocumentId: this.publication.DocumentId,
ProcessId: this.publication.ProcessId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: this.publication.DatePublication,
OriginalFileName: this.publication.OriginalFileName,
Files: this.seletedContent,
}
/* } else if (this.capturedVideo != '' && this.capturedImage == '') {
this.publication = {
DateIndex: this.publication.DateIndex,
DocumentId: this.publication.DocumentId,
ProcessId: this.publication.ProcessId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: this.publication.DatePublication,
OriginalFileName: this.publication.OriginalFileName || 'video',
Files: this.seletedContent,
FileExtension: 'mp4',
}
} */
// no names
} else if (!this.PublicationFolderService.PublicationHasImage(this.publication)) {
this.publication = {
DateIndex: this.publication.DateIndex,
DocumentId: this.publication.DocumentId,
ProcessId: this.publication.ProcessId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: this.publication.DatePublication,
OriginalFileName: this.publication.OriginalFileName,
Files: this.seletedContent,
}
/* } else if (this.capturedVideo != '' && this.capturedImage == '') {
this.publication = {
DateIndex: this.publication.DateIndex,
DocumentId: this.publication.DocumentId,
ProcessId: this.publication.ProcessId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: this.publication.DatePublication,
OriginalFileName: this.publication.OriginalFileName || 'video',
Files: this.seletedContent,
FileExtension: 'mp4',
}
} */
// no names
} else if (!this.PublicationFolderService.PublicationHasImage(this.publication)) {
this.publication = {
DateIndex: this.publication.DateIndex,
DocumentId: this.publication.DocumentId,
ProcessId: this.publication.ProcessId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: this.publication.DatePublication,
OriginalFileName: this.publication.OriginalFileName,
Files: this.seletedContent,
}
} /* else {
} /* else {
this.publication = {
DateIndex: this.publication.DateIndex,
DocumentId: this.publication.DocumentId,
@@ -470,96 +505,90 @@ export class NewPublicationPage implements OnInit {
} */
try {
try {
const response = await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise()
const response = await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise()
this.httpErrorHandle.httpsSucessMessagge('Editar publicação')
console.log({ response })
this.httpErrorHandle.httpsSucessMessagge('Editar publicação')
console.log({ response })
this.close();
} catch (error) {
if (error.status == 404) {
this.PublicationFolderService.deletePost(this.publication.ProcessId, this.publication.DocumentId)
this.close();
} catch (error) {
if (error.status == 404) {
this.PublicationFolderService.deletePost(this.publication.ProcessId, this.publication.DocumentId)
this.close();
}
this.httpErrorHandle.httpStatusHandle(error)
} finally {
loader.remove()
}
}
else {
const date = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss')
/* this.seletedContent = this.seletedContent.map((e) => {
if(e.FileExtension == "mp4") {
return {
FileBase64: e.FileBase64,
FileExtension: 'data:video/mp4;base64,'+e.FileExtension,
OriginalFileName: "video",
}
}
return e
}) */
/* if (this.capturedImage != '') { */
this.publication = {
DateIndex: date,
DocumentId: null,
ProcessId: this.folderId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: date,
OriginalFileName: this.capturedImageTitle || 'foto',
Files: this.seletedContent,
/* FileExtension: 'jpeg', */
}
/* } else if (this.capturedVideo != '') {
this.publication = {
DateIndex: date,
DocumentId: null,
ProcessId: this.folderId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: date,
OriginalFileName: this.capturedImageTitle || 'video',
Files: this.seletedContent,
FileExtension: 'mp4',
}
} */
const loader = this.toastService.loading()
try {
await this.publications.CreatePublication(this.folderId, this.publication).toPromise();
this.httpErrorHandle.httpsSucessMessagge('Criar publicação')
if(window["sharedContent"]) {
this.router.navigate(['/home/publications', this.folderId]);
return
}
this.close();
} catch (error) {
this.httpErrorHandle.httpStatusHandle(error)
} finally {
loader.remove()
}
this.httpErrorHandle.httpStatusHandle(error)
} finally {
loader.remove()
}
this.PublicationFolderService.getPublicationsIds(this.folderId)
} else {
this.httpErrorHandle.validationMessagge("noFileSelected")
}
else {
const date = formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss')
/* this.seletedContent = this.seletedContent.map((e) => {
if(e.FileExtension == "mp4") {
return {
FileBase64: e.FileBase64,
FileExtension: 'data:video/mp4;base64,'+e.FileExtension,
OriginalFileName: "video",
}
}
return e
}) */
/* if (this.capturedImage != '') { */
this.publication = {
DateIndex: date,
DocumentId: null,
ProcessId: this.folderId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: date,
OriginalFileName: this.capturedImageTitle || 'foto',
Files: this.seletedContent,
/* FileExtension: 'jpeg', */
}
/* } else if (this.capturedVideo != '') {
this.publication = {
DateIndex: date,
DocumentId: null,
ProcessId: this.folderId,
Title: this.pub.Title,
Message: this.pub.Message,
DatePublication: date,
OriginalFileName: this.capturedImageTitle || 'video',
Files: this.seletedContent,
FileExtension: 'mp4',
}
} */
const loader = this.toastService.loading()
try {
await this.publications.CreatePublication(this.folderId, this.publication).toPromise();
this.close();
this.httpErrorHandle.httpsSucessMessagge('Criar publicação')
window["sharedContent"] = null;
window["endSharedContent"] = null;
this.close();
} catch (error) {
this.httpErrorHandle.httpStatusHandle(error)
} finally {
loader.remove()
}
}
this.PublicationFolderService.getPublicationsIds(this.folderId)
}
@@ -567,10 +596,6 @@ export class NewPublicationPage implements OnInit {
this.modalController.dismiss(this.publication).then(() => {
this.showLoader = true;
});
if(window["sharedContent"]) {
this.closeApp();
}
}
clear() {
@@ -753,23 +778,15 @@ export class NewPublicationPage implements OnInit {
if (this.checkFileType.checkFileType(FileExtension) == 'image' || this.checkFileType.checkFileType(FileExtension) == 'video') {
let resultUrl = decodeURIComponent(element.url);
Filesystem.readFile({ path: resultUrl }).then(async (content) => {
let fileObject;
if (this.checkFileType.checkFileType(FileExtension) == 'image') {
fileObject = {
FileBase64: this.removeTextBeforeSlash(content.data, ','),
FileExtension: FileExtension,
OriginalFileName: 'shared',
}
} else if (this.checkFileType.checkFileType(FileExtension) == 'video') {
fileObject = {
FileBase64: 'data:video/mp4;base64,' + this.removeTextBeforeSlash(content.data, ','),
FileExtension: FileExtension,
OriginalFileName: 'shared',
let fileObject = new PublicationAttachmentEntity(
{
base64: this.removeTextBeforeSlash(content.data, ','),
extension: FileExtension,
OriginalFileName: "share-content",
FileType: this.checkFileType.checkFileType(FileExtension) as any
}
}
console.log('shared base', content.data)
)
this.seletedContent.push(fileObject)
})
@@ -791,9 +808,5 @@ export class NewPublicationPage implements OnInit {
this.seletedContent.splice(index, 1)
}
closeApp() {
App.exitApp()
}
}
@@ -19,12 +19,9 @@
<div class="title-content width-100 d-flex justify-space-between">
<div class="div-title flex-grow-1">
<ion-label class="title font-25-em">Acções</ion-label>
<!-- <div>
<input type="file" (change)="onFileSelect($event)" />
</div> -->
</div>
<div class="div-icon">
<div *ngIf="!intent" class="div-icon">
<button *ngIf="p.userPermission([p.permissionList.Actions.create])" title="Adicionar nova ação presidencial" class="btn-no-color" (click)="AddPublicationFolder()">
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " slot="icon-only" src='assets/images/icons-add.svg'></ion-icon>
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " slot="icon-only" src='assets/images/theme/gov/icons-add.svg'></ion-icon>
@@ -34,12 +31,12 @@
<ion-icon class=" font-45-em" src="assets/images/theme/gov/icon-reload.svg"></ion-icon>
</button>
</div>
<!-- <div *ngIf="intent" class="div-icon">
<div *ngIf="intent" class="div-icon">
<button title="Atualizar" class="btn-no-color" (click)="close()">
<ion-icon class=" font-45-em" src="assets/images/icons-search-close.svg"></ion-icon>
</button>
</div> -->
</div>
</div>
</div>
@@ -82,7 +82,7 @@ export class PublicationsPage implements OnInit {
this.months = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
this.days = ["Domingo", "Segunda-feira", "Terça-feira", "Quarta-feira", "Quinta-feira", "Sexta-feira", "Sábado"];
this.intent = window["sharedContent"]
}
ngOnInit() {