From eceb851fd071fbe2a7ae90c1f83e37c33221a6b1 Mon Sep 17 00:00:00 2001 From: chrismclarke Date: Thu, 1 Aug 2024 22:09:16 -0700 Subject: [PATCH 1/2] feat: step-video component --- .../step-video/step-video.component.html | 1 + .../step-video/step-video.component.scss | 0 .../step-video/step-video.component.spec.ts | 22 +++++++++ .../step-video/step-video.component.ts | 49 +++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.html create mode 100644 apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.scss create mode 100644 apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.spec.ts create mode 100644 apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.ts diff --git a/apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.html b/apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.html new file mode 100644 index 000000000..ea079b5c6 --- /dev/null +++ b/apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.html @@ -0,0 +1 @@ + diff --git a/apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.scss b/apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.spec.ts b/apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.spec.ts new file mode 100644 index 000000000..17a6297b3 --- /dev/null +++ b/apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.spec.ts @@ -0,0 +1,22 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { StepVideoComponent } from './step-video.component'; + +describe('StepVideoComponent', () => { + let component: StepVideoComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [StepVideoComponent], + }).compileComponents(); + + fixture = TestBed.createComponent(StepVideoComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.ts b/apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.ts new file mode 100644 index 000000000..3958ceaa1 --- /dev/null +++ b/apps/picsa-tools/farmer-content/src/app/components/step-video/step-video.component.ts @@ -0,0 +1,49 @@ +import { CommonModule } from '@angular/common'; +import { Component, computed, input } from '@angular/core'; +import { ConfigurationService } from '@picsa/configuration/src'; +import { ILocaleCode } from '@picsa/data'; +import { IPicsaVideo, IPicsaVideoData } from '@picsa/data/resources'; +import { PICSA_FARMER_VIDEO_RESOURCES_HASHMAP } from '@picsa/data/resources'; +import { ResourcesComponentsModule } from '@picsa/resources/src/app/components/components.module'; + +/** + * Temporary component to help migrate between legacy flat resource format + * to newer content which contains nested videos and allows auto-select + * video based on user's locale preference + * + * TODO - ideally all video resources should be refactored in a similar way + * and support for child resources integrated into main resource components + */ +@Component({ + selector: 'farmer-step-video', + standalone: true, + imports: [CommonModule, ResourcesComponentsModule], + templateUrl: './step-video.component.html', + styleUrl: './step-video.component.scss', +}) +export class FarmerStepVideoComponent { + videoData = input.required(); + + videoResource = computed(() => { + const { language_code } = this.configurationService.userSettings(); + const availableVideos = this.videoData().children; + const video = this.selectDefaultVideo(language_code, availableVideos); + // HACK - lookup resource entry which should be given by same id + const resource = PICSA_FARMER_VIDEO_RESOURCES_HASHMAP[video.id]; + return resource; + }); + + constructor(private configurationService: ConfigurationService) {} + + private selectDefaultVideo(locale_code: ILocaleCode, videos: IPicsaVideo[]) { + // prioritise video in same locale + const localeVideo = videos.find((v) => v.locale_code === locale_code); + if (localeVideo) return localeVideo; + + // TODO - fallback video to same language different locale + // TODO - track preference for video size (when supported in future, currently all 360p) + + // default fallback to first video entry + return videos[0]; + } +} From 84105b0d3b90e873751a2a2faf2d6bec784ce066 Mon Sep 17 00:00:00 2001 From: chrismclarke Date: Thu, 1 Aug 2024 22:19:26 -0700 Subject: [PATCH 2/2] refactor: farmer videos --- .../module-home/module-home.component.html | 6 +- .../module-home/module-home.component.ts | 10 +- .../src/app/data/_deprecated/farmer-videos.ts | 263 ++++++++++++++++++ .../src/app/data/picsa/farmer-videos.ts | 259 +---------------- .../farmer_content/data/content/0_intro.ts | 5 +- .../data/content/1_what_you_do.ts | 6 +- .../data/content/2_climate_change.ts | 4 +- .../data/content/3_opportunities_risks.ts | 4 +- .../data/content/4_what_are_the_options.ts | 4 +- .../data/content/5_compare_options.ts | 4 +- .../data/content/6_decide_and_plan.ts | 1 - libs/data/farmer_content/types.ts | 5 +- libs/data/resources/farmerVideos.ts | 150 ++++++++++ libs/data/resources/index.ts | 2 + libs/data/resources/types.ts | 20 ++ 15 files changed, 465 insertions(+), 278 deletions(-) create mode 100644 apps/picsa-tools/resources-tool/src/app/data/_deprecated/farmer-videos.ts create mode 100644 libs/data/resources/farmerVideos.ts create mode 100644 libs/data/resources/index.ts create mode 100644 libs/data/resources/types.ts diff --git a/apps/picsa-tools/farmer-content/src/app/pages/module-home/module-home.component.html b/apps/picsa-tools/farmer-content/src/app/pages/module-home/module-home.component.html index 26f0e3c7b..2d9bf4fd1 100644 --- a/apps/picsa-tools/farmer-content/src/app/pages/module-home/module-home.component.html +++ b/apps/picsa-tools/farmer-content/src/app/pages/module-home/module-home.component.html @@ -32,10 +32,8 @@

{{ content.title | translate }}

{{ step.tabLabel || 'video' | translate }}
- @if(step.resource){ - - } @else { -
Video resource not found
+ @if(step.video){ + }
diff --git a/apps/picsa-tools/farmer-content/src/app/pages/module-home/module-home.component.ts b/apps/picsa-tools/farmer-content/src/app/pages/module-home/module-home.component.ts index cb93a7d13..414059e73 100644 --- a/apps/picsa-tools/farmer-content/src/app/pages/module-home/module-home.component.ts +++ b/apps/picsa-tools/farmer-content/src/app/pages/module-home/module-home.component.ts @@ -1,24 +1,26 @@ import { CommonModule } from '@angular/common'; import { ChangeDetectionStrategy, Component, computed, effect, signal } from '@angular/core'; import { toSignal } from '@angular/core/rxjs-interop'; +import { MatIconModule } from '@angular/material/icon'; import { MatTabChangeEvent, MatTabsModule } from '@angular/material/tabs'; import { ActivatedRoute, Router, RouterOutlet } from '@angular/router'; import { PicsaCommonComponentsService } from '@picsa/components/src'; import { FARMER_CONTENT_DATA_BY_SLUG, IFarmerContent, IFarmerContentStep, IToolData } from '@picsa/data'; -// eslint-disable-next-line @nx/enforce-module-boundaries -import { ResourcesComponentsModule } from '@picsa/resources/src/app/components/components.module'; import { FadeInOut } from '@picsa/shared/animations'; -import { PhotoInputComponent, PhotoListComponent,PhotoViewComponent } from '@picsa/shared/features'; +import { PhotoInputComponent, PhotoListComponent, PhotoViewComponent } from '@picsa/shared/features'; import { PicsaTranslateModule } from '@picsa/shared/modules'; import { TourService } from '@picsa/shared/services/core/tour'; +import { FarmerStepVideoComponent } from '../../components/step-video/step-video.component'; + @Component({ selector: 'farmer-content-module-home', standalone: true, imports: [ CommonModule, + FarmerStepVideoComponent, PicsaTranslateModule, - ResourcesComponentsModule, + MatIconModule, MatTabsModule, PhotoInputComponent, PhotoViewComponent, diff --git a/apps/picsa-tools/resources-tool/src/app/data/_deprecated/farmer-videos.ts b/apps/picsa-tools/resources-tool/src/app/data/_deprecated/farmer-videos.ts new file mode 100644 index 000000000..8b8f167fe --- /dev/null +++ b/apps/picsa-tools/resources-tool/src/app/data/_deprecated/farmer-videos.ts @@ -0,0 +1,263 @@ +import { IResourceCollection, IResourceFile } from '../../schemas'; + +export interface IFarmerVideosById { + ram: IResourceFile; + seasonal_calendar: IResourceFile; + historic_climate: IResourceFile; + probability_risk: IResourceFile; + options: IResourceFile; + participatory_budget: IResourceFile; +} + +interface IFarmerVideoHashmap { + en: { + '360p': IFarmerVideosById; + }; + mw_ny: { + '360p': IFarmerVideosById; + }; + zm_ny: { + '360p': IFarmerVideosById; + }; +} + +export const PICSA_FARMER_VIDEO_RESOURCES: IFarmerVideoHashmap = { + en: { + '360p': {} as any, + }, + mw_ny: { + '360p': { + ram: { + id: '', + title: 'Resource Allocation Maps', + mimetype: 'video/mp4', + description: '', + filename: 'farmer_ram_mw_ny_360p.mp4', + type: 'file', + subtype: 'video', + cover: { image: '' }, + url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_mw_ny_360p%2F1.%20Resource%20Allocation%20Map.mp4?alt=media&token=389663db-b51b-447f-97fb-8cac3596cf08', + size_kb: 13849.1, + md5Checksum: '3a45d2aa858b9346b82344f3f9b07be1', + filter: { + countries: ['mw'], + }, + language: 'chichewa', + }, + seasonal_calendar: { + id: '', + title: 'Seasonal Calendar', + mimetype: 'video/mp4', + description: '', + filename: 'farmer_seasonal_calendar_mw_ny_360p.mp4', + type: 'file', + subtype: 'video', + cover: { image: '' }, + url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_mw_ny_360p%2F2.%20Seasonal%20Calendar.mp4?alt=media&token=3c51f6bc-82bb-4a85-83b2-7740ca8a0d14', + size_kb: 15009.5, + md5Checksum: '61e55aa62764a62c9fd6f181e1c092d0', + filter: { + countries: ['mw'], + }, + language: 'chichewa', + }, + historic_climate: { + id: '', + title: 'Historic Climate', + mimetype: 'video/mp4', + description: '', + filename: 'farmer_historic_climate_mw_ny_360p.mp4', + type: 'file', + subtype: 'video', + cover: { image: '' }, + url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_mw_ny_360p%2F3.%20Historic%20Climate%20Info.mp4?alt=media&token=79d1ec35-7bc8-4dc1-a1dc-09abb7cb1585', + size_kb: 22243.2, + md5Checksum: '34146918bbdb7e4dd66525283d355d74', + filter: { + countries: ['mw'], + }, + language: 'chichewa', + }, + probability_risk: { + id: '', + title: 'Probability and Risk', + mimetype: 'video/mp4', + description: '', + filename: 'farmer_probability_risk_mw_ny_360p.mp4', + type: 'file', + subtype: 'video', + cover: { image: '' }, + url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_mw_ny_360p%2F4.%20Probability%20and%20Risk.mp4?alt=media&token=a40efecf-97c1-497c-9ac3-d359c6b35bdc', + size_kb: 15475.5, + md5Checksum: '7a16e9f97cc38af86db73b5375620188', + filter: { + countries: ['mw'], + }, + language: 'chichewa', + }, + options: { + id: '', + title: 'Options', + mimetype: 'video/mp4', + description: '', + filename: 'farmer_options_mw_ny_360p.mp4', + type: 'file', + subtype: 'video', + cover: { image: '' }, + url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_mw_ny_360p%2F5.%20Options.mp4?alt=media&token=8a8c45d7-c37d-4eed-8010-0ba4938e8bde', + size_kb: 23894.9, + md5Checksum: 'd6a120bfd36fd8209d189b4c7a2ab66c', + filter: { + countries: ['mw'], + }, + language: 'chichewa', + }, + participatory_budget: { + id: '', + title: 'Participatory Budgets', + mimetype: 'video/mp4', + description: '', + filename: 'farmer_participatory_budget_mw_ny_360p.mp4', + type: 'file', + subtype: 'video', + cover: { image: '' }, + url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_mw_ny_360p%2F6.%20Participatory%20Budgets.mp4?alt=media&token=80530f77-35bd-48b9-bd7a-ed1400e2b449', + size_kb: 24937.8, + md5Checksum: '933e92eb90875bed4a1029244cd11270', + filter: { + countries: ['mw'], + }, + language: 'chichewa', + }, + }, + }, + zm_ny: { + '360p': { + ram: { + id: '', + title: 'Resource Allocation Maps', + mimetype: 'video/mp4', + description: '', + filename: 'farmer_ram_zm_ny_360p.mp4', + type: 'file', + subtype: 'video', + cover: { image: '' }, + url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_zm_ny_360p%2F1.%20%20Resource%20Allocation%20Maps.mp4?alt=media&token=d5279c07-7ccb-42b7-980b-6d168cce40a2', + size_kb: 13446.1, + md5Checksum: 'e0afe2791e2ed24bed2148f9977e34a9', + filter: { + countries: ['zm'], + }, + language: 'chichewa', + }, + seasonal_calendar: { + id: '', + title: 'Seasonal Calendar', + mimetype: 'video/mp4', + description: '', + filename: 'farmer_seasonal_calendar_zm_ny_360p.mp4', + type: 'file', + subtype: 'video', + cover: { image: '' }, + url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_zm_ny_360p%2F2.%20%20Seasonal%20Calendar.mp4?alt=media&token=e47c8178-2416-42b3-9c72-8df2efcf3c95', + size_kb: 12415.1, + md5Checksum: '3420a2b421d6c6da8441e971b8520bc0', + filter: { + countries: ['zm'], + }, + language: 'chichewa', + }, + historic_climate: { + id: '', + title: 'Historic Climate', + mimetype: 'video/mp4', + description: '', + filename: 'farmer_historic_climate_zm_ny_360p.mp4', + type: 'file', + subtype: 'video', + cover: { image: '' }, + url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_zm_ny_360p%2F3.%20%20Historic%20Climate%20Information.mp4?alt=media&token=a64c8696-35c1-4fe0-9a8d-f3bead09d593', + size_kb: 17362.3, + md5Checksum: 'f2e0293ff76b6c852f4549aa73d08051', + filter: { + countries: ['zm'], + }, + language: 'chichewa', + }, + probability_risk: { + id: '', + title: 'Probability and Risk', + mimetype: 'video/mp4', + description: '', + filename: 'farmer_probability_risk_zm_ny_360p.mp4', + type: 'file', + subtype: 'video', + cover: { image: '' }, + url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_zm_ny_360p%2F4.%20%20Probability%20and%20Risk.mp4?alt=media&token=fde8fd2a-b948-41ee-8faf-006554296294', + size_kb: 15211.6, + md5Checksum: '3bcb23740c3bc04ddab8e518882abe0e', + filter: { + countries: ['zm'], + }, + language: 'chichewa', + }, + options: { + id: '', + title: 'Options', + mimetype: 'video/mp4', + description: '', + filename: 'farmer_options_zm_ny_360p.mp4', + type: 'file', + subtype: 'video', + cover: { image: '' }, + url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_zm_ny_360p%2F5.%20%20Options.mp4?alt=media&token=b4f61ebc-9ce3-40f4-8fee-a8e5f912c9e6', + size_kb: 20092.7, + md5Checksum: '78cca3684177bcceb127e9314949a669', + filter: { + countries: ['zm'], + }, + language: 'chichewa', + }, + participatory_budget: { + id: '', + title: 'Participatory Budgets', + mimetype: 'video/mp4', + description: '', + filename: 'farmer_participatory_budget_zm_ny_360p.mp4', + type: 'file', + subtype: 'video', + cover: { image: '' }, + url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_zm_ny_360p%2F6.%20%20Participatory%20Budgets.mp4?alt=media&token=83083852-0b13-4fd5-a607-e33ed4745396', + size_kb: 22867.8, + md5Checksum: 'a52c0c86ffe01ff6430ef03575c4f1b3', + filter: { + countries: ['zm'], + }, + language: 'chichewa', + }, + }, + }, +}; + +const fileResources: Record = {}; +for (const [languageCode, resourcesByResolution] of Object.entries(PICSA_FARMER_VIDEO_RESOURCES)) { + for (const [resolution, resourcesById] of Object.entries(resourcesByResolution as IFarmerVideoHashmap)) { + for (const [videoId, resource] of Object.entries(resourcesById as IFarmerVideoHashmap)) { + const id = `farmer_${videoId}_${languageCode}_${resolution}`; + resource.id = id; + fileResources[id] = resource; + } + } +} + +const picsa_videos_farmer: IResourceCollection = { + id: 'picsa_videos_farmer', + priority: 10, + type: 'collection', + title: 'Farmer Videos', + description: 'Training videos to support PICSA', + childResources: { collections: [], files: Object.keys(fileResources), links: [] }, + parentCollection: 'picsa_videos', +}; + +export default { ...fileResources, picsa_videos_farmer }; diff --git a/apps/picsa-tools/resources-tool/src/app/data/picsa/farmer-videos.ts b/apps/picsa-tools/resources-tool/src/app/data/picsa/farmer-videos.ts index 8b8f167fe..54b440d19 100644 --- a/apps/picsa-tools/resources-tool/src/app/data/picsa/farmer-videos.ts +++ b/apps/picsa-tools/resources-tool/src/app/data/picsa/farmer-videos.ts @@ -1,263 +1,18 @@ -import { IResourceCollection, IResourceFile } from '../../schemas'; +import { PICSA_FARMER_VIDEO_RESOURCES_HASHMAP } from '@picsa/data/resources'; -export interface IFarmerVideosById { - ram: IResourceFile; - seasonal_calendar: IResourceFile; - historic_climate: IResourceFile; - probability_risk: IResourceFile; - options: IResourceFile; - participatory_budget: IResourceFile; -} - -interface IFarmerVideoHashmap { - en: { - '360p': IFarmerVideosById; - }; - mw_ny: { - '360p': IFarmerVideosById; - }; - zm_ny: { - '360p': IFarmerVideosById; - }; -} - -export const PICSA_FARMER_VIDEO_RESOURCES: IFarmerVideoHashmap = { - en: { - '360p': {} as any, - }, - mw_ny: { - '360p': { - ram: { - id: '', - title: 'Resource Allocation Maps', - mimetype: 'video/mp4', - description: '', - filename: 'farmer_ram_mw_ny_360p.mp4', - type: 'file', - subtype: 'video', - cover: { image: '' }, - url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_mw_ny_360p%2F1.%20Resource%20Allocation%20Map.mp4?alt=media&token=389663db-b51b-447f-97fb-8cac3596cf08', - size_kb: 13849.1, - md5Checksum: '3a45d2aa858b9346b82344f3f9b07be1', - filter: { - countries: ['mw'], - }, - language: 'chichewa', - }, - seasonal_calendar: { - id: '', - title: 'Seasonal Calendar', - mimetype: 'video/mp4', - description: '', - filename: 'farmer_seasonal_calendar_mw_ny_360p.mp4', - type: 'file', - subtype: 'video', - cover: { image: '' }, - url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_mw_ny_360p%2F2.%20Seasonal%20Calendar.mp4?alt=media&token=3c51f6bc-82bb-4a85-83b2-7740ca8a0d14', - size_kb: 15009.5, - md5Checksum: '61e55aa62764a62c9fd6f181e1c092d0', - filter: { - countries: ['mw'], - }, - language: 'chichewa', - }, - historic_climate: { - id: '', - title: 'Historic Climate', - mimetype: 'video/mp4', - description: '', - filename: 'farmer_historic_climate_mw_ny_360p.mp4', - type: 'file', - subtype: 'video', - cover: { image: '' }, - url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_mw_ny_360p%2F3.%20Historic%20Climate%20Info.mp4?alt=media&token=79d1ec35-7bc8-4dc1-a1dc-09abb7cb1585', - size_kb: 22243.2, - md5Checksum: '34146918bbdb7e4dd66525283d355d74', - filter: { - countries: ['mw'], - }, - language: 'chichewa', - }, - probability_risk: { - id: '', - title: 'Probability and Risk', - mimetype: 'video/mp4', - description: '', - filename: 'farmer_probability_risk_mw_ny_360p.mp4', - type: 'file', - subtype: 'video', - cover: { image: '' }, - url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_mw_ny_360p%2F4.%20Probability%20and%20Risk.mp4?alt=media&token=a40efecf-97c1-497c-9ac3-d359c6b35bdc', - size_kb: 15475.5, - md5Checksum: '7a16e9f97cc38af86db73b5375620188', - filter: { - countries: ['mw'], - }, - language: 'chichewa', - }, - options: { - id: '', - title: 'Options', - mimetype: 'video/mp4', - description: '', - filename: 'farmer_options_mw_ny_360p.mp4', - type: 'file', - subtype: 'video', - cover: { image: '' }, - url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_mw_ny_360p%2F5.%20Options.mp4?alt=media&token=8a8c45d7-c37d-4eed-8010-0ba4938e8bde', - size_kb: 23894.9, - md5Checksum: 'd6a120bfd36fd8209d189b4c7a2ab66c', - filter: { - countries: ['mw'], - }, - language: 'chichewa', - }, - participatory_budget: { - id: '', - title: 'Participatory Budgets', - mimetype: 'video/mp4', - description: '', - filename: 'farmer_participatory_budget_mw_ny_360p.mp4', - type: 'file', - subtype: 'video', - cover: { image: '' }, - url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_mw_ny_360p%2F6.%20Participatory%20Budgets.mp4?alt=media&token=80530f77-35bd-48b9-bd7a-ed1400e2b449', - size_kb: 24937.8, - md5Checksum: '933e92eb90875bed4a1029244cd11270', - filter: { - countries: ['mw'], - }, - language: 'chichewa', - }, - }, - }, - zm_ny: { - '360p': { - ram: { - id: '', - title: 'Resource Allocation Maps', - mimetype: 'video/mp4', - description: '', - filename: 'farmer_ram_zm_ny_360p.mp4', - type: 'file', - subtype: 'video', - cover: { image: '' }, - url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_zm_ny_360p%2F1.%20%20Resource%20Allocation%20Maps.mp4?alt=media&token=d5279c07-7ccb-42b7-980b-6d168cce40a2', - size_kb: 13446.1, - md5Checksum: 'e0afe2791e2ed24bed2148f9977e34a9', - filter: { - countries: ['zm'], - }, - language: 'chichewa', - }, - seasonal_calendar: { - id: '', - title: 'Seasonal Calendar', - mimetype: 'video/mp4', - description: '', - filename: 'farmer_seasonal_calendar_zm_ny_360p.mp4', - type: 'file', - subtype: 'video', - cover: { image: '' }, - url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_zm_ny_360p%2F2.%20%20Seasonal%20Calendar.mp4?alt=media&token=e47c8178-2416-42b3-9c72-8df2efcf3c95', - size_kb: 12415.1, - md5Checksum: '3420a2b421d6c6da8441e971b8520bc0', - filter: { - countries: ['zm'], - }, - language: 'chichewa', - }, - historic_climate: { - id: '', - title: 'Historic Climate', - mimetype: 'video/mp4', - description: '', - filename: 'farmer_historic_climate_zm_ny_360p.mp4', - type: 'file', - subtype: 'video', - cover: { image: '' }, - url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_zm_ny_360p%2F3.%20%20Historic%20Climate%20Information.mp4?alt=media&token=a64c8696-35c1-4fe0-9a8d-f3bead09d593', - size_kb: 17362.3, - md5Checksum: 'f2e0293ff76b6c852f4549aa73d08051', - filter: { - countries: ['zm'], - }, - language: 'chichewa', - }, - probability_risk: { - id: '', - title: 'Probability and Risk', - mimetype: 'video/mp4', - description: '', - filename: 'farmer_probability_risk_zm_ny_360p.mp4', - type: 'file', - subtype: 'video', - cover: { image: '' }, - url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_zm_ny_360p%2F4.%20%20Probability%20and%20Risk.mp4?alt=media&token=fde8fd2a-b948-41ee-8faf-006554296294', - size_kb: 15211.6, - md5Checksum: '3bcb23740c3bc04ddab8e518882abe0e', - filter: { - countries: ['zm'], - }, - language: 'chichewa', - }, - options: { - id: '', - title: 'Options', - mimetype: 'video/mp4', - description: '', - filename: 'farmer_options_zm_ny_360p.mp4', - type: 'file', - subtype: 'video', - cover: { image: '' }, - url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_zm_ny_360p%2F5.%20%20Options.mp4?alt=media&token=b4f61ebc-9ce3-40f4-8fee-a8e5f912c9e6', - size_kb: 20092.7, - md5Checksum: '78cca3684177bcceb127e9314949a669', - filter: { - countries: ['zm'], - }, - language: 'chichewa', - }, - participatory_budget: { - id: '', - title: 'Participatory Budgets', - mimetype: 'video/mp4', - description: '', - filename: 'farmer_participatory_budget_zm_ny_360p.mp4', - type: 'file', - subtype: 'video', - cover: { image: '' }, - url: 'https://firebasestorage.googleapis.com/v0/b/picsa-apps.appspot.com/o/picsa%2Fvideos%2Ffarmer_zm_ny_360p%2F6.%20%20Participatory%20Budgets.mp4?alt=media&token=83083852-0b13-4fd5-a607-e33ed4745396', - size_kb: 22867.8, - md5Checksum: 'a52c0c86ffe01ff6430ef03575c4f1b3', - filter: { - countries: ['zm'], - }, - language: 'chichewa', - }, - }, - }, -}; - -const fileResources: Record = {}; -for (const [languageCode, resourcesByResolution] of Object.entries(PICSA_FARMER_VIDEO_RESOURCES)) { - for (const [resolution, resourcesById] of Object.entries(resourcesByResolution as IFarmerVideoHashmap)) { - for (const [videoId, resource] of Object.entries(resourcesById as IFarmerVideoHashmap)) { - const id = `farmer_${videoId}_${languageCode}_${resolution}`; - resource.id = id; - fileResources[id] = resource; - } - } -} +import { IResourceCollection } from '../../schemas'; +/** + * Create a collection to store all farmer videos populated to hardcoded data + */ const picsa_videos_farmer: IResourceCollection = { id: 'picsa_videos_farmer', priority: 10, type: 'collection', title: 'Farmer Videos', description: 'Training videos to support PICSA', - childResources: { collections: [], files: Object.keys(fileResources), links: [] }, + childResources: { collections: [], files: Object.keys(PICSA_FARMER_VIDEO_RESOURCES_HASHMAP), links: [] }, parentCollection: 'picsa_videos', }; -export default { ...fileResources, picsa_videos_farmer }; +export default { ...PICSA_FARMER_VIDEO_RESOURCES_HASHMAP, picsa_videos_farmer }; diff --git a/libs/data/farmer_content/data/content/0_intro.ts b/libs/data/farmer_content/data/content/0_intro.ts index 1dbb03f69..f8552ea27 100644 --- a/libs/data/farmer_content/data/content/0_intro.ts +++ b/libs/data/farmer_content/data/content/0_intro.ts @@ -1,9 +1,9 @@ import { marker as translateMarker } from '@biesbjerg/ngx-translate-extract-marker'; -import { PICSA_FARMER_VIDEO_RESOURCES } from '@picsa/resources/src/app/data/picsa/farmer-videos'; import { IFarmerContent, IFarmerContentStep } from '../../types'; +import { PICSA_FARMER_VIDEOS_HASHMAP } from '@picsa/data/resources'; -const steps: IFarmerContentStep[] = []; +const steps: IFarmerContentStep[] = [{ type: 'video', video: PICSA_FARMER_VIDEOS_HASHMAP.intro }]; const content: Omit = { slug: 'intro', @@ -11,6 +11,5 @@ const content: Omit = { tools: [], tags: [{ label: translateMarker('Tutorials') }], steps, - disabled: true, }; export default content; diff --git a/libs/data/farmer_content/data/content/1_what_you_do.ts b/libs/data/farmer_content/data/content/1_what_you_do.ts index fc3539a10..ea3198138 100644 --- a/libs/data/farmer_content/data/content/1_what_you_do.ts +++ b/libs/data/farmer_content/data/content/1_what_you_do.ts @@ -1,20 +1,20 @@ import { marker as translateMarker } from '@biesbjerg/ngx-translate-extract-marker'; -import { PICSA_FARMER_VIDEO_RESOURCES } from '@picsa/resources/src/app/data/picsa/farmer-videos'; import { IFarmerContent, IFarmerContentStep } from '../../types'; import { TOOLS_DATA_HASHMAP } from '../tools'; +import { PICSA_FARMER_VIDEOS_HASHMAP } from '@picsa/data/resources'; const { seasonal_calendar } = TOOLS_DATA_HASHMAP; const steps: IFarmerContentStep[] = [ { type: 'video', - resource: PICSA_FARMER_VIDEO_RESOURCES.mw_ny['360p'].ram, + video: PICSA_FARMER_VIDEOS_HASHMAP.ram, tabLabel: translateMarker('Ram'), }, { type: 'video', - resource: PICSA_FARMER_VIDEO_RESOURCES.mw_ny['360p'].seasonal_calendar, + video: PICSA_FARMER_VIDEOS_HASHMAP.seasonal_calendar, tabLabel: translateMarker('Calendar'), }, ]; diff --git a/libs/data/farmer_content/data/content/2_climate_change.ts b/libs/data/farmer_content/data/content/2_climate_change.ts index 05f2db846..986c3b10f 100644 --- a/libs/data/farmer_content/data/content/2_climate_change.ts +++ b/libs/data/farmer_content/data/content/2_climate_change.ts @@ -1,15 +1,15 @@ import { marker as translateMarker } from '@biesbjerg/ngx-translate-extract-marker'; -import { PICSA_FARMER_VIDEO_RESOURCES } from '@picsa/resources/src/app/data/picsa/farmer-videos'; import { IFarmerContent, IFarmerContentStep } from '../../types'; import { TOOLS_DATA_HASHMAP } from '../tools'; +import { PICSA_FARMER_VIDEOS_HASHMAP } from '@picsa/data/resources'; const { climate } = TOOLS_DATA_HASHMAP; const steps: IFarmerContentStep[] = [ { type: 'video', - resource: PICSA_FARMER_VIDEO_RESOURCES.mw_ny['360p'].historic_climate, + video: PICSA_FARMER_VIDEOS_HASHMAP.historic_climate, }, ]; diff --git a/libs/data/farmer_content/data/content/3_opportunities_risks.ts b/libs/data/farmer_content/data/content/3_opportunities_risks.ts index 9da5f466e..10b141351 100644 --- a/libs/data/farmer_content/data/content/3_opportunities_risks.ts +++ b/libs/data/farmer_content/data/content/3_opportunities_risks.ts @@ -1,15 +1,15 @@ import { marker as translateMarker } from '@biesbjerg/ngx-translate-extract-marker'; -import { PICSA_FARMER_VIDEO_RESOURCES } from '@picsa/resources/src/app/data/picsa/farmer-videos'; import { IFarmerContent, IFarmerContentStep } from '../../types'; import { TOOLS_DATA_HASHMAP } from '../tools'; +import { PICSA_FARMER_VIDEOS_HASHMAP } from '@picsa/data/resources'; const { probability_and_risk } = TOOLS_DATA_HASHMAP; const steps: IFarmerContentStep[] = [ { type: 'video', - resource: PICSA_FARMER_VIDEO_RESOURCES.mw_ny['360p'].probability_risk, + video: PICSA_FARMER_VIDEOS_HASHMAP.probability_risk, }, ]; diff --git a/libs/data/farmer_content/data/content/4_what_are_the_options.ts b/libs/data/farmer_content/data/content/4_what_are_the_options.ts index 3d1d91daa..2b78f3173 100644 --- a/libs/data/farmer_content/data/content/4_what_are_the_options.ts +++ b/libs/data/farmer_content/data/content/4_what_are_the_options.ts @@ -1,15 +1,15 @@ import { marker as translateMarker } from '@biesbjerg/ngx-translate-extract-marker'; -import { PICSA_FARMER_VIDEO_RESOURCES } from '@picsa/resources/src/app/data/picsa/farmer-videos'; import { IFarmerContent, IFarmerContentStep } from '../../types'; import { TOOLS_DATA_HASHMAP } from '../tools'; +import { PICSA_FARMER_VIDEOS_HASHMAP } from '@picsa/data/resources'; const { options } = TOOLS_DATA_HASHMAP; const steps: IFarmerContentStep[] = [ { type: 'video', - resource: PICSA_FARMER_VIDEO_RESOURCES.mw_ny['360p'].options, + video: PICSA_FARMER_VIDEOS_HASHMAP.options, }, ]; diff --git a/libs/data/farmer_content/data/content/5_compare_options.ts b/libs/data/farmer_content/data/content/5_compare_options.ts index 94a106fb0..bab5df29f 100644 --- a/libs/data/farmer_content/data/content/5_compare_options.ts +++ b/libs/data/farmer_content/data/content/5_compare_options.ts @@ -1,15 +1,15 @@ import { marker as translateMarker } from '@biesbjerg/ngx-translate-extract-marker'; -import { PICSA_FARMER_VIDEO_RESOURCES } from '@picsa/resources/src/app/data/picsa/farmer-videos'; import { IFarmerContent, IFarmerContentStep } from '../../types'; import { TOOLS_DATA_HASHMAP } from '../tools'; +import { PICSA_FARMER_VIDEOS_HASHMAP } from '@picsa/data/resources'; const { budget } = TOOLS_DATA_HASHMAP; const steps: IFarmerContentStep[] = [ { type: 'video', - resource: PICSA_FARMER_VIDEO_RESOURCES.mw_ny['360p'].participatory_budget, + video: PICSA_FARMER_VIDEOS_HASHMAP.participatory_budget, }, ]; diff --git a/libs/data/farmer_content/data/content/6_decide_and_plan.ts b/libs/data/farmer_content/data/content/6_decide_and_plan.ts index 1d83e72b0..400fb6d27 100644 --- a/libs/data/farmer_content/data/content/6_decide_and_plan.ts +++ b/libs/data/farmer_content/data/content/6_decide_and_plan.ts @@ -1,6 +1,5 @@ import { marker as translateMarker } from '@biesbjerg/ngx-translate-extract-marker'; -import { PICSA_FARMER_VIDEO_RESOURCES } from '@picsa/resources/src/app/data/picsa/farmer-videos'; import { IFarmerContent, IFarmerContentStep } from '../../types'; import { TOOLS_DATA_HASHMAP } from '../tools'; diff --git a/libs/data/farmer_content/types.ts b/libs/data/farmer_content/types.ts index 0fd5ff8b9..a6773df0e 100644 --- a/libs/data/farmer_content/types.ts +++ b/libs/data/farmer_content/types.ts @@ -1,8 +1,7 @@ -import type { IResourceFile } from '@picsa/resources/src/app/schemas'; - import type { IFarmerContentId } from './data/content'; import type { IToolId } from './data/tools'; +import { IPicsaVideoData } from '../resources'; export interface IToolData { id: IToolId; @@ -14,7 +13,7 @@ export interface IToolData { interface IFarmerContentStepVideo { type: 'video'; - resource: IResourceFile; + video: IPicsaVideoData; /** Label to show when selecting content from tab */ tabLabel?: string; } diff --git a/libs/data/resources/farmerVideos.ts b/libs/data/resources/farmerVideos.ts new file mode 100644 index 000000000..6e956c324 --- /dev/null +++ b/libs/data/resources/farmerVideos.ts @@ -0,0 +1,150 @@ +import { arrayToHashmap } from '@picsa/utils'; +import type { IResourceFile } from '@picsa/resources/src/app/schemas'; +import { IPicsaVideoData } from './types'; + +type IPicsaFarmerVideoId = + | 'intro' + | 'ram' + | 'seasonal_calendar' + | 'historic_climate' + | 'probability_risk' + | 'options' + | 'participatory_budget'; + +const PICSA_FARMER_VIDEOS_BASE: Record> = { + intro: { + children: [ + { + id: '', + locale_code: 'mw_ny', + resolution: '360p', + size_kb: 12900, + supabase_url: + 'https://wpctacqpzxfzlucblowh.supabase.co/storage/v1/object/public/mw/videos/PICSA%20Intro.mp4?t=2024-08-02T05%3A17%3A54.946Z', + }, + ], + }, + ram: { + children: [ + { + id: '', + locale_code: 'global_en', + size_kb: 14840, + resolution: '360p', + supabase_url: + 'https://wpctacqpzxfzlucblowh.supabase.co/storage/v1/object/public/global/videos/PICSA%20Steps/1a%20%20Resource%20Allocation%20Map.mp4', + }, + ], + }, + seasonal_calendar: { + children: [ + { + id: '', + locale_code: 'global_en', + size_kb: 12950, + resolution: '360p', + supabase_url: + 'https://wpctacqpzxfzlucblowh.supabase.co/storage/v1/object/public/global/videos/PICSA%20Steps/1b%20%20Seasonal%20Calendar.mp4', + }, + ], + }, + historic_climate: { + children: [ + { + id: '', + locale_code: 'global_en', + size_kb: 20710, + resolution: '360p', + supabase_url: + 'https://wpctacqpzxfzlucblowh.supabase.co/storage/v1/object/public/global/videos/PICSA%20Steps/2%20%20Historical%20Climate%20Information.mp4', + }, + ], + }, + probability_risk: { + children: [ + { + id: '', + locale_code: 'global_en', + size_kb: 20800, + resolution: '360p', + supabase_url: + 'https://wpctacqpzxfzlucblowh.supabase.co/storage/v1/object/public/global/videos/PICSA%20Steps/3%20%20What%20are%20the%20risks%20and%20opportunities.mp4', + }, + ], + }, + options: { + children: [ + { + id: '', + locale_code: 'global_en', + size_kb: 19680, + resolution: '360p', + supabase_url: + 'https://wpctacqpzxfzlucblowh.supabase.co/storage/v1/object/public/global/videos/PICSA%20Steps/4%20%20Crop,%20Livestock%20and%20Livelihood%20Options.mp4', + }, + ], + }, + participatory_budget: { + children: [ + { + id: '', + locale_code: 'global_en', + size_kb: 21720, + resolution: '360p', + supabase_url: + 'https://wpctacqpzxfzlucblowh.supabase.co/storage/v1/object/public/global/videos/PICSA%20Steps/5%20%20Particpatory%20Budget.mp4', + }, + ], + }, +}; + +export const PICSA_FARMER_VIDEOS_DATA: IPicsaVideoData[] = Object.entries(PICSA_FARMER_VIDEOS_BASE).map( + ([id, entry]) => ({ + id: id as IPicsaFarmerVideoId, + children: entry.children.map((child) => { + const { locale_code, resolution } = child; + child.id = `farmer_${id}_${locale_code}_${resolution}`; + return child; + }), + }) +); + +export const PICSA_FARMER_VIDEOS_HASHMAP: Record = arrayToHashmap( + PICSA_FARMER_VIDEOS_DATA, + 'id' +); + +/************************************************************************** + * Legacy Resource Format + * Support legacy resources system where each resource child has own db entry + * + * TODO - migrate all resources to use modern format so code below can be removed + ***************************************************************************/ + +export const PICSA_FARMER_VIDEO_RESOURCES = hackGenerateLegacyResources(); + +export const PICSA_FARMER_VIDEO_RESOURCES_HASHMAP = arrayToHashmap(PICSA_FARMER_VIDEO_RESOURCES, 'id'); + +/** + * HACK - generate a list of legacy resources from updated farmer data + */ +function hackGenerateLegacyResources() { + const resources: IResourceFile[] = []; + for (const { children } of PICSA_FARMER_VIDEOS_DATA) { + for (const { id, size_kb, supabase_url } of children) { + const resourceFile: IResourceFile = { + id, + filename: `${id}.mp4`, + md5Checksum: '', + mimetype: 'video/mp4', + size_kb, + subtype: 'video', + title: '', + type: 'file', + url: supabase_url, + }; + resources.push(resourceFile); + } + } + return resources; +} diff --git a/libs/data/resources/index.ts b/libs/data/resources/index.ts new file mode 100644 index 000000000..69c8d315c --- /dev/null +++ b/libs/data/resources/index.ts @@ -0,0 +1,2 @@ +export * from './types'; +export * from './farmerVideos'; diff --git a/libs/data/resources/types.ts b/libs/data/resources/types.ts new file mode 100644 index 000000000..e28ee367d --- /dev/null +++ b/libs/data/resources/types.ts @@ -0,0 +1,20 @@ +import { ILocaleCode } from '../deployments'; + +export interface IPicsaVideo { + id: string; + locale_code: ILocaleCode; + size_kb: number; + resolution: '360p'; + supabase_url: string; +} + +/** + * Video resource type with child video entries + * TODO - replace previous resource format with videoData type + */ +export interface IPicsaVideoData { + id: string; + children: IPicsaVideo[]; + title?: string; + description?: string; +}