From c3d6e1cc1e0d92703f5499373209b56b565faebb Mon Sep 17 00:00:00 2001 From: chrismclarke Date: Mon, 25 Sep 2023 13:33:16 -0700 Subject: [PATCH] chore: code tidying --- .../resource-item/templates/file.ts | 26 +++++----- .../components/resource-item/templates/pdf.ts | 11 +++++ .../resource-item/templates/video.ts | 48 +++++++++---------- .../resources-tool/src/app/models/index.ts | 1 - .../src/app/pages/home/home.component.ts | 29 +++++++++-- .../resources-tool/src/app/schemas/index.ts | 3 ++ .../video-player/video-player.component.scss | 1 + 7 files changed, 78 insertions(+), 41 deletions(-) create mode 100644 apps/picsa-tools/resources-tool/src/app/components/resource-item/templates/pdf.ts create mode 100644 apps/picsa-tools/resources-tool/src/app/schemas/index.ts diff --git a/apps/picsa-tools/resources-tool/src/app/components/resource-item/templates/file.ts b/apps/picsa-tools/resources-tool/src/app/components/resource-item/templates/file.ts index 12beab7ca..f4d554b1e 100644 --- a/apps/picsa-tools/resources-tool/src/app/components/resource-item/templates/file.ts +++ b/apps/picsa-tools/resources-tool/src/app/components/resource-item/templates/file.ts @@ -12,7 +12,7 @@ export class FileItemHandler { constructor(public component: ResourceItemComponent) { component.handleResourceClick = (e) => this.handleClick(e); - this.resource._isDownloaded = this.component.store.isFileDownloaded(this.resource); + // this.resource._isDownloaded = this.component.store.isFileDownloaded(this.resource); this.handleInit(); } @@ -22,9 +22,9 @@ export class FileItemHandler { } public handleInit() { - this.component.actionButton = { - icon: this.resource._isDownloaded ? 'open_in_new' : 'file_download', - }; // TODO show file download size alongside download icon + // this.component.actionButton = { + // icon: this.resource._isDownloaded ? 'open_in_new' : 'file_download', + // }; // TODO show file download size alongside download icon } public handleDownloadComplete() { @@ -39,14 +39,14 @@ export class FileItemHandler { private async handleClick(e: Event) { e.stopPropagation(); - if (this.download$) { - return this.cancelDownload(); - } - if (!this.resource._isDownloaded) { - this.handleResourceDownload(); - } else { - this.handleResourceOpen(); - } + // if (this.download$) { + // return this.cancelDownload(); + // } + // if (!this.resource._isDownloaded) { + // this.handleResourceDownload(); + // } else { + // this.handleResourceOpen(); + // } } /** Cancel ongoing download */ private cancelDownload() { @@ -76,7 +76,7 @@ export class FileItemHandler { complete: () => { this.component.downloadProgress = undefined; this.component.downloadComplete.emit(this.resource); - this.resource._isDownloaded = true; + // this.resource._isDownloaded = true; this.handleDownloadComplete(); }, }); diff --git a/apps/picsa-tools/resources-tool/src/app/components/resource-item/templates/pdf.ts b/apps/picsa-tools/resources-tool/src/app/components/resource-item/templates/pdf.ts new file mode 100644 index 000000000..864100c2f --- /dev/null +++ b/apps/picsa-tools/resources-tool/src/app/components/resource-item/templates/pdf.ts @@ -0,0 +1,11 @@ +import { Component, Input } from '@angular/core'; + +import { IResourceFile } from '../../../models'; + +@Component({ + selector: 'resource-item-pdf', + template: `name.component.html`, +}) +export class ResourceItemPDFComponent { + @Input() resource: IResourceFile; +} diff --git a/apps/picsa-tools/resources-tool/src/app/components/resource-item/templates/video.ts b/apps/picsa-tools/resources-tool/src/app/components/resource-item/templates/video.ts index e14141013..4bbf724ae 100644 --- a/apps/picsa-tools/resources-tool/src/app/components/resource-item/templates/video.ts +++ b/apps/picsa-tools/resources-tool/src/app/components/resource-item/templates/video.ts @@ -22,28 +22,28 @@ export class ResourceItemVideoComponent { @Input() resource: IResourceVideo; } -export class VideoItemHandler extends FileItemHandler { - constructor(component: ResourceItemComponent) { - super(component); - } +// export class VideoItemHandler extends FileItemHandler { +// constructor(component: ResourceItemComponent) { +// super(component); +// } - public override handleDownloadComplete(): void { - this.component.actionButton = undefined; - // this.resource.url = this.component.store.getFileLocalLink(this.resource) - // TODO - prompt auto open - } - public override handleResourceOpen(): void { - // - } - public override handleInit(): void { - if (this.resource._isDownloaded) { - this.component.actionButton = undefined; - // TODO - get fully qualified storage URI to play from - // Possibly using convertToLocalUrl - } else { - this.component.actionButton = { - icon: 'file_download', - }; - } - } -} +// public override handleDownloadComplete(): void { +// this.component.actionButton = undefined; +// // this.resource.url = this.component.store.getFileLocalLink(this.resource) +// // TODO - prompt auto open +// } +// public override handleResourceOpen(): void { +// // +// } +// public override handleInit(): void { +// if (this.resource._isDownloaded) { +// this.component.actionButton = undefined; +// // TODO - get fully qualified storage URI to play from +// // Possibly using convertToLocalUrl +// } else { +// this.component.actionButton = { +// icon: 'file_download', +// }; +// } +// } +// } diff --git a/apps/picsa-tools/resources-tool/src/app/models/index.ts b/apps/picsa-tools/resources-tool/src/app/models/index.ts index e967aca04..3492b740f 100644 --- a/apps/picsa-tools/resources-tool/src/app/models/index.ts +++ b/apps/picsa-tools/resources-tool/src/app/models/index.ts @@ -27,7 +27,6 @@ interface IDownloadableResource { } // export interface IResourceFile extends IResourceItemBase, IDownloadableResource { - _isDownloaded?: boolean; type: 'file'; mimetype: 'application/pdf'; } diff --git a/apps/picsa-tools/resources-tool/src/app/pages/home/home.component.ts b/apps/picsa-tools/resources-tool/src/app/pages/home/home.component.ts index ca8c948b5..f0cc2e787 100644 --- a/apps/picsa-tools/resources-tool/src/app/pages/home/home.component.ts +++ b/apps/picsa-tools/resources-tool/src/app/pages/home/home.component.ts @@ -1,5 +1,7 @@ -import { Component } from '@angular/core'; +import { Component, OnDestroy, OnInit } from '@angular/core'; +import { Subject, takeUntil } from 'rxjs'; +import { ResourcesToolService } from '../../services/resources-tool.service'; import { ResourcesStore } from '../../stores'; @Component({ @@ -7,6 +9,27 @@ import { ResourcesStore } from '../../stores'; templateUrl: './home.component.html', styleUrls: ['./home.component.scss'], }) -export class HomeComponent { - constructor(public store: ResourcesStore) {} +export class HomeComponent implements OnInit, OnDestroy { + private componentDestroyed$ = new Subject(); + + constructor(public service: ResourcesToolService, public store: ResourcesStore) {} + + async ngOnInit() { + await this.service.ready(); + // TODO - want to subscribe to collections + const query = this.service.dbFileCollection.find(); + query.$.pipe(takeUntil(this.componentDestroyed$)).subscribe((docs) => { + console.log('home page files retrieved', docs); + // const { code } = this.configurationService.activeConfiguration.localisation.country; + // // filter forms to include only active config country forms + // this.forms = docs + // .map((doc) => doc._data) + // .filter((form) => !form.appCountries || form.appCountries.includes(code)); + }); + } + + ngOnDestroy(): void { + this.componentDestroyed$.next(true); + this.componentDestroyed$.complete(); + } } diff --git a/apps/picsa-tools/resources-tool/src/app/schemas/index.ts b/apps/picsa-tools/resources-tool/src/app/schemas/index.ts new file mode 100644 index 000000000..9e25b4cab --- /dev/null +++ b/apps/picsa-tools/resources-tool/src/app/schemas/index.ts @@ -0,0 +1,3 @@ +// export * from './collection'; +export * from './file'; +// export * from './link'; diff --git a/libs/shared/src/features/video-player/video-player.component.scss b/libs/shared/src/features/video-player/video-player.component.scss index 8c8a3e2fe..8910e3822 100644 --- a/libs/shared/src/features/video-player/video-player.component.scss +++ b/libs/shared/src/features/video-player/video-player.component.scss @@ -26,6 +26,7 @@ $playerWidth: 480px; z-index: 3; background-repeat: no-repeat; background-size: cover; + filter: saturate(0.75); } $icon-size: 3rem; .play-button {