add entry media upload menu
This commit is contained in:
1 parent
4c318fb569
commit
c46309e458
14 files changed
+616
-2
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,29 @@
|
||||
<div class="dialog-mod card border-top border-3 border-primary rounded-0"
|
||||
style="margin-bottom: 0 !important; max-width: 800px; margin: auto;">
|
||||
<div class="modal-header card-header py-3 px-4">
|
||||
<h5 class="mb-0 text-primary">Media Upload</h5>
|
||||
<button type="button" class="btn-close" (click)="onClose()" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="card-body p-4 pt-0">
|
||||
<div class="row g-3">
|
||||
<div class="col-md-12">
|
||||
<form class="row g-3" [formGroup]="fileForm" enctype="multipart/form-data">
|
||||
<div class="col-md-12">
|
||||
<div class="form-group">
|
||||
<input type="file" id="file" name="file" class="form-control" (change)="onFileChange($event)">
|
||||
<div *ngIf="fileForm.get('file')?.invalid && fileForm.get('file')?.touched"
|
||||
class="text-danger">
|
||||
File is required
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<div class="col-12 mt-3 d-flex justify-content-end gap-3">
|
||||
<button type="button" class="btn btn-primary px-4 rounded-0" (click)="onSubmit()">Confirmer</button>
|
||||
<button type="button" class="btn btn-secondary px-4 rounded-0" (click)="onClose()">Annuler</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/* tslint:disable:no-unused-variable */
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { DebugElement } from '@angular/core';
|
||||
|
||||
import { MediaUploadModalComponent } from './media-upload-modal.component';
|
||||
|
||||
describe('MediaUploadModalComponent', () => {
|
||||
let component: MediaUploadModalComponent;
|
||||
let fixture: ComponentFixture<MediaUploadModalComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ MediaUploadModalComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(MediaUploadModalComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,63 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
|
||||
import { EntryService } from '../../../core/services/entry.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-media-upload-modal',
|
||||
templateUrl: './media-upload-modal.component.html',
|
||||
styleUrls: ['./media-upload-modal.component.css'],
|
||||
})
|
||||
export class MediaUploadModalComponent implements OnInit {
|
||||
fileForm: FormGroup;
|
||||
mediaType!: string;
|
||||
entryId!: number;
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<MediaUploadModalComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: any,
|
||||
private formBuilder: FormBuilder,
|
||||
private entryService: EntryService
|
||||
) {
|
||||
this.fileForm = this.formBuilder.group({
|
||||
file: [null],
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
if (this.data && this.data.mediaType && this.data.entryId) {
|
||||
this.mediaType = this.data.mediaType;
|
||||
this.entryId = this.data.entryId;
|
||||
} else {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
|
||||
onFileChange(event: any) {
|
||||
const file = event.target.files[0];
|
||||
this.fileForm.patchValue({ file: file });
|
||||
this.fileForm.get('file')?.updateValueAndValidity();
|
||||
}
|
||||
|
||||
onSubmit() {
|
||||
if (!this.fileForm.valid) return;
|
||||
|
||||
const formData = new FormData();
|
||||
|
||||
const fileValue = this.fileForm.get('file')?.value;
|
||||
if (fileValue) formData.append(this.mediaType, fileValue);
|
||||
|
||||
this.entryService.addEntryMedia(this.entryId, formData).subscribe({
|
||||
next: (result) => {
|
||||
this.dialogRef.close({ data: result });
|
||||
},
|
||||
error: (error) => {
|
||||
console.log(error);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
onClose() {
|
||||
this.dialogRef.close();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user