Skip to content

Commit

Permalink
Merge pull request #314 from e-picsa/feat/farmer-videos-update
Browse files Browse the repository at this point in the history
Feat: farmer videos update
  • Loading branch information
chrismclarke authored Aug 2, 2024
2 parents eddfa97 + 84105b0 commit a2c9aff
Show file tree
Hide file tree
Showing 19 changed files with 537 additions and 278 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<resource-item-file [resource]="videoResource()"></resource-item-file>
Empty file.
Original file line number Diff line number Diff line change
@@ -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<StepVideoComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [StepVideoComponent],
}).compileComponents();

fixture = TestBed.createComponent(StepVideoComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -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<IPicsaVideoData>();

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];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ <h2 class="title">{{ content.title | translate }}</h2>
{{ step.tabLabel || 'video' | translate }}
</ng-template>
<div class="tab-content">
@if(step.resource){
<resource-item-file [resource]="step.resource"></resource-item-file>
} @else {
<div>Video resource not found</div>
@if(step.video){
<farmer-step-video [videoData]="step.video"></farmer-step-video>
}
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string, IResourceFile> = {};
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 };
Loading

0 comments on commit a2c9aff

Please sign in to comment.