Commit d2da4a91 authored by Venkat's avatar Venkat
Browse files

added the code to make puts

parent 2198d162
......@@ -31,7 +31,7 @@ export class AppComponent {
mac: any;
ipResultSet: IPResultSet[] = [];
currentRecordData: PostUIObject = {};
postUIObject: PostUIObject = {};
selectedRow: PostUIObject = {};
......@@ -85,7 +85,7 @@ export class AppComponent {
.toPromise()
.then((res) => {
let records = res.find(x => x.host.id == row['host_id']);
if(records !== undefined || records !== null){
if(records){
this.AllRecordList.push(records);
}
......@@ -103,13 +103,12 @@ export class AppComponent {
})
}
getAllIps(): void{
getAllIps(): void{
this.sampleService.ListAllIPs()
.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.mac : null, x.mac_addr!== null && x.mac_addr.adapter !== null ? x.mac_addr.adapter.adapter_name : null, x.subnet !== null ? x.subnet.subnet_name : null, null, x.mac_addr !== null ? x.mac_addr.adapter.host.id : 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.ipResultSet.push(item)
})
this.dataSource = this.ipResultSet;
......@@ -123,17 +122,7 @@ export class AppComponent {
.then((res) => {
console.log("hi")
})
}
// PostHosts(recordID): any {
// this.sampleService.PostHosts()
// .toPromise()
// .then((res) => {
// //this.returned_host_id = res.id
// this.returned_host_id = res.id
// })
// //return this.returned_host_id
// }
}
PostAdapters(hostID, adapter_name): any {
this.sampleService.PostAdapters(hostID, adapter_name)
......@@ -150,6 +139,45 @@ export class AppComponent {
})
}
PutInformation(host_name, ipv4?, ipv6?, mac_address?, adapter_name?): 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)
.toPromise()
.then((res) => {
console.log('host name updated');
})
}
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).
toPromise()
.then((res) => {
console.log('mac address updated');
});
}
if(this.currentRecordData.adapter_name !== adapter_name){
let host_id = this.ipResultSet.find(x => x.host == this.currentRecordData.host_name).host_id
let adapter_id = this.ipResultSet.find(x => x.adapter === this.currentRecordData.adapter_name).adapter_id;
this.sampleService.UpdateAdapters(host_id, adapter_id, adapter_name)
.toPromise()
.then((res) => {
console.log('adapter name updated');
});
}
if(this.currentRecordData.ipv4 !== ipv4 || this.currentRecordData.ipv6 !== ipv6){
let mac_id = this.ipResultSet.find(x => x.mac_addr === this.currentRecordData.mac_address).mac_id;
let ip_id = this.ipResultSet.find(x => x.ipv4 === this.postUIObject.ipv4 || x.ipv4 === this.postUIObject.ipv6).ip_id
let subnet_id = this.ipResultSet.find(x => x.subnet_name === this.postUIObject.subnet_name).subnet_id;
this.sampleService.PutIP(mac_id, subnet_id, ip_id, ipv4, ipv6)
.toPromise()
.then((res) => {
console.log('IP name updated')
});
//this.getAllIps();
}
}
PutRecords(): void {
this.sampleService.PutRecord()
.toPromise()
......@@ -171,12 +199,9 @@ export class AppComponent {
.then((res) => {
console.log('updated mac')
})
}
// PostRecords(host_name, ipv4?, ipv6?, mac_address?, adapter_name?): void {
// this.UpdateMac(5, '1B:2A:3F:4E:5D')
// }
}
PostRecords(host_name, ipv4?, ipv6?, mac_address?, adapter_name?): void {
PostRecords(host_name, ipv4?, ipv6?, mac_address?, adapter_name?, subnet_name?): void {
this.sampleService.PostHosts(host_name)
.toPromise()
.then((res) => {
......@@ -191,8 +216,8 @@ export class AppComponent {
.toPromise()
.then((item) => {
let ip_id = this.ipResultSet.find(x => x.ipv4 === this.postUIObject.ipv4 || x.ipv4 === this.postUIObject.ipv6).ip_id
this.sampleService.PutIP(item.id, 1, ip_id, this.postUIObject.ipv4, this.postUIObject.ipv6)
let subnet_id = this.ipResultSet.find(x => x.subnet_name == this.postUIObject.subnet_name).subnet_id
this.sampleService.PutIP(item.id, subnet_id, ip_id, this.postUIObject.ipv4, this.postUIObject.ipv6)
.toPromise()
.then((item) => {
console.log('inserted')
......@@ -204,10 +229,19 @@ export class AppComponent {
}
openDialog(): void {
openDialog(): void {
this.currentRecordData.ipv4 = this.selectedRow['ipv4'];
this.currentRecordData.ipv6 = this.selectedRow['ipv6'];
this.currentRecordData.host_name = this.selectedRow['host'];
this.currentRecordData.adapter_name = this.selectedRow['adapter'];
this.currentRecordData.mac_address = this.selectedRow['mac_addr'];
this.currentRecordData.records = this.selectedRow['records'];
this.currentRecordData.record_type = this.selectedRow['record_type'];
this.currentRecordData.subnet_name = this.selectedRow['subnet_name'];
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}
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}
});
......@@ -219,9 +253,14 @@ export class AppComponent {
this.postUIObject.host_name = result.host;
this.postUIObject.mac_address = result.mac;
this.postUIObject.adapter_name = result.adapter;
this.postUIObject.subnet_name = this.currentRecordData.subnet_name;
this.PostRecords(this.postUIObject.host_name, this.postUIObject.ipv4, this.postUIObject.ipv6, this.postUIObject.mac_address, this.postUIObject.adapter_name);
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);
}
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.AllRecordList = [];
});
......@@ -297,6 +336,11 @@ export interface PostUIObject{
host_name?: string;
mac_address?: string;
adapter_name?: string;
records?: Records[];
record_type?: string;
mac_id?: any;
subnet_name?: any;
subnet_id?: any;
}
export class IPResultSet{
......@@ -304,23 +348,31 @@ export class IPResultSet{
ipv4: any;
ipv6: any;
host: any
mac_id: any
mac_addr: any;
adapter_id: any;
adapter: any;
subnet_id: any;
subnet_name: any;
records: any;
host_id: any
host_id: any;
record_type: any
constructor(id, ipv4, ipv6, host, mac_addr, adapter, subnet_name, records, host_Id){
constructor(id, ipv4, ipv6, host, mac_id, mac_addr, adapter_id, adapter, subnet_id, subnet_name, records, host_Id, record_type){
this.ip_id = id;
this.ipv4 = ipv4;
this.ipv6 = ipv6;
this.host = host;
this.mac_id = mac_id;
this.mac_addr = mac_addr;
this.adapter_id = adapter_id;
this.adapter = adapter;
this.subnet_id = subnet_id;
this.subnet_name = subnet_name;
this.records = records;
this.host_id = host_Id;
this.record_type = record_type;
}
}
......@@ -17,26 +17,38 @@
<input matInput placeholder="Mac" [(ngModel)]="data.mac">
</mat-form-field>
</div>
<div id="page-wrap">
<p>Currently Assigned Records</p>
<mat-selection-list>
<div *ngIf="data.display">
<mat-selection-list *ngIf="data.records !== 'undefined'">
<mat-list-option *ngFor="let record of data.records" [selected]="true">
{{record.record_type}}
</mat-list-option>
</mat-selection-list>
</div>
<div *ngIf="!data.display">
<p>No records</p>
</div>
<br/>
<br/>
<div align="center" *ngIf="!showButton">
<button (click)="toggleButton()" mat-button>Add a Record</button>
</div>
<div *ngIf="showButton">
<mat-form-field>
<mat-label>Pick a Record Type</mat-label>
<mat-select>
<mat-option *ngFor="let record of data.records" [value]="record.dropDownRecordType">
<mat-select [(ngModel)]="data.record_type">
<mat-option *ngFor="let record of data.records" [(value)]="record.record_type">
{{record.record_type}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
</div>
<div>
<button mat-button (click)="onNoClick()">No Thanks</button>
<button mat-button (click)="onNoClick()">No, Thanks</button>
<button mat-button [mat-dialog-close]="data" cdkFocusInitial>Ok</button>
</div>
</div>
......@@ -11,8 +11,7 @@ import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '@angular/material';
export class DialogOverviewComponent implements OnInit {
typesOfShoes: string[] = ['Boots', 'Clogs', 'Loafers', 'Moccasins', 'Sneakers'];
showButton: boolean = false;
ngOnInit() {
}
......@@ -24,6 +23,11 @@ export class DialogOverviewComponent implements OnInit {
this.dialogRef.close();
}
toggleButton(): void{
this.showButton = true;
}
}
export interface DialogData {
......@@ -33,7 +37,8 @@ export interface DialogData {
adapter: string;
mac: string;
records: Records[],
dropDownValue: any
record_type: any,
display: boolean
}
export interface Records{
......
......@@ -149,6 +149,14 @@ export class SampleService {
return this.http.post<Adapters>(this.HostLocation + this.endpoint, this.new_adapter)
}
UpdateAdapters(hostID, adapter_id, adapter_name): Observable<Adapters> {
this.endpoint = 'ipam/updateadapter/' + adapter_id + '/';
this.new_adapter.host = hostID;
this.new_adapter.adapter_name = adapter_name;
this.new_adapter.id = adapter_id;
return this.http.put<Adapters>(this.HostLocation + this.endpoint, this.new_adapter);
}
PostMacs(adapterID, mac_address): Observable<MacAddresses>{
this.endpoint = "ipam/createmac/";
this.new_mac.mac = mac_address;
......@@ -172,6 +180,13 @@ export class SampleService {
return this.http.put<any>(this.HostLocation + this.endpoint, this.new_mac)
}
UpdateHost(host_id, host_name): Observable<any> {
this.endpoint = 'ipam/updatehost/' + host_id + '/';
this.new_host.id = host_id;
this.new_host.host_name = host_name
return this.http.put<any>(this.HostLocation + this.endpoint, this.new_host);
}
DeleteHost(id): any {
this.endpoint = 'ipam/deletehost/'+ id +'/';
return this.http.delete<any>(this.HostLocation + this.endpoint);
......
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