mirror of
https://github.com/loewexy/pdnsmanager.git
synced 2025-01-16 03:02:22 +01:00
Added slave edit component
This commit is contained in:
parent
b4f6922c96
commit
2bd996fe10
7 changed files with 86 additions and 21 deletions
|
@ -35,4 +35,26 @@ export class DomainsOperation {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async getSingle(domainId: number): Promise<DomainApitype> {
|
||||
try {
|
||||
return new DomainApitype(await this.http.get(['/domains', domainId.toString()]));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return new DomainApitype({});
|
||||
}
|
||||
}
|
||||
|
||||
public async updateMaster(domainId: number, master: string): Promise<boolean> {
|
||||
try {
|
||||
await this.http.put(['/domains', domainId.toString()], {
|
||||
master: master
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
<app-pagesize [pagesizes]="gs.pageSizes" [currentPagesize]="gs.pageSize" (pagesizeChange)="onPagesizeChange($event)"></app-pagesize>
|
||||
<div class="row">
|
||||
<app-pagesize class="ml-auto" [pagesizes]="gs.pageSizes" [currentPagesize]="gs.pageSize" (pagesizeChange)="onPagesizeChange($event)"></app-pagesize>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="table-responsive-lg">
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
<p>
|
||||
edit-slave works!
|
||||
</p>
|
||||
<div class="row">
|
||||
<div class="col-12 col-md-6 col-lg-3">
|
||||
<p class="font-weight-bold">Master for {{ domainName }}</p>
|
||||
|
||||
<form autocomplete="off" [formGroup]="slaveForm" (ngSubmit)="onSubmit()">
|
||||
<div class="form-group">
|
||||
<label>Master</label>
|
||||
<input type="text" class="form-control auto-invalid" formControlName="master" />
|
||||
<div class="invalid-feedback">
|
||||
Master can not be empty.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary float-right" [disabled]="!slaveForm.valid || slaveForm.pristine">Save</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
|
@ -1,3 +1,6 @@
|
|||
import { DomainsOperation } from './../../operations/domains.operations';
|
||||
import { ActivatedRoute, ParamMap } from '@angular/router';
|
||||
import { FormGroup, Validators, FormBuilder } from '@angular/forms';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
|
@ -7,9 +10,37 @@ import { Component, OnInit } from '@angular/core';
|
|||
})
|
||||
export class EditSlaveComponent implements OnInit {
|
||||
|
||||
constructor() { }
|
||||
public slaveForm: FormGroup;
|
||||
|
||||
constructor(private fb: FormBuilder, private route: ActivatedRoute, private domains: DomainsOperation) { }
|
||||
|
||||
public domainName = '';
|
||||
public domainId = 0;
|
||||
|
||||
ngOnInit() {
|
||||
this.createForm();
|
||||
|
||||
this.route.paramMap.subscribe((params) => this.initControl(params));
|
||||
}
|
||||
|
||||
private async initControl(params: ParamMap) {
|
||||
const domain = await this.domains.getSingle(+params.get('domainId'));
|
||||
|
||||
this.domainName = domain.name;
|
||||
this.domainId = domain.id;
|
||||
|
||||
this.slaveForm.reset({ master: domain.master });
|
||||
}
|
||||
|
||||
private createForm() {
|
||||
this.slaveForm = this.fb.group({
|
||||
master: ['', Validators.required]
|
||||
});
|
||||
}
|
||||
|
||||
public async onSubmit() {
|
||||
await this.domains.updateMaster(this.domainId, this.slaveForm.value.master);
|
||||
|
||||
this.slaveForm.markAsPristine();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
<div class="row">
|
||||
<nav class="mr-3 ml-auto">
|
||||
<ul class="pagination pagination-sm">
|
||||
<li class="disabled page-item">
|
||||
<span class="page-link">Entries per page</span>
|
||||
</li>
|
||||
<li *ngFor="let i of pagesizes" class="page-item" [class.active]="i === currentPagesize" (click)="newPagesize(i)">
|
||||
<span class="page-link">{{ i }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
<nav class="mr-3 ml-auto">
|
||||
<ul class="pagination pagination-sm">
|
||||
<li class="disabled page-item">
|
||||
<span class="page-link">Entries per page</span>
|
||||
</li>
|
||||
<li *ngFor="let i of pagesizes" class="page-item" [class.active]="i === currentPagesize" (click)="newPagesize(i)">
|
||||
<span class="page-link">{{ i }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
|
@ -78,8 +78,6 @@ export class SelectComponent implements OnInit, ControlValueAccessor {
|
|||
}
|
||||
|
||||
public writeValue(obj: any): void {
|
||||
console.log('input obj ' + JSON.stringify(obj));
|
||||
console.log(obj);
|
||||
if (obj === null) {
|
||||
this.selections = [];
|
||||
} else if (obj instanceof Array) {
|
||||
|
|
|
@ -15,7 +15,7 @@ export class HttpService {
|
|||
});
|
||||
}
|
||||
|
||||
public async get(url: string, params: Object = {}): Promise<any> {
|
||||
public async get(url: string | Array<string>, params: Object = {}): Promise<any> {
|
||||
const parts = [];
|
||||
for (const [k, v] of Object.entries(params)) {
|
||||
if (v === undefined || v === null) {
|
||||
|
@ -34,7 +34,7 @@ export class HttpService {
|
|||
|
||||
const queryStr = parts.join('&');
|
||||
|
||||
const reqUrl = queryStr.length > 0 ? this.makeUrl(url) + '?' + queryStr : url;
|
||||
const reqUrl = queryStr.length > 0 ? this.makeUrl(url) + '?' + queryStr : this.makeUrl(url);
|
||||
|
||||
return (await this.http({
|
||||
url: reqUrl,
|
||||
|
|
Loading…
Reference in a new issue