Skip to content

Commit 010a9c9

Browse files
committed
feat: chapters first step
1 parent 432880b commit 010a9c9

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

frontend/src/angular/src/app/book-import/book-import.component.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
<div class="base-container">
1818

1919
<form [formGroup]="bookForm">
20+
<button mat-flat-button color="primary" i18n="@@bookImportAddChapter">Add Chapter</button>
21+
<ng-container formArrayName="chapters">
22+
@for(chaptersForm of chapters.controls;track chaptersForm) {
23+
<div class="chapter-container" [formGroup]="chaptersForm">
24+
<div>A</div>
25+
<div>B</div>
26+
</div>
27+
}
28+
</ng-container>
29+
2030
<input type="file" class="file-input"
2131
(change)="onFileSelected($event)" #fileUpload>
2232
<div class="file-upload">

frontend/src/angular/src/app/book-import/book-import.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,8 @@
3737

3838
.base-container {
3939
margin: 20px 5px 0 5px;
40+
}
41+
42+
.chapter-container {
43+
display: flex;
4044
}

frontend/src/angular/src/app/book-import/book-import.component.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,26 @@ import { Book, ChapterPages } from '../model/book';
1919
import { MatToolbarModule } from '@angular/material/toolbar';
2020
import { MatButtonModule } from '@angular/material/button';
2121
import { FormArray, FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
22+
import { CommonModule } from '@angular/common';
2223

2324
enum FormGroupKey{
2425
file='file',
25-
chapters='chapters'
26+
chapters='chapters',
27+
chapterStart='chapterStart',
28+
chapterEnd='chapterEnd'
2629
}
2730

2831
@Component({
2932
selector: 'app-book-import',
3033
standalone: true,
31-
imports: [MatIconModule,MatToolbarModule,MatButtonModule,ReactiveFormsModule],
34+
imports: [MatIconModule,MatToolbarModule,MatButtonModule,ReactiveFormsModule, CommonModule],
3235
templateUrl: './book-import.component.html',
3336
styleUrl: './book-import.component.scss'
3437
})
3538
export class BookImportComponent {
3639
protected bookForm = new FormGroup({
3740
[FormGroupKey.file]: new FormControl<File | null>(null, Validators.required),
38-
[FormGroupKey.chapters]: new FormArray([])
41+
[FormGroupKey.chapters]: new FormArray([this.createChapterGroupForm()])
3942
});
4043
private destroyRef = inject(DestroyRef);
4144
protected FormGroupKey = FormGroupKey;
@@ -44,6 +47,17 @@ export class BookImportComponent {
4447

4548
constructor(private documentService: DocumentService) {}
4649

50+
get chapters() {
51+
return this.bookForm.controls[FormGroupKey.chapters] as FormArray<FormGroup>;
52+
}
53+
54+
protected createChapterGroupForm(): FormGroup {
55+
return new FormGroup({
56+
[FormGroupKey.chapterStart]: new FormControl(0, Validators.required),
57+
[FormGroupKey.chapterEnd]: new FormControl(0, Validators.required)
58+
});
59+
}
60+
4761
protected logout(): void {
4862
console.log('logout');
4963
}

0 commit comments

Comments
 (0)