Skip to content

Commit

Permalink
Cobbler-Frontend: Refactor Settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
SchoolGuy committed Jun 28, 2022
1 parent a9de130 commit 4732226
Show file tree
Hide file tree
Showing 22 changed files with 392 additions and 129 deletions.
4 changes: 2 additions & 2 deletions projects/cobbler-frontend/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {ImagesComponent} from './items/images/images.component';
import {TemplatesComponent} from './items/templates/templates.component';
import {SnippetsComponent} from './items/snippets/snippets.component';
import {ManagementClassesComponent} from './items/management-classes/management-classes.component';
import {AppSettingsComponent} from './app-settings/app-settings.component';
import {SettingsViewComponent} from './settings/view/settings-view.component';
import {PackagesComponent} from './items/packages/packages.component';
import {FilesComponent} from './items/files/files.component';
import {ImportDVDComponent} from './actions/import-dvd/import-dvd.component';
Expand Down Expand Up @@ -38,7 +38,7 @@ const routes: Routes = [
{path: 'templates', component: TemplatesComponent, canActivate: [AuthGuardService]},
{path: 'snippets', component: SnippetsComponent, canActivate: [AuthGuardService]},
{path: 'management-classes', component: ManagementClassesComponent, canActivate: [AuthGuardService]},
{path: 'settings', component: AppSettingsComponent, canActivate: [AuthGuardService]},
{path: 'settings', component: SettingsViewComponent, canActivate: [AuthGuardService]},
{path: 'packages', component: PackagesComponent, canActivate: [AuthGuardService]},
{path: 'app-files', component: FilesComponent, canActivate: [AuthGuardService]},
{path: 'import', component: ImportDVDComponent, canActivate: [AuthGuardService]},
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

20 changes: 18 additions & 2 deletions projects/cobbler-frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ import {MatButtonModule} from '@angular/material/button';
import {MatFormFieldModule} from '@angular/material/form-field';
import {MatIconModule} from '@angular/material/icon';
import {MatInputModule} from '@angular/material/input';
import {MatPaginatorModule} from '@angular/material/paginator';
import {MatRadioModule} from '@angular/material/radio';
import {MatSidenavModule} from '@angular/material/sidenav';
import {MatSlideToggleModule} from '@angular/material/slide-toggle';
import {MatSnackBarModule} from '@angular/material/snack-bar';
import {MatTableModule} from '@angular/material/table';
import {MatTabsModule} from '@angular/material/tabs';
import {MatToolbarModule} from '@angular/material/toolbar';
import {MatTooltipModule} from '@angular/material/tooltip';
import {MatTreeModule} from '@angular/material/tree';
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
Expand All @@ -26,7 +31,7 @@ import {ImagesComponent} from './items/images/images.component';
import {TemplatesComponent} from './items/templates/templates.component';
import {SnippetsComponent} from './items/snippets/snippets.component';
import {ManagementClassesComponent} from './items/management-classes/management-classes.component';
import {AppSettingsComponent} from './app-settings/app-settings.component';
import {SettingsViewComponent} from './settings/view/settings-view.component';
import {PackagesComponent} from './items/packages/packages.component';
import {FilesComponent} from './items/files/files.component';
import {ImportDVDComponent} from './actions/import-dvd/import-dvd.component';
Expand All @@ -43,6 +48,9 @@ import {NavbarComponent} from './navbar/navbar.component';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {LayoutModule} from '@angular/cdk/layout';
import {MatListModule} from '@angular/material/list';
import { EditableTreeComponent } from './common/editable-tree/editable-tree.component';
import { ViewableTreeComponent } from './common/viewable-tree/viewable-tree.component';
import { SettingsEditComponent } from './settings/edit/settings-edit.component';

@NgModule({
declarations: [
Expand All @@ -57,7 +65,7 @@ import {MatListModule} from '@angular/material/list';
TemplatesComponent,
SnippetsComponent,
ManagementClassesComponent,
AppSettingsComponent,
SettingsViewComponent,
DistrosComponent,
ProfilesComponent,
SystemsComponent,
Expand All @@ -75,6 +83,9 @@ import {MatListModule} from '@angular/material/list';
NotFoundComponent,
ManageMenuComponent,
NavbarComponent,
EditableTreeComponent,
ViewableTreeComponent,
SettingsEditComponent,
],
imports: [
BrowserModule,
Expand All @@ -96,6 +107,11 @@ import {MatListModule} from '@angular/material/list';
MatTableModule,
MatTabsModule,
MatSnackBarModule,
MatRadioModule,
MatTreeModule,
MatTooltipModule,
MatSlideToggleModule,
MatPaginatorModule,
],
providers: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<mat-tree>
</mat-tree>
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();
});
});
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() { }

}
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">
&#123;&nbsp;&#125;
</span>
Empty file.
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();
});
});
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);
}

}
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.
Loading

0 comments on commit 4732226

Please sign in to comment.