-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(provider/kubernetes): v2 resize modal (#4279)
- Loading branch information
Showing
7 changed files
with
154 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
77 changes: 77 additions & 0 deletions
77
app/scripts/modules/kubernetes/v2/serverGroup/details/resize/resize.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { copy, equals, IController, module } from 'angular' | ||
import { IModalServiceInstance } from 'angular-ui-bootstrap'; | ||
|
||
import { | ||
Application, | ||
ICapacity, | ||
SERVER_GROUP_WRITER, | ||
ServerGroupWriter, | ||
TASK_MONITOR_BUILDER, | ||
TaskMonitor, | ||
TaskMonitorBuilder | ||
} from '@spinnaker/core'; | ||
import { IKubernetesServerGroup } from '../IKubernetesServerGroup'; | ||
|
||
interface IResizeCommand { | ||
capacity: ICapacity; | ||
reason: string; | ||
} | ||
|
||
class KubernetesServerGroupResizeController implements IController { | ||
public taskMonitor: TaskMonitor; | ||
public command: IResizeCommand; | ||
public current: ICapacity; | ||
public verification = { | ||
verified: false | ||
}; | ||
|
||
constructor(public serverGroup: IKubernetesServerGroup, | ||
taskMonitorBuilder: TaskMonitorBuilder, | ||
private $uibModalInstance: IModalServiceInstance, | ||
private serverGroupWriter: ServerGroupWriter, | ||
private application: Application) { | ||
'ngInject'; | ||
this.taskMonitor = taskMonitorBuilder.buildTaskMonitor({ | ||
title: `Resizing ${this.serverGroup.name}`, | ||
application: application, | ||
modalInstance: $uibModalInstance, | ||
}); | ||
|
||
this.current = this.serverGroup.capacity; | ||
this.command = { | ||
capacity: copy(this.current), | ||
reason: null, | ||
}; | ||
} | ||
|
||
public isValid(): boolean { | ||
return this.verification.verified && this.command.capacity.desired >= 0 && !equals(this.command.capacity, this.current); | ||
} | ||
|
||
public cancel(): void { | ||
this.$uibModalInstance.dismiss(); | ||
}; | ||
|
||
public resize(): void { | ||
this.taskMonitor.submit(() => { | ||
const payload = { | ||
capacity: this.command.capacity, | ||
serverGroupName: this.serverGroup.name, | ||
account: this.serverGroup.account, | ||
region: this.serverGroup.region, | ||
interestingHealthProviderNames: ['KubernetesPod'], | ||
reason: this.command.reason, | ||
}; | ||
|
||
return this.serverGroupWriter.resizeServerGroup(this.serverGroup, this.application, payload); | ||
}); | ||
} | ||
} | ||
|
||
export const KUBERNETES_V2_SERVER_GROUP_RESIZE_CTRL = 'spinnaker.kubernetes.v2.serverGroup.details.resize.controller'; | ||
|
||
module(KUBERNETES_V2_SERVER_GROUP_RESIZE_CTRL, [ | ||
SERVER_GROUP_WRITER, | ||
TASK_MONITOR_BUILDER, | ||
]) | ||
.controller('kubernetesV2ServerGroupResizeCtrl', KubernetesServerGroupResizeController); |
54 changes: 54 additions & 0 deletions
54
app/scripts/modules/kubernetes/v2/serverGroup/details/resize/resize.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<div modal-page class="confirmation-modal"> | ||
<task-monitor monitor="ctrl.taskMonitor"></task-monitor> | ||
<form role="form" name="resizeForm"> | ||
<modal-close dismiss="$dismiss()"></modal-close> | ||
<div class="modal-header"> | ||
<h3>Resize {{ctrl.serverGroup.kind}} {{ctrl.serverGroup.displayName}}</h3> | ||
</div> | ||
<div class="modal-body confirmation-modal"> | ||
<div class="form-horizontal"> | ||
<div class="form-group form-inline"> | ||
<div class="col-md-3 sm-label-right"> | ||
Current | ||
</div> | ||
<div class="col-md-3"> | ||
<div class="input-group"> | ||
<input type="number" | ||
class="form-control input-sm highlight-pristine" | ||
ng-model="ctrl.current.desired" | ||
readonly/> | ||
<span class="input-group-addon">pod<span ng-if="ctrl.current.desired !== 1">s</span></span> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="form-group form-inline"> | ||
<div class="col-md-3 sm-label-right"> | ||
Desired | ||
</div> | ||
<div class="col-md-3"> | ||
<div class="input-group"> | ||
<input type="number" | ||
class="form-control input-sm highlight-pristine" | ||
ng-model="ctrl.command.capacity.desired" | ||
min="0" | ||
required/> | ||
<span class="input-group-addon">pod<span ng-if="ctrl.command.capacity.desired !== 1">s</span></span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<task-reason command="ctrl.command"></task-reason> | ||
</div> | ||
<div class="modal-footer"> | ||
<user-verification account="ctrl.serverGroup.account" verification="ctrl.verification"></user-verification> | ||
<button type="submit" ng-click="ctrl.resize()" style="display:none"></button> <!-- Allows form submission via enter keypress--> | ||
<button class="btn btn-default" ng-click="ctrl.cancel()">Cancel</button> | ||
<button type="submit" | ||
class="btn btn-primary" | ||
ng-click="ctrl.resize()" | ||
ng-disabled="!ctrl.isValid() || !resizeForm.$valid"> | ||
Submit | ||
</button> | ||
</div> | ||
</form> | ||
</div> |