-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e02dc68
commit 189f2ec
Showing
10 changed files
with
146 additions
and
136 deletions.
There are no files selected for viewing
35 changes: 10 additions & 25 deletions
35
...csa-apps/dashboard/src/app/modules/translations/pages/edit/translations-edit.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,33 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { FormBuilder, FormControl, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms'; | ||
import { FormBuilder, FormControl, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
// eslint-disable-next-line @nx/enforce-module-boundaries | ||
import type { Database } from '@picsa/server-types'; | ||
import { PICSAFormValidators } from '@picsa/shared/modules/forms/validators'; | ||
//import { | ||
// IUploadResult, | ||
// SupabaseStoragePickerDirective, | ||
// SupabaseUploadComponent, | ||
// } from '@picsa/shared/services/core/supabase'; | ||
// import { IStorageEntry } from '@picsa/shared/services/core/supabase/services/supabase-storage.service'; | ||
import type { Database } from '@picsa/server-types'; | ||
import { PICSAFormValidators } from '@picsa/shared/modules/forms/validators'; | ||
|
||
// import { DashboardMaterialModule } from '../../../../material.module'; | ||
import { DashboardMaterialModule } from '../../../../material.module'; | ||
// import { DashboardResourcesStorageLinkComponent } from '../../components/storage-link/storage-link.component'; | ||
// import { ResourcesDashboardService } from '../../translations.service'; | ||
import { TranslationDashboardService } from '../../translations.service'; | ||
|
||
// type IResourceEntry = Database['public']['Tables']['resources']['Row']; | ||
|
||
@Component({ | ||
selector: 'dashboard-resource-create', | ||
selector: 'dashboard-translations-edit', | ||
standalone: true, | ||
imports: [ | ||
CommonModule, | ||
// DashboardMaterialModule, | ||
// DashboardResourcesStorageLinkComponent, | ||
// FormsModule, | ||
// ReactiveFormsModule, | ||
// SupabaseStoragePickerDirective, | ||
// SupabaseUploadComponent, | ||
DashboardMaterialModule, | ||
FormsModule, | ||
ReactiveFormsModule, | ||
], | ||
templateUrl: './translations-edit.component.html', | ||
styleUrls: ['./translations-edit.component.scss'], | ||
}) | ||
export class TranslationsEditComponent { | ||
constructor( | ||
// private service: ResourcesDashboardService, | ||
private service: TranslationDashboardService, | ||
private route: ActivatedRoute | ||
) {} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,7 @@ tr.resource-row { | |
th { | ||
font-weight: bold; | ||
} | ||
|
||
td { | ||
cursor: pointer; | ||
} |
19 changes: 14 additions & 5 deletions
19
apps/picsa-apps/dashboard/src/app/modules/translations/pages/home/translations.page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { RouterModule } from '@angular/router'; | ||
import { Router } from '@angular/router'; | ||
// eslint-disable-next-line @nx/enforce-module-boundaries | ||
import { Database } from '@picsa/server-types'; | ||
|
||
import { DashboardMaterialModule } from '../../../../material.module'; | ||
// import { DashboardResourcesStorageLinkComponent } from '../../components'; | ||
import { ResourcesDashboardService } from '../../translations.service'; | ||
import { TranslationDashboardService } from '../../translations.service'; | ||
|
||
export type ITranslationRow = Database['public']['Tables']['translations']['Row']; | ||
@Component({ | ||
selector: 'dashboard-resources-page', | ||
selector: 'dashboard-translations-page', | ||
standalone: true, | ||
imports: [CommonModule, DashboardMaterialModule, RouterModule], | ||
templateUrl: './translations.page.html', | ||
styleUrls: ['./translations.page.scss'], | ||
}) | ||
export class TranslationsPageComponent implements OnInit { | ||
//public displayedColumns = ['title', 'storage_file']; | ||
constructor(public service: ResourcesDashboardService) {} | ||
displayedColumns: string[] = [ 'en', 'mw_ny', 'sw', 'tg', 'zm_ny','created_at',]; | ||
constructor(public service: TranslationDashboardService, private router: Router) {} | ||
ngOnInit(): void { | ||
this.service.ready(); | ||
|
||
} | ||
goToRecord(row:ITranslationRow){ | ||
console.log(row) | ||
this.router.navigate([`/`, row.id]); | ||
|
||
} | ||
} |
98 changes: 13 additions & 85 deletions
98
apps/picsa-apps/dashboard/src/app/modules/translations/translations.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,41 @@ | ||
import { Injectable, signal } from '@angular/core'; | ||
import { Injectable } from '@angular/core'; | ||
// eslint-disable-next-line @nx/enforce-module-boundaries | ||
import { Database } from '@picsa/server-types'; | ||
import { PicsaAsyncService } from '@picsa/shared/services/asyncService.service'; | ||
import { PicsaNotificationService } from '@picsa/shared/services/core/notification.service'; | ||
// import { PicsaNotificationService } from '@picsa/shared/services/core/notification.service'; | ||
import { SupabaseService } from '@picsa/shared/services/core/supabase'; | ||
import { IStorageEntry } from '@picsa/shared/services/core/supabase/services/supabase-storage.service'; | ||
import { arrayToHashmap } from '@picsa/utils'; | ||
|
||
export type ITranslationRow = Database['public']['Tables']['translations']['Row']; | ||
|
||
export interface IResourceStorageEntry extends IStorageEntry { | ||
/** Url generated when upload to public bucket (will always be populated, even if bucket not public) */ | ||
publicUrl: string; | ||
} | ||
|
||
export type IResourceEntry = Database['public']['Tables']['resources']['Row']; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class ResourcesDashboardService extends PicsaAsyncService { | ||
private storageFiles: IResourceStorageEntry[] = []; | ||
public storageFilesHashmap: Record<string, IResourceStorageEntry> = {}; | ||
public readonly resources = signal<IResourceEntry[]>([]); | ||
export class TranslationDashboardService extends PicsaAsyncService { | ||
|
||
public translations: ITranslationRow[] = []; | ||
|
||
public get table() { | ||
return this.supabaseService.db.table('resources'); | ||
return this.supabaseService.db.table('translations'); | ||
} | ||
|
||
constructor(private supabaseService: SupabaseService, private notificationService: PicsaNotificationService) { | ||
constructor(private supabaseService: SupabaseService) { | ||
super(); | ||
} | ||
|
||
public override async init() { | ||
await this.supabaseService.ready(); | ||
await this.listStorageFiles(); | ||
await this.listResources(); | ||
} | ||
|
||
/** Retrieve storage db meta for a file */ | ||
public async getStorageFileById(id: string) { | ||
// Refresh storage file cache if id not found | ||
if (!this.storageFilesHashmap[id]) { | ||
await this.listStorageFiles(); | ||
} | ||
return this.storageFilesHashmap[id]; | ||
} | ||
|
||
/** | ||
* | ||
* TODO - only enable super admin/local dev | ||
* TODO - remove when no longer required | ||
*/ | ||
public async migrateHardcodedResources() { | ||
// NOTE - assumes storage files manually uploaded | ||
|
||
// eslint-disable-next-line @nx/enforce-module-boundaries | ||
const { DB_COLLECTION_ENTRIES, DB_FILE_ENTRIES, DB_LINK_ENTRIES } = await import( | ||
'@picsa/resources/src/app/data/index' | ||
); | ||
console.log({ DB_COLLECTION_ENTRIES, DB_FILE_ENTRIES, DB_LINK_ENTRIES }); | ||
const ref = this.supabaseService.db.table('resources'); | ||
const uploaded: unknown[] = []; | ||
const missing: unknown[] = []; | ||
|
||
for (const fileEntry of Object.values(DB_FILE_ENTRIES)) { | ||
const { type, description, url } = fileEntry; | ||
// extract pathname from firebase url | ||
const { pathname } = new URL(url); | ||
const storagePath = decodeURI(pathname).replace(/%2F/g, '/').replace('/v0/b/picsa-apps.appspot.com/o/', ''); | ||
// check for equivalent storage file | ||
const storageFile = this.storageFiles.find((file) => file.name === storagePath); | ||
if (storageFile) { | ||
const dbEntry: Database['public']['Tables']['resources']['Insert'] = { | ||
description, | ||
type, | ||
|
||
storage_file: storageFile.id, | ||
}; | ||
const { error } = await ref.upsert(dbEntry, { ignoreDuplicates: false }); | ||
|
||
if (error) { | ||
console.error(error); | ||
} | ||
uploaded.push(fileEntry); | ||
} else { | ||
missing.push(fileEntry); | ||
} | ||
} | ||
console.log({ uploaded, missing }); | ||
if (missing.length > 0) { | ||
this.notificationService.showUserNotification({ | ||
matIcon: 'error', | ||
message: `${missing.length} files missing from storage`, | ||
}); | ||
} | ||
await this.listTranslations(); | ||
} | ||
|
||
private async listStorageFiles() { | ||
const storageFiles = await this.supabaseService.storage.list('resources'); | ||
this.storageFiles = storageFiles.map((file) => ({ | ||
...file, | ||
publicUrl: this.supabaseService.storage.getPublicLink(file.bucket_id as string, file.name as string), | ||
})); | ||
this.storageFilesHashmap = arrayToHashmap(this.storageFiles, 'id'); | ||
console.log('storage files', this.storageFilesHashmap); | ||
} | ||
|
||
private async listResources() { | ||
const { data, error } = await this.supabaseService.db.table('resources').select<'*', IResourceEntry>('*'); | ||
private async listTranslations() { | ||
const { data, error } = await this.supabaseService.db.table('translations').select<'*', ITranslationRow>('*'); | ||
if (error) { | ||
throw error; | ||
} | ||
this.resources.set(data); | ||
this.translations = data || []; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
apps/picsa-server/supabase/migrations/20240102153452_translations_table_create.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
create table | ||
public.translations ( | ||
id bigint generated by default as identity, | ||
created_at timestamp with time zone not null default now(), | ||
en text null, | ||
mw_ny text null, | ||
sw text null, | ||
tg text null, | ||
zm_ny text null, | ||
constraint translations_pkey primary key (id) | ||
) tablespace pg_default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.