This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export interface TODO { | |
| id: number; | |
| name: string; | |
| type: string; // = 'Coding' | 'Reading' | 'Writing'; | |
| description?: string; | |
| dependencies?: TODO; | |
| } | |
| @Component({ | |
| selector: 'app-todo-list', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <h1 mat-dialog-title>Create new TODO</h1> | |
| <div mat-dialog-content [formGroup]="todoForm"> | |
| <mat-form-field> | |
| <mat-label>Name</mat-label> | |
| <input formControlName="name" matInput required/> | |
| </mat-form-field> | |
| <mat-form-field> | |
| <mat-label>Select a type</mat-label> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export interface TodoDialogData { | |
| todo?: TODO; | |
| mode: string; // 'create' | 'update' | |
| } | |
| @Component({ | |
| selector: 'todo.dialog', | |
| templateUrl: 'todo.dialog.html', | |
| styleUrls: ['./todo.dialog.css'] | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @NgModule({ | |
| declarations: [ AppComponent, TodoListComponent, TodoDialog ], | |
| imports: [ | |
| BrowserModule, | |
| BrowserAnimationsModule, | |
| ReactiveFormsModule, | |
| RouterModule.forRoot([{path: '', component: TodoListComponent}]), | |
| MatListModule, | |
| MatButtonModule, | |
| MatCardModule, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="container"> | |
| <router-outlet></router-outlet> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Injectable({ | |
| providedIn: 'root' | |
| }) | |
| export class TodoService { | |
| todoList: TODO[]; | |
| types: string[]; | |
| constructor() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export class TodoDialog implements OnInit { | |
| todosForm: FormGroup; | |
| type: string; | |
| types: string[] = []; | |
| todoList: TODO[] = []; | |
| filteredTodoList: TODO[] = []; | |
| mode: string = 'create'; // 'create' | 'update' | |
| constructor(private formBuilder: FormBuilder, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div mat-dialog-content> | |
| <div fxLayout="row" fxLayoutGap="10px"> | |
| <form [formGroup]="todosForm"> | |
| <div formArrayName="todos" *ngFor="let item of todosFormArray.controls; let i = index;"> | |
| <div fxLayout="row" [formGroupName]="i" fxLayoutAlign="start center"> | |
| <mat-form-field> | |
| <mat-label>Name</mat-label> | |
| <input formControlName="name" matInput required/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| openTodoDialog(mode: string, todo?: TODO): void { // mode = 'create' | 'update' | |
| const dialogRef = this.dialog.open(TodoDialog, { | |
| width: '800px', | |
| data: { mode: mode, todos: todo ? [todo] : [] } | |
| }); | |
| dialogRef.afterClosed().subscribe((result: TODO[]) => { | |
| if (result) { | |
| this.todoService.updateTodoList(result, mode); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| updateTodoList(todos: TODO[], mode: string) { | |
| // if the todo-dialog is opened with 'update' mode, it will contain only 1 TODO | |
| if (mode === 'update') { | |
| this.todoList[todos[0].id - 1] = todos[0]; | |
| } | |
| if (mode === 'create') { | |
| todos.forEach(todo => { | |
| todo.id = this.todoList.length + 1; | |
| this.todoList.push(todo); |