Skip to content

Commit bd145df

Browse files
Marcin MaciaszczykMarcin Maciaszczyk
authored andcommitted
Update validation messages
1 parent e321dd0 commit bd145df

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

src/app/frontend/replicationcontrollerdetail/updatereplicas.html

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,21 @@
1818
<md-dialog-content layout-padding>
1919
<h4 class="md-title">Set desired number of pods</h4>
2020
<div>
21-
Replication controller {{ctrl.replicationController}} will be updated to reflect the desired count.<br/>
21+
Replication controller {{ctrl.replicationController}} will be updated to reflect the desired
22+
count.<br/>
2223
<span class="kd-updatereplicas-pod-status">
23-
Current status: {{ctrl.currentPods}}
24-
created, {{ctrl.desiredPods}} desired
24+
Current status: {{ctrl.currentPods}} created, {{ctrl.desiredPods}} desired
2525
</span>
2626
</div>
27-
<form ng-submit="ctrl.updateReplicas()">
27+
<form name="ctrl.updateReplicasForm" ng-submit="ctrl.updateReplicas()" novalidate>
2828
<md-input-container class="md-block">
2929
<label>Number of pods</label>
30-
<input type="number" min="1" ng-model="ctrl.replicas" required>
30+
<input name="podCount" type="number" kd-validate="integer" min="1" ng-model="ctrl.replicas"
31+
required>
32+
<ng-messages for="ctrl.updateReplicasForm.podCount.$error" role="alert">
33+
<ng-message when="required">Number of pods is required.</ng-message>
34+
<ng-message when="number,kdValid">Must be a positive integer.</ng-message>
35+
</ng-messages>
3136
</md-input-container>
3237
<md-dialog-actions layout="row">
3338
<md-button class="md-primary" ng-click="ctrl.cancel()">Cancel</md-button>

src/app/frontend/replicationcontrollerdetail/updatereplicas_controller.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ export default class UpdateReplicasDialogController {
6161

6262
/** @private {!angular.$resource} */
6363
this.resource_ = $resource;
64+
65+
/** @export {!angular.FormController} Initialized from the template */
66+
this.updateReplicasForm;
6467
}
6568

6669
/**
@@ -69,17 +72,19 @@ export default class UpdateReplicasDialogController {
6972
* @export
7073
*/
7174
updateReplicas() {
72-
let resource = getReplicationControllerSpecPodsResource(
73-
new StateParams(this.namespace_, this.replicationController), this.resource_);
74-
75-
/** @type {!backendApi.ReplicationControllerSpec} */
76-
let replicationControllerSpec = {
77-
replicas: this.replicas,
78-
};
79-
80-
resource.save(
81-
replicationControllerSpec, this.onUpdateReplicasSuccess_.bind(this),
82-
this.onUpdateReplicasError_.bind(this));
75+
if (this.updateReplicasForm.$valid) {
76+
let resource = getReplicationControllerSpecPodsResource(
77+
new StateParams(this.namespace_, this.replicationController), this.resource_);
78+
79+
/** @type {!backendApi.ReplicationControllerSpec} */
80+
let replicationControllerSpec = {
81+
replicas: this.replicas,
82+
};
83+
84+
resource.save(
85+
replicationControllerSpec, this.onUpdateReplicasSuccess_.bind(this),
86+
this.onUpdateReplicasError_.bind(this));
87+
}
8388
}
8489

8590
/**

src/test/frontend/replicationcontrollerdetail/updatereplicas_controller_test.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ describe('Update Replicas controller', () => {
4747
httpBackend = $httpBackend;
4848
log = $log;
4949

50-
ctrl = $controller(UpdateReplicasDialogController, {
51-
$resource: resource,
52-
namespace: namespaceMock,
53-
replicationController: replicationControllerMock,
54-
currentPods: 1,
55-
desiredPods: 1,
56-
});
50+
ctrl = $controller(
51+
UpdateReplicasDialogController, {
52+
$resource: resource,
53+
namespace: namespaceMock,
54+
replicationController: replicationControllerMock,
55+
currentPods: 1,
56+
desiredPods: 1,
57+
},
58+
{updateReplicasForm: {$valid: true}});
5759
});
5860
});
5961

0 commit comments

Comments
 (0)