Skip to content

Commit

Permalink
Single/Multiple media upload based restriction - On Project creation
Browse files Browse the repository at this point in the history
  • Loading branch information
sajeeth1009 committed Nov 6, 2019
1 parent 6fc53fa commit f666ae1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 16 deletions.
28 changes: 15 additions & 13 deletions srv/src/project/project.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,21 @@ export class ProjectController {
@UseInterceptors(FilesInterceptor('file'))
async uploadFile(@Param('id') id, @UploadedFiles() uploads: FileUpload[]) {
const project = await this.projectService.findOne(id);
uploads.forEach((upload: FileUpload) => {
if (upload.filename) {
const file = new File();

file.name = upload.originalname;
file.filename = upload.filename;
file.path = upload.path;
file.size = upload.size;
file.mimetype = upload.mimetype;

project.fileTree.children.push(file);
}
});
if(!(project.singleMedia && project.fileTree.size == 1)) {
uploads.forEach((upload: FileUpload) => {
if (upload.filename) {
const file = new File();

file.name = upload.originalname;
file.filename = upload.filename;
file.path = upload.path;
file.size = upload.size;
file.mimetype = upload.mimetype;

project.fileTree.children.push(file);
}
});
}
return await this.projectService.update(project.id.toHexString(), project);
}

Expand Down
2 changes: 1 addition & 1 deletion web/src/app/layout/filetree/filetree.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{{ directory.name }}
</div>
<div class="btn-group btn-link btn-icon action-icons">
<button type="button" class="btn" title="Upload Files" (click)="openUploadDialog()">
<button type="button" class="btn" title="Upload Files" [disabled]="(project.singleMedia && project.fileTree.children.length == 1)" (click)="openUploadDialog()">
<clr-icon shape="upload"></clr-icon>
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class ProjectModalComponent implements OnInit, OnDestroy {
onSubmit(form: FormGroup) {
this.submitted = true;
this.modalOpen = false;
this.model.singleMedia = form.value.options;

this.subscription = this.projectsService.insertProject(this.model)
.subscribe(response => {
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/upload/file-upload/file-upload.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h3 class="modal-title">Upload files</h3>
<div class="modal-body">

<div>
<button [disabled]="uploading || uploadSuccessful"
<button [disabled]="uploading || uploadSuccessful || (currentProject.singleMedia && files.size == 1)"
class="btn btn-primary-outline" (click)="addFiles()">Add files
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion web/src/app/upload/file-upload/file-upload.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class FileUploadComponent implements OnInit {
}

onFilesAdded() {
const files: { [key: string]: File } = this.file.nativeElement.files;
const files: { [key: string]: File } = this.currentProject.singleMedia? Array.prototype.slice.call( this.file.nativeElement.files, 0, 1 ) : this.file.nativeElement.files;
for (const key in files) {
if (!isNaN(parseInt(key, 10))) {
this.files.add(files[key]);
Expand Down

0 comments on commit f666ae1

Please sign in to comment.