Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
凌波微步_大先生
dashboard
提交
a5b3196b
D
dashboard
项目概览
凌波微步_大先生
/
dashboard
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dashboard
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a5b3196b
编写于
1月 22, 2016
作者:
P
Piotr Bryk
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #280 from floreks/edit-replica-card-menu
Added edit replica set option to replica set card menu
上级
d9e08a12
3f1953e6
变更
13
显示空白变更内容
内联
并排
Showing
13 changed file
with
212 addition
and
126 deletion
+212
-126
src/app/frontend/replicasetdetail/replicaset_service.js
src/app/frontend/replicasetdetail/replicaset_service.js
+18
-2
src/app/frontend/replicasetdetail/replicasetdetail_controller.js
.../frontend/replicasetdetail/replicasetdetail_controller.js
+9
-35
src/app/frontend/replicasetdetail/replicasetdetail_module.js
src/app/frontend/replicasetdetail/replicasetdetail_module.js
+2
-2
src/app/frontend/replicasetdetail/replicasetdetail_stateconfig.js
...frontend/replicasetdetail/replicasetdetail_stateconfig.js
+1
-1
src/app/frontend/replicasetdetail/updatereplicas.html
src/app/frontend/replicasetdetail/updatereplicas.html
+4
-4
src/app/frontend/replicasetdetail/updatereplicas_controller.js
...pp/frontend/replicasetdetail/updatereplicas_controller.js
+42
-16
src/app/frontend/replicasetdetail/updatereplicas_dialog.js
src/app/frontend/replicasetdetail/updatereplicas_dialog.js
+10
-6
src/app/frontend/replicasetlist/replicasetcardmenu.html
src/app/frontend/replicasetlist/replicasetcardmenu.html
+5
-0
src/app/frontend/replicasetlist/replicasetcardmenu_controller.js
.../frontend/replicasetlist/replicasetcardmenu_controller.js
+14
-7
src/test/frontend/replicasetdetail/replicaset_service_test.js
...test/frontend/replicasetdetail/replicaset_service_test.js
+18
-4
src/test/frontend/replicasetdetail/replicasetdetail_controller_test.js
...tend/replicasetdetail/replicasetdetail_controller_test.js
+27
-8
src/test/frontend/replicasetdetail/updatereplicas_controller_test.js
...ontend/replicasetdetail/updatereplicas_controller_test.js
+37
-35
src/test/frontend/replicasetlist/replicasetcardmenu_controller_test.js
...tend/replicasetlist/replicasetcardmenu_controller_test.js
+25
-6
未找到文件。
src/app/frontend/replicasetdetail/
delete
replicaset_service.js
→
src/app/frontend/replicasetdetail/replicaset_service.js
浏览文件 @
a5b3196b
...
@@ -14,13 +14,14 @@
...
@@ -14,13 +14,14 @@
import
{
StateParams
}
from
'
./replicasetdetail_state
'
;
import
{
StateParams
}
from
'
./replicasetdetail_state
'
;
import
{
getReplicaSetDetailsResource
}
from
'
./replicasetdetail_stateconfig
'
;
import
{
getReplicaSetDetailsResource
}
from
'
./replicasetdetail_stateconfig
'
;
import
showUpdateReplicasDialog
from
'
./updatereplicas_dialog
'
;
/**
/**
* Opens replica set delete dialog.
* Opens replica set delete dialog.
*
*
* @final
* @final
*/
*/
export
class
Delete
ReplicaSetService
{
export
class
ReplicaSetService
{
/**
/**
* @param {!md.$dialog} $mdDialog
* @param {!md.$dialog} $mdDialog
* @param {!angular.$resource} $resource
* @param {!angular.$resource} $resource
...
@@ -39,7 +40,7 @@ export class DeleteReplicaSetService {
...
@@ -39,7 +40,7 @@ export class DeleteReplicaSetService {
}
}
/**
/**
* Opens a replica set delete dialog. Returns a promise that is resolved/rejeced when user wants
* Opens a replica set delete dialog. Returns a promise that is resolved/rejec
t
ed when user wants
* to delete the replica. Nothing happens when user clicks cancel on the dialog.
* to delete the replica. Nothing happens when user clicks cancel on the dialog.
*
*
* @param {string} namespace
* @param {string} namespace
...
@@ -64,4 +65,19 @@ export class DeleteReplicaSetService {
...
@@ -64,4 +65,19 @@ export class DeleteReplicaSetService {
return
deferred
.
promise
;
return
deferred
.
promise
;
}
}
/**
* Opens an update replica set dialog. Returns a promise that is resolved/rejected when user wants
* to update the replicas. Nothing happens when user clicks cancel on the dialog.
*
* @param {string} namespace
* @param {string} replicaSet
* @param {number} currentPods
* @param {number} desiredPods
* @returns {!angular.$q.Promise}
*/
showUpdateReplicasDialog
(
namespace
,
replicaSet
,
currentPods
,
desiredPods
)
{
return
showUpdateReplicasDialog
(
this
.
mdDialog_
,
namespace
,
replicaSet
,
currentPods
,
desiredPods
);
}
}
}
src/app/frontend/replicasetdetail/replicasetdetail_controller.js
浏览文件 @
a5b3196b
...
@@ -12,7 +12,6 @@
...
@@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License.
import
showUpdateReplicasDialog
from
'
replicasetdetail/updatereplicas_dialog
'
;
import
{
UPWARDS
,
DOWNWARDS
}
from
'
replicasetdetail/sortedheader_controller
'
;
import
{
UPWARDS
,
DOWNWARDS
}
from
'
replicasetdetail/sortedheader_controller
'
;
import
{
stateName
as
replicasets
}
from
'
replicasetlist/replicasetlist_state
'
;
import
{
stateName
as
replicasets
}
from
'
replicasetlist/replicasetlist_state
'
;
import
{
stateName
as
logsStateName
}
from
'
logs/logs_state
'
;
import
{
stateName
as
logsStateName
}
from
'
logs/logs_state
'
;
...
@@ -38,26 +37,18 @@ export default class ReplicaSetDetailController {
...
@@ -38,26 +37,18 @@ export default class ReplicaSetDetailController {
* @param {!angular.$log} $log
* @param {!angular.$log} $log
* @param {!backendApi.ReplicaSetDetail} replicaSetDetail
* @param {!backendApi.ReplicaSetDetail} replicaSetDetail
* @param {!backendApi.Events} replicaSetEvents
* @param {!backendApi.Events} replicaSetEvents
* @param {!angular.Resource<!backendApi.ReplicaSetDetail>} replicaSetDetailResource
* @param {!./replicaset_service.ReplicaSetService} kdReplicaSetService
* @param {!angular.Resource<!backendApi.ReplicaSetSpec>} replicaSetSpecPodsResource
* @param {!./deletereplicaset_service.DeleteReplicaSetService} kdDeleteReplicaSetService
* @ngInject
* @ngInject
*/
*/
constructor
(
constructor
(
$mdDialog
,
$stateParams
,
$state
,
$resource
,
$log
,
replicaSetDetail
,
replicaSetEvents
,
$mdDialog
,
$stateParams
,
$state
,
$resource
,
$log
,
replicaSetDetail
,
replicaSetEvents
,
replicaSetDetailResource
,
replicaSetSpecPodsResource
,
kdDelete
ReplicaSetService
)
{
kd
ReplicaSetService
)
{
/** @export {!backendApi.ReplicaSetDetail} */
/** @export {!backendApi.ReplicaSetDetail} */
this
.
replicaSetDetail
=
replicaSetDetail
;
this
.
replicaSetDetail
=
replicaSetDetail
;
/** @export {!backendApi.Events} */
/** @export {!backendApi.Events} */
this
.
replicaSetEvents
=
replicaSetEvents
;
this
.
replicaSetEvents
=
replicaSetEvents
;
/** @private {!angular.Resource<!backendApi.ReplicaSetDetail>} */
this
.
replicaSetDetailResource_
=
replicaSetDetailResource
;
/** @private {!angular.Resource<!backendApi.ReplicaSetSpec>} */
this
.
replicaSetSpecPodsResource_
=
replicaSetSpecPodsResource
;
/** @export !Array<!backendApi.Event> */
/** @export !Array<!backendApi.Event> */
this
.
events
=
replicaSetEvents
.
events
;
this
.
events
=
replicaSetEvents
.
events
;
...
@@ -88,8 +79,8 @@ export default class ReplicaSetDetailController {
...
@@ -88,8 +79,8 @@ export default class ReplicaSetDetailController {
/** @private {!angular.$log} */
/** @private {!angular.$log} */
this
.
log_
=
$log
;
this
.
log_
=
$log
;
/** @private {!./
deletereplicaset_service.Delete
ReplicaSetService} */
/** @private {!./
replicaset_service.
ReplicaSetService} */
this
.
kd
DeleteReplicaSetService_
=
kdDelete
ReplicaSetService
;
this
.
kd
ReplicaSetService_
=
kd
ReplicaSetService
;
/**
/**
* Name of column, that will be used for pods sorting.
* Name of column, that will be used for pods sorting.
...
@@ -183,8 +174,9 @@ export default class ReplicaSetDetailController {
...
@@ -183,8 +174,9 @@ export default class ReplicaSetDetailController {
* @export
* @export
*/
*/
handleUpdateReplicasDialog
()
{
handleUpdateReplicasDialog
()
{
showUpdateReplicasDialog
(
this
.
kdReplicaSetService_
.
showUpdateReplicasDialog
(
this
.
mdDialog_
,
this
.
replicaSetDetail
,
this
.
updateReplicas_
.
bind
(
this
));
this
.
replicaSetDetail
.
namespace
,
this
.
replicaSetDetail
.
name
,
this
.
replicaSetDetail
.
podInfo
.
current
,
this
.
replicaSetDetail
.
podInfo
.
desired
);
}
}
/**
/**
...
@@ -192,7 +184,7 @@ export default class ReplicaSetDetailController {
...
@@ -192,7 +184,7 @@ export default class ReplicaSetDetailController {
* @export
* @export
*/
*/
handleDeleteReplicaSetDialog
()
{
handleDeleteReplicaSetDialog
()
{
this
.
kd
Delete
ReplicaSetService_
.
showDeleteDialog
(
this
.
kdReplicaSetService_
.
showDeleteDialog
(
this
.
stateParams_
.
namespace
,
this
.
stateParams_
.
replicaSet
)
this
.
stateParams_
.
namespace
,
this
.
stateParams_
.
replicaSet
)
.
then
(
this
.
onReplicaSetDeleteSuccess_
.
bind
(
this
),
this
.
onReplicaSetDeleteError_
.
bind
(
this
));
.
then
(
this
.
onReplicaSetDeleteSuccess_
.
bind
(
this
),
this
.
onReplicaSetDeleteError_
.
bind
(
this
));
}
}
...
@@ -202,23 +194,6 @@ export default class ReplicaSetDetailController {
...
@@ -202,23 +194,6 @@ export default class ReplicaSetDetailController {
* or log unsuccessful operation error.
* or log unsuccessful operation error.
*/
*/
/**
* Updates replicas count in replica set
* @param {number} replicasCount
* @param {function(!backendApi.ReplicaSetSpec)=} opt_callback
* @param {function(!angular.$http.Response)=} opt_errback
* @private
*/
updateReplicas_
(
replicasCount
,
opt_callback
,
opt_errback
)
{
/** @type {!backendApi.ReplicaSetSpec} */
let
replicaSetSpec
=
{
replicas
:
replicasCount
,
};
this
.
replicaSetSpecPodsResource_
.
save
(
replicaSetSpec
,
opt_callback
,
opt_errback
);
// TODO(floreks): Think about refreshing data on this page after update.
}
/**
/**
* Changes state back to replica set list after successful deletion of replica set.
* Changes state back to replica set list after successful deletion of replica set.
* @private
* @private
...
@@ -229,7 +204,6 @@ export default class ReplicaSetDetailController {
...
@@ -229,7 +204,6 @@ export default class ReplicaSetDetailController {
}
}
/**
/**
* TODO(floreks): display message to the user
* Logs error after replica set deletion failure.
* Logs error after replica set deletion failure.
* @param {!angular.$http.Response} err
* @param {!angular.$http.Response} err
* @private
* @private
...
...
src/app/frontend/replicasetdetail/replicasetdetail_module.js
浏览文件 @
a5b3196b
...
@@ -18,7 +18,7 @@ import logsModule from 'logs/logs_module';
...
@@ -18,7 +18,7 @@ import logsModule from 'logs/logs_module';
import
serviceEndpointDirective
from
'
./serviceendpoint_directive
'
;
import
serviceEndpointDirective
from
'
./serviceendpoint_directive
'
;
import
stateConfig
from
'
./replicasetdetail_stateconfig
'
;
import
stateConfig
from
'
./replicasetdetail_stateconfig
'
;
import
sortedHeaderDirective
from
'
./sortedheader_directive
'
;
import
sortedHeaderDirective
from
'
./sortedheader_directive
'
;
import
{
DeleteReplicaSetService
}
from
'
./delete
replicaset_service
'
;
import
{
ReplicaSetService
}
from
'
./
replicaset_service
'
;
/**
/**
* Angular module for the Replica Set details view.
* Angular module for the Replica Set details view.
...
@@ -38,4 +38,4 @@ export default angular.module(
...
@@ -38,4 +38,4 @@ export default angular.module(
.
config
(
stateConfig
)
.
config
(
stateConfig
)
.
directive
(
'
kdServiceEndpoint
'
,
serviceEndpointDirective
)
.
directive
(
'
kdServiceEndpoint
'
,
serviceEndpointDirective
)
.
directive
(
'
kdSortedHeader
'
,
sortedHeaderDirective
)
.
directive
(
'
kdSortedHeader
'
,
sortedHeaderDirective
)
.
service
(
'
kd
DeleteReplicaSetService
'
,
Delete
ReplicaSetService
);
.
service
(
'
kd
ReplicaSetService
'
,
ReplicaSetService
);
src/app/frontend/replicasetdetail/replicasetdetail_stateconfig.js
浏览文件 @
a5b3196b
...
@@ -52,7 +52,7 @@ export function getReplicaSetDetailsResource($stateParams, $resource) {
...
@@ -52,7 +52,7 @@ export function getReplicaSetDetailsResource($stateParams, $resource) {
* @return {!angular.Resource<!backendApi.ReplicaSetSpec>}
* @return {!angular.Resource<!backendApi.ReplicaSetSpec>}
* @ngInject
* @ngInject
*/
*/
function
getReplicaSetSpecPodsResource
(
$stateParams
,
$resource
)
{
export
function
getReplicaSetSpecPodsResource
(
$stateParams
,
$resource
)
{
return
$resource
(
`api/replicasets/
${
$stateParams
.
namespace
}
/
${
$stateParams
.
replicaSet
}
/update/pods`
);
return
$resource
(
`api/replicasets/
${
$stateParams
.
namespace
}
/
${
$stateParams
.
replicaSet
}
/update/pods`
);
}
}
...
...
src/app/frontend/replicasetdetail/updatereplicas.html
浏览文件 @
a5b3196b
...
@@ -17,14 +17,14 @@ limitations under the License.
...
@@ -17,14 +17,14 @@ limitations under the License.
<md-dialog
aria-label=
"Create a new namespace"
layout=
"column"
layout-padding
>
<md-dialog
aria-label=
"Create a new namespace"
layout=
"column"
layout-padding
>
<md-content
layout-padding
>
<md-content
layout-padding
>
<h4
class=
"md-title"
>
Set desired number of pods
</h4>
<h4
class=
"md-title"
>
Set desired number of pods
</h4>
<p>
Replica set {{ctrl.replicaSet
Detail.name
}} will be updated to reflect the desired count.
<p>
Replica set {{ctrl.replicaSet}} will be updated to reflect the desired count.
<br/>
<br/>
<span
class=
"kd-updatereplicas-pod-status"
>
<span
class=
"kd-updatereplicas-pod-status"
>
Current status: {{ctrl.
replicaSetDetail.podsCreated
}}
Current status: {{ctrl.
currentPods
}}
created, {{ctrl.
replicaSetDetail.podsDesired
}} desired
created, {{ctrl.
desiredPods
}} desired
</span>
</span>
</p>
</p>
<form
ng-submit=
"ctrl.updateReplicas
Count
()"
>
<form
ng-submit=
"ctrl.updateReplicas()"
>
<md-input-container
class=
"md-block"
>
<md-input-container
class=
"md-block"
>
<label>
Number of pods
</label>
<label>
Number of pods
</label>
<input
type=
"number"
min=
"1"
ng-model=
"ctrl.replicas"
required
>
<input
type=
"number"
min=
"1"
ng-model=
"ctrl.replicas"
required
>
...
...
src/app/frontend/replicasetdetail/updatereplicas_controller.js
浏览文件 @
a5b3196b
...
@@ -12,6 +12,9 @@
...
@@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// See the License for the specific language governing permissions and
// limitations under the License.
// limitations under the License.
import
{
StateParams
}
from
'
./replicasetdetail_state
'
;
import
{
getReplicaSetSpecPodsResource
}
from
'
./replicasetdetail_stateconfig
'
;
/**
/**
* Controller for the update replica set dialog.
* Controller for the update replica set dialog.
*
*
...
@@ -22,39 +25,63 @@ export default class UpdateReplicasDialogController {
...
@@ -22,39 +25,63 @@ export default class UpdateReplicasDialogController {
* @param {!md.$dialog} $mdDialog
* @param {!md.$dialog} $mdDialog
* @param {!angular.$log} $log
* @param {!angular.$log} $log
* @param {!ui.router.$state} $state
* @param {!ui.router.$state} $state
* @param {!backendApi.ReplicaSetDetail} replicaSetDetail
* @param {!angular.$resource} $resource
* @param {!function(number, function(!backendApi.ReplicaSetSpec),
* @param {!angular.$q} $q
* function(!angular.$http.Response)=)} updateReplicasFn
* @param {string} namespace
* @param {string} replicaSet
* @param {number} currentPods
* @param {number} desiredPods
* @ngInject
* @ngInject
*/
*/
constructor
(
$mdDialog
,
$log
,
$state
,
replicaSetDetail
,
updateReplicasFn
)
{
constructor
(
$mdDialog
,
$log
,
$state
,
$resource
,
$q
,
namespace
,
replicaSet
,
currentPods
,
desiredPods
)
{
/** @export {number} */
/** @export {number} */
this
.
replicas
;
this
.
replicas
;
/** @export {!backendApi.ReplicaSetDetail} */
/** @export {number} */
this
.
replicaSetDetail
=
replicaSetDetail
;
this
.
currentPods
=
currentPods
;
/** @export {number} */
this
.
desiredPods
=
desiredPods
;
/** @export {string} */
this
.
replicaSet
=
replicaSet
;
/** @private {string} */
this
.
namespace_
=
namespace
;
/** @private {!md.$dialog} */
/** @private {!md.$dialog} */
this
.
mdDialog_
=
$mdDialog
;
this
.
mdDialog_
=
$mdDialog
;
/** @private {!function(number, function(!backendApi.ReplicaSetSpec),
* function(!angular.$http.Response)=)} */
this
.
updateReplicasFn_
=
updateReplicasFn
;
/** @private {!angular.$log} */
/** @private {!angular.$log} */
this
.
log_
=
$log
;
this
.
log_
=
$log
;
/** @private {!ui.router.$state} */
/** @private {!ui.router.$state} */
this
.
state_
=
$state
;
this
.
state_
=
$state
;
/** @private {!angular.$resource} */
this
.
resource_
=
$resource
;
/** @private {!angular.$q} */
this
.
q_
=
$q
;
}
}
/**
/**
* Executes callback function to update replicas count in replica set.
* Updates number of replicas in replica set.
*
* @export
* @export
*/
*/
updateReplicasCount
()
{
updateReplicas
()
{
this
.
updateReplicasFn_
(
let
resource
=
getReplicaSetSpecPodsResource
(
this
.
replicas
,
this
.
onUpdateReplicasSuccess_
.
bind
(
this
),
new
StateParams
(
this
.
namespace_
,
this
.
replicaSet
),
this
.
resource_
);
/** @type {!backendApi.ReplicaSetSpec} */
let
replicaSetSpec
=
{
replicas
:
this
.
replicas
,
};
resource
.
save
(
replicaSetSpec
,
this
.
onUpdateReplicasSuccess_
.
bind
(
this
),
this
.
onUpdateReplicasError_
.
bind
(
this
));
this
.
onUpdateReplicasError_
.
bind
(
this
));
}
}
...
@@ -69,8 +96,7 @@ export default class UpdateReplicasDialogController {
...
@@ -69,8 +96,7 @@ export default class UpdateReplicasDialogController {
* @private
* @private
*/
*/
onUpdateReplicasSuccess_
(
updatedSpec
)
{
onUpdateReplicasSuccess_
(
updatedSpec
)
{
this
.
log_
.
info
(
'
Successfully updated replica set.
'
);
this
.
log_
.
info
(
`Successfully updated replicas number to
${
updatedSpec
.
replicas
}
`
);
this
.
log_
.
info
(
updatedSpec
);
this
.
mdDialog_
.
hide
();
this
.
mdDialog_
.
hide
();
this
.
state_
.
reload
();
this
.
state_
.
reload
();
}
}
...
...
src/app/frontend/replicasetdetail/updatereplicas_dialog.js
浏览文件 @
a5b3196b
...
@@ -17,20 +17,24 @@ import UpdateReplicasDialogController from 'replicasetdetail/updatereplicas_cont
...
@@ -17,20 +17,24 @@ import UpdateReplicasDialogController from 'replicasetdetail/updatereplicas_cont
/**
/**
* Opens update replicas dialog.
* Opens update replicas dialog.
* @param {!md.$dialog} mdDialog
* @param {!md.$dialog} mdDialog
* @param {!backendApi.ReplicaSetDetail} replicaSetDetail
* @param {string} namespace
* @param {!function(number, function(!backendApi.ReplicaSetSpec)=,
* @param {string} replicaSet
* function(!angular.$http.Response)=)} updateReplicasFn
* @param {number} currentPods
* @param {number} desiredPods
* @return {!angular.$q.Promise}
* @return {!angular.$q.Promise}
*/
*/
export
default
function
showUpdateReplicasDialog
(
mdDialog
,
replicaSetDetail
,
updateReplicasFn
)
{
export
default
function
showUpdateReplicasDialog
(
mdDialog
,
namespace
,
replicaSet
,
currentPods
,
desiredPods
)
{
return
mdDialog
.
show
({
return
mdDialog
.
show
({
controller
:
UpdateReplicasDialogController
,
controller
:
UpdateReplicasDialogController
,
controllerAs
:
'
ctrl
'
,
controllerAs
:
'
ctrl
'
,
clickOutsideToClose
:
true
,
clickOutsideToClose
:
true
,
templateUrl
:
'
replicasetdetail/updatereplicas.html
'
,
templateUrl
:
'
replicasetdetail/updatereplicas.html
'
,
locals
:
{
locals
:
{
'
updateReplicasFn
'
:
updateReplicasFn
,
'
namespace
'
:
namespace
,
'
replicaSetDetail
'
:
replicaSetDetail
,
'
replicaSet
'
:
replicaSet
,
'
currentPods
'
:
currentPods
,
'
desiredPods
'
:
desiredPods
,
},
},
});
});
}
}
src/app/frontend/replicasetlist/replicasetcardmenu.html
浏览文件 @
a5b3196b
...
@@ -25,6 +25,11 @@ limitations under the License.
...
@@ -25,6 +25,11 @@ limitations under the License.
View details
View details
</md-button>
</md-button>
</md-menu-item>
</md-menu-item>
<md-menu-item>
<md-button
ng-click=
"ctrl.showUpdateReplicasDialog()"
>
Edit pod count
</md-button>
</md-menu-item>
<md-menu-item>
<md-menu-item>
<md-button
ng-click=
"ctrl.showDeleteDialog()"
>
<md-button
ng-click=
"ctrl.showDeleteDialog()"
>
Delete
Delete
...
...
src/app/frontend/replicasetlist/replicasetcardmenu_controller.js
浏览文件 @
a5b3196b
...
@@ -24,11 +24,10 @@ export default class ReplicaSetCardMenuController {
...
@@ -24,11 +24,10 @@ export default class ReplicaSetCardMenuController {
/**
/**
* @param {!ui.router.$state} $state
* @param {!ui.router.$state} $state
* @param {!angular.$log} $log
* @param {!angular.$log} $log
* @param {!./../replicasetdetail/deletereplicaset_service.DeleteReplicaSetService}
* @param {!./../replicasetdetail/replicaset_service.ReplicaSetService} kdReplicaSetService
* kdDeleteReplicaSetService
* @ngInject
* @ngInject
*/
*/
constructor
(
$state
,
$log
,
kd
Delete
ReplicaSetService
)
{
constructor
(
$state
,
$log
,
kdReplicaSetService
)
{
/**
/**
* Initialized from the scope.
* Initialized from the scope.
* @export {!backendApi.ReplicaSet}
* @export {!backendApi.ReplicaSet}
...
@@ -41,8 +40,8 @@ export default class ReplicaSetCardMenuController {
...
@@ -41,8 +40,8 @@ export default class ReplicaSetCardMenuController {
/** @private {!angular.$log} */
/** @private {!angular.$log} */
this
.
log_
=
$log
;
this
.
log_
=
$log
;
/** @private {!./../replicasetdetail/
deletereplicaset_service.Delete
ReplicaSetService} */
/** @private {!./../replicasetdetail/
replicaset_service.
ReplicaSetService} */
this
.
kd
DeleteReplicaSetService_
=
kdDelete
ReplicaSetService
;
this
.
kd
ReplicaSetService_
=
kd
ReplicaSetService
;
}
}
/**
/**
...
@@ -63,8 +62,16 @@ export default class ReplicaSetCardMenuController {
...
@@ -63,8 +62,16 @@ export default class ReplicaSetCardMenuController {
* @export
* @export
*/
*/
showDeleteDialog
()
{
showDeleteDialog
()
{
this
.
kdDeleteReplicaSetService_
.
showDeleteDialog
(
this
.
kdReplicaSetService_
.
showDeleteDialog
(
this
.
replicaSet
.
namespace
,
this
.
replicaSet
.
name
)
this
.
replicaSet
.
namespace
,
this
.
replicaSet
.
name
)
.
then
(()
=>
this
.
state_
.
reload
(),
()
=>
this
.
log_
.
error
(
'
Error deleting replica set
'
));
.
then
(()
=>
this
.
state_
.
reload
(),
()
=>
this
.
log_
.
error
(
'
Error deleting replica set
'
));
}
}
/**
* @export
*/
showUpdateReplicasDialog
()
{
this
.
kdReplicaSetService_
.
showUpdateReplicasDialog
(
this
.
replicaSet
.
namespace
,
this
.
replicaSet
.
name
,
this
.
replicaSet
.
pods
.
current
,
this
.
replicaSet
.
pods
.
desired
);
}
}
}
src/test/frontend/replicasetdetail/
delete
replicaset_service_test.js
→
src/test/frontend/replicasetdetail/replicaset_service_test.js
浏览文件 @
a5b3196b
...
@@ -14,8 +14,8 @@
...
@@ -14,8 +14,8 @@
import
replicaSetDetailModule
from
'
replicasetdetail/replicasetdetail_module
'
;
import
replicaSetDetailModule
from
'
replicasetdetail/replicasetdetail_module
'
;
describe
(
'
Delete r
eplica set service
'
,
()
=>
{
describe
(
'
R
eplica set service
'
,
()
=>
{
/** @type {!
Delete
ReplicaSetService} */
/** @type {!ReplicaSetService} */
let
service
;
let
service
;
/** @type {!md.$dialog} */
/** @type {!md.$dialog} */
let
mdDialog
;
let
mdDialog
;
...
@@ -27,8 +27,8 @@ describe('Delete replica set service', () => {
...
@@ -27,8 +27,8 @@ describe('Delete replica set service', () => {
beforeEach
(()
=>
{
beforeEach
(()
=>
{
angular
.
mock
.
module
(
replicaSetDetailModule
.
name
);
angular
.
mock
.
module
(
replicaSetDetailModule
.
name
);
angular
.
mock
.
inject
((
kd
Delete
ReplicaSetService
,
$mdDialog
,
$q
,
$httpBackend
)
=>
{
angular
.
mock
.
inject
((
kdReplicaSetService
,
$mdDialog
,
$q
,
$httpBackend
)
=>
{
service
=
kd
Delete
ReplicaSetService
;
service
=
kdReplicaSetService
;
mdDialog
=
$mdDialog
;
mdDialog
=
$mdDialog
;
q
=
$q
;
q
=
$q
;
httpBackend
=
$httpBackend
;
httpBackend
=
$httpBackend
;
...
@@ -64,4 +64,18 @@ describe('Delete replica set service', () => {
...
@@ -64,4 +64,18 @@ describe('Delete replica set service', () => {
deferred
.
resolve
();
deferred
.
resolve
();
httpBackend
.
flush
();
httpBackend
.
flush
();
});
});
it
(
'
should show edit replicas dialog
'
,
()
=>
{
// given
let
namespace
=
'
foo-namespace
'
;
let
replicaSet
=
'
foo-name
'
;
let
currentPods
=
3
;
spyOn
(
mdDialog
,
'
show
'
);
// when
service
.
showUpdateReplicasDialog
(
namespace
,
replicaSet
,
currentPods
,
currentPods
);
// then
expect
(
mdDialog
.
show
).
toHaveBeenCalled
();
});
});
});
src/test/frontend/replicasetdetail/replicasetdetail_controller_test.js
浏览文件 @
a5b3196b
...
@@ -21,15 +21,17 @@ describe('Replica Set Detail controller', () => {
...
@@ -21,15 +21,17 @@ describe('Replica Set Detail controller', () => {
* @type {!ReplicaSetDetailController}
* @type {!ReplicaSetDetailController}
*/
*/
let
ctrl
;
let
ctrl
;
/** @type {!replicasetdetail/replicaset_service.ReplicaSetService} */
/** @type {!md.$dialog} */
let
kdReplicaSetService
;
let
mdDialog
;
/** @type {!angular.$q} */
let
q
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
angular
.
mock
.
module
(
replicaSetDetailModule
.
name
);
angular
.
mock
.
module
(
replicaSetDetailModule
.
name
);
angular
.
mock
.
inject
((
$controller
,
$mdDialog
,
$resource
)
=>
{
angular
.
mock
.
inject
((
$controller
,
$resource
,
$q
,
_kdReplicaSetService_
)
=>
{
mdDialog
=
$mdDialog
;
q
=
$q
;
kdReplicaSetService
=
_kdReplicaSetService_
;
ctrl
=
$controller
(
ReplicaSetDetailController
,
{
ctrl
=
$controller
(
ReplicaSetDetailController
,
{
replicaSetDetail
:
{},
replicaSetDetail
:
{},
replicaSetEvents
:
{},
replicaSetEvents
:
{},
...
@@ -89,19 +91,36 @@ describe('Replica Set Detail controller', () => {
...
@@ -89,19 +91,36 @@ describe('Replica Set Detail controller', () => {
it
(
'
should show edit replicas dialog
'
,
()
=>
{
it
(
'
should show edit replicas dialog
'
,
()
=>
{
// given
// given
ctrl
.
replicaSetDetail
=
{
ctrl
.
replicaSetDetail
=
{
pods
:
[],
namespace
:
'
foo-namespace
'
,
name
:
'
foo-name
'
,
podInfo
:
{
current
:
3
,
desired
:
3
,
},
};
};
spyOn
(
mdDialog
,
'
show
'
);
spyOn
(
kdReplicaSetService
,
'
showUpdateReplicasDialog
'
);
// when
// when
ctrl
.
handleUpdateReplicasDialog
();
ctrl
.
handleUpdateReplicasDialog
();
// then
// then
expect
(
mdDialog
.
show
).
toHaveBeenCalled
();
expect
(
kdReplicaSetService
.
showUpdateReplicasDialog
).
toHaveBeenCalled
();
});
});
it
(
'
should create logs href
'
,
()
=>
{
it
(
'
should create logs href
'
,
()
=>
{
expect
(
ctrl
.
getPodLogsHref
({
name
:
'
foo-pod
'
}))
expect
(
ctrl
.
getPodLogsHref
({
name
:
'
foo-pod
'
}))
.
toBe
(
'
#/logs/foo-namespace/foo-replicaset/foo-pod/
'
);
.
toBe
(
'
#/logs/foo-namespace/foo-replicaset/foo-pod/
'
);
});
});
it
(
'
should show delete replicas dialog
'
,
()
=>
{
// given
let
deferred
=
q
.
defer
();
spyOn
(
kdReplicaSetService
,
'
showDeleteDialog
'
).
and
.
returnValue
(
deferred
.
promise
);
// when
ctrl
.
handleDeleteReplicaSetDialog
();
// then
expect
(
kdReplicaSetService
.
showDeleteDialog
).
toHaveBeenCalled
();
});
});
});
src/test/frontend/replicasetdetail/updatereplicas_controller_test.js
浏览文件 @
a5b3196b
...
@@ -15,77 +15,79 @@
...
@@ -15,77 +15,79 @@
import
UpdateReplicasDialogController
from
'
replicasetdetail/updatereplicas_controller
'
;
import
UpdateReplicasDialogController
from
'
replicasetdetail/updatereplicas_controller
'
;
import
replicaSetDetailModule
from
'
replicasetdetail/replicasetdetail_module
'
;
import
replicaSetDetailModule
from
'
replicasetdetail/replicasetdetail_module
'
;
describe
(
'
Replica Set Detail
controller
'
,
()
=>
{
describe
(
'
Update Replicas
controller
'
,
()
=>
{
/**
/**
* Replica Set Detail controller.
* Replica Set Detail controller.
* @type {!
ReplicaSetDetail
Controller}
* @type {!
UpdateReplicasDialog
Controller}
*/
*/
let
ctrl
;
let
ctrl
;
/** @type {!md.$dialog} */
/** @type {!md.$dialog} */
let
mdDialog
;
let
mdDialog
;
/** @type {!angular.$log} */
let
log
;
/** @type {!ui.router.$state} */
/** @type {!ui.router.$state} */
let
state
;
let
state
;
/** @type {!angular.$resource} */
let
resource
;
/** @type {!angular.$httpBackend} */
let
httpBackend
;
/** @type {!angular.$log} */
let
log
;
/**
/** @type {string} */
* First parameter behavior is changed to indicate successful/failed update.
let
namespaceMock
=
'
foo-namespace
'
;
* @param {!boolean} isError
/** @type {string} */
* @param {!function(!backendApi.ReplicaSetSpec)} onSuccess
let
replicaSetMock
=
'
foo-name
'
;
* @param {!function(!angular.$http.Response)} onError
*/
let
mockUpdateReplicasFn
=
function
(
isError
,
onSuccess
,
onError
)
{
if
(
isError
)
{
onError
();
}
else
{
onSuccess
();
}
};
beforeEach
(()
=>
{
beforeEach
(()
=>
{
angular
.
mock
.
module
(
replicaSetDetailModule
.
name
);
angular
.
mock
.
module
(
replicaSetDetailModule
.
name
);
angular
.
mock
.
inject
((
$
resource
,
$log
,
$state
,
$mdDialog
,
$controller
)
=>
{
angular
.
mock
.
inject
((
$
log
,
$state
,
$mdDialog
,
$controller
,
$httpBackend
,
$resource
)
=>
{
mdDialog
=
$mdDialog
;
mdDialog
=
$mdDialog
;
log
=
$log
;
state
=
$state
;
state
=
$state
;
resource
=
$resource
;
httpBackend
=
$httpBackend
;
log
=
$log
;
ctrl
=
$controller
(
ctrl
=
$controller
(
UpdateReplicasDialogController
,
{
UpdateReplicasDialogController
,
$resource
:
resource
,
{
replicaSetDetail
:
{},
updateReplicasFn
:
mockUpdateReplicasFn
});
namespace
:
namespaceMock
,
replicaSet
:
replicaSetMock
,
currentPods
:
1
,
desiredPods
:
1
,
});
});
});
});
});
it
(
'
should
log success after edit replicas and hide the dialog
'
,
()
=>
{
it
(
'
should
update controller replicas to given number and log success
'
,
()
=>
{
// given
// given
let
replicaSpec
=
{
replicas
:
5
,
};
spyOn
(
log
,
'
info
'
);
spyOn
(
log
,
'
info
'
);
spyOn
(
mdDialog
,
'
hide
'
);
spyOn
(
state
,
'
reload
'
);
spyOn
(
state
,
'
reload
'
);
// Indicates if there was error during update
httpBackend
.
whenPOST
(
'
api/replicasets/foo-namespace/foo-name/update/pods
'
)
ctrl
.
replicas
=
false
;
.
respond
(
200
,
replicaSpec
)
;
// when
// when
ctrl
.
updateReplicasCount
();
ctrl
.
updateReplicas
();
httpBackend
.
flush
();
// then
// then
expect
(
log
.
info
)
.
toHaveBeenCalledWith
(
'
Successfully updated replica set.
'
);
expect
(
log
.
info
)
expect
(
mdDialog
.
hide
).
toHaveBeenCalled
(
);
.
toHaveBeenCalledWith
(
`Successfully updated replicas number to
${
replicaSpec
.
replicas
}
`
);
expect
(
state
.
reload
).
toHaveBeenCalled
();
expect
(
state
.
reload
).
toHaveBeenCalled
();
});
});
it
(
'
should log error
after edit replicas and hide the dialog
'
,
()
=>
{
it
(
'
should log error
on failed update
'
,
()
=>
{
// given
// given
spyOn
(
log
,
'
error
'
);
spyOn
(
log
,
'
error
'
);
spyOn
(
mdDialog
,
'
hide
'
);
httpBackend
.
whenPOST
(
'
api/replicasets/foo-namespace/foo-name/update/pods
'
).
respond
(
404
);
// Indicates if there was error during update
ctrl
.
replicas
=
true
;
// when
// when
ctrl
.
updateReplicasCount
();
ctrl
.
updateReplicas
();
httpBackend
.
flush
();
// then
// then
expect
(
log
.
error
).
toHaveBeenCalled
();
expect
(
log
.
error
).
toHaveBeenCalled
();
expect
(
mdDialog
.
hide
).
toHaveBeenCalled
();
});
});
it
(
'
should close the dialog on cancel
'
,
()
=>
{
it
(
'
should close the dialog on cancel
'
,
()
=>
{
...
...
src/test/frontend/replicasetlist/replicasetcardmenu_controller_test.js
浏览文件 @
a5b3196b
...
@@ -23,15 +23,15 @@ describe('Replica set card menu controller', () => {
...
@@ -23,15 +23,15 @@ describe('Replica set card menu controller', () => {
let
state
;
let
state
;
/** @type {!angular.Scope} */
/** @type {!angular.Scope} */
let
scope
;
let
scope
;
/** @type {!replicasetdetail/
deletereplicaset_service.Delete
ReplicaSetService} */
/** @type {!replicasetdetail/
replicaset_service.
ReplicaSetService} */
let
kd
Delete
ReplicaSetService
;
let
kdReplicaSetService
;
beforeEach
(()
=>
{
beforeEach
(()
=>
{
angular
.
mock
.
module
(
replicaSetListModule
.
name
);
angular
.
mock
.
module
(
replicaSetListModule
.
name
);
angular
.
mock
.
inject
((
$controller
,
$state
,
_kd
Delete
ReplicaSetService_
,
$rootScope
)
=>
{
angular
.
mock
.
inject
((
$controller
,
$state
,
_kdReplicaSetService_
,
$rootScope
)
=>
{
state
=
$state
;
state
=
$state
;
kd
DeleteReplicaSetService
=
_kdDelete
ReplicaSetService_
;
kd
ReplicaSetService
=
_kd
ReplicaSetService_
;
scope
=
$rootScope
;
scope
=
$rootScope
;
ctrl
=
$controller
(
ctrl
=
$controller
(
ReplicaSetCardMenuController
,
null
,
ReplicaSetCardMenuController
,
null
,
...
@@ -67,7 +67,7 @@ describe('Replica set card menu controller', () => {
...
@@ -67,7 +67,7 @@ describe('Replica set card menu controller', () => {
// given
// given
let
deferred
=
$q
.
defer
();
let
deferred
=
$q
.
defer
();
spyOn
(
state
,
'
reload
'
);
spyOn
(
state
,
'
reload
'
);
spyOn
(
kd
Delete
ReplicaSetService
,
'
showDeleteDialog
'
).
and
.
returnValue
(
deferred
.
promise
);
spyOn
(
kdReplicaSetService
,
'
showDeleteDialog
'
).
and
.
returnValue
(
deferred
.
promise
);
// when
// when
ctrl
.
showDeleteDialog
();
ctrl
.
showDeleteDialog
();
...
@@ -84,7 +84,7 @@ describe('Replica set card menu controller', () => {
...
@@ -84,7 +84,7 @@ describe('Replica set card menu controller', () => {
let
deferred
=
$q
.
defer
();
let
deferred
=
$q
.
defer
();
spyOn
(
$log
,
'
error
'
);
spyOn
(
$log
,
'
error
'
);
spyOn
(
state
,
'
reload
'
);
spyOn
(
state
,
'
reload
'
);
spyOn
(
kd
Delete
ReplicaSetService
,
'
showDeleteDialog
'
).
and
.
returnValue
(
deferred
.
promise
);
spyOn
(
kdReplicaSetService
,
'
showDeleteDialog
'
).
and
.
returnValue
(
deferred
.
promise
);
// when
// when
ctrl
.
showDeleteDialog
();
ctrl
.
showDeleteDialog
();
...
@@ -97,4 +97,23 @@ describe('Replica set card menu controller', () => {
...
@@ -97,4 +97,23 @@ describe('Replica set card menu controller', () => {
expect
(
state
.
reload
).
not
.
toHaveBeenCalled
();
expect
(
state
.
reload
).
not
.
toHaveBeenCalled
();
expect
(
$log
.
error
).
toHaveBeenCalled
();
expect
(
$log
.
error
).
toHaveBeenCalled
();
}));
}));
it
(
'
should show update replicas dialog
'
,
()
=>
{
// given
ctrl
.
replicaSet
=
{
namespace
:
''
,
name
:
''
,
pods
:
{
current
:
1
,
desired
:
1
,
},
};
spyOn
(
kdReplicaSetService
,
'
showUpdateReplicasDialog
'
);
// when
ctrl
.
showUpdateReplicasDialog
();
// then
expect
(
kdReplicaSetService
.
showUpdateReplicasDialog
).
toHaveBeenCalled
();
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录