Skip to content

Commit

Permalink
Adding NG-Grid 2.0.7 deployables and plugins.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesfrk7 committed Jul 15, 2013
1 parent 8b6cd95 commit 1531466
Show file tree
Hide file tree
Showing 15 changed files with 4,329 additions and 0 deletions.
76 changes: 76 additions & 0 deletions ajax/libs/ng-grid/2.0.7/ng-grid-csv-export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Todo:
// 1) Make the button prettier
// 2) add a config option for IE users which takes a URL. That URL should accept a POST request with a
// JSON encoded object in the payload and return a CSV. This is necessary because IE doesn't let you
// download from a data-uri link
//
// Notes: This has not been adequately tested and is very much a proof of concept at this point
function ngGridCsvExportPlugin (opts) {
var self = this;
self.grid = null;
self.scope = null;
self.init = function(scope, grid, services) {
self.grid = grid;
self.scope = scope;
function showDs() {
var keys = [];
for (var f in grid.config.columnDefs) { keys.push(grid.config.columnDefs[f].field);}
var csvData = '';
function csvStringify(str) {
if (str == null) { // we want to catch anything null-ish, hence just == not ===
return '';
}
if (typeof(str) === 'number') {
return '' + str;
}
if (typeof(str) === 'boolean') {
return (str ? 'TRUE' : 'FALSE') ;
}
if (typeof(str) === 'string') {
return str.replace(/"/g,'""');
}

return JSON.stringify(str).replace(/"/g,'""');
}
function swapLastCommaForNewline(str) {
var newStr = str.substr(0,str.length - 1);
return newStr + "\n";
}
for (var k in keys) {
csvData += '"' + csvStringify(keys[k]) + '",';
}
csvData = swapLastCommaForNewline(csvData);
var gridData = grid.data;
for (var gridRow in gridData) {
for ( k in keys) {
var curCellRaw;
if (opts != null && opts.columnOverrides != null && opts.columnOverrides[keys[k]] != null) {
curCellRaw = opts.columnOverrides[keys[k]](gridData[gridRow][keys[k]]);
}
else {
curCellRaw = gridData[gridRow][keys[k]];
}
csvData += '"' + csvStringify(curCellRaw) + '",';
}
csvData = swapLastCommaForNewline(csvData);
}
var fp = grid.$root.find(".ngFooterPanel");
var csvDataLinkPrevious = grid.$root.find('.ngFooterPanel .csv-data-link-span');
if (csvDataLinkPrevious != null) {csvDataLinkPrevious.remove() ; }
var csvDataLinkHtml = "<span class=\"csv-data-link-span\">";
csvDataLinkHtml += "<br><a href=\"data:text/csv;charset=UTF-8,";
csvDataLinkHtml += encodeURIComponent(csvData);
csvDataLinkHtml += "\" download=\"Export.csv\">CSV Export</a></br></span>" ;
fp.append(csvDataLinkHtml);
}
setTimeout(showDs, 0);
scope.catHashKeys = function() {
var hash = '';
for (var idx in scope.renderedRows) {
hash += scope.renderedRows[idx].$$hashKey;
}
return hash;
};
scope.$watch('catHashKeys()', showDs);
};
}
1 change: 1 addition & 0 deletions ajax/libs/ng-grid/2.0.7/ng-grid-csv-export.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions ajax/libs/ng-grid/2.0.7/ng-grid-flexible-height.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function ngGridFlexibleHeightPlugin (opts) {
var self = this;
self.grid = null;
self.scope = null;
self.init = function (scope, grid, services) {
self.domUtilityService = services.DomUtilityService;
self.grid = grid;
self.scope = scope;
var recalcHeightForData = function () { setTimeout(innerRecalcForData, 1); };
var innerRecalcForData = function () {
var gridId = self.grid.gridId;
var footerPanelSel = '.' + gridId + ' .ngFooterPanel';
var extraHeight = self.grid.$topPanel.height() + $(footerPanelSel).height();
var naturalHeight = self.grid.$canvas.height() + 1;
if (opts != null) {
if (opts.minHeight != null && (naturalHeight + extraHeight) < opts.minHeight) {
naturalHeight = opts.minHeight - extraHeight - 2;
}
}

var newViewportHeight = naturalHeight + 2;
if (!self.scope.baseViewportHeight || self.scope.baseViewportHeight !== newViewportHeight) {
self.grid.$viewport.css('height', newViewportHeight + 'px');
self.grid.$root.css('height', (newViewportHeight + extraHeight) + 'px');
self.scope.baseViewportHeight = newViewportHeight;
self.domUtilityService.UpdateGridLayout(self.scope, self.grid);
}
};
self.scope.catHashKeys = function () {
var hash = '',
idx;
for (idx in self.scope.renderedRows) {
hash += self.scope.renderedRows[idx].$$hashKey;
}
return hash;
};
self.scope.$watch('catHashKeys()', innerRecalcForData);
self.scope.$watch(self.grid.config.data, recalcHeightForData);
};
}
1 change: 1 addition & 0 deletions ajax/libs/ng-grid/2.0.7/ng-grid-flexible-height.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions ajax/libs/ng-grid/2.0.7/ng-grid-layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function ngGridLayoutPlugin () {
var self = this;
this.grid = null;
this.scope = null;
this.init = function(scope, grid, services) {
self.domUtilityService = services.DomUtilityService;
self.grid = grid;
self.scope = scope;
};

this.updateGridLayout = function () {
if (!self.scope.$$phase) {
self.scope.$apply(function(){
self.domUtilityService.RebuildGrid(self.scope, self.grid);
});
}
else {
// $digest or $apply already in progress
self.domUtilityService.RebuildGrid(self.scope, self.grid);
}
};
}
1 change: 1 addition & 0 deletions ajax/libs/ng-grid/2.0.7/ng-grid-layout.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions ajax/libs/ng-grid/2.0.7/ng-grid-reorderable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
Reorderablr row plugin
*/

function ngGridReorderable () {
var self = this;
self.$scope = null;
self.myGrid = null;

// The init method gets called during the ng-grid directive execution.
self.init = function(scope, grid, services) {
// The directive passes in the grid scope and the grid object which we will want to save for manipulation later.
self.$scope = scope;
self.myGrid = grid;
self.services = services;
// In this example we want to assign grid events.
self.assignEvents();
};
self.colToMove = undefined;
self.groupToMove = undefined;
self.assignEvents = function() {
// Here we set the onmousedown event handler to the header container.
self.myGrid.$viewport.on('mousedown', self.onRowMouseDown).on('dragover', self.dragOver).on('drop', self.onRowDrop);
};
// Row functions
self.onRowMouseDown = function(event) {
// Get the closest row element from where we clicked.
var targetRow = $(event.target).closest('.ngRow');
// Get the scope from the row element
var rowScope = angular.element(targetRow).scope();
if (rowScope) {
// set draggable events
targetRow.attr('draggable', 'true');
// Save the row for later.
self.services.DomUtilityService.eventStorage.rowToMove = { targetRow: targetRow, scope: rowScope };
}
};
self.onRowDrop = function(event) {
// Get the closest row to where we dropped
var targetRow = $(event.target).closest('.ngRow');
// Get the scope from the row element.
var rowScope = angular.element(targetRow).scope();
if (rowScope) {
// If we have the same Row, do nothing.
var prevRow = self.services.DomUtilityService.eventStorage.rowToMove;
if (prevRow.scope.row === rowScope.row) {
return;
}
self.changeRowOrder(prevRow.scope.row, rowScope.row);
grid.searchProvider.evalFilter();
// clear out the rowToMove object
self.services.DomUtilityService.eventStorage.rowToMove = undefined;
// if there isn't an apply already in progress lets start one
self.services.DomUtilityService.digest(rowScope.$root);
}
};
self.changeRowOrder = function (prevRow, targetRow) {
// Splice the Rows via the actual datasource
var i = self.rowCache.indexOf(prevRow);
var j = self.rowCache.indexOf(targetRow);
self.myGrid.rowCache.splice(i, 1);
self.myGrid.rowCache.splice(j, 0, prevRow);
self.$scope.$emit('ngGridEventChangeOrder', self.rowCache);
};
self.dragOver = function(evt) {
evt.preventDefault();
};
}
1 change: 1 addition & 0 deletions ajax/libs/ng-grid/2.0.7/ng-grid-reorderable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions ajax/libs/ng-grid/2.0.7/ng-grid-wysiwyg-export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function ngGridWYSIWYGPlugin (filter) {
var self = this;
self.grid = null;
self.scope = null;
self.services = null;

self.init = function (scope, grid, services) {
self.grid = grid;
self.scope = scope;
self.services = services;
};

self.exportData = function () {
var ret = {
columns: [],
columnWidths: [],
gridWidth: self.scope.totalRowWidth(),
data: []
};

angular.forEach(self.scope.columns, function (col) {
if (col.visible) {
ret.columns.push(col.displayName);
ret.columnWidths.push(col.width);
}
});
angular.forEach(self.grid.filteredRows, function (row) {
var item = row.entity;
angular.forEach(self.scope.columns, function (col) {
if (col.visible) {
var obj = self.services.UtilityService.evalProperty(item, col.field);
var val = col.cellFilter && filter ? filter(col.cellFilter)(obj) : obj;
ret.data.push(val ? val.toString() : '');
}
});
});
return ret;
};
}
1 change: 1 addition & 0 deletions ajax/libs/ng-grid/2.0.7/ng-grid-wysiwyg-export.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1531466

Please sign in to comment.