From cdaf36b2fdc79c8df8dda879be3b6ad49b6a9704 Mon Sep 17 00:00:00 2001 From: Rodrigo Damazio Bovendorp Date: Fri, 26 Apr 2024 03:55:50 -0700 Subject: [PATCH] Add a file command bar and show file picker conditionally --- src/app/checklists/checklists.component.html | 29 ++++++---- src/app/checklists/checklists.component.ts | 54 +++++++++++++++++++ .../command-bar/command-bar.component.html | 27 ++++++++++ .../command-bar/command-bar.component.scss | 3 ++ .../command-bar/command-bar.component.spec.ts | 23 ++++++++ .../command-bar/command-bar.component.ts | 20 +++++++ .../file-picker/file-picker.component.html | 35 ++++++------ .../file-picker/file-picker.component.scss | 8 ++- .../file-picker/file-picker.component.ts | 45 ++-------------- 9 files changed, 172 insertions(+), 72 deletions(-) create mode 100644 src/app/checklists/command-bar/command-bar.component.html create mode 100644 src/app/checklists/command-bar/command-bar.component.scss create mode 100644 src/app/checklists/command-bar/command-bar.component.spec.ts create mode 100644 src/app/checklists/command-bar/command-bar.component.ts diff --git a/src/app/checklists/checklists.component.html b/src/app/checklists/checklists.component.html index e7a5d3c..a88ccc5 100644 --- a/src/app/checklists/checklists.component.html +++ b/src/app/checklists/checklists.component.html @@ -1,17 +1,28 @@
+ + #filePicker + (fileSelected)="onFileSelected($event)" + (cancel)="onOpenFileCancel()" + [fileNames]="store.listChecklistFiles()" + [style.display]="showFilePicker ? '' : 'none'" + /> + #tree + class="checklist-tree" + (checklistSelected)="items.checklist = $event" + (checklistStructureChanged)="onStructureChanged($event)" + />
\ No newline at end of file diff --git a/src/app/checklists/checklists.component.ts b/src/app/checklists/checklists.component.ts index f061d17..47c8800 100644 --- a/src/app/checklists/checklists.component.ts +++ b/src/app/checklists/checklists.component.ts @@ -2,6 +2,7 @@ import { Component, ViewChild } from '@angular/core'; import { Checklist, ChecklistFile } from '../../../gen/ts/checklist'; import { ChecklistStorage } from '../../model/storage/checklist-storage'; import { ChecklistTreeComponent } from './checklist-tree/checklist-tree.component'; +import { ChecklistCommandBarComponent } from './command-bar/command-bar.component'; import { ChecklistFilePickerComponent } from './file-picker/file-picker.component'; import { ChecklistItemsComponent } from './items-list/items-list.component'; @@ -9,6 +10,7 @@ import { ChecklistItemsComponent } from './items-list/items-list.component'; selector: 'app-checklists', standalone: true, imports: [ + ChecklistCommandBarComponent, ChecklistFilePickerComponent, ChecklistItemsComponent, ChecklistTreeComponent @@ -19,10 +21,52 @@ import { ChecklistItemsComponent } from './items-list/items-list.component'; export class ChecklistsComponent { private _selectedFile?: ChecklistFile; @ViewChild("tree") tree?: ChecklistTreeComponent; + @ViewChild("filePicker") filePicker?: ChecklistFilePickerComponent; + + showFilePicker: boolean = false; constructor(public store: ChecklistStorage) { } + onNewFile() { + this.showFilePicker = false; + + let name = prompt("Enter a name for the new file:"); + if (!name) { + return; + } + + // Save an empty file with that name. + let file: ChecklistFile = { + name: name, + groups: [], + }; + this.store.saveChecklistFile(file); + this._displayFile(file); + } + + onOpenFile() { + this.showFilePicker = true; + } + + onOpenFileCancel() { + this.showFilePicker = false; + } + + onUploadFile() { + this.showFilePicker = false; + + window.alert('TODO'); + } + + onDownloadFile() { + this.showFilePicker = false; + + window.alert('TODO'); + } + onFileSelected(id: string) { + this.showFilePicker = false; + let file: ChecklistFile | undefined; if (id) { let loadedFile = this.store.getChecklistFile(id); @@ -30,8 +74,18 @@ export class ChecklistsComponent { file = loadedFile; } } + this._displayFile(file); + + // TODO: Add filename to topbar, add rename pencil there + } + + private _displayFile(file?: ChecklistFile) { this._selectedFile = file; this.tree!.file = file; + if (file) { + // Make the file selected the next time the picker gets displayed + this.filePicker!.selectedFile = file.name; + } } onStructureChanged(file: ChecklistFile) { diff --git a/src/app/checklists/command-bar/command-bar.component.html b/src/app/checklists/command-bar/command-bar.component.html new file mode 100644 index 0000000..e12fd10 --- /dev/null +++ b/src/app/checklists/command-bar/command-bar.component.html @@ -0,0 +1,27 @@ +
+ + + + + +
\ No newline at end of file diff --git a/src/app/checklists/command-bar/command-bar.component.scss b/src/app/checklists/command-bar/command-bar.component.scss new file mode 100644 index 0000000..8617676 --- /dev/null +++ b/src/app/checklists/command-bar/command-bar.component.scss @@ -0,0 +1,3 @@ +.command-bar { + padding: 10px; +} \ No newline at end of file diff --git a/src/app/checklists/command-bar/command-bar.component.spec.ts b/src/app/checklists/command-bar/command-bar.component.spec.ts new file mode 100644 index 0000000..8bc6119 --- /dev/null +++ b/src/app/checklists/command-bar/command-bar.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ChecklistCommandBarComponent } from './command-bar.component'; + +describe('ChecklistCommandBarComponent', () => { + let component: ChecklistCommandBarComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ChecklistCommandBarComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(ChecklistCommandBarComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/checklists/command-bar/command-bar.component.ts b/src/app/checklists/command-bar/command-bar.component.ts new file mode 100644 index 0000000..46a6f06 --- /dev/null +++ b/src/app/checklists/command-bar/command-bar.component.ts @@ -0,0 +1,20 @@ +import { Component, EventEmitter, Output } from '@angular/core'; +import { MatButtonModule } from '@angular/material/button'; +import { MatIconModule } from '@angular/material/icon'; + +@Component({ + selector: 'checklist-command-bar', + standalone: true, + imports: [ + MatButtonModule, + MatIconModule, + ], + templateUrl: './command-bar.component.html', + styleUrl: './command-bar.component.scss' +}) +export class ChecklistCommandBarComponent { + @Output() newFile = new EventEmitter(); + @Output() openFile = new EventEmitter(); + @Output() uploadFile = new EventEmitter(); + @Output() downloadFile = new EventEmitter(); +} diff --git a/src/app/checklists/file-picker/file-picker.component.html b/src/app/checklists/file-picker/file-picker.component.html index 299d0a4..d2e58b2 100644 --- a/src/app/checklists/file-picker/file-picker.component.html +++ b/src/app/checklists/file-picker/file-picker.component.html @@ -1,20 +1,15 @@ - - Select checklist file - - - {{file}} - - - - Create new file - - - - Upload new file - - - \ No newline at end of file +
+ + Select checklist file + + + {{file}} + + + + +
\ No newline at end of file diff --git a/src/app/checklists/file-picker/file-picker.component.scss b/src/app/checklists/file-picker/file-picker.component.scss index 3dfefe9..ede8ee5 100644 --- a/src/app/checklists/file-picker/file-picker.component.scss +++ b/src/app/checklists/file-picker/file-picker.component.scss @@ -1,4 +1,8 @@ .container { - width: 300px; - padding-top: 20px; + width: 100%; + display: flex; +} + +.dropdown { + flex-grow: 1; } \ No newline at end of file diff --git a/src/app/checklists/file-picker/file-picker.component.ts b/src/app/checklists/file-picker/file-picker.component.ts index 90c385c..6b2bf4a 100644 --- a/src/app/checklists/file-picker/file-picker.component.ts +++ b/src/app/checklists/file-picker/file-picker.component.ts @@ -1,9 +1,7 @@ import { NgFor } from '@angular/common'; -import { Component, EventEmitter, Output } from '@angular/core'; +import { Component, EventEmitter, Input, Output } from '@angular/core'; import { MatIconModule } from '@angular/material/icon'; import { MatSelectModule } from '@angular/material/select'; -import { ChecklistFile } from '../../../../gen/ts/checklist'; -import { ChecklistStorage } from '../../../model/storage/checklist-storage'; @Component({ selector: 'checklist-file-picker', @@ -17,43 +15,8 @@ import { ChecklistStorage } from '../../../model/storage/checklist-storage'; styleUrl: './file-picker.component.scss' }) export class ChecklistFilePickerComponent { + @Input() fileNames? : string[]; + @Input() selectedFile = ''; @Output() fileSelected = new EventEmitter(); - selectedFile = ''; - - constructor(public store: ChecklistStorage) { } - - onFileSelected() { - if (this.selectedFile === 'new') { - this.onNewFile(); - } else if (this.selectedFile === 'upload') { - this.onUploadFile(); - } else { - this.loadFile(); - } - } - - private loadFile() { - this.fileSelected.emit(this.selectedFile); - } - - onNewFile() { - let name = prompt("Enter a name for the new file:"); - if (name) { - // Save an empty file with that name. - let file: ChecklistFile = { - name: name, - groups: [], - }; - this.store.saveChecklistFile(file); - this.selectedFile = name; - } else { - // TODO: Doesn't unselect the New File item if ESC is pressed (vs cancelling) - this.selectedFile = ''; - } - this.loadFile(); - } - - onUploadFile() { - // TODO - } + @Output() cancel = new EventEmitter(); }