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", "@logisticinfotech/ionic4-datepicker": "^1.4.4",
"@ng-bootstrap/ng-bootstrap": "^9.1.2", "@ng-bootstrap/ng-bootstrap": "^9.1.2",
"@ngx-translate/core": "^13.0.0", "@ngx-translate/core": "^13.0.0",
"@ngxs/store": "^3.8.2",
"@pdftron/pdfjs-express": "^8.0.1", "@pdftron/pdfjs-express": "^8.0.1",
"@sentry/angular": "7.73.0", "@sentry/angular": "7.73.0",
"@sentry/capacitor": "^0.14.0", "@sentry/capacitor": "^0.14.0",
@@ -7464,6 +7465,22 @@
"rxjs": ">=6.5.3" "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": { "node_modules/@nodelib/fs.scandir": {
"version": "2.1.5", "version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@@ -49120,6 +49137,14 @@
"tslib": "^2.0.0" "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": { "@nodelib/fs.scandir": {
"version": "2.1.5", "version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", "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", "@logisticinfotech/ionic4-datepicker": "^1.4.4",
"@ng-bootstrap/ng-bootstrap": "^9.1.2", "@ng-bootstrap/ng-bootstrap": "^9.1.2",
"@ngx-translate/core": "^13.0.0", "@ngx-translate/core": "^13.0.0",
"@ngxs/store": "^3.8.2",
"@pdftron/pdfjs-express": "^8.0.1", "@pdftron/pdfjs-express": "^8.0.1",
"@sentry/angular": "7.73.0", "@sentry/angular": "7.73.0",
"@sentry/capacitor": "^0.14.0", "@sentry/capacitor": "^0.14.0",
@@ -40,7 +40,7 @@
<video *ngIf="checkFileType.checkFileType(seleted.FileExtension) == 'video'" width="70" height="70" <video *ngIf="checkFileType.checkFileType(seleted.FileExtension) == 'video'" width="70" height="70"
controls="controls" preload="metadata" autoplay="autoplay" webkit-playsinline="webkit-playsinline"> 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> </video>
</ion-thumbnail> </ion-thumbnail>
@@ -25,12 +25,13 @@ import { FileService } from 'src/app/services/functions/file.service';
import { readAndCompressImage } from 'browser-image-resizer'; import { readAndCompressImage } from 'browser-image-resizer';
import { FilePicker } from '@capawesome/capacitor-file-picker'; import { FilePicker } from '@capawesome/capacitor-file-picker';
import { CapacitorVideoPlayer } from 'capacitor-video-player'; 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 { Capacitor } from '@capacitor/core';
import { File } from '@ionic-native/file/ngx'; import { File } from '@ionic-native/file/ngx';
import { Media } from '@ionic-native/media/ngx'; import { Media } from '@ionic-native/media/ngx';
import { checkFileTypeService } from 'src/app/services/checkFileType.service'; import { checkFileTypeService } from 'src/app/services/checkFileType.service';
import { FileValidatorService } from "src/app/services/file/file-validator.service" import { FileValidatorService } from "src/app/services/file/file-validator.service"
import { CameraService } from "src/app/services/camera.service"
const config = { const config = {
quality: 0.5, quality: 0.5,
maxWidth: 800, maxWidth: 800,
@@ -133,7 +134,9 @@ export class NewPublicationPage implements OnInit {
public FileService: FileService, public FileService: FileService,
private mediaCapture: MediaCapture, private mediaCapture: MediaCapture,
public checkFileType: checkFileTypeService, public checkFileType: checkFileTypeService,
private FileValidatorService: FileValidatorService private FileValidatorService: FileValidatorService,
private file: File,
private cameraService: CameraService
) { ) {
this.publicationType = this.navParams.get('publicationType'); this.publicationType = this.navParams.get('publicationType');
@@ -161,12 +164,17 @@ export class NewPublicationPage implements OnInit {
recursive: true recursive: true
}); });
try {
document.addEventListener("click", clickOutside, false); document.addEventListener("click", clickOutside, false);
function clickOutside(e) { function clickOutside(e) {
const inside = document.getElementById('container-multiselect').contains(e.target); const inside = document.getElementById('container-multiselect').contains(e.target);
this.photoOrVideo = false; this.photoOrVideo = false;
console.log(this.photoOrVideo) console.log(this.photoOrVideo)
} }
} catch (error) {}
} }
// in use // in use
@@ -195,7 +203,8 @@ export class NewPublicationPage implements OnInit {
this.photoOrVideo = false; this.photoOrVideo = false;
let fileObject = { let fileObject = {
FileBase64: this.removeTextBeforeSlash(picture, ','), FileBase64: this.removeTextBeforeSlash(picture, ','),
FileExtension: capturedImage.format FileExtension: capturedImage.format,
OriginalFileName: 'foto'
} }
this.seletedContent.push(fileObject) this.seletedContent.push(fileObject)
@@ -232,6 +241,7 @@ export class NewPublicationPage implements OnInit {
} }
async startVideoRecording() { async startVideoRecording() {
try { try {
let options: CaptureImageOptions = { limit: 1 } let options: CaptureImageOptions = { limit: 1 }
const data: any = await this.mediaCapture.captureVideo(options) const data: any = await this.mediaCapture.captureVideo(options)
@@ -268,6 +278,7 @@ export class NewPublicationPage implements OnInit {
} catch (error) { } catch (error) {
console.log('record video error: ', error) console.log('record video error: ', error)
} }
} }
async loadVideo() { async loadVideo() {
@@ -290,7 +301,8 @@ export class NewPublicationPage implements OnInit {
this.filecontent = true; this.filecontent = true;
let fileObject = { let fileObject = {
FileBase64: content.data, FileBase64: content.data,
FileExtension: this.removeTextBeforeSlash(element.mimeType, '/') FileExtension: this.removeTextBeforeSlash(element.mimeType, '/'),
OriginalFileName: 'foto'
} }
this.seletedContent.push(fileObject) this.seletedContent.push(fileObject)
}) })
@@ -390,34 +402,6 @@ export class NewPublicationPage implements OnInit {
if (this.publicationType == '3') { if (this.publicationType == '3') {
const loader = this.toastService.loading() 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 = { this.publication = {
DateIndex: this.publication.DateIndex, DateIndex: this.publication.DateIndex,
DocumentId: this.publication.DocumentId, DocumentId: this.publication.DocumentId,
@@ -430,7 +414,7 @@ export class NewPublicationPage implements OnInit {
} }
} /* else { /* else {
this.publication = { this.publication = {
DateIndex: this.publication.DateIndex, DateIndex: this.publication.DateIndex,
DocumentId: this.publication.DocumentId, DocumentId: this.publication.DocumentId,
@@ -18,6 +18,7 @@ import { CapacitorVideoPlayer } from 'capacitor-video-player';
import { checkFileTypeService } from 'src/app/services/checkFileType.service'; import { checkFileTypeService } from 'src/app/services/checkFileType.service';
import { PublicationVideoManagerService } from "src/app/services/publication/publication-video-manager.service" import { PublicationVideoManagerService } from "src/app/services/publication/publication-video-manager.service"
import { StopvideoService } from "src/app/services/stopvideo.service" import { StopvideoService } from "src/app/services/stopvideo.service"
import { Result } from 'neverthrow';
@Component({ @Component({
selector: 'app-view-publications', selector: 'app-view-publications',
templateUrl: './view-publications.page.html', templateUrl: './view-publications.page.html',
+27 -2
View File
@@ -1,12 +1,15 @@
import { Injectable } from '@angular/core'; 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 { Camera, CameraResultType, CameraSource, Photo} from '@capacitor/camera';
import { File } from "@awesome-cordova-plugins/file/ngx"
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
export class CameraService { export class CameraService {
constructor() { } constructor(
private mediaCapture: MediaCapture,
private file: File) { }
async takePicture() { async takePicture() {
@@ -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'" <ion-img *ngIf="checkFileType.checkFileType(seleted.FileExtension) == 'image'"
name="image" ngDefaultControl [src]="seleted.FileBase64"></ion-img> name="image" ngDefaultControl [src]="seleted.FileBase64"></ion-img>
<video *ngIf="checkFileType.checkFileType(seleted.FileExtension) == 'video'" width="70" height="70" <video *ngIf="checkFileType.checkFileType(seleted.FileExtension) == 'video'" width="70" height="70"
preload="metadata" webkit-playsinline="webkit-playsinline"> preload="metadata" webkit-playsinline="webkit-playsinline">
<source type="video/mp4" [src]="seleted.FileBase64"> <source type="video/mp4" [src]="seleted.FileBase64">
</video> </video>
</ion-thumbnail> </ion-thumbnail>
<!-- Display the blurred image and count if there are more images --> <!-- Display the blurred image and count if there are more images -->
<ion-thumbnail *ngIf="seletedContent.length > displayLimit" lot="start"> <ion-thumbnail *ngIf="seletedContent.length > displayLimit" lot="start">
@@ -102,8 +102,6 @@
</div> </div>
</div> --> </div> -->
<div class="ion-item-container-no-border hide-desktop"> <div class="ion-item-container-no-border hide-desktop">
<ion-label (click)="loadVideo()"> <ion-label (click)="loadVideo()">
<div class="attach-icon"> <div class="attach-icon">
@@ -130,7 +130,16 @@ export class NewPublicationPage implements OnInit {
} }
console.log('edit',this.publication) console.log('edit',this.publication)
this.pub = 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; this.showLoader = false;
}, (error) => { }, (error) => {
console.log(error) console.log(error)
@@ -322,18 +331,9 @@ export class NewPublicationPage implements OnInit {
if (this.publicationType == ActionType.edit) { 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() const loader = this.toastService.loading()
if (this.seletedContent.length > 0) {
this.publication = { this.publication = {
DateIndex: this.publication.DateIndex, DateIndex: this.publication.DateIndex,
@@ -342,10 +342,16 @@ export class NewPublicationPage implements OnInit {
Title: this.pub.Title, Title: this.pub.Title,
Message: this.pub.Message, Message: this.pub.Message,
DatePublication: this.publication.DatePublication, DatePublication: this.publication.DatePublication,
OriginalFileName: this.publication.OriginalFileName || 'foto',
Files: this.seletedContent, Files: this.seletedContent,
} }
this.publication.Files = this.publication.Files.map( e => ({
FileBase64: e.FileBase64,
FileExtension: e.FileExtension,
OriginalFileName: 'foto'
}))
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()
@@ -364,9 +370,7 @@ export class NewPublicationPage implements OnInit {
} finally { } finally {
loader.remove() loader.remove()
} }
/*
} else {
}/*
else if (!this.PublicationFolderService.PublicationHasImage(this.publication)) { // else if (!this.PublicationFolderService.PublicationHasImage(this.publication)) { //
this.publication = { this.publication = {
@@ -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() const loader = this.toastService.loading()
try { try {
@@ -1043,7 +1057,7 @@ class PublicationAttachmentEntity {
this.FileBase64 = 'data:image/jpg;base64,' + this.FileBase64 this.FileBase64 = 'data:image/jpg;base64,' + this.FileBase64
} }
} else if (this.FileType == 'video' ) { } 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 this.FileBase64 = 'data:video/mp4;base64,' + this.FileBase64
} }
@@ -186,10 +186,4 @@ export class PublicationDetailPage implements OnInit {
modal.present(); modal.present();
} }
} }
@@ -79,7 +79,7 @@
</div>s --> </div>s -->
</swiper-container> </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-time">
<div class="post-title"> <div class="post-title">
<ion-label>{{publication.Title}}</ion-label> <ion-label>{{publication.Title}}</ion-label>
@@ -227,8 +227,6 @@ export class ViewPublicationsPage implements OnInit {
this.publicationFolderService.publicationList[folderId].push(publicationDetails) this.publicationFolderService.publicationList[folderId].push(publicationDetails)
} else { } else {
// console.log("names");
let a: any = Object.assign({},this.publicationFolderService.publicationList[folderId][findIndex]) let a: any = Object.assign({},this.publicationFolderService.publicationList[folderId][findIndex])
let b: any = Object.assign({}, publicationDetails) let b: any = Object.assign({}, publicationDetails)
+2 -2
View File
@@ -217,11 +217,11 @@ export class PublicationFolderService {
PublicationHasImage(Publication: Publication) { 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) { 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"
} }
} }