Skip to content

Commit

Permalink
Add toolbar settings service provider
Browse files Browse the repository at this point in the history
toolbar setting service provider is for fetching data based on which toolbar will be created. These data does not contain function calls to handle events so we have to bind specific function based on IDs of these toolbar items
  • Loading branch information
karelhala committed May 25, 2016
1 parent 0bf1669 commit 7f8de14
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 50 deletions.
13 changes: 6 additions & 7 deletions demo/controllers/toolbarMenuController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@

export default class ToolbarMenuController {
public toolbarMenu: any;
public constructor(private $http: any) {
this.$http({
method: 'GET',
url: '/data/toolbar.json'
}).then((responseData) => {
this.toolbarMenu = responseData.data;
});

public constructor(private MiQToolbarSettingsService: any) {
this.MiQToolbarSettingsService.getSettings(true)
.then(dataResponse => {
this.toolbarMenu = dataResponse;
});
}
}
139 changes: 106 additions & 33 deletions demo/data/toolbar.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,108 @@
[
{
"title": "Configuration",
"icon": "fa fa-cog fa-lg",
"children": [
{
"id": "new_provider",
"title": "Add a New Middleware Provider",
"icon": "pficon pficon-add-circle-o fa-lg"
},
{
"title": "Edit Selected Middleware Provider",
"disabled": true,
"icon": "pficon pficon-edit fa-lg"
},
{
"title": "Remove Middleware Providers from the VMDB",
"disabled": true,
"icon": "pficon pficon-delete fa-lg"
}
]
},
{
"title": "Policy",
"icon": "fa fa-shield fa-lg",
"disabled": true,
"children": [
{
"title": "Edit Tags",
"disabled": true,
"icon": "pficon pficon-edit fa-lg"
}
]
}
[
{
"id": "ems_middleware_vmdb_choice",
"type": "buttonSelect",
"img": "ems_middleware_vmdb_choice.png",
"imgdis": "ems_middleware_vmdb_choice.png",
"icon": "fa fa-cog fa-lg",
"name": "ems_middleware_vmdb_choice",
"hidden": false,
"pressed": null,
"onwhen": null,
"data": null,
"enabled": true,
"title": "Configuration",
"text": "Configuration",
"items": [
{
"child_id": "ems_middleware_new",
"id": "ems_middleware_vmdb_choice__ems_middleware_new",
"type": "button",
"img": "ems_middleware_new.png",
"imgdis": "ems_middleware_new.png",
"icon": "pficon pficon-add-circle-o fa-lg",
"name": "ems_middleware_vmdb_choice__ems_middleware_new",
"hidden": false,
"pressed": null,
"onwhen": null,
"data": null,
"enabled": true,
"title": "Add a New Middleware Provider",
"text": "Add a New Middleware Provider",
"url": "/new"
},
{
"child_id": "ems_middleware_edit",
"id": "ems_middleware_vmdb_choice__ems_middleware_edit",
"type": "button",
"img": "ems_middleware_edit.png",
"imgdis": "ems_middleware_edit.png",
"icon": "pficon pficon-edit fa-lg",
"name": "ems_middleware_vmdb_choice__ems_middleware_edit",
"hidden": false,
"pressed": null,
"onwhen": "1",
"data": null,
"enabled": false,
"title": "Select a single Middleware Provider to edit",
"text": "Edit Selected Middleware Provider",
"url_parms": "main_div"
},
{
"child_id": "ems_middleware_delete",
"id": "ems_middleware_vmdb_choice__ems_middleware_delete",
"type": "button",
"img": "ems_middleware_delete.png",
"imgdis": "ems_middleware_delete.png",
"icon": "pficon pficon-delete fa-lg",
"name": "ems_middleware_vmdb_choice__ems_middleware_delete",
"hidden": false,
"pressed": null,
"onwhen": "1+",
"data": null,
"enabled": false,
"title": "Remove selected Middleware Providers from the VMDB",
"text": "Remove Middleware Providers from the VMDB",
"confirm": "Warning: The selected Middleware Providers and ALL of their components will be permanently removed from the Virtual Management Database. Are you sure you want to remove the selected Middleware Providers?",
"url_parms": "main_div"
}
]
},
{
"id": "ems_middleware_policy_choice",
"type": "buttonSelect",
"img": "ems_middleware_policy_choice.png",
"imgdis": "ems_middleware_policy_choice.png",
"icon": "fa fa-shield fa-lg",
"name": "ems_middleware_policy_choice",
"hidden": false,
"pressed": null,
"onwhen": "1+",
"data": null,
"enabled": false,
"title": "Policy",
"text": "Policy",
"items": [
{
"child_id": "ems_middleware_tag",
"id": "ems_middleware_policy_choice__ems_middleware_tag",
"type": "button",
"img": "ems_middleware_tag.png",
"imgdis": "ems_middleware_tag.png",
"icon": "pficon pficon-edit fa-lg",
"name": "ems_middleware_policy_choice__ems_middleware_tag",
"hidden": false,
"pressed": null,
"onwhen": "1+",
"data": null,
"enabled": false,
"title": "Edit Tags for this Middleware Provider",
"text": "Edit Tags",
"url_parms": "main_div"
}
]
}
],
null
]
9 changes: 8 additions & 1 deletion demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ import controllers from './controllers/loader';

const app = angular.module('demoApp', ['miQStaticAssets', 'ui.bootstrap', 'ui.router',
'patternfly.select', 'ui.bootstrap.tabs', 'patternfly.views', 'ngAnimate']);
app.config((MiQDataAccessServiceProvider: any, MiQDataTableServiceProvider: any) => {
app.config((MiQDataAccessServiceProvider: any,
MiQDataTableServiceProvider: any,
MiQToolbarSettingsServiceProvider: any) => {
MiQDataTableServiceProvider.endpoints = {
list: '/data-table.json'
};

MiQDataAccessServiceProvider.setUrlPrefix('/data');

MiQToolbarSettingsServiceProvider.endpoints = {
settings: '/toolbar.json'
};
});
controllers(app);
views(app);
64 changes: 59 additions & 5 deletions dist/js/hawkular-ui-components.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/components/toolbar-menu/toolbar-list.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div class="btn-group" dropdown>
<button type="button" dropdown-toggle class="btn dropdown-toggle btn-default"
ng-class="{disabled: toolbarList.disabled}" title="{{toolbarList.title}}">
ng-class="{disabled: !toolbarList.enabled}" title="{{toolbarList.title}}">
<i class="{{toolbarList.icon}}" style="margin-right: 5px;" ng-if="toolbarList.icon"></i>
{{toolbarList.title}}
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li ng-repeat="item in toolbarList.children" ng-class="{disabled: item.disabled}">
<li ng-repeat="item in toolbarList.items" ng-class="{disabled: !item.enabled}">
<a href="javascript:void(0)" ng-click="onItemClick({item: item})">
<i ng-if="item.icon" class="{{item.icon}}"></i>
{{item.title}}
Expand Down
4 changes: 2 additions & 2 deletions src/components/toolbar-menu/toolbar-menu.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="toolbar-pf-actions miq-toolbar-actions">
<div class="form-group">
<miq-toolbar-list ng-repeat="item in vm.toolbarItems | filter: children"
<div class="form-group" ng-repeat="toolbarItem in vm.toolbarItems">
<miq-toolbar-list ng-repeat="item in toolbarItem | filter: items"
toolbar-list="item"
on-item-click="vm.onItemClick(item)">
</miq-toolbar-list>
Expand Down
2 changes: 2 additions & 0 deletions src/services/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import DataTableService from './dataTableService';
import FormValidatorService from './formValidatorService';
import NotificationService from './notificationService';
import ToolbarSettingsService from './toolbarSettingsService';

export default (module: ng.IModule) => {
module.provider('MiQDataTableService', DataTableService);
module.provider('MiQFormValidatorService', FormValidatorService);
module.provider('MiQToolbarSettingsService', ToolbarSettingsService);
module.service('MiQNotificationService', NotificationService);
}
42 changes: 42 additions & 0 deletions src/services/toolbarSettingsService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
///
/// Copyright 2015-2016 Red Hat, Inc. and/or its affiliates
/// and other contributors as indicated by the @author tags.
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///

///<reference path="../tsd.d.ts"/>
export default class ToolbarSettingsService {
private $http: any;
private MiQDataAccessService: any;
public endpoints = {
settings : '/toolbar_settings'
};

public getSettings(isList = false) {
return this.httpGet(this.MiQDataAccessService.getUrlPrefix() + this.endpoints.settings, {'is_list': isList});
}

private httpGet(url: string, dataObject: any): any {
return this.$http.get(url, {params: dataObject})
.then(dataResponse => dataResponse.data);
}
/*@ngInject*/
public $get($http: any, MiQDataAccessService: any): any {
this.$http = $http;
this.MiQDataAccessService = MiQDataAccessService;
return {
getSettings: (isList) => this.getSettings(isList)
};
}
}

0 comments on commit 7f8de14

Please sign in to comment.