Skip to content

Commit d7b0cec

Browse files
committed
Frontend for generic delete menu on list views (#735)
Please sync and test this :)
1 parent 5b450ec commit d7b0cec

38 files changed

+641
-295
lines changed

src/app/backend/resource/common/event.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ type EventList struct {
2929

3030
// Event is a single event representation.
3131
type Event struct {
32+
ObjectMeta ObjectMeta `json:"objectMeta"`
33+
TypeMeta TypeMeta `json:"typeMeta"`
34+
3235
// A human-readable description of the status of related object.
3336
Message string `json:"message"`
3437

src/app/backend/resource/common/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const (
9292
ResourceKindService = "service"
9393
ResourceKindDeployment = "deployment"
9494
ResourceKindPod = "pod"
95+
ResourceKindEvent = "event"
9596
ResourceKindReplicationController = "replicationcontroller"
9697
)
9798

@@ -101,6 +102,7 @@ const (
101102
var kindToAPIPathMapping = map[string]string{
102103
ResourceKindService: "services",
103104
ResourceKindPod: "pods",
105+
ResourceKindEvent: "events",
104106
ResourceKindReplicationController: "replicationcontrollers",
105107
ResourceKindDeployment: "deployments",
106108
ResourceKindReplicaSet: "replicasets",

src/app/backend/resource/event/eventcommon.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ func GetPodsEvents(client client.Interface, namespace string, resourceSelector m
7979
func AppendEvents(source []api.Event, target common.EventList) common.EventList {
8080
for _, event := range source {
8181
target.Events = append(target.Events, common.Event{
82+
ObjectMeta: common.NewObjectMeta(event.ObjectMeta),
83+
TypeMeta: common.NewTypeMeta(common.ResourceKindEvent),
8284
Message: event.Message,
8385
SourceComponent: event.Source.Component,
8486
SourceHost: event.Source.Host,

src/app/externs/backendapi.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ backendApi.EventList;
8686

8787
/**
8888
* @typedef {{
89+
* objectMeta: !backendApi.ObjectMeta,
90+
* typeMeta: !backendApi.TypeMeta,
8991
* message: string,
9092
* sourceComponent: string,
9193
* sourceHost: string,

src/app/frontend/common/components/resourcecard/resourcecard_component.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,30 @@ export class ResourceCardController {
2727
*/
2828
this.objectMeta;
2929

30+
/**
31+
* Initialized from a binding.
32+
* @export {!backendApi.TypeMeta}
33+
*/
34+
this.typeMeta;
35+
3036
/**
3137
* Initialized from require just before $onInit is called.
3238
* @export {!./resourcecardlist_component.ResourceCardListController}
3339
*/
3440
this.resourceCardListCtrl;
3541
}
3642

43+
/** @export */
44+
$onInit() {
45+
if (!this.objectMeta) {
46+
throw new Error('object-meta binding is required for resource card component');
47+
}
48+
49+
if (!this.typeMeta) {
50+
throw new Error('type-meta binding is required for resource card component');
51+
}
52+
}
53+
3754
/**
3855
* @return {boolean}
3956
* @export
@@ -54,8 +71,10 @@ export class ResourceCardController {
5471
*/
5572
export const resourceCardComponent = {
5673
bindings: {
57-
/** type {!backendApi.ObjectMeta} Metadata of the resource displayed in the card. */
74+
/** type {!backendApi.ObjectMeta} Object metadata of the resource displayed in the card. */
5875
'objectMeta': '<',
76+
/** type {!backendApi.TypeMeta} Type metadata of the resource displayed in the card. */
77+
'typeMeta': '<',
5978
},
6079
controller: ResourceCardController,
6180
templateUrl: 'common/components/resourcecard/resourcecard.html',

src/app/frontend/common/components/resourcecard/resourcecard_module.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import resourceModule from 'common/resource/resource_module';
1516
import {resourceCardComponent} from './resourcecard_component';
1617
import {resourceCardListComponent} from './resourcecardlist_component';
18+
import {resourceCardMenuComponent} from './resourcecardmenu_component';
19+
import {resourceCardDeleteMenuItemComponent} from './resourcecarddeletemenuitem_component';
1720
import {resourceCardColumnComponent} from './resourcecardcolumn_component';
1821
import {resourceCardColumnsComponent} from './resourcecardcolumns_component';
1922
import {resourceCardHeaderColumnComponent} from './resourcecardheadercolumn_component';
@@ -29,9 +32,13 @@ export default angular
2932
'kubernetesDashboard.common.components.resourcecard',
3033
[
3134
'ngMaterial',
35+
'ui.router',
36+
resourceModule.name,
3237
])
3338
.component('kdResourceCard', resourceCardComponent)
3439
.component('kdResourceCardList', resourceCardListComponent)
40+
.component('kdResourceCardMenu', resourceCardMenuComponent)
41+
.component('kdResourceCardDeleteMenuItem', resourceCardDeleteMenuItemComponent)
3542
.component('kdResourceCardColumn', resourceCardColumnComponent)
3643
.component('kdResourceCardColumns', resourceCardColumnsComponent)
3744
.component('kdResourceCardHeaderColumn', resourceCardHeaderColumnComponent)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!--
2+
Copyright 2015 Google Inc. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<md-menu-item>
18+
<md-button ng-click="$ctrl.remove()">
19+
Delete
20+
</md-button>
21+
</md-menu-item>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright 2015 Google Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* Controller for the resource card delete menu item component. It deletes card's resource.
17+
* @final
18+
*/
19+
export class ResourceCardDeleteMenuItemController {
20+
/**
21+
* @param {!./../../resource/verber_service.VerberService} kdResourceVerberService
22+
* @param {!ui.router.$state} $state
23+
* @param {!md.$dialog} $mdDialog
24+
* @ngInject
25+
*/
26+
constructor(kdResourceVerberService, $state, $mdDialog) {
27+
/**
28+
* Initialized from require just before $onInit is called.
29+
* @export {!./resourcecard_component.ResourceCardController}
30+
*/
31+
this.resourceCardCtrl;
32+
33+
/** @export {string} Initialized from a binding.*/
34+
this.resourceKindName;
35+
36+
/** @private {!./../../resource/verber_service.VerberService} */
37+
this.kdResourceVerberService_ = kdResourceVerberService;
38+
39+
/** @private {!ui.router.$state}} */
40+
this.state_ = $state;
41+
42+
/** @private {!md.$dialog} */
43+
this.mdDialog_ = $mdDialog;
44+
}
45+
46+
/**
47+
* @export
48+
*/
49+
remove() {
50+
this.kdResourceVerberService_
51+
.showDeleteDialog(
52+
this.resourceKindName, this.resourceCardCtrl.typeMeta, this.resourceCardCtrl.objectMeta)
53+
.then(
54+
() => {
55+
// For now just reload the state. Later we can remove the item in place.
56+
this.state_.reload();
57+
},
58+
(/** angular.$http.Response|null */ err) => {
59+
if (err) {
60+
// Show dialog if there was an error, not user canceling dialog.
61+
this.mdDialog_.show(this.mdDialog_.alert()
62+
.ok('Ok')
63+
.title(err.statusText || 'Internal server error')
64+
.textContent(err.data || 'Could not delete the resource'));
65+
}
66+
});
67+
}
68+
}
69+
70+
/**
71+
* @type {!angular.Component}
72+
*/
73+
export const resourceCardDeleteMenuItemComponent = {
74+
templateUrl: 'common/components/resourcecard/resourcecarddeletemenuitem.html',
75+
bindings: {
76+
'resourceKindName': '@',
77+
},
78+
bindToController: true,
79+
require: {
80+
'resourceCardCtrl': '^kdResourceCard',
81+
},
82+
controller: ResourceCardDeleteMenuItemController,
83+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!--
2+
Copyright 2015 Google Inc. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<md-menu>
18+
<md-button ng-click="$mdOpenMenu($event)" class="md-icon-button">
19+
<md-icon md-font-library="material-icons">more_vert</md-icon>
20+
<md-tooltip>Actions</md-tooltip>
21+
</md-button>
22+
<md-menu-content ng-transclude>
23+
</md-menu-content>
24+
</md-menu>

src/app/frontend/replicationcontrollerdetail/deletereplicationcontroller.scss renamed to src/app/frontend/common/components/resourcecard/resourcecardmenu_component.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
@import '../variables';
16-
17-
md-checkbox {
18-
&.kd-deletedialog-services-checkbox {
19-
margin: $baseline-grid 0 0 $baseline-grid;
20-
}
21-
}
22-
23-
.kd-deletedialog-info-icon {
24-
font-size: $subhead-font-size-base;
25-
height: $subhead-font-size-base;
26-
line-height: $caption-font-size-base;
27-
margin-left: $baseline-grid / 2;
28-
}
15+
/**
16+
* Resource card header columns component. See resource card list for documentation.
17+
* @type {!angular.Component}
18+
*/
19+
export const resourceCardMenuComponent = {
20+
templateUrl: 'common/components/resourcecard/resourcecardmenu.html',
21+
transclude: true,
22+
};

0 commit comments

Comments
 (0)