Skip to content

Commit

Permalink
add ids to prevent duplicates on name edit (#163)
Browse files Browse the repository at this point in the history
Co-authored-by: Philip Prinz <Philip.Prinz@sva.de>
  • Loading branch information
PhPrinz and Philip Prinz authored Mar 24, 2023
1 parent 5b67438 commit 3651183
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ServerResponse } from 'src/app/data/serverresponse';
import { vmServiceToJSON } from 'src/app/data/vm-template-service-configuration';
import { VMTemplate } from 'src/app/data/vmtemplate';
import { VmtemplateService } from 'src/app/data/vmtemplate.service';
import * as uuid from 'uuid'

@Component({
selector: 'edit-vmtemplate-wizard',
Expand Down Expand Up @@ -87,7 +88,8 @@ export class EditVmtemplateComponent implements OnInit, OnChanges {
let resultMap = new Map()
temp.forEach(entry => {
entry.cloudConfigMap = new Map(Object.entries(entry["cloudConfigMap"])); // Convert Object to map
resultMap.set(entry['name'], entry)
entry['id'] = entry['id'] ?? uuid.v4() //Catch old entries, that do not have an ID
resultMap.set(entry['id'], entry)
})
return resultMap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
getCloudConfigString,
VMTemplateServiceConfiguration,
} from 'src/app/data/vm-template-service-configuration';
import * as uuid from 'uuid'

@Component({
selector: 'app-vmtemplate-service-form',
Expand Down Expand Up @@ -76,6 +77,7 @@ export class VMTemplateServiceFormComponent implements OnInit {
newVMServiceClose() {
let newVMService: VMTemplateServiceConfiguration =
new VMTemplateServiceConfiguration();
newVMService.id = this.editVMService?.id ?? uuid.v4()
newVMService.name = this.newVMServiceFormGroup.get('name').value;
newVMService.hasWebinterface =
this.newVMServiceFormGroup.get('hasWebinterface').value;
Expand Down Expand Up @@ -124,6 +126,7 @@ export const PredefinedWebInterfaces: VMTemplateServiceConfiguration[] =
//This has to be modeled into a CRD and retrieved over the Backend
[
{
id: uuid.v4(),
name: 'VS Code IDE',
port: 8080,
path: '/?folder=/root',
Expand All @@ -141,6 +144,7 @@ export const PredefinedWebInterfaces: VMTemplateServiceConfiguration[] =
`,
},
{
id: uuid.v4(),
name: 'Test-Service without Webinterface',
cloudConfigMap: new Map(),
hasWebinterface: false,
Expand All @@ -150,6 +154,7 @@ export const PredefinedWebInterfaces: VMTemplateServiceConfiguration[] =
`,
},
{
id: uuid.v4(),
name: 'Test-Interface without Cloud Config',
port: 8081,
hasOwnTab: false,
Expand Down
6 changes: 3 additions & 3 deletions src/app/data/cloud-init-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export class CloudInitConfig {
}


removeVMService(name: string) {
this.vmServices.delete(name)
removeVMService(id: string) {
this.vmServices.delete(id)
this.buildNewYAMLFile()
}

addVMService(newInterface: VMTemplateServiceConfiguration) {
this.vmServices.set(newInterface.name, newInterface)
this.vmServices.set(newInterface.id, newInterface)
this.buildNewYAMLFile()
}

Expand Down
5 changes: 4 additions & 1 deletion src/app/data/vm-template-service-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import YAML from 'yaml';
import * as uuid from 'uuid'
export class VMTemplateServiceConfiguration {
public id: string;
public name: string;
public hasWebinterface;
public port?: number;
Expand All @@ -24,6 +26,7 @@ export class VMTemplateServiceConfiguration {
disallowIFrame: boolean = false,
cloudConfigString: string = ''
) {
this.id = uuid.v4()
this.name = name;
this.hasWebinterface = hasWebinterface;
this.port = port;
Expand Down Expand Up @@ -56,7 +59,7 @@ export function getCloudConfigString(

export function vmServiceToJSON(vmService: VMTemplateServiceConfiguration) {
let result =
'{"name": "' +
'{"id" : "' + vmService.id + '" , "name": "' +
vmService.name +
'" ,"hasWebinterface": ' +
vmService.hasWebinterface;
Expand Down

0 comments on commit 3651183

Please sign in to comment.