File
Implements
Metadata
selector |
cd-osd-reweight-modal |
styleUrls |
./osd-reweight-modal.component.scss |
templateUrl |
./osd-reweight-modal.component.html |
Index
Properties
|
|
Methods
|
|
Accessors
|
|
Public
bsModalRef
|
Type : BsModalRef
|
|
currentWeight
|
Type : number
|
Default value : 1
|
|
import { Component, OnInit } from '@angular/core';
import { Validators } from '@angular/forms';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { OsdService } from '../../../../shared/api/osd.service';
import { CdFormBuilder } from '../../../../shared/forms/cd-form-builder';
import { CdFormGroup } from '../../../../shared/forms/cd-form-group';
@Component({
selector: 'cd-osd-reweight-modal',
templateUrl: './osd-reweight-modal.component.html',
styleUrls: ['./osd-reweight-modal.component.scss']
})
export class OsdReweightModalComponent implements OnInit {
currentWeight = 1;
osdId: number;
reweightForm: CdFormGroup;
constructor(
public bsModalRef: BsModalRef,
private osdService: OsdService,
private fb: CdFormBuilder
) {}
get weight() {
return this.reweightForm.get('weight');
}
ngOnInit() {
this.reweightForm = this.fb.group({
weight: this.fb.control(this.currentWeight, [
Validators.required,
Validators.max(1),
Validators.min(0)
])
});
}
reweight() {
this.osdService
.reweight(this.osdId, this.reweightForm.value.weight)
.subscribe(() => this.bsModalRef.hide());
}
}
<cd-modal [modalRef]="bsModalRef">
<ng-container class="modal-title"
i18n>Reweight OSD</ng-container>
<ng-container class="modal-content">
<form class="form-horizontal"
[formGroup]="reweightForm">
<div class="modal-body" [ngClass]="{'has-error': weight.errors}">
<div class="row">
<label for="weight" class="col-sm-2 control-label">Weight</label>
<div class="col-sm-10">
<input id="weight" class="form-control" type="number"
step="0.1" formControlName="weight" min="0" max="1"
[value]="currentWeight">
<span class="help-block"
*ngIf="weight.errors">
<span *ngIf="weight.errors?.required"
i18n>This field is required.</span>
<span *ngIf="weight.errors?.max || weight.errors?.min"
i18n>The value needs to be between 0 and 1.</span>
</span>
</div>
</div>
</div>
<div class="modal-footer">
<cd-submit-button (submitAction)="reweight()"
[form]="reweightForm"
[disabled]="reweightForm.invalid"
i18n>Reweight</cd-submit-button>
<cd-back-button [back]="bsModalRef.hide"
name="Cancel"
i18n-name>
</cd-back-button>
</div>
</form>
</ng-container>
</cd-modal>
Legend
Html element with directive