-
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
66bc218
commit e02dc68
Showing
14 changed files
with
295 additions
and
13 deletions.
There are no files selected for viewing
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
5 changes: 5 additions & 0 deletions
5
...a-apps/dashboard/src/app/modules/translations/pages/edit/translations-edit.component.html
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,5 @@ | ||
<div class="page-content"> | ||
<h2>Edit Translations</h2> | ||
|
||
|
||
</div> |
Empty file.
21 changes: 21 additions & 0 deletions
21
...pps/dashboard/src/app/modules/translations/pages/edit/translations-edit.component.spec.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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { TranslationsEditComponent } from './translations-edit.component'; | ||
|
||
describe('TranslationsEditComponent', () => { | ||
let component: TranslationsEditComponent; | ||
let fixture: ComponentFixture<TranslationsEditComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [TranslationsEditComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(TranslationsEditComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
...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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, OnInit } from '@angular/core'; | ||
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 { DashboardMaterialModule } from '../../../../material.module'; | ||
// import { DashboardResourcesStorageLinkComponent } from '../../components/storage-link/storage-link.component'; | ||
// import { ResourcesDashboardService } from '../../translations.service'; | ||
|
||
// type IResourceEntry = Database['public']['Tables']['resources']['Row']; | ||
|
||
@Component({ | ||
selector: 'dashboard-resource-create', | ||
standalone: true, | ||
imports: [ | ||
CommonModule, | ||
// DashboardMaterialModule, | ||
// DashboardResourcesStorageLinkComponent, | ||
// FormsModule, | ||
// ReactiveFormsModule, | ||
// SupabaseStoragePickerDirective, | ||
// SupabaseUploadComponent, | ||
], | ||
templateUrl: './translations-edit.component.html', | ||
styleUrls: ['./translations-edit.component.scss'], | ||
}) | ||
export class TranslationsEditComponent { | ||
constructor( | ||
// private service: ResourcesDashboardService, | ||
private route: ActivatedRoute | ||
) {} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} |
5 changes: 5 additions & 0 deletions
5
apps/picsa-apps/dashboard/src/app/modules/translations/pages/home/translations.page.html
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,5 @@ | ||
<div class="page-content"> | ||
<div style="display: flex"> | ||
<h2 style="flex: 1">Translations</h2> | ||
</div> | ||
</div> |
14 changes: 14 additions & 0 deletions
14
apps/picsa-apps/dashboard/src/app/modules/translations/pages/home/translations.page.scss
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,14 @@ | ||
table.resources-table { | ||
max-height: 50vh; | ||
display: block; | ||
overflow: auto; | ||
} | ||
tr.resource-row { | ||
cursor: pointer; | ||
&:hover { | ||
background: whitesmoke; | ||
} | ||
} | ||
th { | ||
font-weight: bold; | ||
} |
22 changes: 22 additions & 0 deletions
22
apps/picsa-apps/dashboard/src/app/modules/translations/pages/home/translations.page.spec.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { TranslationsPageComponent } from './translations.page'; | ||
|
||
describe('TranslationsPageComponent', () => { | ||
let component: TranslationsPageComponent; | ||
let fixture: ComponentFixture<TranslationsPageComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [TranslationsPageComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(TranslationsPageComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { RouterModule } from '@angular/router'; | ||
|
||
import { DashboardMaterialModule } from '../../../../material.module'; | ||
// import { DashboardResourcesStorageLinkComponent } from '../../components'; | ||
import { ResourcesDashboardService } from '../../translations.service'; | ||
|
||
@Component({ | ||
selector: 'dashboard-resources-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) {} | ||
ngOnInit(): void { | ||
this.service.ready(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
apps/picsa-apps/dashboard/src/app/modules/translations/translations.module.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { NgModule } from '@angular/core'; | ||
import { RouterModule } from '@angular/router'; | ||
|
||
import { TranslationsEditComponent } from './pages/edit/translations-edit.component'; | ||
import { TranslationsPageComponent } from './pages/home/translations.page'; | ||
|
||
@NgModule({ | ||
declarations: [], | ||
imports: [ | ||
CommonModule, | ||
RouterModule.forChild([ | ||
{ | ||
path: '', | ||
component: TranslationsPageComponent, | ||
}, | ||
{ | ||
path: 'edit', | ||
component: TranslationsEditComponent, | ||
}, | ||
{ | ||
path: ':id', | ||
component: TranslationsEditComponent, | ||
}, | ||
]), | ||
], | ||
}) | ||
export class TranslationsPageModule {} |
113 changes: 113 additions & 0 deletions
113
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 |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { Injectable, signal } 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 { 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 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[]>([]); | ||
|
||
public get table() { | ||
return this.supabaseService.db.table('resources'); | ||
} | ||
|
||
constructor(private supabaseService: SupabaseService, private notificationService: PicsaNotificationService) { | ||
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`, | ||
}); | ||
} | ||
} | ||
|
||
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>('*'); | ||
if (error) { | ||
throw error; | ||
} | ||
this.resources.set(data); | ||
} | ||
} |
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