Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates slick lib files #116

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion qgrid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def template_contents(filename):

SLICK_GRID_CSS = template_contents('slickgrid.css.template')
SLICK_GRID_JS = template_contents('slickgrid.js.template')
REMOTE_URL = ("https://cdn.rawgit.com/quantopian/qgrid/"
REMOTE_URL = ("https://cdn.rawgit.com/sbremer/qgrid/"
"73eaa7adf1762f66eaf4d30ed9cbf385a7e9d9fa/qgrid/qgridjs/")
LOCAL_URL = "/nbextensions/qgridjs"

Expand Down
210 changes: 194 additions & 16 deletions qgrid/qgridjs/lib/slick.core.2.2.js → qgrid/qgridjs/lib/slick.core.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
/***
* @license
* (c) 2009-2013 Michael Leibman
* michael{dot}leibman{at}gmail{dot}com
* http://github.com/mleibman/slickgrid
*
* Distributed under MIT license.
* All rights reserved.
*
* Contains core SlickGrid classes.
* @module Core
* @namespace Slick
*/

(function ($) {
// CommonJS, AMD or browser globals
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS
module.exports = factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
// register namespace
$.extend(true, window, {
"Slick": {
Expand All @@ -31,7 +35,8 @@
* @static
* @constructor
*/
"GlobalEditorLock": new EditorLock()
"GlobalEditorLock": new EditorLock(),
"TreeColumns": TreeColumns
}
});

Expand Down Expand Up @@ -155,7 +160,7 @@
var i = handlers.length;
while (i--) {
if (handlers[i].event === event &&
handlers[i].handler === handler) {
handlers[i].handler === handler) {
handlers.splice(i, 1);
event.unsubscribe(handler);
return;
Expand Down Expand Up @@ -242,7 +247,7 @@
*/
this.contains = function (row, cell) {
return row >= this.fromRow && row <= this.toRow &&
cell >= this.fromCell && cell <= this.toCell;
cell >= this.fromCell && cell <= this.toCell;
};

/***
Expand Down Expand Up @@ -355,9 +360,9 @@
*/
Group.prototype.equals = function (group) {
return this.value === group.value &&
this.count === group.count &&
this.collapsed === group.collapsed &&
this.title === group.title;
this.count === group.count &&
this.collapsed === group.collapsed &&
this.title === group.title;
};

/***
Expand Down Expand Up @@ -470,6 +475,179 @@
return (activeEditController ? activeEditController.cancelCurrentEdit() : true);
};
}
})(jQuery);

/**
*
* @param {Array} treeColumns Array com levels of columns
* @returns {{hasDepth: 'hasDepth', getTreeColumns: 'getTreeColumns', extractColumns: 'extractColumns', getDepth: 'getDepth', getColumnsInDepth: 'getColumnsInDepth', getColumnsInGroup: 'getColumnsInGroup', visibleColumns: 'visibleColumns', filter: 'filter', reOrder: reOrder}}
* @constructor
*/
function TreeColumns(treeColumns) {

var columnsById = {};

function init() {
mapToId(treeColumns);
}

function mapToId(columns) {
columns
.forEach(function (column) {
columnsById[column.id] = column;

if (column.columns)
mapToId(column.columns);
});
}

function filter(node, condition) {

return node.filter(function (column) {

var valid = condition.call(column);

if (valid && column.columns)
column.columns = filter(column.columns, condition);

return valid && (!column.columns || column.columns.length);
});

}

function sort(columns, grid) {
columns
.sort(function (a, b) {
var indexA = getOrDefault(grid.getColumnIndex(a.id)),
indexB = getOrDefault(grid.getColumnIndex(b.id));

return indexA - indexB;
})
.forEach(function (column) {
if (column.columns)
sort(column.columns, grid);
});
}

function getOrDefault(value) {
return typeof value === 'undefined' ? -1 : value;
}

function getDepth(node) {
if (node.length)
for (var i in node)
return getDepth(node[i]);
else if (node.columns)
return 1 + getDepth(node.columns);
else
return 1;
}

function getColumnsInDepth(node, depth, current) {
var columns = [];
current = current || 0;

if (depth == current) {

if (node.length)
node.forEach(function(n) {
if (n.columns)
n.extractColumns = function() {
return extractColumns(n);
};
});

return node;
} else
for (var i in node)
if (node[i].columns) {
columns = columns.concat(getColumnsInDepth(node[i].columns, depth, current + 1));
}

return columns;
}

function extractColumns(node) {
var result = [];

if (node.hasOwnProperty('length')) {

for (var i = 0; i < node.length; i++)
result = result.concat(extractColumns(node[i]));

} else {

if (node.hasOwnProperty('columns'))

result = result.concat(extractColumns(node.columns));

else
return node;

}

return result;
}

function cloneTreeColumns() {
return $.extend(true, [], treeColumns);
}

init();

this.hasDepth = function () {

for (var i in treeColumns)
if (treeColumns[i].hasOwnProperty('columns'))
return true;

return false;
};

this.getTreeColumns = function () {
return treeColumns;
};

this.extractColumns = function () {
return this.hasDepth()? extractColumns(treeColumns): treeColumns;
};

this.getDepth = function () {
return getDepth(treeColumns);
};

this.getColumnsInDepth = function (depth) {
return getColumnsInDepth(treeColumns, depth);
};

this.getColumnsInGroup = function (groups) {
return extractColumns(groups);
};

this.visibleColumns = function () {
return filter(cloneTreeColumns(), function () {
return this.visible;
});
};

this.filter = function (condition) {
return filter(cloneTreeColumns(), condition);
};

this.reOrder = function (grid) {
return sort(treeColumns, grid);
};

this.getById = function (id) {
return columnsById[id];
};

this.getInIds = function (ids) {
return ids.map(function (id) {
return columnsById[id];
});
}
}

}));


Loading