Skip to content

Commit

Permalink
Merge pull request #188 from e-picsa/content/2023-10
Browse files Browse the repository at this point in the history
Content/2023 10
  • Loading branch information
chrismclarke authored Oct 21, 2023
2 parents 1fa5eba + 4f44d4d commit 213a8d1
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 45 deletions.
4 changes: 2 additions & 2 deletions apps/picsa-apps/extension-app-native/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "io.picsa.extension"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 3036000
versionName "3.36.0"
versionCode 3036001
versionName "3.36.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
>
<!-- Extension version -->
<mat-tab [label]="'Extension' | translate" #extensionTab>
<ng-container *ngTemplateOutlet="manualDownload"></ng-container>
<ng-container *ngTemplateOutlet="manualDownload; context: { version: 'extension' }"></ng-container>
<picsa-manual-steps-container
[style.visibility]="pdfSrc ? 'visible' : 'hidden'"
[pageMapping]="localisation"
Expand All @@ -24,7 +24,7 @@

<!-- Farmer Version -->
<mat-tab [label]="'Farmer' | translate" #farmerTab>
<ng-container *ngTemplateOutlet="manualDownload"></ng-container>
<ng-container *ngTemplateOutlet="manualDownload; context: { version: 'farmer' }"></ng-container>
<picsa-manual-steps-container
[style.visibility]="pdfSrc ? 'visible' : 'hidden'"
[pageMapping]="localisation"
Expand All @@ -35,7 +35,7 @@
</mat-tab-group>
</div>

