Skip to content

Commit

Permalink
chore: code tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismclarke committed Sep 25, 2023
1 parent 849f04f commit c3d6e1c
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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();
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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',
// };
// }
// }
// }
1 change: 0 additions & 1 deletion apps/picsa-tools/resources-tool/src/app/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ interface IDownloadableResource {
}
//
export interface IResourceFile extends IResourceItemBase, IDownloadableResource {
_isDownloaded?: boolean;
type: 'file';
mimetype: 'application/pdf';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
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({
selector: 'resource-home',
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();
}
}
3 changes: 3 additions & 0 deletions apps/picsa-tools/resources-tool/src/app/schemas/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// export * from './collection';
export * from './file';
// export * from './link';
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c3d6e1c

Please sign in to comment.