mirror of
https://github.com/valitydev/redash.git
synced 2024-11-08 18:03:54 +00:00
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
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 },
|
|
query: { method: 'GET', isArray: true, transformResponse: transform },
|
|
recent: {
|
|
method: 'get',
|
|
isArray: true,
|
|
url: 'api/dashboards/recent',
|
|
transformResponse: transform,
|
|
},
|
|
});
|
|
|
|
resource.prototype.canEdit = function canEdit() {
|
|
return currentUser.canEdit(this) || this.can_edit;
|
|
};
|
|
|
|
return resource;
|
|
}
|
|
|
|
export default function (ngModule) {
|
|
ngModule.factory('Dashboard', Dashboard);
|
|
}
|