-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor config-table into its own component
- Loading branch information
1 parent
887e585
commit abb40fc
Showing
11 changed files
with
252 additions
and
187 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...administration/pages/config-administration-page/config-administration-page.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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { FormlyFieldConfig } from '@ngx-formly/core'; | ||
import { Icon } from 'src/design/atoms/_models/icon'; | ||
|
||
export interface ConfigTable<T extends object> { | ||
name: string; | ||
kind: ConfigTableKind; | ||
entries?: T[]; | ||
icon: Icon; | ||
model: Partial<T>; | ||
formFields: FormlyFieldConfig[]; | ||
showForm: boolean; | ||
idProp: keyof T; | ||
} | ||
|
||
export const CONFIG_TABLE_KINDS = [ | ||
'MARKER_TYPE', | ||
'PLAYER_CLASS', | ||
'NODE_LINK_TYPE', | ||
] as const; | ||
export type ConfigTableKind = (typeof CONFIG_TABLE_KINDS)[number]; | ||
|
||
export type ConfigTableData = { | ||
[key in ConfigTableKind]?: any[] | undefined; | ||
}; |
98 changes: 98 additions & 0 deletions
98
src/design/organisms/config-table/config-table.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,98 @@ | ||
<div class="config-tables__section section"> | ||
<!-- Section Heading --> | ||
<div class="section__heading heading"> | ||
<h3 class="heading__text"> | ||
<app-icon [icon]="table().icon"></app-icon> | ||
{{ table().name }} | ||
</h3> | ||
|
||
<!-- Heading Buttons --> | ||
<div class="heading__buttons"> | ||
<!-- Add Users --> | ||
<button | ||
btn | ||
[kind]="'DARK'" | ||
[icon]="table().showForm ? 'times' : 'plus'" | ||
[text]=" | ||
table().showForm | ||
? 'Cancel ' + table().name + ' creation' | ||
: 'Add ' + table().name | ||
" | ||
(click)="table().showForm = !table().showForm" | ||
></button> | ||
|
||
<button | ||
btn | ||
[kind]="'PRIMARY'" | ||
[icon]="'refresh'" | ||
[text]="'Load table data'" | ||
(click)="loadTableEntries.emit()" | ||
></button> | ||
</div> | ||
</div> | ||
|
||
<app-separator class="section__separator"></app-separator> | ||
|
||
<!-- Section Body --> | ||
|
||
@if (!table().showForm) { | ||
@if (table().entries?.length === 0) { | ||
Load entries to see them | ||
} | ||
<div class="section__table-container"> | ||
<!-- Table --> | ||
|
||
@let entries = table().entries; | ||
@if (entries && entries.length > 0) { | ||
<table class="table table-dark table-striped"> | ||
<!-- Table heading --> | ||
<thead> | ||
<tr> | ||
<th scope="col">#</th> | ||
@for (property of entries[0] | keyvalue; track property.key) { | ||
<th scope="col" class="text-uppercase"> | ||
{{ property.key }} | ||
</th> | ||
} | ||
</tr> | ||
</thead> | ||
<!-- Table body --> | ||
<tbody> | ||
@for (entry of entries; track entry[table().idProp]) { | ||
<tr> | ||
<th scope="row">{{ entry[table().idProp] }}</th> | ||
@for (property of entry | keyvalue; track property.key) { | ||
<td> | ||
{{ property.value }} | ||
</td> | ||
} | ||
<td> | ||
<app-confirmation-toggle-button | ||
[toggleSize]="'SMALL'" | ||
[confirmationQuestion]="'Delete this Entry?'" | ||
[icon]="'trash'" | ||
(confirm)="deleteTableEntry.emit(entry)" | ||
></app-confirmation-toggle-button> | ||
</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
} | ||
</div> | ||
} | ||
|
||
@if (table().showForm) { | ||
<app-card> | ||
<h4>Adding new {{ table().name }}</h4> | ||
<!-- Form --> | ||
<app-form | ||
[model]="table().model" | ||
[fields]="table().formFields" | ||
[cancelButtonType]="'DARK'" | ||
(formlySubmit)="createEntry($event)" | ||
(formlyCancel)="table().showForm = !table().showForm" | ||
></app-form> | ||
</app-card> | ||
} | ||
</div> |
37 changes: 37 additions & 0 deletions
37
src/design/organisms/config-table/config-table.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,37 @@ | ||
.config-tables { | ||
&__return-button { | ||
} | ||
|
||
&__section { | ||
margin-top: var(--spacer-3); | ||
margin-bottom: var(--spacer-5); | ||
} | ||
} | ||
|
||
.section { | ||
&__separator { | ||
--separator-margin-top: var(--spacer-0); | ||
} | ||
|
||
&__heading { | ||
} | ||
|
||
&__table-container { | ||
overflow-x: auto; | ||
} | ||
} | ||
|
||
.heading { | ||
display: flex; | ||
justify-content: space-between; | ||
|
||
&__text { | ||
margin-bottom: var(--spacer-0); | ||
} | ||
|
||
&__buttons { | ||
align-self: flex-end; | ||
position: relative; | ||
top: 1px; | ||
} | ||
} |
14 changes: 7 additions & 7 deletions
14
...ig-tables/config-tables.component.spec.ts → ...nfig-table/config-table.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
42 changes: 42 additions & 0 deletions
42
src/design/organisms/config-table/config-table.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,42 @@ | ||
import { KeyValuePipe } from '@angular/common'; | ||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
input, | ||
output, | ||
} from '@angular/core'; | ||
import { ButtonComponent } from 'src/design/atoms/button/button.component'; | ||
import { CardComponent } from '../../atoms/card/card.component'; | ||
import { IconComponent } from '../../atoms/icon/icon.component'; | ||
import { SeparatorComponent } from '../../atoms/separator/separator.component'; | ||
import { ConfirmationToggleButtonComponent } from '../../molecules/confirmation-toggle-button/confirmation-toggle-button.component'; | ||
import { FormComponent } from '../../molecules/form/form.component'; | ||
import { ConfigTable } from '../_model/config-table'; | ||
|
||
@Component({ | ||
selector: 'app-config-table', | ||
standalone: true, | ||
imports: [ | ||
IconComponent, | ||
SeparatorComponent, | ||
ConfirmationToggleButtonComponent, | ||
FormComponent, | ||
CardComponent, | ||
ButtonComponent, | ||
KeyValuePipe, | ||
], | ||
templateUrl: './config-table.component.html', | ||
styleUrl: './config-table.component.scss', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class ConfigTableComponent<T extends object> { | ||
table = input.required<ConfigTable<T>>(); | ||
|
||
loadTableEntries = output<void>(); | ||
deleteTableEntry = output<T>(); | ||
createTableEntry = output<T>(); | ||
|
||
createEntry(entry: Partial<T>): void { | ||
this.createTableEntry.emit(entry as T); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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.