redash/client/app/services/dashboard.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

import { map, isArray } from 'underscore';
function Dashboard($resource, $http, currentUser, Widget) {
function transformSingle(dashboard) {
dashboard.widgets = map(dashboard.widgets, row => row.map(widget => new Widget(widget)));
dashboard.publicAccessEnabled = dashboard.public_url !== undefined;
}
const transform = $http.defaults.transformResponse.concat((data) => {
if (isArray(data)) {
data.forEach(transformSingle);
} else {
transformSingle(data);
}
return data;
});
const resource = $resource('api/dashboards/:slug', { slug: '@slug' }, {
get: { method: 'GET', transformResponse: transform },
save: { method: 'POST', transformResponse: transform },
2016-11-16 13:34:11 +00:00
query: { method: 'GET', isArray: true, transformResponse: transform },
recent: {
method: 'get',
isArray: true,
url: 'api/dashboards/recent',
transformResponse: transform,
2016-11-21 09:31:48 +00:00
},
2016-11-16 13:05:43 +00:00
});
resource.prototype.canEdit = function canEdit() {
return currentUser.canEdit(this) || this.can_edit;
};
return resource;
}
export default function (ngModule) {
ngModule.factory('Dashboard', Dashboard);
}