mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 01:25:16 +00:00
gridstack: add comments, exclude lodash and moment locales from bundle
This commit is contained in:
parent
2fbf8926c4
commit
61ef5f9a02
@ -101,6 +101,10 @@ function gridstack($parse, dashboardGridOptions) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.batchUpdateWidgets = (items) => {
|
this.batchUpdateWidgets = (items) => {
|
||||||
|
// This method is used to update multiple widgets with a single
|
||||||
|
// reflow (for example, restore positions when dashboard editing cancelled).
|
||||||
|
// "dirty" part of code: updating grid and DOM nodes directly.
|
||||||
|
// layout reflow is triggered by `batchUpdate`/`commit` calls
|
||||||
this.update((grid) => {
|
this.update((grid) => {
|
||||||
_.each(grid.grid.nodes, (node) => {
|
_.each(grid.grid.nodes, (node) => {
|
||||||
const item = items[node.id];
|
const item = items[node.id];
|
||||||
@ -167,11 +171,14 @@ function gridstack($parse, dashboardGridOptions) {
|
|||||||
this.getNodeByElement = (element) => {
|
this.getNodeByElement = (element) => {
|
||||||
const grid = this.grid();
|
const grid = this.grid();
|
||||||
if (grid && grid.grid) {
|
if (grid && grid.grid) {
|
||||||
|
// This method seems to be internal
|
||||||
return grid.grid.getNodeDataByDOMEl($(element));
|
return grid.grid.getNodeDataByDOMEl($(element));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.setWidgetId = ($element, id) => {
|
this.setWidgetId = ($element, id) => {
|
||||||
|
// `gridstack` has no API method to change node id; but since it's not used
|
||||||
|
// by library, we can just update grid and DOM node
|
||||||
const node = this.getNodeByElement($element);
|
const node = this.getNodeByElement($element);
|
||||||
if (node) {
|
if (node) {
|
||||||
node.id = id;
|
node.id = id;
|
||||||
@ -198,6 +205,8 @@ function gridstack($parse, dashboardGridOptions) {
|
|||||||
if (_.isFunction(callback)) {
|
if (_.isFunction(callback)) {
|
||||||
callback(grid);
|
callback(grid);
|
||||||
}
|
}
|
||||||
|
// `_updateStyles` is internal, but grid sometimes "forgets"
|
||||||
|
// to rebuild stylesheet, so we need to force it
|
||||||
grid._updateStyles(grid.grid.getGridHeight());
|
grid._updateStyles(grid.grid.getGridHeight());
|
||||||
} finally {
|
} finally {
|
||||||
grid.commit();
|
grid.commit();
|
||||||
@ -295,18 +304,25 @@ function gridstack($parse, dashboardGridOptions) {
|
|||||||
controller.$el = null;
|
controller.$el = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// `gridstack` does not provide API to detect when one-column mode changes.
|
||||||
|
// Just watch `$element` for specific class
|
||||||
function updateOneColumnMode() {
|
function updateOneColumnMode() {
|
||||||
const grid = controller.grid();
|
const grid = controller.grid();
|
||||||
if (grid) {
|
if (grid) {
|
||||||
$scope.isOneColumnMode = $element.hasClass(grid.opts.oneColumnModeClass);
|
const isOneColumnMode = $element.hasClass(grid.opts.oneColumnModeClass);
|
||||||
|
if ($scope.isOneColumnMode !== isOneColumnMode) {
|
||||||
|
$scope.isOneColumnMode = isOneColumnMode;
|
||||||
$scope.$applyAsync();
|
$scope.$applyAsync();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (enablePolling) {
|
if (enablePolling) {
|
||||||
setTimeout(updateOneColumnMode, 150);
|
setTimeout(updateOneColumnMode, 150);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start polling only if we can update scope binding; otherwise it
|
||||||
|
// will just waisting CPU time (example: public dashboards don't need it)
|
||||||
if (isOneColumnModeAssignable) {
|
if (isOneColumnModeAssignable) {
|
||||||
updateOneColumnMode();
|
updateOneColumnMode();
|
||||||
}
|
}
|
||||||
@ -329,6 +345,7 @@ function gridstackItem($timeout) {
|
|||||||
|
|
||||||
controller.addWidget($element, $scope.gridstackItem, $scope.gridstackItemId);
|
controller.addWidget($element, $scope.gridstackItem, $scope.gridstackItemId);
|
||||||
|
|
||||||
|
// these events are triggered only on user interaction
|
||||||
$element.on('gridstack.resize-start', () => {
|
$element.on('gridstack.resize-start', () => {
|
||||||
const node = controller.getNodeByElement($element);
|
const node = controller.getNodeByElement($element);
|
||||||
heightBeforeResize = _.isObject(node) ? node.height : null;
|
heightBeforeResize = _.isObject(node) ? node.height : null;
|
||||||
|
@ -33,7 +33,12 @@ const config = {
|
|||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': appPath
|
'@': appPath,
|
||||||
|
// Currently `lodash` is used only by `gridstack.js`, but it can work
|
||||||
|
// with `underscore` as well, so set an alias to avoid bundling both `lodash` and
|
||||||
|
// `underscore`. When adding new libraries, check if they can work
|
||||||
|
// with `underscore`, otherwise remove this line
|
||||||
|
'lodash': 'underscore',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
@ -43,6 +48,8 @@ const config = {
|
|||||||
}),
|
}),
|
||||||
// Enforce angular to use jQuery instead of jqLite
|
// Enforce angular to use jQuery instead of jqLite
|
||||||
new webpack.ProvidePlugin({'window.jQuery': 'jquery'}),
|
new webpack.ProvidePlugin({'window.jQuery': 'jquery'}),
|
||||||
|
// bundle only default `moment` locale (`en`)
|
||||||
|
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/),
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
new webpack.optimize.CommonsChunkPlugin({
|
||||||
name: 'vendor',
|
name: 'vendor',
|
||||||
minChunks: function (module, count) {
|
minChunks: function (module, count) {
|
||||||
|
Loading…
Reference in New Issue
Block a user