Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lectures: Validate the date for lecture units #9765

Merged
merged 10 commits into from
Nov 24, 2024
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Component, ElementRef, OnChanges, ViewChild, computed, inject, input, output, signal } from '@angular/core';
import { Component, ElementRef, OnChanges, ViewChild, computed, inject, input, output, signal, viewChild } from '@angular/core';
import dayjs from 'dayjs/esm';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { faQuestionCircle, faTimes } from '@fortawesome/free-solid-svg-icons';
import { ACCEPTED_FILE_EXTENSIONS_FILE_BROWSER, ALLOWED_FILE_EXTENSIONS_HUMAN_READABLE } from 'app/shared/constants/file-extensions.constants';
import { CompetencyLectureUnitLink } from 'app/entities/competency.model';
import { MAX_FILE_SIZE } from 'app/shared/constants/input.constants';
import { toSignal } from '@angular/core/rxjs-interop';
import { FormDateTimePickerComponent } from 'app/shared/date-time-picker/date-time-picker.component';

export interface AttachmentUnitFormData {
formProperties: FormProperties;
Expand Down Expand Up @@ -47,6 +48,8 @@ export class AttachmentUnitFormComponent implements OnChanges {
hasCancelButton = input<boolean>(false);
onCancel = output<void>();

datePickerComponent = viewChild(FormDateTimePickerComponent);

// have to handle the file input as a special case at is not part of the reactive form
@ViewChild('fileInput', { static: false })
fileInput: ElementRef;
Expand All @@ -68,7 +71,7 @@ export class AttachmentUnitFormComponent implements OnChanges {
private readonly statusChanges = toSignal(this.form.statusChanges ?? 'INVALID');

isFormValid = computed(() => {
return (this.statusChanges() === 'VALID' || this.fileName()) && !this.isFileTooBig();
return (this.statusChanges() === 'VALID' || this.fileName()) && !this.isFileTooBig() && this.datePickerComponent()?.isValid();
});
florian-glombik marked this conversation as resolved.
Show resolved Hide resolved

ngOnChanges(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dayjs from 'dayjs/esm';
import { Component, OnChanges, computed, inject, input, output } from '@angular/core';
import { Component, OnChanges, computed, inject, input, output, viewChild } from '@angular/core';
import { AbstractControl, FormBuilder, FormGroup, Validators } from '@angular/forms';
import { faArrowLeft, faTimes } from '@fortawesome/free-solid-svg-icons';
import { map } from 'rxjs';
Expand All @@ -8,6 +8,7 @@ import { OnlineResourceDTO } from 'app/lecture/lecture-unit/lecture-unit-managem
import { OnlineUnitService } from 'app/lecture/lecture-unit/lecture-unit-management/onlineUnit.service';
import { CompetencyLectureUnitLink } from 'app/entities/competency.model';
import { toSignal } from '@angular/core/rxjs-interop';
import { FormDateTimePickerComponent } from 'app/shared/date-time-picker/date-time-picker.component';

export interface OnlineUnitFormData {
name?: string;
Expand Down Expand Up @@ -45,6 +46,8 @@ export class OnlineUnitFormComponent implements OnChanges {
hasCancelButton = input<boolean>(false);
onCancel = output<void>();

datePickerComponent = viewChild(FormDateTimePickerComponent);

urlValidator = urlValidator;

private readonly formBuilder = inject(FormBuilder);
Expand All @@ -59,7 +62,7 @@ export class OnlineUnitFormComponent implements OnChanges {
});

private readonly statusChanges = toSignal(this.form.statusChanges ?? 'INVALID');
isFormValid = computed(() => this.statusChanges() === 'VALID');
isFormValid = computed(() => this.statusChanges() === 'VALID' && this.datePickerComponent()?.isValid());

get nameControl() {
return this.form.get('name');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnChanges, OnDestroy, OnInit, computed, inject, input, output } from '@angular/core';
import { Component, OnChanges, OnDestroy, OnInit, computed, inject, input, output, viewChild } from '@angular/core';
import dayjs from 'dayjs/esm';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Router } from '@angular/router';
Expand All @@ -8,6 +8,7 @@ import { TranslateService } from '@ngx-translate/core';
import { faTimes } from '@fortawesome/free-solid-svg-icons';
import { CompetencyLectureUnitLink } from 'app/entities/competency.model';
import { toSignal } from '@angular/core/rxjs-interop';
import { FormDateTimePickerComponent } from 'app/shared/date-time-picker/date-time-picker.component';

export interface TextUnitFormData {
name?: string;
Expand All @@ -32,6 +33,8 @@ export class TextUnitFormComponent implements OnInit, OnChanges, OnDestroy {
hasCancelButton = input<boolean>(false);
onCancel = output<void>();

datePickerComponent = viewChild(FormDateTimePickerComponent);

// not included in reactive form
content: string | undefined;
contentLoadedFromCache = false;
Expand All @@ -46,7 +49,7 @@ export class TextUnitFormComponent implements OnInit, OnChanges, OnDestroy {
});

private readonly statusChanges = toSignal(this.form.statusChanges ?? 'INVALID');
isFormValid = computed(() => this.statusChanges() === 'VALID');
isFormValid = computed(() => this.statusChanges() === 'VALID' && this.datePickerComponent()?.isValid());

private markdownChanges = new Subject<string>();
private markdownChangesSubscription: Subscription;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import dayjs from 'dayjs/esm';
import { Component, computed, effect, inject, input, output, untracked } from '@angular/core';
import { Component, computed, effect, inject, input, output, untracked, viewChild } from '@angular/core';
import { AbstractControl, FormBuilder, FormGroup, ValidationErrors, Validators } from '@angular/forms';
import urlParser from 'js-video-url-parser';
import { faArrowLeft, faTimes } from '@fortawesome/free-solid-svg-icons';
import { CompetencyLectureUnitLink } from 'app/entities/competency.model';
import { toSignal } from '@angular/core/rxjs-interop';
import { FormDateTimePickerComponent } from 'app/shared/date-time-picker/date-time-picker.component';

export interface VideoUnitFormData {
name?: string;
Expand Down Expand Up @@ -72,6 +73,8 @@ export class VideoUnitFormComponent {
hasCancelButton = input<boolean>();
onCancel = output<void>();

datePickerComponent = viewChild(FormDateTimePickerComponent);
florian-glombik marked this conversation as resolved.
Show resolved Hide resolved

videoSourceUrlValidator = videoSourceUrlValidator;
videoSourceTransformUrlValidator = videoSourceTransformUrlValidator;

Expand All @@ -84,7 +87,7 @@ export class VideoUnitFormComponent {
competencyLinks: [undefined as CompetencyLectureUnitLink[] | undefined],
});
private readonly statusChanges = toSignal(this.form.statusChanges ?? 'INVALID');
isFormValid = computed(() => this.statusChanges() === 'VALID');
isFormValid = computed(() => this.statusChanges() === 'VALID' && this.datePickerComponent()?.isValid());

constructor() {
effect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@ import { AttachmentUnitFormComponent, AttachmentUnitFormData } from 'app/lecture
import { FormDateTimePickerComponent } from 'app/shared/date-time-picker/date-time-picker.component';
import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe';
import dayjs from 'dayjs/esm';
import { MockComponent, MockDirective, MockPipe } from 'ng-mocks';
import { MockComponent, MockDirective, MockModule, MockPipe } from 'ng-mocks';
import { NgbTooltip } from '@ng-bootstrap/ng-bootstrap';
import { CompetencySelectionComponent } from 'app/shared/competency-selection/competency-selection.component';
import { MAX_FILE_SIZE } from 'app/shared/constants/input.constants';
import { OwlDateTimeModule, OwlNativeDateTimeModule } from '@danielmoncada/angular-datetime-picker';

describe('AttachmentUnitFormComponent', () => {
let attachmentUnitFormComponentFixture: ComponentFixture<AttachmentUnitFormComponent>;
let attachmentUnitFormComponent: AttachmentUnitFormComponent;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ReactiveFormsModule, FormsModule, MockDirective(NgbTooltip)],
imports: [ReactiveFormsModule, FormsModule, MockDirective(NgbTooltip), FormDateTimePickerComponent],
florian-glombik marked this conversation as resolved.
Show resolved Hide resolved
declarations: [
AttachmentUnitFormComponent,
MockPipe(ArtemisTranslatePipe),
MockComponent(FormDateTimePickerComponent),
MockComponent(FaIconComponent),
MockComponent(CompetencySelectionComponent),
MockModule(OwlDateTimeModule),
MockModule(OwlNativeDateTimeModule),
florian-glombik marked this conversation as resolved.
Show resolved Hide resolved
],
schemas: [],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,32 @@ import { OnlineUnitFormComponent, OnlineUnitFormData } from 'app/lecture/lecture
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe';
import { MockComponent, MockPipe, MockProvider } from 'ng-mocks';
import { MockComponent, MockModule, MockPipe, MockProvider } from 'ng-mocks';
import { FormDateTimePickerComponent } from 'app/shared/date-time-picker/date-time-picker.component';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { OnlineUnitService } from 'app/lecture/lecture-unit/lecture-unit-management/onlineUnit.service';
import { OnlineResourceDTO } from 'app/lecture/lecture-unit/lecture-unit-management/online-resource-dto.model';
import { HttpResponse } from '@angular/common/http';
import { of } from 'rxjs';
import { CompetencySelectionComponent } from 'app/shared/competency-selection/competency-selection.component';
import { OwlDateTimeModule, OwlNativeDateTimeModule } from '@danielmoncada/angular-datetime-picker';
import { ArtemisTestModule } from '../../../test.module';
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';

describe('OnlineUnitFormComponent', () => {
let onlineUnitFormComponentFixture: ComponentFixture<OnlineUnitFormComponent>;
let onlineUnitFormComponent: OnlineUnitFormComponent;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ReactiveFormsModule, FormsModule],
imports: [ArtemisTestModule, ReactiveFormsModule, FormsModule, FormDateTimePickerComponent, MockModule(NgbTooltipModule)],
florian-glombik marked this conversation as resolved.
Show resolved Hide resolved
declarations: [
OnlineUnitFormComponent,
MockPipe(ArtemisTranslatePipe),
MockComponent(FormDateTimePickerComponent),
MockComponent(FaIconComponent),
MockComponent(CompetencySelectionComponent),
MockModule(OwlDateTimeModule),
MockModule(OwlNativeDateTimeModule),
],
providers: [MockProvider(OnlineUnitService)],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import { TextUnitFormComponent, TextUnitFormData } from 'app/lecture/lecture-uni
import { FormDateTimePickerComponent } from 'app/shared/date-time-picker/date-time-picker.component';
import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe';
import dayjs from 'dayjs/esm';
import { MockComponent, MockPipe, MockProvider } from 'ng-mocks';
import { MockComponent, MockModule, MockPipe, MockProvider } from 'ng-mocks';
import { MockRouter } from '../../../helpers/mocks/mock-router';
import { CompetencySelectionComponent } from 'app/shared/competency-selection/competency-selection.component';
import { ArtemisTestModule } from '../../../test.module';
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
import { OwlDateTimeModule, OwlNativeDateTimeModule } from '@danielmoncada/angular-datetime-picker';

@Component({ selector: 'jhi-markdown-editor-monaco', template: '' })
class MarkdownEditorStubComponent {
Expand Down Expand Up @@ -43,13 +46,14 @@ describe('TextUnitFormComponent', () => {
});

TestBed.configureTestingModule({
imports: [ReactiveFormsModule, FormsModule],
imports: [ArtemisTestModule, ReactiveFormsModule, FormsModule, FormDateTimePickerComponent, MockModule(NgbTooltipModule)],
florian-glombik marked this conversation as resolved.
Show resolved Hide resolved
declarations: [
TextUnitFormComponent,
MarkdownEditorStubComponent,
MockComponent(FormDateTimePickerComponent),
MockPipe(ArtemisTranslatePipe),
MockComponent(CompetencySelectionComponent),
MockModule(OwlDateTimeModule),
MockModule(OwlNativeDateTimeModule),
],
providers: [MockProvider(TranslateService), { provide: Router, useClass: MockRouter }],
schemas: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { VideoUnitFormComponent, VideoUnitFormData } from 'app/lecture/lecture-u
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe';
import { MockComponent, MockPipe } from 'ng-mocks';
import { MockComponent, MockModule, MockPipe } from 'ng-mocks';
import { FormDateTimePickerComponent } from 'app/shared/date-time-picker/date-time-picker.component';
import { FaIconComponent } from '@fortawesome/angular-fontawesome';
import { CompetencySelectionComponent } from 'app/shared/competency-selection/competency-selection.component';
import { OwlDateTimeModule, OwlNativeDateTimeModule } from '@danielmoncada/angular-datetime-picker';
import { ArtemisTestModule } from '../../../test.module';
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';

describe('VideoUnitFormComponent', () => {
const validYouTubeUrl = 'https://www.youtube.com/watch?v=8iU8LPEa4o0';
Expand All @@ -16,13 +19,14 @@ describe('VideoUnitFormComponent', () => {

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ReactiveFormsModule, FormsModule],
imports: [ArtemisTestModule, ReactiveFormsModule, FormsModule, FormDateTimePickerComponent, MockModule(NgbTooltipModule)],
declarations: [
VideoUnitFormComponent,
MockPipe(ArtemisTranslatePipe),
MockComponent(FormDateTimePickerComponent),
MockComponent(FaIconComponent),
MockComponent(CompetencySelectionComponent),
MockModule(OwlDateTimeModule),
MockModule(OwlNativeDateTimeModule),
florian-glombik marked this conversation as resolved.
Show resolved Hide resolved
],
providers: [],
schemas: [],
Expand Down
Loading