-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Admin UI): basic prototype to manage entity types (#2440)
see #2270 [prototype for internal use only]
- Loading branch information
Showing
9 changed files
with
280 additions
and
5 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
39 changes: 39 additions & 0 deletions
39
src/app/core/admin/admin-entity-types/admin-entity-types.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,39 @@ | ||
<p style="color: red"> | ||
This is an internal server admin preview and not stable functionality yet. | ||
</p> | ||
|
||
<div class="flex-row gap-regular"> | ||
<button mat-raised-button color="accent" (click)="create()"> | ||
Add New Entity Type | ||
</button> | ||
|
||
<button mat-stroked-button color="accent" (click)="loadEntityTypes(false)"> | ||
Also load internal types | ||
</button> | ||
</div> | ||
|
||
<table mat-table [dataSource]="entityTypes"> | ||
<ng-container matColumnDef="label"> | ||
<th mat-header-cell *matHeaderCellDef class="table-header">Entity Type</th> | ||
|
||
<td mat-cell *matCellDef="let row"> | ||
{{ row.label }} | ||
</td> | ||
</ng-container> | ||
|
||
<ng-container matColumnDef="icon"> | ||
<th mat-header-cell *matHeaderCellDef class="table-header">Icon</th> | ||
|
||
<td mat-cell *matCellDef="let row"> | ||
<fa-icon *ngIf="row.icon" [icon]="row.icon"></fa-icon> | ||
</td> | ||
</ng-container> | ||
|
||
<tr mat-header-row *matHeaderRowDef="columnsToDisplay"></tr> | ||
<tr | ||
mat-row | ||
*matRowDef="let row; columns: columnsToDisplay" | ||
[routerLink]="['/admin', 'entity', row.ENTITY_TYPE]" | ||
style="cursor: pointer" | ||
></tr> | ||
</table> |
4 changes: 4 additions & 0 deletions
4
src/app/core/admin/admin-entity-types/admin-entity-types.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,4 @@ | ||
.table-header { | ||
font-weight: bold; | ||
font-style: italic; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/app/core/admin/admin-entity-types/admin-entity-types.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,32 @@ | ||
import { ComponentFixture, TestBed } from "@angular/core/testing"; | ||
|
||
import { AdminEntityTypesComponent } from "./admin-entity-types.component"; | ||
import { | ||
entityRegistry, | ||
EntityRegistry, | ||
} from "../../entity/database-entity.decorator"; | ||
import { EntityMapperService } from "../../entity/entity-mapper/entity-mapper.service"; | ||
import { mockEntityMapper } from "../../entity/entity-mapper/mock-entity-mapper-service"; | ||
|
||
describe("AdminEntityTypesComponent", () => { | ||
let component: AdminEntityTypesComponent; | ||
let fixture: ComponentFixture<AdminEntityTypesComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [AdminEntityTypesComponent], | ||
providers: [ | ||
{ provide: EntityRegistry, useValue: entityRegistry }, | ||
{ provide: EntityMapperService, useValue: mockEntityMapper() }, | ||
], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(AdminEntityTypesComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it("should create", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
179 changes: 179 additions & 0 deletions
179
src/app/core/admin/admin-entity-types/admin-entity-types.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,179 @@ | ||
import { Component, OnInit } from "@angular/core"; | ||
import { EntityRegistry } from "../../entity/database-entity.decorator"; | ||
import { | ||
MatCell, | ||
MatCellDef, | ||
MatColumnDef, | ||
MatHeaderCell, | ||
MatHeaderCellDef, | ||
MatHeaderRow, | ||
MatHeaderRowDef, | ||
MatRow, | ||
MatRowDef, | ||
MatTable, | ||
} from "@angular/material/table"; | ||
import { MatButton } from "@angular/material/button"; | ||
import { FaIconComponent } from "@fortawesome/angular-fontawesome"; | ||
import { NgIf } from "@angular/common"; | ||
import { EntityConstructor } from "../../entity/model/entity"; | ||
import { RouterLink } from "@angular/router"; | ||
import { generateIdFromLabel } from "../../../utils/generate-id-from-label/generate-id-from-label"; | ||
import { EntityMapperService } from "../../entity/entity-mapper/entity-mapper.service"; | ||
import { EntityConfig } from "../../entity/entity-config"; | ||
import { EntityDetailsConfig } from "../../entity-details/EntityDetailsConfig"; | ||
import { EntityListConfig } from "../../entity-list/EntityListConfig"; | ||
import { Config } from "../../config/config"; | ||
import { EntityConfigService } from "../../entity/entity-config.service"; | ||
import { DynamicComponentConfig } from "../../config/dynamic-components/dynamic-component-config.interface"; | ||
|
||
/** | ||
* Manage the configuration of all entity types. | ||
* Currently, this only serves as a utility for internal use, speeding up setup processes. | ||
* | ||
* TODO: This component is only a raw prototype! Needs further concept and implementation. | ||
*/ | ||
@Component({ | ||
selector: "app-admin-entity-types", | ||
standalone: true, | ||
imports: [ | ||
MatHeaderRow, | ||
MatHeaderRowDef, | ||
MatRow, | ||
MatRowDef, | ||
MatCell, | ||
MatHeaderCell, | ||
MatColumnDef, | ||
MatTable, | ||
MatButton, | ||
MatCellDef, | ||
MatHeaderCellDef, | ||
FaIconComponent, | ||
NgIf, | ||
RouterLink, | ||
], | ||
templateUrl: "./admin-entity-types.component.html", | ||
styleUrl: "./admin-entity-types.component.scss", | ||
}) | ||
export class AdminEntityTypesComponent implements OnInit { | ||
entityTypes: EntityConstructor[] = []; | ||
columnsToDisplay: string[] = ["label", "icon"]; | ||
|
||
constructor( | ||
private entities: EntityRegistry, | ||
private entityMapper: EntityMapperService, | ||
) {} | ||
|
||
ngOnInit() { | ||
this.loadEntityTypes(); | ||
} | ||
|
||
protected loadEntityTypes(onlyUserFacing = true) { | ||
this.entityTypes = this.entities | ||
.getEntityTypes(onlyUserFacing) | ||
.map((e) => e.value); | ||
} | ||
|
||
async create() { | ||
const name = prompt("Please enter entity type name:"); | ||
if (!name) { | ||
return; | ||
} | ||
const id = generateIdFromLabel(name); | ||
if (this.entityTypeExists(id)) { | ||
alert("Entity type already exists."); | ||
return; | ||
} | ||
|
||
// save default entity schema | ||
await this.saveDefaultEntityConfig( | ||
id, | ||
this.getDefaultEntityConfig(id, name), | ||
this.getDefaultDetailsViewConfig(id), | ||
this.getDefaultListViewConfig(id), | ||
); | ||
} | ||
|
||
private entityTypeExists(id: string) { | ||
return Array.from(this.entities.keys()).some( | ||
(key) => key.toLowerCase() === id.toLowerCase(), | ||
); | ||
} | ||
|
||
private async saveDefaultEntityConfig( | ||
id: string, | ||
entityConfig: EntityConfig, | ||
detailsViewConfig: DynamicComponentConfig, | ||
listViewConfig: DynamicComponentConfig, | ||
) { | ||
const originalConfig = await this.entityMapper.load( | ||
Config, | ||
Config.CONFIG_KEY, | ||
); | ||
const newConfig = originalConfig.copy(); | ||
|
||
newConfig.data[EntityConfigService.PREFIX_ENTITY_CONFIG + id] = | ||
entityConfig; | ||
newConfig.data[EntityConfigService.getDetailsViewId(entityConfig)] = | ||
detailsViewConfig; | ||
newConfig.data[EntityConfigService.getListViewId(entityConfig)] = | ||
listViewConfig; | ||
|
||
await this.entityMapper.save(newConfig); | ||
} | ||
|
||
private getDefaultEntityConfig( | ||
entityTypeId: string, | ||
name: string, | ||
): EntityConfig { | ||
return { | ||
label: name, | ||
route: entityTypeId, | ||
}; | ||
} | ||
|
||
private getDefaultDetailsViewConfig( | ||
entityType: string, | ||
): DynamicComponentConfig<EntityDetailsConfig> { | ||
return { | ||
component: "EntityDetails", | ||
config: { | ||
entityType: entityType, | ||
panels: [ | ||
{ | ||
title: "Basic Information", | ||
components: [ | ||
{ | ||
title: "", | ||
component: "Form", | ||
config: { | ||
fieldGroups: [{ fields: [] }], | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}; | ||
} | ||
|
||
private getDefaultListViewConfig( | ||
entityType: string, | ||
): DynamicComponentConfig<EntityListConfig> { | ||
return { | ||
component: "EntityList", | ||
config: { | ||
entityType: entityType, | ||
columnGroups: { | ||
default: "Overview", | ||
mobile: "Overview", | ||
groups: [ | ||
{ | ||
name: "Overview", | ||
columns: [], | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
} | ||
} |
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