Commit 26f1402f authored by Venkat's avatar Venkat
Browse files

added the delete host call and pulling actual record types

parent d2da4a91
......@@ -37,6 +37,9 @@ export class AppComponent {
selectedRow: PostUIObject = {};
selectedCell: string = '';
AvailableRecordTypes: String[] = []
AvailabeRecords: Records[] = []
AllRecordList: Records[] =[]
hostRecords: Records[] = []
new_record: Records = {
......@@ -84,7 +87,13 @@ export class AppComponent {
this.sampleService.GetRecords()
.toPromise()
.then((res) => {
let records = res.find(x => x.host.id == row['host_id']);
res.forEach(element => {
if(this.AvailableRecordTypes.indexOf(element.record_type) < 0){
this.AvailableRecordTypes.push(element.record_type);
this.AvailabeRecords.push(element);
}
});
let records = res.find(x => x.host == row['host_id']);
if(records){
this.AllRecordList.push(records);
}
......@@ -108,7 +117,7 @@ export class AppComponent {
.toPromise()
.then((res) => {
res.forEach(x => {
let item = new IPResultSet(x.id != null ? x.id : null , x.ipv4, x.ipv6, x.mac_addr != null ? x.mac_addr.adapter.host.host_name: null, x.mac_addr != null ? x.mac_addr.id : null, x.mac_addr != null ? x.mac_addr.mac : null, x.mac_addr !== null ? x.mac_addr.adapter.id : null, x.mac_addr!== null ? x.mac_addr.adapter.adapter_name : null, x.subnet !== null ? x.subnet.id : null, x.subnet !== null ? x.subnet.subnet_name : null, null, x.mac_addr !== null ? x.mac_addr.adapter.host.id : null, null);
let item = new IPResultSet(x.id != null ? x.id : null , x.ipv4, x.ipv6, x.mac_addr != null ? x.mac_addr.adapter.host.host_name: null, x.mac_addr != null ? x.mac_addr.id : null, x.mac_addr != null ? x.mac_addr.mac : null, x.mac_addr !== null ? x.mac_addr.adapter.id : null, x.mac_addr!== null ? x.mac_addr.adapter.adapter_name : null, x.subnet !== null ? x.subnet.id : null, x.subnet !== null ? x.subnet.subnet_name : null, null, x.mac_addr !== null ? x.mac_addr.adapter.host.id : null, null, this.AvailableRecords);
this.ipResultSet.push(item)
})
this.dataSource = this.ipResultSet;
......@@ -139,7 +148,7 @@ export class AppComponent {
})
}
PutInformation(host_name, ipv4?, ipv6?, mac_address?, adapter_name?): void {
PutInformation(host_name, ipv4?, ipv6?, mac_address?, adapter_name?, record_type?): void {
if(this.currentRecordData.host_name !== host_name){
let host_id = this.ipResultSet.find(x => x.host == this.currentRecordData.host_name).host_id
this.sampleService.UpdateHost(host_id, host_name)
......@@ -148,9 +157,18 @@ export class AppComponent {
console.log('host name updated');
})
}
if(record_type !== null){
let host_id = this.ipResultSet.find(x => x.host == this.currentRecordData.host_name).host_id
this.sampleService.AddRecord(host_id, record_type)
.toPromise()
.then((res) =>{
console.log('record added on update');
});
}
if(this.currentRecordData.mac_address !== mac_address){
let mac_id = this.ipResultSet.find(x => x.mac_addr === this.currentRecordData.mac_address).mac_id;
this.sampleService.PutMac(mac_id, mac_address).
let adapter_id = 2;
this.sampleService.PutMac(adapter_id, mac_id, mac_address).
toPromise()
.then((res) => {
console.log('mac address updated');
......@@ -201,15 +219,15 @@ export class AppComponent {
})
}
PostRecords(host_name, ipv4?, ipv6?, mac_address?, adapter_name?, subnet_name?): void {
PostRecords(host_name, ipv4?, ipv6?, mac_address?, adapter_name?, subnet_name?, record_type?): void {
this.sampleService.PostHosts(host_name)
.toPromise()
.then((res) => {
this.returned_record_id = res.id
this.sampleService.AddRecord(this.returned_record_id)
this.returned_host_id = res.id
this.sampleService.AddRecord(this.returned_host_id, record_type)
.toPromise()
.then((item) => {
this.sampleService.PostAdapters(this.returned_record_id, adapter_name)
this.sampleService.PostAdapters(this.returned_host_id, adapter_name)
.toPromise()
.then((item) => {
this.sampleService.PostMacs(item.id, mac_address)
......@@ -238,10 +256,12 @@ export class AppComponent {
this.currentRecordData.records = this.selectedRow['records'];
this.currentRecordData.record_type = this.selectedRow['record_type'];
this.currentRecordData.subnet_name = this.selectedRow['subnet_name'];
this.currentRecordData.record_type = this.selectedRow['record_type'];
this.currentRecordData.host_id = this.ipResultSet.find(x => x.host === this.selectedRow['host']).host_id;
const dialogRef = this.dialog.open(DialogOverviewComponent, {
width: '700px',
data: {ipv4: this.selectedRow['ipv4'], ipv6: this.selectedRow['ipv6'], host: this.selectedRow['host'], adapter: this.selectedRow['adapter'], mac: this.selectedRow['mac_addr'], records: this.AllRecordList, record_type: null, display: this.AllRecordList.length > 0 ? true: false}
data: {ipv4: this.selectedRow['ipv4'], ipv6: this.selectedRow['ipv6'], host: this.selectedRow['host'], adapter: this.selectedRow['adapter'], mac: this.selectedRow['mac_addr'], records: this.AllRecordList, record_type: this.currentRecordData.record_type, display: this.AllRecordList.length > 0 ? true: false, AvailableRecords: this.AvailabeRecords, host_id: this.currentRecordData.host_id }
});
......@@ -254,12 +274,13 @@ export class AppComponent {
this.postUIObject.mac_address = result.mac;
this.postUIObject.adapter_name = result.adapter;
this.postUIObject.subnet_name = this.currentRecordData.subnet_name;
this.postUIObject.record_type = result.record_type;
if(this.currentRecordData.mac_address != null){
this.PutInformation(this.postUIObject.host_name, this.postUIObject.ipv4, this.postUIObject.ipv6, this.postUIObject.mac_address, this.postUIObject.adapter_name);
this.PutInformation(this.postUIObject.host_name, this.postUIObject.ipv4, this.postUIObject.ipv6, this.postUIObject.mac_address, this.postUIObject.adapter_name, this.postUIObject.record_type);
}
else{
this.PostRecords(this.postUIObject.host_name, this.postUIObject.ipv4, this.postUIObject.ipv6, this.postUIObject.mac_address, this.postUIObject.adapter_name, this.postUIObject.subnet_name);
this.PostRecords(this.postUIObject.host_name, this.postUIObject.ipv4, this.postUIObject.ipv6, this.postUIObject.mac_address, this.postUIObject.adapter_name, this.postUIObject.subnet_name, this.postUIObject.record_type);
}
}
this.AllRecordList = [];
......@@ -333,6 +354,7 @@ export interface PostUIObject{
ip_id?: any;
ipv4?: string;
ipv6?: string;
host_id?: string;
host_name?: string;
mac_address?: string;
adapter_name?: string;
......@@ -356,10 +378,11 @@ export class IPResultSet{
subnet_name: any;
records: any;
host_id: any;
record_type: any
record_type: any;
AvailableRecords: any;
constructor(id, ipv4, ipv6, host, mac_id, mac_addr, adapter_id, adapter, subnet_id, subnet_name, records, host_Id, record_type){
constructor(id, ipv4, ipv6, host, mac_id, mac_addr, adapter_id, adapter, subnet_id, subnet_name, records, host_Id, record_type, allAvailableRecords){
this.ip_id = id;
this.ipv4 = ipv4;
this.ipv6 = ipv6;
......@@ -373,6 +396,7 @@ export class IPResultSet{
this.records = records;
this.host_id = host_Id;
this.record_type = record_type;
this.AvailableRecords = allAvailableRecords;
}
}
......@@ -14,3 +14,7 @@
height: 400px;
margin-left: 400px;
}
#floatLeft {
float: left;
}
......@@ -2,19 +2,22 @@
<div mat-dialog-content id="sidebar">
<p>Enter the data in the fields</p>
<mat-form-field>
<input matInput placeholder="IPV4" [(ngModel)]="data.ipv4">
<input matInput placeholder="IPV4" [(ngModel)]="data.ipv4">
</mat-form-field>
<mat-form-field>
<input matInput placeholder="IPV6" [(ngModel)]="data.ipv6">
</mat-form-field>
<mat-form-field>
<input matInput placeholder="Host" [(ngModel)]="data.host">
<input required matInput placeholder="Host" [(ngModel)]="data.host">
</mat-form-field>
<mat-form-field>
<input matInput placeholder="Adapter" [(ngModel)]="data.adapter">
<button *ngIf="data.host !== null" mat-button (click)="onDeleteClick()">Delete Host</button>
<mat-form-field>
<input required matInput placeholder="Adapter" [(ngModel)]="data.adapter">
</mat-form-field>
<mat-form-field>
<input matInput placeholder="Mac" [(ngModel)]="data.mac">
<input required matInput placeholder="Mac" [(ngModel)]="data.mac">
</mat-form-field>
</div>
......@@ -40,15 +43,15 @@
<mat-form-field>
<mat-label>Pick a Record Type</mat-label>
<mat-select [(ngModel)]="data.record_type">
<mat-option *ngFor="let record of data.records" [(value)]="record.record_type">
<mat-option *ngFor="let record of data.AvailableRecords" [(value)]="record.record_type">
{{record.record_type}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>
<div>
<div id="floatLeft">
<button mat-button (click)="onNoClick()">No, Thanks</button>
<button mat-button [mat-dialog-close]="data" cdkFocusInitial>Ok</button>
<button mat-button [mat-dialog-close]="data" cdkFocusInitial>Ok</button>
</div>
</div>
import { Component, OnInit, Inject} from '@angular/core';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
import { SampleService } from '../sample.service';
@Component({
......@@ -17,12 +18,25 @@ export class DialogOverviewComponent implements OnInit {
constructor(
public dialogRef: MatDialogRef<DialogOverviewComponent>,
private sampleService: SampleService,
@Inject(MAT_DIALOG_DATA) public data: DialogData) {}
onNoClick(): void {
this.dialogRef.close();
}
onDeleteClick(): void {
this.sampleService.DeleteHost(this.data.host_id)
.toPromise()
.then((res) => {
this.sampleService.ListAllIPs().
toPromise()
.then((res) => {
this.dialogRef.close();
})
});
}
toggleButton(): void{
this.showButton = true;
}
......@@ -34,11 +48,13 @@ export interface DialogData {
ipv4: string;
ipv6: string;
host: string;
host_id: any;
adapter: string;
mac: string;
records: Records[],
record_type: any,
display: boolean
display: boolean,
AvailableRecords: Records[];
}
export interface Records{
......
......@@ -78,10 +78,10 @@ export class SampleService {
constructor(private http: HttpClient) {
}
AddRecord(hostID): Observable<Records> {
AddRecord(hostID,record_type?): Observable<Records> {
// this.new_records.push(this.new_record)
this.record_insert.host = hostID
this.record_insert.record_type = 'A'
this.record_insert.record_type = record_type
return this.http.post<Records>(this.HostLocation + 'ipam/createrecord/', this.record_insert);
}
......@@ -174,9 +174,12 @@ export class SampleService {
return this.http.put<IPs>(this.HostLocation + this.endpoint, this.new_ip);
}
PutMac(mac_id, mac_address): Observable<any>{
PutMac(adapter_id, mac_id, mac_address): Observable<any>{
this.endpoint = 'ipam/updatemac/' + mac_id +'/';
this.new_mac.mac = mac_address;
this.new_mac.adapter.id = 2;
this.new_mac.adapter.adapter_name = 'eth0';
// this.new_mac.adapter.host =
return this.http.put<any>(this.HostLocation + this.endpoint, this.new_mac)
}
......
......@@ -9,7 +9,7 @@
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<mat-card>
<div class="alert alert-info">
<div align="center" class="alert alert-info">
<strong>IP Allocation Management System</strong>
</div>
</mat-card>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment