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 27, 2023
1 parent 43f69db commit 5c10075
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ResourcesToolService } from '../../../services/resources-tool.service';
<h2>{{ resource.title | translate }}</h2>
<div style="position:relative">
<picsa-video-player [source]="videoData" #videoPlayer [thumbnail]="resource.image"> </picsa-video-player>
<div class="download-overlay" *ngIf="!isDownloaded">
<div class="download-overlay" [style.visibility]="showDownloadOverlay ? 'visible' : 'hidden'">
<resource-download
*ngIf="dbDoc"
[dbDoc]="dbDoc"
Expand Down Expand Up @@ -56,24 +56,31 @@ export class ResourceItemVideoComponent implements OnInit {
@Input() resource: IResourceVideo;

public dbDoc: RxDocument<IResourceFile>;
public isDownloaded: boolean;
public videoData: Blob;

public showDownloadOverlay = false;

constructor(private service: ResourcesToolService) {}

async ngOnInit() {
await this.service.ready();
const dbDoc = await this.service.dbFileCollection.findOne(this.resource._key).exec();
if (dbDoc) {
this.dbDoc = dbDoc;
this.loadVideo();
}
}

public async loadVideo() {
const dbAttachment = await this.service.getFileAttachment(this.dbDoc);
if (dbAttachment) {
this.isDownloaded = true;
this.videoData = dbAttachment;
// avoid duplicate calls on initial init as downloadComplete emits
if (!this.videoData) {
const dbAttachment = await this.service.getFileAttachment(this.dbDoc);
if (dbAttachment) {
this.videoData = dbAttachment;
this.showDownloadOverlay = false;
} else {
this.showDownloadOverlay = true;
}
}
}
}
6 changes: 3 additions & 3 deletions apps/picsa-tools/resources-tool/src/app/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ for (const [key, resources] of Object.entries(typeExports)) {
* Format of hardcoded resources to be used in database
* TODO - alternate formats can be removed once DB used throughout app
*/
const dbEntries: schemas.IResourceFile[] = [];
const dbFileEntries: schemas.IResourceFile[] = [];
for (const entry of [...typeExports.file, ...typeExports.video]) {
/* eslint-disable @typescript-eslint/no-unused-vars */
const { _created, _key, _modified, meta, appCountries, image, imageFit, subtitle, ...keptFields } = entry;
Expand All @@ -71,8 +71,8 @@ for (const entry of [...typeExports.file, ...typeExports.video]) {
countries: appCountries || [],
},
};
dbEntries.push(file);
dbFileEntries.push(file);
}
export const DB_ENTRIES = dbEntries;
export const DB_FILE_ENTRIES = dbFileEntries;

export default { ...typeExports, byId };
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="page-content no-padding">
<resource-item-collection [collection]="collection" viewStyle="expanded" *ngIf="collection; else elseBlock">
<resource-item-collection [collection]="collection" viewStyle="expanded" *ngIf="collection">
</resource-item-collection>
<ng-template #elseBlock>{{ 'Collection not found' | translate }}</ng-template>
<picsa-alert-box *ngIf="showcollectionNotFound" type="info" style="margin: 2rem">{{
'Collection not found' | translate
}}</picsa-alert-box>
</div>

<!-- -->
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Injectable } from '@angular/core';
import { PicsaAsyncService } from '@picsa/shared/services/asyncService.service';
import { PicsaDatabase_V2_Service } from '@picsa/shared/services/core/db_v2';
import { RxCollection } from 'rxdb';
import { RxCollection, RxDocument } from 'rxdb';

import HARDCODED_RESOURCES from '../data';
import { DB_FILE_ENTRIES } from '../data';
import * as schemas from '../schemas';

@Injectable({ providedIn: 'root' })
Expand All @@ -29,27 +29,12 @@ export class ResourcesToolService extends PicsaAsyncService {
return this.dbService.db.collections['resources_tool_files'] as RxCollection<schemas.IResourceFile>;
}

public getFileAttachment(doc: RxDocument<schemas.IResourceFile>) {
return this.dbService.getAttachment('resources_tool_files', doc as any);
}

private async populateFileList() {
// TODO - ideally refactor hardcoded to keep all file resources together and remove store methods
const { file, video } = HARDCODED_RESOURCES;
/* eslint-disable @typescript-eslint/no-unused-vars */
const combined = [...file, ...video];
const fileResources: schemas.IResourceFile[] = combined.map((entry) => {
const { _created, _key, _modified, _downloaded, meta, appCountries, image, imageFit, subtitle, ...keptFields } =
entry;
const file: schemas.IResourceFile = {
...keptFields,
id: _key,
md5Hash: 'TODO',
size_kb: -1,
priority: entry.priority || 1,
};
return file;
});
console.log('populating file resources', fileResources);
// TODO - handle resource removal or file updated
await this.dbFileCollection.bulkUpsert(fileResources);
// dbFormCollection.bulkUpsert(HARDCODED_FORMS);
await this.dbFileCollection.bulkUpsert(DB_FILE_ENTRIES);
}

private async populateAssetResources() {
Expand Down

0 comments on commit 5c10075

Please sign in to comment.