mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
export sorted dashboard json
This commit is contained in:
parent
36929c2a92
commit
df1e90c723
23
public/app/core/utils/sort_by_keys.ts
Normal file
23
public/app/core/utils/sort_by_keys.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
export default function sortByKeys(input) {
|
||||
if (_.isArray(input)) {
|
||||
var newArray = [];
|
||||
_.forEach(
|
||||
input,
|
||||
function(item) { newArray.push(sortByKeys(item)); }
|
||||
);
|
||||
return newArray;
|
||||
}
|
||||
|
||||
if (_.isPlainObject(input)) {
|
||||
var sortedObject = {};
|
||||
_.forEach(
|
||||
_.keys(input).sort(),
|
||||
function(key) { sortedObject[key] = sortByKeys(input[key]); }
|
||||
);
|
||||
return sortedObject;
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
import config from 'app/core/config';
|
||||
import angular from 'angular';
|
||||
import _ from 'lodash';
|
||||
import sortByKeys from 'app/core/utils/sort_by_keys';
|
||||
|
||||
import {DynamicDashboardSrv} from '../dynamic_dashboard_srv';
|
||||
|
||||
@ -145,18 +146,14 @@ export class DashboardExporter {
|
||||
}
|
||||
}
|
||||
|
||||
requires = _.map(requires, req => {
|
||||
return req;
|
||||
});
|
||||
|
||||
// make inputs and requires a top thing
|
||||
var newObj = {};
|
||||
newObj["__inputs"] = inputs;
|
||||
newObj["__requires"] = requires;
|
||||
newObj["__requires"] = _.sortBy(requires, ['id']);
|
||||
|
||||
_.defaults(newObj, saveModel);
|
||||
|
||||
return newObj;
|
||||
return sortByKeys(newObj);
|
||||
}).catch(err => {
|
||||
console.log('Export failed:', err);
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user