Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Handle creating and duplicating dashboards in the dashboard repositor…
…y, add a getType() operation so the UI can enable controls based on the repository type
  • Loading branch information
gashcrumb committed Sep 19, 2013
1 parent 5df43a5 commit e4ad4c5
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 19 deletions.
Expand Up @@ -10,6 +10,12 @@ module Dashboard {

getDashboard: (id:string, fn) => any;

createDashboard: (options:any) => any;

cloneDashboard:(dashboard:any) => any;

getType:() => string;

}

/**
Expand Down Expand Up @@ -46,6 +52,19 @@ module Dashboard {
this.getRepository().getDashboard(id, onLoad);
}


public createDashboard(options:any) {
return this.getRepository().createDashboard(options);
}

public cloneDashboard(dashboard:any) {
return this.getRepository().cloneDashboard(dashboard);
}

public getType() {
return this.getRepository().getType();
}

/**
* Looks up the MBean in the JMX tree
*/
Expand All @@ -67,12 +86,16 @@ module Dashboard {
id: "m1", title: "Monitor", group: "Personal",
widgets: [
{ id: "w1", title: "Operating System", row: 1, col: 1,
size_x: 3,
size_y: 4,
path: "jmx/attributes",
include: "app/jmx/html/attributes.html",
search: {nid: "root-java.lang-OperatingSystem"},
hash: ""
},
{ id: "w2", title: "Broker", row: 1, col: 2,
{ id: "w2", title: "Broker", row: 1, col: 4,
size_x: 3,
size_y: 4,
path: "jmx/attributes",
include: "app/jmx/html/attributes.html",
search: {nid: "root-org.apache.activemq-broker1-Broker"},
Expand All @@ -84,6 +107,8 @@ module Dashboard {
id: "t1", title: "Threading", group: "Admin",
widgets: [
{ id: "w1", title: "Operating System", row: 1, col: 1,
size_x: 3,
size_y: 4,
path: "jmx/attributes",
include: "app/jmx/html/attributes.html",
search: {nid: "root-java.lang-OperatingSystem"},
Expand Down Expand Up @@ -120,6 +145,28 @@ module Dashboard {
var dashboard = this.dashboards.find({id: id});
onLoad(dashboard);
}

public createDashboard(options:any) {
var answer ={
title: "New Dashboard",
group: "Personal",
widgets: []
};
answer = angular.extend(answer, options);
answer['id'] = Core.getUUID();
return answer;
}

public cloneDashboard(dashboard:any) {
var newDashboard = Object.clone(dashboard);
newDashboard['id'] = Core.getUUID();
newDashboard['title'] = "Copy of " + dashboard.title;
return newDashboard;
}

public getType() {
return 'local';
}
}

export class GitDashboardRepository implements DashboardRepository {
Expand All @@ -144,6 +191,27 @@ module Dashboard {
});
}

public createDashboard(options:any) {
var answer ={
title: "New Dashboard",
group: "Personal",
widgets: []
};
answer = angular.extend(answer, options);
answer['id'] = Core.getUUID();
return answer;
}

public cloneDashboard(dashboard:any) {
var newDashboard = Object.clone(dashboard);
newDashboard['id'] = Core.getUUID();
newDashboard['title'] = "Copy of " + dashboard.title;
return newDashboard;
}

public getType() {
return 'git';
}

public getDashboardPath(dash) {
// TODO assume a user dashboard for now
Expand Down
37 changes: 30 additions & 7 deletions hawtio-web/src/main/webapp/app/dashboard/js/editDashboards.ts
Expand Up @@ -27,7 +27,6 @@ module Dashboard {
},
data: 'repository.dashboards',
selectWithCheckboxOnly: true,
multiSelect: false,
showSelectionCheckbox: true,
columnDefs: [
{
Expand All @@ -42,6 +41,34 @@ module Dashboard {
]
};

// helpers so we can enable/disable parts of the UI depending on how
// dashboard data is stored
$scope.usingGit = () => {
return dashboardRepository.getType() === 'git';
};

$scope.usingFabric = () => {
return dashboardRepository.getType() === 'fabric';
};

$scope.usingLocal = () => {
return dashboardRepository.getType() === 'local';
};

if ($scope.usingFabric()) {
$scope.gridOptions.columnDefs.add([{
field: 'versionId',
displayName: 'Version'
}, {
field: 'profileId',
displayName: 'Profile'
}, {
field: 'fileName',
displayName: 'File Name'
}]);
}


// Okay, now this is needed :-)
$scope.$on("$routeChangeSuccess", function (event, current, previous) {
// lets do this asynchronously to avoid Error: $digest already in progress
Expand Down Expand Up @@ -148,9 +175,8 @@ module Dashboard {

$scope.create = () => {
var counter = dashboards().length + 1;
var id = Core.getUUID();
var title = "Untitled" + counter;
var newDash = {id: id, title: title, group: "Personal", widgets: []};
var newDash = dashboardRepository.createDashboard({title: title});

// TODO how to really add??
addDashboard(newDash, "Created new dashboard " + title);
Expand All @@ -160,11 +186,8 @@ module Dashboard {
angular.forEach($scope.selectedItems, (item, idx) => {
// lets unselect this item
$scope.selectedItems = $scope.selectedItems.splice(idx, 1);
var counter = dashboards().length + 1;
var id = Core.getUUID();
var widgets = item.widgets || [];
var commitMessage = "Duplicated dashboard " + item.title;
var newDash = {id: id, title: item.title + " Copy", group: item.group, widgets: widgets };
var newDash = dashboardRepository.cloneDashboard(item);
addDashboard(newDash, commitMessage);
});
};
Expand Down
Expand Up @@ -28,6 +28,7 @@ module Dashboard {
var jolokia = this.jolokia;
var details = this.details;
array.forEach((dashboard) => {
// console.log("Saving dash: ", dashboard);
var data = angular.toJson(dashboard, true);
var profileId = dashboard.profileId;
if (!profileId) {
Expand Down Expand Up @@ -62,6 +63,34 @@ module Dashboard {
});
}

public createDashboard(options:any) {
var answer ={
title: "New Dashboard",
group: "Fabric",
versionId: this.details.branch,
profileId: this.details.profiles.first(),
widgets: []
};
answer = angular.extend(answer, options);
var uuid = Core.getUUID();
answer['id'] = uuid;
answer['fileName'] = uuid + ".dashboard";
return answer;
}

public cloneDashboard(dashboard:any) {
var newDashboard = Object.clone(dashboard);
var uuid = Core.getUUID();
newDashboard['id'] = uuid;
newDashboard['fileName'] = uuid + ".dashboard";
newDashboard['title'] = "Copy of " + dashboard.title;
return newDashboard;
}

public getType() {
return 'fabric';
}

public getDashboards(fn) {

var jolokia = this.jolokia;
Expand All @@ -78,12 +107,18 @@ module Dashboard {
dashboard['versionId'] = details.branch;
dashboard['profileId'] = profile;
dashboard['fileName'] = configuration;

//console.log("Loading dashboard: ", dashboard);
dashboards.push(dashboard);
}
}
});
});

if (dashboards.isEmpty()) {
dashboards.push(this.createDashboard({}));
}

fn(dashboards);
}

Expand Down
13 changes: 2 additions & 11 deletions hawtio-web/src/main/webapp/app/dashboard/js/import.ts
Expand Up @@ -18,7 +18,7 @@ module Dashboard {
try {
json = JSON.parse($scope.source);
} catch (e) {
notification("ERROR", "Could not parse the JSON\n" + e);
notification("error", "Could not parse the JSON\n" + e);
json = [];
}
var array = [];
Expand All @@ -31,16 +31,7 @@ module Dashboard {
if (array.length) {
// lets ensure we have some valid ids and stuff...
angular.forEach(array, (dash, index) => {
var counter = index + 1;
if (!dash.id) {
dash.id = "imported" + counter;
}
if (!dash.title) {
dash.title = "Imported" + counter;
}
if (!dash.group) {
dash.group = "Personal";
}
angular.copy(dash, dashboardRepository.createDashboard(dash));
});
dashboardRepository.putDashboards(array, "Imported dashboard JSON", Dashboard.onOperationComplete);
$location.path("/dashboard/edit");
Expand Down

0 comments on commit e4ad4c5

Please sign in to comment.