fix publication OrifinalFilename

This commit is contained in:
Peter Maquiran
2024-01-12 12:13:51 +01:00
parent 86b65f3e46
commit 69ee75b039
15 changed files with 187 additions and 122 deletions
+25
View File
@@ -91,6 +91,7 @@
"@logisticinfotech/ionic4-datepicker": "^1.4.4",
"@ng-bootstrap/ng-bootstrap": "^9.1.2",
"@ngx-translate/core": "^13.0.0",
"@ngxs/store": "^3.8.2",
"@pdftron/pdfjs-express": "^8.0.1",
"@sentry/angular": "7.73.0",
"@sentry/capacitor": "^0.14.0",
@@ -7464,6 +7465,22 @@
"rxjs": ">=6.5.3"
}
},
"node_modules/@ngxs/store": {
"version": "3.8.2",
"resolved": "https://registry.npmjs.org/@ngxs/store/-/store-3.8.2.tgz",
"integrity": "sha512-IovxuGQDEpB9VefmbTaV1k4hms4iZ4aS9gPVZOC+qzyfvpi7zrUEsjo+yT6FfVBmBg/RLUmPCtqArzbKU5XrLQ==",
"dependencies": {
"tslib": "^2.2.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/ngxs"
},
"peerDependencies": {
"@angular/core": ">=12.0.0 <18.0.0",
"rxjs": ">=6.5.5"
}
},
"node_modules/@nodelib/fs.scandir": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@@ -49120,6 +49137,14 @@
"tslib": "^2.0.0"
}
},
"@ngxs/store": {
"version": "3.8.2",
"resolved": "https://registry.npmjs.org/@ngxs/store/-/store-3.8.2.tgz",
"integrity": "sha512-IovxuGQDEpB9VefmbTaV1k4hms4iZ4aS9gPVZOC+qzyfvpi7zrUEsjo+yT6FfVBmBg/RLUmPCtqArzbKU5XrLQ==",
"requires": {
"tslib": "^2.2.0"
}
},
"@nodelib/fs.scandir": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
+1
View File
@@ -105,6 +105,7 @@
"@logisticinfotech/ionic4-datepicker": "^1.4.4",
"@ng-bootstrap/ng-bootstrap": "^9.1.2",
"@ngx-translate/core": "^13.0.0",
"@ngxs/store": "^3.8.2",
"@pdftron/pdfjs-express": "^8.0.1",
"@sentry/angular": "7.73.0",
"@sentry/capacitor": "^0.14.0",
@@ -40,7 +40,7 @@
<video *ngIf="checkFileType.checkFileType(seleted.FileExtension) == 'video'" 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.FileBase64">
</video>
</ion-thumbnail>
@@ -25,12 +25,13 @@ 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';
import { CaptureError, CaptureImageOptions, CaptureVideoOptions, MediaCapture, MediaFile } from '@awesome-cordova-plugins/media-capture/ngx';
import { Capacitor } from '@capacitor/core';
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 { CameraService } from "src/app/services/camera.service"
const config = {
quality: 0.5,
maxWidth: 800,
@@ -133,7 +134,9 @@ export class NewPublicationPage implements OnInit {
public FileService: FileService,
private mediaCapture: MediaCapture,
public checkFileType: checkFileTypeService,
private FileValidatorService: FileValidatorService
private FileValidatorService: FileValidatorService,
private file: File,
private cameraService: CameraService
) {
this.publicationType = this.navParams.get('publicationType');
@@ -161,12 +164,17 @@ 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
@@ -195,7 +203,8 @@ export class NewPublicationPage implements OnInit {
this.photoOrVideo = false;
let fileObject = {
FileBase64: this.removeTextBeforeSlash(picture, ','),
FileExtension: capturedImage.format
FileExtension: capturedImage.format,
OriginalFileName: 'foto'
}
this.seletedContent.push(fileObject)
@@ -232,6 +241,7 @@ export class NewPublicationPage implements OnInit {
}
async startVideoRecording() {
try {
let options: CaptureImageOptions = { limit: 1 }
const data: any = await this.mediaCapture.captureVideo(options)
@@ -268,6 +278,7 @@ export class NewPublicationPage implements OnInit {
} catch (error) {
console.log('record video error: ', error)
}
}
async loadVideo() {
@@ -290,7 +301,8 @@ export class NewPublicationPage implements OnInit {
this.filecontent = true;
let fileObject = {
FileBase64: content.data,
FileExtension: this.removeTextBeforeSlash(element.mimeType, '/')
FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'),
OriginalFileName: 'foto'
}
this.seletedContent.push(fileObject)
})
@@ -390,47 +402,19 @@ export class NewPublicationPage implements OnInit {
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,
}
/* } 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,
}
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,
@@ -65,7 +65,7 @@
</div> -->
<div class="post-content">
<div class="post-content" >
<div class="post-title-time">
<div class="post-title font-15-em">
<ion-label>{{publication.Title}}</ion-label>
@@ -18,6 +18,7 @@ import { CapacitorVideoPlayer } from 'capacitor-video-player';
import { checkFileTypeService } from 'src/app/services/checkFileType.service';
import { PublicationVideoManagerService } from "src/app/services/publication/publication-video-manager.service"
import { StopvideoService } from "src/app/services/stopvideo.service"
import { Result } from 'neverthrow';
@Component({
selector: 'app-view-publications',
templateUrl: './view-publications.page.html',
+28 -3
View File
@@ -1,15 +1,18 @@
import { Injectable } from '@angular/core';
import { CaptureImageOptions, MediaCapture, MediaFile } from '@awesome-cordova-plugins/media-capture/ngx';
import { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera';
import { File } from "@awesome-cordova-plugins/file/ngx"
@Injectable({
providedIn: 'root'
})
export class CameraService {
constructor() { }
constructor(
private mediaCapture: MediaCapture,
private file: File) { }
async takePicture(){
async takePicture() {
return new Promise<Photo>(async (resolve, reject)=>{
@@ -33,4 +36,26 @@ export class CameraService {
})
}
async startRecording() {
try {
let options: CaptureImageOptions = { limit: 1}
const data: MediaFile[] = (await this.mediaCapture.captureVideo(options) as any )
const video = data[0]
let dir = video.fullPath.split("/")
dir.pop()
let fromDir = dir.join("/")
let toDir = this.file.dataDirectory
const response = await this.file.copyFile(fromDir, video.name, toDir, video.name )
console.log({response})
} catch(e) {
console.log(e)
}
}
nice() {}
}
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { CameraService } from './camera.service';
describe('CameraService', () => {
let service: CameraService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(CameraService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -0,0 +1,9 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class CameraService {
constructor() { }
}
@@ -51,12 +51,12 @@
<ion-img *ngIf="checkFileType.checkFileType(seleted.FileExtension) == 'image'"
name="image" ngDefaultControl [src]="seleted.FileBase64"></ion-img>
<video *ngIf="checkFileType.checkFileType(seleted.FileExtension) == 'video'" width="70" height="70"
preload="metadata" webkit-playsinline="webkit-playsinline">
<source type="video/mp4" [src]="seleted.FileBase64">
</video>
</ion-thumbnail>
<!-- Display the blurred image and count if there are more images -->
<ion-thumbnail *ngIf="seletedContent.length > displayLimit" lot="start">
@@ -102,8 +102,6 @@
</div>
</div> -->
<div class="ion-item-container-no-border hide-desktop">
<ion-label (click)="loadVideo()">
<div class="attach-icon">
@@ -130,7 +130,16 @@ export class NewPublicationPage implements OnInit {
}
console.log('edit',this.publication)
this.pub = this.publication;
this.seletedContent = this.publication.Files;
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)
}
)
})
this.showLoader = false;
}, (error) => {
console.log(error)
@@ -322,52 +331,47 @@ export class NewPublicationPage implements OnInit {
if (this.publicationType == ActionType.edit) {
if (!this.publication?.OriginalFileName || !this.pub.OriginalFileName) {
if (this.pub?.OriginalFileName) {
console.log('this.pub', this.pub)
}
throw ('no this.publication.OriginalFileName')
}
const loader = this.toastService.loading()
if (this.seletedContent.length > 0) {
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 || 'foto',
Files: this.seletedContent,
}
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,
Files: this.seletedContent,
}
try {
const response = await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise()
this.publication.Files = this.publication.Files.map( e => ({
FileBase64: e.FileBase64,
FileExtension: e.FileExtension,
OriginalFileName: 'foto'
}))
this.httpErroHandle.httpsSucessMessagge('Editar publicação')
console.log({ response })
try {
const response = await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise()
this.httpErroHandle.httpsSucessMessagge('Editar publicação')
console.log({ response })
this.goBack();
} catch (error) {
this.httpErroHandle.httpStatusHandle(error)
if (error.status == 404) {
this.PublicationFolderService.deletePost(this.publication.ProcessId, this.publication.DocumentId)
this.goBack();
} catch (error) {
this.httpErroHandle.httpStatusHandle(error)
if (error.status == 404) {
this.PublicationFolderService.deletePost(this.publication.ProcessId, this.publication.DocumentId)
this.goBack();
}
} finally {
loader.remove()
}
} else {
}/*
else if (!this.PublicationFolderService.PublicationHasImage(this.publication)) { //
} finally {
loader.remove()
}
/*
else if (!this.PublicationFolderService.PublicationHasImage(this.publication)) { //
this.publication = {
DateIndex: this.publication.DateIndex,
@@ -412,6 +416,16 @@ export class NewPublicationPage implements OnInit {
}
// this.publicationFormMV.setDataToFrom(this.publication)
// this.publicationFormMV.uploadVideosFiles()
this.publication.Files = this.publication.Files.map( e => ({
FileBase64: e.FileBase64,
FileExtension: e.FileExtension,
OriginalFileName: 'foto'
}))
const loader = this.toastService.loading()
try {
@@ -1043,7 +1057,7 @@ class PublicationAttachmentEntity {
this.FileBase64 = 'data:image/jpg;base64,' + this.FileBase64
}
} else if (this.FileType == 'video' ) {
if(!this.FileBase64.startsWith('data:')) {
if(!this.FileBase64.startsWith('data:') && !this.FileBase64.startsWith('http')) {
this.FileBase64 = 'data:video/mp4;base64,' + this.FileBase64
}
@@ -186,10 +186,4 @@ export class PublicationDetailPage implements OnInit {
modal.present();
}
}
@@ -79,7 +79,7 @@
</div>s -->
</swiper-container>
<div class="post-content">
<div class="post-content" (click)="viewPublicationDetail(publication.DocumentId, publication.ProcessId)">
<div class="post-title-time">
<div class="post-title">
<ion-label>{{publication.Title}}</ion-label>
@@ -227,8 +227,6 @@ export class ViewPublicationsPage implements OnInit {
this.publicationFolderService.publicationList[folderId].push(publicationDetails)
} else {
// console.log("names");
let a: any = Object.assign({},this.publicationFolderService.publicationList[folderId][findIndex])
let b: any = Object.assign({}, publicationDetails)
+2 -2
View File
@@ -217,11 +217,11 @@ 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"
}
}