angular-ng-grid-plugins-rails 2.0.7.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 iniciontingookou
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,25 @@
1
+ # angular-ng-grid-rails
2
+
3
+ angular-ng-grid-rails wraps the [AngularJS ng-grid](http://angular-ui.github.io/ng-grid/) component for use in Rails 3.1 and above. Assets will minify automatically during production.
4
+
5
+ ## Usage
6
+
7
+ Add the following to your gemfile:
8
+
9
+ gem 'angular-ng-grid-plugins-rails'
10
+
11
+ Add the following directive to your Javascript manifest file (application.js):
12
+
13
+ //= require angular-ng-grid-plugins
14
+
15
+ ## Version
16
+
17
+ The gem version will try match the original ng-grid release version.
18
+
19
+ # License
20
+
21
+ MIT
22
+
23
+ # Thanks
24
+
25
+ Gem based on Angularjs-rails(https://github.com/confuseddesi/angularjs-rails) by Hirav Gandhi
@@ -0,0 +1,8 @@
1
+ require "angular-ng-grid-plugins-rails/version"
2
+
3
+ module AngularNgGridPlugins
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module AngularNgGridPlugins
2
+ module Rails
3
+ VERSION = "2.0.7.2"
4
+ end
5
+ end
@@ -0,0 +1,43 @@
1
+ Notes
2
+ =====
3
+
4
+ For anyone else writing plugins, please feel free to add to this readme.
5
+
6
+ Flexible-Height
7
+ ===============
8
+
9
+ Automatically resize a table to accomodate a varying number of rows.
10
+
11
+ Usage
12
+ -----
13
+
14
+ A semi-ugly hack to make tables shrink automatically so you dont have big ugly gray space to worry about .
15
+
16
+ plugins: [new ngGridFlexibleHeightPlugin()]
17
+
18
+ Options
19
+ -------
20
+
21
+ opts =
22
+ { minHeight: <minimum height in px> }
23
+
24
+ CSV-Export
25
+ ==========
26
+
27
+ Usage
28
+ -----
29
+
30
+ Add CSV Export to your ng-grid tables by including it in your plugins array:
31
+
32
+ plugins: [new ngGridCsvExportPlugin()]
33
+
34
+ Options
35
+ -------
36
+
37
+ opts =
38
+ { columnOverrides: < hash of column override functions > }
39
+
40
+ For arrays and objects you may want to override the default `JSON.stringify`
41
+ conversion into strings.
42
+
43
+
@@ -0,0 +1,5 @@
1
+ //= require ng-grid-csv-export
2
+ //= require ng-grid-flexible-height
3
+ //= require ng-grid-layout
4
+ //= require ng-grid-reorderable
5
+ //= require ng-grid-wysiwyg-export
@@ -0,0 +1,76 @@
1
+ // Todo:
2
+ // 1) Make the button prettier
3
+ // 2) add a config option for IE users which takes a URL. That URL should accept a POST request with a
4
+ // JSON encoded object in the payload and return a CSV. This is necessary because IE doesn't let you
5
+ // download from a data-uri link
6
+ //
7
+ // Notes: This has not been adequately tested and is very much a proof of concept at this point
8
+ function ngGridCsvExportPlugin (opts) {
9
+ var self = this;
10
+ self.grid = null;
11
+ self.scope = null;
12
+ self.init = function(scope, grid, services) {
13
+ self.grid = grid;
14
+ self.scope = scope;
15
+ function showDs() {
16
+ var keys = [];
17
+ for (var f in grid.config.columnDefs) { keys.push(grid.config.columnDefs[f].field);}
18
+ var csvData = '';
19
+ function csvStringify(str) {
20
+ if (str == null) { // we want to catch anything null-ish, hence just == not ===
21
+ return '';
22
+ }
23
+ if (typeof(str) === 'number') {
24
+ return '' + str;
25
+ }
26
+ if (typeof(str) === 'boolean') {
27
+ return (str ? 'TRUE' : 'FALSE') ;
28
+ }
29
+ if (typeof(str) === 'string') {
30
+ return str.replace(/"/g,'""');
31
+ }
32
+
33
+ return JSON.stringify(str).replace(/"/g,'""');
34
+ }
35
+ function swapLastCommaForNewline(str) {
36
+ var newStr = str.substr(0,str.length - 1);
37
+ return newStr + "\n";
38
+ }
39
+ for (var k in keys) {
40
+ csvData += '"' + csvStringify(keys[k]) + '",';
41
+ }
42
+ csvData = swapLastCommaForNewline(csvData);
43
+ var gridData = grid.data;
44
+ for (var gridRow in gridData) {
45
+ for ( k in keys) {
46
+ var curCellRaw;
47
+ if (opts != null && opts.columnOverrides != null && opts.columnOverrides[keys[k]] != null) {
48
+ curCellRaw = opts.columnOverrides[keys[k]](gridData[gridRow][keys[k]]);
49
+ }
50
+ else {
51
+ curCellRaw = gridData[gridRow][keys[k]];
52
+ }
53
+ csvData += '"' + csvStringify(curCellRaw) + '",';
54
+ }
55
+ csvData = swapLastCommaForNewline(csvData);
56
+ }
57
+ var fp = grid.$root.find(".ngFooterPanel");
58
+ var csvDataLinkPrevious = grid.$root.find('.ngFooterPanel .csv-data-link-span');
59
+ if (csvDataLinkPrevious != null) {csvDataLinkPrevious.remove() ; }
60
+ var csvDataLinkHtml = "<span class=\"csv-data-link-span\">";
61
+ csvDataLinkHtml += "<br><a href=\"data:text/csv;charset=UTF-8,";
62
+ csvDataLinkHtml += encodeURIComponent(csvData);
63
+ csvDataLinkHtml += "\" download=\"Export.csv\">CSV Export</a></br></span>" ;
64
+ fp.append(csvDataLinkHtml);
65
+ }
66
+ setTimeout(showDs, 0);
67
+ scope.catHashKeys = function() {
68
+ var hash = '';
69
+ for (var idx in scope.renderedRows) {
70
+ hash += scope.renderedRows[idx].$$hashKey;
71
+ }
72
+ return hash;
73
+ };
74
+ scope.$watch('catHashKeys()', showDs);
75
+ };
76
+ }
@@ -0,0 +1,40 @@
1
+ function ngGridFlexibleHeightPlugin (opts) {
2
+ var self = this;
3
+ self.grid = null;
4
+ self.scope = null;
5
+ self.init = function (scope, grid, services) {
6
+ self.domUtilityService = services.DomUtilityService;
7
+ self.grid = grid;
8
+ self.scope = scope;
9
+ var recalcHeightForData = function () { setTimeout(innerRecalcForData, 1); };
10
+ var innerRecalcForData = function () {
11
+ var gridId = self.grid.gridId;
12
+ var footerPanelSel = '.' + gridId + ' .ngFooterPanel';
13
+ var extraHeight = self.grid.$topPanel.height() + $(footerPanelSel).height();
14
+ var naturalHeight = self.grid.$canvas.height() + 1;
15
+ if (opts != null) {
16
+ if (opts.minHeight != null && (naturalHeight + extraHeight) < opts.minHeight) {
17
+ naturalHeight = opts.minHeight - extraHeight - 2;
18
+ }
19
+ }
20
+
21
+ var newViewportHeight = naturalHeight + 2;
22
+ if (!self.scope.baseViewportHeight || self.scope.baseViewportHeight !== newViewportHeight) {
23
+ self.grid.$viewport.css('height', newViewportHeight + 'px');
24
+ self.grid.$root.css('height', (newViewportHeight + extraHeight) + 'px');
25
+ self.scope.baseViewportHeight = newViewportHeight;
26
+ self.domUtilityService.UpdateGridLayout(self.scope, self.grid);
27
+ }
28
+ };
29
+ self.scope.catHashKeys = function () {
30
+ var hash = '',
31
+ idx;
32
+ for (idx in self.scope.renderedRows) {
33
+ hash += self.scope.renderedRows[idx].$$hashKey;
34
+ }
35
+ return hash;
36
+ };
37
+ self.scope.$watch('catHashKeys()', innerRecalcForData);
38
+ self.scope.$watch(self.grid.config.data, recalcHeightForData);
39
+ };
40
+ }
@@ -0,0 +1,22 @@
1
+ function ngGridLayoutPlugin () {
2
+ var self = this;
3
+ this.grid = null;
4
+ this.scope = null;
5
+ this.init = function(scope, grid, services) {
6
+ self.domUtilityService = services.DomUtilityService;
7
+ self.grid = grid;
8
+ self.scope = scope;
9
+ };
10
+
11
+ this.updateGridLayout = function () {
12
+ if (!self.scope.$$phase) {
13
+ self.scope.$apply(function(){
14
+ self.domUtilityService.RebuildGrid(self.scope, self.grid);
15
+ });
16
+ }
17
+ else {
18
+ // $digest or $apply already in progress
19
+ self.domUtilityService.RebuildGrid(self.scope, self.grid);
20
+ }
21
+ };
22
+ }
@@ -0,0 +1,68 @@
1
+ /*
2
+ Reorderablr row plugin
3
+ */
4
+
5
+ function ngGridReorderable () {
6
+ var self = this;
7
+ self.$scope = null;
8
+ self.myGrid = null;
9
+
10
+ // The init method gets called during the ng-grid directive execution.
11
+ self.init = function(scope, grid, services) {
12
+ // The directive passes in the grid scope and the grid object which we will want to save for manipulation later.
13
+ self.$scope = scope;
14
+ self.myGrid = grid;
15
+ self.services = services;
16
+ // In this example we want to assign grid events.
17
+ self.assignEvents();
18
+ };
19
+ self.colToMove = undefined;
20
+ self.groupToMove = undefined;
21
+ self.assignEvents = function() {
22
+ // Here we set the onmousedown event handler to the header container.
23
+ self.myGrid.$viewport.on('mousedown', self.onRowMouseDown).on('dragover', self.dragOver).on('drop', self.onRowDrop);
24
+ };
25
+ // Row functions
26
+ self.onRowMouseDown = function(event) {
27
+ // Get the closest row element from where we clicked.
28
+ var targetRow = $(event.target).closest('.ngRow');
29
+ // Get the scope from the row element
30
+ var rowScope = angular.element(targetRow).scope();
31
+ if (rowScope) {
32
+ // set draggable events
33
+ targetRow.attr('draggable', 'true');
34
+ // Save the row for later.
35
+ self.services.DomUtilityService.eventStorage.rowToMove = { targetRow: targetRow, scope: rowScope };
36
+ }
37
+ };
38
+ self.onRowDrop = function(event) {
39
+ // Get the closest row to where we dropped
40
+ var targetRow = $(event.target).closest('.ngRow');
41
+ // Get the scope from the row element.
42
+ var rowScope = angular.element(targetRow).scope();
43
+ if (rowScope) {
44
+ // If we have the same Row, do nothing.
45
+ var prevRow = self.services.DomUtilityService.eventStorage.rowToMove;
46
+ if (prevRow.scope.row === rowScope.row) {
47
+ return;
48
+ }
49
+ self.changeRowOrder(prevRow.scope.row, rowScope.row);
50
+ grid.searchProvider.evalFilter();
51
+ // clear out the rowToMove object
52
+ self.services.DomUtilityService.eventStorage.rowToMove = undefined;
53
+ // if there isn't an apply already in progress lets start one
54
+ self.services.DomUtilityService.digest(rowScope.$root);
55
+ }
56
+ };
57
+ self.changeRowOrder = function (prevRow, targetRow) {
58
+ // Splice the Rows via the actual datasource
59
+ var i = self.rowCache.indexOf(prevRow);
60
+ var j = self.rowCache.indexOf(targetRow);
61
+ self.myGrid.rowCache.splice(i, 1);
62
+ self.myGrid.rowCache.splice(j, 0, prevRow);
63
+ self.$scope.$emit('ngGridEventChangeOrder', self.rowCache);
64
+ };
65
+ self.dragOver = function(evt) {
66
+ evt.preventDefault();
67
+ };
68
+ }
@@ -0,0 +1,39 @@
1
+ function ngGridWYSIWYGPlugin (filter) {
2
+ var self = this;
3
+ self.grid = null;
4
+ self.scope = null;
5
+ self.services = null;
6
+
7
+ self.init = function (scope, grid, services) {
8
+ self.grid = grid;
9
+ self.scope = scope;
10
+ self.services = services;
11
+ };
12
+
13
+ self.exportData = function () {
14
+ var ret = {
15
+ columns: [],
16
+ columnWidths: [],
17
+ gridWidth: self.scope.totalRowWidth(),
18
+ data: []
19
+ };
20
+
21
+ angular.forEach(self.scope.columns, function (col) {
22
+ if (col.visible) {
23
+ ret.columns.push(col.displayName);
24
+ ret.columnWidths.push(col.width);
25
+ }
26
+ });
27
+ angular.forEach(self.grid.filteredRows, function (row) {
28
+ var item = row.entity;
29
+ angular.forEach(self.scope.columns, function (col) {
30
+ if (col.visible) {
31
+ var obj = self.services.UtilityService.evalProperty(item, col.field);
32
+ var val = col.cellFilter && filter ? filter(col.cellFilter)(obj) : obj;
33
+ ret.data.push(val ? val.toString() : '');
34
+ }
35
+ });
36
+ });
37
+ return ret;
38
+ };
39
+ }
@@ -0,0 +1,82 @@
1
+ <!DOCTYPE html>
2
+ <html ng-app="myApp">
3
+ <head lang="en">
4
+ <meta charset="utf-8">
5
+ <title>Custom Plunker</title>
6
+ <link rel="stylesheet" type="text/css" href="http://angular-ui.github.com/ng-grid/css/ng-grid.css" />
7
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
8
+ <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.min.js"></script>
9
+ <script type="text/javascript" src="../build/ng-grid.debug.js"></script>
10
+ <script type="text/javascript" src="ng-grid-csv-export.js"></script>
11
+ <script type="text/javascript" src="ng-grid-flexible-height.js"></script>
12
+ <style type="text/css">
13
+ .gridStyle
14
+ { border: 1px solid rgb(212,212,212)
15
+ ; height: 1400px
16
+ ; width: 80%
17
+ }
18
+ </style>
19
+ <script type="text/javascript">
20
+ // main.js
21
+ var app = angular.module('myApp', ['ngGrid']);
22
+ app.controller('MyCtrl', function($scope) {
23
+ csvOpts = { columnOverrides: { obj: function(o) { return o.a + '|' + o.b; } } }
24
+ hgtOpts = { minHeight: 200 } ;
25
+ $scope.myDataSmall = [ {hasThing: false, obj: {a:5, b:6}, name: "Moroni", age: 50, ln: 'sdf'}
26
+ , {hasThing: true, obj: {a:6, b:7}, ln: "Tiasdfsdfnd", age: 43}
27
+ ]
28
+ $scope.myDataBig = [ {hasThing: false, obj: {a:5, b:6}, name: "Moroni", age: 50, ln: 'sdf'}
29
+ , {hasThing: true, obj: {a:6, b:7}, ln: "Tiasdfsdfnd", age: 43}
30
+ , {hasThing: true, obj: {a:6, b:7}, ln: "asdfsdfnd", age: 43}
31
+ , {hasThing: true, obj: {a:6, b:7}, ln: "Tiasdfsdfnd", age: 43}
32
+ , {hasThing: true, obj: {a:6, b:7}, ln: "iadfsdfnd", age: 43}
33
+ , {hasThing: true, obj: {a:6, b:7}, ln: "iafsdfnd", age: 43}
34
+ , {hasThing: true, obj: {a:6, b:7}, ln: "iafsdfnd", age: 43}
35
+ , {hasThing: true, obj: {a:6, b:7}, ln: "iafsdfnd", age: 43}
36
+ , {hasThing: true, obj: {a:6, b:7}, ln: "iadfsdfnd", age: 43}
37
+ , {hasThing: true, obj: {a:6, b:7}, ln: "iadfsdfnd", age: 43}
38
+ , {hasThing: true, obj: {a:6, b:7}, ln: "iadfsdfnd", age: 43}
39
+ , {hasThing: true, obj: {a:6, b:7}, ln: "Tisdfsdfnd", age: 43}
40
+ , {hasThing: true, obj: {a:6, b:7}, ln: "Tiasdfsdfnd", age: 43}
41
+ , {hasThing: true, obj: {a:6, b:7}, ln: "Tiasdfsdfnd", age: 43}
42
+ , {hasThing: true, obj: {a:6, b:7}, ln: "Tiasdfsdfnd", age: 43}
43
+ , {hasThing: true, obj: {a:6, b:7}, ln: "Tiasdfsdfnd", age: 43}
44
+ , {hasThing: true, obj: {a:6, b:7}, ln: "Tiasdfsdfnd", age: 43}
45
+ , {hasThing: true, obj: {a:6, b:7}, ln: "Tiasdfsdfnd", age: 43}
46
+ , {hasThing: true, obj: {a:6, b:7}, ln: "Tiasdfsdfnd", age: 43}
47
+ , {hasThing: true, obj: {a:6, b:7}, ln: "Tiasdfsdfnd", age: 43}
48
+ , {hasThing: true, obj: {a:6, b:7}, ln: "Tiasdfsdfnd", age: 43}
49
+ , {hasThing: true, obj: {a:6, b:7}, ln: "Tiasdfsdfnd", age: 43}
50
+ , {hasThing: false, obj: {a:5, b:7}, name: "Jacob", age: 27}
51
+ , {hasThing: true, obj: {a:2, b:8}, ln: "Tiasdfsdfnd", age: 43}
52
+ , {hasThing: true, obj: {a:1, b:8}, ln: "Jacob", age: 27}
53
+ , {hasThing: false, obj: {a:7, b:9}, name: "Tiasdfsdfnd", age: 43}
54
+ , {hasThing: false, obj: {a:5, b:9}, name: "Jacob", age: 27}
55
+ , {hasThing: true, obj: {a:5, b:7}, name: "Nephi", age: 29}
56
+ , {hasThing: false, obj: {a:5, b:7}, name: "Enos", age: 34}
57
+ ];
58
+ $scope.gridOptionsBig = {
59
+ data: 'myDataBig',
60
+ plugins: [new ngGridCsvExportPlugin(csvOpts),new ngGridFlexibleHeightPlugin(hgtOpts)],
61
+ showGroupPanel: true,
62
+ showFooter: true
63
+ };
64
+ $scope.gridOptionsSmall = {
65
+ data: 'myDataSmall',
66
+ plugins: [new ngGridCsvExportPlugin(csvOpts),new ngGridFlexibleHeightPlugin()],
67
+ showGroupPanel: true,
68
+ showFooter: true
69
+ };
70
+ });
71
+ </script>
72
+ </head>
73
+ <body ng-controller="MyCtrl">
74
+ <div> <a ng-click="myDataSmall.push(myDataBig[0])"> add one to small </a></div>
75
+ <div> <a ng-click="myDataSmall.pop()"> remove one from small </a> </div>
76
+ <div class="gridStyle" ng-grid="gridOptionsSmall"></div>
77
+ <hr>
78
+ <div> <a ng-click="myDataBig.push(myDataSmall[0])"> add one to big </a> </div>
79
+ <div> <a ng-click="myDataBig.pop()"> remove one from big </a> </div>
80
+ <div class="gridStyle" ng-grid="gridOptionsBig"></div>
81
+ </body>
82
+ </html>
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: angular-ng-grid-plugins-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.7.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Iniciontin Gookou
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-24 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Injects angular-ng-grid plugins js into your asset pipeline.
15
+ email: iniciontingookou@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/angular-ng-grid-plugins-rails/version.rb
21
+ - lib/angular-ng-grid-plugins-rails.rb
22
+ - vendor/assets/javascripts/angular-ng-grid-plugins.js
23
+ - vendor/assets/javascripts/ng-grid-csv-export.js
24
+ - vendor/assets/javascripts/ng-grid-flexible-height.js
25
+ - vendor/assets/javascripts/ng-grid-layout.js
26
+ - vendor/assets/javascripts/ng-grid-reorderable.js
27
+ - vendor/assets/javascripts/ng-grid-wysiwyg-export.js
28
+ - vendor/assets/javascripts/playground.html
29
+ - vendor/assets/javascripts/README.md
30
+ - LICENSE
31
+ - README.md
32
+ homepage: https://github.com/iniciontingookou/angular-ng-grid-plugins-rails/
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.25
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: angular-ng-grid plugins on Rails
56
+ test_files: []