From 4d34faa2071d7c7caed209ac1ae8e8f201c8306d Mon Sep 17 00:00:00 2001 From: Florian Glombik <63976129+florian-glombik@users.noreply.github.com> Date: Fri, 8 Nov 2024 00:20:32 +0100 Subject: [PATCH] Development: Use signals in lecture add attachment form (#9656) --- .../lecture/lecture-attachments.component.ts | 32 +++---- .../attachment-unit-form.component.html | 10 +- .../attachment-unit-form.component.ts | 91 +++++++------------ .../create-exercise-unit.component.html | 4 +- .../create-exercise-unit.component.ts | 36 +++----- .../constants/file-extensions.constants.ts | 4 + .../attachment-unit-form.component.spec.ts | 16 ++-- 7 files changed, 79 insertions(+), 114 deletions(-) diff --git a/src/main/webapp/app/lecture/lecture-attachments.component.ts b/src/main/webapp/app/lecture/lecture-attachments.component.ts index 5b12fa24b510..6d89f669946a 100644 --- a/src/main/webapp/app/lecture/lecture-attachments.component.ts +++ b/src/main/webapp/app/lecture/lecture-attachments.component.ts @@ -1,15 +1,14 @@ import { Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; -import { HttpClient, HttpErrorResponse, HttpResponse } from '@angular/common/http'; +import { HttpErrorResponse, HttpResponse } from '@angular/common/http'; import { Lecture } from 'app/entities/lecture.model'; -import { FileUploaderService } from 'app/shared/http/file-uploader.service'; import dayjs from 'dayjs/esm'; import { Subject } from 'rxjs'; import { FileService } from 'app/shared/http/file.service'; import { Attachment, AttachmentType } from 'app/entities/attachment.model'; import { AttachmentService } from 'app/lecture/attachment.service'; import { faEye, faPaperclip, faPencilAlt, faQuestionCircle, faSpinner, faTimes, faTrash } from '@fortawesome/free-solid-svg-icons'; -import { UPLOAD_FILE_EXTENSIONS } from 'app/shared/constants/file-extensions.constants'; +import { ACCEPTED_FILE_EXTENSIONS_FILE_BROWSER, ALLOWED_FILE_EXTENSIONS_HUMAN_READABLE } from 'app/shared/constants/file-extensions.constants'; import { LectureService } from 'app/lecture/lecture.service'; @Component({ @@ -18,6 +17,17 @@ import { LectureService } from 'app/lecture/lecture.service'; styleUrls: ['./lecture-attachments.component.scss'], }) export class LectureAttachmentsComponent implements OnInit, OnDestroy { + protected readonly faSpinner = faSpinner; + protected readonly faTimes = faTimes; + protected readonly faTrash = faTrash; + protected readonly faPencilAlt = faPencilAlt; + protected readonly faPaperclip = faPaperclip; + protected readonly faQuestionCircle = faQuestionCircle; + protected readonly faEye = faEye; + + protected readonly allowedFileExtensions = ALLOWED_FILE_EXTENSIONS_HUMAN_READABLE; + protected readonly acceptedFileExtensionsFileBrowser = ACCEPTED_FILE_EXTENSIONS_FILE_BROWSER; + @ViewChild('fileInput', { static: false }) fileInput: ElementRef; @Input() lectureId: number | undefined; @Input() showHeader = true; @@ -33,29 +43,13 @@ export class LectureAttachmentsComponent implements OnInit, OnDestroy { errorMessage?: string; viewButtonAvailable: Record = {}; - // A human-readable list of allowed file extensions - readonly allowedFileExtensions = UPLOAD_FILE_EXTENSIONS.join(', '); - // The list of file extensions for the "accept" attribute of the file input field - readonly acceptedFileExtensionsFileBrowser = UPLOAD_FILE_EXTENSIONS.map((ext) => '.' + ext).join(','); - private dialogErrorSource = new Subject(); dialogError$ = this.dialogErrorSource.asObservable(); - // Icons - faSpinner = faSpinner; - faTimes = faTimes; - faTrash = faTrash; - faPencilAlt = faPencilAlt; - faPaperclip = faPaperclip; - faQuestionCircle = faQuestionCircle; - faEye = faEye; - constructor( protected activatedRoute: ActivatedRoute, private attachmentService: AttachmentService, private lectureService: LectureService, - private httpClient: HttpClient, - private fileUploaderService: FileUploaderService, private fileService: FileService, ) {} diff --git a/src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.html b/src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.html index c7d9568fb7c2..7c8434dc9023 100644 --- a/src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.html +++ b/src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-unit-form/attachment-unit-form.component.html @@ -60,13 +60,13 @@ /> - @if (isFileTooBig) { + @if (isFileTooBig()) {
{{ 'artemisApp.attachmentUnit.createAttachmentUnit.fileTooBig' | artemisTranslate }} {{ 'artemisApp.attachmentUnit.createAttachmentUnit.fileLimitation' | artemisTranslate }}
} - @if (!fileName && fileInputTouched) { + @if (!fileName() && fileInputTouched) {
} @@ -81,7 +81,7 @@ formControlName="competencyLinks" /> -
+