-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cobbler-Frontend: Refactor Settings page
- Loading branch information
Showing
22 changed files
with
392 additions
and
129 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
24 changes: 0 additions & 24 deletions
24
projects/cobbler-frontend/src/app/app-settings/app-settings.component.html
This file was deleted.
Oops, something went wrong.
66 changes: 0 additions & 66 deletions
66
projects/cobbler-frontend/src/app/app-settings/app-settings.component.spec.js
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
projects/cobbler-frontend/src/app/app-settings/app-settings.component.spec.js.map
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
projects/cobbler-frontend/src/app/app-settings/app-settings.component.ts
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
2 changes: 2 additions & 0 deletions
2
projects/cobbler-frontend/src/app/common/editable-tree/editable-tree.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,2 @@ | ||
<mat-tree> | ||
</mat-tree> |
File renamed without changes.
25 changes: 25 additions & 0 deletions
25
projects/cobbler-frontend/src/app/common/editable-tree/editable-tree.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,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { EditableTreeComponent } from './editable-tree.component'; | ||
|
||
describe('EditableTreeComponent', () => { | ||
let component: EditableTreeComponent; | ||
let fixture: ComponentFixture<EditableTreeComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ EditableTreeComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(EditableTreeComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
projects/cobbler-frontend/src/app/common/editable-tree/editable-tree.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,12 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-editable-tree', | ||
templateUrl: './editable-tree.component.html', | ||
styleUrls: ['./editable-tree.component.scss'] | ||
}) | ||
export class EditableTreeComponent { | ||
|
||
constructor() { } | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
projects/cobbler-frontend/src/app/common/viewable-tree/viewable-tree.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,26 @@ | ||
<mat-tree | ||
[dataSource]="dataSource" | ||
[treeControl]="viewableTreeControl" | ||
*ngIf="inputLength(inputObject) > 0"> | ||
<!-- This is the tree node template for leaf nodes --> | ||
<mat-tree-node *matTreeNodeDef="let node" matTreeNodePadding> | ||
<!-- use a disabled button to provide padding for tree leaf --> | ||
<button mat-icon-button disabled></button> | ||
{{node.name}}: {{node.value}} | ||
</mat-tree-node> | ||
<!-- This is the tree node template for expandable nodes --> | ||
<mat-tree-node *matTreeNodeDef="let node;when: hasChild" matTreeNodePadding> | ||
<button mat-icon-button matTreeNodeToggle | ||
[attr.aria-label]="'Toggle ' + node.name"> | ||
<mat-icon class="mat-icon-rtl-mirror"> | ||
{{viewableTreeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}} | ||
</mat-icon> | ||
</button> | ||
{{node.name}} | ||
</mat-tree-node> | ||
</mat-tree> | ||
<span | ||
*ngIf="inputLength(inputObject) === 0" | ||
class="settings-values"> | ||
{ } | ||
</span> |
Empty file.
25 changes: 25 additions & 0 deletions
25
projects/cobbler-frontend/src/app/common/viewable-tree/viewable-tree.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,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ViewableTreeComponent } from './viewable-tree.component'; | ||
|
||
describe('ViewableTreeComponent', () => { | ||
let component: ViewableTreeComponent; | ||
let fixture: ComponentFixture<ViewableTreeComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ ViewableTreeComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ViewableTreeComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
77 changes: 77 additions & 0 deletions
77
projects/cobbler-frontend/src/app/common/viewable-tree/viewable-tree.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,77 @@ | ||
import {FlatTreeControl} from '@angular/cdk/tree'; | ||
import {Component, Input, OnInit} from '@angular/core'; | ||
import {MatTreeFlatDataSource, MatTreeFlattener} from '@angular/material/tree'; | ||
|
||
/** | ||
* Food data with nested structure. | ||
* Each node has a name and an optional list of children. | ||
*/ | ||
interface ObjectNode { | ||
name: string; | ||
value: any; | ||
children?: ObjectNode[]; | ||
} | ||
|
||
/** Flat node with expandable and level information */ | ||
interface ExampleFlatNode { | ||
expandable: boolean; | ||
name: string; | ||
level: number; | ||
} | ||
|
||
@Component({ | ||
selector: 'app-viewable-tree', | ||
templateUrl: './viewable-tree.component.html', | ||
styleUrls: ['./viewable-tree.component.scss'] | ||
}) | ||
export class ViewableTreeComponent implements OnInit { | ||
@Input() inputObject: object = {}; | ||
viewableTreeControl = new FlatTreeControl<ExampleFlatNode>( | ||
node => node.level, | ||
node => node.expandable | ||
); | ||
|
||
private _transformer = (node: ObjectNode, level: number) => { | ||
return { | ||
expandable: !!node.children && node.children.length > 0, | ||
name: node.name, | ||
value: node.value, | ||
level: level, | ||
}; | ||
}; | ||
|
||
treeFlattener = new MatTreeFlattener( | ||
this._transformer, | ||
node => node.level, | ||
node => node.expandable, | ||
node => node.children, | ||
); | ||
|
||
dataSource = new MatTreeFlatDataSource(this.viewableTreeControl, this.treeFlattener); | ||
|
||
hasChild = (_: number, node: ExampleFlatNode) => node.expandable; | ||
|
||
constructor() { | ||
} | ||
|
||
inputLength(inputObject: object): number { | ||
return Object.keys(inputObject).length; | ||
} | ||
|
||
private transformObject(inputObject: object): ObjectNode[] { | ||
const resultStructure = []; | ||
let children = []; | ||
Object.keys(inputObject).forEach((key) => { | ||
if (!Array.isArray(inputObject[key]) && typeof inputObject[key] === 'object') { | ||
children = this.transformObject(inputObject[key]); | ||
} | ||
resultStructure.push({name: key, value: inputObject[key], children: children}); | ||
}) | ||
return resultStructure; | ||
} | ||
|
||
ngOnInit(): void { | ||
this.dataSource.data = this.transformObject(this.inputObject); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
projects/cobbler-frontend/src/app/settings/edit/settings-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,16 @@ | ||
<div [hidden]="true"> | ||
<!-- Edit - Text --> | ||
<input matInput> | ||
|
||
<!-- Edit - Number --> | ||
<input matInput> | ||
|
||
<!-- Edit - Bool --> | ||
<mat-radio-group aria-label="Select an option"> | ||
<mat-radio-button value="true">true</mat-radio-button> | ||
<mat-radio-button value="false">false</mat-radio-button> | ||
</mat-radio-group> | ||
|
||
<!-- Edit - Object --> | ||
<app-editable-tree></app-editable-tree> | ||
</div> |
Empty file.
Oops, something went wrong.