<ng-template #manualDownload>
<ng-template #manualDownload let-version="version">
<picsa-alert-box
[style.display]="downloadPrompt.show ? 'block' : 'none'"
type="info"
Expand All @@ -44,8 +44,8 @@
>
<div style="max-width: 300px; margin: auto">
<resource-item-file
*ngIf="resourceDoc"
[resource]="resourceDoc._data"
*ngIf="resourceDocs[version]"
[resource]="resourceDocs[version]._data"
(attachmentChange)="handleResourceAttachmentChange($event)"
></resource-item-file>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ const LOCALISED_VERSIONS: { [version in IManualVersion]: { [code: string]: IReso
animations: [FlyInOut({ axis: 'Y' }), FadeInOut({ inDelay: 200, inSpeed: 300 })],
})
export class HomeComponent implements OnDestroy, AfterViewInit {
public resourceDoc: RxDocument<IResourceFile> | null;
// TODO - ideally all variables should be tracked by version (use additional component)
public resourceDocs: { [version in IManualVersion]: RxDocument<IResourceFile> | null } = {
farmer: null,
extension: null,
};

public localisation: string;

Expand Down Expand Up @@ -81,6 +85,7 @@ export class HomeComponent implements OnDestroy, AfterViewInit {
/** Prompt manual load if resource file attachment updated */
public async handleResourceAttachmentChange(attachment?: RxAttachment<IResourceFile>) {
if (attachment) {
console.log('resource attachment changed', attachment);
await this.loadManual();
this.cdr.markForCheck();
}
Expand All @@ -99,8 +104,8 @@ export class HomeComponent implements OnDestroy, AfterViewInit {
}
const manualDoc = await this.resourcesService.dbFiles.findOne(manualResource.id).exec();
if (manualDoc) {
this.resourceDoc = manualDoc;
const uri = await this.resourcesService.getFileAttachmentURI(this.resourceDoc, true);
this.resourceDocs[version] = manualDoc;
const uri = await this.resourcesService.getFileAttachmentURI(manualDoc, true);
if (uri) {
this.downloadPrompt.show = false;
this.pdfSrc = uri;
Expand All @@ -112,7 +117,6 @@ export class HomeComponent implements OnDestroy, AfterViewInit {

public async setSelectedTab(index: number) {
this.pdfSrc = undefined;
this.resourceDoc = null;
const version = index === 1 ? 'farmer' : 'extension';
this.setManualVersion(version);
await this.loadManual();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
<!-- TODO - should be able to refactor video item to be included here -->
<div style="position: relative">
<!-- Download overlay -->
<div class="download-overlay" [style.visibility]="attachment ? 'hidden' : 'visible'">
<div
class="download-overlay"
[style.visibility]="attachment ? 'hidden' : 'visible'"
[attr.data-file-type]="dbDoc?.subtype || null"
>
<div class="mat-elevation-z8; border-radius: 8px;">
<resource-download
*ngIf="dbDoc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
left: 0;
z-index: 4;
background: #fbfbfb91;
max-width: 480px;
display: flex;
justify-content: center;
align-items: center;
}
.download-overlay[data-file-type='video'] {
max-width: 854px;
}
.download-button {
display: flex;
background: var(--color-primary);
Expand Down
48 changes: 24 additions & 24 deletions apps/picsa-tools/resources-tool/src/app/data/weather/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,68 @@ interface IDownscaledForecast extends IResourceFile {
}

export const DOWNSCALED_FORECASTS: Record<string, IDownscaledForecast> = {
downscaled_forecast_kasungu_en: {
id: 'downscaled_forecast_kasungu_en',
downscaled_forecast_2023_kasungu_en: {
id: 'downscaled_forecast_2023_kasungu_en',
description: '',
filename: 'forecast-kasungu-english.pdf',
mimetype: 'application/pdf',
title: 'KASUNGU DISTRICT DOWNSCALED SEASONAL FORECAST, 2022-2023',
title: 'KASUNGU DISTRICT DOWNSCALED SEASONAL FORECAST, 2023-2024',
type: 'file',
subtype: 'pdf',
url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/weather%2Fforecast-kasungu-english.pdf?alt=media&token=bbb710a6-4854-4f0c-8447-cf919fef1061',
size_kb: 1084.1,
md5Checksum: '95aa01cddb75d06725a7cd3904334043',
url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/weather%2FSeasonal%20Forecasts%2FKASUNGU_English_Poster_2023_2024_compressed.pdf?alt=media&token=79f46884-e20e-45fd-b2f1-aa096c4e61db',
size_kb: 356,
md5Checksum: '1e9d080d9395f14687100191e75a02f0',
filter: { countries: ['mw'] },
language: 'en',
meta: {
locationId: 'Malawi_Kasungu',
},
},
downscaled_forecast_kasungu_ny: {
id: 'downscaled_forecast_kasungu_ny',
downscaled_forecast_2023_kasungu_ny: {
id: 'downscaled_forecast_2023_kasungu_ny',
description: '',
filename: 'forecast-kasungu-chichewa.pdf',
mimetype: 'application/pdf',
title: 'ULOSI WA KAGWEDWE KA MVULA M’BOMA LA KASUNGU M’DZINJA LA 2022-2023',
title: 'ULOSI WA KAGWEDWE KA MVULA M’BOMA LA KASUNGU M’DZINJA LA 2023-2024',
type: 'file',
subtype: 'pdf',
url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/weather%2Fforecast-kasungu-chichewa.pdf?alt=media&token=c8353b9b-0a1a-4a5e-8df0-8ffc136cc38c',
size_kb: 1085.3,
md5Checksum: '9de79ed0fdd77bb202c5716ce3e8d11c',
url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/weather%2FSeasonal%20Forecasts%2FKASUNGU_Chichewa_Poster_2023_2024_compressed.pdf?alt=media&token=18da5ae1-09dc-4224-b742-0e555cf584fe',
size_kb: 381.4,
md5Checksum: '5e9c7141d11bc6fab0c113487e46d410',
filter: { countries: ['mw'] },
language: 'ny',
meta: {
locationId: 'Malawi_Kasungu',
},
},
downscaled_forecast_nkhotakota_en: {
id: 'downscaled_forecast_nkhotakota_en',
downscaled_forecast_2023_nkhotakota_en: {
id: 'downscaled_forecast_2023_nkhotakota_en',
description: '',
filename: 'forecast-nkhotakota-english.pdf',
mimetype: 'application/pdf',
title: 'NKHOTAKOTA DISTRICT DOWNSCALED SEASONAL FORECAST, 2022-2023',
title: 'NKHOTAKOTA DISTRICT DOWNSCALED SEASONAL FORECAST, 2023-2024',
type: 'file',
subtype: 'pdf',
url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/weather%2Fforecast-nkhotakota-english.pdf?alt=media&token=c642c01b-a94d-4953-a16a-d375db9f642a',
size_kb: 702.4,
md5Checksum: '98c2332a4d83d251725fdccc83af1826',
url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/weather%2FSeasonal%20Forecasts%2FNKHOTAKOTA_English_Poster_2023_2024_compressed.pdf?alt=media&token=0b2b4317-4c0a-44f5-a681-ce10b45af841',
size_kb: 396.2,
md5Checksum: 'b6221f1f62791e9110471b2ed04b9954',
filter: { countries: ['mw'] },
language: 'en',
meta: {
locationId: 'Malawi_Nkhotakota',
},
},
downscaled_forecast_nkhotakota_ny: {
id: 'downscaled_forecast_nkhotakota_ny',
downscaled_forecast_2023_nkhotakota_ny: {
id: 'downscaled_forecast_2023_nkhotakota_ny',
description: '',
filename: 'forecast-nkhotakota-chichewa.pdf',
mimetype: 'application/pdf',
title: 'ULOSI WA KAGWEDWE KA MVULA M’BOMA LA NKHOTAKOTA M’DZINJA LA 2022-2023',
title: 'ULOSI WA KAGWEDWE KA MVULA M’BOMA LA NKHOTAKOTA M’DZINJA LA 2023-2024',
type: 'file',
subtype: 'pdf',
url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/weather%2Fforecast-nkhotakota-chichewa.pdf?alt=media&token=04b95abf-a78c-4752-b2b7-a6f42149b492',
size_kb: 742.9,
md5Checksum: '359f9e0df76b4887befcca129b502dc1',
url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/weather%2FSeasonal%20Forecasts%2FNKHOTAKOTA_Chichewa_Poster_2023_2024_compressed.pdf?alt=media&token=2e4d14cf-2e82-48ac-9222-e8020791c50b',
size_kb: 416.1,
md5Checksum: '70a8fb7adb64982e630d4d3890880c72',
filter: { countries: ['mw'] },
language: 'ny',
meta: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export const WEATHER_LOCATIONS: IWeatherLocation[] = [
id: 'Malawi_Kasungu',
label: 'Kasungu',
countryCode: 'mw',
meteoBlueId: 'kasungu_malawi_928534',
// meteoBlueId: 'kasungu_malawi_928534',
},
{
id: 'Malawi_Nkhotakota',
label: 'Nkhotakota',
countryCode: 'mw',
meteoBlueId: 'nkhotakota_malawi_924705',
// meteoBlueId: 'nkhotakota_malawi_924705',
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ export class ResourcesToolService extends PicsaAsyncService {
}

private async populateHardcodedResources() {
// Remove resources marked for deletion (TODO - find cleaner method to keep in sync)
// TODO - process after cache check
await this.deleteRemovedResources();

// Use caching system to only populate once per app version launch
const assetsCacheVersion = this.getAssetResourcesVersion();
if (assetsCacheVersion === APP_VERSION.number) {
Expand All @@ -125,6 +129,32 @@ export class ResourcesToolService extends PicsaAsyncService {
this.setAssetResourcesVersion();
}

/** Remove any resources that no longer appear in hardcoded resource list */
private async deleteRemovedResources() {
// TODO - likely more efficient to track locally docs with a _deleted property (?)
// But keep as-is for now to ensure any legacy data cleaned
const collectionDeletes = await this.diffDBHardcodedResources(this.dbCollections as any, DB_COLLECTION_ENTRIES);
const fileDeletes = await this.diffDBHardcodedResources(this.dbFiles as any, DB_FILE_ENTRIES);
const LinkDeletes = await this.diffDBHardcodedResources(this.dbLinks as any, DB_LINK_ENTRIES);

await this.dbCollections.bulkRemove(collectionDeletes);
// TODO - ensure attachments removed also
await this.dbFiles.bulkRemove(fileDeletes);
await this.dbLinks.bulkRemove(LinkDeletes);
}
/**
* Compare list of hardcoded resources with db collection, returning IDs of any resources that
* exist in DB but not in hardcoded
* */
private async diffDBHardcodedResources(
collection: RxCollection<schemas.IResourceBase>,
hardcoded: schemas.IResourceBase[]
) {
const hardcodedHashmap = arrayToHashmap(hardcoded, 'id');
const dbEntries = await collection.find().exec();
return dbEntries.filter((doc) => !(doc.id in hardcodedHashmap)).map((doc) => doc.id);
}

/** Copy hardcoded assets to db (if checksums match) */
private async copyResourcesFromAssets() {
// Populate files from cache
Expand Down
2 changes: 1 addition & 1 deletion libs/environments/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import packageJson from '../../../package.json';

export const APP_VERSION = {
number: packageJson.version,
date: '2023-10-09',
date: '2023-10-21',
};
14 changes: 12 additions & 2 deletions libs/shared/src/features/video-player/video-player.component.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
@use '@angular/material' as mat;

$playerWidth: 480px;
$playerWidth: 854px;

:host {
display: contents;
display: block;
width: 100%;
max-width: $playerWidth;
aspect-ratio: 16/9;
// Assuming that video player displayed within 1rem content padding,
// force video to display across all space (full width)
@media screen and (max-width: $playerWidth) {
width: calc(100% + 2rem);
margin-left: -1rem;
margin-right: -1rem;
}
}
.placeholder,
.thumbnail {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ export class VideoPlayerComponent implements OnDestroy {
playerId: this.playerId,
componentTag: 'picsa-video-player',
exitOnEnd: false,
width: 480,
height: 270,
width: 854,
height: 480,
displayMode: 'landscape',
};
if (Capacitor.isNativePlatform()) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "picsa-apps",
"version": "3.36.0",
"version": "3.36.1",
"license": "See LICENSE",
"scripts": {
"ng": "nx",
Expand Down

0 comments on commit 213a8d1

Please sign in to comment.