-
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.
Merge pull request #261 from e-picsa/feat/resources-refactor
Feat(dashboard): resources system improvements
- Loading branch information
Showing
82 changed files
with
1,673 additions
and
243 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
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
50 changes: 50 additions & 0 deletions
50
...dashboard/src/app/modules/resources/pages/collections/resource-collections.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,50 @@ | ||
<div class="page-content"> | ||
<div style="display: flex; align-items: center"> | ||
<h2>Resource Collections</h2> | ||
<button | ||
mat-stroked-button | ||
color="primary" | ||
routerLink="create" | ||
style="margin-top: 1rem; margin-left: auto" | ||
[disabled]="true" | ||
> | ||
<mat-icon>add</mat-icon> | ||
Add Collection | ||
</button> | ||
</div> | ||
<p> | ||
Here you can find resources that have been grouped to form a collection. | ||
<br /> | ||
Collections can also contain nested sub-collections | ||
</p> | ||
|
||
<picsa-data-table | ||
[data]="collections" | ||
[options]="tableOptions" | ||
[valueTemplates]="{ | ||
modified_at: modifiedAtTemplate, | ||
cover_image: coverImageTemplate, | ||
collection_parent: collectionParentTemplate | ||
}" | ||
> | ||
<!-- cover image --> | ||
<ng-template #coverImageTemplate let-coverImage> | ||
<img class="cover-image" [src]="coverImage | storagePath" /> | ||
</ng-template> | ||
<!-- parent collection --> | ||
<ng-template #collectionParentTemplate let-collection> | ||
@if(collection){ | ||
<img | ||
class="cover-image color-on-hover" | ||
[src]="collection.cover_image | storagePath" | ||
[matTooltip]="collection.title" | ||
/> | ||
} | ||
</ng-template> | ||
|
||
<!-- modified date --> | ||
<ng-template #modifiedAtTemplate let-date> | ||
{{ date | date: 'mediumDate' }} | ||
</ng-template></picsa-data-table | ||
> | ||
</div> |
7 changes: 7 additions & 0 deletions
7
...dashboard/src/app/modules/resources/pages/collections/resource-collections.component.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,7 @@ | ||
.cover-image { | ||
width: 40px; | ||
height: 40px; | ||
object-fit: cover; | ||
display: block; | ||
margin: auto; | ||
} |
22 changes: 22 additions & 0 deletions
22
...hboard/src/app/modules/resources/pages/collections/resource-collections.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,22 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ResourceCollectionsComponent } from './resource-collections.component'; | ||
|
||
describe('ResourceCollectionsComponent', () => { | ||
let component: ResourceCollectionsComponent; | ||
let fixture: ComponentFixture<ResourceCollectionsComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ResourceCollectionsComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ResourceCollectionsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
101 changes: 101 additions & 0 deletions
101
...s/dashboard/src/app/modules/resources/pages/collections/resource-collections.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,101 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, effect, OnInit } from '@angular/core'; | ||
import { RouterModule } from '@angular/router'; | ||
import { formatHeaderDefault, IDataTableOptions, PicsaDataTableComponent } from '@picsa/shared/features'; | ||
import { StoragePathPipe } from '@picsa/shared/services/core/supabase'; | ||
|
||
import { DashboardMaterialModule } from '../../../../material.module'; | ||
import { ResourcesDashboardService } from '../../resources.service'; | ||
import { IResourceCollectionRow } from '../../types'; | ||
|
||
interface IMergedCollection extends Omit<IResourceCollectionRow, 'collection_parent'> { | ||
collection_parent?: IResourceCollectionRow; | ||
} | ||
|
||
const DISPLAY_COLUMNS: (keyof IMergedCollection)[] = [ | ||
'cover_image', | ||
'title', | ||
'description', | ||
// 'resource_collections', | ||
// 'resource_files', | ||
// 'resource_links', | ||
'collection_parent', | ||
// 'sort_order', | ||
'modified_at', | ||
]; | ||
|
||
@Component({ | ||
selector: 'dashboard-resource-collections', | ||
standalone: true, | ||
imports: [ | ||
CommonModule, | ||
CommonModule, | ||
DashboardMaterialModule, | ||
PicsaDataTableComponent, | ||
RouterModule, | ||
StoragePathPipe, | ||
], | ||
templateUrl: './resource-collections.component.html', | ||
styleUrl: './resource-collections.component.scss', | ||
}) | ||
export class ResourceCollectionsComponent implements OnInit { | ||
public collections: IMergedCollection[] = []; | ||
public tableOptions: IDataTableOptions = { | ||
displayColumns: DISPLAY_COLUMNS, | ||
formatHeader: (v) => { | ||
switch (v as keyof IMergedCollection) { | ||
case 'resource_collections': | ||
return 'Child Collections'; | ||
case 'resource_files': | ||
return 'Files'; | ||
case 'resource_links': | ||
return 'Links'; | ||
case 'collection_parent': | ||
return 'Parent Collection'; | ||
default: | ||
return formatHeaderDefault(v); | ||
} | ||
}, | ||
}; | ||
|
||
constructor(private service: ResourcesDashboardService) { | ||
effect(() => { | ||
const collectionsHashmap = this.service.collectionsById(); | ||
const collections = service.collections().map((c) => this.mergeCollectionData(c, collectionsHashmap)); | ||
this.collections = collections.sort(this.sortCollections); | ||
}); | ||
} | ||
async ngOnInit() { | ||
await this.service.ready(); | ||
} | ||
|
||
private mergeCollectionData( | ||
collection: IResourceCollectionRow, | ||
collectionsHashmap: Record<string, IResourceCollectionRow> | ||
): IMergedCollection { | ||
return { | ||
...collection, | ||
collection_parent: collectionsHashmap[collection.collection_parent || ''], | ||
}; | ||
} | ||
|
||
/** Sort collections first by name of parent (root collections first), then by modified date */ | ||
private sortCollections(a: IMergedCollection, b: IMergedCollection) { | ||
if (a.collection_parent === b.collection_parent) { | ||
return b.modified_at > a.modified_at ? 1 : -1; | ||
} | ||
return (b.collection_parent || '') > (a.collection_parent || '') ? -1 : 1; | ||
} | ||
|
||
private getCollectionTree(collections: IResourceCollectionRow[]) { | ||
const nodes = {}; | ||
|
||
const children = {}; | ||
for (const { collection_parent } of collections) { | ||
if (collection_parent) { | ||
if (!children[collection_parent]) children[collection_parent] = []; | ||
children[collection_parent].push(collections); | ||
} | ||
} | ||
} | ||
} |
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.