Skip to content

Commit

Permalink
Merge pull request #89 from cobbler/implement-settings
Browse files Browse the repository at this point in the history
Cobbler-Frontend: Implement Settings CRUD
  • Loading branch information
SchoolGuy authored Jun 28, 2022
2 parents 71b7643 + aef2894 commit 7d3f0c9
Show file tree
Hide file tree
Showing 31 changed files with 639 additions and 361 deletions.
14 changes: 11 additions & 3 deletions projects/cobbler-api/src/lib/cobbler-api.service.spec.ts

Large diffs are not rendered by default.

44 changes: 35 additions & 9 deletions projects/cobbler-api/src/lib/cobbler-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class CobblerApiService {
background_syncsystems(options: SyncSystemsOptions, token: string): Observable<string> {
const transformedOptions: XmlRpcStruct = {
members: [
{name: 'systems', value: { data: options.systems }},
{name: 'systems', value: {data: options.systems}},
{name: 'verbose', value: options.verbose},
]
}
Expand Down Expand Up @@ -245,7 +245,7 @@ export class CobblerApiService {
background_reposync(options: BackgroundReposyncOptions, token: string): Observable<string> {
const transformedOptions: XmlRpcStruct = {
members: [
{name: 'repos', value: { data: options.repos }},
{name: 'repos', value: {data: options.repos}},
{name: 'only', value: options.only},
{name: 'nofail', value: options.nofail},
{name: 'tries', value: options.tries},
Expand All @@ -268,7 +268,7 @@ export class CobblerApiService {
background_power_system(options: BackgroundPowerSystem, token: string): Observable<string> {
const transformedOptions: XmlRpcStruct = {
members: [
{name: 'systems', value: { data: options.systems }},
{name: 'systems', value: {data: options.systems}},
{name: 'power', value: options.power},
]
}
Expand Down Expand Up @@ -2050,18 +2050,44 @@ export class CobblerApiService {
);
}

private convertXmlRpcStructToTypeScriptObject(inputStruct: XmlRpcStruct): object {
const result_object = {}
inputStruct.members.forEach((member) => {
let value;
if (AngularXmlrpcService.instanceOfXmlRpcArray(member.value)) {
value = this.convertXmlRpcArrayToTypeScriptArray(member.value);
} else if (AngularXmlrpcService.instanceOfXmlRpcStruct(member.value)) {
value = this.convertXmlRpcStructToTypeScriptObject(member.value);
} else {
value = member.value;
}
result_object[member.name] = value;
})
return result_object;
}

private convertXmlRpcArrayToTypeScriptArray(inputArray: XmlRpcArray): Array<any> {
const resultArray = []
inputArray.data.forEach((value) => {
if (AngularXmlrpcService.instanceOfXmlRpcArray(value)) {
resultArray.push(this.convertXmlRpcArrayToTypeScriptArray(value));
} else if (AngularXmlrpcService.instanceOfXmlRpcStruct(value)) {
resultArray.push(this.convertXmlRpcStructToTypeScriptObject(value));
} else {
resultArray.push(value);
}
})
return resultArray;
}

get_settings(token: string): Observable<Settings> {
return this.client
.methodCall('get_settings', [token])
.pipe(
map<MethodResponse | MethodFault, Settings>((data: MethodResponse | MethodFault) => {
if (AngularXmlrpcService.instanceOfMethodResponse(data)) {
const return_value = {}
if (AngularXmlrpcService.instanceOfXmlRpcStruct(data.value)) {
data.value.members.forEach((value) => {
return_value[value.name] = value.value
});
return return_value as Settings;
return this.convertXmlRpcStructToTypeScriptObject(data.value) as Settings;
}
throw new Error('The return value of the settings was not in the expected format of an XML-RPC Struct!')
} else if (AngularXmlrpcService.instanceOfMethodFault(data)) {
Expand Down Expand Up @@ -2211,7 +2237,7 @@ export class CobblerApiService {
register_new_system(info: RegisterOptions): Observable<boolean> {
const transformedOptions: XmlRpcStruct = {
members: [
{name: 'name', value: info.name },
{name: 'name', value: info.name},
{name: 'profile', value: info.profile},
{name: 'hostname', value: info.hostname},
{name: 'interfaces', value: info.interfaces as XmlRpcStruct},
Expand Down
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.

This file was deleted.

31 changes: 3 additions & 28 deletions projects/cobbler-frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,13 @@
import {Component, OnInit} from '@angular/core';

import {CobblerApiService} from 'cobbler-api';
import {UserService} from './services/user.service';
import {Component} from '@angular/core';


@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
providers: [
CobblerApiService,
{provide: 'COBBLER_URL', useFactory: () => {
const value = localStorage.getItem("COBBLER_URL")
if (value) {
return new URL(value);
}
return new URL("http://localhost/cobbler_api")
}},
UserService
]
providers: []
})
export class AppComponent implements OnInit {
userStatus = {
loggedin: false,
};

export class AppComponent {
constructor() {
}

ngOnInit(): void {
const is_user_logged_in = window.sessionStorage.getItem('loggedIn');
if (is_user_logged_in) {
this.userStatus.loggedin = (is_user_logged_in === 'true');
window.localStorage.userStatus = this.userStatus;
}
}
}
Loading

0 comments on commit 7d3f0c9

Please sign in to comment.