From ed4e70df8114c6e93fa4aab8d07a4f034f992e2b Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 7 Jul 2013 16:02:16 +0200 Subject: [PATCH 001/190] updated rakefile --- Rakefile | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index 6a2043d..04cf202 100644 --- a/Rakefile +++ b/Rakefile @@ -7,7 +7,7 @@ task :compile do require "coffee-script" require "uglifier" - script = CoffeeScript.compile collect_coffees + script = CoffeeScript.compile collect_coffees("coffee") prepend_author_notice(script) @@ -17,11 +17,11 @@ task :compile do end -def collect_coffees +def collect_coffees src files = ["atTable", "atImplicit", "atPagination", "metaCollector", "setupFactory"] script = "" files.each do |file| - script << File.read("coffee/#{file}.coffee") << "\n" + script << File.read("#{src}/#{file}.coffee") << "\n" end script end @@ -35,4 +35,14 @@ def prepend_author_notice script script.prepend comments script +end + +task :dev do + require "listen" + puts "listening!" + + Listen.to!("coffee", :force_polling => true) do |modified, added, removed| + puts "recompiling source!" + `rake compile` + end end \ No newline at end of file From 6c4e44527ecbe5cca867f1feea067c6379ab4854 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 7 Jul 2013 19:12:36 +0200 Subject: [PATCH 002/190] implemented tests --- karma.conf.js | 79 +++++++++++++++++++++++++ test/templates/sortableTable.html | 8 +++ test/templates/tableWithPagination.html | 10 ++++ test/tests.coffee | 52 ++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 karma.conf.js create mode 100644 test/templates/sortableTable.html create mode 100644 test/templates/tableWithPagination.html create mode 100644 test/tests.coffee diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..681ff17 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,79 @@ +// Karma configuration +// Generated on Thu Jul 04 2013 23:17:10 GMT+0200 (CEST) + + +// base path, that will be used to resolve files and exclude +basePath = ''; + + +// list of files / patterns to load in the browser +files = [ + JASMINE, + JASMINE_ADAPTER, + "http://code.jquery.com/jquery-1.10.1.min.js", + "http://code.angularjs.org/1.1.5/angular.min.js", + "http://code.angularjs.org/1.1.5/angular-mocks.js", + "http://underscorejs.org/underscore-min.js", + // important to load this first, because it contains the module definition + "coffee/atTable.coffee", + "coffee/*.coffee", + "test/*.coffee", + "test/templates/*.html" +]; + +preprocessors = { + "coffee/*.coffee": "coffee", + "test/*.coffee": "coffee", + "test/templates/*.html": "html2js" +}; + +// list of files to exclude +exclude = [ + +]; + + +// test results reporter to use +// possible values: 'dots', 'progress', 'junit' +reporters = ['progress']; + + +// web server port +port = 9876; + + +// cli runner port +runnerPort = 9100; + + +// enable / disable colors in the output (reporters and logs) +colors = true; + + +// level of logging +// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG +logLevel = LOG_INFO; + + +// enable / disable watching file and executing tests whenever any file changes +autoWatch = true; + + +// Start these browsers, currently available: +// - Chrome +// - ChromeCanary +// - Firefox +// - Opera +// - Safari (only Mac) +// - PhantomJS +// - IE (only Windows) +browsers = ['Chrome']; + + +// If browser does not capture in given timeout [ms], kill it +captureTimeout = 60000; + + +// Continuous Integration mode +// if true, it capture browsers, run tests and exit +singleRun = false; diff --git a/test/templates/sortableTable.html b/test/templates/sortableTable.html new file mode 100644 index 0000000..be076f0 --- /dev/null +++ b/test/templates/sortableTable.html @@ -0,0 +1,8 @@ + + + + + + + +
diff --git a/test/templates/tableWithPagination.html b/test/templates/tableWithPagination.html new file mode 100644 index 0000000..f401606 --- /dev/null +++ b/test/templates/tableWithPagination.html @@ -0,0 +1,10 @@ + + + + + + + +
+ + \ No newline at end of file diff --git a/test/tests.coffee b/test/tests.coffee new file mode 100644 index 0000000..6ad24e1 --- /dev/null +++ b/test/tests.coffee @@ -0,0 +1,52 @@ +describe "AnglarTable", () -> + + template1 = "test/templates/sortableTable.html" + template2 = "test/templates/tableWithPagination.html" + + beforeEach module "angular-table" + beforeEach module(template1, template2) + + tdsToArray = (tds) -> + _.map tds, (td) -> angular.element(td).html() + + loadTemplate = (template, templateCache) -> + angular.element(templateCache.get(template)) + + it "makes a table sortable", inject ($compile, $rootScope, $templateCache) -> + + element = loadTemplate template1, $templateCache + + $rootScope.cities = [{name: "Helsinki"}, {name: "Zurich"}, {name: "Amsterdam"}] + + element = $compile(element)($rootScope) + $rootScope.$digest() + + tds = tdsToArray(element.find("td")) + expect(tds).toEqual ["Zurich", "Helsinki", "Amsterdam"] + + element.find("th")[0].click() + + tds = tdsToArray(element.find("td")) + expect(tds).toEqual ["Amsterdam", "Helsinki", "Zurich"] + + + + it "adds pagination to a table", inject ($compile, $rootScope, $templateCache) -> + + element = loadTemplate template2, $templateCache + + $rootScope.rammstein = [ + {name: "Till"}, {name: "Richard"}, {name: "Christoph"}, + {name: "Paul"}, {name: "Flake"}, {name: "Oliver"}] + + element = $compile(element)($rootScope) + $rootScope.$digest() + + tds = tdsToArray(element.find("td")) + expect(tds).toEqual ["Till", "Richard", "Christoph"] + + paginationLinks = element.find "a" + _.find(paginationLinks, (link) -> angular.element(link).html() == "2").click() + + tds = tdsToArray(element.find("td")) + expect(tds).toEqual ["Paul", "Flake", "Oliver"] From c98d18f6b8da231cd125a6add6b111fd5ed4916b Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 7 Jul 2013 20:22:35 +0200 Subject: [PATCH 003/190] updated template --- test/templates/tableWithPagination.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/templates/tableWithPagination.html b/test/templates/tableWithPagination.html index f401606..e461552 100644 --- a/test/templates/tableWithPagination.html +++ b/test/templates/tableWithPagination.html @@ -2,7 +2,7 @@ - + {{item.name}} From 2b738ffd91cc8d455372183112d73976cc77002d Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Thu, 18 Jul 2013 12:00:47 +0200 Subject: [PATCH 004/190] fixed bug when tag was not defined --- .gitignore | 3 ++- angular-table.js | 7 +++---- angular-table.min.js | 4 ++-- coffee/atTable.coffee | 5 ++--- gem/app/assets/javascripts/angular-table.js | 7 +++---- gem/lib/angular-table/version.rb | 2 +- 6 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index b8a66e4..1571595 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *sublime* _site -*.gem \ No newline at end of file +*.gem +*.log \ No newline at end of file diff --git a/angular-table.js b/angular-table.js index 70ce0d6..1ab2e96 100644 --- a/angular-table.js +++ b/angular-table.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 0.0.4 +// version: 0.0.5 // license: MIT // homepage: http://github.com/ssmm/angular-table (function() { @@ -41,15 +41,14 @@ restrict: "AC", scope: true, compile: function(element, attributes, transclude) { - var bodyDefinition, customHeaderMarkup, setup, tbody, tds, thead, tr; + var bodyDefinition, customHeaderMarkup, setup, tbody, thead, tr; validateInput(attributes); thead = element.find("thead"); tbody = element.find("tbody"); - tds = element.find("td"); + bodyDefinition = metaCollector.collectBodyDefinition(tbody); if (thead[0]) { customHeaderMarkup = metaCollector.collectCustomHeaderMarkup(thead); - bodyDefinition = metaCollector.collectBodyDefinition(tbody); tr = thead.find("tr"); tr.remove(); thead.append(constructHeader(customHeaderMarkup, bodyDefinition.tds)); diff --git a/angular-table.min.js b/angular-table.min.js index 836cd65..8b572b7 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 0.0.4 +// version: 0.0.5 // license: MIT // homepage: http://github.com/ssmm/angular-table -!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n;return i=function(t,e){var i,n,r,a,l,o,u;for(l=angular.element(""),o=0,u=e.length;u>o;o++)n=e[o],r=angular.element(""),a=t[n.attribute]||n.title,r.html(""+a),n.sortable&&(r.attr("ng-click","predicate = '"+n.attribute+"'; descending = !descending;"),i=angular.element(""),i.attr("ng-class","getSortIcon('"+n.attribute+"')"),r.append(i)),r.attr("width",n.width),l.append(r);return l},n=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},{restrict:"AC",scope:!0,compile:function(r,a,l){var o,u,c,g,s,d,f;return n(a),d=r.find("thead"),g=r.find("tbody"),s=r.find("td"),d[0]&&(u=t.collectCustomHeaderMarkup(d),o=t.collectBodyDefinition(g),f=d.find("tr"),f.remove(),d.append(i(u,o.tds))),c=e(a),c.compile(r,a,l),{post:function(t,e,i){return o.initialSorting&&(t.predicate=o.initialSorting.predicate,t.descending="desc"===o.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},c.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){return t.instance=t,t.currentPage=0,t.update=function(){var e;return t.currentPage=0,t.list?(t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]),t.list=t.list):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,l,o;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,o=[],n=r=a=t.list.length,l=t.list.length+e;l>=a?l>=r:r>=l;n=l>=a?++r:--r)o.push(n);return o}return[]}},t.goToPage=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e),t.currentPage=e},t.update(),t.$watch("list",function(){return t.update()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,l;for(e={},n=t.find("tr"),l=n.find("th"),r=0,a=l.length;a>r;r++)i=l[r],i=angular.element(i),e[i.attr("attribute")]=i.html();return e},collectBodyDefinition:function(r){var a,l,o,u,c,g,s,d,f,p;for(l={},l.tds=[],l.initialSorting=void 0,p=r.find("td"),d=0,f=p.length;f>d;d++)if(c=p[d],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),l.tds.push({attribute:a,title:g,sortable:u,width:s}),o=i(c)){if(!a)throw"initial-sorting specified without attribute.";l.initialSorting={},l.initialSorting.direction=o,l.initialSorting.predicate=a}return l}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a;if(a=t.sortContext||"global","global"===a)e="item in "+t.pagination+".list "+n+" "+i;else{if("page"!==a)throw"Invalid sort-context: "+a+".";e="item in "+t.pagination+".list "+i+" "+n+" "}this.compile=function(t,i){var n,a,l,o,u,c,g;if(a=r(t,e),"undefined"!=typeof i.fillLastPage){for(u=t.find("td"),o="",c=0,g=u.length;g>c;c++)l=u[c],o+=" ";return n=angular.element(""+o+""),n.attr("ng-repeat","item in "+i.pagination+".getFillerArray() "),a.append(n)}},this.link=function(e){var i;return i=t.pagination,e.fromPage=function(){return e[i]?e[i].fromPage():void 0},e.toPage=function(){return e[i]?e[i].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this); \ No newline at end of file +!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n;return i=function(t,e){var i,n,r,a,l,o,u;for(l=angular.element(""),o=0,u=e.length;u>o;o++)n=e[o],r=angular.element(""),a=t[n.attribute]||n.title,r.html(""+a),n.sortable&&(r.attr("ng-click","predicate = '"+n.attribute+"'; descending = !descending;"),i=angular.element(""),i.attr("ng-class","getSortIcon('"+n.attribute+"')"),r.append(i)),r.attr("width",n.width),l.append(r);return l},n=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},{restrict:"AC",scope:!0,compile:function(r,a,l){var o,u,c,g,s,d;return n(a),s=r.find("thead"),g=r.find("tbody"),o=t.collectBodyDefinition(g),s[0]&&(u=t.collectCustomHeaderMarkup(s),d=s.find("tr"),d.remove(),s.append(i(u,o.tds))),c=e(a),c.compile(r,a,l),{post:function(t,e,i){return o.initialSorting&&(t.predicate=o.initialSorting.predicate,t.descending="desc"===o.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},c.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){return t.instance=t,t.currentPage=0,t.update=function(){var e;return t.currentPage=0,t.list?(t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]),t.list=t.list):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,l,o;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,o=[],n=r=a=t.list.length,l=t.list.length+e;l>=a?l>=r:r>=l;n=l>=a?++r:--r)o.push(n);return o}return[]}},t.goToPage=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e),t.currentPage=e},t.update(),t.$watch("list",function(){return t.update()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,l;for(e={},n=t.find("tr"),l=n.find("th"),r=0,a=l.length;a>r;r++)i=l[r],i=angular.element(i),e[i.attr("attribute")]=i.html();return e},collectBodyDefinition:function(r){var a,l,o,u,c,g,s,d,f,p;for(l={},l.tds=[],l.initialSorting=void 0,p=r.find("td"),d=0,f=p.length;f>d;d++)if(c=p[d],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),l.tds.push({attribute:a,title:g,sortable:u,width:s}),o=i(c)){if(!a)throw"initial-sorting specified without attribute.";l.initialSorting={},l.initialSorting.direction=o,l.initialSorting.predicate=a}return l}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a;if(a=t.sortContext||"global","global"===a)e="item in "+t.pagination+".list "+n+" "+i;else{if("page"!==a)throw"Invalid sort-context: "+a+".";e="item in "+t.pagination+".list "+i+" "+n+" "}this.compile=function(t,i){var n,a,l,o,u,c,g;if(a=r(t,e),"undefined"!=typeof i.fillLastPage){for(u=t.find("td"),o="",c=0,g=u.length;g>c;c++)l=u[c],o+=" ";return n=angular.element(""+o+""),n.attr("ng-repeat","item in "+i.pagination+".getFillerArray() "),a.append(n)}},this.link=function(e){var i;return i=t.pagination,e.fromPage=function(){return e[i]?e[i].fromPage():void 0},e.toPage=function(){return e[i]?e[i].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this); \ No newline at end of file diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index 5f7f2eb..d194b4f 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -36,11 +36,10 @@ angular.module("angular-table").directive "atTable", ["metaCollector", "setupFac thead = element.find "thead" tbody = element.find "tbody" - tds = element.find "td" + bodyDefinition = metaCollector.collectBodyDefinition(tbody) + if thead[0] customHeaderMarkup = metaCollector.collectCustomHeaderMarkup(thead) - bodyDefinition = metaCollector.collectBodyDefinition(tbody) - tr = thead.find "tr" tr.remove() thead.append constructHeader(customHeaderMarkup, bodyDefinition.tds) diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 70ce0d6..1ab2e96 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 0.0.4 +// version: 0.0.5 // license: MIT // homepage: http://github.com/ssmm/angular-table (function() { @@ -41,15 +41,14 @@ restrict: "AC", scope: true, compile: function(element, attributes, transclude) { - var bodyDefinition, customHeaderMarkup, setup, tbody, tds, thead, tr; + var bodyDefinition, customHeaderMarkup, setup, tbody, thead, tr; validateInput(attributes); thead = element.find("thead"); tbody = element.find("tbody"); - tds = element.find("td"); + bodyDefinition = metaCollector.collectBodyDefinition(tbody); if (thead[0]) { customHeaderMarkup = metaCollector.collectCustomHeaderMarkup(thead); - bodyDefinition = metaCollector.collectBodyDefinition(tbody); tr = thead.find("tr"); tr.remove(); thead.append(constructHeader(customHeaderMarkup, bodyDefinition.tds)); diff --git a/gem/lib/angular-table/version.rb b/gem/lib/angular-table/version.rb index 64554e5..2b3b45b 100644 --- a/gem/lib/angular-table/version.rb +++ b/gem/lib/angular-table/version.rb @@ -1,3 +1,3 @@ module AngularTable - VERSION = "0.0.4" + VERSION = "0.0.5" end From d42ec735c9b52e41b86476e761e1b74f84ed98e0 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 23 Jul 2013 22:28:19 +0200 Subject: [PATCH 005/190] a table can now be wired with a pagination by using 'at-pagination' instead of 'pagination'. This way name clashes with other directives called 'pagination' are less likely --- angular-table.js | 23 +++++++++++++-------- angular-table.min.js | 4 ++-- coffee/atTable.coffee | 11 ++++++++++ coffee/setupFactory.coffee | 8 +++---- gem/app/assets/javascripts/angular-table.js | 23 +++++++++++++-------- gem/lib/angular-table/version.rb | 2 +- test/templates/tableWithPagination.html | 2 +- 7 files changed, 47 insertions(+), 26 deletions(-) diff --git a/angular-table.js b/angular-table.js index 1ab2e96..fed6bbf 100644 --- a/angular-table.js +++ b/angular-table.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 0.0.5 +// version: 0.0.6 // license: MIT // homepage: http://github.com/ssmm/angular-table (function() { @@ -7,7 +7,7 @@ angular.module("angular-table").directive("atTable", [ "metaCollector", "setupFactory", function(metaCollector, setupFactory) { - var constructHeader, validateInput; + var constructHeader, normalizeInput, validateInput; constructHeader = function(customHeaderMarkup, bodyDefinitions) { var icon, td, th, title, tr, _i, _len; @@ -37,12 +37,19 @@ throw "Either a list or pagination must be specified."; } }; + normalizeInput = function(attributes) { + if (attributes.atPagination) { + attributes.pagination = attributes.atPagination; + return attributes.atPagination = null; + } + }; return { restrict: "AC", scope: true, compile: function(element, attributes, transclude) { var bodyDefinition, customHeaderMarkup, setup, tbody, thead, tr; + normalizeInput(attributes); validateInput(attributes); thead = element.find("thead"); tbody = element.find("tbody"); @@ -286,13 +293,14 @@ this.link = function() {}; }; PaginationSetup = function(attributes) { - var repeatString, sortContext; + var paginationName, repeatString, sortContext; sortContext = attributes.sortContext || "global"; + paginationName = attributes.pagination; if (sortContext === "global") { - repeatString = "item in " + attributes.pagination + ".list " + orderByExpression + " " + limitToExpression; + repeatString = "item in " + paginationName + ".list " + orderByExpression + " " + limitToExpression; } else if (sortContext === "page") { - repeatString = "item in " + attributes.pagination + ".list " + limitToExpression + " " + orderByExpression + " "; + repeatString = "item in " + paginationName + ".list " + limitToExpression + " " + orderByExpression + " "; } else { throw "Invalid sort-context: " + sortContext + "."; } @@ -308,14 +316,11 @@ tdString += " "; } fillerTr = angular.element("" + tdString + ""); - fillerTr.attr("ng-repeat", "item in " + attributes.pagination + ".getFillerArray() "); + fillerTr.attr("ng-repeat", "item in " + paginationName + ".getFillerArray() "); return tbody.append(fillerTr); } }; this.link = function($scope, $element, $attributes) { - var paginationName; - - paginationName = attributes.pagination; $scope.fromPage = function() { if ($scope[paginationName]) { return $scope[paginationName].fromPage(); diff --git a/angular-table.min.js b/angular-table.min.js index 8b572b7..2785b5e 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 0.0.5 +// version: 0.0.6 // license: MIT // homepage: http://github.com/ssmm/angular-table -!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n;return i=function(t,e){var i,n,r,a,l,o,u;for(l=angular.element(""),o=0,u=e.length;u>o;o++)n=e[o],r=angular.element(""),a=t[n.attribute]||n.title,r.html(""+a),n.sortable&&(r.attr("ng-click","predicate = '"+n.attribute+"'; descending = !descending;"),i=angular.element(""),i.attr("ng-class","getSortIcon('"+n.attribute+"')"),r.append(i)),r.attr("width",n.width),l.append(r);return l},n=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},{restrict:"AC",scope:!0,compile:function(r,a,l){var o,u,c,g,s,d;return n(a),s=r.find("thead"),g=r.find("tbody"),o=t.collectBodyDefinition(g),s[0]&&(u=t.collectCustomHeaderMarkup(s),d=s.find("tr"),d.remove(),s.append(i(u,o.tds))),c=e(a),c.compile(r,a,l),{post:function(t,e,i){return o.initialSorting&&(t.predicate=o.initialSorting.predicate,t.descending="desc"===o.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},c.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){return t.instance=t,t.currentPage=0,t.update=function(){var e;return t.currentPage=0,t.list?(t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]),t.list=t.list):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,l,o;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,o=[],n=r=a=t.list.length,l=t.list.length+e;l>=a?l>=r:r>=l;n=l>=a?++r:--r)o.push(n);return o}return[]}},t.goToPage=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e),t.currentPage=e},t.update(),t.$watch("list",function(){return t.update()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,l;for(e={},n=t.find("tr"),l=n.find("th"),r=0,a=l.length;a>r;r++)i=l[r],i=angular.element(i),e[i.attr("attribute")]=i.html();return e},collectBodyDefinition:function(r){var a,l,o,u,c,g,s,d,f,p;for(l={},l.tds=[],l.initialSorting=void 0,p=r.find("td"),d=0,f=p.length;f>d;d++)if(c=p[d],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),l.tds.push({attribute:a,title:g,sortable:u,width:s}),o=i(c)){if(!a)throw"initial-sorting specified without attribute.";l.initialSorting={},l.initialSorting.direction=o,l.initialSorting.predicate=a}return l}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a;if(a=t.sortContext||"global","global"===a)e="item in "+t.pagination+".list "+n+" "+i;else{if("page"!==a)throw"Invalid sort-context: "+a+".";e="item in "+t.pagination+".list "+i+" "+n+" "}this.compile=function(t,i){var n,a,l,o,u,c,g;if(a=r(t,e),"undefined"!=typeof i.fillLastPage){for(u=t.find("td"),o="",c=0,g=u.length;g>c;c++)l=u[c],o+=" ";return n=angular.element(""+o+""),n.attr("ng-repeat","item in "+i.pagination+".getFillerArray() "),a.append(n)}},this.link=function(e){var i;return i=t.pagination,e.fromPage=function(){return e[i]?e[i].fromPage():void 0},e.toPage=function(){return e[i]?e[i].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this); \ No newline at end of file +!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n,r;return i=function(t,e){var i,n,r,a,l,o,u;for(l=angular.element(""),o=0,u=e.length;u>o;o++)n=e[o],r=angular.element(""),a=t[n.attribute]||n.title,r.html(""+a),n.sortable&&(r.attr("ng-click","predicate = '"+n.attribute+"'; descending = !descending;"),i=angular.element(""),i.attr("ng-class","getSortIcon('"+n.attribute+"')"),r.append(i)),r.attr("width",n.width),l.append(r);return l},r=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(a,l,o){var u,c,g,s,d,f;return n(l),r(l),d=a.find("thead"),s=a.find("tbody"),u=t.collectBodyDefinition(s),d[0]&&(c=t.collectCustomHeaderMarkup(d),f=d.find("tr"),f.remove(),d.append(i(c,u.tds))),g=e(l),g.compile(a,l,o),{post:function(t,e,i){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){return t.instance=t,t.currentPage=0,t.update=function(){var e;return t.currentPage=0,t.list?(t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]),t.list=t.list):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,l,o;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,o=[],n=r=a=t.list.length,l=t.list.length+e;l>=a?l>=r:r>=l;n=l>=a?++r:--r)o.push(n);return o}return[]}},t.goToPage=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e),t.currentPage=e},t.update(),t.$watch("list",function(){return t.update()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,l;for(e={},n=t.find("tr"),l=n.find("th"),r=0,a=l.length;a>r;r++)i=l[r],i=angular.element(i),e[i.attr("attribute")]=i.html();return e},collectBodyDefinition:function(r){var a,l,o,u,c,g,s,d,f,p;for(l={},l.tds=[],l.initialSorting=void 0,p=r.find("td"),d=0,f=p.length;f>d;d++)if(c=p[d],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),l.tds.push({attribute:a,title:g,sortable:u,width:s}),o=i(c)){if(!a)throw"initial-sorting specified without attribute.";l.initialSorting={},l.initialSorting.direction=o,l.initialSorting.predicate=a}return l}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a,l;if(l=t.sortContext||"global",e=t.pagination,"global"===l)a="item in "+e+".list "+n+" "+i;else{if("page"!==l)throw"Invalid sort-context: "+l+".";a="item in "+e+".list "+i+" "+n+" "}this.compile=function(t,i){var n,l,o,u,c,g,s;if(l=r(t,a),"undefined"!=typeof i.fillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)o=c[g],u+=" ";return n=angular.element(""+u+""),n.attr("ng-repeat","item in "+e+".getFillerArray() "),l.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this); \ No newline at end of file diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index d194b4f..a06baf4 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -27,10 +27,21 @@ angular.module("angular-table").directive "atTable", ["metaCollector", "setupFac if not attributes.pagination and not attributes.list throw "Either a list or pagination must be specified." + # Earlier versions of angular table used 'pagination' instead of 'at-pagination' + # to wire a table to a pagination instance. However, this declaration can become + # ambiguous (ui-bootstrap for example has a directive called 'pagination'). So + # right now, you can either use 'pagination' or 'at-pagination'. The support + # for 'pagination' should be dropped some time. + normalizeInput = (attributes) -> + if attributes.atPagination + attributes.pagination = attributes.atPagination + attributes.atPagination = null + { restrict: "AC" scope: true compile: (element, attributes, transclude) -> + normalizeInput attributes validateInput attributes thead = element.find "thead" diff --git a/coffee/setupFactory.coffee b/coffee/setupFactory.coffee index ec4b1ff..34f7040 100644 --- a/coffee/setupFactory.coffee +++ b/coffee/setupFactory.coffee @@ -20,11 +20,12 @@ angular.module("angular-table").factory "setupFactory", [() -> PaginationSetup = (attributes) -> sortContext = attributes.sortContext || "global" + paginationName = attributes.pagination if sortContext == "global" - repeatString = "item in #{attributes.pagination}.list #{orderByExpression} #{limitToExpression}" + repeatString = "item in #{paginationName}.list #{orderByExpression} #{limitToExpression}" else if sortContext == "page" - repeatString = "item in #{attributes.pagination}.list #{limitToExpression} #{orderByExpression} " + repeatString = "item in #{paginationName}.list #{limitToExpression} #{orderByExpression} " else throw "Invalid sort-context: #{sortContext}." @@ -38,12 +39,11 @@ angular.module("angular-table").factory "setupFactory", [() -> tdString += " " fillerTr = angular.element("#{tdString}") - fillerTr.attr("ng-repeat", "item in #{attributes.pagination}.getFillerArray() ") + fillerTr.attr("ng-repeat", "item in #{paginationName}.getFillerArray() ") tbody.append(fillerTr) @link = ($scope, $element, $attributes) -> - paginationName = attributes.pagination $scope.fromPage = () -> if $scope[paginationName] then $scope[paginationName].fromPage() diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 1ab2e96..fed6bbf 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 0.0.5 +// version: 0.0.6 // license: MIT // homepage: http://github.com/ssmm/angular-table (function() { @@ -7,7 +7,7 @@ angular.module("angular-table").directive("atTable", [ "metaCollector", "setupFactory", function(metaCollector, setupFactory) { - var constructHeader, validateInput; + var constructHeader, normalizeInput, validateInput; constructHeader = function(customHeaderMarkup, bodyDefinitions) { var icon, td, th, title, tr, _i, _len; @@ -37,12 +37,19 @@ throw "Either a list or pagination must be specified."; } }; + normalizeInput = function(attributes) { + if (attributes.atPagination) { + attributes.pagination = attributes.atPagination; + return attributes.atPagination = null; + } + }; return { restrict: "AC", scope: true, compile: function(element, attributes, transclude) { var bodyDefinition, customHeaderMarkup, setup, tbody, thead, tr; + normalizeInput(attributes); validateInput(attributes); thead = element.find("thead"); tbody = element.find("tbody"); @@ -286,13 +293,14 @@ this.link = function() {}; }; PaginationSetup = function(attributes) { - var repeatString, sortContext; + var paginationName, repeatString, sortContext; sortContext = attributes.sortContext || "global"; + paginationName = attributes.pagination; if (sortContext === "global") { - repeatString = "item in " + attributes.pagination + ".list " + orderByExpression + " " + limitToExpression; + repeatString = "item in " + paginationName + ".list " + orderByExpression + " " + limitToExpression; } else if (sortContext === "page") { - repeatString = "item in " + attributes.pagination + ".list " + limitToExpression + " " + orderByExpression + " "; + repeatString = "item in " + paginationName + ".list " + limitToExpression + " " + orderByExpression + " "; } else { throw "Invalid sort-context: " + sortContext + "."; } @@ -308,14 +316,11 @@ tdString += " "; } fillerTr = angular.element("" + tdString + ""); - fillerTr.attr("ng-repeat", "item in " + attributes.pagination + ".getFillerArray() "); + fillerTr.attr("ng-repeat", "item in " + paginationName + ".getFillerArray() "); return tbody.append(fillerTr); } }; this.link = function($scope, $element, $attributes) { - var paginationName; - - paginationName = attributes.pagination; $scope.fromPage = function() { if ($scope[paginationName]) { return $scope[paginationName].fromPage(); diff --git a/gem/lib/angular-table/version.rb b/gem/lib/angular-table/version.rb index 2b3b45b..f4c4049 100644 --- a/gem/lib/angular-table/version.rb +++ b/gem/lib/angular-table/version.rb @@ -1,3 +1,3 @@ module AngularTable - VERSION = "0.0.5" + VERSION = "0.0.6" end diff --git a/test/templates/tableWithPagination.html b/test/templates/tableWithPagination.html index e461552..737c7fa 100644 --- a/test/templates/tableWithPagination.html +++ b/test/templates/tableWithPagination.html @@ -1,4 +1,4 @@ - +
From fa26c744b7c9c88b59c583d502c12a7c2c467b57 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 24 Jul 2013 20:20:04 +0200 Subject: [PATCH 006/190] readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ef345c..bab6d5c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # angular-table -Lets you declare sortable, pageable tables with minimal effort while providing high flexibilty. +Angular directive for rendering tables. Add sorting and pagination with ease. [Written in CoffeeScript.](https://github.com/ssmm/angular-table/blob/master/coffee) From 5f88fcc7f11e7d138ec8728e1cdeb2381145ba31 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 24 Jul 2013 20:22:28 +0200 Subject: [PATCH 007/190] new test, currently failing --- test/tests.coffee | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/tests.coffee b/test/tests.coffee index 6ad24e1..afbef28 100644 --- a/test/tests.coffee +++ b/test/tests.coffee @@ -50,3 +50,27 @@ describe "AnglarTable", () -> tds = tdsToArray(element.find("td")) expect(tds).toEqual ["Paul", "Flake", "Oliver"] + + it "the pagination automatically updates when elements are added to or removed from the list", + inject ($compile, $rootScope, $templateCache) -> + + element = loadTemplate template2, $templateCache + + $rootScope.rammstein = [ + {name: "Till"}, {name: "Richard"}, {name: "Christoph"}] + + element = $compile(element)($rootScope) + $rootScope.$digest() + + tds = tdsToArray(element.find("td")) + expect(tds).toEqual ["Till", "Richard", "Christoph"] + + paginationLinks = element.find "a" + # there should be three buttons: << | 1 | >> + expect(paginationLinks.length).toEqual 3 + + $rootScope.rammstein.push {name: "Paul"} + $rootScope.$digest() + paginationLinks = element.find "a" + # now, there should be four buttons: << | 1 | 2 | >> + expect(paginationLinks.length).toEqual 4 From a26325a00b32bf108439eb9c66292e72e0a1cfb2 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 24 Jul 2013 20:32:24 +0200 Subject: [PATCH 008/190] readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bab6d5c..8158fde 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # angular-table -Angular directive for rendering tables. Add sorting and pagination with ease. +Html tables with sorting and pagination. [Written in CoffeeScript.](https://github.com/ssmm/angular-table/blob/master/coffee) From d7945819227109d6efc71784151f97b087ca9605 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 24 Jul 2013 20:33:38 +0200 Subject: [PATCH 009/190] updated description in gemspec --- gem/angular-table.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gem/angular-table.gemspec b/gem/angular-table.gemspec index 681b35d..87e4871 100644 --- a/gem/angular-table.gemspec +++ b/gem/angular-table.gemspec @@ -8,7 +8,7 @@ Gem::Specification.new do |spec| spec.version = AngularTable::VERSION spec.authors = ["Samuel Mueller"] spec.email = ["mueller.samu@gmail.com"] - spec.description = "Angular directive for easy HTML table declaration. Makes them sortable and adds pagination." + spec.description = "Html tables with sorting and pagination." spec.summary = spec.description spec.homepage = "https://github.com/ssmm/angular-table" spec.license = "MIT" From d8a23ed3d3290dc390d49f4732cfab7fdd696f2d Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 28 Jul 2013 16:29:48 +0200 Subject: [PATCH 010/190] refactoring --- coffee/atPagination.coffee | 30 ++++++++++++++++++++++-------- test/tests.coffee | 34 +++++++++++++++++----------------- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/coffee/atPagination.coffee b/coffee/atPagination.coffee index c46235b..03b61a8 100644 --- a/coffee/atPagination.coffee +++ b/coffee/atPagination.coffee @@ -26,8 +26,15 @@ angular.module("angular-table").directive "atPagination", [() -> $scope.instance = $scope $scope.currentPage = 0 - $scope.update = () -> + normalizePage = (page) -> + page = Math.max(0, page) + page = Math.min($scope.numberOfPages - 1, page) + page + + update = (reset) -> + # $scope.currentPage = if reset then 0 else normalizePage($scope.currentPage) $scope.currentPage = 0 + if $scope.list if $scope.list.length > 0 $scope.numberOfPages = Math.ceil($scope.list.length / $scope.itemsPerPage) @@ -36,7 +43,6 @@ angular.module("angular-table").directive "atPagination", [() -> else $scope.numberOfPages = 1 $scope.pages = [0] - $scope.list = $scope.list $scope.fromPage = () -> if $scope.list @@ -52,15 +58,23 @@ angular.module("angular-table").directive "atPagination", [() -> [] $scope.goToPage = (page) -> - page = Math.max(0, page) - page = Math.min($scope.numberOfPages - 1, page) + $scope.currentPage = normalizePage(page) - $scope.currentPage = page + update() - $scope.update() + $scope.$watch "list", (newValue, oldValue) -> + update() + # # console.log newValue.length, oldValue.length + # if newValue.length != oldValue.length + # update false + # else + # update true + # , true - $scope.$watch "list", () -> - $scope.update() + # Additional watch on the length of the list. This will + # be fired if items are added to or removed from it. + # $scope.$watch "list.length", (newValue, oldValue) -> + # update(false) if newValue != oldValue } ] \ No newline at end of file diff --git a/test/tests.coffee b/test/tests.coffee index afbef28..fde0c4c 100644 --- a/test/tests.coffee +++ b/test/tests.coffee @@ -51,26 +51,26 @@ describe "AnglarTable", () -> tds = tdsToArray(element.find("td")) expect(tds).toEqual ["Paul", "Flake", "Oliver"] - it "the pagination automatically updates when elements are added to or removed from the list", - inject ($compile, $rootScope, $templateCache) -> + # it "the pagination automatically updates when elements are added to or removed from the list", + # inject ($compile, $rootScope, $templateCache) -> - element = loadTemplate template2, $templateCache + # element = loadTemplate template2, $templateCache - $rootScope.rammstein = [ - {name: "Till"}, {name: "Richard"}, {name: "Christoph"}] + # $rootScope.rammstein = [ + # {name: "Till"}, {name: "Richard"}, {name: "Christoph"}] - element = $compile(element)($rootScope) - $rootScope.$digest() + # element = $compile(element)($rootScope) + # $rootScope.$digest() - tds = tdsToArray(element.find("td")) - expect(tds).toEqual ["Till", "Richard", "Christoph"] + # tds = tdsToArray(element.find("td")) + # expect(tds).toEqual ["Till", "Richard", "Christoph"] - paginationLinks = element.find "a" - # there should be three buttons: << | 1 | >> - expect(paginationLinks.length).toEqual 3 + # paginationLinks = element.find "a" + # # there should be three buttons: << | 1 | >> + # expect(paginationLinks.length).toEqual 3 - $rootScope.rammstein.push {name: "Paul"} - $rootScope.$digest() - paginationLinks = element.find "a" - # now, there should be four buttons: << | 1 | 2 | >> - expect(paginationLinks.length).toEqual 4 + # $rootScope.rammstein.push {name: "Paul"} + # $rootScope.$digest() + # paginationLinks = element.find "a" + # # now, there should be four buttons: << | 1 | 2 | >> + # expect(paginationLinks.length).toEqual 4 From 919178526be6e9e62326705b6bb2eef3f1cf6b73 Mon Sep 17 00:00:00 2001 From: le-yams Date: Tue, 27 Aug 2013 11:51:21 +0200 Subject: [PATCH 011/190] Add pagination update on itemsPerPage change --- coffee/atPagination.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/coffee/atPagination.coffee b/coffee/atPagination.coffee index c46235b..4b5cccb 100644 --- a/coffee/atPagination.coffee +++ b/coffee/atPagination.coffee @@ -59,8 +59,10 @@ angular.module("angular-table").directive "atPagination", [() -> $scope.update() + $scope.$watch "itemsPerPage", () -> + $scope.update() $scope.$watch "list", () -> $scope.update() } -] \ No newline at end of file +] From 532286df4440e83e25b9954434d93e9fb5dfd89b Mon Sep 17 00:00:00 2001 From: le-yams Date: Tue, 27 Aug 2013 11:53:57 +0200 Subject: [PATCH 012/190] Update angular-table.js --- angular-table.js | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/angular-table.js b/angular-table.js index fed6bbf..b35b977 100644 --- a/angular-table.js +++ b/angular-table.js @@ -8,10 +8,8 @@ angular.module("angular-table").directive("atTable", [ "metaCollector", "setupFactory", function(metaCollector, setupFactory) { var constructHeader, normalizeInput, validateInput; - constructHeader = function(customHeaderMarkup, bodyDefinitions) { var icon, td, th, title, tr, _i, _len; - tr = angular.element(""); for (_i = 0, _len = bodyDefinitions.length; _i < _len; _i++) { td = bodyDefinitions[_i]; @@ -48,7 +46,6 @@ scope: true, compile: function(element, attributes, transclude) { var bodyDefinition, customHeaderMarkup, setup, tbody, thead, tr; - normalizeInput(attributes); validateInput(attributes); thead = element.find("thead"); @@ -92,7 +89,6 @@ restrict: "AC", compile: function(element, attributes, transclude) { var attribute; - attribute = element.attr("attribute"); if (!attribute) { throw "at-implicit specified without attribute: " + (element.html()); @@ -119,14 +115,12 @@ $scope.currentPage = 0; $scope.update = function() { var x; - $scope.currentPage = 0; if ($scope.list) { if ($scope.list.length > 0) { $scope.numberOfPages = Math.ceil($scope.list.length / $scope.itemsPerPage); $scope.pages = (function() { var _i, _ref, _results; - _results = []; for (x = _i = 0, _ref = $scope.numberOfPages - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { _results.push(x); @@ -147,7 +141,6 @@ }; $scope.getFillerArray = function() { var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; - if ($scope.currentPage === $scope.numberOfPages - 1) { itemCountOnLastPage = $scope.list.length % $scope.itemsPerPage; if (itemCountOnLastPage !== 0 || $scope.list.length === 0) { @@ -168,6 +161,9 @@ return $scope.currentPage = page; }; $scope.update(); + $scope.$watch("itemsPerPage", function() { + return $scope.update(); + }); return $scope.$watch("list", function() { return $scope.update(); }); @@ -179,7 +175,6 @@ angular.module("angular-table").service("metaCollector", [ function() { var capitaliseFirstLetter, extractWidth, getInitialSortDirection, isSortable; - capitaliseFirstLetter = function(string) { if (string) { return string.charAt(0).toUpperCase() + string.slice(1); @@ -189,7 +184,6 @@ }; extractWidth = function(classes) { var width; - width = /([0-9]+px)/i.exec(classes); if (width) { return width[0]; @@ -199,7 +193,6 @@ }; isSortable = function(classes) { var sortable; - sortable = /(sortable)/i.exec(classes); if (sortable) { return true; @@ -209,7 +202,6 @@ }; getInitialSortDirection = function(td) { var initialSorting; - initialSorting = td.attr("initial-sorting"); if (initialSorting) { if (initialSorting === "asc" || initialSorting === "desc") { @@ -222,7 +214,6 @@ return { collectCustomHeaderMarkup: function(thead) { var customHeaderMarkup, th, tr, _i, _len, _ref; - customHeaderMarkup = {}; tr = thead.find("tr"); _ref = tr.find("th"); @@ -235,7 +226,6 @@ }, collectBodyDefinition: function(tbody) { var attribute, bodyDefinition, initialSortDirection, sortable, td, title, width, _i, _len, _ref; - bodyDefinition = {}; bodyDefinition.tds = []; bodyDefinition.initialSorting = void 0; @@ -272,12 +262,10 @@ angular.module("angular-table").factory("setupFactory", [ function() { var PaginationSetup, StandardSetup, limitToExpression, orderByExpression, setupTr; - orderByExpression = "| orderBy:predicate:descending"; limitToExpression = "| limitTo:fromPage() | limitTo:toPage()"; setupTr = function(element, repeatString) { var tbody, tr; - tbody = element.find("tbody"); tr = tbody.find("tr"); tr.attr("ng-repeat", repeatString); @@ -285,7 +273,6 @@ }; StandardSetup = function(attributes) { var repeatString; - repeatString = "item in " + attributes.list + " " + orderByExpression; this.compile = function(element, attributes, transclude) { return setupTr(element, repeatString); @@ -294,7 +281,6 @@ }; PaginationSetup = function(attributes) { var paginationName, repeatString, sortContext; - sortContext = attributes.sortContext || "global"; paginationName = attributes.pagination; if (sortContext === "global") { @@ -306,7 +292,6 @@ } this.compile = function(element, attributes, transclude) { var fillerTr, tbody, td, tdString, tds, _i, _len; - tbody = setupTr(element, repeatString); if (typeof attributes.fillLastPage !== "undefined") { tds = element.find("td"); From 1375c52ddf9c805f1cb5e3186dd911517993e431 Mon Sep 17 00:00:00 2001 From: le-yams Date: Tue, 27 Aug 2013 11:57:43 +0200 Subject: [PATCH 013/190] Add pagination update on itemsPerPage change --- angular-table.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/angular-table.min.js b/angular-table.min.js index 2785b5e..624145d 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.6 // license: MIT // homepage: http://github.com/ssmm/angular-table -!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n,r;return i=function(t,e){var i,n,r,a,l,o,u;for(l=angular.element(""),o=0,u=e.length;u>o;o++)n=e[o],r=angular.element(""),a=t[n.attribute]||n.title,r.html(""+a),n.sortable&&(r.attr("ng-click","predicate = '"+n.attribute+"'; descending = !descending;"),i=angular.element(""),i.attr("ng-class","getSortIcon('"+n.attribute+"')"),r.append(i)),r.attr("width",n.width),l.append(r);return l},r=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(a,l,o){var u,c,g,s,d,f;return n(l),r(l),d=a.find("thead"),s=a.find("tbody"),u=t.collectBodyDefinition(s),d[0]&&(c=t.collectCustomHeaderMarkup(d),f=d.find("tr"),f.remove(),d.append(i(c,u.tds))),g=e(l),g.compile(a,l,o),{post:function(t,e,i){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){return t.instance=t,t.currentPage=0,t.update=function(){var e;return t.currentPage=0,t.list?(t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]),t.list=t.list):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,l,o;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,o=[],n=r=a=t.list.length,l=t.list.length+e;l>=a?l>=r:r>=l;n=l>=a?++r:--r)o.push(n);return o}return[]}},t.goToPage=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e),t.currentPage=e},t.update(),t.$watch("list",function(){return t.update()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,l;for(e={},n=t.find("tr"),l=n.find("th"),r=0,a=l.length;a>r;r++)i=l[r],i=angular.element(i),e[i.attr("attribute")]=i.html();return e},collectBodyDefinition:function(r){var a,l,o,u,c,g,s,d,f,p;for(l={},l.tds=[],l.initialSorting=void 0,p=r.find("td"),d=0,f=p.length;f>d;d++)if(c=p[d],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),l.tds.push({attribute:a,title:g,sortable:u,width:s}),o=i(c)){if(!a)throw"initial-sorting specified without attribute.";l.initialSorting={},l.initialSorting.direction=o,l.initialSorting.predicate=a}return l}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a,l;if(l=t.sortContext||"global",e=t.pagination,"global"===l)a="item in "+e+".list "+n+" "+i;else{if("page"!==l)throw"Invalid sort-context: "+l+".";a="item in "+e+".list "+i+" "+n+" "}this.compile=function(t,i){var n,l,o,u,c,g,s;if(l=r(t,a),"undefined"!=typeof i.fillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)o=c[g],u+="";return n=angular.element(""+u+""),n.attr("ng-repeat","item in "+e+".getFillerArray() "),l.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this); \ No newline at end of file +(function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n,r;return i=function(t,e){var i,n,r,a,l,o,u;for(l=angular.element(""),o=0,u=e.length;u>o;o++)n=e[o],r=angular.element(""),a=t[n.attribute]||n.title,r.html(""+a),n.sortable&&(r.attr("ng-click","predicate = '"+n.attribute+"'; descending = !descending;"),i=angular.element(""),i.attr("ng-class","getSortIcon('"+n.attribute+"')"),r.append(i)),r.attr("width",n.width),l.append(r);return l},r=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(a,l,o){var u,c,g,s,d,f;return n(l),r(l),d=a.find("thead"),s=a.find("tbody"),u=t.collectBodyDefinition(s),d[0]&&(c=t.collectCustomHeaderMarkup(d),f=d.find("tr"),f.remove(),d.append(i(c,u.tds))),g=e(l),g.compile(a,l,o),{post:function(t,e,i){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){return t.instance=t,t.currentPage=0,t.update=function(){var e;return t.currentPage=0,t.list?(t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]),t.list=t.list):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,l,o;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,o=[],n=r=a=t.list.length,l=t.list.length+e;l>=a?l>=r:r>=l;n=l>=a?++r:--r)o.push(n);return o}return[]}},t.goToPage=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e),t.currentPage=e},t.update(),t.$watch("itemsPerPage",function(){return t.update()}),t.$watch("list",function(){return t.update()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,l;for(e={},n=t.find("tr"),l=n.find("th"),r=0,a=l.length;a>r;r++)i=l[r],i=angular.element(i),e[i.attr("attribute")]=i.html();return e},collectBodyDefinition:function(r){var a,l,o,u,c,g,s,d,f,p;for(l={},l.tds=[],l.initialSorting=void 0,p=r.find("td"),d=0,f=p.length;f>d;d++)if(c=p[d],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),l.tds.push({attribute:a,title:g,sortable:u,width:s}),o=i(c)){if(!a)throw"initial-sorting specified without attribute.";l.initialSorting={},l.initialSorting.direction=o,l.initialSorting.predicate=a}return l}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a,l;if(l=t.sortContext||"global",e=t.pagination,"global"===l)a="item in "+e+".list "+n+" "+i;else{if("page"!==l)throw"Invalid sort-context: "+l+".";a="item in "+e+".list "+i+" "+n+" "}this.compile=function(t,i){var n,l,o,u,c,g,s;if(l=r(t,a),"undefined"!=typeof i.fillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)o=c[g],u+="";return n=angular.element(""+u+""),n.attr("ng-repeat","item in "+e+".getFillerArray() "),l.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}).call(this); From 4bef352cdbb0f0c9c0fe50e1b817613d403b36ba Mon Sep 17 00:00:00 2001 From: le-yams Date: Tue, 27 Aug 2013 12:03:14 +0200 Subject: [PATCH 014/190] Add pagination update on itemsPerPage change --- angular-table.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/angular-table.js b/angular-table.js index b35b977..80e5a52 100644 --- a/angular-table.js +++ b/angular-table.js @@ -8,8 +8,10 @@ angular.module("angular-table").directive("atTable", [ "metaCollector", "setupFactory", function(metaCollector, setupFactory) { var constructHeader, normalizeInput, validateInput; + constructHeader = function(customHeaderMarkup, bodyDefinitions) { var icon, td, th, title, tr, _i, _len; + tr = angular.element(""); for (_i = 0, _len = bodyDefinitions.length; _i < _len; _i++) { td = bodyDefinitions[_i]; @@ -46,6 +48,7 @@ scope: true, compile: function(element, attributes, transclude) { var bodyDefinition, customHeaderMarkup, setup, tbody, thead, tr; + normalizeInput(attributes); validateInput(attributes); thead = element.find("thead"); @@ -89,6 +92,7 @@ restrict: "AC", compile: function(element, attributes, transclude) { var attribute; + attribute = element.attr("attribute"); if (!attribute) { throw "at-implicit specified without attribute: " + (element.html()); @@ -115,12 +119,14 @@ $scope.currentPage = 0; $scope.update = function() { var x; + $scope.currentPage = 0; if ($scope.list) { if ($scope.list.length > 0) { $scope.numberOfPages = Math.ceil($scope.list.length / $scope.itemsPerPage); $scope.pages = (function() { var _i, _ref, _results; + _results = []; for (x = _i = 0, _ref = $scope.numberOfPages - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { _results.push(x); @@ -141,6 +147,7 @@ }; $scope.getFillerArray = function() { var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; + if ($scope.currentPage === $scope.numberOfPages - 1) { itemCountOnLastPage = $scope.list.length % $scope.itemsPerPage; if (itemCountOnLastPage !== 0 || $scope.list.length === 0) { @@ -175,6 +182,7 @@ angular.module("angular-table").service("metaCollector", [ function() { var capitaliseFirstLetter, extractWidth, getInitialSortDirection, isSortable; + capitaliseFirstLetter = function(string) { if (string) { return string.charAt(0).toUpperCase() + string.slice(1); @@ -184,6 +192,7 @@ }; extractWidth = function(classes) { var width; + width = /([0-9]+px)/i.exec(classes); if (width) { return width[0]; @@ -193,6 +202,7 @@ }; isSortable = function(classes) { var sortable; + sortable = /(sortable)/i.exec(classes); if (sortable) { return true; @@ -202,6 +212,7 @@ }; getInitialSortDirection = function(td) { var initialSorting; + initialSorting = td.attr("initial-sorting"); if (initialSorting) { if (initialSorting === "asc" || initialSorting === "desc") { @@ -214,6 +225,7 @@ return { collectCustomHeaderMarkup: function(thead) { var customHeaderMarkup, th, tr, _i, _len, _ref; + customHeaderMarkup = {}; tr = thead.find("tr"); _ref = tr.find("th"); @@ -226,6 +238,7 @@ }, collectBodyDefinition: function(tbody) { var attribute, bodyDefinition, initialSortDirection, sortable, td, title, width, _i, _len, _ref; + bodyDefinition = {}; bodyDefinition.tds = []; bodyDefinition.initialSorting = void 0; @@ -262,10 +275,12 @@ angular.module("angular-table").factory("setupFactory", [ function() { var PaginationSetup, StandardSetup, limitToExpression, orderByExpression, setupTr; + orderByExpression = "| orderBy:predicate:descending"; limitToExpression = "| limitTo:fromPage() | limitTo:toPage()"; setupTr = function(element, repeatString) { var tbody, tr; + tbody = element.find("tbody"); tr = tbody.find("tr"); tr.attr("ng-repeat", repeatString); @@ -273,6 +288,7 @@ }; StandardSetup = function(attributes) { var repeatString; + repeatString = "item in " + attributes.list + " " + orderByExpression; this.compile = function(element, attributes, transclude) { return setupTr(element, repeatString); @@ -281,6 +297,7 @@ }; PaginationSetup = function(attributes) { var paginationName, repeatString, sortContext; + sortContext = attributes.sortContext || "global"; paginationName = attributes.pagination; if (sortContext === "global") { @@ -292,6 +309,7 @@ } this.compile = function(element, attributes, transclude) { var fillerTr, tbody, td, tdString, tds, _i, _len; + tbody = setupTr(element, repeatString); if (typeof attributes.fillLastPage !== "undefined") { tds = element.find("td"); From 8b3ea86fe5846bb7e9ba1cba681213a21a9182c8 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Thu, 5 Sep 2013 23:21:00 +0200 Subject: [PATCH 015/190] commented out unfinished code --- coffee/atPagination.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/coffee/atPagination.coffee b/coffee/atPagination.coffee index 513a07c..28c530e 100644 --- a/coffee/atPagination.coffee +++ b/coffee/atPagination.coffee @@ -62,8 +62,8 @@ angular.module("angular-table").directive "atPagination", [() -> update() - $scope.$watch "list", (newValue, oldValue) -> - update() + # $scope.$watch "list", (newValue, oldValue) -> + # update() # # console.log newValue.length, oldValue.length # if newValue.length != oldValue.length # update false @@ -78,6 +78,7 @@ angular.module("angular-table").directive "atPagination", [() -> $scope.$watch "itemsPerPage", () -> $scope.update() + $scope.$watch "list", () -> $scope.update() From fa47656c80c78cdd12d55a92ae7b11e60eaff8a5 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Thu, 5 Sep 2013 23:21:11 +0200 Subject: [PATCH 016/190] commented out unfinished code --- angular-table.js | 3 --- angular-table.min.js | 2 +- gem/app/assets/javascripts/angular-table.js | 3 --- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/angular-table.js b/angular-table.js index e4fbca5..4bdaba2 100644 --- a/angular-table.js +++ b/angular-table.js @@ -172,9 +172,6 @@ return $scope.currentPage = normalizePage(page); }; update(); - $scope.$watch("list", function(newValue, oldValue) { - return update(); - }); $scope.$watch("itemsPerPage", function() { return $scope.update(); }); diff --git a/angular-table.min.js b/angular-table.min.js index 098b8f7..18f21fe 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.6 // license: MIT // homepage: http://github.com/ssmm/angular-table -!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n,r;return i=function(t,e){var i,n,r,a,o,l,u;for(o=angular.element(""),l=0,u=e.length;u>l;l++)n=e[l],r=angular.element(""),a=t[n.attribute]||n.title,r.html(""+a),n.sortable&&(r.attr("ng-click","predicate = '"+n.attribute+"'; descending = !descending;"),i=angular.element(""),i.attr("ng-class","getSortIcon('"+n.attribute+"')"),r.append(i)),r.attr("width",n.width),o.append(r);return o},r=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(a,o,l){var u,c,g,s,f,d;return n(o),r(o),f=a.find("thead"),s=a.find("tbody"),u=t.collectBodyDefinition(s),f[0]&&(c=t.collectCustomHeaderMarkup(f),d=f.find("tr"),d.remove(),f.append(i(c,u.tds))),g=e(o),g.compile(a,o,l),{post:function(t,e,i){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){var e,i;return t.instance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},i=function(){var e;return t.currentPage=0,t.list?t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,o,l;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,l=[],n=r=a=t.list.length,o=t.list.length+e;o>=a?o>=r:r>=o;n=o>=a?++r:--r)l.push(n);return l}return[]}},t.goToPage=function(i){return t.currentPage=e(i)},i(),t.$watch("list",function(){return i()}),t.$watch("itemsPerPage",function(){return t.update()}),t.$watch("list",function(){return t.update()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("attribute")]=i.html();return e},collectBodyDefinition:function(r){var a,o,l,u,c,g,s,f,d,p;for(o={},o.tds=[],o.initialSorting=void 0,p=r.find("td"),f=0,d=p.length;d>f;f++)if(c=p[f],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:a,title:g,sortable:u,width:s}),l=i(c)){if(!a)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=l,o.initialSorting.predicate=a}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a,o;if(o=t.sortContext||"global",e=t.pagination,"global"===o)a="item in "+e+".list "+n+" "+i;else{if("page"!==o)throw"Invalid sort-context: "+o+".";a="item in "+e+".list "+i+" "+n+" "}this.compile=function(t,i){var n,o,l,u,c,g,s;if(o=r(t,a),"undefined"!=typeof i.fillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)l=c[g],u+="";return n=angular.element(""+u+""),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this); \ No newline at end of file +!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n,r;return i=function(t,e){var i,n,r,a,o,l,u;for(o=angular.element(""),l=0,u=e.length;u>l;l++)n=e[l],r=angular.element(""),a=t[n.attribute]||n.title,r.html(""+a),n.sortable&&(r.attr("ng-click","predicate = '"+n.attribute+"'; descending = !descending;"),i=angular.element(""),i.attr("ng-class","getSortIcon('"+n.attribute+"')"),r.append(i)),r.attr("width",n.width),o.append(r);return o},r=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(a,o,l){var u,c,g,s,f,d;return n(o),r(o),f=a.find("thead"),s=a.find("tbody"),u=t.collectBodyDefinition(s),f[0]&&(c=t.collectCustomHeaderMarkup(f),d=f.find("tr"),d.remove(),f.append(i(c,u.tds))),g=e(o),g.compile(a,o,l),{post:function(t,e,i){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){var e,i;return t.instance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},i=function(){var e;return t.currentPage=0,t.list?t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,o,l;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,l=[],n=r=a=t.list.length,o=t.list.length+e;o>=a?o>=r:r>=o;n=o>=a?++r:--r)l.push(n);return l}return[]}},t.goToPage=function(i){return t.currentPage=e(i)},i(),t.$watch("itemsPerPage",function(){return t.update()}),t.$watch("list",function(){return t.update()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("attribute")]=i.html();return e},collectBodyDefinition:function(r){var a,o,l,u,c,g,s,f,d,p;for(o={},o.tds=[],o.initialSorting=void 0,p=r.find("td"),f=0,d=p.length;d>f;f++)if(c=p[f],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:a,title:g,sortable:u,width:s}),l=i(c)){if(!a)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=l,o.initialSorting.predicate=a}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a,o;if(o=t.sortContext||"global",e=t.pagination,"global"===o)a="item in "+e+".list "+n+" "+i;else{if("page"!==o)throw"Invalid sort-context: "+o+".";a="item in "+e+".list "+i+" "+n+" "}this.compile=function(t,i){var n,o,l,u,c,g,s;if(o=r(t,a),"undefined"!=typeof i.fillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)l=c[g],u+="";return n=angular.element(""+u+""),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this); \ No newline at end of file diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index e4fbca5..4bdaba2 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -172,9 +172,6 @@ return $scope.currentPage = normalizePage(page); }; update(); - $scope.$watch("list", function(newValue, oldValue) { - return update(); - }); $scope.$watch("itemsPerPage", function() { return $scope.update(); }); From d9ae3e7941bab4a66fa85935d2b8cd41f3dab988 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Thu, 5 Sep 2013 23:44:51 +0200 Subject: [PATCH 017/190] fixed typo --- angular-table.js | 2 +- angular-table.min.js | 2 +- coffee/atPagination.coffee | 5 +---- gem/app/assets/javascripts/angular-table.js | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/angular-table.js b/angular-table.js index 4bdaba2..c16c69b 100644 --- a/angular-table.js +++ b/angular-table.js @@ -172,7 +172,7 @@ return $scope.currentPage = normalizePage(page); }; update(); - $scope.$watch("itemsPerPage", function() { + $scoepe.$watch("itemsPerPage", function() { return $scope.update(); }); return $scope.$watch("list", function() { diff --git a/angular-table.min.js b/angular-table.min.js index 18f21fe..f389931 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.6 // license: MIT // homepage: http://github.com/ssmm/angular-table -!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n,r;return i=function(t,e){var i,n,r,a,o,l,u;for(o=angular.element(""),l=0,u=e.length;u>l;l++)n=e[l],r=angular.element(""),a=t[n.attribute]||n.title,r.html(""+a),n.sortable&&(r.attr("ng-click","predicate = '"+n.attribute+"'; descending = !descending;"),i=angular.element(""),i.attr("ng-class","getSortIcon('"+n.attribute+"')"),r.append(i)),r.attr("width",n.width),o.append(r);return o},r=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(a,o,l){var u,c,g,s,f,d;return n(o),r(o),f=a.find("thead"),s=a.find("tbody"),u=t.collectBodyDefinition(s),f[0]&&(c=t.collectCustomHeaderMarkup(f),d=f.find("tr"),d.remove(),f.append(i(c,u.tds))),g=e(o),g.compile(a,o,l),{post:function(t,e,i){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){var e,i;return t.instance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},i=function(){var e;return t.currentPage=0,t.list?t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,o,l;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,l=[],n=r=a=t.list.length,o=t.list.length+e;o>=a?o>=r:r>=o;n=o>=a?++r:--r)l.push(n);return l}return[]}},t.goToPage=function(i){return t.currentPage=e(i)},i(),t.$watch("itemsPerPage",function(){return t.update()}),t.$watch("list",function(){return t.update()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("attribute")]=i.html();return e},collectBodyDefinition:function(r){var a,o,l,u,c,g,s,f,d,p;for(o={},o.tds=[],o.initialSorting=void 0,p=r.find("td"),f=0,d=p.length;d>f;f++)if(c=p[f],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:a,title:g,sortable:u,width:s}),l=i(c)){if(!a)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=l,o.initialSorting.predicate=a}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a,o;if(o=t.sortContext||"global",e=t.pagination,"global"===o)a="item in "+e+".list "+n+" "+i;else{if("page"!==o)throw"Invalid sort-context: "+o+".";a="item in "+e+".list "+i+" "+n+" "}this.compile=function(t,i){var n,o,l,u,c,g,s;if(o=r(t,a),"undefined"!=typeof i.fillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)l=c[g],u+="";return n=angular.element(""+u+""),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this); \ No newline at end of file +!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n,r;return i=function(t,e){var i,n,r,a,o,l,u;for(o=angular.element(""),l=0,u=e.length;u>l;l++)n=e[l],r=angular.element(""),a=t[n.attribute]||n.title,r.html(""+a),n.sortable&&(r.attr("ng-click","predicate = '"+n.attribute+"'; descending = !descending;"),i=angular.element(""),i.attr("ng-class","getSortIcon('"+n.attribute+"')"),r.append(i)),r.attr("width",n.width),o.append(r);return o},r=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(a,o,l){var u,c,g,s,f,d;return n(o),r(o),f=a.find("thead"),s=a.find("tbody"),u=t.collectBodyDefinition(s),f[0]&&(c=t.collectCustomHeaderMarkup(f),d=f.find("tr"),d.remove(),f.append(i(c,u.tds))),g=e(o),g.compile(a,o,l),{post:function(t,e,i){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){var e,i;return t.instance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},i=function(){var e;return t.currentPage=0,t.list?t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,o,l;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,l=[],n=r=a=t.list.length,o=t.list.length+e;o>=a?o>=r:r>=o;n=o>=a?++r:--r)l.push(n);return l}return[]}},t.goToPage=function(i){return t.currentPage=e(i)},i(),$scoepe.$watch("itemsPerPage",function(){return t.update()}),t.$watch("list",function(){return t.update()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("attribute")]=i.html();return e},collectBodyDefinition:function(r){var a,o,l,u,c,g,s,f,d,p;for(o={},o.tds=[],o.initialSorting=void 0,p=r.find("td"),f=0,d=p.length;d>f;f++)if(c=p[f],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:a,title:g,sortable:u,width:s}),l=i(c)){if(!a)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=l,o.initialSorting.predicate=a}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a,o;if(o=t.sortContext||"global",e=t.pagination,"global"===o)a="item in "+e+".list "+n+" "+i;else{if("page"!==o)throw"Invalid sort-context: "+o+".";a="item in "+e+".list "+i+" "+n+" "}this.compile=function(t,i){var n,o,l,u,c,g,s;if(o=r(t,a),"undefined"!=typeof i.fillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)l=c[g],u+="";return n=angular.element(""+u+""),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this); \ No newline at end of file diff --git a/coffee/atPagination.coffee b/coffee/atPagination.coffee index 28c530e..21242b6 100644 --- a/coffee/atPagination.coffee +++ b/coffee/atPagination.coffee @@ -71,17 +71,14 @@ angular.module("angular-table").directive "atPagination", [() -> # update true # , true - # Additional watch on the length of the list. This will - # be fired if items are added to or removed from it. # $scope.$watch "list.length", (newValue, oldValue) -> # update(false) if newValue != oldValue - $scope.$watch "itemsPerPage", () -> + $scoepe.$watch "itemsPerPage", () -> $scope.update() $scope.$watch "list", () -> $scope.update() - } ] diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 4bdaba2..c16c69b 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -172,7 +172,7 @@ return $scope.currentPage = normalizePage(page); }; update(); - $scope.$watch("itemsPerPage", function() { + $scoepe.$watch("itemsPerPage", function() { return $scope.update(); }); return $scope.$watch("list", function() { From 956249e96959c2f3ba62e460ee497571841464bb Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Thu, 5 Sep 2013 23:45:12 +0200 Subject: [PATCH 018/190] fixed typo --- angular-table.js | 2 +- angular-table.min.js | 2 +- coffee/atPagination.coffee | 2 +- gem/app/assets/javascripts/angular-table.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/angular-table.js b/angular-table.js index c16c69b..4bdaba2 100644 --- a/angular-table.js +++ b/angular-table.js @@ -172,7 +172,7 @@ return $scope.currentPage = normalizePage(page); }; update(); - $scoepe.$watch("itemsPerPage", function() { + $scope.$watch("itemsPerPage", function() { return $scope.update(); }); return $scope.$watch("list", function() { diff --git a/angular-table.min.js b/angular-table.min.js index f389931..18f21fe 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.6 // license: MIT // homepage: http://github.com/ssmm/angular-table -!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n,r;return i=function(t,e){var i,n,r,a,o,l,u;for(o=angular.element(""),l=0,u=e.length;u>l;l++)n=e[l],r=angular.element(""),a=t[n.attribute]||n.title,r.html(""+a),n.sortable&&(r.attr("ng-click","predicate = '"+n.attribute+"'; descending = !descending;"),i=angular.element(""),i.attr("ng-class","getSortIcon('"+n.attribute+"')"),r.append(i)),r.attr("width",n.width),o.append(r);return o},r=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(a,o,l){var u,c,g,s,f,d;return n(o),r(o),f=a.find("thead"),s=a.find("tbody"),u=t.collectBodyDefinition(s),f[0]&&(c=t.collectCustomHeaderMarkup(f),d=f.find("tr"),d.remove(),f.append(i(c,u.tds))),g=e(o),g.compile(a,o,l),{post:function(t,e,i){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){var e,i;return t.instance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},i=function(){var e;return t.currentPage=0,t.list?t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,o,l;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,l=[],n=r=a=t.list.length,o=t.list.length+e;o>=a?o>=r:r>=o;n=o>=a?++r:--r)l.push(n);return l}return[]}},t.goToPage=function(i){return t.currentPage=e(i)},i(),$scoepe.$watch("itemsPerPage",function(){return t.update()}),t.$watch("list",function(){return t.update()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("attribute")]=i.html();return e},collectBodyDefinition:function(r){var a,o,l,u,c,g,s,f,d,p;for(o={},o.tds=[],o.initialSorting=void 0,p=r.find("td"),f=0,d=p.length;d>f;f++)if(c=p[f],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:a,title:g,sortable:u,width:s}),l=i(c)){if(!a)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=l,o.initialSorting.predicate=a}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a,o;if(o=t.sortContext||"global",e=t.pagination,"global"===o)a="item in "+e+".list "+n+" "+i;else{if("page"!==o)throw"Invalid sort-context: "+o+".";a="item in "+e+".list "+i+" "+n+" "}this.compile=function(t,i){var n,o,l,u,c,g,s;if(o=r(t,a),"undefined"!=typeof i.fillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)l=c[g],u+="";return n=angular.element(""+u+""),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this); \ No newline at end of file +!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n,r;return i=function(t,e){var i,n,r,a,o,l,u;for(o=angular.element(""),l=0,u=e.length;u>l;l++)n=e[l],r=angular.element(""),a=t[n.attribute]||n.title,r.html(""+a),n.sortable&&(r.attr("ng-click","predicate = '"+n.attribute+"'; descending = !descending;"),i=angular.element(""),i.attr("ng-class","getSortIcon('"+n.attribute+"')"),r.append(i)),r.attr("width",n.width),o.append(r);return o},r=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(a,o,l){var u,c,g,s,f,d;return n(o),r(o),f=a.find("thead"),s=a.find("tbody"),u=t.collectBodyDefinition(s),f[0]&&(c=t.collectCustomHeaderMarkup(f),d=f.find("tr"),d.remove(),f.append(i(c,u.tds))),g=e(o),g.compile(a,o,l),{post:function(t,e,i){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){var e,i;return t.instance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},i=function(){var e;return t.currentPage=0,t.list?t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,o,l;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,l=[],n=r=a=t.list.length,o=t.list.length+e;o>=a?o>=r:r>=o;n=o>=a?++r:--r)l.push(n);return l}return[]}},t.goToPage=function(i){return t.currentPage=e(i)},i(),t.$watch("itemsPerPage",function(){return t.update()}),t.$watch("list",function(){return t.update()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("attribute")]=i.html();return e},collectBodyDefinition:function(r){var a,o,l,u,c,g,s,f,d,p;for(o={},o.tds=[],o.initialSorting=void 0,p=r.find("td"),f=0,d=p.length;d>f;f++)if(c=p[f],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:a,title:g,sortable:u,width:s}),l=i(c)){if(!a)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=l,o.initialSorting.predicate=a}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a,o;if(o=t.sortContext||"global",e=t.pagination,"global"===o)a="item in "+e+".list "+n+" "+i;else{if("page"!==o)throw"Invalid sort-context: "+o+".";a="item in "+e+".list "+i+" "+n+" "}this.compile=function(t,i){var n,o,l,u,c,g,s;if(o=r(t,a),"undefined"!=typeof i.fillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)l=c[g],u+="";return n=angular.element(""+u+""),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this); \ No newline at end of file diff --git a/coffee/atPagination.coffee b/coffee/atPagination.coffee index 21242b6..83f5484 100644 --- a/coffee/atPagination.coffee +++ b/coffee/atPagination.coffee @@ -74,7 +74,7 @@ angular.module("angular-table").directive "atPagination", [() -> # $scope.$watch "list.length", (newValue, oldValue) -> # update(false) if newValue != oldValue - $scoepe.$watch "itemsPerPage", () -> + $scope.$watch "itemsPerPage", () -> $scope.update() $scope.$watch "list", () -> diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index c16c69b..4bdaba2 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -172,7 +172,7 @@ return $scope.currentPage = normalizePage(page); }; update(); - $scoepe.$watch("itemsPerPage", function() { + $scope.$watch("itemsPerPage", function() { return $scope.update(); }); return $scope.$watch("list", function() { From caa2bd1d33b8f7b4038d6359302a4c1769bc6c4c Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 19 Oct 2013 17:49:51 +0200 Subject: [PATCH 019/190] resolves #15 --- coffee/atPagination.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coffee/atPagination.coffee b/coffee/atPagination.coffee index 83f5484..0d8b9d8 100644 --- a/coffee/atPagination.coffee +++ b/coffee/atPagination.coffee @@ -75,10 +75,10 @@ angular.module("angular-table").directive "atPagination", [() -> # update(false) if newValue != oldValue $scope.$watch "itemsPerPage", () -> - $scope.update() + update() $scope.$watch "list", () -> - $scope.update() + update() } ] From 4f6cda9ee38f655189f0b9e67747d682ce44332e Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 19 Oct 2013 18:37:12 +0200 Subject: [PATCH 020/190] resolves #6 --- coffee/atTable.coffee | 10 +++++++++- coffee/metaCollector.coffee | 13 ++++++++++--- test/templates/sortableTable.html | 4 +++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index a06baf4..83e7200 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -7,9 +7,17 @@ angular.module("angular-table").directive "atTable", ["metaCollector", "setupFac for td in bodyDefinitions th = angular.element("") - title = customHeaderMarkup[td.attribute] || td.title + if customHeaderMarkup[td.attribute] + for attribute in customHeaderMarkup[td.attribute].attributes + th.attr("#{attribute.name}", "#{attribute.value}") + title = customHeaderMarkup[td.attribute].content + else + title = td.title + th.html("#{title}") + + if td.sortable th.attr("ng-click", "predicate = '#{td.attribute}'; descending = !descending;") icon = angular.element("") diff --git a/coffee/metaCollector.coffee b/coffee/metaCollector.coffee index b5b7440..a2cb175 100644 --- a/coffee/metaCollector.coffee +++ b/coffee/metaCollector.coffee @@ -18,16 +18,23 @@ angular.module("angular-table").service "metaCollector", [() -> throw "Invalid value for initial-sorting: #{initialSorting}. Allowed values are 'asc' or 'desc'." return undefined + # collectAttributes = (attributes) -> + # result = [] + # for attribute in attributes + # result.push({name: attribute.name, value: attribute.value}) + { collectCustomHeaderMarkup: (thead) -> - customHeaderMarkup = {} + customHeaderMarkups = {} tr = thead.find "tr" for th in tr.find "th" th = angular.element(th) - customHeaderMarkup[th.attr("attribute")] = th.html() + customHeaderMarkup = customHeaderMarkups[th.attr("attribute")] = {} + customHeaderMarkup.content = th.html() + customHeaderMarkup.attributes = th[0].attributes - customHeaderMarkup + customHeaderMarkups collectBodyDefinition: (tbody) -> bodyDefinition = {} diff --git a/test/templates/sortableTable.html b/test/templates/sortableTable.html index be076f0..1c231c2 100644 --- a/test/templates/sortableTable.html +++ b/test/templates/sortableTable.html @@ -1,5 +1,7 @@
 
 
 
 
 
 
 
 
- + + + From f04b63e198f768e05d8037b7c265690d0ab728d2 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 19 Oct 2013 18:38:18 +0200 Subject: [PATCH 021/190] compiled v.0.0.7 --- angular-table.js | 29 ++++++++++++++------- angular-table.min.js | 4 +-- gem/app/assets/javascripts/angular-table.js | 29 ++++++++++++++------- gem/lib/angular-table/version.rb | 2 +- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/angular-table.js b/angular-table.js index 4bdaba2..d4c9c3c 100644 --- a/angular-table.js +++ b/angular-table.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 0.0.6 +// version: 0.0.7 // license: MIT // homepage: http://github.com/ssmm/angular-table (function() { @@ -10,13 +10,22 @@ var constructHeader, normalizeInput, validateInput; constructHeader = function(customHeaderMarkup, bodyDefinitions) { - var icon, td, th, title, tr, _i, _len; + var attribute, icon, td, th, title, tr, _i, _j, _len, _len1, _ref; tr = angular.element(""); for (_i = 0, _len = bodyDefinitions.length; _i < _len; _i++) { td = bodyDefinitions[_i]; th = angular.element(""); - title = customHeaderMarkup[td.attribute] || td.title; + if (customHeaderMarkup[td.attribute]) { + _ref = customHeaderMarkup[td.attribute].attributes; + for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { + attribute = _ref[_j]; + th.attr("" + attribute.name, "" + attribute.value); + } + title = customHeaderMarkup[td.attribute].content; + } else { + title = td.title; + } th.html("" + title); if (td.sortable) { th.attr("ng-click", "predicate = '" + td.attribute + "'; descending = !descending;"); @@ -173,10 +182,10 @@ }; update(); $scope.$watch("itemsPerPage", function() { - return $scope.update(); + return update(); }); return $scope.$watch("list", function() { - return $scope.update(); + return update(); }); } }; @@ -228,17 +237,19 @@ }; return { collectCustomHeaderMarkup: function(thead) { - var customHeaderMarkup, th, tr, _i, _len, _ref; + var customHeaderMarkup, customHeaderMarkups, th, tr, _i, _len, _ref; - customHeaderMarkup = {}; + customHeaderMarkups = {}; tr = thead.find("tr"); _ref = tr.find("th"); for (_i = 0, _len = _ref.length; _i < _len; _i++) { th = _ref[_i]; th = angular.element(th); - customHeaderMarkup[th.attr("attribute")] = th.html(); + customHeaderMarkup = customHeaderMarkups[th.attr("attribute")] = {}; + customHeaderMarkup.content = th.html(); + customHeaderMarkup.attributes = th[0].attributes; } - return customHeaderMarkup; + return customHeaderMarkups; }, collectBodyDefinition: function(tbody) { var attribute, bodyDefinition, initialSortDirection, sortable, td, title, width, _i, _len, _ref; diff --git a/angular-table.min.js b/angular-table.min.js index 18f21fe..fc4c4e4 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 0.0.6 +// version: 0.0.7 // license: MIT // homepage: http://github.com/ssmm/angular-table -!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n,r;return i=function(t,e){var i,n,r,a,o,l,u;for(o=angular.element(""),l=0,u=e.length;u>l;l++)n=e[l],r=angular.element(""),a=t[n.attribute]||n.title,r.html(""+a),n.sortable&&(r.attr("ng-click","predicate = '"+n.attribute+"'; descending = !descending;"),i=angular.element(""),i.attr("ng-class","getSortIcon('"+n.attribute+"')"),r.append(i)),r.attr("width",n.width),o.append(r);return o},r=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(a,o,l){var u,c,g,s,f,d;return n(o),r(o),f=a.find("thead"),s=a.find("tbody"),u=t.collectBodyDefinition(s),f[0]&&(c=t.collectCustomHeaderMarkup(f),d=f.find("tr"),d.remove(),f.append(i(c,u.tds))),g=e(o),g.compile(a,o,l),{post:function(t,e,i){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){var e,i;return t.instance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},i=function(){var e;return t.currentPage=0,t.list?t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,o,l;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,l=[],n=r=a=t.list.length,o=t.list.length+e;o>=a?o>=r:r>=o;n=o>=a?++r:--r)l.push(n);return l}return[]}},t.goToPage=function(i){return t.currentPage=e(i)},i(),t.$watch("itemsPerPage",function(){return t.update()}),t.$watch("list",function(){return t.update()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("attribute")]=i.html();return e},collectBodyDefinition:function(r){var a,o,l,u,c,g,s,f,d,p;for(o={},o.tds=[],o.initialSorting=void 0,p=r.find("td"),f=0,d=p.length;d>f;f++)if(c=p[f],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:a,title:g,sortable:u,width:s}),l=i(c)){if(!a)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=l,o.initialSorting.predicate=a}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a,o;if(o=t.sortContext||"global",e=t.pagination,"global"===o)a="item in "+e+".list "+n+" "+i;else{if("page"!==o)throw"Invalid sort-context: "+o+".";a="item in "+e+".list "+i+" "+n+" "}this.compile=function(t,i){var n,o,l,u,c,g,s;if(o=r(t,a),"undefined"!=typeof i.fillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)l=c[g],u+="";return n=angular.element(""+u+""),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this); \ No newline at end of file +!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n,r;return i=function(t,e){var i,n,r,a,o,l,u,c,g,s,f;for(l=angular.element(""),u=0,g=e.length;g>u;u++){if(r=e[u],a=angular.element(""),t[r.attribute]){for(f=t[r.attribute].attributes,c=0,s=f.length;s>c;c++)i=f[c],a.attr(""+i.name,""+i.value);o=t[r.attribute].content}else o=r.title;a.html(""+o),r.sortable&&(a.attr("ng-click","predicate = '"+r.attribute+"'; descending = !descending;"),n=angular.element(""),n.attr("ng-class","getSortIcon('"+r.attribute+"')"),a.append(n)),a.attr("width",r.width),l.append(a)}return l},r=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(a,o,l){var u,c,g,s,f,d;return n(o),r(o),f=a.find("thead"),s=a.find("tbody"),u=t.collectBodyDefinition(s),f[0]&&(c=t.collectCustomHeaderMarkup(f),d=f.find("tr"),d.remove(),f.append(i(c,u.tds))),g=e(o),g.compile(a,o,l),{post:function(t,e,i){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){var e,i;return t.instance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},i=function(){var e;return t.currentPage=0,t.list?t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,o,l;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,l=[],n=r=a=t.list.length,o=t.list.length+e;o>=a?o>=r:r>=o;n=o>=a?++r:--r)l.push(n);return l}return[]}},t.goToPage=function(i){return t.currentPage=e(i)},i(),t.$watch("itemsPerPage",function(){return i()}),t.$watch("list",function(){return i()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,o,l;for(i={},r=t.find("tr"),l=r.find("th"),a=0,o=l.length;o>a;a++)n=l[a],n=angular.element(n),e=i[n.attr("attribute")]={},e.content=n.html(),e.attributes=n[0].attributes;return i},collectBodyDefinition:function(r){var a,o,l,u,c,g,s,f,d,p;for(o={},o.tds=[],o.initialSorting=void 0,p=r.find("td"),f=0,d=p.length;d>f;f++)if(c=p[f],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:a,title:g,sortable:u,width:s}),l=i(c)){if(!a)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=l,o.initialSorting.predicate=a}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a,o;if(o=t.sortContext||"global",e=t.pagination,"global"===o)a="item in "+e+".list "+n+" "+i;else{if("page"!==o)throw"Invalid sort-context: "+o+".";a="item in "+e+".list "+i+" "+n+" "}this.compile=function(t,i){var n,o,l,u,c,g,s;if(o=r(t,a),"undefined"!=typeof i.fillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)l=c[g],u+="";return n=angular.element(""+u+""),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this); \ No newline at end of file diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 4bdaba2..d4c9c3c 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 0.0.6 +// version: 0.0.7 // license: MIT // homepage: http://github.com/ssmm/angular-table (function() { @@ -10,13 +10,22 @@ var constructHeader, normalizeInput, validateInput; constructHeader = function(customHeaderMarkup, bodyDefinitions) { - var icon, td, th, title, tr, _i, _len; + var attribute, icon, td, th, title, tr, _i, _j, _len, _len1, _ref; tr = angular.element(""); for (_i = 0, _len = bodyDefinitions.length; _i < _len; _i++) { td = bodyDefinitions[_i]; th = angular.element(""); - title = customHeaderMarkup[td.attribute] || td.title; + if (customHeaderMarkup[td.attribute]) { + _ref = customHeaderMarkup[td.attribute].attributes; + for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { + attribute = _ref[_j]; + th.attr("" + attribute.name, "" + attribute.value); + } + title = customHeaderMarkup[td.attribute].content; + } else { + title = td.title; + } th.html("" + title); if (td.sortable) { th.attr("ng-click", "predicate = '" + td.attribute + "'; descending = !descending;"); @@ -173,10 +182,10 @@ }; update(); $scope.$watch("itemsPerPage", function() { - return $scope.update(); + return update(); }); return $scope.$watch("list", function() { - return $scope.update(); + return update(); }); } }; @@ -228,17 +237,19 @@ }; return { collectCustomHeaderMarkup: function(thead) { - var customHeaderMarkup, th, tr, _i, _len, _ref; + var customHeaderMarkup, customHeaderMarkups, th, tr, _i, _len, _ref; - customHeaderMarkup = {}; + customHeaderMarkups = {}; tr = thead.find("tr"); _ref = tr.find("th"); for (_i = 0, _len = _ref.length; _i < _len; _i++) { th = _ref[_i]; th = angular.element(th); - customHeaderMarkup[th.attr("attribute")] = th.html(); + customHeaderMarkup = customHeaderMarkups[th.attr("attribute")] = {}; + customHeaderMarkup.content = th.html(); + customHeaderMarkup.attributes = th[0].attributes; } - return customHeaderMarkup; + return customHeaderMarkups; }, collectBodyDefinition: function(tbody) { var attribute, bodyDefinition, initialSortDirection, sortable, td, title, width, _i, _len, _ref; diff --git a/gem/lib/angular-table/version.rb b/gem/lib/angular-table/version.rb index f4c4049..867b105 100644 --- a/gem/lib/angular-table/version.rb +++ b/gem/lib/angular-table/version.rb @@ -1,3 +1,3 @@ module AngularTable - VERSION = "0.0.6" + VERSION = "0.0.7" end From 690e6bcfab2dc2a4061b7109e0068ad54b19ec66 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 23 Dec 2013 20:13:30 +0100 Subject: [PATCH 022/190] refactored tests --- coffee/atTable.coffee | 2 - karma.conf.js | 7 +- test/header.coffee | 19 ++++ test/pagination.coffee | 26 +++++ test/sorting.coffee | 18 ++++ test/templates/header/header.html | 15 +++ test/templates/header/no_header.html | 9 ++ .../{sortableTable.html => sorting.html} | 0 test/test_helper.coffee | 28 ++++++ test/tests.coffee | 96 +++++++++---------- 10 files changed, 165 insertions(+), 55 deletions(-) create mode 100644 test/header.coffee create mode 100644 test/pagination.coffee create mode 100644 test/sorting.coffee create mode 100644 test/templates/header/header.html create mode 100644 test/templates/header/no_header.html rename test/templates/{sortableTable.html => sorting.html} (100%) create mode 100644 test/test_helper.coffee diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index 83e7200..1174159 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -16,8 +16,6 @@ angular.module("angular-table").directive "atTable", ["metaCollector", "setupFac th.html("#{title}") - - if td.sortable th.attr("ng-click", "predicate = '#{td.attribute}'; descending = !descending;") icon = angular.element("") diff --git a/karma.conf.js b/karma.conf.js index 681ff17..f596b1a 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -17,14 +17,17 @@ files = [ // important to load this first, because it contains the module definition "coffee/atTable.coffee", "coffee/*.coffee", + "test/test_helper.coffee", "test/*.coffee", - "test/templates/*.html" + "test/templates/*.html", + "test/templates/*/*.html" ]; preprocessors = { "coffee/*.coffee": "coffee", "test/*.coffee": "coffee", - "test/templates/*.html": "html2js" + "test/templates/*.html": "html2js", + "test/templates/*/*.html": "html2js" }; // list of files to exclude diff --git a/test/header.coffee b/test/header.coffee new file mode 100644 index 0000000..d400361 --- /dev/null +++ b/test/header.coffee @@ -0,0 +1,19 @@ +describe "angular-table", () -> + describe "header", () -> + + it "doesnt add a header at all if the header tag wasnt declared", () -> + @element = prepare_element(new TemplateCompiler("header/no_header.html"), (scope) ->) + header = @element.find("thead")[0] + expect(header).toBe undefined + + it "creates column headers implicitly", () -> + @element = prepare_element(new TemplateCompiler("header/header.html"), (scope) ->) + header = extract_html_to_array(@element.find("thead > tr > th")) + expect(header[0]).toEqual 'Name' + + it "allows to set custom column headers", () -> + @element = prepare_element(new TemplateCompiler("header/header.html"), (scope) ->) + header = extract_html_to_array(@element.find("thead > tr > th")) + expect(header[1]).toEqual 'The population' + expect(header[2]).toEqual 'Country' + expect(header[3]).toEqual 'Size' diff --git a/test/pagination.coffee b/test/pagination.coffee new file mode 100644 index 0000000..032f6dc --- /dev/null +++ b/test/pagination.coffee @@ -0,0 +1,26 @@ +describe "AnglarTable", () -> + + template2 = "test/templates/tableWithPagination.html" + + beforeEach(module("angular-table")) + beforeEach(module(template2)) + + it "adds pagination to a table", inject ($compile, $rootScope, $templateCache) -> + + element = load_template template2, $templateCache + + $rootScope.rammstein = [ + {name: "Till"}, {name: "Richard"}, {name: "Christoph"}, + {name: "Paul"}, {name: "Flake"}, {name: "Oliver"}] + + element = $compile(element)($rootScope) + $rootScope.$digest() + + tds = extract_html_to_array(element.find("td")) + expect(tds).toEqual ["Till", "Richard", "Christoph"] + + paginationLinks = element.find "a" + _.find(paginationLinks, (link) -> angular.element(link).html() == "2").click() + + tds = extract_html_to_array(element.find("td")) + expect(tds).toEqual ["Paul", "Flake", "Oliver"] diff --git a/test/sorting.coffee b/test/sorting.coffee new file mode 100644 index 0000000..346606f --- /dev/null +++ b/test/sorting.coffee @@ -0,0 +1,18 @@ +describe "angular-table", () -> + describe "sorting", () -> + + beforeEach(() -> + tc = new TemplateCompiler("sorting.html") + @element = prepare_element(tc, (scope) -> + scope.cities = [{name: "Helsinki"}, {name: "Zurich"}, {name: "Amsterdam"}] + ) + ) + + it "allows to set an initial sorting direction", () -> + tds = extract_html_to_array(@element.find("td")) + expect(tds).toEqual ["Zurich", "Helsinki", "Amsterdam"] + + it "makes columns sortable", () -> + @element.find("th")[0].click() + tds = extract_html_to_array(@element.find("td")) + expect(tds).toEqual ["Amsterdam", "Helsinki", "Zurich"] \ No newline at end of file diff --git a/test/templates/header/header.html b/test/templates/header/header.html new file mode 100644 index 0000000..863cea1 --- /dev/null +++ b/test/templates/header/header.html @@ -0,0 +1,15 @@ +
 
 
+ + + + + + + + + + + + + +
Size
{{item.country}}
diff --git a/test/templates/header/no_header.html b/test/templates/header/no_header.html new file mode 100644 index 0000000..e6e40d5 --- /dev/null +++ b/test/templates/header/no_header.html @@ -0,0 +1,9 @@ + + + + + + + + +
{{item.country}}
diff --git a/test/templates/sortableTable.html b/test/templates/sorting.html similarity index 100% rename from test/templates/sortableTable.html rename to test/templates/sorting.html diff --git a/test/test_helper.coffee b/test/test_helper.coffee new file mode 100644 index 0000000..bbb033d --- /dev/null +++ b/test/test_helper.coffee @@ -0,0 +1,28 @@ +extract_html_to_array = (tds) -> + _.map(tds, (td) -> angular.element(td).html()) + +load_template = (template_name, template_cache) -> + angular.element(template_cache.get(template_name)) + +prepare_element = (template_compiler, callback) -> + element = null + inject ($compile, $rootScope, $templateCache) -> + element = template_compiler.compile_template($compile, $rootScope, $templateCache, callback) + return element + +class TemplateCompiler + constructor : (template_name) -> + @template_name = template_name + + module("angular-table") + module("test/templates/#{@template_name}") + + compile_template : ($compile, $rootScope, $templateCache, callback) -> + element = null + + element = load_template("test/templates/#{@template_name}", $templateCache) + callback($rootScope) + element = $compile(element)($rootScope) + $rootScope.$digest() + + return element \ No newline at end of file diff --git a/test/tests.coffee b/test/tests.coffee index fde0c4c..b6824f2 100644 --- a/test/tests.coffee +++ b/test/tests.coffee @@ -1,76 +1,70 @@ -describe "AnglarTable", () -> +# describe "AnglarTable", () -> - template1 = "test/templates/sortableTable.html" - template2 = "test/templates/tableWithPagination.html" +# template1 = "test/templates/sortableTable.html" +# template2 = "test/templates/tableWithPagination.html" - beforeEach module "angular-table" - beforeEach module(template1, template2) +# beforeEach(module("angular-table")) +# beforeEach(module(template1, template2)) - tdsToArray = (tds) -> - _.map tds, (td) -> angular.element(td).html() +# it "makes a table sortable", inject ($compile, $rootScope, $templateCache) -> - loadTemplate = (template, templateCache) -> - angular.element(templateCache.get(template)) +# element = loadTemplate template1, $templateCache - it "makes a table sortable", inject ($compile, $rootScope, $templateCache) -> +# $rootScope.cities = [{name: "Helsinki"}, {name: "Zurich"}, {name: "Amsterdam"}] - element = loadTemplate template1, $templateCache +# element = $compile(element)($rootScope) +# $rootScope.$digest() - $rootScope.cities = [{name: "Helsinki"}, {name: "Zurich"}, {name: "Amsterdam"}] +# tds = extract_html_to_array(element.find("td")) +# expect(tds).toEqual ["Zurich", "Helsinki", "Amsterdam"] - element = $compile(element)($rootScope) - $rootScope.$digest() +# element.find("th")[0].click() - tds = tdsToArray(element.find("td")) - expect(tds).toEqual ["Zurich", "Helsinki", "Amsterdam"] +# tds = extract_html_to_array(element.find("td")) +# expect(tds).toEqual ["Amsterdam", "Helsinki", "Zurich"] - element.find("th")[0].click() - tds = tdsToArray(element.find("td")) - expect(tds).toEqual ["Amsterdam", "Helsinki", "Zurich"] +# it "adds pagination to a table", inject ($compile, $rootScope, $templateCache) -> +# element = loadTemplate template2, $templateCache - it "adds pagination to a table", inject ($compile, $rootScope, $templateCache) -> +# $rootScope.rammstein = [ +# {name: "Till"}, {name: "Richard"}, {name: "Christoph"}, +# {name: "Paul"}, {name: "Flake"}, {name: "Oliver"}] - element = loadTemplate template2, $templateCache +# element = $compile(element)($rootScope) +# $rootScope.$digest() - $rootScope.rammstein = [ - {name: "Till"}, {name: "Richard"}, {name: "Christoph"}, - {name: "Paul"}, {name: "Flake"}, {name: "Oliver"}] +# tds = extract_html_to_array(element.find("td")) +# expect(tds).toEqual ["Till", "Richard", "Christoph"] - element = $compile(element)($rootScope) - $rootScope.$digest() +# paginationLinks = element.find "a" +# _.find(paginationLinks, (link) -> angular.element(link).html() == "2").click() - tds = tdsToArray(element.find("td")) - expect(tds).toEqual ["Till", "Richard", "Christoph"] +# tds = extract_html_to_array(element.find("td")) +# expect(tds).toEqual ["Paul", "Flake", "Oliver"] - paginationLinks = element.find "a" - _.find(paginationLinks, (link) -> angular.element(link).html() == "2").click() +# # it "the pagination automatically updates when elements are added to or removed from the list", +# # inject ($compile, $rootScope, $templateCache) -> - tds = tdsToArray(element.find("td")) - expect(tds).toEqual ["Paul", "Flake", "Oliver"] +# # element = loadTemplate template2, $templateCache - # it "the pagination automatically updates when elements are added to or removed from the list", - # inject ($compile, $rootScope, $templateCache) -> +# # $rootScope.rammstein = [ +# # {name: "Till"}, {name: "Richard"}, {name: "Christoph"}] - # element = loadTemplate template2, $templateCache +# # element = $compile(element)($rootScope) +# # $rootScope.$digest() - # $rootScope.rammstein = [ - # {name: "Till"}, {name: "Richard"}, {name: "Christoph"}] +# # tds = extract_html_to_array(element.find("td")) +# # expect(tds).toEqual ["Till", "Richard", "Christoph"] - # element = $compile(element)($rootScope) - # $rootScope.$digest() +# # paginationLinks = element.find "a" +# # # there should be three buttons: << | 1 | >> +# # expect(paginationLinks.length).toEqual 3 - # tds = tdsToArray(element.find("td")) - # expect(tds).toEqual ["Till", "Richard", "Christoph"] - - # paginationLinks = element.find "a" - # # there should be three buttons: << | 1 | >> - # expect(paginationLinks.length).toEqual 3 - - # $rootScope.rammstein.push {name: "Paul"} - # $rootScope.$digest() - # paginationLinks = element.find "a" - # # now, there should be four buttons: << | 1 | 2 | >> - # expect(paginationLinks.length).toEqual 4 +# # $rootScope.rammstein.push {name: "Paul"} +# # $rootScope.$digest() +# # paginationLinks = element.find "a" +# # # now, there should be four buttons: << | 1 | 2 | >> +# # expect(paginationLinks.length).toEqual 4 From dc7280eeed2c37ade1317492d52ce5981ae1bfa5 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 23 Dec 2013 22:37:59 +0100 Subject: [PATCH 023/190] added and refactored tests --- test/header.coffee | 10 ++-- test/pagination.coffee | 47 +++++++++---------- test/templates/header/header.html | 2 +- ...bleWithPagination.html => pagination.html} | 4 +- 4 files changed, 29 insertions(+), 34 deletions(-) rename test/templates/{tableWithPagination.html => pagination.html} (70%) diff --git a/test/header.coffee b/test/header.coffee index d400361..0791ffd 100644 --- a/test/header.coffee +++ b/test/header.coffee @@ -1,7 +1,7 @@ describe "angular-table", () -> describe "header", () -> - it "doesnt add a header at all if the header tag wasnt declared", () -> + it "doesnt add a header at all if the header tag isnt declared", () -> @element = prepare_element(new TemplateCompiler("header/no_header.html"), (scope) ->) header = @element.find("thead")[0] expect(header).toBe undefined @@ -9,11 +9,11 @@ describe "angular-table", () -> it "creates column headers implicitly", () -> @element = prepare_element(new TemplateCompiler("header/header.html"), (scope) ->) header = extract_html_to_array(@element.find("thead > tr > th")) - expect(header[0]).toEqual 'Name' + expect(header[0]).toEqual "Name" it "allows to set custom column headers", () -> @element = prepare_element(new TemplateCompiler("header/header.html"), (scope) ->) header = extract_html_to_array(@element.find("thead > tr > th")) - expect(header[1]).toEqual 'The population' - expect(header[2]).toEqual 'Country' - expect(header[3]).toEqual 'Size' + expect(header[1]).toEqual "The population" + expect(header[2]).toEqual "Country" + expect(header[3]).toEqual "Size" diff --git a/test/pagination.coffee b/test/pagination.coffee index 032f6dc..6a05f91 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -1,26 +1,21 @@ -describe "AnglarTable", () -> - - template2 = "test/templates/tableWithPagination.html" - - beforeEach(module("angular-table")) - beforeEach(module(template2)) - - it "adds pagination to a table", inject ($compile, $rootScope, $templateCache) -> - - element = load_template template2, $templateCache - - $rootScope.rammstein = [ - {name: "Till"}, {name: "Richard"}, {name: "Christoph"}, - {name: "Paul"}, {name: "Flake"}, {name: "Oliver"}] - - element = $compile(element)($rootScope) - $rootScope.$digest() - - tds = extract_html_to_array(element.find("td")) - expect(tds).toEqual ["Till", "Richard", "Christoph"] - - paginationLinks = element.find "a" - _.find(paginationLinks, (link) -> angular.element(link).html() == "2").click() - - tds = extract_html_to_array(element.find("td")) - expect(tds).toEqual ["Paul", "Flake", "Oliver"] +describe "angular-table", () -> + describe "pagination", () -> + beforeEach(() -> + tc = new TemplateCompiler("pagination.html") + @element = prepare_element(tc, (scope) -> + scope.rammstein = [ + {name: "Till"}, {name: "Richard"}, {name: "Christoph"}, + {name: "Paul"}, {name: "Flake"}, {name: "Oliver"} + ] + ) + ) + + it "adds pagination to a table", inject ($compile, $rootScope, $templateCache) -> + tds = extract_html_to_array(@element.find("td")) + expect(tds).toEqual ["Till", "Richard", "Christoph", "Paul"] + + paginationLinks = @element.find "a" + _.find(paginationLinks, (link) -> angular.element(link).html() == "2").click() + + tds = extract_html_to_array(@element.find("td")) + expect(tds).toEqual ["Flake", "Oliver", " ", " "] diff --git a/test/templates/header/header.html b/test/templates/header/header.html index 863cea1..46e3360 100644 --- a/test/templates/header/header.html +++ b/test/templates/header/header.html @@ -1,7 +1,7 @@ - + diff --git a/test/templates/tableWithPagination.html b/test/templates/pagination.html similarity index 70% rename from test/templates/tableWithPagination.html rename to test/templates/pagination.html index 737c7fa..446ddd8 100644 --- a/test/templates/tableWithPagination.html +++ b/test/templates/pagination.html @@ -1,4 +1,4 @@ -
SizeSize
+
@@ -7,4 +7,4 @@
- \ No newline at end of file + \ No newline at end of file From d9b6c7d7f38978bb5544cf2a57c51488a4ebf751 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 23 Dec 2013 23:10:50 +0100 Subject: [PATCH 024/190] added new tests for pagination --- coffee/setupFactory.coffee | 2 +- test/pagination.coffee | 24 +++++++++++++++---- .../{ => pagination}/pagination.html | 0 .../pagination/sort_context_global.html | 10 ++++++++ .../pagination/sort_context_page.html | 10 ++++++++ 5 files changed, 40 insertions(+), 6 deletions(-) rename test/templates/{ => pagination}/pagination.html (100%) create mode 100644 test/templates/pagination/sort_context_global.html create mode 100644 test/templates/pagination/sort_context_page.html diff --git a/coffee/setupFactory.coffee b/coffee/setupFactory.coffee index 34f7040..06eaa2a 100644 --- a/coffee/setupFactory.coffee +++ b/coffee/setupFactory.coffee @@ -18,8 +18,8 @@ angular.module("angular-table").factory "setupFactory", [() -> return PaginationSetup = (attributes) -> - sortContext = attributes.sortContext || "global" + paginationName = attributes.pagination if sortContext == "global" diff --git a/test/pagination.coffee b/test/pagination.coffee index 6a05f91..45e6f9c 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -1,16 +1,14 @@ describe "angular-table", () -> describe "pagination", () -> - beforeEach(() -> - tc = new TemplateCompiler("pagination.html") - @element = prepare_element(tc, (scope) -> + + it "adds pagination to a table", () -> + @element = prepare_element(new TemplateCompiler("pagination/pagination.html"), (scope) -> scope.rammstein = [ {name: "Till"}, {name: "Richard"}, {name: "Christoph"}, {name: "Paul"}, {name: "Flake"}, {name: "Oliver"} ] ) - ) - it "adds pagination to a table", inject ($compile, $rootScope, $templateCache) -> tds = extract_html_to_array(@element.find("td")) expect(tds).toEqual ["Till", "Richard", "Christoph", "Paul"] @@ -19,3 +17,19 @@ describe "angular-table", () -> tds = extract_html_to_array(@element.find("td")) expect(tds).toEqual ["Flake", "Oliver", " ", " "] + + describe "sort context", () -> + + callback = (scope) -> + scope.letters = [{char: "c"}, {char: "b"}, {char: "d"}, {char: "f"}, + {char: "a"}, {char: "e"}, {char: "h"}, {char: "g"}] + + it "allows to set the sort context to global", () -> + @element = prepare_element(new TemplateCompiler("pagination/sort_context_global.html"), callback) + tds = extract_html_to_array(@element.find("td")) + expect(tds).toEqual ["a", "b", "c", "d"] + + it "allows to set the sort context to page", () -> + @element = prepare_element(new TemplateCompiler("pagination/sort_context_page.html"), callback) + tds = extract_html_to_array(@element.find("td")) + expect(tds).toEqual ["b", "c", "d", "f"] \ No newline at end of file diff --git a/test/templates/pagination.html b/test/templates/pagination/pagination.html similarity index 100% rename from test/templates/pagination.html rename to test/templates/pagination/pagination.html diff --git a/test/templates/pagination/sort_context_global.html b/test/templates/pagination/sort_context_global.html new file mode 100644 index 0000000..edb8d96 --- /dev/null +++ b/test/templates/pagination/sort_context_global.html @@ -0,0 +1,10 @@ + + + + + + + +
+ + \ No newline at end of file diff --git a/test/templates/pagination/sort_context_page.html b/test/templates/pagination/sort_context_page.html new file mode 100644 index 0000000..a8b0b23 --- /dev/null +++ b/test/templates/pagination/sort_context_page.html @@ -0,0 +1,10 @@ + + + + + + + +
+ + \ No newline at end of file From 1d68d0bb2e9430b303f7590c3964c282fea83648 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 23 Dec 2013 23:15:36 +0100 Subject: [PATCH 025/190] changed 'title' keyword to 'at-title' --- coffee/metaCollector.coffee | 2 +- test/templates/header/header.html | 4 ++-- test/templates/header/no_header.html | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/coffee/metaCollector.coffee b/coffee/metaCollector.coffee index a2cb175..4177113 100644 --- a/coffee/metaCollector.coffee +++ b/coffee/metaCollector.coffee @@ -45,7 +45,7 @@ angular.module("angular-table").service "metaCollector", [() -> td = angular.element(td) attribute = td.attr("attribute") - title = td.attr("title") || capitaliseFirstLetter(td.attr("attribute")) + title = td.attr("at-title") || capitaliseFirstLetter(td.attr("attribute")) sortable = td[0].attributes.sortable || isSortable(td.attr("class")) width = extractWidth(td.attr("class")) diff --git a/test/templates/header/header.html b/test/templates/header/header.html index 46e3360..d659126 100644 --- a/test/templates/header/header.html +++ b/test/templates/header/header.html @@ -7,8 +7,8 @@ - - {{item.country}} + + {{item.country}} diff --git a/test/templates/header/no_header.html b/test/templates/header/no_header.html index e6e40d5..0cc16c7 100644 --- a/test/templates/header/no_header.html +++ b/test/templates/header/no_header.html @@ -2,8 +2,8 @@ - - {{item.country}} + + {{item.country}} From 12e595f5aa4fa472132bf42853efede3d9902cf8 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 23 Dec 2013 23:16:33 +0100 Subject: [PATCH 026/190] removed comment --- coffee/atTable.coffee | 5 ----- 1 file changed, 5 deletions(-) diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index 1174159..67bded9 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -33,11 +33,6 @@ angular.module("angular-table").directive "atTable", ["metaCollector", "setupFac if not attributes.pagination and not attributes.list throw "Either a list or pagination must be specified." - # Earlier versions of angular table used 'pagination' instead of 'at-pagination' - # to wire a table to a pagination instance. However, this declaration can become - # ambiguous (ui-bootstrap for example has a directive called 'pagination'). So - # right now, you can either use 'pagination' or 'at-pagination'. The support - # for 'pagination' should be dropped some time. normalizeInput = (attributes) -> if attributes.atPagination attributes.pagination = attributes.atPagination From f38340d3bc2e4c78036bec6145afa0725409ab74 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 24 Jan 2014 12:32:58 +0100 Subject: [PATCH 027/190] new URLs --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8158fde..a9a64d7 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ Html tables with sorting and pagination. -[Written in CoffeeScript.](https://github.com/ssmm/angular-table/blob/master/coffee) +[Written in CoffeeScript.](https://github.com/samu/angular-table/blob/master/coffee) -Check out the [examples](http://ssmm.github.io/angular-table/examples.html) for more information. +Check out the [examples](http://samu.github.io/angular-table/examples.html) for more information. ## How From bb8126cc38b04022e46912640e5f1d11bef8a130 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 7 Feb 2014 20:22:47 +0100 Subject: [PATCH 028/190] renamed list keyword to at-list --- coffee/atPagination.coffee | 20 +++++++++---------- coffee/atTable.coffee | 7 +++---- coffee/setupFactory.coffee | 8 ++++---- test/templates/header/header.html | 2 +- test/templates/header/no_header.html | 2 +- test/templates/pagination/pagination.html | 2 +- .../pagination/sort_context_global.html | 2 +- .../pagination/sort_context_page.html | 2 +- test/templates/sorting/sorting.html | 10 ++++++++++ 9 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 test/templates/sorting/sorting.html diff --git a/coffee/atPagination.coffee b/coffee/atPagination.coffee index 0d8b9d8..83a31fc 100644 --- a/coffee/atPagination.coffee +++ b/coffee/atPagination.coffee @@ -19,7 +19,7 @@ angular.module("angular-table").directive "atPagination", [() -> scope: { itemsPerPage: "@" instance: "=" - list: "=" + atList: "=" } link: ($scope, $element, $attributes) -> @@ -35,9 +35,9 @@ angular.module("angular-table").directive "atPagination", [() -> # $scope.currentPage = if reset then 0 else normalizePage($scope.currentPage) $scope.currentPage = 0 - if $scope.list - if $scope.list.length > 0 - $scope.numberOfPages = Math.ceil($scope.list.length / $scope.itemsPerPage) + if $scope.atList + if $scope.atList.length > 0 + $scope.numberOfPages = Math.ceil($scope.atList.length / $scope.itemsPerPage) $scope.pages = for x in [0..($scope.numberOfPages - 1)] x else @@ -45,15 +45,15 @@ angular.module("angular-table").directive "atPagination", [() -> $scope.pages = [0] $scope.fromPage = () -> - if $scope.list - $scope.itemsPerPage * $scope.currentPage - $scope.list.length + if $scope.atList + $scope.itemsPerPage * $scope.currentPage - $scope.atList.length $scope.getFillerArray = () -> if $scope.currentPage == $scope.numberOfPages - 1 - itemCountOnLastPage = $scope.list.length % $scope.itemsPerPage - if itemCountOnLastPage != 0 || $scope.list.length == 0 + itemCountOnLastPage = $scope.atList.length % $scope.itemsPerPage + if itemCountOnLastPage != 0 || $scope.atList.length == 0 fillerLength = $scope.itemsPerPage - itemCountOnLastPage - 1 - x for x in [($scope.list.length)..($scope.list.length + fillerLength)] + x for x in [($scope.atList.length)..($scope.atList.length + fillerLength)] else [] @@ -77,7 +77,7 @@ angular.module("angular-table").directive "atPagination", [() -> $scope.$watch "itemsPerPage", () -> update() - $scope.$watch "list", () -> + $scope.$watch "atList", () -> update() } diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index 67bded9..eb9df15 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -28,9 +28,9 @@ angular.module("angular-table").directive "atTable", ["metaCollector", "setupFac tr validateInput = (attributes) -> - if attributes.pagination and attributes.list + if attributes.pagination and attributes.atList throw "You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used." - if not attributes.pagination and not attributes.list + if not attributes.pagination and not attributes.atList throw "Either a list or pagination must be specified." normalizeInput = (attributes) -> @@ -73,5 +73,4 @@ angular.module("angular-table").directive "atTable", ["metaCollector", "setupFac setup.link($scope, $element, $attributes) } } -] - +] \ No newline at end of file diff --git a/coffee/setupFactory.coffee b/coffee/setupFactory.coffee index 06eaa2a..527a336 100644 --- a/coffee/setupFactory.coffee +++ b/coffee/setupFactory.coffee @@ -10,7 +10,7 @@ angular.module("angular-table").factory "setupFactory", [() -> tbody StandardSetup = (attributes) -> - repeatString = "item in #{attributes.list} #{orderByExpression}" + repeatString = "item in #{attributes.atList} #{orderByExpression}" @compile = (element, attributes, transclude) -> setupTr element, repeatString @@ -23,9 +23,9 @@ angular.module("angular-table").factory "setupFactory", [() -> paginationName = attributes.pagination if sortContext == "global" - repeatString = "item in #{paginationName}.list #{orderByExpression} #{limitToExpression}" + repeatString = "item in #{paginationName}.atList #{orderByExpression} #{limitToExpression}" else if sortContext == "page" - repeatString = "item in #{paginationName}.list #{limitToExpression} #{orderByExpression} " + repeatString = "item in #{paginationName}.atList #{limitToExpression} #{orderByExpression} " else throw "Invalid sort-context: #{sortContext}." @@ -53,7 +53,7 @@ angular.module("angular-table").factory "setupFactory", [() -> return (attributes) -> - if attributes.list + if attributes.atList return new StandardSetup(attributes) if attributes.pagination return new PaginationSetup(attributes) diff --git a/test/templates/header/header.html b/test/templates/header/header.html index d659126..313f9bc 100644 --- a/test/templates/header/header.html +++ b/test/templates/header/header.html @@ -1,4 +1,4 @@ - +
diff --git a/test/templates/header/no_header.html b/test/templates/header/no_header.html index 0cc16c7..11cd317 100644 --- a/test/templates/header/no_header.html +++ b/test/templates/header/no_header.html @@ -1,4 +1,4 @@ -
Size
+
diff --git a/test/templates/pagination/pagination.html b/test/templates/pagination/pagination.html index 446ddd8..520c0ff 100644 --- a/test/templates/pagination/pagination.html +++ b/test/templates/pagination/pagination.html @@ -7,4 +7,4 @@
- \ No newline at end of file + \ No newline at end of file diff --git a/test/templates/pagination/sort_context_global.html b/test/templates/pagination/sort_context_global.html index edb8d96..daaca18 100644 --- a/test/templates/pagination/sort_context_global.html +++ b/test/templates/pagination/sort_context_global.html @@ -7,4 +7,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test/templates/pagination/sort_context_page.html b/test/templates/pagination/sort_context_page.html index a8b0b23..aa6d8a5 100644 --- a/test/templates/pagination/sort_context_page.html +++ b/test/templates/pagination/sort_context_page.html @@ -7,4 +7,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test/templates/sorting/sorting.html b/test/templates/sorting/sorting.html new file mode 100644 index 0000000..a51ae92 --- /dev/null +++ b/test/templates/sorting/sorting.html @@ -0,0 +1,10 @@ + + + + + + + + + +
From 0e4f550383d558f293622dc4a4966cbef16d926d Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 7 Feb 2014 20:24:12 +0100 Subject: [PATCH 029/190] updated folder structure --- test/pagination.coffee | 2 -- test/sorting.coffee | 2 +- test/templates/sorting.html | 10 ---------- 3 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 test/templates/sorting.html diff --git a/test/pagination.coffee b/test/pagination.coffee index 45e6f9c..c1e44b1 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -1,6 +1,5 @@ describe "angular-table", () -> describe "pagination", () -> - it "adds pagination to a table", () -> @element = prepare_element(new TemplateCompiler("pagination/pagination.html"), (scope) -> scope.rammstein = [ @@ -19,7 +18,6 @@ describe "angular-table", () -> expect(tds).toEqual ["Flake", "Oliver", " ", " "] describe "sort context", () -> - callback = (scope) -> scope.letters = [{char: "c"}, {char: "b"}, {char: "d"}, {char: "f"}, {char: "a"}, {char: "e"}, {char: "h"}, {char: "g"}] diff --git a/test/sorting.coffee b/test/sorting.coffee index 346606f..7302bfe 100644 --- a/test/sorting.coffee +++ b/test/sorting.coffee @@ -2,7 +2,7 @@ describe "angular-table", () -> describe "sorting", () -> beforeEach(() -> - tc = new TemplateCompiler("sorting.html") + tc = new TemplateCompiler("sorting/sorting.html") @element = prepare_element(tc, (scope) -> scope.cities = [{name: "Helsinki"}, {name: "Zurich"}, {name: "Amsterdam"}] ) diff --git a/test/templates/sorting.html b/test/templates/sorting.html deleted file mode 100644 index 1c231c2..0000000 --- a/test/templates/sorting.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - -
From cf6297edf03bc3353deb97758214876eebe95a76 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 7 Feb 2014 20:25:01 +0100 Subject: [PATCH 030/190] updated karma configuration for newest version --- karma.conf.js | 121 +++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 61 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index f596b1a..c0fc1b1 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,82 +1,81 @@ // Karma configuration -// Generated on Thu Jul 04 2013 23:17:10 GMT+0200 (CEST) - - -// base path, that will be used to resolve files and exclude -basePath = ''; - - -// list of files / patterns to load in the browser -files = [ - JASMINE, - JASMINE_ADAPTER, - "http://code.jquery.com/jquery-1.10.1.min.js", - "http://code.angularjs.org/1.1.5/angular.min.js", - "http://code.angularjs.org/1.1.5/angular-mocks.js", - "http://underscorejs.org/underscore-min.js", - // important to load this first, because it contains the module definition - "coffee/atTable.coffee", - "coffee/*.coffee", - "test/test_helper.coffee", - "test/*.coffee", - "test/templates/*.html", - "test/templates/*/*.html" -]; - -preprocessors = { - "coffee/*.coffee": "coffee", - "test/*.coffee": "coffee", - "test/templates/*.html": "html2js", - "test/templates/*/*.html": "html2js" -}; +// Generated on Wed Feb 05 2014 13:15:20 GMT+0100 (CET) + +module.exports = function(config) { + config.set({ + + // base path, that will be used to resolve files and exclude + basePath: '', + -// list of files to exclude -exclude = [ + // frameworks to use + frameworks: ['jasmine'], -]; + // list of files / patterns to load in the browser + files: [ + "http://code.jquery.com/jquery-1.10.1.min.js", + "http://code.angularjs.org/1.2.11/angular.min.js", + "http://code.angularjs.org/1.2.11/angular-mocks.js", + "http://underscorejs.org/underscore-min.js", + 'coffee/atTable.coffee', + 'coffee/*.coffee', + 'test/test_helper.coffee', + 'test/*.coffee', + 'test/templates/**/*.html' + ], -// test results reporter to use -// possible values: 'dots', 'progress', 'junit' -reporters = ['progress']; + // list of files to exclude + exclude: [ -// web server port -port = 9876; + ], + preprocessors: { + "coffee/*.coffee": ["coffee"], + "test/*.coffee": ["coffee"], + "test/templates/**/*.html": ["ng-html2js"] + }, -// cli runner port -runnerPort = 9100; + // test results reporter to use + // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' + reporters: ['progress'], -// enable / disable colors in the output (reporters and logs) -colors = true; + // web server port + port: 9876, -// level of logging -// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG -logLevel = LOG_INFO; + // enable / disable colors in the output (reporters and logs) + colors: true, -// enable / disable watching file and executing tests whenever any file changes -autoWatch = true; + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, -// Start these browsers, currently available: -// - Chrome -// - ChromeCanary -// - Firefox -// - Opera -// - Safari (only Mac) -// - PhantomJS -// - IE (only Windows) -browsers = ['Chrome']; + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, -// If browser does not capture in given timeout [ms], kill it -captureTimeout = 60000; + // Start these browsers, currently available: + // - Chrome + // - ChromeCanary + // - Firefox + // - Opera + // - Safari (only Mac) + // - PhantomJS + // - IE (only Windows) + browsers: ['Chrome'], -// Continuous Integration mode -// if true, it capture browsers, run tests and exit -singleRun = false; + // If browser does not capture in given timeout [ms], kill it + captureTimeout: 60000, + + + // Continuous Integration mode + // if true, it capture browsers, run tests and exit + singleRun: false + }); +}; From aa4b2ac01984657d94f6d28982a88c2f4c3ca0c8 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 7 Feb 2014 20:40:00 +0100 Subject: [PATCH 031/190] changed keyword 'attribute' to 'at-attribute' --- coffee/atImplicit.coffee | 4 ++-- coffee/metaCollector.coffee | 6 +++--- test/templates/header/header.html | 8 ++++---- test/templates/header/no_header.html | 4 ++-- test/templates/pagination/sort_context_global.html | 2 +- test/templates/pagination/sort_context_page.html | 2 +- test/templates/sorting/sorting.html | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/coffee/atImplicit.coffee b/coffee/atImplicit.coffee index 7040572..85403c7 100644 --- a/coffee/atImplicit.coffee +++ b/coffee/atImplicit.coffee @@ -2,8 +2,8 @@ angular.module("angular-table").directive "atImplicit", [() -> { restrict: "AC" compile: (element, attributes, transclude) -> - attribute = element.attr("attribute") - throw "at-implicit specified without attribute: #{element.html()}" if not attribute + attribute = element.attr("at-attribute") + throw "at-implicit specified without at-attribute: #{element.html()}" if not attribute element.append "{{item.#{attribute}}}" } ] \ No newline at end of file diff --git a/coffee/metaCollector.coffee b/coffee/metaCollector.coffee index 4177113..38891d7 100644 --- a/coffee/metaCollector.coffee +++ b/coffee/metaCollector.coffee @@ -30,7 +30,7 @@ angular.module("angular-table").service "metaCollector", [() -> tr = thead.find "tr" for th in tr.find "th" th = angular.element(th) - customHeaderMarkup = customHeaderMarkups[th.attr("attribute")] = {} + customHeaderMarkup = customHeaderMarkups[th.attr("at-attribute")] = {} customHeaderMarkup.content = th.html() customHeaderMarkup.attributes = th[0].attributes @@ -44,8 +44,8 @@ angular.module("angular-table").service "metaCollector", [() -> for td in tbody.find("td") td = angular.element(td) - attribute = td.attr("attribute") - title = td.attr("at-title") || capitaliseFirstLetter(td.attr("attribute")) + attribute = td.attr("at-attribute") + title = td.attr("at-title") || capitaliseFirstLetter(td.attr("at-attribute")) sortable = td[0].attributes.sortable || isSortable(td.attr("class")) width = extractWidth(td.attr("class")) diff --git a/test/templates/header/header.html b/test/templates/header/header.html index 313f9bc..084649d 100644 --- a/test/templates/header/header.html +++ b/test/templates/header/header.html @@ -1,15 +1,15 @@ - + - - + + - +
SizeSize
{{item.country}}
diff --git a/test/templates/header/no_header.html b/test/templates/header/no_header.html index 11cd317..115327c 100644 --- a/test/templates/header/no_header.html +++ b/test/templates/header/no_header.html @@ -1,8 +1,8 @@ - - + + diff --git a/test/templates/pagination/sort_context_global.html b/test/templates/pagination/sort_context_global.html index daaca18..b9180c4 100644 --- a/test/templates/pagination/sort_context_global.html +++ b/test/templates/pagination/sort_context_global.html @@ -2,7 +2,7 @@ - +
{{item.country}}
diff --git a/test/templates/pagination/sort_context_page.html b/test/templates/pagination/sort_context_page.html index aa6d8a5..4d63ac1 100644 --- a/test/templates/pagination/sort_context_page.html +++ b/test/templates/pagination/sort_context_page.html @@ -2,7 +2,7 @@ - + diff --git a/test/templates/sorting/sorting.html b/test/templates/sorting/sorting.html index a51ae92..01695d5 100644 --- a/test/templates/sorting/sorting.html +++ b/test/templates/sorting/sorting.html @@ -4,7 +4,7 @@ - + From e82233744407079d736c491eaf6ea017ac36191c Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 7 Feb 2014 20:44:02 +0100 Subject: [PATCH 032/190] prefixed keyword 'fill-last-table' --- coffee/setupFactory.coffee | 2 +- test/templates/pagination/pagination.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/coffee/setupFactory.coffee b/coffee/setupFactory.coffee index 527a336..55208db 100644 --- a/coffee/setupFactory.coffee +++ b/coffee/setupFactory.coffee @@ -32,7 +32,7 @@ angular.module("angular-table").factory "setupFactory", [() -> @compile = (element, attributes, transclude) -> tbody = setupTr element, repeatString - if typeof attributes.fillLastPage != "undefined" + if typeof attributes.atFillLastPage != "undefined" tds = element.find("td") tdString = "" for td in tds diff --git a/test/templates/pagination/pagination.html b/test/templates/pagination/pagination.html index 520c0ff..bfd91be 100644 --- a/test/templates/pagination/pagination.html +++ b/test/templates/pagination/pagination.html @@ -1,4 +1,4 @@ - +
From 84191f24f7307f428d2617f19b9202475eff474c Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 7 Feb 2014 20:54:09 +0100 Subject: [PATCH 033/190] prefixed keywords items-per-page, instance, sort-context, initial-sorting --- coffee/atPagination.coffee | 16 ++++++++-------- coffee/metaCollector.coffee | 2 +- coffee/setupFactory.coffee | 4 ++-- test/templates/pagination/pagination.html | 2 +- .../pagination/sort_context_global.html | 6 +++--- test/templates/pagination/sort_context_page.html | 6 +++--- test/templates/sorting/sorting.html | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/coffee/atPagination.coffee b/coffee/atPagination.coffee index 83a31fc..04215f9 100644 --- a/coffee/atPagination.coffee +++ b/coffee/atPagination.coffee @@ -17,13 +17,13 @@ angular.module("angular-table").directive "atPagination", [() -> " scope: { - itemsPerPage: "@" - instance: "=" + atItemsPerPage: "@" + atInstance: "=" atList: "=" } link: ($scope, $element, $attributes) -> - $scope.instance = $scope + $scope.atInstance = $scope $scope.currentPage = 0 normalizePage = (page) -> @@ -37,7 +37,7 @@ angular.module("angular-table").directive "atPagination", [() -> if $scope.atList if $scope.atList.length > 0 - $scope.numberOfPages = Math.ceil($scope.atList.length / $scope.itemsPerPage) + $scope.numberOfPages = Math.ceil($scope.atList.length / $scope.atItemsPerPage) $scope.pages = for x in [0..($scope.numberOfPages - 1)] x else @@ -46,13 +46,13 @@ angular.module("angular-table").directive "atPagination", [() -> $scope.fromPage = () -> if $scope.atList - $scope.itemsPerPage * $scope.currentPage - $scope.atList.length + $scope.atItemsPerPage * $scope.currentPage - $scope.atList.length $scope.getFillerArray = () -> if $scope.currentPage == $scope.numberOfPages - 1 - itemCountOnLastPage = $scope.atList.length % $scope.itemsPerPage + itemCountOnLastPage = $scope.atList.length % $scope.atItemsPerPage if itemCountOnLastPage != 0 || $scope.atList.length == 0 - fillerLength = $scope.itemsPerPage - itemCountOnLastPage - 1 + fillerLength = $scope.atItemsPerPage - itemCountOnLastPage - 1 x for x in [($scope.atList.length)..($scope.atList.length + fillerLength)] else [] @@ -74,7 +74,7 @@ angular.module("angular-table").directive "atPagination", [() -> # $scope.$watch "list.length", (newValue, oldValue) -> # update(false) if newValue != oldValue - $scope.$watch "itemsPerPage", () -> + $scope.$watch "atItemsPerPage", () -> update() $scope.$watch "atList", () -> diff --git a/coffee/metaCollector.coffee b/coffee/metaCollector.coffee index 38891d7..0784745 100644 --- a/coffee/metaCollector.coffee +++ b/coffee/metaCollector.coffee @@ -12,7 +12,7 @@ angular.module("angular-table").service "metaCollector", [() -> if sortable then true else false getInitialSortDirection = (td) -> - initialSorting = td.attr("initial-sorting") + initialSorting = td.attr("at-initial-sorting") if initialSorting return initialSorting if initialSorting == "asc" || initialSorting == "desc" throw "Invalid value for initial-sorting: #{initialSorting}. Allowed values are 'asc' or 'desc'." diff --git a/coffee/setupFactory.coffee b/coffee/setupFactory.coffee index 55208db..920b7d0 100644 --- a/coffee/setupFactory.coffee +++ b/coffee/setupFactory.coffee @@ -18,7 +18,7 @@ angular.module("angular-table").factory "setupFactory", [() -> return PaginationSetup = (attributes) -> - sortContext = attributes.sortContext || "global" + sortContext = attributes.atSortContext || "global" paginationName = attributes.pagination @@ -48,7 +48,7 @@ angular.module("angular-table").factory "setupFactory", [() -> if $scope[paginationName] then $scope[paginationName].fromPage() $scope.toPage = () -> - if $scope[paginationName] then $scope[paginationName].itemsPerPage + if $scope[paginationName] then $scope[paginationName].atItemsPerPage return diff --git a/test/templates/pagination/pagination.html b/test/templates/pagination/pagination.html index bfd91be..8839cc8 100644 --- a/test/templates/pagination/pagination.html +++ b/test/templates/pagination/pagination.html @@ -7,4 +7,4 @@
- \ No newline at end of file + \ No newline at end of file diff --git a/test/templates/pagination/sort_context_global.html b/test/templates/pagination/sort_context_global.html index b9180c4..06cb92d 100644 --- a/test/templates/pagination/sort_context_global.html +++ b/test/templates/pagination/sort_context_global.html @@ -1,10 +1,10 @@ - +
- +
- \ No newline at end of file + \ No newline at end of file diff --git a/test/templates/pagination/sort_context_page.html b/test/templates/pagination/sort_context_page.html index 4d63ac1..c3c2ff5 100644 --- a/test/templates/pagination/sort_context_page.html +++ b/test/templates/pagination/sort_context_page.html @@ -1,10 +1,10 @@ - +
- +
- \ No newline at end of file + \ No newline at end of file diff --git a/test/templates/sorting/sorting.html b/test/templates/sorting/sorting.html index 01695d5..ba233b6 100644 --- a/test/templates/sorting/sorting.html +++ b/test/templates/sorting/sorting.html @@ -4,7 +4,7 @@ - + From 657f9281a2c2c00a5123bcc7d3c4d965b4dccd64 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 7 Feb 2014 21:34:07 +0100 Subject: [PATCH 034/190] prefixed attribute 'sortable' --- coffee/metaCollector.coffee | 2 +- test/templates/pagination/sort_context_global.html | 2 +- test/templates/pagination/sort_context_page.html | 2 +- test/templates/sorting/sorting.html | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/coffee/metaCollector.coffee b/coffee/metaCollector.coffee index 0784745..10ccb34 100644 --- a/coffee/metaCollector.coffee +++ b/coffee/metaCollector.coffee @@ -46,7 +46,7 @@ angular.module("angular-table").service "metaCollector", [() -> attribute = td.attr("at-attribute") title = td.attr("at-title") || capitaliseFirstLetter(td.attr("at-attribute")) - sortable = td[0].attributes.sortable || isSortable(td.attr("class")) + sortable = td.attr("at-sortable") != undefined || isSortable(td.attr("class")) width = extractWidth(td.attr("class")) bodyDefinition.tds.push {attribute: attribute, title: title, sortable: sortable, width: width} diff --git a/test/templates/pagination/sort_context_global.html b/test/templates/pagination/sort_context_global.html index 06cb92d..a97d0b1 100644 --- a/test/templates/pagination/sort_context_global.html +++ b/test/templates/pagination/sort_context_global.html @@ -2,7 +2,7 @@ - + diff --git a/test/templates/pagination/sort_context_page.html b/test/templates/pagination/sort_context_page.html index c3c2ff5..351aa4a 100644 --- a/test/templates/pagination/sort_context_page.html +++ b/test/templates/pagination/sort_context_page.html @@ -2,7 +2,7 @@ - + diff --git a/test/templates/sorting/sorting.html b/test/templates/sorting/sorting.html index ba233b6..5facddb 100644 --- a/test/templates/sorting/sorting.html +++ b/test/templates/sorting/sorting.html @@ -4,7 +4,7 @@ - + From 7a2c406e884668ad75fd2d1f4d43a370d93a9ae8 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 7 Feb 2014 21:36:53 +0100 Subject: [PATCH 035/190] compiled new version --- angular-table.js | 83 ++++++++------------- angular-table.min.js | 4 +- gem/app/assets/javascripts/angular-table.js | 83 ++++++++------------- gem/lib/angular-table/version.rb | 2 +- 4 files changed, 67 insertions(+), 105 deletions(-) diff --git a/angular-table.js b/angular-table.js index d4c9c3c..3e03991 100644 --- a/angular-table.js +++ b/angular-table.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 0.0.7 +// version: 0.0.8 // license: MIT // homepage: http://github.com/ssmm/angular-table (function() { @@ -8,10 +8,8 @@ angular.module("angular-table").directive("atTable", [ "metaCollector", "setupFactory", function(metaCollector, setupFactory) { var constructHeader, normalizeInput, validateInput; - constructHeader = function(customHeaderMarkup, bodyDefinitions) { var attribute, icon, td, th, title, tr, _i, _j, _len, _len1, _ref; - tr = angular.element(""); for (_i = 0, _len = bodyDefinitions.length; _i < _len; _i++) { td = bodyDefinitions[_i]; @@ -39,10 +37,10 @@ return tr; }; validateInput = function(attributes) { - if (attributes.pagination && attributes.list) { + if (attributes.pagination && attributes.atList) { throw "You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used."; } - if (!attributes.pagination && !attributes.list) { + if (!attributes.pagination && !attributes.atList) { throw "Either a list or pagination must be specified."; } }; @@ -57,7 +55,6 @@ scope: true, compile: function(element, attributes, transclude) { var bodyDefinition, customHeaderMarkup, setup, tbody, thead, tr; - normalizeInput(attributes); validateInput(attributes); thead = element.find("thead"); @@ -101,10 +98,9 @@ restrict: "AC", compile: function(element, attributes, transclude) { var attribute; - - attribute = element.attr("attribute"); + attribute = element.attr("at-attribute"); if (!attribute) { - throw "at-implicit specified without attribute: " + (element.html()); + throw "at-implicit specified without at-attribute: " + (element.html()); } return element.append("{{item." + attribute + "}}"); } @@ -119,14 +115,13 @@ restrict: "E", template: " ", scope: { - itemsPerPage: "@", - instance: "=", - list: "=" + atItemsPerPage: "@", + atInstance: "=", + atList: "=" }, link: function($scope, $element, $attributes) { var normalizePage, update; - - $scope.instance = $scope; + $scope.atInstance = $scope; $scope.currentPage = 0; normalizePage = function(page) { page = Math.max(0, page); @@ -135,14 +130,12 @@ }; update = function(reset) { var x; - $scope.currentPage = 0; - if ($scope.list) { - if ($scope.list.length > 0) { - $scope.numberOfPages = Math.ceil($scope.list.length / $scope.itemsPerPage); + if ($scope.atList) { + if ($scope.atList.length > 0) { + $scope.numberOfPages = Math.ceil($scope.atList.length / $scope.atItemsPerPage); return $scope.pages = (function() { var _i, _ref, _results; - _results = []; for (x = _i = 0, _ref = $scope.numberOfPages - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { _results.push(x); @@ -156,19 +149,18 @@ } }; $scope.fromPage = function() { - if ($scope.list) { - return $scope.itemsPerPage * $scope.currentPage - $scope.list.length; + if ($scope.atList) { + return $scope.atItemsPerPage * $scope.currentPage - $scope.atList.length; } }; $scope.getFillerArray = function() { var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; - if ($scope.currentPage === $scope.numberOfPages - 1) { - itemCountOnLastPage = $scope.list.length % $scope.itemsPerPage; - if (itemCountOnLastPage !== 0 || $scope.list.length === 0) { - fillerLength = $scope.itemsPerPage - itemCountOnLastPage - 1; + itemCountOnLastPage = $scope.atList.length % $scope.atItemsPerPage; + if (itemCountOnLastPage !== 0 || $scope.atList.length === 0) { + fillerLength = $scope.atItemsPerPage - itemCountOnLastPage - 1; _results = []; - for (x = _i = _ref = $scope.list.length, _ref1 = $scope.list.length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { + for (x = _i = _ref = $scope.atList.length, _ref1 = $scope.atList.length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { _results.push(x); } return _results; @@ -181,10 +173,10 @@ return $scope.currentPage = normalizePage(page); }; update(); - $scope.$watch("itemsPerPage", function() { + $scope.$watch("atItemsPerPage", function() { return update(); }); - return $scope.$watch("list", function() { + return $scope.$watch("atList", function() { return update(); }); } @@ -195,7 +187,6 @@ angular.module("angular-table").service("metaCollector", [ function() { var capitaliseFirstLetter, extractWidth, getInitialSortDirection, isSortable; - capitaliseFirstLetter = function(string) { if (string) { return string.charAt(0).toUpperCase() + string.slice(1); @@ -205,7 +196,6 @@ }; extractWidth = function(classes) { var width; - width = /([0-9]+px)/i.exec(classes); if (width) { return width[0]; @@ -215,7 +205,6 @@ }; isSortable = function(classes) { var sortable; - sortable = /(sortable)/i.exec(classes); if (sortable) { return true; @@ -225,8 +214,7 @@ }; getInitialSortDirection = function(td) { var initialSorting; - - initialSorting = td.attr("initial-sorting"); + initialSorting = td.attr("at-initial-sorting"); if (initialSorting) { if (initialSorting === "asc" || initialSorting === "desc") { return initialSorting; @@ -238,14 +226,13 @@ return { collectCustomHeaderMarkup: function(thead) { var customHeaderMarkup, customHeaderMarkups, th, tr, _i, _len, _ref; - customHeaderMarkups = {}; tr = thead.find("tr"); _ref = tr.find("th"); for (_i = 0, _len = _ref.length; _i < _len; _i++) { th = _ref[_i]; th = angular.element(th); - customHeaderMarkup = customHeaderMarkups[th.attr("attribute")] = {}; + customHeaderMarkup = customHeaderMarkups[th.attr("at-attribute")] = {}; customHeaderMarkup.content = th.html(); customHeaderMarkup.attributes = th[0].attributes; } @@ -253,7 +240,6 @@ }, collectBodyDefinition: function(tbody) { var attribute, bodyDefinition, initialSortDirection, sortable, td, title, width, _i, _len, _ref; - bodyDefinition = {}; bodyDefinition.tds = []; bodyDefinition.initialSorting = void 0; @@ -261,9 +247,9 @@ for (_i = 0, _len = _ref.length; _i < _len; _i++) { td = _ref[_i]; td = angular.element(td); - attribute = td.attr("attribute"); - title = td.attr("title") || capitaliseFirstLetter(td.attr("attribute")); - sortable = td[0].attributes.sortable || isSortable(td.attr("class")); + attribute = td.attr("at-attribute"); + title = td.attr("at-title") || capitaliseFirstLetter(td.attr("at-attribute")); + sortable = td.attr("at-sortable") !== void 0 || isSortable(td.attr("class")); width = extractWidth(td.attr("class")); bodyDefinition.tds.push({ attribute: attribute, @@ -290,12 +276,10 @@ angular.module("angular-table").factory("setupFactory", [ function() { var PaginationSetup, StandardSetup, limitToExpression, orderByExpression, setupTr; - orderByExpression = "| orderBy:predicate:descending"; limitToExpression = "| limitTo:fromPage() | limitTo:toPage()"; setupTr = function(element, repeatString) { var tbody, tr; - tbody = element.find("tbody"); tr = tbody.find("tr"); tr.attr("ng-repeat", repeatString); @@ -303,8 +287,7 @@ }; StandardSetup = function(attributes) { var repeatString; - - repeatString = "item in " + attributes.list + " " + orderByExpression; + repeatString = "item in " + attributes.atList + " " + orderByExpression; this.compile = function(element, attributes, transclude) { return setupTr(element, repeatString); }; @@ -312,21 +295,19 @@ }; PaginationSetup = function(attributes) { var paginationName, repeatString, sortContext; - - sortContext = attributes.sortContext || "global"; + sortContext = attributes.atSortContext || "global"; paginationName = attributes.pagination; if (sortContext === "global") { - repeatString = "item in " + paginationName + ".list " + orderByExpression + " " + limitToExpression; + repeatString = "item in " + paginationName + ".atList " + orderByExpression + " " + limitToExpression; } else if (sortContext === "page") { - repeatString = "item in " + paginationName + ".list " + limitToExpression + " " + orderByExpression + " "; + repeatString = "item in " + paginationName + ".atList " + limitToExpression + " " + orderByExpression + " "; } else { throw "Invalid sort-context: " + sortContext + "."; } this.compile = function(element, attributes, transclude) { var fillerTr, tbody, td, tdString, tds, _i, _len; - tbody = setupTr(element, repeatString); - if (typeof attributes.fillLastPage !== "undefined") { + if (typeof attributes.atFillLastPage !== "undefined") { tds = element.find("td"); tdString = ""; for (_i = 0, _len = tds.length; _i < _len; _i++) { @@ -346,13 +327,13 @@ }; return $scope.toPage = function() { if ($scope[paginationName]) { - return $scope[paginationName].itemsPerPage; + return $scope[paginationName].atItemsPerPage; } }; }; }; return function(attributes) { - if (attributes.list) { + if (attributes.atList) { return new StandardSetup(attributes); } if (attributes.pagination) { diff --git a/angular-table.min.js b/angular-table.min.js index fc4c4e4..fe1d58a 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 0.0.7 +// version: 0.0.8 // license: MIT // homepage: http://github.com/ssmm/angular-table -!function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var i,n,r;return i=function(t,e){var i,n,r,a,o,l,u,c,g,s,f;for(l=angular.element(""),u=0,g=e.length;g>u;u++){if(r=e[u],a=angular.element(""),t[r.attribute]){for(f=t[r.attribute].attributes,c=0,s=f.length;s>c;c++)i=f[c],a.attr(""+i.name,""+i.value);o=t[r.attribute].content}else o=r.title;a.html(""+o),r.sortable&&(a.attr("ng-click","predicate = '"+r.attribute+"'; descending = !descending;"),n=angular.element(""),n.attr("ng-class","getSortIcon('"+r.attribute+"')"),a.append(n)),a.attr("width",r.width),l.append(a)}return l},r=function(t){if(t.pagination&&t.list)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.list)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(a,o,l){var u,c,g,s,f,d;return n(o),r(o),f=a.find("thead"),s=a.find("tbody"),u=t.collectBodyDefinition(s),f[0]&&(c=t.collectCustomHeaderMarkup(f),d=f.find("tr"),d.remove(),f.append(i(c,u.tds))),g=e(o),g.compile(a,o,l),{post:function(t,e,i){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.link(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("attribute"),!e)throw"at-implicit specified without attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{itemsPerPage:"@",instance:"=",list:"="},link:function(t){var e,i;return t.instance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},i=function(){var e;return t.currentPage=0,t.list?t.list.length>0?(t.numberOfPages=Math.ceil(t.list.length/t.itemsPerPage),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t.numberOfPages-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.list?t.itemsPerPage*t.currentPage-t.list.length:void 0},t.getFillerArray=function(){var e,i,n,r,a,o,l;if(t.currentPage===t.numberOfPages-1){if(i=t.list.length%t.itemsPerPage,0!==i||0===t.list.length){for(e=t.itemsPerPage-i-1,l=[],n=r=a=t.list.length,o=t.list.length+e;o>=a?o>=r:r>=o;n=o>=a?++r:--r)l.push(n);return l}return[]}},t.goToPage=function(i){return t.currentPage=e(i)},i(),t.$watch("itemsPerPage",function(){return i()}),t.$watch("list",function(){return i()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,i,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i=function(t){var e;if(e=t.attr("initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,i,n,r,a,o,l;for(i={},r=t.find("tr"),l=r.find("th"),a=0,o=l.length;o>a;a++)n=l[a],n=angular.element(n),e=i[n.attr("attribute")]={},e.content=n.html(),e.attributes=n[0].attributes;return i},collectBodyDefinition:function(r){var a,o,l,u,c,g,s,f,d,p;for(o={},o.tds=[],o.initialSorting=void 0,p=r.find("td"),f=0,d=p.length;d>f;f++)if(c=p[f],c=angular.element(c),a=c.attr("attribute"),g=c.attr("title")||t(c.attr("attribute")),u=c[0].attributes.sortable||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:a,title:g,sortable:u,width:s}),l=i(c)){if(!a)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=l,o.initialSorting.predicate=a}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,i,n,r;return n="| orderBy:predicate:descending",i="| limitTo:fromPage() | limitTo:toPage()",r=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},e=function(t){var e;e="item in "+t.list+" "+n,this.compile=function(t){return r(t,e)},this.link=function(){}},t=function(t){var e,a,o;if(o=t.sortContext||"global",e=t.pagination,"global"===o)a="item in "+e+".list "+n+" "+i;else{if("page"!==o)throw"Invalid sort-context: "+o+".";a="item in "+e+".list "+i+" "+n+" "}this.compile=function(t,i){var n,o,l,u,c,g,s;if(o=r(t,a),"undefined"!=typeof i.fillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)l=c[g],u+=" ";return n=angular.element(""+u+""),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].itemsPerPage:void 0}}},function(i){return i.list?new e(i):i.pagination?new t(i):void 0}}])}.call(this); \ No newline at end of file +(function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var a,n,i;return a=function(t,e){var a,n,i,r,o,u,l,c,g,s,f;for(u=angular.element(""),l=0,g=e.length;g>l;l++){if(i=e[l],r=angular.element(""),t[i.attribute]){for(f=t[i.attribute].attributes,c=0,s=f.length;s>c;c++)a=f[c],r.attr(""+a.name,""+a.value);o=t[i.attribute].content}else o=i.title;r.html(""+o),i.sortable&&(r.attr("ng-click","predicate = '"+i.attribute+"'; descending = !descending;"),n=angular.element(""),n.attr("ng-class","getSortIcon('"+i.attribute+"')"),r.append(n)),r.attr("width",i.width),u.append(r)}return u},i=function(t){if(t.pagination&&t.atList)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.atList)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(r,o,u){var l,c,g,s,f,d;return n(o),i(o),f=r.find("thead"),s=r.find("tbody"),l=t.collectBodyDefinition(s),f[0]&&(c=t.collectCustomHeaderMarkup(f),d=f.find("tr"),d.remove(),f.append(a(c,l.tds))),g=e(o),g.compile(r,o,u),{post:function(t,e,a){return l.initialSorting&&(t.predicate=l.initialSorting.predicate,t.descending="desc"===l.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.link(t,e,a)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{atItemsPerPage:"@",atInstance:"=",atList:"="},link:function(t){var e,a;return t.atInstance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},a=function(){var e;return t.currentPage=0,t.atList?t.atList.length>0?(t.numberOfPages=Math.ceil(t.atList.length/t.atItemsPerPage),t.pages=function(){var a,n,i;for(i=[],e=a=0,n=t.numberOfPages-1;n>=0?n>=a:a>=n;e=n>=0?++a:--a)i.push(e);return i}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.atList?t.atItemsPerPage*t.currentPage-t.atList.length:void 0},t.getFillerArray=function(){var e,a,n,i,r,o,u;if(t.currentPage===t.numberOfPages-1){if(a=t.atList.length%t.atItemsPerPage,0!==a||0===t.atList.length){for(e=t.atItemsPerPage-a-1,u=[],n=i=r=t.atList.length,o=t.atList.length+e;o>=r?o>=i:i>=o;n=o>=r?++i:--i)u.push(n);return u}return[]}},t.goToPage=function(a){return t.currentPage=e(a)},a(),t.$watch("atItemsPerPage",function(){return a()}),t.$watch("atList",function(){return a()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,a,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},a=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,a,n,i,r,o,u;for(a={},i=t.find("tr"),u=i.find("th"),r=0,o=u.length;o>r;r++)n=u[r],n=angular.element(n),e=a[n.attr("at-attribute")]={},e.content=n.html(),e.attributes=n[0].attributes;return a},collectBodyDefinition:function(i){var r,o,u,l,c,g,s,f,d,p;for(o={},o.tds=[],o.initialSorting=void 0,p=i.find("td"),f=0,d=p.length;d>f;f++)if(c=p[f],c=angular.element(c),r=c.attr("at-attribute"),g=c.attr("at-title")||t(c.attr("at-attribute")),l=void 0!==c.attr("at-sortable")||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:r,title:g,sortable:l,width:s}),u=a(c)){if(!r)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=u,o.initialSorting.predicate=r}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,a,n,i;return n="| orderBy:predicate:descending",a="| limitTo:fromPage() | limitTo:toPage()",i=function(t,e){var a,n;return a=t.find("tbody"),n=a.find("tr"),n.attr("ng-repeat",e),a},e=function(t){var e;e="item in "+t.atList+" "+n,this.compile=function(t){return i(t,e)},this.link=function(){}},t=function(t){var e,r,o;if(o=t.atSortContext||"global",e=t.pagination,"global"===o)r="item in "+e+".atList "+n+" "+a;else{if("page"!==o)throw"Invalid sort-context: "+o+".";r="item in "+e+".atList "+a+" "+n+" "}this.compile=function(t,a){var n,o,u,l,c,g,s;if(o=i(t,r),"undefined"!=typeof a.atFillLastPage){for(c=t.find("td"),l="",g=0,s=c.length;s>g;g++)u=c[g],l+=" ";return n=angular.element(""+l+""),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].atItemsPerPage:void 0}}},function(a){return a.atList?new e(a):a.pagination?new t(a):void 0}}])}).call(this); \ No newline at end of file diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index d4c9c3c..3e03991 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 0.0.7 +// version: 0.0.8 // license: MIT // homepage: http://github.com/ssmm/angular-table (function() { @@ -8,10 +8,8 @@ angular.module("angular-table").directive("atTable", [ "metaCollector", "setupFactory", function(metaCollector, setupFactory) { var constructHeader, normalizeInput, validateInput; - constructHeader = function(customHeaderMarkup, bodyDefinitions) { var attribute, icon, td, th, title, tr, _i, _j, _len, _len1, _ref; - tr = angular.element(""); for (_i = 0, _len = bodyDefinitions.length; _i < _len; _i++) { td = bodyDefinitions[_i]; @@ -39,10 +37,10 @@ return tr; }; validateInput = function(attributes) { - if (attributes.pagination && attributes.list) { + if (attributes.pagination && attributes.atList) { throw "You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used."; } - if (!attributes.pagination && !attributes.list) { + if (!attributes.pagination && !attributes.atList) { throw "Either a list or pagination must be specified."; } }; @@ -57,7 +55,6 @@ scope: true, compile: function(element, attributes, transclude) { var bodyDefinition, customHeaderMarkup, setup, tbody, thead, tr; - normalizeInput(attributes); validateInput(attributes); thead = element.find("thead"); @@ -101,10 +98,9 @@ restrict: "AC", compile: function(element, attributes, transclude) { var attribute; - - attribute = element.attr("attribute"); + attribute = element.attr("at-attribute"); if (!attribute) { - throw "at-implicit specified without attribute: " + (element.html()); + throw "at-implicit specified without at-attribute: " + (element.html()); } return element.append("{{item." + attribute + "}}"); } @@ -119,14 +115,13 @@ restrict: "E", template: " ", scope: { - itemsPerPage: "@", - instance: "=", - list: "=" + atItemsPerPage: "@", + atInstance: "=", + atList: "=" }, link: function($scope, $element, $attributes) { var normalizePage, update; - - $scope.instance = $scope; + $scope.atInstance = $scope; $scope.currentPage = 0; normalizePage = function(page) { page = Math.max(0, page); @@ -135,14 +130,12 @@ }; update = function(reset) { var x; - $scope.currentPage = 0; - if ($scope.list) { - if ($scope.list.length > 0) { - $scope.numberOfPages = Math.ceil($scope.list.length / $scope.itemsPerPage); + if ($scope.atList) { + if ($scope.atList.length > 0) { + $scope.numberOfPages = Math.ceil($scope.atList.length / $scope.atItemsPerPage); return $scope.pages = (function() { var _i, _ref, _results; - _results = []; for (x = _i = 0, _ref = $scope.numberOfPages - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { _results.push(x); @@ -156,19 +149,18 @@ } }; $scope.fromPage = function() { - if ($scope.list) { - return $scope.itemsPerPage * $scope.currentPage - $scope.list.length; + if ($scope.atList) { + return $scope.atItemsPerPage * $scope.currentPage - $scope.atList.length; } }; $scope.getFillerArray = function() { var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; - if ($scope.currentPage === $scope.numberOfPages - 1) { - itemCountOnLastPage = $scope.list.length % $scope.itemsPerPage; - if (itemCountOnLastPage !== 0 || $scope.list.length === 0) { - fillerLength = $scope.itemsPerPage - itemCountOnLastPage - 1; + itemCountOnLastPage = $scope.atList.length % $scope.atItemsPerPage; + if (itemCountOnLastPage !== 0 || $scope.atList.length === 0) { + fillerLength = $scope.atItemsPerPage - itemCountOnLastPage - 1; _results = []; - for (x = _i = _ref = $scope.list.length, _ref1 = $scope.list.length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { + for (x = _i = _ref = $scope.atList.length, _ref1 = $scope.atList.length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { _results.push(x); } return _results; @@ -181,10 +173,10 @@ return $scope.currentPage = normalizePage(page); }; update(); - $scope.$watch("itemsPerPage", function() { + $scope.$watch("atItemsPerPage", function() { return update(); }); - return $scope.$watch("list", function() { + return $scope.$watch("atList", function() { return update(); }); } @@ -195,7 +187,6 @@ angular.module("angular-table").service("metaCollector", [ function() { var capitaliseFirstLetter, extractWidth, getInitialSortDirection, isSortable; - capitaliseFirstLetter = function(string) { if (string) { return string.charAt(0).toUpperCase() + string.slice(1); @@ -205,7 +196,6 @@ }; extractWidth = function(classes) { var width; - width = /([0-9]+px)/i.exec(classes); if (width) { return width[0]; @@ -215,7 +205,6 @@ }; isSortable = function(classes) { var sortable; - sortable = /(sortable)/i.exec(classes); if (sortable) { return true; @@ -225,8 +214,7 @@ }; getInitialSortDirection = function(td) { var initialSorting; - - initialSorting = td.attr("initial-sorting"); + initialSorting = td.attr("at-initial-sorting"); if (initialSorting) { if (initialSorting === "asc" || initialSorting === "desc") { return initialSorting; @@ -238,14 +226,13 @@ return { collectCustomHeaderMarkup: function(thead) { var customHeaderMarkup, customHeaderMarkups, th, tr, _i, _len, _ref; - customHeaderMarkups = {}; tr = thead.find("tr"); _ref = tr.find("th"); for (_i = 0, _len = _ref.length; _i < _len; _i++) { th = _ref[_i]; th = angular.element(th); - customHeaderMarkup = customHeaderMarkups[th.attr("attribute")] = {}; + customHeaderMarkup = customHeaderMarkups[th.attr("at-attribute")] = {}; customHeaderMarkup.content = th.html(); customHeaderMarkup.attributes = th[0].attributes; } @@ -253,7 +240,6 @@ }, collectBodyDefinition: function(tbody) { var attribute, bodyDefinition, initialSortDirection, sortable, td, title, width, _i, _len, _ref; - bodyDefinition = {}; bodyDefinition.tds = []; bodyDefinition.initialSorting = void 0; @@ -261,9 +247,9 @@ for (_i = 0, _len = _ref.length; _i < _len; _i++) { td = _ref[_i]; td = angular.element(td); - attribute = td.attr("attribute"); - title = td.attr("title") || capitaliseFirstLetter(td.attr("attribute")); - sortable = td[0].attributes.sortable || isSortable(td.attr("class")); + attribute = td.attr("at-attribute"); + title = td.attr("at-title") || capitaliseFirstLetter(td.attr("at-attribute")); + sortable = td.attr("at-sortable") !== void 0 || isSortable(td.attr("class")); width = extractWidth(td.attr("class")); bodyDefinition.tds.push({ attribute: attribute, @@ -290,12 +276,10 @@ angular.module("angular-table").factory("setupFactory", [ function() { var PaginationSetup, StandardSetup, limitToExpression, orderByExpression, setupTr; - orderByExpression = "| orderBy:predicate:descending"; limitToExpression = "| limitTo:fromPage() | limitTo:toPage()"; setupTr = function(element, repeatString) { var tbody, tr; - tbody = element.find("tbody"); tr = tbody.find("tr"); tr.attr("ng-repeat", repeatString); @@ -303,8 +287,7 @@ }; StandardSetup = function(attributes) { var repeatString; - - repeatString = "item in " + attributes.list + " " + orderByExpression; + repeatString = "item in " + attributes.atList + " " + orderByExpression; this.compile = function(element, attributes, transclude) { return setupTr(element, repeatString); }; @@ -312,21 +295,19 @@ }; PaginationSetup = function(attributes) { var paginationName, repeatString, sortContext; - - sortContext = attributes.sortContext || "global"; + sortContext = attributes.atSortContext || "global"; paginationName = attributes.pagination; if (sortContext === "global") { - repeatString = "item in " + paginationName + ".list " + orderByExpression + " " + limitToExpression; + repeatString = "item in " + paginationName + ".atList " + orderByExpression + " " + limitToExpression; } else if (sortContext === "page") { - repeatString = "item in " + paginationName + ".list " + limitToExpression + " " + orderByExpression + " "; + repeatString = "item in " + paginationName + ".atList " + limitToExpression + " " + orderByExpression + " "; } else { throw "Invalid sort-context: " + sortContext + "."; } this.compile = function(element, attributes, transclude) { var fillerTr, tbody, td, tdString, tds, _i, _len; - tbody = setupTr(element, repeatString); - if (typeof attributes.fillLastPage !== "undefined") { + if (typeof attributes.atFillLastPage !== "undefined") { tds = element.find("td"); tdString = ""; for (_i = 0, _len = tds.length; _i < _len; _i++) { @@ -346,13 +327,13 @@ }; return $scope.toPage = function() { if ($scope[paginationName]) { - return $scope[paginationName].itemsPerPage; + return $scope[paginationName].atItemsPerPage; } }; }; }; return function(attributes) { - if (attributes.list) { + if (attributes.atList) { return new StandardSetup(attributes); } if (attributes.pagination) { diff --git a/gem/lib/angular-table/version.rb b/gem/lib/angular-table/version.rb index 867b105..35aaad1 100644 --- a/gem/lib/angular-table/version.rb +++ b/gem/lib/angular-table/version.rb @@ -1,3 +1,3 @@ module AngularTable - VERSION = "0.0.7" + VERSION = "0.0.8" end From 75f43432b272d094fc825fd94522009e7f5ec914 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 8 Feb 2014 18:10:30 +0100 Subject: [PATCH 036/190] removed dependency on jquery --- coffee/atTable.coffee | 21 +++++++++++++-------- coffee/metaCollector.coffee | 4 ++-- coffee/setupFactory.coffee | 4 +++- test/header.coffee | 4 ++-- test/test_helper.coffee | 3 +++ 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index eb9df15..9cdbbad 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -2,11 +2,14 @@ angular.module "angular-table", [] angular.module("angular-table").directive "atTable", ["metaCollector", "setupFactory", (metaCollector, setupFactory) -> + # TODO clean up constructHeader = (customHeaderMarkup, bodyDefinitions) -> - tr = angular.element("") + tr = angular.element("
") + tr = tr.find("tr") for td in bodyDefinitions - th = angular.element("") + th = angular.element("
") + th = th.find("th") if customHeaderMarkup[td.attribute] for attribute in customHeaderMarkup[td.attribute].attributes th.attr("#{attribute.name}", "#{attribute.value}") @@ -27,6 +30,7 @@ angular.module("angular-table").directive "atTable", ["metaCollector", "setupFac tr + validateInput = (attributes) -> if attributes.pagination and attributes.atList throw "You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used." @@ -45,16 +49,17 @@ angular.module("angular-table").directive "atTable", ["metaCollector", "setupFac normalizeInput attributes validateInput attributes - thead = element.find "thead" - tbody = element.find "tbody" - bodyDefinition = metaCollector.collectBodyDefinition(tbody) + bodyDefinition = metaCollector.collectBodyDefinition(element) + # TODO: better solution + thead = element.find("thead") if thead[0] - customHeaderMarkup = metaCollector.collectCustomHeaderMarkup(thead) - tr = thead.find "tr" + customHeaderMarkup = metaCollector.collectCustomHeaderMarkup(element) + tr = angular.element(thead).find("tr") tr.remove() - thead.append constructHeader(customHeaderMarkup, bodyDefinition.tds) + header = constructHeader(customHeaderMarkup, bodyDefinition.tds) + angular.element(thead[0]).append(header) setup = setupFactory attributes setup.compile(element, attributes, transclude) diff --git a/coffee/metaCollector.coffee b/coffee/metaCollector.coffee index 10ccb34..ff3a436 100644 --- a/coffee/metaCollector.coffee +++ b/coffee/metaCollector.coffee @@ -27,8 +27,8 @@ angular.module("angular-table").service "metaCollector", [() -> collectCustomHeaderMarkup: (thead) -> customHeaderMarkups = {} - tr = thead.find "tr" - for th in tr.find "th" + tr = thead.find("tr") + for th in tr.find("th") th = angular.element(th) customHeaderMarkup = customHeaderMarkups[th.attr("at-attribute")] = {} customHeaderMarkup.content = th.html() diff --git a/coffee/setupFactory.coffee b/coffee/setupFactory.coffee index 920b7d0..41342f3 100644 --- a/coffee/setupFactory.coffee +++ b/coffee/setupFactory.coffee @@ -38,7 +38,9 @@ angular.module("angular-table").factory "setupFactory", [() -> for td in tds tdString += " " - fillerTr = angular.element("#{tdString}") + # TODO + fillerTr = angular.element("#{tdString}
") + fillerTr = fillerTr.find("tr") fillerTr.attr("ng-repeat", "item in #{paginationName}.getFillerArray() ") tbody.append(fillerTr) diff --git a/test/header.coffee b/test/header.coffee index 0791ffd..a70738a 100644 --- a/test/header.coffee +++ b/test/header.coffee @@ -8,12 +8,12 @@ describe "angular-table", () -> it "creates column headers implicitly", () -> @element = prepare_element(new TemplateCompiler("header/header.html"), (scope) ->) - header = extract_html_to_array(@element.find("thead > tr > th")) + header = extract_html_to_array(getChildrenFor(@element, "thead > tr > th")) expect(header[0]).toEqual "Name" it "allows to set custom column headers", () -> @element = prepare_element(new TemplateCompiler("header/header.html"), (scope) ->) - header = extract_html_to_array(@element.find("thead > tr > th")) + header = extract_html_to_array(getChildrenFor(@element, "thead > tr > th")) expect(header[1]).toEqual "The population" expect(header[2]).toEqual "Country" expect(header[3]).toEqual "Size" diff --git a/test/test_helper.coffee b/test/test_helper.coffee index bbb033d..25c992f 100644 --- a/test/test_helper.coffee +++ b/test/test_helper.coffee @@ -1,3 +1,6 @@ +getChildrenFor = (element, selector) -> + element[0].querySelectorAll(selector) + extract_html_to_array = (tds) -> _.map(tds, (td) -> angular.element(td).html()) From 61e5ac086d8b3704a77329d8e0f3e2945eabcff1 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 8 Feb 2014 18:12:08 +0100 Subject: [PATCH 037/190] removed jquery reference from karma config --- karma.conf.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index c0fc1b1..7475da7 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -14,10 +14,9 @@ module.exports = function(config) { // list of files / patterns to load in the browser files: [ - "http://code.jquery.com/jquery-1.10.1.min.js", - "http://code.angularjs.org/1.2.11/angular.min.js", - "http://code.angularjs.org/1.2.11/angular-mocks.js", - "http://underscorejs.org/underscore-min.js", + 'http://code.angularjs.org/1.2.11/angular.min.js', + 'http://code.angularjs.org/1.2.11/angular-mocks.js', + 'http://underscorejs.org/underscore-min.js', 'coffee/atTable.coffee', 'coffee/*.coffee', 'test/test_helper.coffee', @@ -32,9 +31,9 @@ module.exports = function(config) { ], preprocessors: { - "coffee/*.coffee": ["coffee"], - "test/*.coffee": ["coffee"], - "test/templates/**/*.html": ["ng-html2js"] + 'coffee/*.coffee': ['coffee'], + 'test/*.coffee': ['coffee'], + 'test/templates/**/*.html': ['ng-html2js'] }, // test results reporter to use From 0cd6e30d9303f5ae126360d22f5688259eff8d86 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 8 Feb 2014 18:12:22 +0100 Subject: [PATCH 038/190] new test for metaCollector --- test/metaCollectorTest.coffee | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/metaCollectorTest.coffee diff --git a/test/metaCollectorTest.coffee b/test/metaCollectorTest.coffee new file mode 100644 index 0000000..7ec6072 --- /dev/null +++ b/test/metaCollectorTest.coffee @@ -0,0 +1,25 @@ +describe "angular-table", () -> + describe "MetaCollector", () -> + + mc = null + + beforeEach () -> + module("angular-table") + inject (metaCollector) -> + mc = metaCollector + + it "bla", () -> + + header = angular.element( + " + +
hello world
" + ) + + headerMarkup = mc.collectCustomHeaderMarkup(header) + + one = headerMarkup["one"] + + expect(one).toBeDefined() + expect(one["content"]).toEqual "hello world" + expect(one["attributes"]).toBeDefined() From e9491706dd1dc007e8a35cb092cb953ed2245d19 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 8 Feb 2014 18:14:23 +0100 Subject: [PATCH 039/190] compiled new version --- angular-table.js | 21 ++++++++++++--------- angular-table.min.js | 2 +- gem/app/assets/javascripts/angular-table.js | 21 ++++++++++++--------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/angular-table.js b/angular-table.js index 3e03991..8be76f1 100644 --- a/angular-table.js +++ b/angular-table.js @@ -10,10 +10,12 @@ var constructHeader, normalizeInput, validateInput; constructHeader = function(customHeaderMarkup, bodyDefinitions) { var attribute, icon, td, th, title, tr, _i, _j, _len, _len1, _ref; - tr = angular.element(""); + tr = angular.element("
"); + tr = tr.find("tr"); for (_i = 0, _len = bodyDefinitions.length; _i < _len; _i++) { td = bodyDefinitions[_i]; - th = angular.element(""); + th = angular.element("
"); + th = th.find("th"); if (customHeaderMarkup[td.attribute]) { _ref = customHeaderMarkup[td.attribute].attributes; for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { @@ -54,17 +56,17 @@ restrict: "AC", scope: true, compile: function(element, attributes, transclude) { - var bodyDefinition, customHeaderMarkup, setup, tbody, thead, tr; + var bodyDefinition, customHeaderMarkup, header, setup, thead, tr; normalizeInput(attributes); validateInput(attributes); + bodyDefinition = metaCollector.collectBodyDefinition(element); thead = element.find("thead"); - tbody = element.find("tbody"); - bodyDefinition = metaCollector.collectBodyDefinition(tbody); if (thead[0]) { - customHeaderMarkup = metaCollector.collectCustomHeaderMarkup(thead); - tr = thead.find("tr"); + customHeaderMarkup = metaCollector.collectCustomHeaderMarkup(element); + tr = angular.element(thead).find("tr"); tr.remove(); - thead.append(constructHeader(customHeaderMarkup, bodyDefinition.tds)); + header = constructHeader(customHeaderMarkup, bodyDefinition.tds); + angular.element(thead[0]).append(header); } setup = setupFactory(attributes); setup.compile(element, attributes, transclude); @@ -314,7 +316,8 @@ td = tds[_i]; tdString += " "; } - fillerTr = angular.element("" + tdString + ""); + fillerTr = angular.element("" + tdString + "
"); + fillerTr = fillerTr.find("tr"); fillerTr.attr("ng-repeat", "item in " + paginationName + ".getFillerArray() "); return tbody.append(fillerTr); } diff --git a/angular-table.min.js b/angular-table.min.js index fe1d58a..cdf0172 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/ssmm/angular-table -(function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var a,n,i;return a=function(t,e){var a,n,i,r,o,u,l,c,g,s,f;for(u=angular.element(""),l=0,g=e.length;g>l;l++){if(i=e[l],r=angular.element(""),t[i.attribute]){for(f=t[i.attribute].attributes,c=0,s=f.length;s>c;c++)a=f[c],r.attr(""+a.name,""+a.value);o=t[i.attribute].content}else o=i.title;r.html(""+o),i.sortable&&(r.attr("ng-click","predicate = '"+i.attribute+"'; descending = !descending;"),n=angular.element(""),n.attr("ng-class","getSortIcon('"+i.attribute+"')"),r.append(n)),r.attr("width",i.width),u.append(r)}return u},i=function(t){if(t.pagination&&t.atList)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.atList)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(r,o,u){var l,c,g,s,f,d;return n(o),i(o),f=r.find("thead"),s=r.find("tbody"),l=t.collectBodyDefinition(s),f[0]&&(c=t.collectCustomHeaderMarkup(f),d=f.find("tr"),d.remove(),f.append(a(c,l.tds))),g=e(o),g.compile(r,o,u),{post:function(t,e,a){return l.initialSorting&&(t.predicate=l.initialSorting.predicate,t.descending="desc"===l.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},g.link(t,e,a)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{atItemsPerPage:"@",atInstance:"=",atList:"="},link:function(t){var e,a;return t.atInstance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},a=function(){var e;return t.currentPage=0,t.atList?t.atList.length>0?(t.numberOfPages=Math.ceil(t.atList.length/t.atItemsPerPage),t.pages=function(){var a,n,i;for(i=[],e=a=0,n=t.numberOfPages-1;n>=0?n>=a:a>=n;e=n>=0?++a:--a)i.push(e);return i}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.atList?t.atItemsPerPage*t.currentPage-t.atList.length:void 0},t.getFillerArray=function(){var e,a,n,i,r,o,u;if(t.currentPage===t.numberOfPages-1){if(a=t.atList.length%t.atItemsPerPage,0!==a||0===t.atList.length){for(e=t.atItemsPerPage-a-1,u=[],n=i=r=t.atList.length,o=t.atList.length+e;o>=r?o>=i:i>=o;n=o>=r?++i:--i)u.push(n);return u}return[]}},t.goToPage=function(a){return t.currentPage=e(a)},a(),t.$watch("atItemsPerPage",function(){return a()}),t.$watch("atList",function(){return a()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,a,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},a=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,a,n,i,r,o,u;for(a={},i=t.find("tr"),u=i.find("th"),r=0,o=u.length;o>r;r++)n=u[r],n=angular.element(n),e=a[n.attr("at-attribute")]={},e.content=n.html(),e.attributes=n[0].attributes;return a},collectBodyDefinition:function(i){var r,o,u,l,c,g,s,f,d,p;for(o={},o.tds=[],o.initialSorting=void 0,p=i.find("td"),f=0,d=p.length;d>f;f++)if(c=p[f],c=angular.element(c),r=c.attr("at-attribute"),g=c.attr("at-title")||t(c.attr("at-attribute")),l=void 0!==c.attr("at-sortable")||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:r,title:g,sortable:l,width:s}),u=a(c)){if(!r)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=u,o.initialSorting.predicate=r}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,a,n,i;return n="| orderBy:predicate:descending",a="| limitTo:fromPage() | limitTo:toPage()",i=function(t,e){var a,n;return a=t.find("tbody"),n=a.find("tr"),n.attr("ng-repeat",e),a},e=function(t){var e;e="item in "+t.atList+" "+n,this.compile=function(t){return i(t,e)},this.link=function(){}},t=function(t){var e,r,o;if(o=t.atSortContext||"global",e=t.pagination,"global"===o)r="item in "+e+".atList "+n+" "+a;else{if("page"!==o)throw"Invalid sort-context: "+o+".";r="item in "+e+".atList "+a+" "+n+" "}this.compile=function(t,a){var n,o,u,l,c,g,s;if(o=i(t,r),"undefined"!=typeof a.atFillLastPage){for(c=t.find("td"),l="",g=0,s=c.length;s>g;g++)u=c[g],l+=" ";return n=angular.element(""+l+""),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].atItemsPerPage:void 0}}},function(a){return a.atList?new e(a):a.pagination?new t(a):void 0}}])}).call(this); \ No newline at end of file +(function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var a,n,i;return a=function(t,e){var a,n,i,r,o,l,u,c,g,s,f;for(l=angular.element("
"),l=l.find("tr"),u=0,g=e.length;g>u;u++){if(i=e[u],r=angular.element("
"),r=r.find("th"),t[i.attribute]){for(f=t[i.attribute].attributes,c=0,s=f.length;s>c;c++)a=f[c],r.attr(""+a.name,""+a.value);o=t[i.attribute].content}else o=i.title;r.html(""+o),i.sortable&&(r.attr("ng-click","predicate = '"+i.attribute+"'; descending = !descending;"),n=angular.element(""),n.attr("ng-class","getSortIcon('"+i.attribute+"')"),r.append(n)),r.attr("width",i.width),l.append(r)}return l},i=function(t){if(t.pagination&&t.atList)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.atList)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(r,o,l){var u,c,g,s,f,d;return n(o),i(o),u=t.collectBodyDefinition(r),f=r.find("thead"),f[0]&&(c=t.collectCustomHeaderMarkup(r),d=angular.element(f).find("tr"),d.remove(),g=a(c,u.tds),angular.element(f[0]).append(g)),s=e(o),s.compile(r,o,l),{post:function(t,e,a){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},s.link(t,e,a)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{atItemsPerPage:"@",atInstance:"=",atList:"="},link:function(t){var e,a;return t.atInstance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},a=function(){var e;return t.currentPage=0,t.atList?t.atList.length>0?(t.numberOfPages=Math.ceil(t.atList.length/t.atItemsPerPage),t.pages=function(){var a,n,i;for(i=[],e=a=0,n=t.numberOfPages-1;n>=0?n>=a:a>=n;e=n>=0?++a:--a)i.push(e);return i}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.atList?t.atItemsPerPage*t.currentPage-t.atList.length:void 0},t.getFillerArray=function(){var e,a,n,i,r,o,l;if(t.currentPage===t.numberOfPages-1){if(a=t.atList.length%t.atItemsPerPage,0!==a||0===t.atList.length){for(e=t.atItemsPerPage-a-1,l=[],n=i=r=t.atList.length,o=t.atList.length+e;o>=r?o>=i:i>=o;n=o>=r?++i:--i)l.push(n);return l}return[]}},t.goToPage=function(a){return t.currentPage=e(a)},a(),t.$watch("atItemsPerPage",function(){return a()}),t.$watch("atList",function(){return a()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,a,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},a=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,a,n,i,r,o,l;for(a={},i=t.find("tr"),l=i.find("th"),r=0,o=l.length;o>r;r++)n=l[r],n=angular.element(n),e=a[n.attr("at-attribute")]={},e.content=n.html(),e.attributes=n[0].attributes;return a},collectBodyDefinition:function(i){var r,o,l,u,c,g,s,f,d,p;for(o={},o.tds=[],o.initialSorting=void 0,p=i.find("td"),f=0,d=p.length;d>f;f++)if(c=p[f],c=angular.element(c),r=c.attr("at-attribute"),g=c.attr("at-title")||t(c.attr("at-attribute")),u=void 0!==c.attr("at-sortable")||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:r,title:g,sortable:u,width:s}),l=a(c)){if(!r)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=l,o.initialSorting.predicate=r}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,a,n,i;return n="| orderBy:predicate:descending",a="| limitTo:fromPage() | limitTo:toPage()",i=function(t,e){var a,n;return a=t.find("tbody"),n=a.find("tr"),n.attr("ng-repeat",e),a},e=function(t){var e;e="item in "+t.atList+" "+n,this.compile=function(t){return i(t,e)},this.link=function(){}},t=function(t){var e,r,o;if(o=t.atSortContext||"global",e=t.pagination,"global"===o)r="item in "+e+".atList "+n+" "+a;else{if("page"!==o)throw"Invalid sort-context: "+o+".";r="item in "+e+".atList "+a+" "+n+" "}this.compile=function(t,a){var n,o,l,u,c,g,s;if(o=i(t,r),"undefined"!=typeof a.atFillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)l=c[g],u+=" ";return n=angular.element(""+u+"
"),n=n.find("tr"),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].atItemsPerPage:void 0}}},function(a){return a.atList?new e(a):a.pagination?new t(a):void 0}}])}).call(this); \ No newline at end of file diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 3e03991..8be76f1 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -10,10 +10,12 @@ var constructHeader, normalizeInput, validateInput; constructHeader = function(customHeaderMarkup, bodyDefinitions) { var attribute, icon, td, th, title, tr, _i, _j, _len, _len1, _ref; - tr = angular.element(""); + tr = angular.element("
"); + tr = tr.find("tr"); for (_i = 0, _len = bodyDefinitions.length; _i < _len; _i++) { td = bodyDefinitions[_i]; - th = angular.element(""); + th = angular.element("
"); + th = th.find("th"); if (customHeaderMarkup[td.attribute]) { _ref = customHeaderMarkup[td.attribute].attributes; for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { @@ -54,17 +56,17 @@ restrict: "AC", scope: true, compile: function(element, attributes, transclude) { - var bodyDefinition, customHeaderMarkup, setup, tbody, thead, tr; + var bodyDefinition, customHeaderMarkup, header, setup, thead, tr; normalizeInput(attributes); validateInput(attributes); + bodyDefinition = metaCollector.collectBodyDefinition(element); thead = element.find("thead"); - tbody = element.find("tbody"); - bodyDefinition = metaCollector.collectBodyDefinition(tbody); if (thead[0]) { - customHeaderMarkup = metaCollector.collectCustomHeaderMarkup(thead); - tr = thead.find("tr"); + customHeaderMarkup = metaCollector.collectCustomHeaderMarkup(element); + tr = angular.element(thead).find("tr"); tr.remove(); - thead.append(constructHeader(customHeaderMarkup, bodyDefinition.tds)); + header = constructHeader(customHeaderMarkup, bodyDefinition.tds); + angular.element(thead[0]).append(header); } setup = setupFactory(attributes); setup.compile(element, attributes, transclude); @@ -314,7 +316,8 @@ td = tds[_i]; tdString += " "; } - fillerTr = angular.element("" + tdString + ""); + fillerTr = angular.element("" + tdString + "
"); + fillerTr = fillerTr.find("tr"); fillerTr.attr("ng-repeat", "item in " + paginationName + ".getFillerArray() "); return tbody.append(fillerTr); } From 962801fe2629abba25c6d1f8e5f10ed4f5c5aef0 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 8 Feb 2014 18:35:17 +0100 Subject: [PATCH 040/190] updated url --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 04cf202..1c2fc5f 100644 --- a/Rakefile +++ b/Rakefile @@ -31,7 +31,7 @@ def prepend_author_notice script comments << "// author: Samuel Mueller \n" comments << "// version: #{AngularTable::VERSION} \n" comments << "// license: MIT \n" - comments << "// homepage: http://github.com/ssmm/angular-table \n" + comments << "// homepage: http://github.com/samu/angular-table \n" script.prepend comments script From 5ba801081eea137820b4c0dc250066ee0933ac80 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 8 Feb 2014 18:57:39 +0100 Subject: [PATCH 041/190] solved the TODOs --- coffee/atTable.coffee | 10 ++++------ coffee/setupFactory.coffee | 5 ++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index 9cdbbad..742b9a8 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -2,14 +2,13 @@ angular.module "angular-table", [] angular.module("angular-table").directive "atTable", ["metaCollector", "setupFactory", (metaCollector, setupFactory) -> - # TODO clean up constructHeader = (customHeaderMarkup, bodyDefinitions) -> - tr = angular.element("
") - tr = tr.find("tr") + tr = angular.element(document.createElement("tr")) for td in bodyDefinitions - th = angular.element("
") - th = th.find("th") + th = angular.element(document.createElement("th")) + th.attr("style","cursor: pointer;") + if customHeaderMarkup[td.attribute] for attribute in customHeaderMarkup[td.attribute].attributes th.attr("#{attribute.name}", "#{attribute.value}") @@ -52,7 +51,6 @@ angular.module("angular-table").directive "atTable", ["metaCollector", "setupFac bodyDefinition = metaCollector.collectBodyDefinition(element) - # TODO: better solution thead = element.find("thead") if thead[0] customHeaderMarkup = metaCollector.collectCustomHeaderMarkup(element) diff --git a/coffee/setupFactory.coffee b/coffee/setupFactory.coffee index 41342f3..b6574fd 100644 --- a/coffee/setupFactory.coffee +++ b/coffee/setupFactory.coffee @@ -38,9 +38,8 @@ angular.module("angular-table").factory "setupFactory", [() -> for td in tds tdString += " " - # TODO - fillerTr = angular.element("#{tdString}
") - fillerTr = fillerTr.find("tr") + fillerTr = angular.element(document.createElement("tr")) + fillerTr.html(tdString) fillerTr.attr("ng-repeat", "item in #{paginationName}.getFillerArray() ") tbody.append(fillerTr) From 90e0a64d92672ebded32a06990c6b164e13b27ba Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 8 Feb 2014 18:58:01 +0100 Subject: [PATCH 042/190] compiled new version --- angular-table.js | 13 ++++++------- angular-table.min.js | 4 ++-- gem/app/assets/javascripts/angular-table.js | 13 ++++++------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/angular-table.js b/angular-table.js index 8be76f1..14b0797 100644 --- a/angular-table.js +++ b/angular-table.js @@ -1,7 +1,7 @@ // author: Samuel Mueller // version: 0.0.8 // license: MIT -// homepage: http://github.com/ssmm/angular-table +// homepage: http://github.com/samu/angular-table (function() { angular.module("angular-table", []); @@ -10,12 +10,11 @@ var constructHeader, normalizeInput, validateInput; constructHeader = function(customHeaderMarkup, bodyDefinitions) { var attribute, icon, td, th, title, tr, _i, _j, _len, _len1, _ref; - tr = angular.element("
"); - tr = tr.find("tr"); + tr = angular.element(document.createElement("tr")); for (_i = 0, _len = bodyDefinitions.length; _i < _len; _i++) { td = bodyDefinitions[_i]; - th = angular.element("
"); - th = th.find("th"); + th = angular.element(document.createElement("th")); + th.attr("style", "cursor: pointer;"); if (customHeaderMarkup[td.attribute]) { _ref = customHeaderMarkup[td.attribute].attributes; for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { @@ -316,8 +315,8 @@ td = tds[_i]; tdString += " "; } - fillerTr = angular.element("" + tdString + "
"); - fillerTr = fillerTr.find("tr"); + fillerTr = angular.element(document.createElement("tr")); + fillerTr.html(tdString); fillerTr.attr("ng-repeat", "item in " + paginationName + ".getFillerArray() "); return tbody.append(fillerTr); } diff --git a/angular-table.min.js b/angular-table.min.js index cdf0172..f691a6f 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -1,5 +1,5 @@ // author: Samuel Mueller // version: 0.0.8 // license: MIT -// homepage: http://github.com/ssmm/angular-table -(function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var a,n,i;return a=function(t,e){var a,n,i,r,o,l,u,c,g,s,f;for(l=angular.element("
"),l=l.find("tr"),u=0,g=e.length;g>u;u++){if(i=e[u],r=angular.element("
"),r=r.find("th"),t[i.attribute]){for(f=t[i.attribute].attributes,c=0,s=f.length;s>c;c++)a=f[c],r.attr(""+a.name,""+a.value);o=t[i.attribute].content}else o=i.title;r.html(""+o),i.sortable&&(r.attr("ng-click","predicate = '"+i.attribute+"'; descending = !descending;"),n=angular.element(""),n.attr("ng-class","getSortIcon('"+i.attribute+"')"),r.append(n)),r.attr("width",i.width),l.append(r)}return l},i=function(t){if(t.pagination&&t.atList)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.atList)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(r,o,l){var u,c,g,s,f,d;return n(o),i(o),u=t.collectBodyDefinition(r),f=r.find("thead"),f[0]&&(c=t.collectCustomHeaderMarkup(r),d=angular.element(f).find("tr"),d.remove(),g=a(c,u.tds),angular.element(f[0]).append(g)),s=e(o),s.compile(r,o,l),{post:function(t,e,a){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},s.link(t,e,a)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{atItemsPerPage:"@",atInstance:"=",atList:"="},link:function(t){var e,a;return t.atInstance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},a=function(){var e;return t.currentPage=0,t.atList?t.atList.length>0?(t.numberOfPages=Math.ceil(t.atList.length/t.atItemsPerPage),t.pages=function(){var a,n,i;for(i=[],e=a=0,n=t.numberOfPages-1;n>=0?n>=a:a>=n;e=n>=0?++a:--a)i.push(e);return i}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.atList?t.atItemsPerPage*t.currentPage-t.atList.length:void 0},t.getFillerArray=function(){var e,a,n,i,r,o,l;if(t.currentPage===t.numberOfPages-1){if(a=t.atList.length%t.atItemsPerPage,0!==a||0===t.atList.length){for(e=t.atItemsPerPage-a-1,l=[],n=i=r=t.atList.length,o=t.atList.length+e;o>=r?o>=i:i>=o;n=o>=r?++i:--i)l.push(n);return l}return[]}},t.goToPage=function(a){return t.currentPage=e(a)},a(),t.$watch("atItemsPerPage",function(){return a()}),t.$watch("atList",function(){return a()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,a,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},a=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,a,n,i,r,o,l;for(a={},i=t.find("tr"),l=i.find("th"),r=0,o=l.length;o>r;r++)n=l[r],n=angular.element(n),e=a[n.attr("at-attribute")]={},e.content=n.html(),e.attributes=n[0].attributes;return a},collectBodyDefinition:function(i){var r,o,l,u,c,g,s,f,d,p;for(o={},o.tds=[],o.initialSorting=void 0,p=i.find("td"),f=0,d=p.length;d>f;f++)if(c=p[f],c=angular.element(c),r=c.attr("at-attribute"),g=c.attr("at-title")||t(c.attr("at-attribute")),u=void 0!==c.attr("at-sortable")||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:r,title:g,sortable:u,width:s}),l=a(c)){if(!r)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=l,o.initialSorting.predicate=r}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,a,n,i;return n="| orderBy:predicate:descending",a="| limitTo:fromPage() | limitTo:toPage()",i=function(t,e){var a,n;return a=t.find("tbody"),n=a.find("tr"),n.attr("ng-repeat",e),a},e=function(t){var e;e="item in "+t.atList+" "+n,this.compile=function(t){return i(t,e)},this.link=function(){}},t=function(t){var e,r,o;if(o=t.atSortContext||"global",e=t.pagination,"global"===o)r="item in "+e+".atList "+n+" "+a;else{if("page"!==o)throw"Invalid sort-context: "+o+".";r="item in "+e+".atList "+a+" "+n+" "}this.compile=function(t,a){var n,o,l,u,c,g,s;if(o=i(t,r),"undefined"!=typeof a.atFillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)l=c[g],u+=" ";return n=angular.element(""+u+"
"),n=n.find("tr"),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].atItemsPerPage:void 0}}},function(a){return a.atList?new e(a):a.pagination?new t(a):void 0}}])}).call(this); \ No newline at end of file +// homepage: http://github.com/samu/angular-table +(function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var a,n,i;return a=function(t,e){var a,n,i,r,o,l,u,c,g,s,f;for(l=angular.element(document.createElement("tr")),u=0,g=e.length;g>u;u++){if(i=e[u],r=angular.element(document.createElement("th")),r.attr("style","cursor: pointer;"),t[i.attribute]){for(f=t[i.attribute].attributes,c=0,s=f.length;s>c;c++)a=f[c],r.attr(""+a.name,""+a.value);o=t[i.attribute].content}else o=i.title;r.html(""+o),i.sortable&&(r.attr("ng-click","predicate = '"+i.attribute+"'; descending = !descending;"),n=angular.element(""),n.attr("ng-class","getSortIcon('"+i.attribute+"')"),r.append(n)),r.attr("width",i.width),l.append(r)}return l},i=function(t){if(t.pagination&&t.atList)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.atList)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(r,o,l){var u,c,g,s,f,d;return n(o),i(o),u=t.collectBodyDefinition(r),f=r.find("thead"),f[0]&&(c=t.collectCustomHeaderMarkup(r),d=angular.element(f).find("tr"),d.remove(),g=a(c,u.tds),angular.element(f[0]).append(g)),s=e(o),s.compile(r,o,l),{post:function(t,e,a){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},s.link(t,e,a)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{atItemsPerPage:"@",atInstance:"=",atList:"="},link:function(t){var e,a;return t.atInstance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},a=function(){var e;return t.currentPage=0,t.atList?t.atList.length>0?(t.numberOfPages=Math.ceil(t.atList.length/t.atItemsPerPage),t.pages=function(){var a,n,i;for(i=[],e=a=0,n=t.numberOfPages-1;n>=0?n>=a:a>=n;e=n>=0?++a:--a)i.push(e);return i}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.atList?t.atItemsPerPage*t.currentPage-t.atList.length:void 0},t.getFillerArray=function(){var e,a,n,i,r,o,l;if(t.currentPage===t.numberOfPages-1){if(a=t.atList.length%t.atItemsPerPage,0!==a||0===t.atList.length){for(e=t.atItemsPerPage-a-1,l=[],n=i=r=t.atList.length,o=t.atList.length+e;o>=r?o>=i:i>=o;n=o>=r?++i:--i)l.push(n);return l}return[]}},t.goToPage=function(a){return t.currentPage=e(a)},a(),t.$watch("atItemsPerPage",function(){return a()}),t.$watch("atList",function(){return a()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,a,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},a=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,a,n,i,r,o,l;for(a={},i=t.find("tr"),l=i.find("th"),r=0,o=l.length;o>r;r++)n=l[r],n=angular.element(n),e=a[n.attr("at-attribute")]={},e.content=n.html(),e.attributes=n[0].attributes;return a},collectBodyDefinition:function(i){var r,o,l,u,c,g,s,f,d,m;for(o={},o.tds=[],o.initialSorting=void 0,m=i.find("td"),f=0,d=m.length;d>f;f++)if(c=m[f],c=angular.element(c),r=c.attr("at-attribute"),g=c.attr("at-title")||t(c.attr("at-attribute")),u=void 0!==c.attr("at-sortable")||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:r,title:g,sortable:u,width:s}),l=a(c)){if(!r)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=l,o.initialSorting.predicate=r}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,a,n,i;return n="| orderBy:predicate:descending",a="| limitTo:fromPage() | limitTo:toPage()",i=function(t,e){var a,n;return a=t.find("tbody"),n=a.find("tr"),n.attr("ng-repeat",e),a},e=function(t){var e;e="item in "+t.atList+" "+n,this.compile=function(t){return i(t,e)},this.link=function(){}},t=function(t){var e,r,o;if(o=t.atSortContext||"global",e=t.pagination,"global"===o)r="item in "+e+".atList "+n+" "+a;else{if("page"!==o)throw"Invalid sort-context: "+o+".";r="item in "+e+".atList "+a+" "+n+" "}this.compile=function(t,a){var n,o,l,u,c,g,s;if(o=i(t,r),"undefined"!=typeof a.atFillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)l=c[g],u+=" ";return n=angular.element(document.createElement("tr")),n.html(u),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].atItemsPerPage:void 0}}},function(a){return a.atList?new e(a):a.pagination?new t(a):void 0}}])}).call(this); \ No newline at end of file diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 8be76f1..14b0797 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -1,7 +1,7 @@ // author: Samuel Mueller // version: 0.0.8 // license: MIT -// homepage: http://github.com/ssmm/angular-table +// homepage: http://github.com/samu/angular-table (function() { angular.module("angular-table", []); @@ -10,12 +10,11 @@ var constructHeader, normalizeInput, validateInput; constructHeader = function(customHeaderMarkup, bodyDefinitions) { var attribute, icon, td, th, title, tr, _i, _j, _len, _len1, _ref; - tr = angular.element("
"); - tr = tr.find("tr"); + tr = angular.element(document.createElement("tr")); for (_i = 0, _len = bodyDefinitions.length; _i < _len; _i++) { td = bodyDefinitions[_i]; - th = angular.element("
"); - th = th.find("th"); + th = angular.element(document.createElement("th")); + th.attr("style", "cursor: pointer;"); if (customHeaderMarkup[td.attribute]) { _ref = customHeaderMarkup[td.attribute].attributes; for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { @@ -316,8 +315,8 @@ td = tds[_i]; tdString += " "; } - fillerTr = angular.element("" + tdString + "
"); - fillerTr = fillerTr.find("tr"); + fillerTr = angular.element(document.createElement("tr")); + fillerTr.html(tdString); fillerTr.attr("ng-repeat", "item in " + paginationName + ".getFillerArray() "); return tbody.append(fillerTr); } From 8539a7a1cb753bdf77691e575e778015b3b65c5c Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 8 Feb 2014 19:25:31 +0100 Subject: [PATCH 043/190] removed normlizeInput function --- coffee/atTable.coffee | 15 ++++----------- coffee/setupFactory.coffee | 4 ++-- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index 742b9a8..d5620d8 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -29,23 +29,16 @@ angular.module("angular-table").directive "atTable", ["metaCollector", "setupFac tr - validateInput = (attributes) -> - if attributes.pagination and attributes.atList - throw "You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used." - if not attributes.pagination and not attributes.atList - throw "Either a list or pagination must be specified." - - normalizeInput = (attributes) -> - if attributes.atPagination - attributes.pagination = attributes.atPagination - attributes.atPagination = null + if attributes.atPagination and attributes.atList + throw "You can not specify a list if you have specified a Pagination. The list defined for the pagnination will automatically be used." + if not attributes.atPagination and not attributes.atList + throw "Either a list or Pagination must be specified." { restrict: "AC" scope: true compile: (element, attributes, transclude) -> - normalizeInput attributes validateInput attributes diff --git a/coffee/setupFactory.coffee b/coffee/setupFactory.coffee index b6574fd..96ecc5f 100644 --- a/coffee/setupFactory.coffee +++ b/coffee/setupFactory.coffee @@ -20,7 +20,7 @@ angular.module("angular-table").factory "setupFactory", [() -> PaginationSetup = (attributes) -> sortContext = attributes.atSortContext || "global" - paginationName = attributes.pagination + paginationName = attributes.atPagination if sortContext == "global" repeatString = "item in #{paginationName}.atList #{orderByExpression} #{limitToExpression}" @@ -56,7 +56,7 @@ angular.module("angular-table").factory "setupFactory", [() -> (attributes) -> if attributes.atList return new StandardSetup(attributes) - if attributes.pagination + if attributes.atPagination return new PaginationSetup(attributes) return From 3e2c1219a9e516c4b6cfff35cb09a81d066924e9 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 8 Feb 2014 19:29:53 +0100 Subject: [PATCH 044/190] removed commented code --- coffee/metaCollector.coffee | 5 ----- 1 file changed, 5 deletions(-) diff --git a/coffee/metaCollector.coffee b/coffee/metaCollector.coffee index ff3a436..8fb2f49 100644 --- a/coffee/metaCollector.coffee +++ b/coffee/metaCollector.coffee @@ -18,11 +18,6 @@ angular.module("angular-table").service "metaCollector", [() -> throw "Invalid value for initial-sorting: #{initialSorting}. Allowed values are 'asc' or 'desc'." return undefined - # collectAttributes = (attributes) -> - # result = [] - # for attribute in attributes - # result.push({name: attribute.name, value: attribute.value}) - { collectCustomHeaderMarkup: (thead) -> customHeaderMarkups = {} From dd9b6c093a646562bb9762757049304c73e4fcb3 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 9 Feb 2014 12:41:34 +0100 Subject: [PATCH 045/190] refactored metaCollector --- coffee/atTable.coffee | 48 +++++++---------- coffee/metaCollector.coffee | 98 ++++++++++++++++++++++++----------- test/metaCollectorTest.coffee | 13 +++-- 3 files changed, 95 insertions(+), 64 deletions(-) diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index d5620d8..437c80e 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -2,32 +2,13 @@ angular.module "angular-table", [] angular.module("angular-table").directive "atTable", ["metaCollector", "setupFactory", (metaCollector, setupFactory) -> - constructHeader = (customHeaderMarkup, bodyDefinitions) -> + constructHeader = (column_configurations) -> tr = angular.element(document.createElement("tr")) - for td in bodyDefinitions - th = angular.element(document.createElement("th")) - th.attr("style","cursor: pointer;") + for i in column_configurations + tr.append(i.html()) - if customHeaderMarkup[td.attribute] - for attribute in customHeaderMarkup[td.attribute].attributes - th.attr("#{attribute.name}", "#{attribute.value}") - title = customHeaderMarkup[td.attribute].content - else - title = td.title - - th.html("#{title}") - - if td.sortable - th.attr("ng-click", "predicate = '#{td.attribute}'; descending = !descending;") - icon = angular.element("") - icon.attr("ng-class", "getSortIcon('#{td.attribute}')") - th.append(icon) - - th.attr("width", td.width) - tr.append(th) - - tr + return tr validateInput = (attributes) -> if attributes.atPagination and attributes.atList @@ -41,15 +22,13 @@ angular.module("angular-table").directive "atTable", ["metaCollector", "setupFac compile: (element, attributes, transclude) -> validateInput attributes - - bodyDefinition = metaCollector.collectBodyDefinition(element) + column_configurations = metaCollector.collectColumnConfigurations(element) thead = element.find("thead") if thead[0] - customHeaderMarkup = metaCollector.collectCustomHeaderMarkup(element) + header = constructHeader(column_configurations) tr = angular.element(thead).find("tr") tr.remove() - header = constructHeader(customHeaderMarkup, bodyDefinition.tds) angular.element(thead[0]).append(header) setup = setupFactory attributes @@ -57,16 +36,25 @@ angular.module("angular-table").directive "atTable", ["metaCollector", "setupFac { post: ($scope, $element, $attributes) -> + initialSortingPredicate = undefined + initialSortingDirection = undefined + + for bd in column_configurations + if bd.initialSorting + throw "initial-sorting specified without attribute." if not bd.attribute + initialSortingPredicate = bd.attribute + initialSortingDirection = bd.initialSorting - if bodyDefinition.initialSorting - $scope.predicate = bodyDefinition.initialSorting.predicate - $scope.descending = (bodyDefinition.initialSorting.direction == "desc") + if initialSortingPredicate + $scope.predicate = initialSortingPredicate + $scope.descending = initialSortingDirection == "desc" $scope.getSortIcon = (predicate) -> return "icon-minus" if predicate != $scope.predicate if $scope.descending then "icon-chevron-down" else "icon-chevron-up" setup.link($scope, $element, $attributes) + } } ] \ No newline at end of file diff --git a/coffee/metaCollector.coffee b/coffee/metaCollector.coffee index 8fb2f49..9e6d937 100644 --- a/coffee/metaCollector.coffee +++ b/coffee/metaCollector.coffee @@ -1,3 +1,38 @@ +class ColumnConfiguration + constructor: (body_markup, header_markup) -> + @attribute = body_markup.attribute + @title = body_markup.title + @sortable = body_markup.sortable + @width = body_markup.width + @initialSorting = body_markup.initialSorting + + if header_markup + @content = header_markup.content + @attributes = header_markup.attributes + + html: () -> + th = angular.element(document.createElement("th")) + th.attr("style","cursor: pointer;") + + if @content + for attribute in @attributes + th.attr(attribute.name, attribute.value) + title = @content + else + title = @title + + th.html(title) + + if @sortable + th.attr("ng-click", "predicate = '#{@attribute}'; descending = !descending;") + icon = angular.element("") + icon.attr("ng-class", "getSortIcon('#{@attribute}')") + th.append(icon) + + th.attr("width", @width) + + return th + angular.module("angular-table").service "metaCollector", [() -> capitaliseFirstLetter = (string) -> @@ -11,50 +46,55 @@ angular.module("angular-table").service "metaCollector", [() -> sortable = /(sortable)/i.exec classes if sortable then true else false - getInitialSortDirection = (td) -> + getInitialSorting = (td) -> initialSorting = td.attr("at-initial-sorting") if initialSorting return initialSorting if initialSorting == "asc" || initialSorting == "desc" throw "Invalid value for initial-sorting: #{initialSorting}. Allowed values are 'asc' or 'desc'." return undefined - { - collectCustomHeaderMarkup: (thead) -> - customHeaderMarkups = {} + collect_header_markup = (table) -> + customHeaderMarkups = {} - tr = thead.find("tr") - for th in tr.find("th") - th = angular.element(th) - customHeaderMarkup = customHeaderMarkups[th.attr("at-attribute")] = {} - customHeaderMarkup.content = th.html() - customHeaderMarkup.attributes = th[0].attributes + tr = table.find("tr") + for th in tr.find("th") + th = angular.element(th) + customHeaderMarkups[th.attr("at-attribute")] = { + content: th.html(), attributes: th[0].attributes + } - customHeaderMarkups + return customHeaderMarkups - collectBodyDefinition: (tbody) -> - bodyDefinition = {} - bodyDefinition.tds = [] - bodyDefinition.initialSorting = undefined + collect_body_markup = (table) -> + bodyDefinition = [] - for td in tbody.find("td") - td = angular.element(td) + for td in table.find("td") + td = angular.element(td) - attribute = td.attr("at-attribute") - title = td.attr("at-title") || capitaliseFirstLetter(td.attr("at-attribute")) - sortable = td.attr("at-sortable") != undefined || isSortable(td.attr("class")) - width = extractWidth(td.attr("class")) + attribute = td.attr("at-attribute") + title = td.attr("at-title") || capitaliseFirstLetter(td.attr("at-attribute")) + sortable = td.attr("at-sortable") != undefined || isSortable(td.attr("class")) + width = extractWidth(td.attr("class")) + initialSorting = getInitialSorting td - bodyDefinition.tds.push {attribute: attribute, title: title, sortable: sortable, width: width} + bodyDefinition.push { + attribute: attribute, title: title, sortable: sortable, + width: width, initialSorting: initialSorting + } + + return bodyDefinition + + { - initialSortDirection = getInitialSortDirection td - if initialSortDirection - throw "initial-sorting specified without attribute." if not attribute - bodyDefinition.initialSorting = {} - bodyDefinition.initialSorting.direction = initialSortDirection - bodyDefinition.initialSorting.predicate = attribute + collectColumnConfigurations: (table) -> + header_markup = collect_header_markup(table) + body_markup = collect_body_markup(table) + column_configuration = [] - bodyDefinition + for i in body_markup + column_configuration.push new ColumnConfiguration(i, header_markup[i.attribute]) + return column_configuration } ] \ No newline at end of file diff --git a/test/metaCollectorTest.coffee b/test/metaCollectorTest.coffee index 7ec6072..42e2802 100644 --- a/test/metaCollectorTest.coffee +++ b/test/metaCollectorTest.coffee @@ -16,10 +16,13 @@ describe "angular-table", () -> " ) - headerMarkup = mc.collectCustomHeaderMarkup(header) + # TODO uncomment - one = headerMarkup["one"] - expect(one).toBeDefined() - expect(one["content"]).toEqual "hello world" - expect(one["attributes"]).toBeDefined() + # headerMarkup = mc.collectCustomHeaderMarkup(header) + + # one = headerMarkup["one"] + + # expect(one).toBeDefined() + # expect(one["content"]).toEqual "hello world" + # expect(one["attributes"]).toBeDefined() From a2031b84e27b718e0db67b1d1d52e16aa3d4eb9a Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 9 Feb 2014 14:54:04 +0100 Subject: [PATCH 046/190] refactored table generation code into more cohesive classes --- coffee/atTable.coffee | 51 +----------- coffee/column_configuration.coffee | 41 ++++++++++ coffee/declarative_table.coffee | 66 +++++++++++++++ coffee/metaCollector.coffee | 127 +++++++++++------------------ coffee/table.coffee | 43 ++++++++++ 5 files changed, 199 insertions(+), 129 deletions(-) create mode 100644 coffee/column_configuration.coffee create mode 100644 coffee/declarative_table.coffee create mode 100644 coffee/table.coffee diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index 437c80e..e67bcbb 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -1,60 +1,15 @@ angular.module "angular-table", [] angular.module("angular-table").directive "atTable", ["metaCollector", "setupFactory", (metaCollector, setupFactory) -> - - constructHeader = (column_configurations) -> - tr = angular.element(document.createElement("tr")) - - for i in column_configurations - tr.append(i.html()) - - return tr - - validateInput = (attributes) -> - if attributes.atPagination and attributes.atList - throw "You can not specify a list if you have specified a Pagination. The list defined for the pagnination will automatically be used." - if not attributes.atPagination and not attributes.atList - throw "Either a list or Pagination must be specified." - { restrict: "AC" scope: true compile: (element, attributes, transclude) -> - validateInput attributes - - column_configurations = metaCollector.collectColumnConfigurations(element) - - thead = element.find("thead") - if thead[0] - header = constructHeader(column_configurations) - tr = angular.element(thead).find("tr") - tr.remove() - angular.element(thead[0]).append(header) - - setup = setupFactory attributes - setup.compile(element, attributes, transclude) - + dt = new DeclarativeTable(element, attributes) + dt.compile(setupFactory) { post: ($scope, $element, $attributes) -> - initialSortingPredicate = undefined - initialSortingDirection = undefined - - for bd in column_configurations - if bd.initialSorting - throw "initial-sorting specified without attribute." if not bd.attribute - initialSortingPredicate = bd.attribute - initialSortingDirection = bd.initialSorting - - if initialSortingPredicate - $scope.predicate = initialSortingPredicate - $scope.descending = initialSortingDirection == "desc" - - $scope.getSortIcon = (predicate) -> - return "icon-minus" if predicate != $scope.predicate - if $scope.descending then "icon-chevron-down" else "icon-chevron-up" - - setup.link($scope, $element, $attributes) - + dt.post($scope, $element, $attributes) } } ] \ No newline at end of file diff --git a/coffee/column_configuration.coffee b/coffee/column_configuration.coffee new file mode 100644 index 0000000..25ed10c --- /dev/null +++ b/coffee/column_configuration.coffee @@ -0,0 +1,41 @@ +class ColumnConfiguration + constructor: (body_markup, header_markup) -> + @attribute = body_markup.attribute + @title = body_markup.title + @sortable = body_markup.sortable + @width = body_markup.width + @initialSorting = body_markup.initialSorting + + if header_markup + @custom_content = header_markup.custom_content + @attributes = header_markup.attributes + + create_element: () -> + th = angular.element(document.createElement("th")) + th.attr("style","cursor: pointer;") + + render_title: (element) -> + element.html(@custom_content || @title) + + render_attributes: (element) -> + if @custom_content + for attribute in @attributes + element.attr(attribute.name, attribute.value) + + render_sorting: (element) -> + if @sortable + element.attr("ng-click", "predicate = '#{@attribute}'; descending = !descending;") + icon = angular.element("") + icon.attr("ng-class", "getSortIcon('#{@attribute}')") + element.append(icon) + + render_width: (element) -> + element.attr("width", @width) + + render_html: () -> + th = @create_element() + @render_title(th) + @render_attributes(th) + @render_sorting(th) + @render_width(th) + return th diff --git a/coffee/declarative_table.coffee b/coffee/declarative_table.coffee new file mode 100644 index 0000000..e1a25dd --- /dev/null +++ b/coffee/declarative_table.coffee @@ -0,0 +1,66 @@ +class DeclarativeTable extends Table + + constructor: (@element, @attributes) -> + + capitaliseFirstLetter: (string) -> + if string then string.charAt(0).toUpperCase() + string.slice(1) else "" + + extractWidth: (classes) -> + width = /([0-9]+px)/i.exec classes + if width then width[0] else "" + + isSortable: (classes) -> + sortable = /(sortable)/i.exec classes + if sortable then true else false + + getInitialSorting: (td) -> + initialSorting = td.attr("at-initial-sorting") + if initialSorting + return initialSorting if initialSorting == "asc" || initialSorting == "desc" + throw "Invalid value for initial-sorting: #{initialSorting}. Allowed values are 'asc' or 'desc'." + return undefined + + collect_header_markup: (table) -> + customHeaderMarkups = {} + + tr = table.find("tr") + for th in tr.find("th") + th = angular.element(th) + customHeaderMarkups[th.attr("at-attribute")] = { + custom_content: th.html(), attributes: th[0].attributes + } + + return customHeaderMarkups + + collect_body_markup: (table) -> + bodyDefinition = [] + + for td in table.find("td") + td = angular.element(td) + + attribute = td.attr("at-attribute") + title = td.attr("at-title") || @capitaliseFirstLetter(td.attr("at-attribute")) + sortable = td.attr("at-sortable") != undefined || @isSortable(td.attr("class")) + width = @extractWidth(td.attr("class")) + initialSorting = @getInitialSorting(td) + + bodyDefinition.push { + attribute: attribute, title: title, sortable: sortable, + width: width, initialSorting: initialSorting + } + + return bodyDefinition + + create_column_configurations: () -> + header_markup = @collect_header_markup(@element) + body_markup = @collect_body_markup(@element) + + column_configurations = [] + + for i in body_markup + column_configurations.push new ColumnConfiguration(i, header_markup[i.attribute]) + + return column_configurations + + get_column_configurations: () -> + @column_configurations ||= @create_column_configurations() diff --git a/coffee/metaCollector.coffee b/coffee/metaCollector.coffee index 9e6d937..88ab51d 100644 --- a/coffee/metaCollector.coffee +++ b/coffee/metaCollector.coffee @@ -1,100 +1,65 @@ -class ColumnConfiguration - constructor: (body_markup, header_markup) -> - @attribute = body_markup.attribute - @title = body_markup.title - @sortable = body_markup.sortable - @width = body_markup.width - @initialSorting = body_markup.initialSorting - - if header_markup - @content = header_markup.content - @attributes = header_markup.attributes - - html: () -> - th = angular.element(document.createElement("th")) - th.attr("style","cursor: pointer;") - - if @content - for attribute in @attributes - th.attr(attribute.name, attribute.value) - title = @content - else - title = @title - - th.html(title) - - if @sortable - th.attr("ng-click", "predicate = '#{@attribute}'; descending = !descending;") - icon = angular.element("") - icon.attr("ng-class", "getSortIcon('#{@attribute}')") - th.append(icon) - - th.attr("width", @width) - - return th - angular.module("angular-table").service "metaCollector", [() -> - capitaliseFirstLetter = (string) -> - if string then string.charAt(0).toUpperCase() + string.slice(1) else "" + # capitaliseFirstLetter = (string) -> + # if string then string.charAt(0).toUpperCase() + string.slice(1) else "" - extractWidth = (classes) -> - width = /([0-9]+px)/i.exec classes - if width then width[0] else "" + # extractWidth = (classes) -> + # width = /([0-9]+px)/i.exec classes + # if width then width[0] else "" - isSortable = (classes) -> - sortable = /(sortable)/i.exec classes - if sortable then true else false + # isSortable = (classes) -> + # sortable = /(sortable)/i.exec classes + # if sortable then true else false - getInitialSorting = (td) -> - initialSorting = td.attr("at-initial-sorting") - if initialSorting - return initialSorting if initialSorting == "asc" || initialSorting == "desc" - throw "Invalid value for initial-sorting: #{initialSorting}. Allowed values are 'asc' or 'desc'." - return undefined + # getInitialSorting = (td) -> + # initialSorting = td.attr("at-initial-sorting") + # if initialSorting + # return initialSorting if initialSorting == "asc" || initialSorting == "desc" + # throw "Invalid value for initial-sorting: #{initialSorting}. Allowed values are 'asc' or 'desc'." + # return undefined - collect_header_markup = (table) -> - customHeaderMarkups = {} + # collect_header_markup = (table) -> + # customHeaderMarkups = {} - tr = table.find("tr") - for th in tr.find("th") - th = angular.element(th) - customHeaderMarkups[th.attr("at-attribute")] = { - content: th.html(), attributes: th[0].attributes - } + # tr = table.find("tr") + # for th in tr.find("th") + # th = angular.element(th) + # customHeaderMarkups[th.attr("at-attribute")] = { + # custom_content: th.html(), attributes: th[0].attributes + # } - return customHeaderMarkups + # return customHeaderMarkups - collect_body_markup = (table) -> - bodyDefinition = [] + # collect_body_markup = (table) -> + # bodyDefinition = [] - for td in table.find("td") - td = angular.element(td) + # for td in table.find("td") + # td = angular.element(td) - attribute = td.attr("at-attribute") - title = td.attr("at-title") || capitaliseFirstLetter(td.attr("at-attribute")) - sortable = td.attr("at-sortable") != undefined || isSortable(td.attr("class")) - width = extractWidth(td.attr("class")) - initialSorting = getInitialSorting td + # attribute = td.attr("at-attribute") + # title = td.attr("at-title") || capitaliseFirstLetter(td.attr("at-attribute")) + # sortable = td.attr("at-sortable") != undefined || isSortable(td.attr("class")) + # width = extractWidth(td.attr("class")) + # initialSorting = getInitialSorting td - bodyDefinition.push { - attribute: attribute, title: title, sortable: sortable, - width: width, initialSorting: initialSorting - } + # bodyDefinition.push { + # attribute: attribute, title: title, sortable: sortable, + # width: width, initialSorting: initialSorting + # } - return bodyDefinition + # return bodyDefinition - { + # { - collectColumnConfigurations: (table) -> - header_markup = collect_header_markup(table) - body_markup = collect_body_markup(table) + # collectColumnConfigurations: (table) -> + # header_markup = collect_header_markup(table) + # body_markup = collect_body_markup(table) - column_configuration = [] + # column_configuration = [] - for i in body_markup - column_configuration.push new ColumnConfiguration(i, header_markup[i.attribute]) + # for i in body_markup + # column_configuration.push new ColumnConfiguration(i, header_markup[i.attribute]) - return column_configuration - } + # return column_configuration + # } ] \ No newline at end of file diff --git a/coffee/table.coffee b/coffee/table.coffee new file mode 100644 index 0000000..eba475f --- /dev/null +++ b/coffee/table.coffee @@ -0,0 +1,43 @@ +class Table + + constructHeader: () -> + tr = angular.element(document.createElement("tr")) + for i in @get_column_configurations() + tr.append(i.render_html()) + return tr + + setup_header: () -> + thead = @element.find("thead") + if thead + header = @constructHeader() + tr = angular.element(thead).find("tr") + tr.remove() + thead.append(header) + + validateInput: () -> + if @attributes.atPagination and @attributes.atList + throw "You can not specify a list if you have specified a Pagination. The list defined for the pagnination will automatically be used." + if not @attributes.atPagination and not @attributes.atList + throw "Either a list or Pagination must be specified." + + compile: (setupFactory) -> + @validateInput() + @setup_header() + @setup = setupFactory(@attributes) + @setup.compile(@element, @attributes) + + setup_initial_sorting: ($scope) -> + for bd in @get_column_configurations() + if bd.initialSorting + throw "initial-sorting specified without attribute." if not bd.attribute + $scope.predicate = bd.attribute + $scope.descending = bd.initialSorting == "desc" + + post: ($scope, $element, $attributes) -> + @setup_initial_sorting($scope) + + $scope.getSortIcon = (predicate) -> + return "icon-minus" if predicate != $scope.predicate + if $scope.descending then "icon-chevron-down" else "icon-chevron-up" + + @setup.link($scope, $element, $attributes) From 507a8bb53ad8cd9eeef3a50d77304d87730246ad Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 9 Feb 2014 14:56:32 +0100 Subject: [PATCH 047/190] removed unused metaCollector --- coffee/atTable.coffee | 2 +- coffee/metaCollector.coffee | 65 ------------------------------------- 2 files changed, 1 insertion(+), 66 deletions(-) delete mode 100644 coffee/metaCollector.coffee diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index e67bcbb..9a4c8c5 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -1,6 +1,6 @@ angular.module "angular-table", [] -angular.module("angular-table").directive "atTable", ["metaCollector", "setupFactory", (metaCollector, setupFactory) -> +angular.module("angular-table").directive "atTable", ["setupFactory", (setupFactory) -> { restrict: "AC" scope: true diff --git a/coffee/metaCollector.coffee b/coffee/metaCollector.coffee deleted file mode 100644 index 88ab51d..0000000 --- a/coffee/metaCollector.coffee +++ /dev/null @@ -1,65 +0,0 @@ -angular.module("angular-table").service "metaCollector", [() -> - - # capitaliseFirstLetter = (string) -> - # if string then string.charAt(0).toUpperCase() + string.slice(1) else "" - - # extractWidth = (classes) -> - # width = /([0-9]+px)/i.exec classes - # if width then width[0] else "" - - # isSortable = (classes) -> - # sortable = /(sortable)/i.exec classes - # if sortable then true else false - - # getInitialSorting = (td) -> - # initialSorting = td.attr("at-initial-sorting") - # if initialSorting - # return initialSorting if initialSorting == "asc" || initialSorting == "desc" - # throw "Invalid value for initial-sorting: #{initialSorting}. Allowed values are 'asc' or 'desc'." - # return undefined - - # collect_header_markup = (table) -> - # customHeaderMarkups = {} - - # tr = table.find("tr") - # for th in tr.find("th") - # th = angular.element(th) - # customHeaderMarkups[th.attr("at-attribute")] = { - # custom_content: th.html(), attributes: th[0].attributes - # } - - # return customHeaderMarkups - - # collect_body_markup = (table) -> - # bodyDefinition = [] - - # for td in table.find("td") - # td = angular.element(td) - - # attribute = td.attr("at-attribute") - # title = td.attr("at-title") || capitaliseFirstLetter(td.attr("at-attribute")) - # sortable = td.attr("at-sortable") != undefined || isSortable(td.attr("class")) - # width = extractWidth(td.attr("class")) - # initialSorting = getInitialSorting td - - # bodyDefinition.push { - # attribute: attribute, title: title, sortable: sortable, - # width: width, initialSorting: initialSorting - # } - - # return bodyDefinition - - # { - - # collectColumnConfigurations: (table) -> - # header_markup = collect_header_markup(table) - # body_markup = collect_body_markup(table) - - # column_configuration = [] - - # for i in body_markup - # column_configuration.push new ColumnConfiguration(i, header_markup[i.attribute]) - - # return column_configuration - # } -] \ No newline at end of file From dbb95d3da2e162b71a1fe3f1666b101735cab5ce Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 9 Feb 2014 15:34:16 +0100 Subject: [PATCH 048/190] refactored setupFactory into more cohesive classes --- coffee/atTable.coffee | 4 +- coffee/pagination_table_setup.coffee | 40 ++++++++++++++++++ coffee/setupFactory.coffee | 63 ---------------------------- coffee/standard_table_setup.coffee | 8 ++++ coffee/table.coffee | 12 ++++-- coffee/table_setup.coffee | 18 ++++++++ 6 files changed, 77 insertions(+), 68 deletions(-) create mode 100644 coffee/pagination_table_setup.coffee delete mode 100644 coffee/setupFactory.coffee create mode 100644 coffee/standard_table_setup.coffee create mode 100644 coffee/table_setup.coffee diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index 9a4c8c5..b789f20 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -1,12 +1,12 @@ angular.module "angular-table", [] -angular.module("angular-table").directive "atTable", ["setupFactory", (setupFactory) -> +angular.module("angular-table").directive "atTable", [() -> { restrict: "AC" scope: true compile: (element, attributes, transclude) -> dt = new DeclarativeTable(element, attributes) - dt.compile(setupFactory) + dt.compile() { post: ($scope, $element, $attributes) -> dt.post($scope, $element, $attributes) diff --git a/coffee/pagination_table_setup.coffee b/coffee/pagination_table_setup.coffee new file mode 100644 index 0000000..bb2b688 --- /dev/null +++ b/coffee/pagination_table_setup.coffee @@ -0,0 +1,40 @@ +class PaginationTableSetup extends TableSetup + constructor: (attributes) -> + @sortContext = attributes.atSortContext || "global" + @paginationName = attributes.atPagination + @fillLastPage = attributes.atFillLastPage + + if @sortContext == "global" + @repeatString = "item in #{@paginationName}.atList #{@orderByExpression} #{@limitToExpression}" + else if @sortContext == "page" + @repeatString = "item in #{@paginationName}.atList #{@limitToExpression} #{@orderByExpression} " + else + throw "Invalid sort-context: #{@sortContext}." + + compile: (element, attributes, transclude) -> + tbody = @setupTr(element, @repeatString) + + if typeof @fillLastPage != "undefined" + tds = element.find("td") + tdString = "" + for td in tds + tdString += " " + + fillerTr = angular.element(document.createElement("tr")) + fillerTr.html(tdString) + fillerTr.attr("ng-repeat", "item in #{@paginationName}.getFillerArray() ") + + tbody.append(fillerTr) + + return + + link: ($scope, $element, $attributes) -> + paginationName = @paginationName + + $scope.fromPage = () -> + if $scope[paginationName] then $scope[paginationName].fromPage() + + $scope.toPage = () -> + if $scope[paginationName] then $scope[paginationName].atItemsPerPage + + return diff --git a/coffee/setupFactory.coffee b/coffee/setupFactory.coffee deleted file mode 100644 index 96ecc5f..0000000 --- a/coffee/setupFactory.coffee +++ /dev/null @@ -1,63 +0,0 @@ -angular.module("angular-table").factory "setupFactory", [() -> - - orderByExpression = "| orderBy:predicate:descending" - limitToExpression = "| limitTo:fromPage() | limitTo:toPage()" - - setupTr = (element, repeatString) -> - tbody = element.find "tbody" - tr = tbody.find "tr" - tr.attr("ng-repeat", repeatString) - tbody - - StandardSetup = (attributes) -> - repeatString = "item in #{attributes.atList} #{orderByExpression}" - @compile = (element, attributes, transclude) -> - setupTr element, repeatString - - @link = () -> - return - - PaginationSetup = (attributes) -> - sortContext = attributes.atSortContext || "global" - - paginationName = attributes.atPagination - - if sortContext == "global" - repeatString = "item in #{paginationName}.atList #{orderByExpression} #{limitToExpression}" - else if sortContext == "page" - repeatString = "item in #{paginationName}.atList #{limitToExpression} #{orderByExpression} " - else - throw "Invalid sort-context: #{sortContext}." - - @compile = (element, attributes, transclude) -> - tbody = setupTr element, repeatString - - if typeof attributes.atFillLastPage != "undefined" - tds = element.find("td") - tdString = "" - for td in tds - tdString += " " - - fillerTr = angular.element(document.createElement("tr")) - fillerTr.html(tdString) - fillerTr.attr("ng-repeat", "item in #{paginationName}.getFillerArray() ") - - tbody.append(fillerTr) - - @link = ($scope, $element, $attributes) -> - $scope.fromPage = () -> - if $scope[paginationName] then $scope[paginationName].fromPage() - - $scope.toPage = () -> - if $scope[paginationName] then $scope[paginationName].atItemsPerPage - - return - - (attributes) -> - if attributes.atList - return new StandardSetup(attributes) - if attributes.atPagination - return new PaginationSetup(attributes) - return - -] \ No newline at end of file diff --git a/coffee/standard_table_setup.coffee b/coffee/standard_table_setup.coffee new file mode 100644 index 0000000..91e359f --- /dev/null +++ b/coffee/standard_table_setup.coffee @@ -0,0 +1,8 @@ +class StandardTableSetup extends TableSetup + constructor: (attributes) -> + @repeatString = "item in #{attributes.atList} #{@orderByExpression}" + + compile: (element, attributes, transclude) -> + @setupTr(element, @repeatString) + + link: () -> diff --git a/coffee/table.coffee b/coffee/table.coffee index eba475f..14420ee 100644 --- a/coffee/table.coffee +++ b/coffee/table.coffee @@ -1,5 +1,4 @@ class Table - constructHeader: () -> tr = angular.element(document.createElement("tr")) for i in @get_column_configurations() @@ -20,10 +19,17 @@ class Table if not @attributes.atPagination and not @attributes.atList throw "Either a list or Pagination must be specified." - compile: (setupFactory) -> + create_table_setup: (attributes) -> + if attributes.atList + return new StandardTableSetup(attributes) + if attributes.atPagination + return new PaginationTableSetup(attributes) + return + + compile: () -> @validateInput() @setup_header() - @setup = setupFactory(@attributes) + @setup = @create_table_setup(@attributes) @setup.compile(@element, @attributes) setup_initial_sorting: ($scope) -> diff --git a/coffee/table_setup.coffee b/coffee/table_setup.coffee new file mode 100644 index 0000000..45fa450 --- /dev/null +++ b/coffee/table_setup.coffee @@ -0,0 +1,18 @@ +class TableSetup + orderByExpression: "| orderBy:predicate:descending" + limitToExpression: "| limitTo:fromPage() | limitTo:toPage()" + + constructor: () -> + + setupTr: (element, repeatString) -> + tbody = element.find "tbody" + tr = tbody.find "tr" + tr.attr("ng-repeat", repeatString) + tbody + + (attributes) -> + if attributes.atList + return new StandardSetup(attributes) + if attributes.atPagination + return new PaginationSetup(attributes) + return From 59b813a20ff4c43e4849d18cd658a0faebcdc874 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 9 Feb 2014 15:34:47 +0100 Subject: [PATCH 049/190] table_setup needs to be loaded before other classes --- karma.conf.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/karma.conf.js b/karma.conf.js index 7475da7..1ec1ce2 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -18,6 +18,8 @@ module.exports = function(config) { 'http://code.angularjs.org/1.2.11/angular-mocks.js', 'http://underscorejs.org/underscore-min.js', 'coffee/atTable.coffee', + 'coffee/table.coffee', + 'coffee/table_setup.coffee', 'coffee/*.coffee', 'test/test_helper.coffee', 'test/*.coffee', From 22c1481e39a32cbf3d73a68586064cb8ba738e68 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 9 Feb 2014 15:38:30 +0100 Subject: [PATCH 050/190] updated test --- test/metaCollectorTest.coffee | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/test/metaCollectorTest.coffee b/test/metaCollectorTest.coffee index 42e2802..529b749 100644 --- a/test/metaCollectorTest.coffee +++ b/test/metaCollectorTest.coffee @@ -1,28 +1,28 @@ -describe "angular-table", () -> - describe "MetaCollector", () -> +# describe "angular-table", () -> +# describe "MetaCollector", () -> - mc = null +# mc = null - beforeEach () -> - module("angular-table") - inject (metaCollector) -> - mc = metaCollector +# beforeEach () -> +# module("angular-table") +# inject (metaCollector) -> +# mc = metaCollector - it "bla", () -> +# it "bla", () -> - header = angular.element( - " - -
hello world
" - ) +# header = angular.element( +# " +# +#
hello world
" +# ) - # TODO uncomment +# # TODO uncomment - # headerMarkup = mc.collectCustomHeaderMarkup(header) +# # headerMarkup = mc.collectCustomHeaderMarkup(header) - # one = headerMarkup["one"] +# # one = headerMarkup["one"] - # expect(one).toBeDefined() - # expect(one["content"]).toEqual "hello world" - # expect(one["attributes"]).toBeDefined() +# # expect(one).toBeDefined() +# # expect(one["content"]).toEqual "hello world" +# # expect(one["attributes"]).toBeDefined() From 4f3a2f6dd2b5935833b3cc549ecda3312592fe8e Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 9 Feb 2014 15:42:22 +0100 Subject: [PATCH 051/190] compiled new version --- Rakefile | 7 +- angular-table.js | 569 ++++++++++++-------- angular-table.min.js | 2 +- gem/app/assets/javascripts/angular-table.js | 569 ++++++++++++-------- 4 files changed, 705 insertions(+), 442 deletions(-) diff --git a/Rakefile b/Rakefile index 1c2fc5f..6697b78 100644 --- a/Rakefile +++ b/Rakefile @@ -18,7 +18,12 @@ task :compile do end def collect_coffees src - files = ["atTable", "atImplicit", "atPagination", "metaCollector", "setupFactory"] + files = [ + "atTable", "atImplicit", "atPagination", + "table", "table_setup", + "column_configuration", "declarative_table", + "standard_table_setup", "pagination_table_setup" + ] script = "" files.each do |file| script << File.read("#{src}/#{file}.coffee") << "\n" diff --git a/angular-table.js b/angular-table.js index 14b0797..e9300b0 100644 --- a/angular-table.js +++ b/angular-table.js @@ -3,89 +3,24 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { + var ColumnConfiguration, DeclarativeTable, PaginationTableSetup, StandardTableSetup, Table, TableSetup, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + angular.module("angular-table", []); angular.module("angular-table").directive("atTable", [ - "metaCollector", "setupFactory", function(metaCollector, setupFactory) { - var constructHeader, normalizeInput, validateInput; - constructHeader = function(customHeaderMarkup, bodyDefinitions) { - var attribute, icon, td, th, title, tr, _i, _j, _len, _len1, _ref; - tr = angular.element(document.createElement("tr")); - for (_i = 0, _len = bodyDefinitions.length; _i < _len; _i++) { - td = bodyDefinitions[_i]; - th = angular.element(document.createElement("th")); - th.attr("style", "cursor: pointer;"); - if (customHeaderMarkup[td.attribute]) { - _ref = customHeaderMarkup[td.attribute].attributes; - for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { - attribute = _ref[_j]; - th.attr("" + attribute.name, "" + attribute.value); - } - title = customHeaderMarkup[td.attribute].content; - } else { - title = td.title; - } - th.html("" + title); - if (td.sortable) { - th.attr("ng-click", "predicate = '" + td.attribute + "'; descending = !descending;"); - icon = angular.element(""); - icon.attr("ng-class", "getSortIcon('" + td.attribute + "')"); - th.append(icon); - } - th.attr("width", td.width); - tr.append(th); - } - return tr; - }; - validateInput = function(attributes) { - if (attributes.pagination && attributes.atList) { - throw "You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used."; - } - if (!attributes.pagination && !attributes.atList) { - throw "Either a list or pagination must be specified."; - } - }; - normalizeInput = function(attributes) { - if (attributes.atPagination) { - attributes.pagination = attributes.atPagination; - return attributes.atPagination = null; - } - }; + function() { return { restrict: "AC", scope: true, compile: function(element, attributes, transclude) { - var bodyDefinition, customHeaderMarkup, header, setup, thead, tr; - normalizeInput(attributes); - validateInput(attributes); - bodyDefinition = metaCollector.collectBodyDefinition(element); - thead = element.find("thead"); - if (thead[0]) { - customHeaderMarkup = metaCollector.collectCustomHeaderMarkup(element); - tr = angular.element(thead).find("tr"); - tr.remove(); - header = constructHeader(customHeaderMarkup, bodyDefinition.tds); - angular.element(thead[0]).append(header); - } - setup = setupFactory(attributes); - setup.compile(element, attributes, transclude); + var dt; + dt = new DeclarativeTable(element, attributes); + dt.compile(); return { post: function($scope, $element, $attributes) { - if (bodyDefinition.initialSorting) { - $scope.predicate = bodyDefinition.initialSorting.predicate; - $scope.descending = bodyDefinition.initialSorting.direction === "desc"; - } - $scope.getSortIcon = function(predicate) { - if (predicate !== $scope.predicate) { - return "icon-minus"; - } - if ($scope.descending) { - return "icon-chevron-down"; - } else { - return "icon-chevron-up"; - } - }; - return setup.link($scope, $element, $attributes); + return dt.post($scope, $element, $attributes); } }; } @@ -185,164 +120,358 @@ } ]); - angular.module("angular-table").service("metaCollector", [ - function() { - var capitaliseFirstLetter, extractWidth, getInitialSortDirection, isSortable; - capitaliseFirstLetter = function(string) { - if (string) { - return string.charAt(0).toUpperCase() + string.slice(1); - } else { - return ""; + Table = (function() { + function Table() {} + + Table.prototype.constructHeader = function() { + var i, tr, _i, _len, _ref; + tr = angular.element(document.createElement("tr")); + _ref = this.get_column_configurations(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + i = _ref[_i]; + tr.append(i.render_html()); + } + return tr; + }; + + Table.prototype.setup_header = function() { + var header, thead, tr; + thead = this.element.find("thead"); + if (thead) { + header = this.constructHeader(); + tr = angular.element(thead).find("tr"); + tr.remove(); + return thead.append(header); + } + }; + + Table.prototype.validateInput = function() { + if (this.attributes.atPagination && this.attributes.atList) { + throw "You can not specify a list if you have specified a Pagination. The list defined for the pagnination will automatically be used."; + } + if (!this.attributes.atPagination && !this.attributes.atList) { + throw "Either a list or Pagination must be specified."; + } + }; + + Table.prototype.create_table_setup = function(attributes) { + if (attributes.atList) { + return new StandardTableSetup(attributes); + } + if (attributes.atPagination) { + return new PaginationTableSetup(attributes); + } + }; + + Table.prototype.compile = function() { + this.validateInput(); + this.setup_header(); + this.setup = this.create_table_setup(this.attributes); + return this.setup.compile(this.element, this.attributes); + }; + + Table.prototype.setup_initial_sorting = function($scope) { + var bd, _i, _len, _ref, _results; + _ref = this.get_column_configurations(); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + bd = _ref[_i]; + if (bd.initialSorting) { + if (!bd.attribute) { + throw "initial-sorting specified without attribute."; + } } - }; - extractWidth = function(classes) { - var width; - width = /([0-9]+px)/i.exec(classes); - if (width) { - return width[0]; - } else { - return ""; + $scope.predicate = bd.attribute; + _results.push($scope.descending = bd.initialSorting === "desc"); + } + return _results; + }; + + Table.prototype.post = function($scope, $element, $attributes) { + this.setup_initial_sorting($scope); + $scope.getSortIcon = function(predicate) { + if (predicate !== $scope.predicate) { + return "icon-minus"; } - }; - isSortable = function(classes) { - var sortable; - sortable = /(sortable)/i.exec(classes); - if (sortable) { - return true; + if ($scope.descending) { + return "icon-chevron-down"; } else { - return false; + return "icon-chevron-up"; } }; - getInitialSortDirection = function(td) { - var initialSorting; - initialSorting = td.attr("at-initial-sorting"); - if (initialSorting) { - if (initialSorting === "asc" || initialSorting === "desc") { - return initialSorting; - } - throw "Invalid value for initial-sorting: " + initialSorting + ". Allowed values are 'asc' or 'desc'."; - } - return void 0; - }; - return { - collectCustomHeaderMarkup: function(thead) { - var customHeaderMarkup, customHeaderMarkups, th, tr, _i, _len, _ref; - customHeaderMarkups = {}; - tr = thead.find("tr"); - _ref = tr.find("th"); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - th = _ref[_i]; - th = angular.element(th); - customHeaderMarkup = customHeaderMarkups[th.attr("at-attribute")] = {}; - customHeaderMarkup.content = th.html(); - customHeaderMarkup.attributes = th[0].attributes; - } - return customHeaderMarkups; - }, - collectBodyDefinition: function(tbody) { - var attribute, bodyDefinition, initialSortDirection, sortable, td, title, width, _i, _len, _ref; - bodyDefinition = {}; - bodyDefinition.tds = []; - bodyDefinition.initialSorting = void 0; - _ref = tbody.find("td"); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - td = _ref[_i]; - td = angular.element(td); - attribute = td.attr("at-attribute"); - title = td.attr("at-title") || capitaliseFirstLetter(td.attr("at-attribute")); - sortable = td.attr("at-sortable") !== void 0 || isSortable(td.attr("class")); - width = extractWidth(td.attr("class")); - bodyDefinition.tds.push({ - attribute: attribute, - title: title, - sortable: sortable, - width: width - }); - initialSortDirection = getInitialSortDirection(td); - if (initialSortDirection) { - if (!attribute) { - throw "initial-sorting specified without attribute."; - } - bodyDefinition.initialSorting = {}; - bodyDefinition.initialSorting.direction = initialSortDirection; - bodyDefinition.initialSorting.predicate = attribute; - } - } - return bodyDefinition; + return this.setup.link($scope, $element, $attributes); + }; + + return Table; + + })(); + + TableSetup = (function() { + TableSetup.prototype.orderByExpression = "| orderBy:predicate:descending"; + + TableSetup.prototype.limitToExpression = "| limitTo:fromPage() | limitTo:toPage()"; + + function TableSetup() {} + + TableSetup.prototype.setupTr = function(element, repeatString) { + var tbody, tr; + tbody = element.find("tbody"); + tr = tbody.find("tr"); + tr.attr("ng-repeat", repeatString); + return tbody; + }; + + (function(attributes) { + if (attributes.atList) { + return new StandardSetup(attributes); + } + if (attributes.atPagination) { + return new PaginationSetup(attributes); + } + }); + + return TableSetup; + + })(); + + ColumnConfiguration = (function() { + function ColumnConfiguration(body_markup, header_markup) { + this.attribute = body_markup.attribute; + this.title = body_markup.title; + this.sortable = body_markup.sortable; + this.width = body_markup.width; + this.initialSorting = body_markup.initialSorting; + if (header_markup) { + this.custom_content = header_markup.custom_content; + this.attributes = header_markup.attributes; + } + } + + ColumnConfiguration.prototype.create_element = function() { + var th; + th = angular.element(document.createElement("th")); + return th.attr("style", "cursor: pointer;"); + }; + + ColumnConfiguration.prototype.render_title = function(element) { + return element.html(this.custom_content || this.title); + }; + + ColumnConfiguration.prototype.render_attributes = function(element) { + var attribute, _i, _len, _ref, _results; + if (this.custom_content) { + _ref = this.attributes; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + attribute = _ref[_i]; + _results.push(element.attr(attribute.name, attribute.value)); } - }; + return _results; + } + }; + + ColumnConfiguration.prototype.render_sorting = function(element) { + var icon; + if (this.sortable) { + element.attr("ng-click", "predicate = '" + this.attribute + "'; descending = !descending;"); + icon = angular.element(""); + icon.attr("ng-class", "getSortIcon('" + this.attribute + "')"); + return element.append(icon); + } + }; + + ColumnConfiguration.prototype.render_width = function(element) { + return element.attr("width", this.width); + }; + + ColumnConfiguration.prototype.render_html = function() { + var th; + th = this.create_element(); + this.render_title(th); + this.render_attributes(th); + this.render_sorting(th); + this.render_width(th); + return th; + }; + + return ColumnConfiguration; + + })(); + + DeclarativeTable = (function(_super) { + __extends(DeclarativeTable, _super); + + function DeclarativeTable(element, attributes) { + this.element = element; + this.attributes = attributes; } - ]); - angular.module("angular-table").factory("setupFactory", [ - function() { - var PaginationSetup, StandardSetup, limitToExpression, orderByExpression, setupTr; - orderByExpression = "| orderBy:predicate:descending"; - limitToExpression = "| limitTo:fromPage() | limitTo:toPage()"; - setupTr = function(element, repeatString) { - var tbody, tr; - tbody = element.find("tbody"); - tr = tbody.find("tr"); - tr.attr("ng-repeat", repeatString); - return tbody; - }; - StandardSetup = function(attributes) { - var repeatString; - repeatString = "item in " + attributes.atList + " " + orderByExpression; - this.compile = function(element, attributes, transclude) { - return setupTr(element, repeatString); - }; - this.link = function() {}; - }; - PaginationSetup = function(attributes) { - var paginationName, repeatString, sortContext; - sortContext = attributes.atSortContext || "global"; - paginationName = attributes.pagination; - if (sortContext === "global") { - repeatString = "item in " + paginationName + ".atList " + orderByExpression + " " + limitToExpression; - } else if (sortContext === "page") { - repeatString = "item in " + paginationName + ".atList " + limitToExpression + " " + orderByExpression + " "; - } else { - throw "Invalid sort-context: " + sortContext + "."; + DeclarativeTable.prototype.capitaliseFirstLetter = function(string) { + if (string) { + return string.charAt(0).toUpperCase() + string.slice(1); + } else { + return ""; + } + }; + + DeclarativeTable.prototype.extractWidth = function(classes) { + var width; + width = /([0-9]+px)/i.exec(classes); + if (width) { + return width[0]; + } else { + return ""; + } + }; + + DeclarativeTable.prototype.isSortable = function(classes) { + var sortable; + sortable = /(sortable)/i.exec(classes); + if (sortable) { + return true; + } else { + return false; + } + }; + + DeclarativeTable.prototype.getInitialSorting = function(td) { + var initialSorting; + initialSorting = td.attr("at-initial-sorting"); + if (initialSorting) { + if (initialSorting === "asc" || initialSorting === "desc") { + return initialSorting; } - this.compile = function(element, attributes, transclude) { - var fillerTr, tbody, td, tdString, tds, _i, _len; - tbody = setupTr(element, repeatString); - if (typeof attributes.atFillLastPage !== "undefined") { - tds = element.find("td"); - tdString = ""; - for (_i = 0, _len = tds.length; _i < _len; _i++) { - td = tds[_i]; - tdString += " "; - } - fillerTr = angular.element(document.createElement("tr")); - fillerTr.html(tdString); - fillerTr.attr("ng-repeat", "item in " + paginationName + ".getFillerArray() "); - return tbody.append(fillerTr); - } - }; - this.link = function($scope, $element, $attributes) { - $scope.fromPage = function() { - if ($scope[paginationName]) { - return $scope[paginationName].fromPage(); - } - }; - return $scope.toPage = function() { - if ($scope[paginationName]) { - return $scope[paginationName].atItemsPerPage; - } - }; + throw "Invalid value for initial-sorting: " + initialSorting + ". Allowed values are 'asc' or 'desc'."; + } + return void 0; + }; + + DeclarativeTable.prototype.collect_header_markup = function(table) { + var customHeaderMarkups, th, tr, _i, _len, _ref; + customHeaderMarkups = {}; + tr = table.find("tr"); + _ref = tr.find("th"); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + th = _ref[_i]; + th = angular.element(th); + customHeaderMarkups[th.attr("at-attribute")] = { + custom_content: th.html(), + attributes: th[0].attributes }; - }; - return function(attributes) { - if (attributes.atList) { - return new StandardSetup(attributes); + } + return customHeaderMarkups; + }; + + DeclarativeTable.prototype.collect_body_markup = function(table) { + var attribute, bodyDefinition, initialSorting, sortable, td, title, width, _i, _len, _ref; + bodyDefinition = []; + _ref = table.find("td"); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + td = _ref[_i]; + td = angular.element(td); + attribute = td.attr("at-attribute"); + title = td.attr("at-title") || this.capitaliseFirstLetter(td.attr("at-attribute")); + sortable = td.attr("at-sortable") !== void 0 || this.isSortable(td.attr("class")); + width = this.extractWidth(td.attr("class")); + initialSorting = this.getInitialSorting(td); + bodyDefinition.push({ + attribute: attribute, + title: title, + sortable: sortable, + width: width, + initialSorting: initialSorting + }); + } + return bodyDefinition; + }; + + DeclarativeTable.prototype.create_column_configurations = function() { + var body_markup, column_configurations, header_markup, i, _i, _len; + header_markup = this.collect_header_markup(this.element); + body_markup = this.collect_body_markup(this.element); + column_configurations = []; + for (_i = 0, _len = body_markup.length; _i < _len; _i++) { + i = body_markup[_i]; + column_configurations.push(new ColumnConfiguration(i, header_markup[i.attribute])); + } + return column_configurations; + }; + + DeclarativeTable.prototype.get_column_configurations = function() { + return this.column_configurations || (this.column_configurations = this.create_column_configurations()); + }; + + return DeclarativeTable; + + })(Table); + + StandardTableSetup = (function(_super) { + __extends(StandardTableSetup, _super); + + function StandardTableSetup(attributes) { + this.repeatString = "item in " + attributes.atList + " " + this.orderByExpression; + } + + StandardTableSetup.prototype.compile = function(element, attributes, transclude) { + return this.setupTr(element, this.repeatString); + }; + + StandardTableSetup.prototype.link = function() {}; + + return StandardTableSetup; + + })(TableSetup); + + PaginationTableSetup = (function(_super) { + __extends(PaginationTableSetup, _super); + + function PaginationTableSetup(attributes) { + this.sortContext = attributes.atSortContext || "global"; + this.paginationName = attributes.atPagination; + this.fillLastPage = attributes.atFillLastPage; + if (this.sortContext === "global") { + this.repeatString = "item in " + this.paginationName + ".atList " + this.orderByExpression + " " + this.limitToExpression; + } else if (this.sortContext === "page") { + this.repeatString = "item in " + this.paginationName + ".atList " + this.limitToExpression + " " + this.orderByExpression + " "; + } else { + throw "Invalid sort-context: " + this.sortContext + "."; + } + } + + PaginationTableSetup.prototype.compile = function(element, attributes, transclude) { + var fillerTr, tbody, td, tdString, tds, _i, _len; + tbody = this.setupTr(element, this.repeatString); + if (typeof this.fillLastPage !== "undefined") { + tds = element.find("td"); + tdString = ""; + for (_i = 0, _len = tds.length; _i < _len; _i++) { + td = tds[_i]; + tdString += " "; + } + fillerTr = angular.element(document.createElement("tr")); + fillerTr.html(tdString); + fillerTr.attr("ng-repeat", "item in " + this.paginationName + ".getFillerArray() "); + tbody.append(fillerTr); + } + }; + + PaginationTableSetup.prototype.link = function($scope, $element, $attributes) { + var paginationName; + paginationName = this.paginationName; + $scope.fromPage = function() { + if ($scope[paginationName]) { + return $scope[paginationName].fromPage(); } - if (attributes.pagination) { - return new PaginationSetup(attributes); + }; + $scope.toPage = function() { + if ($scope[paginationName]) { + return $scope[paginationName].atItemsPerPage; } }; - } - ]); + }; + + return PaginationTableSetup; + + })(TableSetup); }).call(this); diff --git a/angular-table.min.js b/angular-table.min.js index f691a6f..87d8fc3 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",["metaCollector","setupFactory",function(t,e){var a,n,i;return a=function(t,e){var a,n,i,r,o,l,u,c,g,s,f;for(l=angular.element(document.createElement("tr")),u=0,g=e.length;g>u;u++){if(i=e[u],r=angular.element(document.createElement("th")),r.attr("style","cursor: pointer;"),t[i.attribute]){for(f=t[i.attribute].attributes,c=0,s=f.length;s>c;c++)a=f[c],r.attr(""+a.name,""+a.value);o=t[i.attribute].content}else o=i.title;r.html(""+o),i.sortable&&(r.attr("ng-click","predicate = '"+i.attribute+"'; descending = !descending;"),n=angular.element(""),n.attr("ng-class","getSortIcon('"+i.attribute+"')"),r.append(n)),r.attr("width",i.width),l.append(r)}return l},i=function(t){if(t.pagination&&t.atList)throw"You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used.";if(!t.pagination&&!t.atList)throw"Either a list or pagination must be specified."},n=function(t){return t.atPagination?(t.pagination=t.atPagination,t.atPagination=null):void 0},{restrict:"AC",scope:!0,compile:function(r,o,l){var u,c,g,s,f,d;return n(o),i(o),u=t.collectBodyDefinition(r),f=r.find("thead"),f[0]&&(c=t.collectCustomHeaderMarkup(r),d=angular.element(f).find("tr"),d.remove(),g=a(c,u.tds),angular.element(f[0]).append(g)),s=e(o),s.compile(r,o,l),{post:function(t,e,a){return u.initialSorting&&(t.predicate=u.initialSorting.predicate,t.descending="desc"===u.initialSorting.direction),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},s.link(t,e,a)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{atItemsPerPage:"@",atInstance:"=",atList:"="},link:function(t){var e,a;return t.atInstance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},a=function(){var e;return t.currentPage=0,t.atList?t.atList.length>0?(t.numberOfPages=Math.ceil(t.atList.length/t.atItemsPerPage),t.pages=function(){var a,n,i;for(i=[],e=a=0,n=t.numberOfPages-1;n>=0?n>=a:a>=n;e=n>=0?++a:--a)i.push(e);return i}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.atList?t.atItemsPerPage*t.currentPage-t.atList.length:void 0},t.getFillerArray=function(){var e,a,n,i,r,o,l;if(t.currentPage===t.numberOfPages-1){if(a=t.atList.length%t.atItemsPerPage,0!==a||0===t.atList.length){for(e=t.atItemsPerPage-a-1,l=[],n=i=r=t.atList.length,o=t.atList.length+e;o>=r?o>=i:i>=o;n=o>=r?++i:--i)l.push(n);return l}return[]}},t.goToPage=function(a){return t.currentPage=e(a)},a(),t.$watch("atItemsPerPage",function(){return a()}),t.$watch("atList",function(){return a()})}}}]),angular.module("angular-table").service("metaCollector",[function(){var t,e,a,n;return t=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},n=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},a=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},{collectCustomHeaderMarkup:function(t){var e,a,n,i,r,o,l;for(a={},i=t.find("tr"),l=i.find("th"),r=0,o=l.length;o>r;r++)n=l[r],n=angular.element(n),e=a[n.attr("at-attribute")]={},e.content=n.html(),e.attributes=n[0].attributes;return a},collectBodyDefinition:function(i){var r,o,l,u,c,g,s,f,d,m;for(o={},o.tds=[],o.initialSorting=void 0,m=i.find("td"),f=0,d=m.length;d>f;f++)if(c=m[f],c=angular.element(c),r=c.attr("at-attribute"),g=c.attr("at-title")||t(c.attr("at-attribute")),u=void 0!==c.attr("at-sortable")||n(c.attr("class")),s=e(c.attr("class")),o.tds.push({attribute:r,title:g,sortable:u,width:s}),l=a(c)){if(!r)throw"initial-sorting specified without attribute.";o.initialSorting={},o.initialSorting.direction=l,o.initialSorting.predicate=r}return o}}}]),angular.module("angular-table").factory("setupFactory",[function(){var t,e,a,n,i;return n="| orderBy:predicate:descending",a="| limitTo:fromPage() | limitTo:toPage()",i=function(t,e){var a,n;return a=t.find("tbody"),n=a.find("tr"),n.attr("ng-repeat",e),a},e=function(t){var e;e="item in "+t.atList+" "+n,this.compile=function(t){return i(t,e)},this.link=function(){}},t=function(t){var e,r,o;if(o=t.atSortContext||"global",e=t.pagination,"global"===o)r="item in "+e+".atList "+n+" "+a;else{if("page"!==o)throw"Invalid sort-context: "+o+".";r="item in "+e+".atList "+a+" "+n+" "}this.compile=function(t,a){var n,o,l,u,c,g,s;if(o=i(t,r),"undefined"!=typeof a.atFillLastPage){for(c=t.find("td"),u="",g=0,s=c.length;s>g;g++)l=c[g],u+=" ";return n=angular.element(document.createElement("tr")),n.html(u),n.attr("ng-repeat","item in "+e+".getFillerArray() "),o.append(n)}},this.link=function(t){return t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].atItemsPerPage:void 0}}},function(a){return a.atList?new e(a):a.pagination?new t(a):void 0}}])}).call(this); \ No newline at end of file +(function(){var t,e,i,r,n,a,o={}.hasOwnProperty,s=function(t,e){function i(){this.constructor=t}for(var r in e)o.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",[function(){return{restrict:"AC",scope:!0,compile:function(t,i){var r;return r=new e(t,i),r.compile(),{post:function(t,e,i){return r.post(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{atItemsPerPage:"@",atInstance:"=",atList:"="},link:function(t){var e,i;return t.atInstance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},i=function(){var e;return t.currentPage=0,t.atList?t.atList.length>0?(t.numberOfPages=Math.ceil(t.atList.length/t.atItemsPerPage),t.pages=function(){var i,r,n;for(n=[],e=i=0,r=t.numberOfPages-1;r>=0?r>=i:i>=r;e=r>=0?++i:--i)n.push(e);return n}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.atList?t.atItemsPerPage*t.currentPage-t.atList.length:void 0},t.getFillerArray=function(){var e,i,r,n,a,o,s;if(t.currentPage===t.numberOfPages-1){if(i=t.atList.length%t.atItemsPerPage,0!==i||0===t.atList.length){for(e=t.atItemsPerPage-i-1,s=[],r=n=a=t.atList.length,o=t.atList.length+e;o>=a?o>=n:n>=o;r=o>=a?++n:--n)s.push(r);return s}return[]}},t.goToPage=function(i){return t.currentPage=e(i)},i(),t.$watch("atItemsPerPage",function(){return i()}),t.$watch("atList",function(){return i()})}}}]),n=function(){function t(){}return t.prototype.constructHeader=function(){var t,e,i,r,n;for(e=angular.element(document.createElement("tr")),n=this.get_column_configurations(),i=0,r=n.length;r>i;i++)t=n[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.validateInput=function(){if(this.attributes.atPagination&&this.attributes.atList)throw"You can not specify a list if you have specified a Pagination. The list defined for the pagnination will automatically be used.";if(!this.attributes.atPagination&&!this.attributes.atList)throw"Either a list or Pagination must be specified."},t.prototype.create_table_setup=function(t){return t.atList?new r(t):t.atPagination?new i(t):void 0},t.prototype.compile=function(){return this.validateInput(),this.setup_header(),this.setup=this.create_table_setup(this.attributes),this.setup.compile(this.element,this.attributes)},t.prototype.setup_initial_sorting=function(t){var e,i,r,n,a;for(n=this.get_column_configurations(),a=[],i=0,r=n.length;r>i;i++){if(e=n[i],e.initialSorting&&!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}return a},t.prototype.post=function(t,e,i){return this.setup_initial_sorting(t),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},this.setup.link(t,e,i)},t}(),a=function(){function t(){}return t.prototype.orderByExpression="| orderBy:predicate:descending",t.prototype.limitToExpression="| limitTo:fromPage() | limitTo:toPage()",t.prototype.setupTr=function(t,e){var i,r;return i=t.find("tbody"),r=i.find("tr"),r.attr("ng-repeat",e),i},t}(),t=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,r,n,a;if(this.custom_content){for(n=this.attributes,a=[],i=0,r=n.length;r>i;i++)e=n[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"')"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),e=function(e){function i(t,e){this.element=t,this.attributes=e}return s(i,e),i.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},i.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},i.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},i.prototype.collect_header_markup=function(t){var e,i,r,n,a,o;for(e={},r=t.find("tr"),o=r.find("th"),n=0,a=o.length;a>n;n++)i=o[n],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},i.prototype.collect_body_markup=function(t){var e,i,r,n,a,o,s,u,c,l;for(i=[],l=t.find("td"),u=0,c=l.length;c>u;u++)a=l[u],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),n=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),r=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:n,width:s,initialSorting:r});return i},i.prototype.create_column_configurations=function(){var e,i,r,n,a,o;for(r=this.collect_header_markup(this.element),e=this.collect_body_markup(this.element),i=[],a=0,o=e.length;o>a;a++)n=e[a],i.push(new t(n,r[n.attribute]));return i},i.prototype.get_column_configurations=function(){return this.column_configurations||(this.column_configurations=this.create_column_configurations())},i}(n),r=function(t){function e(t){this.repeatString="item in "+t.atList+" "+this.orderByExpression}return s(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(a),i=function(t){function e(t){if(this.sortContext=t.atSortContext||"global",this.paginationName=t.atPagination,this.fillLastPage=t.atFillLastPage,"global"===this.sortContext)this.repeatString="item in "+this.paginationName+".atList "+this.orderByExpression+" "+this.limitToExpression;else{if("page"!==this.sortContext)throw"Invalid sort-context: "+this.sortContext+".";this.repeatString="item in "+this.paginationName+".atList "+this.limitToExpression+" "+this.orderByExpression+" "}}return s(e,t),e.prototype.compile=function(t){var e,i,r,n,a,o,s;if(i=this.setupTr(t,this.repeatString),"undefined"!=typeof this.fillLastPage){for(a=t.find("td"),n="",o=0,s=a.length;s>o;o++)r=a[o],n+=" ";e=angular.element(document.createElement("tr")),e.html(n),e.attr("ng-repeat","item in "+this.paginationName+".getFillerArray() "),i.append(e)}},e.prototype.link=function(t){var e;e=this.paginationName,t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].atItemsPerPage:void 0}},e}(a)}).call(this); \ No newline at end of file diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 14b0797..e9300b0 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -3,89 +3,24 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { + var ColumnConfiguration, DeclarativeTable, PaginationTableSetup, StandardTableSetup, Table, TableSetup, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + angular.module("angular-table", []); angular.module("angular-table").directive("atTable", [ - "metaCollector", "setupFactory", function(metaCollector, setupFactory) { - var constructHeader, normalizeInput, validateInput; - constructHeader = function(customHeaderMarkup, bodyDefinitions) { - var attribute, icon, td, th, title, tr, _i, _j, _len, _len1, _ref; - tr = angular.element(document.createElement("tr")); - for (_i = 0, _len = bodyDefinitions.length; _i < _len; _i++) { - td = bodyDefinitions[_i]; - th = angular.element(document.createElement("th")); - th.attr("style", "cursor: pointer;"); - if (customHeaderMarkup[td.attribute]) { - _ref = customHeaderMarkup[td.attribute].attributes; - for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { - attribute = _ref[_j]; - th.attr("" + attribute.name, "" + attribute.value); - } - title = customHeaderMarkup[td.attribute].content; - } else { - title = td.title; - } - th.html("" + title); - if (td.sortable) { - th.attr("ng-click", "predicate = '" + td.attribute + "'; descending = !descending;"); - icon = angular.element(""); - icon.attr("ng-class", "getSortIcon('" + td.attribute + "')"); - th.append(icon); - } - th.attr("width", td.width); - tr.append(th); - } - return tr; - }; - validateInput = function(attributes) { - if (attributes.pagination && attributes.atList) { - throw "You can not specify a list if you have specified a pagination. The list defined for the pagnination will automatically be used."; - } - if (!attributes.pagination && !attributes.atList) { - throw "Either a list or pagination must be specified."; - } - }; - normalizeInput = function(attributes) { - if (attributes.atPagination) { - attributes.pagination = attributes.atPagination; - return attributes.atPagination = null; - } - }; + function() { return { restrict: "AC", scope: true, compile: function(element, attributes, transclude) { - var bodyDefinition, customHeaderMarkup, header, setup, thead, tr; - normalizeInput(attributes); - validateInput(attributes); - bodyDefinition = metaCollector.collectBodyDefinition(element); - thead = element.find("thead"); - if (thead[0]) { - customHeaderMarkup = metaCollector.collectCustomHeaderMarkup(element); - tr = angular.element(thead).find("tr"); - tr.remove(); - header = constructHeader(customHeaderMarkup, bodyDefinition.tds); - angular.element(thead[0]).append(header); - } - setup = setupFactory(attributes); - setup.compile(element, attributes, transclude); + var dt; + dt = new DeclarativeTable(element, attributes); + dt.compile(); return { post: function($scope, $element, $attributes) { - if (bodyDefinition.initialSorting) { - $scope.predicate = bodyDefinition.initialSorting.predicate; - $scope.descending = bodyDefinition.initialSorting.direction === "desc"; - } - $scope.getSortIcon = function(predicate) { - if (predicate !== $scope.predicate) { - return "icon-minus"; - } - if ($scope.descending) { - return "icon-chevron-down"; - } else { - return "icon-chevron-up"; - } - }; - return setup.link($scope, $element, $attributes); + return dt.post($scope, $element, $attributes); } }; } @@ -185,164 +120,358 @@ } ]); - angular.module("angular-table").service("metaCollector", [ - function() { - var capitaliseFirstLetter, extractWidth, getInitialSortDirection, isSortable; - capitaliseFirstLetter = function(string) { - if (string) { - return string.charAt(0).toUpperCase() + string.slice(1); - } else { - return ""; + Table = (function() { + function Table() {} + + Table.prototype.constructHeader = function() { + var i, tr, _i, _len, _ref; + tr = angular.element(document.createElement("tr")); + _ref = this.get_column_configurations(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + i = _ref[_i]; + tr.append(i.render_html()); + } + return tr; + }; + + Table.prototype.setup_header = function() { + var header, thead, tr; + thead = this.element.find("thead"); + if (thead) { + header = this.constructHeader(); + tr = angular.element(thead).find("tr"); + tr.remove(); + return thead.append(header); + } + }; + + Table.prototype.validateInput = function() { + if (this.attributes.atPagination && this.attributes.atList) { + throw "You can not specify a list if you have specified a Pagination. The list defined for the pagnination will automatically be used."; + } + if (!this.attributes.atPagination && !this.attributes.atList) { + throw "Either a list or Pagination must be specified."; + } + }; + + Table.prototype.create_table_setup = function(attributes) { + if (attributes.atList) { + return new StandardTableSetup(attributes); + } + if (attributes.atPagination) { + return new PaginationTableSetup(attributes); + } + }; + + Table.prototype.compile = function() { + this.validateInput(); + this.setup_header(); + this.setup = this.create_table_setup(this.attributes); + return this.setup.compile(this.element, this.attributes); + }; + + Table.prototype.setup_initial_sorting = function($scope) { + var bd, _i, _len, _ref, _results; + _ref = this.get_column_configurations(); + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + bd = _ref[_i]; + if (bd.initialSorting) { + if (!bd.attribute) { + throw "initial-sorting specified without attribute."; + } } - }; - extractWidth = function(classes) { - var width; - width = /([0-9]+px)/i.exec(classes); - if (width) { - return width[0]; - } else { - return ""; + $scope.predicate = bd.attribute; + _results.push($scope.descending = bd.initialSorting === "desc"); + } + return _results; + }; + + Table.prototype.post = function($scope, $element, $attributes) { + this.setup_initial_sorting($scope); + $scope.getSortIcon = function(predicate) { + if (predicate !== $scope.predicate) { + return "icon-minus"; } - }; - isSortable = function(classes) { - var sortable; - sortable = /(sortable)/i.exec(classes); - if (sortable) { - return true; + if ($scope.descending) { + return "icon-chevron-down"; } else { - return false; + return "icon-chevron-up"; } }; - getInitialSortDirection = function(td) { - var initialSorting; - initialSorting = td.attr("at-initial-sorting"); - if (initialSorting) { - if (initialSorting === "asc" || initialSorting === "desc") { - return initialSorting; - } - throw "Invalid value for initial-sorting: " + initialSorting + ". Allowed values are 'asc' or 'desc'."; - } - return void 0; - }; - return { - collectCustomHeaderMarkup: function(thead) { - var customHeaderMarkup, customHeaderMarkups, th, tr, _i, _len, _ref; - customHeaderMarkups = {}; - tr = thead.find("tr"); - _ref = tr.find("th"); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - th = _ref[_i]; - th = angular.element(th); - customHeaderMarkup = customHeaderMarkups[th.attr("at-attribute")] = {}; - customHeaderMarkup.content = th.html(); - customHeaderMarkup.attributes = th[0].attributes; - } - return customHeaderMarkups; - }, - collectBodyDefinition: function(tbody) { - var attribute, bodyDefinition, initialSortDirection, sortable, td, title, width, _i, _len, _ref; - bodyDefinition = {}; - bodyDefinition.tds = []; - bodyDefinition.initialSorting = void 0; - _ref = tbody.find("td"); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - td = _ref[_i]; - td = angular.element(td); - attribute = td.attr("at-attribute"); - title = td.attr("at-title") || capitaliseFirstLetter(td.attr("at-attribute")); - sortable = td.attr("at-sortable") !== void 0 || isSortable(td.attr("class")); - width = extractWidth(td.attr("class")); - bodyDefinition.tds.push({ - attribute: attribute, - title: title, - sortable: sortable, - width: width - }); - initialSortDirection = getInitialSortDirection(td); - if (initialSortDirection) { - if (!attribute) { - throw "initial-sorting specified without attribute."; - } - bodyDefinition.initialSorting = {}; - bodyDefinition.initialSorting.direction = initialSortDirection; - bodyDefinition.initialSorting.predicate = attribute; - } - } - return bodyDefinition; + return this.setup.link($scope, $element, $attributes); + }; + + return Table; + + })(); + + TableSetup = (function() { + TableSetup.prototype.orderByExpression = "| orderBy:predicate:descending"; + + TableSetup.prototype.limitToExpression = "| limitTo:fromPage() | limitTo:toPage()"; + + function TableSetup() {} + + TableSetup.prototype.setupTr = function(element, repeatString) { + var tbody, tr; + tbody = element.find("tbody"); + tr = tbody.find("tr"); + tr.attr("ng-repeat", repeatString); + return tbody; + }; + + (function(attributes) { + if (attributes.atList) { + return new StandardSetup(attributes); + } + if (attributes.atPagination) { + return new PaginationSetup(attributes); + } + }); + + return TableSetup; + + })(); + + ColumnConfiguration = (function() { + function ColumnConfiguration(body_markup, header_markup) { + this.attribute = body_markup.attribute; + this.title = body_markup.title; + this.sortable = body_markup.sortable; + this.width = body_markup.width; + this.initialSorting = body_markup.initialSorting; + if (header_markup) { + this.custom_content = header_markup.custom_content; + this.attributes = header_markup.attributes; + } + } + + ColumnConfiguration.prototype.create_element = function() { + var th; + th = angular.element(document.createElement("th")); + return th.attr("style", "cursor: pointer;"); + }; + + ColumnConfiguration.prototype.render_title = function(element) { + return element.html(this.custom_content || this.title); + }; + + ColumnConfiguration.prototype.render_attributes = function(element) { + var attribute, _i, _len, _ref, _results; + if (this.custom_content) { + _ref = this.attributes; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + attribute = _ref[_i]; + _results.push(element.attr(attribute.name, attribute.value)); } - }; + return _results; + } + }; + + ColumnConfiguration.prototype.render_sorting = function(element) { + var icon; + if (this.sortable) { + element.attr("ng-click", "predicate = '" + this.attribute + "'; descending = !descending;"); + icon = angular.element(""); + icon.attr("ng-class", "getSortIcon('" + this.attribute + "')"); + return element.append(icon); + } + }; + + ColumnConfiguration.prototype.render_width = function(element) { + return element.attr("width", this.width); + }; + + ColumnConfiguration.prototype.render_html = function() { + var th; + th = this.create_element(); + this.render_title(th); + this.render_attributes(th); + this.render_sorting(th); + this.render_width(th); + return th; + }; + + return ColumnConfiguration; + + })(); + + DeclarativeTable = (function(_super) { + __extends(DeclarativeTable, _super); + + function DeclarativeTable(element, attributes) { + this.element = element; + this.attributes = attributes; } - ]); - angular.module("angular-table").factory("setupFactory", [ - function() { - var PaginationSetup, StandardSetup, limitToExpression, orderByExpression, setupTr; - orderByExpression = "| orderBy:predicate:descending"; - limitToExpression = "| limitTo:fromPage() | limitTo:toPage()"; - setupTr = function(element, repeatString) { - var tbody, tr; - tbody = element.find("tbody"); - tr = tbody.find("tr"); - tr.attr("ng-repeat", repeatString); - return tbody; - }; - StandardSetup = function(attributes) { - var repeatString; - repeatString = "item in " + attributes.atList + " " + orderByExpression; - this.compile = function(element, attributes, transclude) { - return setupTr(element, repeatString); - }; - this.link = function() {}; - }; - PaginationSetup = function(attributes) { - var paginationName, repeatString, sortContext; - sortContext = attributes.atSortContext || "global"; - paginationName = attributes.pagination; - if (sortContext === "global") { - repeatString = "item in " + paginationName + ".atList " + orderByExpression + " " + limitToExpression; - } else if (sortContext === "page") { - repeatString = "item in " + paginationName + ".atList " + limitToExpression + " " + orderByExpression + " "; - } else { - throw "Invalid sort-context: " + sortContext + "."; + DeclarativeTable.prototype.capitaliseFirstLetter = function(string) { + if (string) { + return string.charAt(0).toUpperCase() + string.slice(1); + } else { + return ""; + } + }; + + DeclarativeTable.prototype.extractWidth = function(classes) { + var width; + width = /([0-9]+px)/i.exec(classes); + if (width) { + return width[0]; + } else { + return ""; + } + }; + + DeclarativeTable.prototype.isSortable = function(classes) { + var sortable; + sortable = /(sortable)/i.exec(classes); + if (sortable) { + return true; + } else { + return false; + } + }; + + DeclarativeTable.prototype.getInitialSorting = function(td) { + var initialSorting; + initialSorting = td.attr("at-initial-sorting"); + if (initialSorting) { + if (initialSorting === "asc" || initialSorting === "desc") { + return initialSorting; } - this.compile = function(element, attributes, transclude) { - var fillerTr, tbody, td, tdString, tds, _i, _len; - tbody = setupTr(element, repeatString); - if (typeof attributes.atFillLastPage !== "undefined") { - tds = element.find("td"); - tdString = ""; - for (_i = 0, _len = tds.length; _i < _len; _i++) { - td = tds[_i]; - tdString += " "; - } - fillerTr = angular.element(document.createElement("tr")); - fillerTr.html(tdString); - fillerTr.attr("ng-repeat", "item in " + paginationName + ".getFillerArray() "); - return tbody.append(fillerTr); - } - }; - this.link = function($scope, $element, $attributes) { - $scope.fromPage = function() { - if ($scope[paginationName]) { - return $scope[paginationName].fromPage(); - } - }; - return $scope.toPage = function() { - if ($scope[paginationName]) { - return $scope[paginationName].atItemsPerPage; - } - }; + throw "Invalid value for initial-sorting: " + initialSorting + ". Allowed values are 'asc' or 'desc'."; + } + return void 0; + }; + + DeclarativeTable.prototype.collect_header_markup = function(table) { + var customHeaderMarkups, th, tr, _i, _len, _ref; + customHeaderMarkups = {}; + tr = table.find("tr"); + _ref = tr.find("th"); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + th = _ref[_i]; + th = angular.element(th); + customHeaderMarkups[th.attr("at-attribute")] = { + custom_content: th.html(), + attributes: th[0].attributes }; - }; - return function(attributes) { - if (attributes.atList) { - return new StandardSetup(attributes); + } + return customHeaderMarkups; + }; + + DeclarativeTable.prototype.collect_body_markup = function(table) { + var attribute, bodyDefinition, initialSorting, sortable, td, title, width, _i, _len, _ref; + bodyDefinition = []; + _ref = table.find("td"); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + td = _ref[_i]; + td = angular.element(td); + attribute = td.attr("at-attribute"); + title = td.attr("at-title") || this.capitaliseFirstLetter(td.attr("at-attribute")); + sortable = td.attr("at-sortable") !== void 0 || this.isSortable(td.attr("class")); + width = this.extractWidth(td.attr("class")); + initialSorting = this.getInitialSorting(td); + bodyDefinition.push({ + attribute: attribute, + title: title, + sortable: sortable, + width: width, + initialSorting: initialSorting + }); + } + return bodyDefinition; + }; + + DeclarativeTable.prototype.create_column_configurations = function() { + var body_markup, column_configurations, header_markup, i, _i, _len; + header_markup = this.collect_header_markup(this.element); + body_markup = this.collect_body_markup(this.element); + column_configurations = []; + for (_i = 0, _len = body_markup.length; _i < _len; _i++) { + i = body_markup[_i]; + column_configurations.push(new ColumnConfiguration(i, header_markup[i.attribute])); + } + return column_configurations; + }; + + DeclarativeTable.prototype.get_column_configurations = function() { + return this.column_configurations || (this.column_configurations = this.create_column_configurations()); + }; + + return DeclarativeTable; + + })(Table); + + StandardTableSetup = (function(_super) { + __extends(StandardTableSetup, _super); + + function StandardTableSetup(attributes) { + this.repeatString = "item in " + attributes.atList + " " + this.orderByExpression; + } + + StandardTableSetup.prototype.compile = function(element, attributes, transclude) { + return this.setupTr(element, this.repeatString); + }; + + StandardTableSetup.prototype.link = function() {}; + + return StandardTableSetup; + + })(TableSetup); + + PaginationTableSetup = (function(_super) { + __extends(PaginationTableSetup, _super); + + function PaginationTableSetup(attributes) { + this.sortContext = attributes.atSortContext || "global"; + this.paginationName = attributes.atPagination; + this.fillLastPage = attributes.atFillLastPage; + if (this.sortContext === "global") { + this.repeatString = "item in " + this.paginationName + ".atList " + this.orderByExpression + " " + this.limitToExpression; + } else if (this.sortContext === "page") { + this.repeatString = "item in " + this.paginationName + ".atList " + this.limitToExpression + " " + this.orderByExpression + " "; + } else { + throw "Invalid sort-context: " + this.sortContext + "."; + } + } + + PaginationTableSetup.prototype.compile = function(element, attributes, transclude) { + var fillerTr, tbody, td, tdString, tds, _i, _len; + tbody = this.setupTr(element, this.repeatString); + if (typeof this.fillLastPage !== "undefined") { + tds = element.find("td"); + tdString = ""; + for (_i = 0, _len = tds.length; _i < _len; _i++) { + td = tds[_i]; + tdString += " "; + } + fillerTr = angular.element(document.createElement("tr")); + fillerTr.html(tdString); + fillerTr.attr("ng-repeat", "item in " + this.paginationName + ".getFillerArray() "); + tbody.append(fillerTr); + } + }; + + PaginationTableSetup.prototype.link = function($scope, $element, $attributes) { + var paginationName; + paginationName = this.paginationName; + $scope.fromPage = function() { + if ($scope[paginationName]) { + return $scope[paginationName].fromPage(); } - if (attributes.pagination) { - return new PaginationSetup(attributes); + }; + $scope.toPage = function() { + if ($scope[paginationName]) { + return $scope[paginationName].atItemsPerPage; } }; - } - ]); + }; + + return PaginationTableSetup; + + })(TableSetup); }).call(this); From 7f0c38885af14f917866873dcf155e6c9fef406d Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 10 Feb 2014 19:21:47 +0100 Subject: [PATCH 052/190] experimental refactoring --- Rakefile | 2 +- angular-table.js | 274 +++++++++++++----- angular-table.min.js | 2 +- coffee/atPagination.coffee | 84 +++--- coffee/atTable.coffee | 92 +++++- coffee/declarative_table.coffee | 6 +- coffee/pagination_table_setup.coffee | 60 ++-- coffee/table.coffee | 14 +- coffee/table_configuration.coffee | 40 +++ coffee/table_setup.coffee | 10 +- gem/app/assets/javascripts/angular-table.js | 274 +++++++++++++----- test/templates/pagination/pagination.html | 4 +- .../pagination/sort_context_global.html | 4 +- .../pagination/sort_context_page.html | 4 +- 14 files changed, 619 insertions(+), 251 deletions(-) create mode 100644 coffee/table_configuration.coffee diff --git a/Rakefile b/Rakefile index 6697b78..b977726 100644 --- a/Rakefile +++ b/Rakefile @@ -20,7 +20,7 @@ end def collect_coffees src files = [ "atTable", "atImplicit", "atPagination", - "table", "table_setup", + "table", "table_setup", "table_configuration", "column_configuration", "declarative_table", "standard_table_setup", "pagination_table_setup" ] diff --git a/angular-table.js b/angular-table.js index e9300b0..c45b4ec 100644 --- a/angular-table.js +++ b/angular-table.js @@ -3,17 +3,110 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var ColumnConfiguration, DeclarativeTable, PaginationTableSetup, StandardTableSetup, Table, TableSetup, + var AngularTableManager, ColumnConfiguration, DeclarativeTable, PaginationTableSetup, StandardTableSetup, Table, TableConfiguration, TableSetup, TableToPaginationMapping, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_items_per_page, irk_list, irk_number_of_pages, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; angular.module("angular-table", []); + irk_from_page = "from_page"; + + irk_current_page = "current_page"; + + irk_number_of_pages = "number_of_pages"; + + irk_items_per_page = "items_per_page"; + + irk_list = "list"; + + erk_list = "atList"; + + erk_items_per_page = "atItemsPerPage"; + + erk_fill_last_page = "atFillLastPage"; + + erk_sort_context = "atSortContext"; + + erk_attribute = "at-attribute"; + + erk_sortable = "at-sortable"; + + erk_initial_sorting = "at-initial-sorting"; + + calculate_from_page = function(items_per_page, current_page, list) { + if (list) { + return items_per_page * current_page - list.length; + } + }; + + TableToPaginationMapping = (function() { + function TableToPaginationMapping() { + this.table_scope = void 0; + this.pagination_scope = void 0; + this.list = void 0; + } + + return TableToPaginationMapping; + + })(); + + AngularTableManager = (function() { + function AngularTableManager() { + this.mappings = {}; + } + + AngularTableManager.prototype.register_table = function(table_configuration) { + var mapping, _base, _name; + mapping = (_base = this.mappings)[_name = table_configuration.get_id()] || (_base[_name] = new TableToPaginationMapping()); + mapping.table_configuration = table_configuration; + if (mapping.pagination_scope) { + throw "WHOOPS"; + } + }; + + AngularTableManager.prototype.register_pagination = function(id, pagination_scope) { + var mapping, _base; + mapping = (_base = this.mappings)[id] || (_base[id] = new TableToPaginationMapping()); + mapping.pagination_scope = pagination_scope; + pagination_scope.$watch("vari", function() { + return console.log("it changed lol: ", pagination_scope.vari); + }); + mapping.table_configuration.get_scope().$parent.vari = "hello"; + if (mapping.table_configuration) { + pagination_scope[irk_list] = mapping.table_configuration.get_list(); + return pagination_scope.$watch(irk_current_page, function() { + var ts; + ts = mapping.table_configuration.get_scope(); + ts[irk_current_page] = pagination_scope[irk_current_page]; + ts[irk_items_per_page] = pagination_scope[irk_items_per_page]; + ts[irk_number_of_pages] = pagination_scope[irk_number_of_pages]; + return ts[irk_from_page] = calculate_from_page(ts[irk_items_per_page], ts[irk_current_page], ts[mapping.table_configuration.get_list()]); + }); + } + }; + + return AngularTableManager; + + })(); + + angular.module("angular-table").service("angularTableManager", [ + function() { + return new AngularTableManager(); + } + ]); + angular.module("angular-table").directive("atTable", [ function() { return { restrict: "AC", scope: true, + controller: [ + "$scope", "$element", "$attrs", "angularTableManager", function($scope, $element, $attrs, angularTableManager) { + var tc; + tc = new TableConfiguration($scope, $attrs); + return angularTableManager.register_table(tc); + } + ], compile: function(element, attributes, transclude) { var dt; dt = new DeclarativeTable(element, attributes); @@ -49,67 +142,50 @@ return { replace: true, restrict: "E", - template: " ", - scope: { - atItemsPerPage: "@", - atInstance: "=", - atList: "=" - }, + template: " ", + controller: [ + "$scope", "$element", "$attrs", "angularTableManager", function($scope, $element, $attrs, angularTableManager) { + return angularTableManager.register_pagination($attrs.atTableId, $scope); + } + ], + scope: true, link: function($scope, $element, $attributes) { - var normalizePage, update; - $scope.atInstance = $scope; - $scope.currentPage = 0; - normalizePage = function(page) { - page = Math.max(0, page); - page = Math.min($scope.numberOfPages - 1, page); - return page; + var get_list, normalizePage, update; + $scope[irk_items_per_page] = $attributes.atItemsPerPage; + $scope[irk_current_page] = 0; + get_list = function() { + return $scope[$scope[irk_list]]; }; update = function(reset) { var x; - $scope.currentPage = 0; - if ($scope.atList) { - if ($scope.atList.length > 0) { - $scope.numberOfPages = Math.ceil($scope.atList.length / $scope.atItemsPerPage); + $scope[irk_current_page] = 0; + if (get_list()) { + if (get_list().length > 0) { + $scope[irk_number_of_pages] = Math.ceil(get_list().length / $scope[irk_items_per_page]); return $scope.pages = (function() { var _i, _ref, _results; _results = []; - for (x = _i = 0, _ref = $scope.numberOfPages - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { + for (x = _i = 0, _ref = $scope[irk_number_of_pages] - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { _results.push(x); } return _results; })(); } else { - $scope.numberOfPages = 1; + $scope[irk_number_of_pages] = 1; return $scope.pages = [0]; } } }; - $scope.fromPage = function() { - if ($scope.atList) { - return $scope.atItemsPerPage * $scope.currentPage - $scope.atList.length; - } - }; - $scope.getFillerArray = function() { - var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; - if ($scope.currentPage === $scope.numberOfPages - 1) { - itemCountOnLastPage = $scope.atList.length % $scope.atItemsPerPage; - if (itemCountOnLastPage !== 0 || $scope.atList.length === 0) { - fillerLength = $scope.atItemsPerPage - itemCountOnLastPage - 1; - _results = []; - for (x = _i = _ref = $scope.atList.length, _ref1 = $scope.atList.length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { - _results.push(x); - } - return _results; - } else { - return []; - } - } + normalizePage = function(page) { + page = Math.max(0, page); + page = Math.min($scope[irk_number_of_pages] - 1, page); + return page; }; - $scope.goToPage = function(page) { - return $scope.currentPage = normalizePage(page); + $scope.go_to_page = function(page) { + return $scope[irk_current_page] = normalizePage(page); }; update(); - $scope.$watch("atItemsPerPage", function() { + $scope.$watch(irk_items_per_page, function() { return update(); }); return $scope.$watch("atList", function() { @@ -146,19 +222,16 @@ }; Table.prototype.validateInput = function() { - if (this.attributes.atPagination && this.attributes.atList) { - throw "You can not specify a list if you have specified a Pagination. The list defined for the pagnination will automatically be used."; - } if (!this.attributes.atPagination && !this.attributes.atList) { throw "Either a list or Pagination must be specified."; } }; Table.prototype.create_table_setup = function(attributes) { - if (attributes.atList) { + if (attributes.atList && !attributes.atPagination) { return new StandardTableSetup(attributes); } - if (attributes.atPagination) { + if (attributes.atList && attributes.atPagination) { return new PaginationTableSetup(attributes); } }; @@ -209,7 +282,7 @@ TableSetup = (function() { TableSetup.prototype.orderByExpression = "| orderBy:predicate:descending"; - TableSetup.prototype.limitToExpression = "| limitTo:fromPage() | limitTo:toPage()"; + TableSetup.prototype.limitToExpression = "| limitTo:" + irk_from_page + " | limitTo:" + irk_items_per_page; function TableSetup() {} @@ -221,19 +294,50 @@ return tbody; }; - (function(attributes) { - if (attributes.atList) { - return new StandardSetup(attributes); - } - if (attributes.atPagination) { - return new PaginationSetup(attributes); - } - }); - return TableSetup; })(); + TableConfiguration = (function() { + function TableConfiguration($scope, attributes) { + this.scope = $scope; + this.id = attributes.id; + this.list = attributes[erk_list]; + this.fill_last_page = attributes[erk_fill_last_page]; + this.items_per_page = attributes[erk_items_per_page]; + this.sort_context = attributes[erk_sort_context]; + } + + TableConfiguration.prototype.get_scope = function() { + return this.scope; + }; + + TableConfiguration.prototype.get_id = function() { + return this.id; + }; + + TableConfiguration.prototype.get_list = function() { + return this.list; + }; + + TableConfiguration.prototype.get_fill_last_page = function() { + return this.fill_last_page; + }; + + TableConfiguration.prototype.get_items_per_page = function() { + return this.items_per_page; + }; + + TableConfiguration.prototype.get_sort_context = function() { + return this.sort_context; + }; + + return TableConfiguration; + + })(); + + new TableConfiguration({}, {}); + ColumnConfiguration = (function() { function ColumnConfiguration(body_markup, header_markup) { this.attribute = body_markup.attribute; @@ -401,6 +505,10 @@ return this.column_configurations || (this.column_configurations = this.create_column_configurations()); }; + DeclarativeTable.prototype.create_table_configuration = function() {}; + + DeclarativeTable.prototype.get_table_configuration = function() {}; + return DeclarativeTable; })(Table); @@ -425,17 +533,23 @@ PaginationTableSetup = (function(_super) { __extends(PaginationTableSetup, _super); + PaginationTableSetup.prototype.evaluate_repeat_expression = function() { + var option; + option = { + "global": "" + this.orderByExpression + " " + this.limitToExpression, + "page": "" + this.limitToExpression + " " + this.orderByExpression + }[this.sortContext]; + if (!option) { + throw "Invalid sort-context: " + this.sortContext + "."; + } + return this.repeatString = "item in " + this.list_name + " " + option; + }; + function PaginationTableSetup(attributes) { this.sortContext = attributes.atSortContext || "global"; - this.paginationName = attributes.atPagination; + this.list_name = attributes.atList; this.fillLastPage = attributes.atFillLastPage; - if (this.sortContext === "global") { - this.repeatString = "item in " + this.paginationName + ".atList " + this.orderByExpression + " " + this.limitToExpression; - } else if (this.sortContext === "page") { - this.repeatString = "item in " + this.paginationName + ".atList " + this.limitToExpression + " " + this.orderByExpression + " "; - } else { - throw "Invalid sort-context: " + this.sortContext + "."; - } + this.evaluate_repeat_expression(); } PaginationTableSetup.prototype.compile = function(element, attributes, transclude) { @@ -450,22 +564,28 @@ } fillerTr = angular.element(document.createElement("tr")); fillerTr.html(tdString); - fillerTr.attr("ng-repeat", "item in " + this.paginationName + ".getFillerArray() "); + fillerTr.attr("ng-repeat", "item in getFillerArray() "); tbody.append(fillerTr); } }; PaginationTableSetup.prototype.link = function($scope, $element, $attributes) { - var paginationName; - paginationName = this.paginationName; - $scope.fromPage = function() { - if ($scope[paginationName]) { - return $scope[paginationName].fromPage(); - } - }; - $scope.toPage = function() { - if ($scope[paginationName]) { - return $scope[paginationName].atItemsPerPage; + var list_name; + list_name = this.list_name; + $scope.getFillerArray = function() { + var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; + if ($scope[irk_current_page] === $scope[irk_number_of_pages] - 1) { + itemCountOnLastPage = $scope[list_name].length % $scope[irk_items_per_page]; + if (itemCountOnLastPage !== 0 || $scope[list_name].length === 0) { + fillerLength = $scope[irk_items_per_page] - itemCountOnLastPage - 1; + _results = []; + for (x = _i = _ref = $scope[list_name].length, _ref1 = $scope[list_name].length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { + _results.push(x); + } + return _results; + } else { + return []; + } } }; }; diff --git a/angular-table.min.js b/angular-table.min.js index 87d8fc3..2b230c9 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,r,n,a,o={}.hasOwnProperty,s=function(t,e){function i(){this.constructor=t}for(var r in e)o.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};angular.module("angular-table",[]),angular.module("angular-table").directive("atTable",[function(){return{restrict:"AC",scope:!0,compile:function(t,i){var r;return r=new e(t,i),r.compile(),{post:function(t,e,i){return r.post(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",scope:{atItemsPerPage:"@",atInstance:"=",atList:"="},link:function(t){var e,i;return t.atInstance=t,t.currentPage=0,e=function(e){return e=Math.max(0,e),e=Math.min(t.numberOfPages-1,e)},i=function(){var e;return t.currentPage=0,t.atList?t.atList.length>0?(t.numberOfPages=Math.ceil(t.atList.length/t.atItemsPerPage),t.pages=function(){var i,r,n;for(n=[],e=i=0,r=t.numberOfPages-1;r>=0?r>=i:i>=r;e=r>=0?++i:--i)n.push(e);return n}()):(t.numberOfPages=1,t.pages=[0]):void 0},t.fromPage=function(){return t.atList?t.atItemsPerPage*t.currentPage-t.atList.length:void 0},t.getFillerArray=function(){var e,i,r,n,a,o,s;if(t.currentPage===t.numberOfPages-1){if(i=t.atList.length%t.atItemsPerPage,0!==i||0===t.atList.length){for(e=t.atItemsPerPage-i-1,s=[],r=n=a=t.atList.length,o=t.atList.length+e;o>=a?o>=n:n>=o;r=o>=a?++n:--n)s.push(r);return s}return[]}},t.goToPage=function(i){return t.currentPage=e(i)},i(),t.$watch("atItemsPerPage",function(){return i()}),t.$watch("atList",function(){return i()})}}}]),n=function(){function t(){}return t.prototype.constructHeader=function(){var t,e,i,r,n;for(e=angular.element(document.createElement("tr")),n=this.get_column_configurations(),i=0,r=n.length;r>i;i++)t=n[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.validateInput=function(){if(this.attributes.atPagination&&this.attributes.atList)throw"You can not specify a list if you have specified a Pagination. The list defined for the pagnination will automatically be used.";if(!this.attributes.atPagination&&!this.attributes.atList)throw"Either a list or Pagination must be specified."},t.prototype.create_table_setup=function(t){return t.atList?new r(t):t.atPagination?new i(t):void 0},t.prototype.compile=function(){return this.validateInput(),this.setup_header(),this.setup=this.create_table_setup(this.attributes),this.setup.compile(this.element,this.attributes)},t.prototype.setup_initial_sorting=function(t){var e,i,r,n,a;for(n=this.get_column_configurations(),a=[],i=0,r=n.length;r>i;i++){if(e=n[i],e.initialSorting&&!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}return a},t.prototype.post=function(t,e,i){return this.setup_initial_sorting(t),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},this.setup.link(t,e,i)},t}(),a=function(){function t(){}return t.prototype.orderByExpression="| orderBy:predicate:descending",t.prototype.limitToExpression="| limitTo:fromPage() | limitTo:toPage()",t.prototype.setupTr=function(t,e){var i,r;return i=t.find("tbody"),r=i.find("tr"),r.attr("ng-repeat",e),i},t}(),t=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,r,n,a;if(this.custom_content){for(n=this.attributes,a=[],i=0,r=n.length;r>i;i++)e=n[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"')"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),e=function(e){function i(t,e){this.element=t,this.attributes=e}return s(i,e),i.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},i.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},i.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},i.prototype.collect_header_markup=function(t){var e,i,r,n,a,o;for(e={},r=t.find("tr"),o=r.find("th"),n=0,a=o.length;a>n;n++)i=o[n],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},i.prototype.collect_body_markup=function(t){var e,i,r,n,a,o,s,u,c,l;for(i=[],l=t.find("td"),u=0,c=l.length;c>u;u++)a=l[u],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),n=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),r=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:n,width:s,initialSorting:r});return i},i.prototype.create_column_configurations=function(){var e,i,r,n,a,o;for(r=this.collect_header_markup(this.element),e=this.collect_body_markup(this.element),i=[],a=0,o=e.length;o>a;a++)n=e[a],i.push(new t(n,r[n.attribute]));return i},i.prototype.get_column_configurations=function(){return this.column_configurations||(this.column_configurations=this.create_column_configurations())},i}(n),r=function(t){function e(t){this.repeatString="item in "+t.atList+" "+this.orderByExpression}return s(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(a),i=function(t){function e(t){if(this.sortContext=t.atSortContext||"global",this.paginationName=t.atPagination,this.fillLastPage=t.atFillLastPage,"global"===this.sortContext)this.repeatString="item in "+this.paginationName+".atList "+this.orderByExpression+" "+this.limitToExpression;else{if("page"!==this.sortContext)throw"Invalid sort-context: "+this.sortContext+".";this.repeatString="item in "+this.paginationName+".atList "+this.limitToExpression+" "+this.orderByExpression+" "}}return s(e,t),e.prototype.compile=function(t){var e,i,r,n,a,o,s;if(i=this.setupTr(t,this.repeatString),"undefined"!=typeof this.fillLastPage){for(a=t.find("td"),n="",o=0,s=a.length;s>o;o++)r=a[o],n+=" ";e=angular.element(document.createElement("tr")),e.html(n),e.attr("ng-repeat","item in "+this.paginationName+".getFillerArray() "),i.append(e)}},e.prototype.link=function(t){var e;e=this.paginationName,t.fromPage=function(){return t[e]?t[e].fromPage():void 0},t.toPage=function(){return t[e]?t[e].atItemsPerPage:void 0}},e}(a)}).call(this); \ No newline at end of file +(function(){var t,e,i,n,r,o,a,s,u,l,c,p,g,h,f,_,d,m,b,v,y,w,x={}.hasOwnProperty,S=function(t,e){function i(){this.constructor=t}for(var n in e)x.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};angular.module("angular-table",[]),b="from_page",m="current_page",w="number_of_pages",v="items_per_page",y="list",f="atList",h="atItemsPerPage",p="atFillLastPage",_="atSortContext",c="at-attribute",d="at-sortable",g="at-initial-sorting",l=function(t,e,i){return i?t*e-i.length:void 0},u=function(){function t(){this.table_scope=void 0,this.pagination_scope=void 0,this.list=void 0}return t}(),t=function(){function t(){this.mappings={}}return t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.get_id()]||(i[n]=new u),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_pagination=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]=new u),i.pagination_scope=e,e.$watch("vari",function(){return console.log("it changed lol: ",e.vari)}),i.table_configuration.get_scope().$parent.vari="hello",i.table_configuration?(e[y]=i.table_configuration.get_list(),e.$watch(m,function(){var t;return t=i.table_configuration.get_scope(),t[m]=e[m],t[v]=e[v],t[w]=e[w],t[b]=l(t[v],t[m],t[i.table_configuration.get_list()])})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",[function(){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs","angularTableManager",function(t,e,i,n){var r;return r=new a(t,i),n.register_table(r)}],compile:function(t,e){var n;return n=new i(t,e),n.compile(),{post:function(t,e,i){return n.post(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",controller:["$scope","$element","$attrs","angularTableManager",function(t,e,i,n){return n.register_pagination(i.atTableId,t)}],scope:!0,link:function(t,e,i){var n,r,o;return t[v]=i.atItemsPerPage,t[m]=0,n=function(){return t[t[y]]},o=function(){var e;return t[m]=0,n()?n().length>0?(t[w]=Math.ceil(n().length/t[v]),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t[w]-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t[w]=1,t.pages=[0]):void 0},r=function(e){return e=Math.max(0,e),e=Math.min(t[w]-1,e)},t.go_to_page=function(e){return t[m]=r(e)},o(),t.$watch(v,function(){return o()}),t.$watch("atList",function(){return o()})}}}]),o=function(){function t(){}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.get_column_configurations(),i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.validateInput=function(){if(!this.attributes.atPagination&&!this.attributes.atList)throw"Either a list or Pagination must be specified."},t.prototype.create_table_setup=function(t){return t.atList&&!t.atPagination?new r(t):t.atList&&t.atPagination?new n(t):void 0},t.prototype.compile=function(){return this.validateInput(),this.setup_header(),this.setup=this.create_table_setup(this.attributes),this.setup.compile(this.element,this.attributes)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,o;for(r=this.get_column_configurations(),o=[],i=0,n=r.length;n>i;i++){if(e=r[i],e.initialSorting&&!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,o.push(t.descending="desc"===e.initialSorting)}return o},t.prototype.post=function(t,e,i){return this.setup_initial_sorting(t),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},this.setup.link(t,e,i)},t}(),s=function(){function t(){}return t.prototype.orderByExpression="| orderBy:predicate:descending",t.prototype.limitToExpression="| limitTo:"+b+" | limitTo:"+v,t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),a=function(){function t(t,e){this.scope=t,this.id=e.id,this.list=e[f],this.fill_last_page=e[p],this.items_per_page=e[h],this.sort_context=e[_]}return t.prototype.get_scope=function(){return this.scope},t.prototype.get_id=function(){return this.id},t.prototype.get_list=function(){return this.list},t.prototype.get_fill_last_page=function(){return this.fill_last_page},t.prototype.get_items_per_page=function(){return this.items_per_page},t.prototype.get_sort_context=function(){return this.sort_context},t}(),new a({},{}),e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,o;if(this.custom_content){for(r=this.attributes,o=[],i=0,n=r.length;n>i;i++)e=r[i],o.push(t.attr(e.name,e.value));return o}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"')"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),i=function(t){function i(t,e){this.element=t,this.attributes=e}return S(i,t),i.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},i.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},i.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},i.prototype.collect_header_markup=function(t){var e,i,n,r,o,a;for(e={},n=t.find("tr"),a=n.find("th"),r=0,o=a.length;o>r;r++)i=a[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},i.prototype.collect_body_markup=function(t){var e,i,n,r,o,a,s,u,l,c;for(i=[],c=t.find("td"),u=0,l=c.length;l>u;u++)o=c[u],o=angular.element(o),e=o.attr("at-attribute"),a=o.attr("at-title")||this.capitaliseFirstLetter(o.attr("at-attribute")),r=void 0!==o.attr("at-sortable")||this.isSortable(o.attr("class")),s=this.extractWidth(o.attr("class")),n=this.getInitialSorting(o),i.push({attribute:e,title:a,sortable:r,width:s,initialSorting:n});return i},i.prototype.create_column_configurations=function(){var t,i,n,r,o,a;for(n=this.collect_header_markup(this.element),t=this.collect_body_markup(this.element),i=[],o=0,a=t.length;a>o;o++)r=t[o],i.push(new e(r,n[r.attribute]));return i},i.prototype.get_column_configurations=function(){return this.column_configurations||(this.column_configurations=this.create_column_configurations())},i.prototype.create_table_configuration=function(){},i.prototype.get_table_configuration=function(){},i}(o),r=function(t){function e(t){this.repeatString="item in "+t.atList+" "+this.orderByExpression}return S(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(s),n=function(t){function e(t){this.sortContext=t.atSortContext||"global",this.list_name=t.atList,this.fillLastPage=t.atFillLastPage,this.evaluate_repeat_expression()}return S(e,t),e.prototype.evaluate_repeat_expression=function(){var t;if(t={global:""+this.orderByExpression+" "+this.limitToExpression,page:""+this.limitToExpression+" "+this.orderByExpression}[this.sortContext],!t)throw"Invalid sort-context: "+this.sortContext+".";return this.repeatString="item in "+this.list_name+" "+t},e.prototype.compile=function(t){var e,i,n,r,o,a,s;if(i=this.setupTr(t,this.repeatString),"undefined"!=typeof this.fillLastPage){for(o=t.find("td"),r="",a=0,s=o.length;s>a;a++)n=o[a],r+=" ";e=angular.element(document.createElement("tr")),e.html(r),e.attr("ng-repeat","item in getFillerArray() "),i.append(e)}},e.prototype.link=function(t){var e;e=this.list_name,t.getFillerArray=function(){var i,n,r,o,a,s,u;if(t[m]===t[w]-1){if(n=t[e].length%t[v],0!==n||0===t[e].length){for(i=t[v]-n-1,u=[],r=o=a=t[e].length,s=t[e].length+i;s>=a?s>=o:o>=s;r=s>=a?++o:--o)u.push(r);return u}return[]}}},e}(s)}).call(this); \ No newline at end of file diff --git a/coffee/atPagination.coffee b/coffee/atPagination.coffee index 04215f9..a8ad36a 100644 --- a/coffee/atPagination.coffee +++ b/coffee/atPagination.coffee @@ -1,80 +1,62 @@ angular.module("angular-table").directive "atPagination", [() -> + { replace: true restrict: "E" + template: " " - scope: { - atItemsPerPage: "@" - atInstance: "=" - atList: "=" - } + + controller: ["$scope", "$element", "$attrs", "angularTableManager", + ($scope, $element, $attrs, angularTableManager) -> + angularTableManager.register_pagination($attrs.atTableId, $scope) + ] + + scope: true + link: ($scope, $element, $attributes) -> - $scope.atInstance = $scope - $scope.currentPage = 0 + $scope[irk_items_per_page] = $attributes.atItemsPerPage + $scope[irk_current_page] = 0 - normalizePage = (page) -> - page = Math.max(0, page) - page = Math.min($scope.numberOfPages - 1, page) - page + get_list = () -> + $scope[$scope[irk_list]] update = (reset) -> - # $scope.currentPage = if reset then 0 else normalizePage($scope.currentPage) - $scope.currentPage = 0 + $scope[irk_current_page] = 0 - if $scope.atList - if $scope.atList.length > 0 - $scope.numberOfPages = Math.ceil($scope.atList.length / $scope.atItemsPerPage) - $scope.pages = for x in [0..($scope.numberOfPages - 1)] + if get_list() + if get_list().length > 0 + $scope[irk_number_of_pages] = Math.ceil(get_list().length / $scope[irk_items_per_page]) + $scope.pages = for x in [0..($scope[irk_number_of_pages] - 1)] x else - $scope.numberOfPages = 1 + $scope[irk_number_of_pages] = 1 $scope.pages = [0] - $scope.fromPage = () -> - if $scope.atList - $scope.atItemsPerPage * $scope.currentPage - $scope.atList.length - - $scope.getFillerArray = () -> - if $scope.currentPage == $scope.numberOfPages - 1 - itemCountOnLastPage = $scope.atList.length % $scope.atItemsPerPage - if itemCountOnLastPage != 0 || $scope.atList.length == 0 - fillerLength = $scope.atItemsPerPage - itemCountOnLastPage - 1 - x for x in [($scope.atList.length)..($scope.atList.length + fillerLength)] - else - [] + normalizePage = (page) -> + page = Math.max(0, page) + page = Math.min($scope[irk_number_of_pages] - 1, page) + page - $scope.goToPage = (page) -> - $scope.currentPage = normalizePage(page) + $scope.go_to_page = (page) -> + $scope[irk_current_page] = normalizePage(page) update() - # $scope.$watch "list", (newValue, oldValue) -> - # update() - # # console.log newValue.length, oldValue.length - # if newValue.length != oldValue.length - # update false - # else - # update true - # , true - - # $scope.$watch "list.length", (newValue, oldValue) -> - # update(false) if newValue != oldValue - - $scope.$watch "atItemsPerPage", () -> + $scope.$watch irk_items_per_page, () -> update() $scope.$watch "atList", () -> diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index b789f20..d9047e9 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -1,15 +1,99 @@ angular.module "angular-table", [] -angular.module("angular-table").directive "atTable", [() -> +# internal reserved keywords +irk_from_page = "from_page" # atTable +irk_current_page = "current_page" # atTable (getFillerArray), atPagination +irk_number_of_pages = "number_of_pages" # atTable (getFillerArray), atPagination +irk_items_per_page = "items_per_page" # atTable, atPagination (calculate number of pages) +irk_list = "list" # atTable, atPagination + +# external reserved keywords +# table +erk_list = "atList" +erk_items_per_page = "atItemsPerPage" +erk_fill_last_page = "atFillLastPage" +erk_sort_context = "atSortContext" +# column +erk_attribute = "at-attribute" +erk_sortable = "at-sortable" +erk_initial_sorting = "at-initial-sorting" + +calculate_from_page = (items_per_page, current_page, list) -> + if list + items_per_page * current_page - list.length + +class AngularTableManager + + constructor: () -> + @mappings = {} + + register_table: (table_configuration) -> + mapping = @mappings[table_configuration.get_id()] ||= {} + + mapping.table_configuration = table_configuration + + if mapping.pagination_scope + throw "WHOOPS" + + register_table_scope: (id, scope) -> + @mappings[id].table_scope = scope + + register_pagination: (id, pagination_scope) -> + mapping = @mappings[id] ||= {} + mapping.pagination_scope = pagination_scope + + if mapping.table_configuration + pagination_scope[irk_list] = mapping.table_configuration.get_list() + + pagination_scope.$watch(irk_current_page, () -> + ts = mapping.table_scope + ts[irk_current_page] = pagination_scope[irk_current_page] + ts[irk_items_per_page] = pagination_scope[irk_items_per_page] + ts[irk_number_of_pages] = pagination_scope[irk_number_of_pages] + ts[irk_from_page] = calculate_from_page(ts[irk_items_per_page], + ts[irk_current_page], + ts[mapping.table_configuration.get_list()]) + ) + +angular.module("angular-table").service "angularTableManager", [() -> + new AngularTableManager() +] + +angular.module("angular-table").directive "atTable", ["$filter", "angularTableManager", ($filter, angularTableManager) -> { restrict: "AC" scope: true + controller: ["$scope", "$element", "$attrs", "angularTableManager", + ($scope, $element, $attrs, angularTableManager) -> + id = $attrs["id"] + if id + angularTableManager.register_table_scope(id, $scope) + ] + compile: (element, attributes, transclude) -> - dt = new DeclarativeTable(element, attributes) + tc = new TableConfiguration(attributes) + angularTableManager.register_table(tc) + + dt = new DeclarativeTable(element, attributes, tc) dt.compile() { post: ($scope, $element, $attributes) -> - dt.post($scope, $element, $attributes) + dt.post($scope, $element, $attributes, $filter) } } -] \ No newline at end of file +] + +# + +# itemsPerPage ist im parent scope definiert +# table und pagination können diese variable watchen und müssen ihre eigen scopevariablen updaten +# das selbe gilt für fill-last-page und sort-context + +#
+# es muss eine itemsPerPage variable im parent scope erstellt werden + + + +# current_page kann sich ändern in der pagination +# dann muss table notifiziert werden + diff --git a/coffee/declarative_table.coffee b/coffee/declarative_table.coffee index e1a25dd..af567e1 100644 --- a/coffee/declarative_table.coffee +++ b/coffee/declarative_table.coffee @@ -1,6 +1,6 @@ class DeclarativeTable extends Table - constructor: (@element, @attributes) -> + constructor: (@element, @attributes, @table_configuration) -> capitaliseFirstLetter: (string) -> if string then string.charAt(0).toUpperCase() + string.slice(1) else "" @@ -64,3 +64,7 @@ class DeclarativeTable extends Table get_column_configurations: () -> @column_configurations ||= @create_column_configurations() + + create_table_configuration: () -> + + get_table_configuration: () -> diff --git a/coffee/pagination_table_setup.coffee b/coffee/pagination_table_setup.coffee index bb2b688..5a57234 100644 --- a/coffee/pagination_table_setup.coffee +++ b/coffee/pagination_table_setup.coffee @@ -1,15 +1,24 @@ class PaginationTableSetup extends TableSetup - constructor: (attributes) -> - @sortContext = attributes.atSortContext || "global" - @paginationName = attributes.atPagination - @fillLastPage = attributes.atFillLastPage - - if @sortContext == "global" - @repeatString = "item in #{@paginationName}.atList #{@orderByExpression} #{@limitToExpression}" - else if @sortContext == "page" - @repeatString = "item in #{@paginationName}.atList #{@limitToExpression} #{@orderByExpression} " - else - throw "Invalid sort-context: #{@sortContext}." + + evaluate_repeat_expression: () -> + option = { + "global": "#{@orderByExpression} #{@limitToExpression}", + "page": "#{@limitToExpression} #{@orderByExpression}" + }[@sortContext] + + throw "Invalid sort-context: #{@sortContext}." unless option + @repeatString = "item in #{@list_name} #{option}" + + constructor: (attributes, table_configuration) -> + @sortContext = attributes.atSortContext || "global" + @list_name = attributes.atList + @fillLastPage = attributes.atFillLastPage + @evaluate_repeat_expression() + + @table_configuration = table_configuration + @limit_to_expression = "limitTo:#{irk_from_page} | limitTo:#{@table_configuration.get_items_per_page()}" + + # console.log @limit_to_expression compile: (element, attributes, transclude) -> tbody = @setupTr(element, @repeatString) @@ -22,19 +31,34 @@ class PaginationTableSetup extends TableSetup fillerTr = angular.element(document.createElement("tr")) fillerTr.html(tdString) - fillerTr.attr("ng-repeat", "item in #{@paginationName}.getFillerArray() ") + fillerTr.attr("ng-repeat", "item in getFillerArray() ") tbody.append(fillerTr) return - link: ($scope, $element, $attributes) -> - paginationName = @paginationName + link: ($scope, $element, $attributes, $filter) -> + list_name = @list_name + limitToExpression = @limitToExpression + + $scope.filtered_list = () -> + # console.log $scope.predicate + val = $filter("orderBy")($scope[list_name], $scope.predicate) + + console.log limitToExpression + val = $filter("limitTo")(val, limitToExpression) + console.log val + + return val - $scope.fromPage = () -> - if $scope[paginationName] then $scope[paginationName].fromPage() - $scope.toPage = () -> - if $scope[paginationName] then $scope[paginationName].atItemsPerPage + $scope.getFillerArray = () -> + if $scope[irk_current_page] == $scope[irk_number_of_pages] - 1 + itemCountOnLastPage = $scope[list_name].length % $scope[irk_items_per_page] + if itemCountOnLastPage != 0 || $scope[list_name].length == 0 + fillerLength = $scope[irk_items_per_page] - itemCountOnLastPage - 1 + x for x in [($scope[list_name].length)..($scope[list_name].length + fillerLength)] + else + [] return diff --git a/coffee/table.coffee b/coffee/table.coffee index 14420ee..819d5d2 100644 --- a/coffee/table.coffee +++ b/coffee/table.coffee @@ -14,16 +14,16 @@ class Table thead.append(header) validateInput: () -> - if @attributes.atPagination and @attributes.atList - throw "You can not specify a list if you have specified a Pagination. The list defined for the pagnination will automatically be used." + # if @attributes.atPagination and @attributes.atList + # throw "You can not specify a list if you have specified a Pagination. The list defined for the pagnination will automatically be used." if not @attributes.atPagination and not @attributes.atList throw "Either a list or Pagination must be specified." create_table_setup: (attributes) -> - if attributes.atList + if attributes.atList && !attributes.atPagination return new StandardTableSetup(attributes) - if attributes.atPagination - return new PaginationTableSetup(attributes) + if attributes.atList && attributes.atPagination + return new PaginationTableSetup(attributes, @table_configuration) return compile: () -> @@ -39,11 +39,11 @@ class Table $scope.predicate = bd.attribute $scope.descending = bd.initialSorting == "desc" - post: ($scope, $element, $attributes) -> + post: ($scope, $element, $attributes, $filter) -> @setup_initial_sorting($scope) $scope.getSortIcon = (predicate) -> return "icon-minus" if predicate != $scope.predicate if $scope.descending then "icon-chevron-down" else "icon-chevron-up" - @setup.link($scope, $element, $attributes) + @setup.link($scope, $element, $attributes, $filter) diff --git a/coffee/table_configuration.coffee b/coffee/table_configuration.coffee new file mode 100644 index 0000000..f25eedf --- /dev/null +++ b/coffee/table_configuration.coffee @@ -0,0 +1,40 @@ +class TableConfiguration + + register_items_per_page: (items_per_page) -> + n = parseInt(items_per_page) + if angular.isNumber(n) + @items_per_page = "#{@id}_itemsPerPage" + # @scope.$parent[@items_per_page] = n + else + @items_per_page = items_per_page + + constructor: (attributes) -> + # console.log $scope + # @scope = $scope + @id = attributes.id + @list = attributes[erk_list] + @fill_last_page = attributes[erk_fill_last_page] + + @register_items_per_page(attributes[erk_items_per_page]) if attributes[erk_items_per_page] + + @sort_context = attributes[erk_sort_context] + + # get_scope: () -> + # @scope + + get_id: () -> + @id + + get_list: () -> + @list + + get_fill_last_page: () -> + @fill_last_page + + get_items_per_page: () -> + @items_per_page + + get_sort_context: () -> + @sort_context + +new TableConfiguration({}, {}) \ No newline at end of file diff --git a/coffee/table_setup.coffee b/coffee/table_setup.coffee index 45fa450..6f6c67d 100644 --- a/coffee/table_setup.coffee +++ b/coffee/table_setup.coffee @@ -1,6 +1,7 @@ class TableSetup + orderByExpression: "| orderBy:predicate:descending" - limitToExpression: "| limitTo:fromPage() | limitTo:toPage()" + limitToExpression: "| limitTo:#{irk_from_page} | limitTo:#{irk_items_per_page}" constructor: () -> @@ -9,10 +10,3 @@ class TableSetup tr = tbody.find "tr" tr.attr("ng-repeat", repeatString) tbody - - (attributes) -> - if attributes.atList - return new StandardSetup(attributes) - if attributes.atPagination - return new PaginationSetup(attributes) - return diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index e9300b0..c45b4ec 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -3,17 +3,110 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var ColumnConfiguration, DeclarativeTable, PaginationTableSetup, StandardTableSetup, Table, TableSetup, + var AngularTableManager, ColumnConfiguration, DeclarativeTable, PaginationTableSetup, StandardTableSetup, Table, TableConfiguration, TableSetup, TableToPaginationMapping, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_items_per_page, irk_list, irk_number_of_pages, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; angular.module("angular-table", []); + irk_from_page = "from_page"; + + irk_current_page = "current_page"; + + irk_number_of_pages = "number_of_pages"; + + irk_items_per_page = "items_per_page"; + + irk_list = "list"; + + erk_list = "atList"; + + erk_items_per_page = "atItemsPerPage"; + + erk_fill_last_page = "atFillLastPage"; + + erk_sort_context = "atSortContext"; + + erk_attribute = "at-attribute"; + + erk_sortable = "at-sortable"; + + erk_initial_sorting = "at-initial-sorting"; + + calculate_from_page = function(items_per_page, current_page, list) { + if (list) { + return items_per_page * current_page - list.length; + } + }; + + TableToPaginationMapping = (function() { + function TableToPaginationMapping() { + this.table_scope = void 0; + this.pagination_scope = void 0; + this.list = void 0; + } + + return TableToPaginationMapping; + + })(); + + AngularTableManager = (function() { + function AngularTableManager() { + this.mappings = {}; + } + + AngularTableManager.prototype.register_table = function(table_configuration) { + var mapping, _base, _name; + mapping = (_base = this.mappings)[_name = table_configuration.get_id()] || (_base[_name] = new TableToPaginationMapping()); + mapping.table_configuration = table_configuration; + if (mapping.pagination_scope) { + throw "WHOOPS"; + } + }; + + AngularTableManager.prototype.register_pagination = function(id, pagination_scope) { + var mapping, _base; + mapping = (_base = this.mappings)[id] || (_base[id] = new TableToPaginationMapping()); + mapping.pagination_scope = pagination_scope; + pagination_scope.$watch("vari", function() { + return console.log("it changed lol: ", pagination_scope.vari); + }); + mapping.table_configuration.get_scope().$parent.vari = "hello"; + if (mapping.table_configuration) { + pagination_scope[irk_list] = mapping.table_configuration.get_list(); + return pagination_scope.$watch(irk_current_page, function() { + var ts; + ts = mapping.table_configuration.get_scope(); + ts[irk_current_page] = pagination_scope[irk_current_page]; + ts[irk_items_per_page] = pagination_scope[irk_items_per_page]; + ts[irk_number_of_pages] = pagination_scope[irk_number_of_pages]; + return ts[irk_from_page] = calculate_from_page(ts[irk_items_per_page], ts[irk_current_page], ts[mapping.table_configuration.get_list()]); + }); + } + }; + + return AngularTableManager; + + })(); + + angular.module("angular-table").service("angularTableManager", [ + function() { + return new AngularTableManager(); + } + ]); + angular.module("angular-table").directive("atTable", [ function() { return { restrict: "AC", scope: true, + controller: [ + "$scope", "$element", "$attrs", "angularTableManager", function($scope, $element, $attrs, angularTableManager) { + var tc; + tc = new TableConfiguration($scope, $attrs); + return angularTableManager.register_table(tc); + } + ], compile: function(element, attributes, transclude) { var dt; dt = new DeclarativeTable(element, attributes); @@ -49,67 +142,50 @@ return { replace: true, restrict: "E", - template: " ", - scope: { - atItemsPerPage: "@", - atInstance: "=", - atList: "=" - }, + template: " ", + controller: [ + "$scope", "$element", "$attrs", "angularTableManager", function($scope, $element, $attrs, angularTableManager) { + return angularTableManager.register_pagination($attrs.atTableId, $scope); + } + ], + scope: true, link: function($scope, $element, $attributes) { - var normalizePage, update; - $scope.atInstance = $scope; - $scope.currentPage = 0; - normalizePage = function(page) { - page = Math.max(0, page); - page = Math.min($scope.numberOfPages - 1, page); - return page; + var get_list, normalizePage, update; + $scope[irk_items_per_page] = $attributes.atItemsPerPage; + $scope[irk_current_page] = 0; + get_list = function() { + return $scope[$scope[irk_list]]; }; update = function(reset) { var x; - $scope.currentPage = 0; - if ($scope.atList) { - if ($scope.atList.length > 0) { - $scope.numberOfPages = Math.ceil($scope.atList.length / $scope.atItemsPerPage); + $scope[irk_current_page] = 0; + if (get_list()) { + if (get_list().length > 0) { + $scope[irk_number_of_pages] = Math.ceil(get_list().length / $scope[irk_items_per_page]); return $scope.pages = (function() { var _i, _ref, _results; _results = []; - for (x = _i = 0, _ref = $scope.numberOfPages - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { + for (x = _i = 0, _ref = $scope[irk_number_of_pages] - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { _results.push(x); } return _results; })(); } else { - $scope.numberOfPages = 1; + $scope[irk_number_of_pages] = 1; return $scope.pages = [0]; } } }; - $scope.fromPage = function() { - if ($scope.atList) { - return $scope.atItemsPerPage * $scope.currentPage - $scope.atList.length; - } - }; - $scope.getFillerArray = function() { - var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; - if ($scope.currentPage === $scope.numberOfPages - 1) { - itemCountOnLastPage = $scope.atList.length % $scope.atItemsPerPage; - if (itemCountOnLastPage !== 0 || $scope.atList.length === 0) { - fillerLength = $scope.atItemsPerPage - itemCountOnLastPage - 1; - _results = []; - for (x = _i = _ref = $scope.atList.length, _ref1 = $scope.atList.length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { - _results.push(x); - } - return _results; - } else { - return []; - } - } + normalizePage = function(page) { + page = Math.max(0, page); + page = Math.min($scope[irk_number_of_pages] - 1, page); + return page; }; - $scope.goToPage = function(page) { - return $scope.currentPage = normalizePage(page); + $scope.go_to_page = function(page) { + return $scope[irk_current_page] = normalizePage(page); }; update(); - $scope.$watch("atItemsPerPage", function() { + $scope.$watch(irk_items_per_page, function() { return update(); }); return $scope.$watch("atList", function() { @@ -146,19 +222,16 @@ }; Table.prototype.validateInput = function() { - if (this.attributes.atPagination && this.attributes.atList) { - throw "You can not specify a list if you have specified a Pagination. The list defined for the pagnination will automatically be used."; - } if (!this.attributes.atPagination && !this.attributes.atList) { throw "Either a list or Pagination must be specified."; } }; Table.prototype.create_table_setup = function(attributes) { - if (attributes.atList) { + if (attributes.atList && !attributes.atPagination) { return new StandardTableSetup(attributes); } - if (attributes.atPagination) { + if (attributes.atList && attributes.atPagination) { return new PaginationTableSetup(attributes); } }; @@ -209,7 +282,7 @@ TableSetup = (function() { TableSetup.prototype.orderByExpression = "| orderBy:predicate:descending"; - TableSetup.prototype.limitToExpression = "| limitTo:fromPage() | limitTo:toPage()"; + TableSetup.prototype.limitToExpression = "| limitTo:" + irk_from_page + " | limitTo:" + irk_items_per_page; function TableSetup() {} @@ -221,19 +294,50 @@ return tbody; }; - (function(attributes) { - if (attributes.atList) { - return new StandardSetup(attributes); - } - if (attributes.atPagination) { - return new PaginationSetup(attributes); - } - }); - return TableSetup; })(); + TableConfiguration = (function() { + function TableConfiguration($scope, attributes) { + this.scope = $scope; + this.id = attributes.id; + this.list = attributes[erk_list]; + this.fill_last_page = attributes[erk_fill_last_page]; + this.items_per_page = attributes[erk_items_per_page]; + this.sort_context = attributes[erk_sort_context]; + } + + TableConfiguration.prototype.get_scope = function() { + return this.scope; + }; + + TableConfiguration.prototype.get_id = function() { + return this.id; + }; + + TableConfiguration.prototype.get_list = function() { + return this.list; + }; + + TableConfiguration.prototype.get_fill_last_page = function() { + return this.fill_last_page; + }; + + TableConfiguration.prototype.get_items_per_page = function() { + return this.items_per_page; + }; + + TableConfiguration.prototype.get_sort_context = function() { + return this.sort_context; + }; + + return TableConfiguration; + + })(); + + new TableConfiguration({}, {}); + ColumnConfiguration = (function() { function ColumnConfiguration(body_markup, header_markup) { this.attribute = body_markup.attribute; @@ -401,6 +505,10 @@ return this.column_configurations || (this.column_configurations = this.create_column_configurations()); }; + DeclarativeTable.prototype.create_table_configuration = function() {}; + + DeclarativeTable.prototype.get_table_configuration = function() {}; + return DeclarativeTable; })(Table); @@ -425,17 +533,23 @@ PaginationTableSetup = (function(_super) { __extends(PaginationTableSetup, _super); + PaginationTableSetup.prototype.evaluate_repeat_expression = function() { + var option; + option = { + "global": "" + this.orderByExpression + " " + this.limitToExpression, + "page": "" + this.limitToExpression + " " + this.orderByExpression + }[this.sortContext]; + if (!option) { + throw "Invalid sort-context: " + this.sortContext + "."; + } + return this.repeatString = "item in " + this.list_name + " " + option; + }; + function PaginationTableSetup(attributes) { this.sortContext = attributes.atSortContext || "global"; - this.paginationName = attributes.atPagination; + this.list_name = attributes.atList; this.fillLastPage = attributes.atFillLastPage; - if (this.sortContext === "global") { - this.repeatString = "item in " + this.paginationName + ".atList " + this.orderByExpression + " " + this.limitToExpression; - } else if (this.sortContext === "page") { - this.repeatString = "item in " + this.paginationName + ".atList " + this.limitToExpression + " " + this.orderByExpression + " "; - } else { - throw "Invalid sort-context: " + this.sortContext + "."; - } + this.evaluate_repeat_expression(); } PaginationTableSetup.prototype.compile = function(element, attributes, transclude) { @@ -450,22 +564,28 @@ } fillerTr = angular.element(document.createElement("tr")); fillerTr.html(tdString); - fillerTr.attr("ng-repeat", "item in " + this.paginationName + ".getFillerArray() "); + fillerTr.attr("ng-repeat", "item in getFillerArray() "); tbody.append(fillerTr); } }; PaginationTableSetup.prototype.link = function($scope, $element, $attributes) { - var paginationName; - paginationName = this.paginationName; - $scope.fromPage = function() { - if ($scope[paginationName]) { - return $scope[paginationName].fromPage(); - } - }; - $scope.toPage = function() { - if ($scope[paginationName]) { - return $scope[paginationName].atItemsPerPage; + var list_name; + list_name = this.list_name; + $scope.getFillerArray = function() { + var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; + if ($scope[irk_current_page] === $scope[irk_number_of_pages] - 1) { + itemCountOnLastPage = $scope[list_name].length % $scope[irk_items_per_page]; + if (itemCountOnLastPage !== 0 || $scope[list_name].length === 0) { + fillerLength = $scope[irk_items_per_page] - itemCountOnLastPage - 1; + _results = []; + for (x = _i = _ref = $scope[list_name].length, _ref1 = $scope[list_name].length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { + _results.push(x); + } + return _results; + } else { + return []; + } } }; }; diff --git a/test/templates/pagination/pagination.html b/test/templates/pagination/pagination.html index 8839cc8..eb9d9c3 100644 --- a/test/templates/pagination/pagination.html +++ b/test/templates/pagination/pagination.html @@ -1,4 +1,4 @@ -
+
@@ -7,4 +7,4 @@
- \ No newline at end of file + diff --git a/test/templates/pagination/sort_context_global.html b/test/templates/pagination/sort_context_global.html index a97d0b1..30cd710 100644 --- a/test/templates/pagination/sort_context_global.html +++ b/test/templates/pagination/sort_context_global.html @@ -1,4 +1,4 @@ - +
@@ -7,4 +7,4 @@
- \ No newline at end of file + \ No newline at end of file diff --git a/test/templates/pagination/sort_context_page.html b/test/templates/pagination/sort_context_page.html index 351aa4a..eda407e 100644 --- a/test/templates/pagination/sort_context_page.html +++ b/test/templates/pagination/sort_context_page.html @@ -1,4 +1,4 @@ - +
@@ -7,4 +7,4 @@
- \ No newline at end of file + \ No newline at end of file From 5de1a098b741977657a3fb397a340f4a7042e9ee Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 12 Feb 2014 14:27:47 +0100 Subject: [PATCH 053/190] created a table configuration class and refactored code to use it --- coffee/atPagination.coffee | 17 +++-- coffee/atTable.coffee | 29 ++++++--- coffee/pagination_table_setup.coffee | 65 ++++++++----------- coffee/standard_table_setup.coffee | 2 +- coffee/table_configuration.coffee | 63 +++++++++--------- coffee/table_setup.coffee | 5 -- test/templates/pagination/pagination.html | 2 +- .../pagination/sort_context_global.html | 2 +- .../pagination/sort_context_page.html | 2 +- 9 files changed, 93 insertions(+), 94 deletions(-) diff --git a/coffee/atPagination.coffee b/coffee/atPagination.coffee index a8ad36a..37efe6c 100644 --- a/coffee/atPagination.coffee +++ b/coffee/atPagination.coffee @@ -1,4 +1,4 @@ -angular.module("angular-table").directive "atPagination", [() -> +angular.module("angular-table").directive "atPagination", ["angularTableManager", (angularTableManager) -> { replace: true @@ -20,7 +20,7 @@ angular.module("angular-table").directive "atPagination", [() -> " controller: ["$scope", "$element", "$attrs", "angularTableManager", - ($scope, $element, $attrs, angularTableManager) -> + ($scope, $element, $attrs) -> angularTableManager.register_pagination($attrs.atTableId, $scope) ] @@ -28,18 +28,22 @@ angular.module("angular-table").directive "atPagination", [() -> link: ($scope, $element, $attributes) -> - $scope[irk_items_per_page] = $attributes.atItemsPerPage + tc = angularTableManager.get_table_configuration($attributes.atTableId) + + # console.log tc.items_per_page() + + # $scope[irk_items_per_page] = $attributes.atItemsPerPage $scope[irk_current_page] = 0 get_list = () -> - $scope[$scope[irk_list]] + $scope[tc.list] update = (reset) -> $scope[irk_current_page] = 0 if get_list() if get_list().length > 0 - $scope[irk_number_of_pages] = Math.ceil(get_list().length / $scope[irk_items_per_page]) + $scope[irk_number_of_pages] = Math.ceil(get_list().length / $scope[tc.items_per_page]) $scope.pages = for x in [0..($scope[irk_number_of_pages] - 1)] x else @@ -56,7 +60,8 @@ angular.module("angular-table").directive "atPagination", [() -> update() - $scope.$watch irk_items_per_page, () -> + # TODO still needed, but could be replaced? + $scope.$watch tc.items_per_page, () -> update() $scope.$watch "atList", () -> diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index d9047e9..79d1b3a 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -4,8 +4,6 @@ angular.module "angular-table", [] irk_from_page = "from_page" # atTable irk_current_page = "current_page" # atTable (getFillerArray), atPagination irk_number_of_pages = "number_of_pages" # atTable (getFillerArray), atPagination -irk_items_per_page = "items_per_page" # atTable, atPagination (calculate number of pages) -irk_list = "list" # atTable, atPagination # external reserved keywords # table @@ -27,8 +25,11 @@ class AngularTableManager constructor: () -> @mappings = {} + get_table_configuration: (id) -> + @mappings[id].table_configuration + register_table: (table_configuration) -> - mapping = @mappings[table_configuration.get_id()] ||= {} + mapping = @mappings[table_configuration.id] ||= {} mapping.table_configuration = table_configuration @@ -38,21 +39,29 @@ class AngularTableManager register_table_scope: (id, scope) -> @mappings[id].table_scope = scope + tc = @mappings[id].table_configuration + + if tc.initial_items_per_page + scope.$parent[tc.items_per_page] = tc.initial_items_per_page + + if tc.initial_sort_context + scope.$parent[tc.sort_context] = tc.initial_sort_context + + if tc.initial_fill_last_page + scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page + register_pagination: (id, pagination_scope) -> mapping = @mappings[id] ||= {} mapping.pagination_scope = pagination_scope if mapping.table_configuration - pagination_scope[irk_list] = mapping.table_configuration.get_list() - pagination_scope.$watch(irk_current_page, () -> ts = mapping.table_scope ts[irk_current_page] = pagination_scope[irk_current_page] - ts[irk_items_per_page] = pagination_scope[irk_items_per_page] ts[irk_number_of_pages] = pagination_scope[irk_number_of_pages] - ts[irk_from_page] = calculate_from_page(ts[irk_items_per_page], + ts[irk_from_page] = calculate_from_page(ts[mapping.table_configuration.items_per_page], ts[irk_current_page], - ts[mapping.table_configuration.get_list()]) + ts[mapping.table_configuration.list]) ) angular.module("angular-table").service "angularTableManager", [() -> @@ -63,8 +72,8 @@ angular.module("angular-table").directive "atTable", ["$filter", "angularTableMa { restrict: "AC" scope: true - controller: ["$scope", "$element", "$attrs", "angularTableManager", - ($scope, $element, $attrs, angularTableManager) -> + controller: ["$scope", "$element", "$attrs", + ($scope, $element, $attrs) -> id = $attrs["id"] if id angularTableManager.register_table_scope(id, $scope) diff --git a/coffee/pagination_table_setup.coffee b/coffee/pagination_table_setup.coffee index 5a57234..e285b22 100644 --- a/coffee/pagination_table_setup.coffee +++ b/coffee/pagination_table_setup.coffee @@ -1,64 +1,51 @@ class PaginationTableSetup extends TableSetup - evaluate_repeat_expression: () -> - option = { - "global": "#{@orderByExpression} #{@limitToExpression}", - "page": "#{@limitToExpression} #{@orderByExpression}" - }[@sortContext] - - throw "Invalid sort-context: #{@sortContext}." unless option - @repeatString = "item in #{@list_name} #{option}" - constructor: (attributes, table_configuration) -> - @sortContext = attributes.atSortContext || "global" - @list_name = attributes.atList - @fillLastPage = attributes.atFillLastPage - @evaluate_repeat_expression() - @table_configuration = table_configuration - @limit_to_expression = "limitTo:#{irk_from_page} | limitTo:#{@table_configuration.get_items_per_page()}" - - # console.log @limit_to_expression + @repeatString = "item in filtered_list()" compile: (element, attributes, transclude) -> tbody = @setupTr(element, @repeatString) - if typeof @fillLastPage != "undefined" - tds = element.find("td") - tdString = "" - for td in tds - tdString += " " + tds = element.find("td") + tdString = "" + for td in tds + tdString += " " - fillerTr = angular.element(document.createElement("tr")) - fillerTr.html(tdString) - fillerTr.attr("ng-repeat", "item in getFillerArray() ") + # TODO + fillerTr = angular.element(document.createElement("tr")) + fillerTr.attr("ng-show", @table_configuration.fill_last_page) + fillerTr.html(tdString) + fillerTr.attr("ng-repeat", "item in getFillerArray() ") - tbody.append(fillerTr) + tbody.append(fillerTr) return link: ($scope, $element, $attributes, $filter) -> - list_name = @list_name - limitToExpression = @limitToExpression + list_name = @table_configuration.list + ipp = @table_configuration.items_per_page + sc = @table_configuration.sort_context $scope.filtered_list = () -> - # console.log $scope.predicate - val = $filter("orderBy")($scope[list_name], $scope.predicate) + val = $scope[list_name] - console.log limitToExpression - val = $filter("limitTo")(val, limitToExpression) - console.log val + if $scope[sc] == "global" + val = $filter("orderBy")(val, $scope.predicate, $scope.descending) + val = $filter("limitTo")(val, $scope[irk_from_page]) + val = $filter("limitTo")(val, $scope[ipp]) + else + val = $filter("limitTo")(val, $scope[irk_from_page]) + val = $filter("limitTo")(val, $scope[ipp]) + val = $filter("orderBy")(val, $scope.predicate, $scope.descending) return val - $scope.getFillerArray = () -> if $scope[irk_current_page] == $scope[irk_number_of_pages] - 1 - itemCountOnLastPage = $scope[list_name].length % $scope[irk_items_per_page] + itemCountOnLastPage = $scope[list_name].length % $scope[ipp] if itemCountOnLastPage != 0 || $scope[list_name].length == 0 - fillerLength = $scope[irk_items_per_page] - itemCountOnLastPage - 1 + fillerLength = $scope[ipp] - itemCountOnLastPage - 1 x for x in [($scope[list_name].length)..($scope[list_name].length + fillerLength)] else - [] - - return + [] \ No newline at end of file diff --git a/coffee/standard_table_setup.coffee b/coffee/standard_table_setup.coffee index 91e359f..5159cdb 100644 --- a/coffee/standard_table_setup.coffee +++ b/coffee/standard_table_setup.coffee @@ -1,6 +1,6 @@ class StandardTableSetup extends TableSetup constructor: (attributes) -> - @repeatString = "item in #{attributes.atList} #{@orderByExpression}" + @repeatString = "item in #{attributes.atList} | orderBy:predicate:descending" compile: (element, attributes, transclude) -> @setupTr(element, @repeatString) diff --git a/coffee/table_configuration.coffee b/coffee/table_configuration.coffee index f25eedf..8edeaf5 100644 --- a/coffee/table_configuration.coffee +++ b/coffee/table_configuration.coffee @@ -1,40 +1,43 @@ class TableConfiguration register_items_per_page: (items_per_page) -> - n = parseInt(items_per_page) - if angular.isNumber(n) + if isNaN(items_per_page) + @items_per_page = items_per_page + else @items_per_page = "#{@id}_itemsPerPage" - # @scope.$parent[@items_per_page] = n + @initial_items_per_page = parseInt(items_per_page) + + register_sort_context: (sort_context) -> + if sort_context != undefined + if sort_context == "global" + @sort_context = "#{@id}_sortContext" + @initial_sort_context = "global" + else if sort_context == "page" + @sort_context = "#{@id}_sortContext" + @initial_sort_context = "page" + else + @sort_context = sort_context else - @items_per_page = items_per_page + @sort_context = "#{@id}_sortContext" + @initial_sort_context = "global" + + register_fill_last_page: (fill_last_page) -> + if fill_last_page != undefined + if fill_last_page == "true" + @fill_last_page = "#{@id}_fillLastPage" + @initial_fill_last_page = true + else if fill_last_page == "false" + @fill_last_page = "#{@id}_fillLastPage" + @initial_fill_last_page = false + else if fill_last_page == "" + @fill_last_page = "#{@id}_fillLastPage" + @initial_fill_last_page = true + else + @fill_last_page = fill_last_page constructor: (attributes) -> - # console.log $scope - # @scope = $scope @id = attributes.id @list = attributes[erk_list] - @fill_last_page = attributes[erk_fill_last_page] - @register_items_per_page(attributes[erk_items_per_page]) if attributes[erk_items_per_page] - - @sort_context = attributes[erk_sort_context] - - # get_scope: () -> - # @scope - - get_id: () -> - @id - - get_list: () -> - @list - - get_fill_last_page: () -> - @fill_last_page - - get_items_per_page: () -> - @items_per_page - - get_sort_context: () -> - @sort_context - -new TableConfiguration({}, {}) \ No newline at end of file + @register_sort_context(attributes[erk_sort_context]) + @register_fill_last_page(attributes[erk_fill_last_page]) diff --git a/coffee/table_setup.coffee b/coffee/table_setup.coffee index 6f6c67d..065ab8d 100644 --- a/coffee/table_setup.coffee +++ b/coffee/table_setup.coffee @@ -1,10 +1,5 @@ class TableSetup - orderByExpression: "| orderBy:predicate:descending" - limitToExpression: "| limitTo:#{irk_from_page} | limitTo:#{irk_items_per_page}" - - constructor: () -> - setupTr: (element, repeatString) -> tbody = element.find "tbody" tr = tbody.find "tr" diff --git a/test/templates/pagination/pagination.html b/test/templates/pagination/pagination.html index eb9d9c3..dea76b0 100644 --- a/test/templates/pagination/pagination.html +++ b/test/templates/pagination/pagination.html @@ -7,4 +7,4 @@ - + diff --git a/test/templates/pagination/sort_context_global.html b/test/templates/pagination/sort_context_global.html index 30cd710..5f2da97 100644 --- a/test/templates/pagination/sort_context_global.html +++ b/test/templates/pagination/sort_context_global.html @@ -7,4 +7,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/test/templates/pagination/sort_context_page.html b/test/templates/pagination/sort_context_page.html index eda407e..c491d0f 100644 --- a/test/templates/pagination/sort_context_page.html +++ b/test/templates/pagination/sort_context_page.html @@ -7,4 +7,4 @@ - \ No newline at end of file + \ No newline at end of file From d8357d5cd4d04f41eab3be5938b28c32398e19be Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 12 Feb 2014 14:28:15 +0100 Subject: [PATCH 054/190] compiled new version --- angular-table.js | 246 +++++++++++--------- angular-table.min.js | 2 +- gem/app/assets/javascripts/angular-table.js | 246 +++++++++++--------- 3 files changed, 265 insertions(+), 229 deletions(-) diff --git a/angular-table.js b/angular-table.js index c45b4ec..975a1c6 100644 --- a/angular-table.js +++ b/angular-table.js @@ -3,7 +3,7 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var AngularTableManager, ColumnConfiguration, DeclarativeTable, PaginationTableSetup, StandardTableSetup, Table, TableConfiguration, TableSetup, TableToPaginationMapping, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_items_per_page, irk_list, irk_number_of_pages, + var AngularTableManager, ColumnConfiguration, DeclarativeTable, PaginationTableSetup, StandardTableSetup, Table, TableConfiguration, TableSetup, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -15,10 +15,6 @@ irk_number_of_pages = "number_of_pages"; - irk_items_per_page = "items_per_page"; - - irk_list = "list"; - erk_list = "atList"; erk_items_per_page = "atItemsPerPage"; @@ -39,48 +35,50 @@ } }; - TableToPaginationMapping = (function() { - function TableToPaginationMapping() { - this.table_scope = void 0; - this.pagination_scope = void 0; - this.list = void 0; - } - - return TableToPaginationMapping; - - })(); - AngularTableManager = (function() { function AngularTableManager() { this.mappings = {}; } + AngularTableManager.prototype.get_table_configuration = function(id) { + return this.mappings[id].table_configuration; + }; + AngularTableManager.prototype.register_table = function(table_configuration) { var mapping, _base, _name; - mapping = (_base = this.mappings)[_name = table_configuration.get_id()] || (_base[_name] = new TableToPaginationMapping()); + mapping = (_base = this.mappings)[_name = table_configuration.id] || (_base[_name] = {}); mapping.table_configuration = table_configuration; if (mapping.pagination_scope) { throw "WHOOPS"; } }; + AngularTableManager.prototype.register_table_scope = function(id, scope) { + var tc; + this.mappings[id].table_scope = scope; + tc = this.mappings[id].table_configuration; + if (tc.initial_items_per_page) { + scope.$parent[tc.items_per_page] = tc.initial_items_per_page; + } + if (tc.initial_sort_context) { + scope.$parent[tc.sort_context] = tc.initial_sort_context; + } + if (tc.initial_fill_last_page) { + return scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page; + } + }; + AngularTableManager.prototype.register_pagination = function(id, pagination_scope) { var mapping, _base; - mapping = (_base = this.mappings)[id] || (_base[id] = new TableToPaginationMapping()); + mapping = (_base = this.mappings)[id] || (_base[id] = {}); mapping.pagination_scope = pagination_scope; - pagination_scope.$watch("vari", function() { - return console.log("it changed lol: ", pagination_scope.vari); - }); - mapping.table_configuration.get_scope().$parent.vari = "hello"; if (mapping.table_configuration) { - pagination_scope[irk_list] = mapping.table_configuration.get_list(); return pagination_scope.$watch(irk_current_page, function() { var ts; - ts = mapping.table_configuration.get_scope(); + ts = mapping.table_scope; ts[irk_current_page] = pagination_scope[irk_current_page]; - ts[irk_items_per_page] = pagination_scope[irk_items_per_page]; ts[irk_number_of_pages] = pagination_scope[irk_number_of_pages]; - return ts[irk_from_page] = calculate_from_page(ts[irk_items_per_page], ts[irk_current_page], ts[mapping.table_configuration.get_list()]); + return ts[irk_from_page] = calculate_from_page(ts[mapping.table_configuration.items_per_page], ts[irk_current_page], ts[mapping.table_configuration.list]); }); } }; @@ -96,24 +94,28 @@ ]); angular.module("angular-table").directive("atTable", [ - function() { + "$filter", "angularTableManager", function($filter, angularTableManager) { return { restrict: "AC", scope: true, controller: [ - "$scope", "$element", "$attrs", "angularTableManager", function($scope, $element, $attrs, angularTableManager) { - var tc; - tc = new TableConfiguration($scope, $attrs); - return angularTableManager.register_table(tc); + "$scope", "$element", "$attrs", function($scope, $element, $attrs) { + var id; + id = $attrs["id"]; + if (id) { + return angularTableManager.register_table_scope(id, $scope); + } } ], compile: function(element, attributes, transclude) { - var dt; - dt = new DeclarativeTable(element, attributes); + var dt, tc; + tc = new TableConfiguration(attributes); + angularTableManager.register_table(tc); + dt = new DeclarativeTable(element, attributes, tc); dt.compile(); return { post: function($scope, $element, $attributes) { - return dt.post($scope, $element, $attributes); + return dt.post($scope, $element, $attributes, $filter); } }; } @@ -138,30 +140,30 @@ ]); angular.module("angular-table").directive("atPagination", [ - function() { + "angularTableManager", function(angularTableManager) { return { replace: true, restrict: "E", template: " ", controller: [ - "$scope", "$element", "$attrs", "angularTableManager", function($scope, $element, $attrs, angularTableManager) { + "$scope", "$element", "$attrs", "angularTableManager", function($scope, $element, $attrs) { return angularTableManager.register_pagination($attrs.atTableId, $scope); } ], scope: true, link: function($scope, $element, $attributes) { - var get_list, normalizePage, update; - $scope[irk_items_per_page] = $attributes.atItemsPerPage; + var get_list, normalizePage, tc, update; + tc = angularTableManager.get_table_configuration($attributes.atTableId); $scope[irk_current_page] = 0; get_list = function() { - return $scope[$scope[irk_list]]; + return $scope[tc.list]; }; update = function(reset) { var x; $scope[irk_current_page] = 0; if (get_list()) { if (get_list().length > 0) { - $scope[irk_number_of_pages] = Math.ceil(get_list().length / $scope[irk_items_per_page]); + $scope[irk_number_of_pages] = Math.ceil(get_list().length / $scope[tc.items_per_page]); return $scope.pages = (function() { var _i, _ref, _results; _results = []; @@ -185,7 +187,7 @@ return $scope[irk_current_page] = normalizePage(page); }; update(); - $scope.$watch(irk_items_per_page, function() { + $scope.$watch(tc.items_per_page, function() { return update(); }); return $scope.$watch("atList", function() { @@ -232,7 +234,7 @@ return new StandardTableSetup(attributes); } if (attributes.atList && attributes.atPagination) { - return new PaginationTableSetup(attributes); + return new PaginationTableSetup(attributes, this.table_configuration); } }; @@ -260,7 +262,7 @@ return _results; }; - Table.prototype.post = function($scope, $element, $attributes) { + Table.prototype.post = function($scope, $element, $attributes, $filter) { this.setup_initial_sorting($scope); $scope.getSortIcon = function(predicate) { if (predicate !== $scope.predicate) { @@ -272,7 +274,7 @@ return "icon-chevron-up"; } }; - return this.setup.link($scope, $element, $attributes); + return this.setup.link($scope, $element, $attributes, $filter); }; return Table; @@ -280,10 +282,6 @@ })(); TableSetup = (function() { - TableSetup.prototype.orderByExpression = "| orderBy:predicate:descending"; - - TableSetup.prototype.limitToExpression = "| limitTo:" + irk_from_page + " | limitTo:" + irk_items_per_page; - function TableSetup() {} TableSetup.prototype.setupTr = function(element, repeatString) { @@ -299,45 +297,63 @@ })(); TableConfiguration = (function() { - function TableConfiguration($scope, attributes) { - this.scope = $scope; - this.id = attributes.id; - this.list = attributes[erk_list]; - this.fill_last_page = attributes[erk_fill_last_page]; - this.items_per_page = attributes[erk_items_per_page]; - this.sort_context = attributes[erk_sort_context]; - } - - TableConfiguration.prototype.get_scope = function() { - return this.scope; - }; - - TableConfiguration.prototype.get_id = function() { - return this.id; - }; - - TableConfiguration.prototype.get_list = function() { - return this.list; + TableConfiguration.prototype.register_items_per_page = function(items_per_page) { + if (isNaN(items_per_page)) { + return this.items_per_page = items_per_page; + } else { + this.items_per_page = "" + this.id + "_itemsPerPage"; + return this.initial_items_per_page = parseInt(items_per_page); + } }; - TableConfiguration.prototype.get_fill_last_page = function() { - return this.fill_last_page; + TableConfiguration.prototype.register_sort_context = function(sort_context) { + if (sort_context !== void 0) { + if (sort_context === "global") { + this.sort_context = "" + this.id + "_sortContext"; + return this.initial_sort_context = "global"; + } else if (sort_context === "page") { + this.sort_context = "" + this.id + "_sortContext"; + return this.initial_sort_context = "page"; + } else { + return this.sort_context = sort_context; + } + } else { + this.sort_context = "" + this.id + "_sortContext"; + return this.initial_sort_context = "global"; + } }; - TableConfiguration.prototype.get_items_per_page = function() { - return this.items_per_page; + TableConfiguration.prototype.register_fill_last_page = function(fill_last_page) { + if (fill_last_page !== void 0) { + if (fill_last_page === "true") { + this.fill_last_page = "" + this.id + "_fillLastPage"; + return this.initial_fill_last_page = true; + } else if (fill_last_page === "false") { + this.fill_last_page = "" + this.id + "_fillLastPage"; + return this.initial_fill_last_page = false; + } else if (fill_last_page === "") { + this.fill_last_page = "" + this.id + "_fillLastPage"; + return this.initial_fill_last_page = true; + } else { + return this.fill_last_page = fill_last_page; + } + } }; - TableConfiguration.prototype.get_sort_context = function() { - return this.sort_context; - }; + function TableConfiguration(attributes) { + this.id = attributes.id; + this.list = attributes[erk_list]; + if (attributes[erk_items_per_page]) { + this.register_items_per_page(attributes[erk_items_per_page]); + } + this.register_sort_context(attributes[erk_sort_context]); + this.register_fill_last_page(attributes[erk_fill_last_page]); + } return TableConfiguration; })(); - new TableConfiguration({}, {}); - ColumnConfiguration = (function() { function ColumnConfiguration(body_markup, header_markup) { this.attribute = body_markup.attribute; @@ -405,9 +421,10 @@ DeclarativeTable = (function(_super) { __extends(DeclarativeTable, _super); - function DeclarativeTable(element, attributes) { + function DeclarativeTable(element, attributes, table_configuration) { this.element = element; this.attributes = attributes; + this.table_configuration = table_configuration; } DeclarativeTable.prototype.capitaliseFirstLetter = function(string) { @@ -517,7 +534,7 @@ __extends(StandardTableSetup, _super); function StandardTableSetup(attributes) { - this.repeatString = "item in " + attributes.atList + " " + this.orderByExpression; + this.repeatString = "item in " + attributes.atList + " | orderBy:predicate:descending"; } StandardTableSetup.prototype.compile = function(element, attributes, transclude) { @@ -533,51 +550,52 @@ PaginationTableSetup = (function(_super) { __extends(PaginationTableSetup, _super); - PaginationTableSetup.prototype.evaluate_repeat_expression = function() { - var option; - option = { - "global": "" + this.orderByExpression + " " + this.limitToExpression, - "page": "" + this.limitToExpression + " " + this.orderByExpression - }[this.sortContext]; - if (!option) { - throw "Invalid sort-context: " + this.sortContext + "."; - } - return this.repeatString = "item in " + this.list_name + " " + option; - }; - - function PaginationTableSetup(attributes) { - this.sortContext = attributes.atSortContext || "global"; - this.list_name = attributes.atList; - this.fillLastPage = attributes.atFillLastPage; - this.evaluate_repeat_expression(); + function PaginationTableSetup(attributes, table_configuration) { + this.table_configuration = table_configuration; + this.repeatString = "item in filtered_list()"; } PaginationTableSetup.prototype.compile = function(element, attributes, transclude) { var fillerTr, tbody, td, tdString, tds, _i, _len; tbody = this.setupTr(element, this.repeatString); - if (typeof this.fillLastPage !== "undefined") { - tds = element.find("td"); - tdString = ""; - for (_i = 0, _len = tds.length; _i < _len; _i++) { - td = tds[_i]; - tdString += " "; - } - fillerTr = angular.element(document.createElement("tr")); - fillerTr.html(tdString); - fillerTr.attr("ng-repeat", "item in getFillerArray() "); - tbody.append(fillerTr); + tds = element.find("td"); + tdString = ""; + for (_i = 0, _len = tds.length; _i < _len; _i++) { + td = tds[_i]; + tdString += " "; } - }; - - PaginationTableSetup.prototype.link = function($scope, $element, $attributes) { - var list_name; - list_name = this.list_name; - $scope.getFillerArray = function() { + fillerTr = angular.element(document.createElement("tr")); + fillerTr.attr("ng-show", this.table_configuration.fill_last_page); + fillerTr.html(tdString); + fillerTr.attr("ng-repeat", "item in getFillerArray() "); + tbody.append(fillerTr); + }; + + PaginationTableSetup.prototype.link = function($scope, $element, $attributes, $filter) { + var ipp, list_name, sc; + list_name = this.table_configuration.list; + ipp = this.table_configuration.items_per_page; + sc = this.table_configuration.sort_context; + $scope.filtered_list = function() { + var val; + val = $scope[list_name]; + if ($scope[sc] === "global") { + val = $filter("orderBy")(val, $scope.predicate, $scope.descending); + val = $filter("limitTo")(val, $scope[irk_from_page]); + val = $filter("limitTo")(val, $scope[ipp]); + } else { + val = $filter("limitTo")(val, $scope[irk_from_page]); + val = $filter("limitTo")(val, $scope[ipp]); + val = $filter("orderBy")(val, $scope.predicate, $scope.descending); + } + return val; + }; + return $scope.getFillerArray = function() { var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; if ($scope[irk_current_page] === $scope[irk_number_of_pages] - 1) { - itemCountOnLastPage = $scope[list_name].length % $scope[irk_items_per_page]; + itemCountOnLastPage = $scope[list_name].length % $scope[ipp]; if (itemCountOnLastPage !== 0 || $scope[list_name].length === 0) { - fillerLength = $scope[irk_items_per_page] - itemCountOnLastPage - 1; + fillerLength = $scope[ipp] - itemCountOnLastPage - 1; _results = []; for (x = _i = _ref = $scope[list_name].length, _ref1 = $scope[list_name].length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { _results.push(x); diff --git a/angular-table.min.js b/angular-table.min.js index 2b230c9..185d101 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,o,a,s,u,l,c,p,g,h,f,_,d,m,b,v,y,w,x={}.hasOwnProperty,S=function(t,e){function i(){this.constructor=t}for(var n in e)x.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};angular.module("angular-table",[]),b="from_page",m="current_page",w="number_of_pages",v="items_per_page",y="list",f="atList",h="atItemsPerPage",p="atFillLastPage",_="atSortContext",c="at-attribute",d="at-sortable",g="at-initial-sorting",l=function(t,e,i){return i?t*e-i.length:void 0},u=function(){function t(){this.table_scope=void 0,this.pagination_scope=void 0,this.list=void 0}return t}(),t=function(){function t(){this.mappings={}}return t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.get_id()]||(i[n]=new u),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_pagination=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]=new u),i.pagination_scope=e,e.$watch("vari",function(){return console.log("it changed lol: ",e.vari)}),i.table_configuration.get_scope().$parent.vari="hello",i.table_configuration?(e[y]=i.table_configuration.get_list(),e.$watch(m,function(){var t;return t=i.table_configuration.get_scope(),t[m]=e[m],t[v]=e[v],t[w]=e[w],t[b]=l(t[v],t[m],t[i.table_configuration.get_list()])})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",[function(){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs","angularTableManager",function(t,e,i,n){var r;return r=new a(t,i),n.register_table(r)}],compile:function(t,e){var n;return n=new i(t,e),n.compile(),{post:function(t,e,i){return n.post(t,e,i)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",[function(){return{replace:!0,restrict:"E",template:" ",controller:["$scope","$element","$attrs","angularTableManager",function(t,e,i,n){return n.register_pagination(i.atTableId,t)}],scope:!0,link:function(t,e,i){var n,r,o;return t[v]=i.atItemsPerPage,t[m]=0,n=function(){return t[t[y]]},o=function(){var e;return t[m]=0,n()?n().length>0?(t[w]=Math.ceil(n().length/t[v]),t.pages=function(){var i,n,r;for(r=[],e=i=0,n=t[w]-1;n>=0?n>=i:i>=n;e=n>=0?++i:--i)r.push(e);return r}()):(t[w]=1,t.pages=[0]):void 0},r=function(e){return e=Math.max(0,e),e=Math.min(t[w]-1,e)},t.go_to_page=function(e){return t[m]=r(e)},o(),t.$watch(v,function(){return o()}),t.$watch("atList",function(){return o()})}}}]),o=function(){function t(){}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.get_column_configurations(),i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.validateInput=function(){if(!this.attributes.atPagination&&!this.attributes.atList)throw"Either a list or Pagination must be specified."},t.prototype.create_table_setup=function(t){return t.atList&&!t.atPagination?new r(t):t.atList&&t.atPagination?new n(t):void 0},t.prototype.compile=function(){return this.validateInput(),this.setup_header(),this.setup=this.create_table_setup(this.attributes),this.setup.compile(this.element,this.attributes)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,o;for(r=this.get_column_configurations(),o=[],i=0,n=r.length;n>i;i++){if(e=r[i],e.initialSorting&&!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,o.push(t.descending="desc"===e.initialSorting)}return o},t.prototype.post=function(t,e,i){return this.setup_initial_sorting(t),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},this.setup.link(t,e,i)},t}(),s=function(){function t(){}return t.prototype.orderByExpression="| orderBy:predicate:descending",t.prototype.limitToExpression="| limitTo:"+b+" | limitTo:"+v,t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),a=function(){function t(t,e){this.scope=t,this.id=e.id,this.list=e[f],this.fill_last_page=e[p],this.items_per_page=e[h],this.sort_context=e[_]}return t.prototype.get_scope=function(){return this.scope},t.prototype.get_id=function(){return this.id},t.prototype.get_list=function(){return this.list},t.prototype.get_fill_last_page=function(){return this.fill_last_page},t.prototype.get_items_per_page=function(){return this.items_per_page},t.prototype.get_sort_context=function(){return this.sort_context},t}(),new a({},{}),e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,o;if(this.custom_content){for(r=this.attributes,o=[],i=0,n=r.length;n>i;i++)e=r[i],o.push(t.attr(e.name,e.value));return o}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"')"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),i=function(t){function i(t,e){this.element=t,this.attributes=e}return S(i,t),i.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},i.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},i.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},i.prototype.collect_header_markup=function(t){var e,i,n,r,o,a;for(e={},n=t.find("tr"),a=n.find("th"),r=0,o=a.length;o>r;r++)i=a[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},i.prototype.collect_body_markup=function(t){var e,i,n,r,o,a,s,u,l,c;for(i=[],c=t.find("td"),u=0,l=c.length;l>u;u++)o=c[u],o=angular.element(o),e=o.attr("at-attribute"),a=o.attr("at-title")||this.capitaliseFirstLetter(o.attr("at-attribute")),r=void 0!==o.attr("at-sortable")||this.isSortable(o.attr("class")),s=this.extractWidth(o.attr("class")),n=this.getInitialSorting(o),i.push({attribute:e,title:a,sortable:r,width:s,initialSorting:n});return i},i.prototype.create_column_configurations=function(){var t,i,n,r,o,a;for(n=this.collect_header_markup(this.element),t=this.collect_body_markup(this.element),i=[],o=0,a=t.length;a>o;o++)r=t[o],i.push(new e(r,n[r.attribute]));return i},i.prototype.get_column_configurations=function(){return this.column_configurations||(this.column_configurations=this.create_column_configurations())},i.prototype.create_table_configuration=function(){},i.prototype.get_table_configuration=function(){},i}(o),r=function(t){function e(t){this.repeatString="item in "+t.atList+" "+this.orderByExpression}return S(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(s),n=function(t){function e(t){this.sortContext=t.atSortContext||"global",this.list_name=t.atList,this.fillLastPage=t.atFillLastPage,this.evaluate_repeat_expression()}return S(e,t),e.prototype.evaluate_repeat_expression=function(){var t;if(t={global:""+this.orderByExpression+" "+this.limitToExpression,page:""+this.limitToExpression+" "+this.orderByExpression}[this.sortContext],!t)throw"Invalid sort-context: "+this.sortContext+".";return this.repeatString="item in "+this.list_name+" "+t},e.prototype.compile=function(t){var e,i,n,r,o,a,s;if(i=this.setupTr(t,this.repeatString),"undefined"!=typeof this.fillLastPage){for(o=t.find("td"),r="",a=0,s=o.length;s>a;a++)n=o[a],r+=" ";e=angular.element(document.createElement("tr")),e.html(r),e.attr("ng-repeat","item in getFillerArray() "),i.append(e)}},e.prototype.link=function(t){var e;e=this.list_name,t.getFillerArray=function(){var i,n,r,o,a,s,u;if(t[m]===t[w]-1){if(n=t[e].length%t[v],0!==n||0===t[e].length){for(i=t[v]-n-1,u=[],r=o=a=t[e].length,s=t[e].length+i;s>=a?s>=o:o>=s;r=s>=a?++o:--o)u.push(r);return u}return[]}}},e}(s)}).call(this); \ No newline at end of file +(function(){var t,e,i,n,r,a,o,s,l,u,c,p,g,_,h,f,d,m,b,v={}.hasOwnProperty,y=function(t,e){function i(){this.constructor=t}for(var n in e)v.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};angular.module("angular-table",[]),m="from_page",d="current_page",b="number_of_pages",_="atList",g="atItemsPerPage",c="atFillLastPage",h="atSortContext",u="at-attribute",f="at-sortable",p="at-initial-sorting",l=function(t,e,i){return i?t*e-i.length:void 0},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page?e.$parent[i.fill_last_page]=i.initial_fill_last_page:void 0},t.prototype.register_pagination=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?e.$watch(d,function(){var t;return t=i.table_scope,t[d]=e[d],t[b]=e[b],t[m]=l(t[i.table_configuration.items_per_page],t[d],t[i.table_configuration.list])}):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(t,i,n){var r;return r=n.id,r?e.register_table_scope(r,t):void 0}],compile:function(n,r){var a,s;return s=new o(r),e.register_table(s),a=new i(n,r,s),a.compile(),{post:function(e,i,n){return a.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:" ",controller:["$scope","$element","$attrs","angularTableManager",function(e,i,n){return t.register_pagination(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s;return o=t.get_table_configuration(n.atTableId),e[d]=0,r=function(){return e[o.list]},s=function(){var t;return e[d]=0,r()?r().length>0?(e[b]=Math.ceil(r().length/e[o.items_per_page]),e.pages=function(){var i,n,r;for(r=[],t=i=0,n=e[b]-1;n>=0?n>=i:i>=n;t=n>=0?++i:--i)r.push(t);return r}()):(e[b]=1,e.pages=[0]):void 0},a=function(t){return t=Math.max(0,t),t=Math.min(e[b]-1,t)},e.go_to_page=function(t){return e[d]=a(t)},s(),e.$watch(o.items_per_page,function(){return s()}),e.$watch("atList",function(){return s()})}}}]),a=function(){function t(){}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.get_column_configurations(),i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.validateInput=function(){if(!this.attributes.atPagination&&!this.attributes.atList)throw"Either a list or Pagination must be specified."},t.prototype.create_table_setup=function(t){return t.atList&&!t.atPagination?new r(t):t.atList&&t.atPagination?new n(t,this.table_configuration):void 0},t.prototype.compile=function(){return this.validateInput(),this.setup_header(),this.setup=this.create_table_setup(this.attributes),this.setup.compile(this.element,this.attributes)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.get_column_configurations(),a=[],i=0,n=r.length;n>i;i++){if(e=r[i],e.initialSorting&&!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},this.setup.link(t,e,i,n)},t}(),s=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),o=function(){function t(t){this.id=t.id,this.list=t[_],t[g]&&this.register_items_per_page(t[g]),this.register_sort_context(t[h]),this.register_fill_last_page(t[c])}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t}(),e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"')"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),i=function(t){function i(t,e,i){this.element=t,this.attributes=e,this.table_configuration=i}return y(i,t),i.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},i.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},i.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},i.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},i.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,c;for(i=[],c=t.find("td"),l=0,u=c.length;u>l;l++)a=c[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},i.prototype.create_column_configurations=function(){var t,i,n,r,a,o;for(n=this.collect_header_markup(this.element),t=this.collect_body_markup(this.element),i=[],a=0,o=t.length;o>a;a++)r=t[a],i.push(new e(r,n[r.attribute]));return i},i.prototype.get_column_configurations=function(){return this.column_configurations||(this.column_configurations=this.create_column_configurations())},i.prototype.create_table_configuration=function(){},i.prototype.get_table_configuration=function(){},i}(a),r=function(t){function e(t){this.repeatString="item in "+t.atList+" | orderBy:predicate:descending"}return y(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(s),n=function(t){function e(t,e){this.table_configuration=e,this.repeatString="item in filtered_list()"}return y(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+=" ";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in getFillerArray() "),i.append(e)},e.prototype.link=function(t,e,i,n){var r,a,o;return a=this.table_configuration.list,r=this.table_configuration.items_per_page,o=this.table_configuration.sort_context,t.filtered_list=function(){var e;return e=t[a],"global"===t[o]?(e=n("orderBy")(e,t.predicate,t.descending),e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r])):(e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r]),e=n("orderBy")(e,t.predicate,t.descending)),e},t.getFillerArray=function(){var e,i,n,o,s,l,u;if(t[d]===t[b]-1){if(i=t[a].length%t[r],0!==i||0===t[a].length){for(e=t[r]-i-1,u=[],n=o=s=t[a].length,l=t[a].length+e;l>=s?l>=o:o>=l;n=l>=s?++o:--o)u.push(n);return u}return[]}}},e}(s)}).call(this); \ No newline at end of file diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index c45b4ec..975a1c6 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -3,7 +3,7 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var AngularTableManager, ColumnConfiguration, DeclarativeTable, PaginationTableSetup, StandardTableSetup, Table, TableConfiguration, TableSetup, TableToPaginationMapping, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_items_per_page, irk_list, irk_number_of_pages, + var AngularTableManager, ColumnConfiguration, DeclarativeTable, PaginationTableSetup, StandardTableSetup, Table, TableConfiguration, TableSetup, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -15,10 +15,6 @@ irk_number_of_pages = "number_of_pages"; - irk_items_per_page = "items_per_page"; - - irk_list = "list"; - erk_list = "atList"; erk_items_per_page = "atItemsPerPage"; @@ -39,48 +35,50 @@ } }; - TableToPaginationMapping = (function() { - function TableToPaginationMapping() { - this.table_scope = void 0; - this.pagination_scope = void 0; - this.list = void 0; - } - - return TableToPaginationMapping; - - })(); - AngularTableManager = (function() { function AngularTableManager() { this.mappings = {}; } + AngularTableManager.prototype.get_table_configuration = function(id) { + return this.mappings[id].table_configuration; + }; + AngularTableManager.prototype.register_table = function(table_configuration) { var mapping, _base, _name; - mapping = (_base = this.mappings)[_name = table_configuration.get_id()] || (_base[_name] = new TableToPaginationMapping()); + mapping = (_base = this.mappings)[_name = table_configuration.id] || (_base[_name] = {}); mapping.table_configuration = table_configuration; if (mapping.pagination_scope) { throw "WHOOPS"; } }; + AngularTableManager.prototype.register_table_scope = function(id, scope) { + var tc; + this.mappings[id].table_scope = scope; + tc = this.mappings[id].table_configuration; + if (tc.initial_items_per_page) { + scope.$parent[tc.items_per_page] = tc.initial_items_per_page; + } + if (tc.initial_sort_context) { + scope.$parent[tc.sort_context] = tc.initial_sort_context; + } + if (tc.initial_fill_last_page) { + return scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page; + } + }; + AngularTableManager.prototype.register_pagination = function(id, pagination_scope) { var mapping, _base; - mapping = (_base = this.mappings)[id] || (_base[id] = new TableToPaginationMapping()); + mapping = (_base = this.mappings)[id] || (_base[id] = {}); mapping.pagination_scope = pagination_scope; - pagination_scope.$watch("vari", function() { - return console.log("it changed lol: ", pagination_scope.vari); - }); - mapping.table_configuration.get_scope().$parent.vari = "hello"; if (mapping.table_configuration) { - pagination_scope[irk_list] = mapping.table_configuration.get_list(); return pagination_scope.$watch(irk_current_page, function() { var ts; - ts = mapping.table_configuration.get_scope(); + ts = mapping.table_scope; ts[irk_current_page] = pagination_scope[irk_current_page]; - ts[irk_items_per_page] = pagination_scope[irk_items_per_page]; ts[irk_number_of_pages] = pagination_scope[irk_number_of_pages]; - return ts[irk_from_page] = calculate_from_page(ts[irk_items_per_page], ts[irk_current_page], ts[mapping.table_configuration.get_list()]); + return ts[irk_from_page] = calculate_from_page(ts[mapping.table_configuration.items_per_page], ts[irk_current_page], ts[mapping.table_configuration.list]); }); } }; @@ -96,24 +94,28 @@ ]); angular.module("angular-table").directive("atTable", [ - function() { + "$filter", "angularTableManager", function($filter, angularTableManager) { return { restrict: "AC", scope: true, controller: [ - "$scope", "$element", "$attrs", "angularTableManager", function($scope, $element, $attrs, angularTableManager) { - var tc; - tc = new TableConfiguration($scope, $attrs); - return angularTableManager.register_table(tc); + "$scope", "$element", "$attrs", function($scope, $element, $attrs) { + var id; + id = $attrs["id"]; + if (id) { + return angularTableManager.register_table_scope(id, $scope); + } } ], compile: function(element, attributes, transclude) { - var dt; - dt = new DeclarativeTable(element, attributes); + var dt, tc; + tc = new TableConfiguration(attributes); + angularTableManager.register_table(tc); + dt = new DeclarativeTable(element, attributes, tc); dt.compile(); return { post: function($scope, $element, $attributes) { - return dt.post($scope, $element, $attributes); + return dt.post($scope, $element, $attributes, $filter); } }; } @@ -138,30 +140,30 @@ ]); angular.module("angular-table").directive("atPagination", [ - function() { + "angularTableManager", function(angularTableManager) { return { replace: true, restrict: "E", template: " ", controller: [ - "$scope", "$element", "$attrs", "angularTableManager", function($scope, $element, $attrs, angularTableManager) { + "$scope", "$element", "$attrs", "angularTableManager", function($scope, $element, $attrs) { return angularTableManager.register_pagination($attrs.atTableId, $scope); } ], scope: true, link: function($scope, $element, $attributes) { - var get_list, normalizePage, update; - $scope[irk_items_per_page] = $attributes.atItemsPerPage; + var get_list, normalizePage, tc, update; + tc = angularTableManager.get_table_configuration($attributes.atTableId); $scope[irk_current_page] = 0; get_list = function() { - return $scope[$scope[irk_list]]; + return $scope[tc.list]; }; update = function(reset) { var x; $scope[irk_current_page] = 0; if (get_list()) { if (get_list().length > 0) { - $scope[irk_number_of_pages] = Math.ceil(get_list().length / $scope[irk_items_per_page]); + $scope[irk_number_of_pages] = Math.ceil(get_list().length / $scope[tc.items_per_page]); return $scope.pages = (function() { var _i, _ref, _results; _results = []; @@ -185,7 +187,7 @@ return $scope[irk_current_page] = normalizePage(page); }; update(); - $scope.$watch(irk_items_per_page, function() { + $scope.$watch(tc.items_per_page, function() { return update(); }); return $scope.$watch("atList", function() { @@ -232,7 +234,7 @@ return new StandardTableSetup(attributes); } if (attributes.atList && attributes.atPagination) { - return new PaginationTableSetup(attributes); + return new PaginationTableSetup(attributes, this.table_configuration); } }; @@ -260,7 +262,7 @@ return _results; }; - Table.prototype.post = function($scope, $element, $attributes) { + Table.prototype.post = function($scope, $element, $attributes, $filter) { this.setup_initial_sorting($scope); $scope.getSortIcon = function(predicate) { if (predicate !== $scope.predicate) { @@ -272,7 +274,7 @@ return "icon-chevron-up"; } }; - return this.setup.link($scope, $element, $attributes); + return this.setup.link($scope, $element, $attributes, $filter); }; return Table; @@ -280,10 +282,6 @@ })(); TableSetup = (function() { - TableSetup.prototype.orderByExpression = "| orderBy:predicate:descending"; - - TableSetup.prototype.limitToExpression = "| limitTo:" + irk_from_page + " | limitTo:" + irk_items_per_page; - function TableSetup() {} TableSetup.prototype.setupTr = function(element, repeatString) { @@ -299,45 +297,63 @@ })(); TableConfiguration = (function() { - function TableConfiguration($scope, attributes) { - this.scope = $scope; - this.id = attributes.id; - this.list = attributes[erk_list]; - this.fill_last_page = attributes[erk_fill_last_page]; - this.items_per_page = attributes[erk_items_per_page]; - this.sort_context = attributes[erk_sort_context]; - } - - TableConfiguration.prototype.get_scope = function() { - return this.scope; - }; - - TableConfiguration.prototype.get_id = function() { - return this.id; - }; - - TableConfiguration.prototype.get_list = function() { - return this.list; + TableConfiguration.prototype.register_items_per_page = function(items_per_page) { + if (isNaN(items_per_page)) { + return this.items_per_page = items_per_page; + } else { + this.items_per_page = "" + this.id + "_itemsPerPage"; + return this.initial_items_per_page = parseInt(items_per_page); + } }; - TableConfiguration.prototype.get_fill_last_page = function() { - return this.fill_last_page; + TableConfiguration.prototype.register_sort_context = function(sort_context) { + if (sort_context !== void 0) { + if (sort_context === "global") { + this.sort_context = "" + this.id + "_sortContext"; + return this.initial_sort_context = "global"; + } else if (sort_context === "page") { + this.sort_context = "" + this.id + "_sortContext"; + return this.initial_sort_context = "page"; + } else { + return this.sort_context = sort_context; + } + } else { + this.sort_context = "" + this.id + "_sortContext"; + return this.initial_sort_context = "global"; + } }; - TableConfiguration.prototype.get_items_per_page = function() { - return this.items_per_page; + TableConfiguration.prototype.register_fill_last_page = function(fill_last_page) { + if (fill_last_page !== void 0) { + if (fill_last_page === "true") { + this.fill_last_page = "" + this.id + "_fillLastPage"; + return this.initial_fill_last_page = true; + } else if (fill_last_page === "false") { + this.fill_last_page = "" + this.id + "_fillLastPage"; + return this.initial_fill_last_page = false; + } else if (fill_last_page === "") { + this.fill_last_page = "" + this.id + "_fillLastPage"; + return this.initial_fill_last_page = true; + } else { + return this.fill_last_page = fill_last_page; + } + } }; - TableConfiguration.prototype.get_sort_context = function() { - return this.sort_context; - }; + function TableConfiguration(attributes) { + this.id = attributes.id; + this.list = attributes[erk_list]; + if (attributes[erk_items_per_page]) { + this.register_items_per_page(attributes[erk_items_per_page]); + } + this.register_sort_context(attributes[erk_sort_context]); + this.register_fill_last_page(attributes[erk_fill_last_page]); + } return TableConfiguration; })(); - new TableConfiguration({}, {}); - ColumnConfiguration = (function() { function ColumnConfiguration(body_markup, header_markup) { this.attribute = body_markup.attribute; @@ -405,9 +421,10 @@ DeclarativeTable = (function(_super) { __extends(DeclarativeTable, _super); - function DeclarativeTable(element, attributes) { + function DeclarativeTable(element, attributes, table_configuration) { this.element = element; this.attributes = attributes; + this.table_configuration = table_configuration; } DeclarativeTable.prototype.capitaliseFirstLetter = function(string) { @@ -517,7 +534,7 @@ __extends(StandardTableSetup, _super); function StandardTableSetup(attributes) { - this.repeatString = "item in " + attributes.atList + " " + this.orderByExpression; + this.repeatString = "item in " + attributes.atList + " | orderBy:predicate:descending"; } StandardTableSetup.prototype.compile = function(element, attributes, transclude) { @@ -533,51 +550,52 @@ PaginationTableSetup = (function(_super) { __extends(PaginationTableSetup, _super); - PaginationTableSetup.prototype.evaluate_repeat_expression = function() { - var option; - option = { - "global": "" + this.orderByExpression + " " + this.limitToExpression, - "page": "" + this.limitToExpression + " " + this.orderByExpression - }[this.sortContext]; - if (!option) { - throw "Invalid sort-context: " + this.sortContext + "."; - } - return this.repeatString = "item in " + this.list_name + " " + option; - }; - - function PaginationTableSetup(attributes) { - this.sortContext = attributes.atSortContext || "global"; - this.list_name = attributes.atList; - this.fillLastPage = attributes.atFillLastPage; - this.evaluate_repeat_expression(); + function PaginationTableSetup(attributes, table_configuration) { + this.table_configuration = table_configuration; + this.repeatString = "item in filtered_list()"; } PaginationTableSetup.prototype.compile = function(element, attributes, transclude) { var fillerTr, tbody, td, tdString, tds, _i, _len; tbody = this.setupTr(element, this.repeatString); - if (typeof this.fillLastPage !== "undefined") { - tds = element.find("td"); - tdString = ""; - for (_i = 0, _len = tds.length; _i < _len; _i++) { - td = tds[_i]; - tdString += " "; - } - fillerTr = angular.element(document.createElement("tr")); - fillerTr.html(tdString); - fillerTr.attr("ng-repeat", "item in getFillerArray() "); - tbody.append(fillerTr); + tds = element.find("td"); + tdString = ""; + for (_i = 0, _len = tds.length; _i < _len; _i++) { + td = tds[_i]; + tdString += " "; } - }; - - PaginationTableSetup.prototype.link = function($scope, $element, $attributes) { - var list_name; - list_name = this.list_name; - $scope.getFillerArray = function() { + fillerTr = angular.element(document.createElement("tr")); + fillerTr.attr("ng-show", this.table_configuration.fill_last_page); + fillerTr.html(tdString); + fillerTr.attr("ng-repeat", "item in getFillerArray() "); + tbody.append(fillerTr); + }; + + PaginationTableSetup.prototype.link = function($scope, $element, $attributes, $filter) { + var ipp, list_name, sc; + list_name = this.table_configuration.list; + ipp = this.table_configuration.items_per_page; + sc = this.table_configuration.sort_context; + $scope.filtered_list = function() { + var val; + val = $scope[list_name]; + if ($scope[sc] === "global") { + val = $filter("orderBy")(val, $scope.predicate, $scope.descending); + val = $filter("limitTo")(val, $scope[irk_from_page]); + val = $filter("limitTo")(val, $scope[ipp]); + } else { + val = $filter("limitTo")(val, $scope[irk_from_page]); + val = $filter("limitTo")(val, $scope[ipp]); + val = $filter("orderBy")(val, $scope.predicate, $scope.descending); + } + return val; + }; + return $scope.getFillerArray = function() { var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; if ($scope[irk_current_page] === $scope[irk_number_of_pages] - 1) { - itemCountOnLastPage = $scope[list_name].length % $scope[irk_items_per_page]; + itemCountOnLastPage = $scope[list_name].length % $scope[ipp]; if (itemCountOnLastPage !== 0 || $scope[list_name].length === 0) { - fillerLength = $scope[irk_items_per_page] - itemCountOnLastPage - 1; + fillerLength = $scope[ipp] - itemCountOnLastPage - 1; _results = []; for (x = _i = _ref = $scope[list_name].length, _ref1 = $scope[list_name].length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { _results.push(x); From 29270d0b8df4eeb09aa404c274e3a4a30b0b64b8 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 12 Feb 2014 18:21:59 +0100 Subject: [PATCH 055/190] refactored table configuration code --- coffee/atPagination.coffee | 21 ++---- coffee/atTable.coffee | 21 +----- coffee/declarative_table.coffee | 100 +++++++++++++-------------- coffee/pagination_table_setup.coffee | 4 +- coffee/standard_table_setup.coffee | 4 +- coffee/table.coffee | 28 ++++---- coffee/table_configuration.coffee | 74 ++++++++++++++++++-- 7 files changed, 143 insertions(+), 109 deletions(-) diff --git a/coffee/atPagination.coffee b/coffee/atPagination.coffee index 37efe6c..f3386b1 100644 --- a/coffee/atPagination.coffee +++ b/coffee/atPagination.coffee @@ -1,5 +1,4 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager", (angularTableManager) -> - { replace: true restrict: "E" @@ -19,31 +18,24 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" " - controller: ["$scope", "$element", "$attrs", "angularTableManager", + controller: ["$scope", "$element", "$attrs", ($scope, $element, $attrs) -> - angularTableManager.register_pagination($attrs.atTableId, $scope) + angularTableManager.register_pagination_scope($attrs.atTableId, $scope) ] scope: true link: ($scope, $element, $attributes) -> - tc = angularTableManager.get_table_configuration($attributes.atTableId) - # console.log tc.items_per_page() - - # $scope[irk_items_per_page] = $attributes.atItemsPerPage $scope[irk_current_page] = 0 - get_list = () -> - $scope[tc.list] - update = (reset) -> $scope[irk_current_page] = 0 - if get_list() - if get_list().length > 0 - $scope[irk_number_of_pages] = Math.ceil(get_list().length / $scope[tc.items_per_page]) + if $scope[tc.list] + if $scope[tc.list].length > 0 + $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]) $scope.pages = for x in [0..($scope[irk_number_of_pages] - 1)] x else @@ -60,11 +52,10 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" update() - # TODO still needed, but could be replaced? $scope.$watch tc.items_per_page, () -> update() - $scope.$watch "atList", () -> + $scope.$watch tc.list, () -> update() } diff --git a/coffee/atTable.coffee b/coffee/atTable.coffee index 79d1b3a..3d0f26f 100644 --- a/coffee/atTable.coffee +++ b/coffee/atTable.coffee @@ -50,7 +50,7 @@ class AngularTableManager if tc.initial_fill_last_page scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page - register_pagination: (id, pagination_scope) -> + register_pagination_scope: (id, pagination_scope) -> mapping = @mappings[id] ||= {} mapping.pagination_scope = pagination_scope @@ -80,10 +80,10 @@ angular.module("angular-table").directive "atTable", ["$filter", "angularTableMa ] compile: (element, attributes, transclude) -> - tc = new TableConfiguration(attributes) + tc = new TableConfiguration(element, attributes) angularTableManager.register_table(tc) - dt = new DeclarativeTable(element, attributes, tc) + dt = new Table(element, tc) dt.compile() { post: ($scope, $element, $attributes) -> @@ -91,18 +91,3 @@ angular.module("angular-table").directive "atTable", ["$filter", "angularTableMa } } ] - -# - -# itemsPerPage ist im parent scope definiert -# table und pagination können diese variable watchen und müssen ihre eigen scopevariablen updaten -# das selbe gilt für fill-last-page und sort-context - -#
-# es muss eine itemsPerPage variable im parent scope erstellt werden - - - -# current_page kann sich ändern in der pagination -# dann muss table notifiziert werden - diff --git a/coffee/declarative_table.coffee b/coffee/declarative_table.coffee index af567e1..f578c53 100644 --- a/coffee/declarative_table.coffee +++ b/coffee/declarative_table.coffee @@ -1,70 +1,70 @@ -class DeclarativeTable extends Table +# class DeclarativeTable extends Table - constructor: (@element, @attributes, @table_configuration) -> +# constructor: (@element, @attributes, @table_configuration) -> - capitaliseFirstLetter: (string) -> - if string then string.charAt(0).toUpperCase() + string.slice(1) else "" +# # capitaliseFirstLetter: (string) -> +# # if string then string.charAt(0).toUpperCase() + string.slice(1) else "" - extractWidth: (classes) -> - width = /([0-9]+px)/i.exec classes - if width then width[0] else "" +# # extractWidth: (classes) -> +# # width = /([0-9]+px)/i.exec classes +# # if width then width[0] else "" - isSortable: (classes) -> - sortable = /(sortable)/i.exec classes - if sortable then true else false +# # isSortable: (classes) -> +# # sortable = /(sortable)/i.exec classes +# # if sortable then true else false - getInitialSorting: (td) -> - initialSorting = td.attr("at-initial-sorting") - if initialSorting - return initialSorting if initialSorting == "asc" || initialSorting == "desc" - throw "Invalid value for initial-sorting: #{initialSorting}. Allowed values are 'asc' or 'desc'." - return undefined +# # getInitialSorting: (td) -> +# # initialSorting = td.attr("at-initial-sorting") +# # if initialSorting +# # return initialSorting if initialSorting == "asc" || initialSorting == "desc" +# # throw "Invalid value for initial-sorting: #{initialSorting}. Allowed values are 'asc' or 'desc'." +# # return undefined - collect_header_markup: (table) -> - customHeaderMarkups = {} +# # collect_header_markup: (table) -> +# # customHeaderMarkups = {} - tr = table.find("tr") - for th in tr.find("th") - th = angular.element(th) - customHeaderMarkups[th.attr("at-attribute")] = { - custom_content: th.html(), attributes: th[0].attributes - } +# # tr = table.find("tr") +# # for th in tr.find("th") +# # th = angular.element(th) +# # customHeaderMarkups[th.attr("at-attribute")] = { +# # custom_content: th.html(), attributes: th[0].attributes +# # } - return customHeaderMarkups +# # return customHeaderMarkups - collect_body_markup: (table) -> - bodyDefinition = [] +# # collect_body_markup: (table) -> +# # bodyDefinition = [] - for td in table.find("td") - td = angular.element(td) +# # for td in table.find("td") +# # td = angular.element(td) - attribute = td.attr("at-attribute") - title = td.attr("at-title") || @capitaliseFirstLetter(td.attr("at-attribute")) - sortable = td.attr("at-sortable") != undefined || @isSortable(td.attr("class")) - width = @extractWidth(td.attr("class")) - initialSorting = @getInitialSorting(td) +# # attribute = td.attr("at-attribute") +# # title = td.attr("at-title") || @capitaliseFirstLetter(td.attr("at-attribute")) +# # sortable = td.attr("at-sortable") != undefined || @isSortable(td.attr("class")) +# # width = @extractWidth(td.attr("class")) +# # initialSorting = @getInitialSorting(td) - bodyDefinition.push { - attribute: attribute, title: title, sortable: sortable, - width: width, initialSorting: initialSorting - } +# # bodyDefinition.push { +# # attribute: attribute, title: title, sortable: sortable, +# # width: width, initialSorting: initialSorting +# # } - return bodyDefinition +# # return bodyDefinition - create_column_configurations: () -> - header_markup = @collect_header_markup(@element) - body_markup = @collect_body_markup(@element) +# # create_column_configurations: () -> +# # header_markup = @collect_header_markup(@element) +# # body_markup = @collect_body_markup(@element) - column_configurations = [] +# # column_configurations = [] - for i in body_markup - column_configurations.push new ColumnConfiguration(i, header_markup[i.attribute]) +# # for i in body_markup +# # column_configurations.push new ColumnConfiguration(i, header_markup[i.attribute]) - return column_configurations +# # return column_configurations - get_column_configurations: () -> - @column_configurations ||= @create_column_configurations() +# # get_column_configurations: () -> +# # @column_configurations ||= @create_column_configurations() - create_table_configuration: () -> +# # create_table_configuration: () -> - get_table_configuration: () -> +# # get_table_configuration: () -> diff --git a/coffee/pagination_table_setup.coffee b/coffee/pagination_table_setup.coffee index e285b22..a0c74ec 100644 --- a/coffee/pagination_table_setup.coffee +++ b/coffee/pagination_table_setup.coffee @@ -1,10 +1,10 @@ class PaginationTableSetup extends TableSetup - constructor: (attributes, table_configuration) -> + constructor: (table_configuration) -> @table_configuration = table_configuration @repeatString = "item in filtered_list()" - compile: (element, attributes, transclude) -> + compile: (element) -> tbody = @setupTr(element, @repeatString) tds = element.find("td") diff --git a/coffee/standard_table_setup.coffee b/coffee/standard_table_setup.coffee index 5159cdb..0565146 100644 --- a/coffee/standard_table_setup.coffee +++ b/coffee/standard_table_setup.coffee @@ -1,6 +1,6 @@ class StandardTableSetup extends TableSetup - constructor: (attributes) -> - @repeatString = "item in #{attributes.atList} | orderBy:predicate:descending" + constructor: (table_configuration) -> + @repeatString = "item in #{table_configuration.list} | orderBy:predicate:descending" compile: (element, attributes, transclude) -> @setupTr(element, @repeatString) diff --git a/coffee/table.coffee b/coffee/table.coffee index 819d5d2..9ffe2e8 100644 --- a/coffee/table.coffee +++ b/coffee/table.coffee @@ -1,7 +1,10 @@ class Table + + constructor: (@element, @table_configuration) -> + constructHeader: () -> tr = angular.element(document.createElement("tr")) - for i in @get_column_configurations() + for i in @table_configuration.column_configurations tr.append(i.render_html()) return tr @@ -13,27 +16,20 @@ class Table tr.remove() thead.append(header) - validateInput: () -> - # if @attributes.atPagination and @attributes.atList - # throw "You can not specify a list if you have specified a Pagination. The list defined for the pagnination will automatically be used." - if not @attributes.atPagination and not @attributes.atList - throw "Either a list or Pagination must be specified." - - create_table_setup: (attributes) -> - if attributes.atList && !attributes.atPagination - return new StandardTableSetup(attributes) - if attributes.atList && attributes.atPagination - return new PaginationTableSetup(attributes, @table_configuration) + create_table_setup: () -> + if @table_configuration.paginated + return new PaginationTableSetup(@table_configuration) + else + return new StandardTableSetup(@table_configuration) return compile: () -> - @validateInput() @setup_header() - @setup = @create_table_setup(@attributes) - @setup.compile(@element, @attributes) + @setup = @create_table_setup() + @setup.compile(@element) setup_initial_sorting: ($scope) -> - for bd in @get_column_configurations() + for bd in @table_configuration.column_configurations if bd.initialSorting throw "initial-sorting specified without attribute." if not bd.attribute $scope.predicate = bd.attribute diff --git a/coffee/table_configuration.coffee b/coffee/table_configuration.coffee index 8edeaf5..875adb5 100644 --- a/coffee/table_configuration.coffee +++ b/coffee/table_configuration.coffee @@ -1,5 +1,14 @@ class TableConfiguration + constructor: (@table_element, @attributes) -> + @id = @attributes.id + @list = @attributes[erk_list] + @register_items_per_page(@attributes[erk_items_per_page]) if @attributes[erk_items_per_page] + @register_sort_context(@attributes[erk_sort_context]) + @register_fill_last_page(@attributes[erk_fill_last_page]) + @paginated = @items_per_page != undefined + @create_column_configurations() + register_items_per_page: (items_per_page) -> if isNaN(items_per_page) @items_per_page = items_per_page @@ -35,9 +44,62 @@ class TableConfiguration else @fill_last_page = fill_last_page - constructor: (attributes) -> - @id = attributes.id - @list = attributes[erk_list] - @register_items_per_page(attributes[erk_items_per_page]) if attributes[erk_items_per_page] - @register_sort_context(attributes[erk_sort_context]) - @register_fill_last_page(attributes[erk_fill_last_page]) + capitaliseFirstLetter: (string) -> + if string then string.charAt(0).toUpperCase() + string.slice(1) else "" + + extractWidth: (classes) -> + width = /([0-9]+px)/i.exec classes + if width then width[0] else "" + + isSortable: (classes) -> + sortable = /(sortable)/i.exec classes + if sortable then true else false + + getInitialSorting: (td) -> + initialSorting = td.attr("at-initial-sorting") + if initialSorting + return initialSorting if initialSorting == "asc" || initialSorting == "desc" + throw "Invalid value for initial-sorting: #{initialSorting}. Allowed values are 'asc' or 'desc'." + return undefined + + collect_header_markup: (table) -> + customHeaderMarkups = {} + + tr = table.find("tr") + for th in tr.find("th") + th = angular.element(th) + customHeaderMarkups[th.attr("at-attribute")] = { + custom_content: th.html(), attributes: th[0].attributes + } + + return customHeaderMarkups + + collect_body_markup: (table) -> + bodyDefinition = [] + + for td in table.find("td") + td = angular.element(td) + + attribute = td.attr("at-attribute") + title = td.attr("at-title") || @capitaliseFirstLetter(td.attr("at-attribute")) + sortable = td.attr("at-sortable") != undefined || @isSortable(td.attr("class")) + width = @extractWidth(td.attr("class")) + initialSorting = @getInitialSorting(td) + + bodyDefinition.push { + attribute: attribute, title: title, sortable: sortable, + width: width, initialSorting: initialSorting + } + + return bodyDefinition + + create_column_configurations: () -> + header_markup = @collect_header_markup(@table_element) + body_markup = @collect_body_markup(@table_element) + + @column_configurations = [] + + for i in body_markup + @column_configurations.push new ColumnConfiguration(i, header_markup[i.attribute]) + + return @column_configurations From 3e6ae2dcd9a9c105cf343e227249efb3be80883d Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 12 Feb 2014 18:41:59 +0100 Subject: [PATCH 056/190] refactored code into new folder structure and renaming --- Rakefile | 21 ++++-- .../{atImplicit.coffee => at-implicit.coffee} | 0 ...Pagination.coffee => at-pagination.coffee} | 0 coffee/{atTable.coffee => at-table.coffee} | 0 .../column_configuration.coffee | 1 + .../table_configuration.coffee | 0 coffee/declarative_table.coffee | 70 ------------------- .../setup/paginated_setup.coffee} | 2 +- .../setup/setup.coffee} | 2 +- .../setup/standard_setup.coffee} | 3 +- coffee/{ => table}/table.coffee | 8 +-- karma.conf.js | 19 +++-- 12 files changed, 37 insertions(+), 89 deletions(-) rename coffee/{atImplicit.coffee => at-implicit.coffee} (100%) rename coffee/{atPagination.coffee => at-pagination.coffee} (100%) rename coffee/{atTable.coffee => at-table.coffee} (100%) rename coffee/{ => configuration}/column_configuration.coffee (99%) rename coffee/{ => configuration}/table_configuration.coffee (100%) delete mode 100644 coffee/declarative_table.coffee rename coffee/{pagination_table_setup.coffee => table/setup/paginated_setup.coffee} (97%) rename coffee/{table_setup.coffee => table/setup/setup.coffee} (89%) rename coffee/{standard_table_setup.coffee => table/setup/standard_setup.coffee} (83%) rename coffee/{ => table}/table.coffee (86%) diff --git a/Rakefile b/Rakefile index b977726..7f3a884 100644 --- a/Rakefile +++ b/Rakefile @@ -7,7 +7,7 @@ task :compile do require "coffee-script" require "uglifier" - script = CoffeeScript.compile collect_coffees("coffee") + script = CoffeeScript.compile collect_coffees() prepend_author_notice(script) @@ -17,16 +17,23 @@ task :compile do end -def collect_coffees src +def collect_coffees files = [ - "atTable", "atImplicit", "atPagination", - "table", "table_setup", "table_configuration", - "column_configuration", "declarative_table", - "standard_table_setup", "pagination_table_setup" + "coffee/configuration/column_configuration.coffee", + "coffee/configuration/table_configuration.coffee", + + "coffee/table/setup/setup.coffee", + "coffee/table/setup/standard_setup.coffee", + "coffee/table/setup/paginated_setup.coffee", + "coffee/table/table.coffee", + + "coffee/at-table.coffee", + "coffee/at-pagination.coffee", + "coffee/at-implicit.coffee", ] script = "" files.each do |file| - script << File.read("#{src}/#{file}.coffee") << "\n" + script << File.read("#{file}") << "\n" end script end diff --git a/coffee/atImplicit.coffee b/coffee/at-implicit.coffee similarity index 100% rename from coffee/atImplicit.coffee rename to coffee/at-implicit.coffee diff --git a/coffee/atPagination.coffee b/coffee/at-pagination.coffee similarity index 100% rename from coffee/atPagination.coffee rename to coffee/at-pagination.coffee diff --git a/coffee/atTable.coffee b/coffee/at-table.coffee similarity index 100% rename from coffee/atTable.coffee rename to coffee/at-table.coffee diff --git a/coffee/column_configuration.coffee b/coffee/configuration/column_configuration.coffee similarity index 99% rename from coffee/column_configuration.coffee rename to coffee/configuration/column_configuration.coffee index 25ed10c..7daa934 100644 --- a/coffee/column_configuration.coffee +++ b/coffee/configuration/column_configuration.coffee @@ -1,4 +1,5 @@ class ColumnConfiguration + constructor: (body_markup, header_markup) -> @attribute = body_markup.attribute @title = body_markup.title diff --git a/coffee/table_configuration.coffee b/coffee/configuration/table_configuration.coffee similarity index 100% rename from coffee/table_configuration.coffee rename to coffee/configuration/table_configuration.coffee diff --git a/coffee/declarative_table.coffee b/coffee/declarative_table.coffee deleted file mode 100644 index f578c53..0000000 --- a/coffee/declarative_table.coffee +++ /dev/null @@ -1,70 +0,0 @@ -# class DeclarativeTable extends Table - -# constructor: (@element, @attributes, @table_configuration) -> - -# # capitaliseFirstLetter: (string) -> -# # if string then string.charAt(0).toUpperCase() + string.slice(1) else "" - -# # extractWidth: (classes) -> -# # width = /([0-9]+px)/i.exec classes -# # if width then width[0] else "" - -# # isSortable: (classes) -> -# # sortable = /(sortable)/i.exec classes -# # if sortable then true else false - -# # getInitialSorting: (td) -> -# # initialSorting = td.attr("at-initial-sorting") -# # if initialSorting -# # return initialSorting if initialSorting == "asc" || initialSorting == "desc" -# # throw "Invalid value for initial-sorting: #{initialSorting}. Allowed values are 'asc' or 'desc'." -# # return undefined - -# # collect_header_markup: (table) -> -# # customHeaderMarkups = {} - -# # tr = table.find("tr") -# # for th in tr.find("th") -# # th = angular.element(th) -# # customHeaderMarkups[th.attr("at-attribute")] = { -# # custom_content: th.html(), attributes: th[0].attributes -# # } - -# # return customHeaderMarkups - -# # collect_body_markup: (table) -> -# # bodyDefinition = [] - -# # for td in table.find("td") -# # td = angular.element(td) - -# # attribute = td.attr("at-attribute") -# # title = td.attr("at-title") || @capitaliseFirstLetter(td.attr("at-attribute")) -# # sortable = td.attr("at-sortable") != undefined || @isSortable(td.attr("class")) -# # width = @extractWidth(td.attr("class")) -# # initialSorting = @getInitialSorting(td) - -# # bodyDefinition.push { -# # attribute: attribute, title: title, sortable: sortable, -# # width: width, initialSorting: initialSorting -# # } - -# # return bodyDefinition - -# # create_column_configurations: () -> -# # header_markup = @collect_header_markup(@element) -# # body_markup = @collect_body_markup(@element) - -# # column_configurations = [] - -# # for i in body_markup -# # column_configurations.push new ColumnConfiguration(i, header_markup[i.attribute]) - -# # return column_configurations - -# # get_column_configurations: () -> -# # @column_configurations ||= @create_column_configurations() - -# # create_table_configuration: () -> - -# # get_table_configuration: () -> diff --git a/coffee/pagination_table_setup.coffee b/coffee/table/setup/paginated_setup.coffee similarity index 97% rename from coffee/pagination_table_setup.coffee rename to coffee/table/setup/paginated_setup.coffee index a0c74ec..26fb3a6 100644 --- a/coffee/pagination_table_setup.coffee +++ b/coffee/table/setup/paginated_setup.coffee @@ -1,4 +1,4 @@ -class PaginationTableSetup extends TableSetup +class PaginatedSetup extends Setup constructor: (table_configuration) -> @table_configuration = table_configuration diff --git a/coffee/table_setup.coffee b/coffee/table/setup/setup.coffee similarity index 89% rename from coffee/table_setup.coffee rename to coffee/table/setup/setup.coffee index 065ab8d..d3ffd90 100644 --- a/coffee/table_setup.coffee +++ b/coffee/table/setup/setup.coffee @@ -1,4 +1,4 @@ -class TableSetup +class Setup setupTr: (element, repeatString) -> tbody = element.find "tbody" diff --git a/coffee/standard_table_setup.coffee b/coffee/table/setup/standard_setup.coffee similarity index 83% rename from coffee/standard_table_setup.coffee rename to coffee/table/setup/standard_setup.coffee index 0565146..1e6a791 100644 --- a/coffee/standard_table_setup.coffee +++ b/coffee/table/setup/standard_setup.coffee @@ -1,4 +1,5 @@ -class StandardTableSetup extends TableSetup +class StandardSetup extends Setup + constructor: (table_configuration) -> @repeatString = "item in #{table_configuration.list} | orderBy:predicate:descending" diff --git a/coffee/table.coffee b/coffee/table/table.coffee similarity index 86% rename from coffee/table.coffee rename to coffee/table/table.coffee index 9ffe2e8..322e3a3 100644 --- a/coffee/table.coffee +++ b/coffee/table/table.coffee @@ -16,16 +16,16 @@ class Table tr.remove() thead.append(header) - create_table_setup: () -> + get_setup: () -> if @table_configuration.paginated - return new PaginationTableSetup(@table_configuration) + return new PaginatedSetup(@table_configuration) else - return new StandardTableSetup(@table_configuration) + return new StandardSetup(@table_configuration) return compile: () -> @setup_header() - @setup = @create_table_setup() + @setup = @get_setup() @setup.compile(@element) setup_initial_sorting: ($scope) -> diff --git a/karma.conf.js b/karma.conf.js index 1ec1ce2..2f6b314 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -17,10 +17,19 @@ module.exports = function(config) { 'http://code.angularjs.org/1.2.11/angular.min.js', 'http://code.angularjs.org/1.2.11/angular-mocks.js', 'http://underscorejs.org/underscore-min.js', - 'coffee/atTable.coffee', - 'coffee/table.coffee', - 'coffee/table_setup.coffee', - 'coffee/*.coffee', + + 'coffee/configuration/column_configuration.coffee', + 'coffee/configuration/table_configuration.coffee', + + 'coffee/table/setup/setup.coffee', + 'coffee/table/setup/standard_setup.coffee', + 'coffee/table/setup/paginated_setup.coffee', + 'coffee/table/table.coffee', + + 'coffee/at-table.coffee', + 'coffee/at-pagination.coffee', + 'coffee/at-implicit.coffee', + 'test/test_helper.coffee', 'test/*.coffee', 'test/templates/**/*.html' @@ -33,7 +42,7 @@ module.exports = function(config) { ], preprocessors: { - 'coffee/*.coffee': ['coffee'], + 'coffee/**/**/*.coffee': ['coffee'], 'test/*.coffee': ['coffee'], 'test/templates/**/*.html': ['ng-html2js'] }, From 6084eee7a6ffed3c0e4e41760b451311a517893f Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 12 Feb 2014 18:44:28 +0100 Subject: [PATCH 057/190] compiled new version --- angular-table.js | 753 ++++++++++---------- angular-table.min.js | 2 +- gem/app/assets/javascripts/angular-table.js | 753 ++++++++++---------- 3 files changed, 729 insertions(+), 779 deletions(-) diff --git a/angular-table.js b/angular-table.js index 975a1c6..3f10783 100644 --- a/angular-table.js +++ b/angular-table.js @@ -3,357 +3,10 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var AngularTableManager, ColumnConfiguration, DeclarativeTable, PaginationTableSetup, StandardTableSetup, Table, TableConfiguration, TableSetup, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, + var AngularTableManager, ColumnConfiguration, PaginatedSetup, Setup, StandardSetup, Table, TableConfiguration, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; - angular.module("angular-table", []); - - irk_from_page = "from_page"; - - irk_current_page = "current_page"; - - irk_number_of_pages = "number_of_pages"; - - erk_list = "atList"; - - erk_items_per_page = "atItemsPerPage"; - - erk_fill_last_page = "atFillLastPage"; - - erk_sort_context = "atSortContext"; - - erk_attribute = "at-attribute"; - - erk_sortable = "at-sortable"; - - erk_initial_sorting = "at-initial-sorting"; - - calculate_from_page = function(items_per_page, current_page, list) { - if (list) { - return items_per_page * current_page - list.length; - } - }; - - AngularTableManager = (function() { - function AngularTableManager() { - this.mappings = {}; - } - - AngularTableManager.prototype.get_table_configuration = function(id) { - return this.mappings[id].table_configuration; - }; - - AngularTableManager.prototype.register_table = function(table_configuration) { - var mapping, _base, _name; - mapping = (_base = this.mappings)[_name = table_configuration.id] || (_base[_name] = {}); - mapping.table_configuration = table_configuration; - if (mapping.pagination_scope) { - throw "WHOOPS"; - } - }; - - AngularTableManager.prototype.register_table_scope = function(id, scope) { - var tc; - this.mappings[id].table_scope = scope; - tc = this.mappings[id].table_configuration; - if (tc.initial_items_per_page) { - scope.$parent[tc.items_per_page] = tc.initial_items_per_page; - } - if (tc.initial_sort_context) { - scope.$parent[tc.sort_context] = tc.initial_sort_context; - } - if (tc.initial_fill_last_page) { - return scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page; - } - }; - - AngularTableManager.prototype.register_pagination = function(id, pagination_scope) { - var mapping, _base; - mapping = (_base = this.mappings)[id] || (_base[id] = {}); - mapping.pagination_scope = pagination_scope; - if (mapping.table_configuration) { - return pagination_scope.$watch(irk_current_page, function() { - var ts; - ts = mapping.table_scope; - ts[irk_current_page] = pagination_scope[irk_current_page]; - ts[irk_number_of_pages] = pagination_scope[irk_number_of_pages]; - return ts[irk_from_page] = calculate_from_page(ts[mapping.table_configuration.items_per_page], ts[irk_current_page], ts[mapping.table_configuration.list]); - }); - } - }; - - return AngularTableManager; - - })(); - - angular.module("angular-table").service("angularTableManager", [ - function() { - return new AngularTableManager(); - } - ]); - - angular.module("angular-table").directive("atTable", [ - "$filter", "angularTableManager", function($filter, angularTableManager) { - return { - restrict: "AC", - scope: true, - controller: [ - "$scope", "$element", "$attrs", function($scope, $element, $attrs) { - var id; - id = $attrs["id"]; - if (id) { - return angularTableManager.register_table_scope(id, $scope); - } - } - ], - compile: function(element, attributes, transclude) { - var dt, tc; - tc = new TableConfiguration(attributes); - angularTableManager.register_table(tc); - dt = new DeclarativeTable(element, attributes, tc); - dt.compile(); - return { - post: function($scope, $element, $attributes) { - return dt.post($scope, $element, $attributes, $filter); - } - }; - } - }; - } - ]); - - angular.module("angular-table").directive("atImplicit", [ - function() { - return { - restrict: "AC", - compile: function(element, attributes, transclude) { - var attribute; - attribute = element.attr("at-attribute"); - if (!attribute) { - throw "at-implicit specified without at-attribute: " + (element.html()); - } - return element.append("{{item." + attribute + "}}"); - } - }; - } - ]); - - angular.module("angular-table").directive("atPagination", [ - "angularTableManager", function(angularTableManager) { - return { - replace: true, - restrict: "E", - template: " ", - controller: [ - "$scope", "$element", "$attrs", "angularTableManager", function($scope, $element, $attrs) { - return angularTableManager.register_pagination($attrs.atTableId, $scope); - } - ], - scope: true, - link: function($scope, $element, $attributes) { - var get_list, normalizePage, tc, update; - tc = angularTableManager.get_table_configuration($attributes.atTableId); - $scope[irk_current_page] = 0; - get_list = function() { - return $scope[tc.list]; - }; - update = function(reset) { - var x; - $scope[irk_current_page] = 0; - if (get_list()) { - if (get_list().length > 0) { - $scope[irk_number_of_pages] = Math.ceil(get_list().length / $scope[tc.items_per_page]); - return $scope.pages = (function() { - var _i, _ref, _results; - _results = []; - for (x = _i = 0, _ref = $scope[irk_number_of_pages] - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { - _results.push(x); - } - return _results; - })(); - } else { - $scope[irk_number_of_pages] = 1; - return $scope.pages = [0]; - } - } - }; - normalizePage = function(page) { - page = Math.max(0, page); - page = Math.min($scope[irk_number_of_pages] - 1, page); - return page; - }; - $scope.go_to_page = function(page) { - return $scope[irk_current_page] = normalizePage(page); - }; - update(); - $scope.$watch(tc.items_per_page, function() { - return update(); - }); - return $scope.$watch("atList", function() { - return update(); - }); - } - }; - } - ]); - - Table = (function() { - function Table() {} - - Table.prototype.constructHeader = function() { - var i, tr, _i, _len, _ref; - tr = angular.element(document.createElement("tr")); - _ref = this.get_column_configurations(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - i = _ref[_i]; - tr.append(i.render_html()); - } - return tr; - }; - - Table.prototype.setup_header = function() { - var header, thead, tr; - thead = this.element.find("thead"); - if (thead) { - header = this.constructHeader(); - tr = angular.element(thead).find("tr"); - tr.remove(); - return thead.append(header); - } - }; - - Table.prototype.validateInput = function() { - if (!this.attributes.atPagination && !this.attributes.atList) { - throw "Either a list or Pagination must be specified."; - } - }; - - Table.prototype.create_table_setup = function(attributes) { - if (attributes.atList && !attributes.atPagination) { - return new StandardTableSetup(attributes); - } - if (attributes.atList && attributes.atPagination) { - return new PaginationTableSetup(attributes, this.table_configuration); - } - }; - - Table.prototype.compile = function() { - this.validateInput(); - this.setup_header(); - this.setup = this.create_table_setup(this.attributes); - return this.setup.compile(this.element, this.attributes); - }; - - Table.prototype.setup_initial_sorting = function($scope) { - var bd, _i, _len, _ref, _results; - _ref = this.get_column_configurations(); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - bd = _ref[_i]; - if (bd.initialSorting) { - if (!bd.attribute) { - throw "initial-sorting specified without attribute."; - } - } - $scope.predicate = bd.attribute; - _results.push($scope.descending = bd.initialSorting === "desc"); - } - return _results; - }; - - Table.prototype.post = function($scope, $element, $attributes, $filter) { - this.setup_initial_sorting($scope); - $scope.getSortIcon = function(predicate) { - if (predicate !== $scope.predicate) { - return "icon-minus"; - } - if ($scope.descending) { - return "icon-chevron-down"; - } else { - return "icon-chevron-up"; - } - }; - return this.setup.link($scope, $element, $attributes, $filter); - }; - - return Table; - - })(); - - TableSetup = (function() { - function TableSetup() {} - - TableSetup.prototype.setupTr = function(element, repeatString) { - var tbody, tr; - tbody = element.find("tbody"); - tr = tbody.find("tr"); - tr.attr("ng-repeat", repeatString); - return tbody; - }; - - return TableSetup; - - })(); - - TableConfiguration = (function() { - TableConfiguration.prototype.register_items_per_page = function(items_per_page) { - if (isNaN(items_per_page)) { - return this.items_per_page = items_per_page; - } else { - this.items_per_page = "" + this.id + "_itemsPerPage"; - return this.initial_items_per_page = parseInt(items_per_page); - } - }; - - TableConfiguration.prototype.register_sort_context = function(sort_context) { - if (sort_context !== void 0) { - if (sort_context === "global") { - this.sort_context = "" + this.id + "_sortContext"; - return this.initial_sort_context = "global"; - } else if (sort_context === "page") { - this.sort_context = "" + this.id + "_sortContext"; - return this.initial_sort_context = "page"; - } else { - return this.sort_context = sort_context; - } - } else { - this.sort_context = "" + this.id + "_sortContext"; - return this.initial_sort_context = "global"; - } - }; - - TableConfiguration.prototype.register_fill_last_page = function(fill_last_page) { - if (fill_last_page !== void 0) { - if (fill_last_page === "true") { - this.fill_last_page = "" + this.id + "_fillLastPage"; - return this.initial_fill_last_page = true; - } else if (fill_last_page === "false") { - this.fill_last_page = "" + this.id + "_fillLastPage"; - return this.initial_fill_last_page = false; - } else if (fill_last_page === "") { - this.fill_last_page = "" + this.id + "_fillLastPage"; - return this.initial_fill_last_page = true; - } else { - return this.fill_last_page = fill_last_page; - } - } - }; - - function TableConfiguration(attributes) { - this.id = attributes.id; - this.list = attributes[erk_list]; - if (attributes[erk_items_per_page]) { - this.register_items_per_page(attributes[erk_items_per_page]); - } - this.register_sort_context(attributes[erk_sort_context]); - this.register_fill_last_page(attributes[erk_fill_last_page]); - } - - return TableConfiguration; - - })(); - ColumnConfiguration = (function() { function ColumnConfiguration(body_markup, header_markup) { this.attribute = body_markup.attribute; @@ -418,16 +71,65 @@ })(); - DeclarativeTable = (function(_super) { - __extends(DeclarativeTable, _super); - - function DeclarativeTable(element, attributes, table_configuration) { - this.element = element; + TableConfiguration = (function() { + function TableConfiguration(table_element, attributes) { + this.table_element = table_element; this.attributes = attributes; - this.table_configuration = table_configuration; + this.id = this.attributes.id; + this.list = this.attributes[erk_list]; + if (this.attributes[erk_items_per_page]) { + this.register_items_per_page(this.attributes[erk_items_per_page]); + } + this.register_sort_context(this.attributes[erk_sort_context]); + this.register_fill_last_page(this.attributes[erk_fill_last_page]); + this.paginated = this.items_per_page !== void 0; + this.create_column_configurations(); } - DeclarativeTable.prototype.capitaliseFirstLetter = function(string) { + TableConfiguration.prototype.register_items_per_page = function(items_per_page) { + if (isNaN(items_per_page)) { + return this.items_per_page = items_per_page; + } else { + this.items_per_page = "" + this.id + "_itemsPerPage"; + return this.initial_items_per_page = parseInt(items_per_page); + } + }; + + TableConfiguration.prototype.register_sort_context = function(sort_context) { + if (sort_context !== void 0) { + if (sort_context === "global") { + this.sort_context = "" + this.id + "_sortContext"; + return this.initial_sort_context = "global"; + } else if (sort_context === "page") { + this.sort_context = "" + this.id + "_sortContext"; + return this.initial_sort_context = "page"; + } else { + return this.sort_context = sort_context; + } + } else { + this.sort_context = "" + this.id + "_sortContext"; + return this.initial_sort_context = "global"; + } + }; + + TableConfiguration.prototype.register_fill_last_page = function(fill_last_page) { + if (fill_last_page !== void 0) { + if (fill_last_page === "true") { + this.fill_last_page = "" + this.id + "_fillLastPage"; + return this.initial_fill_last_page = true; + } else if (fill_last_page === "false") { + this.fill_last_page = "" + this.id + "_fillLastPage"; + return this.initial_fill_last_page = false; + } else if (fill_last_page === "") { + this.fill_last_page = "" + this.id + "_fillLastPage"; + return this.initial_fill_last_page = true; + } else { + return this.fill_last_page = fill_last_page; + } + } + }; + + TableConfiguration.prototype.capitaliseFirstLetter = function(string) { if (string) { return string.charAt(0).toUpperCase() + string.slice(1); } else { @@ -435,7 +137,7 @@ } }; - DeclarativeTable.prototype.extractWidth = function(classes) { + TableConfiguration.prototype.extractWidth = function(classes) { var width; width = /([0-9]+px)/i.exec(classes); if (width) { @@ -445,7 +147,7 @@ } }; - DeclarativeTable.prototype.isSortable = function(classes) { + TableConfiguration.prototype.isSortable = function(classes) { var sortable; sortable = /(sortable)/i.exec(classes); if (sortable) { @@ -455,7 +157,7 @@ } }; - DeclarativeTable.prototype.getInitialSorting = function(td) { + TableConfiguration.prototype.getInitialSorting = function(td) { var initialSorting; initialSorting = td.attr("at-initial-sorting"); if (initialSorting) { @@ -467,7 +169,7 @@ return void 0; }; - DeclarativeTable.prototype.collect_header_markup = function(table) { + TableConfiguration.prototype.collect_header_markup = function(table) { var customHeaderMarkups, th, tr, _i, _len, _ref; customHeaderMarkups = {}; tr = table.find("tr"); @@ -483,7 +185,7 @@ return customHeaderMarkups; }; - DeclarativeTable.prototype.collect_body_markup = function(table) { + TableConfiguration.prototype.collect_body_markup = function(table) { var attribute, bodyDefinition, initialSorting, sortable, td, title, width, _i, _len, _ref; bodyDefinition = []; _ref = table.find("td"); @@ -506,56 +208,63 @@ return bodyDefinition; }; - DeclarativeTable.prototype.create_column_configurations = function() { - var body_markup, column_configurations, header_markup, i, _i, _len; - header_markup = this.collect_header_markup(this.element); - body_markup = this.collect_body_markup(this.element); - column_configurations = []; + TableConfiguration.prototype.create_column_configurations = function() { + var body_markup, header_markup, i, _i, _len; + header_markup = this.collect_header_markup(this.table_element); + body_markup = this.collect_body_markup(this.table_element); + this.column_configurations = []; for (_i = 0, _len = body_markup.length; _i < _len; _i++) { i = body_markup[_i]; - column_configurations.push(new ColumnConfiguration(i, header_markup[i.attribute])); + this.column_configurations.push(new ColumnConfiguration(i, header_markup[i.attribute])); } - return column_configurations; + return this.column_configurations; }; - DeclarativeTable.prototype.get_column_configurations = function() { - return this.column_configurations || (this.column_configurations = this.create_column_configurations()); - }; + return TableConfiguration; + + })(); - DeclarativeTable.prototype.create_table_configuration = function() {}; + Setup = (function() { + function Setup() {} - DeclarativeTable.prototype.get_table_configuration = function() {}; + Setup.prototype.setupTr = function(element, repeatString) { + var tbody, tr; + tbody = element.find("tbody"); + tr = tbody.find("tr"); + tr.attr("ng-repeat", repeatString); + return tbody; + }; - return DeclarativeTable; + return Setup; - })(Table); + })(); - StandardTableSetup = (function(_super) { - __extends(StandardTableSetup, _super); + StandardSetup = (function(_super) { + __extends(StandardSetup, _super); - function StandardTableSetup(attributes) { - this.repeatString = "item in " + attributes.atList + " | orderBy:predicate:descending"; + function StandardSetup(table_configuration) { + this.repeatString = "item in " + table_configuration.list + " | orderBy:predicate:descending"; } - StandardTableSetup.prototype.compile = function(element, attributes, transclude) { + StandardSetup.prototype.compile = function(element, attributes, transclude) { return this.setupTr(element, this.repeatString); }; - StandardTableSetup.prototype.link = function() {}; + StandardSetup.prototype.link = function() {}; - return StandardTableSetup; + return StandardSetup; - })(TableSetup); + })(Setup); - PaginationTableSetup = (function(_super) { - __extends(PaginationTableSetup, _super); + PaginatedSetup = (function(_super) { + __extends(PaginatedSetup, _super); - function PaginationTableSetup(attributes, table_configuration) { + function PaginatedSetup(table_configuration) { this.table_configuration = table_configuration; this.repeatString = "item in filtered_list()"; } - PaginationTableSetup.prototype.compile = function(element, attributes, transclude) { + PaginatedSetup.prototype.compile = function(element) { var fillerTr, tbody, td, tdString, tds, _i, _len; tbody = this.setupTr(element, this.repeatString); tds = element.find("td"); @@ -571,7 +280,7 @@ tbody.append(fillerTr); }; - PaginationTableSetup.prototype.link = function($scope, $element, $attributes, $filter) { + PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) { var ipp, list_name, sc; list_name = this.table_configuration.list; ipp = this.table_configuration.items_per_page; @@ -608,8 +317,274 @@ }; }; - return PaginationTableSetup; + return PaginatedSetup; + + })(Setup); + + Table = (function() { + function Table(element, table_configuration) { + this.element = element; + this.table_configuration = table_configuration; + } + + Table.prototype.constructHeader = function() { + var i, tr, _i, _len, _ref; + tr = angular.element(document.createElement("tr")); + _ref = this.table_configuration.column_configurations; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + i = _ref[_i]; + tr.append(i.render_html()); + } + return tr; + }; + + Table.prototype.setup_header = function() { + var header, thead, tr; + thead = this.element.find("thead"); + if (thead) { + header = this.constructHeader(); + tr = angular.element(thead).find("tr"); + tr.remove(); + return thead.append(header); + } + }; + + Table.prototype.get_setup = function() { + if (this.table_configuration.paginated) { + return new PaginatedSetup(this.table_configuration); + } else { + return new StandardSetup(this.table_configuration); + } + }; + + Table.prototype.compile = function() { + this.setup_header(); + this.setup = this.get_setup(); + return this.setup.compile(this.element); + }; + + Table.prototype.setup_initial_sorting = function($scope) { + var bd, _i, _len, _ref, _results; + _ref = this.table_configuration.column_configurations; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + bd = _ref[_i]; + if (bd.initialSorting) { + if (!bd.attribute) { + throw "initial-sorting specified without attribute."; + } + } + $scope.predicate = bd.attribute; + _results.push($scope.descending = bd.initialSorting === "desc"); + } + return _results; + }; + + Table.prototype.post = function($scope, $element, $attributes, $filter) { + this.setup_initial_sorting($scope); + $scope.getSortIcon = function(predicate) { + if (predicate !== $scope.predicate) { + return "icon-minus"; + } + if ($scope.descending) { + return "icon-chevron-down"; + } else { + return "icon-chevron-up"; + } + }; + return this.setup.link($scope, $element, $attributes, $filter); + }; + + return Table; + + })(); + + angular.module("angular-table", []); + + irk_from_page = "from_page"; + + irk_current_page = "current_page"; + + irk_number_of_pages = "number_of_pages"; + + erk_list = "atList"; + + erk_items_per_page = "atItemsPerPage"; + + erk_fill_last_page = "atFillLastPage"; + + erk_sort_context = "atSortContext"; + + erk_attribute = "at-attribute"; + + erk_sortable = "at-sortable"; + + erk_initial_sorting = "at-initial-sorting"; + + calculate_from_page = function(items_per_page, current_page, list) { + if (list) { + return items_per_page * current_page - list.length; + } + }; + + AngularTableManager = (function() { + function AngularTableManager() { + this.mappings = {}; + } + + AngularTableManager.prototype.get_table_configuration = function(id) { + return this.mappings[id].table_configuration; + }; + + AngularTableManager.prototype.register_table = function(table_configuration) { + var mapping, _base, _name; + mapping = (_base = this.mappings)[_name = table_configuration.id] || (_base[_name] = {}); + mapping.table_configuration = table_configuration; + if (mapping.pagination_scope) { + throw "WHOOPS"; + } + }; + + AngularTableManager.prototype.register_table_scope = function(id, scope) { + var tc; + this.mappings[id].table_scope = scope; + tc = this.mappings[id].table_configuration; + if (tc.initial_items_per_page) { + scope.$parent[tc.items_per_page] = tc.initial_items_per_page; + } + if (tc.initial_sort_context) { + scope.$parent[tc.sort_context] = tc.initial_sort_context; + } + if (tc.initial_fill_last_page) { + return scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page; + } + }; + + AngularTableManager.prototype.register_pagination_scope = function(id, pagination_scope) { + var mapping, _base; + mapping = (_base = this.mappings)[id] || (_base[id] = {}); + mapping.pagination_scope = pagination_scope; + if (mapping.table_configuration) { + return pagination_scope.$watch(irk_current_page, function() { + var ts; + ts = mapping.table_scope; + ts[irk_current_page] = pagination_scope[irk_current_page]; + ts[irk_number_of_pages] = pagination_scope[irk_number_of_pages]; + return ts[irk_from_page] = calculate_from_page(ts[mapping.table_configuration.items_per_page], ts[irk_current_page], ts[mapping.table_configuration.list]); + }); + } + }; + + return AngularTableManager; + + })(); + + angular.module("angular-table").service("angularTableManager", [ + function() { + return new AngularTableManager(); + } + ]); + + angular.module("angular-table").directive("atTable", [ + "$filter", "angularTableManager", function($filter, angularTableManager) { + return { + restrict: "AC", + scope: true, + controller: [ + "$scope", "$element", "$attrs", function($scope, $element, $attrs) { + var id; + id = $attrs["id"]; + if (id) { + return angularTableManager.register_table_scope(id, $scope); + } + } + ], + compile: function(element, attributes, transclude) { + var dt, tc; + tc = new TableConfiguration(element, attributes); + angularTableManager.register_table(tc); + dt = new Table(element, tc); + dt.compile(); + return { + post: function($scope, $element, $attributes) { + return dt.post($scope, $element, $attributes, $filter); + } + }; + } + }; + } + ]); + + angular.module("angular-table").directive("atPagination", [ + "angularTableManager", function(angularTableManager) { + return { + replace: true, + restrict: "E", + template: " ", + controller: [ + "$scope", "$element", "$attrs", function($scope, $element, $attrs) { + return angularTableManager.register_pagination_scope($attrs.atTableId, $scope); + } + ], + scope: true, + link: function($scope, $element, $attributes) { + var normalizePage, tc, update; + tc = angularTableManager.get_table_configuration($attributes.atTableId); + $scope[irk_current_page] = 0; + update = function(reset) { + var x; + $scope[irk_current_page] = 0; + if ($scope[tc.list]) { + if ($scope[tc.list].length > 0) { + $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]); + return $scope.pages = (function() { + var _i, _ref, _results; + _results = []; + for (x = _i = 0, _ref = $scope[irk_number_of_pages] - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { + _results.push(x); + } + return _results; + })(); + } else { + $scope[irk_number_of_pages] = 1; + return $scope.pages = [0]; + } + } + }; + normalizePage = function(page) { + page = Math.max(0, page); + page = Math.min($scope[irk_number_of_pages] - 1, page); + return page; + }; + $scope.go_to_page = function(page) { + return $scope[irk_current_page] = normalizePage(page); + }; + update(); + $scope.$watch(tc.items_per_page, function() { + return update(); + }); + return $scope.$watch(tc.list, function() { + return update(); + }); + } + }; + } + ]); - })(TableSetup); + angular.module("angular-table").directive("atImplicit", [ + function() { + return { + restrict: "AC", + compile: function(element, attributes, transclude) { + var attribute; + attribute = element.attr("at-attribute"); + if (!attribute) { + throw "at-implicit specified without at-attribute: " + (element.html()); + } + return element.append("{{item." + attribute + "}}"); + } + }; + } + ]); }).call(this); diff --git a/angular-table.min.js b/angular-table.min.js index 185d101..157095e 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,l,u,c,p,g,_,h,f,d,m,b,v={}.hasOwnProperty,y=function(t,e){function i(){this.constructor=t}for(var n in e)v.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};angular.module("angular-table",[]),m="from_page",d="current_page",b="number_of_pages",_="atList",g="atItemsPerPage",c="atFillLastPage",h="atSortContext",u="at-attribute",f="at-sortable",p="at-initial-sorting",l=function(t,e,i){return i?t*e-i.length:void 0},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page?e.$parent[i.fill_last_page]=i.initial_fill_last_page:void 0},t.prototype.register_pagination=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?e.$watch(d,function(){var t;return t=i.table_scope,t[d]=e[d],t[b]=e[b],t[m]=l(t[i.table_configuration.items_per_page],t[d],t[i.table_configuration.list])}):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(t,i,n){var r;return r=n.id,r?e.register_table_scope(r,t):void 0}],compile:function(n,r){var a,s;return s=new o(r),e.register_table(s),a=new i(n,r,s),a.compile(),{post:function(e,i,n){return a.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:" ",controller:["$scope","$element","$attrs","angularTableManager",function(e,i,n){return t.register_pagination(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s;return o=t.get_table_configuration(n.atTableId),e[d]=0,r=function(){return e[o.list]},s=function(){var t;return e[d]=0,r()?r().length>0?(e[b]=Math.ceil(r().length/e[o.items_per_page]),e.pages=function(){var i,n,r;for(r=[],t=i=0,n=e[b]-1;n>=0?n>=i:i>=n;t=n>=0?++i:--i)r.push(t);return r}()):(e[b]=1,e.pages=[0]):void 0},a=function(t){return t=Math.max(0,t),t=Math.min(e[b]-1,t)},e.go_to_page=function(t){return e[d]=a(t)},s(),e.$watch(o.items_per_page,function(){return s()}),e.$watch("atList",function(){return s()})}}}]),a=function(){function t(){}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.get_column_configurations(),i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.validateInput=function(){if(!this.attributes.atPagination&&!this.attributes.atList)throw"Either a list or Pagination must be specified."},t.prototype.create_table_setup=function(t){return t.atList&&!t.atPagination?new r(t):t.atList&&t.atPagination?new n(t,this.table_configuration):void 0},t.prototype.compile=function(){return this.validateInput(),this.setup_header(),this.setup=this.create_table_setup(this.attributes),this.setup.compile(this.element,this.attributes)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.get_column_configurations(),a=[],i=0,n=r.length;n>i;i++){if(e=r[i],e.initialSorting&&!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},this.setup.link(t,e,i,n)},t}(),s=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),o=function(){function t(t){this.id=t.id,this.list=t[_],t[g]&&this.register_items_per_page(t[g]),this.register_sort_context(t[h]),this.register_fill_last_page(t[c])}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t}(),e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"')"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),i=function(t){function i(t,e,i){this.element=t,this.attributes=e,this.table_configuration=i}return y(i,t),i.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},i.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},i.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},i.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},i.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},i.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,c;for(i=[],c=t.find("td"),l=0,u=c.length;u>l;l++)a=c[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},i.prototype.create_column_configurations=function(){var t,i,n,r,a,o;for(n=this.collect_header_markup(this.element),t=this.collect_body_markup(this.element),i=[],a=0,o=t.length;o>a;a++)r=t[a],i.push(new e(r,n[r.attribute]));return i},i.prototype.get_column_configurations=function(){return this.column_configurations||(this.column_configurations=this.create_column_configurations())},i.prototype.create_table_configuration=function(){},i.prototype.get_table_configuration=function(){},i}(a),r=function(t){function e(t){this.repeatString="item in "+t.atList+" | orderBy:predicate:descending"}return y(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(s),n=function(t){function e(t,e){this.table_configuration=e,this.repeatString="item in filtered_list()"}return y(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in getFillerArray() "),i.append(e)},e.prototype.link=function(t,e,i,n){var r,a,o;return a=this.table_configuration.list,r=this.table_configuration.items_per_page,o=this.table_configuration.sort_context,t.filtered_list=function(){var e;return e=t[a],"global"===t[o]?(e=n("orderBy")(e,t.predicate,t.descending),e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r])):(e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r]),e=n("orderBy")(e,t.predicate,t.descending)),e},t.getFillerArray=function(){var e,i,n,o,s,l,u;if(t[d]===t[b]-1){if(i=t[a].length%t[r],0!==i||0===t[a].length){for(e=t[r]-i-1,u=[],n=o=s=t[a].length,l=t[a].length+e;l>=s?l>=o:o>=l;n=l>=s?++o:--o)u.push(n);return u}return[]}}},e}(s)}).call(this); \ No newline at end of file +(function(){var t,e,i,r,n,a,o,s,l,u,c,p,g,_,h,f,d,m,b={}.hasOwnProperty,v=function(t,e){function i(){this.constructor=t}for(var r in e)b.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,r,n,a;if(this.custom_content){for(n=this.attributes,a=[],i=0,r=n.length;r>i;i++)e=n[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"')"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[p]&&this.register_items_per_page(this.attributes[p]),this.register_sort_context(this.attributes[_]),this.register_fill_last_page(this.attributes[u]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,r,n,a,o;for(e={},r=t.find("tr"),o=r.find("th"),n=0,a=o.length;a>n;n++)i=o[n],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,r,n,a,o,s,l,u,c;for(i=[],c=t.find("td"),l=0,u=c.length;u>l;l++)a=c[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),n=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),r=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:n,width:s,initialSorting:r});return i},t.prototype.create_column_configurations=function(){var t,i,r,n,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],n=0,a=t.length;a>n;n++)r=t[n],this.column_configurations.push(new e(r,i[r.attribute]));return this.column_configurations},t}(),r=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,r;return i=t.find("tbody"),r=i.find("tr"),r.attr("ng-repeat",e),i},t}(),n=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return v(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(r),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in filtered_list()"}return v(e,t),e.prototype.compile=function(t){var e,i,r,n,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),n="",o=0,s=a.length;s>o;o++)r=a[o],n+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(n),e.attr("ng-repeat","item in getFillerArray() "),i.append(e)},e.prototype.link=function(t,e,i,r){var n,a,o;return a=this.table_configuration.list,n=this.table_configuration.items_per_page,o=this.table_configuration.sort_context,t.filtered_list=function(){var e;return e=t[a],"global"===t[o]?(e=r("orderBy")(e,t.predicate,t.descending),e=r("limitTo")(e,t[d]),e=r("limitTo")(e,t[n])):(e=r("limitTo")(e,t[d]),e=r("limitTo")(e,t[n]),e=r("orderBy")(e,t.predicate,t.descending)),e},t.getFillerArray=function(){var e,i,r,o,s,l,u;if(t[f]===t[m]-1){if(i=t[a].length%t[n],0!==i||0===t[a].length){for(e=t[n]-i-1,u=[],r=o=s=t[a].length,l=t[a].length+e;l>=s?l>=o:o>=l;r=l>=s?++o:--o)u.push(r);return u}return[]}}},e}(r),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,r,n;for(e=angular.element(document.createElement("tr")),n=this.table_configuration.column_configurations,i=0,r=n.length;r>i;i++)t=n[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new n(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,r,n,a;for(n=this.table_configuration.column_configurations,a=[],i=0,r=n.length;r>i;i++){if(e=n[i],e.initialSorting&&!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}return a},t.prototype.post=function(t,e,i,r){return this.setup_initial_sorting(t),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},this.setup.link(t,e,i,r)},t}(),angular.module("angular-table",[]),d="from_page",f="current_page",m="number_of_pages",g="atList",p="atItemsPerPage",u="atFillLastPage",_="atSortContext",l="at-attribute",h="at-sortable",c="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,r;if(e=(i=this.mappings)[r=t.id]||(i[r]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page?e.$parent[i.fill_last_page]=i.initial_fill_last_page:void 0},t.prototype.register_pagination_scope=function(t,e){var i,r;return i=(r=this.mappings)[t]||(r[t]={}),i.pagination_scope=e,i.table_configuration?e.$watch(f,function(){var t;return t=i.table_scope,t[f]=e[f],t[m]=e[m],t[d]=s(t[i.table_configuration.items_per_page],t[f],t[i.table_configuration.list])}):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(t,i,r){var n;return n=r.id,n?e.register_table_scope(n,t):void 0}],compile:function(i,r){var n,s;return s=new o(i,r),e.register_table(s),n=new a(i,s),n.compile(),{post:function(e,i,r){return n.post(e,i,r,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:" ",controller:["$scope","$element","$attrs",function(e,i,r){return t.register_pagination_scope(r.atTableId,e)}],scope:!0,link:function(e,i,r){var n,a,o;return a=t.get_table_configuration(r.atTableId),e[f]=0,o=function(){var t;return e[f]=0,e[a.list]?e[a.list].length>0?(e[m]=Math.ceil(e[a.list].length/e[a.items_per_page]),e.pages=function(){var i,r,n;for(n=[],t=i=0,r=e[m]-1;r>=0?r>=i:i>=r;t=r>=0?++i:--i)n.push(t);return n}()):(e[m]=1,e.pages=[0]):void 0},n=function(t){return t=Math.max(0,t),t=Math.min(e[m]-1,t)},e.go_to_page=function(t){return e[f]=n(t)},o(),e.$watch(a.items_per_page,function(){return o()}),e.$watch(a.list,function(){return o()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 975a1c6..3f10783 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -3,357 +3,10 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var AngularTableManager, ColumnConfiguration, DeclarativeTable, PaginationTableSetup, StandardTableSetup, Table, TableConfiguration, TableSetup, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, + var AngularTableManager, ColumnConfiguration, PaginatedSetup, Setup, StandardSetup, Table, TableConfiguration, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; - angular.module("angular-table", []); - - irk_from_page = "from_page"; - - irk_current_page = "current_page"; - - irk_number_of_pages = "number_of_pages"; - - erk_list = "atList"; - - erk_items_per_page = "atItemsPerPage"; - - erk_fill_last_page = "atFillLastPage"; - - erk_sort_context = "atSortContext"; - - erk_attribute = "at-attribute"; - - erk_sortable = "at-sortable"; - - erk_initial_sorting = "at-initial-sorting"; - - calculate_from_page = function(items_per_page, current_page, list) { - if (list) { - return items_per_page * current_page - list.length; - } - }; - - AngularTableManager = (function() { - function AngularTableManager() { - this.mappings = {}; - } - - AngularTableManager.prototype.get_table_configuration = function(id) { - return this.mappings[id].table_configuration; - }; - - AngularTableManager.prototype.register_table = function(table_configuration) { - var mapping, _base, _name; - mapping = (_base = this.mappings)[_name = table_configuration.id] || (_base[_name] = {}); - mapping.table_configuration = table_configuration; - if (mapping.pagination_scope) { - throw "WHOOPS"; - } - }; - - AngularTableManager.prototype.register_table_scope = function(id, scope) { - var tc; - this.mappings[id].table_scope = scope; - tc = this.mappings[id].table_configuration; - if (tc.initial_items_per_page) { - scope.$parent[tc.items_per_page] = tc.initial_items_per_page; - } - if (tc.initial_sort_context) { - scope.$parent[tc.sort_context] = tc.initial_sort_context; - } - if (tc.initial_fill_last_page) { - return scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page; - } - }; - - AngularTableManager.prototype.register_pagination = function(id, pagination_scope) { - var mapping, _base; - mapping = (_base = this.mappings)[id] || (_base[id] = {}); - mapping.pagination_scope = pagination_scope; - if (mapping.table_configuration) { - return pagination_scope.$watch(irk_current_page, function() { - var ts; - ts = mapping.table_scope; - ts[irk_current_page] = pagination_scope[irk_current_page]; - ts[irk_number_of_pages] = pagination_scope[irk_number_of_pages]; - return ts[irk_from_page] = calculate_from_page(ts[mapping.table_configuration.items_per_page], ts[irk_current_page], ts[mapping.table_configuration.list]); - }); - } - }; - - return AngularTableManager; - - })(); - - angular.module("angular-table").service("angularTableManager", [ - function() { - return new AngularTableManager(); - } - ]); - - angular.module("angular-table").directive("atTable", [ - "$filter", "angularTableManager", function($filter, angularTableManager) { - return { - restrict: "AC", - scope: true, - controller: [ - "$scope", "$element", "$attrs", function($scope, $element, $attrs) { - var id; - id = $attrs["id"]; - if (id) { - return angularTableManager.register_table_scope(id, $scope); - } - } - ], - compile: function(element, attributes, transclude) { - var dt, tc; - tc = new TableConfiguration(attributes); - angularTableManager.register_table(tc); - dt = new DeclarativeTable(element, attributes, tc); - dt.compile(); - return { - post: function($scope, $element, $attributes) { - return dt.post($scope, $element, $attributes, $filter); - } - }; - } - }; - } - ]); - - angular.module("angular-table").directive("atImplicit", [ - function() { - return { - restrict: "AC", - compile: function(element, attributes, transclude) { - var attribute; - attribute = element.attr("at-attribute"); - if (!attribute) { - throw "at-implicit specified without at-attribute: " + (element.html()); - } - return element.append("{{item." + attribute + "}}"); - } - }; - } - ]); - - angular.module("angular-table").directive("atPagination", [ - "angularTableManager", function(angularTableManager) { - return { - replace: true, - restrict: "E", - template: " ", - controller: [ - "$scope", "$element", "$attrs", "angularTableManager", function($scope, $element, $attrs) { - return angularTableManager.register_pagination($attrs.atTableId, $scope); - } - ], - scope: true, - link: function($scope, $element, $attributes) { - var get_list, normalizePage, tc, update; - tc = angularTableManager.get_table_configuration($attributes.atTableId); - $scope[irk_current_page] = 0; - get_list = function() { - return $scope[tc.list]; - }; - update = function(reset) { - var x; - $scope[irk_current_page] = 0; - if (get_list()) { - if (get_list().length > 0) { - $scope[irk_number_of_pages] = Math.ceil(get_list().length / $scope[tc.items_per_page]); - return $scope.pages = (function() { - var _i, _ref, _results; - _results = []; - for (x = _i = 0, _ref = $scope[irk_number_of_pages] - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { - _results.push(x); - } - return _results; - })(); - } else { - $scope[irk_number_of_pages] = 1; - return $scope.pages = [0]; - } - } - }; - normalizePage = function(page) { - page = Math.max(0, page); - page = Math.min($scope[irk_number_of_pages] - 1, page); - return page; - }; - $scope.go_to_page = function(page) { - return $scope[irk_current_page] = normalizePage(page); - }; - update(); - $scope.$watch(tc.items_per_page, function() { - return update(); - }); - return $scope.$watch("atList", function() { - return update(); - }); - } - }; - } - ]); - - Table = (function() { - function Table() {} - - Table.prototype.constructHeader = function() { - var i, tr, _i, _len, _ref; - tr = angular.element(document.createElement("tr")); - _ref = this.get_column_configurations(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - i = _ref[_i]; - tr.append(i.render_html()); - } - return tr; - }; - - Table.prototype.setup_header = function() { - var header, thead, tr; - thead = this.element.find("thead"); - if (thead) { - header = this.constructHeader(); - tr = angular.element(thead).find("tr"); - tr.remove(); - return thead.append(header); - } - }; - - Table.prototype.validateInput = function() { - if (!this.attributes.atPagination && !this.attributes.atList) { - throw "Either a list or Pagination must be specified."; - } - }; - - Table.prototype.create_table_setup = function(attributes) { - if (attributes.atList && !attributes.atPagination) { - return new StandardTableSetup(attributes); - } - if (attributes.atList && attributes.atPagination) { - return new PaginationTableSetup(attributes, this.table_configuration); - } - }; - - Table.prototype.compile = function() { - this.validateInput(); - this.setup_header(); - this.setup = this.create_table_setup(this.attributes); - return this.setup.compile(this.element, this.attributes); - }; - - Table.prototype.setup_initial_sorting = function($scope) { - var bd, _i, _len, _ref, _results; - _ref = this.get_column_configurations(); - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - bd = _ref[_i]; - if (bd.initialSorting) { - if (!bd.attribute) { - throw "initial-sorting specified without attribute."; - } - } - $scope.predicate = bd.attribute; - _results.push($scope.descending = bd.initialSorting === "desc"); - } - return _results; - }; - - Table.prototype.post = function($scope, $element, $attributes, $filter) { - this.setup_initial_sorting($scope); - $scope.getSortIcon = function(predicate) { - if (predicate !== $scope.predicate) { - return "icon-minus"; - } - if ($scope.descending) { - return "icon-chevron-down"; - } else { - return "icon-chevron-up"; - } - }; - return this.setup.link($scope, $element, $attributes, $filter); - }; - - return Table; - - })(); - - TableSetup = (function() { - function TableSetup() {} - - TableSetup.prototype.setupTr = function(element, repeatString) { - var tbody, tr; - tbody = element.find("tbody"); - tr = tbody.find("tr"); - tr.attr("ng-repeat", repeatString); - return tbody; - }; - - return TableSetup; - - })(); - - TableConfiguration = (function() { - TableConfiguration.prototype.register_items_per_page = function(items_per_page) { - if (isNaN(items_per_page)) { - return this.items_per_page = items_per_page; - } else { - this.items_per_page = "" + this.id + "_itemsPerPage"; - return this.initial_items_per_page = parseInt(items_per_page); - } - }; - - TableConfiguration.prototype.register_sort_context = function(sort_context) { - if (sort_context !== void 0) { - if (sort_context === "global") { - this.sort_context = "" + this.id + "_sortContext"; - return this.initial_sort_context = "global"; - } else if (sort_context === "page") { - this.sort_context = "" + this.id + "_sortContext"; - return this.initial_sort_context = "page"; - } else { - return this.sort_context = sort_context; - } - } else { - this.sort_context = "" + this.id + "_sortContext"; - return this.initial_sort_context = "global"; - } - }; - - TableConfiguration.prototype.register_fill_last_page = function(fill_last_page) { - if (fill_last_page !== void 0) { - if (fill_last_page === "true") { - this.fill_last_page = "" + this.id + "_fillLastPage"; - return this.initial_fill_last_page = true; - } else if (fill_last_page === "false") { - this.fill_last_page = "" + this.id + "_fillLastPage"; - return this.initial_fill_last_page = false; - } else if (fill_last_page === "") { - this.fill_last_page = "" + this.id + "_fillLastPage"; - return this.initial_fill_last_page = true; - } else { - return this.fill_last_page = fill_last_page; - } - } - }; - - function TableConfiguration(attributes) { - this.id = attributes.id; - this.list = attributes[erk_list]; - if (attributes[erk_items_per_page]) { - this.register_items_per_page(attributes[erk_items_per_page]); - } - this.register_sort_context(attributes[erk_sort_context]); - this.register_fill_last_page(attributes[erk_fill_last_page]); - } - - return TableConfiguration; - - })(); - ColumnConfiguration = (function() { function ColumnConfiguration(body_markup, header_markup) { this.attribute = body_markup.attribute; @@ -418,16 +71,65 @@ })(); - DeclarativeTable = (function(_super) { - __extends(DeclarativeTable, _super); - - function DeclarativeTable(element, attributes, table_configuration) { - this.element = element; + TableConfiguration = (function() { + function TableConfiguration(table_element, attributes) { + this.table_element = table_element; this.attributes = attributes; - this.table_configuration = table_configuration; + this.id = this.attributes.id; + this.list = this.attributes[erk_list]; + if (this.attributes[erk_items_per_page]) { + this.register_items_per_page(this.attributes[erk_items_per_page]); + } + this.register_sort_context(this.attributes[erk_sort_context]); + this.register_fill_last_page(this.attributes[erk_fill_last_page]); + this.paginated = this.items_per_page !== void 0; + this.create_column_configurations(); } - DeclarativeTable.prototype.capitaliseFirstLetter = function(string) { + TableConfiguration.prototype.register_items_per_page = function(items_per_page) { + if (isNaN(items_per_page)) { + return this.items_per_page = items_per_page; + } else { + this.items_per_page = "" + this.id + "_itemsPerPage"; + return this.initial_items_per_page = parseInt(items_per_page); + } + }; + + TableConfiguration.prototype.register_sort_context = function(sort_context) { + if (sort_context !== void 0) { + if (sort_context === "global") { + this.sort_context = "" + this.id + "_sortContext"; + return this.initial_sort_context = "global"; + } else if (sort_context === "page") { + this.sort_context = "" + this.id + "_sortContext"; + return this.initial_sort_context = "page"; + } else { + return this.sort_context = sort_context; + } + } else { + this.sort_context = "" + this.id + "_sortContext"; + return this.initial_sort_context = "global"; + } + }; + + TableConfiguration.prototype.register_fill_last_page = function(fill_last_page) { + if (fill_last_page !== void 0) { + if (fill_last_page === "true") { + this.fill_last_page = "" + this.id + "_fillLastPage"; + return this.initial_fill_last_page = true; + } else if (fill_last_page === "false") { + this.fill_last_page = "" + this.id + "_fillLastPage"; + return this.initial_fill_last_page = false; + } else if (fill_last_page === "") { + this.fill_last_page = "" + this.id + "_fillLastPage"; + return this.initial_fill_last_page = true; + } else { + return this.fill_last_page = fill_last_page; + } + } + }; + + TableConfiguration.prototype.capitaliseFirstLetter = function(string) { if (string) { return string.charAt(0).toUpperCase() + string.slice(1); } else { @@ -435,7 +137,7 @@ } }; - DeclarativeTable.prototype.extractWidth = function(classes) { + TableConfiguration.prototype.extractWidth = function(classes) { var width; width = /([0-9]+px)/i.exec(classes); if (width) { @@ -445,7 +147,7 @@ } }; - DeclarativeTable.prototype.isSortable = function(classes) { + TableConfiguration.prototype.isSortable = function(classes) { var sortable; sortable = /(sortable)/i.exec(classes); if (sortable) { @@ -455,7 +157,7 @@ } }; - DeclarativeTable.prototype.getInitialSorting = function(td) { + TableConfiguration.prototype.getInitialSorting = function(td) { var initialSorting; initialSorting = td.attr("at-initial-sorting"); if (initialSorting) { @@ -467,7 +169,7 @@ return void 0; }; - DeclarativeTable.prototype.collect_header_markup = function(table) { + TableConfiguration.prototype.collect_header_markup = function(table) { var customHeaderMarkups, th, tr, _i, _len, _ref; customHeaderMarkups = {}; tr = table.find("tr"); @@ -483,7 +185,7 @@ return customHeaderMarkups; }; - DeclarativeTable.prototype.collect_body_markup = function(table) { + TableConfiguration.prototype.collect_body_markup = function(table) { var attribute, bodyDefinition, initialSorting, sortable, td, title, width, _i, _len, _ref; bodyDefinition = []; _ref = table.find("td"); @@ -506,56 +208,63 @@ return bodyDefinition; }; - DeclarativeTable.prototype.create_column_configurations = function() { - var body_markup, column_configurations, header_markup, i, _i, _len; - header_markup = this.collect_header_markup(this.element); - body_markup = this.collect_body_markup(this.element); - column_configurations = []; + TableConfiguration.prototype.create_column_configurations = function() { + var body_markup, header_markup, i, _i, _len; + header_markup = this.collect_header_markup(this.table_element); + body_markup = this.collect_body_markup(this.table_element); + this.column_configurations = []; for (_i = 0, _len = body_markup.length; _i < _len; _i++) { i = body_markup[_i]; - column_configurations.push(new ColumnConfiguration(i, header_markup[i.attribute])); + this.column_configurations.push(new ColumnConfiguration(i, header_markup[i.attribute])); } - return column_configurations; + return this.column_configurations; }; - DeclarativeTable.prototype.get_column_configurations = function() { - return this.column_configurations || (this.column_configurations = this.create_column_configurations()); - }; + return TableConfiguration; + + })(); - DeclarativeTable.prototype.create_table_configuration = function() {}; + Setup = (function() { + function Setup() {} - DeclarativeTable.prototype.get_table_configuration = function() {}; + Setup.prototype.setupTr = function(element, repeatString) { + var tbody, tr; + tbody = element.find("tbody"); + tr = tbody.find("tr"); + tr.attr("ng-repeat", repeatString); + return tbody; + }; - return DeclarativeTable; + return Setup; - })(Table); + })(); - StandardTableSetup = (function(_super) { - __extends(StandardTableSetup, _super); + StandardSetup = (function(_super) { + __extends(StandardSetup, _super); - function StandardTableSetup(attributes) { - this.repeatString = "item in " + attributes.atList + " | orderBy:predicate:descending"; + function StandardSetup(table_configuration) { + this.repeatString = "item in " + table_configuration.list + " | orderBy:predicate:descending"; } - StandardTableSetup.prototype.compile = function(element, attributes, transclude) { + StandardSetup.prototype.compile = function(element, attributes, transclude) { return this.setupTr(element, this.repeatString); }; - StandardTableSetup.prototype.link = function() {}; + StandardSetup.prototype.link = function() {}; - return StandardTableSetup; + return StandardSetup; - })(TableSetup); + })(Setup); - PaginationTableSetup = (function(_super) { - __extends(PaginationTableSetup, _super); + PaginatedSetup = (function(_super) { + __extends(PaginatedSetup, _super); - function PaginationTableSetup(attributes, table_configuration) { + function PaginatedSetup(table_configuration) { this.table_configuration = table_configuration; this.repeatString = "item in filtered_list()"; } - PaginationTableSetup.prototype.compile = function(element, attributes, transclude) { + PaginatedSetup.prototype.compile = function(element) { var fillerTr, tbody, td, tdString, tds, _i, _len; tbody = this.setupTr(element, this.repeatString); tds = element.find("td"); @@ -571,7 +280,7 @@ tbody.append(fillerTr); }; - PaginationTableSetup.prototype.link = function($scope, $element, $attributes, $filter) { + PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) { var ipp, list_name, sc; list_name = this.table_configuration.list; ipp = this.table_configuration.items_per_page; @@ -608,8 +317,274 @@ }; }; - return PaginationTableSetup; + return PaginatedSetup; + + })(Setup); + + Table = (function() { + function Table(element, table_configuration) { + this.element = element; + this.table_configuration = table_configuration; + } + + Table.prototype.constructHeader = function() { + var i, tr, _i, _len, _ref; + tr = angular.element(document.createElement("tr")); + _ref = this.table_configuration.column_configurations; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + i = _ref[_i]; + tr.append(i.render_html()); + } + return tr; + }; + + Table.prototype.setup_header = function() { + var header, thead, tr; + thead = this.element.find("thead"); + if (thead) { + header = this.constructHeader(); + tr = angular.element(thead).find("tr"); + tr.remove(); + return thead.append(header); + } + }; + + Table.prototype.get_setup = function() { + if (this.table_configuration.paginated) { + return new PaginatedSetup(this.table_configuration); + } else { + return new StandardSetup(this.table_configuration); + } + }; + + Table.prototype.compile = function() { + this.setup_header(); + this.setup = this.get_setup(); + return this.setup.compile(this.element); + }; + + Table.prototype.setup_initial_sorting = function($scope) { + var bd, _i, _len, _ref, _results; + _ref = this.table_configuration.column_configurations; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + bd = _ref[_i]; + if (bd.initialSorting) { + if (!bd.attribute) { + throw "initial-sorting specified without attribute."; + } + } + $scope.predicate = bd.attribute; + _results.push($scope.descending = bd.initialSorting === "desc"); + } + return _results; + }; + + Table.prototype.post = function($scope, $element, $attributes, $filter) { + this.setup_initial_sorting($scope); + $scope.getSortIcon = function(predicate) { + if (predicate !== $scope.predicate) { + return "icon-minus"; + } + if ($scope.descending) { + return "icon-chevron-down"; + } else { + return "icon-chevron-up"; + } + }; + return this.setup.link($scope, $element, $attributes, $filter); + }; + + return Table; + + })(); + + angular.module("angular-table", []); + + irk_from_page = "from_page"; + + irk_current_page = "current_page"; + + irk_number_of_pages = "number_of_pages"; + + erk_list = "atList"; + + erk_items_per_page = "atItemsPerPage"; + + erk_fill_last_page = "atFillLastPage"; + + erk_sort_context = "atSortContext"; + + erk_attribute = "at-attribute"; + + erk_sortable = "at-sortable"; + + erk_initial_sorting = "at-initial-sorting"; + + calculate_from_page = function(items_per_page, current_page, list) { + if (list) { + return items_per_page * current_page - list.length; + } + }; + + AngularTableManager = (function() { + function AngularTableManager() { + this.mappings = {}; + } + + AngularTableManager.prototype.get_table_configuration = function(id) { + return this.mappings[id].table_configuration; + }; + + AngularTableManager.prototype.register_table = function(table_configuration) { + var mapping, _base, _name; + mapping = (_base = this.mappings)[_name = table_configuration.id] || (_base[_name] = {}); + mapping.table_configuration = table_configuration; + if (mapping.pagination_scope) { + throw "WHOOPS"; + } + }; + + AngularTableManager.prototype.register_table_scope = function(id, scope) { + var tc; + this.mappings[id].table_scope = scope; + tc = this.mappings[id].table_configuration; + if (tc.initial_items_per_page) { + scope.$parent[tc.items_per_page] = tc.initial_items_per_page; + } + if (tc.initial_sort_context) { + scope.$parent[tc.sort_context] = tc.initial_sort_context; + } + if (tc.initial_fill_last_page) { + return scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page; + } + }; + + AngularTableManager.prototype.register_pagination_scope = function(id, pagination_scope) { + var mapping, _base; + mapping = (_base = this.mappings)[id] || (_base[id] = {}); + mapping.pagination_scope = pagination_scope; + if (mapping.table_configuration) { + return pagination_scope.$watch(irk_current_page, function() { + var ts; + ts = mapping.table_scope; + ts[irk_current_page] = pagination_scope[irk_current_page]; + ts[irk_number_of_pages] = pagination_scope[irk_number_of_pages]; + return ts[irk_from_page] = calculate_from_page(ts[mapping.table_configuration.items_per_page], ts[irk_current_page], ts[mapping.table_configuration.list]); + }); + } + }; + + return AngularTableManager; + + })(); + + angular.module("angular-table").service("angularTableManager", [ + function() { + return new AngularTableManager(); + } + ]); + + angular.module("angular-table").directive("atTable", [ + "$filter", "angularTableManager", function($filter, angularTableManager) { + return { + restrict: "AC", + scope: true, + controller: [ + "$scope", "$element", "$attrs", function($scope, $element, $attrs) { + var id; + id = $attrs["id"]; + if (id) { + return angularTableManager.register_table_scope(id, $scope); + } + } + ], + compile: function(element, attributes, transclude) { + var dt, tc; + tc = new TableConfiguration(element, attributes); + angularTableManager.register_table(tc); + dt = new Table(element, tc); + dt.compile(); + return { + post: function($scope, $element, $attributes) { + return dt.post($scope, $element, $attributes, $filter); + } + }; + } + }; + } + ]); + + angular.module("angular-table").directive("atPagination", [ + "angularTableManager", function(angularTableManager) { + return { + replace: true, + restrict: "E", + template: " ", + controller: [ + "$scope", "$element", "$attrs", function($scope, $element, $attrs) { + return angularTableManager.register_pagination_scope($attrs.atTableId, $scope); + } + ], + scope: true, + link: function($scope, $element, $attributes) { + var normalizePage, tc, update; + tc = angularTableManager.get_table_configuration($attributes.atTableId); + $scope[irk_current_page] = 0; + update = function(reset) { + var x; + $scope[irk_current_page] = 0; + if ($scope[tc.list]) { + if ($scope[tc.list].length > 0) { + $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]); + return $scope.pages = (function() { + var _i, _ref, _results; + _results = []; + for (x = _i = 0, _ref = $scope[irk_number_of_pages] - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { + _results.push(x); + } + return _results; + })(); + } else { + $scope[irk_number_of_pages] = 1; + return $scope.pages = [0]; + } + } + }; + normalizePage = function(page) { + page = Math.max(0, page); + page = Math.min($scope[irk_number_of_pages] - 1, page); + return page; + }; + $scope.go_to_page = function(page) { + return $scope[irk_current_page] = normalizePage(page); + }; + update(); + $scope.$watch(tc.items_per_page, function() { + return update(); + }); + return $scope.$watch(tc.list, function() { + return update(); + }); + } + }; + } + ]); - })(TableSetup); + angular.module("angular-table").directive("atImplicit", [ + function() { + return { + restrict: "AC", + compile: function(element, attributes, transclude) { + var attribute; + attribute = element.attr("at-attribute"); + if (!attribute) { + throw "at-implicit specified without at-attribute: " + (element.html()); + } + return element.append("{{item." + attribute + "}}"); + } + }; + } + ]); }).call(this); From 2fae882e47943bfaac5fa8df4edb952c746e0e9d Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 12 Feb 2014 18:59:34 +0100 Subject: [PATCH 058/190] updated test templates --- test/templates/pagination/pagination.html | 2 +- test/templates/pagination/sort_context_global.html | 2 +- test/templates/pagination/sort_context_page.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/templates/pagination/pagination.html b/test/templates/pagination/pagination.html index dea76b0..9a3a262 100644 --- a/test/templates/pagination/pagination.html +++ b/test/templates/pagination/pagination.html @@ -1,4 +1,4 @@ -
  
+
diff --git a/test/templates/pagination/sort_context_global.html b/test/templates/pagination/sort_context_global.html index 5f2da97..ea178cb 100644 --- a/test/templates/pagination/sort_context_global.html +++ b/test/templates/pagination/sort_context_global.html @@ -1,4 +1,4 @@ -
+
diff --git a/test/templates/pagination/sort_context_page.html b/test/templates/pagination/sort_context_page.html index c491d0f..f471c19 100644 --- a/test/templates/pagination/sort_context_page.html +++ b/test/templates/pagination/sort_context_page.html @@ -1,4 +1,4 @@ -
+
From 74613806b2bd9f628df73fa8bf957932f9fdc7fe Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Thu, 13 Feb 2014 14:51:02 +0100 Subject: [PATCH 059/190] implemented max-page feature --- coffee/at-pagination.coffee | 76 ++++++++++++++++--- coffee/at-table.coffee | 20 +++-- .../configuration/table_configuration.coffee | 12 ++- 3 files changed, 92 insertions(+), 16 deletions(-) diff --git a/coffee/at-pagination.coffee b/coffee/at-pagination.coffee index f3386b1..3afa798 100644 --- a/coffee/at-pagination.coffee +++ b/coffee/at-pagination.coffee @@ -7,13 +7,31 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" " @@ -30,31 +48,71 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" $scope[irk_current_page] = 0 + generate_page_array = (start, end) -> + x for x in [start..end] + update = (reset) -> $scope[irk_current_page] = 0 if $scope[tc.list] if $scope[tc.list].length > 0 $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]) - $scope.pages = for x in [0..($scope[irk_number_of_pages] - 1)] - x + if $scope.show_sectioning() + $scope.pages = generate_page_array(0, $scope[tc.max_pages] - 1) + else + $scope.pages = generate_page_array(0, $scope[irk_number_of_pages] - 1) else $scope[irk_number_of_pages] = 1 $scope.pages = [0] - normalizePage = (page) -> - page = Math.max(0, page) - page = Math.min($scope[irk_number_of_pages] - 1, page) - page + keep_in_bounds = (val, min, max) -> + val = Math.max(min, val) + Math.min(max, val) + + $scope.show_sectioning = () -> + tc.max_pages && $scope[irk_number_of_pages] > $scope[tc.max_pages] + + shift_sectioning = (current_start, steps, length, upper_bound) -> + new_start = current_start + steps + if new_start > (upper_bound - length) + upper_bound - length + else if new_start < 0 + 0 + else + new_start + $scope.pages = generate_page_array(new_start, new_start + parseInt($scope[tc.max_pages]) - 1) + + $scope.update_sectioning = () -> + new_start = undefined + if $scope.pages[0] > $scope[irk_current_page] + diff = $scope.pages[0] - $scope[irk_current_page] + shift_sectioning($scope.pages[0], -diff, $scope[tc.max_pages], $scope[irk_number_of_pages]) + else if $scope.pages[$scope.pages.length - 1] < $scope[irk_current_page] + diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1] + shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]) + + $scope.step_page = (step) -> + step = parseInt(step) + $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page] + step, 0, $scope[irk_number_of_pages] - 1) + $scope.update_sectioning() $scope.go_to_page = (page) -> - $scope[irk_current_page] = normalizePage(page) + $scope[irk_current_page] = page + + $scope.jump_back = () -> + $scope.step_page(-$scope[tc.max_pages]) + + $scope.jump_ahead = () -> + $scope.step_page($scope[tc.max_pages]) update() $scope.$watch tc.items_per_page, () -> update() + $scope.$watch tc.max_pages, () -> + update() + $scope.$watch tc.list, () -> update() diff --git a/coffee/at-table.coffee b/coffee/at-table.coffee index 3d0f26f..f36f0aa 100644 --- a/coffee/at-table.coffee +++ b/coffee/at-table.coffee @@ -11,6 +11,7 @@ erk_list = "atList" erk_items_per_page = "atItemsPerPage" erk_fill_last_page = "atFillLastPage" erk_sort_context = "atSortContext" +erk_max_pages = "atMaxPages" # column erk_attribute = "at-attribute" erk_sortable = "at-sortable" @@ -20,6 +21,13 @@ calculate_from_page = (items_per_page, current_page, list) -> if list items_per_page * current_page - list.length +update_table_scope = (table_scope, pagination_scope, table_configuration) -> + table_scope[irk_current_page] = pagination_scope[irk_current_page] + table_scope[irk_number_of_pages] = pagination_scope[irk_number_of_pages] + table_scope[irk_from_page] = calculate_from_page(table_scope[table_configuration.items_per_page], + table_scope[irk_current_page], + table_scope[table_configuration.list]) + class AngularTableManager constructor: () -> @@ -50,18 +58,18 @@ class AngularTableManager if tc.initial_fill_last_page scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page + register_pagination_scope: (id, pagination_scope) -> mapping = @mappings[id] ||= {} mapping.pagination_scope = pagination_scope if mapping.table_configuration pagination_scope.$watch(irk_current_page, () -> - ts = mapping.table_scope - ts[irk_current_page] = pagination_scope[irk_current_page] - ts[irk_number_of_pages] = pagination_scope[irk_number_of_pages] - ts[irk_from_page] = calculate_from_page(ts[mapping.table_configuration.items_per_page], - ts[irk_current_page], - ts[mapping.table_configuration.list]) + update_table_scope(mapping.table_scope, pagination_scope, mapping.table_configuration) + ) + + pagination_scope.$watch(irk_number_of_pages, () -> + update_table_scope(mapping.table_scope, pagination_scope, mapping.table_configuration) ) angular.module("angular-table").service "angularTableManager", [() -> diff --git a/coffee/configuration/table_configuration.coffee b/coffee/configuration/table_configuration.coffee index 875adb5..1f24634 100644 --- a/coffee/configuration/table_configuration.coffee +++ b/coffee/configuration/table_configuration.coffee @@ -6,9 +6,11 @@ class TableConfiguration @register_items_per_page(@attributes[erk_items_per_page]) if @attributes[erk_items_per_page] @register_sort_context(@attributes[erk_sort_context]) @register_fill_last_page(@attributes[erk_fill_last_page]) - @paginated = @items_per_page != undefined + @register_max_pages(@attributes[erk_max_pages]) + @paginated = @items_per_page != undefined @create_column_configurations() + # TODO: refactor the following 4 methods into nicer, if-less logic register_items_per_page: (items_per_page) -> if isNaN(items_per_page) @items_per_page = items_per_page @@ -44,6 +46,14 @@ class TableConfiguration else @fill_last_page = fill_last_page + register_max_pages: (max_pages) -> + if max_pages isnt undefined + if isNaN(max_pages) + @max_pages = max_pages + else + @max_pages = "#{@id}_maxPages" + @initial_items_per_page = parseInt(max_pages) + capitaliseFirstLetter: (string) -> if string then string.charAt(0).toUpperCase() + string.slice(1) else "" From ed2fba9b1036b8e2b70db348b7b826beecf2c28e Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Thu, 13 Feb 2014 21:03:57 +0100 Subject: [PATCH 060/190] compiled new version --- angular-table.js | 108 +++++++++++++++----- angular-table.min.js | 2 +- gem/app/assets/javascripts/angular-table.js | 108 +++++++++++++++----- 3 files changed, 171 insertions(+), 47 deletions(-) diff --git a/angular-table.js b/angular-table.js index 3f10783..45e2f33 100644 --- a/angular-table.js +++ b/angular-table.js @@ -3,7 +3,7 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var AngularTableManager, ColumnConfiguration, PaginatedSetup, Setup, StandardSetup, Table, TableConfiguration, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, + var AngularTableManager, ColumnConfiguration, PaginatedSetup, Setup, StandardSetup, Table, TableConfiguration, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, update_table_scope, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -82,6 +82,7 @@ } this.register_sort_context(this.attributes[erk_sort_context]); this.register_fill_last_page(this.attributes[erk_fill_last_page]); + this.register_max_pages(this.attributes[erk_max_pages]); this.paginated = this.items_per_page !== void 0; this.create_column_configurations(); } @@ -129,6 +130,17 @@ } }; + TableConfiguration.prototype.register_max_pages = function(max_pages) { + if (max_pages !== void 0) { + if (isNaN(max_pages)) { + return this.max_pages = max_pages; + } else { + this.max_pages = "" + this.id + "_maxPages"; + return this.initial_items_per_page = parseInt(max_pages); + } + } + }; + TableConfiguration.prototype.capitaliseFirstLetter = function(string) { if (string) { return string.charAt(0).toUpperCase() + string.slice(1); @@ -415,6 +427,8 @@ erk_sort_context = "atSortContext"; + erk_max_pages = "atMaxPages"; + erk_attribute = "at-attribute"; erk_sortable = "at-sortable"; @@ -427,6 +441,12 @@ } }; + update_table_scope = function(table_scope, pagination_scope, table_configuration) { + table_scope[irk_current_page] = pagination_scope[irk_current_page]; + table_scope[irk_number_of_pages] = pagination_scope[irk_number_of_pages]; + return table_scope[irk_from_page] = calculate_from_page(table_scope[table_configuration.items_per_page], table_scope[irk_current_page], table_scope[table_configuration.list]); + }; + AngularTableManager = (function() { function AngularTableManager() { this.mappings = {}; @@ -465,12 +485,11 @@ mapping = (_base = this.mappings)[id] || (_base[id] = {}); mapping.pagination_scope = pagination_scope; if (mapping.table_configuration) { - return pagination_scope.$watch(irk_current_page, function() { - var ts; - ts = mapping.table_scope; - ts[irk_current_page] = pagination_scope[irk_current_page]; - ts[irk_number_of_pages] = pagination_scope[irk_number_of_pages]; - return ts[irk_from_page] = calculate_from_page(ts[mapping.table_configuration.items_per_page], ts[irk_current_page], ts[mapping.table_configuration.list]); + pagination_scope.$watch(irk_current_page, function() { + return update_table_scope(mapping.table_scope, pagination_scope, mapping.table_configuration); + }); + return pagination_scope.$watch(irk_number_of_pages, function() { + return update_table_scope(mapping.table_scope, pagination_scope, mapping.table_configuration); }); } }; @@ -520,7 +539,7 @@ return { replace: true, restrict: "E", - template: " ", + template: " ", controller: [ "$scope", "$element", "$attrs", function($scope, $element, $attrs) { return angularTableManager.register_pagination_scope($attrs.atTableId, $scope); @@ -528,41 +547,84 @@ ], scope: true, link: function($scope, $element, $attributes) { - var normalizePage, tc, update; + var generate_page_array, keep_in_bounds, shift_sectioning, tc, update; tc = angularTableManager.get_table_configuration($attributes.atTableId); $scope[irk_current_page] = 0; + generate_page_array = function(start, end) { + var x, _i, _results; + _results = []; + for (x = _i = start; start <= end ? _i <= end : _i >= end; x = start <= end ? ++_i : --_i) { + _results.push(x); + } + return _results; + }; update = function(reset) { - var x; $scope[irk_current_page] = 0; if ($scope[tc.list]) { if ($scope[tc.list].length > 0) { $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]); - return $scope.pages = (function() { - var _i, _ref, _results; - _results = []; - for (x = _i = 0, _ref = $scope[irk_number_of_pages] - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { - _results.push(x); - } - return _results; - })(); + if ($scope.show_sectioning()) { + return $scope.pages = generate_page_array(0, $scope[tc.max_pages] - 1); + } else { + return $scope.pages = generate_page_array(0, $scope[irk_number_of_pages] - 1); + } } else { $scope[irk_number_of_pages] = 1; return $scope.pages = [0]; } } }; - normalizePage = function(page) { - page = Math.max(0, page); - page = Math.min($scope[irk_number_of_pages] - 1, page); - return page; + keep_in_bounds = function(val, min, max) { + val = Math.max(min, val); + return Math.min(max, val); + }; + $scope.show_sectioning = function() { + return tc.max_pages && $scope[irk_number_of_pages] > $scope[tc.max_pages]; + }; + shift_sectioning = function(current_start, steps, length, upper_bound) { + var new_start; + new_start = current_start + steps; + if (new_start > (upper_bound - length)) { + upper_bound - length; + } else if (new_start < 0) { + 0; + } else { + new_start; + } + return $scope.pages = generate_page_array(new_start, new_start + parseInt($scope[tc.max_pages]) - 1); + }; + $scope.update_sectioning = function() { + var diff, new_start; + new_start = void 0; + if ($scope.pages[0] > $scope[irk_current_page]) { + diff = $scope.pages[0] - $scope[irk_current_page]; + return shift_sectioning($scope.pages[0], -diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); + } else if ($scope.pages[$scope.pages.length - 1] < $scope[irk_current_page]) { + diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1]; + return shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); + } + }; + $scope.step_page = function(step) { + step = parseInt(step); + $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page] + step, 0, $scope[irk_number_of_pages] - 1); + return $scope.update_sectioning(); }; $scope.go_to_page = function(page) { - return $scope[irk_current_page] = normalizePage(page); + return $scope[irk_current_page] = page; + }; + $scope.jump_back = function() { + return $scope.step_page(-$scope[tc.max_pages]); + }; + $scope.jump_ahead = function() { + return $scope.step_page($scope[tc.max_pages]); }; update(); $scope.$watch(tc.items_per_page, function() { return update(); }); + $scope.$watch(tc.max_pages, function() { + return update(); + }); return $scope.$watch(tc.list, function() { return update(); }); diff --git a/angular-table.min.js b/angular-table.min.js index 157095e..104828c 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,r,n,a,o,s,l,u,c,p,g,_,h,f,d,m,b={}.hasOwnProperty,v=function(t,e){function i(){this.constructor=t}for(var r in e)b.call(e,r)&&(t[r]=e[r]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,r,n,a;if(this.custom_content){for(n=this.attributes,a=[],i=0,r=n.length;r>i;i++)e=n[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"')"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[p]&&this.register_items_per_page(this.attributes[p]),this.register_sort_context(this.attributes[_]),this.register_fill_last_page(this.attributes[u]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,r,n,a,o;for(e={},r=t.find("tr"),o=r.find("th"),n=0,a=o.length;a>n;n++)i=o[n],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,r,n,a,o,s,l,u,c;for(i=[],c=t.find("td"),l=0,u=c.length;u>l;l++)a=c[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),n=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),r=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:n,width:s,initialSorting:r});return i},t.prototype.create_column_configurations=function(){var t,i,r,n,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],n=0,a=t.length;a>n;n++)r=t[n],this.column_configurations.push(new e(r,i[r.attribute]));return this.column_configurations},t}(),r=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,r;return i=t.find("tbody"),r=i.find("tr"),r.attr("ng-repeat",e),i},t}(),n=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return v(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(r),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in filtered_list()"}return v(e,t),e.prototype.compile=function(t){var e,i,r,n,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),n="",o=0,s=a.length;s>o;o++)r=a[o],n+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(n),e.attr("ng-repeat","item in getFillerArray() "),i.append(e)},e.prototype.link=function(t,e,i,r){var n,a,o;return a=this.table_configuration.list,n=this.table_configuration.items_per_page,o=this.table_configuration.sort_context,t.filtered_list=function(){var e;return e=t[a],"global"===t[o]?(e=r("orderBy")(e,t.predicate,t.descending),e=r("limitTo")(e,t[d]),e=r("limitTo")(e,t[n])):(e=r("limitTo")(e,t[d]),e=r("limitTo")(e,t[n]),e=r("orderBy")(e,t.predicate,t.descending)),e},t.getFillerArray=function(){var e,i,r,o,s,l,u;if(t[f]===t[m]-1){if(i=t[a].length%t[n],0!==i||0===t[a].length){for(e=t[n]-i-1,u=[],r=o=s=t[a].length,l=t[a].length+e;l>=s?l>=o:o>=l;r=l>=s?++o:--o)u.push(r);return u}return[]}}},e}(r),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,r,n;for(e=angular.element(document.createElement("tr")),n=this.table_configuration.column_configurations,i=0,r=n.length;r>i;i++)t=n[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new n(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,r,n,a;for(n=this.table_configuration.column_configurations,a=[],i=0,r=n.length;r>i;i++){if(e=n[i],e.initialSorting&&!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}return a},t.prototype.post=function(t,e,i,r){return this.setup_initial_sorting(t),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},this.setup.link(t,e,i,r)},t}(),angular.module("angular-table",[]),d="from_page",f="current_page",m="number_of_pages",g="atList",p="atItemsPerPage",u="atFillLastPage",_="atSortContext",l="at-attribute",h="at-sortable",c="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,r;if(e=(i=this.mappings)[r=t.id]||(i[r]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page?e.$parent[i.fill_last_page]=i.initial_fill_last_page:void 0},t.prototype.register_pagination_scope=function(t,e){var i,r;return i=(r=this.mappings)[t]||(r[t]={}),i.pagination_scope=e,i.table_configuration?e.$watch(f,function(){var t;return t=i.table_scope,t[f]=e[f],t[m]=e[m],t[d]=s(t[i.table_configuration.items_per_page],t[f],t[i.table_configuration.list])}):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(t,i,r){var n;return n=r.id,n?e.register_table_scope(n,t):void 0}],compile:function(i,r){var n,s;return s=new o(i,r),e.register_table(s),n=new a(i,s),n.compile(),{post:function(e,i,r){return n.post(e,i,r,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:" ",controller:["$scope","$element","$attrs",function(e,i,r){return t.register_pagination_scope(r.atTableId,e)}],scope:!0,link:function(e,i,r){var n,a,o;return a=t.get_table_configuration(r.atTableId),e[f]=0,o=function(){var t;return e[f]=0,e[a.list]?e[a.list].length>0?(e[m]=Math.ceil(e[a.list].length/e[a.items_per_page]),e.pages=function(){var i,r,n;for(n=[],t=i=0,r=e[m]-1;r>=0?r>=i:i>=r;t=r>=0?++i:--i)n.push(t);return n}()):(e[m]=1,e.pages=[0]):void 0},n=function(t){return t=Math.max(0,t),t=Math.min(e[m]-1,t)},e.go_to_page=function(t){return e[f]=n(t)},o(),e.$watch(a.items_per_page,function(){return o()}),e.$watch(a.list,function(){return o()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var t,e,i,n,r,a,o,s,l,u,p,c,g,_,h,f,d,m,b,v,y={}.hasOwnProperty,x=function(t,e){function i(){this.constructor=t}for(var n in e)y.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"')"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[u]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_items_per_page=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,p;for(i=[],p=t.find("td"),l=0,u=p.length;u>l;l++)a=p[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return x(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in filtered_list()"}return x(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in getFillerArray() "),i.append(e)},e.prototype.link=function(t,e,i,n){var r,a,o;return a=this.table_configuration.list,r=this.table_configuration.items_per_page,o=this.table_configuration.sort_context,t.filtered_list=function(){var e;return e=t[a],"global"===t[o]?(e=n("orderBy")(e,t.predicate,t.descending),e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r])):(e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r]),e=n("orderBy")(e,t.predicate,t.descending)),e},t.getFillerArray=function(){var e,i,n,o,s,l,u;if(t[d]===t[b]-1){if(i=t[a].length%t[r],0!==i||0===t[a].length){for(e=t[r]-i-1,u=[],n=o=s=t[a].length,l=t[a].length+e;l>=s?l>=o:o>=l;n=l>=s?++o:--o)u.push(n);return u}return[]}}},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++){if(e=r[i],e.initialSorting&&!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),m="from_page",d="current_page",b="number_of_pages",g="atList",c="atItemsPerPage",u="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",p="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},v=function(t,e,i){return t[d]=e[d],t[b]=e[b],t[m]=s(t[i.items_per_page],t[d],t[i.list])},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page?e.$parent[i.fill_last_page]=i.initial_fill_last_page:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(d,function(){return v(i.table_scope,e,i.table_configuration)}),e.$watch(b,function(){return v(i.table_scope,e,i.table_configuration)})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(t,i,n){var r;return r=n.id,r?e.register_table_scope(r,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:" ",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[d]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[d]=0,e[s.list]?e[s.list].length>0?(e[b]=Math.ceil(e[s.list].length/e[s.items_per_page]),e.pages=e.show_sectioning()?r(0,e[s.max_pages]-1):r(0,e[b]-1)):(e[b]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[b]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[d]?(t=e.pages[0]-e[d],o(e.pages[0],-t,e[s.max_pages],e[b])):e.pages[e.pages.length-1] ", + template: " ", controller: [ "$scope", "$element", "$attrs", function($scope, $element, $attrs) { return angularTableManager.register_pagination_scope($attrs.atTableId, $scope); @@ -528,41 +547,84 @@ ], scope: true, link: function($scope, $element, $attributes) { - var normalizePage, tc, update; + var generate_page_array, keep_in_bounds, shift_sectioning, tc, update; tc = angularTableManager.get_table_configuration($attributes.atTableId); $scope[irk_current_page] = 0; + generate_page_array = function(start, end) { + var x, _i, _results; + _results = []; + for (x = _i = start; start <= end ? _i <= end : _i >= end; x = start <= end ? ++_i : --_i) { + _results.push(x); + } + return _results; + }; update = function(reset) { - var x; $scope[irk_current_page] = 0; if ($scope[tc.list]) { if ($scope[tc.list].length > 0) { $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]); - return $scope.pages = (function() { - var _i, _ref, _results; - _results = []; - for (x = _i = 0, _ref = $scope[irk_number_of_pages] - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { - _results.push(x); - } - return _results; - })(); + if ($scope.show_sectioning()) { + return $scope.pages = generate_page_array(0, $scope[tc.max_pages] - 1); + } else { + return $scope.pages = generate_page_array(0, $scope[irk_number_of_pages] - 1); + } } else { $scope[irk_number_of_pages] = 1; return $scope.pages = [0]; } } }; - normalizePage = function(page) { - page = Math.max(0, page); - page = Math.min($scope[irk_number_of_pages] - 1, page); - return page; + keep_in_bounds = function(val, min, max) { + val = Math.max(min, val); + return Math.min(max, val); + }; + $scope.show_sectioning = function() { + return tc.max_pages && $scope[irk_number_of_pages] > $scope[tc.max_pages]; + }; + shift_sectioning = function(current_start, steps, length, upper_bound) { + var new_start; + new_start = current_start + steps; + if (new_start > (upper_bound - length)) { + upper_bound - length; + } else if (new_start < 0) { + 0; + } else { + new_start; + } + return $scope.pages = generate_page_array(new_start, new_start + parseInt($scope[tc.max_pages]) - 1); + }; + $scope.update_sectioning = function() { + var diff, new_start; + new_start = void 0; + if ($scope.pages[0] > $scope[irk_current_page]) { + diff = $scope.pages[0] - $scope[irk_current_page]; + return shift_sectioning($scope.pages[0], -diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); + } else if ($scope.pages[$scope.pages.length - 1] < $scope[irk_current_page]) { + diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1]; + return shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); + } + }; + $scope.step_page = function(step) { + step = parseInt(step); + $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page] + step, 0, $scope[irk_number_of_pages] - 1); + return $scope.update_sectioning(); }; $scope.go_to_page = function(page) { - return $scope[irk_current_page] = normalizePage(page); + return $scope[irk_current_page] = page; + }; + $scope.jump_back = function() { + return $scope.step_page(-$scope[tc.max_pages]); + }; + $scope.jump_ahead = function() { + return $scope.step_page($scope[tc.max_pages]); }; update(); $scope.$watch(tc.items_per_page, function() { return update(); }); + $scope.$watch(tc.max_pages, function() { + return update(); + }); return $scope.$watch(tc.list, function() { return update(); }); From 6c51c6a60e2ef3d0a728c95170b078c578c5e464 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Thu, 13 Feb 2014 21:17:50 +0100 Subject: [PATCH 061/190] initial max pages was not used correctly --- coffee/at-table.coffee | 3 +++ coffee/configuration/table_configuration.coffee | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/coffee/at-table.coffee b/coffee/at-table.coffee index f36f0aa..9059926 100644 --- a/coffee/at-table.coffee +++ b/coffee/at-table.coffee @@ -58,6 +58,9 @@ class AngularTableManager if tc.initial_fill_last_page scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page + if tc.initial_max_pages + scope.$parent[tc.max_pages] = tc.initial_max_pages + register_pagination_scope: (id, pagination_scope) -> mapping = @mappings[id] ||= {} diff --git a/coffee/configuration/table_configuration.coffee b/coffee/configuration/table_configuration.coffee index 1f24634..b13f78b 100644 --- a/coffee/configuration/table_configuration.coffee +++ b/coffee/configuration/table_configuration.coffee @@ -52,7 +52,7 @@ class TableConfiguration @max_pages = max_pages else @max_pages = "#{@id}_maxPages" - @initial_items_per_page = parseInt(max_pages) + @initial_max_pages = parseInt(max_pages) capitaliseFirstLetter: (string) -> if string then string.charAt(0).toUpperCase() + string.slice(1) else "" From fe7f7b02061d310fd0b495b4eda7d3f493e06be7 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Thu, 13 Feb 2014 21:17:56 +0100 Subject: [PATCH 062/190] compiled new version --- angular-table.js | 7 +++++-- angular-table.min.js | 2 +- gem/app/assets/javascripts/angular-table.js | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/angular-table.js b/angular-table.js index 45e2f33..044b81f 100644 --- a/angular-table.js +++ b/angular-table.js @@ -136,7 +136,7 @@ return this.max_pages = max_pages; } else { this.max_pages = "" + this.id + "_maxPages"; - return this.initial_items_per_page = parseInt(max_pages); + return this.initial_max_pages = parseInt(max_pages); } } }; @@ -476,7 +476,10 @@ scope.$parent[tc.sort_context] = tc.initial_sort_context; } if (tc.initial_fill_last_page) { - return scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page; + scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page; + } + if (tc.initial_max_pages) { + return scope.$parent[tc.max_pages] = tc.initial_max_pages; } }; diff --git a/angular-table.min.js b/angular-table.min.js index 104828c..503e6b3 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,l,u,p,c,g,_,h,f,d,m,b,v,y={}.hasOwnProperty,x=function(t,e){function i(){this.constructor=t}for(var n in e)y.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"')"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[u]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_items_per_page=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,p;for(i=[],p=t.find("td"),l=0,u=p.length;u>l;l++)a=p[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return x(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in filtered_list()"}return x(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in getFillerArray() "),i.append(e)},e.prototype.link=function(t,e,i,n){var r,a,o;return a=this.table_configuration.list,r=this.table_configuration.items_per_page,o=this.table_configuration.sort_context,t.filtered_list=function(){var e;return e=t[a],"global"===t[o]?(e=n("orderBy")(e,t.predicate,t.descending),e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r])):(e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r]),e=n("orderBy")(e,t.predicate,t.descending)),e},t.getFillerArray=function(){var e,i,n,o,s,l,u;if(t[d]===t[b]-1){if(i=t[a].length%t[r],0!==i||0===t[a].length){for(e=t[r]-i-1,u=[],n=o=s=t[a].length,l=t[a].length+e;l>=s?l>=o:o>=l;n=l>=s?++o:--o)u.push(n);return u}return[]}}},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++){if(e=r[i],e.initialSorting&&!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),m="from_page",d="current_page",b="number_of_pages",g="atList",c="atItemsPerPage",u="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",p="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},v=function(t,e,i){return t[d]=e[d],t[b]=e[b],t[m]=s(t[i.items_per_page],t[d],t[i.list])},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page?e.$parent[i.fill_last_page]=i.initial_fill_last_page:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(d,function(){return v(i.table_scope,e,i.table_configuration)}),e.$watch(b,function(){return v(i.table_scope,e,i.table_configuration)})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(t,i,n){var r;return r=n.id,r?e.register_table_scope(r,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:" ",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[d]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[d]=0,e[s.list]?e[s.list].length>0?(e[b]=Math.ceil(e[s.list].length/e[s.items_per_page]),e.pages=e.show_sectioning()?r(0,e[s.max_pages]-1):r(0,e[b]-1)):(e[b]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[b]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[d]?(t=e.pages[0]-e[d],o(e.pages[0],-t,e[s.max_pages],e[b])):e.pages[e.pages.length-1]i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"')"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[u]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,p;for(i=[],p=t.find("td"),l=0,u=p.length;u>l;l++)a=p[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return x(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in filtered_list()"}return x(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in getFillerArray() "),i.append(e)},e.prototype.link=function(t,e,i,n){var r,a,o;return a=this.table_configuration.list,r=this.table_configuration.items_per_page,o=this.table_configuration.sort_context,t.filtered_list=function(){var e;return e=t[a],"global"===t[o]?(e=n("orderBy")(e,t.predicate,t.descending),e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r])):(e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r]),e=n("orderBy")(e,t.predicate,t.descending)),e},t.getFillerArray=function(){var e,i,n,o,s,l,u;if(t[d]===t[b]-1){if(i=t[a].length%t[r],0!==i||0===t[a].length){for(e=t[r]-i-1,u=[],n=o=s=t[a].length,l=t[a].length+e;l>=s?l>=o:o>=l;n=l>=s?++o:--o)u.push(n);return u}return[]}}},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++){if(e=r[i],e.initialSorting&&!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),m="from_page",d="current_page",b="number_of_pages",g="atList",c="atItemsPerPage",u="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",p="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},v=function(t,e,i){return t[d]=e[d],t[b]=e[b],t[m]=s(t[i.items_per_page],t[d],t[i.list])},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages?e.$parent[i.max_pages]=i.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(d,function(){return v(i.table_scope,e,i.table_configuration)}),e.$watch(b,function(){return v(i.table_scope,e,i.table_configuration)})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(t,i,n){var r;return r=n.id,r?e.register_table_scope(r,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:" ",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[d]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[d]=0,e[s.list]?e[s.list].length>0?(e[b]=Math.ceil(e[s.list].length/e[s.items_per_page]),e.pages=e.show_sectioning()?r(0,e[s.max_pages]-1):r(0,e[b]-1)):(e[b]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[b]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[d]?(t=e.pages[0]-e[d],o(e.pages[0],-t,e[s.max_pages],e[b])):e.pages[e.pages.length-1] Date: Fri, 14 Feb 2014 20:41:12 +0100 Subject: [PATCH 063/190] fixed initial sorting --- angular-table.js | 6 ++++-- angular-table.min.js | 2 +- coffee/table/table.coffee | 4 ++-- gem/app/assets/javascripts/angular-table.js | 6 ++++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/angular-table.js b/angular-table.js index 044b81f..8be264e 100644 --- a/angular-table.js +++ b/angular-table.js @@ -385,9 +385,11 @@ if (!bd.attribute) { throw "initial-sorting specified without attribute."; } + $scope.predicate = bd.attribute; + _results.push($scope.descending = bd.initialSorting === "desc"); + } else { + _results.push(void 0); } - $scope.predicate = bd.attribute; - _results.push($scope.descending = bd.initialSorting === "desc"); } return _results; }; diff --git a/angular-table.min.js b/angular-table.min.js index 503e6b3..280d996 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,l,u,p,c,g,_,h,f,d,m,b,v,y={}.hasOwnProperty,x=function(t,e){function i(){this.constructor=t}for(var n in e)y.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"')"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[u]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,p;for(i=[],p=t.find("td"),l=0,u=p.length;u>l;l++)a=p[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return x(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in filtered_list()"}return x(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in getFillerArray() "),i.append(e)},e.prototype.link=function(t,e,i,n){var r,a,o;return a=this.table_configuration.list,r=this.table_configuration.items_per_page,o=this.table_configuration.sort_context,t.filtered_list=function(){var e;return e=t[a],"global"===t[o]?(e=n("orderBy")(e,t.predicate,t.descending),e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r])):(e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r]),e=n("orderBy")(e,t.predicate,t.descending)),e},t.getFillerArray=function(){var e,i,n,o,s,l,u;if(t[d]===t[b]-1){if(i=t[a].length%t[r],0!==i||0===t[a].length){for(e=t[r]-i-1,u=[],n=o=s=t[a].length,l=t[a].length+e;l>=s?l>=o:o>=l;n=l>=s?++o:--o)u.push(n);return u}return[]}}},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++){if(e=r[i],e.initialSorting&&!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),m="from_page",d="current_page",b="number_of_pages",g="atList",c="atItemsPerPage",u="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",p="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},v=function(t,e,i){return t[d]=e[d],t[b]=e[b],t[m]=s(t[i.items_per_page],t[d],t[i.list])},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages?e.$parent[i.max_pages]=i.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(d,function(){return v(i.table_scope,e,i.table_configuration)}),e.$watch(b,function(){return v(i.table_scope,e,i.table_configuration)})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(t,i,n){var r;return r=n.id,r?e.register_table_scope(r,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:" ",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[d]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[d]=0,e[s.list]?e[s.list].length>0?(e[b]=Math.ceil(e[s.list].length/e[s.items_per_page]),e.pages=e.show_sectioning()?r(0,e[s.max_pages]-1):r(0,e[b]-1)):(e[b]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[b]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[d]?(t=e.pages[0]-e[d],o(e.pages[0],-t,e[s.max_pages],e[b])):e.pages[e.pages.length-1]i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"')"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[u]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,p;for(i=[],p=t.find("td"),l=0,u=p.length;u>l;l++)a=p[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return x(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in filtered_list()"}return x(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in getFillerArray() "),i.append(e)},e.prototype.link=function(t,e,i,n){var r,a,o;return a=this.table_configuration.list,r=this.table_configuration.items_per_page,o=this.table_configuration.sort_context,t.filtered_list=function(){var e;return e=t[a],"global"===t[o]?(e=n("orderBy")(e,t.predicate,t.descending),e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r])):(e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r]),e=n("orderBy")(e,t.predicate,t.descending)),e},t.getFillerArray=function(){var e,i,n,o,s,l,u;if(t[d]===t[b]-1){if(i=t[a].length%t[r],0!==i||0===t[a].length){for(e=t[r]-i-1,u=[],n=o=s=t[a].length,l=t[a].length+e;l>=s?l>=o:o>=l;n=l>=s?++o:--o)u.push(n);return u}return[]}}},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),m="from_page",d="current_page",b="number_of_pages",g="atList",c="atItemsPerPage",u="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",p="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},v=function(t,e,i){return t[d]=e[d],t[b]=e[b],t[m]=s(t[i.items_per_page],t[d],t[i.list])},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages?e.$parent[i.max_pages]=i.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(d,function(){return v(i.table_scope,e,i.table_configuration)}),e.$watch(b,function(){return v(i.table_scope,e,i.table_configuration)})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(t,i,n){var r;return r=n.id,r?e.register_table_scope(r,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:" ",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[d]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[d]=0,e[s.list]?e[s.list].length>0?(e[b]=Math.ceil(e[s.list].length/e[s.items_per_page]),e.pages=e.show_sectioning()?r(0,e[s.max_pages]-1):r(0,e[b]-1)):(e[b]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[b]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[d]?(t=e.pages[0]-e[d],o(e.pages[0],-t,e[s.max_pages],e[b])):e.pages[e.pages.length-1] @setup_initial_sorting($scope) diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 044b81f..8be264e 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -385,9 +385,11 @@ if (!bd.attribute) { throw "initial-sorting specified without attribute."; } + $scope.predicate = bd.attribute; + _results.push($scope.descending = bd.initialSorting === "desc"); + } else { + _results.push(void 0); } - $scope.predicate = bd.attribute; - _results.push($scope.descending = bd.initialSorting === "desc"); } return _results; }; From 086cb24ab6089c26e0bcb93bd04e9d56087213c9 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 14 Feb 2014 22:34:53 +0100 Subject: [PATCH 064/190] readme --- README.md | 64 +++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index a9a64d7..01d4745 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,34 @@ # angular-table -Html tables with sorting and pagination. - -[Written in CoffeeScript.](https://github.com/samu/angular-table/blob/master/coffee) - -Check out the [examples](http://samu.github.io/angular-table/examples.html) for more information. - -## How - -All you have to do in your controller is setting up a list on your `$scope`: - -```javascript -$scope.nameList = [{name: "Laura"}, {name: "Lea"}, {name: "Sara"}] -``` - -Defining a table is 100% declarative. Here's a simple example: - -```html -
      
- - - - - - - - - - -
- The name is {{item.name}} -
-``` +Angular directive which allows to declare sortable tables and to add +pagination with very little effort. + +## Features + * Makes columns sortable + * Adds pagination in a plug-and-play manner + * Implicitly renders cell contents by name convention and allows custom cell content if needed + * Renders headers implicitly and allows custom header declarations if needed + * Lets you define pagination options `items per page`, `maximum pages`, `sort context` and `fill last page` + * 100% declarative, no code required in your controllers + +Check out the [examples](http://samu.github.io/angular-table/examples.html) for a demo. + +## Configuration + +### Configurations for a table with pagination + +The following configurations can be used inside the `` tag and come into play when a pagination is used: + + * `at-items-per-page=integer` defines the maximum amount of items to be displayed per page. + + * `at-fill-last-page=string` fills up the remaining space of the last page of your table. + + * `at-maximum-pages=integer` comes in handy if you expect your list to contain a lot of entries. + + * `at-sort-context` allows to set the sorting behaviour to `'global'` or `'page'`. + +These options can be configured by using a scope model, such as `at-items-per-page="yourScopeVariable"`. However, +you can also directly assign values, such as `at-items-per-page="5"`. In that case, `angular-table` will automatically +set up appropriate variables in your scope, prefixed with the id of the table, for example `$scope.tableId_itemsPerPage`. + +### Column options \ No newline at end of file From 0dad18d694e0674d636c8a393007c5545042657f Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 14 Feb 2014 22:36:49 +0100 Subject: [PATCH 065/190] added work in progress note --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 01d4745..a8fa449 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # angular-table +_work in progress!_ + Angular directive which allows to declare sortable tables and to add pagination with very little effort. @@ -31,4 +33,4 @@ These options can be configured by using a scope model, such as `at-items-per-pa you can also directly assign values, such as `at-items-per-page="5"`. In that case, `angular-table` will automatically set up appropriate variables in your scope, prefixed with the id of the table, for example `$scope.tableId_itemsPerPage`. -### Column options \ No newline at end of file +### Column options From 01501516a4f9efff685e82f6a3e4cfdd04a07019 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 15 Feb 2014 16:48:24 +0100 Subject: [PATCH 066/190] updated to use bootstrap 3 classes --- angular-table.js | 26 ++++++++++--------- angular-table.min.js | 2 +- coffee/at-pagination.coffee | 4 +-- .../configuration/column_configuration.coffee | 2 +- coffee/table/table.coffee | 7 ++--- gem/app/assets/javascripts/angular-table.js | 26 ++++++++++--------- 6 files changed, 36 insertions(+), 31 deletions(-) diff --git a/angular-table.js b/angular-table.js index 8be264e..af7913b 100644 --- a/angular-table.js +++ b/angular-table.js @@ -48,7 +48,7 @@ if (this.sortable) { element.attr("ng-click", "predicate = '" + this.attribute + "'; descending = !descending;"); icon = angular.element(""); - icon.attr("ng-class", "getSortIcon('" + this.attribute + "')"); + icon.attr("ng-class", "getSortIcon('" + this.attribute + "', predicate)"); return element.append(icon); } }; @@ -396,16 +396,18 @@ Table.prototype.post = function($scope, $element, $attributes, $filter) { this.setup_initial_sorting($scope); - $scope.getSortIcon = function(predicate) { - if (predicate !== $scope.predicate) { - return "icon-minus"; - } - if ($scope.descending) { - return "icon-chevron-down"; - } else { - return "icon-chevron-up"; - } - }; + if (!$scope.getSortIcon) { + $scope.getSortIcon = function(predicate, current_predicate) { + if (predicate !== $scope.predicate) { + return "icon-minus"; + } + if ($scope.descending) { + return "glyphicon glyphicon-chevron-down"; + } else { + return "glyphicon glyphicon-chevron-up"; + } + }; + } return this.setup.link($scope, $element, $attributes, $filter); }; @@ -544,7 +546,7 @@ return { replace: true, restrict: "E", - template: " ", + template: " ", controller: [ "$scope", "$element", "$attrs", function($scope, $element, $attrs) { return angularTableManager.register_pagination_scope($attrs.atTableId, $scope); diff --git a/angular-table.min.js b/angular-table.min.js index 280d996..36cfc2d 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,l,u,p,c,g,_,h,f,d,m,b,v,y={}.hasOwnProperty,x=function(t,e){function i(){this.constructor=t}for(var n in e)y.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"')"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[u]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,p;for(i=[],p=t.find("td"),l=0,u=p.length;u>l;l++)a=p[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return x(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in filtered_list()"}return x(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in getFillerArray() "),i.append(e)},e.prototype.link=function(t,e,i,n){var r,a,o;return a=this.table_configuration.list,r=this.table_configuration.items_per_page,o=this.table_configuration.sort_context,t.filtered_list=function(){var e;return e=t[a],"global"===t[o]?(e=n("orderBy")(e,t.predicate,t.descending),e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r])):(e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r]),e=n("orderBy")(e,t.predicate,t.descending)),e},t.getFillerArray=function(){var e,i,n,o,s,l,u;if(t[d]===t[b]-1){if(i=t[a].length%t[r],0!==i||0===t[a].length){for(e=t[r]-i-1,u=[],n=o=s=t[a].length,l=t[a].length+e;l>=s?l>=o:o>=l;n=l>=s?++o:--o)u.push(n);return u}return[]}}},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"icon-chevron-down":"icon-chevron-up"},this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),m="from_page",d="current_page",b="number_of_pages",g="atList",c="atItemsPerPage",u="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",p="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},v=function(t,e,i){return t[d]=e[d],t[b]=e[b],t[m]=s(t[i.items_per_page],t[d],t[i.list])},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages?e.$parent[i.max_pages]=i.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(d,function(){return v(i.table_scope,e,i.table_configuration)}),e.$watch(b,function(){return v(i.table_scope,e,i.table_configuration)})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(t,i,n){var r;return r=n.id,r?e.register_table_scope(r,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:" ",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[d]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[d]=0,e[s.list]?e[s.list].length>0?(e[b]=Math.ceil(e[s.list].length/e[s.items_per_page]),e.pages=e.show_sectioning()?r(0,e[s.max_pages]-1):r(0,e[b]-1)):(e[b]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[b]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[d]?(t=e.pages[0]-e[d],o(e.pages[0],-t,e[s.max_pages],e[b])):e.pages[e.pages.length-1]i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[u]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,p;for(i=[],p=t.find("td"),l=0,u=p.length;u>l;l++)a=p[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return x(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in filtered_list()"}return x(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in getFillerArray() "),i.append(e)},e.prototype.link=function(t,e,i,n){var r,a,o;return a=this.table_configuration.list,r=this.table_configuration.items_per_page,o=this.table_configuration.sort_context,t.filtered_list=function(){var e;return e=t[a],"global"===t[o]?(e=n("orderBy")(e,t.predicate,t.descending),e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r])):(e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r]),e=n("orderBy")(e,t.predicate,t.descending)),e},t.getFillerArray=function(){var e,i,n,o,s,l,u;if(t[d]===t[b]-1){if(i=t[a].length%t[r],0!==i||0===t[a].length){for(e=t[r]-i-1,u=[],n=o=s=t[a].length,l=t[a].length+e;l>=s?l>=o:o>=l;n=l>=s?++o:--o)u.push(n);return u}return[]}}},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),m="from_page",d="current_page",b="number_of_pages",g="atList",c="atItemsPerPage",u="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",p="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},v=function(t,e,i){return t[d]=e[d],t[b]=e[b],t[m]=s(t[i.items_per_page],t[d],t[i.list])},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages?e.$parent[i.max_pages]=i.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(d,function(){return v(i.table_scope,e,i.table_configuration)}),e.$watch(b,function(){return v(i.table_scope,e,i.table_configuration)})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(t,i,n){var r;return r=n.id,r?e.register_table_scope(r,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:" ",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[d]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[d]=0,e[s.list]?e[s.list].length>0?(e[b]=Math.ceil(e[s.list].length/e[s.items_per_page]),e.pages=e.show_sectioning()?r(0,e[s.max_pages]-1):r(0,e[b]-1)):(e[b]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[b]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[d]?(t=e.pages[0]-e[d],o(e.pages[0],-t,e[s.max_pages],e[b])):e.pages[e.pages.length-1] -
    +
    +
    • First
    • diff --git a/coffee/configuration/column_configuration.coffee b/coffee/configuration/column_configuration.coffee index 7daa934..e045253 100644 --- a/coffee/configuration/column_configuration.coffee +++ b/coffee/configuration/column_configuration.coffee @@ -27,7 +27,7 @@ class ColumnConfiguration if @sortable element.attr("ng-click", "predicate = '#{@attribute}'; descending = !descending;") icon = angular.element("") - icon.attr("ng-class", "getSortIcon('#{@attribute}')") + icon.attr("ng-class", "getSortIcon('#{@attribute}', predicate)") element.append(icon) render_width: (element) -> diff --git a/coffee/table/table.coffee b/coffee/table/table.coffee index 1159aec..d9007d5 100644 --- a/coffee/table/table.coffee +++ b/coffee/table/table.coffee @@ -38,8 +38,9 @@ class Table post: ($scope, $element, $attributes, $filter) -> @setup_initial_sorting($scope) - $scope.getSortIcon = (predicate) -> - return "icon-minus" if predicate != $scope.predicate - if $scope.descending then "icon-chevron-down" else "icon-chevron-up" + if not $scope.getSortIcon + $scope.getSortIcon = (predicate, current_predicate) -> + return "icon-minus" if predicate != $scope.predicate + if $scope.descending then "glyphicon glyphicon-chevron-down" else "glyphicon glyphicon-chevron-up" @setup.link($scope, $element, $attributes, $filter) diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 8be264e..af7913b 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -48,7 +48,7 @@ if (this.sortable) { element.attr("ng-click", "predicate = '" + this.attribute + "'; descending = !descending;"); icon = angular.element(""); - icon.attr("ng-class", "getSortIcon('" + this.attribute + "')"); + icon.attr("ng-class", "getSortIcon('" + this.attribute + "', predicate)"); return element.append(icon); } }; @@ -396,16 +396,18 @@ Table.prototype.post = function($scope, $element, $attributes, $filter) { this.setup_initial_sorting($scope); - $scope.getSortIcon = function(predicate) { - if (predicate !== $scope.predicate) { - return "icon-minus"; - } - if ($scope.descending) { - return "icon-chevron-down"; - } else { - return "icon-chevron-up"; - } - }; + if (!$scope.getSortIcon) { + $scope.getSortIcon = function(predicate, current_predicate) { + if (predicate !== $scope.predicate) { + return "icon-minus"; + } + if ($scope.descending) { + return "glyphicon glyphicon-chevron-down"; + } else { + return "glyphicon glyphicon-chevron-up"; + } + }; + } return this.setup.link($scope, $element, $attributes, $filter); }; @@ -544,7 +546,7 @@ return { replace: true, restrict: "E", - template: " ", + template: " ", controller: [ "$scope", "$element", "$attrs", function($scope, $element, $attrs) { return angularTableManager.register_pagination_scope($attrs.atTableId, $scope); From 80434cb5143ebba68c92b5d0c105fd56d7956668 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 16 Feb 2014 17:15:26 +0100 Subject: [PATCH 067/190] added .travis.yml --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c2ba3f9 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - 0.8 \ No newline at end of file From 82fec1f788faf9fffb3cc433c04198ad51766f89 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 16 Feb 2014 17:17:28 +0100 Subject: [PATCH 068/190] readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a8fa449..5681977 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,4 @@ you can also directly assign values, such as `at-items-per-page="5"`. In that ca set up appropriate variables in your scope, prefixed with the id of the table, for example `$scope.tableId_itemsPerPage`. ### Column options + From 804e1c8b378e14130d9cc6c811f994fc85b754e0 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 16 Feb 2014 17:29:00 +0100 Subject: [PATCH 069/190] added package.json --- package.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..6394996 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "angular-table", + "version": "0.0.8", + "author": "Samuel Mueller", + "repository": { + "type": "git", + "url": "git://github.com/samu/angular-table.git" + }, + "devDependencies": { + }, + "scripts": { + "test": "karma start --single-run --no-auto-watch" + } +} From bcda7532d58d654502c552bbd30f7b0d7e9e35a4 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 16 Feb 2014 17:31:08 +0100 Subject: [PATCH 070/190] added karma dev dependency --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 6394996..64b44e5 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "url": "git://github.com/samu/angular-table.git" }, "devDependencies": { + "karma": "~0.10" }, "scripts": { "test": "karma start --single-run --no-auto-watch" From 37d3b6f9f6d4ceca5d364b2aaf3540c111d3d045 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 16 Feb 2014 17:36:30 +0100 Subject: [PATCH 071/190] added html2js preprocessor dependency --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 64b44e5..8f24c01 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "url": "git://github.com/samu/angular-table.git" }, "devDependencies": { - "karma": "~0.10" + "karma": "~0.10", + "karma-ng-html2js-preprocessor" : "0.1.0" }, "scripts": { "test": "karma start --single-run --no-auto-watch" From 2c449134cfe687e84bf4e84effc8a1d79bccbb85 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 16 Feb 2014 17:39:32 +0100 Subject: [PATCH 072/190] use phantomjs instead of chrom in travis --- karma.conf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/karma.conf.js b/karma.conf.js index 2f6b314..745b0d7 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -77,7 +77,7 @@ module.exports = function(config) { // - Safari (only Mac) // - PhantomJS // - IE (only Windows) - browsers: ['Chrome'], + browsers: ['PhantomJS'], // If browser does not capture in given timeout [ms], kill it From f689dcefa77fe677ebef90539497929aaecb9da1 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 16 Feb 2014 18:06:31 +0100 Subject: [PATCH 073/190] click hack for phantomjs --- test/pagination.coffee | 3 ++- test/sorting.coffee | 2 +- test/test_helper.coffee | 8 +++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/test/pagination.coffee b/test/pagination.coffee index c1e44b1..494f3af 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -12,7 +12,8 @@ describe "angular-table", () -> expect(tds).toEqual ["Till", "Richard", "Christoph", "Paul"] paginationLinks = @element.find "a" - _.find(paginationLinks, (link) -> angular.element(link).html() == "2").click() + link = _.find(paginationLinks, (link) -> angular.element(link).html() == "2") + click(link) tds = extract_html_to_array(@element.find("td")) expect(tds).toEqual ["Flake", "Oliver", " ", " "] diff --git a/test/sorting.coffee b/test/sorting.coffee index 7302bfe..a408951 100644 --- a/test/sorting.coffee +++ b/test/sorting.coffee @@ -13,6 +13,6 @@ describe "angular-table", () -> expect(tds).toEqual ["Zurich", "Helsinki", "Amsterdam"] it "makes columns sortable", () -> - @element.find("th")[0].click() + click(@element.find("th")[0]) tds = extract_html_to_array(@element.find("td")) expect(tds).toEqual ["Amsterdam", "Helsinki", "Zurich"] \ No newline at end of file diff --git a/test/test_helper.coffee b/test/test_helper.coffee index 25c992f..8ed50b1 100644 --- a/test/test_helper.coffee +++ b/test/test_helper.coffee @@ -28,4 +28,10 @@ class TemplateCompiler element = $compile(element)($rootScope) $rootScope.$digest() - return element \ No newline at end of file + return element + +click = (el) -> + ev = document.createEvent("MouseEvent") + ev.initMouseEvent "click", true, true, window, null, 0, 0, 0, 0, false, false, false, false, 0, null + el.dispatchEvent ev + return \ No newline at end of file From 6f584707ae175c62097f9dba99370fd39fa98c7f Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 16 Feb 2014 18:10:14 +0100 Subject: [PATCH 074/190] added travis badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5681977..1fc59f0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# angular-table +# angular-table [![Build Status](https://travis-ci.org/samu/angular-table.png?branch=master)](https://travis-ci.org/samu/angular-table) _work in progress!_ From 3db3d41ca594e98e4418cce032903f760784868c Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 17 Feb 2014 22:03:17 +0100 Subject: [PATCH 075/190] refactored table interaction --- coffee/at-pagination.coffee | 3 + coffee/at-table.coffee | 72 +++++++++++++++++++++-- coffee/table/setup/paginated_setup.coffee | 62 ++++++++++--------- 3 files changed, 105 insertions(+), 32 deletions(-) diff --git a/coffee/at-pagination.coffee b/coffee/at-pagination.coffee index 4d1aba9..d83aa5c 100644 --- a/coffee/at-pagination.coffee +++ b/coffee/at-pagination.coffee @@ -116,5 +116,8 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" $scope.$watch tc.list, () -> update() + $scope.$watch "#{tc.list}.length", () -> + update() + } ] diff --git a/coffee/at-table.coffee b/coffee/at-table.coffee index 9059926..909f360 100644 --- a/coffee/at-table.coffee +++ b/coffee/at-table.coffee @@ -28,6 +28,36 @@ update_table_scope = (table_scope, pagination_scope, table_configuration) -> table_scope[irk_current_page], table_scope[table_configuration.list]) +get_sorted_and_paginated_list = (list, current_page, items_per_page, sort_context, predicate, descending, $filter) -> + if list + val = list + + from_page = items_per_page * current_page - list.length + + # if $scope[sc] == "global" + if sort_context == "global" + val = $filter("orderBy")(val, predicate, descending) + val = $filter("limitTo")(val, from_page) + val = $filter("limitTo")(val, items_per_page) + else + val = $filter("limitTo")(val, from_page) + val = $filter("limitTo")(val, items_per_page) + val = $filter("orderBy")(val, predicate, descending) + + return val + else + console.log "RETURNING NOTHING!!" + return [] + +get_filler_array = (list, current_page, number_of_pages, items_per_page) -> + if current_page == number_of_pages - 1 + itemCountOnLastPage = list.length % items_per_page + if itemCountOnLastPage != 0 || list.length == 0 + fillerLength = items_per_page - itemCountOnLastPage - 1 + x for x in [(list.length)..(list.length + fillerLength)] + else + [] + class AngularTableManager constructor: () -> @@ -44,11 +74,43 @@ class AngularTableManager if mapping.pagination_scope throw "WHOOPS" - register_table_scope: (id, scope) -> + register_table_scope: (id, scope, filter) -> @mappings[id].table_scope = scope tc = @mappings[id].table_configuration + update_stuff = () -> + scope.sorted_and_paginated_list = get_sorted_and_paginated_list( + scope[tc.list], + scope[irk_current_page], + scope[tc.items_per_page], + scope[tc.sort_context] + scope.predicate, + scope.descending, + filter + ) + + scope.filler_array = get_filler_array( + scope[tc.list], + scope[irk_current_page], + scope[irk_number_of_pages], + scope[tc.items_per_page] + ) + + console.log scope.filler_array.length if scope.filler_array + + scope.notify_change = (current_page, number_of_pages) -> + scope[irk_current_page] = current_page + scope[irk_number_of_pages] = number_of_pages + update_stuff() + + scope.$watch("#{tc.list}.length", () -> + console.log "it changed!" + update_stuff() + ) + + tc = @mappings[id].table_configuration + if tc.initial_items_per_page scope.$parent[tc.items_per_page] = tc.initial_items_per_page @@ -68,11 +130,13 @@ class AngularTableManager if mapping.table_configuration pagination_scope.$watch(irk_current_page, () -> - update_table_scope(mapping.table_scope, pagination_scope, mapping.table_configuration) + # update_table_scope(mapping.table_scope, pagination_scope, mapping.table_configuration) + mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]) ) pagination_scope.$watch(irk_number_of_pages, () -> - update_table_scope(mapping.table_scope, pagination_scope, mapping.table_configuration) + mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]) + # update_table_scope(mapping.table_scope, pagination_scope, mapping.table_configuration) ) angular.module("angular-table").service "angularTableManager", [() -> @@ -87,7 +151,7 @@ angular.module("angular-table").directive "atTable", ["$filter", "angularTableMa ($scope, $element, $attrs) -> id = $attrs["id"] if id - angularTableManager.register_table_scope(id, $scope) + angularTableManager.register_table_scope(id, $scope, $filter) ] compile: (element, attributes, transclude) -> diff --git a/coffee/table/setup/paginated_setup.coffee b/coffee/table/setup/paginated_setup.coffee index 26fb3a6..5536905 100644 --- a/coffee/table/setup/paginated_setup.coffee +++ b/coffee/table/setup/paginated_setup.coffee @@ -2,7 +2,7 @@ class PaginatedSetup extends Setup constructor: (table_configuration) -> @table_configuration = table_configuration - @repeatString = "item in filtered_list()" + @repeatString = "item in sorted_and_paginated_list" compile: (element) -> tbody = @setupTr(element, @repeatString) @@ -16,36 +16,42 @@ class PaginatedSetup extends Setup fillerTr = angular.element(document.createElement("tr")) fillerTr.attr("ng-show", @table_configuration.fill_last_page) fillerTr.html(tdString) - fillerTr.attr("ng-repeat", "item in getFillerArray() ") + fillerTr.attr("ng-repeat", "item in filler_array") tbody.append(fillerTr) return link: ($scope, $element, $attributes, $filter) -> - list_name = @table_configuration.list - ipp = @table_configuration.items_per_page - sc = @table_configuration.sort_context - - $scope.filtered_list = () -> - val = $scope[list_name] - - if $scope[sc] == "global" - val = $filter("orderBy")(val, $scope.predicate, $scope.descending) - val = $filter("limitTo")(val, $scope[irk_from_page]) - val = $filter("limitTo")(val, $scope[ipp]) - else - val = $filter("limitTo")(val, $scope[irk_from_page]) - val = $filter("limitTo")(val, $scope[ipp]) - val = $filter("orderBy")(val, $scope.predicate, $scope.descending) - - return val - - $scope.getFillerArray = () -> - if $scope[irk_current_page] == $scope[irk_number_of_pages] - 1 - itemCountOnLastPage = $scope[list_name].length % $scope[ipp] - if itemCountOnLastPage != 0 || $scope[list_name].length == 0 - fillerLength = $scope[ipp] - itemCountOnLastPage - 1 - x for x in [($scope[list_name].length)..($scope[list_name].length + fillerLength)] - else - [] \ No newline at end of file + # list_name = @table_configuration.list + # ipp = @table_configuration.items_per_page + # sc = @table_configuration.sort_context + # tc = @table_configuration + + # $scope.filtered_list = () -> + # val = $scope[list_name] + + # from_page = calculate_from_page($scope[tc.items_per_page], + # $scope[irk_current_page], + # $scope[tc.list]) + + # if $scope[sc] == "global" + # val = $filter("orderBy")(val, $scope.predicate, $scope.descending) + # val = $filter("limitTo")(val, from_page) + # val = $filter("limitTo")(val, $scope[ipp]) + # else + # val = $filter("limitTo")(val, from_page) + # val = $filter("limitTo")(val, $scope[ipp]) + # val = $filter("orderBy")(val, $scope.predicate, $scope.descending) + + + # return val + + # $scope.getFillerArray = () -> + # if $scope[irk_current_page] == $scope[irk_number_of_pages] - 1 + # itemCountOnLastPage = $scope[list_name].length % $scope[ipp] + # if itemCountOnLastPage != 0 || $scope[list_name].length == 0 + # fillerLength = $scope[ipp] - itemCountOnLastPage - 1 + # x for x in [($scope[list_name].length)..($scope[list_name].length + fillerLength)] + # else + # [] \ No newline at end of file From 979db6a9a6262292841bbb9b7fe0c34086a09011 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 17 Feb 2014 22:03:32 +0100 Subject: [PATCH 076/190] compiled --- angular-table.js | 115 ++++++++++++-------- angular-table.min.js | 2 +- gem/app/assets/javascripts/angular-table.js | 115 ++++++++++++-------- 3 files changed, 139 insertions(+), 93 deletions(-) diff --git a/angular-table.js b/angular-table.js index af7913b..b1eb28e 100644 --- a/angular-table.js +++ b/angular-table.js @@ -3,7 +3,7 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var AngularTableManager, ColumnConfiguration, PaginatedSetup, Setup, StandardSetup, Table, TableConfiguration, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, update_table_scope, + var AngularTableManager, ColumnConfiguration, PaginatedSetup, Setup, StandardSetup, Table, TableConfiguration, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, get_filler_array, get_sorted_and_paginated_list, irk_current_page, irk_from_page, irk_number_of_pages, update_table_scope, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -273,7 +273,7 @@ function PaginatedSetup(table_configuration) { this.table_configuration = table_configuration; - this.repeatString = "item in filtered_list()"; + this.repeatString = "item in sorted_and_paginated_list"; } PaginatedSetup.prototype.compile = function(element) { @@ -288,46 +288,11 @@ fillerTr = angular.element(document.createElement("tr")); fillerTr.attr("ng-show", this.table_configuration.fill_last_page); fillerTr.html(tdString); - fillerTr.attr("ng-repeat", "item in getFillerArray() "); + fillerTr.attr("ng-repeat", "item in filler_array"); tbody.append(fillerTr); }; - PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) { - var ipp, list_name, sc; - list_name = this.table_configuration.list; - ipp = this.table_configuration.items_per_page; - sc = this.table_configuration.sort_context; - $scope.filtered_list = function() { - var val; - val = $scope[list_name]; - if ($scope[sc] === "global") { - val = $filter("orderBy")(val, $scope.predicate, $scope.descending); - val = $filter("limitTo")(val, $scope[irk_from_page]); - val = $filter("limitTo")(val, $scope[ipp]); - } else { - val = $filter("limitTo")(val, $scope[irk_from_page]); - val = $filter("limitTo")(val, $scope[ipp]); - val = $filter("orderBy")(val, $scope.predicate, $scope.descending); - } - return val; - }; - return $scope.getFillerArray = function() { - var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; - if ($scope[irk_current_page] === $scope[irk_number_of_pages] - 1) { - itemCountOnLastPage = $scope[list_name].length % $scope[ipp]; - if (itemCountOnLastPage !== 0 || $scope[list_name].length === 0) { - fillerLength = $scope[ipp] - itemCountOnLastPage - 1; - _results = []; - for (x = _i = _ref = $scope[list_name].length, _ref1 = $scope[list_name].length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { - _results.push(x); - } - return _results; - } else { - return []; - } - } - }; - }; + PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) {}; return PaginatedSetup; @@ -451,6 +416,44 @@ return table_scope[irk_from_page] = calculate_from_page(table_scope[table_configuration.items_per_page], table_scope[irk_current_page], table_scope[table_configuration.list]); }; + get_sorted_and_paginated_list = function(list, current_page, items_per_page, sort_context, predicate, descending, $filter) { + var from_page, val; + if (list) { + val = list; + from_page = items_per_page * current_page - list.length; + if (sort_context === "global") { + val = $filter("orderBy")(val, predicate, descending); + val = $filter("limitTo")(val, from_page); + val = $filter("limitTo")(val, items_per_page); + } else { + val = $filter("limitTo")(val, from_page); + val = $filter("limitTo")(val, items_per_page); + val = $filter("orderBy")(val, predicate, descending); + } + return val; + } else { + console.log("RETURNING NOTHING!!"); + return []; + } + }; + + get_filler_array = function(list, current_page, number_of_pages, items_per_page) { + var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; + if (current_page === number_of_pages - 1) { + itemCountOnLastPage = list.length % items_per_page; + if (itemCountOnLastPage !== 0 || list.length === 0) { + fillerLength = items_per_page - itemCountOnLastPage - 1; + _results = []; + for (x = _i = _ref = list.length, _ref1 = list.length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { + _results.push(x); + } + return _results; + } else { + return []; + } + } + }; + AngularTableManager = (function() { function AngularTableManager() { this.mappings = {}; @@ -469,10 +472,27 @@ } }; - AngularTableManager.prototype.register_table_scope = function(id, scope) { - var tc; + AngularTableManager.prototype.register_table_scope = function(id, scope, filter) { + var tc, update_stuff; this.mappings[id].table_scope = scope; tc = this.mappings[id].table_configuration; + update_stuff = function() { + scope.sorted_and_paginated_list = get_sorted_and_paginated_list(scope[tc.list], scope[irk_current_page], scope[tc.items_per_page], scope[tc.sort_context], scope.predicate, scope.descending, filter); + scope.filler_array = get_filler_array(scope[tc.list], scope[irk_current_page], scope[irk_number_of_pages], scope[tc.items_per_page]); + if (scope.filler_array) { + return console.log(scope.filler_array.length); + } + }; + scope.notify_change = function(current_page, number_of_pages) { + scope[irk_current_page] = current_page; + scope[irk_number_of_pages] = number_of_pages; + return update_stuff(); + }; + scope.$watch("" + tc.list + ".length", function() { + console.log("it changed!"); + return update_stuff(); + }); + tc = this.mappings[id].table_configuration; if (tc.initial_items_per_page) { scope.$parent[tc.items_per_page] = tc.initial_items_per_page; } @@ -493,10 +513,10 @@ mapping.pagination_scope = pagination_scope; if (mapping.table_configuration) { pagination_scope.$watch(irk_current_page, function() { - return update_table_scope(mapping.table_scope, pagination_scope, mapping.table_configuration); + return mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]); }); return pagination_scope.$watch(irk_number_of_pages, function() { - return update_table_scope(mapping.table_scope, pagination_scope, mapping.table_configuration); + return mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]); }); } }; @@ -521,7 +541,7 @@ var id; id = $attrs["id"]; if (id) { - return angularTableManager.register_table_scope(id, $scope); + return angularTableManager.register_table_scope(id, $scope, $filter); } } ], @@ -546,7 +566,7 @@ return { replace: true, restrict: "E", - template: " ", + template: "", controller: [ "$scope", "$element", "$attrs", function($scope, $element, $attrs) { return angularTableManager.register_pagination_scope($attrs.atTableId, $scope); @@ -632,7 +652,10 @@ $scope.$watch(tc.max_pages, function() { return update(); }); - return $scope.$watch(tc.list, function() { + $scope.$watch(tc.list, function() { + return update(); + }); + return $scope.$watch("" + tc.list + ".length", function() { return update(); }); } diff --git a/angular-table.min.js b/angular-table.min.js index 36cfc2d..4f5387e 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,l,u,p,c,g,_,h,f,d,m,b,v,y={}.hasOwnProperty,x=function(t,e){function i(){this.constructor=t}for(var n in e)y.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[u]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,p;for(i=[],p=t.find("td"),l=0,u=p.length;u>l;l++)a=p[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return x(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in filtered_list()"}return x(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="
";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in getFillerArray() "),i.append(e)},e.prototype.link=function(t,e,i,n){var r,a,o;return a=this.table_configuration.list,r=this.table_configuration.items_per_page,o=this.table_configuration.sort_context,t.filtered_list=function(){var e;return e=t[a],"global"===t[o]?(e=n("orderBy")(e,t.predicate,t.descending),e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r])):(e=n("limitTo")(e,t[m]),e=n("limitTo")(e,t[r]),e=n("orderBy")(e,t.predicate,t.descending)),e},t.getFillerArray=function(){var e,i,n,o,s,l,u;if(t[d]===t[b]-1){if(i=t[a].length%t[r],0!==i||0===t[a].length){for(e=t[r]-i-1,u=[],n=o=s=t[a].length,l=t[a].length+e;l>=s?l>=o:o>=l;n=l>=s?++o:--o)u.push(n);return u}return[]}}},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),m="from_page",d="current_page",b="number_of_pages",g="atList",c="atItemsPerPage",u="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",p="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},v=function(t,e,i){return t[d]=e[d],t[b]=e[b],t[m]=s(t[i.items_per_page],t[d],t[i.list])},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages?e.$parent[i.max_pages]=i.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(d,function(){return v(i.table_scope,e,i.table_configuration)}),e.$watch(b,function(){return v(i.table_scope,e,i.table_configuration)})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(t,i,n){var r;return r=n.id,r?e.register_table_scope(r,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:" ",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[d]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[d]=0,e[s.list]?e[s.list].length>0?(e[b]=Math.ceil(e[s.list].length/e[s.items_per_page]),e.pages=e.show_sectioning()?r(0,e[s.max_pages]-1):r(0,e[b]-1)):(e[b]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[b]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[d]?(t=e.pages[0]-e[d],o(e.pages[0],-t,e[s.max_pages],e[b])):e.pages[e.pages.length-1]i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[u]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,p;for(i=[],p=t.find("td"),l=0,u=p.length;u>l;l++)a=p[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return k(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return k(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(){},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),v="from_page",b="current_page",y="number_of_pages",g="atList",c="atItemsPerPage",u="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",p="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},x=function(t,e,i){return t[b]=e[b],t[y]=e[y],t[v]=s(t[i.items_per_page],t[b],t[i.list])},m=function(t,e,i,n,r,a,o){var s,l;return t?(l=t,s=i*e-t.length,"global"===n?(l=o("orderBy")(l,r,a),l=o("limitTo")(l,s),l=o("limitTo")(l,i)):(l=o("limitTo")(l,s),l=o("limitTo")(l,i),l=o("orderBy")(l,r,a)),l):(console.log("RETURNING NOTHING!!"),[])},d=function(t,e,i,n){var r,a,o,s,l,u,p;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,p=[],o=s=l=t.length,u=t.length+r;u>=l?u>=s:s>=u;o=u>=l?++s:--s)p.push(o);return p}return[]}},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e,i){var n,r;return this.mappings[t].table_scope=e,n=this.mappings[t].table_configuration,r=function(){return e.sorted_and_paginated_list=m(e[n.list],e[b],e[n.items_per_page],e[n.sort_context],e.predicate,e.descending,i),e.filler_array=d(e[n.list],e[b],e[y],e[n.items_per_page]),e.filler_array?console.log(e.filler_array.length):void 0},e.notify_change=function(t,i){return e[b]=t,e[y]=i,r()},e.$watch(""+n.list+".length",function(){return console.log("it changed!"),r()}),n=this.mappings[t].table_configuration,n.initial_items_per_page&&(e.$parent[n.items_per_page]=n.initial_items_per_page),n.initial_sort_context&&(e.$parent[n.sort_context]=n.initial_sort_context),n.initial_fill_last_page&&(e.$parent[n.fill_last_page]=n.initial_fill_last_page),n.initial_max_pages?e.$parent[n.max_pages]=n.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(b,function(){return i.table_scope.notify_change(e[b],e[y])}),e.$watch(y,function(){return i.table_scope.notify_change(e[b],e[y])})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[b]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[b]=0,e[s.list]?e[s.list].length>0?(e[y]=Math.ceil(e[s.list].length/e[s.items_per_page]),e.pages=e.show_sectioning()?r(0,e[s.max_pages]-1):r(0,e[y]-1)):(e[y]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[y]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[b]?(t=e.pages[0]-e[b],o(e.pages[0],-t,e[s.max_pages],e[y])):e.pages[e.pages.length-1]= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { - _results.push(x); - } - return _results; - } else { - return []; - } - } - }; - }; + PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) {}; return PaginatedSetup; @@ -451,6 +416,44 @@ return table_scope[irk_from_page] = calculate_from_page(table_scope[table_configuration.items_per_page], table_scope[irk_current_page], table_scope[table_configuration.list]); }; + get_sorted_and_paginated_list = function(list, current_page, items_per_page, sort_context, predicate, descending, $filter) { + var from_page, val; + if (list) { + val = list; + from_page = items_per_page * current_page - list.length; + if (sort_context === "global") { + val = $filter("orderBy")(val, predicate, descending); + val = $filter("limitTo")(val, from_page); + val = $filter("limitTo")(val, items_per_page); + } else { + val = $filter("limitTo")(val, from_page); + val = $filter("limitTo")(val, items_per_page); + val = $filter("orderBy")(val, predicate, descending); + } + return val; + } else { + console.log("RETURNING NOTHING!!"); + return []; + } + }; + + get_filler_array = function(list, current_page, number_of_pages, items_per_page) { + var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; + if (current_page === number_of_pages - 1) { + itemCountOnLastPage = list.length % items_per_page; + if (itemCountOnLastPage !== 0 || list.length === 0) { + fillerLength = items_per_page - itemCountOnLastPage - 1; + _results = []; + for (x = _i = _ref = list.length, _ref1 = list.length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { + _results.push(x); + } + return _results; + } else { + return []; + } + } + }; + AngularTableManager = (function() { function AngularTableManager() { this.mappings = {}; @@ -469,10 +472,27 @@ } }; - AngularTableManager.prototype.register_table_scope = function(id, scope) { - var tc; + AngularTableManager.prototype.register_table_scope = function(id, scope, filter) { + var tc, update_stuff; this.mappings[id].table_scope = scope; tc = this.mappings[id].table_configuration; + update_stuff = function() { + scope.sorted_and_paginated_list = get_sorted_and_paginated_list(scope[tc.list], scope[irk_current_page], scope[tc.items_per_page], scope[tc.sort_context], scope.predicate, scope.descending, filter); + scope.filler_array = get_filler_array(scope[tc.list], scope[irk_current_page], scope[irk_number_of_pages], scope[tc.items_per_page]); + if (scope.filler_array) { + return console.log(scope.filler_array.length); + } + }; + scope.notify_change = function(current_page, number_of_pages) { + scope[irk_current_page] = current_page; + scope[irk_number_of_pages] = number_of_pages; + return update_stuff(); + }; + scope.$watch("" + tc.list + ".length", function() { + console.log("it changed!"); + return update_stuff(); + }); + tc = this.mappings[id].table_configuration; if (tc.initial_items_per_page) { scope.$parent[tc.items_per_page] = tc.initial_items_per_page; } @@ -493,10 +513,10 @@ mapping.pagination_scope = pagination_scope; if (mapping.table_configuration) { pagination_scope.$watch(irk_current_page, function() { - return update_table_scope(mapping.table_scope, pagination_scope, mapping.table_configuration); + return mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]); }); return pagination_scope.$watch(irk_number_of_pages, function() { - return update_table_scope(mapping.table_scope, pagination_scope, mapping.table_configuration); + return mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]); }); } }; @@ -521,7 +541,7 @@ var id; id = $attrs["id"]; if (id) { - return angularTableManager.register_table_scope(id, $scope); + return angularTableManager.register_table_scope(id, $scope, $filter); } } ], @@ -546,7 +566,7 @@ return { replace: true, restrict: "E", - template: " ", + template: "", controller: [ "$scope", "$element", "$attrs", function($scope, $element, $attrs) { return angularTableManager.register_pagination_scope($attrs.atTableId, $scope); @@ -632,7 +652,10 @@ $scope.$watch(tc.max_pages, function() { return update(); }); - return $scope.$watch(tc.list, function() { + $scope.$watch(tc.list, function() { + return update(); + }); + return $scope.$watch("" + tc.list + ".length", function() { return update(); }); } From 5baec8d81cb8ca54424a574ffd2eafb6a3f64404 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 17 Feb 2014 22:25:53 +0100 Subject: [PATCH 077/190] number of pages needs to be recalculated --- angular-table.js | 2 +- angular-table.min.js | 2 +- coffee/at-table.coffee | 3 ++- gem/app/assets/javascripts/angular-table.js | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/angular-table.js b/angular-table.js index b1eb28e..55751c6 100644 --- a/angular-table.js +++ b/angular-table.js @@ -489,10 +489,10 @@ return update_stuff(); }; scope.$watch("" + tc.list + ".length", function() { + scope[irk_number_of_pages] = Math.ceil(scope[tc.list].length / scope[tc.items_per_page]); console.log("it changed!"); return update_stuff(); }); - tc = this.mappings[id].table_configuration; if (tc.initial_items_per_page) { scope.$parent[tc.items_per_page] = tc.initial_items_per_page; } diff --git a/angular-table.min.js b/angular-table.min.js index 4f5387e..9dc5120 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,l,u,p,c,g,_,h,f,d,m,b,v,y,x,w={}.hasOwnProperty,k=function(t,e){function i(){this.constructor=t}for(var n in e)w.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[u]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,p;for(i=[],p=t.find("td"),l=0,u=p.length;u>l;l++)a=p[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return k(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return k(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(){},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),v="from_page",b="current_page",y="number_of_pages",g="atList",c="atItemsPerPage",u="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",p="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},x=function(t,e,i){return t[b]=e[b],t[y]=e[y],t[v]=s(t[i.items_per_page],t[b],t[i.list])},m=function(t,e,i,n,r,a,o){var s,l;return t?(l=t,s=i*e-t.length,"global"===n?(l=o("orderBy")(l,r,a),l=o("limitTo")(l,s),l=o("limitTo")(l,i)):(l=o("limitTo")(l,s),l=o("limitTo")(l,i),l=o("orderBy")(l,r,a)),l):(console.log("RETURNING NOTHING!!"),[])},d=function(t,e,i,n){var r,a,o,s,l,u,p;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,p=[],o=s=l=t.length,u=t.length+r;u>=l?u>=s:s>=u;o=u>=l?++s:--s)p.push(o);return p}return[]}},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e,i){var n,r;return this.mappings[t].table_scope=e,n=this.mappings[t].table_configuration,r=function(){return e.sorted_and_paginated_list=m(e[n.list],e[b],e[n.items_per_page],e[n.sort_context],e.predicate,e.descending,i),e.filler_array=d(e[n.list],e[b],e[y],e[n.items_per_page]),e.filler_array?console.log(e.filler_array.length):void 0},e.notify_change=function(t,i){return e[b]=t,e[y]=i,r()},e.$watch(""+n.list+".length",function(){return console.log("it changed!"),r()}),n=this.mappings[t].table_configuration,n.initial_items_per_page&&(e.$parent[n.items_per_page]=n.initial_items_per_page),n.initial_sort_context&&(e.$parent[n.sort_context]=n.initial_sort_context),n.initial_fill_last_page&&(e.$parent[n.fill_last_page]=n.initial_fill_last_page),n.initial_max_pages?e.$parent[n.max_pages]=n.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(b,function(){return i.table_scope.notify_change(e[b],e[y])}),e.$watch(y,function(){return i.table_scope.notify_change(e[b],e[y])})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[b]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[b]=0,e[s.list]?e[s.list].length>0?(e[y]=Math.ceil(e[s.list].length/e[s.items_per_page]),e.pages=e.show_sectioning()?r(0,e[s.max_pages]-1):r(0,e[y]-1)):(e[y]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[y]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[b]?(t=e.pages[0]-e[b],o(e.pages[0],-t,e[s.max_pages],e[y])):e.pages[e.pages.length-1]i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[u]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,p;for(i=[],p=t.find("td"),l=0,u=p.length;u>l;l++)a=p[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return k(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return k(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(){},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),v="from_page",b="current_page",y="number_of_pages",g="atList",c="atItemsPerPage",u="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",p="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},x=function(t,e,i){return t[b]=e[b],t[y]=e[y],t[v]=s(t[i.items_per_page],t[b],t[i.list])},m=function(t,e,i,n,r,a,o){var s,l;return t?(l=t,s=i*e-t.length,"global"===n?(l=o("orderBy")(l,r,a),l=o("limitTo")(l,s),l=o("limitTo")(l,i)):(l=o("limitTo")(l,s),l=o("limitTo")(l,i),l=o("orderBy")(l,r,a)),l):(console.log("RETURNING NOTHING!!"),[])},d=function(t,e,i,n){var r,a,o,s,l,u,p;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,p=[],o=s=l=t.length,u=t.length+r;u>=l?u>=s:s>=u;o=u>=l?++s:--s)p.push(o);return p}return[]}},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e,i){var n,r;return this.mappings[t].table_scope=e,n=this.mappings[t].table_configuration,r=function(){return e.sorted_and_paginated_list=m(e[n.list],e[b],e[n.items_per_page],e[n.sort_context],e.predicate,e.descending,i),e.filler_array=d(e[n.list],e[b],e[y],e[n.items_per_page]),e.filler_array?console.log(e.filler_array.length):void 0},e.notify_change=function(t,i){return e[b]=t,e[y]=i,r()},e.$watch(""+n.list+".length",function(){return e[y]=Math.ceil(e[n.list].length/e[n.items_per_page]),console.log("it changed!"),r()}),n.initial_items_per_page&&(e.$parent[n.items_per_page]=n.initial_items_per_page),n.initial_sort_context&&(e.$parent[n.sort_context]=n.initial_sort_context),n.initial_fill_last_page&&(e.$parent[n.fill_last_page]=n.initial_fill_last_page),n.initial_max_pages?e.$parent[n.max_pages]=n.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(b,function(){return i.table_scope.notify_change(e[b],e[y])}),e.$watch(y,function(){return i.table_scope.notify_change(e[b],e[y])})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[b]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[b]=0,e[s.list]?e[s.list].length>0?(e[y]=Math.ceil(e[s.list].length/e[s.items_per_page]),e.pages=e.show_sectioning()?r(0,e[s.max_pages]-1):r(0,e[y]-1)):(e[y]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[y]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[b]?(t=e.pages[0]-e[b],o(e.pages[0],-t,e[s.max_pages],e[y])):e.pages[e.pages.length-1] + scope[irk_number_of_pages] = Math.ceil(scope[tc.list].length / scope[tc.items_per_page]) console.log "it changed!" update_stuff() ) - tc = @mappings[id].table_configuration + # tc = @mappings[id].table_configuration if tc.initial_items_per_page scope.$parent[tc.items_per_page] = tc.initial_items_per_page diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index b1eb28e..55751c6 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -489,10 +489,10 @@ return update_stuff(); }; scope.$watch("" + tc.list + ".length", function() { + scope[irk_number_of_pages] = Math.ceil(scope[tc.list].length / scope[tc.items_per_page]); console.log("it changed!"); return update_stuff(); }); - tc = this.mappings[id].table_configuration; if (tc.initial_items_per_page) { scope.$parent[tc.items_per_page] = tc.initial_items_per_page; } From 4187269efdd143527953980f530e25d8a247a3c2 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 17 Feb 2014 22:53:07 +0100 Subject: [PATCH 078/190] dont reset current page to zero --- coffee/at-pagination.coffee | 3 ++- coffee/at-table.coffee | 3 --- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/coffee/at-pagination.coffee b/coffee/at-pagination.coffee index d83aa5c..eb7af37 100644 --- a/coffee/at-pagination.coffee +++ b/coffee/at-pagination.coffee @@ -52,11 +52,12 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" x for x in [start..end] update = (reset) -> - $scope[irk_current_page] = 0 + # $scope[irk_current_page] = 0 if $scope[tc.list] if $scope[tc.list].length > 0 $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]) + $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages]) if $scope.show_sectioning() $scope.pages = generate_page_array(0, $scope[tc.max_pages] - 1) else diff --git a/coffee/at-table.coffee b/coffee/at-table.coffee index efb8ce3..6700ea8 100644 --- a/coffee/at-table.coffee +++ b/coffee/at-table.coffee @@ -97,8 +97,6 @@ class AngularTableManager scope[tc.items_per_page] ) - console.log scope.filler_array.length if scope.filler_array - scope.notify_change = (current_page, number_of_pages) -> scope[irk_current_page] = current_page scope[irk_number_of_pages] = number_of_pages @@ -106,7 +104,6 @@ class AngularTableManager scope.$watch("#{tc.list}.length", () -> scope[irk_number_of_pages] = Math.ceil(scope[tc.list].length / scope[tc.items_per_page]) - console.log "it changed!" update_stuff() ) From 2aaaf613378936db0c9eeed0e63ce669c1352f40 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 17 Feb 2014 22:56:35 +0100 Subject: [PATCH 079/190] compiled --- angular-table.js | 8 ++------ angular-table.min.js | 2 +- gem/app/assets/javascripts/angular-table.js | 8 ++------ 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/angular-table.js b/angular-table.js index 55751c6..cafd8ba 100644 --- a/angular-table.js +++ b/angular-table.js @@ -478,10 +478,7 @@ tc = this.mappings[id].table_configuration; update_stuff = function() { scope.sorted_and_paginated_list = get_sorted_and_paginated_list(scope[tc.list], scope[irk_current_page], scope[tc.items_per_page], scope[tc.sort_context], scope.predicate, scope.descending, filter); - scope.filler_array = get_filler_array(scope[tc.list], scope[irk_current_page], scope[irk_number_of_pages], scope[tc.items_per_page]); - if (scope.filler_array) { - return console.log(scope.filler_array.length); - } + return scope.filler_array = get_filler_array(scope[tc.list], scope[irk_current_page], scope[irk_number_of_pages], scope[tc.items_per_page]); }; scope.notify_change = function(current_page, number_of_pages) { scope[irk_current_page] = current_page; @@ -490,7 +487,6 @@ }; scope.$watch("" + tc.list + ".length", function() { scope[irk_number_of_pages] = Math.ceil(scope[tc.list].length / scope[tc.items_per_page]); - console.log("it changed!"); return update_stuff(); }); if (tc.initial_items_per_page) { @@ -586,10 +582,10 @@ return _results; }; update = function(reset) { - $scope[irk_current_page] = 0; if ($scope[tc.list]) { if ($scope[tc.list].length > 0) { $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]); + $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages]); if ($scope.show_sectioning()) { return $scope.pages = generate_page_array(0, $scope[tc.max_pages] - 1); } else { diff --git a/angular-table.min.js b/angular-table.min.js index 9dc5120..584aeed 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,l,u,p,c,g,_,h,f,d,m,b,v,y,x,w={}.hasOwnProperty,k=function(t,e){function i(){this.constructor=t}for(var n in e)w.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[u]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,p;for(i=[],p=t.find("td"),l=0,u=p.length;u>l;l++)a=p[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return k(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return k(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(){},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),v="from_page",b="current_page",y="number_of_pages",g="atList",c="atItemsPerPage",u="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",p="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},x=function(t,e,i){return t[b]=e[b],t[y]=e[y],t[v]=s(t[i.items_per_page],t[b],t[i.list])},m=function(t,e,i,n,r,a,o){var s,l;return t?(l=t,s=i*e-t.length,"global"===n?(l=o("orderBy")(l,r,a),l=o("limitTo")(l,s),l=o("limitTo")(l,i)):(l=o("limitTo")(l,s),l=o("limitTo")(l,i),l=o("orderBy")(l,r,a)),l):(console.log("RETURNING NOTHING!!"),[])},d=function(t,e,i,n){var r,a,o,s,l,u,p;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,p=[],o=s=l=t.length,u=t.length+r;u>=l?u>=s:s>=u;o=u>=l?++s:--s)p.push(o);return p}return[]}},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e,i){var n,r;return this.mappings[t].table_scope=e,n=this.mappings[t].table_configuration,r=function(){return e.sorted_and_paginated_list=m(e[n.list],e[b],e[n.items_per_page],e[n.sort_context],e.predicate,e.descending,i),e.filler_array=d(e[n.list],e[b],e[y],e[n.items_per_page]),e.filler_array?console.log(e.filler_array.length):void 0},e.notify_change=function(t,i){return e[b]=t,e[y]=i,r()},e.$watch(""+n.list+".length",function(){return e[y]=Math.ceil(e[n.list].length/e[n.items_per_page]),console.log("it changed!"),r()}),n.initial_items_per_page&&(e.$parent[n.items_per_page]=n.initial_items_per_page),n.initial_sort_context&&(e.$parent[n.sort_context]=n.initial_sort_context),n.initial_fill_last_page&&(e.$parent[n.fill_last_page]=n.initial_fill_last_page),n.initial_max_pages?e.$parent[n.max_pages]=n.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(b,function(){return i.table_scope.notify_change(e[b],e[y])}),e.$watch(y,function(){return i.table_scope.notify_change(e[b],e[y])})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[b]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[b]=0,e[s.list]?e[s.list].length>0?(e[y]=Math.ceil(e[s.list].length/e[s.items_per_page]),e.pages=e.show_sectioning()?r(0,e[s.max_pages]-1):r(0,e[y]-1)):(e[y]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[y]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[b]?(t=e.pages[0]-e[b],o(e.pages[0],-t,e[s.max_pages],e[y])):e.pages[e.pages.length-1]i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[u]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,p;for(i=[],p=t.find("td"),l=0,u=p.length;u>l;l++)a=p[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return k(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return k(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(){},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),v="from_page",b="current_page",y="number_of_pages",g="atList",c="atItemsPerPage",u="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",p="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},x=function(t,e,i){return t[b]=e[b],t[y]=e[y],t[v]=s(t[i.items_per_page],t[b],t[i.list])},m=function(t,e,i,n,r,a,o){var s,l;return t?(l=t,s=i*e-t.length,"global"===n?(l=o("orderBy")(l,r,a),l=o("limitTo")(l,s),l=o("limitTo")(l,i)):(l=o("limitTo")(l,s),l=o("limitTo")(l,i),l=o("orderBy")(l,r,a)),l):(console.log("RETURNING NOTHING!!"),[])},d=function(t,e,i,n){var r,a,o,s,l,u,p;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,p=[],o=s=l=t.length,u=t.length+r;u>=l?u>=s:s>=u;o=u>=l?++s:--s)p.push(o);return p}return[]}},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e,i){var n,r;return this.mappings[t].table_scope=e,n=this.mappings[t].table_configuration,r=function(){return e.sorted_and_paginated_list=m(e[n.list],e[b],e[n.items_per_page],e[n.sort_context],e.predicate,e.descending,i),e.filler_array=d(e[n.list],e[b],e[y],e[n.items_per_page])},e.notify_change=function(t,i){return e[b]=t,e[y]=i,r()},e.$watch(""+n.list+".length",function(){return e[y]=Math.ceil(e[n.list].length/e[n.items_per_page]),r()}),n.initial_items_per_page&&(e.$parent[n.items_per_page]=n.initial_items_per_page),n.initial_sort_context&&(e.$parent[n.sort_context]=n.initial_sort_context),n.initial_fill_last_page&&(e.$parent[n.fill_last_page]=n.initial_fill_last_page),n.initial_max_pages?e.$parent[n.max_pages]=n.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(b,function(){return i.table_scope.notify_change(e[b],e[y])}),e.$watch(y,function(){return i.table_scope.notify_change(e[b],e[y])})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[b]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[s.list]?e[s.list].length>0?(e[y]=Math.ceil(e[s.list].length/e[s.items_per_page]),e[b]=a(e[b],0,e[y]),e.pages=e.show_sectioning()?r(0,e[s.max_pages]-1):r(0,e[y]-1)):(e[y]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[y]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[b]?(t=e.pages[0]-e[b],o(e.pages[0],-t,e[s.max_pages],e[y])):e.pages[e.pages.length-1] 0) { $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]); + $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages]); if ($scope.show_sectioning()) { return $scope.pages = generate_page_array(0, $scope[tc.max_pages] - 1); } else { From d14c0fcd2bb47523ff8f471d978f230fc9935012 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 17 Feb 2014 23:05:10 +0100 Subject: [PATCH 080/190] readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1fc59f0..9dd9d64 100644 --- a/README.md +++ b/README.md @@ -35,3 +35,4 @@ set up appropriate variables in your scope, prefixed with the id of the table, f ### Column options + From 24fdc3879dc0629293ed6287711f8a4e0d0b62ea Mon Sep 17 00:00:00 2001 From: Bitdeli Chef Date: Tue, 18 Feb 2014 14:46:00 +0000 Subject: [PATCH 081/190] Add a Bitdeli badge to README --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 9dd9d64..7222d0c 100644 --- a/README.md +++ b/README.md @@ -36,3 +36,7 @@ set up appropriate variables in your scope, prefixed with the id of the table, f ### Column options + + +[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/samu/angular-table/trend.png)](https://bitdeli.com/free "Bitdeli Badge") + From 11a1646d687a0fd527cc894a106f4b49141c04fa Mon Sep 17 00:00:00 2001 From: ssmm Date: Tue, 18 Feb 2014 16:36:29 +0100 Subject: [PATCH 082/190] bugfix --- angular-table.js | 11 +++++++++-- angular-table.min.js | 2 +- coffee/at-pagination.coffee | 17 +++++++++++++---- gem/app/assets/javascripts/angular-table.js | 11 +++++++++-- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/angular-table.js b/angular-table.js index cafd8ba..81aeed3 100644 --- a/angular-table.js +++ b/angular-table.js @@ -585,9 +585,10 @@ if ($scope[tc.list]) { if ($scope[tc.list].length > 0) { $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]); - $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages]); + $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages] - 1); + console.log("current page after update: ", $scope[irk_current_page]); if ($scope.show_sectioning()) { - return $scope.pages = generate_page_array(0, $scope[tc.max_pages] - 1); + return $scope.update_sectioning(); } else { return $scope.pages = generate_page_array(0, $scope[irk_number_of_pages] - 1); } @@ -618,6 +619,8 @@ }; $scope.update_sectioning = function() { var diff, new_start; + console.log("last displayed page: ", $scope.pages[$scope.pages.length - 1]); + console.log("current page: ", $scope[irk_current_page]); new_start = void 0; if ($scope.pages[0] > $scope[irk_current_page]) { diff = $scope.pages[0] - $scope[irk_current_page]; @@ -625,6 +628,10 @@ } else if ($scope.pages[$scope.pages.length - 1] < $scope[irk_current_page]) { diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1]; return shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); + } else if ($scope.pages[$scope.pages.length - 1] > $scope[irk_number_of_pages]) { + diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1]; + console.log(diff); + return shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); } }; $scope.step_page = function(step) { diff --git a/angular-table.min.js b/angular-table.min.js index 584aeed..2e68f02 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,l,u,p,c,g,_,h,f,d,m,b,v,y,x,w={}.hasOwnProperty,k=function(t,e){function i(){this.constructor=t}for(var n in e)w.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[u]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,u,p;for(i=[],p=t.find("td"),l=0,u=p.length;u>l;l++)a=p[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return k(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return k(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(){},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),v="from_page",b="current_page",y="number_of_pages",g="atList",c="atItemsPerPage",u="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",p="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},x=function(t,e,i){return t[b]=e[b],t[y]=e[y],t[v]=s(t[i.items_per_page],t[b],t[i.list])},m=function(t,e,i,n,r,a,o){var s,l;return t?(l=t,s=i*e-t.length,"global"===n?(l=o("orderBy")(l,r,a),l=o("limitTo")(l,s),l=o("limitTo")(l,i)):(l=o("limitTo")(l,s),l=o("limitTo")(l,i),l=o("orderBy")(l,r,a)),l):(console.log("RETURNING NOTHING!!"),[])},d=function(t,e,i,n){var r,a,o,s,l,u,p;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,p=[],o=s=l=t.length,u=t.length+r;u>=l?u>=s:s>=u;o=u>=l?++s:--s)p.push(o);return p}return[]}},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e,i){var n,r;return this.mappings[t].table_scope=e,n=this.mappings[t].table_configuration,r=function(){return e.sorted_and_paginated_list=m(e[n.list],e[b],e[n.items_per_page],e[n.sort_context],e.predicate,e.descending,i),e.filler_array=d(e[n.list],e[b],e[y],e[n.items_per_page])},e.notify_change=function(t,i){return e[b]=t,e[y]=i,r()},e.$watch(""+n.list+".length",function(){return e[y]=Math.ceil(e[n.list].length/e[n.items_per_page]),r()}),n.initial_items_per_page&&(e.$parent[n.items_per_page]=n.initial_items_per_page),n.initial_sort_context&&(e.$parent[n.sort_context]=n.initial_sort_context),n.initial_fill_last_page&&(e.$parent[n.fill_last_page]=n.initial_fill_last_page),n.initial_max_pages?e.$parent[n.max_pages]=n.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(b,function(){return i.table_scope.notify_change(e[b],e[y])}),e.$watch(y,function(){return i.table_scope.notify_change(e[b],e[y])})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[b]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[s.list]?e[s.list].length>0?(e[y]=Math.ceil(e[s.list].length/e[s.items_per_page]),e[b]=a(e[b],0,e[y]),e.pages=e.show_sectioning()?r(0,e[s.max_pages]-1):r(0,e[y]-1)):(e[y]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[y]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[b]?(t=e.pages[0]-e[b],o(e.pages[0],-t,e[s.max_pages],e[y])):e.pages[e.pages.length-1]i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[p]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,p,u;for(i=[],u=t.find("td"),l=0,p=u.length;p>l;l++)a=u[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return k(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return k(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(){},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),v="from_page",b="current_page",y="number_of_pages",g="atList",c="atItemsPerPage",p="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",u="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},x=function(t,e,i){return t[b]=e[b],t[y]=e[y],t[v]=s(t[i.items_per_page],t[b],t[i.list])},m=function(t,e,i,n,r,a,o){var s,l;return t?(l=t,s=i*e-t.length,"global"===n?(l=o("orderBy")(l,r,a),l=o("limitTo")(l,s),l=o("limitTo")(l,i)):(l=o("limitTo")(l,s),l=o("limitTo")(l,i),l=o("orderBy")(l,r,a)),l):(console.log("RETURNING NOTHING!!"),[])},d=function(t,e,i,n){var r,a,o,s,l,p,u;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,u=[],o=s=l=t.length,p=t.length+r;p>=l?p>=s:s>=p;o=p>=l?++s:--s)u.push(o);return u}return[]}},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e,i){var n,r;return this.mappings[t].table_scope=e,n=this.mappings[t].table_configuration,r=function(){return e.sorted_and_paginated_list=m(e[n.list],e[b],e[n.items_per_page],e[n.sort_context],e.predicate,e.descending,i),e.filler_array=d(e[n.list],e[b],e[y],e[n.items_per_page])},e.notify_change=function(t,i){return e[b]=t,e[y]=i,r()},e.$watch(""+n.list+".length",function(){return e[y]=Math.ceil(e[n.list].length/e[n.items_per_page]),r()}),n.initial_items_per_page&&(e.$parent[n.items_per_page]=n.initial_items_per_page),n.initial_sort_context&&(e.$parent[n.sort_context]=n.initial_sort_context),n.initial_fill_last_page&&(e.$parent[n.fill_last_page]=n.initial_fill_last_page),n.initial_max_pages?e.$parent[n.max_pages]=n.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(b,function(){return i.table_scope.notify_change(e[b],e[y])}),e.$watch(y,function(){return i.table_scope.notify_change(e[b],e[y])})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[b]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[s.list]?e[s.list].length>0?(e[y]=Math.ceil(e[s.list].length/e[s.items_per_page]),e[b]=a(e[b],0,e[y]-1),console.log("current page after update: ",e[b]),e.show_sectioning()?e.update_sectioning():e.pages=r(0,e[y]-1)):(e[y]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[y]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return console.log("last displayed page: ",e.pages[e.pages.length-1]),console.log("current page: ",e[b]),i=void 0,e.pages[0]>e[b]?(t=e.pages[0]-e[b],o(e.pages[0],-t,e[s.max_pages],e[y])):e.pages[e.pages.length-1]e[y]?(t=e[b]-e.pages[e.pages.length-1],console.log(t),o(e.pages[0],t,e[s.max_pages],e[y])):void 0},e.step_page=function(t){return t=parseInt(t),e[b]=a(e[b]+t,0,e[y]-1),e.update_sectioning()},e.go_to_page=function(t){return e[b]=t},e.jump_back=function(){return e.step_page(-e[s.max_pages])},e.jump_ahead=function(){return e.step_page(e[s.max_pages])},l(),e.$watch(s.items_per_page,function(){return l()}),e.$watch(s.max_pages,function(){return l()}),e.$watch(s.list,function(){return l()}),e.$watch(""+s.list+".length",function(){return l()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file diff --git a/coffee/at-pagination.coffee b/coffee/at-pagination.coffee index eb7af37..fda9351 100644 --- a/coffee/at-pagination.coffee +++ b/coffee/at-pagination.coffee @@ -52,14 +52,14 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" x for x in [start..end] update = (reset) -> - # $scope[irk_current_page] = 0 - if $scope[tc.list] if $scope[tc.list].length > 0 $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]) - $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages]) + $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages] - 1) + console.log "current page after update: ", $scope[irk_current_page] if $scope.show_sectioning() - $scope.pages = generate_page_array(0, $scope[tc.max_pages] - 1) + # $scope.pages = generate_page_array(0, $scope[tc.max_pages] - 1) + $scope.update_sectioning() else $scope.pages = generate_page_array(0, $scope[irk_number_of_pages] - 1) else @@ -84,6 +84,10 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" $scope.pages = generate_page_array(new_start, new_start + parseInt($scope[tc.max_pages]) - 1) $scope.update_sectioning = () -> + + console.log "last displayed page: ", $scope.pages[$scope.pages.length - 1] + console.log "current page: ", $scope[irk_current_page] + new_start = undefined if $scope.pages[0] > $scope[irk_current_page] diff = $scope.pages[0] - $scope[irk_current_page] @@ -91,6 +95,11 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" else if $scope.pages[$scope.pages.length - 1] < $scope[irk_current_page] diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1] shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]) + else if $scope.pages[$scope.pages.length - 1] > $scope[irk_number_of_pages] + diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1] + console.log diff + shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]) + $scope.step_page = (step) -> step = parseInt(step) diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index cafd8ba..81aeed3 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -585,9 +585,10 @@ if ($scope[tc.list]) { if ($scope[tc.list].length > 0) { $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]); - $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages]); + $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages] - 1); + console.log("current page after update: ", $scope[irk_current_page]); if ($scope.show_sectioning()) { - return $scope.pages = generate_page_array(0, $scope[tc.max_pages] - 1); + return $scope.update_sectioning(); } else { return $scope.pages = generate_page_array(0, $scope[irk_number_of_pages] - 1); } @@ -618,6 +619,8 @@ }; $scope.update_sectioning = function() { var diff, new_start; + console.log("last displayed page: ", $scope.pages[$scope.pages.length - 1]); + console.log("current page: ", $scope[irk_current_page]); new_start = void 0; if ($scope.pages[0] > $scope[irk_current_page]) { diff = $scope.pages[0] - $scope[irk_current_page]; @@ -625,6 +628,10 @@ } else if ($scope.pages[$scope.pages.length - 1] < $scope[irk_current_page]) { diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1]; return shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); + } else if ($scope.pages[$scope.pages.length - 1] > $scope[irk_number_of_pages]) { + diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1]; + console.log(diff); + return shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); } }; $scope.step_page = function(step) { From 60a8d68df6e2d1ced1a5b0a2a67440d430f1dc6e Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 18 Feb 2014 21:20:18 +0100 Subject: [PATCH 083/190] fixed pagination bug --- angular-table.js | 8 ++------ angular-table.min.js | 2 +- coffee/at-pagination.coffee | 8 +------- coffee/at-table.coffee | 2 +- gem/app/assets/javascripts/angular-table.js | 8 ++------ 5 files changed, 7 insertions(+), 21 deletions(-) diff --git a/angular-table.js b/angular-table.js index 81aeed3..20f09e9 100644 --- a/angular-table.js +++ b/angular-table.js @@ -432,7 +432,7 @@ } return val; } else { - console.log("RETURNING NOTHING!!"); + console.log("RETURNING EMPTY"); return []; } }; @@ -586,7 +586,6 @@ if ($scope[tc.list].length > 0) { $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]); $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages] - 1); - console.log("current page after update: ", $scope[irk_current_page]); if ($scope.show_sectioning()) { return $scope.update_sectioning(); } else { @@ -619,8 +618,6 @@ }; $scope.update_sectioning = function() { var diff, new_start; - console.log("last displayed page: ", $scope.pages[$scope.pages.length - 1]); - console.log("current page: ", $scope[irk_current_page]); new_start = void 0; if ($scope.pages[0] > $scope[irk_current_page]) { diff = $scope.pages[0] - $scope[irk_current_page]; @@ -628,9 +625,8 @@ } else if ($scope.pages[$scope.pages.length - 1] < $scope[irk_current_page]) { diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1]; return shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); - } else if ($scope.pages[$scope.pages.length - 1] > $scope[irk_number_of_pages]) { + } else if ($scope.pages[$scope.pages.length - 1] > ($scope[irk_number_of_pages] - 1)) { diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1]; - console.log(diff); return shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); } }; diff --git a/angular-table.min.js b/angular-table.min.js index 2e68f02..6b28bef 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,l,p,u,c,g,_,h,f,d,m,b,v,y,x,w={}.hasOwnProperty,k=function(t,e){function i(){this.constructor=t}for(var n in e)w.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[p]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,p,u;for(i=[],u=t.find("td"),l=0,p=u.length;p>l;l++)a=u[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return k(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return k(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(){},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),v="from_page",b="current_page",y="number_of_pages",g="atList",c="atItemsPerPage",p="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",u="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},x=function(t,e,i){return t[b]=e[b],t[y]=e[y],t[v]=s(t[i.items_per_page],t[b],t[i.list])},m=function(t,e,i,n,r,a,o){var s,l;return t?(l=t,s=i*e-t.length,"global"===n?(l=o("orderBy")(l,r,a),l=o("limitTo")(l,s),l=o("limitTo")(l,i)):(l=o("limitTo")(l,s),l=o("limitTo")(l,i),l=o("orderBy")(l,r,a)),l):(console.log("RETURNING NOTHING!!"),[])},d=function(t,e,i,n){var r,a,o,s,l,p,u;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,u=[],o=s=l=t.length,p=t.length+r;p>=l?p>=s:s>=p;o=p>=l?++s:--s)u.push(o);return u}return[]}},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e,i){var n,r;return this.mappings[t].table_scope=e,n=this.mappings[t].table_configuration,r=function(){return e.sorted_and_paginated_list=m(e[n.list],e[b],e[n.items_per_page],e[n.sort_context],e.predicate,e.descending,i),e.filler_array=d(e[n.list],e[b],e[y],e[n.items_per_page])},e.notify_change=function(t,i){return e[b]=t,e[y]=i,r()},e.$watch(""+n.list+".length",function(){return e[y]=Math.ceil(e[n.list].length/e[n.items_per_page]),r()}),n.initial_items_per_page&&(e.$parent[n.items_per_page]=n.initial_items_per_page),n.initial_sort_context&&(e.$parent[n.sort_context]=n.initial_sort_context),n.initial_fill_last_page&&(e.$parent[n.fill_last_page]=n.initial_fill_last_page),n.initial_max_pages?e.$parent[n.max_pages]=n.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(b,function(){return i.table_scope.notify_change(e[b],e[y])}),e.$watch(y,function(){return i.table_scope.notify_change(e[b],e[y])})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[b]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[s.list]?e[s.list].length>0?(e[y]=Math.ceil(e[s.list].length/e[s.items_per_page]),e[b]=a(e[b],0,e[y]-1),console.log("current page after update: ",e[b]),e.show_sectioning()?e.update_sectioning():e.pages=r(0,e[y]-1)):(e[y]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[y]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return console.log("last displayed page: ",e.pages[e.pages.length-1]),console.log("current page: ",e[b]),i=void 0,e.pages[0]>e[b]?(t=e.pages[0]-e[b],o(e.pages[0],-t,e[s.max_pages],e[y])):e.pages[e.pages.length-1]e[y]?(t=e[b]-e.pages[e.pages.length-1],console.log(t),o(e.pages[0],t,e[s.max_pages],e[y])):void 0},e.step_page=function(t){return t=parseInt(t),e[b]=a(e[b]+t,0,e[y]-1),e.update_sectioning()},e.go_to_page=function(t){return e[b]=t},e.jump_back=function(){return e.step_page(-e[s.max_pages])},e.jump_ahead=function(){return e.step_page(e[s.max_pages])},l(),e.$watch(s.items_per_page,function(){return l()}),e.$watch(s.max_pages,function(){return l()}),e.$watch(s.list,function(){return l()}),e.$watch(""+s.list+".length",function(){return l()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var t,e,i,n,r,a,o,s,l,p,u,c,g,_,h,f,d,m,b,v,y,x,w={}.hasOwnProperty,k=function(t,e){function i(){this.constructor=t}for(var n in e)w.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[p]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,p,u;for(i=[],u=t.find("td"),l=0,p=u.length;p>l;l++)a=u[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return k(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return k(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(){},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),v="from_page",b="current_page",y="number_of_pages",g="atList",c="atItemsPerPage",p="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",u="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},x=function(t,e,i){return t[b]=e[b],t[y]=e[y],t[v]=s(t[i.items_per_page],t[b],t[i.list])},m=function(t,e,i,n,r,a,o){var s,l;return t?(l=t,s=i*e-t.length,"global"===n?(l=o("orderBy")(l,r,a),l=o("limitTo")(l,s),l=o("limitTo")(l,i)):(l=o("limitTo")(l,s),l=o("limitTo")(l,i),l=o("orderBy")(l,r,a)),l):(console.log("RETURNING EMPTY"),[])},d=function(t,e,i,n){var r,a,o,s,l,p,u;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,u=[],o=s=l=t.length,p=t.length+r;p>=l?p>=s:s>=p;o=p>=l?++s:--s)u.push(o);return u}return[]}},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e,i){var n,r;return this.mappings[t].table_scope=e,n=this.mappings[t].table_configuration,r=function(){return e.sorted_and_paginated_list=m(e[n.list],e[b],e[n.items_per_page],e[n.sort_context],e.predicate,e.descending,i),e.filler_array=d(e[n.list],e[b],e[y],e[n.items_per_page])},e.notify_change=function(t,i){return e[b]=t,e[y]=i,r()},e.$watch(""+n.list+".length",function(){return e[y]=Math.ceil(e[n.list].length/e[n.items_per_page]),r()}),n.initial_items_per_page&&(e.$parent[n.items_per_page]=n.initial_items_per_page),n.initial_sort_context&&(e.$parent[n.sort_context]=n.initial_sort_context),n.initial_fill_last_page&&(e.$parent[n.fill_last_page]=n.initial_fill_last_page),n.initial_max_pages?e.$parent[n.max_pages]=n.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(b,function(){return i.table_scope.notify_change(e[b],e[y])}),e.$watch(y,function(){return i.table_scope.notify_change(e[b],e[y])})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[b]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[s.list]?e[s.list].length>0?(e[y]=Math.ceil(e[s.list].length/e[s.items_per_page]),e[b]=a(e[b],0,e[y]-1),e.show_sectioning()?e.update_sectioning():e.pages=r(0,e[y]-1)):(e[y]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[y]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[b]?(t=e.pages[0]-e[b],o(e.pages[0],-t,e[s.max_pages],e[y])):e.pages[e.pages.length-1]e[y]-1?(t=e[b]-e.pages[e.pages.length-1],o(e.pages[0],t,e[s.max_pages],e[y])):void 0},e.step_page=function(t){return t=parseInt(t),e[b]=a(e[b]+t,0,e[y]-1),e.update_sectioning()},e.go_to_page=function(t){return e[b]=t},e.jump_back=function(){return e.step_page(-e[s.max_pages])},e.jump_ahead=function(){return e.step_page(e[s.max_pages])},l(),e.$watch(s.items_per_page,function(){return l()}),e.$watch(s.max_pages,function(){return l()}),e.$watch(s.list,function(){return l()}),e.$watch(""+s.list+".length",function(){return l()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file diff --git a/coffee/at-pagination.coffee b/coffee/at-pagination.coffee index fda9351..93665c8 100644 --- a/coffee/at-pagination.coffee +++ b/coffee/at-pagination.coffee @@ -56,7 +56,6 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" if $scope[tc.list].length > 0 $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]) $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages] - 1) - console.log "current page after update: ", $scope[irk_current_page] if $scope.show_sectioning() # $scope.pages = generate_page_array(0, $scope[tc.max_pages] - 1) $scope.update_sectioning() @@ -84,10 +83,6 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" $scope.pages = generate_page_array(new_start, new_start + parseInt($scope[tc.max_pages]) - 1) $scope.update_sectioning = () -> - - console.log "last displayed page: ", $scope.pages[$scope.pages.length - 1] - console.log "current page: ", $scope[irk_current_page] - new_start = undefined if $scope.pages[0] > $scope[irk_current_page] diff = $scope.pages[0] - $scope[irk_current_page] @@ -95,9 +90,8 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" else if $scope.pages[$scope.pages.length - 1] < $scope[irk_current_page] diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1] shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]) - else if $scope.pages[$scope.pages.length - 1] > $scope[irk_number_of_pages] + else if $scope.pages[$scope.pages.length - 1] > ($scope[irk_number_of_pages] - 1) diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1] - console.log diff shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]) diff --git a/coffee/at-table.coffee b/coffee/at-table.coffee index 6700ea8..7479c13 100644 --- a/coffee/at-table.coffee +++ b/coffee/at-table.coffee @@ -46,7 +46,7 @@ get_sorted_and_paginated_list = (list, current_page, items_per_page, sort_contex return val else - console.log "RETURNING NOTHING!!" + console.log "RETURNING EMPTY" return [] get_filler_array = (list, current_page, number_of_pages, items_per_page) -> diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 81aeed3..20f09e9 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -432,7 +432,7 @@ } return val; } else { - console.log("RETURNING NOTHING!!"); + console.log("RETURNING EMPTY"); return []; } }; @@ -586,7 +586,6 @@ if ($scope[tc.list].length > 0) { $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]); $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages] - 1); - console.log("current page after update: ", $scope[irk_current_page]); if ($scope.show_sectioning()) { return $scope.update_sectioning(); } else { @@ -619,8 +618,6 @@ }; $scope.update_sectioning = function() { var diff, new_start; - console.log("last displayed page: ", $scope.pages[$scope.pages.length - 1]); - console.log("current page: ", $scope[irk_current_page]); new_start = void 0; if ($scope.pages[0] > $scope[irk_current_page]) { diff = $scope.pages[0] - $scope[irk_current_page]; @@ -628,9 +625,8 @@ } else if ($scope.pages[$scope.pages.length - 1] < $scope[irk_current_page]) { diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1]; return shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); - } else if ($scope.pages[$scope.pages.length - 1] > $scope[irk_number_of_pages]) { + } else if ($scope.pages[$scope.pages.length - 1] > ($scope[irk_number_of_pages] - 1)) { diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1]; - console.log(diff); return shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); } }; From de1fab655bc1b7c2a9def242e38e0f0f8645c4f1 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 18 Feb 2014 21:30:55 +0100 Subject: [PATCH 084/190] fixed sorting --- angular-table.js | 6 ++++++ angular-table.min.js | 2 +- coffee/at-table.coffee | 8 ++++++++ gem/app/assets/javascripts/angular-table.js | 6 ++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/angular-table.js b/angular-table.js index 20f09e9..159fcea 100644 --- a/angular-table.js +++ b/angular-table.js @@ -489,6 +489,12 @@ scope[irk_number_of_pages] = Math.ceil(scope[tc.list].length / scope[tc.items_per_page]); return update_stuff(); }); + scope.$watch("predicate", function() { + return update_stuff(); + }); + scope.$watch("descending", function() { + return update_stuff(); + }); if (tc.initial_items_per_page) { scope.$parent[tc.items_per_page] = tc.initial_items_per_page; } diff --git a/angular-table.min.js b/angular-table.min.js index 6b28bef..50ac008 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,l,p,u,c,g,_,h,f,d,m,b,v,y,x,w={}.hasOwnProperty,k=function(t,e){function i(){this.constructor=t}for(var n in e)w.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[p]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,p,u;for(i=[],u=t.find("td"),l=0,p=u.length;p>l;l++)a=u[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return k(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return k(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(){},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),v="from_page",b="current_page",y="number_of_pages",g="atList",c="atItemsPerPage",p="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",u="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},x=function(t,e,i){return t[b]=e[b],t[y]=e[y],t[v]=s(t[i.items_per_page],t[b],t[i.list])},m=function(t,e,i,n,r,a,o){var s,l;return t?(l=t,s=i*e-t.length,"global"===n?(l=o("orderBy")(l,r,a),l=o("limitTo")(l,s),l=o("limitTo")(l,i)):(l=o("limitTo")(l,s),l=o("limitTo")(l,i),l=o("orderBy")(l,r,a)),l):(console.log("RETURNING EMPTY"),[])},d=function(t,e,i,n){var r,a,o,s,l,p,u;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,u=[],o=s=l=t.length,p=t.length+r;p>=l?p>=s:s>=p;o=p>=l?++s:--s)u.push(o);return u}return[]}},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e,i){var n,r;return this.mappings[t].table_scope=e,n=this.mappings[t].table_configuration,r=function(){return e.sorted_and_paginated_list=m(e[n.list],e[b],e[n.items_per_page],e[n.sort_context],e.predicate,e.descending,i),e.filler_array=d(e[n.list],e[b],e[y],e[n.items_per_page])},e.notify_change=function(t,i){return e[b]=t,e[y]=i,r()},e.$watch(""+n.list+".length",function(){return e[y]=Math.ceil(e[n.list].length/e[n.items_per_page]),r()}),n.initial_items_per_page&&(e.$parent[n.items_per_page]=n.initial_items_per_page),n.initial_sort_context&&(e.$parent[n.sort_context]=n.initial_sort_context),n.initial_fill_last_page&&(e.$parent[n.fill_last_page]=n.initial_fill_last_page),n.initial_max_pages?e.$parent[n.max_pages]=n.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(b,function(){return i.table_scope.notify_change(e[b],e[y])}),e.$watch(y,function(){return i.table_scope.notify_change(e[b],e[y])})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[b]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[s.list]?e[s.list].length>0?(e[y]=Math.ceil(e[s.list].length/e[s.items_per_page]),e[b]=a(e[b],0,e[y]-1),e.show_sectioning()?e.update_sectioning():e.pages=r(0,e[y]-1)):(e[y]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[y]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[b]?(t=e.pages[0]-e[b],o(e.pages[0],-t,e[s.max_pages],e[y])):e.pages[e.pages.length-1]e[y]-1?(t=e[b]-e.pages[e.pages.length-1],o(e.pages[0],t,e[s.max_pages],e[y])):void 0},e.step_page=function(t){return t=parseInt(t),e[b]=a(e[b]+t,0,e[y]-1),e.update_sectioning()},e.go_to_page=function(t){return e[b]=t},e.jump_back=function(){return e.step_page(-e[s.max_pages])},e.jump_ahead=function(){return e.step_page(e[s.max_pages])},l(),e.$watch(s.items_per_page,function(){return l()}),e.$watch(s.max_pages,function(){return l()}),e.$watch(s.list,function(){return l()}),e.$watch(""+s.list+".length",function(){return l()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var t,e,i,n,r,a,o,s,l,p,u,c,g,_,h,f,d,m,b,v,y,x,w={}.hasOwnProperty,$=function(t,e){function i(){this.constructor=t}for(var n in e)w.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[p]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,p,u;for(i=[],u=t.find("td"),l=0,p=u.length;p>l;l++)a=u[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return $(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return $(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(){},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),v="from_page",b="current_page",y="number_of_pages",g="atList",c="atItemsPerPage",p="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",u="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},x=function(t,e,i){return t[b]=e[b],t[y]=e[y],t[v]=s(t[i.items_per_page],t[b],t[i.list])},m=function(t,e,i,n,r,a,o){var s,l;return t?(l=t,s=i*e-t.length,"global"===n?(l=o("orderBy")(l,r,a),l=o("limitTo")(l,s),l=o("limitTo")(l,i)):(l=o("limitTo")(l,s),l=o("limitTo")(l,i),l=o("orderBy")(l,r,a)),l):(console.log("RETURNING EMPTY"),[])},d=function(t,e,i,n){var r,a,o,s,l,p,u;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,u=[],o=s=l=t.length,p=t.length+r;p>=l?p>=s:s>=p;o=p>=l?++s:--s)u.push(o);return u}return[]}},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e,i){var n,r;return this.mappings[t].table_scope=e,n=this.mappings[t].table_configuration,r=function(){return e.sorted_and_paginated_list=m(e[n.list],e[b],e[n.items_per_page],e[n.sort_context],e.predicate,e.descending,i),e.filler_array=d(e[n.list],e[b],e[y],e[n.items_per_page])},e.notify_change=function(t,i){return e[b]=t,e[y]=i,r()},e.$watch(""+n.list+".length",function(){return e[y]=Math.ceil(e[n.list].length/e[n.items_per_page]),r()}),e.$watch("predicate",function(){return r()}),e.$watch("descending",function(){return r()}),n.initial_items_per_page&&(e.$parent[n.items_per_page]=n.initial_items_per_page),n.initial_sort_context&&(e.$parent[n.sort_context]=n.initial_sort_context),n.initial_fill_last_page&&(e.$parent[n.fill_last_page]=n.initial_fill_last_page),n.initial_max_pages?e.$parent[n.max_pages]=n.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(b,function(){return i.table_scope.notify_change(e[b],e[y])}),e.$watch(y,function(){return i.table_scope.notify_change(e[b],e[y])})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[b]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[s.list]?e[s.list].length>0?(e[y]=Math.ceil(e[s.list].length/e[s.items_per_page]),e[b]=a(e[b],0,e[y]-1),e.show_sectioning()?e.update_sectioning():e.pages=r(0,e[y]-1)):(e[y]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[y]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[b]?(t=e.pages[0]-e[b],o(e.pages[0],-t,e[s.max_pages],e[y])):e.pages[e.pages.length-1]e[y]-1?(t=e[b]-e.pages[e.pages.length-1],o(e.pages[0],t,e[s.max_pages],e[y])):void 0},e.step_page=function(t){return t=parseInt(t),e[b]=a(e[b]+t,0,e[y]-1),e.update_sectioning()},e.go_to_page=function(t){return e[b]=t},e.jump_back=function(){return e.step_page(-e[s.max_pages])},e.jump_ahead=function(){return e.step_page(e[s.max_pages])},l(),e.$watch(s.items_per_page,function(){return l()}),e.$watch(s.max_pages,function(){return l()}),e.$watch(s.list,function(){return l()}),e.$watch(""+s.list+".length",function(){return l()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file diff --git a/coffee/at-table.coffee b/coffee/at-table.coffee index 7479c13..3ad99f9 100644 --- a/coffee/at-table.coffee +++ b/coffee/at-table.coffee @@ -107,6 +107,14 @@ class AngularTableManager update_stuff() ) + scope.$watch("predicate", () -> + update_stuff() + ) + + scope.$watch("descending", () -> + update_stuff() + ) + # tc = @mappings[id].table_configuration if tc.initial_items_per_page diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 20f09e9..159fcea 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -489,6 +489,12 @@ scope[irk_number_of_pages] = Math.ceil(scope[tc.list].length / scope[tc.items_per_page]); return update_stuff(); }); + scope.$watch("predicate", function() { + return update_stuff(); + }); + scope.$watch("descending", function() { + return update_stuff(); + }); if (tc.initial_items_per_page) { scope.$parent[tc.items_per_page] = tc.initial_items_per_page; } From 195d1b4d1c3d25a226a09b6a843d316a9e63b92e Mon Sep 17 00:00:00 2001 From: ssmm Date: Wed, 19 Feb 2014 14:05:34 +0100 Subject: [PATCH 085/190] lots of refactoring --- angular-table.js | 246 ++++++++++-------- angular-table.min.js | 2 +- coffee/at-pagination.coffee | 69 +++-- coffee/at-table.coffee | 119 ++------- .../configuration/table_configuration.coffee | 12 + coffee/table/setup/paginated_setup.coffee | 101 ++++--- gem/app/assets/javascripts/angular-table.js | 246 ++++++++++-------- test/templates/pagination/pagination.html | 4 +- 8 files changed, 434 insertions(+), 365 deletions(-) diff --git a/angular-table.js b/angular-table.js index 159fcea..1772109 100644 --- a/angular-table.js +++ b/angular-table.js @@ -3,7 +3,7 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var AngularTableManager, ColumnConfiguration, PaginatedSetup, Setup, StandardSetup, Table, TableConfiguration, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, get_filler_array, get_sorted_and_paginated_list, irk_current_page, irk_from_page, irk_number_of_pages, update_table_scope, + var AngularTableManager, ColumnConfiguration, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, erk_attribute, erk_current_page, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -83,6 +83,7 @@ this.register_sort_context(this.attributes[erk_sort_context]); this.register_fill_last_page(this.attributes[erk_fill_last_page]); this.register_max_pages(this.attributes[erk_max_pages]); + this.register_current_page(this.attributes[erk_current_page]); this.paginated = this.items_per_page !== void 0; this.create_column_configurations(); } @@ -141,6 +142,20 @@ } }; + TableConfiguration.prototype.register_current_page = function(current_page) { + if (current_page !== void 0) { + if (isNaN(current_page)) { + return this.current_page = current_page; + } else { + this.current_page = "" + this.id + "_currentPage"; + return this.initial_current_page = parseInt(current_page); + } + } else { + this.current_page = "" + this.id + "_currentPage"; + return this.initial_current_page = 0; + } + }; + TableConfiguration.prototype.capitaliseFirstLetter = function(string) { if (string) { return string.charAt(0).toUpperCase() + string.slice(1); @@ -292,7 +307,66 @@ tbody.append(fillerTr); }; - PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) {}; + PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) { + var get_filler_array, get_sorted_and_paginated_list, tc, update_stuff, w; + tc = this.table_configuration; + w = new ScopeConfigWrapper($scope, tc); + get_sorted_and_paginated_list = function(list, current_page, items_per_page, sort_context, predicate, descending, $filter) { + var from_page, val; + if (list) { + val = list; + from_page = items_per_page * current_page - list.length; + if (sort_context === "global") { + val = $filter("orderBy")(val, predicate, descending); + val = $filter("limitTo")(val, from_page); + val = $filter("limitTo")(val, items_per_page); + } else { + val = $filter("limitTo")(val, from_page); + val = $filter("limitTo")(val, items_per_page); + val = $filter("orderBy")(val, predicate, descending); + } + return val; + } else { + return []; + } + }; + get_filler_array = function(list, current_page, number_of_pages, items_per_page) { + var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; + if (current_page === number_of_pages - 1) { + itemCountOnLastPage = list.length % items_per_page; + if (itemCountOnLastPage !== 0 || list.length === 0) { + fillerLength = items_per_page - itemCountOnLastPage - 1; + _results = []; + for (x = _i = _ref = list.length, _ref1 = list.length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { + _results.push(x); + } + return _results; + } else { + return []; + } + } + }; + update_stuff = function() { + $scope.sorted_and_paginated_list = get_sorted_and_paginated_list($scope[tc.list], w.get_current_page(), w.get_items_per_page(), $scope[tc.sort_context], $scope.predicate, $scope.descending, $filter); + return $scope.filler_array = get_filler_array($scope[tc.list], w.get_current_page(), $scope[irk_number_of_pages], w.get_items_per_page()); + }; + $scope.$watch(tc.current_page, function() { + return update_stuff(); + }); + $scope.$watch(tc.items_per_page, function() { + return update_stuff(); + }); + $scope.$watch("" + tc.list + ".length", function() { + $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / w.get_items_per_page()); + return update_stuff(); + }); + $scope.$watch("predicate", function() { + return update_stuff(); + }); + return $scope.$watch("descending", function() { + return update_stuff(); + }); + }; return PaginatedSetup; @@ -398,61 +472,35 @@ erk_max_pages = "atMaxPages"; + erk_current_page = "atCurrentPage"; + erk_attribute = "at-attribute"; erk_sortable = "at-sortable"; erk_initial_sorting = "at-initial-sorting"; - calculate_from_page = function(items_per_page, current_page, list) { - if (list) { - return items_per_page * current_page - list.length; - } - }; - - update_table_scope = function(table_scope, pagination_scope, table_configuration) { - table_scope[irk_current_page] = pagination_scope[irk_current_page]; - table_scope[irk_number_of_pages] = pagination_scope[irk_number_of_pages]; - return table_scope[irk_from_page] = calculate_from_page(table_scope[table_configuration.items_per_page], table_scope[irk_current_page], table_scope[table_configuration.list]); - }; - - get_sorted_and_paginated_list = function(list, current_page, items_per_page, sort_context, predicate, descending, $filter) { - var from_page, val; - if (list) { - val = list; - from_page = items_per_page * current_page - list.length; - if (sort_context === "global") { - val = $filter("orderBy")(val, predicate, descending); - val = $filter("limitTo")(val, from_page); - val = $filter("limitTo")(val, items_per_page); - } else { - val = $filter("limitTo")(val, from_page); - val = $filter("limitTo")(val, items_per_page); - val = $filter("orderBy")(val, predicate, descending); - } - return val; - } else { - console.log("RETURNING EMPTY"); - return []; + ScopeConfigWrapper = (function() { + function ScopeConfigWrapper(table_scope, table_configuration) { + this.scope = table_scope; + this.config = table_configuration; } - }; - - get_filler_array = function(list, current_page, number_of_pages, items_per_page) { - var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; - if (current_page === number_of_pages - 1) { - itemCountOnLastPage = list.length % items_per_page; - if (itemCountOnLastPage !== 0 || list.length === 0) { - fillerLength = items_per_page - itemCountOnLastPage - 1; - _results = []; - for (x = _i = _ref = list.length, _ref1 = list.length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { - _results.push(x); - } - return _results; - } else { - return []; - } - } - }; + + ScopeConfigWrapper.prototype.get_items_per_page = function() { + return this.scope.$eval(this.config.items_per_page); + }; + + ScopeConfigWrapper.prototype.get_current_page = function() { + return this.scope.$eval(this.config.current_page); + }; + + ScopeConfigWrapper.prototype.get_max_pages = function() { + return this.scope.$eval(this.config.max_pages); + }; + + return ScopeConfigWrapper; + + })(); AngularTableManager = (function() { function AngularTableManager() { @@ -473,28 +521,9 @@ }; AngularTableManager.prototype.register_table_scope = function(id, scope, filter) { - var tc, update_stuff; + var tc; this.mappings[id].table_scope = scope; tc = this.mappings[id].table_configuration; - update_stuff = function() { - scope.sorted_and_paginated_list = get_sorted_and_paginated_list(scope[tc.list], scope[irk_current_page], scope[tc.items_per_page], scope[tc.sort_context], scope.predicate, scope.descending, filter); - return scope.filler_array = get_filler_array(scope[tc.list], scope[irk_current_page], scope[irk_number_of_pages], scope[tc.items_per_page]); - }; - scope.notify_change = function(current_page, number_of_pages) { - scope[irk_current_page] = current_page; - scope[irk_number_of_pages] = number_of_pages; - return update_stuff(); - }; - scope.$watch("" + tc.list + ".length", function() { - scope[irk_number_of_pages] = Math.ceil(scope[tc.list].length / scope[tc.items_per_page]); - return update_stuff(); - }); - scope.$watch("predicate", function() { - return update_stuff(); - }); - scope.$watch("descending", function() { - return update_stuff(); - }); if (tc.initial_items_per_page) { scope.$parent[tc.items_per_page] = tc.initial_items_per_page; } @@ -505,24 +534,15 @@ scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page; } if (tc.initial_max_pages) { - return scope.$parent[tc.max_pages] = tc.initial_max_pages; + scope.$parent[tc.max_pages] = tc.initial_max_pages; } - }; - - AngularTableManager.prototype.register_pagination_scope = function(id, pagination_scope) { - var mapping, _base; - mapping = (_base = this.mappings)[id] || (_base[id] = {}); - mapping.pagination_scope = pagination_scope; - if (mapping.table_configuration) { - pagination_scope.$watch(irk_current_page, function() { - return mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]); - }); - return pagination_scope.$watch(irk_number_of_pages, function() { - return mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]); - }); + if (tc.initial_current_page !== void 0) { + return scope.$parent[tc.current_page] = tc.initial_current_page; } }; + AngularTableManager.prototype.register_pagination_scope = function(id, pagination_scope) {}; + return AngularTableManager; })(); @@ -568,7 +588,7 @@ return { replace: true, restrict: "E", - template: "", + template: "", controller: [ "$scope", "$element", "$attrs", function($scope, $element, $attrs) { return angularTableManager.register_pagination_scope($attrs.atTableId, $scope); @@ -576,9 +596,9 @@ ], scope: true, link: function($scope, $element, $attributes) { - var generate_page_array, keep_in_bounds, shift_sectioning, tc, update; + var generate_page_array, get_number_of_pages, keep_in_bounds, set_current_page, set_number_of_pages, shift_sectioning, tc, update, w; tc = angularTableManager.get_table_configuration($attributes.atTableId); - $scope[irk_current_page] = 0; + w = new ScopeConfigWrapper($scope, tc); generate_page_array = function(start, end) { var x, _i, _results; _results = []; @@ -587,18 +607,27 @@ } return _results; }; + set_current_page = function(current_page) { + return $scope.$parent.$eval("" + tc.current_page + "=" + current_page); + }; + get_number_of_pages = function() { + return $scope[irk_number_of_pages]; + }; + set_number_of_pages = function(number_of_pages) { + return $scope[irk_number_of_pages] = number_of_pages; + }; update = function(reset) { if ($scope[tc.list]) { if ($scope[tc.list].length > 0) { - $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]); - $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages] - 1); + set_number_of_pages(Math.ceil($scope[tc.list].length / w.get_items_per_page())); + set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); if ($scope.show_sectioning()) { return $scope.update_sectioning(); } else { - return $scope.pages = generate_page_array(0, $scope[irk_number_of_pages] - 1); + return $scope.pages = generate_page_array(0, get_number_of_pages() - 1); } } else { - $scope[irk_number_of_pages] = 1; + set_number_of_pages(1); return $scope.pages = [0]; } } @@ -608,7 +637,10 @@ return Math.min(max, val); }; $scope.show_sectioning = function() { - return tc.max_pages && $scope[irk_number_of_pages] > $scope[tc.max_pages]; + return tc.max_pages && get_number_of_pages() > w.get_max_pages(); + }; + $scope.get_current_page = function() { + return w.get_current_page(); }; shift_sectioning = function(current_start, steps, length, upper_bound) { var new_start; @@ -620,35 +652,37 @@ } else { new_start; } - return $scope.pages = generate_page_array(new_start, new_start + parseInt($scope[tc.max_pages]) - 1); + return $scope.pages = generate_page_array(new_start, new_start + parseInt(w.get_max_pages()) - 1); }; $scope.update_sectioning = function() { var diff, new_start; new_start = void 0; - if ($scope.pages[0] > $scope[irk_current_page]) { - diff = $scope.pages[0] - $scope[irk_current_page]; - return shift_sectioning($scope.pages[0], -diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); - } else if ($scope.pages[$scope.pages.length - 1] < $scope[irk_current_page]) { - diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1]; - return shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); - } else if ($scope.pages[$scope.pages.length - 1] > ($scope[irk_number_of_pages] - 1)) { - diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1]; - return shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); + if ($scope.pages[0] > w.get_current_page()) { + diff = $scope.pages[0] - w.get_current_page(); + return shift_sectioning($scope.pages[0], -diff, w.get_max_pages(), get_number_of_pages()); + } else if ($scope.pages[$scope.pages.length - 1] < w.get_current_page()) { + diff = w.get_current_page() - $scope.pages[$scope.pages.length - 1]; + return shift_sectioning($scope.pages[0], diff, w.get_max_pages(), get_number_of_pages()); + } else if ($scope.pages[$scope.pages.length - 1] > (get_number_of_pages() - 1)) { + diff = w.get_current_page() - $scope.pages[$scope.pages.length - 1]; + return shift_sectioning($scope.pages[0], diff, w.get_max_pages(), get_number_of_pages()); + } else { + return $scope.pages = generate_page_array(0, parseInt(w.get_max_pages()) - 1); } }; $scope.step_page = function(step) { step = parseInt(step); - $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page] + step, 0, $scope[irk_number_of_pages] - 1); + set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)); return $scope.update_sectioning(); }; $scope.go_to_page = function(page) { - return $scope[irk_current_page] = page; + return set_current_page(page); }; $scope.jump_back = function() { - return $scope.step_page(-$scope[tc.max_pages]); + return $scope.step_page(-w.get_max_pages()); }; $scope.jump_ahead = function() { - return $scope.step_page($scope[tc.max_pages]); + return $scope.step_page(w.get_max_pages()); }; update(); $scope.$watch(tc.items_per_page, function() { diff --git a/angular-table.min.js b/angular-table.min.js index 50ac008..0b312f4 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,l,p,u,c,g,_,h,f,d,m,b,v,y,x,w={}.hasOwnProperty,$=function(t,e){function i(){this.constructor=t}for(var n in e)w.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[g],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[h]),this.register_fill_last_page(this.attributes[p]),this.register_max_pages(this.attributes[_]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,l,p,u;for(i=[],u=t.find("td"),l=0,p=u.length;p>l;l++)a=u[l],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),n=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),r=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return $(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(n),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return $(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(){},e}(n),a=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new r(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),v="from_page",b="current_page",y="number_of_pages",g="atList",c="atItemsPerPage",p="atFillLastPage",h="atSortContext",_="atMaxPages",l="at-attribute",f="at-sortable",u="at-initial-sorting",s=function(t,e,i){return i?t*e-i.length:void 0},x=function(t,e,i){return t[b]=e[b],t[y]=e[y],t[v]=s(t[i.items_per_page],t[b],t[i.list])},m=function(t,e,i,n,r,a,o){var s,l;return t?(l=t,s=i*e-t.length,"global"===n?(l=o("orderBy")(l,r,a),l=o("limitTo")(l,s),l=o("limitTo")(l,i)):(l=o("limitTo")(l,s),l=o("limitTo")(l,i),l=o("orderBy")(l,r,a)),l):(console.log("RETURNING EMPTY"),[])},d=function(t,e,i,n){var r,a,o,s,l,p,u;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,u=[],o=s=l=t.length,p=t.length+r;p>=l?p>=s:s>=p;o=p>=l?++s:--s)u.push(o);return u}return[]}},t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e,i){var n,r;return this.mappings[t].table_scope=e,n=this.mappings[t].table_configuration,r=function(){return e.sorted_and_paginated_list=m(e[n.list],e[b],e[n.items_per_page],e[n.sort_context],e.predicate,e.descending,i),e.filler_array=d(e[n.list],e[b],e[y],e[n.items_per_page])},e.notify_change=function(t,i){return e[b]=t,e[y]=i,r()},e.$watch(""+n.list+".length",function(){return e[y]=Math.ceil(e[n.list].length/e[n.items_per_page]),r()}),e.$watch("predicate",function(){return r()}),e.$watch("descending",function(){return r()}),n.initial_items_per_page&&(e.$parent[n.items_per_page]=n.initial_items_per_page),n.initial_sort_context&&(e.$parent[n.sort_context]=n.initial_sort_context),n.initial_fill_last_page&&(e.$parent[n.fill_last_page]=n.initial_fill_last_page),n.initial_max_pages?e.$parent[n.max_pages]=n.initial_max_pages:void 0},t.prototype.register_pagination_scope=function(t,e){var i,n;return i=(n=this.mappings)[t]||(n[t]={}),i.pagination_scope=e,i.table_configuration?(e.$watch(b,function(){return i.table_scope.notify_change(e[b],e[y])}),e.$watch(y,function(){return i.table_scope.notify_change(e[b],e[y])})):void 0},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,s;return s=new o(i,n),e.register_table(s),r=new a(i,s),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,n){var r,a,o,s,l;return s=t.get_table_configuration(n.atTableId),e[b]=0,r=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},l=function(){return e[s.list]?e[s.list].length>0?(e[y]=Math.ceil(e[s.list].length/e[s.items_per_page]),e[b]=a(e[b],0,e[y]-1),e.show_sectioning()?e.update_sectioning():e.pages=r(0,e[y]-1)):(e[y]=1,e.pages=[0]):void 0},a=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return s.max_pages&&e[y]>e[s.max_pages]},o=function(t,i,n,a){var o;return o=t+i,e.pages=r(o,o+parseInt(e[s.max_pages])-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>e[b]?(t=e.pages[0]-e[b],o(e.pages[0],-t,e[s.max_pages],e[y])):e.pages[e.pages.length-1]e[y]-1?(t=e[b]-e.pages[e.pages.length-1],o(e.pages[0],t,e[s.max_pages],e[y])):void 0},e.step_page=function(t){return t=parseInt(t),e[b]=a(e[b]+t,0,e[y]-1),e.update_sectioning()},e.go_to_page=function(t){return e[b]=t},e.jump_back=function(){return e.step_page(-e[s.max_pages])},e.jump_ahead=function(){return e.step_page(e[s.max_pages])},l(),e.$watch(s.items_per_page,function(){return l()}),e.$watch(s.max_pages,function(){return l()}),e.$watch(s.list,function(){return l()}),e.$watch(""+s.list+".length",function(){return l()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var t,e,i,n,r,a,s,o,p,u,g,l,c,_,h,f,d,m,b,v,y={}.hasOwnProperty,x=function(t,e){function i(){this.constructor=t}for(var n in e)y.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[_],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[f]),this.register_fill_last_page(this.attributes[g]),this.register_max_pages(this.attributes[h]),this.register_current_page(this.attributes[u]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.register_current_page=function(t){return void 0!==t?isNaN(t)?this.current_page=t:(this.current_page=""+this.id+"_currentPage",this.initial_current_page=parseInt(t)):(this.current_page=""+this.id+"_currentPage",this.initial_current_page=0)},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,s;for(e={},n=t.find("tr"),s=n.find("th"),r=0,a=s.length;a>r;r++)i=s[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,s,o,p,u,g;for(i=[],g=t.find("td"),p=0,u=g.length;u>p;p++)a=g[p],a=angular.element(a),e=a.attr("at-attribute"),s=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),o=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:s,sortable:r,width:o,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),r=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),a=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return x(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(r),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return x(e,t),e.prototype.compile=function(t){var e,i,n,r,a,s,o;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",s=0,o=a.length;o>s;s++)n=a[s],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(t,e,i,r){var a,s,o,p,u;return o=this.table_configuration,u=new n(t,o),s=function(t,e,i,n,r,a,s){var o,p;return t?(p=t,o=i*e-t.length,"global"===n?(p=s("orderBy")(p,r,a),p=s("limitTo")(p,o),p=s("limitTo")(p,i)):(p=s("limitTo")(p,o),p=s("limitTo")(p,i),p=s("orderBy")(p,r,a)),p):[]},a=function(t,e,i,n){var r,a,s,o,p,u,g;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,g=[],s=o=p=t.length,u=t.length+r;u>=p?u>=o:o>=u;s=u>=p?++o:--o)g.push(s);return g}return[]}},p=function(){return t.sorted_and_paginated_list=s(t[o.list],u.get_current_page(),u.get_items_per_page(),t[o.sort_context],t.predicate,t.descending,r),t.filler_array=a(t[o.list],u.get_current_page(),t[v],u.get_items_per_page())},t.$watch(o.current_page,function(){return p()}),t.$watch(o.items_per_page,function(){return p()}),t.$watch(""+o.list+".length",function(){return t[v]=Math.ceil(t[o.list].length/u.get_items_per_page()),p()}),t.$watch("predicate",function(){return p()}),t.$watch("descending",function(){return p()})},e}(r),s=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new a(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),b="from_page",m="current_page",v="number_of_pages",_="atList",c="atItemsPerPage",g="atFillLastPage",f="atSortContext",h="atMaxPages",u="atCurrentPage",p="at-attribute",d="at-sortable",l="at-initial-sorting",n=function(){function t(t,e){this.scope=t,this.config=e}return t.prototype.get_items_per_page=function(){return this.scope.$eval(this.config.items_per_page)},t.prototype.get_current_page=function(){return this.scope.$eval(this.config.current_page)},t.prototype.get_max_pages=function(){return this.scope.$eval(this.config.max_pages)},t}(),t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages&&(e.$parent[i.max_pages]=i.initial_max_pages),void 0!==i.initial_current_page?e.$parent[i.current_page]=i.initial_current_page:void 0},t.prototype.register_pagination_scope=function(){},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,a;return a=new o(i,n),e.register_table(a),r=new s(i,a),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,r){var a,s,o,p,u,g,l,c,_;return l=t.get_table_configuration(r.atTableId),_=new n(e,l),a=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},p=function(t){return e.$parent.$eval(""+l.current_page+"="+t)},s=function(){return e[v]},u=function(t){return e[v]=t},c=function(){return e[l.list]?e[l.list].length>0?(u(Math.ceil(e[l.list].length/_.get_items_per_page())),p(o(_.get_current_page(),0,s()-1)),e.show_sectioning()?e.update_sectioning():e.pages=a(0,s()-1)):(u(1),e.pages=[0]):void 0},o=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return l.max_pages&&s()>_.get_max_pages()},e.get_current_page=function(){return _.get_current_page()},g=function(t,i,n,r){var s;return s=t+i,e.pages=a(s,s+parseInt(_.get_max_pages())-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>_.get_current_page()?(t=e.pages[0]-_.get_current_page(),g(e.pages[0],-t,_.get_max_pages(),s())):e.pages[e.pages.length-1]<_.get_current_page()?(t=_.get_current_page()-e.pages[e.pages.length-1],g(e.pages[0],t,_.get_max_pages(),s())):e.pages[e.pages.length-1]>s()-1?(t=_.get_current_page()-e.pages[e.pages.length-1],g(e.pages[0],t,_.get_max_pages(),s())):e.pages=a(0,parseInt(_.get_max_pages())-1)},e.step_page=function(t){return t=parseInt(t),p(o(_.get_current_page()+t,0,s()-1)),e.update_sectioning()},e.go_to_page=function(t){return p(t)},e.jump_back=function(){return e.step_page(-_.get_max_pages())},e.jump_ahead=function(){return e.step_page(_.get_max_pages())},c(),e.$watch(l.items_per_page,function(){return c()}),e.$watch(l.max_pages,function(){return c()}),e.$watch(l.list,function(){return c()}),e.$watch(""+l.list+".length",function(){return c()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file diff --git a/coffee/at-pagination.coffee b/coffee/at-pagination.coffee index 93665c8..6691492 100644 --- a/coffee/at-pagination.coffee +++ b/coffee/at-pagination.coffee @@ -6,31 +6,31 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" template: "
@@ -46,23 +46,31 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" link: ($scope, $element, $attributes) -> tc = angularTableManager.get_table_configuration($attributes.atTableId) - $scope[irk_current_page] = 0 + w = new ScopeConfigWrapper($scope, tc) generate_page_array = (start, end) -> x for x in [start..end] + set_current_page = (current_page) -> + $scope.$parent.$eval("#{tc.current_page}=#{current_page}") + + get_number_of_pages = () -> + $scope[irk_number_of_pages] + + set_number_of_pages = (number_of_pages) -> + $scope[irk_number_of_pages] = number_of_pages + update = (reset) -> if $scope[tc.list] if $scope[tc.list].length > 0 - $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]) - $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages] - 1) + set_number_of_pages(Math.ceil($scope[tc.list].length / w.get_items_per_page())) + set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)) if $scope.show_sectioning() - # $scope.pages = generate_page_array(0, $scope[tc.max_pages] - 1) $scope.update_sectioning() else - $scope.pages = generate_page_array(0, $scope[irk_number_of_pages] - 1) + $scope.pages = generate_page_array(0, get_number_of_pages() - 1) else - $scope[irk_number_of_pages] = 1 + set_number_of_pages(1) $scope.pages = [0] keep_in_bounds = (val, min, max) -> @@ -70,7 +78,10 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" Math.min(max, val) $scope.show_sectioning = () -> - tc.max_pages && $scope[irk_number_of_pages] > $scope[tc.max_pages] + tc.max_pages && get_number_of_pages() > w.get_max_pages() + + $scope.get_current_page = () -> + w.get_current_page() shift_sectioning = (current_start, steps, length, upper_bound) -> new_start = current_start + steps @@ -80,34 +91,36 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" 0 else new_start - $scope.pages = generate_page_array(new_start, new_start + parseInt($scope[tc.max_pages]) - 1) + $scope.pages = generate_page_array(new_start, new_start + parseInt(w.get_max_pages()) - 1) $scope.update_sectioning = () -> new_start = undefined - if $scope.pages[0] > $scope[irk_current_page] - diff = $scope.pages[0] - $scope[irk_current_page] - shift_sectioning($scope.pages[0], -diff, $scope[tc.max_pages], $scope[irk_number_of_pages]) - else if $scope.pages[$scope.pages.length - 1] < $scope[irk_current_page] - diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1] - shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]) - else if $scope.pages[$scope.pages.length - 1] > ($scope[irk_number_of_pages] - 1) - diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1] - shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]) + if $scope.pages[0] > w.get_current_page() + diff = $scope.pages[0] - w.get_current_page() + shift_sectioning($scope.pages[0], -diff, w.get_max_pages(), get_number_of_pages()) + else if $scope.pages[$scope.pages.length - 1] < w.get_current_page() + diff = w.get_current_page() - $scope.pages[$scope.pages.length - 1] + shift_sectioning($scope.pages[0], diff, w.get_max_pages(), get_number_of_pages()) + else if $scope.pages[$scope.pages.length - 1] > (get_number_of_pages() - 1) + diff = w.get_current_page() - $scope.pages[$scope.pages.length - 1] + shift_sectioning($scope.pages[0], diff, w.get_max_pages(), get_number_of_pages()) + else + $scope.pages = generate_page_array(0, parseInt(w.get_max_pages()) - 1) $scope.step_page = (step) -> step = parseInt(step) - $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page] + step, 0, $scope[irk_number_of_pages] - 1) + set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)) $scope.update_sectioning() $scope.go_to_page = (page) -> - $scope[irk_current_page] = page + set_current_page(page) $scope.jump_back = () -> - $scope.step_page(-$scope[tc.max_pages]) + $scope.step_page(-w.get_max_pages()) $scope.jump_ahead = () -> - $scope.step_page($scope[tc.max_pages]) + $scope.step_page(w.get_max_pages()) update() diff --git a/coffee/at-table.coffee b/coffee/at-table.coffee index 3ad99f9..8d579b3 100644 --- a/coffee/at-table.coffee +++ b/coffee/at-table.coffee @@ -12,51 +12,26 @@ erk_items_per_page = "atItemsPerPage" erk_fill_last_page = "atFillLastPage" erk_sort_context = "atSortContext" erk_max_pages = "atMaxPages" +erk_current_page = "atCurrentPage" # column erk_attribute = "at-attribute" erk_sortable = "at-sortable" erk_initial_sorting = "at-initial-sorting" -calculate_from_page = (items_per_page, current_page, list) -> - if list - items_per_page * current_page - list.length - -update_table_scope = (table_scope, pagination_scope, table_configuration) -> - table_scope[irk_current_page] = pagination_scope[irk_current_page] - table_scope[irk_number_of_pages] = pagination_scope[irk_number_of_pages] - table_scope[irk_from_page] = calculate_from_page(table_scope[table_configuration.items_per_page], - table_scope[irk_current_page], - table_scope[table_configuration.list]) - -get_sorted_and_paginated_list = (list, current_page, items_per_page, sort_context, predicate, descending, $filter) -> - if list - val = list - - from_page = items_per_page * current_page - list.length - - # if $scope[sc] == "global" - if sort_context == "global" - val = $filter("orderBy")(val, predicate, descending) - val = $filter("limitTo")(val, from_page) - val = $filter("limitTo")(val, items_per_page) - else - val = $filter("limitTo")(val, from_page) - val = $filter("limitTo")(val, items_per_page) - val = $filter("orderBy")(val, predicate, descending) - - return val - else - console.log "RETURNING EMPTY" - return [] - -get_filler_array = (list, current_page, number_of_pages, items_per_page) -> - if current_page == number_of_pages - 1 - itemCountOnLastPage = list.length % items_per_page - if itemCountOnLastPage != 0 || list.length == 0 - fillerLength = items_per_page - itemCountOnLastPage - 1 - x for x in [(list.length)..(list.length + fillerLength)] - else - [] +class ScopeConfigWrapper + + constructor: (table_scope, table_configuration) -> + @scope = table_scope + @config = table_configuration + + get_items_per_page: () -> + @scope.$eval(@config.items_per_page) + + get_current_page: () -> + @scope.$eval(@config.current_page) + + get_max_pages: () -> + @scope.$eval(@config.max_pages) class AngularTableManager @@ -79,44 +54,6 @@ class AngularTableManager tc = @mappings[id].table_configuration - update_stuff = () -> - scope.sorted_and_paginated_list = get_sorted_and_paginated_list( - scope[tc.list], - scope[irk_current_page], - scope[tc.items_per_page], - scope[tc.sort_context] - scope.predicate, - scope.descending, - filter - ) - - scope.filler_array = get_filler_array( - scope[tc.list], - scope[irk_current_page], - scope[irk_number_of_pages], - scope[tc.items_per_page] - ) - - scope.notify_change = (current_page, number_of_pages) -> - scope[irk_current_page] = current_page - scope[irk_number_of_pages] = number_of_pages - update_stuff() - - scope.$watch("#{tc.list}.length", () -> - scope[irk_number_of_pages] = Math.ceil(scope[tc.list].length / scope[tc.items_per_page]) - update_stuff() - ) - - scope.$watch("predicate", () -> - update_stuff() - ) - - scope.$watch("descending", () -> - update_stuff() - ) - - # tc = @mappings[id].table_configuration - if tc.initial_items_per_page scope.$parent[tc.items_per_page] = tc.initial_items_per_page @@ -129,21 +66,21 @@ class AngularTableManager if tc.initial_max_pages scope.$parent[tc.max_pages] = tc.initial_max_pages + if tc.initial_current_page isnt undefined + scope.$parent[tc.current_page] = tc.initial_current_page register_pagination_scope: (id, pagination_scope) -> - mapping = @mappings[id] ||= {} - mapping.pagination_scope = pagination_scope - - if mapping.table_configuration - pagination_scope.$watch(irk_current_page, () -> - # update_table_scope(mapping.table_scope, pagination_scope, mapping.table_configuration) - mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]) - ) - - pagination_scope.$watch(irk_number_of_pages, () -> - mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]) - # update_table_scope(mapping.table_scope, pagination_scope, mapping.table_configuration) - ) + # mapping = @mappings[id] ||= {} + # mapping.pagination_scope = pagination_scope + + # if mapping.table_configuration + # pagination_scope.$watch(irk_current_page, () -> + # mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]) + # ) + + # pagination_scope.$watch(irk_number_of_pages, () -> + # mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]) + # ) angular.module("angular-table").service "angularTableManager", [() -> new AngularTableManager() diff --git a/coffee/configuration/table_configuration.coffee b/coffee/configuration/table_configuration.coffee index b13f78b..cb1590e 100644 --- a/coffee/configuration/table_configuration.coffee +++ b/coffee/configuration/table_configuration.coffee @@ -7,6 +7,7 @@ class TableConfiguration @register_sort_context(@attributes[erk_sort_context]) @register_fill_last_page(@attributes[erk_fill_last_page]) @register_max_pages(@attributes[erk_max_pages]) + @register_current_page(@attributes[erk_current_page]) @paginated = @items_per_page != undefined @create_column_configurations() @@ -54,6 +55,17 @@ class TableConfiguration @max_pages = "#{@id}_maxPages" @initial_max_pages = parseInt(max_pages) + register_current_page: (current_page) -> + if current_page isnt undefined + if isNaN(current_page) + @current_page = current_page + else + @current_page = "#{@id}_currentPage" + @initial_current_page = parseInt(current_page) + else + @current_page = "#{@id}_currentPage" + @initial_current_page = 0 + capitaliseFirstLetter: (string) -> if string then string.charAt(0).toUpperCase() + string.slice(1) else "" diff --git a/coffee/table/setup/paginated_setup.coffee b/coffee/table/setup/paginated_setup.coffee index 5536905..673599e 100644 --- a/coffee/table/setup/paginated_setup.coffee +++ b/coffee/table/setup/paginated_setup.coffee @@ -23,35 +23,72 @@ class PaginatedSetup extends Setup return link: ($scope, $element, $attributes, $filter) -> - # list_name = @table_configuration.list - # ipp = @table_configuration.items_per_page - # sc = @table_configuration.sort_context - # tc = @table_configuration - - # $scope.filtered_list = () -> - # val = $scope[list_name] - - # from_page = calculate_from_page($scope[tc.items_per_page], - # $scope[irk_current_page], - # $scope[tc.list]) - - # if $scope[sc] == "global" - # val = $filter("orderBy")(val, $scope.predicate, $scope.descending) - # val = $filter("limitTo")(val, from_page) - # val = $filter("limitTo")(val, $scope[ipp]) - # else - # val = $filter("limitTo")(val, from_page) - # val = $filter("limitTo")(val, $scope[ipp]) - # val = $filter("orderBy")(val, $scope.predicate, $scope.descending) - - - # return val - - # $scope.getFillerArray = () -> - # if $scope[irk_current_page] == $scope[irk_number_of_pages] - 1 - # itemCountOnLastPage = $scope[list_name].length % $scope[ipp] - # if itemCountOnLastPage != 0 || $scope[list_name].length == 0 - # fillerLength = $scope[ipp] - itemCountOnLastPage - 1 - # x for x in [($scope[list_name].length)..($scope[list_name].length + fillerLength)] - # else - # [] \ No newline at end of file + tc = @table_configuration + + w = new ScopeConfigWrapper($scope, tc) + + get_sorted_and_paginated_list = (list, current_page, items_per_page, sort_context, predicate, descending, $filter) -> + if list + val = list + from_page = items_per_page * current_page - list.length + if sort_context == "global" + val = $filter("orderBy")(val, predicate, descending) + val = $filter("limitTo")(val, from_page) + val = $filter("limitTo")(val, items_per_page) + else + val = $filter("limitTo")(val, from_page) + val = $filter("limitTo")(val, items_per_page) + val = $filter("orderBy")(val, predicate, descending) + + return val + else + return [] + + get_filler_array = (list, current_page, number_of_pages, items_per_page) -> + if current_page == number_of_pages - 1 + itemCountOnLastPage = list.length % items_per_page + if itemCountOnLastPage != 0 || list.length == 0 + fillerLength = items_per_page - itemCountOnLastPage - 1 + x for x in [(list.length)..(list.length + fillerLength)] + else + [] + + update_stuff = () -> + $scope.sorted_and_paginated_list = get_sorted_and_paginated_list( + $scope[tc.list], + w.get_current_page(), + w.get_items_per_page(), + $scope[tc.sort_context], + $scope.predicate, + $scope.descending, + $filter + ) + + $scope.filler_array = get_filler_array( + $scope[tc.list], + w.get_current_page(), + $scope[irk_number_of_pages], + w.get_items_per_page() + ) + + $scope.$watch(tc.current_page, () -> + update_stuff() + ) + + $scope.$watch(tc.items_per_page, () -> + update_stuff() + ) + + $scope.$watch("#{tc.list}.length", () -> + $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / w.get_items_per_page()) + update_stuff() + ) + + $scope.$watch("predicate", () -> + update_stuff() + ) + + $scope.$watch("descending", () -> + update_stuff() + ) + diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 159fcea..1772109 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -3,7 +3,7 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var AngularTableManager, ColumnConfiguration, PaginatedSetup, Setup, StandardSetup, Table, TableConfiguration, calculate_from_page, erk_attribute, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, get_filler_array, get_sorted_and_paginated_list, irk_current_page, irk_from_page, irk_number_of_pages, update_table_scope, + var AngularTableManager, ColumnConfiguration, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, erk_attribute, erk_current_page, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -83,6 +83,7 @@ this.register_sort_context(this.attributes[erk_sort_context]); this.register_fill_last_page(this.attributes[erk_fill_last_page]); this.register_max_pages(this.attributes[erk_max_pages]); + this.register_current_page(this.attributes[erk_current_page]); this.paginated = this.items_per_page !== void 0; this.create_column_configurations(); } @@ -141,6 +142,20 @@ } }; + TableConfiguration.prototype.register_current_page = function(current_page) { + if (current_page !== void 0) { + if (isNaN(current_page)) { + return this.current_page = current_page; + } else { + this.current_page = "" + this.id + "_currentPage"; + return this.initial_current_page = parseInt(current_page); + } + } else { + this.current_page = "" + this.id + "_currentPage"; + return this.initial_current_page = 0; + } + }; + TableConfiguration.prototype.capitaliseFirstLetter = function(string) { if (string) { return string.charAt(0).toUpperCase() + string.slice(1); @@ -292,7 +307,66 @@ tbody.append(fillerTr); }; - PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) {}; + PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) { + var get_filler_array, get_sorted_and_paginated_list, tc, update_stuff, w; + tc = this.table_configuration; + w = new ScopeConfigWrapper($scope, tc); + get_sorted_and_paginated_list = function(list, current_page, items_per_page, sort_context, predicate, descending, $filter) { + var from_page, val; + if (list) { + val = list; + from_page = items_per_page * current_page - list.length; + if (sort_context === "global") { + val = $filter("orderBy")(val, predicate, descending); + val = $filter("limitTo")(val, from_page); + val = $filter("limitTo")(val, items_per_page); + } else { + val = $filter("limitTo")(val, from_page); + val = $filter("limitTo")(val, items_per_page); + val = $filter("orderBy")(val, predicate, descending); + } + return val; + } else { + return []; + } + }; + get_filler_array = function(list, current_page, number_of_pages, items_per_page) { + var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; + if (current_page === number_of_pages - 1) { + itemCountOnLastPage = list.length % items_per_page; + if (itemCountOnLastPage !== 0 || list.length === 0) { + fillerLength = items_per_page - itemCountOnLastPage - 1; + _results = []; + for (x = _i = _ref = list.length, _ref1 = list.length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { + _results.push(x); + } + return _results; + } else { + return []; + } + } + }; + update_stuff = function() { + $scope.sorted_and_paginated_list = get_sorted_and_paginated_list($scope[tc.list], w.get_current_page(), w.get_items_per_page(), $scope[tc.sort_context], $scope.predicate, $scope.descending, $filter); + return $scope.filler_array = get_filler_array($scope[tc.list], w.get_current_page(), $scope[irk_number_of_pages], w.get_items_per_page()); + }; + $scope.$watch(tc.current_page, function() { + return update_stuff(); + }); + $scope.$watch(tc.items_per_page, function() { + return update_stuff(); + }); + $scope.$watch("" + tc.list + ".length", function() { + $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / w.get_items_per_page()); + return update_stuff(); + }); + $scope.$watch("predicate", function() { + return update_stuff(); + }); + return $scope.$watch("descending", function() { + return update_stuff(); + }); + }; return PaginatedSetup; @@ -398,61 +472,35 @@ erk_max_pages = "atMaxPages"; + erk_current_page = "atCurrentPage"; + erk_attribute = "at-attribute"; erk_sortable = "at-sortable"; erk_initial_sorting = "at-initial-sorting"; - calculate_from_page = function(items_per_page, current_page, list) { - if (list) { - return items_per_page * current_page - list.length; - } - }; - - update_table_scope = function(table_scope, pagination_scope, table_configuration) { - table_scope[irk_current_page] = pagination_scope[irk_current_page]; - table_scope[irk_number_of_pages] = pagination_scope[irk_number_of_pages]; - return table_scope[irk_from_page] = calculate_from_page(table_scope[table_configuration.items_per_page], table_scope[irk_current_page], table_scope[table_configuration.list]); - }; - - get_sorted_and_paginated_list = function(list, current_page, items_per_page, sort_context, predicate, descending, $filter) { - var from_page, val; - if (list) { - val = list; - from_page = items_per_page * current_page - list.length; - if (sort_context === "global") { - val = $filter("orderBy")(val, predicate, descending); - val = $filter("limitTo")(val, from_page); - val = $filter("limitTo")(val, items_per_page); - } else { - val = $filter("limitTo")(val, from_page); - val = $filter("limitTo")(val, items_per_page); - val = $filter("orderBy")(val, predicate, descending); - } - return val; - } else { - console.log("RETURNING EMPTY"); - return []; + ScopeConfigWrapper = (function() { + function ScopeConfigWrapper(table_scope, table_configuration) { + this.scope = table_scope; + this.config = table_configuration; } - }; - - get_filler_array = function(list, current_page, number_of_pages, items_per_page) { - var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; - if (current_page === number_of_pages - 1) { - itemCountOnLastPage = list.length % items_per_page; - if (itemCountOnLastPage !== 0 || list.length === 0) { - fillerLength = items_per_page - itemCountOnLastPage - 1; - _results = []; - for (x = _i = _ref = list.length, _ref1 = list.length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { - _results.push(x); - } - return _results; - } else { - return []; - } - } - }; + + ScopeConfigWrapper.prototype.get_items_per_page = function() { + return this.scope.$eval(this.config.items_per_page); + }; + + ScopeConfigWrapper.prototype.get_current_page = function() { + return this.scope.$eval(this.config.current_page); + }; + + ScopeConfigWrapper.prototype.get_max_pages = function() { + return this.scope.$eval(this.config.max_pages); + }; + + return ScopeConfigWrapper; + + })(); AngularTableManager = (function() { function AngularTableManager() { @@ -473,28 +521,9 @@ }; AngularTableManager.prototype.register_table_scope = function(id, scope, filter) { - var tc, update_stuff; + var tc; this.mappings[id].table_scope = scope; tc = this.mappings[id].table_configuration; - update_stuff = function() { - scope.sorted_and_paginated_list = get_sorted_and_paginated_list(scope[tc.list], scope[irk_current_page], scope[tc.items_per_page], scope[tc.sort_context], scope.predicate, scope.descending, filter); - return scope.filler_array = get_filler_array(scope[tc.list], scope[irk_current_page], scope[irk_number_of_pages], scope[tc.items_per_page]); - }; - scope.notify_change = function(current_page, number_of_pages) { - scope[irk_current_page] = current_page; - scope[irk_number_of_pages] = number_of_pages; - return update_stuff(); - }; - scope.$watch("" + tc.list + ".length", function() { - scope[irk_number_of_pages] = Math.ceil(scope[tc.list].length / scope[tc.items_per_page]); - return update_stuff(); - }); - scope.$watch("predicate", function() { - return update_stuff(); - }); - scope.$watch("descending", function() { - return update_stuff(); - }); if (tc.initial_items_per_page) { scope.$parent[tc.items_per_page] = tc.initial_items_per_page; } @@ -505,24 +534,15 @@ scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page; } if (tc.initial_max_pages) { - return scope.$parent[tc.max_pages] = tc.initial_max_pages; + scope.$parent[tc.max_pages] = tc.initial_max_pages; } - }; - - AngularTableManager.prototype.register_pagination_scope = function(id, pagination_scope) { - var mapping, _base; - mapping = (_base = this.mappings)[id] || (_base[id] = {}); - mapping.pagination_scope = pagination_scope; - if (mapping.table_configuration) { - pagination_scope.$watch(irk_current_page, function() { - return mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]); - }); - return pagination_scope.$watch(irk_number_of_pages, function() { - return mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]); - }); + if (tc.initial_current_page !== void 0) { + return scope.$parent[tc.current_page] = tc.initial_current_page; } }; + AngularTableManager.prototype.register_pagination_scope = function(id, pagination_scope) {}; + return AngularTableManager; })(); @@ -568,7 +588,7 @@ return { replace: true, restrict: "E", - template: "", + template: "", controller: [ "$scope", "$element", "$attrs", function($scope, $element, $attrs) { return angularTableManager.register_pagination_scope($attrs.atTableId, $scope); @@ -576,9 +596,9 @@ ], scope: true, link: function($scope, $element, $attributes) { - var generate_page_array, keep_in_bounds, shift_sectioning, tc, update; + var generate_page_array, get_number_of_pages, keep_in_bounds, set_current_page, set_number_of_pages, shift_sectioning, tc, update, w; tc = angularTableManager.get_table_configuration($attributes.atTableId); - $scope[irk_current_page] = 0; + w = new ScopeConfigWrapper($scope, tc); generate_page_array = function(start, end) { var x, _i, _results; _results = []; @@ -587,18 +607,27 @@ } return _results; }; + set_current_page = function(current_page) { + return $scope.$parent.$eval("" + tc.current_page + "=" + current_page); + }; + get_number_of_pages = function() { + return $scope[irk_number_of_pages]; + }; + set_number_of_pages = function(number_of_pages) { + return $scope[irk_number_of_pages] = number_of_pages; + }; update = function(reset) { if ($scope[tc.list]) { if ($scope[tc.list].length > 0) { - $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / $scope[tc.items_per_page]); - $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page], 0, $scope[irk_number_of_pages] - 1); + set_number_of_pages(Math.ceil($scope[tc.list].length / w.get_items_per_page())); + set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); if ($scope.show_sectioning()) { return $scope.update_sectioning(); } else { - return $scope.pages = generate_page_array(0, $scope[irk_number_of_pages] - 1); + return $scope.pages = generate_page_array(0, get_number_of_pages() - 1); } } else { - $scope[irk_number_of_pages] = 1; + set_number_of_pages(1); return $scope.pages = [0]; } } @@ -608,7 +637,10 @@ return Math.min(max, val); }; $scope.show_sectioning = function() { - return tc.max_pages && $scope[irk_number_of_pages] > $scope[tc.max_pages]; + return tc.max_pages && get_number_of_pages() > w.get_max_pages(); + }; + $scope.get_current_page = function() { + return w.get_current_page(); }; shift_sectioning = function(current_start, steps, length, upper_bound) { var new_start; @@ -620,35 +652,37 @@ } else { new_start; } - return $scope.pages = generate_page_array(new_start, new_start + parseInt($scope[tc.max_pages]) - 1); + return $scope.pages = generate_page_array(new_start, new_start + parseInt(w.get_max_pages()) - 1); }; $scope.update_sectioning = function() { var diff, new_start; new_start = void 0; - if ($scope.pages[0] > $scope[irk_current_page]) { - diff = $scope.pages[0] - $scope[irk_current_page]; - return shift_sectioning($scope.pages[0], -diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); - } else if ($scope.pages[$scope.pages.length - 1] < $scope[irk_current_page]) { - diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1]; - return shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); - } else if ($scope.pages[$scope.pages.length - 1] > ($scope[irk_number_of_pages] - 1)) { - diff = $scope[irk_current_page] - $scope.pages[$scope.pages.length - 1]; - return shift_sectioning($scope.pages[0], diff, $scope[tc.max_pages], $scope[irk_number_of_pages]); + if ($scope.pages[0] > w.get_current_page()) { + diff = $scope.pages[0] - w.get_current_page(); + return shift_sectioning($scope.pages[0], -diff, w.get_max_pages(), get_number_of_pages()); + } else if ($scope.pages[$scope.pages.length - 1] < w.get_current_page()) { + diff = w.get_current_page() - $scope.pages[$scope.pages.length - 1]; + return shift_sectioning($scope.pages[0], diff, w.get_max_pages(), get_number_of_pages()); + } else if ($scope.pages[$scope.pages.length - 1] > (get_number_of_pages() - 1)) { + diff = w.get_current_page() - $scope.pages[$scope.pages.length - 1]; + return shift_sectioning($scope.pages[0], diff, w.get_max_pages(), get_number_of_pages()); + } else { + return $scope.pages = generate_page_array(0, parseInt(w.get_max_pages()) - 1); } }; $scope.step_page = function(step) { step = parseInt(step); - $scope[irk_current_page] = keep_in_bounds($scope[irk_current_page] + step, 0, $scope[irk_number_of_pages] - 1); + set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)); return $scope.update_sectioning(); }; $scope.go_to_page = function(page) { - return $scope[irk_current_page] = page; + return set_current_page(page); }; $scope.jump_back = function() { - return $scope.step_page(-$scope[tc.max_pages]); + return $scope.step_page(-w.get_max_pages()); }; $scope.jump_ahead = function() { - return $scope.step_page($scope[tc.max_pages]); + return $scope.step_page(w.get_max_pages()); }; update(); $scope.$watch(tc.items_per_page, function() { diff --git a/test/templates/pagination/pagination.html b/test/templates/pagination/pagination.html index 9a3a262..ad4217a 100644 --- a/test/templates/pagination/pagination.html +++ b/test/templates/pagination/pagination.html @@ -1,4 +1,6 @@ -
                
+
+
+
From 744a7b7ce45905046826a5d5c8515c7c0637c315 Mon Sep 17 00:00:00 2001 From: ssmm Date: Wed, 19 Feb 2014 14:20:24 +0100 Subject: [PATCH 086/190] get list from wrapper --- angular-table.js | 12 ++++++++++-- angular-table.min.js | 2 +- coffee/at-table.coffee | 6 ++++++ coffee/table/setup/paginated_setup.coffee | 4 ++-- gem/app/assets/javascripts/angular-table.js | 12 ++++++++++-- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/angular-table.js b/angular-table.js index 1772109..3b85844 100644 --- a/angular-table.js +++ b/angular-table.js @@ -347,8 +347,8 @@ } }; update_stuff = function() { - $scope.sorted_and_paginated_list = get_sorted_and_paginated_list($scope[tc.list], w.get_current_page(), w.get_items_per_page(), $scope[tc.sort_context], $scope.predicate, $scope.descending, $filter); - return $scope.filler_array = get_filler_array($scope[tc.list], w.get_current_page(), $scope[irk_number_of_pages], w.get_items_per_page()); + $scope.sorted_and_paginated_list = get_sorted_and_paginated_list(w.get_list(), w.get_current_page(), w.get_items_per_page(), $scope[tc.sort_context], $scope.predicate, $scope.descending, $filter); + return $scope.filler_array = get_filler_array(w.get_list(), w.get_current_page(), $scope[irk_number_of_pages], w.get_items_per_page()); }; $scope.$watch(tc.current_page, function() { return update_stuff(); @@ -486,6 +486,10 @@ this.config = table_configuration; } + ScopeConfigWrapper.prototype.get_list = function() { + return this.scope.$eval(this.config.list); + }; + ScopeConfigWrapper.prototype.get_items_per_page = function() { return this.scope.$eval(this.config.items_per_page); }; @@ -498,6 +502,10 @@ return this.scope.$eval(this.config.max_pages); }; + ScopeConfigWrapper.prototype.get_sort_context = function() { + return this.scope.$eval(this.config.sort_context); + }; + return ScopeConfigWrapper; })(); diff --git a/angular-table.min.js b/angular-table.min.js index 0b312f4..fcb0c23 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,s,o,p,u,g,l,c,_,h,f,d,m,b,v,y={}.hasOwnProperty,x=function(t,e){function i(){this.constructor=t}for(var n in e)y.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),o=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[_],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[f]),this.register_fill_last_page(this.attributes[g]),this.register_max_pages(this.attributes[h]),this.register_current_page(this.attributes[u]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.register_current_page=function(t){return void 0!==t?isNaN(t)?this.current_page=t:(this.current_page=""+this.id+"_currentPage",this.initial_current_page=parseInt(t)):(this.current_page=""+this.id+"_currentPage",this.initial_current_page=0)},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,s;for(e={},n=t.find("tr"),s=n.find("th"),r=0,a=s.length;a>r;r++)i=s[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,s,o,p,u,g;for(i=[],g=t.find("td"),p=0,u=g.length;u>p;p++)a=g[p],a=angular.element(a),e=a.attr("at-attribute"),s=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),o=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:s,sortable:r,width:o,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),r=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),a=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return x(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(r),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return x(e,t),e.prototype.compile=function(t){var e,i,n,r,a,s,o;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",s=0,o=a.length;o>s;s++)n=a[s],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(t,e,i,r){var a,s,o,p,u;return o=this.table_configuration,u=new n(t,o),s=function(t,e,i,n,r,a,s){var o,p;return t?(p=t,o=i*e-t.length,"global"===n?(p=s("orderBy")(p,r,a),p=s("limitTo")(p,o),p=s("limitTo")(p,i)):(p=s("limitTo")(p,o),p=s("limitTo")(p,i),p=s("orderBy")(p,r,a)),p):[]},a=function(t,e,i,n){var r,a,s,o,p,u,g;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,g=[],s=o=p=t.length,u=t.length+r;u>=p?u>=o:o>=u;s=u>=p?++o:--o)g.push(s);return g}return[]}},p=function(){return t.sorted_and_paginated_list=s(t[o.list],u.get_current_page(),u.get_items_per_page(),t[o.sort_context],t.predicate,t.descending,r),t.filler_array=a(t[o.list],u.get_current_page(),t[v],u.get_items_per_page())},t.$watch(o.current_page,function(){return p()}),t.$watch(o.items_per_page,function(){return p()}),t.$watch(""+o.list+".length",function(){return t[v]=Math.ceil(t[o.list].length/u.get_items_per_page()),p()}),t.$watch("predicate",function(){return p()}),t.$watch("descending",function(){return p()})},e}(r),s=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new a(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),b="from_page",m="current_page",v="number_of_pages",_="atList",c="atItemsPerPage",g="atFillLastPage",f="atSortContext",h="atMaxPages",u="atCurrentPage",p="at-attribute",d="at-sortable",l="at-initial-sorting",n=function(){function t(t,e){this.scope=t,this.config=e}return t.prototype.get_items_per_page=function(){return this.scope.$eval(this.config.items_per_page)},t.prototype.get_current_page=function(){return this.scope.$eval(this.config.current_page)},t.prototype.get_max_pages=function(){return this.scope.$eval(this.config.max_pages)},t}(),t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages&&(e.$parent[i.max_pages]=i.initial_max_pages),void 0!==i.initial_current_page?e.$parent[i.current_page]=i.initial_current_page:void 0},t.prototype.register_pagination_scope=function(){},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,a;return a=new o(i,n),e.register_table(a),r=new s(i,a),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,r){var a,s,o,p,u,g,l,c,_;return l=t.get_table_configuration(r.atTableId),_=new n(e,l),a=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},p=function(t){return e.$parent.$eval(""+l.current_page+"="+t)},s=function(){return e[v]},u=function(t){return e[v]=t},c=function(){return e[l.list]?e[l.list].length>0?(u(Math.ceil(e[l.list].length/_.get_items_per_page())),p(o(_.get_current_page(),0,s()-1)),e.show_sectioning()?e.update_sectioning():e.pages=a(0,s()-1)):(u(1),e.pages=[0]):void 0},o=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return l.max_pages&&s()>_.get_max_pages()},e.get_current_page=function(){return _.get_current_page()},g=function(t,i,n,r){var s;return s=t+i,e.pages=a(s,s+parseInt(_.get_max_pages())-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>_.get_current_page()?(t=e.pages[0]-_.get_current_page(),g(e.pages[0],-t,_.get_max_pages(),s())):e.pages[e.pages.length-1]<_.get_current_page()?(t=_.get_current_page()-e.pages[e.pages.length-1],g(e.pages[0],t,_.get_max_pages(),s())):e.pages[e.pages.length-1]>s()-1?(t=_.get_current_page()-e.pages[e.pages.length-1],g(e.pages[0],t,_.get_max_pages(),s())):e.pages=a(0,parseInt(_.get_max_pages())-1)},e.step_page=function(t){return t=parseInt(t),p(o(_.get_current_page()+t,0,s()-1)),e.update_sectioning()},e.go_to_page=function(t){return p(t)},e.jump_back=function(){return e.step_page(-_.get_max_pages())},e.jump_ahead=function(){return e.step_page(_.get_max_pages())},c(),e.$watch(l.items_per_page,function(){return c()}),e.$watch(l.max_pages,function(){return c()}),e.$watch(l.list,function(){return c()}),e.$watch(""+l.list+".length",function(){return c()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var t,e,i,n,r,a,o,s,p,u,g,l,c,_,h,f,d,m,b,v,y={}.hasOwnProperty,x=function(t,e){function i(){this.constructor=t}for(var n in e)y.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),s=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[_],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[f]),this.register_fill_last_page(this.attributes[g]),this.register_max_pages(this.attributes[h]),this.register_current_page(this.attributes[u]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.register_current_page=function(t){return void 0!==t?isNaN(t)?this.current_page=t:(this.current_page=""+this.id+"_currentPage",this.initial_current_page=parseInt(t)):(this.current_page=""+this.id+"_currentPage",this.initial_current_page=0)},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,p,u,g;for(i=[],g=t.find("td"),p=0,u=g.length;u>p;p++)a=g[p],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),r=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),a=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return x(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(r),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return x(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(t,e,i,r){var a,o,s,p,u;return s=this.table_configuration,u=new n(t,s),o=function(t,e,i,n,r,a,o){var s,p;return t?(p=t,s=i*e-t.length,"global"===n?(p=o("orderBy")(p,r,a),p=o("limitTo")(p,s),p=o("limitTo")(p,i)):(p=o("limitTo")(p,s),p=o("limitTo")(p,i),p=o("orderBy")(p,r,a)),p):[]},a=function(t,e,i,n){var r,a,o,s,p,u,g;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,g=[],o=s=p=t.length,u=t.length+r;u>=p?u>=s:s>=u;o=u>=p?++s:--s)g.push(o);return g}return[]}},p=function(){return t.sorted_and_paginated_list=o(u.get_list(),u.get_current_page(),u.get_items_per_page(),t[s.sort_context],t.predicate,t.descending,r),t.filler_array=a(u.get_list(),u.get_current_page(),t[v],u.get_items_per_page())},t.$watch(s.current_page,function(){return p()}),t.$watch(s.items_per_page,function(){return p()}),t.$watch(""+s.list+".length",function(){return t[v]=Math.ceil(t[s.list].length/u.get_items_per_page()),p()}),t.$watch("predicate",function(){return p()}),t.$watch("descending",function(){return p()})},e}(r),o=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new a(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),b="from_page",m="current_page",v="number_of_pages",_="atList",c="atItemsPerPage",g="atFillLastPage",f="atSortContext",h="atMaxPages",u="atCurrentPage",p="at-attribute",d="at-sortable",l="at-initial-sorting",n=function(){function t(t,e){this.scope=t,this.config=e}return t.prototype.get_list=function(){return this.scope.$eval(this.config.list)},t.prototype.get_items_per_page=function(){return this.scope.$eval(this.config.items_per_page)},t.prototype.get_current_page=function(){return this.scope.$eval(this.config.current_page)},t.prototype.get_max_pages=function(){return this.scope.$eval(this.config.max_pages)},t.prototype.get_sort_context=function(){return this.scope.$eval(this.config.sort_context)},t}(),t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages&&(e.$parent[i.max_pages]=i.initial_max_pages),void 0!==i.initial_current_page?e.$parent[i.current_page]=i.initial_current_page:void 0},t.prototype.register_pagination_scope=function(){},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,a;return a=new s(i,n),e.register_table(a),r=new o(i,a),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,r){var a,o,s,p,u,g,l,c,_;return l=t.get_table_configuration(r.atTableId),_=new n(e,l),a=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},p=function(t){return e.$parent.$eval(""+l.current_page+"="+t)},o=function(){return e[v]},u=function(t){return e[v]=t},c=function(){return e[l.list]?e[l.list].length>0?(u(Math.ceil(e[l.list].length/_.get_items_per_page())),p(s(_.get_current_page(),0,o()-1)),e.show_sectioning()?e.update_sectioning():e.pages=a(0,o()-1)):(u(1),e.pages=[0]):void 0},s=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return l.max_pages&&o()>_.get_max_pages()},e.get_current_page=function(){return _.get_current_page()},g=function(t,i,n,r){var o;return o=t+i,e.pages=a(o,o+parseInt(_.get_max_pages())-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>_.get_current_page()?(t=e.pages[0]-_.get_current_page(),g(e.pages[0],-t,_.get_max_pages(),o())):e.pages[e.pages.length-1]<_.get_current_page()?(t=_.get_current_page()-e.pages[e.pages.length-1],g(e.pages[0],t,_.get_max_pages(),o())):e.pages[e.pages.length-1]>o()-1?(t=_.get_current_page()-e.pages[e.pages.length-1],g(e.pages[0],t,_.get_max_pages(),o())):e.pages=a(0,parseInt(_.get_max_pages())-1)},e.step_page=function(t){return t=parseInt(t),p(s(_.get_current_page()+t,0,o()-1)),e.update_sectioning()},e.go_to_page=function(t){return p(t)},e.jump_back=function(){return e.step_page(-_.get_max_pages())},e.jump_ahead=function(){return e.step_page(_.get_max_pages())},c(),e.$watch(l.items_per_page,function(){return c()}),e.$watch(l.max_pages,function(){return c()}),e.$watch(l.list,function(){return c()}),e.$watch(""+l.list+".length",function(){return c()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file diff --git a/coffee/at-table.coffee b/coffee/at-table.coffee index 8d579b3..36503f7 100644 --- a/coffee/at-table.coffee +++ b/coffee/at-table.coffee @@ -24,6 +24,9 @@ class ScopeConfigWrapper @scope = table_scope @config = table_configuration + get_list: () -> + @scope.$eval(@config.list) + get_items_per_page: () -> @scope.$eval(@config.items_per_page) @@ -33,6 +36,9 @@ class ScopeConfigWrapper get_max_pages: () -> @scope.$eval(@config.max_pages) + get_sort_context: () -> + @scope.$eval(@config.sort_context) + class AngularTableManager constructor: () -> diff --git a/coffee/table/setup/paginated_setup.coffee b/coffee/table/setup/paginated_setup.coffee index 673599e..9d0649a 100644 --- a/coffee/table/setup/paginated_setup.coffee +++ b/coffee/table/setup/paginated_setup.coffee @@ -55,7 +55,7 @@ class PaginatedSetup extends Setup update_stuff = () -> $scope.sorted_and_paginated_list = get_sorted_and_paginated_list( - $scope[tc.list], + w.get_list(), w.get_current_page(), w.get_items_per_page(), $scope[tc.sort_context], @@ -65,7 +65,7 @@ class PaginatedSetup extends Setup ) $scope.filler_array = get_filler_array( - $scope[tc.list], + w.get_list(), w.get_current_page(), $scope[irk_number_of_pages], w.get_items_per_page() diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 1772109..3b85844 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -347,8 +347,8 @@ } }; update_stuff = function() { - $scope.sorted_and_paginated_list = get_sorted_and_paginated_list($scope[tc.list], w.get_current_page(), w.get_items_per_page(), $scope[tc.sort_context], $scope.predicate, $scope.descending, $filter); - return $scope.filler_array = get_filler_array($scope[tc.list], w.get_current_page(), $scope[irk_number_of_pages], w.get_items_per_page()); + $scope.sorted_and_paginated_list = get_sorted_and_paginated_list(w.get_list(), w.get_current_page(), w.get_items_per_page(), $scope[tc.sort_context], $scope.predicate, $scope.descending, $filter); + return $scope.filler_array = get_filler_array(w.get_list(), w.get_current_page(), $scope[irk_number_of_pages], w.get_items_per_page()); }; $scope.$watch(tc.current_page, function() { return update_stuff(); @@ -486,6 +486,10 @@ this.config = table_configuration; } + ScopeConfigWrapper.prototype.get_list = function() { + return this.scope.$eval(this.config.list); + }; + ScopeConfigWrapper.prototype.get_items_per_page = function() { return this.scope.$eval(this.config.items_per_page); }; @@ -498,6 +502,10 @@ return this.scope.$eval(this.config.max_pages); }; + ScopeConfigWrapper.prototype.get_sort_context = function() { + return this.scope.$eval(this.config.sort_context); + }; + return ScopeConfigWrapper; })(); From 385bd6397a7a7a029c4dc851d5dd06e520fa4b6a Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 19 Feb 2014 22:43:45 +0100 Subject: [PATCH 087/190] refactored pagination logic into own class and wrote tests for it --- angular-table.js | 125 +++++++++++------- angular-table.min.js | 2 +- coffee/at-pagination.coffee | 81 +++++++----- coffee/table/setup/paginated_setup.coffee | 7 +- gem/app/assets/javascripts/angular-table.js | 125 +++++++++++------- test/pagination.coffee | 91 ++++++++++++- .../pagination/complete_config_hardcoded.html | 17 +++ test/test_helper.coffee | 15 ++- 8 files changed, 332 insertions(+), 131 deletions(-) create mode 100644 test/templates/pagination/complete_config_hardcoded.html diff --git a/angular-table.js b/angular-table.js index 3b85844..fc65f00 100644 --- a/angular-table.js +++ b/angular-table.js @@ -3,7 +3,7 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var AngularTableManager, ColumnConfiguration, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, erk_attribute, erk_current_page, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, + var AngularTableManager, ColumnConfiguration, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, erk_attribute, erk_current_page, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -332,6 +332,7 @@ }; get_filler_array = function(list, current_page, number_of_pages, items_per_page) { var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; + items_per_page = parseInt(items_per_page); if (current_page === number_of_pages - 1) { itemCountOnLastPage = list.length % items_per_page; if (itemCountOnLastPage !== 0 || list.length === 0) { @@ -347,8 +348,10 @@ } }; update_stuff = function() { + var nop; $scope.sorted_and_paginated_list = get_sorted_and_paginated_list(w.get_list(), w.get_current_page(), w.get_items_per_page(), $scope[tc.sort_context], $scope.predicate, $scope.descending, $filter); - return $scope.filler_array = get_filler_array(w.get_list(), w.get_current_page(), $scope[irk_number_of_pages], w.get_items_per_page()); + nop = Math.ceil(w.get_list().length / w.get_items_per_page()); + return $scope.filler_array = get_filler_array(w.get_list(), w.get_current_page(), nop, w.get_items_per_page()); }; $scope.$watch(tc.current_page, function() { return update_stuff(); @@ -591,12 +594,73 @@ } ]); + PageSequence = (function() { + PageSequence.prototype.generate = function(start) { + var x, _i, _ref, _results; + if (start > (this.upper_bound - this.length)) { + start = this.upper_bound - this.length; + } else if (start < this.lower_bound) { + start = this.lower_bound; + } + _results = []; + for (x = _i = start, _ref = parseInt(start) + parseInt(this.length) - 1; start <= _ref ? _i <= _ref : _i >= _ref; x = start <= _ref ? ++_i : --_i) { + _results.push(x); + } + return _results; + }; + + function PageSequence(lower_bound, upper_bound, start, length) { + this.lower_bound = lower_bound != null ? lower_bound : 0; + this.upper_bound = upper_bound != null ? upper_bound : 1; + if (start == null) { + start = 0; + } + this.length = length != null ? length : 1; + if (this.length > (this.upper_bound - this.lower_bound)) { + throw "sequence is too long"; + } + this.data = this.generate(start); + } + + PageSequence.prototype.reset_parameters = function(lower_bound, upper_bound, length) { + this.lower_bound = lower_bound; + this.upper_bound = upper_bound; + this.length = length; + if (this.length > (this.upper_bound - this.lower_bound)) { + throw "sequence is too long"; + } + return this.data = this.generate(this.data[0]); + }; + + PageSequence.prototype.relocate = function(distance) { + var new_start; + new_start = this.data[0] + distance; + return this.data = this.generate(new_start, new_start + this.length); + }; + + PageSequence.prototype.realign_greedy = function(page) { + var new_start; + if (page < this.data[0]) { + new_start = page; + return this.data = this.generate(new_start); + } else if (page > this.data[this.length - 1]) { + new_start = page - (this.length - 1); + return this.data = this.generate(new_start); + } + }; + + PageSequence.prototype.realign_generous = function(page) {}; + + return PageSequence; + + })(); + angular.module("angular-table").directive("atPagination", [ "angularTableManager", function(angularTableManager) { return { replace: true, restrict: "E", - template: "", + template: "", controller: [ "$scope", "$element", "$attrs", function($scope, $element, $attrs) { return angularTableManager.register_pagination_scope($attrs.atTableId, $scope); @@ -604,17 +668,10 @@ ], scope: true, link: function($scope, $element, $attributes) { - var generate_page_array, get_number_of_pages, keep_in_bounds, set_current_page, set_number_of_pages, shift_sectioning, tc, update, w; + var get_number_of_pages, keep_in_bounds, set_current_page, set_number_of_pages, tc, update, w; tc = angularTableManager.get_table_configuration($attributes.atTableId); w = new ScopeConfigWrapper($scope, tc); - generate_page_array = function(start, end) { - var x, _i, _results; - _results = []; - for (x = _i = start; start <= end ? _i <= end : _i >= end; x = start <= end ? ++_i : --_i) { - _results.push(x); - } - return _results; - }; + $scope.page_sequence = new PageSequence(); set_current_page = function(current_page) { return $scope.$parent.$eval("" + tc.current_page + "=" + current_page); }; @@ -625,15 +682,19 @@ return $scope[irk_number_of_pages] = number_of_pages; }; update = function(reset) { + var new_number_of_pages, pages_to_display; if ($scope[tc.list]) { if ($scope[tc.list].length > 0) { - set_number_of_pages(Math.ceil($scope[tc.list].length / w.get_items_per_page())); - set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); + new_number_of_pages = Math.ceil($scope[tc.list].length / w.get_items_per_page()); + set_number_of_pages(new_number_of_pages); if ($scope.show_sectioning()) { - return $scope.update_sectioning(); + pages_to_display = w.get_max_pages(); } else { - return $scope.pages = generate_page_array(0, get_number_of_pages() - 1); + pages_to_display = new_number_of_pages; } + $scope.page_sequence.reset_parameters(0, new_number_of_pages, pages_to_display); + $scope.page_sequence.realign_greedy(w.get_current_page()); + return set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); } else { set_number_of_pages(1); return $scope.pages = [0]; @@ -645,43 +706,15 @@ return Math.min(max, val); }; $scope.show_sectioning = function() { - return tc.max_pages && get_number_of_pages() > w.get_max_pages(); + return w.get_max_pages() && get_number_of_pages() > w.get_max_pages(); }; $scope.get_current_page = function() { return w.get_current_page(); }; - shift_sectioning = function(current_start, steps, length, upper_bound) { - var new_start; - new_start = current_start + steps; - if (new_start > (upper_bound - length)) { - upper_bound - length; - } else if (new_start < 0) { - 0; - } else { - new_start; - } - return $scope.pages = generate_page_array(new_start, new_start + parseInt(w.get_max_pages()) - 1); - }; - $scope.update_sectioning = function() { - var diff, new_start; - new_start = void 0; - if ($scope.pages[0] > w.get_current_page()) { - diff = $scope.pages[0] - w.get_current_page(); - return shift_sectioning($scope.pages[0], -diff, w.get_max_pages(), get_number_of_pages()); - } else if ($scope.pages[$scope.pages.length - 1] < w.get_current_page()) { - diff = w.get_current_page() - $scope.pages[$scope.pages.length - 1]; - return shift_sectioning($scope.pages[0], diff, w.get_max_pages(), get_number_of_pages()); - } else if ($scope.pages[$scope.pages.length - 1] > (get_number_of_pages() - 1)) { - diff = w.get_current_page() - $scope.pages[$scope.pages.length - 1]; - return shift_sectioning($scope.pages[0], diff, w.get_max_pages(), get_number_of_pages()); - } else { - return $scope.pages = generate_page_array(0, parseInt(w.get_max_pages()) - 1); - } - }; $scope.step_page = function(step) { step = parseInt(step); set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)); - return $scope.update_sectioning(); + return $scope.page_sequence.realign_greedy(w.get_current_page()); }; $scope.go_to_page = function(page) { return set_current_page(page); diff --git a/angular-table.min.js b/angular-table.min.js index fcb0c23..5f8ebf0 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,p,u,g,l,c,_,h,f,d,m,b,v,y={}.hasOwnProperty,x=function(t,e){function i(){this.constructor=t}for(var n in e)y.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),s=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[_],this.attributes[c]&&this.register_items_per_page(this.attributes[c]),this.register_sort_context(this.attributes[f]),this.register_fill_last_page(this.attributes[g]),this.register_max_pages(this.attributes[h]),this.register_current_page(this.attributes[u]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.register_current_page=function(t){return void 0!==t?isNaN(t)?this.current_page=t:(this.current_page=""+this.id+"_currentPage",this.initial_current_page=parseInt(t)):(this.current_page=""+this.id+"_currentPage",this.initial_current_page=0)},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,p,u,g;for(i=[],g=t.find("td"),p=0,u=g.length;u>p;p++)a=g[p],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),r=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),a=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return x(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(r),i=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return x(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(t,e,i,r){var a,o,s,p,u;return s=this.table_configuration,u=new n(t,s),o=function(t,e,i,n,r,a,o){var s,p;return t?(p=t,s=i*e-t.length,"global"===n?(p=o("orderBy")(p,r,a),p=o("limitTo")(p,s),p=o("limitTo")(p,i)):(p=o("limitTo")(p,s),p=o("limitTo")(p,i),p=o("orderBy")(p,r,a)),p):[]},a=function(t,e,i,n){var r,a,o,s,p,u,g;if(e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,g=[],o=s=p=t.length,u=t.length+r;u>=p?u>=s:s>=u;o=u>=p?++s:--s)g.push(o);return g}return[]}},p=function(){return t.sorted_and_paginated_list=o(u.get_list(),u.get_current_page(),u.get_items_per_page(),t[s.sort_context],t.predicate,t.descending,r),t.filler_array=a(u.get_list(),u.get_current_page(),t[v],u.get_items_per_page())},t.$watch(s.current_page,function(){return p()}),t.$watch(s.items_per_page,function(){return p()}),t.$watch(""+s.list+".length",function(){return t[v]=Math.ceil(t[s.list].length/u.get_items_per_page()),p()}),t.$watch("predicate",function(){return p()}),t.$watch("descending",function(){return p()})},e}(r),o=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.table_configuration):new a(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),b="from_page",m="current_page",v="number_of_pages",_="atList",c="atItemsPerPage",g="atFillLastPage",f="atSortContext",h="atMaxPages",u="atCurrentPage",p="at-attribute",d="at-sortable",l="at-initial-sorting",n=function(){function t(t,e){this.scope=t,this.config=e}return t.prototype.get_list=function(){return this.scope.$eval(this.config.list)},t.prototype.get_items_per_page=function(){return this.scope.$eval(this.config.items_per_page)},t.prototype.get_current_page=function(){return this.scope.$eval(this.config.current_page)},t.prototype.get_max_pages=function(){return this.scope.$eval(this.config.max_pages)},t.prototype.get_sort_context=function(){return this.scope.$eval(this.config.sort_context)},t}(),t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages&&(e.$parent[i.max_pages]=i.initial_max_pages),void 0!==i.initial_current_page?e.$parent[i.current_page]=i.initial_current_page:void 0},t.prototype.register_pagination_scope=function(){},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,a;return a=new s(i,n),e.register_table(a),r=new o(i,a),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,i,r){var a,o,s,p,u,g,l,c,_;return l=t.get_table_configuration(r.atTableId),_=new n(e,l),a=function(t,e){var i,n,r;for(r=[],i=n=t;e>=t?e>=n:n>=e;i=e>=t?++n:--n)r.push(i);return r},p=function(t){return e.$parent.$eval(""+l.current_page+"="+t)},o=function(){return e[v]},u=function(t){return e[v]=t},c=function(){return e[l.list]?e[l.list].length>0?(u(Math.ceil(e[l.list].length/_.get_items_per_page())),p(s(_.get_current_page(),0,o()-1)),e.show_sectioning()?e.update_sectioning():e.pages=a(0,o()-1)):(u(1),e.pages=[0]):void 0},s=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return l.max_pages&&o()>_.get_max_pages()},e.get_current_page=function(){return _.get_current_page()},g=function(t,i,n,r){var o;return o=t+i,e.pages=a(o,o+parseInt(_.get_max_pages())-1)},e.update_sectioning=function(){var t,i;return i=void 0,e.pages[0]>_.get_current_page()?(t=e.pages[0]-_.get_current_page(),g(e.pages[0],-t,_.get_max_pages(),o())):e.pages[e.pages.length-1]<_.get_current_page()?(t=_.get_current_page()-e.pages[e.pages.length-1],g(e.pages[0],t,_.get_max_pages(),o())):e.pages[e.pages.length-1]>o()-1?(t=_.get_current_page()-e.pages[e.pages.length-1],g(e.pages[0],t,_.get_max_pages(),o())):e.pages=a(0,parseInt(_.get_max_pages())-1)},e.step_page=function(t){return t=parseInt(t),p(s(_.get_current_page()+t,0,o()-1)),e.update_sectioning()},e.go_to_page=function(t){return p(t)},e.jump_back=function(){return e.step_page(-_.get_max_pages())},e.jump_ahead=function(){return e.step_page(_.get_max_pages())},c(),e.$watch(l.items_per_page,function(){return c()}),e.$watch(l.max_pages,function(){return c()}),e.$watch(l.list,function(){return c()}),e.$watch(""+l.list+".length",function(){return c()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var t,e,i,n,r,a,o,s,u,l,p,c,g,_,h,f,d,m,b,v,y,w={}.hasOwnProperty,x=function(t,e){function i(){this.constructor=t}for(var n in e)w.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),u=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[h],this.attributes[_]&&this.register_items_per_page(this.attributes[_]),this.register_sort_context(this.attributes[d]),this.register_fill_last_page(this.attributes[c]),this.register_max_pages(this.attributes[f]),this.register_current_page(this.attributes[p]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.register_current_page=function(t){return void 0!==t?isNaN(t)?this.current_page=t:(this.current_page=""+this.id+"_currentPage",this.initial_current_page=parseInt(t)):(this.current_page=""+this.id+"_currentPage",this.initial_current_page=0)},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,u,l,p;for(i=[],p=t.find("td"),u=0,l=p.length;l>u;u++)a=p[u],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),a=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),o=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return x(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(a),n=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return x(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(t,e,i,n){var a,o,s,u,l;return s=this.table_configuration,l=new r(t,s),o=function(t,e,i,n,r,a,o){var s,u;return t?(u=t,s=i*e-t.length,"global"===n?(u=o("orderBy")(u,r,a),u=o("limitTo")(u,s),u=o("limitTo")(u,i)):(u=o("limitTo")(u,s),u=o("limitTo")(u,i),u=o("orderBy")(u,r,a)),u):[]},a=function(t,e,i,n){var r,a,o,s,u,l,p;if(n=parseInt(n),e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,p=[],o=s=u=t.length,l=t.length+r;l>=u?l>=s:s>=l;o=l>=u?++s:--s)p.push(o);return p}return[]}},u=function(){var e;return t.sorted_and_paginated_list=o(l.get_list(),l.get_current_page(),l.get_items_per_page(),t[s.sort_context],t.predicate,t.descending,n),e=Math.ceil(l.get_list().length/l.get_items_per_page()),t.filler_array=a(l.get_list(),l.get_current_page(),e,l.get_items_per_page())},t.$watch(s.current_page,function(){return u()}),t.$watch(s.items_per_page,function(){return u()}),t.$watch(""+s.list+".length",function(){return t[y]=Math.ceil(t[s.list].length/l.get_items_per_page()),u()}),t.$watch("predicate",function(){return u()}),t.$watch("descending",function(){return u()})},e}(a),s=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new n(this.table_configuration):new o(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),v="from_page",b="current_page",y="number_of_pages",h="atList",_="atItemsPerPage",c="atFillLastPage",d="atSortContext",f="atMaxPages",p="atCurrentPage",l="at-attribute",m="at-sortable",g="at-initial-sorting",r=function(){function t(t,e){this.scope=t,this.config=e}return t.prototype.get_list=function(){return this.scope.$eval(this.config.list)},t.prototype.get_items_per_page=function(){return this.scope.$eval(this.config.items_per_page)},t.prototype.get_current_page=function(){return this.scope.$eval(this.config.current_page)},t.prototype.get_max_pages=function(){return this.scope.$eval(this.config.max_pages)},t.prototype.get_sort_context=function(){return this.scope.$eval(this.config.sort_context)},t}(),t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages&&(e.$parent[i.max_pages]=i.initial_max_pages),void 0!==i.initial_current_page?e.$parent[i.current_page]=i.initial_current_page:void 0},t.prototype.register_pagination_scope=function(){},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,a;return a=new u(i,n),e.register_table(a),r=new s(i,a),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),i=function(){function t(t,e,i,n){if(this.lower_bound=null!=t?t:0,this.upper_bound=null!=e?e:1,null==i&&(i=0),this.length=null!=n?n:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(i)}return t.prototype.generate=function(t){var e,i,n,r;for(t>this.upper_bound-this.length?t=this.upper_bound-this.length:t=t?n>=i:i>=n;e=n>=t?++i:--i)r.push(e);return r},t.prototype.reset_parameters=function(t,e,i){if(this.lower_bound=t,this.upper_bound=e,this.length=i,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},t.prototype.relocate=function(t){var e;return e=this.data[0]+t,this.data=this.generate(e,e+this.length)},t.prototype.realign_greedy=function(t){var e;return tthis.data[this.length-1]?(e=t-(this.length-1),this.data=this.generate(e)):void 0},t.prototype.realign_generous=function(){},t}(),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,n,a){var o,s,u,l,p,c,g;return p=t.get_table_configuration(a.atTableId),g=new r(e,p),e.page_sequence=new i,u=function(t){return e.$parent.$eval(""+p.current_page+"="+t)},o=function(){return e[y]},l=function(t){return e[y]=t},c=function(){var t,i;return e[p.list]?e[p.list].length>0?(t=Math.ceil(e[p.list].length/g.get_items_per_page()),l(t),i=e.show_sectioning()?g.get_max_pages():t,e.page_sequence.reset_parameters(0,t,i),e.page_sequence.realign_greedy(g.get_current_page()),u(s(g.get_current_page(),0,o()-1))):(l(1),e.pages=[0]):void 0},s=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return g.get_max_pages()&&o()>g.get_max_pages()},e.get_current_page=function(){return g.get_current_page()},e.step_page=function(t){return t=parseInt(t),u(s(g.get_current_page()+t,0,o()-1)),e.page_sequence.realign_greedy(g.get_current_page())},e.go_to_page=function(t){return u(t)},e.jump_back=function(){return e.step_page(-g.get_max_pages())},e.jump_ahead=function(){return e.step_page(g.get_max_pages())},c(),e.$watch(p.items_per_page,function(){return c()}),e.$watch(p.max_pages,function(){return c()}),e.$watch(p.list,function(){return c()}),e.$watch(""+p.list+".length",function(){return c()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file diff --git a/coffee/at-pagination.coffee b/coffee/at-pagination.coffee index 6691492..bbc3706 100644 --- a/coffee/at-pagination.coffee +++ b/coffee/at-pagination.coffee @@ -1,3 +1,37 @@ +class PageSequence + + generate: (start) -> + if start > (@upper_bound - @length) + start = @upper_bound - @length + else if start < @lower_bound + start = @lower_bound + x for x in [start..(parseInt(start) + parseInt(@length) - 1)] + + constructor: (@lower_bound = 0, @upper_bound = 1, start = 0, @length = 1) -> + throw "sequence is too long" if @length > (@upper_bound - @lower_bound) + @data = @generate(start) + + reset_parameters: (lower_bound, upper_bound, length) -> + @lower_bound = lower_bound + @upper_bound = upper_bound + @length = length + throw "sequence is too long" if @length > (@upper_bound - @lower_bound) + @data = @generate(@data[0]) + + relocate: (distance) -> + new_start = @data[0] + distance + @data = @generate(new_start, new_start + @length) + + realign_greedy: (page) -> + if page < @data[0] + new_start = page + @data = @generate(new_start) + else if page > @data[@length - 1] + new_start = page - (@length - 1) + @data = @generate(new_start) + + realign_generous: (page) -> + angular.module("angular-table").directive "atPagination", ["angularTableManager", (angularTableManager) -> { replace: true @@ -18,7 +52,7 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" -
  • +
  • {{page + 1}}
  • @@ -48,8 +82,7 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" w = new ScopeConfigWrapper($scope, tc) - generate_page_array = (start, end) -> - x for x in [start..end] + $scope.page_sequence = new PageSequence() set_current_page = (current_page) -> $scope.$parent.$eval("#{tc.current_page}=#{current_page}") @@ -63,12 +96,17 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" update = (reset) -> if $scope[tc.list] if $scope[tc.list].length > 0 - set_number_of_pages(Math.ceil($scope[tc.list].length / w.get_items_per_page())) - set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)) + # old_number_of_pages = get_number_of_pages() + new_number_of_pages = Math.ceil($scope[tc.list].length / w.get_items_per_page()) + # if (old_number_of_pages != new_number_of_pages) + set_number_of_pages(new_number_of_pages) if $scope.show_sectioning() - $scope.update_sectioning() + pages_to_display = w.get_max_pages() else - $scope.pages = generate_page_array(0, get_number_of_pages() - 1) + pages_to_display = new_number_of_pages + $scope.page_sequence.reset_parameters(0, new_number_of_pages, pages_to_display) + $scope.page_sequence.realign_greedy(w.get_current_page()) + set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)) else set_number_of_pages(1) $scope.pages = [0] @@ -78,40 +116,15 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" Math.min(max, val) $scope.show_sectioning = () -> - tc.max_pages && get_number_of_pages() > w.get_max_pages() + w.get_max_pages() && get_number_of_pages() > w.get_max_pages() $scope.get_current_page = () -> w.get_current_page() - shift_sectioning = (current_start, steps, length, upper_bound) -> - new_start = current_start + steps - if new_start > (upper_bound - length) - upper_bound - length - else if new_start < 0 - 0 - else - new_start - $scope.pages = generate_page_array(new_start, new_start + parseInt(w.get_max_pages()) - 1) - - $scope.update_sectioning = () -> - new_start = undefined - - if $scope.pages[0] > w.get_current_page() - diff = $scope.pages[0] - w.get_current_page() - shift_sectioning($scope.pages[0], -diff, w.get_max_pages(), get_number_of_pages()) - else if $scope.pages[$scope.pages.length - 1] < w.get_current_page() - diff = w.get_current_page() - $scope.pages[$scope.pages.length - 1] - shift_sectioning($scope.pages[0], diff, w.get_max_pages(), get_number_of_pages()) - else if $scope.pages[$scope.pages.length - 1] > (get_number_of_pages() - 1) - diff = w.get_current_page() - $scope.pages[$scope.pages.length - 1] - shift_sectioning($scope.pages[0], diff, w.get_max_pages(), get_number_of_pages()) - else - $scope.pages = generate_page_array(0, parseInt(w.get_max_pages()) - 1) - $scope.step_page = (step) -> step = parseInt(step) set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)) - $scope.update_sectioning() + $scope.page_sequence.realign_greedy(w.get_current_page()) $scope.go_to_page = (page) -> set_current_page(page) diff --git a/coffee/table/setup/paginated_setup.coffee b/coffee/table/setup/paginated_setup.coffee index 9d0649a..c50cdfb 100644 --- a/coffee/table/setup/paginated_setup.coffee +++ b/coffee/table/setup/paginated_setup.coffee @@ -45,6 +45,8 @@ class PaginatedSetup extends Setup return [] get_filler_array = (list, current_page, number_of_pages, items_per_page) -> + items_per_page = parseInt(items_per_page) + if current_page == number_of_pages - 1 itemCountOnLastPage = list.length % items_per_page if itemCountOnLastPage != 0 || list.length == 0 @@ -54,6 +56,7 @@ class PaginatedSetup extends Setup [] update_stuff = () -> + $scope.sorted_and_paginated_list = get_sorted_and_paginated_list( w.get_list(), w.get_current_page(), @@ -64,10 +67,12 @@ class PaginatedSetup extends Setup $filter ) + nop = Math.ceil(w.get_list().length / w.get_items_per_page()) + $scope.filler_array = get_filler_array( w.get_list(), w.get_current_page(), - $scope[irk_number_of_pages], + nop, w.get_items_per_page() ) diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 3b85844..fc65f00 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -3,7 +3,7 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var AngularTableManager, ColumnConfiguration, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, erk_attribute, erk_current_page, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, + var AngularTableManager, ColumnConfiguration, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, erk_attribute, erk_current_page, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -332,6 +332,7 @@ }; get_filler_array = function(list, current_page, number_of_pages, items_per_page) { var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; + items_per_page = parseInt(items_per_page); if (current_page === number_of_pages - 1) { itemCountOnLastPage = list.length % items_per_page; if (itemCountOnLastPage !== 0 || list.length === 0) { @@ -347,8 +348,10 @@ } }; update_stuff = function() { + var nop; $scope.sorted_and_paginated_list = get_sorted_and_paginated_list(w.get_list(), w.get_current_page(), w.get_items_per_page(), $scope[tc.sort_context], $scope.predicate, $scope.descending, $filter); - return $scope.filler_array = get_filler_array(w.get_list(), w.get_current_page(), $scope[irk_number_of_pages], w.get_items_per_page()); + nop = Math.ceil(w.get_list().length / w.get_items_per_page()); + return $scope.filler_array = get_filler_array(w.get_list(), w.get_current_page(), nop, w.get_items_per_page()); }; $scope.$watch(tc.current_page, function() { return update_stuff(); @@ -591,12 +594,73 @@ } ]); + PageSequence = (function() { + PageSequence.prototype.generate = function(start) { + var x, _i, _ref, _results; + if (start > (this.upper_bound - this.length)) { + start = this.upper_bound - this.length; + } else if (start < this.lower_bound) { + start = this.lower_bound; + } + _results = []; + for (x = _i = start, _ref = parseInt(start) + parseInt(this.length) - 1; start <= _ref ? _i <= _ref : _i >= _ref; x = start <= _ref ? ++_i : --_i) { + _results.push(x); + } + return _results; + }; + + function PageSequence(lower_bound, upper_bound, start, length) { + this.lower_bound = lower_bound != null ? lower_bound : 0; + this.upper_bound = upper_bound != null ? upper_bound : 1; + if (start == null) { + start = 0; + } + this.length = length != null ? length : 1; + if (this.length > (this.upper_bound - this.lower_bound)) { + throw "sequence is too long"; + } + this.data = this.generate(start); + } + + PageSequence.prototype.reset_parameters = function(lower_bound, upper_bound, length) { + this.lower_bound = lower_bound; + this.upper_bound = upper_bound; + this.length = length; + if (this.length > (this.upper_bound - this.lower_bound)) { + throw "sequence is too long"; + } + return this.data = this.generate(this.data[0]); + }; + + PageSequence.prototype.relocate = function(distance) { + var new_start; + new_start = this.data[0] + distance; + return this.data = this.generate(new_start, new_start + this.length); + }; + + PageSequence.prototype.realign_greedy = function(page) { + var new_start; + if (page < this.data[0]) { + new_start = page; + return this.data = this.generate(new_start); + } else if (page > this.data[this.length - 1]) { + new_start = page - (this.length - 1); + return this.data = this.generate(new_start); + } + }; + + PageSequence.prototype.realign_generous = function(page) {}; + + return PageSequence; + + })(); + angular.module("angular-table").directive("atPagination", [ "angularTableManager", function(angularTableManager) { return { replace: true, restrict: "E", - template: "", + template: "", controller: [ "$scope", "$element", "$attrs", function($scope, $element, $attrs) { return angularTableManager.register_pagination_scope($attrs.atTableId, $scope); @@ -604,17 +668,10 @@ ], scope: true, link: function($scope, $element, $attributes) { - var generate_page_array, get_number_of_pages, keep_in_bounds, set_current_page, set_number_of_pages, shift_sectioning, tc, update, w; + var get_number_of_pages, keep_in_bounds, set_current_page, set_number_of_pages, tc, update, w; tc = angularTableManager.get_table_configuration($attributes.atTableId); w = new ScopeConfigWrapper($scope, tc); - generate_page_array = function(start, end) { - var x, _i, _results; - _results = []; - for (x = _i = start; start <= end ? _i <= end : _i >= end; x = start <= end ? ++_i : --_i) { - _results.push(x); - } - return _results; - }; + $scope.page_sequence = new PageSequence(); set_current_page = function(current_page) { return $scope.$parent.$eval("" + tc.current_page + "=" + current_page); }; @@ -625,15 +682,19 @@ return $scope[irk_number_of_pages] = number_of_pages; }; update = function(reset) { + var new_number_of_pages, pages_to_display; if ($scope[tc.list]) { if ($scope[tc.list].length > 0) { - set_number_of_pages(Math.ceil($scope[tc.list].length / w.get_items_per_page())); - set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); + new_number_of_pages = Math.ceil($scope[tc.list].length / w.get_items_per_page()); + set_number_of_pages(new_number_of_pages); if ($scope.show_sectioning()) { - return $scope.update_sectioning(); + pages_to_display = w.get_max_pages(); } else { - return $scope.pages = generate_page_array(0, get_number_of_pages() - 1); + pages_to_display = new_number_of_pages; } + $scope.page_sequence.reset_parameters(0, new_number_of_pages, pages_to_display); + $scope.page_sequence.realign_greedy(w.get_current_page()); + return set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); } else { set_number_of_pages(1); return $scope.pages = [0]; @@ -645,43 +706,15 @@ return Math.min(max, val); }; $scope.show_sectioning = function() { - return tc.max_pages && get_number_of_pages() > w.get_max_pages(); + return w.get_max_pages() && get_number_of_pages() > w.get_max_pages(); }; $scope.get_current_page = function() { return w.get_current_page(); }; - shift_sectioning = function(current_start, steps, length, upper_bound) { - var new_start; - new_start = current_start + steps; - if (new_start > (upper_bound - length)) { - upper_bound - length; - } else if (new_start < 0) { - 0; - } else { - new_start; - } - return $scope.pages = generate_page_array(new_start, new_start + parseInt(w.get_max_pages()) - 1); - }; - $scope.update_sectioning = function() { - var diff, new_start; - new_start = void 0; - if ($scope.pages[0] > w.get_current_page()) { - diff = $scope.pages[0] - w.get_current_page(); - return shift_sectioning($scope.pages[0], -diff, w.get_max_pages(), get_number_of_pages()); - } else if ($scope.pages[$scope.pages.length - 1] < w.get_current_page()) { - diff = w.get_current_page() - $scope.pages[$scope.pages.length - 1]; - return shift_sectioning($scope.pages[0], diff, w.get_max_pages(), get_number_of_pages()); - } else if ($scope.pages[$scope.pages.length - 1] > (get_number_of_pages() - 1)) { - diff = w.get_current_page() - $scope.pages[$scope.pages.length - 1]; - return shift_sectioning($scope.pages[0], diff, w.get_max_pages(), get_number_of_pages()); - } else { - return $scope.pages = generate_page_array(0, parseInt(w.get_max_pages()) - 1); - } - }; $scope.step_page = function(step) { step = parseInt(step); set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)); - return $scope.update_sectioning(); + return $scope.page_sequence.realign_greedy(w.get_current_page()); }; $scope.go_to_page = function(page) { return set_current_page(page); diff --git a/test/pagination.coffee b/test/pagination.coffee index 494f3af..c14dd42 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -1,4 +1,89 @@ describe "angular-table", () -> + + describe "PageSequence", () -> + + it "is constructed from upper_bound, lower_bound, start and length paramters", () -> + sequence = new PageSequence(0, 10, 0, 5) + expect(sequence.data).toEqual [0, 1, 2, 3, 4] + + sequence = new PageSequence(0, 10, 4, 3) + expect(sequence.data).toEqual [4, 5, 6] + + sequence = new PageSequence(0, 5, 3, 4) + expect(sequence.data).toEqual [1, 2, 3, 4] + + it "throws an exception when length does not fit into lower and upper bounds", () -> + expect(() -> new PageSequence(0, 2, 0, 3)).toThrow() + + it "s parameters can be reset", () -> + sequence = new PageSequence(0, 10, 4, 3) + expect(sequence.data).toEqual [4, 5, 6] + + sequence.reset_parameters(0, 6, 3) + expect(sequence.data).toEqual [3, 4, 5] + + it "relocates by a given distance and wont underrun or exceed a given boundary", () -> + sequence = new PageSequence(0, 7, 0, 3) + expect(sequence.data).toEqual [0, 1, 2] + + sequence.relocate(1) + expect(sequence.data).toEqual [1, 2, 3] + + sequence.relocate(2) + expect(sequence.data).toEqual [3, 4, 5] + + sequence.relocate(2) + expect(sequence.data).toEqual [4, 5, 6] + + describe "realignment", () -> + it "does not realign if the given page is in the current sequence scope", () -> + sequence = new PageSequence(0, 7, 2, 3) + expect(sequence.data).toEqual [2, 3, 4] + + sequence.realign_greedy(2) + expect(sequence.data).toEqual [2, 3, 4] + + sequence.realign_greedy(4) + expect(sequence.data).toEqual [2, 3, 4] + + it "realigns greedy", () -> + sequence = new PageSequence(0, 7, 2, 3) + expect(sequence.data).toEqual [2, 3, 4] + + sequence.realign_greedy(6) + expect(sequence.data).toEqual [4, 5, 6] + + # expect(() -> sequence.realign_greedy(7)).toThrow() + + sequence.realign_greedy(4) + expect(sequence.data).toEqual [4, 5, 6] + + sequence.realign_greedy(1) + expect(sequence.data).toEqual [1, 2, 3] + + sequence.realign_greedy(0) + expect(sequence.data).toEqual [0, 1, 2] + + # expect(() -> sequence.realign_greedy(-1)).toThrow() + + + + # describe "complete configuration hardcoded", () -> + # beforeEach () -> + # @element = prepare_element(new TemplateCompiler("pagination/complete_config_hardcoded.html"), (scope) -> + # scope.list = [ + # {name: "g"}, {name: "h"}, {name: "i"}, {name: "j"}, {name: "k"}, {name: "l"} + # {name: "a"}, {name: "b"}, {name: "c"}, {name: "d"}, {name: "e"}, {name: "f"}, + # ] + # ) + + # it "shows", () -> + # tds = extract_html_to_array(@element.find("td")) + # expect(tds).toEqual ["a", "b", "c"] + + # paginationLinks = @element.find "a" + # console.log paginationLinks + describe "pagination", () -> it "adds pagination to a table", () -> @element = prepare_element(new TemplateCompiler("pagination/pagination.html"), (scope) -> @@ -11,7 +96,11 @@ describe "angular-table", () -> tds = extract_html_to_array(@element.find("td")) expect(tds).toEqual ["Till", "Richard", "Christoph", "Paul"] - paginationLinks = @element.find "a" + paginationLinks = @element.find("a") + visible_pagination = extract_pagination_to_array(@element.find("li")) + + expect(visible_pagination).toEqual ['First', '‹', '1', '2', '›', 'Last'] + link = _.find(paginationLinks, (link) -> angular.element(link).html() == "2") click(link) diff --git a/test/templates/pagination/complete_config_hardcoded.html b/test/templates/pagination/complete_config_hardcoded.html new file mode 100644 index 0000000..eeaf882 --- /dev/null +++ b/test/templates/pagination/complete_config_hardcoded.html @@ -0,0 +1,17 @@ +
        
    + + + + + + +
    + + diff --git a/test/test_helper.coffee b/test/test_helper.coffee index 8ed50b1..4d2d92b 100644 --- a/test/test_helper.coffee +++ b/test/test_helper.coffee @@ -1,8 +1,19 @@ getChildrenFor = (element, selector) -> element[0].querySelectorAll(selector) -extract_html_to_array = (tds) -> - _.map(tds, (td) -> angular.element(td).html()) +extract_visible_elements = (elements) -> + _.reject(elements, (element) -> + angular.element(element).hasClass("ng-hide") + ) + +extract_html_to_array = (elements) -> + _.map(elements, (element) -> + angular.element(element).html() + ) + +extract_pagination_to_array = (elements) -> + elements = extract_visible_elements(elements) + angular.element(element).find("a").html() for element in elements load_template = (template_name, template_cache) -> angular.element(template_cache.get(template_name)) From 50ab2e6d41e09877fb1830fe0d0fbbf50428046f Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Thu, 20 Feb 2014 22:55:20 +0100 Subject: [PATCH 088/190] new tests --- test/header.coffee | 9 +- test/pagination.coffee | 127 ++++++++++++++---- test/sorting.coffee | 4 +- .../pagination/complete_config_hardcoded.html | 2 +- test/templates/pagination/pagination.html | 3 +- test/test_helper.coffee | 87 ++++++++++-- 6 files changed, 187 insertions(+), 45 deletions(-) diff --git a/test/header.coffee b/test/header.coffee index a70738a..3405d09 100644 --- a/test/header.coffee +++ b/test/header.coffee @@ -2,17 +2,20 @@ describe "angular-table", () -> describe "header", () -> it "doesnt add a header at all if the header tag isnt declared", () -> - @element = prepare_element(new TemplateCompiler("header/no_header.html"), (scope) ->) + comp = new TemplateCompiler("header/no_header.html") + @element = comp.prepare_element((scope) ->) header = @element.find("thead")[0] expect(header).toBe undefined it "creates column headers implicitly", () -> - @element = prepare_element(new TemplateCompiler("header/header.html"), (scope) ->) + comp = new TemplateCompiler("header/header.html") + @element = comp.prepare_element((scope) ->) header = extract_html_to_array(getChildrenFor(@element, "thead > tr > th")) expect(header[0]).toEqual "Name" it "allows to set custom column headers", () -> - @element = prepare_element(new TemplateCompiler("header/header.html"), (scope) ->) + comp = new TemplateCompiler("header/header.html") + @element = comp.prepare_element((scope) ->) header = extract_html_to_array(getChildrenFor(@element, "thead > tr > th")) expect(header[1]).toEqual "The population" expect(header[2]).toEqual "Country" diff --git a/test/pagination.coffee b/test/pagination.coffee index c14dd42..ab8b32d 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -68,25 +68,102 @@ describe "angular-table", () -> - # describe "complete configuration hardcoded", () -> - # beforeEach () -> - # @element = prepare_element(new TemplateCompiler("pagination/complete_config_hardcoded.html"), (scope) -> - # scope.list = [ - # {name: "g"}, {name: "h"}, {name: "i"}, {name: "j"}, {name: "k"}, {name: "l"} - # {name: "a"}, {name: "b"}, {name: "c"}, {name: "d"}, {name: "e"}, {name: "f"}, - # ] - # ) - - # it "shows", () -> - # tds = extract_html_to_array(@element.find("td")) - # expect(tds).toEqual ["a", "b", "c"] - - # paginationLinks = @element.find "a" - # console.log paginationLinks describe "pagination", () -> + step_back = '‹' + step_ahead = '›' + jump_back = '«' + jump_ahead = '»' + first = 'First' + last = 'Last' + + describe "complete configuration hardcoded", () -> + + beforeEach () -> + @comp = new TemplateCompiler("pagination/complete_config_hardcoded.html") + + @element = @comp.prepare_element((scope) -> + scope.list = [ + {name: "g"}, {name: "h"}, {name: "i"}, {name: "j"}, {name: "k"}, {name: "l"} + {name: "a"}, {name: "b"}, {name: "c"}, {name: "d"}, {name: "e"}, {name: "f"}, + {name: "m"} + ] + ) + + @gui = new GUI(@element, @comp.scope) + + it "allows to select pages", () -> + expect(@gui.pagination.pages).toEqual [1, 2] + expect(@gui.pagination.current_page).toEqual 1 + + @gui.alter_scope((scope) -> + scope.completeConfigHardcoded_itemsPerPage = 4 + scope.completeConfigHardcoded_maxPages = 4 + ) + + expect(@gui.table.rows).toEqual [['a'], ['b'], ['c'], ['d']] + expect(@gui.pagination.pages).toEqual [1, 2, 3, 4] + + @gui.click_pagination(2) + + expect(@gui.table.rows).toEqual [['e'], ['f'], ['g'], ['h']] + expect(@gui.pagination.current_page).toEqual 2 + + @gui.click_pagination(4) + + expect(@gui.table.rows).toEqual [['m'], [' '], [' '], [' ']] + expect(@gui.pagination.current_page).toEqual 4 + + + it "allows to step back and forth", () -> + expect(@gui.table.rows).toEqual [['a'], ['b'], ['c']] + + expect(@gui.table.rows).toEqual [['a'], ['b'], ['c']] + expect(@gui.pagination.current_page).toEqual 1 + expect(@gui.pagination.pages).toEqual [1, 2] + + @gui.click_pagination(step_ahead) + + expect(@gui.table.rows).toEqual [['d'], ['e'], ['f']] + expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.pagination.pages).toEqual [1, 2] + + @gui.click_pagination(step_ahead) + + expect(@gui.table.rows).toEqual [['g'], ['h'], ['i']] + expect(@gui.pagination.current_page).toEqual 3 + expect(@gui.pagination.pages).toEqual [2, 3] + + @gui.click_pagination(step_ahead) + @gui.click_pagination(step_ahead) + + # we reached the end of the pagination by now + + expect(@gui.table.rows).toEqual [['m'], [' '], [' ']] + expect(@gui.pagination.current_page).toEqual 5 + expect(@gui.pagination.pages).toEqual [4, 5] + + @gui.click_pagination(step_ahead) + + expect(@gui.table.rows).toEqual [['m'], [' '], [' ']] + expect(@gui.pagination.current_page).toEqual 5 + expect(@gui.pagination.pages).toEqual [4, 5] + + @gui.click_pagination(step_back) + + expect(@gui.table.rows).toEqual [['j'], ['k'], ['l']] + expect(@gui.pagination.current_page).toEqual 4 + expect(@gui.pagination.pages).toEqual [4, 5] + + @gui.click_pagination(step_back) + + expect(@gui.table.rows).toEqual [['g'], ['h'], ['i']] + expect(@gui.pagination.current_page).toEqual 3 + expect(@gui.pagination.pages).toEqual [3, 4] + it "adds pagination to a table", () -> - @element = prepare_element(new TemplateCompiler("pagination/pagination.html"), (scope) -> + comp = new TemplateCompiler("pagination/pagination.html") + @element = comp.prepare_element((scope) -> scope.rammstein = [ {name: "Till"}, {name: "Richard"}, {name: "Christoph"}, {name: "Paul"}, {name: "Flake"}, {name: "Oliver"} @@ -96,14 +173,10 @@ describe "angular-table", () -> tds = extract_html_to_array(@element.find("td")) expect(tds).toEqual ["Till", "Richard", "Christoph", "Paul"] - paginationLinks = @element.find("a") - visible_pagination = extract_pagination_to_array(@element.find("li")) - - expect(visible_pagination).toEqual ['First', '‹', '1', '2', '›', 'Last'] - - link = _.find(paginationLinks, (link) -> angular.element(link).html() == "2") - click(link) + p = new PaginationGUI(@element) + expect(p.pages).toEqual [1, 2] + p.click(step_ahead) tds = extract_html_to_array(@element.find("td")) expect(tds).toEqual ["Flake", "Oliver", " ", " "] @@ -113,11 +186,13 @@ describe "angular-table", () -> {char: "a"}, {char: "e"}, {char: "h"}, {char: "g"}] it "allows to set the sort context to global", () -> - @element = prepare_element(new TemplateCompiler("pagination/sort_context_global.html"), callback) + comp = new TemplateCompiler("pagination/sort_context_global.html") + @element = comp.prepare_element(callback) tds = extract_html_to_array(@element.find("td")) expect(tds).toEqual ["a", "b", "c", "d"] it "allows to set the sort context to page", () -> - @element = prepare_element(new TemplateCompiler("pagination/sort_context_page.html"), callback) + comp = new TemplateCompiler("pagination/sort_context_page.html") + @element = comp.prepare_element(callback) tds = extract_html_to_array(@element.find("td")) - expect(tds).toEqual ["b", "c", "d", "f"] \ No newline at end of file + expect(tds).toEqual ["b", "c", "d", "f"] diff --git a/test/sorting.coffee b/test/sorting.coffee index a408951..8197dbf 100644 --- a/test/sorting.coffee +++ b/test/sorting.coffee @@ -2,8 +2,8 @@ describe "angular-table", () -> describe "sorting", () -> beforeEach(() -> - tc = new TemplateCompiler("sorting/sorting.html") - @element = prepare_element(tc, (scope) -> + comp = new TemplateCompiler("sorting/sorting.html") + @element = comp.prepare_element((scope) -> scope.cities = [{name: "Helsinki"}, {name: "Zurich"}, {name: "Amsterdam"}] ) ) diff --git a/test/templates/pagination/complete_config_hardcoded.html b/test/templates/pagination/complete_config_hardcoded.html index eeaf882..4ed3b40 100644 --- a/test/templates/pagination/complete_config_hardcoded.html +++ b/test/templates/pagination/complete_config_hardcoded.html @@ -2,7 +2,7 @@ at-table at-list="list" at-items-per-page="3" - at-max-pages="3" + at-max-pages="2" at-fill-last-page="true" at-sort-context="global" > diff --git a/test/templates/pagination/pagination.html b/test/templates/pagination/pagination.html index ad4217a..94a7702 100644 --- a/test/templates/pagination/pagination.html +++ b/test/templates/pagination/pagination.html @@ -1,5 +1,4 @@ -
    -
    +
    diff --git a/test/test_helper.coffee b/test/test_helper.coffee index 4d2d92b..8ad60dd 100644 --- a/test/test_helper.coffee +++ b/test/test_helper.coffee @@ -15,32 +15,97 @@ extract_pagination_to_array = (elements) -> elements = extract_visible_elements(elements) angular.element(element).find("a").html() for element in elements -load_template = (template_name, template_cache) -> - angular.element(template_cache.get(template_name)) -prepare_element = (template_compiler, callback) -> - element = null - inject ($compile, $rootScope, $templateCache) -> - element = template_compiler.compile_template($compile, $rootScope, $templateCache, callback) - return element + class TemplateCompiler - constructor : (template_name) -> + constructor: (template_name) -> @template_name = template_name - module("angular-table") module("test/templates/#{@template_name}") - compile_template : ($compile, $rootScope, $templateCache, callback) -> + load_template: (template_name, template_cache) -> + angular.element(template_cache.get(template_name)) + + compile_template: ($compile, $rootScope, $templateCache, callback) -> element = null - element = load_template("test/templates/#{@template_name}", $templateCache) + element = @load_template("test/templates/#{@template_name}", $templateCache) callback($rootScope) element = $compile(element)($rootScope) $rootScope.$digest() + @scope = $rootScope + + return element + + prepare_element: (callback) -> + element = null + thiz = @ + inject ($compile, $rootScope, $templateCache) -> + element = thiz.compile_template($compile, $rootScope, $templateCache, callback) return element +class TableGUI + + constructor: (@element) -> + @reload() + + reload: () -> + @rows = _.map(@element.find("tr"), (row) -> + _.map(angular.element(row).find("td"), (cell) -> + angular.element(cell).html() + ) + ) + @rows.shift() if @rows[0].length == 0 + + +class PaginationGUI + + constructor: (@element) -> + @reload() + + reload: () -> + lis = @element.find("li") + lis = extract_visible_elements(lis) + as = (angular.element(li).find("a") for li in lis) + + @buttons = {} + (@buttons[a.html()] = a[0]) for a in as + + @representation = (key for key, val of @buttons) + + @pages = [] + for p in @representation + n = parseInt(p) + @pages.push(n) if !isNaN(n) + + @current_page = _.find(lis, (li) -> angular.element(li).hasClass("active")) + @current_page = parseInt(angular.element(@current_page).find("a").html()) + + click: (button) -> + click(@buttons[button]) + @reload() + +class GUI + constructor: (@element, scope) -> + @pagination = new PaginationGUI(@element) + @table = new TableGUI(@element) + @scope = scope + + reload: () -> + @table.reload() + @pagination.reload() + + alter_scope: (f) -> + f(@scope) + @scope.$digest() + @reload() + + click_pagination: (button) -> + @pagination.click(button) + @table.reload() + click = (el) -> ev = document.createEvent("MouseEvent") ev.initMouseEvent "click", true, true, window, null, 0, 0, 0, 0, false, false, false, false, 0, null From 6218f4762c8b4dca64f3d508c3a686d38b8f75a6 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 21 Feb 2014 12:08:14 +0100 Subject: [PATCH 089/190] more testing --- coffee/at-table.coffee | 4 +- coffee/table/setup/paginated_setup.coffee | 2 +- test/page_sequence.coffee | 65 +++++ test/pagination.coffee | 250 +++++++----------- .../complete_config_parameterized.html | 22 ++ test/test_helper.coffee | 21 +- 6 files changed, 198 insertions(+), 166 deletions(-) create mode 100644 test/page_sequence.coffee create mode 100644 test/templates/pagination/complete_config_parameterized.html diff --git a/coffee/at-table.coffee b/coffee/at-table.coffee index 36503f7..ada2f46 100644 --- a/coffee/at-table.coffee +++ b/coffee/at-table.coffee @@ -1,8 +1,8 @@ angular.module "angular-table", [] # internal reserved keywords -irk_from_page = "from_page" # atTable -irk_current_page = "current_page" # atTable (getFillerArray), atPagination +# irk_from_page = "from_page" # atTable +# irk_current_page = "current_page" # atTable (getFillerArray), atPagination irk_number_of_pages = "number_of_pages" # atTable (getFillerArray), atPagination # external reserved keywords diff --git a/coffee/table/setup/paginated_setup.coffee b/coffee/table/setup/paginated_setup.coffee index c50cdfb..6583e8a 100644 --- a/coffee/table/setup/paginated_setup.coffee +++ b/coffee/table/setup/paginated_setup.coffee @@ -61,7 +61,7 @@ class PaginatedSetup extends Setup w.get_list(), w.get_current_page(), w.get_items_per_page(), - $scope[tc.sort_context], + w.get_sort_context(), $scope.predicate, $scope.descending, $filter diff --git a/test/page_sequence.coffee b/test/page_sequence.coffee new file mode 100644 index 0000000..94bf235 --- /dev/null +++ b/test/page_sequence.coffee @@ -0,0 +1,65 @@ +describe "angular-table", () -> + describe "PageSequence", () -> + it "is constructed from upper_bound, lower_bound, start and length paramters", () -> + sequence = new PageSequence(0, 10, 0, 5) + expect(sequence.data).toEqual [0, 1, 2, 3, 4] + + sequence = new PageSequence(0, 10, 4, 3) + expect(sequence.data).toEqual [4, 5, 6] + + sequence = new PageSequence(0, 5, 3, 4) + expect(sequence.data).toEqual [1, 2, 3, 4] + + it "throws an exception when length does not fit into lower and upper bounds", () -> + expect(() -> new PageSequence(0, 2, 0, 3)).toThrow() + + it "s parameters can be reset", () -> + sequence = new PageSequence(0, 10, 4, 3) + expect(sequence.data).toEqual [4, 5, 6] + + sequence.reset_parameters(0, 6, 3) + expect(sequence.data).toEqual [3, 4, 5] + + it "relocates by a given distance and wont underrun or exceed a given boundary", () -> + sequence = new PageSequence(0, 7, 0, 3) + expect(sequence.data).toEqual [0, 1, 2] + + sequence.relocate(1) + expect(sequence.data).toEqual [1, 2, 3] + + sequence.relocate(2) + expect(sequence.data).toEqual [3, 4, 5] + + sequence.relocate(2) + expect(sequence.data).toEqual [4, 5, 6] + + describe "realignment", () -> + it "does not realign if the given page is in the current sequence scope", () -> + sequence = new PageSequence(0, 7, 2, 3) + expect(sequence.data).toEqual [2, 3, 4] + + sequence.realign_greedy(2) + expect(sequence.data).toEqual [2, 3, 4] + + sequence.realign_greedy(4) + expect(sequence.data).toEqual [2, 3, 4] + + it "realigns greedy", () -> + sequence = new PageSequence(0, 7, 2, 3) + expect(sequence.data).toEqual [2, 3, 4] + + sequence.realign_greedy(6) + expect(sequence.data).toEqual [4, 5, 6] + + # expect(() -> sequence.realign_greedy(7)).toThrow() + + sequence.realign_greedy(4) + expect(sequence.data).toEqual [4, 5, 6] + + sequence.realign_greedy(1) + expect(sequence.data).toEqual [1, 2, 3] + + sequence.realign_greedy(0) + expect(sequence.data).toEqual [0, 1, 2] + + # expect(() -> sequence.realign_greedy(-1)).toThrow() diff --git a/test/pagination.coffee b/test/pagination.coffee index ab8b32d..afd10b9 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -1,75 +1,6 @@ describe "angular-table", () -> + describe "Pagination", () -> - describe "PageSequence", () -> - - it "is constructed from upper_bound, lower_bound, start and length paramters", () -> - sequence = new PageSequence(0, 10, 0, 5) - expect(sequence.data).toEqual [0, 1, 2, 3, 4] - - sequence = new PageSequence(0, 10, 4, 3) - expect(sequence.data).toEqual [4, 5, 6] - - sequence = new PageSequence(0, 5, 3, 4) - expect(sequence.data).toEqual [1, 2, 3, 4] - - it "throws an exception when length does not fit into lower and upper bounds", () -> - expect(() -> new PageSequence(0, 2, 0, 3)).toThrow() - - it "s parameters can be reset", () -> - sequence = new PageSequence(0, 10, 4, 3) - expect(sequence.data).toEqual [4, 5, 6] - - sequence.reset_parameters(0, 6, 3) - expect(sequence.data).toEqual [3, 4, 5] - - it "relocates by a given distance and wont underrun or exceed a given boundary", () -> - sequence = new PageSequence(0, 7, 0, 3) - expect(sequence.data).toEqual [0, 1, 2] - - sequence.relocate(1) - expect(sequence.data).toEqual [1, 2, 3] - - sequence.relocate(2) - expect(sequence.data).toEqual [3, 4, 5] - - sequence.relocate(2) - expect(sequence.data).toEqual [4, 5, 6] - - describe "realignment", () -> - it "does not realign if the given page is in the current sequence scope", () -> - sequence = new PageSequence(0, 7, 2, 3) - expect(sequence.data).toEqual [2, 3, 4] - - sequence.realign_greedy(2) - expect(sequence.data).toEqual [2, 3, 4] - - sequence.realign_greedy(4) - expect(sequence.data).toEqual [2, 3, 4] - - it "realigns greedy", () -> - sequence = new PageSequence(0, 7, 2, 3) - expect(sequence.data).toEqual [2, 3, 4] - - sequence.realign_greedy(6) - expect(sequence.data).toEqual [4, 5, 6] - - # expect(() -> sequence.realign_greedy(7)).toThrow() - - sequence.realign_greedy(4) - expect(sequence.data).toEqual [4, 5, 6] - - sequence.realign_greedy(1) - expect(sequence.data).toEqual [1, 2, 3] - - sequence.realign_greedy(0) - expect(sequence.data).toEqual [0, 1, 2] - - # expect(() -> sequence.realign_greedy(-1)).toThrow() - - - - - describe "pagination", () -> step_back = '‹' step_ahead = '›' jump_back = '«' @@ -77,122 +8,123 @@ describe "angular-table", () -> first = 'First' last = 'Last' - describe "complete configuration hardcoded", () -> - - beforeEach () -> - @comp = new TemplateCompiler("pagination/complete_config_hardcoded.html") - - @element = @comp.prepare_element((scope) -> - scope.list = [ - {name: "g"}, {name: "h"}, {name: "i"}, {name: "j"}, {name: "k"}, {name: "l"} - {name: "a"}, {name: "b"}, {name: "c"}, {name: "d"}, {name: "e"}, {name: "f"}, - {name: "m"} - ] - ) - - @gui = new GUI(@element, @comp.scope) + setups = [ + { + template: "pagination/complete_config_hardcoded.html" + variable_names: { + items_per_page: "completeConfigHardcoded_itemsPerPage", + max_pages: "completeConfigHardcoded_maxPages" + } + }, + { + template: "pagination/complete_config_parameterized.html" + variable_names: { + items_per_page: "config.my_items_per_page", + max_pages: "config.my_max_pages" + } + } + ] - it "allows to select pages", () -> - expect(@gui.pagination.pages).toEqual [1, 2] - expect(@gui.pagination.current_page).toEqual 1 + for setup in setups + do (setup) -> + describe "complete configuration hardcoded #{setup.template}", () -> + beforeEach () -> + @comp = new TemplateCompiler(setup.template) - @gui.alter_scope((scope) -> - scope.completeConfigHardcoded_itemsPerPage = 4 - scope.completeConfigHardcoded_maxPages = 4 - ) + @element = @comp.prepare_element((scope) -> + scope.list = [ + {name: "g"}, {name: "h"}, {name: "i"}, {name: "j"}, {name: "k"}, {name: "l"} + {name: "a"}, {name: "b"}, {name: "c"}, {name: "d"}, {name: "e"}, {name: "f"}, + {name: "m"} + ] + ) - expect(@gui.table.rows).toEqual [['a'], ['b'], ['c'], ['d']] - expect(@gui.pagination.pages).toEqual [1, 2, 3, 4] + @gui = new GUI(@element, @comp.scope, setup.variable_names) - @gui.click_pagination(2) + it "allows to select pages", () -> - expect(@gui.table.rows).toEqual [['e'], ['f'], ['g'], ['h']] - expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.pagination.pages).toEqual([1, 2]) + expect(@gui.pagination.current_page).toEqual(1) - @gui.click_pagination(4) + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.items_per_page, 4) + scope_wrapper.set(vars.max_pages, 4) + ) - expect(@gui.table.rows).toEqual [['m'], [' '], [' '], [' ']] - expect(@gui.pagination.current_page).toEqual 4 + expect(@gui.table.rows).toEqual([['a'], ['b'], ['c'], ['d']]) + expect(@gui.pagination.pages).toEqual([1, 2, 3, 4]) + @gui.click_pagination(2) - it "allows to step back and forth", () -> - expect(@gui.table.rows).toEqual [['a'], ['b'], ['c']] + expect(@gui.table.rows).toEqual([['e'], ['f'], ['g'], ['h']]) + expect(@gui.pagination.current_page).toEqual(2) - expect(@gui.table.rows).toEqual [['a'], ['b'], ['c']] - expect(@gui.pagination.current_page).toEqual 1 - expect(@gui.pagination.pages).toEqual [1, 2] + @gui.click_pagination(4) - @gui.click_pagination(step_ahead) + expect(@gui.table.rows).toEqual([['m'], [' '], [' '], [' ']]) + expect(@gui.pagination.current_page).toEqual(4) - expect(@gui.table.rows).toEqual [['d'], ['e'], ['f']] - expect(@gui.pagination.current_page).toEqual 2 - expect(@gui.pagination.pages).toEqual [1, 2] + it "allows to step back and forth", () -> + expect(@gui.table.rows).toEqual([['a'], ['b'], ['c']]) + expect(@gui.pagination.current_page).toEqual(1) + expect(@gui.pagination.pages).toEqual([1, 2]) - @gui.click_pagination(step_ahead) + @gui.click_pagination(step_ahead) - expect(@gui.table.rows).toEqual [['g'], ['h'], ['i']] - expect(@gui.pagination.current_page).toEqual 3 - expect(@gui.pagination.pages).toEqual [2, 3] + expect(@gui.table.rows).toEqual([['d'], ['e'], ['f']]) + expect(@gui.pagination.current_page).toEqual(2) + expect(@gui.pagination.pages).toEqual([1, 2]) - @gui.click_pagination(step_ahead) - @gui.click_pagination(step_ahead) + @gui.click_pagination(step_ahead) - # we reached the end of the pagination by now + expect(@gui.table.rows).toEqual([['g'], ['h'], ['i']]) + expect(@gui.pagination.current_page).toEqual(3) + expect(@gui.pagination.pages).toEqual([2, 3]) - expect(@gui.table.rows).toEqual [['m'], [' '], [' ']] - expect(@gui.pagination.current_page).toEqual 5 - expect(@gui.pagination.pages).toEqual [4, 5] + @gui.click_pagination(step_ahead) + @gui.click_pagination(step_ahead) - @gui.click_pagination(step_ahead) + # we reached the end of the pagination by now - expect(@gui.table.rows).toEqual [['m'], [' '], [' ']] - expect(@gui.pagination.current_page).toEqual 5 - expect(@gui.pagination.pages).toEqual [4, 5] + expect(@gui.table.rows).toEqual([['m'], [' '], [' ']]) + expect(@gui.pagination.current_page).toEqual(5) + expect(@gui.pagination.pages).toEqual([4, 5]) - @gui.click_pagination(step_back) + @gui.click_pagination(step_ahead) - expect(@gui.table.rows).toEqual [['j'], ['k'], ['l']] - expect(@gui.pagination.current_page).toEqual 4 - expect(@gui.pagination.pages).toEqual [4, 5] + expect(@gui.table.rows).toEqual([['m'], [' '], [' ']]) + expect(@gui.pagination.current_page).toEqual(5) + expect(@gui.pagination.pages).toEqual([4, 5]) - @gui.click_pagination(step_back) + @gui.click_pagination(step_back) - expect(@gui.table.rows).toEqual [['g'], ['h'], ['i']] - expect(@gui.pagination.current_page).toEqual 3 - expect(@gui.pagination.pages).toEqual [3, 4] + expect(@gui.table.rows).toEqual([['j'], ['k'], ['l']]) + expect(@gui.pagination.current_page).toEqual(4) + expect(@gui.pagination.pages).toEqual([4, 5]) - it "adds pagination to a table", () -> - comp = new TemplateCompiler("pagination/pagination.html") - @element = comp.prepare_element((scope) -> - scope.rammstein = [ - {name: "Till"}, {name: "Richard"}, {name: "Christoph"}, - {name: "Paul"}, {name: "Flake"}, {name: "Oliver"} - ] - ) + @gui.click_pagination(step_back) - tds = extract_html_to_array(@element.find("td")) - expect(tds).toEqual ["Till", "Richard", "Christoph", "Paul"] + expect(@gui.table.rows).toEqual([['g'], ['h'], ['i']]) + expect(@gui.pagination.current_page).toEqual(3) + expect(@gui.pagination.pages).toEqual([3, 4]) - p = new PaginationGUI(@element) - expect(p.pages).toEqual [1, 2] + describe "the maximum pages setting", () -> + for val in [undefined, null] + it "shows all pages if max_pages is undefined or null", () -> - p.click(step_ahead) - tds = extract_html_to_array(@element.find("td")) - expect(tds).toEqual ["Flake", "Oliver", " ", " "] + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.max_pages, val) + ) - describe "sort context", () -> - callback = (scope) -> - scope.letters = [{char: "c"}, {char: "b"}, {char: "d"}, {char: "f"}, - {char: "a"}, {char: "e"}, {char: "h"}, {char: "g"}] + expect(@gui.pagination.pages).toEqual([1, 2, 3, 4, 5]) + expect(@gui.pagination.representation).toEqual( + ['First', '‹', '1', '2', '3', '4', '5', '›', 'Last']) - it "allows to set the sort context to global", () -> - comp = new TemplateCompiler("pagination/sort_context_global.html") - @element = comp.prepare_element(callback) - tds = extract_html_to_array(@element.find("td")) - expect(tds).toEqual ["a", "b", "c", "d"] + it "shows a subsection of pages if maximum pages is smaller than total pages", () -> + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.max_pages, 3) + ) - it "allows to set the sort context to page", () -> - comp = new TemplateCompiler("pagination/sort_context_page.html") - @element = comp.prepare_element(callback) - tds = extract_html_to_array(@element.find("td")) - expect(tds).toEqual ["b", "c", "d", "f"] + expect(@gui.pagination.pages).toEqual([1, 2, 3]) + expect(@gui.pagination.representation).toEqual( + [ 'First', '«', '‹', '1', '2', '3', '›', '»', 'Last' ]) diff --git a/test/templates/pagination/complete_config_parameterized.html b/test/templates/pagination/complete_config_parameterized.html new file mode 100644 index 0000000..676e7c3 --- /dev/null +++ b/test/templates/pagination/complete_config_parameterized.html @@ -0,0 +1,22 @@ +
    +
    + + + + + + +
    + + diff --git a/test/test_helper.coffee b/test/test_helper.coffee index 8ad60dd..b6a619c 100644 --- a/test/test_helper.coffee +++ b/test/test_helper.coffee @@ -16,7 +16,14 @@ extract_pagination_to_array = (elements) -> angular.element(element).find("a").html() for element in elements +class ScopeWrapper + constructor: (@scope) -> + set: (expression, value) -> + @scope.$eval("#{expression}=#{value}") + + get: (expression) -> + $scope.$eval("#{expression}") class TemplateCompiler constructor: (template_name) -> @@ -88,17 +95,16 @@ class PaginationGUI @reload() class GUI - constructor: (@element, scope) -> + constructor: (@element, @scope, @variable_names) -> @pagination = new PaginationGUI(@element) @table = new TableGUI(@element) - @scope = scope reload: () -> @table.reload() @pagination.reload() alter_scope: (f) -> - f(@scope) + f(new ScopeWrapper(@scope), @variable_names) @scope.$digest() @reload() @@ -110,4 +116,11 @@ click = (el) -> ev = document.createEvent("MouseEvent") ev.initMouseEvent "click", true, true, window, null, 0, 0, 0, 0, false, false, false, false, 0, null el.dispatchEvent ev - return \ No newline at end of file + return + +# currently untested +# - jump back/ahead buttons +# - enabled/disabled buttons +# - interactive table (removing/adding elements) +# - sort context +# - fill last page \ No newline at end of file From c350587289c6d93d6fa1b540acf7e875f281f811 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 21 Feb 2014 12:15:46 +0100 Subject: [PATCH 090/190] consistent formatting --- test/test_helper.coffee | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/test_helper.coffee b/test/test_helper.coffee index b6a619c..77bc677 100644 --- a/test/test_helper.coffee +++ b/test/test_helper.coffee @@ -54,7 +54,6 @@ class TemplateCompiler return element class TableGUI - constructor: (@element) -> @reload() @@ -68,7 +67,6 @@ class TableGUI class PaginationGUI - constructor: (@element) -> @reload() From 19527c45a2b0d356309f763375bf59ea24df23aa Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 21 Feb 2014 12:16:46 +0100 Subject: [PATCH 091/190] removed unused function --- test/test_helper.coffee | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/test_helper.coffee b/test/test_helper.coffee index 77bc677..01ba969 100644 --- a/test/test_helper.coffee +++ b/test/test_helper.coffee @@ -11,11 +11,6 @@ extract_html_to_array = (elements) -> angular.element(element).html() ) -extract_pagination_to_array = (elements) -> - elements = extract_visible_elements(elements) - angular.element(element).find("a").html() for element in elements - - class ScopeWrapper constructor: (@scope) -> From 3b8ec9d80e31112a5669fe82d5718d9edd4f9a0b Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 21 Feb 2014 14:43:06 +0100 Subject: [PATCH 092/190] new test --- test/pagination.coffee | 157 ++++++++++++++++++ .../complete_config_parameterized.html | 5 +- 2 files changed, 160 insertions(+), 2 deletions(-) diff --git a/test/pagination.coffee b/test/pagination.coffee index afd10b9..bb8a030 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -108,6 +108,49 @@ describe "angular-table", () -> expect(@gui.pagination.current_page).toEqual(3) expect(@gui.pagination.pages).toEqual([3, 4]) + it "allows to jump back and forth", () -> + expect(@gui.table.rows).toEqual([['a'], ['b'], ['c']]) + expect(@gui.pagination.current_page).toEqual(1) + expect(@gui.pagination.pages).toEqual([1, 2]) + + @gui.click_pagination(jump_ahead) + + expect(@gui.table.rows).toEqual([['g'], ['h'], ['i']]) + expect(@gui.pagination.current_page).toEqual(3) + expect(@gui.pagination.pages).toEqual([2, 3]) + + @gui.click_pagination(jump_ahead) + + # we reached the end of the pagination by now + + expect(@gui.table.rows).toEqual([['m'], [' '], [' ']]) + expect(@gui.pagination.current_page).toEqual(5) + expect(@gui.pagination.pages).toEqual([4, 5]) + + @gui.click_pagination(jump_ahead) + + expect(@gui.table.rows).toEqual([['m'], [' '], [' ']]) + expect(@gui.pagination.current_page).toEqual(5) + expect(@gui.pagination.pages).toEqual([4, 5]) + + @gui.click_pagination(step_back) + + expect(@gui.table.rows).toEqual([['j'], ['k'], ['l']]) + expect(@gui.pagination.current_page).toEqual(4) + expect(@gui.pagination.pages).toEqual([4, 5]) + + @gui.click_pagination(jump_back) + + expect(@gui.table.rows).toEqual([['d'], ['e'], ['f']]) + expect(@gui.pagination.current_page).toEqual(2) + expect(@gui.pagination.pages).toEqual([2, 3]) + + @gui.click_pagination(jump_back) + + expect(@gui.table.rows).toEqual([['a'], ['b'], ['c']]) + expect(@gui.pagination.current_page).toEqual(1) + expect(@gui.pagination.pages).toEqual([1, 2]) + describe "the maximum pages setting", () -> for val in [undefined, null] it "shows all pages if max_pages is undefined or null", () -> @@ -128,3 +171,117 @@ describe "angular-table", () -> expect(@gui.pagination.pages).toEqual([1, 2, 3]) expect(@gui.pagination.representation).toEqual( [ 'First', '«', '‹', '1', '2', '3', '›', '»', 'Last' ]) + + describe "heavy interaction", () -> + it "does stuff", () -> + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.items_per_page, 5) + scope_wrapper.set(vars.max_pages, 4) + ) + + @gui.click_pagination(step_ahead) + + expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.table.rows).toEqual([['f'], ['g'], ['h'], ['i'], ['j']]) + expect(@gui.pagination.pages).toEqual([1, 2, 3]) + + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.max_pages, 2) + ) + + expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.table.rows).toEqual([['f'], ['g'], ['h'], ['i'], ['j']]) + expect(@gui.pagination.pages).toEqual([1, 2]) + + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.max_pages, 1) + ) + + expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.table.rows).toEqual([['f'], ['g'], ['h'], ['i'], ['j']]) + expect(@gui.pagination.pages).toEqual([2]) + + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.items_per_page, 2) + ) + + expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.table.rows).toEqual([['c'], ['d']]) + expect(@gui.pagination.pages).toEqual([2]) + + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.items_per_page, 3) + ) + + expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.table.rows).toEqual([['d'], ['e'], ['f']]) + expect(@gui.pagination.pages).toEqual([2]) + + @gui.click_pagination(step_ahead) + + expect(@gui.pagination.current_page).toEqual 3 + expect(@gui.table.rows).toEqual([['g'], ['h'], ['i']]) + expect(@gui.pagination.pages).toEqual([3]) + + @gui.click_pagination(step_ahead) + @gui.click_pagination(step_ahead) + + expect(@gui.table.rows).toEqual([['m'], [' '], [' ']]) + expect(@gui.pagination.current_page).toEqual(5) + expect(@gui.pagination.pages).toEqual([5]) + + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.max_pages, 3) + ) + + expect(@gui.table.rows).toEqual([['m'], [' '], [' ']]) + expect(@gui.pagination.current_page).toEqual(5) + expect(@gui.pagination.pages).toEqual([3, 4, 5]) + + @gui.click_pagination(jump_back) + + expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.table.rows).toEqual([['d'], ['e'], ['f']]) + expect(@gui.pagination.pages).toEqual([2, 3, 4]) + + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.max_pages, 4) + ) + + expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.table.rows).toEqual([['d'], ['e'], ['f']]) + expect(@gui.pagination.pages).toEqual([2, 3, 4, 5]) + + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.items_per_page, 6) + ) + + expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.table.rows).toEqual([['g'], ['h'], ['i'], ['j'], ['k'], ['l']]) + expect(@gui.pagination.pages).toEqual([1, 2, 3]) + + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.items_per_page, 2) + scope_wrapper.set(vars.max_pages, 2) + ) + + @gui.click_pagination(jump_ahead) + + expect(@gui.pagination.current_page).toEqual 4 + + @gui.click_pagination(jump_ahead) + + expect(@gui.pagination.current_page).toEqual 6 + + @gui.click_pagination(jump_ahead) + + expect(@gui.pagination.current_page).toEqual 7 + + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.items_per_page, 6) + scope_wrapper.set(vars.max_pages, 4) + ) + + expect(@gui.table.rows).toEqual([['m'], [' '], [' '], [' '], [' '], [' ']]) + expect(@gui.pagination.current_page).toEqual(3) + expect(@gui.pagination.pages).toEqual([1, 2, 3]) \ No newline at end of file diff --git a/test/templates/pagination/complete_config_parameterized.html b/test/templates/pagination/complete_config_parameterized.html index 676e7c3..b692a4a 100644 --- a/test/templates/pagination/complete_config_parameterized.html +++ b/test/templates/pagination/complete_config_parameterized.html @@ -1,14 +1,15 @@
    From 0743ceec348370d5306ad77ff7aca4afc85aad91 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Fri, 21 Feb 2014 14:44:10 +0100 Subject: [PATCH 093/190] compiled new version --- angular-table.js | 8 ++------ angular-table.min.js | 2 +- gem/app/assets/javascripts/angular-table.js | 8 ++------ 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/angular-table.js b/angular-table.js index fc65f00..778d2ad 100644 --- a/angular-table.js +++ b/angular-table.js @@ -3,7 +3,7 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var AngularTableManager, ColumnConfiguration, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, erk_attribute, erk_current_page, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, + var AngularTableManager, ColumnConfiguration, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, erk_attribute, erk_current_page, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, irk_number_of_pages, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -349,7 +349,7 @@ }; update_stuff = function() { var nop; - $scope.sorted_and_paginated_list = get_sorted_and_paginated_list(w.get_list(), w.get_current_page(), w.get_items_per_page(), $scope[tc.sort_context], $scope.predicate, $scope.descending, $filter); + $scope.sorted_and_paginated_list = get_sorted_and_paginated_list(w.get_list(), w.get_current_page(), w.get_items_per_page(), w.get_sort_context(), $scope.predicate, $scope.descending, $filter); nop = Math.ceil(w.get_list().length / w.get_items_per_page()); return $scope.filler_array = get_filler_array(w.get_list(), w.get_current_page(), nop, w.get_items_per_page()); }; @@ -459,10 +459,6 @@ angular.module("angular-table", []); - irk_from_page = "from_page"; - - irk_current_page = "current_page"; - irk_number_of_pages = "number_of_pages"; erk_list = "atList"; diff --git a/angular-table.min.js b/angular-table.min.js index 5f8ebf0..d1fc118 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,u,l,p,c,g,_,h,f,d,m,b,v,y,w={}.hasOwnProperty,x=function(t,e){function i(){this.constructor=t}for(var n in e)w.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),u=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[h],this.attributes[_]&&this.register_items_per_page(this.attributes[_]),this.register_sort_context(this.attributes[d]),this.register_fill_last_page(this.attributes[c]),this.register_max_pages(this.attributes[f]),this.register_current_page(this.attributes[p]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.register_current_page=function(t){return void 0!==t?isNaN(t)?this.current_page=t:(this.current_page=""+this.id+"_currentPage",this.initial_current_page=parseInt(t)):(this.current_page=""+this.id+"_currentPage",this.initial_current_page=0)},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,u,l,p;for(i=[],p=t.find("td"),u=0,l=p.length;l>u;u++)a=p[u],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),a=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),o=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return x(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(a),n=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return x(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(t,e,i,n){var a,o,s,u,l;return s=this.table_configuration,l=new r(t,s),o=function(t,e,i,n,r,a,o){var s,u;return t?(u=t,s=i*e-t.length,"global"===n?(u=o("orderBy")(u,r,a),u=o("limitTo")(u,s),u=o("limitTo")(u,i)):(u=o("limitTo")(u,s),u=o("limitTo")(u,i),u=o("orderBy")(u,r,a)),u):[]},a=function(t,e,i,n){var r,a,o,s,u,l,p;if(n=parseInt(n),e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,p=[],o=s=u=t.length,l=t.length+r;l>=u?l>=s:s>=l;o=l>=u?++s:--s)p.push(o);return p}return[]}},u=function(){var e;return t.sorted_and_paginated_list=o(l.get_list(),l.get_current_page(),l.get_items_per_page(),t[s.sort_context],t.predicate,t.descending,n),e=Math.ceil(l.get_list().length/l.get_items_per_page()),t.filler_array=a(l.get_list(),l.get_current_page(),e,l.get_items_per_page())},t.$watch(s.current_page,function(){return u()}),t.$watch(s.items_per_page,function(){return u()}),t.$watch(""+s.list+".length",function(){return t[y]=Math.ceil(t[s.list].length/l.get_items_per_page()),u()}),t.$watch("predicate",function(){return u()}),t.$watch("descending",function(){return u()})},e}(a),s=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new n(this.table_configuration):new o(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),v="from_page",b="current_page",y="number_of_pages",h="atList",_="atItemsPerPage",c="atFillLastPage",d="atSortContext",f="atMaxPages",p="atCurrentPage",l="at-attribute",m="at-sortable",g="at-initial-sorting",r=function(){function t(t,e){this.scope=t,this.config=e}return t.prototype.get_list=function(){return this.scope.$eval(this.config.list)},t.prototype.get_items_per_page=function(){return this.scope.$eval(this.config.items_per_page)},t.prototype.get_current_page=function(){return this.scope.$eval(this.config.current_page)},t.prototype.get_max_pages=function(){return this.scope.$eval(this.config.max_pages)},t.prototype.get_sort_context=function(){return this.scope.$eval(this.config.sort_context)},t}(),t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages&&(e.$parent[i.max_pages]=i.initial_max_pages),void 0!==i.initial_current_page?e.$parent[i.current_page]=i.initial_current_page:void 0},t.prototype.register_pagination_scope=function(){},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,a;return a=new u(i,n),e.register_table(a),r=new s(i,a),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),i=function(){function t(t,e,i,n){if(this.lower_bound=null!=t?t:0,this.upper_bound=null!=e?e:1,null==i&&(i=0),this.length=null!=n?n:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(i)}return t.prototype.generate=function(t){var e,i,n,r;for(t>this.upper_bound-this.length?t=this.upper_bound-this.length:t=t?n>=i:i>=n;e=n>=t?++i:--i)r.push(e);return r},t.prototype.reset_parameters=function(t,e,i){if(this.lower_bound=t,this.upper_bound=e,this.length=i,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},t.prototype.relocate=function(t){var e;return e=this.data[0]+t,this.data=this.generate(e,e+this.length)},t.prototype.realign_greedy=function(t){var e;return tthis.data[this.length-1]?(e=t-(this.length-1),this.data=this.generate(e)):void 0},t.prototype.realign_generous=function(){},t}(),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,n,a){var o,s,u,l,p,c,g;return p=t.get_table_configuration(a.atTableId),g=new r(e,p),e.page_sequence=new i,u=function(t){return e.$parent.$eval(""+p.current_page+"="+t)},o=function(){return e[y]},l=function(t){return e[y]=t},c=function(){var t,i;return e[p.list]?e[p.list].length>0?(t=Math.ceil(e[p.list].length/g.get_items_per_page()),l(t),i=e.show_sectioning()?g.get_max_pages():t,e.page_sequence.reset_parameters(0,t,i),e.page_sequence.realign_greedy(g.get_current_page()),u(s(g.get_current_page(),0,o()-1))):(l(1),e.pages=[0]):void 0},s=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return g.get_max_pages()&&o()>g.get_max_pages()},e.get_current_page=function(){return g.get_current_page()},e.step_page=function(t){return t=parseInt(t),u(s(g.get_current_page()+t,0,o()-1)),e.page_sequence.realign_greedy(g.get_current_page())},e.go_to_page=function(t){return u(t)},e.jump_back=function(){return e.step_page(-g.get_max_pages())},e.jump_ahead=function(){return e.step_page(g.get_max_pages())},c(),e.$watch(p.items_per_page,function(){return c()}),e.$watch(p.max_pages,function(){return c()}),e.$watch(p.list,function(){return c()}),e.$watch(""+p.list+".length",function(){return c()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var t,e,i,n,r,a,o,s,u,l,p,c,g,_,h,f,d,m,b,v={}.hasOwnProperty,y=function(t,e){function i(){this.constructor=t}for(var n in e)v.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),u=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[h],this.attributes[_]&&this.register_items_per_page(this.attributes[_]),this.register_sort_context(this.attributes[d]),this.register_fill_last_page(this.attributes[c]),this.register_max_pages(this.attributes[f]),this.register_current_page(this.attributes[p]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.register_current_page=function(t){return void 0!==t?isNaN(t)?this.current_page=t:(this.current_page=""+this.id+"_currentPage",this.initial_current_page=parseInt(t)):(this.current_page=""+this.id+"_currentPage",this.initial_current_page=0)},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,u,l,p;for(i=[],p=t.find("td"),u=0,l=p.length;l>u;u++)a=p[u],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),a=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),o=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return y(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(a),n=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return y(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(t,e,i,n){var a,o,s,u,l;return s=this.table_configuration,l=new r(t,s),o=function(t,e,i,n,r,a,o){var s,u;return t?(u=t,s=i*e-t.length,"global"===n?(u=o("orderBy")(u,r,a),u=o("limitTo")(u,s),u=o("limitTo")(u,i)):(u=o("limitTo")(u,s),u=o("limitTo")(u,i),u=o("orderBy")(u,r,a)),u):[]},a=function(t,e,i,n){var r,a,o,s,u,l,p;if(n=parseInt(n),e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,p=[],o=s=u=t.length,l=t.length+r;l>=u?l>=s:s>=l;o=l>=u?++s:--s)p.push(o);return p}return[]}},u=function(){var e;return t.sorted_and_paginated_list=o(l.get_list(),l.get_current_page(),l.get_items_per_page(),l.get_sort_context(),t.predicate,t.descending,n),e=Math.ceil(l.get_list().length/l.get_items_per_page()),t.filler_array=a(l.get_list(),l.get_current_page(),e,l.get_items_per_page())},t.$watch(s.current_page,function(){return u()}),t.$watch(s.items_per_page,function(){return u()}),t.$watch(""+s.list+".length",function(){return t[b]=Math.ceil(t[s.list].length/l.get_items_per_page()),u()}),t.$watch("predicate",function(){return u()}),t.$watch("descending",function(){return u()})},e}(a),s=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new n(this.table_configuration):new o(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),b="number_of_pages",h="atList",_="atItemsPerPage",c="atFillLastPage",d="atSortContext",f="atMaxPages",p="atCurrentPage",l="at-attribute",m="at-sortable",g="at-initial-sorting",r=function(){function t(t,e){this.scope=t,this.config=e}return t.prototype.get_list=function(){return this.scope.$eval(this.config.list)},t.prototype.get_items_per_page=function(){return this.scope.$eval(this.config.items_per_page)},t.prototype.get_current_page=function(){return this.scope.$eval(this.config.current_page)},t.prototype.get_max_pages=function(){return this.scope.$eval(this.config.max_pages)},t.prototype.get_sort_context=function(){return this.scope.$eval(this.config.sort_context)},t}(),t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages&&(e.$parent[i.max_pages]=i.initial_max_pages),void 0!==i.initial_current_page?e.$parent[i.current_page]=i.initial_current_page:void 0},t.prototype.register_pagination_scope=function(){},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,a;return a=new u(i,n),e.register_table(a),r=new s(i,a),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),i=function(){function t(t,e,i,n){if(this.lower_bound=null!=t?t:0,this.upper_bound=null!=e?e:1,null==i&&(i=0),this.length=null!=n?n:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(i)}return t.prototype.generate=function(t){var e,i,n,r;for(t>this.upper_bound-this.length?t=this.upper_bound-this.length:t=t?n>=i:i>=n;e=n>=t?++i:--i)r.push(e);return r},t.prototype.reset_parameters=function(t,e,i){if(this.lower_bound=t,this.upper_bound=e,this.length=i,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},t.prototype.relocate=function(t){var e;return e=this.data[0]+t,this.data=this.generate(e,e+this.length)},t.prototype.realign_greedy=function(t){var e;return tthis.data[this.length-1]?(e=t-(this.length-1),this.data=this.generate(e)):void 0},t.prototype.realign_generous=function(){},t}(),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,n,a){var o,s,u,l,p,c,g;return p=t.get_table_configuration(a.atTableId),g=new r(e,p),e.page_sequence=new i,u=function(t){return e.$parent.$eval(""+p.current_page+"="+t)},o=function(){return e[b]},l=function(t){return e[b]=t},c=function(){var t,i;return e[p.list]?e[p.list].length>0?(t=Math.ceil(e[p.list].length/g.get_items_per_page()),l(t),i=e.show_sectioning()?g.get_max_pages():t,e.page_sequence.reset_parameters(0,t,i),e.page_sequence.realign_greedy(g.get_current_page()),u(s(g.get_current_page(),0,o()-1))):(l(1),e.pages=[0]):void 0},s=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return g.get_max_pages()&&o()>g.get_max_pages()},e.get_current_page=function(){return g.get_current_page()},e.step_page=function(t){return t=parseInt(t),u(s(g.get_current_page()+t,0,o()-1)),e.page_sequence.realign_greedy(g.get_current_page())},e.go_to_page=function(t){return u(t)},e.jump_back=function(){return e.step_page(-g.get_max_pages())},e.jump_ahead=function(){return e.step_page(g.get_max_pages())},c(),e.$watch(p.items_per_page,function(){return c()}),e.$watch(p.max_pages,function(){return c()}),e.$watch(p.list,function(){return c()}),e.$watch(""+p.list+".length",function(){return c()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index fc65f00..778d2ad 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -3,7 +3,7 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var AngularTableManager, ColumnConfiguration, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, erk_attribute, erk_current_page, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, irk_current_page, irk_from_page, irk_number_of_pages, + var AngularTableManager, ColumnConfiguration, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, erk_attribute, erk_current_page, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, irk_number_of_pages, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; @@ -349,7 +349,7 @@ }; update_stuff = function() { var nop; - $scope.sorted_and_paginated_list = get_sorted_and_paginated_list(w.get_list(), w.get_current_page(), w.get_items_per_page(), $scope[tc.sort_context], $scope.predicate, $scope.descending, $filter); + $scope.sorted_and_paginated_list = get_sorted_and_paginated_list(w.get_list(), w.get_current_page(), w.get_items_per_page(), w.get_sort_context(), $scope.predicate, $scope.descending, $filter); nop = Math.ceil(w.get_list().length / w.get_items_per_page()); return $scope.filler_array = get_filler_array(w.get_list(), w.get_current_page(), nop, w.get_items_per_page()); }; @@ -459,10 +459,6 @@ angular.module("angular-table", []); - irk_from_page = "from_page"; - - irk_current_page = "current_page"; - irk_number_of_pages = "number_of_pages"; erk_list = "atList"; From 1f6c1fb90f53ed863f7baa27ec442e6b49222836 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 22 Feb 2014 17:17:12 +0100 Subject: [PATCH 094/190] added test for sort context feature --- coffee/table/setup/paginated_setup.coffee | 4 +++ test/pagination.coffee | 30 ++++++++++++++++++++--- test/test_helper.coffee | 8 +++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/coffee/table/setup/paginated_setup.coffee b/coffee/table/setup/paginated_setup.coffee index 6583e8a..f55fa28 100644 --- a/coffee/table/setup/paginated_setup.coffee +++ b/coffee/table/setup/paginated_setup.coffee @@ -84,6 +84,10 @@ class PaginatedSetup extends Setup update_stuff() ) + $scope.$watch(tc.sort_context, () -> + update_stuff() + ) + $scope.$watch("#{tc.list}.length", () -> $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / w.get_items_per_page()) update_stuff() diff --git a/test/pagination.coffee b/test/pagination.coffee index bb8a030..b29face 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -13,14 +13,16 @@ describe "angular-table", () -> template: "pagination/complete_config_hardcoded.html" variable_names: { items_per_page: "completeConfigHardcoded_itemsPerPage", - max_pages: "completeConfigHardcoded_maxPages" + max_pages: "completeConfigHardcoded_maxPages", + sort_context: "completeConfigHardcoded_sortContext" } }, { template: "pagination/complete_config_parameterized.html" variable_names: { items_per_page: "config.my_items_per_page", - max_pages: "config.my_max_pages" + max_pages: "config.my_max_pages", + sort_context: "config.my_sort_context" } } ] @@ -33,7 +35,7 @@ describe "angular-table", () -> @element = @comp.prepare_element((scope) -> scope.list = [ - {name: "g"}, {name: "h"}, {name: "i"}, {name: "j"}, {name: "k"}, {name: "l"} + {name: "i"}, {name: "g"}, {name: "h"}, {name: "j"}, {name: "k"}, {name: "l"} {name: "a"}, {name: "b"}, {name: "c"}, {name: "d"}, {name: "e"}, {name: "f"}, {name: "m"} ] @@ -151,6 +153,28 @@ describe "angular-table", () -> expect(@gui.pagination.current_page).toEqual(1) expect(@gui.pagination.pages).toEqual([1, 2]) + it "allows to set a sort context", () -> + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.items_per_page, 4) + scope_wrapper.set(vars.sort_context, "'global'") + ) + + expect(@gui.table.rows).toEqual([['a'], ['b'], ['c'], ['d']]) + + @gui.table.sort(0) + + expect(@gui.table.rows).toEqual([['m'], ['l'], ['k'], ['j']]) + + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.sort_context, "'page'") + ) + + expect(@gui.table.rows).toEqual([['j'], ['i'], ['h'], ['g']]) + + @gui.table.sort(0) + + expect(@gui.table.rows).toEqual([['g'], ['h'], ['i'], ['j']]) + describe "the maximum pages setting", () -> for val in [undefined, null] it "shows all pages if max_pages is undefined or null", () -> diff --git a/test/test_helper.coffee b/test/test_helper.coffee index 01ba969..ff94f7c 100644 --- a/test/test_helper.coffee +++ b/test/test_helper.coffee @@ -18,7 +18,7 @@ class ScopeWrapper @scope.$eval("#{expression}=#{value}") get: (expression) -> - $scope.$eval("#{expression}") + @scope.$eval("#{expression}") class TemplateCompiler constructor: (template_name) -> @@ -60,6 +60,10 @@ class TableGUI ) @rows.shift() if @rows[0].length == 0 + sort: (i) -> + click(@element.find("th")[i]) + @reload() + class PaginationGUI constructor: (@element) -> @@ -112,8 +116,6 @@ click = (el) -> return # currently untested -# - jump back/ahead buttons # - enabled/disabled buttons # - interactive table (removing/adding elements) -# - sort context # - fill last page \ No newline at end of file From c3a343c495171c189ef1d8b20c04c074b0b324b0 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 24 Feb 2014 15:50:12 +0100 Subject: [PATCH 095/190] new test --- test/pagination.coffee | 49 ++++++++++++++++++++++++++++++++++++++++- test/test_helper.coffee | 1 - 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/test/pagination.coffee b/test/pagination.coffee index b29face..0d85311 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -197,7 +197,54 @@ describe "angular-table", () -> [ 'First', '«', '‹', '1', '2', '3', '›', '»', 'Last' ]) describe "heavy interaction", () -> - it "does stuff", () -> + it "updates when the length of the list changes", () -> + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.items_per_page, 3) + scope_wrapper.set(vars.max_pages, 2) + scope_wrapper.set("list", "[{name: 'z'}]") + ) + + expect(@gui.table.rows).toEqual [['z'], [' '], [' ']] + + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.get("list").push({name: 'a'}) + ) + + expect(@gui.table.rows).toEqual [['a'], ['z'], [' ']] + expect(@gui.pagination.representation).toEqual ['First', '‹', '1', '›', 'Last'] + expect(@gui.pagination.pages).toEqual [1] + + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.get("list").push({name: 'x'}) + scope_wrapper.get("list").push({name: 'b'}) + ) + + expect(@gui.table.rows).toEqual [['a'], ['b'], ['x']] + expect(@gui.pagination.representation).toEqual ['First', '‹', '1', '2', '›', 'Last'] + expect(@gui.pagination.pages).toEqual [1, 2] + + @gui.click_pagination(2) + + expect(@gui.table.rows).toEqual [['z'], [' '], [' ']] + + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.get("list").push({name: 'c'}) + scope_wrapper.get("list").push({name: 'y'}) + scope_wrapper.get("list").push({name: 'u'}) + ) + + expect(@gui.table.rows).toEqual [['u'], ['x'], ['y']] + expect(@gui.pagination.representation).toEqual( + [ 'First', '«', '‹', '1', '2', '›', '»', 'Last' ]) + + @gui.click_pagination(step_ahead) + + expect(@gui.table.rows).toEqual [['z'], [' '], [' ']] + expect(@gui.pagination.representation).toEqual( + [ 'First', '«', '‹', '2', '3', '›', '»', 'Last' ]) + + + it "updates when ever a configuration parameter changes", () -> @gui.alter_scope((scope_wrapper, vars) -> scope_wrapper.set(vars.items_per_page, 5) scope_wrapper.set(vars.max_pages, 4) diff --git a/test/test_helper.coffee b/test/test_helper.coffee index ff94f7c..176c51f 100644 --- a/test/test_helper.coffee +++ b/test/test_helper.coffee @@ -117,5 +117,4 @@ click = (el) -> # currently untested # - enabled/disabled buttons -# - interactive table (removing/adding elements) # - fill last page \ No newline at end of file From 98821a1ff2e54dceb26cc215133351ead23c62cf Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 24 Feb 2014 16:35:16 +0100 Subject: [PATCH 096/190] new test --- coffee/at-pagination.coffee | 8 ++++++-- coffee/table/setup/paginated_setup.coffee | 7 ++++--- test/pagination.coffee | 23 ++++++++++++++++++++--- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/coffee/at-pagination.coffee b/coffee/at-pagination.coffee index bbc3706..2d47de2 100644 --- a/coffee/at-pagination.coffee +++ b/coffee/at-pagination.coffee @@ -104,12 +104,16 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" pages_to_display = w.get_max_pages() else pages_to_display = new_number_of_pages + $scope.page_sequence.reset_parameters(0, new_number_of_pages, pages_to_display) - $scope.page_sequence.realign_greedy(w.get_current_page()) + # TODO warum ist die reihenfolge der folgenden beiden aufrufe irrelevant? set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)) + $scope.page_sequence.realign_greedy(w.get_current_page()) else set_number_of_pages(1) - $scope.pages = [0] + $scope.page_sequence.reset_parameters(0, 1, 1) + set_current_page(0) + $scope.page_sequence.realign_greedy(0) keep_in_bounds = (val, min, max) -> val = Math.max(min, val) diff --git a/coffee/table/setup/paginated_setup.coffee b/coffee/table/setup/paginated_setup.coffee index f55fa28..8a04baf 100644 --- a/coffee/table/setup/paginated_setup.coffee +++ b/coffee/table/setup/paginated_setup.coffee @@ -46,10 +46,11 @@ class PaginatedSetup extends Setup get_filler_array = (list, current_page, number_of_pages, items_per_page) -> items_per_page = parseInt(items_per_page) - - if current_page == number_of_pages - 1 + if list.length <= 0 + x for x in [0..items_per_page - 1] + else if current_page == number_of_pages - 1 itemCountOnLastPage = list.length % items_per_page - if itemCountOnLastPage != 0 || list.length == 0 + if itemCountOnLastPage != 0 fillerLength = items_per_page - itemCountOnLastPage - 1 x for x in [(list.length)..(list.length + fillerLength)] else diff --git a/test/pagination.coffee b/test/pagination.coffee index 0d85311..e3c18fc 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -14,7 +14,8 @@ describe "angular-table", () -> variable_names: { items_per_page: "completeConfigHardcoded_itemsPerPage", max_pages: "completeConfigHardcoded_maxPages", - sort_context: "completeConfigHardcoded_sortContext" + sort_context: "completeConfigHardcoded_sortContext", + fill_last_page: "completeConfigHardcoded_fillLastPage" } }, { @@ -22,7 +23,8 @@ describe "angular-table", () -> variable_names: { items_per_page: "config.my_items_per_page", max_pages: "config.my_max_pages", - sort_context: "config.my_sort_context" + sort_context: "config.my_sort_context", + fill_last_page: "config.my_fill_last_page" } } ] @@ -44,7 +46,6 @@ describe "angular-table", () -> @gui = new GUI(@element, @comp.scope, setup.variable_names) it "allows to select pages", () -> - expect(@gui.pagination.pages).toEqual([1, 2]) expect(@gui.pagination.current_page).toEqual(1) @@ -175,6 +176,22 @@ describe "angular-table", () -> expect(@gui.table.rows).toEqual([['g'], ['h'], ['i'], ['j']]) + it "shows an empty table if fill-last-page is true and the list is empty", () -> + @gui.click_pagination(2) + + expect(@gui.table.rows).toEqual [['d'], ['e'], ['f']] + expect(@gui.pagination.current_page).toEqual 2 + + @gui.alter_scope((scope_wrapper, vars) -> + scope_wrapper.set(vars.items_per_page, 3) + scope_wrapper.set(vars.fill_last_page, true) + scope_wrapper.set("list", "[]") + ) + + expect(@gui.table.rows).toEqual [[' '], [' '], [' ']] + expect(@gui.pagination.pages).toEqual [1] + expect(@gui.pagination.current_page).toEqual 1 + describe "the maximum pages setting", () -> for val in [undefined, null] it "shows all pages if max_pages is undefined or null", () -> From 6b9d3401759beaa10908fa282ff73f08afbf028c Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 24 Feb 2014 16:35:27 +0100 Subject: [PATCH 097/190] compiled new version --- angular-table.js | 31 ++++++++++++++------- angular-table.min.js | 2 +- gem/app/assets/javascripts/angular-table.js | 31 ++++++++++++++------- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/angular-table.js b/angular-table.js index 778d2ad..b814413 100644 --- a/angular-table.js +++ b/angular-table.js @@ -331,17 +331,23 @@ } }; get_filler_array = function(list, current_page, number_of_pages, items_per_page) { - var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; + var fillerLength, itemCountOnLastPage, x, _i, _j, _ref, _ref1, _ref2, _results, _results1; items_per_page = parseInt(items_per_page); - if (current_page === number_of_pages - 1) { + if (list.length <= 0) { + _results = []; + for (x = _i = 0, _ref = items_per_page - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { + _results.push(x); + } + return _results; + } else if (current_page === number_of_pages - 1) { itemCountOnLastPage = list.length % items_per_page; - if (itemCountOnLastPage !== 0 || list.length === 0) { + if (itemCountOnLastPage !== 0) { fillerLength = items_per_page - itemCountOnLastPage - 1; - _results = []; - for (x = _i = _ref = list.length, _ref1 = list.length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { - _results.push(x); + _results1 = []; + for (x = _j = _ref1 = list.length, _ref2 = list.length + fillerLength; _ref1 <= _ref2 ? _j <= _ref2 : _j >= _ref2; x = _ref1 <= _ref2 ? ++_j : --_j) { + _results1.push(x); } - return _results; + return _results1; } else { return []; } @@ -359,6 +365,9 @@ $scope.$watch(tc.items_per_page, function() { return update_stuff(); }); + $scope.$watch(tc.sort_context, function() { + return update_stuff(); + }); $scope.$watch("" + tc.list + ".length", function() { $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / w.get_items_per_page()); return update_stuff(); @@ -689,11 +698,13 @@ pages_to_display = new_number_of_pages; } $scope.page_sequence.reset_parameters(0, new_number_of_pages, pages_to_display); - $scope.page_sequence.realign_greedy(w.get_current_page()); - return set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); + set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); + return $scope.page_sequence.realign_greedy(w.get_current_page()); } else { set_number_of_pages(1); - return $scope.pages = [0]; + $scope.page_sequence.reset_parameters(0, 1, 1); + set_current_page(0); + return $scope.page_sequence.realign_greedy(0); } } }; diff --git a/angular-table.min.js b/angular-table.min.js index d1fc118..7429068 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,u,l,p,c,g,_,h,f,d,m,b,v={}.hasOwnProperty,y=function(t,e){function i(){this.constructor=t}for(var n in e)v.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),u=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[h],this.attributes[_]&&this.register_items_per_page(this.attributes[_]),this.register_sort_context(this.attributes[d]),this.register_fill_last_page(this.attributes[c]),this.register_max_pages(this.attributes[f]),this.register_current_page(this.attributes[p]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.register_current_page=function(t){return void 0!==t?isNaN(t)?this.current_page=t:(this.current_page=""+this.id+"_currentPage",this.initial_current_page=parseInt(t)):(this.current_page=""+this.id+"_currentPage",this.initial_current_page=0)},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,u,l,p;for(i=[],p=t.find("td"),u=0,l=p.length;l>u;u++)a=p[u],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),a=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),o=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return y(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(a),n=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return y(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(t,e,i,n){var a,o,s,u,l;return s=this.table_configuration,l=new r(t,s),o=function(t,e,i,n,r,a,o){var s,u;return t?(u=t,s=i*e-t.length,"global"===n?(u=o("orderBy")(u,r,a),u=o("limitTo")(u,s),u=o("limitTo")(u,i)):(u=o("limitTo")(u,s),u=o("limitTo")(u,i),u=o("orderBy")(u,r,a)),u):[]},a=function(t,e,i,n){var r,a,o,s,u,l,p;if(n=parseInt(n),e===i-1){if(a=t.length%n,0!==a||0===t.length){for(r=n-a-1,p=[],o=s=u=t.length,l=t.length+r;l>=u?l>=s:s>=l;o=l>=u?++s:--s)p.push(o);return p}return[]}},u=function(){var e;return t.sorted_and_paginated_list=o(l.get_list(),l.get_current_page(),l.get_items_per_page(),l.get_sort_context(),t.predicate,t.descending,n),e=Math.ceil(l.get_list().length/l.get_items_per_page()),t.filler_array=a(l.get_list(),l.get_current_page(),e,l.get_items_per_page())},t.$watch(s.current_page,function(){return u()}),t.$watch(s.items_per_page,function(){return u()}),t.$watch(""+s.list+".length",function(){return t[b]=Math.ceil(t[s.list].length/l.get_items_per_page()),u()}),t.$watch("predicate",function(){return u()}),t.$watch("descending",function(){return u()})},e}(a),s=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new n(this.table_configuration):new o(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),b="number_of_pages",h="atList",_="atItemsPerPage",c="atFillLastPage",d="atSortContext",f="atMaxPages",p="atCurrentPage",l="at-attribute",m="at-sortable",g="at-initial-sorting",r=function(){function t(t,e){this.scope=t,this.config=e}return t.prototype.get_list=function(){return this.scope.$eval(this.config.list)},t.prototype.get_items_per_page=function(){return this.scope.$eval(this.config.items_per_page)},t.prototype.get_current_page=function(){return this.scope.$eval(this.config.current_page)},t.prototype.get_max_pages=function(){return this.scope.$eval(this.config.max_pages)},t.prototype.get_sort_context=function(){return this.scope.$eval(this.config.sort_context)},t}(),t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages&&(e.$parent[i.max_pages]=i.initial_max_pages),void 0!==i.initial_current_page?e.$parent[i.current_page]=i.initial_current_page:void 0},t.prototype.register_pagination_scope=function(){},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,a;return a=new u(i,n),e.register_table(a),r=new s(i,a),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),i=function(){function t(t,e,i,n){if(this.lower_bound=null!=t?t:0,this.upper_bound=null!=e?e:1,null==i&&(i=0),this.length=null!=n?n:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(i)}return t.prototype.generate=function(t){var e,i,n,r;for(t>this.upper_bound-this.length?t=this.upper_bound-this.length:t=t?n>=i:i>=n;e=n>=t?++i:--i)r.push(e);return r},t.prototype.reset_parameters=function(t,e,i){if(this.lower_bound=t,this.upper_bound=e,this.length=i,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},t.prototype.relocate=function(t){var e;return e=this.data[0]+t,this.data=this.generate(e,e+this.length)},t.prototype.realign_greedy=function(t){var e;return tthis.data[this.length-1]?(e=t-(this.length-1),this.data=this.generate(e)):void 0},t.prototype.realign_generous=function(){},t}(),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,n,a){var o,s,u,l,p,c,g;return p=t.get_table_configuration(a.atTableId),g=new r(e,p),e.page_sequence=new i,u=function(t){return e.$parent.$eval(""+p.current_page+"="+t)},o=function(){return e[b]},l=function(t){return e[b]=t},c=function(){var t,i;return e[p.list]?e[p.list].length>0?(t=Math.ceil(e[p.list].length/g.get_items_per_page()),l(t),i=e.show_sectioning()?g.get_max_pages():t,e.page_sequence.reset_parameters(0,t,i),e.page_sequence.realign_greedy(g.get_current_page()),u(s(g.get_current_page(),0,o()-1))):(l(1),e.pages=[0]):void 0},s=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return g.get_max_pages()&&o()>g.get_max_pages()},e.get_current_page=function(){return g.get_current_page()},e.step_page=function(t){return t=parseInt(t),u(s(g.get_current_page()+t,0,o()-1)),e.page_sequence.realign_greedy(g.get_current_page())},e.go_to_page=function(t){return u(t)},e.jump_back=function(){return e.step_page(-g.get_max_pages())},e.jump_ahead=function(){return e.step_page(g.get_max_pages())},c(),e.$watch(p.items_per_page,function(){return c()}),e.$watch(p.max_pages,function(){return c()}),e.$watch(p.list,function(){return c()}),e.$watch(""+p.list+".length",function(){return c()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var t,e,i,n,r,a,o,s,u,l,p,c,g,_,h,f,d,m,b,v={}.hasOwnProperty,y=function(t,e){function i(){this.constructor=t}for(var n in e)v.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),u=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[h],this.attributes[_]&&this.register_items_per_page(this.attributes[_]),this.register_sort_context(this.attributes[d]),this.register_fill_last_page(this.attributes[c]),this.register_max_pages(this.attributes[f]),this.register_current_page(this.attributes[p]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.register_current_page=function(t){return void 0!==t?isNaN(t)?this.current_page=t:(this.current_page=""+this.id+"_currentPage",this.initial_current_page=parseInt(t)):(this.current_page=""+this.id+"_currentPage",this.initial_current_page=0)},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,u,l,p;for(i=[],p=t.find("td"),u=0,l=p.length;l>u;u++)a=p[u],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),a=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),o=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return y(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(a),n=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return y(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+="";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(t,e,i,n){var a,o,s,u,l;return s=this.table_configuration,l=new r(t,s),o=function(t,e,i,n,r,a,o){var s,u;return t?(u=t,s=i*e-t.length,"global"===n?(u=o("orderBy")(u,r,a),u=o("limitTo")(u,s),u=o("limitTo")(u,i)):(u=o("limitTo")(u,s),u=o("limitTo")(u,i),u=o("orderBy")(u,r,a)),u):[]},a=function(t,e,i,n){var r,a,o,s,u,l,p,c,g,_;if(n=parseInt(n),t.length<=0){for(g=[],o=s=0,l=n-1;l>=0?l>=s:s>=l;o=l>=0?++s:--s)g.push(o);return g}if(e===i-1){if(a=t.length%n,0!==a){for(r=n-a-1,_=[],o=u=p=t.length,c=t.length+r;c>=p?c>=u:u>=c;o=c>=p?++u:--u)_.push(o);return _}return[]}},u=function(){var e;return t.sorted_and_paginated_list=o(l.get_list(),l.get_current_page(),l.get_items_per_page(),l.get_sort_context(),t.predicate,t.descending,n),e=Math.ceil(l.get_list().length/l.get_items_per_page()),t.filler_array=a(l.get_list(),l.get_current_page(),e,l.get_items_per_page())},t.$watch(s.current_page,function(){return u()}),t.$watch(s.items_per_page,function(){return u()}),t.$watch(s.sort_context,function(){return u()}),t.$watch(""+s.list+".length",function(){return t[b]=Math.ceil(t[s.list].length/l.get_items_per_page()),u()}),t.$watch("predicate",function(){return u()}),t.$watch("descending",function(){return u()})},e}(a),s=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new n(this.table_configuration):new o(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),b="number_of_pages",h="atList",_="atItemsPerPage",c="atFillLastPage",d="atSortContext",f="atMaxPages",p="atCurrentPage",l="at-attribute",m="at-sortable",g="at-initial-sorting",r=function(){function t(t,e){this.scope=t,this.config=e}return t.prototype.get_list=function(){return this.scope.$eval(this.config.list)},t.prototype.get_items_per_page=function(){return this.scope.$eval(this.config.items_per_page)},t.prototype.get_current_page=function(){return this.scope.$eval(this.config.current_page)},t.prototype.get_max_pages=function(){return this.scope.$eval(this.config.max_pages)},t.prototype.get_sort_context=function(){return this.scope.$eval(this.config.sort_context)},t}(),t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages&&(e.$parent[i.max_pages]=i.initial_max_pages),void 0!==i.initial_current_page?e.$parent[i.current_page]=i.initial_current_page:void 0},t.prototype.register_pagination_scope=function(){},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,a;return a=new u(i,n),e.register_table(a),r=new s(i,a),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),i=function(){function t(t,e,i,n){if(this.lower_bound=null!=t?t:0,this.upper_bound=null!=e?e:1,null==i&&(i=0),this.length=null!=n?n:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(i)}return t.prototype.generate=function(t){var e,i,n,r;for(t>this.upper_bound-this.length?t=this.upper_bound-this.length:t=t?n>=i:i>=n;e=n>=t?++i:--i)r.push(e);return r},t.prototype.reset_parameters=function(t,e,i){if(this.lower_bound=t,this.upper_bound=e,this.length=i,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},t.prototype.relocate=function(t){var e;return e=this.data[0]+t,this.data=this.generate(e,e+this.length)},t.prototype.realign_greedy=function(t){var e;return tthis.data[this.length-1]?(e=t-(this.length-1),this.data=this.generate(e)):void 0},t.prototype.realign_generous=function(){},t}(),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,n,a){var o,s,u,l,p,c,g;return p=t.get_table_configuration(a.atTableId),g=new r(e,p),e.page_sequence=new i,u=function(t){return e.$parent.$eval(""+p.current_page+"="+t)},o=function(){return e[b]},l=function(t){return e[b]=t},c=function(){var t,i;return e[p.list]?e[p.list].length>0?(t=Math.ceil(e[p.list].length/g.get_items_per_page()),l(t),i=e.show_sectioning()?g.get_max_pages():t,e.page_sequence.reset_parameters(0,t,i),u(s(g.get_current_page(),0,o()-1)),e.page_sequence.realign_greedy(g.get_current_page())):(l(1),e.page_sequence.reset_parameters(0,1,1),u(0),e.page_sequence.realign_greedy(0)):void 0},s=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return g.get_max_pages()&&o()>g.get_max_pages()},e.get_current_page=function(){return g.get_current_page()},e.step_page=function(t){return t=parseInt(t),u(s(g.get_current_page()+t,0,o()-1)),e.page_sequence.realign_greedy(g.get_current_page())},e.go_to_page=function(t){return u(t)},e.jump_back=function(){return e.step_page(-g.get_max_pages())},e.jump_ahead=function(){return e.step_page(g.get_max_pages())},c(),e.$watch(p.items_per_page,function(){return c()}),e.$watch(p.max_pages,function(){return c()}),e.$watch(p.list,function(){return c()}),e.$watch(""+p.list+".length",function(){return c()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index 778d2ad..b814413 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -331,17 +331,23 @@ } }; get_filler_array = function(list, current_page, number_of_pages, items_per_page) { - var fillerLength, itemCountOnLastPage, x, _i, _ref, _ref1, _results; + var fillerLength, itemCountOnLastPage, x, _i, _j, _ref, _ref1, _ref2, _results, _results1; items_per_page = parseInt(items_per_page); - if (current_page === number_of_pages - 1) { + if (list.length <= 0) { + _results = []; + for (x = _i = 0, _ref = items_per_page - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { + _results.push(x); + } + return _results; + } else if (current_page === number_of_pages - 1) { itemCountOnLastPage = list.length % items_per_page; - if (itemCountOnLastPage !== 0 || list.length === 0) { + if (itemCountOnLastPage !== 0) { fillerLength = items_per_page - itemCountOnLastPage - 1; - _results = []; - for (x = _i = _ref = list.length, _ref1 = list.length + fillerLength; _ref <= _ref1 ? _i <= _ref1 : _i >= _ref1; x = _ref <= _ref1 ? ++_i : --_i) { - _results.push(x); + _results1 = []; + for (x = _j = _ref1 = list.length, _ref2 = list.length + fillerLength; _ref1 <= _ref2 ? _j <= _ref2 : _j >= _ref2; x = _ref1 <= _ref2 ? ++_j : --_j) { + _results1.push(x); } - return _results; + return _results1; } else { return []; } @@ -359,6 +365,9 @@ $scope.$watch(tc.items_per_page, function() { return update_stuff(); }); + $scope.$watch(tc.sort_context, function() { + return update_stuff(); + }); $scope.$watch("" + tc.list + ".length", function() { $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / w.get_items_per_page()); return update_stuff(); @@ -689,11 +698,13 @@ pages_to_display = new_number_of_pages; } $scope.page_sequence.reset_parameters(0, new_number_of_pages, pages_to_display); - $scope.page_sequence.realign_greedy(w.get_current_page()); - return set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); + set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); + return $scope.page_sequence.realign_greedy(w.get_current_page()); } else { set_number_of_pages(1); - return $scope.pages = [0]; + $scope.page_sequence.reset_parameters(0, 1, 1); + set_current_page(0); + return $scope.page_sequence.realign_greedy(0); } } }; From b3084a8e8ea18bc5cf1746fd220e24ccae4dbc55 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 24 Feb 2014 22:50:44 +0100 Subject: [PATCH 098/190] removed unused function --- coffee/at-pagination.coffee | 11 ++--------- coffee/at-table.coffee | 13 ------------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/coffee/at-pagination.coffee b/coffee/at-pagination.coffee index 2d47de2..78d4187 100644 --- a/coffee/at-pagination.coffee +++ b/coffee/at-pagination.coffee @@ -34,9 +34,9 @@ class PageSequence angular.module("angular-table").directive "atPagination", ["angularTableManager", (angularTableManager) -> { - replace: true restrict: "E" - + scope: true + replace: true template: "
      @@ -70,13 +70,6 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager"
    " - controller: ["$scope", "$element", "$attrs", - ($scope, $element, $attrs) -> - angularTableManager.register_pagination_scope($attrs.atTableId, $scope) - ] - - scope: true - link: ($scope, $element, $attributes) -> tc = angularTableManager.get_table_configuration($attributes.atTableId) diff --git a/coffee/at-table.coffee b/coffee/at-table.coffee index ada2f46..25020f8 100644 --- a/coffee/at-table.coffee +++ b/coffee/at-table.coffee @@ -75,19 +75,6 @@ class AngularTableManager if tc.initial_current_page isnt undefined scope.$parent[tc.current_page] = tc.initial_current_page - register_pagination_scope: (id, pagination_scope) -> - # mapping = @mappings[id] ||= {} - # mapping.pagination_scope = pagination_scope - - # if mapping.table_configuration - # pagination_scope.$watch(irk_current_page, () -> - # mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]) - # ) - - # pagination_scope.$watch(irk_number_of_pages, () -> - # mapping.table_scope.notify_change(pagination_scope[irk_current_page], pagination_scope[irk_number_of_pages]) - # ) - angular.module("angular-table").service "angularTableManager", [() -> new AngularTableManager() ] From ec7887072895ba3d238d83da3799936eaabd266b Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 24 Feb 2014 23:03:49 +0100 Subject: [PATCH 099/190] restructured files --- .../at_implicit.coffee} | 0 .../at_pagination.coffee} | 0 .../at_table.coffee} | 0 .../table/setup/paginated_setup.coffee | 0 coffee/{ => directives}/table/setup/setup.coffee | 0 .../table/setup/standard_setup.coffee | 0 coffee/{ => directives}/table/table.coffee | 0 karma.conf.js | 16 ++++++++-------- 8 files changed, 8 insertions(+), 8 deletions(-) rename coffee/{at-implicit.coffee => directives/at_implicit.coffee} (100%) rename coffee/{at-pagination.coffee => directives/at_pagination.coffee} (100%) rename coffee/{at-table.coffee => directives/at_table.coffee} (100%) rename coffee/{ => directives}/table/setup/paginated_setup.coffee (100%) rename coffee/{ => directives}/table/setup/setup.coffee (100%) rename coffee/{ => directives}/table/setup/standard_setup.coffee (100%) rename coffee/{ => directives}/table/table.coffee (100%) diff --git a/coffee/at-implicit.coffee b/coffee/directives/at_implicit.coffee similarity index 100% rename from coffee/at-implicit.coffee rename to coffee/directives/at_implicit.coffee diff --git a/coffee/at-pagination.coffee b/coffee/directives/at_pagination.coffee similarity index 100% rename from coffee/at-pagination.coffee rename to coffee/directives/at_pagination.coffee diff --git a/coffee/at-table.coffee b/coffee/directives/at_table.coffee similarity index 100% rename from coffee/at-table.coffee rename to coffee/directives/at_table.coffee diff --git a/coffee/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee similarity index 100% rename from coffee/table/setup/paginated_setup.coffee rename to coffee/directives/table/setup/paginated_setup.coffee diff --git a/coffee/table/setup/setup.coffee b/coffee/directives/table/setup/setup.coffee similarity index 100% rename from coffee/table/setup/setup.coffee rename to coffee/directives/table/setup/setup.coffee diff --git a/coffee/table/setup/standard_setup.coffee b/coffee/directives/table/setup/standard_setup.coffee similarity index 100% rename from coffee/table/setup/standard_setup.coffee rename to coffee/directives/table/setup/standard_setup.coffee diff --git a/coffee/table/table.coffee b/coffee/directives/table/table.coffee similarity index 100% rename from coffee/table/table.coffee rename to coffee/directives/table/table.coffee diff --git a/karma.conf.js b/karma.conf.js index 745b0d7..f347dfe 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -21,14 +21,14 @@ module.exports = function(config) { 'coffee/configuration/column_configuration.coffee', 'coffee/configuration/table_configuration.coffee', - 'coffee/table/setup/setup.coffee', - 'coffee/table/setup/standard_setup.coffee', - 'coffee/table/setup/paginated_setup.coffee', - 'coffee/table/table.coffee', - - 'coffee/at-table.coffee', - 'coffee/at-pagination.coffee', - 'coffee/at-implicit.coffee', + 'coffee/directives/table/setup/setup.coffee', + 'coffee/directives/table/setup/standard_setup.coffee', + 'coffee/directives/table/setup/paginated_setup.coffee', + 'coffee/directives/table/table.coffee', + + 'coffee/directives/at_table.coffee', + 'coffee/directives/at_pagination.coffee', + 'coffee/directives/at_implicit.coffee', 'test/test_helper.coffee', 'test/*.coffee', From 3ce90249a7184216d0868da37da7571ab81d5e6c Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 24 Feb 2014 23:20:07 +0100 Subject: [PATCH 100/190] split code into separate files --- coffee/angular_table.coffee | 64 +++++++++++++++ .../configuration/table_configuration.coffee | 12 +-- coffee/directives/at_pagination.coffee | 34 -------- coffee/directives/at_table.coffee | 81 ------------------- .../pagination/page_sequence.coffee | 33 ++++++++ karma.conf.js | 4 + 6 files changed, 107 insertions(+), 121 deletions(-) create mode 100644 coffee/angular_table.coffee create mode 100644 coffee/directives/pagination/page_sequence.coffee diff --git a/coffee/angular_table.coffee b/coffee/angular_table.coffee new file mode 100644 index 0000000..77d0c97 --- /dev/null +++ b/coffee/angular_table.coffee @@ -0,0 +1,64 @@ +class ScopeConfigWrapper + + constructor: (table_scope, table_configuration) -> + @scope = table_scope + @config = table_configuration + + get_list: () -> + @scope.$eval(@config.list) + + get_items_per_page: () -> + @scope.$eval(@config.items_per_page) + + get_current_page: () -> + @scope.$eval(@config.current_page) + + get_max_pages: () -> + @scope.$eval(@config.max_pages) + + get_sort_context: () -> + @scope.$eval(@config.sort_context) + +class AngularTableManager + + constructor: () -> + @mappings = {} + + get_table_configuration: (id) -> + @mappings[id].table_configuration + + register_table: (table_configuration) -> + mapping = @mappings[table_configuration.id] ||= {} + + mapping.table_configuration = table_configuration + + if mapping.pagination_scope + throw "pagination element before table element is going to be supported soon" + + register_table_scope: (id, scope, filter) -> + @mappings[id].table_scope = scope + + tc = @mappings[id].table_configuration + + if tc.initial_items_per_page + scope.$parent[tc.items_per_page] = tc.initial_items_per_page + + if tc.initial_sort_context + scope.$parent[tc.sort_context] = tc.initial_sort_context + + if tc.initial_fill_last_page + scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page + + if tc.initial_max_pages + scope.$parent[tc.max_pages] = tc.initial_max_pages + + if tc.initial_current_page isnt undefined + scope.$parent[tc.current_page] = tc.initial_current_page + +angular.module "angular-table", [] + +angular.module("angular-table").service "angularTableManager", [() -> + new AngularTableManager() +] + +irk_number_of_pages = "number_of_pages" diff --git a/coffee/configuration/table_configuration.coffee b/coffee/configuration/table_configuration.coffee index cb1590e..1f2632f 100644 --- a/coffee/configuration/table_configuration.coffee +++ b/coffee/configuration/table_configuration.coffee @@ -2,12 +2,12 @@ class TableConfiguration constructor: (@table_element, @attributes) -> @id = @attributes.id - @list = @attributes[erk_list] - @register_items_per_page(@attributes[erk_items_per_page]) if @attributes[erk_items_per_page] - @register_sort_context(@attributes[erk_sort_context]) - @register_fill_last_page(@attributes[erk_fill_last_page]) - @register_max_pages(@attributes[erk_max_pages]) - @register_current_page(@attributes[erk_current_page]) + @list = @attributes["atList"] + @register_items_per_page(@attributes["atItemsPerPage"]) if @attributes["atItemsPerPage"] + @register_sort_context(@attributes["atSortContext"]) + @register_fill_last_page(@attributes["atFillLastPage"]) + @register_max_pages(@attributes["atMaxPages"]) + @register_current_page(@attributes["atCurrentPage"]) @paginated = @items_per_page != undefined @create_column_configurations() diff --git a/coffee/directives/at_pagination.coffee b/coffee/directives/at_pagination.coffee index 78d4187..c82c51e 100644 --- a/coffee/directives/at_pagination.coffee +++ b/coffee/directives/at_pagination.coffee @@ -1,37 +1,3 @@ -class PageSequence - - generate: (start) -> - if start > (@upper_bound - @length) - start = @upper_bound - @length - else if start < @lower_bound - start = @lower_bound - x for x in [start..(parseInt(start) + parseInt(@length) - 1)] - - constructor: (@lower_bound = 0, @upper_bound = 1, start = 0, @length = 1) -> - throw "sequence is too long" if @length > (@upper_bound - @lower_bound) - @data = @generate(start) - - reset_parameters: (lower_bound, upper_bound, length) -> - @lower_bound = lower_bound - @upper_bound = upper_bound - @length = length - throw "sequence is too long" if @length > (@upper_bound - @lower_bound) - @data = @generate(@data[0]) - - relocate: (distance) -> - new_start = @data[0] + distance - @data = @generate(new_start, new_start + @length) - - realign_greedy: (page) -> - if page < @data[0] - new_start = page - @data = @generate(new_start) - else if page > @data[@length - 1] - new_start = page - (@length - 1) - @data = @generate(new_start) - - realign_generous: (page) -> - angular.module("angular-table").directive "atPagination", ["angularTableManager", (angularTableManager) -> { restrict: "E" diff --git a/coffee/directives/at_table.coffee b/coffee/directives/at_table.coffee index 25020f8..cb3ac49 100644 --- a/coffee/directives/at_table.coffee +++ b/coffee/directives/at_table.coffee @@ -1,84 +1,3 @@ -angular.module "angular-table", [] - -# internal reserved keywords -# irk_from_page = "from_page" # atTable -# irk_current_page = "current_page" # atTable (getFillerArray), atPagination -irk_number_of_pages = "number_of_pages" # atTable (getFillerArray), atPagination - -# external reserved keywords -# table -erk_list = "atList" -erk_items_per_page = "atItemsPerPage" -erk_fill_last_page = "atFillLastPage" -erk_sort_context = "atSortContext" -erk_max_pages = "atMaxPages" -erk_current_page = "atCurrentPage" -# column -erk_attribute = "at-attribute" -erk_sortable = "at-sortable" -erk_initial_sorting = "at-initial-sorting" - -class ScopeConfigWrapper - - constructor: (table_scope, table_configuration) -> - @scope = table_scope - @config = table_configuration - - get_list: () -> - @scope.$eval(@config.list) - - get_items_per_page: () -> - @scope.$eval(@config.items_per_page) - - get_current_page: () -> - @scope.$eval(@config.current_page) - - get_max_pages: () -> - @scope.$eval(@config.max_pages) - - get_sort_context: () -> - @scope.$eval(@config.sort_context) - -class AngularTableManager - - constructor: () -> - @mappings = {} - - get_table_configuration: (id) -> - @mappings[id].table_configuration - - register_table: (table_configuration) -> - mapping = @mappings[table_configuration.id] ||= {} - - mapping.table_configuration = table_configuration - - if mapping.pagination_scope - throw "WHOOPS" - - register_table_scope: (id, scope, filter) -> - @mappings[id].table_scope = scope - - tc = @mappings[id].table_configuration - - if tc.initial_items_per_page - scope.$parent[tc.items_per_page] = tc.initial_items_per_page - - if tc.initial_sort_context - scope.$parent[tc.sort_context] = tc.initial_sort_context - - if tc.initial_fill_last_page - scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page - - if tc.initial_max_pages - scope.$parent[tc.max_pages] = tc.initial_max_pages - - if tc.initial_current_page isnt undefined - scope.$parent[tc.current_page] = tc.initial_current_page - -angular.module("angular-table").service "angularTableManager", [() -> - new AngularTableManager() -] - angular.module("angular-table").directive "atTable", ["$filter", "angularTableManager", ($filter, angularTableManager) -> { restrict: "AC" diff --git a/coffee/directives/pagination/page_sequence.coffee b/coffee/directives/pagination/page_sequence.coffee new file mode 100644 index 0000000..993729a --- /dev/null +++ b/coffee/directives/pagination/page_sequence.coffee @@ -0,0 +1,33 @@ +class PageSequence + + constructor: (@lower_bound = 0, @upper_bound = 1, start = 0, @length = 1) -> + throw "sequence is too long" if @length > (@upper_bound - @lower_bound) + @data = @generate(start) + + generate: (start) -> + if start > (@upper_bound - @length) + start = @upper_bound - @length + else if start < @lower_bound + start = @lower_bound + x for x in [start..(parseInt(start) + parseInt(@length) - 1)] + + reset_parameters: (lower_bound, upper_bound, length) -> + @lower_bound = lower_bound + @upper_bound = upper_bound + @length = length + throw "sequence is too long" if @length > (@upper_bound - @lower_bound) + @data = @generate(@data[0]) + + relocate: (distance) -> + new_start = @data[0] + distance + @data = @generate(new_start, new_start + @length) + + realign_greedy: (page) -> + if page < @data[0] + new_start = page + @data = @generate(new_start) + else if page > @data[@length - 1] + new_start = page - (@length - 1) + @data = @generate(new_start) + + realign_generous: (page) -> diff --git a/karma.conf.js b/karma.conf.js index f347dfe..8215d88 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -18,6 +18,8 @@ module.exports = function(config) { 'http://code.angularjs.org/1.2.11/angular-mocks.js', 'http://underscorejs.org/underscore-min.js', + 'coffee/angular_table.coffee', + 'coffee/configuration/column_configuration.coffee', 'coffee/configuration/table_configuration.coffee', @@ -26,6 +28,8 @@ module.exports = function(config) { 'coffee/directives/table/setup/paginated_setup.coffee', 'coffee/directives/table/table.coffee', + 'coffee/directives/pagination/page_sequence.coffee', + 'coffee/directives/at_table.coffee', 'coffee/directives/at_pagination.coffee', 'coffee/directives/at_implicit.coffee', From 411d77925d4038c1a06769c965a2af5cceb07ff9 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 24 Feb 2014 23:31:28 +0100 Subject: [PATCH 101/190] removed css --- coffee/configuration/column_configuration.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/coffee/configuration/column_configuration.coffee b/coffee/configuration/column_configuration.coffee index e045253..e57b555 100644 --- a/coffee/configuration/column_configuration.coffee +++ b/coffee/configuration/column_configuration.coffee @@ -13,7 +13,6 @@ class ColumnConfiguration create_element: () -> th = angular.element(document.createElement("th")) - th.attr("style","cursor: pointer;") render_title: (element) -> element.html(@custom_content || @title) From 983a47da54ee941f813f1f3941c0122a3887d795 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Mon, 24 Feb 2014 23:31:40 +0100 Subject: [PATCH 102/190] applied new file structure --- Rakefile | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index 7f3a884..719c4a3 100644 --- a/Rakefile +++ b/Rakefile @@ -19,17 +19,21 @@ end def collect_coffees files = [ + "coffee/angular_table.coffee", + "coffee/configuration/column_configuration.coffee", "coffee/configuration/table_configuration.coffee", - "coffee/table/setup/setup.coffee", - "coffee/table/setup/standard_setup.coffee", - "coffee/table/setup/paginated_setup.coffee", - "coffee/table/table.coffee", + "coffee/directives/table/setup/setup.coffee", + "coffee/directives/table/setup/standard_setup.coffee", + "coffee/directives/table/setup/paginated_setup.coffee", + "coffee/directives/table/table.coffee", + + "coffee/directives/pagination/page_sequence.coffee", - "coffee/at-table.coffee", - "coffee/at-pagination.coffee", - "coffee/at-implicit.coffee", + "coffee/directives/at_table.coffee", + "coffee/directives/at_pagination.coffee", + "coffee/directives/at_implicit.coffee", ] script = "" files.each do |file| From 444c383da4e2dcd920d4af5e88de3f75efdc109c Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 25 Feb 2014 10:54:17 +0100 Subject: [PATCH 103/190] save three lines --- test/pagination.coffee | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/pagination.coffee b/test/pagination.coffee index e3c18fc..f1493b8 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -8,8 +8,7 @@ describe "angular-table", () -> first = 'First' last = 'Last' - setups = [ - { + setups = [{ template: "pagination/complete_config_hardcoded.html" variable_names: { items_per_page: "completeConfigHardcoded_itemsPerPage", @@ -17,8 +16,7 @@ describe "angular-table", () -> sort_context: "completeConfigHardcoded_sortContext", fill_last_page: "completeConfigHardcoded_fillLastPage" } - }, - { + }, { template: "pagination/complete_config_parameterized.html" variable_names: { items_per_page: "config.my_items_per_page", @@ -26,8 +24,7 @@ describe "angular-table", () -> sort_context: "config.my_sort_context", fill_last_page: "config.my_fill_last_page" } - } - ] + }] for setup in setups do (setup) -> @@ -45,6 +42,10 @@ describe "angular-table", () -> @gui = new GUI(@element, @comp.scope, setup.variable_names) + @gui.alter_scope (scope_wrapper, vars) -> + scope_wrapper.set("tableconfig", "{}") + + it "allows to select pages", () -> expect(@gui.pagination.pages).toEqual([1, 2]) expect(@gui.pagination.current_page).toEqual(1) From d3bad3bea587afff3cf54c5cc025e6dacf3a454c Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 25 Feb 2014 10:54:38 +0100 Subject: [PATCH 104/190] access list through wrapper --- coffee/directives/at_pagination.coffee | 6 +++--- coffee/directives/table/setup/paginated_setup.coffee | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/coffee/directives/at_pagination.coffee b/coffee/directives/at_pagination.coffee index c82c51e..741ca9e 100644 --- a/coffee/directives/at_pagination.coffee +++ b/coffee/directives/at_pagination.coffee @@ -53,10 +53,10 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" $scope[irk_number_of_pages] = number_of_pages update = (reset) -> - if $scope[tc.list] - if $scope[tc.list].length > 0 + if w.get_list() + if w.get_list().length > 0 # old_number_of_pages = get_number_of_pages() - new_number_of_pages = Math.ceil($scope[tc.list].length / w.get_items_per_page()) + new_number_of_pages = Math.ceil(w.get_list().length / w.get_items_per_page()) # if (old_number_of_pages != new_number_of_pages) set_number_of_pages(new_number_of_pages) if $scope.show_sectioning() diff --git a/coffee/directives/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee index 8a04baf..e471201 100644 --- a/coffee/directives/table/setup/paginated_setup.coffee +++ b/coffee/directives/table/setup/paginated_setup.coffee @@ -90,7 +90,7 @@ class PaginatedSetup extends Setup ) $scope.$watch("#{tc.list}.length", () -> - $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / w.get_items_per_page()) + $scope[irk_number_of_pages] = Math.ceil(w.get_list().length / w.get_items_per_page()) update_stuff() ) From 508888eeccdfd4d89400ae43458add4ce10a6c0a Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 25 Feb 2014 11:05:10 +0100 Subject: [PATCH 105/190] stringify objects --- test/pagination.coffee | 16 +++++++++++----- test/test_helper.coffee | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/pagination.coffee b/test/pagination.coffee index f1493b8..6ef539f 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -43,7 +43,13 @@ describe "angular-table", () -> @gui = new GUI(@element, @comp.scope, setup.variable_names) @gui.alter_scope (scope_wrapper, vars) -> - scope_wrapper.set("tableconfig", "{}") + config = { + my_items_per_page: 3, + my_max_pages: 2, + my_sort_context: 'global', + my_fill_last_page: true + } + scope_wrapper.set("tableconfig", {}) it "allows to select pages", () -> @@ -158,7 +164,7 @@ describe "angular-table", () -> it "allows to set a sort context", () -> @gui.alter_scope((scope_wrapper, vars) -> scope_wrapper.set(vars.items_per_page, 4) - scope_wrapper.set(vars.sort_context, "'global'") + scope_wrapper.set(vars.sort_context, "global") ) expect(@gui.table.rows).toEqual([['a'], ['b'], ['c'], ['d']]) @@ -168,7 +174,7 @@ describe "angular-table", () -> expect(@gui.table.rows).toEqual([['m'], ['l'], ['k'], ['j']]) @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.sort_context, "'page'") + scope_wrapper.set(vars.sort_context, "page") ) expect(@gui.table.rows).toEqual([['j'], ['i'], ['h'], ['g']]) @@ -186,7 +192,7 @@ describe "angular-table", () -> @gui.alter_scope((scope_wrapper, vars) -> scope_wrapper.set(vars.items_per_page, 3) scope_wrapper.set(vars.fill_last_page, true) - scope_wrapper.set("list", "[]") + scope_wrapper.set("list", []) ) expect(@gui.table.rows).toEqual [[' '], [' '], [' ']] @@ -219,7 +225,7 @@ describe "angular-table", () -> @gui.alter_scope((scope_wrapper, vars) -> scope_wrapper.set(vars.items_per_page, 3) scope_wrapper.set(vars.max_pages, 2) - scope_wrapper.set("list", "[{name: 'z'}]") + scope_wrapper.set("list", [{name: 'z'}]) ) expect(@gui.table.rows).toEqual [['z'], [' '], [' ']] diff --git a/test/test_helper.coffee b/test/test_helper.coffee index 176c51f..8dc938e 100644 --- a/test/test_helper.coffee +++ b/test/test_helper.coffee @@ -15,7 +15,7 @@ class ScopeWrapper constructor: (@scope) -> set: (expression, value) -> - @scope.$eval("#{expression}=#{value}") + @scope.$eval("#{expression}=#{JSON.stringify(value)}") get: (expression) -> @scope.$eval("#{expression}") From a9cdb99203dc33f0baf0c5171aee1ef4bad27552 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 25 Feb 2014 11:09:34 +0100 Subject: [PATCH 106/190] Merge branch 'refactor-settings' --- test/pagination.coffee | 16 +++++++++++----- test/test_helper.coffee | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/pagination.coffee b/test/pagination.coffee index f1493b8..6ef539f 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -43,7 +43,13 @@ describe "angular-table", () -> @gui = new GUI(@element, @comp.scope, setup.variable_names) @gui.alter_scope (scope_wrapper, vars) -> - scope_wrapper.set("tableconfig", "{}") + config = { + my_items_per_page: 3, + my_max_pages: 2, + my_sort_context: 'global', + my_fill_last_page: true + } + scope_wrapper.set("tableconfig", {}) it "allows to select pages", () -> @@ -158,7 +164,7 @@ describe "angular-table", () -> it "allows to set a sort context", () -> @gui.alter_scope((scope_wrapper, vars) -> scope_wrapper.set(vars.items_per_page, 4) - scope_wrapper.set(vars.sort_context, "'global'") + scope_wrapper.set(vars.sort_context, "global") ) expect(@gui.table.rows).toEqual([['a'], ['b'], ['c'], ['d']]) @@ -168,7 +174,7 @@ describe "angular-table", () -> expect(@gui.table.rows).toEqual([['m'], ['l'], ['k'], ['j']]) @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.sort_context, "'page'") + scope_wrapper.set(vars.sort_context, "page") ) expect(@gui.table.rows).toEqual([['j'], ['i'], ['h'], ['g']]) @@ -186,7 +192,7 @@ describe "angular-table", () -> @gui.alter_scope((scope_wrapper, vars) -> scope_wrapper.set(vars.items_per_page, 3) scope_wrapper.set(vars.fill_last_page, true) - scope_wrapper.set("list", "[]") + scope_wrapper.set("list", []) ) expect(@gui.table.rows).toEqual [[' '], [' '], [' ']] @@ -219,7 +225,7 @@ describe "angular-table", () -> @gui.alter_scope((scope_wrapper, vars) -> scope_wrapper.set(vars.items_per_page, 3) scope_wrapper.set(vars.max_pages, 2) - scope_wrapper.set("list", "[{name: 'z'}]") + scope_wrapper.set("list", [{name: 'z'}]) ) expect(@gui.table.rows).toEqual [['z'], [' '], [' ']] diff --git a/test/test_helper.coffee b/test/test_helper.coffee index 176c51f..8dc938e 100644 --- a/test/test_helper.coffee +++ b/test/test_helper.coffee @@ -15,7 +15,7 @@ class ScopeWrapper constructor: (@scope) -> set: (expression, value) -> - @scope.$eval("#{expression}=#{value}") + @scope.$eval("#{expression}=#{JSON.stringify(value)}") get: (expression) -> @scope.$eval("#{expression}") From c213d8419414b167b55073bef2fca1f346273a6d Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 26 Feb 2014 10:53:51 +0100 Subject: [PATCH 107/190] updated read me --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 7222d0c..58e4fda 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,3 @@ set up appropriate variables in your scope, prefixed with the id of the table, f - -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/samu/angular-table/trend.png)](https://bitdeli.com/free "Bitdeli Badge") - From b01cdd0f4b31ef537edae2fc7f4a1941ecf4cbd3 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 26 Feb 2014 13:40:25 +0100 Subject: [PATCH 108/190] refactored table configuration functionality --- coffee/angular_table.coffee | 76 ++++++++++++------- .../configuration/table_configuration.coffee | 65 +--------------- coffee/directives/at_pagination.coffee | 52 +++---------- coffee/directives/at_table.coffee | 11 +-- .../table/setup/paginated_setup.coffee | 17 ++--- .../table/setup/standard_setup.coffee | 4 +- coffee/directives/table/table.coffee | 6 +- test/header.coffee | 38 +++++----- test/pagination.coffee | 36 ++++----- test/sorting.coffee | 30 ++++---- .../complete_config_parameterized.html | 15 +--- 11 files changed, 126 insertions(+), 224 deletions(-) diff --git a/coffee/angular_table.coffee b/coffee/angular_table.coffee index 77d0c97..c03359e 100644 --- a/coffee/angular_table.coffee +++ b/coffee/angular_table.coffee @@ -1,23 +1,30 @@ +class ConfigurationVariableNames + constructor: (@config_object_name) -> + @items_per_page = "#{@config_object_name}.itemsPerPage" + @sort_context = "#{@config_object_name}.sortContext" + @fill_last_page = "#{@config_object_name}.fillLastPage" + @max_pages = "#{@config_object_name}.maxPages" + @current_page = "#{@config_object_name}.currentPage" + @list = "list" + class ScopeConfigWrapper - constructor: (table_scope, table_configuration) -> - @scope = table_scope - @config = table_configuration + constructor: (@scope, @configuration_variable_names) -> get_list: () -> - @scope.$eval(@config.list) + @scope.$eval("list") get_items_per_page: () -> - @scope.$eval(@config.items_per_page) + @scope.$eval(@configuration_variable_names.items_per_page) || 10 get_current_page: () -> - @scope.$eval(@config.current_page) + @scope.$eval(@configuration_variable_names.current_page) || 0 get_max_pages: () -> - @scope.$eval(@config.max_pages) + @scope.$eval(@configuration_variable_names.max_pages) || undefined get_sort_context: () -> - @scope.$eval(@config.sort_context) + @scope.$eval(@configuration_variable_names.sort_context) || 'global' class AngularTableManager @@ -29,36 +36,49 @@ class AngularTableManager register_table: (table_configuration) -> mapping = @mappings[table_configuration.id] ||= {} - mapping.table_configuration = table_configuration - if mapping.pagination_scope throw "pagination element before table element is going to be supported soon" - register_table_scope: (id, scope, filter) -> - @mappings[id].table_scope = scope +angular.module "angular-table", [] - tc = @mappings[id].table_configuration +angular.module("angular-table").service "angularTableManager", [() -> + new AngularTableManager() +] - if tc.initial_items_per_page - scope.$parent[tc.items_per_page] = tc.initial_items_per_page +irk_number_of_pages = "number_of_pages" - if tc.initial_sort_context - scope.$parent[tc.sort_context] = tc.initial_sort_context +pagination_template = " +
    +
      - if tc.initial_fill_last_page - scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page +
    • +First +
    • - if tc.initial_max_pages - scope.$parent[tc.max_pages] = tc.initial_max_pages +
    • +« +
    • - if tc.initial_current_page isnt undefined - scope.$parent[tc.current_page] = tc.initial_current_page +
    • + +
    • -angular.module "angular-table", [] +
    • +{{page + 1}} +
    • -angular.module("angular-table").service "angularTableManager", [() -> - new AngularTableManager() -] +
    • + +
    • -irk_number_of_pages = "number_of_pages" +
    • +» +
    • + +
    • +Last +
    • + +
    +
    " \ No newline at end of file diff --git a/coffee/configuration/table_configuration.coffee b/coffee/configuration/table_configuration.coffee index 1f2632f..b878e45 100644 --- a/coffee/configuration/table_configuration.coffee +++ b/coffee/configuration/table_configuration.coffee @@ -2,69 +2,10 @@ class TableConfiguration constructor: (@table_element, @attributes) -> @id = @attributes.id - @list = @attributes["atList"] - @register_items_per_page(@attributes["atItemsPerPage"]) if @attributes["atItemsPerPage"] - @register_sort_context(@attributes["atSortContext"]) - @register_fill_last_page(@attributes["atFillLastPage"]) - @register_max_pages(@attributes["atMaxPages"]) - @register_current_page(@attributes["atCurrentPage"]) - @paginated = @items_per_page != undefined - @create_column_configurations() + @config = @attributes.atConfig + @paginated = @attributes.atPaginated? - # TODO: refactor the following 4 methods into nicer, if-less logic - register_items_per_page: (items_per_page) -> - if isNaN(items_per_page) - @items_per_page = items_per_page - else - @items_per_page = "#{@id}_itemsPerPage" - @initial_items_per_page = parseInt(items_per_page) - - register_sort_context: (sort_context) -> - if sort_context != undefined - if sort_context == "global" - @sort_context = "#{@id}_sortContext" - @initial_sort_context = "global" - else if sort_context == "page" - @sort_context = "#{@id}_sortContext" - @initial_sort_context = "page" - else - @sort_context = sort_context - else - @sort_context = "#{@id}_sortContext" - @initial_sort_context = "global" - - register_fill_last_page: (fill_last_page) -> - if fill_last_page != undefined - if fill_last_page == "true" - @fill_last_page = "#{@id}_fillLastPage" - @initial_fill_last_page = true - else if fill_last_page == "false" - @fill_last_page = "#{@id}_fillLastPage" - @initial_fill_last_page = false - else if fill_last_page == "" - @fill_last_page = "#{@id}_fillLastPage" - @initial_fill_last_page = true - else - @fill_last_page = fill_last_page - - register_max_pages: (max_pages) -> - if max_pages isnt undefined - if isNaN(max_pages) - @max_pages = max_pages - else - @max_pages = "#{@id}_maxPages" - @initial_max_pages = parseInt(max_pages) - - register_current_page: (current_page) -> - if current_page isnt undefined - if isNaN(current_page) - @current_page = current_page - else - @current_page = "#{@id}_currentPage" - @initial_current_page = parseInt(current_page) - else - @current_page = "#{@id}_currentPage" - @initial_current_page = 0 + @create_column_configurations() capitaliseFirstLetter: (string) -> if string then string.charAt(0).toUpperCase() + string.slice(1) else "" diff --git a/coffee/directives/at_pagination.coffee b/coffee/directives/at_pagination.coffee index 741ca9e..fdb2adf 100644 --- a/coffee/directives/at_pagination.coffee +++ b/coffee/directives/at_pagination.coffee @@ -1,50 +1,18 @@ -angular.module("angular-table").directive "atPagination", ["angularTableManager", (angularTableManager) -> - { +angular.module("angular-table").directive "atPagination", [() -> { restrict: "E" scope: true replace: true - template: " -
    - -
    " + template: pagination_template link: ($scope, $element, $attributes) -> - tc = angularTableManager.get_table_configuration($attributes.atTableId) + cvn = new ConfigurationVariableNames($attributes.atConfig) - w = new ScopeConfigWrapper($scope, tc) + w = new ScopeConfigWrapper($scope, cvn) $scope.page_sequence = new PageSequence() set_current_page = (current_page) -> - $scope.$parent.$eval("#{tc.current_page}=#{current_page}") + $scope.$parent.$eval("#{cvn.current_page}=#{current_page}") get_number_of_pages = () -> $scope[irk_number_of_pages] @@ -55,9 +23,7 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" update = (reset) -> if w.get_list() if w.get_list().length > 0 - # old_number_of_pages = get_number_of_pages() new_number_of_pages = Math.ceil(w.get_list().length / w.get_items_per_page()) - # if (old_number_of_pages != new_number_of_pages) set_number_of_pages(new_number_of_pages) if $scope.show_sectioning() pages_to_display = w.get_max_pages() @@ -100,16 +66,16 @@ angular.module("angular-table").directive "atPagination", ["angularTableManager" update() - $scope.$watch tc.items_per_page, () -> + $scope.$watch cvn.items_per_page, () -> update() - $scope.$watch tc.max_pages, () -> + $scope.$watch cvn.max_pages, () -> update() - $scope.$watch tc.list, () -> + $scope.$watch cvn.list, () -> update() - $scope.$watch "#{tc.list}.length", () -> + $scope.$watch "#{cvn.list}.length", () -> update() } diff --git a/coffee/directives/at_table.coffee b/coffee/directives/at_table.coffee index cb3ac49..74f3fd6 100644 --- a/coffee/directives/at_table.coffee +++ b/coffee/directives/at_table.coffee @@ -2,18 +2,11 @@ angular.module("angular-table").directive "atTable", ["$filter", "angularTableMa { restrict: "AC" scope: true - controller: ["$scope", "$element", "$attrs", - ($scope, $element, $attrs) -> - id = $attrs["id"] - if id - angularTableManager.register_table_scope(id, $scope, $filter) - ] compile: (element, attributes, transclude) -> tc = new TableConfiguration(element, attributes) - angularTableManager.register_table(tc) - - dt = new Table(element, tc) + cvn = new ConfigurationVariableNames(attributes.atConfig) + dt = new Table(element, tc, cvn) dt.compile() { post: ($scope, $element, $attributes) -> diff --git a/coffee/directives/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee index e471201..b18013a 100644 --- a/coffee/directives/table/setup/paginated_setup.coffee +++ b/coffee/directives/table/setup/paginated_setup.coffee @@ -1,7 +1,6 @@ class PaginatedSetup extends Setup - constructor: (table_configuration) -> - @table_configuration = table_configuration + constructor: (@configuration_variable_names) -> @repeatString = "item in sorted_and_paginated_list" compile: (element) -> @@ -14,7 +13,7 @@ class PaginatedSetup extends Setup # TODO fillerTr = angular.element(document.createElement("tr")) - fillerTr.attr("ng-show", @table_configuration.fill_last_page) + fillerTr.attr("ng-show", @configuration_variable_names.fill_last_page) fillerTr.html(tdString) fillerTr.attr("ng-repeat", "item in filler_array") @@ -23,9 +22,9 @@ class PaginatedSetup extends Setup return link: ($scope, $element, $attributes, $filter) -> - tc = @table_configuration + cvn = @configuration_variable_names - w = new ScopeConfigWrapper($scope, tc) + w = new ScopeConfigWrapper($scope, cvn) get_sorted_and_paginated_list = (list, current_page, items_per_page, sort_context, predicate, descending, $filter) -> if list @@ -77,19 +76,19 @@ class PaginatedSetup extends Setup w.get_items_per_page() ) - $scope.$watch(tc.current_page, () -> + $scope.$watch(cvn.current_page, () -> update_stuff() ) - $scope.$watch(tc.items_per_page, () -> + $scope.$watch(cvn.items_per_page, () -> update_stuff() ) - $scope.$watch(tc.sort_context, () -> + $scope.$watch(cvn.sort_context, () -> update_stuff() ) - $scope.$watch("#{tc.list}.length", () -> + $scope.$watch("#{cvn.list}.length", () -> $scope[irk_number_of_pages] = Math.ceil(w.get_list().length / w.get_items_per_page()) update_stuff() ) diff --git a/coffee/directives/table/setup/standard_setup.coffee b/coffee/directives/table/setup/standard_setup.coffee index 1e6a791..c8ffcfb 100644 --- a/coffee/directives/table/setup/standard_setup.coffee +++ b/coffee/directives/table/setup/standard_setup.coffee @@ -1,7 +1,7 @@ class StandardSetup extends Setup - constructor: (table_configuration) -> - @repeatString = "item in #{table_configuration.list} | orderBy:predicate:descending" + constructor: (configuration_variable_names) -> + @repeatString = "item in #{configuration_variable_names.list} | orderBy:predicate:descending" compile: (element, attributes, transclude) -> @setupTr(element, @repeatString) diff --git a/coffee/directives/table/table.coffee b/coffee/directives/table/table.coffee index d9007d5..98fc858 100644 --- a/coffee/directives/table/table.coffee +++ b/coffee/directives/table/table.coffee @@ -1,6 +1,6 @@ class Table - constructor: (@element, @table_configuration) -> + constructor: (@element, @table_configuration, @configuration_variable_names) -> constructHeader: () -> tr = angular.element(document.createElement("tr")) @@ -18,9 +18,9 @@ class Table get_setup: () -> if @table_configuration.paginated - return new PaginatedSetup(@table_configuration) + return new PaginatedSetup(@configuration_variable_names) else - return new StandardSetup(@table_configuration) + return new StandardSetup(@configuration_variable_names) return compile: () -> diff --git a/test/header.coffee b/test/header.coffee index 3405d09..19553f6 100644 --- a/test/header.coffee +++ b/test/header.coffee @@ -1,22 +1,22 @@ -describe "angular-table", () -> - describe "header", () -> +# describe "angular-table", () -> +# describe "header", () -> - it "doesnt add a header at all if the header tag isnt declared", () -> - comp = new TemplateCompiler("header/no_header.html") - @element = comp.prepare_element((scope) ->) - header = @element.find("thead")[0] - expect(header).toBe undefined +# it "doesnt add a header at all if the header tag isnt declared", () -> +# comp = new TemplateCompiler("header/no_header.html") +# @element = comp.prepare_element((scope) ->) +# header = @element.find("thead")[0] +# expect(header).toBe undefined - it "creates column headers implicitly", () -> - comp = new TemplateCompiler("header/header.html") - @element = comp.prepare_element((scope) ->) - header = extract_html_to_array(getChildrenFor(@element, "thead > tr > th")) - expect(header[0]).toEqual "Name" +# it "creates column headers implicitly", () -> +# comp = new TemplateCompiler("header/header.html") +# @element = comp.prepare_element((scope) ->) +# header = extract_html_to_array(getChildrenFor(@element, "thead > tr > th")) +# expect(header[0]).toEqual "Name" - it "allows to set custom column headers", () -> - comp = new TemplateCompiler("header/header.html") - @element = comp.prepare_element((scope) ->) - header = extract_html_to_array(getChildrenFor(@element, "thead > tr > th")) - expect(header[1]).toEqual "The population" - expect(header[2]).toEqual "Country" - expect(header[3]).toEqual "Size" +# it "allows to set custom column headers", () -> +# comp = new TemplateCompiler("header/header.html") +# @element = comp.prepare_element((scope) ->) +# header = extract_html_to_array(getChildrenFor(@element, "thead > tr > th")) +# expect(header[1]).toEqual "The population" +# expect(header[2]).toEqual "Country" +# expect(header[3]).toEqual "Size" diff --git a/test/pagination.coffee b/test/pagination.coffee index 6ef539f..2cca802 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -1,6 +1,8 @@ describe "angular-table", () -> describe "Pagination", () -> + config_name = "table_config" + step_back = '‹' step_ahead = '›' jump_back = '«' @@ -9,20 +11,12 @@ describe "angular-table", () -> last = 'Last' setups = [{ - template: "pagination/complete_config_hardcoded.html" - variable_names: { - items_per_page: "completeConfigHardcoded_itemsPerPage", - max_pages: "completeConfigHardcoded_maxPages", - sort_context: "completeConfigHardcoded_sortContext", - fill_last_page: "completeConfigHardcoded_fillLastPage" - } - }, { template: "pagination/complete_config_parameterized.html" variable_names: { - items_per_page: "config.my_items_per_page", - max_pages: "config.my_max_pages", - sort_context: "config.my_sort_context", - fill_last_page: "config.my_fill_last_page" + items_per_page: "#{config_name}.itemsPerPage", + max_pages: "#{config_name}.maxPages", + sort_context: "#{config_name}.sortContext", + fill_last_page: "#{config_name}.fillLastPage" } }] @@ -38,19 +32,17 @@ describe "angular-table", () -> {name: "a"}, {name: "b"}, {name: "c"}, {name: "d"}, {name: "e"}, {name: "f"}, {name: "m"} ] - ) - @gui = new GUI(@element, @comp.scope, setup.variable_names) - - @gui.alter_scope (scope_wrapper, vars) -> - config = { - my_items_per_page: 3, - my_max_pages: 2, - my_sort_context: 'global', - my_fill_last_page: true + scope[config_name] = { + currentPage: 0, + itemsPerPage: 3, + maxPages: 2, + sortContext: 'global', + fillLastPage: true } - scope_wrapper.set("tableconfig", {}) + ) + @gui = new GUI(@element, @comp.scope, setup.variable_names) it "allows to select pages", () -> expect(@gui.pagination.pages).toEqual([1, 2]) diff --git a/test/sorting.coffee b/test/sorting.coffee index 8197dbf..cc596bc 100644 --- a/test/sorting.coffee +++ b/test/sorting.coffee @@ -1,18 +1,18 @@ -describe "angular-table", () -> - describe "sorting", () -> +# describe "angular-table", () -> +# describe "sorting", () -> - beforeEach(() -> - comp = new TemplateCompiler("sorting/sorting.html") - @element = comp.prepare_element((scope) -> - scope.cities = [{name: "Helsinki"}, {name: "Zurich"}, {name: "Amsterdam"}] - ) - ) +# beforeEach(() -> +# comp = new TemplateCompiler("sorting/sorting.html") +# @element = comp.prepare_element((scope) -> +# scope.cities = [{name: "Helsinki"}, {name: "Zurich"}, {name: "Amsterdam"}] +# ) +# ) - it "allows to set an initial sorting direction", () -> - tds = extract_html_to_array(@element.find("td")) - expect(tds).toEqual ["Zurich", "Helsinki", "Amsterdam"] +# it "allows to set an initial sorting direction", () -> +# tds = extract_html_to_array(@element.find("td")) +# expect(tds).toEqual ["Zurich", "Helsinki", "Amsterdam"] - it "makes columns sortable", () -> - click(@element.find("th")[0]) - tds = extract_html_to_array(@element.find("td")) - expect(tds).toEqual ["Amsterdam", "Helsinki", "Zurich"] \ No newline at end of file +# it "makes columns sortable", () -> +# click(@element.find("th")[0]) +# tds = extract_html_to_array(@element.find("td")) +# expect(tds).toEqual ["Amsterdam", "Helsinki", "Zurich"] \ No newline at end of file diff --git a/test/templates/pagination/complete_config_parameterized.html b/test/templates/pagination/complete_config_parameterized.html index b692a4a..dd7560b 100644 --- a/test/templates/pagination/complete_config_parameterized.html +++ b/test/templates/pagination/complete_config_parameterized.html @@ -1,16 +1,7 @@ -
        
    @@ -20,4 +11,4 @@
    - + From 3b140be7019d8a2cd32f2a8fc4886b83acb00d6d Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 26 Feb 2014 13:51:31 +0100 Subject: [PATCH 109/190] improved overall code style consistency --- coffee/angular_table.coffee | 5 +- .../configuration/column_configuration.coffee | 1 - .../configuration/table_configuration.coffee | 1 - coffee/directives/at_implicit.coffee | 16 +-- coffee/directives/at_pagination.coffee | 128 +++++++++--------- coffee/directives/at_table.coffee | 28 ++-- .../pagination/page_sequence.coffee | 1 - .../table/setup/paginated_setup.coffee | 1 - coffee/directives/table/setup/setup.coffee | 1 - .../table/setup/standard_setup.coffee | 1 - coffee/directives/table/table.coffee | 1 - 11 files changed, 84 insertions(+), 100 deletions(-) diff --git a/coffee/angular_table.coffee b/coffee/angular_table.coffee index c03359e..64afa7c 100644 --- a/coffee/angular_table.coffee +++ b/coffee/angular_table.coffee @@ -8,7 +8,6 @@ class ConfigurationVariableNames @list = "list" class ScopeConfigWrapper - constructor: (@scope, @configuration_variable_names) -> get_list: () -> @@ -26,8 +25,10 @@ class ScopeConfigWrapper get_sort_context: () -> @scope.$eval(@configuration_variable_names.sort_context) || 'global' -class AngularTableManager + set_current_page: (current_page) -> + @scope.$eval("#{@configuration_variable_names.current_page}=#{current_page}") +class AngularTableManager constructor: () -> @mappings = {} diff --git a/coffee/configuration/column_configuration.coffee b/coffee/configuration/column_configuration.coffee index e57b555..44dc702 100644 --- a/coffee/configuration/column_configuration.coffee +++ b/coffee/configuration/column_configuration.coffee @@ -1,5 +1,4 @@ class ColumnConfiguration - constructor: (body_markup, header_markup) -> @attribute = body_markup.attribute @title = body_markup.title diff --git a/coffee/configuration/table_configuration.coffee b/coffee/configuration/table_configuration.coffee index b878e45..54b940b 100644 --- a/coffee/configuration/table_configuration.coffee +++ b/coffee/configuration/table_configuration.coffee @@ -1,5 +1,4 @@ class TableConfiguration - constructor: (@table_element, @attributes) -> @id = @attributes.id @config = @attributes.atConfig diff --git a/coffee/directives/at_implicit.coffee b/coffee/directives/at_implicit.coffee index 85403c7..74a56a0 100644 --- a/coffee/directives/at_implicit.coffee +++ b/coffee/directives/at_implicit.coffee @@ -1,9 +1,7 @@ -angular.module("angular-table").directive "atImplicit", [() -> - { - restrict: "AC" - compile: (element, attributes, transclude) -> - attribute = element.attr("at-attribute") - throw "at-implicit specified without at-attribute: #{element.html()}" if not attribute - element.append "{{item.#{attribute}}}" - } -] \ No newline at end of file +angular.module("angular-table").directive "atImplicit", [() -> { + restrict: "AC" + compile: (element, attributes, transclude) -> + attribute = element.attr("at-attribute") + throw "at-implicit specified without at-attribute: #{element.html()}" if not attribute + element.append "{{item.#{attribute}}}" +}] \ No newline at end of file diff --git a/coffee/directives/at_pagination.coffee b/coffee/directives/at_pagination.coffee index fdb2adf..4548327 100644 --- a/coffee/directives/at_pagination.coffee +++ b/coffee/directives/at_pagination.coffee @@ -1,82 +1,76 @@ angular.module("angular-table").directive "atPagination", [() -> { - restrict: "E" - scope: true - replace: true - template: pagination_template - - link: ($scope, $element, $attributes) -> - cvn = new ConfigurationVariableNames($attributes.atConfig) - - w = new ScopeConfigWrapper($scope, cvn) - - $scope.page_sequence = new PageSequence() - - set_current_page = (current_page) -> - $scope.$parent.$eval("#{cvn.current_page}=#{current_page}") - - get_number_of_pages = () -> - $scope[irk_number_of_pages] - - set_number_of_pages = (number_of_pages) -> - $scope[irk_number_of_pages] = number_of_pages - - update = (reset) -> - if w.get_list() - if w.get_list().length > 0 - new_number_of_pages = Math.ceil(w.get_list().length / w.get_items_per_page()) - set_number_of_pages(new_number_of_pages) - if $scope.show_sectioning() - pages_to_display = w.get_max_pages() - else - pages_to_display = new_number_of_pages - - $scope.page_sequence.reset_parameters(0, new_number_of_pages, pages_to_display) - # TODO warum ist die reihenfolge der folgenden beiden aufrufe irrelevant? - set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)) - $scope.page_sequence.realign_greedy(w.get_current_page()) + restrict: "E" + scope: true + replace: true + template: pagination_template + + link: ($scope, $element, $attributes) -> + cvn = new ConfigurationVariableNames($attributes.atConfig) + w = new ScopeConfigWrapper($scope, cvn) + + keep_in_bounds = (val, min, max) -> + val = Math.max(min, val) + Math.min(max, val) + + get_number_of_pages = () -> + $scope[irk_number_of_pages] + + set_number_of_pages = (number_of_pages) -> + $scope[irk_number_of_pages] = number_of_pages + + update = (reset) -> + if w.get_list() + if w.get_list().length > 0 + new_number_of_pages = Math.ceil(w.get_list().length / w.get_items_per_page()) + set_number_of_pages(new_number_of_pages) + if $scope.show_sectioning() + pages_to_display = w.get_max_pages() else - set_number_of_pages(1) - $scope.page_sequence.reset_parameters(0, 1, 1) - set_current_page(0) - $scope.page_sequence.realign_greedy(0) + pages_to_display = new_number_of_pages - keep_in_bounds = (val, min, max) -> - val = Math.max(min, val) - Math.min(max, val) + $scope.page_sequence.reset_parameters(0, new_number_of_pages, pages_to_display) + # TODO warum ist die reihenfolge der folgenden beiden aufrufe irrelevant? + w.set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)) + $scope.page_sequence.realign_greedy(w.get_current_page()) + else + set_number_of_pages(1) + $scope.page_sequence.reset_parameters(0, 1, 1) + w.set_current_page(0) + $scope.page_sequence.realign_greedy(0) - $scope.show_sectioning = () -> - w.get_max_pages() && get_number_of_pages() > w.get_max_pages() + $scope.show_sectioning = () -> + w.get_max_pages() && get_number_of_pages() > w.get_max_pages() - $scope.get_current_page = () -> - w.get_current_page() + $scope.get_current_page = () -> + w.get_current_page() - $scope.step_page = (step) -> - step = parseInt(step) - set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)) - $scope.page_sequence.realign_greedy(w.get_current_page()) + $scope.step_page = (step) -> + step = parseInt(step) + w.set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)) + $scope.page_sequence.realign_greedy(w.get_current_page()) - $scope.go_to_page = (page) -> - set_current_page(page) + $scope.go_to_page = (page) -> + w.set_current_page(page) - $scope.jump_back = () -> - $scope.step_page(-w.get_max_pages()) + $scope.jump_back = () -> + $scope.step_page(-w.get_max_pages()) - $scope.jump_ahead = () -> - $scope.step_page(w.get_max_pages()) + $scope.jump_ahead = () -> + $scope.step_page(w.get_max_pages()) - update() + $scope.page_sequence = new PageSequence() - $scope.$watch cvn.items_per_page, () -> - update() + $scope.$watch cvn.items_per_page, () -> + update() - $scope.$watch cvn.max_pages, () -> - update() + $scope.$watch cvn.max_pages, () -> + update() - $scope.$watch cvn.list, () -> - update() + $scope.$watch cvn.list, () -> + update() - $scope.$watch "#{cvn.list}.length", () -> - update() + $scope.$watch "#{cvn.list}.length", () -> + update() - } -] + update() +}] diff --git a/coffee/directives/at_table.coffee b/coffee/directives/at_table.coffee index 74f3fd6..86c6a5f 100644 --- a/coffee/directives/at_table.coffee +++ b/coffee/directives/at_table.coffee @@ -1,16 +1,14 @@ -angular.module("angular-table").directive "atTable", ["$filter", "angularTableManager", ($filter, angularTableManager) -> - { - restrict: "AC" - scope: true +angular.module("angular-table").directive "atTable", ["$filter", "angularTableManager", ($filter, angularTableManager) -> { + restrict: "AC" + scope: true - compile: (element, attributes, transclude) -> - tc = new TableConfiguration(element, attributes) - cvn = new ConfigurationVariableNames(attributes.atConfig) - dt = new Table(element, tc, cvn) - dt.compile() - { - post: ($scope, $element, $attributes) -> - dt.post($scope, $element, $attributes, $filter) - } - } -] + compile: (element, attributes, transclude) -> + tc = new TableConfiguration(element, attributes) + cvn = new ConfigurationVariableNames(attributes.atConfig) + table = new Table(element, tc, cvn) + table.compile() + + post: ($scope, $element, $attributes) -> + table.post($scope, $element, $attributes, $filter) + +}] diff --git a/coffee/directives/pagination/page_sequence.coffee b/coffee/directives/pagination/page_sequence.coffee index 993729a..264986a 100644 --- a/coffee/directives/pagination/page_sequence.coffee +++ b/coffee/directives/pagination/page_sequence.coffee @@ -1,5 +1,4 @@ class PageSequence - constructor: (@lower_bound = 0, @upper_bound = 1, start = 0, @length = 1) -> throw "sequence is too long" if @length > (@upper_bound - @lower_bound) @data = @generate(start) diff --git a/coffee/directives/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee index b18013a..8145508 100644 --- a/coffee/directives/table/setup/paginated_setup.coffee +++ b/coffee/directives/table/setup/paginated_setup.coffee @@ -1,5 +1,4 @@ class PaginatedSetup extends Setup - constructor: (@configuration_variable_names) -> @repeatString = "item in sorted_and_paginated_list" diff --git a/coffee/directives/table/setup/setup.coffee b/coffee/directives/table/setup/setup.coffee index d3ffd90..5c6d34d 100644 --- a/coffee/directives/table/setup/setup.coffee +++ b/coffee/directives/table/setup/setup.coffee @@ -1,5 +1,4 @@ class Setup - setupTr: (element, repeatString) -> tbody = element.find "tbody" tr = tbody.find "tr" diff --git a/coffee/directives/table/setup/standard_setup.coffee b/coffee/directives/table/setup/standard_setup.coffee index c8ffcfb..9d7f2f1 100644 --- a/coffee/directives/table/setup/standard_setup.coffee +++ b/coffee/directives/table/setup/standard_setup.coffee @@ -1,5 +1,4 @@ class StandardSetup extends Setup - constructor: (configuration_variable_names) -> @repeatString = "item in #{configuration_variable_names.list} | orderBy:predicate:descending" diff --git a/coffee/directives/table/table.coffee b/coffee/directives/table/table.coffee index 98fc858..4735c71 100644 --- a/coffee/directives/table/table.coffee +++ b/coffee/directives/table/table.coffee @@ -1,5 +1,4 @@ class Table - constructor: (@element, @table_configuration, @configuration_variable_names) -> constructHeader: () -> From 55513cace243b2ffc88be3330b71311409f849bb Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 26 Feb 2014 14:10:57 +0100 Subject: [PATCH 110/190] refactored list definition --- coffee/angular_table.coffee | 5 ++- .../configuration/table_configuration.coffee | 2 +- coffee/directives/at_pagination.coffee | 6 ++-- .../table/setup/paginated_setup.coffee | 4 +-- .../table/setup/standard_setup.coffee | 4 +-- coffee/directives/table/table.coffee | 2 +- test/pagination.coffee | 19 ++++++------ test/sorting.coffee | 31 ++++++++++--------- .../complete_config_parameterized.html | 8 ++--- test/templates/sorting/sorting.html | 2 +- 10 files changed, 40 insertions(+), 43 deletions(-) diff --git a/coffee/angular_table.coffee b/coffee/angular_table.coffee index 64afa7c..8d17c6d 100644 --- a/coffee/angular_table.coffee +++ b/coffee/angular_table.coffee @@ -5,13 +5,12 @@ class ConfigurationVariableNames @fill_last_page = "#{@config_object_name}.fillLastPage" @max_pages = "#{@config_object_name}.maxPages" @current_page = "#{@config_object_name}.currentPage" - @list = "list" class ScopeConfigWrapper - constructor: (@scope, @configuration_variable_names) -> + constructor: (@scope, @configuration_variable_names, @list_name) -> get_list: () -> - @scope.$eval("list") + @scope.$eval(@list_name) get_items_per_page: () -> @scope.$eval(@configuration_variable_names.items_per_page) || 10 diff --git a/coffee/configuration/table_configuration.coffee b/coffee/configuration/table_configuration.coffee index 54b940b..b511dda 100644 --- a/coffee/configuration/table_configuration.coffee +++ b/coffee/configuration/table_configuration.coffee @@ -3,7 +3,7 @@ class TableConfiguration @id = @attributes.id @config = @attributes.atConfig @paginated = @attributes.atPaginated? - + @list = @attributes.atList @create_column_configurations() capitaliseFirstLetter: (string) -> diff --git a/coffee/directives/at_pagination.coffee b/coffee/directives/at_pagination.coffee index 4548327..7775ebb 100644 --- a/coffee/directives/at_pagination.coffee +++ b/coffee/directives/at_pagination.coffee @@ -6,7 +6,7 @@ angular.module("angular-table").directive "atPagination", [() -> { link: ($scope, $element, $attributes) -> cvn = new ConfigurationVariableNames($attributes.atConfig) - w = new ScopeConfigWrapper($scope, cvn) + w = new ScopeConfigWrapper($scope, cvn, $attributes.atList) keep_in_bounds = (val, min, max) -> val = Math.max(min, val) @@ -66,10 +66,10 @@ angular.module("angular-table").directive "atPagination", [() -> { $scope.$watch cvn.max_pages, () -> update() - $scope.$watch cvn.list, () -> + $scope.$watch $attributes.atList, () -> update() - $scope.$watch "#{cvn.list}.length", () -> + $scope.$watch "#{$attributes.atList}.length", () -> update() update() diff --git a/coffee/directives/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee index 8145508..de1cb82 100644 --- a/coffee/directives/table/setup/paginated_setup.coffee +++ b/coffee/directives/table/setup/paginated_setup.coffee @@ -23,7 +23,7 @@ class PaginatedSetup extends Setup link: ($scope, $element, $attributes, $filter) -> cvn = @configuration_variable_names - w = new ScopeConfigWrapper($scope, cvn) + w = new ScopeConfigWrapper($scope, cvn, $attributes.atList) get_sorted_and_paginated_list = (list, current_page, items_per_page, sort_context, predicate, descending, $filter) -> if list @@ -87,7 +87,7 @@ class PaginatedSetup extends Setup update_stuff() ) - $scope.$watch("#{cvn.list}.length", () -> + $scope.$watch("#{$attributes.atList}.length", () -> $scope[irk_number_of_pages] = Math.ceil(w.get_list().length / w.get_items_per_page()) update_stuff() ) diff --git a/coffee/directives/table/setup/standard_setup.coffee b/coffee/directives/table/setup/standard_setup.coffee index 9d7f2f1..4947b38 100644 --- a/coffee/directives/table/setup/standard_setup.coffee +++ b/coffee/directives/table/setup/standard_setup.coffee @@ -1,6 +1,6 @@ class StandardSetup extends Setup - constructor: (configuration_variable_names) -> - @repeatString = "item in #{configuration_variable_names.list} | orderBy:predicate:descending" + constructor: (configuration_variable_names, @list) -> + @repeatString = "item in #{@list} | orderBy:predicate:descending" compile: (element, attributes, transclude) -> @setupTr(element, @repeatString) diff --git a/coffee/directives/table/table.coffee b/coffee/directives/table/table.coffee index 4735c71..3437763 100644 --- a/coffee/directives/table/table.coffee +++ b/coffee/directives/table/table.coffee @@ -19,7 +19,7 @@ class Table if @table_configuration.paginated return new PaginatedSetup(@configuration_variable_names) else - return new StandardSetup(@configuration_variable_names) + return new StandardSetup(@configuration_variable_names, @table_configuration.list) return compile: () -> diff --git a/test/pagination.coffee b/test/pagination.coffee index 2cca802..a07070b 100644 --- a/test/pagination.coffee +++ b/test/pagination.coffee @@ -2,6 +2,7 @@ describe "angular-table", () -> describe "Pagination", () -> config_name = "table_config" + list_name = "myList" step_back = '‹' step_ahead = '›' @@ -27,7 +28,7 @@ describe "angular-table", () -> @comp = new TemplateCompiler(setup.template) @element = @comp.prepare_element((scope) -> - scope.list = [ + scope[list_name] = [ {name: "i"}, {name: "g"}, {name: "h"}, {name: "j"}, {name: "k"}, {name: "l"} {name: "a"}, {name: "b"}, {name: "c"}, {name: "d"}, {name: "e"}, {name: "f"}, {name: "m"} @@ -184,7 +185,7 @@ describe "angular-table", () -> @gui.alter_scope((scope_wrapper, vars) -> scope_wrapper.set(vars.items_per_page, 3) scope_wrapper.set(vars.fill_last_page, true) - scope_wrapper.set("list", []) + scope_wrapper.set(list_name, []) ) expect(@gui.table.rows).toEqual [[' '], [' '], [' ']] @@ -217,13 +218,13 @@ describe "angular-table", () -> @gui.alter_scope((scope_wrapper, vars) -> scope_wrapper.set(vars.items_per_page, 3) scope_wrapper.set(vars.max_pages, 2) - scope_wrapper.set("list", [{name: 'z'}]) + scope_wrapper.set(list_name, [{name: 'z'}]) ) expect(@gui.table.rows).toEqual [['z'], [' '], [' ']] @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.get("list").push({name: 'a'}) + scope_wrapper.get(list_name).push({name: 'a'}) ) expect(@gui.table.rows).toEqual [['a'], ['z'], [' ']] @@ -231,8 +232,8 @@ describe "angular-table", () -> expect(@gui.pagination.pages).toEqual [1] @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.get("list").push({name: 'x'}) - scope_wrapper.get("list").push({name: 'b'}) + scope_wrapper.get(list_name).push({name: 'x'}) + scope_wrapper.get(list_name).push({name: 'b'}) ) expect(@gui.table.rows).toEqual [['a'], ['b'], ['x']] @@ -244,9 +245,9 @@ describe "angular-table", () -> expect(@gui.table.rows).toEqual [['z'], [' '], [' ']] @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.get("list").push({name: 'c'}) - scope_wrapper.get("list").push({name: 'y'}) - scope_wrapper.get("list").push({name: 'u'}) + scope_wrapper.get(list_name).push({name: 'c'}) + scope_wrapper.get(list_name).push({name: 'y'}) + scope_wrapper.get(list_name).push({name: 'u'}) ) expect(@gui.table.rows).toEqual [['u'], ['x'], ['y']] diff --git a/test/sorting.coffee b/test/sorting.coffee index cc596bc..df5f0a1 100644 --- a/test/sorting.coffee +++ b/test/sorting.coffee @@ -1,18 +1,19 @@ -# describe "angular-table", () -> -# describe "sorting", () -> +describe "angular-table", () -> + describe "sorting", () -> -# beforeEach(() -> -# comp = new TemplateCompiler("sorting/sorting.html") -# @element = comp.prepare_element((scope) -> -# scope.cities = [{name: "Helsinki"}, {name: "Zurich"}, {name: "Amsterdam"}] -# ) -# ) + beforeEach(() -> + comp = new TemplateCompiler("sorting/sorting.html") + @element = comp.prepare_element((scope) -> + scope.cities = [{name: "Helsinki"}, {name: "Zurich"}, {name: "Amsterdam"}] + scope.config = {} + ) + ) -# it "allows to set an initial sorting direction", () -> -# tds = extract_html_to_array(@element.find("td")) -# expect(tds).toEqual ["Zurich", "Helsinki", "Amsterdam"] + it "allows to set an initial sorting direction", () -> + tds = extract_html_to_array(@element.find("td")) + expect(tds).toEqual ["Zurich", "Helsinki", "Amsterdam"] -# it "makes columns sortable", () -> -# click(@element.find("th")[0]) -# tds = extract_html_to_array(@element.find("td")) -# expect(tds).toEqual ["Amsterdam", "Helsinki", "Zurich"] \ No newline at end of file + it "makes columns sortable", () -> + click(@element.find("th")[0]) + tds = extract_html_to_array(@element.find("td")) + expect(tds).toEqual ["Amsterdam", "Helsinki", "Zurich"] \ No newline at end of file diff --git a/test/templates/pagination/complete_config_parameterized.html b/test/templates/pagination/complete_config_parameterized.html index dd7560b..c82e862 100644 --- a/test/templates/pagination/complete_config_parameterized.html +++ b/test/templates/pagination/complete_config_parameterized.html @@ -1,8 +1,4 @@ - +
    @@ -11,4 +7,4 @@
    - + diff --git a/test/templates/sorting/sorting.html b/test/templates/sorting/sorting.html index 5facddb..61e19b1 100644 --- a/test/templates/sorting/sorting.html +++ b/test/templates/sorting/sorting.html @@ -1,4 +1,4 @@ - +
    From 83d233a917de09b51730473a9eaf448797aab81a Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 26 Feb 2014 14:16:17 +0100 Subject: [PATCH 111/190] added closing tag --- test/templates/pagination/complete_config_parameterized.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/templates/pagination/complete_config_parameterized.html b/test/templates/pagination/complete_config_parameterized.html index c82e862..a083c43 100644 --- a/test/templates/pagination/complete_config_parameterized.html +++ b/test/templates/pagination/complete_config_parameterized.html @@ -7,4 +7,4 @@
    - + From 4358d99dc50f61ed31e2b2d5db1c094f66726a20 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 26 Feb 2014 14:19:48 +0100 Subject: [PATCH 112/190] table manager no longer required --- coffee/angular_table.coffee | 17 ----------------- coffee/directives/at_table.coffee | 2 +- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/coffee/angular_table.coffee b/coffee/angular_table.coffee index 8d17c6d..fbdb73c 100644 --- a/coffee/angular_table.coffee +++ b/coffee/angular_table.coffee @@ -27,25 +27,8 @@ class ScopeConfigWrapper set_current_page: (current_page) -> @scope.$eval("#{@configuration_variable_names.current_page}=#{current_page}") -class AngularTableManager - constructor: () -> - @mappings = {} - - get_table_configuration: (id) -> - @mappings[id].table_configuration - - register_table: (table_configuration) -> - mapping = @mappings[table_configuration.id] ||= {} - mapping.table_configuration = table_configuration - if mapping.pagination_scope - throw "pagination element before table element is going to be supported soon" - angular.module "angular-table", [] -angular.module("angular-table").service "angularTableManager", [() -> - new AngularTableManager() -] - irk_number_of_pages = "number_of_pages" pagination_template = " diff --git a/coffee/directives/at_table.coffee b/coffee/directives/at_table.coffee index 86c6a5f..50f7d40 100644 --- a/coffee/directives/at_table.coffee +++ b/coffee/directives/at_table.coffee @@ -1,4 +1,4 @@ -angular.module("angular-table").directive "atTable", ["$filter", "angularTableManager", ($filter, angularTableManager) -> { +angular.module("angular-table").directive "atTable", ["$filter", ($filter) -> { restrict: "AC" scope: true From c169c167a7f1e6292cb011df24bfd777e42df58e Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Thu, 27 Feb 2014 19:08:25 +0100 Subject: [PATCH 113/190] indented markup --- angular-table.js | 400 +++++++------------- angular-table.min.js | 2 +- coffee/angular_table.coffee | 60 ++- gem/app/assets/javascripts/angular-table.js | 400 +++++++------------- 4 files changed, 292 insertions(+), 570 deletions(-) diff --git a/angular-table.js b/angular-table.js index b814413..cb073ad 100644 --- a/angular-table.js +++ b/angular-table.js @@ -3,10 +3,65 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var AngularTableManager, ColumnConfiguration, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, erk_attribute, erk_current_page, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, irk_number_of_pages, + var ColumnConfiguration, ConfigurationVariableNames, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, irk_number_of_pages, pagination_template, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + ConfigurationVariableNames = (function() { + function ConfigurationVariableNames(config_object_name) { + this.config_object_name = config_object_name; + this.items_per_page = "" + this.config_object_name + ".itemsPerPage"; + this.sort_context = "" + this.config_object_name + ".sortContext"; + this.fill_last_page = "" + this.config_object_name + ".fillLastPage"; + this.max_pages = "" + this.config_object_name + ".maxPages"; + this.current_page = "" + this.config_object_name + ".currentPage"; + } + + return ConfigurationVariableNames; + + })(); + + ScopeConfigWrapper = (function() { + function ScopeConfigWrapper(scope, configuration_variable_names, list_name) { + this.scope = scope; + this.configuration_variable_names = configuration_variable_names; + this.list_name = list_name; + } + + ScopeConfigWrapper.prototype.get_list = function() { + return this.scope.$eval(this.list_name); + }; + + ScopeConfigWrapper.prototype.get_items_per_page = function() { + return this.scope.$eval(this.configuration_variable_names.items_per_page) || 10; + }; + + ScopeConfigWrapper.prototype.get_current_page = function() { + return this.scope.$eval(this.configuration_variable_names.current_page) || 0; + }; + + ScopeConfigWrapper.prototype.get_max_pages = function() { + return this.scope.$eval(this.configuration_variable_names.max_pages) || void 0; + }; + + ScopeConfigWrapper.prototype.get_sort_context = function() { + return this.scope.$eval(this.configuration_variable_names.sort_context) || 'global'; + }; + + ScopeConfigWrapper.prototype.set_current_page = function(current_page) { + return this.scope.$eval("" + this.configuration_variable_names.current_page + "=" + current_page); + }; + + return ScopeConfigWrapper; + + })(); + + angular.module("angular-table", []); + + irk_number_of_pages = "number_of_pages"; + + pagination_template = ""; + ColumnConfiguration = (function() { function ColumnConfiguration(body_markup, header_markup) { this.attribute = body_markup.attribute; @@ -22,8 +77,7 @@ ColumnConfiguration.prototype.create_element = function() { var th; - th = angular.element(document.createElement("th")); - return th.attr("style", "cursor: pointer;"); + return th = angular.element(document.createElement("th")); }; ColumnConfiguration.prototype.render_title = function(element) { @@ -76,86 +130,12 @@ this.table_element = table_element; this.attributes = attributes; this.id = this.attributes.id; - this.list = this.attributes[erk_list]; - if (this.attributes[erk_items_per_page]) { - this.register_items_per_page(this.attributes[erk_items_per_page]); - } - this.register_sort_context(this.attributes[erk_sort_context]); - this.register_fill_last_page(this.attributes[erk_fill_last_page]); - this.register_max_pages(this.attributes[erk_max_pages]); - this.register_current_page(this.attributes[erk_current_page]); - this.paginated = this.items_per_page !== void 0; + this.config = this.attributes.atConfig; + this.paginated = this.attributes.atPaginated != null; + this.list = this.attributes.atList; this.create_column_configurations(); } - TableConfiguration.prototype.register_items_per_page = function(items_per_page) { - if (isNaN(items_per_page)) { - return this.items_per_page = items_per_page; - } else { - this.items_per_page = "" + this.id + "_itemsPerPage"; - return this.initial_items_per_page = parseInt(items_per_page); - } - }; - - TableConfiguration.prototype.register_sort_context = function(sort_context) { - if (sort_context !== void 0) { - if (sort_context === "global") { - this.sort_context = "" + this.id + "_sortContext"; - return this.initial_sort_context = "global"; - } else if (sort_context === "page") { - this.sort_context = "" + this.id + "_sortContext"; - return this.initial_sort_context = "page"; - } else { - return this.sort_context = sort_context; - } - } else { - this.sort_context = "" + this.id + "_sortContext"; - return this.initial_sort_context = "global"; - } - }; - - TableConfiguration.prototype.register_fill_last_page = function(fill_last_page) { - if (fill_last_page !== void 0) { - if (fill_last_page === "true") { - this.fill_last_page = "" + this.id + "_fillLastPage"; - return this.initial_fill_last_page = true; - } else if (fill_last_page === "false") { - this.fill_last_page = "" + this.id + "_fillLastPage"; - return this.initial_fill_last_page = false; - } else if (fill_last_page === "") { - this.fill_last_page = "" + this.id + "_fillLastPage"; - return this.initial_fill_last_page = true; - } else { - return this.fill_last_page = fill_last_page; - } - } - }; - - TableConfiguration.prototype.register_max_pages = function(max_pages) { - if (max_pages !== void 0) { - if (isNaN(max_pages)) { - return this.max_pages = max_pages; - } else { - this.max_pages = "" + this.id + "_maxPages"; - return this.initial_max_pages = parseInt(max_pages); - } - } - }; - - TableConfiguration.prototype.register_current_page = function(current_page) { - if (current_page !== void 0) { - if (isNaN(current_page)) { - return this.current_page = current_page; - } else { - this.current_page = "" + this.id + "_currentPage"; - return this.initial_current_page = parseInt(current_page); - } - } else { - this.current_page = "" + this.id + "_currentPage"; - return this.initial_current_page = 0; - } - }; - TableConfiguration.prototype.capitaliseFirstLetter = function(string) { if (string) { return string.charAt(0).toUpperCase() + string.slice(1); @@ -269,8 +249,9 @@ StandardSetup = (function(_super) { __extends(StandardSetup, _super); - function StandardSetup(table_configuration) { - this.repeatString = "item in " + table_configuration.list + " | orderBy:predicate:descending"; + function StandardSetup(configuration_variable_names, list) { + this.list = list; + this.repeatString = "item in " + this.list + " | orderBy:predicate:descending"; } StandardSetup.prototype.compile = function(element, attributes, transclude) { @@ -286,8 +267,8 @@ PaginatedSetup = (function(_super) { __extends(PaginatedSetup, _super); - function PaginatedSetup(table_configuration) { - this.table_configuration = table_configuration; + function PaginatedSetup(configuration_variable_names) { + this.configuration_variable_names = configuration_variable_names; this.repeatString = "item in sorted_and_paginated_list"; } @@ -301,16 +282,16 @@ tdString += " "; } fillerTr = angular.element(document.createElement("tr")); - fillerTr.attr("ng-show", this.table_configuration.fill_last_page); + fillerTr.attr("ng-show", this.configuration_variable_names.fill_last_page); fillerTr.html(tdString); fillerTr.attr("ng-repeat", "item in filler_array"); tbody.append(fillerTr); }; PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) { - var get_filler_array, get_sorted_and_paginated_list, tc, update_stuff, w; - tc = this.table_configuration; - w = new ScopeConfigWrapper($scope, tc); + var cvn, get_filler_array, get_sorted_and_paginated_list, update_stuff, w; + cvn = this.configuration_variable_names; + w = new ScopeConfigWrapper($scope, cvn, $attributes.atList); get_sorted_and_paginated_list = function(list, current_page, items_per_page, sort_context, predicate, descending, $filter) { var from_page, val; if (list) { @@ -359,17 +340,17 @@ nop = Math.ceil(w.get_list().length / w.get_items_per_page()); return $scope.filler_array = get_filler_array(w.get_list(), w.get_current_page(), nop, w.get_items_per_page()); }; - $scope.$watch(tc.current_page, function() { + $scope.$watch(cvn.current_page, function() { return update_stuff(); }); - $scope.$watch(tc.items_per_page, function() { + $scope.$watch(cvn.items_per_page, function() { return update_stuff(); }); - $scope.$watch(tc.sort_context, function() { + $scope.$watch(cvn.sort_context, function() { return update_stuff(); }); - $scope.$watch("" + tc.list + ".length", function() { - $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / w.get_items_per_page()); + $scope.$watch("" + $attributes.atList + ".length", function() { + $scope[irk_number_of_pages] = Math.ceil(w.get_list().length / w.get_items_per_page()); return update_stuff(); }); $scope.$watch("predicate", function() { @@ -385,9 +366,10 @@ })(Setup); Table = (function() { - function Table(element, table_configuration) { + function Table(element, table_configuration, configuration_variable_names) { this.element = element; this.table_configuration = table_configuration; + this.configuration_variable_names = configuration_variable_names; } Table.prototype.constructHeader = function() { @@ -414,9 +396,9 @@ Table.prototype.get_setup = function() { if (this.table_configuration.paginated) { - return new PaginatedSetup(this.table_configuration); + return new PaginatedSetup(this.configuration_variable_names); } else { - return new StandardSetup(this.table_configuration); + return new StandardSetup(this.configuration_variable_names, this.table_configuration.list); } }; @@ -466,140 +448,20 @@ })(); - angular.module("angular-table", []); - - irk_number_of_pages = "number_of_pages"; - - erk_list = "atList"; - - erk_items_per_page = "atItemsPerPage"; - - erk_fill_last_page = "atFillLastPage"; - - erk_sort_context = "atSortContext"; - - erk_max_pages = "atMaxPages"; - - erk_current_page = "atCurrentPage"; - - erk_attribute = "at-attribute"; - - erk_sortable = "at-sortable"; - - erk_initial_sorting = "at-initial-sorting"; - - ScopeConfigWrapper = (function() { - function ScopeConfigWrapper(table_scope, table_configuration) { - this.scope = table_scope; - this.config = table_configuration; - } - - ScopeConfigWrapper.prototype.get_list = function() { - return this.scope.$eval(this.config.list); - }; - - ScopeConfigWrapper.prototype.get_items_per_page = function() { - return this.scope.$eval(this.config.items_per_page); - }; - - ScopeConfigWrapper.prototype.get_current_page = function() { - return this.scope.$eval(this.config.current_page); - }; - - ScopeConfigWrapper.prototype.get_max_pages = function() { - return this.scope.$eval(this.config.max_pages); - }; - - ScopeConfigWrapper.prototype.get_sort_context = function() { - return this.scope.$eval(this.config.sort_context); - }; - - return ScopeConfigWrapper; - - })(); - - AngularTableManager = (function() { - function AngularTableManager() { - this.mappings = {}; - } - - AngularTableManager.prototype.get_table_configuration = function(id) { - return this.mappings[id].table_configuration; - }; - - AngularTableManager.prototype.register_table = function(table_configuration) { - var mapping, _base, _name; - mapping = (_base = this.mappings)[_name = table_configuration.id] || (_base[_name] = {}); - mapping.table_configuration = table_configuration; - if (mapping.pagination_scope) { - throw "WHOOPS"; - } - }; - - AngularTableManager.prototype.register_table_scope = function(id, scope, filter) { - var tc; - this.mappings[id].table_scope = scope; - tc = this.mappings[id].table_configuration; - if (tc.initial_items_per_page) { - scope.$parent[tc.items_per_page] = tc.initial_items_per_page; - } - if (tc.initial_sort_context) { - scope.$parent[tc.sort_context] = tc.initial_sort_context; - } - if (tc.initial_fill_last_page) { - scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page; - } - if (tc.initial_max_pages) { - scope.$parent[tc.max_pages] = tc.initial_max_pages; + PageSequence = (function() { + function PageSequence(lower_bound, upper_bound, start, length) { + this.lower_bound = lower_bound != null ? lower_bound : 0; + this.upper_bound = upper_bound != null ? upper_bound : 1; + if (start == null) { + start = 0; } - if (tc.initial_current_page !== void 0) { - return scope.$parent[tc.current_page] = tc.initial_current_page; + this.length = length != null ? length : 1; + if (this.length > (this.upper_bound - this.lower_bound)) { + throw "sequence is too long"; } - }; - - AngularTableManager.prototype.register_pagination_scope = function(id, pagination_scope) {}; - - return AngularTableManager; - - })(); - - angular.module("angular-table").service("angularTableManager", [ - function() { - return new AngularTableManager(); - } - ]); - - angular.module("angular-table").directive("atTable", [ - "$filter", "angularTableManager", function($filter, angularTableManager) { - return { - restrict: "AC", - scope: true, - controller: [ - "$scope", "$element", "$attrs", function($scope, $element, $attrs) { - var id; - id = $attrs["id"]; - if (id) { - return angularTableManager.register_table_scope(id, $scope, $filter); - } - } - ], - compile: function(element, attributes, transclude) { - var dt, tc; - tc = new TableConfiguration(element, attributes); - angularTableManager.register_table(tc); - dt = new Table(element, tc); - dt.compile(); - return { - post: function($scope, $element, $attributes) { - return dt.post($scope, $element, $attributes, $filter); - } - }; - } - }; + this.data = this.generate(start); } - ]); - PageSequence = (function() { PageSequence.prototype.generate = function(start) { var x, _i, _ref, _results; if (start > (this.upper_bound - this.length)) { @@ -614,19 +476,6 @@ return _results; }; - function PageSequence(lower_bound, upper_bound, start, length) { - this.lower_bound = lower_bound != null ? lower_bound : 0; - this.upper_bound = upper_bound != null ? upper_bound : 1; - if (start == null) { - start = 0; - } - this.length = length != null ? length : 1; - if (this.length > (this.upper_bound - this.lower_bound)) { - throw "sequence is too long"; - } - this.data = this.generate(start); - } - PageSequence.prototype.reset_parameters = function(lower_bound, upper_bound, length) { this.lower_bound = lower_bound; this.upper_bound = upper_bound; @@ -660,25 +509,41 @@ })(); + angular.module("angular-table").directive("atTable", [ + "$filter", function($filter) { + return { + restrict: "AC", + scope: true, + compile: function(element, attributes, transclude) { + var cvn, table, tc; + tc = new TableConfiguration(element, attributes); + cvn = new ConfigurationVariableNames(attributes.atConfig); + table = new Table(element, tc, cvn); + table.compile(); + return { + post: function($scope, $element, $attributes) { + return table.post($scope, $element, $attributes, $filter); + } + }; + } + }; + } + ]); + angular.module("angular-table").directive("atPagination", [ - "angularTableManager", function(angularTableManager) { + function() { return { - replace: true, restrict: "E", - template: "", - controller: [ - "$scope", "$element", "$attrs", function($scope, $element, $attrs) { - return angularTableManager.register_pagination_scope($attrs.atTableId, $scope); - } - ], scope: true, + replace: true, + template: pagination_template, link: function($scope, $element, $attributes) { - var get_number_of_pages, keep_in_bounds, set_current_page, set_number_of_pages, tc, update, w; - tc = angularTableManager.get_table_configuration($attributes.atTableId); - w = new ScopeConfigWrapper($scope, tc); - $scope.page_sequence = new PageSequence(); - set_current_page = function(current_page) { - return $scope.$parent.$eval("" + tc.current_page + "=" + current_page); + var cvn, get_number_of_pages, keep_in_bounds, set_number_of_pages, update, w; + cvn = new ConfigurationVariableNames($attributes.atConfig); + w = new ScopeConfigWrapper($scope, cvn, $attributes.atList); + keep_in_bounds = function(val, min, max) { + val = Math.max(min, val); + return Math.min(max, val); }; get_number_of_pages = function() { return $scope[irk_number_of_pages]; @@ -688,9 +553,9 @@ }; update = function(reset) { var new_number_of_pages, pages_to_display; - if ($scope[tc.list]) { - if ($scope[tc.list].length > 0) { - new_number_of_pages = Math.ceil($scope[tc.list].length / w.get_items_per_page()); + if (w.get_list()) { + if (w.get_list().length > 0) { + new_number_of_pages = Math.ceil(w.get_list().length / w.get_items_per_page()); set_number_of_pages(new_number_of_pages); if ($scope.show_sectioning()) { pages_to_display = w.get_max_pages(); @@ -698,20 +563,16 @@ pages_to_display = new_number_of_pages; } $scope.page_sequence.reset_parameters(0, new_number_of_pages, pages_to_display); - set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); + w.set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); return $scope.page_sequence.realign_greedy(w.get_current_page()); } else { set_number_of_pages(1); $scope.page_sequence.reset_parameters(0, 1, 1); - set_current_page(0); + w.set_current_page(0); return $scope.page_sequence.realign_greedy(0); } } }; - keep_in_bounds = function(val, min, max) { - val = Math.max(min, val); - return Math.min(max, val); - }; $scope.show_sectioning = function() { return w.get_max_pages() && get_number_of_pages() > w.get_max_pages(); }; @@ -720,11 +581,11 @@ }; $scope.step_page = function(step) { step = parseInt(step); - set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)); + w.set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)); return $scope.page_sequence.realign_greedy(w.get_current_page()); }; $scope.go_to_page = function(page) { - return set_current_page(page); + return w.set_current_page(page); }; $scope.jump_back = function() { return $scope.step_page(-w.get_max_pages()); @@ -732,19 +593,20 @@ $scope.jump_ahead = function() { return $scope.step_page(w.get_max_pages()); }; - update(); - $scope.$watch(tc.items_per_page, function() { + $scope.page_sequence = new PageSequence(); + $scope.$watch(cvn.items_per_page, function() { return update(); }); - $scope.$watch(tc.max_pages, function() { + $scope.$watch(cvn.max_pages, function() { return update(); }); - $scope.$watch(tc.list, function() { + $scope.$watch($attributes.atList, function() { return update(); }); - return $scope.$watch("" + tc.list + ".length", function() { + $scope.$watch("" + $attributes.atList + ".length", function() { return update(); }); + return update(); } }; } diff --git a/angular-table.min.js b/angular-table.min.js index 7429068..eee15c8 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,i,n,r,a,o,s,u,l,p,c,g,_,h,f,d,m,b,v={}.hasOwnProperty,y=function(t,e){function i(){this.constructor=t}for(var n in e)v.call(e,n)&&(t[n]=e[n]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t};e=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th")),t.attr("style","cursor: pointer;")},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,i,n,r,a;if(this.custom_content){for(r=this.attributes,a=[],i=0,n=r.length;n>i;i++)e=r[i],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),u=function(){function t(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.list=this.attributes[h],this.attributes[_]&&this.register_items_per_page(this.attributes[_]),this.register_sort_context(this.attributes[d]),this.register_fill_last_page(this.attributes[c]),this.register_max_pages(this.attributes[f]),this.register_current_page(this.attributes[p]),this.paginated=void 0!==this.items_per_page,this.create_column_configurations()}return t.prototype.register_items_per_page=function(t){return isNaN(t)?this.items_per_page=t:(this.items_per_page=""+this.id+"_itemsPerPage",this.initial_items_per_page=parseInt(t))},t.prototype.register_sort_context=function(t){return void 0!==t?"global"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global"):"page"===t?(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="page"):this.sort_context=t:(this.sort_context=""+this.id+"_sortContext",this.initial_sort_context="global")},t.prototype.register_fill_last_page=function(t){return void 0!==t?"true"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):"false"===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!1):""===t?(this.fill_last_page=""+this.id+"_fillLastPage",this.initial_fill_last_page=!0):this.fill_last_page=t:void 0},t.prototype.register_max_pages=function(t){return void 0!==t?isNaN(t)?this.max_pages=t:(this.max_pages=""+this.id+"_maxPages",this.initial_max_pages=parseInt(t)):void 0},t.prototype.register_current_page=function(t){return void 0!==t?isNaN(t)?this.current_page=t:(this.current_page=""+this.id+"_currentPage",this.initial_current_page=parseInt(t)):(this.current_page=""+this.id+"_currentPage",this.initial_current_page=0)},t.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},t.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},t.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},t.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},t.prototype.collect_header_markup=function(t){var e,i,n,r,a,o;for(e={},n=t.find("tr"),o=n.find("th"),r=0,a=o.length;a>r;r++)i=o[r],i=angular.element(i),e[i.attr("at-attribute")]={custom_content:i.html(),attributes:i[0].attributes};return e},t.prototype.collect_body_markup=function(t){var e,i,n,r,a,o,s,u,l,p;for(i=[],p=t.find("td"),u=0,l=p.length;l>u;u++)a=p[u],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),n=this.getInitialSorting(a),i.push({attribute:e,title:o,sortable:r,width:s,initialSorting:n});return i},t.prototype.create_column_configurations=function(){var t,i,n,r,a;for(i=this.collect_header_markup(this.table_element),t=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=t.length;a>r;r++)n=t[r],this.column_configurations.push(new e(n,i[n.attribute]));return this.column_configurations},t}(),a=function(){function t(){}return t.prototype.setupTr=function(t,e){var i,n;return i=t.find("tbody"),n=i.find("tr"),n.attr("ng-repeat",e),i},t}(),o=function(t){function e(t){this.repeatString="item in "+t.list+" | orderBy:predicate:descending"}return y(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(a),n=function(t){function e(t){this.table_configuration=t,this.repeatString="item in sorted_and_paginated_list"}return y(e,t),e.prototype.compile=function(t){var e,i,n,r,a,o,s;for(i=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)n=a[o],r+=" ";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.table_configuration.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),i.append(e)},e.prototype.link=function(t,e,i,n){var a,o,s,u,l;return s=this.table_configuration,l=new r(t,s),o=function(t,e,i,n,r,a,o){var s,u;return t?(u=t,s=i*e-t.length,"global"===n?(u=o("orderBy")(u,r,a),u=o("limitTo")(u,s),u=o("limitTo")(u,i)):(u=o("limitTo")(u,s),u=o("limitTo")(u,i),u=o("orderBy")(u,r,a)),u):[]},a=function(t,e,i,n){var r,a,o,s,u,l,p,c,g,_;if(n=parseInt(n),t.length<=0){for(g=[],o=s=0,l=n-1;l>=0?l>=s:s>=l;o=l>=0?++s:--s)g.push(o);return g}if(e===i-1){if(a=t.length%n,0!==a){for(r=n-a-1,_=[],o=u=p=t.length,c=t.length+r;c>=p?c>=u:u>=c;o=c>=p?++u:--u)_.push(o);return _}return[]}},u=function(){var e;return t.sorted_and_paginated_list=o(l.get_list(),l.get_current_page(),l.get_items_per_page(),l.get_sort_context(),t.predicate,t.descending,n),e=Math.ceil(l.get_list().length/l.get_items_per_page()),t.filler_array=a(l.get_list(),l.get_current_page(),e,l.get_items_per_page())},t.$watch(s.current_page,function(){return u()}),t.$watch(s.items_per_page,function(){return u()}),t.$watch(s.sort_context,function(){return u()}),t.$watch(""+s.list+".length",function(){return t[b]=Math.ceil(t[s.list].length/l.get_items_per_page()),u()}),t.$watch("predicate",function(){return u()}),t.$watch("descending",function(){return u()})},e}(a),s=function(){function t(t,e){this.element=t,this.table_configuration=e}return t.prototype.constructHeader=function(){var t,e,i,n,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,i=0,n=r.length;n>i;i++)t=r[i],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,i;return e=this.element.find("thead"),e?(t=this.constructHeader(),i=angular.element(e).find("tr"),i.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new n(this.table_configuration):new o(this.table_configuration)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,i,n,r,a;for(r=this.table_configuration.column_configurations,a=[],i=0,n=r.length;n>i;i++)if(e=r[i],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,i,n){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,i,n)},t}(),angular.module("angular-table",[]),b="number_of_pages",h="atList",_="atItemsPerPage",c="atFillLastPage",d="atSortContext",f="atMaxPages",p="atCurrentPage",l="at-attribute",m="at-sortable",g="at-initial-sorting",r=function(){function t(t,e){this.scope=t,this.config=e}return t.prototype.get_list=function(){return this.scope.$eval(this.config.list)},t.prototype.get_items_per_page=function(){return this.scope.$eval(this.config.items_per_page)},t.prototype.get_current_page=function(){return this.scope.$eval(this.config.current_page)},t.prototype.get_max_pages=function(){return this.scope.$eval(this.config.max_pages)},t.prototype.get_sort_context=function(){return this.scope.$eval(this.config.sort_context)},t}(),t=function(){function t(){this.mappings={}}return t.prototype.get_table_configuration=function(t){return this.mappings[t].table_configuration},t.prototype.register_table=function(t){var e,i,n;if(e=(i=this.mappings)[n=t.id]||(i[n]={}),e.table_configuration=t,e.pagination_scope)throw"WHOOPS"},t.prototype.register_table_scope=function(t,e){var i;return this.mappings[t].table_scope=e,i=this.mappings[t].table_configuration,i.initial_items_per_page&&(e.$parent[i.items_per_page]=i.initial_items_per_page),i.initial_sort_context&&(e.$parent[i.sort_context]=i.initial_sort_context),i.initial_fill_last_page&&(e.$parent[i.fill_last_page]=i.initial_fill_last_page),i.initial_max_pages&&(e.$parent[i.max_pages]=i.initial_max_pages),void 0!==i.initial_current_page?e.$parent[i.current_page]=i.initial_current_page:void 0},t.prototype.register_pagination_scope=function(){},t}(),angular.module("angular-table").service("angularTableManager",[function(){return new t}]),angular.module("angular-table").directive("atTable",["$filter","angularTableManager",function(t,e){return{restrict:"AC",scope:!0,controller:["$scope","$element","$attrs",function(i,n,r){var a;return a=r.id,a?e.register_table_scope(a,i,t):void 0}],compile:function(i,n){var r,a;return a=new u(i,n),e.register_table(a),r=new s(i,a),r.compile(),{post:function(e,i,n){return r.post(e,i,n,t)}}}}}]),i=function(){function t(t,e,i,n){if(this.lower_bound=null!=t?t:0,this.upper_bound=null!=e?e:1,null==i&&(i=0),this.length=null!=n?n:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(i)}return t.prototype.generate=function(t){var e,i,n,r;for(t>this.upper_bound-this.length?t=this.upper_bound-this.length:t=t?n>=i:i>=n;e=n>=t?++i:--i)r.push(e);return r},t.prototype.reset_parameters=function(t,e,i){if(this.lower_bound=t,this.upper_bound=e,this.length=i,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},t.prototype.relocate=function(t){var e;return e=this.data[0]+t,this.data=this.generate(e,e+this.length)},t.prototype.realign_greedy=function(t){var e;return tthis.data[this.length-1]?(e=t-(this.length-1),this.data=this.generate(e)):void 0},t.prototype.realign_generous=function(){},t}(),angular.module("angular-table").directive("atPagination",["angularTableManager",function(t){return{replace:!0,restrict:"E",template:"",controller:["$scope","$element","$attrs",function(e,i,n){return t.register_pagination_scope(n.atTableId,e)}],scope:!0,link:function(e,n,a){var o,s,u,l,p,c,g;return p=t.get_table_configuration(a.atTableId),g=new r(e,p),e.page_sequence=new i,u=function(t){return e.$parent.$eval(""+p.current_page+"="+t)},o=function(){return e[b]},l=function(t){return e[b]=t},c=function(){var t,i;return e[p.list]?e[p.list].length>0?(t=Math.ceil(e[p.list].length/g.get_items_per_page()),l(t),i=e.show_sectioning()?g.get_max_pages():t,e.page_sequence.reset_parameters(0,t,i),u(s(g.get_current_page(),0,o()-1)),e.page_sequence.realign_greedy(g.get_current_page())):(l(1),e.page_sequence.reset_parameters(0,1,1),u(0),e.page_sequence.realign_greedy(0)):void 0},s=function(t,e,i){return t=Math.max(e,t),Math.min(i,t)},e.show_sectioning=function(){return g.get_max_pages()&&o()>g.get_max_pages()},e.get_current_page=function(){return g.get_current_page()},e.step_page=function(t){return t=parseInt(t),u(s(g.get_current_page()+t,0,o()-1)),e.page_sequence.realign_greedy(g.get_current_page())},e.go_to_page=function(t){return u(t)},e.jump_back=function(){return e.step_page(-g.get_max_pages())},e.jump_ahead=function(){return e.step_page(g.get_max_pages())},c(),e.$watch(p.items_per_page,function(){return c()}),e.$watch(p.max_pages,function(){return c()}),e.$watch(p.list,function(){return c()}),e.$watch(""+p.list+".length",function(){return c()})}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var t,e,n,i,r,a,o,s,u,c,l,g={}.hasOwnProperty,p=function(t,e){function n(){this.constructor=t}for(var i in e)g.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=function(){function t(t){this.config_object_name=t,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return t}(),r=function(){function t(t,e,n){this.scope=t,this.configuration_variable_names=e,this.list_name=n}return t.prototype.get_list=function(){return this.scope.$eval(this.list_name)},t.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},t.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},t.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},t.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},t.prototype.set_current_page=function(t){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+t)},t}(),angular.module("angular-table",[]),c="number_of_pages",l="",t=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th"))},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,n,i,r,a;if(this.custom_content){for(r=this.attributes,a=[],n=0,i=r.length;i>n;n++)e=r[n],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),u=function(){function e(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return e.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},e.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},e.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},e.prototype.collect_header_markup=function(t){var e,n,i,r,a,o;for(e={},i=t.find("tr"),o=i.find("th"),r=0,a=o.length;a>r;r++)n=o[r],n=angular.element(n),e[n.attr("at-attribute")]={custom_content:n.html(),attributes:n[0].attributes};return e},e.prototype.collect_body_markup=function(t){var e,n,i,r,a,o,s,u,c,l;for(n=[],l=t.find("td"),u=0,c=l.length;c>u;u++)a=l[u],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),i=this.getInitialSorting(a),n.push({attribute:e,title:o,sortable:r,width:s,initialSorting:i});return n},e.prototype.create_column_configurations=function(){var e,n,i,r,a;for(n=this.collect_header_markup(this.table_element),e=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=e.length;a>r;r++)i=e[r],this.column_configurations.push(new t(i,n[i.attribute]));return this.column_configurations},e}(),a=function(){function t(){}return t.prototype.setupTr=function(t,e){var n,i;return n=t.find("tbody"),i=n.find("tr"),i.attr("ng-repeat",e),n},t}(),o=function(t){function e(t,e){this.list=e,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return p(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(a),i=function(t){function e(t){this.configuration_variable_names=t,this.repeatString="item in sorted_and_paginated_list"}return p(e,t),e.prototype.compile=function(t){var e,n,i,r,a,o,s;for(n=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)i=a[o],r+=" ";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.configuration_variable_names.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),n.append(e)},e.prototype.link=function(t,e,n,i){var a,o,s,u,l;return a=this.configuration_variable_names,l=new r(t,a,n.atList),s=function(t,e,n,i,r,a,o){var s,u;return t?(u=t,s=n*e-t.length,"global"===i?(u=o("orderBy")(u,r,a),u=o("limitTo")(u,s),u=o("limitTo")(u,n)):(u=o("limitTo")(u,s),u=o("limitTo")(u,n),u=o("orderBy")(u,r,a)),u):[]},o=function(t,e,n,i){var r,a,o,s,u,c,l,g,p,_;if(i=parseInt(i),t.length<=0){for(p=[],o=s=0,c=i-1;c>=0?c>=s:s>=c;o=c>=0?++s:--s)p.push(o);return p}if(e===n-1){if(a=t.length%i,0!==a){for(r=i-a-1,_=[],o=u=l=t.length,g=t.length+r;g>=l?g>=u:u>=g;o=g>=l?++u:--u)_.push(o);return _}return[]}},u=function(){var e;return t.sorted_and_paginated_list=s(l.get_list(),l.get_current_page(),l.get_items_per_page(),l.get_sort_context(),t.predicate,t.descending,i),e=Math.ceil(l.get_list().length/l.get_items_per_page()),t.filler_array=o(l.get_list(),l.get_current_page(),e,l.get_items_per_page())},t.$watch(a.current_page,function(){return u()}),t.$watch(a.items_per_page,function(){return u()}),t.$watch(a.sort_context,function(){return u()}),t.$watch(""+n.atList+".length",function(){return t[c]=Math.ceil(l.get_list().length/l.get_items_per_page()),u()}),t.$watch("predicate",function(){return u()}),t.$watch("descending",function(){return u()})},e}(a),s=function(){function t(t,e,n){this.element=t,this.table_configuration=e,this.configuration_variable_names=n}return t.prototype.constructHeader=function(){var t,e,n,i,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,n=0,i=r.length;i>n;n++)t=r[n],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,n;return e=this.element.find("thead"),e?(t=this.constructHeader(),n=angular.element(e).find("tr"),n.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.configuration_variable_names):new o(this.configuration_variable_names,this.table_configuration.list)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,n,i,r,a;for(r=this.table_configuration.column_configurations,a=[],n=0,i=r.length;i>n;n++)if(e=r[n],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,n,i){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,n,i)},t}(),n=function(){function t(t,e,n,i){if(this.lower_bound=null!=t?t:0,this.upper_bound=null!=e?e:1,null==n&&(n=0),this.length=null!=i?i:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(n)}return t.prototype.generate=function(t){var e,n,i,r;for(t>this.upper_bound-this.length?t=this.upper_bound-this.length:t=t?i>=n:n>=i;e=i>=t?++n:--n)r.push(e);return r},t.prototype.reset_parameters=function(t,e,n){if(this.lower_bound=t,this.upper_bound=e,this.length=n,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},t.prototype.relocate=function(t){var e;return e=this.data[0]+t,this.data=this.generate(e,e+this.length)},t.prototype.realign_greedy=function(t){var e;return tthis.data[this.length-1]?(e=t-(this.length-1),this.data=this.generate(e)):void 0},t.prototype.realign_generous=function(){},t}(),angular.module("angular-table").directive("atTable",["$filter",function(t){return{restrict:"AC",scope:!0,compile:function(n,i){var r,a,o;return o=new u(n,i),r=new e(i.atConfig),a=new s(n,o,r),a.compile(),{post:function(e,n,i){return a.post(e,n,i,t)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:l,link:function(t,i,a){var o,s,u,l,g,p;return o=new e(a.atConfig),p=new r(t,o,a.atList),u=function(t,e,n){return t=Math.max(e,t),Math.min(n,t)},s=function(){return t[c]},l=function(e){return t[c]=e},g=function(){var e,n;return p.get_list()?p.get_list().length>0?(e=Math.ceil(p.get_list().length/p.get_items_per_page()),l(e),n=t.show_sectioning()?p.get_max_pages():e,t.page_sequence.reset_parameters(0,e,n),p.set_current_page(u(p.get_current_page(),0,s()-1)),t.page_sequence.realign_greedy(p.get_current_page())):(l(1),t.page_sequence.reset_parameters(0,1,1),p.set_current_page(0),t.page_sequence.realign_greedy(0)):void 0},t.show_sectioning=function(){return p.get_max_pages()&&s()>p.get_max_pages()},t.get_current_page=function(){return p.get_current_page()},t.step_page=function(e){return e=parseInt(e),p.set_current_page(u(p.get_current_page()+e,0,s()-1)),t.page_sequence.realign_greedy(p.get_current_page())},t.go_to_page=function(t){return p.set_current_page(t)},t.jump_back=function(){return t.step_page(-p.get_max_pages())},t.jump_ahead=function(){return t.step_page(p.get_max_pages())},t.page_sequence=new n,t.$watch(o.items_per_page,function(){return g()}),t.$watch(o.max_pages,function(){return g()}),t.$watch(a.atList,function(){return g()}),t.$watch(""+a.atList+".length",function(){return g()}),g()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file diff --git a/coffee/angular_table.coffee b/coffee/angular_table.coffee index fbdb73c..fe87ed6 100644 --- a/coffee/angular_table.coffee +++ b/coffee/angular_table.coffee @@ -33,35 +33,33 @@ irk_number_of_pages = "number_of_pages" pagination_template = "
    - +
    " \ No newline at end of file diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index b814413..cb073ad 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -3,10 +3,65 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var AngularTableManager, ColumnConfiguration, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, erk_attribute, erk_current_page, erk_fill_last_page, erk_initial_sorting, erk_items_per_page, erk_list, erk_max_pages, erk_sort_context, erk_sortable, irk_number_of_pages, + var ColumnConfiguration, ConfigurationVariableNames, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, irk_number_of_pages, pagination_template, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + ConfigurationVariableNames = (function() { + function ConfigurationVariableNames(config_object_name) { + this.config_object_name = config_object_name; + this.items_per_page = "" + this.config_object_name + ".itemsPerPage"; + this.sort_context = "" + this.config_object_name + ".sortContext"; + this.fill_last_page = "" + this.config_object_name + ".fillLastPage"; + this.max_pages = "" + this.config_object_name + ".maxPages"; + this.current_page = "" + this.config_object_name + ".currentPage"; + } + + return ConfigurationVariableNames; + + })(); + + ScopeConfigWrapper = (function() { + function ScopeConfigWrapper(scope, configuration_variable_names, list_name) { + this.scope = scope; + this.configuration_variable_names = configuration_variable_names; + this.list_name = list_name; + } + + ScopeConfigWrapper.prototype.get_list = function() { + return this.scope.$eval(this.list_name); + }; + + ScopeConfigWrapper.prototype.get_items_per_page = function() { + return this.scope.$eval(this.configuration_variable_names.items_per_page) || 10; + }; + + ScopeConfigWrapper.prototype.get_current_page = function() { + return this.scope.$eval(this.configuration_variable_names.current_page) || 0; + }; + + ScopeConfigWrapper.prototype.get_max_pages = function() { + return this.scope.$eval(this.configuration_variable_names.max_pages) || void 0; + }; + + ScopeConfigWrapper.prototype.get_sort_context = function() { + return this.scope.$eval(this.configuration_variable_names.sort_context) || 'global'; + }; + + ScopeConfigWrapper.prototype.set_current_page = function(current_page) { + return this.scope.$eval("" + this.configuration_variable_names.current_page + "=" + current_page); + }; + + return ScopeConfigWrapper; + + })(); + + angular.module("angular-table", []); + + irk_number_of_pages = "number_of_pages"; + + pagination_template = ""; + ColumnConfiguration = (function() { function ColumnConfiguration(body_markup, header_markup) { this.attribute = body_markup.attribute; @@ -22,8 +77,7 @@ ColumnConfiguration.prototype.create_element = function() { var th; - th = angular.element(document.createElement("th")); - return th.attr("style", "cursor: pointer;"); + return th = angular.element(document.createElement("th")); }; ColumnConfiguration.prototype.render_title = function(element) { @@ -76,86 +130,12 @@ this.table_element = table_element; this.attributes = attributes; this.id = this.attributes.id; - this.list = this.attributes[erk_list]; - if (this.attributes[erk_items_per_page]) { - this.register_items_per_page(this.attributes[erk_items_per_page]); - } - this.register_sort_context(this.attributes[erk_sort_context]); - this.register_fill_last_page(this.attributes[erk_fill_last_page]); - this.register_max_pages(this.attributes[erk_max_pages]); - this.register_current_page(this.attributes[erk_current_page]); - this.paginated = this.items_per_page !== void 0; + this.config = this.attributes.atConfig; + this.paginated = this.attributes.atPaginated != null; + this.list = this.attributes.atList; this.create_column_configurations(); } - TableConfiguration.prototype.register_items_per_page = function(items_per_page) { - if (isNaN(items_per_page)) { - return this.items_per_page = items_per_page; - } else { - this.items_per_page = "" + this.id + "_itemsPerPage"; - return this.initial_items_per_page = parseInt(items_per_page); - } - }; - - TableConfiguration.prototype.register_sort_context = function(sort_context) { - if (sort_context !== void 0) { - if (sort_context === "global") { - this.sort_context = "" + this.id + "_sortContext"; - return this.initial_sort_context = "global"; - } else if (sort_context === "page") { - this.sort_context = "" + this.id + "_sortContext"; - return this.initial_sort_context = "page"; - } else { - return this.sort_context = sort_context; - } - } else { - this.sort_context = "" + this.id + "_sortContext"; - return this.initial_sort_context = "global"; - } - }; - - TableConfiguration.prototype.register_fill_last_page = function(fill_last_page) { - if (fill_last_page !== void 0) { - if (fill_last_page === "true") { - this.fill_last_page = "" + this.id + "_fillLastPage"; - return this.initial_fill_last_page = true; - } else if (fill_last_page === "false") { - this.fill_last_page = "" + this.id + "_fillLastPage"; - return this.initial_fill_last_page = false; - } else if (fill_last_page === "") { - this.fill_last_page = "" + this.id + "_fillLastPage"; - return this.initial_fill_last_page = true; - } else { - return this.fill_last_page = fill_last_page; - } - } - }; - - TableConfiguration.prototype.register_max_pages = function(max_pages) { - if (max_pages !== void 0) { - if (isNaN(max_pages)) { - return this.max_pages = max_pages; - } else { - this.max_pages = "" + this.id + "_maxPages"; - return this.initial_max_pages = parseInt(max_pages); - } - } - }; - - TableConfiguration.prototype.register_current_page = function(current_page) { - if (current_page !== void 0) { - if (isNaN(current_page)) { - return this.current_page = current_page; - } else { - this.current_page = "" + this.id + "_currentPage"; - return this.initial_current_page = parseInt(current_page); - } - } else { - this.current_page = "" + this.id + "_currentPage"; - return this.initial_current_page = 0; - } - }; - TableConfiguration.prototype.capitaliseFirstLetter = function(string) { if (string) { return string.charAt(0).toUpperCase() + string.slice(1); @@ -269,8 +249,9 @@ StandardSetup = (function(_super) { __extends(StandardSetup, _super); - function StandardSetup(table_configuration) { - this.repeatString = "item in " + table_configuration.list + " | orderBy:predicate:descending"; + function StandardSetup(configuration_variable_names, list) { + this.list = list; + this.repeatString = "item in " + this.list + " | orderBy:predicate:descending"; } StandardSetup.prototype.compile = function(element, attributes, transclude) { @@ -286,8 +267,8 @@ PaginatedSetup = (function(_super) { __extends(PaginatedSetup, _super); - function PaginatedSetup(table_configuration) { - this.table_configuration = table_configuration; + function PaginatedSetup(configuration_variable_names) { + this.configuration_variable_names = configuration_variable_names; this.repeatString = "item in sorted_and_paginated_list"; } @@ -301,16 +282,16 @@ tdString += " "; } fillerTr = angular.element(document.createElement("tr")); - fillerTr.attr("ng-show", this.table_configuration.fill_last_page); + fillerTr.attr("ng-show", this.configuration_variable_names.fill_last_page); fillerTr.html(tdString); fillerTr.attr("ng-repeat", "item in filler_array"); tbody.append(fillerTr); }; PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) { - var get_filler_array, get_sorted_and_paginated_list, tc, update_stuff, w; - tc = this.table_configuration; - w = new ScopeConfigWrapper($scope, tc); + var cvn, get_filler_array, get_sorted_and_paginated_list, update_stuff, w; + cvn = this.configuration_variable_names; + w = new ScopeConfigWrapper($scope, cvn, $attributes.atList); get_sorted_and_paginated_list = function(list, current_page, items_per_page, sort_context, predicate, descending, $filter) { var from_page, val; if (list) { @@ -359,17 +340,17 @@ nop = Math.ceil(w.get_list().length / w.get_items_per_page()); return $scope.filler_array = get_filler_array(w.get_list(), w.get_current_page(), nop, w.get_items_per_page()); }; - $scope.$watch(tc.current_page, function() { + $scope.$watch(cvn.current_page, function() { return update_stuff(); }); - $scope.$watch(tc.items_per_page, function() { + $scope.$watch(cvn.items_per_page, function() { return update_stuff(); }); - $scope.$watch(tc.sort_context, function() { + $scope.$watch(cvn.sort_context, function() { return update_stuff(); }); - $scope.$watch("" + tc.list + ".length", function() { - $scope[irk_number_of_pages] = Math.ceil($scope[tc.list].length / w.get_items_per_page()); + $scope.$watch("" + $attributes.atList + ".length", function() { + $scope[irk_number_of_pages] = Math.ceil(w.get_list().length / w.get_items_per_page()); return update_stuff(); }); $scope.$watch("predicate", function() { @@ -385,9 +366,10 @@ })(Setup); Table = (function() { - function Table(element, table_configuration) { + function Table(element, table_configuration, configuration_variable_names) { this.element = element; this.table_configuration = table_configuration; + this.configuration_variable_names = configuration_variable_names; } Table.prototype.constructHeader = function() { @@ -414,9 +396,9 @@ Table.prototype.get_setup = function() { if (this.table_configuration.paginated) { - return new PaginatedSetup(this.table_configuration); + return new PaginatedSetup(this.configuration_variable_names); } else { - return new StandardSetup(this.table_configuration); + return new StandardSetup(this.configuration_variable_names, this.table_configuration.list); } }; @@ -466,140 +448,20 @@ })(); - angular.module("angular-table", []); - - irk_number_of_pages = "number_of_pages"; - - erk_list = "atList"; - - erk_items_per_page = "atItemsPerPage"; - - erk_fill_last_page = "atFillLastPage"; - - erk_sort_context = "atSortContext"; - - erk_max_pages = "atMaxPages"; - - erk_current_page = "atCurrentPage"; - - erk_attribute = "at-attribute"; - - erk_sortable = "at-sortable"; - - erk_initial_sorting = "at-initial-sorting"; - - ScopeConfigWrapper = (function() { - function ScopeConfigWrapper(table_scope, table_configuration) { - this.scope = table_scope; - this.config = table_configuration; - } - - ScopeConfigWrapper.prototype.get_list = function() { - return this.scope.$eval(this.config.list); - }; - - ScopeConfigWrapper.prototype.get_items_per_page = function() { - return this.scope.$eval(this.config.items_per_page); - }; - - ScopeConfigWrapper.prototype.get_current_page = function() { - return this.scope.$eval(this.config.current_page); - }; - - ScopeConfigWrapper.prototype.get_max_pages = function() { - return this.scope.$eval(this.config.max_pages); - }; - - ScopeConfigWrapper.prototype.get_sort_context = function() { - return this.scope.$eval(this.config.sort_context); - }; - - return ScopeConfigWrapper; - - })(); - - AngularTableManager = (function() { - function AngularTableManager() { - this.mappings = {}; - } - - AngularTableManager.prototype.get_table_configuration = function(id) { - return this.mappings[id].table_configuration; - }; - - AngularTableManager.prototype.register_table = function(table_configuration) { - var mapping, _base, _name; - mapping = (_base = this.mappings)[_name = table_configuration.id] || (_base[_name] = {}); - mapping.table_configuration = table_configuration; - if (mapping.pagination_scope) { - throw "WHOOPS"; - } - }; - - AngularTableManager.prototype.register_table_scope = function(id, scope, filter) { - var tc; - this.mappings[id].table_scope = scope; - tc = this.mappings[id].table_configuration; - if (tc.initial_items_per_page) { - scope.$parent[tc.items_per_page] = tc.initial_items_per_page; - } - if (tc.initial_sort_context) { - scope.$parent[tc.sort_context] = tc.initial_sort_context; - } - if (tc.initial_fill_last_page) { - scope.$parent[tc.fill_last_page] = tc.initial_fill_last_page; - } - if (tc.initial_max_pages) { - scope.$parent[tc.max_pages] = tc.initial_max_pages; + PageSequence = (function() { + function PageSequence(lower_bound, upper_bound, start, length) { + this.lower_bound = lower_bound != null ? lower_bound : 0; + this.upper_bound = upper_bound != null ? upper_bound : 1; + if (start == null) { + start = 0; } - if (tc.initial_current_page !== void 0) { - return scope.$parent[tc.current_page] = tc.initial_current_page; + this.length = length != null ? length : 1; + if (this.length > (this.upper_bound - this.lower_bound)) { + throw "sequence is too long"; } - }; - - AngularTableManager.prototype.register_pagination_scope = function(id, pagination_scope) {}; - - return AngularTableManager; - - })(); - - angular.module("angular-table").service("angularTableManager", [ - function() { - return new AngularTableManager(); - } - ]); - - angular.module("angular-table").directive("atTable", [ - "$filter", "angularTableManager", function($filter, angularTableManager) { - return { - restrict: "AC", - scope: true, - controller: [ - "$scope", "$element", "$attrs", function($scope, $element, $attrs) { - var id; - id = $attrs["id"]; - if (id) { - return angularTableManager.register_table_scope(id, $scope, $filter); - } - } - ], - compile: function(element, attributes, transclude) { - var dt, tc; - tc = new TableConfiguration(element, attributes); - angularTableManager.register_table(tc); - dt = new Table(element, tc); - dt.compile(); - return { - post: function($scope, $element, $attributes) { - return dt.post($scope, $element, $attributes, $filter); - } - }; - } - }; + this.data = this.generate(start); } - ]); - PageSequence = (function() { PageSequence.prototype.generate = function(start) { var x, _i, _ref, _results; if (start > (this.upper_bound - this.length)) { @@ -614,19 +476,6 @@ return _results; }; - function PageSequence(lower_bound, upper_bound, start, length) { - this.lower_bound = lower_bound != null ? lower_bound : 0; - this.upper_bound = upper_bound != null ? upper_bound : 1; - if (start == null) { - start = 0; - } - this.length = length != null ? length : 1; - if (this.length > (this.upper_bound - this.lower_bound)) { - throw "sequence is too long"; - } - this.data = this.generate(start); - } - PageSequence.prototype.reset_parameters = function(lower_bound, upper_bound, length) { this.lower_bound = lower_bound; this.upper_bound = upper_bound; @@ -660,25 +509,41 @@ })(); + angular.module("angular-table").directive("atTable", [ + "$filter", function($filter) { + return { + restrict: "AC", + scope: true, + compile: function(element, attributes, transclude) { + var cvn, table, tc; + tc = new TableConfiguration(element, attributes); + cvn = new ConfigurationVariableNames(attributes.atConfig); + table = new Table(element, tc, cvn); + table.compile(); + return { + post: function($scope, $element, $attributes) { + return table.post($scope, $element, $attributes, $filter); + } + }; + } + }; + } + ]); + angular.module("angular-table").directive("atPagination", [ - "angularTableManager", function(angularTableManager) { + function() { return { - replace: true, restrict: "E", - template: "", - controller: [ - "$scope", "$element", "$attrs", function($scope, $element, $attrs) { - return angularTableManager.register_pagination_scope($attrs.atTableId, $scope); - } - ], scope: true, + replace: true, + template: pagination_template, link: function($scope, $element, $attributes) { - var get_number_of_pages, keep_in_bounds, set_current_page, set_number_of_pages, tc, update, w; - tc = angularTableManager.get_table_configuration($attributes.atTableId); - w = new ScopeConfigWrapper($scope, tc); - $scope.page_sequence = new PageSequence(); - set_current_page = function(current_page) { - return $scope.$parent.$eval("" + tc.current_page + "=" + current_page); + var cvn, get_number_of_pages, keep_in_bounds, set_number_of_pages, update, w; + cvn = new ConfigurationVariableNames($attributes.atConfig); + w = new ScopeConfigWrapper($scope, cvn, $attributes.atList); + keep_in_bounds = function(val, min, max) { + val = Math.max(min, val); + return Math.min(max, val); }; get_number_of_pages = function() { return $scope[irk_number_of_pages]; @@ -688,9 +553,9 @@ }; update = function(reset) { var new_number_of_pages, pages_to_display; - if ($scope[tc.list]) { - if ($scope[tc.list].length > 0) { - new_number_of_pages = Math.ceil($scope[tc.list].length / w.get_items_per_page()); + if (w.get_list()) { + if (w.get_list().length > 0) { + new_number_of_pages = Math.ceil(w.get_list().length / w.get_items_per_page()); set_number_of_pages(new_number_of_pages); if ($scope.show_sectioning()) { pages_to_display = w.get_max_pages(); @@ -698,20 +563,16 @@ pages_to_display = new_number_of_pages; } $scope.page_sequence.reset_parameters(0, new_number_of_pages, pages_to_display); - set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); + w.set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); return $scope.page_sequence.realign_greedy(w.get_current_page()); } else { set_number_of_pages(1); $scope.page_sequence.reset_parameters(0, 1, 1); - set_current_page(0); + w.set_current_page(0); return $scope.page_sequence.realign_greedy(0); } } }; - keep_in_bounds = function(val, min, max) { - val = Math.max(min, val); - return Math.min(max, val); - }; $scope.show_sectioning = function() { return w.get_max_pages() && get_number_of_pages() > w.get_max_pages(); }; @@ -720,11 +581,11 @@ }; $scope.step_page = function(step) { step = parseInt(step); - set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)); + w.set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)); return $scope.page_sequence.realign_greedy(w.get_current_page()); }; $scope.go_to_page = function(page) { - return set_current_page(page); + return w.set_current_page(page); }; $scope.jump_back = function() { return $scope.step_page(-w.get_max_pages()); @@ -732,19 +593,20 @@ $scope.jump_ahead = function() { return $scope.step_page(w.get_max_pages()); }; - update(); - $scope.$watch(tc.items_per_page, function() { + $scope.page_sequence = new PageSequence(); + $scope.$watch(cvn.items_per_page, function() { return update(); }); - $scope.$watch(tc.max_pages, function() { + $scope.$watch(cvn.max_pages, function() { return update(); }); - $scope.$watch(tc.list, function() { + $scope.$watch($attributes.atList, function() { return update(); }); - return $scope.$watch("" + tc.list + ".length", function() { + $scope.$watch("" + $attributes.atList + ".length", function() { return update(); }); + return update(); } }; } From 189266e03eff3b541db655824a5c9d7ec8e8ca04 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Thu, 27 Feb 2014 19:10:55 +0100 Subject: [PATCH 114/190] renamed method --- .../directives/table/setup/paginated_setup.coffee | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/coffee/directives/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee index de1cb82..3395a44 100644 --- a/coffee/directives/table/setup/paginated_setup.coffee +++ b/coffee/directives/table/setup/paginated_setup.coffee @@ -54,7 +54,7 @@ class PaginatedSetup extends Setup else [] - update_stuff = () -> + update = () -> $scope.sorted_and_paginated_list = get_sorted_and_paginated_list( w.get_list(), @@ -76,27 +76,26 @@ class PaginatedSetup extends Setup ) $scope.$watch(cvn.current_page, () -> - update_stuff() + update() ) $scope.$watch(cvn.items_per_page, () -> - update_stuff() + update() ) $scope.$watch(cvn.sort_context, () -> - update_stuff() + update() ) $scope.$watch("#{$attributes.atList}.length", () -> $scope[irk_number_of_pages] = Math.ceil(w.get_list().length / w.get_items_per_page()) - update_stuff() + update() ) $scope.$watch("predicate", () -> - update_stuff() + update() ) $scope.$watch("descending", () -> - update_stuff() + update() ) - From 543162f6a1647ac416bf80834b690fa2bcae7c43 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Thu, 27 Feb 2014 19:20:45 +0100 Subject: [PATCH 115/190] compiled new version --- angular-table.js | 16 ++++++++-------- gem/app/assets/javascripts/angular-table.js | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/angular-table.js b/angular-table.js index cb073ad..b1bc9d0 100644 --- a/angular-table.js +++ b/angular-table.js @@ -289,7 +289,7 @@ }; PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) { - var cvn, get_filler_array, get_sorted_and_paginated_list, update_stuff, w; + var cvn, get_filler_array, get_sorted_and_paginated_list, update, w; cvn = this.configuration_variable_names; w = new ScopeConfigWrapper($scope, cvn, $attributes.atList); get_sorted_and_paginated_list = function(list, current_page, items_per_page, sort_context, predicate, descending, $filter) { @@ -334,30 +334,30 @@ } } }; - update_stuff = function() { + update = function() { var nop; $scope.sorted_and_paginated_list = get_sorted_and_paginated_list(w.get_list(), w.get_current_page(), w.get_items_per_page(), w.get_sort_context(), $scope.predicate, $scope.descending, $filter); nop = Math.ceil(w.get_list().length / w.get_items_per_page()); return $scope.filler_array = get_filler_array(w.get_list(), w.get_current_page(), nop, w.get_items_per_page()); }; $scope.$watch(cvn.current_page, function() { - return update_stuff(); + return update(); }); $scope.$watch(cvn.items_per_page, function() { - return update_stuff(); + return update(); }); $scope.$watch(cvn.sort_context, function() { - return update_stuff(); + return update(); }); $scope.$watch("" + $attributes.atList + ".length", function() { $scope[irk_number_of_pages] = Math.ceil(w.get_list().length / w.get_items_per_page()); - return update_stuff(); + return update(); }); $scope.$watch("predicate", function() { - return update_stuff(); + return update(); }); return $scope.$watch("descending", function() { - return update_stuff(); + return update(); }); }; diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index cb073ad..b1bc9d0 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -289,7 +289,7 @@ }; PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) { - var cvn, get_filler_array, get_sorted_and_paginated_list, update_stuff, w; + var cvn, get_filler_array, get_sorted_and_paginated_list, update, w; cvn = this.configuration_variable_names; w = new ScopeConfigWrapper($scope, cvn, $attributes.atList); get_sorted_and_paginated_list = function(list, current_page, items_per_page, sort_context, predicate, descending, $filter) { @@ -334,30 +334,30 @@ } } }; - update_stuff = function() { + update = function() { var nop; $scope.sorted_and_paginated_list = get_sorted_and_paginated_list(w.get_list(), w.get_current_page(), w.get_items_per_page(), w.get_sort_context(), $scope.predicate, $scope.descending, $filter); nop = Math.ceil(w.get_list().length / w.get_items_per_page()); return $scope.filler_array = get_filler_array(w.get_list(), w.get_current_page(), nop, w.get_items_per_page()); }; $scope.$watch(cvn.current_page, function() { - return update_stuff(); + return update(); }); $scope.$watch(cvn.items_per_page, function() { - return update_stuff(); + return update(); }); $scope.$watch(cvn.sort_context, function() { - return update_stuff(); + return update(); }); $scope.$watch("" + $attributes.atList + ".length", function() { $scope[irk_number_of_pages] = Math.ceil(w.get_list().length / w.get_items_per_page()); - return update_stuff(); + return update(); }); $scope.$watch("predicate", function() { - return update_stuff(); + return update(); }); return $scope.$watch("descending", function() { - return update_stuff(); + return update(); }); }; From 59dfa7e2ad9510870b88ba2ef38f7dd7bfd70b0e Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 5 Mar 2014 08:48:14 +0100 Subject: [PATCH 116/190] curly braces not required --- coffee/directives/at_implicit.coffee | 5 +++-- coffee/directives/at_pagination.coffee | 4 ++-- coffee/directives/at_table.coffee | 5 ++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/coffee/directives/at_implicit.coffee b/coffee/directives/at_implicit.coffee index 74a56a0..b89331c 100644 --- a/coffee/directives/at_implicit.coffee +++ b/coffee/directives/at_implicit.coffee @@ -1,7 +1,8 @@ -angular.module("angular-table").directive "atImplicit", [() -> { +angular.module("angular-table").directive "atImplicit", [() -> restrict: "AC" + compile: (element, attributes, transclude) -> attribute = element.attr("at-attribute") throw "at-implicit specified without at-attribute: #{element.html()}" if not attribute element.append "{{item.#{attribute}}}" -}] \ No newline at end of file +] \ No newline at end of file diff --git a/coffee/directives/at_pagination.coffee b/coffee/directives/at_pagination.coffee index 7775ebb..7b73be7 100644 --- a/coffee/directives/at_pagination.coffee +++ b/coffee/directives/at_pagination.coffee @@ -1,4 +1,4 @@ -angular.module("angular-table").directive "atPagination", [() -> { +angular.module("angular-table").directive "atPagination", [() -> restrict: "E" scope: true replace: true @@ -73,4 +73,4 @@ angular.module("angular-table").directive "atPagination", [() -> { update() update() -}] +] \ No newline at end of file diff --git a/coffee/directives/at_table.coffee b/coffee/directives/at_table.coffee index 50f7d40..2236bc1 100644 --- a/coffee/directives/at_table.coffee +++ b/coffee/directives/at_table.coffee @@ -1,4 +1,4 @@ -angular.module("angular-table").directive "atTable", ["$filter", ($filter) -> { +angular.module("angular-table").directive "atTable", ["$filter", ($filter) -> restrict: "AC" scope: true @@ -10,5 +10,4 @@ angular.module("angular-table").directive "atTable", ["$filter", ($filter) -> { post: ($scope, $element, $attributes) -> table.post($scope, $element, $attributes, $filter) - -}] +] \ No newline at end of file From 6bd94d2e7500738e1ea7360bca9782f00a386345 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 5 Mar 2014 09:29:24 +0100 Subject: [PATCH 117/190] removed unused tests --- test/metaCollectorTest.coffee | 28 -------------- test/tests.coffee | 70 ----------------------------------- 2 files changed, 98 deletions(-) delete mode 100644 test/metaCollectorTest.coffee delete mode 100644 test/tests.coffee diff --git a/test/metaCollectorTest.coffee b/test/metaCollectorTest.coffee deleted file mode 100644 index 529b749..0000000 --- a/test/metaCollectorTest.coffee +++ /dev/null @@ -1,28 +0,0 @@ -# describe "angular-table", () -> -# describe "MetaCollector", () -> - -# mc = null - -# beforeEach () -> -# module("angular-table") -# inject (metaCollector) -> -# mc = metaCollector - -# it "bla", () -> - -# header = angular.element( -# " -# -#
    hello world
    " -# ) - -# # TODO uncomment - - -# # headerMarkup = mc.collectCustomHeaderMarkup(header) - -# # one = headerMarkup["one"] - -# # expect(one).toBeDefined() -# # expect(one["content"]).toEqual "hello world" -# # expect(one["attributes"]).toBeDefined() diff --git a/test/tests.coffee b/test/tests.coffee deleted file mode 100644 index b6824f2..0000000 --- a/test/tests.coffee +++ /dev/null @@ -1,70 +0,0 @@ -# describe "AnglarTable", () -> - -# template1 = "test/templates/sortableTable.html" -# template2 = "test/templates/tableWithPagination.html" - -# beforeEach(module("angular-table")) -# beforeEach(module(template1, template2)) - -# it "makes a table sortable", inject ($compile, $rootScope, $templateCache) -> - -# element = loadTemplate template1, $templateCache - -# $rootScope.cities = [{name: "Helsinki"}, {name: "Zurich"}, {name: "Amsterdam"}] - -# element = $compile(element)($rootScope) -# $rootScope.$digest() - -# tds = extract_html_to_array(element.find("td")) -# expect(tds).toEqual ["Zurich", "Helsinki", "Amsterdam"] - -# element.find("th")[0].click() - -# tds = extract_html_to_array(element.find("td")) -# expect(tds).toEqual ["Amsterdam", "Helsinki", "Zurich"] - - - -# it "adds pagination to a table", inject ($compile, $rootScope, $templateCache) -> - -# element = loadTemplate template2, $templateCache - -# $rootScope.rammstein = [ -# {name: "Till"}, {name: "Richard"}, {name: "Christoph"}, -# {name: "Paul"}, {name: "Flake"}, {name: "Oliver"}] - -# element = $compile(element)($rootScope) -# $rootScope.$digest() - -# tds = extract_html_to_array(element.find("td")) -# expect(tds).toEqual ["Till", "Richard", "Christoph"] - -# paginationLinks = element.find "a" -# _.find(paginationLinks, (link) -> angular.element(link).html() == "2").click() - -# tds = extract_html_to_array(element.find("td")) -# expect(tds).toEqual ["Paul", "Flake", "Oliver"] - -# # it "the pagination automatically updates when elements are added to or removed from the list", -# # inject ($compile, $rootScope, $templateCache) -> - -# # element = loadTemplate template2, $templateCache - -# # $rootScope.rammstein = [ -# # {name: "Till"}, {name: "Richard"}, {name: "Christoph"}] - -# # element = $compile(element)($rootScope) -# # $rootScope.$digest() - -# # tds = extract_html_to_array(element.find("td")) -# # expect(tds).toEqual ["Till", "Richard", "Christoph"] - -# # paginationLinks = element.find "a" -# # # there should be three buttons: << | 1 | >> -# # expect(paginationLinks.length).toEqual 3 - -# # $rootScope.rammstein.push {name: "Paul"} -# # $rootScope.$digest() -# # paginationLinks = element.find "a" -# # # now, there should be four buttons: << | 1 | 2 | >> -# # expect(paginationLinks.length).toEqual 4 From 785392de955d4d384adadd5a5cb29fafdb18f9e4 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 5 Mar 2014 09:30:48 +0100 Subject: [PATCH 118/190] renamed test files --- test/{pagination.coffee => paginated_setup.coffee} | 0 test/{sorting.coffee => standard_setup.coffee} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename test/{pagination.coffee => paginated_setup.coffee} (100%) rename test/{sorting.coffee => standard_setup.coffee} (100%) diff --git a/test/pagination.coffee b/test/paginated_setup.coffee similarity index 100% rename from test/pagination.coffee rename to test/paginated_setup.coffee diff --git a/test/sorting.coffee b/test/standard_setup.coffee similarity index 100% rename from test/sorting.coffee rename to test/standard_setup.coffee From 2c0b9282c43589f37ce296981c4926d4baef04c5 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 5 Mar 2014 09:33:05 +0100 Subject: [PATCH 119/190] removed unused test files --- .../pagination/complete_config_hardcoded.html | 17 ----------------- test/templates/pagination/pagination.html | 11 ----------- .../pagination/sort_context_global.html | 10 ---------- .../templates/pagination/sort_context_page.html | 10 ---------- 4 files changed, 48 deletions(-) delete mode 100644 test/templates/pagination/complete_config_hardcoded.html delete mode 100644 test/templates/pagination/pagination.html delete mode 100644 test/templates/pagination/sort_context_global.html delete mode 100644 test/templates/pagination/sort_context_page.html diff --git a/test/templates/pagination/complete_config_hardcoded.html b/test/templates/pagination/complete_config_hardcoded.html deleted file mode 100644 index 4ed3b40..0000000 --- a/test/templates/pagination/complete_config_hardcoded.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - -
    - - diff --git a/test/templates/pagination/pagination.html b/test/templates/pagination/pagination.html deleted file mode 100644 index 94a7702..0000000 --- a/test/templates/pagination/pagination.html +++ /dev/null @@ -1,11 +0,0 @@ -
    - - - - - - - -
    {{item.name}}
    - - diff --git a/test/templates/pagination/sort_context_global.html b/test/templates/pagination/sort_context_global.html deleted file mode 100644 index ea178cb..0000000 --- a/test/templates/pagination/sort_context_global.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - -
    - - \ No newline at end of file diff --git a/test/templates/pagination/sort_context_page.html b/test/templates/pagination/sort_context_page.html deleted file mode 100644 index f471c19..0000000 --- a/test/templates/pagination/sort_context_page.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - -
    - - \ No newline at end of file From 0bf925ef1437a9e35da477af8721baaacfe1de5a Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 5 Mar 2014 10:26:38 +0100 Subject: [PATCH 120/190] updated tests --- test/paginated_setup.coffee | 8 ++-- test/standard_setup.coffee | 41 ++++++++++++++----- ...arameterized.html => paginated_setup.html} | 2 +- test/templates/sorting/sorting.html | 10 ----- test/templates/standard_setup.html | 10 +++++ test/test_helper.coffee | 15 ++++--- 6 files changed, 56 insertions(+), 30 deletions(-) rename test/templates/{pagination/complete_config_parameterized.html => paginated_setup.html} (96%) delete mode 100644 test/templates/sorting/sorting.html create mode 100644 test/templates/standard_setup.html diff --git a/test/paginated_setup.coffee b/test/paginated_setup.coffee index a07070b..c26af79 100644 --- a/test/paginated_setup.coffee +++ b/test/paginated_setup.coffee @@ -1,5 +1,5 @@ describe "angular-table", () -> - describe "Pagination", () -> + describe "paginated setup", () -> config_name = "table_config" list_name = "myList" @@ -12,7 +12,7 @@ describe "angular-table", () -> last = 'Last' setups = [{ - template: "pagination/complete_config_parameterized.html" + template: "paginated_setup.html" variable_names: { items_per_page: "#{config_name}.itemsPerPage", max_pages: "#{config_name}.maxPages", @@ -43,7 +43,9 @@ describe "angular-table", () -> } ) - @gui = new GUI(@element, @comp.scope, setup.variable_names) + table = new TableGUI(@element) + pagination = new PaginationGUI(@element) + @gui = new GUI(table, pagination, @comp.scope, setup.variable_names) it "allows to select pages", () -> expect(@gui.pagination.pages).toEqual([1, 2]) diff --git a/test/standard_setup.coffee b/test/standard_setup.coffee index df5f0a1..a2a0aa9 100644 --- a/test/standard_setup.coffee +++ b/test/standard_setup.coffee @@ -1,19 +1,40 @@ describe "angular-table", () -> - describe "sorting", () -> + describe "standard setup", () -> + + expected_rows = [ + ["0", "Helsinki", "Finland"], + ["1", "Zurich", "Switzerland"], + ["2", "Amsterdam", "Netherlands"] + ] beforeEach(() -> - comp = new TemplateCompiler("sorting/sorting.html") + comp = new TemplateCompiler("standard_setup.html") @element = comp.prepare_element((scope) -> - scope.cities = [{name: "Helsinki"}, {name: "Zurich"}, {name: "Amsterdam"}] - scope.config = {} + scope.cities = [{ + id: 0 + name: "Helsinki" + country: "Finland" + }, { + id: 1 + name: "Zurich" + country: "Switzerland" + }, { + id: 2 + name: "Amsterdam" + country: "Netherlands" + }] ) + + @gui = new GUI(new TableGUI(@element), null, comp.scope, null) ) it "allows to set an initial sorting direction", () -> - tds = extract_html_to_array(@element.find("td")) - expect(tds).toEqual ["Zurich", "Helsinki", "Amsterdam"] + expect(@gui.table.rows).toEqual [expected_rows[1], expected_rows[0], expected_rows[2]] + + it "makes columns sortable which are declared at-sortable", () -> + @gui.table.sort(1) + expect(@gui.table.rows).toEqual [expected_rows[2], expected_rows[0], expected_rows[1]] - it "makes columns sortable", () -> - click(@element.find("th")[0]) - tds = extract_html_to_array(@element.find("td")) - expect(tds).toEqual ["Amsterdam", "Helsinki", "Zurich"] \ No newline at end of file + it "leaves columns unsortable if at-sortable is not declared", () -> + @gui.table.sort(2) + expect(@gui.table.rows).toEqual [expected_rows[1], expected_rows[0], expected_rows[2]] \ No newline at end of file diff --git a/test/templates/pagination/complete_config_parameterized.html b/test/templates/paginated_setup.html similarity index 96% rename from test/templates/pagination/complete_config_parameterized.html rename to test/templates/paginated_setup.html index a083c43..eaf0301 100644 --- a/test/templates/pagination/complete_config_parameterized.html +++ b/test/templates/paginated_setup.html @@ -7,4 +7,4 @@ - + \ No newline at end of file diff --git a/test/templates/sorting/sorting.html b/test/templates/sorting/sorting.html deleted file mode 100644 index 61e19b1..0000000 --- a/test/templates/sorting/sorting.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - -
    diff --git a/test/templates/standard_setup.html b/test/templates/standard_setup.html new file mode 100644 index 0000000..34e1d59 --- /dev/null +++ b/test/templates/standard_setup.html @@ -0,0 +1,10 @@ + + + + + + + + + +
    \ No newline at end of file diff --git a/test/test_helper.coffee b/test/test_helper.coffee index 8dc938e..7157608 100644 --- a/test/test_helper.coffee +++ b/test/test_helper.coffee @@ -64,7 +64,6 @@ class TableGUI click(@element.find("th")[i]) @reload() - class PaginationGUI constructor: (@element) -> @reload() @@ -92,13 +91,11 @@ class PaginationGUI @reload() class GUI - constructor: (@element, @scope, @variable_names) -> - @pagination = new PaginationGUI(@element) - @table = new TableGUI(@element) + constructor: (@table, @pagination, @scope, @variable_names) -> reload: () -> - @table.reload() - @pagination.reload() + @table.reload() if @table? + @pagination.reload() if @pagination? alter_scope: (f) -> f(new ScopeWrapper(@scope), @variable_names) @@ -106,9 +103,15 @@ class GUI @reload() click_pagination: (button) -> + throw "no pagination element available" unless @pagination? @pagination.click(button) @table.reload() + click_table_header: (index) -> + @table.click_header(index) + + + click = (el) -> ev = document.createEvent("MouseEvent") ev.initMouseEvent "click", true, true, window, null, 0, 0, 0, 0, false, false, false, false, 0, null From ef50694e4475410b35b105af218898c417fc5948 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 5 Mar 2014 11:30:23 +0100 Subject: [PATCH 121/190] readme --- README.md | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b3e1bc5..40a611e 100644 --- a/README.md +++ b/README.md @@ -9,5 +9,73 @@ pagination with very little effort. * Makes columns sortable * Adds pagination * Implicitly renders cell contents by name convention and allows custom cell content if needed - * Implicitly renders headers and allows custom header content if needed - * Lets you define pagination options `items per page`, `maximum pages`, `sort context` and `fill last page` \ No newline at end of file + * Implicitly renders header titles by name convection and allows custom header content if needed + +## Dependencies +This directive depends on angular only. No jQuery or Bootstrap required! It has been +tested on angular 1.2, but it should also work with 1.1 releases. + +## How +Lets assume we have an array containing objects representing people. A person object has the +following format: + +```javascript +{name: ..., age: ..., birthdate: ...} +``` + +The list contains about 100 entries and we would like to represent that data in a nice, sortable +html table and eventually make it paginated so we don't have to scroll like a madman. With +`angular-table` in our toolbelt, this task becomes easy. Lets write some markup: + +```html + + + + + + + + + +
    +``` + +This renders a simple basic html table, showing every entry in our list. Four attributes have +been used that need further explanation: + + * `at-table` indicate that we want to use the `angular-table` directive to extend + our table + * `at-list` point to the data source in our scope + * `at-attribute` the attribute in each object the respective columns are dedicated to + * `at-implicit` implicitly render the content of each object's attribute defined in `at-attribute` + +Our table looks kind of unspectacular by now, so lets use some css, assuming we have twitter +bootstrap in our sources: + +```html +...
    + +Now that looks better! Next, lets make the birthdate column sortable. We want to see the +youngest people first, therefore sort descending: + +```html + +``` + +And thats it, our table is sortable by birthdate instantly! We can make the other columns +sortable aswell, by using the `at-sortable` attribute only. Our list of people is kind of +long though, and we hate scrolling, so breaking up the table into smaller chunks and making +it possible to go through it with a pagination would be cool. A task done within seconds. +We need to define two additional keywords in our table ... + +```html +...
    +``` + +... and add an additional element to our view. + +```html + +``` + + From 36cfc2148986f0b171f5086250b1a3c3cf892830 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 5 Mar 2014 11:46:12 +0100 Subject: [PATCH 122/190] readme --- README.md | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 40a611e..bfee50b 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ pagination with very little effort. * Makes columns sortable * Adds pagination * Implicitly renders cell contents by name convention and allows custom cell content if needed - * Implicitly renders header titles by name convection and allows custom header content if needed + * Implicitly renders header titles by name convention and allows custom header content if needed ## Dependencies This directive depends on angular only. No jQuery or Bootstrap required! It has been @@ -40,8 +40,8 @@ html table and eventually make it paginated so we don't have to scroll like a ma ``` -This renders a simple basic html table, showing every entry in our list. Four attributes have -been used that need further explanation: +This renders a simple html table with an automatically generated header, showing every entry in +our list. Four attributes have been used that need further explanation: * `at-table` indicate that we want to use the `angular-table` directive to extend our table @@ -54,6 +54,7 @@ bootstrap in our sources: ```html ...
    +``` Now that looks better! Next, lets make the birthdate column sortable. We want to see the youngest people first, therefore sort descending: @@ -63,19 +64,32 @@ youngest people first, therefore sort descending: ``` And thats it, our table is sortable by birthdate instantly! We can make the other columns -sortable aswell, by using the `at-sortable` attribute only. Our list of people is kind of -long though, and we hate scrolling, so breaking up the table into smaller chunks and making -it possible to go through it with a pagination would be cool. A task done within seconds. -We need to define two additional keywords in our table ... +sortable aswell, by using the `at-sortable` attribute only. + +Our list of people is kind of long though, and we hate scrolling, so breaking up the table into +smaller chunks and making it possible to go through it with a pagination would be cool. A task +done within seconds: We need to define two additional keywords in our table ... ```html ...
    ``` -... and add an additional element to our view. +... and add an additional element to our view ... ```html ``` +and end up with a sortable, paginated table! + +## Hacking on angular-table +### Coffee Script +This directive is written in Coffee Script. If you want to contribute, please make sure to +do the changes in the coffee sources only! If you are familiar with Javascript but not with +Coffee Script, I highly recommend you to [take look at it and try it out](http://coffeescript.org). +It has a powerful and beautiful syntax and is easy to learn, You'll need no more than ~2 hours to learn all the basic concepts. +### TDD +The code for this directive is well covered with tests, which can be run with PhantomJS and +Karma. run `npm install` to install the required packages. Then, run `karma start` to run +the tests. From 5553c3af45cd30815228d765d66beefc1397efb4 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 5 Mar 2014 13:49:49 +0100 Subject: [PATCH 123/190] readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bfee50b..d96d2bc 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Angular directive which allows to declare sortable tables and to add pagination with very little effort. ## Features - * Makes columns sortable + * Adds sorting to any column * Adds pagination * Implicitly renders cell contents by name convention and allows custom cell content if needed * Implicitly renders header titles by name convention and allows custom header content if needed @@ -66,7 +66,7 @@ youngest people first, therefore sort descending: And thats it, our table is sortable by birthdate instantly! We can make the other columns sortable aswell, by using the `at-sortable` attribute only. -Our list of people is kind of long though, and we hate scrolling, so breaking up the table into +Our list of people pretty long though, and we hate scrolling, so breaking up the table into smaller chunks and making it possible to go through it with a pagination would be cool. A task done within seconds: We need to define two additional keywords in our table ... @@ -80,7 +80,7 @@ done within seconds: We need to define two additional keywords in our table ... ``` -and end up with a sortable, paginated table! +... and we end up with a sortable, paginated table! ## Hacking on angular-table ### Coffee Script From 18602002f8c15adc3f7706467d894e9baf1756a5 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 5 Mar 2014 21:34:49 +0100 Subject: [PATCH 124/190] readme --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d96d2bc..0485da0 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ youngest people first, therefore sort descending: And thats it, our table is sortable by birthdate instantly! We can make the other columns sortable aswell, by using the `at-sortable` attribute only. -Our list of people pretty long though, and we hate scrolling, so breaking up the table into +Our list of people is pretty long though, and we hate scrolling, so breaking up the table into smaller chunks and making it possible to go through it with a pagination would be cool. A task done within seconds: We need to define two additional keywords in our table ... @@ -85,11 +85,12 @@ done within seconds: We need to define two additional keywords in our table ... ## Hacking on angular-table ### Coffee Script This directive is written in Coffee Script. If you want to contribute, please make sure to -do the changes in the coffee sources only! If you are familiar with Javascript but not with -Coffee Script, I highly recommend you to [take look at it and try it out](http://coffeescript.org). -It has a powerful and beautiful syntax and is easy to learn, You'll need no more than ~2 hours to learn all the basic concepts. +work on the coffee sources only. If you are familiar with Javascript and aren't with +Coffee Script, i highly recommend to [take look at it and try it out](http://coffeescript.org). +It has a powerful and beautiful syntax and is easy to learn. You'll probably need no more than +~2 hours to learn about all the basic concepts. ### TDD The code for this directive is well covered with tests, which can be run with PhantomJS and Karma. run `npm install` to install the required packages. Then, run `karma start` to run -the tests. +the tests. Make sure all the tests pass before you send a pull request. From 5438e206132e2f72e53956b8b66a0db8e106cbde Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 5 Mar 2014 21:47:30 +0100 Subject: [PATCH 125/190] added result links --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 0485da0..23fcb11 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ html table and eventually make it paginated so we don't have to scroll like a ma ``` +[result](http://samu.github.io/angular-table/walkthrough/1.html) This renders a simple html table with an automatically generated header, showing every entry in our list. Four attributes have been used that need further explanation: @@ -55,6 +56,7 @@ bootstrap in our sources: ```html ...
    ``` +[result](http://samu.github.io/angular-table/walkthrough/2.html) Now that looks better! Next, lets make the birthdate column sortable. We want to see the youngest people first, therefore sort descending: @@ -62,6 +64,7 @@ youngest people first, therefore sort descending: ```html ``` +[result](http://samu.github.io/angular-table/walkthrough/3.html) And thats it, our table is sortable by birthdate instantly! We can make the other columns sortable aswell, by using the `at-sortable` attribute only. @@ -82,6 +85,8 @@ done within seconds: We need to define two additional keywords in our table ... ... and we end up with a sortable, paginated table! +[result](http://samu.github.io/angular-table/walkthrough/4.html) + ## Hacking on angular-table ### Coffee Script This directive is written in Coffee Script. If you want to contribute, please make sure to From 2ef31350621f19b559792304fc08f44a7f3ee73f Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 5 Mar 2014 21:59:13 +0100 Subject: [PATCH 126/190] readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 23fcb11..fcef72a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # angular-table [![Build Status](https://travis-ci.org/samu/angular-table.png?branch=master)](https://travis-ci.org/samu/angular-table) -[DEMO](http://samu.github.io/angular-table/examples.html) +[DEMO](http://samu.github.io/angular-table/examples/examples.html) Angular directive which allows to declare sortable tables and to add pagination with very little effort. From 70d9b567c8ee05e3fbcf7c3fe659cb17875dd604 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 5 Mar 2014 22:42:27 +0100 Subject: [PATCH 127/190] readme --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fcef72a..fca940e 100644 --- a/README.md +++ b/README.md @@ -59,15 +59,19 @@ bootstrap in our sources: [result](http://samu.github.io/angular-table/walkthrough/2.html) Now that looks better! Next, lets make the birthdate column sortable. We want to see the -youngest people first, therefore sort descending: +youngest people first, therefore sort descending. We're also going to customize the content +of the birthdate cell since the raw date format looks ugly: ```html - + + {{item.birthdate.substring(0, 10)}} + ``` [result](http://samu.github.io/angular-table/walkthrough/3.html) And thats it, our table is sortable by birthdate instantly! We can make the other columns -sortable aswell, by using the `at-sortable` attribute only. +sortable aswell, by using the `at-sortable` attribute only. Also, note how we removed the +`at-implicit` attribute and rendered our own content by using a custom angular expression. Our list of people is pretty long though, and we hate scrolling, so breaking up the table into smaller chunks and making it possible to go through it with a pagination would be cool. A task From 13b1c4b58c6e18a1e3853c079369ee1f5f4b16db Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 5 Mar 2014 23:07:10 +0100 Subject: [PATCH 128/190] changed css class used for unsorted sortable columns --- angular-table.js | 2 +- angular-table.min.js | 2 +- coffee/directives/table/table.coffee | 2 +- gem/app/assets/javascripts/angular-table.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/angular-table.js b/angular-table.js index b1bc9d0..2df58ce 100644 --- a/angular-table.js +++ b/angular-table.js @@ -432,7 +432,7 @@ if (!$scope.getSortIcon) { $scope.getSortIcon = function(predicate, current_predicate) { if (predicate !== $scope.predicate) { - return "icon-minus"; + return "glyphicon glyphicon-minus"; } if ($scope.descending) { return "glyphicon glyphicon-chevron-down"; diff --git a/angular-table.min.js b/angular-table.min.js index eee15c8..954f38e 100644 --- a/angular-table.min.js +++ b/angular-table.min.js @@ -2,4 +2,4 @@ // version: 0.0.8 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var t,e,n,i,r,a,o,s,u,c,l,g={}.hasOwnProperty,p=function(t,e){function n(){this.constructor=t}for(var i in e)g.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=function(){function t(t){this.config_object_name=t,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return t}(),r=function(){function t(t,e,n){this.scope=t,this.configuration_variable_names=e,this.list_name=n}return t.prototype.get_list=function(){return this.scope.$eval(this.list_name)},t.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},t.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},t.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},t.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},t.prototype.set_current_page=function(t){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+t)},t}(),angular.module("angular-table",[]),c="number_of_pages",l="",t=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th"))},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,n,i,r,a;if(this.custom_content){for(r=this.attributes,a=[],n=0,i=r.length;i>n;n++)e=r[n],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),u=function(){function e(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return e.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},e.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},e.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},e.prototype.collect_header_markup=function(t){var e,n,i,r,a,o;for(e={},i=t.find("tr"),o=i.find("th"),r=0,a=o.length;a>r;r++)n=o[r],n=angular.element(n),e[n.attr("at-attribute")]={custom_content:n.html(),attributes:n[0].attributes};return e},e.prototype.collect_body_markup=function(t){var e,n,i,r,a,o,s,u,c,l;for(n=[],l=t.find("td"),u=0,c=l.length;c>u;u++)a=l[u],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),i=this.getInitialSorting(a),n.push({attribute:e,title:o,sortable:r,width:s,initialSorting:i});return n},e.prototype.create_column_configurations=function(){var e,n,i,r,a;for(n=this.collect_header_markup(this.table_element),e=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=e.length;a>r;r++)i=e[r],this.column_configurations.push(new t(i,n[i.attribute]));return this.column_configurations},e}(),a=function(){function t(){}return t.prototype.setupTr=function(t,e){var n,i;return n=t.find("tbody"),i=n.find("tr"),i.attr("ng-repeat",e),n},t}(),o=function(t){function e(t,e){this.list=e,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return p(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(a),i=function(t){function e(t){this.configuration_variable_names=t,this.repeatString="item in sorted_and_paginated_list"}return p(e,t),e.prototype.compile=function(t){var e,n,i,r,a,o,s;for(n=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)i=a[o],r+=" ";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.configuration_variable_names.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),n.append(e)},e.prototype.link=function(t,e,n,i){var a,o,s,u,l;return a=this.configuration_variable_names,l=new r(t,a,n.atList),s=function(t,e,n,i,r,a,o){var s,u;return t?(u=t,s=n*e-t.length,"global"===i?(u=o("orderBy")(u,r,a),u=o("limitTo")(u,s),u=o("limitTo")(u,n)):(u=o("limitTo")(u,s),u=o("limitTo")(u,n),u=o("orderBy")(u,r,a)),u):[]},o=function(t,e,n,i){var r,a,o,s,u,c,l,g,p,_;if(i=parseInt(i),t.length<=0){for(p=[],o=s=0,c=i-1;c>=0?c>=s:s>=c;o=c>=0?++s:--s)p.push(o);return p}if(e===n-1){if(a=t.length%i,0!==a){for(r=i-a-1,_=[],o=u=l=t.length,g=t.length+r;g>=l?g>=u:u>=g;o=g>=l?++u:--u)_.push(o);return _}return[]}},u=function(){var e;return t.sorted_and_paginated_list=s(l.get_list(),l.get_current_page(),l.get_items_per_page(),l.get_sort_context(),t.predicate,t.descending,i),e=Math.ceil(l.get_list().length/l.get_items_per_page()),t.filler_array=o(l.get_list(),l.get_current_page(),e,l.get_items_per_page())},t.$watch(a.current_page,function(){return u()}),t.$watch(a.items_per_page,function(){return u()}),t.$watch(a.sort_context,function(){return u()}),t.$watch(""+n.atList+".length",function(){return t[c]=Math.ceil(l.get_list().length/l.get_items_per_page()),u()}),t.$watch("predicate",function(){return u()}),t.$watch("descending",function(){return u()})},e}(a),s=function(){function t(t,e,n){this.element=t,this.table_configuration=e,this.configuration_variable_names=n}return t.prototype.constructHeader=function(){var t,e,n,i,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,n=0,i=r.length;i>n;n++)t=r[n],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,n;return e=this.element.find("thead"),e?(t=this.constructHeader(),n=angular.element(e).find("tr"),n.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.configuration_variable_names):new o(this.configuration_variable_names,this.table_configuration.list)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,n,i,r,a;for(r=this.table_configuration.column_configurations,a=[],n=0,i=r.length;i>n;n++)if(e=r[n],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,n,i){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"icon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,n,i)},t}(),n=function(){function t(t,e,n,i){if(this.lower_bound=null!=t?t:0,this.upper_bound=null!=e?e:1,null==n&&(n=0),this.length=null!=i?i:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(n)}return t.prototype.generate=function(t){var e,n,i,r;for(t>this.upper_bound-this.length?t=this.upper_bound-this.length:t=t?i>=n:n>=i;e=i>=t?++n:--n)r.push(e);return r},t.prototype.reset_parameters=function(t,e,n){if(this.lower_bound=t,this.upper_bound=e,this.length=n,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},t.prototype.relocate=function(t){var e;return e=this.data[0]+t,this.data=this.generate(e,e+this.length)},t.prototype.realign_greedy=function(t){var e;return tthis.data[this.length-1]?(e=t-(this.length-1),this.data=this.generate(e)):void 0},t.prototype.realign_generous=function(){},t}(),angular.module("angular-table").directive("atTable",["$filter",function(t){return{restrict:"AC",scope:!0,compile:function(n,i){var r,a,o;return o=new u(n,i),r=new e(i.atConfig),a=new s(n,o,r),a.compile(),{post:function(e,n,i){return a.post(e,n,i,t)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:l,link:function(t,i,a){var o,s,u,l,g,p;return o=new e(a.atConfig),p=new r(t,o,a.atList),u=function(t,e,n){return t=Math.max(e,t),Math.min(n,t)},s=function(){return t[c]},l=function(e){return t[c]=e},g=function(){var e,n;return p.get_list()?p.get_list().length>0?(e=Math.ceil(p.get_list().length/p.get_items_per_page()),l(e),n=t.show_sectioning()?p.get_max_pages():e,t.page_sequence.reset_parameters(0,e,n),p.set_current_page(u(p.get_current_page(),0,s()-1)),t.page_sequence.realign_greedy(p.get_current_page())):(l(1),t.page_sequence.reset_parameters(0,1,1),p.set_current_page(0),t.page_sequence.realign_greedy(0)):void 0},t.show_sectioning=function(){return p.get_max_pages()&&s()>p.get_max_pages()},t.get_current_page=function(){return p.get_current_page()},t.step_page=function(e){return e=parseInt(e),p.set_current_page(u(p.get_current_page()+e,0,s()-1)),t.page_sequence.realign_greedy(p.get_current_page())},t.go_to_page=function(t){return p.set_current_page(t)},t.jump_back=function(){return t.step_page(-p.get_max_pages())},t.jump_ahead=function(){return t.step_page(p.get_max_pages())},t.page_sequence=new n,t.$watch(o.items_per_page,function(){return g()}),t.$watch(o.max_pages,function(){return g()}),t.$watch(a.atList,function(){return g()}),t.$watch(""+a.atList+".length",function(){return g()}),g()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var t,e,n,i,r,a,o,s,u,c,l,g={}.hasOwnProperty,p=function(t,e){function n(){this.constructor=t}for(var i in e)g.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=function(){function t(t){this.config_object_name=t,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return t}(),r=function(){function t(t,e,n){this.scope=t,this.configuration_variable_names=e,this.list_name=n}return t.prototype.get_list=function(){return this.scope.$eval(this.list_name)},t.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},t.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},t.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},t.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},t.prototype.set_current_page=function(t){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+t)},t}(),angular.module("angular-table",[]),c="number_of_pages",l="",t=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th"))},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,n,i,r,a;if(this.custom_content){for(r=this.attributes,a=[],n=0,i=r.length;i>n;n++)e=r[n],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),u=function(){function e(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return e.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},e.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},e.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},e.prototype.collect_header_markup=function(t){var e,n,i,r,a,o;for(e={},i=t.find("tr"),o=i.find("th"),r=0,a=o.length;a>r;r++)n=o[r],n=angular.element(n),e[n.attr("at-attribute")]={custom_content:n.html(),attributes:n[0].attributes};return e},e.prototype.collect_body_markup=function(t){var e,n,i,r,a,o,s,u,c,l;for(n=[],l=t.find("td"),u=0,c=l.length;c>u;u++)a=l[u],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),i=this.getInitialSorting(a),n.push({attribute:e,title:o,sortable:r,width:s,initialSorting:i});return n},e.prototype.create_column_configurations=function(){var e,n,i,r,a;for(n=this.collect_header_markup(this.table_element),e=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=e.length;a>r;r++)i=e[r],this.column_configurations.push(new t(i,n[i.attribute]));return this.column_configurations},e}(),a=function(){function t(){}return t.prototype.setupTr=function(t,e){var n,i;return n=t.find("tbody"),i=n.find("tr"),i.attr("ng-repeat",e),n},t}(),o=function(t){function e(t,e){this.list=e,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return p(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(a),i=function(t){function e(t){this.configuration_variable_names=t,this.repeatString="item in sorted_and_paginated_list"}return p(e,t),e.prototype.compile=function(t){var e,n,i,r,a,o,s;for(n=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)i=a[o],r+=" ";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.configuration_variable_names.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),n.append(e)},e.prototype.link=function(t,e,n,i){var a,o,s,u,l;return a=this.configuration_variable_names,l=new r(t,a,n.atList),s=function(t,e,n,i,r,a,o){var s,u;return t?(u=t,s=n*e-t.length,"global"===i?(u=o("orderBy")(u,r,a),u=o("limitTo")(u,s),u=o("limitTo")(u,n)):(u=o("limitTo")(u,s),u=o("limitTo")(u,n),u=o("orderBy")(u,r,a)),u):[]},o=function(t,e,n,i){var r,a,o,s,u,c,l,g,p,_;if(i=parseInt(i),t.length<=0){for(p=[],o=s=0,c=i-1;c>=0?c>=s:s>=c;o=c>=0?++s:--s)p.push(o);return p}if(e===n-1){if(a=t.length%i,0!==a){for(r=i-a-1,_=[],o=u=l=t.length,g=t.length+r;g>=l?g>=u:u>=g;o=g>=l?++u:--u)_.push(o);return _}return[]}},u=function(){var e;return t.sorted_and_paginated_list=s(l.get_list(),l.get_current_page(),l.get_items_per_page(),l.get_sort_context(),t.predicate,t.descending,i),e=Math.ceil(l.get_list().length/l.get_items_per_page()),t.filler_array=o(l.get_list(),l.get_current_page(),e,l.get_items_per_page())},t.$watch(a.current_page,function(){return u()}),t.$watch(a.items_per_page,function(){return u()}),t.$watch(a.sort_context,function(){return u()}),t.$watch(""+n.atList+".length",function(){return t[c]=Math.ceil(l.get_list().length/l.get_items_per_page()),u()}),t.$watch("predicate",function(){return u()}),t.$watch("descending",function(){return u()})},e}(a),s=function(){function t(t,e,n){this.element=t,this.table_configuration=e,this.configuration_variable_names=n}return t.prototype.constructHeader=function(){var t,e,n,i,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,n=0,i=r.length;i>n;n++)t=r[n],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,n;return e=this.element.find("thead"),e?(t=this.constructHeader(),n=angular.element(e).find("tr"),n.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.configuration_variable_names):new o(this.configuration_variable_names,this.table_configuration.list)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,n,i,r,a;for(r=this.table_configuration.column_configurations,a=[],n=0,i=r.length;i>n;n++)if(e=r[n],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,n,i){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"glyphicon glyphicon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,n,i)},t}(),n=function(){function t(t,e,n,i){if(this.lower_bound=null!=t?t:0,this.upper_bound=null!=e?e:1,null==n&&(n=0),this.length=null!=i?i:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(n)}return t.prototype.generate=function(t){var e,n,i,r;for(t>this.upper_bound-this.length?t=this.upper_bound-this.length:t=t?i>=n:n>=i;e=i>=t?++n:--n)r.push(e);return r},t.prototype.reset_parameters=function(t,e,n){if(this.lower_bound=t,this.upper_bound=e,this.length=n,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},t.prototype.relocate=function(t){var e;return e=this.data[0]+t,this.data=this.generate(e,e+this.length)},t.prototype.realign_greedy=function(t){var e;return tthis.data[this.length-1]?(e=t-(this.length-1),this.data=this.generate(e)):void 0},t.prototype.realign_generous=function(){},t}(),angular.module("angular-table").directive("atTable",["$filter",function(t){return{restrict:"AC",scope:!0,compile:function(n,i){var r,a,o;return o=new u(n,i),r=new e(i.atConfig),a=new s(n,o,r),a.compile(),{post:function(e,n,i){return a.post(e,n,i,t)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:l,link:function(t,i,a){var o,s,u,l,g,p;return o=new e(a.atConfig),p=new r(t,o,a.atList),u=function(t,e,n){return t=Math.max(e,t),Math.min(n,t)},s=function(){return t[c]},l=function(e){return t[c]=e},g=function(){var e,n;return p.get_list()?p.get_list().length>0?(e=Math.ceil(p.get_list().length/p.get_items_per_page()),l(e),n=t.show_sectioning()?p.get_max_pages():e,t.page_sequence.reset_parameters(0,e,n),p.set_current_page(u(p.get_current_page(),0,s()-1)),t.page_sequence.realign_greedy(p.get_current_page())):(l(1),t.page_sequence.reset_parameters(0,1,1),p.set_current_page(0),t.page_sequence.realign_greedy(0)):void 0},t.show_sectioning=function(){return p.get_max_pages()&&s()>p.get_max_pages()},t.get_current_page=function(){return p.get_current_page()},t.step_page=function(e){return e=parseInt(e),p.set_current_page(u(p.get_current_page()+e,0,s()-1)),t.page_sequence.realign_greedy(p.get_current_page())},t.go_to_page=function(t){return p.set_current_page(t)},t.jump_back=function(){return t.step_page(-p.get_max_pages())},t.jump_ahead=function(){return t.step_page(p.get_max_pages())},t.page_sequence=new n,t.$watch(o.items_per_page,function(){return g()}),t.$watch(o.max_pages,function(){return g()}),t.$watch(a.atList,function(){return g()}),t.$watch(""+a.atList+".length",function(){return g()}),g()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file diff --git a/coffee/directives/table/table.coffee b/coffee/directives/table/table.coffee index 3437763..a717cc8 100644 --- a/coffee/directives/table/table.coffee +++ b/coffee/directives/table/table.coffee @@ -39,7 +39,7 @@ class Table if not $scope.getSortIcon $scope.getSortIcon = (predicate, current_predicate) -> - return "icon-minus" if predicate != $scope.predicate + return "glyphicon glyphicon-minus" if predicate != $scope.predicate if $scope.descending then "glyphicon glyphicon-chevron-down" else "glyphicon glyphicon-chevron-up" @setup.link($scope, $element, $attributes, $filter) diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js index b1bc9d0..2df58ce 100644 --- a/gem/app/assets/javascripts/angular-table.js +++ b/gem/app/assets/javascripts/angular-table.js @@ -432,7 +432,7 @@ if (!$scope.getSortIcon) { $scope.getSortIcon = function(predicate, current_predicate) { if (predicate !== $scope.predicate) { - return "icon-minus"; + return "glyphicon glyphicon-minus"; } if ($scope.descending) { return "glyphicon glyphicon-chevron-down"; From 6252773b1ab3dd631947cd3887999dcad8d5b553 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 8 Mar 2014 22:35:44 +0100 Subject: [PATCH 129/190] migrated from rake to grunt --- .gitignore | 3 +- Gruntfile.coffee | 55 +++++++++++++++++++ Rakefile | 64 ----------------------- angular-table.min.js | 5 -- angular-table.js => dist/angular-table.js | 54 +++++++++++++++++-- dist/angular-table.min.js | 5 ++ package.json | 7 ++- 7 files changed, 118 insertions(+), 75 deletions(-) create mode 100644 Gruntfile.coffee delete mode 100644 Rakefile delete mode 100644 angular-table.min.js rename angular-table.js => dist/angular-table.js (96%) create mode 100644 dist/angular-table.min.js diff --git a/.gitignore b/.gitignore index 1571595..9d0dec4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *sublime* _site *.gem -*.log \ No newline at end of file +*.log +node_modules \ No newline at end of file diff --git a/Gruntfile.coffee b/Gruntfile.coffee new file mode 100644 index 0000000..799034d --- /dev/null +++ b/Gruntfile.coffee @@ -0,0 +1,55 @@ +version = "0.1.0" + +banner = " +// author: Samuel Mueller \n +// version: #{version} \n +// license: MIT \n +// homepage: http://github.com/samu/angular-table \n +" + +module.exports = (grunt) -> + grunt.initConfig + pkg: grunt.file.readJSON('package.json') + + version: version + + coffee: + compile: + files: {"dist/angular-table.js" : [ + 'coffee/angular_table.coffee', + + 'coffee/configuration/column_configuration.coffee', + 'coffee/configuration/table_configuration.coffee', + + 'coffee/directives/table/setup/setup.coffee', + 'coffee/directives/table/setup/standard_setup.coffee', + 'coffee/directives/table/setup/paginated_setup.coffee', + 'coffee/directives/table/table.coffee', + + 'coffee/directives/pagination/page_sequence.coffee', + + 'coffee/directives/at_table.coffee', + 'coffee/directives/at_pagination.coffee', + 'coffee/directives/at_implicit.coffee' + ]} + + usebanner: + options: + position: 'top' + banner: banner + linebreak: false + files: + src: ['dist/angular-table.js', 'dist/angular-table.min.js'] + + uglify: + js: + src: 'dist/angular-table.js' + dest: 'dist/angular-table.min.js' + options: + banner: banner + + grunt.loadNpmTasks('grunt-contrib-uglify') + grunt.loadNpmTasks('grunt-contrib-coffee') + grunt.loadNpmTasks('grunt-banner') + + grunt.registerTask('default', ['coffee', 'usebanner', 'uglify']) \ No newline at end of file diff --git a/Rakefile b/Rakefile deleted file mode 100644 index 719c4a3..0000000 --- a/Rakefile +++ /dev/null @@ -1,64 +0,0 @@ -task :default => [:compile] - -task :compile do - - require File.expand_path("gem/lib/angular-table/version") - - require "coffee-script" - require "uglifier" - - script = CoffeeScript.compile collect_coffees() - - prepend_author_notice(script) - - File.open("angular-table.js", "w") { |file| file.write(script) } - File.open("gem/app/assets/javascripts/angular-table.js", "w") { |file| file.write(script) } - File.open("angular-table.min.js", "w") { |file| file.write(prepend_author_notice(Uglifier.new.compile(script))) } - -end - -def collect_coffees - files = [ - "coffee/angular_table.coffee", - - "coffee/configuration/column_configuration.coffee", - "coffee/configuration/table_configuration.coffee", - - "coffee/directives/table/setup/setup.coffee", - "coffee/directives/table/setup/standard_setup.coffee", - "coffee/directives/table/setup/paginated_setup.coffee", - "coffee/directives/table/table.coffee", - - "coffee/directives/pagination/page_sequence.coffee", - - "coffee/directives/at_table.coffee", - "coffee/directives/at_pagination.coffee", - "coffee/directives/at_implicit.coffee", - ] - script = "" - files.each do |file| - script << File.read("#{file}") << "\n" - end - script -end - -def prepend_author_notice script - comments = "" - comments << "// author: Samuel Mueller \n" - comments << "// version: #{AngularTable::VERSION} \n" - comments << "// license: MIT \n" - comments << "// homepage: http://github.com/samu/angular-table \n" - - script.prepend comments - script -end - -task :dev do - require "listen" - puts "listening!" - - Listen.to!("coffee", :force_polling => true) do |modified, added, removed| - puts "recompiling source!" - `rake compile` - end -end \ No newline at end of file diff --git a/angular-table.min.js b/angular-table.min.js deleted file mode 100644 index 954f38e..0000000 --- a/angular-table.min.js +++ /dev/null @@ -1,5 +0,0 @@ -// author: Samuel Mueller -// version: 0.0.8 -// license: MIT -// homepage: http://github.com/samu/angular-table -(function(){var t,e,n,i,r,a,o,s,u,c,l,g={}.hasOwnProperty,p=function(t,e){function n(){this.constructor=t}for(var i in e)g.call(e,i)&&(t[i]=e[i]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};e=function(){function t(t){this.config_object_name=t,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return t}(),r=function(){function t(t,e,n){this.scope=t,this.configuration_variable_names=e,this.list_name=n}return t.prototype.get_list=function(){return this.scope.$eval(this.list_name)},t.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},t.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},t.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},t.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},t.prototype.set_current_page=function(t){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+t)},t}(),angular.module("angular-table",[]),c="number_of_pages",l="",t=function(){function t(t,e){this.attribute=t.attribute,this.title=t.title,this.sortable=t.sortable,this.width=t.width,this.initialSorting=t.initialSorting,e&&(this.custom_content=e.custom_content,this.attributes=e.attributes)}return t.prototype.create_element=function(){var t;return t=angular.element(document.createElement("th"))},t.prototype.render_title=function(t){return t.html(this.custom_content||this.title)},t.prototype.render_attributes=function(t){var e,n,i,r,a;if(this.custom_content){for(r=this.attributes,a=[],n=0,i=r.length;i>n;n++)e=r[n],a.push(t.attr(e.name,e.value));return a}},t.prototype.render_sorting=function(t){var e;return this.sortable?(t.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),e=angular.element(""),e.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),t.append(e)):void 0},t.prototype.render_width=function(t){return t.attr("width",this.width)},t.prototype.render_html=function(){var t;return t=this.create_element(),this.render_title(t),this.render_attributes(t),this.render_sorting(t),this.render_width(t),t},t}(),u=function(){function e(t,e){this.table_element=t,this.attributes=e,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return e.prototype.capitaliseFirstLetter=function(t){return t?t.charAt(0).toUpperCase()+t.slice(1):""},e.prototype.extractWidth=function(t){var e;return e=/([0-9]+px)/i.exec(t),e?e[0]:""},e.prototype.isSortable=function(t){var e;return e=/(sortable)/i.exec(t),e?!0:!1},e.prototype.getInitialSorting=function(t){var e;if(e=t.attr("at-initial-sorting")){if("asc"===e||"desc"===e)return e;throw"Invalid value for initial-sorting: "+e+". Allowed values are 'asc' or 'desc'."}return void 0},e.prototype.collect_header_markup=function(t){var e,n,i,r,a,o;for(e={},i=t.find("tr"),o=i.find("th"),r=0,a=o.length;a>r;r++)n=o[r],n=angular.element(n),e[n.attr("at-attribute")]={custom_content:n.html(),attributes:n[0].attributes};return e},e.prototype.collect_body_markup=function(t){var e,n,i,r,a,o,s,u,c,l;for(n=[],l=t.find("td"),u=0,c=l.length;c>u;u++)a=l[u],a=angular.element(a),e=a.attr("at-attribute"),o=a.attr("at-title")||this.capitaliseFirstLetter(a.attr("at-attribute")),r=void 0!==a.attr("at-sortable")||this.isSortable(a.attr("class")),s=this.extractWidth(a.attr("class")),i=this.getInitialSorting(a),n.push({attribute:e,title:o,sortable:r,width:s,initialSorting:i});return n},e.prototype.create_column_configurations=function(){var e,n,i,r,a;for(n=this.collect_header_markup(this.table_element),e=this.collect_body_markup(this.table_element),this.column_configurations=[],r=0,a=e.length;a>r;r++)i=e[r],this.column_configurations.push(new t(i,n[i.attribute]));return this.column_configurations},e}(),a=function(){function t(){}return t.prototype.setupTr=function(t,e){var n,i;return n=t.find("tbody"),i=n.find("tr"),i.attr("ng-repeat",e),n},t}(),o=function(t){function e(t,e){this.list=e,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return p(e,t),e.prototype.compile=function(t){return this.setupTr(t,this.repeatString)},e.prototype.link=function(){},e}(a),i=function(t){function e(t){this.configuration_variable_names=t,this.repeatString="item in sorted_and_paginated_list"}return p(e,t),e.prototype.compile=function(t){var e,n,i,r,a,o,s;for(n=this.setupTr(t,this.repeatString),a=t.find("td"),r="",o=0,s=a.length;s>o;o++)i=a[o],r+=" ";e=angular.element(document.createElement("tr")),e.attr("ng-show",this.configuration_variable_names.fill_last_page),e.html(r),e.attr("ng-repeat","item in filler_array"),n.append(e)},e.prototype.link=function(t,e,n,i){var a,o,s,u,l;return a=this.configuration_variable_names,l=new r(t,a,n.atList),s=function(t,e,n,i,r,a,o){var s,u;return t?(u=t,s=n*e-t.length,"global"===i?(u=o("orderBy")(u,r,a),u=o("limitTo")(u,s),u=o("limitTo")(u,n)):(u=o("limitTo")(u,s),u=o("limitTo")(u,n),u=o("orderBy")(u,r,a)),u):[]},o=function(t,e,n,i){var r,a,o,s,u,c,l,g,p,_;if(i=parseInt(i),t.length<=0){for(p=[],o=s=0,c=i-1;c>=0?c>=s:s>=c;o=c>=0?++s:--s)p.push(o);return p}if(e===n-1){if(a=t.length%i,0!==a){for(r=i-a-1,_=[],o=u=l=t.length,g=t.length+r;g>=l?g>=u:u>=g;o=g>=l?++u:--u)_.push(o);return _}return[]}},u=function(){var e;return t.sorted_and_paginated_list=s(l.get_list(),l.get_current_page(),l.get_items_per_page(),l.get_sort_context(),t.predicate,t.descending,i),e=Math.ceil(l.get_list().length/l.get_items_per_page()),t.filler_array=o(l.get_list(),l.get_current_page(),e,l.get_items_per_page())},t.$watch(a.current_page,function(){return u()}),t.$watch(a.items_per_page,function(){return u()}),t.$watch(a.sort_context,function(){return u()}),t.$watch(""+n.atList+".length",function(){return t[c]=Math.ceil(l.get_list().length/l.get_items_per_page()),u()}),t.$watch("predicate",function(){return u()}),t.$watch("descending",function(){return u()})},e}(a),s=function(){function t(t,e,n){this.element=t,this.table_configuration=e,this.configuration_variable_names=n}return t.prototype.constructHeader=function(){var t,e,n,i,r;for(e=angular.element(document.createElement("tr")),r=this.table_configuration.column_configurations,n=0,i=r.length;i>n;n++)t=r[n],e.append(t.render_html());return e},t.prototype.setup_header=function(){var t,e,n;return e=this.element.find("thead"),e?(t=this.constructHeader(),n=angular.element(e).find("tr"),n.remove(),e.append(t)):void 0},t.prototype.get_setup=function(){return this.table_configuration.paginated?new i(this.configuration_variable_names):new o(this.configuration_variable_names,this.table_configuration.list)},t.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},t.prototype.setup_initial_sorting=function(t){var e,n,i,r,a;for(r=this.table_configuration.column_configurations,a=[],n=0,i=r.length;i>n;n++)if(e=r[n],e.initialSorting){if(!e.attribute)throw"initial-sorting specified without attribute.";t.predicate=e.attribute,a.push(t.descending="desc"===e.initialSorting)}else a.push(void 0);return a},t.prototype.post=function(t,e,n,i){return this.setup_initial_sorting(t),t.getSortIcon||(t.getSortIcon=function(e){return e!==t.predicate?"glyphicon glyphicon-minus":t.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(t,e,n,i)},t}(),n=function(){function t(t,e,n,i){if(this.lower_bound=null!=t?t:0,this.upper_bound=null!=e?e:1,null==n&&(n=0),this.length=null!=i?i:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(n)}return t.prototype.generate=function(t){var e,n,i,r;for(t>this.upper_bound-this.length?t=this.upper_bound-this.length:t=t?i>=n:n>=i;e=i>=t?++n:--n)r.push(e);return r},t.prototype.reset_parameters=function(t,e,n){if(this.lower_bound=t,this.upper_bound=e,this.length=n,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},t.prototype.relocate=function(t){var e;return e=this.data[0]+t,this.data=this.generate(e,e+this.length)},t.prototype.realign_greedy=function(t){var e;return tthis.data[this.length-1]?(e=t-(this.length-1),this.data=this.generate(e)):void 0},t.prototype.realign_generous=function(){},t}(),angular.module("angular-table").directive("atTable",["$filter",function(t){return{restrict:"AC",scope:!0,compile:function(n,i){var r,a,o;return o=new u(n,i),r=new e(i.atConfig),a=new s(n,o,r),a.compile(),{post:function(e,n,i){return a.post(e,n,i,t)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:l,link:function(t,i,a){var o,s,u,l,g,p;return o=new e(a.atConfig),p=new r(t,o,a.atList),u=function(t,e,n){return t=Math.max(e,t),Math.min(n,t)},s=function(){return t[c]},l=function(e){return t[c]=e},g=function(){var e,n;return p.get_list()?p.get_list().length>0?(e=Math.ceil(p.get_list().length/p.get_items_per_page()),l(e),n=t.show_sectioning()?p.get_max_pages():e,t.page_sequence.reset_parameters(0,e,n),p.set_current_page(u(p.get_current_page(),0,s()-1)),t.page_sequence.realign_greedy(p.get_current_page())):(l(1),t.page_sequence.reset_parameters(0,1,1),p.set_current_page(0),t.page_sequence.realign_greedy(0)):void 0},t.show_sectioning=function(){return p.get_max_pages()&&s()>p.get_max_pages()},t.get_current_page=function(){return p.get_current_page()},t.step_page=function(e){return e=parseInt(e),p.set_current_page(u(p.get_current_page()+e,0,s()-1)),t.page_sequence.realign_greedy(p.get_current_page())},t.go_to_page=function(t){return p.set_current_page(t)},t.jump_back=function(){return t.step_page(-p.get_max_pages())},t.jump_ahead=function(){return t.step_page(p.get_max_pages())},t.page_sequence=new n,t.$watch(o.items_per_page,function(){return g()}),t.$watch(o.max_pages,function(){return g()}),t.$watch(a.atList,function(){return g()}),t.$watch(""+a.atList+".length",function(){return g()}),g()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(t){var e;if(e=t.attr("at-attribute"),!e)throw"at-implicit specified without at-attribute: "+t.html();return t.append("{{item."+e+"}}")}}}])}).call(this); \ No newline at end of file diff --git a/angular-table.js b/dist/angular-table.js similarity index 96% rename from angular-table.js rename to dist/angular-table.js index 2df58ce..b545774 100644 --- a/angular-table.js +++ b/dist/angular-table.js @@ -1,11 +1,9 @@ // author: Samuel Mueller -// version: 0.0.8 +// version: 0.1.0 // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var ColumnConfiguration, ConfigurationVariableNames, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, irk_number_of_pages, pagination_template, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + var ConfigurationVariableNames, ScopeConfigWrapper, irk_number_of_pages, pagination_template; ConfigurationVariableNames = (function() { function ConfigurationVariableNames(config_object_name) { @@ -62,6 +60,11 @@ pagination_template = ""; +}).call(this); + +(function() { + var ColumnConfiguration; + ColumnConfiguration = (function() { function ColumnConfiguration(body_markup, header_markup) { this.attribute = body_markup.attribute; @@ -125,6 +128,11 @@ })(); +}).call(this); + +(function() { + var TableConfiguration; + TableConfiguration = (function() { function TableConfiguration(table_element, attributes) { this.table_element = table_element; @@ -231,6 +239,11 @@ })(); +}).call(this); + +(function() { + var Setup; + Setup = (function() { function Setup() {} @@ -246,6 +259,13 @@ })(); +}).call(this); + +(function() { + var StandardSetup, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + StandardSetup = (function(_super) { __extends(StandardSetup, _super); @@ -264,6 +284,13 @@ })(Setup); +}).call(this); + +(function() { + var PaginatedSetup, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + PaginatedSetup = (function(_super) { __extends(PaginatedSetup, _super); @@ -365,6 +392,11 @@ })(Setup); +}).call(this); + +(function() { + var Table; + Table = (function() { function Table(element, table_configuration, configuration_variable_names) { this.element = element; @@ -448,6 +480,11 @@ })(); +}).call(this); + +(function() { + var PageSequence; + PageSequence = (function() { function PageSequence(lower_bound, upper_bound, start, length) { this.lower_bound = lower_bound != null ? lower_bound : 0; @@ -509,6 +546,9 @@ })(); +}).call(this); + +(function() { angular.module("angular-table").directive("atTable", [ "$filter", function($filter) { return { @@ -530,6 +570,9 @@ } ]); +}).call(this); + +(function() { angular.module("angular-table").directive("atPagination", [ function() { return { @@ -612,6 +655,9 @@ } ]); +}).call(this); + +(function() { angular.module("angular-table").directive("atImplicit", [ function() { return { diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js new file mode 100644 index 0000000..d092d88 --- /dev/null +++ b/dist/angular-table.min.js @@ -0,0 +1,5 @@ +// author: Samuel Mueller +// version: 0.1.0 +// license: MIT +// homepage: http://github.com/samu/angular-table +(function(){var a,b,c,d;a=function(){function a(a){this.config_object_name=a,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return a}(),b=function(){function a(a,b,c){this.scope=a,this.configuration_variable_names=b,this.list_name=c}return a.prototype.get_list=function(){return this.scope.$eval(this.list_name)},a.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},a.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},a.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},a.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},a.prototype.set_current_page=function(a){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+a)},a}(),angular.module("angular-table",[]),c="number_of_pages",d=""}).call(this),function(){var a;a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.custom_content=b.custom_content,this.attributes=b.attributes)}return a.prototype.create_element=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.render_title=function(a){return a.html(this.custom_content||this.title)},a.prototype.render_attributes=function(a){var b,c,d,e,f;if(this.custom_content){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.render_sorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.render_width=function(a){return a.attr("width",this.width)},a.prototype.render_html=function(){var a;return a=this.create_element(),this.render_title(a),this.render_attributes(a),this.render_sorting(a),this.render_width(a),a},a}()}.call(this),function(){var a;a=function(){function a(a,b){this.table_element=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return a.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},a.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},a.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},a.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},a.prototype.collect_header_markup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={custom_content:c.html(),attributes:c[0].attributes};return b},a.prototype.collect_body_markup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},a.prototype.create_column_configurations=function(){var a,b,c,d,e;for(b=this.collect_header_markup(this.table_element),a=this.collect_body_markup(this.table_element),this.column_configurations=[],d=0,e=a.length;e>d;d++)c=a[d],this.column_configurations.push(new ColumnConfiguration(c,b[c.attribute]));return this.column_configurations},a}()}.call(this),function(){var a;a=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}()}.call(this),function(){var a,b={}.hasOwnProperty,c=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a};a=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return c(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(Setup)}.call(this),function(){var a,b={}.hasOwnProperty,c=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a};a=function(a){function b(a){this.configuration_variable_names=a,this.repeatString="item in sorted_and_paginated_list"}return c(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configuration_variable_names.fill_last_page),b.html(e),b.attr("ng-repeat","item in filler_array"),c.append(b)},b.prototype.link=function(a,b,c,d){var e,f,g,h,i;return e=this.configuration_variable_names,i=new ScopeConfigWrapper(a,e,c.atList),g=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},f=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},h=function(){var b;return a.sorted_and_paginated_list=g(i.get_list(),i.get_current_page(),i.get_items_per_page(),i.get_sort_context(),a.predicate,a.descending,d),b=Math.ceil(i.get_list().length/i.get_items_per_page()),a.filler_array=f(i.get_list(),i.get_current_page(),b,i.get_items_per_page())},a.$watch(e.current_page,function(){return h()}),a.$watch(e.items_per_page,function(){return h()}),a.$watch(e.sort_context,function(){return h()}),a.$watch(""+c.atList+".length",function(){return a[irk_number_of_pages]=Math.ceil(i.get_list().length/i.get_items_per_page()),h()}),a.$watch("predicate",function(){return h()}),a.$watch("descending",function(){return h()})},b}(Setup)}.call(this),function(){var a;a=function(){function a(a,b,c){this.element=a,this.table_configuration=b,this.configuration_variable_names=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.table_configuration.column_configurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.render_html());return b},a.prototype.setup_header=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.get_setup=function(){return this.table_configuration.paginated?new PaginatedSetup(this.configuration_variable_names):new StandardSetup(this.configuration_variable_names,this.table_configuration.list)},a.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},a.prototype.setup_initial_sorting=function(a){var b,c,d,e,f;for(e=this.table_configuration.column_configurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setup_initial_sorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}()}.call(this),function(){var a;a=function(){function a(a,b,c,d){if(this.lower_bound=null!=a?a:0,this.upper_bound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upper_bound-this.length?a=this.upper_bound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.reset_parameters=function(a,b,c){if(this.lower_bound=a,this.upper_bound=b,this.length=c,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realign_greedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realign_generous=function(){},a}()}.call(this),function(){angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c){var d,e,f;return f=new TableConfiguration(b,c),d=new ConfigurationVariableNames(c.atConfig),e=new Table(b,f,d),e.compile(),{post:function(b,c,d){return e.post(b,c,d,a)}}}}}])}.call(this),function(){angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:pagination_template,link:function(a,b,c){var d,e,f,g,h,i;return d=new ConfigurationVariableNames(c.atConfig),i=new ScopeConfigWrapper(a,d,c.atList),f=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},e=function(){return a[irk_number_of_pages]},g=function(b){return a[irk_number_of_pages]=b},h=function(){var b,c;return i.get_list()?i.get_list().length>0?(b=Math.ceil(i.get_list().length/i.get_items_per_page()),g(b),c=a.show_sectioning()?i.get_max_pages():b,a.page_sequence.reset_parameters(0,b,c),i.set_current_page(f(i.get_current_page(),0,e()-1)),a.page_sequence.realign_greedy(i.get_current_page())):(g(1),a.page_sequence.reset_parameters(0,1,1),i.set_current_page(0),a.page_sequence.realign_greedy(0)):void 0},a.show_sectioning=function(){return i.get_max_pages()&&e()>i.get_max_pages()},a.get_current_page=function(){return i.get_current_page()},a.step_page=function(b){return b=parseInt(b),i.set_current_page(f(i.get_current_page()+b,0,e()-1)),a.page_sequence.realign_greedy(i.get_current_page())},a.go_to_page=function(a){return i.set_current_page(a)},a.jump_back=function(){return a.step_page(-i.get_max_pages())},a.jump_ahead=function(){return a.step_page(i.get_max_pages())},a.page_sequence=new PageSequence,a.$watch(d.items_per_page,function(){return h()}),a.$watch(d.max_pages,function(){return h()}),a.$watch(c.atList,function(){return h()}),a.$watch(""+c.atList+".length",function(){return h()}),h()}}}])}.call(this),function(){angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}.call(this); \ No newline at end of file diff --git a/package.json b/package.json index 8f24c01..1630877 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,12 @@ }, "devDependencies": { "karma": "~0.10", - "karma-ng-html2js-preprocessor" : "0.1.0" + "karma-ng-html2js-preprocessor" : "0.1.0", + "grunt-contrib-uglify": "~v0.3.3", + "grunt-contrib-coffee": "~0.10.1", + "grunt-banner": "~0.2.1", + "grunt-cli": "~0.1.8", + "grunt": "~0.4.1" }, "scripts": { "test": "karma start --single-run --no-auto-watch" From 5f89a1500c151e6f673bcf3bc32da1c9a6ac76f5 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 8 Mar 2014 22:49:21 +0100 Subject: [PATCH 130/190] moved gem to own branch --- .gitignore | 1 - gem/Gemfile | 4 - gem/angular-table.gemspec | 20 - gem/app/assets/javascripts/angular-table.js | 631 -------------------- gem/lib/angular-table.rb | 4 - gem/lib/angular-table/version.rb | 3 - 6 files changed, 663 deletions(-) delete mode 100644 gem/Gemfile delete mode 100644 gem/angular-table.gemspec delete mode 100644 gem/app/assets/javascripts/angular-table.js delete mode 100644 gem/lib/angular-table.rb delete mode 100644 gem/lib/angular-table/version.rb diff --git a/.gitignore b/.gitignore index 9d0dec4..a36b0cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ *sublime* _site -*.gem *.log node_modules \ No newline at end of file diff --git a/gem/Gemfile b/gem/Gemfile deleted file mode 100644 index c985e4a..0000000 --- a/gem/Gemfile +++ /dev/null @@ -1,4 +0,0 @@ -source 'https://rubygems.org' - -# Specify your gem's dependencies in angular-table.gemspec -gemspec diff --git a/gem/angular-table.gemspec b/gem/angular-table.gemspec deleted file mode 100644 index 87e4871..0000000 --- a/gem/angular-table.gemspec +++ /dev/null @@ -1,20 +0,0 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'angular-table/version' - -Gem::Specification.new do |spec| - spec.name = "angular-table" - spec.version = AngularTable::VERSION - spec.authors = ["Samuel Mueller"] - spec.email = ["mueller.samu@gmail.com"] - spec.description = "Html tables with sorting and pagination." - spec.summary = spec.description - spec.homepage = "https://github.com/ssmm/angular-table" - spec.license = "MIT" - spec.files = Dir["lib/**/*"] + Dir["app/**/*"] - spec.require_paths = ["lib"] - - spec.add_development_dependency "bundler", "~> 1.3" - spec.add_development_dependency "rake" -end diff --git a/gem/app/assets/javascripts/angular-table.js b/gem/app/assets/javascripts/angular-table.js deleted file mode 100644 index 2df58ce..0000000 --- a/gem/app/assets/javascripts/angular-table.js +++ /dev/null @@ -1,631 +0,0 @@ -// author: Samuel Mueller -// version: 0.0.8 -// license: MIT -// homepage: http://github.com/samu/angular-table -(function() { - var ColumnConfiguration, ConfigurationVariableNames, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, irk_number_of_pages, pagination_template, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; - - ConfigurationVariableNames = (function() { - function ConfigurationVariableNames(config_object_name) { - this.config_object_name = config_object_name; - this.items_per_page = "" + this.config_object_name + ".itemsPerPage"; - this.sort_context = "" + this.config_object_name + ".sortContext"; - this.fill_last_page = "" + this.config_object_name + ".fillLastPage"; - this.max_pages = "" + this.config_object_name + ".maxPages"; - this.current_page = "" + this.config_object_name + ".currentPage"; - } - - return ConfigurationVariableNames; - - })(); - - ScopeConfigWrapper = (function() { - function ScopeConfigWrapper(scope, configuration_variable_names, list_name) { - this.scope = scope; - this.configuration_variable_names = configuration_variable_names; - this.list_name = list_name; - } - - ScopeConfigWrapper.prototype.get_list = function() { - return this.scope.$eval(this.list_name); - }; - - ScopeConfigWrapper.prototype.get_items_per_page = function() { - return this.scope.$eval(this.configuration_variable_names.items_per_page) || 10; - }; - - ScopeConfigWrapper.prototype.get_current_page = function() { - return this.scope.$eval(this.configuration_variable_names.current_page) || 0; - }; - - ScopeConfigWrapper.prototype.get_max_pages = function() { - return this.scope.$eval(this.configuration_variable_names.max_pages) || void 0; - }; - - ScopeConfigWrapper.prototype.get_sort_context = function() { - return this.scope.$eval(this.configuration_variable_names.sort_context) || 'global'; - }; - - ScopeConfigWrapper.prototype.set_current_page = function(current_page) { - return this.scope.$eval("" + this.configuration_variable_names.current_page + "=" + current_page); - }; - - return ScopeConfigWrapper; - - })(); - - angular.module("angular-table", []); - - irk_number_of_pages = "number_of_pages"; - - pagination_template = ""; - - ColumnConfiguration = (function() { - function ColumnConfiguration(body_markup, header_markup) { - this.attribute = body_markup.attribute; - this.title = body_markup.title; - this.sortable = body_markup.sortable; - this.width = body_markup.width; - this.initialSorting = body_markup.initialSorting; - if (header_markup) { - this.custom_content = header_markup.custom_content; - this.attributes = header_markup.attributes; - } - } - - ColumnConfiguration.prototype.create_element = function() { - var th; - return th = angular.element(document.createElement("th")); - }; - - ColumnConfiguration.prototype.render_title = function(element) { - return element.html(this.custom_content || this.title); - }; - - ColumnConfiguration.prototype.render_attributes = function(element) { - var attribute, _i, _len, _ref, _results; - if (this.custom_content) { - _ref = this.attributes; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - attribute = _ref[_i]; - _results.push(element.attr(attribute.name, attribute.value)); - } - return _results; - } - }; - - ColumnConfiguration.prototype.render_sorting = function(element) { - var icon; - if (this.sortable) { - element.attr("ng-click", "predicate = '" + this.attribute + "'; descending = !descending;"); - icon = angular.element(""); - icon.attr("ng-class", "getSortIcon('" + this.attribute + "', predicate)"); - return element.append(icon); - } - }; - - ColumnConfiguration.prototype.render_width = function(element) { - return element.attr("width", this.width); - }; - - ColumnConfiguration.prototype.render_html = function() { - var th; - th = this.create_element(); - this.render_title(th); - this.render_attributes(th); - this.render_sorting(th); - this.render_width(th); - return th; - }; - - return ColumnConfiguration; - - })(); - - TableConfiguration = (function() { - function TableConfiguration(table_element, attributes) { - this.table_element = table_element; - this.attributes = attributes; - this.id = this.attributes.id; - this.config = this.attributes.atConfig; - this.paginated = this.attributes.atPaginated != null; - this.list = this.attributes.atList; - this.create_column_configurations(); - } - - TableConfiguration.prototype.capitaliseFirstLetter = function(string) { - if (string) { - return string.charAt(0).toUpperCase() + string.slice(1); - } else { - return ""; - } - }; - - TableConfiguration.prototype.extractWidth = function(classes) { - var width; - width = /([0-9]+px)/i.exec(classes); - if (width) { - return width[0]; - } else { - return ""; - } - }; - - TableConfiguration.prototype.isSortable = function(classes) { - var sortable; - sortable = /(sortable)/i.exec(classes); - if (sortable) { - return true; - } else { - return false; - } - }; - - TableConfiguration.prototype.getInitialSorting = function(td) { - var initialSorting; - initialSorting = td.attr("at-initial-sorting"); - if (initialSorting) { - if (initialSorting === "asc" || initialSorting === "desc") { - return initialSorting; - } - throw "Invalid value for initial-sorting: " + initialSorting + ". Allowed values are 'asc' or 'desc'."; - } - return void 0; - }; - - TableConfiguration.prototype.collect_header_markup = function(table) { - var customHeaderMarkups, th, tr, _i, _len, _ref; - customHeaderMarkups = {}; - tr = table.find("tr"); - _ref = tr.find("th"); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - th = _ref[_i]; - th = angular.element(th); - customHeaderMarkups[th.attr("at-attribute")] = { - custom_content: th.html(), - attributes: th[0].attributes - }; - } - return customHeaderMarkups; - }; - - TableConfiguration.prototype.collect_body_markup = function(table) { - var attribute, bodyDefinition, initialSorting, sortable, td, title, width, _i, _len, _ref; - bodyDefinition = []; - _ref = table.find("td"); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - td = _ref[_i]; - td = angular.element(td); - attribute = td.attr("at-attribute"); - title = td.attr("at-title") || this.capitaliseFirstLetter(td.attr("at-attribute")); - sortable = td.attr("at-sortable") !== void 0 || this.isSortable(td.attr("class")); - width = this.extractWidth(td.attr("class")); - initialSorting = this.getInitialSorting(td); - bodyDefinition.push({ - attribute: attribute, - title: title, - sortable: sortable, - width: width, - initialSorting: initialSorting - }); - } - return bodyDefinition; - }; - - TableConfiguration.prototype.create_column_configurations = function() { - var body_markup, header_markup, i, _i, _len; - header_markup = this.collect_header_markup(this.table_element); - body_markup = this.collect_body_markup(this.table_element); - this.column_configurations = []; - for (_i = 0, _len = body_markup.length; _i < _len; _i++) { - i = body_markup[_i]; - this.column_configurations.push(new ColumnConfiguration(i, header_markup[i.attribute])); - } - return this.column_configurations; - }; - - return TableConfiguration; - - })(); - - Setup = (function() { - function Setup() {} - - Setup.prototype.setupTr = function(element, repeatString) { - var tbody, tr; - tbody = element.find("tbody"); - tr = tbody.find("tr"); - tr.attr("ng-repeat", repeatString); - return tbody; - }; - - return Setup; - - })(); - - StandardSetup = (function(_super) { - __extends(StandardSetup, _super); - - function StandardSetup(configuration_variable_names, list) { - this.list = list; - this.repeatString = "item in " + this.list + " | orderBy:predicate:descending"; - } - - StandardSetup.prototype.compile = function(element, attributes, transclude) { - return this.setupTr(element, this.repeatString); - }; - - StandardSetup.prototype.link = function() {}; - - return StandardSetup; - - })(Setup); - - PaginatedSetup = (function(_super) { - __extends(PaginatedSetup, _super); - - function PaginatedSetup(configuration_variable_names) { - this.configuration_variable_names = configuration_variable_names; - this.repeatString = "item in sorted_and_paginated_list"; - } - - PaginatedSetup.prototype.compile = function(element) { - var fillerTr, tbody, td, tdString, tds, _i, _len; - tbody = this.setupTr(element, this.repeatString); - tds = element.find("td"); - tdString = ""; - for (_i = 0, _len = tds.length; _i < _len; _i++) { - td = tds[_i]; - tdString += " "; - } - fillerTr = angular.element(document.createElement("tr")); - fillerTr.attr("ng-show", this.configuration_variable_names.fill_last_page); - fillerTr.html(tdString); - fillerTr.attr("ng-repeat", "item in filler_array"); - tbody.append(fillerTr); - }; - - PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) { - var cvn, get_filler_array, get_sorted_and_paginated_list, update, w; - cvn = this.configuration_variable_names; - w = new ScopeConfigWrapper($scope, cvn, $attributes.atList); - get_sorted_and_paginated_list = function(list, current_page, items_per_page, sort_context, predicate, descending, $filter) { - var from_page, val; - if (list) { - val = list; - from_page = items_per_page * current_page - list.length; - if (sort_context === "global") { - val = $filter("orderBy")(val, predicate, descending); - val = $filter("limitTo")(val, from_page); - val = $filter("limitTo")(val, items_per_page); - } else { - val = $filter("limitTo")(val, from_page); - val = $filter("limitTo")(val, items_per_page); - val = $filter("orderBy")(val, predicate, descending); - } - return val; - } else { - return []; - } - }; - get_filler_array = function(list, current_page, number_of_pages, items_per_page) { - var fillerLength, itemCountOnLastPage, x, _i, _j, _ref, _ref1, _ref2, _results, _results1; - items_per_page = parseInt(items_per_page); - if (list.length <= 0) { - _results = []; - for (x = _i = 0, _ref = items_per_page - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { - _results.push(x); - } - return _results; - } else if (current_page === number_of_pages - 1) { - itemCountOnLastPage = list.length % items_per_page; - if (itemCountOnLastPage !== 0) { - fillerLength = items_per_page - itemCountOnLastPage - 1; - _results1 = []; - for (x = _j = _ref1 = list.length, _ref2 = list.length + fillerLength; _ref1 <= _ref2 ? _j <= _ref2 : _j >= _ref2; x = _ref1 <= _ref2 ? ++_j : --_j) { - _results1.push(x); - } - return _results1; - } else { - return []; - } - } - }; - update = function() { - var nop; - $scope.sorted_and_paginated_list = get_sorted_and_paginated_list(w.get_list(), w.get_current_page(), w.get_items_per_page(), w.get_sort_context(), $scope.predicate, $scope.descending, $filter); - nop = Math.ceil(w.get_list().length / w.get_items_per_page()); - return $scope.filler_array = get_filler_array(w.get_list(), w.get_current_page(), nop, w.get_items_per_page()); - }; - $scope.$watch(cvn.current_page, function() { - return update(); - }); - $scope.$watch(cvn.items_per_page, function() { - return update(); - }); - $scope.$watch(cvn.sort_context, function() { - return update(); - }); - $scope.$watch("" + $attributes.atList + ".length", function() { - $scope[irk_number_of_pages] = Math.ceil(w.get_list().length / w.get_items_per_page()); - return update(); - }); - $scope.$watch("predicate", function() { - return update(); - }); - return $scope.$watch("descending", function() { - return update(); - }); - }; - - return PaginatedSetup; - - })(Setup); - - Table = (function() { - function Table(element, table_configuration, configuration_variable_names) { - this.element = element; - this.table_configuration = table_configuration; - this.configuration_variable_names = configuration_variable_names; - } - - Table.prototype.constructHeader = function() { - var i, tr, _i, _len, _ref; - tr = angular.element(document.createElement("tr")); - _ref = this.table_configuration.column_configurations; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - i = _ref[_i]; - tr.append(i.render_html()); - } - return tr; - }; - - Table.prototype.setup_header = function() { - var header, thead, tr; - thead = this.element.find("thead"); - if (thead) { - header = this.constructHeader(); - tr = angular.element(thead).find("tr"); - tr.remove(); - return thead.append(header); - } - }; - - Table.prototype.get_setup = function() { - if (this.table_configuration.paginated) { - return new PaginatedSetup(this.configuration_variable_names); - } else { - return new StandardSetup(this.configuration_variable_names, this.table_configuration.list); - } - }; - - Table.prototype.compile = function() { - this.setup_header(); - this.setup = this.get_setup(); - return this.setup.compile(this.element); - }; - - Table.prototype.setup_initial_sorting = function($scope) { - var bd, _i, _len, _ref, _results; - _ref = this.table_configuration.column_configurations; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - bd = _ref[_i]; - if (bd.initialSorting) { - if (!bd.attribute) { - throw "initial-sorting specified without attribute."; - } - $scope.predicate = bd.attribute; - _results.push($scope.descending = bd.initialSorting === "desc"); - } else { - _results.push(void 0); - } - } - return _results; - }; - - Table.prototype.post = function($scope, $element, $attributes, $filter) { - this.setup_initial_sorting($scope); - if (!$scope.getSortIcon) { - $scope.getSortIcon = function(predicate, current_predicate) { - if (predicate !== $scope.predicate) { - return "glyphicon glyphicon-minus"; - } - if ($scope.descending) { - return "glyphicon glyphicon-chevron-down"; - } else { - return "glyphicon glyphicon-chevron-up"; - } - }; - } - return this.setup.link($scope, $element, $attributes, $filter); - }; - - return Table; - - })(); - - PageSequence = (function() { - function PageSequence(lower_bound, upper_bound, start, length) { - this.lower_bound = lower_bound != null ? lower_bound : 0; - this.upper_bound = upper_bound != null ? upper_bound : 1; - if (start == null) { - start = 0; - } - this.length = length != null ? length : 1; - if (this.length > (this.upper_bound - this.lower_bound)) { - throw "sequence is too long"; - } - this.data = this.generate(start); - } - - PageSequence.prototype.generate = function(start) { - var x, _i, _ref, _results; - if (start > (this.upper_bound - this.length)) { - start = this.upper_bound - this.length; - } else if (start < this.lower_bound) { - start = this.lower_bound; - } - _results = []; - for (x = _i = start, _ref = parseInt(start) + parseInt(this.length) - 1; start <= _ref ? _i <= _ref : _i >= _ref; x = start <= _ref ? ++_i : --_i) { - _results.push(x); - } - return _results; - }; - - PageSequence.prototype.reset_parameters = function(lower_bound, upper_bound, length) { - this.lower_bound = lower_bound; - this.upper_bound = upper_bound; - this.length = length; - if (this.length > (this.upper_bound - this.lower_bound)) { - throw "sequence is too long"; - } - return this.data = this.generate(this.data[0]); - }; - - PageSequence.prototype.relocate = function(distance) { - var new_start; - new_start = this.data[0] + distance; - return this.data = this.generate(new_start, new_start + this.length); - }; - - PageSequence.prototype.realign_greedy = function(page) { - var new_start; - if (page < this.data[0]) { - new_start = page; - return this.data = this.generate(new_start); - } else if (page > this.data[this.length - 1]) { - new_start = page - (this.length - 1); - return this.data = this.generate(new_start); - } - }; - - PageSequence.prototype.realign_generous = function(page) {}; - - return PageSequence; - - })(); - - angular.module("angular-table").directive("atTable", [ - "$filter", function($filter) { - return { - restrict: "AC", - scope: true, - compile: function(element, attributes, transclude) { - var cvn, table, tc; - tc = new TableConfiguration(element, attributes); - cvn = new ConfigurationVariableNames(attributes.atConfig); - table = new Table(element, tc, cvn); - table.compile(); - return { - post: function($scope, $element, $attributes) { - return table.post($scope, $element, $attributes, $filter); - } - }; - } - }; - } - ]); - - angular.module("angular-table").directive("atPagination", [ - function() { - return { - restrict: "E", - scope: true, - replace: true, - template: pagination_template, - link: function($scope, $element, $attributes) { - var cvn, get_number_of_pages, keep_in_bounds, set_number_of_pages, update, w; - cvn = new ConfigurationVariableNames($attributes.atConfig); - w = new ScopeConfigWrapper($scope, cvn, $attributes.atList); - keep_in_bounds = function(val, min, max) { - val = Math.max(min, val); - return Math.min(max, val); - }; - get_number_of_pages = function() { - return $scope[irk_number_of_pages]; - }; - set_number_of_pages = function(number_of_pages) { - return $scope[irk_number_of_pages] = number_of_pages; - }; - update = function(reset) { - var new_number_of_pages, pages_to_display; - if (w.get_list()) { - if (w.get_list().length > 0) { - new_number_of_pages = Math.ceil(w.get_list().length / w.get_items_per_page()); - set_number_of_pages(new_number_of_pages); - if ($scope.show_sectioning()) { - pages_to_display = w.get_max_pages(); - } else { - pages_to_display = new_number_of_pages; - } - $scope.page_sequence.reset_parameters(0, new_number_of_pages, pages_to_display); - w.set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); - return $scope.page_sequence.realign_greedy(w.get_current_page()); - } else { - set_number_of_pages(1); - $scope.page_sequence.reset_parameters(0, 1, 1); - w.set_current_page(0); - return $scope.page_sequence.realign_greedy(0); - } - } - }; - $scope.show_sectioning = function() { - return w.get_max_pages() && get_number_of_pages() > w.get_max_pages(); - }; - $scope.get_current_page = function() { - return w.get_current_page(); - }; - $scope.step_page = function(step) { - step = parseInt(step); - w.set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)); - return $scope.page_sequence.realign_greedy(w.get_current_page()); - }; - $scope.go_to_page = function(page) { - return w.set_current_page(page); - }; - $scope.jump_back = function() { - return $scope.step_page(-w.get_max_pages()); - }; - $scope.jump_ahead = function() { - return $scope.step_page(w.get_max_pages()); - }; - $scope.page_sequence = new PageSequence(); - $scope.$watch(cvn.items_per_page, function() { - return update(); - }); - $scope.$watch(cvn.max_pages, function() { - return update(); - }); - $scope.$watch($attributes.atList, function() { - return update(); - }); - $scope.$watch("" + $attributes.atList + ".length", function() { - return update(); - }); - return update(); - } - }; - } - ]); - - angular.module("angular-table").directive("atImplicit", [ - function() { - return { - restrict: "AC", - compile: function(element, attributes, transclude) { - var attribute; - attribute = element.attr("at-attribute"); - if (!attribute) { - throw "at-implicit specified without at-attribute: " + (element.html()); - } - return element.append("{{item." + attribute + "}}"); - } - }; - } - ]); - -}).call(this); diff --git a/gem/lib/angular-table.rb b/gem/lib/angular-table.rb deleted file mode 100644 index 2206d6a..0000000 --- a/gem/lib/angular-table.rb +++ /dev/null @@ -1,4 +0,0 @@ -module AngularTable - class Engine < ::Rails::Engine - end -end diff --git a/gem/lib/angular-table/version.rb b/gem/lib/angular-table/version.rb deleted file mode 100644 index 35aaad1..0000000 --- a/gem/lib/angular-table/version.rb +++ /dev/null @@ -1,3 +0,0 @@ -module AngularTable - VERSION = "0.0.8" -end From 0414011a804c673fcd552356d93369ed8c411d55 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 8 Mar 2014 23:16:18 +0100 Subject: [PATCH 131/190] master branch only --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index c2ba3f9..122fda9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,7 @@ +branches: + only: + - master + language: node_js node_js: - 0.8 \ No newline at end of file From c2ab35a7c8ec531dc4d420060c7b5e4573b70a50 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 18 Mar 2014 21:08:07 +0100 Subject: [PATCH 132/190] moved template to its own file --- Gruntfile.coffee | 3 +- coffee/angular_table.coffee | 33 ------------------- .../pagination/pagination_template.coffee | 32 ++++++++++++++++++ karma.conf.js | 1 + 4 files changed, 35 insertions(+), 34 deletions(-) create mode 100644 coffee/directives/pagination/pagination_template.coffee diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 799034d..892fc90 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -27,6 +27,7 @@ module.exports = (grunt) -> 'coffee/directives/table/table.coffee', 'coffee/directives/pagination/page_sequence.coffee', + 'coffee/directives/pagination/pagination_template.coffee', 'coffee/directives/at_table.coffee', 'coffee/directives/at_pagination.coffee', @@ -52,4 +53,4 @@ module.exports = (grunt) -> grunt.loadNpmTasks('grunt-contrib-coffee') grunt.loadNpmTasks('grunt-banner') - grunt.registerTask('default', ['coffee', 'usebanner', 'uglify']) \ No newline at end of file + grunt.registerTask('default', ['coffee', 'usebanner', 'uglify']) diff --git a/coffee/angular_table.coffee b/coffee/angular_table.coffee index fe87ed6..293e458 100644 --- a/coffee/angular_table.coffee +++ b/coffee/angular_table.coffee @@ -30,36 +30,3 @@ class ScopeConfigWrapper angular.module "angular-table", [] irk_number_of_pages = "number_of_pages" - -pagination_template = " -
    - -
    " \ No newline at end of file diff --git a/coffee/directives/pagination/pagination_template.coffee b/coffee/directives/pagination/pagination_template.coffee new file mode 100644 index 0000000..e922eb2 --- /dev/null +++ b/coffee/directives/pagination/pagination_template.coffee @@ -0,0 +1,32 @@ +pagination_template = " +
    + +
    " diff --git a/karma.conf.js b/karma.conf.js index 8215d88..4d97586 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -29,6 +29,7 @@ module.exports = function(config) { 'coffee/directives/table/table.coffee', 'coffee/directives/pagination/page_sequence.coffee', + 'coffee/directives/pagination/pagination_template.coffee', 'coffee/directives/at_table.coffee', 'coffee/directives/at_pagination.coffee', From 76fb993ef197ae1a297e9ab1f7852bef8e81b20a Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 18 Mar 2014 21:13:52 +0100 Subject: [PATCH 133/190] moved config classes to config folder --- Gruntfile.coffee | 2 ++ coffee/angular_table.coffee | 29 ------------------- .../configuration_variable_names.coffee | 7 +++++ .../configuration/scope_config_wrapper.coffee | 20 +++++++++++++ karma.conf.js | 2 ++ 5 files changed, 31 insertions(+), 29 deletions(-) create mode 100644 coffee/configuration/configuration_variable_names.coffee create mode 100644 coffee/configuration/scope_config_wrapper.coffee diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 892fc90..d072f27 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -19,6 +19,8 @@ module.exports = (grunt) -> 'coffee/angular_table.coffee', 'coffee/configuration/column_configuration.coffee', + 'coffee/configuration/configuration_variable_names.coffee', + 'coffee/configuration/scope_config_wrapper.coffee', 'coffee/configuration/table_configuration.coffee', 'coffee/directives/table/setup/setup.coffee', diff --git a/coffee/angular_table.coffee b/coffee/angular_table.coffee index 293e458..d45a0ab 100644 --- a/coffee/angular_table.coffee +++ b/coffee/angular_table.coffee @@ -1,32 +1,3 @@ -class ConfigurationVariableNames - constructor: (@config_object_name) -> - @items_per_page = "#{@config_object_name}.itemsPerPage" - @sort_context = "#{@config_object_name}.sortContext" - @fill_last_page = "#{@config_object_name}.fillLastPage" - @max_pages = "#{@config_object_name}.maxPages" - @current_page = "#{@config_object_name}.currentPage" - -class ScopeConfigWrapper - constructor: (@scope, @configuration_variable_names, @list_name) -> - - get_list: () -> - @scope.$eval(@list_name) - - get_items_per_page: () -> - @scope.$eval(@configuration_variable_names.items_per_page) || 10 - - get_current_page: () -> - @scope.$eval(@configuration_variable_names.current_page) || 0 - - get_max_pages: () -> - @scope.$eval(@configuration_variable_names.max_pages) || undefined - - get_sort_context: () -> - @scope.$eval(@configuration_variable_names.sort_context) || 'global' - - set_current_page: (current_page) -> - @scope.$eval("#{@configuration_variable_names.current_page}=#{current_page}") - angular.module "angular-table", [] irk_number_of_pages = "number_of_pages" diff --git a/coffee/configuration/configuration_variable_names.coffee b/coffee/configuration/configuration_variable_names.coffee new file mode 100644 index 0000000..1f1d7d8 --- /dev/null +++ b/coffee/configuration/configuration_variable_names.coffee @@ -0,0 +1,7 @@ +class ConfigurationVariableNames + constructor: (@config_object_name) -> + @items_per_page = "#{@config_object_name}.itemsPerPage" + @sort_context = "#{@config_object_name}.sortContext" + @fill_last_page = "#{@config_object_name}.fillLastPage" + @max_pages = "#{@config_object_name}.maxPages" + @current_page = "#{@config_object_name}.currentPage" diff --git a/coffee/configuration/scope_config_wrapper.coffee b/coffee/configuration/scope_config_wrapper.coffee new file mode 100644 index 0000000..fb19fcd --- /dev/null +++ b/coffee/configuration/scope_config_wrapper.coffee @@ -0,0 +1,20 @@ +class ScopeConfigWrapper + constructor: (@scope, @configuration_variable_names, @list_name) -> + + get_list: () -> + @scope.$eval(@list_name) + + get_items_per_page: () -> + @scope.$eval(@configuration_variable_names.items_per_page) || 10 + + get_current_page: () -> + @scope.$eval(@configuration_variable_names.current_page) || 0 + + get_max_pages: () -> + @scope.$eval(@configuration_variable_names.max_pages) || undefined + + get_sort_context: () -> + @scope.$eval(@configuration_variable_names.sort_context) || 'global' + + set_current_page: (current_page) -> + @scope.$eval("#{@configuration_variable_names.current_page}=#{current_page}") diff --git a/karma.conf.js b/karma.conf.js index 4d97586..53cb0b3 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -21,6 +21,8 @@ module.exports = function(config) { 'coffee/angular_table.coffee', 'coffee/configuration/column_configuration.coffee', + 'coffee/configuration/configuration_variable_names.coffee', + 'coffee/configuration/scope_config_wrapper.coffee', 'coffee/configuration/table_configuration.coffee', 'coffee/directives/table/setup/setup.coffee', From c0e8fae17499c08370f5d1ba7f88dac0efd98b44 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 18 Mar 2014 21:33:05 +0100 Subject: [PATCH 134/190] update licence year --- LICENSE.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.txt b/LICENSE.txt index 24e1533..5212913 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2013 Samuel Mueller +Copyright (c) 2014 Samuel Mueller MIT License From 02bcbde8ce8b3087873cb4e4c6ae3cc5b76a9bdd Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 18 Mar 2014 21:41:27 +0100 Subject: [PATCH 135/190] add bower file --- bower.json | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 bower.json diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..96dd73c --- /dev/null +++ b/bower.json @@ -0,0 +1,29 @@ +{ + "name": "at-table", + "version": "1.0.0", + "homepage": "https://github.com/samu/angular-table", + "authors": [ + "Samuel Mueller" + ], + "keywords": [ + "angular", + "table", + "sortable", + "sorting", + "paginated", + "pagination" + ], + "license": "MIT", + "ignore": [ + "Gruntfile.coffee", + "karma.conf.js", + "**/.*", + "coffee", + "node_modules", + "bower_components", + "test" + ], + "dependencies": { + "angular": "~1.2.9" + }, +} From 00e33cdcfd982728613eda7f9ee6a0fdcdb78b34 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 18 Mar 2014 21:41:33 +0100 Subject: [PATCH 136/190] update version --- Gruntfile.coffee | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gruntfile.coffee b/Gruntfile.coffee index d072f27..96d7532 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -1,4 +1,4 @@ -version = "0.1.0" +version = "1.0.0" banner = " // author: Samuel Mueller \n diff --git a/package.json b/package.json index 1630877..386e157 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-table", - "version": "0.0.8", + "version": "1.0.0", "author": "Samuel Mueller", "repository": { "type": "git", From fd9d96be54d177c1626a64a554a42226de5acdab Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 18 Mar 2014 21:41:51 +0100 Subject: [PATCH 137/190] compile latest --- dist/angular-table.js | 121 +++++++++++++++++++++----------------- dist/angular-table.min.js | 4 +- 2 files changed, 70 insertions(+), 55 deletions(-) diff --git a/dist/angular-table.js b/dist/angular-table.js index b545774..60f9132 100644 --- a/dist/angular-table.js +++ b/dist/angular-table.js @@ -1,65 +1,14 @@ // author: Samuel Mueller -// version: 0.1.0 +// version: 1.0.0 // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var ConfigurationVariableNames, ScopeConfigWrapper, irk_number_of_pages, pagination_template; - - ConfigurationVariableNames = (function() { - function ConfigurationVariableNames(config_object_name) { - this.config_object_name = config_object_name; - this.items_per_page = "" + this.config_object_name + ".itemsPerPage"; - this.sort_context = "" + this.config_object_name + ".sortContext"; - this.fill_last_page = "" + this.config_object_name + ".fillLastPage"; - this.max_pages = "" + this.config_object_name + ".maxPages"; - this.current_page = "" + this.config_object_name + ".currentPage"; - } - - return ConfigurationVariableNames; - - })(); - - ScopeConfigWrapper = (function() { - function ScopeConfigWrapper(scope, configuration_variable_names, list_name) { - this.scope = scope; - this.configuration_variable_names = configuration_variable_names; - this.list_name = list_name; - } - - ScopeConfigWrapper.prototype.get_list = function() { - return this.scope.$eval(this.list_name); - }; - - ScopeConfigWrapper.prototype.get_items_per_page = function() { - return this.scope.$eval(this.configuration_variable_names.items_per_page) || 10; - }; - - ScopeConfigWrapper.prototype.get_current_page = function() { - return this.scope.$eval(this.configuration_variable_names.current_page) || 0; - }; - - ScopeConfigWrapper.prototype.get_max_pages = function() { - return this.scope.$eval(this.configuration_variable_names.max_pages) || void 0; - }; - - ScopeConfigWrapper.prototype.get_sort_context = function() { - return this.scope.$eval(this.configuration_variable_names.sort_context) || 'global'; - }; - - ScopeConfigWrapper.prototype.set_current_page = function(current_page) { - return this.scope.$eval("" + this.configuration_variable_names.current_page + "=" + current_page); - }; - - return ScopeConfigWrapper; - - })(); + var irk_number_of_pages; angular.module("angular-table", []); irk_number_of_pages = "number_of_pages"; - pagination_template = ""; - }).call(this); (function() { @@ -130,6 +79,65 @@ }).call(this); +(function() { + var ConfigurationVariableNames; + + ConfigurationVariableNames = (function() { + function ConfigurationVariableNames(config_object_name) { + this.config_object_name = config_object_name; + this.items_per_page = "" + this.config_object_name + ".itemsPerPage"; + this.sort_context = "" + this.config_object_name + ".sortContext"; + this.fill_last_page = "" + this.config_object_name + ".fillLastPage"; + this.max_pages = "" + this.config_object_name + ".maxPages"; + this.current_page = "" + this.config_object_name + ".currentPage"; + } + + return ConfigurationVariableNames; + + })(); + +}).call(this); + +(function() { + var ScopeConfigWrapper; + + ScopeConfigWrapper = (function() { + function ScopeConfigWrapper(scope, configuration_variable_names, list_name) { + this.scope = scope; + this.configuration_variable_names = configuration_variable_names; + this.list_name = list_name; + } + + ScopeConfigWrapper.prototype.get_list = function() { + return this.scope.$eval(this.list_name); + }; + + ScopeConfigWrapper.prototype.get_items_per_page = function() { + return this.scope.$eval(this.configuration_variable_names.items_per_page) || 10; + }; + + ScopeConfigWrapper.prototype.get_current_page = function() { + return this.scope.$eval(this.configuration_variable_names.current_page) || 0; + }; + + ScopeConfigWrapper.prototype.get_max_pages = function() { + return this.scope.$eval(this.configuration_variable_names.max_pages) || void 0; + }; + + ScopeConfigWrapper.prototype.get_sort_context = function() { + return this.scope.$eval(this.configuration_variable_names.sort_context) || 'global'; + }; + + ScopeConfigWrapper.prototype.set_current_page = function(current_page) { + return this.scope.$eval("" + this.configuration_variable_names.current_page + "=" + current_page); + }; + + return ScopeConfigWrapper; + + })(); + +}).call(this); + (function() { var TableConfiguration; @@ -548,6 +556,13 @@ }).call(this); +(function() { + var pagination_template; + + pagination_template = ""; + +}).call(this); + (function() { angular.module("angular-table").directive("atTable", [ "$filter", function($filter) { diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js index d092d88..8bd64e6 100644 --- a/dist/angular-table.min.js +++ b/dist/angular-table.min.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 0.1.0 +// version: 1.0.0 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var a,b,c,d;a=function(){function a(a){this.config_object_name=a,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return a}(),b=function(){function a(a,b,c){this.scope=a,this.configuration_variable_names=b,this.list_name=c}return a.prototype.get_list=function(){return this.scope.$eval(this.list_name)},a.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},a.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},a.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},a.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},a.prototype.set_current_page=function(a){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+a)},a}(),angular.module("angular-table",[]),c="number_of_pages",d=""}).call(this),function(){var a;a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.custom_content=b.custom_content,this.attributes=b.attributes)}return a.prototype.create_element=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.render_title=function(a){return a.html(this.custom_content||this.title)},a.prototype.render_attributes=function(a){var b,c,d,e,f;if(this.custom_content){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.render_sorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.render_width=function(a){return a.attr("width",this.width)},a.prototype.render_html=function(){var a;return a=this.create_element(),this.render_title(a),this.render_attributes(a),this.render_sorting(a),this.render_width(a),a},a}()}.call(this),function(){var a;a=function(){function a(a,b){this.table_element=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return a.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},a.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},a.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},a.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},a.prototype.collect_header_markup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={custom_content:c.html(),attributes:c[0].attributes};return b},a.prototype.collect_body_markup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},a.prototype.create_column_configurations=function(){var a,b,c,d,e;for(b=this.collect_header_markup(this.table_element),a=this.collect_body_markup(this.table_element),this.column_configurations=[],d=0,e=a.length;e>d;d++)c=a[d],this.column_configurations.push(new ColumnConfiguration(c,b[c.attribute]));return this.column_configurations},a}()}.call(this),function(){var a;a=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}()}.call(this),function(){var a,b={}.hasOwnProperty,c=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a};a=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return c(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(Setup)}.call(this),function(){var a,b={}.hasOwnProperty,c=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a};a=function(a){function b(a){this.configuration_variable_names=a,this.repeatString="item in sorted_and_paginated_list"}return c(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configuration_variable_names.fill_last_page),b.html(e),b.attr("ng-repeat","item in filler_array"),c.append(b)},b.prototype.link=function(a,b,c,d){var e,f,g,h,i;return e=this.configuration_variable_names,i=new ScopeConfigWrapper(a,e,c.atList),g=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},f=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},h=function(){var b;return a.sorted_and_paginated_list=g(i.get_list(),i.get_current_page(),i.get_items_per_page(),i.get_sort_context(),a.predicate,a.descending,d),b=Math.ceil(i.get_list().length/i.get_items_per_page()),a.filler_array=f(i.get_list(),i.get_current_page(),b,i.get_items_per_page())},a.$watch(e.current_page,function(){return h()}),a.$watch(e.items_per_page,function(){return h()}),a.$watch(e.sort_context,function(){return h()}),a.$watch(""+c.atList+".length",function(){return a[irk_number_of_pages]=Math.ceil(i.get_list().length/i.get_items_per_page()),h()}),a.$watch("predicate",function(){return h()}),a.$watch("descending",function(){return h()})},b}(Setup)}.call(this),function(){var a;a=function(){function a(a,b,c){this.element=a,this.table_configuration=b,this.configuration_variable_names=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.table_configuration.column_configurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.render_html());return b},a.prototype.setup_header=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.get_setup=function(){return this.table_configuration.paginated?new PaginatedSetup(this.configuration_variable_names):new StandardSetup(this.configuration_variable_names,this.table_configuration.list)},a.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},a.prototype.setup_initial_sorting=function(a){var b,c,d,e,f;for(e=this.table_configuration.column_configurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setup_initial_sorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}()}.call(this),function(){var a;a=function(){function a(a,b,c,d){if(this.lower_bound=null!=a?a:0,this.upper_bound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upper_bound-this.length?a=this.upper_bound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.reset_parameters=function(a,b,c){if(this.lower_bound=a,this.upper_bound=b,this.length=c,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realign_greedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realign_generous=function(){},a}()}.call(this),function(){angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c){var d,e,f;return f=new TableConfiguration(b,c),d=new ConfigurationVariableNames(c.atConfig),e=new Table(b,f,d),e.compile(),{post:function(b,c,d){return e.post(b,c,d,a)}}}}}])}.call(this),function(){angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:pagination_template,link:function(a,b,c){var d,e,f,g,h,i;return d=new ConfigurationVariableNames(c.atConfig),i=new ScopeConfigWrapper(a,d,c.atList),f=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},e=function(){return a[irk_number_of_pages]},g=function(b){return a[irk_number_of_pages]=b},h=function(){var b,c;return i.get_list()?i.get_list().length>0?(b=Math.ceil(i.get_list().length/i.get_items_per_page()),g(b),c=a.show_sectioning()?i.get_max_pages():b,a.page_sequence.reset_parameters(0,b,c),i.set_current_page(f(i.get_current_page(),0,e()-1)),a.page_sequence.realign_greedy(i.get_current_page())):(g(1),a.page_sequence.reset_parameters(0,1,1),i.set_current_page(0),a.page_sequence.realign_greedy(0)):void 0},a.show_sectioning=function(){return i.get_max_pages()&&e()>i.get_max_pages()},a.get_current_page=function(){return i.get_current_page()},a.step_page=function(b){return b=parseInt(b),i.set_current_page(f(i.get_current_page()+b,0,e()-1)),a.page_sequence.realign_greedy(i.get_current_page())},a.go_to_page=function(a){return i.set_current_page(a)},a.jump_back=function(){return a.step_page(-i.get_max_pages())},a.jump_ahead=function(){return a.step_page(i.get_max_pages())},a.page_sequence=new PageSequence,a.$watch(d.items_per_page,function(){return h()}),a.$watch(d.max_pages,function(){return h()}),a.$watch(c.atList,function(){return h()}),a.$watch(""+c.atList+".length",function(){return h()}),h()}}}])}.call(this),function(){angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}.call(this); \ No newline at end of file +(function(){var a;angular.module("angular-table",[]),a="number_of_pages"}).call(this),function(){var a;a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.custom_content=b.custom_content,this.attributes=b.attributes)}return a.prototype.create_element=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.render_title=function(a){return a.html(this.custom_content||this.title)},a.prototype.render_attributes=function(a){var b,c,d,e,f;if(this.custom_content){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.render_sorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.render_width=function(a){return a.attr("width",this.width)},a.prototype.render_html=function(){var a;return a=this.create_element(),this.render_title(a),this.render_attributes(a),this.render_sorting(a),this.render_width(a),a},a}()}.call(this),function(){var a;a=function(){function a(a){this.config_object_name=a,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return a}()}.call(this),function(){var a;a=function(){function a(a,b,c){this.scope=a,this.configuration_variable_names=b,this.list_name=c}return a.prototype.get_list=function(){return this.scope.$eval(this.list_name)},a.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},a.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},a.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},a.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},a.prototype.set_current_page=function(a){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+a)},a}()}.call(this),function(){var a;a=function(){function a(a,b){this.table_element=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return a.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},a.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},a.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},a.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},a.prototype.collect_header_markup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={custom_content:c.html(),attributes:c[0].attributes};return b},a.prototype.collect_body_markup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},a.prototype.create_column_configurations=function(){var a,b,c,d,e;for(b=this.collect_header_markup(this.table_element),a=this.collect_body_markup(this.table_element),this.column_configurations=[],d=0,e=a.length;e>d;d++)c=a[d],this.column_configurations.push(new ColumnConfiguration(c,b[c.attribute]));return this.column_configurations},a}()}.call(this),function(){var a;a=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}()}.call(this),function(){var a,b={}.hasOwnProperty,c=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a};a=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return c(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(Setup)}.call(this),function(){var a,b={}.hasOwnProperty,c=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a};a=function(a){function b(a){this.configuration_variable_names=a,this.repeatString="item in sorted_and_paginated_list"}return c(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configuration_variable_names.fill_last_page),b.html(e),b.attr("ng-repeat","item in filler_array"),c.append(b)},b.prototype.link=function(a,b,c,d){var e,f,g,h,i;return e=this.configuration_variable_names,i=new ScopeConfigWrapper(a,e,c.atList),g=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},f=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},h=function(){var b;return a.sorted_and_paginated_list=g(i.get_list(),i.get_current_page(),i.get_items_per_page(),i.get_sort_context(),a.predicate,a.descending,d),b=Math.ceil(i.get_list().length/i.get_items_per_page()),a.filler_array=f(i.get_list(),i.get_current_page(),b,i.get_items_per_page())},a.$watch(e.current_page,function(){return h()}),a.$watch(e.items_per_page,function(){return h()}),a.$watch(e.sort_context,function(){return h()}),a.$watch(""+c.atList+".length",function(){return a[irk_number_of_pages]=Math.ceil(i.get_list().length/i.get_items_per_page()),h()}),a.$watch("predicate",function(){return h()}),a.$watch("descending",function(){return h()})},b}(Setup)}.call(this),function(){var a;a=function(){function a(a,b,c){this.element=a,this.table_configuration=b,this.configuration_variable_names=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.table_configuration.column_configurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.render_html());return b},a.prototype.setup_header=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.get_setup=function(){return this.table_configuration.paginated?new PaginatedSetup(this.configuration_variable_names):new StandardSetup(this.configuration_variable_names,this.table_configuration.list)},a.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},a.prototype.setup_initial_sorting=function(a){var b,c,d,e,f;for(e=this.table_configuration.column_configurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setup_initial_sorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}()}.call(this),function(){var a;a=function(){function a(a,b,c,d){if(this.lower_bound=null!=a?a:0,this.upper_bound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upper_bound-this.length?a=this.upper_bound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.reset_parameters=function(a,b,c){if(this.lower_bound=a,this.upper_bound=b,this.length=c,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realign_greedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realign_generous=function(){},a}()}.call(this),function(){var a;a=""}.call(this),function(){angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c){var d,e,f;return f=new TableConfiguration(b,c),d=new ConfigurationVariableNames(c.atConfig),e=new Table(b,f,d),e.compile(),{post:function(b,c,d){return e.post(b,c,d,a)}}}}}])}.call(this),function(){angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:pagination_template,link:function(a,b,c){var d,e,f,g,h,i;return d=new ConfigurationVariableNames(c.atConfig),i=new ScopeConfigWrapper(a,d,c.atList),f=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},e=function(){return a[irk_number_of_pages]},g=function(b){return a[irk_number_of_pages]=b},h=function(){var b,c;return i.get_list()?i.get_list().length>0?(b=Math.ceil(i.get_list().length/i.get_items_per_page()),g(b),c=a.show_sectioning()?i.get_max_pages():b,a.page_sequence.reset_parameters(0,b,c),i.set_current_page(f(i.get_current_page(),0,e()-1)),a.page_sequence.realign_greedy(i.get_current_page())):(g(1),a.page_sequence.reset_parameters(0,1,1),i.set_current_page(0),a.page_sequence.realign_greedy(0)):void 0},a.show_sectioning=function(){return i.get_max_pages()&&e()>i.get_max_pages()},a.get_current_page=function(){return i.get_current_page()},a.step_page=function(b){return b=parseInt(b),i.set_current_page(f(i.get_current_page()+b,0,e()-1)),a.page_sequence.realign_greedy(i.get_current_page())},a.go_to_page=function(a){return i.set_current_page(a)},a.jump_back=function(){return a.step_page(-i.get_max_pages())},a.jump_ahead=function(){return a.step_page(i.get_max_pages())},a.page_sequence=new PageSequence,a.$watch(d.items_per_page,function(){return h()}),a.$watch(d.max_pages,function(){return h()}),a.$watch(c.atList,function(){return h()}),a.$watch(""+c.atList+".length",function(){return h()}),h()}}}])}.call(this),function(){angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}.call(this); \ No newline at end of file From cc05ed493ec9ccf032abf7e0fe87839634be2b44 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 18 Mar 2014 21:45:07 +0100 Subject: [PATCH 138/190] fix malformed bower file --- bower.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index 96dd73c..69d2ded 100644 --- a/bower.json +++ b/bower.json @@ -12,7 +12,7 @@ "sorting", "paginated", "pagination" - ], + ], "license": "MIT", "ignore": [ "Gruntfile.coffee", @@ -25,5 +25,5 @@ ], "dependencies": { "angular": "~1.2.9" - }, + } } From c76d285ea1c277676225f4839bc34062634613a7 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 18 Mar 2014 21:56:19 +0100 Subject: [PATCH 139/190] update readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index fca940e..3e63c82 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ pagination with very little effort. This directive depends on angular only. No jQuery or Bootstrap required! It has been tested on angular 1.2, but it should also work with 1.1 releases. +## Install via bower +`bower install at-table` + ## How Lets assume we have an array containing objects representing people. A person object has the following format: From 3267d8da44ca18936bfb996f1ee55d794dab0251 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 18 Mar 2014 21:59:26 +0100 Subject: [PATCH 140/190] update readme --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3e63c82..ac8bf08 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ Angular directive which allows to declare sortable tables and to add pagination with very little effort. +Available via bower: `bower install at-table` + ## Features * Adds sorting to any column * Adds pagination @@ -15,9 +17,6 @@ pagination with very little effort. This directive depends on angular only. No jQuery or Bootstrap required! It has been tested on angular 1.2, but it should also work with 1.1 releases. -## Install via bower -`bower install at-table` - ## How Lets assume we have an array containing objects representing people. A person object has the following format: From c56576213d30a3291e070e77531fe98c7abe7d6a Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 18 Mar 2014 22:00:32 +0100 Subject: [PATCH 141/190] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ac8bf08..9aa84b1 100644 --- a/README.md +++ b/README.md @@ -103,5 +103,5 @@ It has a powerful and beautiful syntax and is easy to learn. You'll probably nee ### TDD The code for this directive is well covered with tests, which can be run with PhantomJS and -Karma. run `npm install` to install the required packages. Then, run `karma start` to run +Karma. Run `npm install` to install the required packages. Then, run `karma start` to run the tests. Make sure all the tests pass before you send a pull request. From 5c86f24cd404904c14858c9e34349d3d3585fd70 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 18 Mar 2014 22:13:15 +0100 Subject: [PATCH 142/190] concatenate first --- Gruntfile.coffee | 2 ++ dist/angular-table.js | 67 ++------------------------------------- dist/angular-table.min.js | 2 +- 3 files changed, 6 insertions(+), 65 deletions(-) diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 96d7532..e7cf941 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -14,6 +14,8 @@ module.exports = (grunt) -> version: version coffee: + options: + join: true compile: files: {"dist/angular-table.js" : [ 'coffee/angular_table.coffee', diff --git a/dist/angular-table.js b/dist/angular-table.js index 60f9132..604c990 100644 --- a/dist/angular-table.js +++ b/dist/angular-table.js @@ -3,17 +3,14 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var irk_number_of_pages; + var ColumnConfiguration, ConfigurationVariableNames, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, irk_number_of_pages, pagination_template, + __hasProp = {}.hasOwnProperty, + __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; angular.module("angular-table", []); irk_number_of_pages = "number_of_pages"; -}).call(this); - -(function() { - var ColumnConfiguration; - ColumnConfiguration = (function() { function ColumnConfiguration(body_markup, header_markup) { this.attribute = body_markup.attribute; @@ -77,11 +74,6 @@ })(); -}).call(this); - -(function() { - var ConfigurationVariableNames; - ConfigurationVariableNames = (function() { function ConfigurationVariableNames(config_object_name) { this.config_object_name = config_object_name; @@ -96,11 +88,6 @@ })(); -}).call(this); - -(function() { - var ScopeConfigWrapper; - ScopeConfigWrapper = (function() { function ScopeConfigWrapper(scope, configuration_variable_names, list_name) { this.scope = scope; @@ -136,11 +123,6 @@ })(); -}).call(this); - -(function() { - var TableConfiguration; - TableConfiguration = (function() { function TableConfiguration(table_element, attributes) { this.table_element = table_element; @@ -247,11 +229,6 @@ })(); -}).call(this); - -(function() { - var Setup; - Setup = (function() { function Setup() {} @@ -267,13 +244,6 @@ })(); -}).call(this); - -(function() { - var StandardSetup, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; - StandardSetup = (function(_super) { __extends(StandardSetup, _super); @@ -292,13 +262,6 @@ })(Setup); -}).call(this); - -(function() { - var PaginatedSetup, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; - PaginatedSetup = (function(_super) { __extends(PaginatedSetup, _super); @@ -400,11 +363,6 @@ })(Setup); -}).call(this); - -(function() { - var Table; - Table = (function() { function Table(element, table_configuration, configuration_variable_names) { this.element = element; @@ -488,11 +446,6 @@ })(); -}).call(this); - -(function() { - var PageSequence; - PageSequence = (function() { function PageSequence(lower_bound, upper_bound, start, length) { this.lower_bound = lower_bound != null ? lower_bound : 0; @@ -554,16 +507,8 @@ })(); -}).call(this); - -(function() { - var pagination_template; - pagination_template = ""; -}).call(this); - -(function() { angular.module("angular-table").directive("atTable", [ "$filter", function($filter) { return { @@ -585,9 +530,6 @@ } ]); -}).call(this); - -(function() { angular.module("angular-table").directive("atPagination", [ function() { return { @@ -670,9 +612,6 @@ } ]); -}).call(this); - -(function() { angular.module("angular-table").directive("atImplicit", [ function() { return { diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js index 8bd64e6..e86e1b1 100644 --- a/dist/angular-table.min.js +++ b/dist/angular-table.min.js @@ -2,4 +2,4 @@ // version: 1.0.0 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var a;angular.module("angular-table",[]),a="number_of_pages"}).call(this),function(){var a;a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.custom_content=b.custom_content,this.attributes=b.attributes)}return a.prototype.create_element=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.render_title=function(a){return a.html(this.custom_content||this.title)},a.prototype.render_attributes=function(a){var b,c,d,e,f;if(this.custom_content){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.render_sorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.render_width=function(a){return a.attr("width",this.width)},a.prototype.render_html=function(){var a;return a=this.create_element(),this.render_title(a),this.render_attributes(a),this.render_sorting(a),this.render_width(a),a},a}()}.call(this),function(){var a;a=function(){function a(a){this.config_object_name=a,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return a}()}.call(this),function(){var a;a=function(){function a(a,b,c){this.scope=a,this.configuration_variable_names=b,this.list_name=c}return a.prototype.get_list=function(){return this.scope.$eval(this.list_name)},a.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},a.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},a.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},a.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},a.prototype.set_current_page=function(a){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+a)},a}()}.call(this),function(){var a;a=function(){function a(a,b){this.table_element=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return a.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},a.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},a.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},a.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},a.prototype.collect_header_markup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={custom_content:c.html(),attributes:c[0].attributes};return b},a.prototype.collect_body_markup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},a.prototype.create_column_configurations=function(){var a,b,c,d,e;for(b=this.collect_header_markup(this.table_element),a=this.collect_body_markup(this.table_element),this.column_configurations=[],d=0,e=a.length;e>d;d++)c=a[d],this.column_configurations.push(new ColumnConfiguration(c,b[c.attribute]));return this.column_configurations},a}()}.call(this),function(){var a;a=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}()}.call(this),function(){var a,b={}.hasOwnProperty,c=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a};a=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return c(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(Setup)}.call(this),function(){var a,b={}.hasOwnProperty,c=function(a,c){function d(){this.constructor=a}for(var e in c)b.call(c,e)&&(a[e]=c[e]);return d.prototype=c.prototype,a.prototype=new d,a.__super__=c.prototype,a};a=function(a){function b(a){this.configuration_variable_names=a,this.repeatString="item in sorted_and_paginated_list"}return c(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configuration_variable_names.fill_last_page),b.html(e),b.attr("ng-repeat","item in filler_array"),c.append(b)},b.prototype.link=function(a,b,c,d){var e,f,g,h,i;return e=this.configuration_variable_names,i=new ScopeConfigWrapper(a,e,c.atList),g=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},f=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},h=function(){var b;return a.sorted_and_paginated_list=g(i.get_list(),i.get_current_page(),i.get_items_per_page(),i.get_sort_context(),a.predicate,a.descending,d),b=Math.ceil(i.get_list().length/i.get_items_per_page()),a.filler_array=f(i.get_list(),i.get_current_page(),b,i.get_items_per_page())},a.$watch(e.current_page,function(){return h()}),a.$watch(e.items_per_page,function(){return h()}),a.$watch(e.sort_context,function(){return h()}),a.$watch(""+c.atList+".length",function(){return a[irk_number_of_pages]=Math.ceil(i.get_list().length/i.get_items_per_page()),h()}),a.$watch("predicate",function(){return h()}),a.$watch("descending",function(){return h()})},b}(Setup)}.call(this),function(){var a;a=function(){function a(a,b,c){this.element=a,this.table_configuration=b,this.configuration_variable_names=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.table_configuration.column_configurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.render_html());return b},a.prototype.setup_header=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.get_setup=function(){return this.table_configuration.paginated?new PaginatedSetup(this.configuration_variable_names):new StandardSetup(this.configuration_variable_names,this.table_configuration.list)},a.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},a.prototype.setup_initial_sorting=function(a){var b,c,d,e,f;for(e=this.table_configuration.column_configurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setup_initial_sorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}()}.call(this),function(){var a;a=function(){function a(a,b,c,d){if(this.lower_bound=null!=a?a:0,this.upper_bound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upper_bound-this.length?a=this.upper_bound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.reset_parameters=function(a,b,c){if(this.lower_bound=a,this.upper_bound=b,this.length=c,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realign_greedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realign_generous=function(){},a}()}.call(this),function(){var a;a=""}.call(this),function(){angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c){var d,e,f;return f=new TableConfiguration(b,c),d=new ConfigurationVariableNames(c.atConfig),e=new Table(b,f,d),e.compile(),{post:function(b,c,d){return e.post(b,c,d,a)}}}}}])}.call(this),function(){angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:pagination_template,link:function(a,b,c){var d,e,f,g,h,i;return d=new ConfigurationVariableNames(c.atConfig),i=new ScopeConfigWrapper(a,d,c.atList),f=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},e=function(){return a[irk_number_of_pages]},g=function(b){return a[irk_number_of_pages]=b},h=function(){var b,c;return i.get_list()?i.get_list().length>0?(b=Math.ceil(i.get_list().length/i.get_items_per_page()),g(b),c=a.show_sectioning()?i.get_max_pages():b,a.page_sequence.reset_parameters(0,b,c),i.set_current_page(f(i.get_current_page(),0,e()-1)),a.page_sequence.realign_greedy(i.get_current_page())):(g(1),a.page_sequence.reset_parameters(0,1,1),i.set_current_page(0),a.page_sequence.realign_greedy(0)):void 0},a.show_sectioning=function(){return i.get_max_pages()&&e()>i.get_max_pages()},a.get_current_page=function(){return i.get_current_page()},a.step_page=function(b){return b=parseInt(b),i.set_current_page(f(i.get_current_page()+b,0,e()-1)),a.page_sequence.realign_greedy(i.get_current_page())},a.go_to_page=function(a){return i.set_current_page(a)},a.jump_back=function(){return a.step_page(-i.get_max_pages())},a.jump_ahead=function(){return a.step_page(i.get_max_pages())},a.page_sequence=new PageSequence,a.$watch(d.items_per_page,function(){return h()}),a.$watch(d.max_pages,function(){return h()}),a.$watch(c.atList,function(){return h()}),a.$watch(""+c.atList+".length",function(){return h()}),h()}}}])}.call(this),function(){angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}.call(this); \ No newline at end of file +(function(){var a,b,c,d,e,f,g,h,i,j,k,l={}.hasOwnProperty,m=function(a,b){function c(){this.constructor=a}for(var d in b)l.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),j="number_of_pages",a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.custom_content=b.custom_content,this.attributes=b.attributes)}return a.prototype.create_element=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.render_title=function(a){return a.html(this.custom_content||this.title)},a.prototype.render_attributes=function(a){var b,c,d,e,f;if(this.custom_content){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.render_sorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.render_width=function(a){return a.attr("width",this.width)},a.prototype.render_html=function(){var a;return a=this.create_element(),this.render_title(a),this.render_attributes(a),this.render_sorting(a),this.render_width(a),a},a}(),b=function(){function a(a){this.config_object_name=a,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return a}(),e=function(){function a(a,b,c){this.scope=a,this.configuration_variable_names=b,this.list_name=c}return a.prototype.get_list=function(){return this.scope.$eval(this.list_name)},a.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},a.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},a.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},a.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},a.prototype.set_current_page=function(a){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+a)},a}(),i=function(){function b(a,b){this.table_element=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collect_header_markup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={custom_content:c.html(),attributes:c[0].attributes};return b},b.prototype.collect_body_markup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.create_column_configurations=function(){var b,c,d,e,f;for(c=this.collect_header_markup(this.table_element),b=this.collect_body_markup(this.table_element),this.column_configurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.column_configurations.push(new a(d,c[d.attribute]));return this.column_configurations},b}(),f=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),g=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return m(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(f),d=function(a){function b(a){this.configuration_variable_names=a,this.repeatString="item in sorted_and_paginated_list"}return m(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configuration_variable_names.fill_last_page),b.html(e),b.attr("ng-repeat","item in filler_array"),c.append(b)},b.prototype.link=function(a,b,c,d){var f,g,h,i,k;return f=this.configuration_variable_names,k=new e(a,f,c.atList),h=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sorted_and_paginated_list=h(k.get_list(),k.get_current_page(),k.get_items_per_page(),k.get_sort_context(),a.predicate,a.descending,d),b=Math.ceil(k.get_list().length/k.get_items_per_page()),a.filler_array=g(k.get_list(),k.get_current_page(),b,k.get_items_per_page())},a.$watch(f.current_page,function(){return i()}),a.$watch(f.items_per_page,function(){return i()}),a.$watch(f.sort_context,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a[j]=Math.ceil(k.get_list().length/k.get_items_per_page()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(f),h=function(){function a(a,b,c){this.element=a,this.table_configuration=b,this.configuration_variable_names=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.table_configuration.column_configurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.render_html());return b},a.prototype.setup_header=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.get_setup=function(){return this.table_configuration.paginated?new d(this.configuration_variable_names):new g(this.configuration_variable_names,this.table_configuration.list)},a.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},a.prototype.setup_initial_sorting=function(a){var b,c,d,e,f;for(e=this.table_configuration.column_configurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setup_initial_sorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),c=function(){function a(a,b,c,d){if(this.lower_bound=null!=a?a:0,this.upper_bound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upper_bound-this.length?a=this.upper_bound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.reset_parameters=function(a,b,c){if(this.lower_bound=a,this.upper_bound=b,this.length=c,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realign_greedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realign_generous=function(){},a}(),k="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(c,d){var e,f,g;return g=new i(c,d),e=new b(d.atConfig),f=new h(c,g,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:k,link:function(a,d,f){var g,h,i,k,l,m;return g=new b(f.atConfig),m=new e(a,g,f.atList),i=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},h=function(){return a[j]},k=function(b){return a[j]=b},l=function(){var b,c;return m.get_list()?m.get_list().length>0?(b=Math.ceil(m.get_list().length/m.get_items_per_page()),k(b),c=a.show_sectioning()?m.get_max_pages():b,a.page_sequence.reset_parameters(0,b,c),m.set_current_page(i(m.get_current_page(),0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())):(k(1),a.page_sequence.reset_parameters(0,1,1),m.set_current_page(0),a.page_sequence.realign_greedy(0)):void 0},a.show_sectioning=function(){return m.get_max_pages()&&h()>m.get_max_pages()},a.get_current_page=function(){return m.get_current_page()},a.step_page=function(b){return b=parseInt(b),m.set_current_page(i(m.get_current_page()+b,0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())},a.go_to_page=function(a){return m.set_current_page(a)},a.jump_back=function(){return a.step_page(-m.get_max_pages())},a.jump_ahead=function(){return a.step_page(m.get_max_pages())},a.page_sequence=new c,a.$watch(g.items_per_page,function(){return l()}),a.$watch(g.max_pages,function(){return l()}),a.$watch(f.atList,function(){return l()}),a.$watch(""+f.atList+".length",function(){return l()}),l()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}).call(this); \ No newline at end of file From b71d210b9529cbb5eb47242b7ca17dde4594896c Mon Sep 17 00:00:00 2001 From: Ben Holland Date: Fri, 2 May 2014 09:34:38 +0100 Subject: [PATCH 143/190] Watching the atList for changes (not just length) --- coffee/directives/table/setup/paginated_setup.coffee | 8 ++++++++ dist/angular-table.js | 6 ++++++ dist/angular-table.min.js | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/coffee/directives/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee index 3395a44..0cc3d72 100644 --- a/coffee/directives/table/setup/paginated_setup.coffee +++ b/coffee/directives/table/setup/paginated_setup.coffee @@ -87,6 +87,14 @@ class PaginatedSetup extends Setup update() ) + $scope.$watch(cvn.sort_context, () -> + update() + ) + + $scope.$watch($attributes.atList, () -> + update() + ) + $scope.$watch("#{$attributes.atList}.length", () -> $scope[irk_number_of_pages] = Math.ceil(w.get_list().length / w.get_items_per_page()) update() diff --git a/dist/angular-table.js b/dist/angular-table.js index 604c990..9b0785d 100644 --- a/dist/angular-table.js +++ b/dist/angular-table.js @@ -347,6 +347,12 @@ $scope.$watch(cvn.sort_context, function() { return update(); }); + $scope.$watch(cvn.sort_context, function() { + return update(); + }); + $scope.$watch($attributes.atList, function() { + return update(); + }); $scope.$watch("" + $attributes.atList + ".length", function() { $scope[irk_number_of_pages] = Math.ceil(w.get_list().length / w.get_items_per_page()); return update(); diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js index e86e1b1..538a481 100644 --- a/dist/angular-table.min.js +++ b/dist/angular-table.min.js @@ -2,4 +2,4 @@ // version: 1.0.0 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var a,b,c,d,e,f,g,h,i,j,k,l={}.hasOwnProperty,m=function(a,b){function c(){this.constructor=a}for(var d in b)l.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),j="number_of_pages",a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.custom_content=b.custom_content,this.attributes=b.attributes)}return a.prototype.create_element=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.render_title=function(a){return a.html(this.custom_content||this.title)},a.prototype.render_attributes=function(a){var b,c,d,e,f;if(this.custom_content){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.render_sorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.render_width=function(a){return a.attr("width",this.width)},a.prototype.render_html=function(){var a;return a=this.create_element(),this.render_title(a),this.render_attributes(a),this.render_sorting(a),this.render_width(a),a},a}(),b=function(){function a(a){this.config_object_name=a,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return a}(),e=function(){function a(a,b,c){this.scope=a,this.configuration_variable_names=b,this.list_name=c}return a.prototype.get_list=function(){return this.scope.$eval(this.list_name)},a.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},a.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},a.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},a.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},a.prototype.set_current_page=function(a){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+a)},a}(),i=function(){function b(a,b){this.table_element=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collect_header_markup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={custom_content:c.html(),attributes:c[0].attributes};return b},b.prototype.collect_body_markup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.create_column_configurations=function(){var b,c,d,e,f;for(c=this.collect_header_markup(this.table_element),b=this.collect_body_markup(this.table_element),this.column_configurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.column_configurations.push(new a(d,c[d.attribute]));return this.column_configurations},b}(),f=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),g=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return m(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(f),d=function(a){function b(a){this.configuration_variable_names=a,this.repeatString="item in sorted_and_paginated_list"}return m(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configuration_variable_names.fill_last_page),b.html(e),b.attr("ng-repeat","item in filler_array"),c.append(b)},b.prototype.link=function(a,b,c,d){var f,g,h,i,k;return f=this.configuration_variable_names,k=new e(a,f,c.atList),h=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sorted_and_paginated_list=h(k.get_list(),k.get_current_page(),k.get_items_per_page(),k.get_sort_context(),a.predicate,a.descending,d),b=Math.ceil(k.get_list().length/k.get_items_per_page()),a.filler_array=g(k.get_list(),k.get_current_page(),b,k.get_items_per_page())},a.$watch(f.current_page,function(){return i()}),a.$watch(f.items_per_page,function(){return i()}),a.$watch(f.sort_context,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a[j]=Math.ceil(k.get_list().length/k.get_items_per_page()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(f),h=function(){function a(a,b,c){this.element=a,this.table_configuration=b,this.configuration_variable_names=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.table_configuration.column_configurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.render_html());return b},a.prototype.setup_header=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.get_setup=function(){return this.table_configuration.paginated?new d(this.configuration_variable_names):new g(this.configuration_variable_names,this.table_configuration.list)},a.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},a.prototype.setup_initial_sorting=function(a){var b,c,d,e,f;for(e=this.table_configuration.column_configurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setup_initial_sorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),c=function(){function a(a,b,c,d){if(this.lower_bound=null!=a?a:0,this.upper_bound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upper_bound-this.length?a=this.upper_bound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.reset_parameters=function(a,b,c){if(this.lower_bound=a,this.upper_bound=b,this.length=c,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realign_greedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realign_generous=function(){},a}(),k="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(c,d){var e,f,g;return g=new i(c,d),e=new b(d.atConfig),f=new h(c,g,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:k,link:function(a,d,f){var g,h,i,k,l,m;return g=new b(f.atConfig),m=new e(a,g,f.atList),i=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},h=function(){return a[j]},k=function(b){return a[j]=b},l=function(){var b,c;return m.get_list()?m.get_list().length>0?(b=Math.ceil(m.get_list().length/m.get_items_per_page()),k(b),c=a.show_sectioning()?m.get_max_pages():b,a.page_sequence.reset_parameters(0,b,c),m.set_current_page(i(m.get_current_page(),0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())):(k(1),a.page_sequence.reset_parameters(0,1,1),m.set_current_page(0),a.page_sequence.realign_greedy(0)):void 0},a.show_sectioning=function(){return m.get_max_pages()&&h()>m.get_max_pages()},a.get_current_page=function(){return m.get_current_page()},a.step_page=function(b){return b=parseInt(b),m.set_current_page(i(m.get_current_page()+b,0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())},a.go_to_page=function(a){return m.set_current_page(a)},a.jump_back=function(){return a.step_page(-m.get_max_pages())},a.jump_ahead=function(){return a.step_page(m.get_max_pages())},a.page_sequence=new c,a.$watch(g.items_per_page,function(){return l()}),a.$watch(g.max_pages,function(){return l()}),a.$watch(f.atList,function(){return l()}),a.$watch(""+f.atList+".length",function(){return l()}),l()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var a,b,c,d,e,f,g,h,i,j,k,l={}.hasOwnProperty,m=function(a,b){function c(){this.constructor=a}for(var d in b)l.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),j="number_of_pages",a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.custom_content=b.custom_content,this.attributes=b.attributes)}return a.prototype.create_element=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.render_title=function(a){return a.html(this.custom_content||this.title)},a.prototype.render_attributes=function(a){var b,c,d,e,f;if(this.custom_content){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.render_sorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.render_width=function(a){return a.attr("width",this.width)},a.prototype.render_html=function(){var a;return a=this.create_element(),this.render_title(a),this.render_attributes(a),this.render_sorting(a),this.render_width(a),a},a}(),b=function(){function a(a){this.config_object_name=a,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return a}(),e=function(){function a(a,b,c){this.scope=a,this.configuration_variable_names=b,this.list_name=c}return a.prototype.get_list=function(){return this.scope.$eval(this.list_name)},a.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},a.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},a.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},a.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},a.prototype.set_current_page=function(a){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+a)},a}(),i=function(){function b(a,b){this.table_element=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collect_header_markup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={custom_content:c.html(),attributes:c[0].attributes};return b},b.prototype.collect_body_markup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.create_column_configurations=function(){var b,c,d,e,f;for(c=this.collect_header_markup(this.table_element),b=this.collect_body_markup(this.table_element),this.column_configurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.column_configurations.push(new a(d,c[d.attribute]));return this.column_configurations},b}(),f=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),g=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return m(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(f),d=function(a){function b(a){this.configuration_variable_names=a,this.repeatString="item in sorted_and_paginated_list"}return m(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configuration_variable_names.fill_last_page),b.html(e),b.attr("ng-repeat","item in filler_array"),c.append(b)},b.prototype.link=function(a,b,c,d){var f,g,h,i,k;return f=this.configuration_variable_names,k=new e(a,f,c.atList),h=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sorted_and_paginated_list=h(k.get_list(),k.get_current_page(),k.get_items_per_page(),k.get_sort_context(),a.predicate,a.descending,d),b=Math.ceil(k.get_list().length/k.get_items_per_page()),a.filler_array=g(k.get_list(),k.get_current_page(),b,k.get_items_per_page())},a.$watch(f.current_page,function(){return i()}),a.$watch(f.items_per_page,function(){return i()}),a.$watch(f.sort_context,function(){return i()}),a.$watch(f.sort_context,function(){return i()}),a.$watch(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a[j]=Math.ceil(k.get_list().length/k.get_items_per_page()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(f),h=function(){function a(a,b,c){this.element=a,this.table_configuration=b,this.configuration_variable_names=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.table_configuration.column_configurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.render_html());return b},a.prototype.setup_header=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.get_setup=function(){return this.table_configuration.paginated?new d(this.configuration_variable_names):new g(this.configuration_variable_names,this.table_configuration.list)},a.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},a.prototype.setup_initial_sorting=function(a){var b,c,d,e,f;for(e=this.table_configuration.column_configurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setup_initial_sorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),c=function(){function a(a,b,c,d){if(this.lower_bound=null!=a?a:0,this.upper_bound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upper_bound-this.length?a=this.upper_bound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.reset_parameters=function(a,b,c){if(this.lower_bound=a,this.upper_bound=b,this.length=c,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realign_greedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realign_generous=function(){},a}(),k="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(c,d){var e,f,g;return g=new i(c,d),e=new b(d.atConfig),f=new h(c,g,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:k,link:function(a,d,f){var g,h,i,k,l,m;return g=new b(f.atConfig),m=new e(a,g,f.atList),i=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},h=function(){return a[j]},k=function(b){return a[j]=b},l=function(){var b,c;return m.get_list()?m.get_list().length>0?(b=Math.ceil(m.get_list().length/m.get_items_per_page()),k(b),c=a.show_sectioning()?m.get_max_pages():b,a.page_sequence.reset_parameters(0,b,c),m.set_current_page(i(m.get_current_page(),0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())):(k(1),a.page_sequence.reset_parameters(0,1,1),m.set_current_page(0),a.page_sequence.realign_greedy(0)):void 0},a.show_sectioning=function(){return m.get_max_pages()&&h()>m.get_max_pages()},a.get_current_page=function(){return m.get_current_page()},a.step_page=function(b){return b=parseInt(b),m.set_current_page(i(m.get_current_page()+b,0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())},a.go_to_page=function(a){return m.set_current_page(a)},a.jump_back=function(){return a.step_page(-m.get_max_pages())},a.jump_ahead=function(){return a.step_page(m.get_max_pages())},a.page_sequence=new c,a.$watch(g.items_per_page,function(){return l()}),a.$watch(g.max_pages,function(){return l()}),a.$watch(f.atList,function(){return l()}),a.$watch(""+f.atList+".length",function(){return l()}),l()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}).call(this); \ No newline at end of file From 2d83dcc6c981737c2ebf48e564bd83320a64b5b0 Mon Sep 17 00:00:00 2001 From: Ben Holland Date: Fri, 2 May 2014 09:35:10 +0100 Subject: [PATCH 144/190] Ignoring bower_components in gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a36b0cf..90f052d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *sublime* _site *.log -node_modules \ No newline at end of file +node_modules +bower_components From b25167c0467a94953be83185f0d162e00de80bcd Mon Sep 17 00:00:00 2001 From: Ben Holland Date: Fri, 2 May 2014 09:49:37 +0100 Subject: [PATCH 145/190] Added development dependencies to bower --- bower.json | 5 +++++ karma.conf.js | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index 69d2ded..e5b63e3 100644 --- a/bower.json +++ b/bower.json @@ -25,5 +25,10 @@ ], "dependencies": { "angular": "~1.2.9" + }, + "devDependencies": { + "angular": "1.2.11", + "angular-mocks": "1.2.11", + "underscore": "~1.6.0" } } diff --git a/karma.conf.js b/karma.conf.js index 53cb0b3..b6f75ca 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -14,9 +14,9 @@ module.exports = function(config) { // list of files / patterns to load in the browser files: [ - 'http://code.angularjs.org/1.2.11/angular.min.js', - 'http://code.angularjs.org/1.2.11/angular-mocks.js', - 'http://underscorejs.org/underscore-min.js', + 'bower_components/angular/angular.min.js', + 'bower_components/angular-mocks/angular-mocks.js', + 'bower_components/underscore/underscore.js', 'coffee/angular_table.coffee', From 8d38ea4f3f97ae8669404b69e7c16fba831b6048 Mon Sep 17 00:00:00 2001 From: Ben Holland Date: Fri, 2 May 2014 09:52:49 +0100 Subject: [PATCH 146/190] Added bower as a npm dev dependency and installing bower components on post install --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 386e157..9701f3c 100644 --- a/package.json +++ b/package.json @@ -8,14 +8,16 @@ }, "devDependencies": { "karma": "~0.10", - "karma-ng-html2js-preprocessor" : "0.1.0", + "karma-ng-html2js-preprocessor": "0.1.0", "grunt-contrib-uglify": "~v0.3.3", "grunt-contrib-coffee": "~0.10.1", "grunt-banner": "~0.2.1", "grunt-cli": "~0.1.8", - "grunt": "~0.4.1" + "grunt": "~0.4.1", + "bower": "^1.3.3" }, "scripts": { + "postinstall": "bower install", "test": "karma start --single-run --no-auto-watch" } } From 7cc00eb8fa8d2a2192d41cd764f55f4f6f3f94f1 Mon Sep 17 00:00:00 2001 From: Ben Holland Date: Fri, 2 May 2014 09:53:00 +0100 Subject: [PATCH 147/190] Bumped versions --- bower.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bower.json b/bower.json index e5b63e3..ffd817a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "at-table", - "version": "1.0.0", + "version": "1.0.1", "homepage": "https://github.com/samu/angular-table", "authors": [ "Samuel Mueller" diff --git a/package.json b/package.json index 9701f3c..59b9de8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-table", - "version": "1.0.0", + "version": "1.0.1", "author": "Samuel Mueller", "repository": { "type": "git", From a4e29b8ca9f5662319cf1eea37e59bd566b8aec0 Mon Sep 17 00:00:00 2001 From: Ben Holland Date: Fri, 2 May 2014 09:56:29 +0100 Subject: [PATCH 148/190] Changed bower version selector --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 59b9de8..1f4daa2 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "grunt-banner": "~0.2.1", "grunt-cli": "~0.1.8", "grunt": "~0.4.1", - "bower": "^1.3.3" + "bower": "~1.3.3" }, "scripts": { "postinstall": "bower install", From 3b7a17d9cdc3e6886a1c54dc9c2d428a01ae03f6 Mon Sep 17 00:00:00 2001 From: Ben Holland Date: Mon, 5 May 2014 09:37:23 +0100 Subject: [PATCH 149/190] Remove additional sort context watch --- coffee/directives/table/setup/paginated_setup.coffee | 4 ---- 1 file changed, 4 deletions(-) diff --git a/coffee/directives/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee index 0cc3d72..aa1299d 100644 --- a/coffee/directives/table/setup/paginated_setup.coffee +++ b/coffee/directives/table/setup/paginated_setup.coffee @@ -87,10 +87,6 @@ class PaginatedSetup extends Setup update() ) - $scope.$watch(cvn.sort_context, () -> - update() - ) - $scope.$watch($attributes.atList, () -> update() ) From eb18d87d136a7acb0fb5826b1ce6b256bb8acae7 Mon Sep 17 00:00:00 2001 From: lopix Date: Fri, 12 Sep 2014 16:37:01 +0100 Subject: [PATCH 150/190] Change the orderBy in config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometimes it’s needed to change the orderBy filter. --- coffee/configuration/configuration_variable_names.coffee | 1 + coffee/configuration/scope_config_wrapper.coffee | 3 +++ coffee/directives/table/setup/paginated_setup.coffee | 7 ++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/coffee/configuration/configuration_variable_names.coffee b/coffee/configuration/configuration_variable_names.coffee index 1f1d7d8..e7e09f9 100644 --- a/coffee/configuration/configuration_variable_names.coffee +++ b/coffee/configuration/configuration_variable_names.coffee @@ -5,3 +5,4 @@ class ConfigurationVariableNames @fill_last_page = "#{@config_object_name}.fillLastPage" @max_pages = "#{@config_object_name}.maxPages" @current_page = "#{@config_object_name}.currentPage" + @order_by = "#{@config_object_name}.orderBy" diff --git a/coffee/configuration/scope_config_wrapper.coffee b/coffee/configuration/scope_config_wrapper.coffee index fb19fcd..e499f50 100644 --- a/coffee/configuration/scope_config_wrapper.coffee +++ b/coffee/configuration/scope_config_wrapper.coffee @@ -18,3 +18,6 @@ class ScopeConfigWrapper set_current_page: (current_page) -> @scope.$eval("#{@configuration_variable_names.current_page}=#{current_page}") + + get_order_by: () -> + @scope.$eval(@configuration_variable_names.order_by) || 'orderBy' diff --git a/coffee/directives/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee index 3395a44..dc5457c 100644 --- a/coffee/directives/table/setup/paginated_setup.coffee +++ b/coffee/directives/table/setup/paginated_setup.coffee @@ -25,18 +25,18 @@ class PaginatedSetup extends Setup w = new ScopeConfigWrapper($scope, cvn, $attributes.atList) - get_sorted_and_paginated_list = (list, current_page, items_per_page, sort_context, predicate, descending, $filter) -> + get_sorted_and_paginated_list = (list, current_page, items_per_page, order_by, sort_context, predicate, descending, $filter) -> if list val = list from_page = items_per_page * current_page - list.length if sort_context == "global" - val = $filter("orderBy")(val, predicate, descending) + val = $filter(order_by)(val, predicate, descending) val = $filter("limitTo")(val, from_page) val = $filter("limitTo")(val, items_per_page) else val = $filter("limitTo")(val, from_page) val = $filter("limitTo")(val, items_per_page) - val = $filter("orderBy")(val, predicate, descending) + val = $filter(order_by)(val, predicate, descending) return val else @@ -60,6 +60,7 @@ class PaginatedSetup extends Setup w.get_list(), w.get_current_page(), w.get_items_per_page(), + w.get_order_by(), w.get_sort_context(), $scope.predicate, $scope.descending, From 09e3376eaf01c0125482a4a0673ff92537b18c17 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 20 Sep 2014 20:00:52 +0200 Subject: [PATCH 151/190] update dependencies and add plugins to karma file --- karma.conf.js | 7 +++++++ package.json | 15 +++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index b6f75ca..4ac3a81 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -48,6 +48,13 @@ module.exports = function(config) { ], + plugins: [ + 'karma-coffee-preprocessor', + 'karma-jasmine', + 'karma-phantomjs-launcher', + 'karma-ng-html2js-preprocessor' + ], + preprocessors: { 'coffee/**/**/*.coffee': ['coffee'], 'test/*.coffee': ['coffee'], diff --git a/package.json b/package.json index 1f4daa2..ad9997b 100644 --- a/package.json +++ b/package.json @@ -7,14 +7,17 @@ "url": "git://github.com/samu/angular-table.git" }, "devDependencies": { - "karma": "~0.10", - "karma-ng-html2js-preprocessor": "0.1.0", - "grunt-contrib-uglify": "~v0.3.3", - "grunt-contrib-coffee": "~0.10.1", + "bower": "~1.3.3", + "grunt": "~0.4.1", "grunt-banner": "~0.2.1", "grunt-cli": "~0.1.8", - "grunt": "~0.4.1", - "bower": "~1.3.3" + "grunt-contrib-coffee": "~0.10.1", + "grunt-contrib-uglify": "~v0.3.3", + "karma": "^0.12.23", + "karma-coffee-preprocessor": "^0.2.1", + "karma-jasmine": "^0.1.5", + "karma-ng-html2js-preprocessor": "0.1.0", + "karma-phantomjs-launcher": "^0.1.4" }, "scripts": { "postinstall": "bower install", From 8d21c739c21675abea6041e469621253d8699721 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 20 Sep 2014 20:05:40 +0200 Subject: [PATCH 152/190] bump node version for travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 122fda9..f473263 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,4 +4,4 @@ branches: language: node_js node_js: - - 0.8 \ No newline at end of file + - 0.10 From 72f03cee4ff3f16c98498150d1b2baebbb230b34 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 20 Sep 2014 20:22:53 +0200 Subject: [PATCH 153/190] remove dependency that might cause travis to fail --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index ad9997b..3439aff 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,7 @@ "karma": "^0.12.23", "karma-coffee-preprocessor": "^0.2.1", "karma-jasmine": "^0.1.5", - "karma-ng-html2js-preprocessor": "0.1.0", - "karma-phantomjs-launcher": "^0.1.4" + "karma-ng-html2js-preprocessor": "0.1.0" }, "scripts": { "postinstall": "bower install", From 22d8367ea97384fb4857ceda721f7189db72fb17 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 20 Sep 2014 20:27:11 +0200 Subject: [PATCH 154/190] try using a different npm version --- .travis.yml | 2 +- package.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f473263..e04778a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,4 +4,4 @@ branches: language: node_js node_js: - - 0.10 + - 0.9 diff --git a/package.json b/package.json index 3439aff..ad9997b 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "karma": "^0.12.23", "karma-coffee-preprocessor": "^0.2.1", "karma-jasmine": "^0.1.5", - "karma-ng-html2js-preprocessor": "0.1.0" + "karma-ng-html2js-preprocessor": "0.1.0", + "karma-phantomjs-launcher": "^0.1.4" }, "scripts": { "postinstall": "bower install", From 7edd2af6b6e0d34880965fa922d23e8484e0646d Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 20 Sep 2014 20:33:14 +0200 Subject: [PATCH 155/190] travis still not happy --- .travis.yml | 2 +- package.json | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index e04778a..f473263 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,4 +4,4 @@ branches: language: node_js node_js: - - 0.9 + - 0.10 diff --git a/package.json b/package.json index ad9997b..0a7fdae 100644 --- a/package.json +++ b/package.json @@ -14,10 +14,10 @@ "grunt-contrib-coffee": "~0.10.1", "grunt-contrib-uglify": "~v0.3.3", "karma": "^0.12.23", - "karma-coffee-preprocessor": "^0.2.1", - "karma-jasmine": "^0.1.5", + "karma-coffee-preprocessor": "0.2.1", + "karma-jasmine": "0.1.5", "karma-ng-html2js-preprocessor": "0.1.0", - "karma-phantomjs-launcher": "^0.1.4" + "karma-phantomjs-launcher": "0.1.4" }, "scripts": { "postinstall": "bower install", From e53901005b0bf2b582fa9f2f802ff4e58740bb60 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 20 Sep 2014 20:38:40 +0200 Subject: [PATCH 156/190] try a different test command --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0a7fdae..cf38f17 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,6 @@ }, "scripts": { "postinstall": "bower install", - "test": "karma start --single-run --no-auto-watch" + "test": "./node_modules/.bin/karma start --single-run --browsers PhantomJS" } } From 6f26a27db2ae18cc2ab19a59fdd9fc489ab70a33 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 20 Sep 2014 20:46:12 +0200 Subject: [PATCH 157/190] try config from recent doc --- .travis.yml | 5 ++++- package.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f473263..932a632 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,4 +4,7 @@ branches: language: node_js node_js: - - 0.10 + - "0.10" +before_script: + - export DISPLAY=:99.0 + - sh -e /etc/init.d/xvfb start diff --git a/package.json b/package.json index cf38f17..2b49bc8 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,6 @@ }, "scripts": { "postinstall": "bower install", - "test": "./node_modules/.bin/karma start --single-run --browsers PhantomJS" + "test": "karma start --browsers Firefox --single-run" } } From 918260c8c6c01838414ba4fe1c65fcf982118def Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 20 Sep 2014 21:09:36 +0200 Subject: [PATCH 158/190] fix travis --- .travis.yml | 4 +--- package.json | 12 ++++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 932a632..bf770cc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,8 @@ branches: only: - master + - fix_travis language: node_js node_js: - "0.10" -before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start diff --git a/package.json b/package.json index 2b49bc8..c055e3b 100644 --- a/package.json +++ b/package.json @@ -13,14 +13,14 @@ "grunt-cli": "~0.1.8", "grunt-contrib-coffee": "~0.10.1", "grunt-contrib-uglify": "~v0.3.3", - "karma": "^0.12.23", - "karma-coffee-preprocessor": "0.2.1", - "karma-jasmine": "0.1.5", - "karma-ng-html2js-preprocessor": "0.1.0", - "karma-phantomjs-launcher": "0.1.4" + "karma": "~0.12", + "karma-coffee-preprocessor": "^0.2.1", + "karma-jasmine": "^0.1.5", + "karma-ng-html2js-preprocessor": "^0.1.0", + "karma-phantomjs-launcher": "^0.1.4" }, "scripts": { "postinstall": "bower install", - "test": "karma start --browsers Firefox --single-run" + "test": "./node_modules/karma/bin/karma start --single-run --browsers PhantomJS" } } From 28bbf5cb6fefb79fb31db2cc7185ae3f4dfa7bf6 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 20 Sep 2014 21:10:56 +0200 Subject: [PATCH 159/190] build master only --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bf770cc..31d2639 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ branches: only: - master - - fix_travis language: node_js node_js: From 9b29136be3ac8e1e4c49958b71d22a41859ad0aa Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 20 Sep 2014 21:48:49 +0200 Subject: [PATCH 160/190] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c055e3b..21e35bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-table", - "version": "1.0.1", + "version": "1.0.2", "author": "Samuel Mueller", "repository": { "type": "git", From 60d64e329a8157426bd5eb3e9ba79e832009fd7e Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 21 Sep 2014 16:25:13 +0200 Subject: [PATCH 161/190] recompiled --- dist/angular-table.js | 3 --- dist/angular-table.min.js | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/dist/angular-table.js b/dist/angular-table.js index 9b0785d..1149268 100644 --- a/dist/angular-table.js +++ b/dist/angular-table.js @@ -347,9 +347,6 @@ $scope.$watch(cvn.sort_context, function() { return update(); }); - $scope.$watch(cvn.sort_context, function() { - return update(); - }); $scope.$watch($attributes.atList, function() { return update(); }); diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js index 538a481..07c30b1 100644 --- a/dist/angular-table.min.js +++ b/dist/angular-table.min.js @@ -2,4 +2,4 @@ // version: 1.0.0 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var a,b,c,d,e,f,g,h,i,j,k,l={}.hasOwnProperty,m=function(a,b){function c(){this.constructor=a}for(var d in b)l.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),j="number_of_pages",a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.custom_content=b.custom_content,this.attributes=b.attributes)}return a.prototype.create_element=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.render_title=function(a){return a.html(this.custom_content||this.title)},a.prototype.render_attributes=function(a){var b,c,d,e,f;if(this.custom_content){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.render_sorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.render_width=function(a){return a.attr("width",this.width)},a.prototype.render_html=function(){var a;return a=this.create_element(),this.render_title(a),this.render_attributes(a),this.render_sorting(a),this.render_width(a),a},a}(),b=function(){function a(a){this.config_object_name=a,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return a}(),e=function(){function a(a,b,c){this.scope=a,this.configuration_variable_names=b,this.list_name=c}return a.prototype.get_list=function(){return this.scope.$eval(this.list_name)},a.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},a.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},a.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},a.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},a.prototype.set_current_page=function(a){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+a)},a}(),i=function(){function b(a,b){this.table_element=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collect_header_markup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={custom_content:c.html(),attributes:c[0].attributes};return b},b.prototype.collect_body_markup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.create_column_configurations=function(){var b,c,d,e,f;for(c=this.collect_header_markup(this.table_element),b=this.collect_body_markup(this.table_element),this.column_configurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.column_configurations.push(new a(d,c[d.attribute]));return this.column_configurations},b}(),f=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),g=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return m(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(f),d=function(a){function b(a){this.configuration_variable_names=a,this.repeatString="item in sorted_and_paginated_list"}return m(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configuration_variable_names.fill_last_page),b.html(e),b.attr("ng-repeat","item in filler_array"),c.append(b)},b.prototype.link=function(a,b,c,d){var f,g,h,i,k;return f=this.configuration_variable_names,k=new e(a,f,c.atList),h=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sorted_and_paginated_list=h(k.get_list(),k.get_current_page(),k.get_items_per_page(),k.get_sort_context(),a.predicate,a.descending,d),b=Math.ceil(k.get_list().length/k.get_items_per_page()),a.filler_array=g(k.get_list(),k.get_current_page(),b,k.get_items_per_page())},a.$watch(f.current_page,function(){return i()}),a.$watch(f.items_per_page,function(){return i()}),a.$watch(f.sort_context,function(){return i()}),a.$watch(f.sort_context,function(){return i()}),a.$watch(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a[j]=Math.ceil(k.get_list().length/k.get_items_per_page()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(f),h=function(){function a(a,b,c){this.element=a,this.table_configuration=b,this.configuration_variable_names=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.table_configuration.column_configurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.render_html());return b},a.prototype.setup_header=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.get_setup=function(){return this.table_configuration.paginated?new d(this.configuration_variable_names):new g(this.configuration_variable_names,this.table_configuration.list)},a.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},a.prototype.setup_initial_sorting=function(a){var b,c,d,e,f;for(e=this.table_configuration.column_configurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setup_initial_sorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),c=function(){function a(a,b,c,d){if(this.lower_bound=null!=a?a:0,this.upper_bound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upper_bound-this.length?a=this.upper_bound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.reset_parameters=function(a,b,c){if(this.lower_bound=a,this.upper_bound=b,this.length=c,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realign_greedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realign_generous=function(){},a}(),k="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(c,d){var e,f,g;return g=new i(c,d),e=new b(d.atConfig),f=new h(c,g,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:k,link:function(a,d,f){var g,h,i,k,l,m;return g=new b(f.atConfig),m=new e(a,g,f.atList),i=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},h=function(){return a[j]},k=function(b){return a[j]=b},l=function(){var b,c;return m.get_list()?m.get_list().length>0?(b=Math.ceil(m.get_list().length/m.get_items_per_page()),k(b),c=a.show_sectioning()?m.get_max_pages():b,a.page_sequence.reset_parameters(0,b,c),m.set_current_page(i(m.get_current_page(),0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())):(k(1),a.page_sequence.reset_parameters(0,1,1),m.set_current_page(0),a.page_sequence.realign_greedy(0)):void 0},a.show_sectioning=function(){return m.get_max_pages()&&h()>m.get_max_pages()},a.get_current_page=function(){return m.get_current_page()},a.step_page=function(b){return b=parseInt(b),m.set_current_page(i(m.get_current_page()+b,0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())},a.go_to_page=function(a){return m.set_current_page(a)},a.jump_back=function(){return a.step_page(-m.get_max_pages())},a.jump_ahead=function(){return a.step_page(m.get_max_pages())},a.page_sequence=new c,a.$watch(g.items_per_page,function(){return l()}),a.$watch(g.max_pages,function(){return l()}),a.$watch(f.atList,function(){return l()}),a.$watch(""+f.atList+".length",function(){return l()}),l()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var a,b,c,d,e,f,g,h,i,j,k,l={}.hasOwnProperty,m=function(a,b){function c(){this.constructor=a}for(var d in b)l.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),j="number_of_pages",a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.custom_content=b.custom_content,this.attributes=b.attributes)}return a.prototype.create_element=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.render_title=function(a){return a.html(this.custom_content||this.title)},a.prototype.render_attributes=function(a){var b,c,d,e,f;if(this.custom_content){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.render_sorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.render_width=function(a){return a.attr("width",this.width)},a.prototype.render_html=function(){var a;return a=this.create_element(),this.render_title(a),this.render_attributes(a),this.render_sorting(a),this.render_width(a),a},a}(),b=function(){function a(a){this.config_object_name=a,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return a}(),e=function(){function a(a,b,c){this.scope=a,this.configuration_variable_names=b,this.list_name=c}return a.prototype.get_list=function(){return this.scope.$eval(this.list_name)},a.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},a.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},a.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},a.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},a.prototype.set_current_page=function(a){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+a)},a}(),i=function(){function b(a,b){this.table_element=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collect_header_markup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={custom_content:c.html(),attributes:c[0].attributes};return b},b.prototype.collect_body_markup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.create_column_configurations=function(){var b,c,d,e,f;for(c=this.collect_header_markup(this.table_element),b=this.collect_body_markup(this.table_element),this.column_configurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.column_configurations.push(new a(d,c[d.attribute]));return this.column_configurations},b}(),f=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),g=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return m(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(f),d=function(a){function b(a){this.configuration_variable_names=a,this.repeatString="item in sorted_and_paginated_list"}return m(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configuration_variable_names.fill_last_page),b.html(e),b.attr("ng-repeat","item in filler_array"),c.append(b)},b.prototype.link=function(a,b,c,d){var f,g,h,i,k;return f=this.configuration_variable_names,k=new e(a,f,c.atList),h=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sorted_and_paginated_list=h(k.get_list(),k.get_current_page(),k.get_items_per_page(),k.get_sort_context(),a.predicate,a.descending,d),b=Math.ceil(k.get_list().length/k.get_items_per_page()),a.filler_array=g(k.get_list(),k.get_current_page(),b,k.get_items_per_page())},a.$watch(f.current_page,function(){return i()}),a.$watch(f.items_per_page,function(){return i()}),a.$watch(f.sort_context,function(){return i()}),a.$watch(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a[j]=Math.ceil(k.get_list().length/k.get_items_per_page()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(f),h=function(){function a(a,b,c){this.element=a,this.table_configuration=b,this.configuration_variable_names=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.table_configuration.column_configurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.render_html());return b},a.prototype.setup_header=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.get_setup=function(){return this.table_configuration.paginated?new d(this.configuration_variable_names):new g(this.configuration_variable_names,this.table_configuration.list)},a.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},a.prototype.setup_initial_sorting=function(a){var b,c,d,e,f;for(e=this.table_configuration.column_configurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setup_initial_sorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),c=function(){function a(a,b,c,d){if(this.lower_bound=null!=a?a:0,this.upper_bound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upper_bound-this.length?a=this.upper_bound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.reset_parameters=function(a,b,c){if(this.lower_bound=a,this.upper_bound=b,this.length=c,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realign_greedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realign_generous=function(){},a}(),k="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(c,d){var e,f,g;return g=new i(c,d),e=new b(d.atConfig),f=new h(c,g,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:k,link:function(a,d,f){var g,h,i,k,l,m;return g=new b(f.atConfig),m=new e(a,g,f.atList),i=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},h=function(){return a[j]},k=function(b){return a[j]=b},l=function(){var b,c;return m.get_list()?m.get_list().length>0?(b=Math.ceil(m.get_list().length/m.get_items_per_page()),k(b),c=a.show_sectioning()?m.get_max_pages():b,a.page_sequence.reset_parameters(0,b,c),m.set_current_page(i(m.get_current_page(),0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())):(k(1),a.page_sequence.reset_parameters(0,1,1),m.set_current_page(0),a.page_sequence.realign_greedy(0)):void 0},a.show_sectioning=function(){return m.get_max_pages()&&h()>m.get_max_pages()},a.get_current_page=function(){return m.get_current_page()},a.step_page=function(b){return b=parseInt(b),m.set_current_page(i(m.get_current_page()+b,0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())},a.go_to_page=function(a){return m.set_current_page(a)},a.jump_back=function(){return a.step_page(-m.get_max_pages())},a.jump_ahead=function(){return a.step_page(m.get_max_pages())},a.page_sequence=new c,a.$watch(g.items_per_page,function(){return l()}),a.$watch(g.max_pages,function(){return l()}),a.$watch(f.atList,function(){return l()}),a.$watch(""+f.atList+".length",function(){return l()}),l()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}).call(this); \ No newline at end of file From 29e2fa921a9bbdd23bab697712abf2006016faa0 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 21 Sep 2014 17:18:26 +0200 Subject: [PATCH 162/190] use watchCollection and implement tests --- .../directives/table/setup/paginated_setup.coffee | 2 +- test/paginated_setup.coffee | 11 ++++++++++- test/standard_setup.coffee | 13 +++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/coffee/directives/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee index aa1299d..b706dd4 100644 --- a/coffee/directives/table/setup/paginated_setup.coffee +++ b/coffee/directives/table/setup/paginated_setup.coffee @@ -87,7 +87,7 @@ class PaginatedSetup extends Setup update() ) - $scope.$watch($attributes.atList, () -> + $scope.$watchCollection($attributes.atList, () -> update() ) diff --git a/test/paginated_setup.coffee b/test/paginated_setup.coffee index c26af79..4c9cabb 100644 --- a/test/paginated_setup.coffee +++ b/test/paginated_setup.coffee @@ -194,6 +194,15 @@ describe "angular-table", () -> expect(@gui.pagination.pages).toEqual [1] expect(@gui.pagination.current_page).toEqual 1 + it "reloads the table if the entries change but the length doesn't", () -> + expect(@gui.table.rows).toEqual([['a'], ['b'], ['c']]) + @gui.alter_scope((scope_wrapper, vars) -> + list = scope_wrapper.get(list_name) + list.splice(6, 1) # delete the 6th element in the list which is "a" + list.push({name: "A"}) + ) + expect(@gui.table.rows).toEqual([['A'], ['b'], ['c']]) + describe "the maximum pages setting", () -> for val in [undefined, null] it "shows all pages if max_pages is undefined or null", () -> @@ -374,4 +383,4 @@ describe "angular-table", () -> expect(@gui.table.rows).toEqual([['m'], [' '], [' '], [' '], [' '], [' ']]) expect(@gui.pagination.current_page).toEqual(3) - expect(@gui.pagination.pages).toEqual([1, 2, 3]) \ No newline at end of file + expect(@gui.pagination.pages).toEqual([1, 2, 3]) diff --git a/test/standard_setup.coffee b/test/standard_setup.coffee index a2a0aa9..5c81707 100644 --- a/test/standard_setup.coffee +++ b/test/standard_setup.coffee @@ -4,7 +4,8 @@ describe "angular-table", () -> expected_rows = [ ["0", "Helsinki", "Finland"], ["1", "Zurich", "Switzerland"], - ["2", "Amsterdam", "Netherlands"] + ["2", "Amsterdam", "Netherlands"], + ["3", "Berlin", "Germany"] ] beforeEach(() -> @@ -37,4 +38,12 @@ describe "angular-table", () -> it "leaves columns unsortable if at-sortable is not declared", () -> @gui.table.sort(2) - expect(@gui.table.rows).toEqual [expected_rows[1], expected_rows[0], expected_rows[2]] \ No newline at end of file + expect(@gui.table.rows).toEqual [expected_rows[1], expected_rows[0], expected_rows[2]] + + it "reloads the table if the entries change but the length doesn't", () -> + @gui.alter_scope((scope_wrapper, vars) -> + cities = scope_wrapper.get("cities") + cities.pop() + cities.push({id: 3, name: "Berlin", country: "Germany"}) + ) + expect(@gui.table.rows).toEqual [expected_rows[1], expected_rows[0], expected_rows[3]] From d13ae767e9afdacebfef76b223fd41047750f576 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 21 Sep 2014 17:23:20 +0200 Subject: [PATCH 163/190] recompile --- dist/angular-table.js | 2 +- dist/angular-table.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/angular-table.js b/dist/angular-table.js index 1149268..0fa3a5f 100644 --- a/dist/angular-table.js +++ b/dist/angular-table.js @@ -347,7 +347,7 @@ $scope.$watch(cvn.sort_context, function() { return update(); }); - $scope.$watch($attributes.atList, function() { + $scope.$watchCollection($attributes.atList, function() { return update(); }); $scope.$watch("" + $attributes.atList + ".length", function() { diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js index 07c30b1..b1cb68a 100644 --- a/dist/angular-table.min.js +++ b/dist/angular-table.min.js @@ -2,4 +2,4 @@ // version: 1.0.0 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var a,b,c,d,e,f,g,h,i,j,k,l={}.hasOwnProperty,m=function(a,b){function c(){this.constructor=a}for(var d in b)l.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),j="number_of_pages",a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.custom_content=b.custom_content,this.attributes=b.attributes)}return a.prototype.create_element=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.render_title=function(a){return a.html(this.custom_content||this.title)},a.prototype.render_attributes=function(a){var b,c,d,e,f;if(this.custom_content){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.render_sorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.render_width=function(a){return a.attr("width",this.width)},a.prototype.render_html=function(){var a;return a=this.create_element(),this.render_title(a),this.render_attributes(a),this.render_sorting(a),this.render_width(a),a},a}(),b=function(){function a(a){this.config_object_name=a,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return a}(),e=function(){function a(a,b,c){this.scope=a,this.configuration_variable_names=b,this.list_name=c}return a.prototype.get_list=function(){return this.scope.$eval(this.list_name)},a.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},a.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},a.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},a.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},a.prototype.set_current_page=function(a){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+a)},a}(),i=function(){function b(a,b){this.table_element=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collect_header_markup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={custom_content:c.html(),attributes:c[0].attributes};return b},b.prototype.collect_body_markup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.create_column_configurations=function(){var b,c,d,e,f;for(c=this.collect_header_markup(this.table_element),b=this.collect_body_markup(this.table_element),this.column_configurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.column_configurations.push(new a(d,c[d.attribute]));return this.column_configurations},b}(),f=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),g=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return m(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(f),d=function(a){function b(a){this.configuration_variable_names=a,this.repeatString="item in sorted_and_paginated_list"}return m(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configuration_variable_names.fill_last_page),b.html(e),b.attr("ng-repeat","item in filler_array"),c.append(b)},b.prototype.link=function(a,b,c,d){var f,g,h,i,k;return f=this.configuration_variable_names,k=new e(a,f,c.atList),h=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sorted_and_paginated_list=h(k.get_list(),k.get_current_page(),k.get_items_per_page(),k.get_sort_context(),a.predicate,a.descending,d),b=Math.ceil(k.get_list().length/k.get_items_per_page()),a.filler_array=g(k.get_list(),k.get_current_page(),b,k.get_items_per_page())},a.$watch(f.current_page,function(){return i()}),a.$watch(f.items_per_page,function(){return i()}),a.$watch(f.sort_context,function(){return i()}),a.$watch(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a[j]=Math.ceil(k.get_list().length/k.get_items_per_page()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(f),h=function(){function a(a,b,c){this.element=a,this.table_configuration=b,this.configuration_variable_names=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.table_configuration.column_configurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.render_html());return b},a.prototype.setup_header=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.get_setup=function(){return this.table_configuration.paginated?new d(this.configuration_variable_names):new g(this.configuration_variable_names,this.table_configuration.list)},a.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},a.prototype.setup_initial_sorting=function(a){var b,c,d,e,f;for(e=this.table_configuration.column_configurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setup_initial_sorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),c=function(){function a(a,b,c,d){if(this.lower_bound=null!=a?a:0,this.upper_bound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upper_bound-this.length?a=this.upper_bound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.reset_parameters=function(a,b,c){if(this.lower_bound=a,this.upper_bound=b,this.length=c,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realign_greedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realign_generous=function(){},a}(),k="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(c,d){var e,f,g;return g=new i(c,d),e=new b(d.atConfig),f=new h(c,g,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:k,link:function(a,d,f){var g,h,i,k,l,m;return g=new b(f.atConfig),m=new e(a,g,f.atList),i=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},h=function(){return a[j]},k=function(b){return a[j]=b},l=function(){var b,c;return m.get_list()?m.get_list().length>0?(b=Math.ceil(m.get_list().length/m.get_items_per_page()),k(b),c=a.show_sectioning()?m.get_max_pages():b,a.page_sequence.reset_parameters(0,b,c),m.set_current_page(i(m.get_current_page(),0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())):(k(1),a.page_sequence.reset_parameters(0,1,1),m.set_current_page(0),a.page_sequence.realign_greedy(0)):void 0},a.show_sectioning=function(){return m.get_max_pages()&&h()>m.get_max_pages()},a.get_current_page=function(){return m.get_current_page()},a.step_page=function(b){return b=parseInt(b),m.set_current_page(i(m.get_current_page()+b,0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())},a.go_to_page=function(a){return m.set_current_page(a)},a.jump_back=function(){return a.step_page(-m.get_max_pages())},a.jump_ahead=function(){return a.step_page(m.get_max_pages())},a.page_sequence=new c,a.$watch(g.items_per_page,function(){return l()}),a.$watch(g.max_pages,function(){return l()}),a.$watch(f.atList,function(){return l()}),a.$watch(""+f.atList+".length",function(){return l()}),l()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var a,b,c,d,e,f,g,h,i,j,k,l={}.hasOwnProperty,m=function(a,b){function c(){this.constructor=a}for(var d in b)l.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),j="number_of_pages",a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.custom_content=b.custom_content,this.attributes=b.attributes)}return a.prototype.create_element=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.render_title=function(a){return a.html(this.custom_content||this.title)},a.prototype.render_attributes=function(a){var b,c,d,e,f;if(this.custom_content){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.render_sorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.render_width=function(a){return a.attr("width",this.width)},a.prototype.render_html=function(){var a;return a=this.create_element(),this.render_title(a),this.render_attributes(a),this.render_sorting(a),this.render_width(a),a},a}(),b=function(){function a(a){this.config_object_name=a,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return a}(),e=function(){function a(a,b,c){this.scope=a,this.configuration_variable_names=b,this.list_name=c}return a.prototype.get_list=function(){return this.scope.$eval(this.list_name)},a.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},a.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},a.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},a.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},a.prototype.set_current_page=function(a){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+a)},a}(),i=function(){function b(a,b){this.table_element=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collect_header_markup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={custom_content:c.html(),attributes:c[0].attributes};return b},b.prototype.collect_body_markup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.create_column_configurations=function(){var b,c,d,e,f;for(c=this.collect_header_markup(this.table_element),b=this.collect_body_markup(this.table_element),this.column_configurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.column_configurations.push(new a(d,c[d.attribute]));return this.column_configurations},b}(),f=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),g=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return m(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(f),d=function(a){function b(a){this.configuration_variable_names=a,this.repeatString="item in sorted_and_paginated_list"}return m(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configuration_variable_names.fill_last_page),b.html(e),b.attr("ng-repeat","item in filler_array"),c.append(b)},b.prototype.link=function(a,b,c,d){var f,g,h,i,k;return f=this.configuration_variable_names,k=new e(a,f,c.atList),h=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sorted_and_paginated_list=h(k.get_list(),k.get_current_page(),k.get_items_per_page(),k.get_sort_context(),a.predicate,a.descending,d),b=Math.ceil(k.get_list().length/k.get_items_per_page()),a.filler_array=g(k.get_list(),k.get_current_page(),b,k.get_items_per_page())},a.$watch(f.current_page,function(){return i()}),a.$watch(f.items_per_page,function(){return i()}),a.$watch(f.sort_context,function(){return i()}),a.$watchCollection(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a[j]=Math.ceil(k.get_list().length/k.get_items_per_page()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(f),h=function(){function a(a,b,c){this.element=a,this.table_configuration=b,this.configuration_variable_names=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.table_configuration.column_configurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.render_html());return b},a.prototype.setup_header=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.get_setup=function(){return this.table_configuration.paginated?new d(this.configuration_variable_names):new g(this.configuration_variable_names,this.table_configuration.list)},a.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},a.prototype.setup_initial_sorting=function(a){var b,c,d,e,f;for(e=this.table_configuration.column_configurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setup_initial_sorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),c=function(){function a(a,b,c,d){if(this.lower_bound=null!=a?a:0,this.upper_bound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upper_bound-this.length?a=this.upper_bound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.reset_parameters=function(a,b,c){if(this.lower_bound=a,this.upper_bound=b,this.length=c,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realign_greedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realign_generous=function(){},a}(),k="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(c,d){var e,f,g;return g=new i(c,d),e=new b(d.atConfig),f=new h(c,g,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:k,link:function(a,d,f){var g,h,i,k,l,m;return g=new b(f.atConfig),m=new e(a,g,f.atList),i=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},h=function(){return a[j]},k=function(b){return a[j]=b},l=function(){var b,c;return m.get_list()?m.get_list().length>0?(b=Math.ceil(m.get_list().length/m.get_items_per_page()),k(b),c=a.show_sectioning()?m.get_max_pages():b,a.page_sequence.reset_parameters(0,b,c),m.set_current_page(i(m.get_current_page(),0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())):(k(1),a.page_sequence.reset_parameters(0,1,1),m.set_current_page(0),a.page_sequence.realign_greedy(0)):void 0},a.show_sectioning=function(){return m.get_max_pages()&&h()>m.get_max_pages()},a.get_current_page=function(){return m.get_current_page()},a.step_page=function(b){return b=parseInt(b),m.set_current_page(i(m.get_current_page()+b,0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())},a.go_to_page=function(a){return m.set_current_page(a)},a.jump_back=function(){return a.step_page(-m.get_max_pages())},a.jump_ahead=function(){return a.step_page(m.get_max_pages())},a.page_sequence=new c,a.$watch(g.items_per_page,function(){return l()}),a.$watch(g.max_pages,function(){return l()}),a.$watch(f.atList,function(){return l()}),a.$watch(""+f.atList+".length",function(){return l()}),l()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}).call(this); \ No newline at end of file From 8b23098a85af6d0063d8a904f6cdd22744ca3e0c Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 21 Sep 2014 17:24:18 +0200 Subject: [PATCH 164/190] bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 21e35bd..052e92c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-table", - "version": "1.0.2", + "version": "1.0.3", "author": "Samuel Mueller", "repository": { "type": "git", From c3b0ae602278d50839c047150cd776f138c96a2e Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 21 Sep 2014 17:32:58 +0200 Subject: [PATCH 165/190] :lipstick: --- coffee/directives/at_pagination.coffee | 10 ++++---- .../pagination/page_sequence.coffee | 24 +++++++++---------- test/page_sequence.coffee | 18 +++++++------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/coffee/directives/at_pagination.coffee b/coffee/directives/at_pagination.coffee index 7b73be7..58ef2a0 100644 --- a/coffee/directives/at_pagination.coffee +++ b/coffee/directives/at_pagination.coffee @@ -28,15 +28,15 @@ angular.module("angular-table").directive "atPagination", [() -> else pages_to_display = new_number_of_pages - $scope.page_sequence.reset_parameters(0, new_number_of_pages, pages_to_display) + $scope.page_sequence.resetParameters(0, new_number_of_pages, pages_to_display) # TODO warum ist die reihenfolge der folgenden beiden aufrufe irrelevant? w.set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)) - $scope.page_sequence.realign_greedy(w.get_current_page()) + $scope.page_sequence.realignGreedy(w.get_current_page()) else set_number_of_pages(1) - $scope.page_sequence.reset_parameters(0, 1, 1) + $scope.page_sequence.resetParameters(0, 1, 1) w.set_current_page(0) - $scope.page_sequence.realign_greedy(0) + $scope.page_sequence.realignGreedy(0) $scope.show_sectioning = () -> w.get_max_pages() && get_number_of_pages() > w.get_max_pages() @@ -47,7 +47,7 @@ angular.module("angular-table").directive "atPagination", [() -> $scope.step_page = (step) -> step = parseInt(step) w.set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)) - $scope.page_sequence.realign_greedy(w.get_current_page()) + $scope.page_sequence.realignGreedy(w.get_current_page()) $scope.go_to_page = (page) -> w.set_current_page(page) diff --git a/coffee/directives/pagination/page_sequence.coffee b/coffee/directives/pagination/page_sequence.coffee index 264986a..7ba61d7 100644 --- a/coffee/directives/pagination/page_sequence.coffee +++ b/coffee/directives/pagination/page_sequence.coffee @@ -1,27 +1,27 @@ class PageSequence - constructor: (@lower_bound = 0, @upper_bound = 1, start = 0, @length = 1) -> - throw "sequence is too long" if @length > (@upper_bound - @lower_bound) + constructor: (@lowerBound = 0, @upperBound = 1, start = 0, @length = 1) -> + throw "sequence is too long" if @length > (@upperBound - @lowerBound) @data = @generate(start) generate: (start) -> - if start > (@upper_bound - @length) - start = @upper_bound - @length - else if start < @lower_bound - start = @lower_bound + if start > (@upperBound - @length) + start = @upperBound - @length + else if start < @lowerBound + start = @lowerBound x for x in [start..(parseInt(start) + parseInt(@length) - 1)] - reset_parameters: (lower_bound, upper_bound, length) -> - @lower_bound = lower_bound - @upper_bound = upper_bound + resetParameters: (lowerBound, upperBound, length) -> + @lowerBound = lowerBound + @upperBound = upperBound @length = length - throw "sequence is too long" if @length > (@upper_bound - @lower_bound) + throw "sequence is too long" if @length > (@upperBound - @lowerBound) @data = @generate(@data[0]) relocate: (distance) -> new_start = @data[0] + distance @data = @generate(new_start, new_start + @length) - realign_greedy: (page) -> + realignGreedy: (page) -> if page < @data[0] new_start = page @data = @generate(new_start) @@ -29,4 +29,4 @@ class PageSequence new_start = page - (@length - 1) @data = @generate(new_start) - realign_generous: (page) -> + realignGenerous: (page) -> diff --git a/test/page_sequence.coffee b/test/page_sequence.coffee index 94bf235..ece4708 100644 --- a/test/page_sequence.coffee +++ b/test/page_sequence.coffee @@ -17,7 +17,7 @@ describe "angular-table", () -> sequence = new PageSequence(0, 10, 4, 3) expect(sequence.data).toEqual [4, 5, 6] - sequence.reset_parameters(0, 6, 3) + sequence.resetParameters(0, 6, 3) expect(sequence.data).toEqual [3, 4, 5] it "relocates by a given distance and wont underrun or exceed a given boundary", () -> @@ -38,28 +38,28 @@ describe "angular-table", () -> sequence = new PageSequence(0, 7, 2, 3) expect(sequence.data).toEqual [2, 3, 4] - sequence.realign_greedy(2) + sequence.realignGreedy(2) expect(sequence.data).toEqual [2, 3, 4] - sequence.realign_greedy(4) + sequence.realignGreedy(4) expect(sequence.data).toEqual [2, 3, 4] it "realigns greedy", () -> sequence = new PageSequence(0, 7, 2, 3) expect(sequence.data).toEqual [2, 3, 4] - sequence.realign_greedy(6) + sequence.realignGreedy(6) expect(sequence.data).toEqual [4, 5, 6] - # expect(() -> sequence.realign_greedy(7)).toThrow() + # expect(() -> sequence.realignGreedy(7)).toThrow() - sequence.realign_greedy(4) + sequence.realignGreedy(4) expect(sequence.data).toEqual [4, 5, 6] - sequence.realign_greedy(1) + sequence.realignGreedy(1) expect(sequence.data).toEqual [1, 2, 3] - sequence.realign_greedy(0) + sequence.realignGreedy(0) expect(sequence.data).toEqual [0, 1, 2] - # expect(() -> sequence.realign_greedy(-1)).toThrow() + # expect(() -> sequence.realignGreedy(-1)).toThrow() From 9961ddaaf67076829fdae14cf72c53a717c23c22 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 21 Sep 2014 17:48:33 +0200 Subject: [PATCH 166/190] :lipstick: --- coffee/angular_table.coffee | 2 +- .../configuration/column_configuration.coffee | 45 ++++++++--------- .../configuration_variable_names.coffee | 14 +++--- .../configuration/scope_config_wrapper.coffee | 22 ++++----- .../configuration/table_configuration.coffee | 2 +- coffee/directives/at_pagination.coffee | 46 +++++++++--------- coffee/directives/at_table.coffee | 2 +- .../pagination/pagination_template.coffee | 20 ++++---- .../table/setup/paginated_setup.coffee | 48 +++++++++---------- coffee/directives/table/table.coffee | 2 +- 10 files changed, 102 insertions(+), 101 deletions(-) diff --git a/coffee/angular_table.coffee b/coffee/angular_table.coffee index d45a0ab..9b270e0 100644 --- a/coffee/angular_table.coffee +++ b/coffee/angular_table.coffee @@ -1,3 +1,3 @@ angular.module "angular-table", [] -irk_number_of_pages = "number_of_pages" +irkNumberOfPages = "number_of_pages" diff --git a/coffee/configuration/column_configuration.coffee b/coffee/configuration/column_configuration.coffee index 44dc702..502e56d 100644 --- a/coffee/configuration/column_configuration.coffee +++ b/coffee/configuration/column_configuration.coffee @@ -1,40 +1,41 @@ class ColumnConfiguration - constructor: (body_markup, header_markup) -> - @attribute = body_markup.attribute - @title = body_markup.title - @sortable = body_markup.sortable - @width = body_markup.width - @initialSorting = body_markup.initialSorting + constructor: (bodyMarkup, headerMarkup) -> + @attribute = bodyMarkup.attribute + @title = bodyMarkup.title + @sortable = bodyMarkup.sortable + @width = bodyMarkup.width + @initialSorting = bodyMarkup.initialSorting - if header_markup - @custom_content = header_markup.custom_content - @attributes = header_markup.attributes + # TODO untested + if headerMarkup + @customContent = headerMarkup.customContent + @attributes = headerMarkup.attributes - create_element: () -> + createElement: () -> th = angular.element(document.createElement("th")) - render_title: (element) -> - element.html(@custom_content || @title) + renderTitle: (element) -> + element.html(@customContent || @title) - render_attributes: (element) -> - if @custom_content + renderAttributes: (element) -> + if @customContent for attribute in @attributes element.attr(attribute.name, attribute.value) - render_sorting: (element) -> + renderSorting: (element) -> if @sortable element.attr("ng-click", "predicate = '#{@attribute}'; descending = !descending;") icon = angular.element("") icon.attr("ng-class", "getSortIcon('#{@attribute}', predicate)") element.append(icon) - render_width: (element) -> + renderWidth: (element) -> element.attr("width", @width) - render_html: () -> - th = @create_element() - @render_title(th) - @render_attributes(th) - @render_sorting(th) - @render_width(th) + renderHtml: () -> + th = @createElement() + @renderTitle(th) + @renderAttributes(th) + @renderSorting(th) + @renderWidth(th) return th diff --git a/coffee/configuration/configuration_variable_names.coffee b/coffee/configuration/configuration_variable_names.coffee index 1f1d7d8..b69c1a5 100644 --- a/coffee/configuration/configuration_variable_names.coffee +++ b/coffee/configuration/configuration_variable_names.coffee @@ -1,7 +1,7 @@ -class ConfigurationVariableNames - constructor: (@config_object_name) -> - @items_per_page = "#{@config_object_name}.itemsPerPage" - @sort_context = "#{@config_object_name}.sortContext" - @fill_last_page = "#{@config_object_name}.fillLastPage" - @max_pages = "#{@config_object_name}.maxPages" - @current_page = "#{@config_object_name}.currentPage" +class configuration_variable_names + constructor: (@configObjectName) -> + @itemsPerPage = "#{@configObjectName}.itemsPerPage" + @sortContext = "#{@configObjectName}.sortContext" + @fillLastPage = "#{@configObjectName}.fillLastPage" + @maxPages = "#{@configObjectName}.maxPages" + @currentPage = "#{@configObjectName}.currentPage" diff --git a/coffee/configuration/scope_config_wrapper.coffee b/coffee/configuration/scope_config_wrapper.coffee index fb19fcd..2c02510 100644 --- a/coffee/configuration/scope_config_wrapper.coffee +++ b/coffee/configuration/scope_config_wrapper.coffee @@ -1,20 +1,20 @@ class ScopeConfigWrapper constructor: (@scope, @configuration_variable_names, @list_name) -> - get_list: () -> + getList: () -> @scope.$eval(@list_name) - get_items_per_page: () -> - @scope.$eval(@configuration_variable_names.items_per_page) || 10 + getItemsPerPage: () -> + @scope.$eval(@configuration_variable_names.itemsPerPage) || 10 - get_current_page: () -> - @scope.$eval(@configuration_variable_names.current_page) || 0 + getCurrentPage: () -> + @scope.$eval(@configuration_variable_names.currentPage) || 0 - get_max_pages: () -> - @scope.$eval(@configuration_variable_names.max_pages) || undefined + getMaxPages: () -> + @scope.$eval(@configuration_variable_names.maxPages) || undefined - get_sort_context: () -> - @scope.$eval(@configuration_variable_names.sort_context) || 'global' + getSortContext: () -> + @scope.$eval(@configuration_variable_names.sortContext) || 'global' - set_current_page: (current_page) -> - @scope.$eval("#{@configuration_variable_names.current_page}=#{current_page}") + setCurrentPage: (currentPage) -> + @scope.$eval("#{@configuration_variable_names.currentPage}=#{currentPage}") diff --git a/coffee/configuration/table_configuration.coffee b/coffee/configuration/table_configuration.coffee index b511dda..3315b53 100644 --- a/coffee/configuration/table_configuration.coffee +++ b/coffee/configuration/table_configuration.coffee @@ -31,7 +31,7 @@ class TableConfiguration for th in tr.find("th") th = angular.element(th) customHeaderMarkups[th.attr("at-attribute")] = { - custom_content: th.html(), attributes: th[0].attributes + customContent: th.html(), attributes: th[0].attributes } return customHeaderMarkups diff --git a/coffee/directives/at_pagination.coffee b/coffee/directives/at_pagination.coffee index 58ef2a0..088a185 100644 --- a/coffee/directives/at_pagination.coffee +++ b/coffee/directives/at_pagination.coffee @@ -2,10 +2,10 @@ angular.module("angular-table").directive "atPagination", [() -> restrict: "E" scope: true replace: true - template: pagination_template + template: paginationTemplate link: ($scope, $element, $attributes) -> - cvn = new ConfigurationVariableNames($attributes.atConfig) + cvn = new configuration_variable_names($attributes.atConfig) w = new ScopeConfigWrapper($scope, cvn, $attributes.atList) keep_in_bounds = (val, min, max) -> @@ -13,57 +13,57 @@ angular.module("angular-table").directive "atPagination", [() -> Math.min(max, val) get_number_of_pages = () -> - $scope[irk_number_of_pages] + $scope[irkNumberOfPages] set_number_of_pages = (number_of_pages) -> - $scope[irk_number_of_pages] = number_of_pages + $scope[irkNumberOfPages] = number_of_pages update = (reset) -> - if w.get_list() - if w.get_list().length > 0 - new_number_of_pages = Math.ceil(w.get_list().length / w.get_items_per_page()) + if w.getList() + if w.getList().length > 0 + new_number_of_pages = Math.ceil(w.getList().length / w.getItemsPerPage()) set_number_of_pages(new_number_of_pages) - if $scope.show_sectioning() - pages_to_display = w.get_max_pages() + if $scope.showSectioning() + pages_to_display = w.getMaxPages() else pages_to_display = new_number_of_pages $scope.page_sequence.resetParameters(0, new_number_of_pages, pages_to_display) # TODO warum ist die reihenfolge der folgenden beiden aufrufe irrelevant? - w.set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)) - $scope.page_sequence.realignGreedy(w.get_current_page()) + w.setCurrentPage(keep_in_bounds(w.getCurrentPage(), 0, get_number_of_pages() - 1)) + $scope.page_sequence.realignGreedy(w.getCurrentPage()) else set_number_of_pages(1) $scope.page_sequence.resetParameters(0, 1, 1) - w.set_current_page(0) + w.setCurrentPage(0) $scope.page_sequence.realignGreedy(0) - $scope.show_sectioning = () -> - w.get_max_pages() && get_number_of_pages() > w.get_max_pages() + $scope.showSectioning = () -> + w.getMaxPages() && get_number_of_pages() > w.getMaxPages() - $scope.get_current_page = () -> - w.get_current_page() + $scope.getCurrentPage = () -> + w.getCurrentPage() $scope.step_page = (step) -> step = parseInt(step) - w.set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)) - $scope.page_sequence.realignGreedy(w.get_current_page()) + w.setCurrentPage(keep_in_bounds(w.getCurrentPage() + step, 0, get_number_of_pages() - 1)) + $scope.page_sequence.realignGreedy(w.getCurrentPage()) $scope.go_to_page = (page) -> - w.set_current_page(page) + w.setCurrentPage(page) $scope.jump_back = () -> - $scope.step_page(-w.get_max_pages()) + $scope.step_page(-w.getMaxPages()) $scope.jump_ahead = () -> - $scope.step_page(w.get_max_pages()) + $scope.step_page(w.getMaxPages()) $scope.page_sequence = new PageSequence() - $scope.$watch cvn.items_per_page, () -> + $scope.$watch cvn.itemsPerPage, () -> update() - $scope.$watch cvn.max_pages, () -> + $scope.$watch cvn.maxPages, () -> update() $scope.$watch $attributes.atList, () -> diff --git a/coffee/directives/at_table.coffee b/coffee/directives/at_table.coffee index 2236bc1..60b9c6e 100644 --- a/coffee/directives/at_table.coffee +++ b/coffee/directives/at_table.coffee @@ -4,7 +4,7 @@ angular.module("angular-table").directive "atTable", ["$filter", ($filter) -> compile: (element, attributes, transclude) -> tc = new TableConfiguration(element, attributes) - cvn = new ConfigurationVariableNames(attributes.atConfig) + cvn = new configuration_variable_names(attributes.atConfig) table = new Table(element, tc, cvn) table.compile() diff --git a/coffee/directives/pagination/pagination_template.coffee b/coffee/directives/pagination/pagination_template.coffee index e922eb2..0e948c3 100644 --- a/coffee/directives/pagination/pagination_template.coffee +++ b/coffee/directives/pagination/pagination_template.coffee @@ -1,32 +1,32 @@ -pagination_template = " +paginationTemplate = "
    " diff --git a/coffee/directives/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee index b706dd4..ff5ce38 100644 --- a/coffee/directives/table/setup/paginated_setup.coffee +++ b/coffee/directives/table/setup/paginated_setup.coffee @@ -12,7 +12,7 @@ class PaginatedSetup extends Setup # TODO fillerTr = angular.element(document.createElement("tr")) - fillerTr.attr("ng-show", @configuration_variable_names.fill_last_page) + fillerTr.attr("ng-show", @configuration_variable_names.fillLastPage) fillerTr.html(tdString) fillerTr.attr("ng-repeat", "item in filler_array") @@ -25,31 +25,31 @@ class PaginatedSetup extends Setup w = new ScopeConfigWrapper($scope, cvn, $attributes.atList) - get_sorted_and_paginated_list = (list, current_page, items_per_page, sort_context, predicate, descending, $filter) -> + get_sorted_and_paginated_list = (list, currentPage, itemsPerPage, sortContext, predicate, descending, $filter) -> if list val = list - from_page = items_per_page * current_page - list.length - if sort_context == "global" + from_page = itemsPerPage * currentPage - list.length + if sortContext == "global" val = $filter("orderBy")(val, predicate, descending) val = $filter("limitTo")(val, from_page) - val = $filter("limitTo")(val, items_per_page) + val = $filter("limitTo")(val, itemsPerPage) else val = $filter("limitTo")(val, from_page) - val = $filter("limitTo")(val, items_per_page) + val = $filter("limitTo")(val, itemsPerPage) val = $filter("orderBy")(val, predicate, descending) return val else return [] - get_filler_array = (list, current_page, number_of_pages, items_per_page) -> - items_per_page = parseInt(items_per_page) + get_filler_array = (list, currentPage, number_of_pages, itemsPerPage) -> + itemsPerPage = parseInt(itemsPerPage) if list.length <= 0 - x for x in [0..items_per_page - 1] - else if current_page == number_of_pages - 1 - itemCountOnLastPage = list.length % items_per_page + x for x in [0..itemsPerPage - 1] + else if currentPage == number_of_pages - 1 + itemCountOnLastPage = list.length % itemsPerPage if itemCountOnLastPage != 0 - fillerLength = items_per_page - itemCountOnLastPage - 1 + fillerLength = itemsPerPage - itemCountOnLastPage - 1 x for x in [(list.length)..(list.length + fillerLength)] else [] @@ -57,33 +57,33 @@ class PaginatedSetup extends Setup update = () -> $scope.sorted_and_paginated_list = get_sorted_and_paginated_list( - w.get_list(), - w.get_current_page(), - w.get_items_per_page(), - w.get_sort_context(), + w.getList(), + w.getCurrentPage(), + w.getItemsPerPage(), + w.getSortContext(), $scope.predicate, $scope.descending, $filter ) - nop = Math.ceil(w.get_list().length / w.get_items_per_page()) + nop = Math.ceil(w.getList().length / w.getItemsPerPage()) $scope.filler_array = get_filler_array( - w.get_list(), - w.get_current_page(), + w.getList(), + w.getCurrentPage(), nop, - w.get_items_per_page() + w.getItemsPerPage() ) - $scope.$watch(cvn.current_page, () -> + $scope.$watch(cvn.currentPage, () -> update() ) - $scope.$watch(cvn.items_per_page, () -> + $scope.$watch(cvn.itemsPerPage, () -> update() ) - $scope.$watch(cvn.sort_context, () -> + $scope.$watch(cvn.sortContext, () -> update() ) @@ -92,7 +92,7 @@ class PaginatedSetup extends Setup ) $scope.$watch("#{$attributes.atList}.length", () -> - $scope[irk_number_of_pages] = Math.ceil(w.get_list().length / w.get_items_per_page()) + $scope[irkNumberOfPages] = Math.ceil(w.getList().length / w.getItemsPerPage()) update() ) diff --git a/coffee/directives/table/table.coffee b/coffee/directives/table/table.coffee index a717cc8..b95740d 100644 --- a/coffee/directives/table/table.coffee +++ b/coffee/directives/table/table.coffee @@ -4,7 +4,7 @@ class Table constructHeader: () -> tr = angular.element(document.createElement("tr")) for i in @table_configuration.column_configurations - tr.append(i.render_html()) + tr.append(i.renderHtml()) return tr setup_header: () -> From c1f6fac9cbdbc153cb8068be00c017a88b25475a Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 21 Sep 2014 18:43:49 +0200 Subject: [PATCH 167/190] :lipstick: --- .../configuration_variable_names.coffee | 2 +- .../configuration/scope_config_wrapper.coffee | 14 ++++++------ .../configuration/table_configuration.coffee | 22 +++++++++---------- coffee/directives/at_pagination.coffee | 2 +- coffee/directives/at_table.coffee | 2 +- .../table/setup/paginated_setup.coffee | 6 ++--- .../table/setup/standard_setup.coffee | 2 +- coffee/directives/table/table.coffee | 10 ++++----- test/paginated_setup.coffee | 22 +++++++++---------- 9 files changed, 41 insertions(+), 41 deletions(-) diff --git a/coffee/configuration/configuration_variable_names.coffee b/coffee/configuration/configuration_variable_names.coffee index b69c1a5..2656c91 100644 --- a/coffee/configuration/configuration_variable_names.coffee +++ b/coffee/configuration/configuration_variable_names.coffee @@ -1,4 +1,4 @@ -class configuration_variable_names +class configurationVariableNames constructor: (@configObjectName) -> @itemsPerPage = "#{@configObjectName}.itemsPerPage" @sortContext = "#{@configObjectName}.sortContext" diff --git a/coffee/configuration/scope_config_wrapper.coffee b/coffee/configuration/scope_config_wrapper.coffee index 2c02510..d28888f 100644 --- a/coffee/configuration/scope_config_wrapper.coffee +++ b/coffee/configuration/scope_config_wrapper.coffee @@ -1,20 +1,20 @@ class ScopeConfigWrapper - constructor: (@scope, @configuration_variable_names, @list_name) -> + constructor: (@scope, @configurationVariableNames, @listName) -> getList: () -> - @scope.$eval(@list_name) + @scope.$eval(@listName) getItemsPerPage: () -> - @scope.$eval(@configuration_variable_names.itemsPerPage) || 10 + @scope.$eval(@configurationVariableNames.itemsPerPage) || 10 getCurrentPage: () -> - @scope.$eval(@configuration_variable_names.currentPage) || 0 + @scope.$eval(@configurationVariableNames.currentPage) || 0 getMaxPages: () -> - @scope.$eval(@configuration_variable_names.maxPages) || undefined + @scope.$eval(@configurationVariableNames.maxPages) || undefined getSortContext: () -> - @scope.$eval(@configuration_variable_names.sortContext) || 'global' + @scope.$eval(@configurationVariableNames.sortContext) || 'global' setCurrentPage: (currentPage) -> - @scope.$eval("#{@configuration_variable_names.currentPage}=#{currentPage}") + @scope.$eval("#{@configurationVariableNames.currentPage}=#{currentPage}") diff --git a/coffee/configuration/table_configuration.coffee b/coffee/configuration/table_configuration.coffee index 3315b53..25faa01 100644 --- a/coffee/configuration/table_configuration.coffee +++ b/coffee/configuration/table_configuration.coffee @@ -1,10 +1,10 @@ class TableConfiguration - constructor: (@table_element, @attributes) -> + constructor: (@tableElement, @attributes) -> @id = @attributes.id @config = @attributes.atConfig @paginated = @attributes.atPaginated? @list = @attributes.atList - @create_column_configurations() + @createColumnConfigurations() capitaliseFirstLetter: (string) -> if string then string.charAt(0).toUpperCase() + string.slice(1) else "" @@ -24,7 +24,7 @@ class TableConfiguration throw "Invalid value for initial-sorting: #{initialSorting}. Allowed values are 'asc' or 'desc'." return undefined - collect_header_markup: (table) -> + collectHeaderMarkup: (table) -> customHeaderMarkups = {} tr = table.find("tr") @@ -36,7 +36,7 @@ class TableConfiguration return customHeaderMarkups - collect_body_markup: (table) -> + collectBodyMarkup: (table) -> bodyDefinition = [] for td in table.find("td") @@ -55,13 +55,13 @@ class TableConfiguration return bodyDefinition - create_column_configurations: () -> - header_markup = @collect_header_markup(@table_element) - body_markup = @collect_body_markup(@table_element) + createColumnConfigurations: () -> + headerMarkup = @collectHeaderMarkup(@tableElement) + bodyMarkup = @collectBodyMarkup(@tableElement) - @column_configurations = [] + @columnConfigurations = [] - for i in body_markup - @column_configurations.push new ColumnConfiguration(i, header_markup[i.attribute]) + for i in bodyMarkup + @columnConfigurations.push new ColumnConfiguration(i, headerMarkup[i.attribute]) - return @column_configurations + return diff --git a/coffee/directives/at_pagination.coffee b/coffee/directives/at_pagination.coffee index 088a185..06a8c9d 100644 --- a/coffee/directives/at_pagination.coffee +++ b/coffee/directives/at_pagination.coffee @@ -5,7 +5,7 @@ angular.module("angular-table").directive "atPagination", [() -> template: paginationTemplate link: ($scope, $element, $attributes) -> - cvn = new configuration_variable_names($attributes.atConfig) + cvn = new configurationVariableNames($attributes.atConfig) w = new ScopeConfigWrapper($scope, cvn, $attributes.atList) keep_in_bounds = (val, min, max) -> diff --git a/coffee/directives/at_table.coffee b/coffee/directives/at_table.coffee index 60b9c6e..2dcefc0 100644 --- a/coffee/directives/at_table.coffee +++ b/coffee/directives/at_table.coffee @@ -4,7 +4,7 @@ angular.module("angular-table").directive "atTable", ["$filter", ($filter) -> compile: (element, attributes, transclude) -> tc = new TableConfiguration(element, attributes) - cvn = new configuration_variable_names(attributes.atConfig) + cvn = new configurationVariableNames(attributes.atConfig) table = new Table(element, tc, cvn) table.compile() diff --git a/coffee/directives/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee index ff5ce38..b041bdb 100644 --- a/coffee/directives/table/setup/paginated_setup.coffee +++ b/coffee/directives/table/setup/paginated_setup.coffee @@ -1,5 +1,5 @@ class PaginatedSetup extends Setup - constructor: (@configuration_variable_names) -> + constructor: (@configurationVariableNames) -> @repeatString = "item in sorted_and_paginated_list" compile: (element) -> @@ -12,7 +12,7 @@ class PaginatedSetup extends Setup # TODO fillerTr = angular.element(document.createElement("tr")) - fillerTr.attr("ng-show", @configuration_variable_names.fillLastPage) + fillerTr.attr("ng-show", @configurationVariableNames.fillLastPage) fillerTr.html(tdString) fillerTr.attr("ng-repeat", "item in filler_array") @@ -21,7 +21,7 @@ class PaginatedSetup extends Setup return link: ($scope, $element, $attributes, $filter) -> - cvn = @configuration_variable_names + cvn = @configurationVariableNames w = new ScopeConfigWrapper($scope, cvn, $attributes.atList) diff --git a/coffee/directives/table/setup/standard_setup.coffee b/coffee/directives/table/setup/standard_setup.coffee index 4947b38..bcc6634 100644 --- a/coffee/directives/table/setup/standard_setup.coffee +++ b/coffee/directives/table/setup/standard_setup.coffee @@ -1,5 +1,5 @@ class StandardSetup extends Setup - constructor: (configuration_variable_names, @list) -> + constructor: (configurationVariableNames, @list) -> @repeatString = "item in #{@list} | orderBy:predicate:descending" compile: (element, attributes, transclude) -> diff --git a/coffee/directives/table/table.coffee b/coffee/directives/table/table.coffee index b95740d..c21570c 100644 --- a/coffee/directives/table/table.coffee +++ b/coffee/directives/table/table.coffee @@ -1,9 +1,9 @@ class Table - constructor: (@element, @table_configuration, @configuration_variable_names) -> + constructor: (@element, @table_configuration, @configurationVariableNames) -> constructHeader: () -> tr = angular.element(document.createElement("tr")) - for i in @table_configuration.column_configurations + for i in @table_configuration.columnConfigurations tr.append(i.renderHtml()) return tr @@ -17,9 +17,9 @@ class Table get_setup: () -> if @table_configuration.paginated - return new PaginatedSetup(@configuration_variable_names) + return new PaginatedSetup(@configurationVariableNames) else - return new StandardSetup(@configuration_variable_names, @table_configuration.list) + return new StandardSetup(@configurationVariableNames, @table_configuration.list) return compile: () -> @@ -28,7 +28,7 @@ class Table @setup.compile(@element) setup_initial_sorting: ($scope) -> - for bd in @table_configuration.column_configurations + for bd in @table_configuration.columnConfigurations if bd.initialSorting throw "initial-sorting specified without attribute." if not bd.attribute $scope.predicate = bd.attribute diff --git a/test/paginated_setup.coffee b/test/paginated_setup.coffee index 4c9cabb..e2476ab 100644 --- a/test/paginated_setup.coffee +++ b/test/paginated_setup.coffee @@ -2,7 +2,7 @@ describe "angular-table", () -> describe "paginated setup", () -> config_name = "table_config" - list_name = "myList" + listName = "myList" step_back = '‹' step_ahead = '›' @@ -28,7 +28,7 @@ describe "angular-table", () -> @comp = new TemplateCompiler(setup.template) @element = @comp.prepare_element((scope) -> - scope[list_name] = [ + scope[listName] = [ {name: "i"}, {name: "g"}, {name: "h"}, {name: "j"}, {name: "k"}, {name: "l"} {name: "a"}, {name: "b"}, {name: "c"}, {name: "d"}, {name: "e"}, {name: "f"}, {name: "m"} @@ -187,7 +187,7 @@ describe "angular-table", () -> @gui.alter_scope((scope_wrapper, vars) -> scope_wrapper.set(vars.items_per_page, 3) scope_wrapper.set(vars.fill_last_page, true) - scope_wrapper.set(list_name, []) + scope_wrapper.set(listName, []) ) expect(@gui.table.rows).toEqual [[' '], [' '], [' ']] @@ -197,7 +197,7 @@ describe "angular-table", () -> it "reloads the table if the entries change but the length doesn't", () -> expect(@gui.table.rows).toEqual([['a'], ['b'], ['c']]) @gui.alter_scope((scope_wrapper, vars) -> - list = scope_wrapper.get(list_name) + list = scope_wrapper.get(listName) list.splice(6, 1) # delete the 6th element in the list which is "a" list.push({name: "A"}) ) @@ -229,13 +229,13 @@ describe "angular-table", () -> @gui.alter_scope((scope_wrapper, vars) -> scope_wrapper.set(vars.items_per_page, 3) scope_wrapper.set(vars.max_pages, 2) - scope_wrapper.set(list_name, [{name: 'z'}]) + scope_wrapper.set(listName, [{name: 'z'}]) ) expect(@gui.table.rows).toEqual [['z'], [' '], [' ']] @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.get(list_name).push({name: 'a'}) + scope_wrapper.get(listName).push({name: 'a'}) ) expect(@gui.table.rows).toEqual [['a'], ['z'], [' ']] @@ -243,8 +243,8 @@ describe "angular-table", () -> expect(@gui.pagination.pages).toEqual [1] @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.get(list_name).push({name: 'x'}) - scope_wrapper.get(list_name).push({name: 'b'}) + scope_wrapper.get(listName).push({name: 'x'}) + scope_wrapper.get(listName).push({name: 'b'}) ) expect(@gui.table.rows).toEqual [['a'], ['b'], ['x']] @@ -256,9 +256,9 @@ describe "angular-table", () -> expect(@gui.table.rows).toEqual [['z'], [' '], [' ']] @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.get(list_name).push({name: 'c'}) - scope_wrapper.get(list_name).push({name: 'y'}) - scope_wrapper.get(list_name).push({name: 'u'}) + scope_wrapper.get(listName).push({name: 'c'}) + scope_wrapper.get(listName).push({name: 'y'}) + scope_wrapper.get(listName).push({name: 'u'}) ) expect(@gui.table.rows).toEqual [['u'], ['x'], ['y']] From c7001fc00800c18b7a8036a64163e6cbd2a7ba45 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 21 Sep 2014 18:57:02 +0200 Subject: [PATCH 168/190] :lipstick: --- coffee/angular_table.coffee | 2 - coffee/directives/at_pagination.coffee | 52 +++++++++---------- .../pagination/page_sequence.coffee | 12 ++--- .../pagination/pagination_template.coffee | 22 ++++---- .../table/setup/paginated_setup.coffee | 22 ++++---- coffee/directives/table/table.coffee | 24 ++++----- test/paginated_setup.coffee | 22 ++++---- 7 files changed, 77 insertions(+), 79 deletions(-) diff --git a/coffee/angular_table.coffee b/coffee/angular_table.coffee index 9b270e0..15ce4e5 100644 --- a/coffee/angular_table.coffee +++ b/coffee/angular_table.coffee @@ -1,3 +1 @@ angular.module "angular-table", [] - -irkNumberOfPages = "number_of_pages" diff --git a/coffee/directives/at_pagination.coffee b/coffee/directives/at_pagination.coffee index 06a8c9d..6860d13 100644 --- a/coffee/directives/at_pagination.coffee +++ b/coffee/directives/at_pagination.coffee @@ -8,57 +8,57 @@ angular.module("angular-table").directive "atPagination", [() -> cvn = new configurationVariableNames($attributes.atConfig) w = new ScopeConfigWrapper($scope, cvn, $attributes.atList) - keep_in_bounds = (val, min, max) -> + keepInBounds = (val, min, max) -> val = Math.max(min, val) Math.min(max, val) - get_number_of_pages = () -> - $scope[irkNumberOfPages] + getNumberOfPages = () -> + $scope.numberOfPages - set_number_of_pages = (number_of_pages) -> - $scope[irkNumberOfPages] = number_of_pages + setNumberOfPages = (numberOfPages) -> + $scope.numberOfPages = numberOfPages update = (reset) -> if w.getList() if w.getList().length > 0 - new_number_of_pages = Math.ceil(w.getList().length / w.getItemsPerPage()) - set_number_of_pages(new_number_of_pages) + newNumberOfPages = Math.ceil(w.getList().length / w.getItemsPerPage()) + setNumberOfPages(newNumberOfPages) if $scope.showSectioning() - pages_to_display = w.getMaxPages() + pagesToDisplay = w.getMaxPages() else - pages_to_display = new_number_of_pages + pagesToDisplay = newNumberOfPages - $scope.page_sequence.resetParameters(0, new_number_of_pages, pages_to_display) + $scope.pageSequence.resetParameters(0, newNumberOfPages, pagesToDisplay) # TODO warum ist die reihenfolge der folgenden beiden aufrufe irrelevant? - w.setCurrentPage(keep_in_bounds(w.getCurrentPage(), 0, get_number_of_pages() - 1)) - $scope.page_sequence.realignGreedy(w.getCurrentPage()) + w.setCurrentPage(keepInBounds(w.getCurrentPage(), 0, getNumberOfPages() - 1)) + $scope.pageSequence.realignGreedy(w.getCurrentPage()) else - set_number_of_pages(1) - $scope.page_sequence.resetParameters(0, 1, 1) + setNumberOfPages(1) + $scope.pageSequence.resetParameters(0, 1, 1) w.setCurrentPage(0) - $scope.page_sequence.realignGreedy(0) + $scope.pageSequence.realignGreedy(0) $scope.showSectioning = () -> - w.getMaxPages() && get_number_of_pages() > w.getMaxPages() + w.getMaxPages() && getNumberOfPages() > w.getMaxPages() $scope.getCurrentPage = () -> w.getCurrentPage() - $scope.step_page = (step) -> + $scope.stepPage = (step) -> step = parseInt(step) - w.setCurrentPage(keep_in_bounds(w.getCurrentPage() + step, 0, get_number_of_pages() - 1)) - $scope.page_sequence.realignGreedy(w.getCurrentPage()) + w.setCurrentPage(keepInBounds(w.getCurrentPage() + step, 0, getNumberOfPages() - 1)) + $scope.pageSequence.realignGreedy(w.getCurrentPage()) - $scope.go_to_page = (page) -> + $scope.goToPage = (page) -> w.setCurrentPage(page) - $scope.jump_back = () -> - $scope.step_page(-w.getMaxPages()) + $scope.jumpBack = () -> + $scope.stepPage(-w.getMaxPages()) - $scope.jump_ahead = () -> - $scope.step_page(w.getMaxPages()) + $scope.jumpAhead = () -> + $scope.stepPage(w.getMaxPages()) - $scope.page_sequence = new PageSequence() + $scope.pageSequence = new PageSequence() $scope.$watch cvn.itemsPerPage, () -> update() @@ -73,4 +73,4 @@ angular.module("angular-table").directive "atPagination", [() -> update() update() -] \ No newline at end of file +] diff --git a/coffee/directives/pagination/page_sequence.coffee b/coffee/directives/pagination/page_sequence.coffee index 7ba61d7..9b51793 100644 --- a/coffee/directives/pagination/page_sequence.coffee +++ b/coffee/directives/pagination/page_sequence.coffee @@ -18,15 +18,15 @@ class PageSequence @data = @generate(@data[0]) relocate: (distance) -> - new_start = @data[0] + distance - @data = @generate(new_start, new_start + @length) + newStart = @data[0] + distance + @data = @generate(newStart, newStart + @length) realignGreedy: (page) -> if page < @data[0] - new_start = page - @data = @generate(new_start) + newStart = page + @data = @generate(newStart) else if page > @data[@length - 1] - new_start = page - (@length - 1) - @data = @generate(new_start) + newStart = page - (@length - 1) + @data = @generate(newStart) realignGenerous: (page) -> diff --git a/coffee/directives/pagination/pagination_template.coffee b/coffee/directives/pagination/pagination_template.coffee index 0e948c3..ca44d3d 100644 --- a/coffee/directives/pagination/pagination_template.coffee +++ b/coffee/directives/pagination/pagination_template.coffee @@ -2,31 +2,31 @@ paginationTemplate = "
    " diff --git a/coffee/directives/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee index b041bdb..fa35a00 100644 --- a/coffee/directives/table/setup/paginated_setup.coffee +++ b/coffee/directives/table/setup/paginated_setup.coffee @@ -1,6 +1,6 @@ class PaginatedSetup extends Setup constructor: (@configurationVariableNames) -> - @repeatString = "item in sorted_and_paginated_list" + @repeatString = "item in sortedAndPaginatedList" compile: (element) -> tbody = @setupTr(element, @repeatString) @@ -14,7 +14,7 @@ class PaginatedSetup extends Setup fillerTr = angular.element(document.createElement("tr")) fillerTr.attr("ng-show", @configurationVariableNames.fillLastPage) fillerTr.html(tdString) - fillerTr.attr("ng-repeat", "item in filler_array") + fillerTr.attr("ng-repeat", "item in fillerArray") tbody.append(fillerTr) @@ -25,16 +25,16 @@ class PaginatedSetup extends Setup w = new ScopeConfigWrapper($scope, cvn, $attributes.atList) - get_sorted_and_paginated_list = (list, currentPage, itemsPerPage, sortContext, predicate, descending, $filter) -> + getSortedAndPaginatedList = (list, currentPage, itemsPerPage, sortContext, predicate, descending, $filter) -> if list val = list - from_page = itemsPerPage * currentPage - list.length + fromPage = itemsPerPage * currentPage - list.length if sortContext == "global" val = $filter("orderBy")(val, predicate, descending) - val = $filter("limitTo")(val, from_page) + val = $filter("limitTo")(val, fromPage) val = $filter("limitTo")(val, itemsPerPage) else - val = $filter("limitTo")(val, from_page) + val = $filter("limitTo")(val, fromPage) val = $filter("limitTo")(val, itemsPerPage) val = $filter("orderBy")(val, predicate, descending) @@ -42,11 +42,11 @@ class PaginatedSetup extends Setup else return [] - get_filler_array = (list, currentPage, number_of_pages, itemsPerPage) -> + getFillerArray = (list, currentPage, numberOfPages, itemsPerPage) -> itemsPerPage = parseInt(itemsPerPage) if list.length <= 0 x for x in [0..itemsPerPage - 1] - else if currentPage == number_of_pages - 1 + else if currentPage == numberOfPages - 1 itemCountOnLastPage = list.length % itemsPerPage if itemCountOnLastPage != 0 fillerLength = itemsPerPage - itemCountOnLastPage - 1 @@ -56,7 +56,7 @@ class PaginatedSetup extends Setup update = () -> - $scope.sorted_and_paginated_list = get_sorted_and_paginated_list( + $scope.sortedAndPaginatedList = getSortedAndPaginatedList( w.getList(), w.getCurrentPage(), w.getItemsPerPage(), @@ -68,7 +68,7 @@ class PaginatedSetup extends Setup nop = Math.ceil(w.getList().length / w.getItemsPerPage()) - $scope.filler_array = get_filler_array( + $scope.fillerArray = getFillerArray( w.getList(), w.getCurrentPage(), nop, @@ -92,7 +92,7 @@ class PaginatedSetup extends Setup ) $scope.$watch("#{$attributes.atList}.length", () -> - $scope[irkNumberOfPages] = Math.ceil(w.getList().length / w.getItemsPerPage()) + $scope.numberOfPages = Math.ceil(w.getList().length / w.getItemsPerPage()) update() ) diff --git a/coffee/directives/table/table.coffee b/coffee/directives/table/table.coffee index c21570c..5d1242e 100644 --- a/coffee/directives/table/table.coffee +++ b/coffee/directives/table/table.coffee @@ -1,13 +1,13 @@ class Table - constructor: (@element, @table_configuration, @configurationVariableNames) -> + constructor: (@element, @tableConfiguration, @configurationVariableNames) -> constructHeader: () -> tr = angular.element(document.createElement("tr")) - for i in @table_configuration.columnConfigurations + for i in @tableConfiguration.columnConfigurations tr.append(i.renderHtml()) return tr - setup_header: () -> + setupHeader: () -> thead = @element.find("thead") if thead header = @constructHeader() @@ -15,30 +15,30 @@ class Table tr.remove() thead.append(header) - get_setup: () -> - if @table_configuration.paginated + getSetup: () -> + if @tableConfiguration.paginated return new PaginatedSetup(@configurationVariableNames) else - return new StandardSetup(@configurationVariableNames, @table_configuration.list) + return new StandardSetup(@configurationVariableNames, @tableConfiguration.list) return compile: () -> - @setup_header() - @setup = @get_setup() + @setupHeader() + @setup = @getSetup() @setup.compile(@element) - setup_initial_sorting: ($scope) -> - for bd in @table_configuration.columnConfigurations + setupInitialSorting: ($scope) -> + for bd in @tableConfiguration.columnConfigurations if bd.initialSorting throw "initial-sorting specified without attribute." if not bd.attribute $scope.predicate = bd.attribute $scope.descending = bd.initialSorting == "desc" post: ($scope, $element, $attributes, $filter) -> - @setup_initial_sorting($scope) + @setupInitialSorting($scope) if not $scope.getSortIcon - $scope.getSortIcon = (predicate, current_predicate) -> + $scope.getSortIcon = (predicate, currentPredicate) -> return "glyphicon glyphicon-minus" if predicate != $scope.predicate if $scope.descending then "glyphicon glyphicon-chevron-down" else "glyphicon glyphicon-chevron-up" diff --git a/test/paginated_setup.coffee b/test/paginated_setup.coffee index e2476ab..65d8100 100644 --- a/test/paginated_setup.coffee +++ b/test/paginated_setup.coffee @@ -6,8 +6,8 @@ describe "angular-table", () -> step_back = '‹' step_ahead = '›' - jump_back = '«' - jump_ahead = '»' + jumpBack = '«' + jumpAhead = '»' first = 'First' last = 'Last' @@ -118,13 +118,13 @@ describe "angular-table", () -> expect(@gui.pagination.current_page).toEqual(1) expect(@gui.pagination.pages).toEqual([1, 2]) - @gui.click_pagination(jump_ahead) + @gui.click_pagination(jumpAhead) expect(@gui.table.rows).toEqual([['g'], ['h'], ['i']]) expect(@gui.pagination.current_page).toEqual(3) expect(@gui.pagination.pages).toEqual([2, 3]) - @gui.click_pagination(jump_ahead) + @gui.click_pagination(jumpAhead) # we reached the end of the pagination by now @@ -132,7 +132,7 @@ describe "angular-table", () -> expect(@gui.pagination.current_page).toEqual(5) expect(@gui.pagination.pages).toEqual([4, 5]) - @gui.click_pagination(jump_ahead) + @gui.click_pagination(jumpAhead) expect(@gui.table.rows).toEqual([['m'], [' '], [' ']]) expect(@gui.pagination.current_page).toEqual(5) @@ -144,13 +144,13 @@ describe "angular-table", () -> expect(@gui.pagination.current_page).toEqual(4) expect(@gui.pagination.pages).toEqual([4, 5]) - @gui.click_pagination(jump_back) + @gui.click_pagination(jumpBack) expect(@gui.table.rows).toEqual([['d'], ['e'], ['f']]) expect(@gui.pagination.current_page).toEqual(2) expect(@gui.pagination.pages).toEqual([2, 3]) - @gui.click_pagination(jump_back) + @gui.click_pagination(jumpBack) expect(@gui.table.rows).toEqual([['a'], ['b'], ['c']]) expect(@gui.pagination.current_page).toEqual(1) @@ -337,7 +337,7 @@ describe "angular-table", () -> expect(@gui.pagination.current_page).toEqual(5) expect(@gui.pagination.pages).toEqual([3, 4, 5]) - @gui.click_pagination(jump_back) + @gui.click_pagination(jumpBack) expect(@gui.pagination.current_page).toEqual 2 expect(@gui.table.rows).toEqual([['d'], ['e'], ['f']]) @@ -364,15 +364,15 @@ describe "angular-table", () -> scope_wrapper.set(vars.max_pages, 2) ) - @gui.click_pagination(jump_ahead) + @gui.click_pagination(jumpAhead) expect(@gui.pagination.current_page).toEqual 4 - @gui.click_pagination(jump_ahead) + @gui.click_pagination(jumpAhead) expect(@gui.pagination.current_page).toEqual 6 - @gui.click_pagination(jump_ahead) + @gui.click_pagination(jumpAhead) expect(@gui.pagination.current_page).toEqual 7 From 81cd0dbdccd2449015068f2cb00cbb47388290f0 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 21 Sep 2014 19:08:34 +0200 Subject: [PATCH 169/190] :lipstick: --- test/header.coffee | 10 +- test/page_sequence.coffee | 2 +- test/paginated_setup.coffee | 252 ++++++++++++++++++------------------ test/standard_setup.coffee | 16 +-- test/test_helper.coffee | 47 +++---- 5 files changed, 161 insertions(+), 166 deletions(-) diff --git a/test/header.coffee b/test/header.coffee index 19553f6..a0eb960 100644 --- a/test/header.coffee +++ b/test/header.coffee @@ -3,20 +3,20 @@ # it "doesnt add a header at all if the header tag isnt declared", () -> # comp = new TemplateCompiler("header/no_header.html") -# @element = comp.prepare_element((scope) ->) +# @element = comp.prepareElement((scope) ->) # header = @element.find("thead")[0] # expect(header).toBe undefined # it "creates column headers implicitly", () -> # comp = new TemplateCompiler("header/header.html") -# @element = comp.prepare_element((scope) ->) -# header = extract_html_to_array(getChildrenFor(@element, "thead > tr > th")) +# @element = comp.prepareElement((scope) ->) +# header = extractHtmlToArray(getChildrenFor(@element, "thead > tr > th")) # expect(header[0]).toEqual "Name" # it "allows to set custom column headers", () -> # comp = new TemplateCompiler("header/header.html") -# @element = comp.prepare_element((scope) ->) -# header = extract_html_to_array(getChildrenFor(@element, "thead > tr > th")) +# @element = comp.prepareElement((scope) ->) +# header = extractHtmlToArray(getChildrenFor(@element, "thead > tr > th")) # expect(header[1]).toEqual "The population" # expect(header[2]).toEqual "Country" # expect(header[3]).toEqual "Size" diff --git a/test/page_sequence.coffee b/test/page_sequence.coffee index ece4708..deacefb 100644 --- a/test/page_sequence.coffee +++ b/test/page_sequence.coffee @@ -1,6 +1,6 @@ describe "angular-table", () -> describe "PageSequence", () -> - it "is constructed from upper_bound, lower_bound, start and length paramters", () -> + it "is constructed from upperBound, lowerBound, start and length paramters", () -> sequence = new PageSequence(0, 10, 0, 5) expect(sequence.data).toEqual [0, 1, 2, 3, 4] diff --git a/test/paginated_setup.coffee b/test/paginated_setup.coffee index 65d8100..2c300b0 100644 --- a/test/paginated_setup.coffee +++ b/test/paginated_setup.coffee @@ -1,11 +1,11 @@ describe "angular-table", () -> describe "paginated setup", () -> - config_name = "table_config" + configName = "table_config" listName = "myList" - step_back = '‹' - step_ahead = '›' + stepBack = '‹' + stepAhead = '›' jumpBack = '«' jumpAhead = '»' first = 'First' @@ -13,11 +13,11 @@ describe "angular-table", () -> setups = [{ template: "paginated_setup.html" - variable_names: { - items_per_page: "#{config_name}.itemsPerPage", - max_pages: "#{config_name}.maxPages", - sort_context: "#{config_name}.sortContext", - fill_last_page: "#{config_name}.fillLastPage" + variableNames: { + itemsPerPage: "#{configName}.itemsPerPage", + maxPages: "#{configName}.maxPages", + sortContext: "#{configName}.sortContext", + fillLastPage: "#{configName}.fillLastPage" } }] @@ -27,14 +27,14 @@ describe "angular-table", () -> beforeEach () -> @comp = new TemplateCompiler(setup.template) - @element = @comp.prepare_element((scope) -> + @element = @comp.prepareElement((scope) -> scope[listName] = [ {name: "i"}, {name: "g"}, {name: "h"}, {name: "j"}, {name: "k"}, {name: "l"} {name: "a"}, {name: "b"}, {name: "c"}, {name: "d"}, {name: "e"}, {name: "f"}, {name: "m"} ] - scope[config_name] = { + scope[configName] = { currentPage: 0, itemsPerPage: 3, maxPages: 2, @@ -45,121 +45,121 @@ describe "angular-table", () -> table = new TableGUI(@element) pagination = new PaginationGUI(@element) - @gui = new GUI(table, pagination, @comp.scope, setup.variable_names) + @gui = new GUI(table, pagination, @comp.scope, setup.variableNames) it "allows to select pages", () -> expect(@gui.pagination.pages).toEqual([1, 2]) - expect(@gui.pagination.current_page).toEqual(1) + expect(@gui.pagination.currentPage).toEqual(1) - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.items_per_page, 4) - scope_wrapper.set(vars.max_pages, 4) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.itemsPerPage, 4) + scopeWrapper.set(vars.maxPages, 4) ) expect(@gui.table.rows).toEqual([['a'], ['b'], ['c'], ['d']]) expect(@gui.pagination.pages).toEqual([1, 2, 3, 4]) - @gui.click_pagination(2) + @gui.clickPagination(2) expect(@gui.table.rows).toEqual([['e'], ['f'], ['g'], ['h']]) - expect(@gui.pagination.current_page).toEqual(2) + expect(@gui.pagination.currentPage).toEqual(2) - @gui.click_pagination(4) + @gui.clickPagination(4) expect(@gui.table.rows).toEqual([['m'], [' '], [' '], [' ']]) - expect(@gui.pagination.current_page).toEqual(4) + expect(@gui.pagination.currentPage).toEqual(4) it "allows to step back and forth", () -> expect(@gui.table.rows).toEqual([['a'], ['b'], ['c']]) - expect(@gui.pagination.current_page).toEqual(1) + expect(@gui.pagination.currentPage).toEqual(1) expect(@gui.pagination.pages).toEqual([1, 2]) - @gui.click_pagination(step_ahead) + @gui.clickPagination(stepAhead) expect(@gui.table.rows).toEqual([['d'], ['e'], ['f']]) - expect(@gui.pagination.current_page).toEqual(2) + expect(@gui.pagination.currentPage).toEqual(2) expect(@gui.pagination.pages).toEqual([1, 2]) - @gui.click_pagination(step_ahead) + @gui.clickPagination(stepAhead) expect(@gui.table.rows).toEqual([['g'], ['h'], ['i']]) - expect(@gui.pagination.current_page).toEqual(3) + expect(@gui.pagination.currentPage).toEqual(3) expect(@gui.pagination.pages).toEqual([2, 3]) - @gui.click_pagination(step_ahead) - @gui.click_pagination(step_ahead) + @gui.clickPagination(stepAhead) + @gui.clickPagination(stepAhead) # we reached the end of the pagination by now expect(@gui.table.rows).toEqual([['m'], [' '], [' ']]) - expect(@gui.pagination.current_page).toEqual(5) + expect(@gui.pagination.currentPage).toEqual(5) expect(@gui.pagination.pages).toEqual([4, 5]) - @gui.click_pagination(step_ahead) + @gui.clickPagination(stepAhead) expect(@gui.table.rows).toEqual([['m'], [' '], [' ']]) - expect(@gui.pagination.current_page).toEqual(5) + expect(@gui.pagination.currentPage).toEqual(5) expect(@gui.pagination.pages).toEqual([4, 5]) - @gui.click_pagination(step_back) + @gui.clickPagination(stepBack) expect(@gui.table.rows).toEqual([['j'], ['k'], ['l']]) - expect(@gui.pagination.current_page).toEqual(4) + expect(@gui.pagination.currentPage).toEqual(4) expect(@gui.pagination.pages).toEqual([4, 5]) - @gui.click_pagination(step_back) + @gui.clickPagination(stepBack) expect(@gui.table.rows).toEqual([['g'], ['h'], ['i']]) - expect(@gui.pagination.current_page).toEqual(3) + expect(@gui.pagination.currentPage).toEqual(3) expect(@gui.pagination.pages).toEqual([3, 4]) it "allows to jump back and forth", () -> expect(@gui.table.rows).toEqual([['a'], ['b'], ['c']]) - expect(@gui.pagination.current_page).toEqual(1) + expect(@gui.pagination.currentPage).toEqual(1) expect(@gui.pagination.pages).toEqual([1, 2]) - @gui.click_pagination(jumpAhead) + @gui.clickPagination(jumpAhead) expect(@gui.table.rows).toEqual([['g'], ['h'], ['i']]) - expect(@gui.pagination.current_page).toEqual(3) + expect(@gui.pagination.currentPage).toEqual(3) expect(@gui.pagination.pages).toEqual([2, 3]) - @gui.click_pagination(jumpAhead) + @gui.clickPagination(jumpAhead) # we reached the end of the pagination by now expect(@gui.table.rows).toEqual([['m'], [' '], [' ']]) - expect(@gui.pagination.current_page).toEqual(5) + expect(@gui.pagination.currentPage).toEqual(5) expect(@gui.pagination.pages).toEqual([4, 5]) - @gui.click_pagination(jumpAhead) + @gui.clickPagination(jumpAhead) expect(@gui.table.rows).toEqual([['m'], [' '], [' ']]) - expect(@gui.pagination.current_page).toEqual(5) + expect(@gui.pagination.currentPage).toEqual(5) expect(@gui.pagination.pages).toEqual([4, 5]) - @gui.click_pagination(step_back) + @gui.clickPagination(stepBack) expect(@gui.table.rows).toEqual([['j'], ['k'], ['l']]) - expect(@gui.pagination.current_page).toEqual(4) + expect(@gui.pagination.currentPage).toEqual(4) expect(@gui.pagination.pages).toEqual([4, 5]) - @gui.click_pagination(jumpBack) + @gui.clickPagination(jumpBack) expect(@gui.table.rows).toEqual([['d'], ['e'], ['f']]) - expect(@gui.pagination.current_page).toEqual(2) + expect(@gui.pagination.currentPage).toEqual(2) expect(@gui.pagination.pages).toEqual([2, 3]) - @gui.click_pagination(jumpBack) + @gui.clickPagination(jumpBack) expect(@gui.table.rows).toEqual([['a'], ['b'], ['c']]) - expect(@gui.pagination.current_page).toEqual(1) + expect(@gui.pagination.currentPage).toEqual(1) expect(@gui.pagination.pages).toEqual([1, 2]) it "allows to set a sort context", () -> - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.items_per_page, 4) - scope_wrapper.set(vars.sort_context, "global") + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.itemsPerPage, 4) + scopeWrapper.set(vars.sortContext, "global") ) expect(@gui.table.rows).toEqual([['a'], ['b'], ['c'], ['d']]) @@ -168,8 +168,8 @@ describe "angular-table", () -> expect(@gui.table.rows).toEqual([['m'], ['l'], ['k'], ['j']]) - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.sort_context, "page") + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.sortContext, "page") ) expect(@gui.table.rows).toEqual([['j'], ['i'], ['h'], ['g']]) @@ -179,25 +179,25 @@ describe "angular-table", () -> expect(@gui.table.rows).toEqual([['g'], ['h'], ['i'], ['j']]) it "shows an empty table if fill-last-page is true and the list is empty", () -> - @gui.click_pagination(2) + @gui.clickPagination(2) expect(@gui.table.rows).toEqual [['d'], ['e'], ['f']] - expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.pagination.currentPage).toEqual 2 - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.items_per_page, 3) - scope_wrapper.set(vars.fill_last_page, true) - scope_wrapper.set(listName, []) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.itemsPerPage, 3) + scopeWrapper.set(vars.fillLastPage, true) + scopeWrapper.set(listName, []) ) expect(@gui.table.rows).toEqual [[' '], [' '], [' ']] expect(@gui.pagination.pages).toEqual [1] - expect(@gui.pagination.current_page).toEqual 1 + expect(@gui.pagination.currentPage).toEqual 1 it "reloads the table if the entries change but the length doesn't", () -> expect(@gui.table.rows).toEqual([['a'], ['b'], ['c']]) - @gui.alter_scope((scope_wrapper, vars) -> - list = scope_wrapper.get(listName) + @gui.alterScope((scopeWrapper, vars) -> + list = scopeWrapper.get(listName) list.splice(6, 1) # delete the 6th element in the list which is "a" list.push({name: "A"}) ) @@ -205,10 +205,10 @@ describe "angular-table", () -> describe "the maximum pages setting", () -> for val in [undefined, null] - it "shows all pages if max_pages is undefined or null", () -> + it "shows all pages if maxPages is undefined or null", () -> - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.max_pages, val) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.maxPages, val) ) expect(@gui.pagination.pages).toEqual([1, 2, 3, 4, 5]) @@ -216,8 +216,8 @@ describe "angular-table", () -> ['First', '‹', '1', '2', '3', '4', '5', '›', 'Last']) it "shows a subsection of pages if maximum pages is smaller than total pages", () -> - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.max_pages, 3) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.maxPages, 3) ) expect(@gui.pagination.pages).toEqual([1, 2, 3]) @@ -226,46 +226,46 @@ describe "angular-table", () -> describe "heavy interaction", () -> it "updates when the length of the list changes", () -> - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.items_per_page, 3) - scope_wrapper.set(vars.max_pages, 2) - scope_wrapper.set(listName, [{name: 'z'}]) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.itemsPerPage, 3) + scopeWrapper.set(vars.maxPages, 2) + scopeWrapper.set(listName, [{name: 'z'}]) ) expect(@gui.table.rows).toEqual [['z'], [' '], [' ']] - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.get(listName).push({name: 'a'}) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.get(listName).push({name: 'a'}) ) expect(@gui.table.rows).toEqual [['a'], ['z'], [' ']] expect(@gui.pagination.representation).toEqual ['First', '‹', '1', '›', 'Last'] expect(@gui.pagination.pages).toEqual [1] - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.get(listName).push({name: 'x'}) - scope_wrapper.get(listName).push({name: 'b'}) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.get(listName).push({name: 'x'}) + scopeWrapper.get(listName).push({name: 'b'}) ) expect(@gui.table.rows).toEqual [['a'], ['b'], ['x']] expect(@gui.pagination.representation).toEqual ['First', '‹', '1', '2', '›', 'Last'] expect(@gui.pagination.pages).toEqual [1, 2] - @gui.click_pagination(2) + @gui.clickPagination(2) expect(@gui.table.rows).toEqual [['z'], [' '], [' ']] - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.get(listName).push({name: 'c'}) - scope_wrapper.get(listName).push({name: 'y'}) - scope_wrapper.get(listName).push({name: 'u'}) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.get(listName).push({name: 'c'}) + scopeWrapper.get(listName).push({name: 'y'}) + scopeWrapper.get(listName).push({name: 'u'}) ) expect(@gui.table.rows).toEqual [['u'], ['x'], ['y']] expect(@gui.pagination.representation).toEqual( [ 'First', '«', '‹', '1', '2', '›', '»', 'Last' ]) - @gui.click_pagination(step_ahead) + @gui.clickPagination(stepAhead) expect(@gui.table.rows).toEqual [['z'], [' '], [' ']] expect(@gui.pagination.representation).toEqual( @@ -273,114 +273,114 @@ describe "angular-table", () -> it "updates when ever a configuration parameter changes", () -> - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.items_per_page, 5) - scope_wrapper.set(vars.max_pages, 4) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.itemsPerPage, 5) + scopeWrapper.set(vars.maxPages, 4) ) - @gui.click_pagination(step_ahead) + @gui.clickPagination(stepAhead) - expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.pagination.currentPage).toEqual 2 expect(@gui.table.rows).toEqual([['f'], ['g'], ['h'], ['i'], ['j']]) expect(@gui.pagination.pages).toEqual([1, 2, 3]) - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.max_pages, 2) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.maxPages, 2) ) - expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.pagination.currentPage).toEqual 2 expect(@gui.table.rows).toEqual([['f'], ['g'], ['h'], ['i'], ['j']]) expect(@gui.pagination.pages).toEqual([1, 2]) - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.max_pages, 1) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.maxPages, 1) ) - expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.pagination.currentPage).toEqual 2 expect(@gui.table.rows).toEqual([['f'], ['g'], ['h'], ['i'], ['j']]) expect(@gui.pagination.pages).toEqual([2]) - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.items_per_page, 2) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.itemsPerPage, 2) ) - expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.pagination.currentPage).toEqual 2 expect(@gui.table.rows).toEqual([['c'], ['d']]) expect(@gui.pagination.pages).toEqual([2]) - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.items_per_page, 3) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.itemsPerPage, 3) ) - expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.pagination.currentPage).toEqual 2 expect(@gui.table.rows).toEqual([['d'], ['e'], ['f']]) expect(@gui.pagination.pages).toEqual([2]) - @gui.click_pagination(step_ahead) + @gui.clickPagination(stepAhead) - expect(@gui.pagination.current_page).toEqual 3 + expect(@gui.pagination.currentPage).toEqual 3 expect(@gui.table.rows).toEqual([['g'], ['h'], ['i']]) expect(@gui.pagination.pages).toEqual([3]) - @gui.click_pagination(step_ahead) - @gui.click_pagination(step_ahead) + @gui.clickPagination(stepAhead) + @gui.clickPagination(stepAhead) expect(@gui.table.rows).toEqual([['m'], [' '], [' ']]) - expect(@gui.pagination.current_page).toEqual(5) + expect(@gui.pagination.currentPage).toEqual(5) expect(@gui.pagination.pages).toEqual([5]) - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.max_pages, 3) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.maxPages, 3) ) expect(@gui.table.rows).toEqual([['m'], [' '], [' ']]) - expect(@gui.pagination.current_page).toEqual(5) + expect(@gui.pagination.currentPage).toEqual(5) expect(@gui.pagination.pages).toEqual([3, 4, 5]) - @gui.click_pagination(jumpBack) + @gui.clickPagination(jumpBack) - expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.pagination.currentPage).toEqual 2 expect(@gui.table.rows).toEqual([['d'], ['e'], ['f']]) expect(@gui.pagination.pages).toEqual([2, 3, 4]) - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.max_pages, 4) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.maxPages, 4) ) - expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.pagination.currentPage).toEqual 2 expect(@gui.table.rows).toEqual([['d'], ['e'], ['f']]) expect(@gui.pagination.pages).toEqual([2, 3, 4, 5]) - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.items_per_page, 6) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.itemsPerPage, 6) ) - expect(@gui.pagination.current_page).toEqual 2 + expect(@gui.pagination.currentPage).toEqual 2 expect(@gui.table.rows).toEqual([['g'], ['h'], ['i'], ['j'], ['k'], ['l']]) expect(@gui.pagination.pages).toEqual([1, 2, 3]) - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.items_per_page, 2) - scope_wrapper.set(vars.max_pages, 2) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.itemsPerPage, 2) + scopeWrapper.set(vars.maxPages, 2) ) - @gui.click_pagination(jumpAhead) + @gui.clickPagination(jumpAhead) - expect(@gui.pagination.current_page).toEqual 4 + expect(@gui.pagination.currentPage).toEqual 4 - @gui.click_pagination(jumpAhead) + @gui.clickPagination(jumpAhead) - expect(@gui.pagination.current_page).toEqual 6 + expect(@gui.pagination.currentPage).toEqual 6 - @gui.click_pagination(jumpAhead) + @gui.clickPagination(jumpAhead) - expect(@gui.pagination.current_page).toEqual 7 + expect(@gui.pagination.currentPage).toEqual 7 - @gui.alter_scope((scope_wrapper, vars) -> - scope_wrapper.set(vars.items_per_page, 6) - scope_wrapper.set(vars.max_pages, 4) + @gui.alterScope((scopeWrapper, vars) -> + scopeWrapper.set(vars.itemsPerPage, 6) + scopeWrapper.set(vars.maxPages, 4) ) expect(@gui.table.rows).toEqual([['m'], [' '], [' '], [' '], [' '], [' ']]) - expect(@gui.pagination.current_page).toEqual(3) + expect(@gui.pagination.currentPage).toEqual(3) expect(@gui.pagination.pages).toEqual([1, 2, 3]) diff --git a/test/standard_setup.coffee b/test/standard_setup.coffee index 5c81707..b65eea4 100644 --- a/test/standard_setup.coffee +++ b/test/standard_setup.coffee @@ -1,7 +1,7 @@ describe "angular-table", () -> describe "standard setup", () -> - expected_rows = [ + expectedRows = [ ["0", "Helsinki", "Finland"], ["1", "Zurich", "Switzerland"], ["2", "Amsterdam", "Netherlands"], @@ -10,7 +10,7 @@ describe "angular-table", () -> beforeEach(() -> comp = new TemplateCompiler("standard_setup.html") - @element = comp.prepare_element((scope) -> + @element = comp.prepareElement((scope) -> scope.cities = [{ id: 0 name: "Helsinki" @@ -30,20 +30,20 @@ describe "angular-table", () -> ) it "allows to set an initial sorting direction", () -> - expect(@gui.table.rows).toEqual [expected_rows[1], expected_rows[0], expected_rows[2]] + expect(@gui.table.rows).toEqual [expectedRows[1], expectedRows[0], expectedRows[2]] it "makes columns sortable which are declared at-sortable", () -> @gui.table.sort(1) - expect(@gui.table.rows).toEqual [expected_rows[2], expected_rows[0], expected_rows[1]] + expect(@gui.table.rows).toEqual [expectedRows[2], expectedRows[0], expectedRows[1]] it "leaves columns unsortable if at-sortable is not declared", () -> @gui.table.sort(2) - expect(@gui.table.rows).toEqual [expected_rows[1], expected_rows[0], expected_rows[2]] + expect(@gui.table.rows).toEqual [expectedRows[1], expectedRows[0], expectedRows[2]] it "reloads the table if the entries change but the length doesn't", () -> - @gui.alter_scope((scope_wrapper, vars) -> - cities = scope_wrapper.get("cities") + @gui.alterScope((scopeWrapper, vars) -> + cities = scopeWrapper.get("cities") cities.pop() cities.push({id: 3, name: "Berlin", country: "Germany"}) ) - expect(@gui.table.rows).toEqual [expected_rows[1], expected_rows[0], expected_rows[3]] + expect(@gui.table.rows).toEqual [expectedRows[1], expectedRows[0], expectedRows[3]] diff --git a/test/test_helper.coffee b/test/test_helper.coffee index 7157608..ba9e64a 100644 --- a/test/test_helper.coffee +++ b/test/test_helper.coffee @@ -1,12 +1,12 @@ getChildrenFor = (element, selector) -> element[0].querySelectorAll(selector) -extract_visible_elements = (elements) -> +extractVisibleElements = (elements) -> _.reject(elements, (element) -> angular.element(element).hasClass("ng-hide") ) -extract_html_to_array = (elements) -> +extractHtmlToArray = (elements) -> _.map(elements, (element) -> angular.element(element).html() ) @@ -21,18 +21,18 @@ class ScopeWrapper @scope.$eval("#{expression}") class TemplateCompiler - constructor: (template_name) -> - @template_name = template_name + constructor: (templateName) -> + @templateName = templateName module("angular-table") - module("test/templates/#{@template_name}") + module("test/templates/#{@templateName}") - load_template: (template_name, template_cache) -> - angular.element(template_cache.get(template_name)) + loadTemplate: (templateName, template_cache) -> + angular.element(template_cache.get(templateName)) - compile_template: ($compile, $rootScope, $templateCache, callback) -> + compileTemplate: ($compile, $rootScope, $templateCache, callback) -> element = null - element = @load_template("test/templates/#{@template_name}", $templateCache) + element = @loadTemplate("test/templates/#{@templateName}", $templateCache) callback($rootScope) element = $compile(element)($rootScope) $rootScope.$digest() @@ -41,11 +41,11 @@ class TemplateCompiler return element - prepare_element: (callback) -> + prepareElement: (callback) -> element = null thiz = @ inject ($compile, $rootScope, $templateCache) -> - element = thiz.compile_template($compile, $rootScope, $templateCache, callback) + element = thiz.compileTemplate($compile, $rootScope, $templateCache, callback) return element class TableGUI @@ -70,7 +70,7 @@ class PaginationGUI reload: () -> lis = @element.find("li") - lis = extract_visible_elements(lis) + lis = extractVisibleElements(lis) as = (angular.element(li).find("a") for li in lis) @buttons = {} @@ -83,41 +83,36 @@ class PaginationGUI n = parseInt(p) @pages.push(n) if !isNaN(n) - @current_page = _.find(lis, (li) -> angular.element(li).hasClass("active")) - @current_page = parseInt(angular.element(@current_page).find("a").html()) + @currentPage = _.find(lis, (li) -> angular.element(li).hasClass("active")) + @currentPage = parseInt(angular.element(@currentPage).find("a").html()) click: (button) -> click(@buttons[button]) @reload() class GUI - constructor: (@table, @pagination, @scope, @variable_names) -> + constructor: (@table, @pagination, @scope, @variableNames) -> reload: () -> @table.reload() if @table? @pagination.reload() if @pagination? - alter_scope: (f) -> - f(new ScopeWrapper(@scope), @variable_names) + alterScope: (f) -> + f(new ScopeWrapper(@scope), @variableNames) @scope.$digest() @reload() - click_pagination: (button) -> + clickPagination: (button) -> throw "no pagination element available" unless @pagination? @pagination.click(button) @table.reload() - click_table_header: (index) -> - @table.click_header(index) - - - click = (el) -> ev = document.createEvent("MouseEvent") - ev.initMouseEvent "click", true, true, window, null, 0, 0, 0, 0, false, false, false, false, 0, null - el.dispatchEvent ev + ev.initMouseEvent("click", true, true, window, null, 0, 0, 0, 0, false, false, false, false, 0, null) + el.dispatchEvent(ev) return # currently untested # - enabled/disabled buttons -# - fill last page \ No newline at end of file +# - fill last page From d8e4bdb94e5c0b75b4a33c3b5aab899ee927d222 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 21 Sep 2014 19:38:33 +0200 Subject: [PATCH 170/190] recompile --- dist/angular-table.js | 341 +++++++++++++++++++------------------- dist/angular-table.min.js | 2 +- 2 files changed, 170 insertions(+), 173 deletions(-) diff --git a/dist/angular-table.js b/dist/angular-table.js index 0fa3a5f..341f946 100644 --- a/dist/angular-table.js +++ b/dist/angular-table.js @@ -3,39 +3,37 @@ // license: MIT // homepage: http://github.com/samu/angular-table (function() { - var ColumnConfiguration, ConfigurationVariableNames, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, irk_number_of_pages, pagination_template, + var ColumnConfiguration, PageSequence, PaginatedSetup, ScopeConfigWrapper, Setup, StandardSetup, Table, TableConfiguration, configurationVariableNames, paginationTemplate, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; angular.module("angular-table", []); - irk_number_of_pages = "number_of_pages"; - ColumnConfiguration = (function() { - function ColumnConfiguration(body_markup, header_markup) { - this.attribute = body_markup.attribute; - this.title = body_markup.title; - this.sortable = body_markup.sortable; - this.width = body_markup.width; - this.initialSorting = body_markup.initialSorting; - if (header_markup) { - this.custom_content = header_markup.custom_content; - this.attributes = header_markup.attributes; + function ColumnConfiguration(bodyMarkup, headerMarkup) { + this.attribute = bodyMarkup.attribute; + this.title = bodyMarkup.title; + this.sortable = bodyMarkup.sortable; + this.width = bodyMarkup.width; + this.initialSorting = bodyMarkup.initialSorting; + if (headerMarkup) { + this.customContent = headerMarkup.customContent; + this.attributes = headerMarkup.attributes; } } - ColumnConfiguration.prototype.create_element = function() { + ColumnConfiguration.prototype.createElement = function() { var th; return th = angular.element(document.createElement("th")); }; - ColumnConfiguration.prototype.render_title = function(element) { - return element.html(this.custom_content || this.title); + ColumnConfiguration.prototype.renderTitle = function(element) { + return element.html(this.customContent || this.title); }; - ColumnConfiguration.prototype.render_attributes = function(element) { + ColumnConfiguration.prototype.renderAttributes = function(element) { var attribute, _i, _len, _ref, _results; - if (this.custom_content) { + if (this.customContent) { _ref = this.attributes; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { @@ -46,7 +44,7 @@ } }; - ColumnConfiguration.prototype.render_sorting = function(element) { + ColumnConfiguration.prototype.renderSorting = function(element) { var icon; if (this.sortable) { element.attr("ng-click", "predicate = '" + this.attribute + "'; descending = !descending;"); @@ -56,17 +54,17 @@ } }; - ColumnConfiguration.prototype.render_width = function(element) { + ColumnConfiguration.prototype.renderWidth = function(element) { return element.attr("width", this.width); }; - ColumnConfiguration.prototype.render_html = function() { + ColumnConfiguration.prototype.renderHtml = function() { var th; - th = this.create_element(); - this.render_title(th); - this.render_attributes(th); - this.render_sorting(th); - this.render_width(th); + th = this.createElement(); + this.renderTitle(th); + this.renderAttributes(th); + this.renderSorting(th); + this.renderWidth(th); return th; }; @@ -74,49 +72,49 @@ })(); - ConfigurationVariableNames = (function() { - function ConfigurationVariableNames(config_object_name) { - this.config_object_name = config_object_name; - this.items_per_page = "" + this.config_object_name + ".itemsPerPage"; - this.sort_context = "" + this.config_object_name + ".sortContext"; - this.fill_last_page = "" + this.config_object_name + ".fillLastPage"; - this.max_pages = "" + this.config_object_name + ".maxPages"; - this.current_page = "" + this.config_object_name + ".currentPage"; + configurationVariableNames = (function() { + function configurationVariableNames(configObjectName) { + this.configObjectName = configObjectName; + this.itemsPerPage = "" + this.configObjectName + ".itemsPerPage"; + this.sortContext = "" + this.configObjectName + ".sortContext"; + this.fillLastPage = "" + this.configObjectName + ".fillLastPage"; + this.maxPages = "" + this.configObjectName + ".maxPages"; + this.currentPage = "" + this.configObjectName + ".currentPage"; } - return ConfigurationVariableNames; + return configurationVariableNames; })(); ScopeConfigWrapper = (function() { - function ScopeConfigWrapper(scope, configuration_variable_names, list_name) { + function ScopeConfigWrapper(scope, configurationVariableNames, listName) { this.scope = scope; - this.configuration_variable_names = configuration_variable_names; - this.list_name = list_name; + this.configurationVariableNames = configurationVariableNames; + this.listName = listName; } - ScopeConfigWrapper.prototype.get_list = function() { - return this.scope.$eval(this.list_name); + ScopeConfigWrapper.prototype.getList = function() { + return this.scope.$eval(this.listName); }; - ScopeConfigWrapper.prototype.get_items_per_page = function() { - return this.scope.$eval(this.configuration_variable_names.items_per_page) || 10; + ScopeConfigWrapper.prototype.getItemsPerPage = function() { + return this.scope.$eval(this.configurationVariableNames.itemsPerPage) || 10; }; - ScopeConfigWrapper.prototype.get_current_page = function() { - return this.scope.$eval(this.configuration_variable_names.current_page) || 0; + ScopeConfigWrapper.prototype.getCurrentPage = function() { + return this.scope.$eval(this.configurationVariableNames.currentPage) || 0; }; - ScopeConfigWrapper.prototype.get_max_pages = function() { - return this.scope.$eval(this.configuration_variable_names.max_pages) || void 0; + ScopeConfigWrapper.prototype.getMaxPages = function() { + return this.scope.$eval(this.configurationVariableNames.maxPages) || void 0; }; - ScopeConfigWrapper.prototype.get_sort_context = function() { - return this.scope.$eval(this.configuration_variable_names.sort_context) || 'global'; + ScopeConfigWrapper.prototype.getSortContext = function() { + return this.scope.$eval(this.configurationVariableNames.sortContext) || 'global'; }; - ScopeConfigWrapper.prototype.set_current_page = function(current_page) { - return this.scope.$eval("" + this.configuration_variable_names.current_page + "=" + current_page); + ScopeConfigWrapper.prototype.setCurrentPage = function(currentPage) { + return this.scope.$eval("" + this.configurationVariableNames.currentPage + "=" + currentPage); }; return ScopeConfigWrapper; @@ -124,14 +122,14 @@ })(); TableConfiguration = (function() { - function TableConfiguration(table_element, attributes) { - this.table_element = table_element; + function TableConfiguration(tableElement, attributes) { + this.tableElement = tableElement; this.attributes = attributes; this.id = this.attributes.id; this.config = this.attributes.atConfig; this.paginated = this.attributes.atPaginated != null; this.list = this.attributes.atList; - this.create_column_configurations(); + this.createColumnConfigurations(); } TableConfiguration.prototype.capitaliseFirstLetter = function(string) { @@ -174,7 +172,7 @@ return void 0; }; - TableConfiguration.prototype.collect_header_markup = function(table) { + TableConfiguration.prototype.collectHeaderMarkup = function(table) { var customHeaderMarkups, th, tr, _i, _len, _ref; customHeaderMarkups = {}; tr = table.find("tr"); @@ -183,14 +181,14 @@ th = _ref[_i]; th = angular.element(th); customHeaderMarkups[th.attr("at-attribute")] = { - custom_content: th.html(), + customContent: th.html(), attributes: th[0].attributes }; } return customHeaderMarkups; }; - TableConfiguration.prototype.collect_body_markup = function(table) { + TableConfiguration.prototype.collectBodyMarkup = function(table) { var attribute, bodyDefinition, initialSorting, sortable, td, title, width, _i, _len, _ref; bodyDefinition = []; _ref = table.find("td"); @@ -213,16 +211,15 @@ return bodyDefinition; }; - TableConfiguration.prototype.create_column_configurations = function() { - var body_markup, header_markup, i, _i, _len; - header_markup = this.collect_header_markup(this.table_element); - body_markup = this.collect_body_markup(this.table_element); - this.column_configurations = []; - for (_i = 0, _len = body_markup.length; _i < _len; _i++) { - i = body_markup[_i]; - this.column_configurations.push(new ColumnConfiguration(i, header_markup[i.attribute])); + TableConfiguration.prototype.createColumnConfigurations = function() { + var bodyMarkup, headerMarkup, i, _i, _len; + headerMarkup = this.collectHeaderMarkup(this.tableElement); + bodyMarkup = this.collectBodyMarkup(this.tableElement); + this.columnConfigurations = []; + for (_i = 0, _len = bodyMarkup.length; _i < _len; _i++) { + i = bodyMarkup[_i]; + this.columnConfigurations.push(new ColumnConfiguration(i, headerMarkup[i.attribute])); } - return this.column_configurations; }; return TableConfiguration; @@ -247,7 +244,7 @@ StandardSetup = (function(_super) { __extends(StandardSetup, _super); - function StandardSetup(configuration_variable_names, list) { + function StandardSetup(configurationVariableNames, list) { this.list = list; this.repeatString = "item in " + this.list + " | orderBy:predicate:descending"; } @@ -265,9 +262,9 @@ PaginatedSetup = (function(_super) { __extends(PaginatedSetup, _super); - function PaginatedSetup(configuration_variable_names) { - this.configuration_variable_names = configuration_variable_names; - this.repeatString = "item in sorted_and_paginated_list"; + function PaginatedSetup(configurationVariableNames) { + this.configurationVariableNames = configurationVariableNames; + this.repeatString = "item in sortedAndPaginatedList"; } PaginatedSetup.prototype.compile = function(element) { @@ -280,28 +277,28 @@ tdString += " "; } fillerTr = angular.element(document.createElement("tr")); - fillerTr.attr("ng-show", this.configuration_variable_names.fill_last_page); + fillerTr.attr("ng-show", this.configurationVariableNames.fillLastPage); fillerTr.html(tdString); - fillerTr.attr("ng-repeat", "item in filler_array"); + fillerTr.attr("ng-repeat", "item in fillerArray"); tbody.append(fillerTr); }; PaginatedSetup.prototype.link = function($scope, $element, $attributes, $filter) { - var cvn, get_filler_array, get_sorted_and_paginated_list, update, w; - cvn = this.configuration_variable_names; + var cvn, getFillerArray, getSortedAndPaginatedList, update, w; + cvn = this.configurationVariableNames; w = new ScopeConfigWrapper($scope, cvn, $attributes.atList); - get_sorted_and_paginated_list = function(list, current_page, items_per_page, sort_context, predicate, descending, $filter) { - var from_page, val; + getSortedAndPaginatedList = function(list, currentPage, itemsPerPage, sortContext, predicate, descending, $filter) { + var fromPage, val; if (list) { val = list; - from_page = items_per_page * current_page - list.length; - if (sort_context === "global") { + fromPage = itemsPerPage * currentPage - list.length; + if (sortContext === "global") { val = $filter("orderBy")(val, predicate, descending); - val = $filter("limitTo")(val, from_page); - val = $filter("limitTo")(val, items_per_page); + val = $filter("limitTo")(val, fromPage); + val = $filter("limitTo")(val, itemsPerPage); } else { - val = $filter("limitTo")(val, from_page); - val = $filter("limitTo")(val, items_per_page); + val = $filter("limitTo")(val, fromPage); + val = $filter("limitTo")(val, itemsPerPage); val = $filter("orderBy")(val, predicate, descending); } return val; @@ -309,19 +306,19 @@ return []; } }; - get_filler_array = function(list, current_page, number_of_pages, items_per_page) { + getFillerArray = function(list, currentPage, numberOfPages, itemsPerPage) { var fillerLength, itemCountOnLastPage, x, _i, _j, _ref, _ref1, _ref2, _results, _results1; - items_per_page = parseInt(items_per_page); + itemsPerPage = parseInt(itemsPerPage); if (list.length <= 0) { _results = []; - for (x = _i = 0, _ref = items_per_page - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { + for (x = _i = 0, _ref = itemsPerPage - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; x = 0 <= _ref ? ++_i : --_i) { _results.push(x); } return _results; - } else if (current_page === number_of_pages - 1) { - itemCountOnLastPage = list.length % items_per_page; + } else if (currentPage === numberOfPages - 1) { + itemCountOnLastPage = list.length % itemsPerPage; if (itemCountOnLastPage !== 0) { - fillerLength = items_per_page - itemCountOnLastPage - 1; + fillerLength = itemsPerPage - itemCountOnLastPage - 1; _results1 = []; for (x = _j = _ref1 = list.length, _ref2 = list.length + fillerLength; _ref1 <= _ref2 ? _j <= _ref2 : _j >= _ref2; x = _ref1 <= _ref2 ? ++_j : --_j) { _results1.push(x); @@ -334,24 +331,24 @@ }; update = function() { var nop; - $scope.sorted_and_paginated_list = get_sorted_and_paginated_list(w.get_list(), w.get_current_page(), w.get_items_per_page(), w.get_sort_context(), $scope.predicate, $scope.descending, $filter); - nop = Math.ceil(w.get_list().length / w.get_items_per_page()); - return $scope.filler_array = get_filler_array(w.get_list(), w.get_current_page(), nop, w.get_items_per_page()); + $scope.sortedAndPaginatedList = getSortedAndPaginatedList(w.getList(), w.getCurrentPage(), w.getItemsPerPage(), w.getSortContext(), $scope.predicate, $scope.descending, $filter); + nop = Math.ceil(w.getList().length / w.getItemsPerPage()); + return $scope.fillerArray = getFillerArray(w.getList(), w.getCurrentPage(), nop, w.getItemsPerPage()); }; - $scope.$watch(cvn.current_page, function() { + $scope.$watch(cvn.currentPage, function() { return update(); }); - $scope.$watch(cvn.items_per_page, function() { + $scope.$watch(cvn.itemsPerPage, function() { return update(); }); - $scope.$watch(cvn.sort_context, function() { + $scope.$watch(cvn.sortContext, function() { return update(); }); $scope.$watchCollection($attributes.atList, function() { return update(); }); $scope.$watch("" + $attributes.atList + ".length", function() { - $scope[irk_number_of_pages] = Math.ceil(w.get_list().length / w.get_items_per_page()); + $scope.numberOfPages = Math.ceil(w.getList().length / w.getItemsPerPage()); return update(); }); $scope.$watch("predicate", function() { @@ -367,24 +364,24 @@ })(Setup); Table = (function() { - function Table(element, table_configuration, configuration_variable_names) { + function Table(element, tableConfiguration, configurationVariableNames) { this.element = element; - this.table_configuration = table_configuration; - this.configuration_variable_names = configuration_variable_names; + this.tableConfiguration = tableConfiguration; + this.configurationVariableNames = configurationVariableNames; } Table.prototype.constructHeader = function() { var i, tr, _i, _len, _ref; tr = angular.element(document.createElement("tr")); - _ref = this.table_configuration.column_configurations; + _ref = this.tableConfiguration.columnConfigurations; for (_i = 0, _len = _ref.length; _i < _len; _i++) { i = _ref[_i]; - tr.append(i.render_html()); + tr.append(i.renderHtml()); } return tr; }; - Table.prototype.setup_header = function() { + Table.prototype.setupHeader = function() { var header, thead, tr; thead = this.element.find("thead"); if (thead) { @@ -395,23 +392,23 @@ } }; - Table.prototype.get_setup = function() { - if (this.table_configuration.paginated) { - return new PaginatedSetup(this.configuration_variable_names); + Table.prototype.getSetup = function() { + if (this.tableConfiguration.paginated) { + return new PaginatedSetup(this.configurationVariableNames); } else { - return new StandardSetup(this.configuration_variable_names, this.table_configuration.list); + return new StandardSetup(this.configurationVariableNames, this.tableConfiguration.list); } }; Table.prototype.compile = function() { - this.setup_header(); - this.setup = this.get_setup(); + this.setupHeader(); + this.setup = this.getSetup(); return this.setup.compile(this.element); }; - Table.prototype.setup_initial_sorting = function($scope) { + Table.prototype.setupInitialSorting = function($scope) { var bd, _i, _len, _ref, _results; - _ref = this.table_configuration.column_configurations; + _ref = this.tableConfiguration.columnConfigurations; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { bd = _ref[_i]; @@ -429,9 +426,9 @@ }; Table.prototype.post = function($scope, $element, $attributes, $filter) { - this.setup_initial_sorting($scope); + this.setupInitialSorting($scope); if (!$scope.getSortIcon) { - $scope.getSortIcon = function(predicate, current_predicate) { + $scope.getSortIcon = function(predicate, currentPredicate) { if (predicate !== $scope.predicate) { return "glyphicon glyphicon-minus"; } @@ -450,14 +447,14 @@ })(); PageSequence = (function() { - function PageSequence(lower_bound, upper_bound, start, length) { - this.lower_bound = lower_bound != null ? lower_bound : 0; - this.upper_bound = upper_bound != null ? upper_bound : 1; + function PageSequence(lowerBound, upperBound, start, length) { + this.lowerBound = lowerBound != null ? lowerBound : 0; + this.upperBound = upperBound != null ? upperBound : 1; if (start == null) { start = 0; } this.length = length != null ? length : 1; - if (this.length > (this.upper_bound - this.lower_bound)) { + if (this.length > (this.upperBound - this.lowerBound)) { throw "sequence is too long"; } this.data = this.generate(start); @@ -465,10 +462,10 @@ PageSequence.prototype.generate = function(start) { var x, _i, _ref, _results; - if (start > (this.upper_bound - this.length)) { - start = this.upper_bound - this.length; - } else if (start < this.lower_bound) { - start = this.lower_bound; + if (start > (this.upperBound - this.length)) { + start = this.upperBound - this.length; + } else if (start < this.lowerBound) { + start = this.lowerBound; } _results = []; for (x = _i = start, _ref = parseInt(start) + parseInt(this.length) - 1; start <= _ref ? _i <= _ref : _i >= _ref; x = start <= _ref ? ++_i : --_i) { @@ -477,40 +474,40 @@ return _results; }; - PageSequence.prototype.reset_parameters = function(lower_bound, upper_bound, length) { - this.lower_bound = lower_bound; - this.upper_bound = upper_bound; + PageSequence.prototype.resetParameters = function(lowerBound, upperBound, length) { + this.lowerBound = lowerBound; + this.upperBound = upperBound; this.length = length; - if (this.length > (this.upper_bound - this.lower_bound)) { + if (this.length > (this.upperBound - this.lowerBound)) { throw "sequence is too long"; } return this.data = this.generate(this.data[0]); }; PageSequence.prototype.relocate = function(distance) { - var new_start; - new_start = this.data[0] + distance; - return this.data = this.generate(new_start, new_start + this.length); + var newStart; + newStart = this.data[0] + distance; + return this.data = this.generate(newStart, newStart + this.length); }; - PageSequence.prototype.realign_greedy = function(page) { - var new_start; + PageSequence.prototype.realignGreedy = function(page) { + var newStart; if (page < this.data[0]) { - new_start = page; - return this.data = this.generate(new_start); + newStart = page; + return this.data = this.generate(newStart); } else if (page > this.data[this.length - 1]) { - new_start = page - (this.length - 1); - return this.data = this.generate(new_start); + newStart = page - (this.length - 1); + return this.data = this.generate(newStart); } }; - PageSequence.prototype.realign_generous = function(page) {}; + PageSequence.prototype.realignGenerous = function(page) {}; return PageSequence; })(); - pagination_template = ""; + paginationTemplate = ""; angular.module("angular-table").directive("atTable", [ "$filter", function($filter) { @@ -520,7 +517,7 @@ compile: function(element, attributes, transclude) { var cvn, table, tc; tc = new TableConfiguration(element, attributes); - cvn = new ConfigurationVariableNames(attributes.atConfig); + cvn = new configurationVariableNames(attributes.atConfig); table = new Table(element, tc, cvn); table.compile(); return { @@ -539,68 +536,68 @@ restrict: "E", scope: true, replace: true, - template: pagination_template, + template: paginationTemplate, link: function($scope, $element, $attributes) { - var cvn, get_number_of_pages, keep_in_bounds, set_number_of_pages, update, w; - cvn = new ConfigurationVariableNames($attributes.atConfig); + var cvn, getNumberOfPages, keepInBounds, setNumberOfPages, update, w; + cvn = new configurationVariableNames($attributes.atConfig); w = new ScopeConfigWrapper($scope, cvn, $attributes.atList); - keep_in_bounds = function(val, min, max) { + keepInBounds = function(val, min, max) { val = Math.max(min, val); return Math.min(max, val); }; - get_number_of_pages = function() { - return $scope[irk_number_of_pages]; + getNumberOfPages = function() { + return $scope.numberOfPages; }; - set_number_of_pages = function(number_of_pages) { - return $scope[irk_number_of_pages] = number_of_pages; + setNumberOfPages = function(numberOfPages) { + return $scope.numberOfPages = numberOfPages; }; update = function(reset) { - var new_number_of_pages, pages_to_display; - if (w.get_list()) { - if (w.get_list().length > 0) { - new_number_of_pages = Math.ceil(w.get_list().length / w.get_items_per_page()); - set_number_of_pages(new_number_of_pages); - if ($scope.show_sectioning()) { - pages_to_display = w.get_max_pages(); + var newNumberOfPages, pagesToDisplay; + if (w.getList()) { + if (w.getList().length > 0) { + newNumberOfPages = Math.ceil(w.getList().length / w.getItemsPerPage()); + setNumberOfPages(newNumberOfPages); + if ($scope.showSectioning()) { + pagesToDisplay = w.getMaxPages(); } else { - pages_to_display = new_number_of_pages; + pagesToDisplay = newNumberOfPages; } - $scope.page_sequence.reset_parameters(0, new_number_of_pages, pages_to_display); - w.set_current_page(keep_in_bounds(w.get_current_page(), 0, get_number_of_pages() - 1)); - return $scope.page_sequence.realign_greedy(w.get_current_page()); + $scope.pageSequence.resetParameters(0, newNumberOfPages, pagesToDisplay); + w.setCurrentPage(keepInBounds(w.getCurrentPage(), 0, getNumberOfPages() - 1)); + return $scope.pageSequence.realignGreedy(w.getCurrentPage()); } else { - set_number_of_pages(1); - $scope.page_sequence.reset_parameters(0, 1, 1); - w.set_current_page(0); - return $scope.page_sequence.realign_greedy(0); + setNumberOfPages(1); + $scope.pageSequence.resetParameters(0, 1, 1); + w.setCurrentPage(0); + return $scope.pageSequence.realignGreedy(0); } } }; - $scope.show_sectioning = function() { - return w.get_max_pages() && get_number_of_pages() > w.get_max_pages(); + $scope.showSectioning = function() { + return w.getMaxPages() && getNumberOfPages() > w.getMaxPages(); }; - $scope.get_current_page = function() { - return w.get_current_page(); + $scope.getCurrentPage = function() { + return w.getCurrentPage(); }; - $scope.step_page = function(step) { + $scope.stepPage = function(step) { step = parseInt(step); - w.set_current_page(keep_in_bounds(w.get_current_page() + step, 0, get_number_of_pages() - 1)); - return $scope.page_sequence.realign_greedy(w.get_current_page()); + w.setCurrentPage(keepInBounds(w.getCurrentPage() + step, 0, getNumberOfPages() - 1)); + return $scope.pageSequence.realignGreedy(w.getCurrentPage()); }; - $scope.go_to_page = function(page) { - return w.set_current_page(page); + $scope.goToPage = function(page) { + return w.setCurrentPage(page); }; - $scope.jump_back = function() { - return $scope.step_page(-w.get_max_pages()); + $scope.jumpBack = function() { + return $scope.stepPage(-w.getMaxPages()); }; - $scope.jump_ahead = function() { - return $scope.step_page(w.get_max_pages()); + $scope.jumpAhead = function() { + return $scope.stepPage(w.getMaxPages()); }; - $scope.page_sequence = new PageSequence(); - $scope.$watch(cvn.items_per_page, function() { + $scope.pageSequence = new PageSequence(); + $scope.$watch(cvn.itemsPerPage, function() { return update(); }); - $scope.$watch(cvn.max_pages, function() { + $scope.$watch(cvn.maxPages, function() { return update(); }); $scope.$watch($attributes.atList, function() { diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js index b1cb68a..0c3bb00 100644 --- a/dist/angular-table.min.js +++ b/dist/angular-table.min.js @@ -2,4 +2,4 @@ // version: 1.0.0 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var a,b,c,d,e,f,g,h,i,j,k,l={}.hasOwnProperty,m=function(a,b){function c(){this.constructor=a}for(var d in b)l.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),j="number_of_pages",a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.custom_content=b.custom_content,this.attributes=b.attributes)}return a.prototype.create_element=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.render_title=function(a){return a.html(this.custom_content||this.title)},a.prototype.render_attributes=function(a){var b,c,d,e,f;if(this.custom_content){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.render_sorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.render_width=function(a){return a.attr("width",this.width)},a.prototype.render_html=function(){var a;return a=this.create_element(),this.render_title(a),this.render_attributes(a),this.render_sorting(a),this.render_width(a),a},a}(),b=function(){function a(a){this.config_object_name=a,this.items_per_page=""+this.config_object_name+".itemsPerPage",this.sort_context=""+this.config_object_name+".sortContext",this.fill_last_page=""+this.config_object_name+".fillLastPage",this.max_pages=""+this.config_object_name+".maxPages",this.current_page=""+this.config_object_name+".currentPage"}return a}(),e=function(){function a(a,b,c){this.scope=a,this.configuration_variable_names=b,this.list_name=c}return a.prototype.get_list=function(){return this.scope.$eval(this.list_name)},a.prototype.get_items_per_page=function(){return this.scope.$eval(this.configuration_variable_names.items_per_page)||10},a.prototype.get_current_page=function(){return this.scope.$eval(this.configuration_variable_names.current_page)||0},a.prototype.get_max_pages=function(){return this.scope.$eval(this.configuration_variable_names.max_pages)||void 0},a.prototype.get_sort_context=function(){return this.scope.$eval(this.configuration_variable_names.sort_context)||"global"},a.prototype.set_current_page=function(a){return this.scope.$eval(""+this.configuration_variable_names.current_page+"="+a)},a}(),i=function(){function b(a,b){this.table_element=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.create_column_configurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collect_header_markup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={custom_content:c.html(),attributes:c[0].attributes};return b},b.prototype.collect_body_markup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.create_column_configurations=function(){var b,c,d,e,f;for(c=this.collect_header_markup(this.table_element),b=this.collect_body_markup(this.table_element),this.column_configurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.column_configurations.push(new a(d,c[d.attribute]));return this.column_configurations},b}(),f=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),g=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return m(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(f),d=function(a){function b(a){this.configuration_variable_names=a,this.repeatString="item in sorted_and_paginated_list"}return m(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configuration_variable_names.fill_last_page),b.html(e),b.attr("ng-repeat","item in filler_array"),c.append(b)},b.prototype.link=function(a,b,c,d){var f,g,h,i,k;return f=this.configuration_variable_names,k=new e(a,f,c.atList),h=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sorted_and_paginated_list=h(k.get_list(),k.get_current_page(),k.get_items_per_page(),k.get_sort_context(),a.predicate,a.descending,d),b=Math.ceil(k.get_list().length/k.get_items_per_page()),a.filler_array=g(k.get_list(),k.get_current_page(),b,k.get_items_per_page())},a.$watch(f.current_page,function(){return i()}),a.$watch(f.items_per_page,function(){return i()}),a.$watch(f.sort_context,function(){return i()}),a.$watchCollection(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a[j]=Math.ceil(k.get_list().length/k.get_items_per_page()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(f),h=function(){function a(a,b,c){this.element=a,this.table_configuration=b,this.configuration_variable_names=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.table_configuration.column_configurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.render_html());return b},a.prototype.setup_header=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.get_setup=function(){return this.table_configuration.paginated?new d(this.configuration_variable_names):new g(this.configuration_variable_names,this.table_configuration.list)},a.prototype.compile=function(){return this.setup_header(),this.setup=this.get_setup(),this.setup.compile(this.element)},a.prototype.setup_initial_sorting=function(a){var b,c,d,e,f;for(e=this.table_configuration.column_configurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setup_initial_sorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),c=function(){function a(a,b,c,d){if(this.lower_bound=null!=a?a:0,this.upper_bound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upper_bound-this.length?a=this.upper_bound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.reset_parameters=function(a,b,c){if(this.lower_bound=a,this.upper_bound=b,this.length=c,this.length>this.upper_bound-this.lower_bound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realign_greedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realign_generous=function(){},a}(),k="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(c,d){var e,f,g;return g=new i(c,d),e=new b(d.atConfig),f=new h(c,g,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:k,link:function(a,d,f){var g,h,i,k,l,m;return g=new b(f.atConfig),m=new e(a,g,f.atList),i=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},h=function(){return a[j]},k=function(b){return a[j]=b},l=function(){var b,c;return m.get_list()?m.get_list().length>0?(b=Math.ceil(m.get_list().length/m.get_items_per_page()),k(b),c=a.show_sectioning()?m.get_max_pages():b,a.page_sequence.reset_parameters(0,b,c),m.set_current_page(i(m.get_current_page(),0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())):(k(1),a.page_sequence.reset_parameters(0,1,1),m.set_current_page(0),a.page_sequence.realign_greedy(0)):void 0},a.show_sectioning=function(){return m.get_max_pages()&&h()>m.get_max_pages()},a.get_current_page=function(){return m.get_current_page()},a.step_page=function(b){return b=parseInt(b),m.set_current_page(i(m.get_current_page()+b,0,h()-1)),a.page_sequence.realign_greedy(m.get_current_page())},a.go_to_page=function(a){return m.set_current_page(a)},a.jump_back=function(){return a.step_page(-m.get_max_pages())},a.jump_ahead=function(){return a.step_page(m.get_max_pages())},a.page_sequence=new c,a.$watch(g.items_per_page,function(){return l()}),a.$watch(g.max_pages,function(){return l()}),a.$watch(f.atList,function(){return l()}),a.$watch(""+f.atList+".length",function(){return l()}),l()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var a,b,c,d,e,f,g,h,i,j,k={}.hasOwnProperty,l=function(a,b){function c(){this.constructor=a}for(var d in b)k.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.customContent=b.customContent,this.attributes=b.attributes)}return a.prototype.createElement=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.renderTitle=function(a){return a.html(this.customContent||this.title)},a.prototype.renderAttributes=function(a){var b,c,d,e,f;if(this.customContent){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.renderSorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.renderWidth=function(a){return a.attr("width",this.width)},a.prototype.renderHtml=function(){var a;return a=this.createElement(),this.renderTitle(a),this.renderAttributes(a),this.renderSorting(a),this.renderWidth(a),a},a}(),i=function(){function a(a){this.configObjectName=a,this.itemsPerPage=""+this.configObjectName+".itemsPerPage",this.sortContext=""+this.configObjectName+".sortContext",this.fillLastPage=""+this.configObjectName+".fillLastPage",this.maxPages=""+this.configObjectName+".maxPages",this.currentPage=""+this.configObjectName+".currentPage"}return a}(),d=function(){function a(a,b,c){this.scope=a,this.configurationVariableNames=b,this.listName=c}return a.prototype.getList=function(){return this.scope.$eval(this.listName)},a.prototype.getItemsPerPage=function(){return this.scope.$eval(this.configurationVariableNames.itemsPerPage)||10},a.prototype.getCurrentPage=function(){return this.scope.$eval(this.configurationVariableNames.currentPage)||0},a.prototype.getMaxPages=function(){return this.scope.$eval(this.configurationVariableNames.maxPages)||void 0},a.prototype.getSortContext=function(){return this.scope.$eval(this.configurationVariableNames.sortContext)||"global"},a.prototype.setCurrentPage=function(a){return this.scope.$eval(""+this.configurationVariableNames.currentPage+"="+a)},a}(),h=function(){function b(a,b){this.tableElement=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.createColumnConfigurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collectHeaderMarkup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={customContent:c.html(),attributes:c[0].attributes};return b},b.prototype.collectBodyMarkup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.createColumnConfigurations=function(){var b,c,d,e,f;for(c=this.collectHeaderMarkup(this.tableElement),b=this.collectBodyMarkup(this.tableElement),this.columnConfigurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.columnConfigurations.push(new a(d,c[d.attribute]))},b}(),e=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),f=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return l(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(e),c=function(a){function b(a){this.configurationVariableNames=a,this.repeatString="item in sortedAndPaginatedList"}return l(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configurationVariableNames.fillLastPage),b.html(e),b.attr("ng-repeat","item in fillerArray"),c.append(b)},b.prototype.link=function(a,b,c,e){var f,g,h,i,j;return f=this.configurationVariableNames,j=new d(a,f,c.atList),h=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sortedAndPaginatedList=h(j.getList(),j.getCurrentPage(),j.getItemsPerPage(),j.getSortContext(),a.predicate,a.descending,e),b=Math.ceil(j.getList().length/j.getItemsPerPage()),a.fillerArray=g(j.getList(),j.getCurrentPage(),b,j.getItemsPerPage())},a.$watch(f.currentPage,function(){return i()}),a.$watch(f.itemsPerPage,function(){return i()}),a.$watch(f.sortContext,function(){return i()}),a.$watchCollection(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a.numberOfPages=Math.ceil(j.getList().length/j.getItemsPerPage()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(e),g=function(){function a(a,b,c){this.element=a,this.tableConfiguration=b,this.configurationVariableNames=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.tableConfiguration.columnConfigurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.renderHtml());return b},a.prototype.setupHeader=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.getSetup=function(){return this.tableConfiguration.paginated?new c(this.configurationVariableNames):new f(this.configurationVariableNames,this.tableConfiguration.list)},a.prototype.compile=function(){return this.setupHeader(),this.setup=this.getSetup(),this.setup.compile(this.element)},a.prototype.setupInitialSorting=function(a){var b,c,d,e,f;for(e=this.tableConfiguration.columnConfigurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setupInitialSorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),b=function(){function a(a,b,c,d){if(this.lowerBound=null!=a?a:0,this.upperBound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upperBound-this.length?a=this.upperBound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.resetParameters=function(a,b,c){if(this.lowerBound=a,this.upperBound=b,this.length=c,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realignGreedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realignGenerous=function(){},a}(),j="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c){var d,e,f;return f=new h(b,c),d=new i(c.atConfig),e=new g(b,f,d),e.compile(),{post:function(b,c,d){return e.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:j,link:function(a,c,e){var f,g,h,j,k,l;return f=new i(e.atConfig),l=new d(a,f,e.atList),h=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},g=function(){return a.numberOfPages},j=function(b){return a.numberOfPages=b},k=function(){var b,c;return l.getList()?l.getList().length>0?(b=Math.ceil(l.getList().length/l.getItemsPerPage()),j(b),c=a.showSectioning()?l.getMaxPages():b,a.pageSequence.resetParameters(0,b,c),l.setCurrentPage(h(l.getCurrentPage(),0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())):(j(1),a.pageSequence.resetParameters(0,1,1),l.setCurrentPage(0),a.pageSequence.realignGreedy(0)):void 0},a.showSectioning=function(){return l.getMaxPages()&&g()>l.getMaxPages()},a.getCurrentPage=function(){return l.getCurrentPage()},a.stepPage=function(b){return b=parseInt(b),l.setCurrentPage(h(l.getCurrentPage()+b,0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())},a.goToPage=function(a){return l.setCurrentPage(a)},a.jumpBack=function(){return a.stepPage(-l.getMaxPages())},a.jumpAhead=function(){return a.stepPage(l.getMaxPages())},a.pageSequence=new b,a.$watch(f.itemsPerPage,function(){return k()}),a.$watch(f.maxPages,function(){return k()}),a.$watch(e.atList,function(){return k()}),a.$watch(""+e.atList+".length",function(){return k()}),k()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}).call(this); \ No newline at end of file From f4899462f7964e0522e131cb406112d60fd1b144 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 24 Sep 2014 10:35:15 +0200 Subject: [PATCH 171/190] update version --- Gruntfile.coffee | 2 +- dist/angular-table.js | 2 +- dist/angular-table.min.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gruntfile.coffee b/Gruntfile.coffee index e7cf941..af31692 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -1,4 +1,4 @@ -version = "1.0.0" +version = "1.0.3" banner = " // author: Samuel Mueller \n diff --git a/dist/angular-table.js b/dist/angular-table.js index 341f946..5fbd450 100644 --- a/dist/angular-table.js +++ b/dist/angular-table.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 1.0.0 +// version: 1.0.3 // license: MIT // homepage: http://github.com/samu/angular-table (function() { diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js index 0c3bb00..1a39d49 100644 --- a/dist/angular-table.min.js +++ b/dist/angular-table.min.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 1.0.0 +// version: 1.0.3 // license: MIT // homepage: http://github.com/samu/angular-table (function(){var a,b,c,d,e,f,g,h,i,j,k={}.hasOwnProperty,l=function(a,b){function c(){this.constructor=a}for(var d in b)k.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.customContent=b.customContent,this.attributes=b.attributes)}return a.prototype.createElement=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.renderTitle=function(a){return a.html(this.customContent||this.title)},a.prototype.renderAttributes=function(a){var b,c,d,e,f;if(this.customContent){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.renderSorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.renderWidth=function(a){return a.attr("width",this.width)},a.prototype.renderHtml=function(){var a;return a=this.createElement(),this.renderTitle(a),this.renderAttributes(a),this.renderSorting(a),this.renderWidth(a),a},a}(),i=function(){function a(a){this.configObjectName=a,this.itemsPerPage=""+this.configObjectName+".itemsPerPage",this.sortContext=""+this.configObjectName+".sortContext",this.fillLastPage=""+this.configObjectName+".fillLastPage",this.maxPages=""+this.configObjectName+".maxPages",this.currentPage=""+this.configObjectName+".currentPage"}return a}(),d=function(){function a(a,b,c){this.scope=a,this.configurationVariableNames=b,this.listName=c}return a.prototype.getList=function(){return this.scope.$eval(this.listName)},a.prototype.getItemsPerPage=function(){return this.scope.$eval(this.configurationVariableNames.itemsPerPage)||10},a.prototype.getCurrentPage=function(){return this.scope.$eval(this.configurationVariableNames.currentPage)||0},a.prototype.getMaxPages=function(){return this.scope.$eval(this.configurationVariableNames.maxPages)||void 0},a.prototype.getSortContext=function(){return this.scope.$eval(this.configurationVariableNames.sortContext)||"global"},a.prototype.setCurrentPage=function(a){return this.scope.$eval(""+this.configurationVariableNames.currentPage+"="+a)},a}(),h=function(){function b(a,b){this.tableElement=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.createColumnConfigurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collectHeaderMarkup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={customContent:c.html(),attributes:c[0].attributes};return b},b.prototype.collectBodyMarkup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.createColumnConfigurations=function(){var b,c,d,e,f;for(c=this.collectHeaderMarkup(this.tableElement),b=this.collectBodyMarkup(this.tableElement),this.columnConfigurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.columnConfigurations.push(new a(d,c[d.attribute]))},b}(),e=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),f=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return l(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(e),c=function(a){function b(a){this.configurationVariableNames=a,this.repeatString="item in sortedAndPaginatedList"}return l(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configurationVariableNames.fillLastPage),b.html(e),b.attr("ng-repeat","item in fillerArray"),c.append(b)},b.prototype.link=function(a,b,c,e){var f,g,h,i,j;return f=this.configurationVariableNames,j=new d(a,f,c.atList),h=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sortedAndPaginatedList=h(j.getList(),j.getCurrentPage(),j.getItemsPerPage(),j.getSortContext(),a.predicate,a.descending,e),b=Math.ceil(j.getList().length/j.getItemsPerPage()),a.fillerArray=g(j.getList(),j.getCurrentPage(),b,j.getItemsPerPage())},a.$watch(f.currentPage,function(){return i()}),a.$watch(f.itemsPerPage,function(){return i()}),a.$watch(f.sortContext,function(){return i()}),a.$watchCollection(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a.numberOfPages=Math.ceil(j.getList().length/j.getItemsPerPage()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(e),g=function(){function a(a,b,c){this.element=a,this.tableConfiguration=b,this.configurationVariableNames=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.tableConfiguration.columnConfigurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.renderHtml());return b},a.prototype.setupHeader=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.getSetup=function(){return this.tableConfiguration.paginated?new c(this.configurationVariableNames):new f(this.configurationVariableNames,this.tableConfiguration.list)},a.prototype.compile=function(){return this.setupHeader(),this.setup=this.getSetup(),this.setup.compile(this.element)},a.prototype.setupInitialSorting=function(a){var b,c,d,e,f;for(e=this.tableConfiguration.columnConfigurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setupInitialSorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),b=function(){function a(a,b,c,d){if(this.lowerBound=null!=a?a:0,this.upperBound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upperBound-this.length?a=this.upperBound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.resetParameters=function(a,b,c){if(this.lowerBound=a,this.upperBound=b,this.length=c,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realignGreedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realignGenerous=function(){},a}(),j="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c){var d,e,f;return f=new h(b,c),d=new i(c.atConfig),e=new g(b,f,d),e.compile(),{post:function(b,c,d){return e.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:j,link:function(a,c,e){var f,g,h,j,k,l;return f=new i(e.atConfig),l=new d(a,f,e.atList),h=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},g=function(){return a.numberOfPages},j=function(b){return a.numberOfPages=b},k=function(){var b,c;return l.getList()?l.getList().length>0?(b=Math.ceil(l.getList().length/l.getItemsPerPage()),j(b),c=a.showSectioning()?l.getMaxPages():b,a.pageSequence.resetParameters(0,b,c),l.setCurrentPage(h(l.getCurrentPage(),0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())):(j(1),a.pageSequence.resetParameters(0,1,1),l.setCurrentPage(0),a.pageSequence.realignGreedy(0)):void 0},a.showSectioning=function(){return l.getMaxPages()&&g()>l.getMaxPages()},a.getCurrentPage=function(){return l.getCurrentPage()},a.stepPage=function(b){return b=parseInt(b),l.setCurrentPage(h(l.getCurrentPage()+b,0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())},a.goToPage=function(a){return l.setCurrentPage(a)},a.jumpBack=function(){return a.stepPage(-l.getMaxPages())},a.jumpAhead=function(){return a.stepPage(l.getMaxPages())},a.pageSequence=new b,a.$watch(f.itemsPerPage,function(){return k()}),a.$watch(f.maxPages,function(){return k()}),a.$watch(e.atList,function(){return k()}),a.$watch(""+e.atList+".length",function(){return k()}),k()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}).call(this); \ No newline at end of file From ee3e507f6ae5da7076c920243ace4df876e98f0f Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 24 Sep 2014 11:19:35 +0200 Subject: [PATCH 172/190] update version --- bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bower.json b/bower.json index ffd817a..b57ab83 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "at-table", - "version": "1.0.1", + "version": "1.0.3", "homepage": "https://github.com/samu/angular-table", "authors": [ "Samuel Mueller" From f3389917a9bad26176d3883b0f688aa9f484506f Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 24 Sep 2014 11:19:42 +0200 Subject: [PATCH 173/190] update title in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9aa84b1..6b3fe15 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ Coffee Script, i highly recommend to [take look at it and try it out](http://cof It has a powerful and beautiful syntax and is easy to learn. You'll probably need no more than ~2 hours to learn about all the basic concepts. -### TDD +### Running the tests The code for this directive is well covered with tests, which can be run with PhantomJS and Karma. Run `npm install` to install the required packages. Then, run `karma start` to run the tests. Make sure all the tests pass before you send a pull request. From c97b53fbaa6a1ec3f5c373af6e808b8fbec18d21 Mon Sep 17 00:00:00 2001 From: lopix Date: Fri, 26 Sep 2014 18:57:08 +0100 Subject: [PATCH 174/190] Change names to CamelCase --- coffee/configuration/configuration_variable_names.coffee | 2 +- coffee/configuration/scope_config_wrapper.coffee | 4 ++-- coffee/directives/table/setup/paginated_setup.coffee | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/coffee/configuration/configuration_variable_names.coffee b/coffee/configuration/configuration_variable_names.coffee index e5aa59d..dfde420 100644 --- a/coffee/configuration/configuration_variable_names.coffee +++ b/coffee/configuration/configuration_variable_names.coffee @@ -5,5 +5,5 @@ class configurationVariableNames @fillLastPage = "#{@configObjectName}.fillLastPage" @maxPages = "#{@configObjectName}.maxPages" @currentPage = "#{@configObjectName}.currentPage" - @order_by = "#{@configObjectName}.orderBy" + @orderBy = "#{@configObjectName}.orderBy" diff --git a/coffee/configuration/scope_config_wrapper.coffee b/coffee/configuration/scope_config_wrapper.coffee index 192e1e7..3935fb0 100644 --- a/coffee/configuration/scope_config_wrapper.coffee +++ b/coffee/configuration/scope_config_wrapper.coffee @@ -19,6 +19,6 @@ class ScopeConfigWrapper setCurrentPage: (currentPage) -> @scope.$eval("#{@configurationVariableNames.currentPage}=#{currentPage}") - get_order_by: () -> - @scope.$eval(@configurationVariableNames.order_by) || 'orderBy' + getOrderBy: () -> + @scope.$eval(@configurationVariableNames.orderBy) || 'orderBy' diff --git a/coffee/directives/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee index cadd8b6..262f745 100644 --- a/coffee/directives/table/setup/paginated_setup.coffee +++ b/coffee/directives/table/setup/paginated_setup.coffee @@ -25,18 +25,18 @@ class PaginatedSetup extends Setup w = new ScopeConfigWrapper($scope, cvn, $attributes.atList) - getSortedAndPaginatedList = (list, currentPage, itemsPerPage, order_by, sortContext, predicate, descending, $filter) -> + getSortedAndPaginatedList = (list, currentPage, itemsPerPage, orderBy, sortContext, predicate, descending, $filter) -> if list val = list fromPage = itemsPerPage * currentPage - list.length if sortContext == "global" - val = $filter(order_by)(val, predicate, descending) + val = $filter(orderBy)(val, predicate, descending) val = $filter("limitTo")(val, fromPage) val = $filter("limitTo")(val, itemsPerPage) else val = $filter("limitTo")(val, fromPage) val = $filter("limitTo")(val, itemsPerPage) - val = $filter(order_by)(val, predicate, descending) + val = $filter(orderBy)(val, predicate, descending) return val else @@ -59,7 +59,7 @@ class PaginatedSetup extends Setup w.getList(), w.getCurrentPage(), w.getItemsPerPage(), - w.get_order_by(), + w.getOrderBy(), w.getSortContext(), $scope.predicate, $scope.descending, From eb82fc97c0324c72c96a691b30dfdbcb74c4bf5a Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sat, 11 Oct 2014 20:27:55 +0200 Subject: [PATCH 175/190] recompile and bump version --- Gruntfile.coffee | 2 +- bower.json | 2 +- dist/angular-table.js | 15 ++++++++++----- dist/angular-table.min.js | 4 ++-- package.json | 2 +- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Gruntfile.coffee b/Gruntfile.coffee index af31692..f480651 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -1,4 +1,4 @@ -version = "1.0.3" +version = "1.0.4" banner = " // author: Samuel Mueller \n diff --git a/bower.json b/bower.json index b57ab83..a484b08 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "at-table", - "version": "1.0.3", + "version": "1.0.4", "homepage": "https://github.com/samu/angular-table", "authors": [ "Samuel Mueller" diff --git a/dist/angular-table.js b/dist/angular-table.js index 5fbd450..0292316 100644 --- a/dist/angular-table.js +++ b/dist/angular-table.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 1.0.3 +// version: 1.0.4 // license: MIT // homepage: http://github.com/samu/angular-table (function() { @@ -80,6 +80,7 @@ this.fillLastPage = "" + this.configObjectName + ".fillLastPage"; this.maxPages = "" + this.configObjectName + ".maxPages"; this.currentPage = "" + this.configObjectName + ".currentPage"; + this.orderBy = "" + this.configObjectName + ".orderBy"; } return configurationVariableNames; @@ -117,6 +118,10 @@ return this.scope.$eval("" + this.configurationVariableNames.currentPage + "=" + currentPage); }; + ScopeConfigWrapper.prototype.getOrderBy = function() { + return this.scope.$eval(this.configurationVariableNames.orderBy) || 'orderBy'; + }; + return ScopeConfigWrapper; })(); @@ -287,19 +292,19 @@ var cvn, getFillerArray, getSortedAndPaginatedList, update, w; cvn = this.configurationVariableNames; w = new ScopeConfigWrapper($scope, cvn, $attributes.atList); - getSortedAndPaginatedList = function(list, currentPage, itemsPerPage, sortContext, predicate, descending, $filter) { + getSortedAndPaginatedList = function(list, currentPage, itemsPerPage, orderBy, sortContext, predicate, descending, $filter) { var fromPage, val; if (list) { val = list; fromPage = itemsPerPage * currentPage - list.length; if (sortContext === "global") { - val = $filter("orderBy")(val, predicate, descending); + val = $filter(orderBy)(val, predicate, descending); val = $filter("limitTo")(val, fromPage); val = $filter("limitTo")(val, itemsPerPage); } else { val = $filter("limitTo")(val, fromPage); val = $filter("limitTo")(val, itemsPerPage); - val = $filter("orderBy")(val, predicate, descending); + val = $filter(orderBy)(val, predicate, descending); } return val; } else { @@ -331,7 +336,7 @@ }; update = function() { var nop; - $scope.sortedAndPaginatedList = getSortedAndPaginatedList(w.getList(), w.getCurrentPage(), w.getItemsPerPage(), w.getSortContext(), $scope.predicate, $scope.descending, $filter); + $scope.sortedAndPaginatedList = getSortedAndPaginatedList(w.getList(), w.getCurrentPage(), w.getItemsPerPage(), w.getOrderBy(), w.getSortContext(), $scope.predicate, $scope.descending, $filter); nop = Math.ceil(w.getList().length / w.getItemsPerPage()); return $scope.fillerArray = getFillerArray(w.getList(), w.getCurrentPage(), nop, w.getItemsPerPage()); }; diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js index 1a39d49..6abde16 100644 --- a/dist/angular-table.min.js +++ b/dist/angular-table.min.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 1.0.3 +// version: 1.0.4 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var a,b,c,d,e,f,g,h,i,j,k={}.hasOwnProperty,l=function(a,b){function c(){this.constructor=a}for(var d in b)k.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.customContent=b.customContent,this.attributes=b.attributes)}return a.prototype.createElement=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.renderTitle=function(a){return a.html(this.customContent||this.title)},a.prototype.renderAttributes=function(a){var b,c,d,e,f;if(this.customContent){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.renderSorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.renderWidth=function(a){return a.attr("width",this.width)},a.prototype.renderHtml=function(){var a;return a=this.createElement(),this.renderTitle(a),this.renderAttributes(a),this.renderSorting(a),this.renderWidth(a),a},a}(),i=function(){function a(a){this.configObjectName=a,this.itemsPerPage=""+this.configObjectName+".itemsPerPage",this.sortContext=""+this.configObjectName+".sortContext",this.fillLastPage=""+this.configObjectName+".fillLastPage",this.maxPages=""+this.configObjectName+".maxPages",this.currentPage=""+this.configObjectName+".currentPage"}return a}(),d=function(){function a(a,b,c){this.scope=a,this.configurationVariableNames=b,this.listName=c}return a.prototype.getList=function(){return this.scope.$eval(this.listName)},a.prototype.getItemsPerPage=function(){return this.scope.$eval(this.configurationVariableNames.itemsPerPage)||10},a.prototype.getCurrentPage=function(){return this.scope.$eval(this.configurationVariableNames.currentPage)||0},a.prototype.getMaxPages=function(){return this.scope.$eval(this.configurationVariableNames.maxPages)||void 0},a.prototype.getSortContext=function(){return this.scope.$eval(this.configurationVariableNames.sortContext)||"global"},a.prototype.setCurrentPage=function(a){return this.scope.$eval(""+this.configurationVariableNames.currentPage+"="+a)},a}(),h=function(){function b(a,b){this.tableElement=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.createColumnConfigurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collectHeaderMarkup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={customContent:c.html(),attributes:c[0].attributes};return b},b.prototype.collectBodyMarkup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.createColumnConfigurations=function(){var b,c,d,e,f;for(c=this.collectHeaderMarkup(this.tableElement),b=this.collectBodyMarkup(this.tableElement),this.columnConfigurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.columnConfigurations.push(new a(d,c[d.attribute]))},b}(),e=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),f=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return l(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(e),c=function(a){function b(a){this.configurationVariableNames=a,this.repeatString="item in sortedAndPaginatedList"}return l(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configurationVariableNames.fillLastPage),b.html(e),b.attr("ng-repeat","item in fillerArray"),c.append(b)},b.prototype.link=function(a,b,c,e){var f,g,h,i,j;return f=this.configurationVariableNames,j=new d(a,f,c.atList),h=function(a,b,c,d,e,f,g){var h,i;return a?(i=a,h=c*b-a.length,"global"===d?(i=g("orderBy")(i,e,f),i=g("limitTo")(i,h),i=g("limitTo")(i,c)):(i=g("limitTo")(i,h),i=g("limitTo")(i,c),i=g("orderBy")(i,e,f)),i):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sortedAndPaginatedList=h(j.getList(),j.getCurrentPage(),j.getItemsPerPage(),j.getSortContext(),a.predicate,a.descending,e),b=Math.ceil(j.getList().length/j.getItemsPerPage()),a.fillerArray=g(j.getList(),j.getCurrentPage(),b,j.getItemsPerPage())},a.$watch(f.currentPage,function(){return i()}),a.$watch(f.itemsPerPage,function(){return i()}),a.$watch(f.sortContext,function(){return i()}),a.$watchCollection(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a.numberOfPages=Math.ceil(j.getList().length/j.getItemsPerPage()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(e),g=function(){function a(a,b,c){this.element=a,this.tableConfiguration=b,this.configurationVariableNames=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.tableConfiguration.columnConfigurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.renderHtml());return b},a.prototype.setupHeader=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.getSetup=function(){return this.tableConfiguration.paginated?new c(this.configurationVariableNames):new f(this.configurationVariableNames,this.tableConfiguration.list)},a.prototype.compile=function(){return this.setupHeader(),this.setup=this.getSetup(),this.setup.compile(this.element)},a.prototype.setupInitialSorting=function(a){var b,c,d,e,f;for(e=this.tableConfiguration.columnConfigurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setupInitialSorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),b=function(){function a(a,b,c,d){if(this.lowerBound=null!=a?a:0,this.upperBound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upperBound-this.length?a=this.upperBound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.resetParameters=function(a,b,c){if(this.lowerBound=a,this.upperBound=b,this.length=c,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realignGreedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realignGenerous=function(){},a}(),j="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c){var d,e,f;return f=new h(b,c),d=new i(c.atConfig),e=new g(b,f,d),e.compile(),{post:function(b,c,d){return e.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:j,link:function(a,c,e){var f,g,h,j,k,l;return f=new i(e.atConfig),l=new d(a,f,e.atList),h=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},g=function(){return a.numberOfPages},j=function(b){return a.numberOfPages=b},k=function(){var b,c;return l.getList()?l.getList().length>0?(b=Math.ceil(l.getList().length/l.getItemsPerPage()),j(b),c=a.showSectioning()?l.getMaxPages():b,a.pageSequence.resetParameters(0,b,c),l.setCurrentPage(h(l.getCurrentPage(),0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())):(j(1),a.pageSequence.resetParameters(0,1,1),l.setCurrentPage(0),a.pageSequence.realignGreedy(0)):void 0},a.showSectioning=function(){return l.getMaxPages()&&g()>l.getMaxPages()},a.getCurrentPage=function(){return l.getCurrentPage()},a.stepPage=function(b){return b=parseInt(b),l.setCurrentPage(h(l.getCurrentPage()+b,0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())},a.goToPage=function(a){return l.setCurrentPage(a)},a.jumpBack=function(){return a.stepPage(-l.getMaxPages())},a.jumpAhead=function(){return a.stepPage(l.getMaxPages())},a.pageSequence=new b,a.$watch(f.itemsPerPage,function(){return k()}),a.$watch(f.maxPages,function(){return k()}),a.$watch(e.atList,function(){return k()}),a.$watch(""+e.atList+".length",function(){return k()}),k()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var a,b,c,d,e,f,g,h,i,j,k={}.hasOwnProperty,l=function(a,b){function c(){this.constructor=a}for(var d in b)k.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.customContent=b.customContent,this.attributes=b.attributes)}return a.prototype.createElement=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.renderTitle=function(a){return a.html(this.customContent||this.title)},a.prototype.renderAttributes=function(a){var b,c,d,e,f;if(this.customContent){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.renderSorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.renderWidth=function(a){return a.attr("width",this.width)},a.prototype.renderHtml=function(){var a;return a=this.createElement(),this.renderTitle(a),this.renderAttributes(a),this.renderSorting(a),this.renderWidth(a),a},a}(),i=function(){function a(a){this.configObjectName=a,this.itemsPerPage=""+this.configObjectName+".itemsPerPage",this.sortContext=""+this.configObjectName+".sortContext",this.fillLastPage=""+this.configObjectName+".fillLastPage",this.maxPages=""+this.configObjectName+".maxPages",this.currentPage=""+this.configObjectName+".currentPage",this.orderBy=""+this.configObjectName+".orderBy"}return a}(),d=function(){function a(a,b,c){this.scope=a,this.configurationVariableNames=b,this.listName=c}return a.prototype.getList=function(){return this.scope.$eval(this.listName)},a.prototype.getItemsPerPage=function(){return this.scope.$eval(this.configurationVariableNames.itemsPerPage)||10},a.prototype.getCurrentPage=function(){return this.scope.$eval(this.configurationVariableNames.currentPage)||0},a.prototype.getMaxPages=function(){return this.scope.$eval(this.configurationVariableNames.maxPages)||void 0},a.prototype.getSortContext=function(){return this.scope.$eval(this.configurationVariableNames.sortContext)||"global"},a.prototype.setCurrentPage=function(a){return this.scope.$eval(""+this.configurationVariableNames.currentPage+"="+a)},a.prototype.getOrderBy=function(){return this.scope.$eval(this.configurationVariableNames.orderBy)||"orderBy"},a}(),h=function(){function b(a,b){this.tableElement=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.createColumnConfigurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collectHeaderMarkup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={customContent:c.html(),attributes:c[0].attributes};return b},b.prototype.collectBodyMarkup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.createColumnConfigurations=function(){var b,c,d,e,f;for(c=this.collectHeaderMarkup(this.tableElement),b=this.collectBodyMarkup(this.tableElement),this.columnConfigurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.columnConfigurations.push(new a(d,c[d.attribute]))},b}(),e=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),f=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return l(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(e),c=function(a){function b(a){this.configurationVariableNames=a,this.repeatString="item in sortedAndPaginatedList"}return l(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configurationVariableNames.fillLastPage),b.html(e),b.attr("ng-repeat","item in fillerArray"),c.append(b)},b.prototype.link=function(a,b,c,e){var f,g,h,i,j;return f=this.configurationVariableNames,j=new d(a,f,c.atList),h=function(a,b,c,d,e,f,g,h){var i,j;return a?(j=a,i=c*b-a.length,"global"===e?(j=h(d)(j,f,g),j=h("limitTo")(j,i),j=h("limitTo")(j,c)):(j=h("limitTo")(j,i),j=h("limitTo")(j,c),j=h(d)(j,f,g)),j):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sortedAndPaginatedList=h(j.getList(),j.getCurrentPage(),j.getItemsPerPage(),j.getOrderBy(),j.getSortContext(),a.predicate,a.descending,e),b=Math.ceil(j.getList().length/j.getItemsPerPage()),a.fillerArray=g(j.getList(),j.getCurrentPage(),b,j.getItemsPerPage())},a.$watch(f.currentPage,function(){return i()}),a.$watch(f.itemsPerPage,function(){return i()}),a.$watch(f.sortContext,function(){return i()}),a.$watchCollection(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a.numberOfPages=Math.ceil(j.getList().length/j.getItemsPerPage()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(e),g=function(){function a(a,b,c){this.element=a,this.tableConfiguration=b,this.configurationVariableNames=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.tableConfiguration.columnConfigurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.renderHtml());return b},a.prototype.setupHeader=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.getSetup=function(){return this.tableConfiguration.paginated?new c(this.configurationVariableNames):new f(this.configurationVariableNames,this.tableConfiguration.list)},a.prototype.compile=function(){return this.setupHeader(),this.setup=this.getSetup(),this.setup.compile(this.element)},a.prototype.setupInitialSorting=function(a){var b,c,d,e,f;for(e=this.tableConfiguration.columnConfigurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setupInitialSorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),b=function(){function a(a,b,c,d){if(this.lowerBound=null!=a?a:0,this.upperBound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upperBound-this.length?a=this.upperBound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.resetParameters=function(a,b,c){if(this.lowerBound=a,this.upperBound=b,this.length=c,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realignGreedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realignGenerous=function(){},a}(),j="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c){var d,e,f;return f=new h(b,c),d=new i(c.atConfig),e=new g(b,f,d),e.compile(),{post:function(b,c,d){return e.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:j,link:function(a,c,e){var f,g,h,j,k,l;return f=new i(e.atConfig),l=new d(a,f,e.atList),h=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},g=function(){return a.numberOfPages},j=function(b){return a.numberOfPages=b},k=function(){var b,c;return l.getList()?l.getList().length>0?(b=Math.ceil(l.getList().length/l.getItemsPerPage()),j(b),c=a.showSectioning()?l.getMaxPages():b,a.pageSequence.resetParameters(0,b,c),l.setCurrentPage(h(l.getCurrentPage(),0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())):(j(1),a.pageSequence.resetParameters(0,1,1),l.setCurrentPage(0),a.pageSequence.realignGreedy(0)):void 0},a.showSectioning=function(){return l.getMaxPages()&&g()>l.getMaxPages()},a.getCurrentPage=function(){return l.getCurrentPage()},a.stepPage=function(b){return b=parseInt(b),l.setCurrentPage(h(l.getCurrentPage()+b,0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())},a.goToPage=function(a){return l.setCurrentPage(a)},a.jumpBack=function(){return a.stepPage(-l.getMaxPages())},a.jumpAhead=function(){return a.stepPage(l.getMaxPages())},a.pageSequence=new b,a.$watch(f.itemsPerPage,function(){return k()}),a.$watch(f.maxPages,function(){return k()}),a.$watch(e.atList,function(){return k()}),a.$watch(""+e.atList+".length",function(){return k()}),k()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}).call(this); \ No newline at end of file diff --git a/package.json b/package.json index 052e92c..b8ee43f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-table", - "version": "1.0.3", + "version": "1.0.4", "author": "Samuel Mueller", "repository": { "type": "git", From c1c9f797c4d4c27bff65d6aba462e2f2560347a4 Mon Sep 17 00:00:00 2001 From: Victor D'Agata Date: Sun, 8 Feb 2015 21:38:58 -0500 Subject: [PATCH 176/190] Update bower.json Added main property so bower tasks can find the file to include --- bower.json | 1 + 1 file changed, 1 insertion(+) diff --git a/bower.json b/bower.json index a484b08..7b0c94b 100644 --- a/bower.json +++ b/bower.json @@ -2,6 +2,7 @@ "name": "at-table", "version": "1.0.4", "homepage": "https://github.com/samu/angular-table", + "main": "./dist/angular-table.js", "authors": [ "Samuel Mueller" ], From 3158f0a9452e29d561b07151fd9c5946018deccf Mon Sep 17 00:00:00 2001 From: didier amyot Date: Mon, 3 Aug 2015 14:14:57 -0400 Subject: [PATCH 177/190] used ng-bind instead of string interpolation. --- coffee/directives/at_implicit.coffee | 4 ++-- coffee/directives/pagination/pagination_template.coffee | 2 +- coffee/directives/table/setup/paginated_setup.coffee | 2 +- test/test_helper.coffee | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/coffee/directives/at_implicit.coffee b/coffee/directives/at_implicit.coffee index b89331c..84bbc1b 100644 --- a/coffee/directives/at_implicit.coffee +++ b/coffee/directives/at_implicit.coffee @@ -4,5 +4,5 @@ angular.module("angular-table").directive "atImplicit", [() -> compile: (element, attributes, transclude) -> attribute = element.attr("at-attribute") throw "at-implicit specified without at-attribute: #{element.html()}" if not attribute - element.append "{{item.#{attribute}}}" -] \ No newline at end of file + element.append "" +] diff --git a/coffee/directives/pagination/pagination_template.coffee b/coffee/directives/pagination/pagination_template.coffee index ca44d3d..0282925 100644 --- a/coffee/directives/pagination/pagination_template.coffee +++ b/coffee/directives/pagination/pagination_template.coffee @@ -14,7 +14,7 @@ paginationTemplate = "
  • - {{page + 1}} +
  • diff --git a/coffee/directives/table/setup/paginated_setup.coffee b/coffee/directives/table/setup/paginated_setup.coffee index 262f745..879112d 100644 --- a/coffee/directives/table/setup/paginated_setup.coffee +++ b/coffee/directives/table/setup/paginated_setup.coffee @@ -8,7 +8,7 @@ class PaginatedSetup extends Setup tds = element.find("td") tdString = "" for td in tds - tdString += " " + tdString += " " # TODO fillerTr = angular.element(document.createElement("tr")) diff --git a/test/test_helper.coffee b/test/test_helper.coffee index ba9e64a..dbcda49 100644 --- a/test/test_helper.coffee +++ b/test/test_helper.coffee @@ -55,7 +55,7 @@ class TableGUI reload: () -> @rows = _.map(@element.find("tr"), (row) -> _.map(angular.element(row).find("td"), (cell) -> - angular.element(cell).html() + angular.element(cell).find("span").html() ) ) @rows.shift() if @rows[0].length == 0 From d898b10472f147cc9369e0b7bb51f8fbfbd82e56 Mon Sep 17 00:00:00 2001 From: didier amyot Date: Mon, 3 Aug 2015 14:22:31 -0400 Subject: [PATCH 178/190] compile coffe script --- dist/angular-table.js | 6 +++--- dist/angular-table.min.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/angular-table.js b/dist/angular-table.js index 0292316..83b9f10 100644 --- a/dist/angular-table.js +++ b/dist/angular-table.js @@ -279,7 +279,7 @@ tdString = ""; for (_i = 0, _len = tds.length; _i < _len; _i++) { td = tds[_i]; - tdString += " "; + tdString += " "; } fillerTr = angular.element(document.createElement("tr")); fillerTr.attr("ng-show", this.configurationVariableNames.fillLastPage); @@ -512,7 +512,7 @@ })(); - paginationTemplate = ""; + paginationTemplate = ""; angular.module("angular-table").directive("atTable", [ "$filter", function($filter) { @@ -627,7 +627,7 @@ if (!attribute) { throw "at-implicit specified without at-attribute: " + (element.html()); } - return element.append("{{item." + attribute + "}}"); + return element.append(""); } }; } diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js index 6abde16..1ba2b0f 100644 --- a/dist/angular-table.min.js +++ b/dist/angular-table.min.js @@ -2,4 +2,4 @@ // version: 1.0.4 // license: MIT // homepage: http://github.com/samu/angular-table -(function(){var a,b,c,d,e,f,g,h,i,j,k={}.hasOwnProperty,l=function(a,b){function c(){this.constructor=a}for(var d in b)k.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.customContent=b.customContent,this.attributes=b.attributes)}return a.prototype.createElement=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.renderTitle=function(a){return a.html(this.customContent||this.title)},a.prototype.renderAttributes=function(a){var b,c,d,e,f;if(this.customContent){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.renderSorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.renderWidth=function(a){return a.attr("width",this.width)},a.prototype.renderHtml=function(){var a;return a=this.createElement(),this.renderTitle(a),this.renderAttributes(a),this.renderSorting(a),this.renderWidth(a),a},a}(),i=function(){function a(a){this.configObjectName=a,this.itemsPerPage=""+this.configObjectName+".itemsPerPage",this.sortContext=""+this.configObjectName+".sortContext",this.fillLastPage=""+this.configObjectName+".fillLastPage",this.maxPages=""+this.configObjectName+".maxPages",this.currentPage=""+this.configObjectName+".currentPage",this.orderBy=""+this.configObjectName+".orderBy"}return a}(),d=function(){function a(a,b,c){this.scope=a,this.configurationVariableNames=b,this.listName=c}return a.prototype.getList=function(){return this.scope.$eval(this.listName)},a.prototype.getItemsPerPage=function(){return this.scope.$eval(this.configurationVariableNames.itemsPerPage)||10},a.prototype.getCurrentPage=function(){return this.scope.$eval(this.configurationVariableNames.currentPage)||0},a.prototype.getMaxPages=function(){return this.scope.$eval(this.configurationVariableNames.maxPages)||void 0},a.prototype.getSortContext=function(){return this.scope.$eval(this.configurationVariableNames.sortContext)||"global"},a.prototype.setCurrentPage=function(a){return this.scope.$eval(""+this.configurationVariableNames.currentPage+"="+a)},a.prototype.getOrderBy=function(){return this.scope.$eval(this.configurationVariableNames.orderBy)||"orderBy"},a}(),h=function(){function b(a,b){this.tableElement=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.createColumnConfigurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collectHeaderMarkup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={customContent:c.html(),attributes:c[0].attributes};return b},b.prototype.collectBodyMarkup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.createColumnConfigurations=function(){var b,c,d,e,f;for(c=this.collectHeaderMarkup(this.tableElement),b=this.collectBodyMarkup(this.tableElement),this.columnConfigurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.columnConfigurations.push(new a(d,c[d.attribute]))},b}(),e=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),f=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return l(b,a),b.prototype.compile=function(a){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(e),c=function(a){function b(a){this.configurationVariableNames=a,this.repeatString="item in sortedAndPaginatedList"}return l(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configurationVariableNames.fillLastPage),b.html(e),b.attr("ng-repeat","item in fillerArray"),c.append(b)},b.prototype.link=function(a,b,c,e){var f,g,h,i,j;return f=this.configurationVariableNames,j=new d(a,f,c.atList),h=function(a,b,c,d,e,f,g,h){var i,j;return a?(j=a,i=c*b-a.length,"global"===e?(j=h(d)(j,f,g),j=h("limitTo")(j,i),j=h("limitTo")(j,c)):(j=h("limitTo")(j,i),j=h("limitTo")(j,c),j=h(d)(j,f,g)),j):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sortedAndPaginatedList=h(j.getList(),j.getCurrentPage(),j.getItemsPerPage(),j.getOrderBy(),j.getSortContext(),a.predicate,a.descending,e),b=Math.ceil(j.getList().length/j.getItemsPerPage()),a.fillerArray=g(j.getList(),j.getCurrentPage(),b,j.getItemsPerPage())},a.$watch(f.currentPage,function(){return i()}),a.$watch(f.itemsPerPage,function(){return i()}),a.$watch(f.sortContext,function(){return i()}),a.$watchCollection(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a.numberOfPages=Math.ceil(j.getList().length/j.getItemsPerPage()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(e),g=function(){function a(a,b,c){this.element=a,this.tableConfiguration=b,this.configurationVariableNames=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.tableConfiguration.columnConfigurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.renderHtml());return b},a.prototype.setupHeader=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.getSetup=function(){return this.tableConfiguration.paginated?new c(this.configurationVariableNames):new f(this.configurationVariableNames,this.tableConfiguration.list)},a.prototype.compile=function(){return this.setupHeader(),this.setup=this.getSetup(),this.setup.compile(this.element)},a.prototype.setupInitialSorting=function(a){var b,c,d,e,f;for(e=this.tableConfiguration.columnConfigurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setupInitialSorting(a),a.getSortIcon||(a.getSortIcon=function(b){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),b=function(){function a(a,b,c,d){if(this.lowerBound=null!=a?a:0,this.upperBound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upperBound-this.length?a=this.upperBound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.resetParameters=function(a,b,c){if(this.lowerBound=a,this.upperBound=b,this.length=c,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realignGreedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realignGenerous=function(){},a}(),j="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c){var d,e,f;return f=new h(b,c),d=new i(c.atConfig),e=new g(b,f,d),e.compile(),{post:function(b,c,d){return e.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:j,link:function(a,c,e){var f,g,h,j,k,l;return f=new i(e.atConfig),l=new d(a,f,e.atList),h=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},g=function(){return a.numberOfPages},j=function(b){return a.numberOfPages=b},k=function(){var b,c;return l.getList()?l.getList().length>0?(b=Math.ceil(l.getList().length/l.getItemsPerPage()),j(b),c=a.showSectioning()?l.getMaxPages():b,a.pageSequence.resetParameters(0,b,c),l.setCurrentPage(h(l.getCurrentPage(),0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())):(j(1),a.pageSequence.resetParameters(0,1,1),l.setCurrentPage(0),a.pageSequence.realignGreedy(0)):void 0},a.showSectioning=function(){return l.getMaxPages()&&g()>l.getMaxPages()},a.getCurrentPage=function(){return l.getCurrentPage()},a.stepPage=function(b){return b=parseInt(b),l.setCurrentPage(h(l.getCurrentPage()+b,0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())},a.goToPage=function(a){return l.setCurrentPage(a)},a.jumpBack=function(){return a.stepPage(-l.getMaxPages())},a.jumpAhead=function(){return a.stepPage(l.getMaxPages())},a.pageSequence=new b,a.$watch(f.itemsPerPage,function(){return k()}),a.$watch(f.maxPages,function(){return k()}),a.$watch(e.atList,function(){return k()}),a.$watch(""+e.atList+".length",function(){return k()}),k()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a){var b;if(b=a.attr("at-attribute"),!b)throw"at-implicit specified without at-attribute: "+a.html();return a.append("{{item."+b+"}}")}}}])}).call(this); \ No newline at end of file +(function(){var a,b,c,d,e,f,g,h,i,j,k={}.hasOwnProperty,l=function(a,b){function c(){this.constructor=a}for(var d in b)k.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.customContent=b.customContent,this.attributes=b.attributes)}return a.prototype.createElement=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.renderTitle=function(a){return a.html(this.customContent||this.title)},a.prototype.renderAttributes=function(a){var b,c,d,e,f;if(this.customContent){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.renderSorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.renderWidth=function(a){return a.attr("width",this.width)},a.prototype.renderHtml=function(){var a;return a=this.createElement(),this.renderTitle(a),this.renderAttributes(a),this.renderSorting(a),this.renderWidth(a),a},a}(),i=function(){function a(a){this.configObjectName=a,this.itemsPerPage=""+this.configObjectName+".itemsPerPage",this.sortContext=""+this.configObjectName+".sortContext",this.fillLastPage=""+this.configObjectName+".fillLastPage",this.maxPages=""+this.configObjectName+".maxPages",this.currentPage=""+this.configObjectName+".currentPage",this.orderBy=""+this.configObjectName+".orderBy"}return a}(),d=function(){function a(a,b,c){this.scope=a,this.configurationVariableNames=b,this.listName=c}return a.prototype.getList=function(){return this.scope.$eval(this.listName)},a.prototype.getItemsPerPage=function(){return this.scope.$eval(this.configurationVariableNames.itemsPerPage)||10},a.prototype.getCurrentPage=function(){return this.scope.$eval(this.configurationVariableNames.currentPage)||0},a.prototype.getMaxPages=function(){return this.scope.$eval(this.configurationVariableNames.maxPages)||void 0},a.prototype.getSortContext=function(){return this.scope.$eval(this.configurationVariableNames.sortContext)||"global"},a.prototype.setCurrentPage=function(a){return this.scope.$eval(""+this.configurationVariableNames.currentPage+"="+a)},a.prototype.getOrderBy=function(){return this.scope.$eval(this.configurationVariableNames.orderBy)||"orderBy"},a}(),h=function(){function b(a,b){this.tableElement=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.createColumnConfigurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collectHeaderMarkup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={customContent:c.html(),attributes:c[0].attributes};return b},b.prototype.collectBodyMarkup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.createColumnConfigurations=function(){var b,c,d,e,f;for(c=this.collectHeaderMarkup(this.tableElement),b=this.collectBodyMarkup(this.tableElement),this.columnConfigurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.columnConfigurations.push(new a(d,c[d.attribute]))},b}(),e=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),f=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return l(b,a),b.prototype.compile=function(a,b,c){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(e),c=function(a){function b(a){this.configurationVariableNames=a,this.repeatString="item in sortedAndPaginatedList"}return l(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configurationVariableNames.fillLastPage),b.html(e),b.attr("ng-repeat","item in fillerArray"),c.append(b)},b.prototype.link=function(a,b,c,e){var f,g,h,i,j;return f=this.configurationVariableNames,j=new d(a,f,c.atList),h=function(a,b,c,d,e,f,g,h){var i,j;return a?(j=a,i=c*b-a.length,"global"===e?(j=h(d)(j,f,g),j=h("limitTo")(j,i),j=h("limitTo")(j,c)):(j=h("limitTo")(j,i),j=h("limitTo")(j,c),j=h(d)(j,f,g)),j):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sortedAndPaginatedList=h(j.getList(),j.getCurrentPage(),j.getItemsPerPage(),j.getOrderBy(),j.getSortContext(),a.predicate,a.descending,e),b=Math.ceil(j.getList().length/j.getItemsPerPage()),a.fillerArray=g(j.getList(),j.getCurrentPage(),b,j.getItemsPerPage())},a.$watch(f.currentPage,function(){return i()}),a.$watch(f.itemsPerPage,function(){return i()}),a.$watch(f.sortContext,function(){return i()}),a.$watchCollection(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a.numberOfPages=Math.ceil(j.getList().length/j.getItemsPerPage()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(e),g=function(){function a(a,b,c){this.element=a,this.tableConfiguration=b,this.configurationVariableNames=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.tableConfiguration.columnConfigurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.renderHtml());return b},a.prototype.setupHeader=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.getSetup=function(){return this.tableConfiguration.paginated?new c(this.configurationVariableNames):new f(this.configurationVariableNames,this.tableConfiguration.list)},a.prototype.compile=function(){return this.setupHeader(),this.setup=this.getSetup(),this.setup.compile(this.element)},a.prototype.setupInitialSorting=function(a){var b,c,d,e,f;for(e=this.tableConfiguration.columnConfigurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setupInitialSorting(a),a.getSortIcon||(a.getSortIcon=function(b,c){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),b=function(){function a(a,b,c,d){if(this.lowerBound=null!=a?a:0,this.upperBound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upperBound-this.length?a=this.upperBound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.resetParameters=function(a,b,c){if(this.lowerBound=a,this.upperBound=b,this.length=c,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realignGreedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realignGenerous=function(a){},a}(),j="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c,d){var e,f,j;return j=new h(b,c),e=new i(c.atConfig),f=new g(b,j,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:j,link:function(a,c,e){var f,g,h,j,k,l;return f=new i(e.atConfig),l=new d(a,f,e.atList),h=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},g=function(){return a.numberOfPages},j=function(b){return a.numberOfPages=b},k=function(b){var c,d;return l.getList()?l.getList().length>0?(c=Math.ceil(l.getList().length/l.getItemsPerPage()),j(c),d=a.showSectioning()?l.getMaxPages():c,a.pageSequence.resetParameters(0,c,d),l.setCurrentPage(h(l.getCurrentPage(),0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())):(j(1),a.pageSequence.resetParameters(0,1,1),l.setCurrentPage(0),a.pageSequence.realignGreedy(0)):void 0},a.showSectioning=function(){return l.getMaxPages()&&g()>l.getMaxPages()},a.getCurrentPage=function(){return l.getCurrentPage()},a.stepPage=function(b){return b=parseInt(b),l.setCurrentPage(h(l.getCurrentPage()+b,0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())},a.goToPage=function(a){return l.setCurrentPage(a)},a.jumpBack=function(){return a.stepPage(-l.getMaxPages())},a.jumpAhead=function(){return a.stepPage(l.getMaxPages())},a.pageSequence=new b,a.$watch(f.itemsPerPage,function(){return k()}),a.$watch(f.maxPages,function(){return k()}),a.$watch(e.atList,function(){return k()}),a.$watch(""+e.atList+".length",function(){return k()}),k()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a,b,c){var d;if(d=a.attr("at-attribute"),!d)throw"at-implicit specified without at-attribute: "+a.html();return a.append("")}}}])}).call(this); \ No newline at end of file From 1f21573c88ea0330b5734aeb30974f5ff89bbb87 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 4 Aug 2015 09:05:24 +0200 Subject: [PATCH 179/190] update version --- Gruntfile.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gruntfile.coffee b/Gruntfile.coffee index f480651..f7c0c62 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -1,4 +1,4 @@ -version = "1.0.4" +version = "1.0.5" banner = " // author: Samuel Mueller \n From d14b273af9d41e79f0c428b619c3e8ea2894aa59 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 4 Aug 2015 09:12:19 +0200 Subject: [PATCH 180/190] update version --- dist/angular-table.js | 2 +- dist/angular-table.min.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dist/angular-table.js b/dist/angular-table.js index 83b9f10..58ee500 100644 --- a/dist/angular-table.js +++ b/dist/angular-table.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 1.0.4 +// version: 1.0.5 // license: MIT // homepage: http://github.com/samu/angular-table (function() { diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js index 1ba2b0f..d2dc543 100644 --- a/dist/angular-table.min.js +++ b/dist/angular-table.min.js @@ -1,4 +1,8 @@ // author: Samuel Mueller +// version: 1.0.5 +// license: MIT +// homepage: http://github.com/samu/angular-table +// author: Samuel Mueller // version: 1.0.4 // license: MIT // homepage: http://github.com/samu/angular-table From b037108813b6e88e5842e478ee2f37d81cf37fea Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Tue, 4 Aug 2015 09:20:49 +0200 Subject: [PATCH 181/190] update readme --- README.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6b3fe15..f4ba048 100644 --- a/README.md +++ b/README.md @@ -93,13 +93,17 @@ done within seconds: We need to define two additional keywords in our table ... [result](http://samu.github.io/angular-table/walkthrough/4.html) -## Hacking on angular-table -### Coffee Script +## Contributing +### Pull Requests This directive is written in Coffee Script. If you want to contribute, please make sure to -work on the coffee sources only. If you are familiar with Javascript and aren't with -Coffee Script, i highly recommend to [take look at it and try it out](http://coffeescript.org). -It has a powerful and beautiful syntax and is easy to learn. You'll probably need no more than -~2 hours to learn about all the basic concepts. +work on the coffee sources only. When you're done with your changes, two steps are required: + +1. Update the version in the Gruntfile +2. Compile: +``` +grunt coffee +grunt usebanner +``` ### Running the tests The code for this directive is well covered with tests, which can be run with PhantomJS and From 45226cecbf623f8ac1ed7b543409f4dbd37aa7f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B3sthenes=20Neto?= Date: Fri, 7 Aug 2015 16:10:52 -0300 Subject: [PATCH 182/190] =?UTF-8?q?A=20little=20change=20to=20customize=20?= =?UTF-8?q?the=20paginator=20text=20Uma=20pequena=20modifica=C3=A7=C3=A3o?= =?UTF-8?q?=20para=20customizar=20o=20texto=20do=20paginador?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coffee/configuration/scope_config_wrapper.coffee | 10 ++++++++++ coffee/directives/at_pagination.coffee | 3 +++ .../directives/pagination/pagination_template.coffee | 12 ++++++------ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/coffee/configuration/scope_config_wrapper.coffee b/coffee/configuration/scope_config_wrapper.coffee index d28888f..dab836d 100644 --- a/coffee/configuration/scope_config_wrapper.coffee +++ b/coffee/configuration/scope_config_wrapper.coffee @@ -18,3 +18,13 @@ class ScopeConfigWrapper setCurrentPage: (currentPage) -> @scope.$eval("#{@configurationVariableNames.currentPage}=#{currentPage}") + + getPaginatorLabel: () -> + paginatorLabelDefault = + stepBack: '‹' + stepAhead: '›' + jumpBack: '«' + jumpAhead: '»' + first: 'First' + last: 'Last' + @scope.$eval(@configurationVariableNames.paginatorLabel) || paginatorLabelDefault diff --git a/coffee/directives/at_pagination.coffee b/coffee/directives/at_pagination.coffee index 6860d13..7da1371 100644 --- a/coffee/directives/at_pagination.coffee +++ b/coffee/directives/at_pagination.coffee @@ -44,6 +44,9 @@ angular.module("angular-table").directive "atPagination", [() -> $scope.getCurrentPage = () -> w.getCurrentPage() + $scope.getPaginatorLabel = () -> + w.getPaginatorLabel() + $scope.stepPage = (step) -> step = parseInt(step) w.setCurrentPage(keepInBounds(w.getCurrentPage() + step, 0, getNumberOfPages() - 1)) diff --git a/coffee/directives/pagination/pagination_template.coffee b/coffee/directives/pagination/pagination_template.coffee index ca44d3d..35263b0 100644 --- a/coffee/directives/pagination/pagination_template.coffee +++ b/coffee/directives/pagination/pagination_template.coffee @@ -2,15 +2,15 @@ paginationTemplate = " " From 9c3ce3213a4632b1f8dcede73f4e24dd15cdc938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B3sthenes=20Neto?= Date: Fri, 25 Sep 2015 11:59:16 -0300 Subject: [PATCH 183/190] Change de prop name to pagitatorLabels --- .../configuration_variable_names.coffee | 1 + coffee/configuration/scope_config_wrapper.coffee | 6 +++--- coffee/directives/at_pagination.coffee | 4 ++-- .../directives/pagination/pagination_template.coffee | 12 ++++++------ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/coffee/configuration/configuration_variable_names.coffee b/coffee/configuration/configuration_variable_names.coffee index 2656c91..4c29cfa 100644 --- a/coffee/configuration/configuration_variable_names.coffee +++ b/coffee/configuration/configuration_variable_names.coffee @@ -5,3 +5,4 @@ class configurationVariableNames @fillLastPage = "#{@configObjectName}.fillLastPage" @maxPages = "#{@configObjectName}.maxPages" @currentPage = "#{@configObjectName}.currentPage" + @paginatorLabels = "#{@configObjectName}.paginatorLabels" diff --git a/coffee/configuration/scope_config_wrapper.coffee b/coffee/configuration/scope_config_wrapper.coffee index dab836d..7707010 100644 --- a/coffee/configuration/scope_config_wrapper.coffee +++ b/coffee/configuration/scope_config_wrapper.coffee @@ -19,12 +19,12 @@ class ScopeConfigWrapper setCurrentPage: (currentPage) -> @scope.$eval("#{@configurationVariableNames.currentPage}=#{currentPage}") - getPaginatorLabel: () -> - paginatorLabelDefault = + getpaginatorLabels: () -> + paginatorLabelsDefault = stepBack: '‹' stepAhead: '›' jumpBack: '«' jumpAhead: '»' first: 'First' last: 'Last' - @scope.$eval(@configurationVariableNames.paginatorLabel) || paginatorLabelDefault + @scope.$eval(@configurationVariableNames.paginatorLabels) || paginatorLabelsDefault diff --git a/coffee/directives/at_pagination.coffee b/coffee/directives/at_pagination.coffee index 7da1371..8d7cfc7 100644 --- a/coffee/directives/at_pagination.coffee +++ b/coffee/directives/at_pagination.coffee @@ -44,8 +44,8 @@ angular.module("angular-table").directive "atPagination", [() -> $scope.getCurrentPage = () -> w.getCurrentPage() - $scope.getPaginatorLabel = () -> - w.getPaginatorLabel() + $scope.getpaginatorLabels = () -> + w.getpaginatorLabels() $scope.stepPage = (step) -> step = parseInt(step) diff --git a/coffee/directives/pagination/pagination_template.coffee b/coffee/directives/pagination/pagination_template.coffee index 35263b0..5a5ea07 100644 --- a/coffee/directives/pagination/pagination_template.coffee +++ b/coffee/directives/pagination/pagination_template.coffee @@ -2,15 +2,15 @@ paginationTemplate = " " From abaae60a9dffefb1b0accd69cd0891e696194125 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B3sthenes=20Neto?= Date: Mon, 28 Sep 2015 09:01:48 -0300 Subject: [PATCH 184/190] Changed to proper name --- coffee/configuration/scope_config_wrapper.coffee | 2 +- coffee/directives/at_pagination.coffee | 4 ++-- .../directives/pagination/pagination_template.coffee | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/coffee/configuration/scope_config_wrapper.coffee b/coffee/configuration/scope_config_wrapper.coffee index 7707010..215c9b9 100644 --- a/coffee/configuration/scope_config_wrapper.coffee +++ b/coffee/configuration/scope_config_wrapper.coffee @@ -19,7 +19,7 @@ class ScopeConfigWrapper setCurrentPage: (currentPage) -> @scope.$eval("#{@configurationVariableNames.currentPage}=#{currentPage}") - getpaginatorLabels: () -> + getPaginatorLabels: () -> paginatorLabelsDefault = stepBack: '‹' stepAhead: '›' diff --git a/coffee/directives/at_pagination.coffee b/coffee/directives/at_pagination.coffee index 8d7cfc7..3c005aa 100644 --- a/coffee/directives/at_pagination.coffee +++ b/coffee/directives/at_pagination.coffee @@ -44,8 +44,8 @@ angular.module("angular-table").directive "atPagination", [() -> $scope.getCurrentPage = () -> w.getCurrentPage() - $scope.getpaginatorLabels = () -> - w.getpaginatorLabels() + $scope.getPaginatorLabels = () -> + w.getPaginatorLabels() $scope.stepPage = (step) -> step = parseInt(step) diff --git a/coffee/directives/pagination/pagination_template.coffee b/coffee/directives/pagination/pagination_template.coffee index 5a5ea07..376b5b0 100644 --- a/coffee/directives/pagination/pagination_template.coffee +++ b/coffee/directives/pagination/pagination_template.coffee @@ -2,15 +2,15 @@ paginationTemplate = " " From 09dfa90fc5a2d1a35bd213f466e0002091512eb8 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 30 Sep 2015 07:52:29 +0200 Subject: [PATCH 185/190] new version --- dist/angular-table.js | 19 ++++++++++++++++++- dist/angular-table.min.js | 6 +----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/dist/angular-table.js b/dist/angular-table.js index 58ee500..2c86833 100644 --- a/dist/angular-table.js +++ b/dist/angular-table.js @@ -81,6 +81,7 @@ this.maxPages = "" + this.configObjectName + ".maxPages"; this.currentPage = "" + this.configObjectName + ".currentPage"; this.orderBy = "" + this.configObjectName + ".orderBy"; + this.paginatorLabels = "" + this.configObjectName + ".paginatorLabels"; } return configurationVariableNames; @@ -122,6 +123,19 @@ return this.scope.$eval(this.configurationVariableNames.orderBy) || 'orderBy'; }; + ScopeConfigWrapper.prototype.getPaginatorLabels = function() { + var paginatorLabelsDefault; + paginatorLabelsDefault = { + stepBack: '‹', + stepAhead: '›', + jumpBack: '«', + jumpAhead: '»', + first: 'First', + last: 'Last' + }; + return this.scope.$eval(this.configurationVariableNames.paginatorLabels) || paginatorLabelsDefault; + }; + return ScopeConfigWrapper; })(); @@ -512,7 +526,7 @@ })(); - paginationTemplate = ""; + paginationTemplate = ""; angular.module("angular-table").directive("atTable", [ "$filter", function($filter) { @@ -584,6 +598,9 @@ $scope.getCurrentPage = function() { return w.getCurrentPage(); }; + $scope.getPaginatorLabels = function() { + return w.getPaginatorLabels(); + }; $scope.stepPage = function(step) { step = parseInt(step); w.setCurrentPage(keepInBounds(w.getCurrentPage() + step, 0, getNumberOfPages() - 1)); diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js index d2dc543..51bcc02 100644 --- a/dist/angular-table.min.js +++ b/dist/angular-table.min.js @@ -2,8 +2,4 @@ // version: 1.0.5 // license: MIT // homepage: http://github.com/samu/angular-table -// author: Samuel Mueller -// version: 1.0.4 -// license: MIT -// homepage: http://github.com/samu/angular-table -(function(){var a,b,c,d,e,f,g,h,i,j,k={}.hasOwnProperty,l=function(a,b){function c(){this.constructor=a}for(var d in b)k.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.customContent=b.customContent,this.attributes=b.attributes)}return a.prototype.createElement=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.renderTitle=function(a){return a.html(this.customContent||this.title)},a.prototype.renderAttributes=function(a){var b,c,d,e,f;if(this.customContent){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.renderSorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.renderWidth=function(a){return a.attr("width",this.width)},a.prototype.renderHtml=function(){var a;return a=this.createElement(),this.renderTitle(a),this.renderAttributes(a),this.renderSorting(a),this.renderWidth(a),a},a}(),i=function(){function a(a){this.configObjectName=a,this.itemsPerPage=""+this.configObjectName+".itemsPerPage",this.sortContext=""+this.configObjectName+".sortContext",this.fillLastPage=""+this.configObjectName+".fillLastPage",this.maxPages=""+this.configObjectName+".maxPages",this.currentPage=""+this.configObjectName+".currentPage",this.orderBy=""+this.configObjectName+".orderBy"}return a}(),d=function(){function a(a,b,c){this.scope=a,this.configurationVariableNames=b,this.listName=c}return a.prototype.getList=function(){return this.scope.$eval(this.listName)},a.prototype.getItemsPerPage=function(){return this.scope.$eval(this.configurationVariableNames.itemsPerPage)||10},a.prototype.getCurrentPage=function(){return this.scope.$eval(this.configurationVariableNames.currentPage)||0},a.prototype.getMaxPages=function(){return this.scope.$eval(this.configurationVariableNames.maxPages)||void 0},a.prototype.getSortContext=function(){return this.scope.$eval(this.configurationVariableNames.sortContext)||"global"},a.prototype.setCurrentPage=function(a){return this.scope.$eval(""+this.configurationVariableNames.currentPage+"="+a)},a.prototype.getOrderBy=function(){return this.scope.$eval(this.configurationVariableNames.orderBy)||"orderBy"},a}(),h=function(){function b(a,b){this.tableElement=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.createColumnConfigurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collectHeaderMarkup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={customContent:c.html(),attributes:c[0].attributes};return b},b.prototype.collectBodyMarkup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.createColumnConfigurations=function(){var b,c,d,e,f;for(c=this.collectHeaderMarkup(this.tableElement),b=this.collectBodyMarkup(this.tableElement),this.columnConfigurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.columnConfigurations.push(new a(d,c[d.attribute]))},b}(),e=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),f=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return l(b,a),b.prototype.compile=function(a,b,c){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(e),c=function(a){function b(a){this.configurationVariableNames=a,this.repeatString="item in sortedAndPaginatedList"}return l(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configurationVariableNames.fillLastPage),b.html(e),b.attr("ng-repeat","item in fillerArray"),c.append(b)},b.prototype.link=function(a,b,c,e){var f,g,h,i,j;return f=this.configurationVariableNames,j=new d(a,f,c.atList),h=function(a,b,c,d,e,f,g,h){var i,j;return a?(j=a,i=c*b-a.length,"global"===e?(j=h(d)(j,f,g),j=h("limitTo")(j,i),j=h("limitTo")(j,c)):(j=h("limitTo")(j,i),j=h("limitTo")(j,c),j=h(d)(j,f,g)),j):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sortedAndPaginatedList=h(j.getList(),j.getCurrentPage(),j.getItemsPerPage(),j.getOrderBy(),j.getSortContext(),a.predicate,a.descending,e),b=Math.ceil(j.getList().length/j.getItemsPerPage()),a.fillerArray=g(j.getList(),j.getCurrentPage(),b,j.getItemsPerPage())},a.$watch(f.currentPage,function(){return i()}),a.$watch(f.itemsPerPage,function(){return i()}),a.$watch(f.sortContext,function(){return i()}),a.$watchCollection(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a.numberOfPages=Math.ceil(j.getList().length/j.getItemsPerPage()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(e),g=function(){function a(a,b,c){this.element=a,this.tableConfiguration=b,this.configurationVariableNames=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.tableConfiguration.columnConfigurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.renderHtml());return b},a.prototype.setupHeader=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.getSetup=function(){return this.tableConfiguration.paginated?new c(this.configurationVariableNames):new f(this.configurationVariableNames,this.tableConfiguration.list)},a.prototype.compile=function(){return this.setupHeader(),this.setup=this.getSetup(),this.setup.compile(this.element)},a.prototype.setupInitialSorting=function(a){var b,c,d,e,f;for(e=this.tableConfiguration.columnConfigurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setupInitialSorting(a),a.getSortIcon||(a.getSortIcon=function(b,c){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),b=function(){function a(a,b,c,d){if(this.lowerBound=null!=a?a:0,this.upperBound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upperBound-this.length?a=this.upperBound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.resetParameters=function(a,b,c){if(this.lowerBound=a,this.upperBound=b,this.length=c,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realignGreedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realignGenerous=function(a){},a}(),j="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c,d){var e,f,j;return j=new h(b,c),e=new i(c.atConfig),f=new g(b,j,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:j,link:function(a,c,e){var f,g,h,j,k,l;return f=new i(e.atConfig),l=new d(a,f,e.atList),h=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},g=function(){return a.numberOfPages},j=function(b){return a.numberOfPages=b},k=function(b){var c,d;return l.getList()?l.getList().length>0?(c=Math.ceil(l.getList().length/l.getItemsPerPage()),j(c),d=a.showSectioning()?l.getMaxPages():c,a.pageSequence.resetParameters(0,c,d),l.setCurrentPage(h(l.getCurrentPage(),0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())):(j(1),a.pageSequence.resetParameters(0,1,1),l.setCurrentPage(0),a.pageSequence.realignGreedy(0)):void 0},a.showSectioning=function(){return l.getMaxPages()&&g()>l.getMaxPages()},a.getCurrentPage=function(){return l.getCurrentPage()},a.stepPage=function(b){return b=parseInt(b),l.setCurrentPage(h(l.getCurrentPage()+b,0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())},a.goToPage=function(a){return l.setCurrentPage(a)},a.jumpBack=function(){return a.stepPage(-l.getMaxPages())},a.jumpAhead=function(){return a.stepPage(l.getMaxPages())},a.pageSequence=new b,a.$watch(f.itemsPerPage,function(){return k()}),a.$watch(f.maxPages,function(){return k()}),a.$watch(e.atList,function(){return k()}),a.$watch(""+e.atList+".length",function(){return k()}),k()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a,b,c){var d;if(d=a.attr("at-attribute"),!d)throw"at-implicit specified without at-attribute: "+a.html();return a.append("")}}}])}).call(this); \ No newline at end of file +(function(){var a,b,c,d,e,f,g,h,i,j,k={}.hasOwnProperty,l=function(a,b){function c(){this.constructor=a}for(var d in b)k.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.customContent=b.customContent,this.attributes=b.attributes)}return a.prototype.createElement=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.renderTitle=function(a){return a.html(this.customContent||this.title)},a.prototype.renderAttributes=function(a){var b,c,d,e,f;if(this.customContent){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.renderSorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.renderWidth=function(a){return a.attr("width",this.width)},a.prototype.renderHtml=function(){var a;return a=this.createElement(),this.renderTitle(a),this.renderAttributes(a),this.renderSorting(a),this.renderWidth(a),a},a}(),i=function(){function a(a){this.configObjectName=a,this.itemsPerPage=""+this.configObjectName+".itemsPerPage",this.sortContext=""+this.configObjectName+".sortContext",this.fillLastPage=""+this.configObjectName+".fillLastPage",this.maxPages=""+this.configObjectName+".maxPages",this.currentPage=""+this.configObjectName+".currentPage",this.orderBy=""+this.configObjectName+".orderBy",this.paginatorLabels=""+this.configObjectName+".paginatorLabels"}return a}(),d=function(){function a(a,b,c){this.scope=a,this.configurationVariableNames=b,this.listName=c}return a.prototype.getList=function(){return this.scope.$eval(this.listName)},a.prototype.getItemsPerPage=function(){return this.scope.$eval(this.configurationVariableNames.itemsPerPage)||10},a.prototype.getCurrentPage=function(){return this.scope.$eval(this.configurationVariableNames.currentPage)||0},a.prototype.getMaxPages=function(){return this.scope.$eval(this.configurationVariableNames.maxPages)||void 0},a.prototype.getSortContext=function(){return this.scope.$eval(this.configurationVariableNames.sortContext)||"global"},a.prototype.setCurrentPage=function(a){return this.scope.$eval(""+this.configurationVariableNames.currentPage+"="+a)},a.prototype.getOrderBy=function(){return this.scope.$eval(this.configurationVariableNames.orderBy)||"orderBy"},a.prototype.getPaginatorLabels=function(){var a;return a={stepBack:"‹",stepAhead:"›",jumpBack:"«",jumpAhead:"»",first:"First",last:"Last"},this.scope.$eval(this.configurationVariableNames.paginatorLabels)||a},a}(),h=function(){function b(a,b){this.tableElement=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.createColumnConfigurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collectHeaderMarkup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={customContent:c.html(),attributes:c[0].attributes};return b},b.prototype.collectBodyMarkup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.createColumnConfigurations=function(){var b,c,d,e,f;for(c=this.collectHeaderMarkup(this.tableElement),b=this.collectBodyMarkup(this.tableElement),this.columnConfigurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.columnConfigurations.push(new a(d,c[d.attribute]))},b}(),e=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),f=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return l(b,a),b.prototype.compile=function(a,b,c){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(e),c=function(a){function b(a){this.configurationVariableNames=a,this.repeatString="item in sortedAndPaginatedList"}return l(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configurationVariableNames.fillLastPage),b.html(e),b.attr("ng-repeat","item in fillerArray"),c.append(b)},b.prototype.link=function(a,b,c,e){var f,g,h,i,j;return f=this.configurationVariableNames,j=new d(a,f,c.atList),h=function(a,b,c,d,e,f,g,h){var i,j;return a?(j=a,i=c*b-a.length,"global"===e?(j=h(d)(j,f,g),j=h("limitTo")(j,i),j=h("limitTo")(j,c)):(j=h("limitTo")(j,i),j=h("limitTo")(j,c),j=h(d)(j,f,g)),j):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sortedAndPaginatedList=h(j.getList(),j.getCurrentPage(),j.getItemsPerPage(),j.getOrderBy(),j.getSortContext(),a.predicate,a.descending,e),b=Math.ceil(j.getList().length/j.getItemsPerPage()),a.fillerArray=g(j.getList(),j.getCurrentPage(),b,j.getItemsPerPage())},a.$watch(f.currentPage,function(){return i()}),a.$watch(f.itemsPerPage,function(){return i()}),a.$watch(f.sortContext,function(){return i()}),a.$watchCollection(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a.numberOfPages=Math.ceil(j.getList().length/j.getItemsPerPage()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(e),g=function(){function a(a,b,c){this.element=a,this.tableConfiguration=b,this.configurationVariableNames=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.tableConfiguration.columnConfigurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.renderHtml());return b},a.prototype.setupHeader=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.getSetup=function(){return this.tableConfiguration.paginated?new c(this.configurationVariableNames):new f(this.configurationVariableNames,this.tableConfiguration.list)},a.prototype.compile=function(){return this.setupHeader(),this.setup=this.getSetup(),this.setup.compile(this.element)},a.prototype.setupInitialSorting=function(a){var b,c,d,e,f;for(e=this.tableConfiguration.columnConfigurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setupInitialSorting(a),a.getSortIcon||(a.getSortIcon=function(b,c){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),b=function(){function a(a,b,c,d){if(this.lowerBound=null!=a?a:0,this.upperBound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upperBound-this.length?a=this.upperBound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.resetParameters=function(a,b,c){if(this.lowerBound=a,this.upperBound=b,this.length=c,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realignGreedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realignGenerous=function(a){},a}(),j="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c,d){var e,f,j;return j=new h(b,c),e=new i(c.atConfig),f=new g(b,j,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:j,link:function(a,c,e){var f,g,h,j,k,l;return f=new i(e.atConfig),l=new d(a,f,e.atList),h=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},g=function(){return a.numberOfPages},j=function(b){return a.numberOfPages=b},k=function(b){var c,d;return l.getList()?l.getList().length>0?(c=Math.ceil(l.getList().length/l.getItemsPerPage()),j(c),d=a.showSectioning()?l.getMaxPages():c,a.pageSequence.resetParameters(0,c,d),l.setCurrentPage(h(l.getCurrentPage(),0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())):(j(1),a.pageSequence.resetParameters(0,1,1),l.setCurrentPage(0),a.pageSequence.realignGreedy(0)):void 0},a.showSectioning=function(){return l.getMaxPages()&&g()>l.getMaxPages()},a.getCurrentPage=function(){return l.getCurrentPage()},a.getPaginatorLabels=function(){return l.getPaginatorLabels()},a.stepPage=function(b){return b=parseInt(b),l.setCurrentPage(h(l.getCurrentPage()+b,0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())},a.goToPage=function(a){return l.setCurrentPage(a)},a.jumpBack=function(){return a.stepPage(-l.getMaxPages())},a.jumpAhead=function(){return a.stepPage(l.getMaxPages())},a.pageSequence=new b,a.$watch(f.itemsPerPage,function(){return k()}),a.$watch(f.maxPages,function(){return k()}),a.$watch(e.atList,function(){return k()}),a.$watch(""+e.atList+".length",function(){return k()}),k()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a,b,c){var d;if(d=a.attr("at-attribute"),!d)throw"at-implicit specified without at-attribute: "+a.html();return a.append("")}}}])}).call(this); \ No newline at end of file From eed6ea061faf4b2826a4c2f382a48043ec667996 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Wed, 30 Sep 2015 07:55:13 +0200 Subject: [PATCH 186/190] new version --- Gruntfile.coffee | 2 +- dist/angular-table.js | 2 +- dist/angular-table.min.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gruntfile.coffee b/Gruntfile.coffee index f7c0c62..f845698 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -1,4 +1,4 @@ -version = "1.0.5" +version = "1.0.6" banner = " // author: Samuel Mueller \n diff --git a/dist/angular-table.js b/dist/angular-table.js index 2c86833..b399b7f 100644 --- a/dist/angular-table.js +++ b/dist/angular-table.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 1.0.5 +// version: 1.0.6 // license: MIT // homepage: http://github.com/samu/angular-table (function() { diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js index 51bcc02..05a13ab 100644 --- a/dist/angular-table.min.js +++ b/dist/angular-table.min.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 1.0.5 +// version: 1.0.6 // license: MIT // homepage: http://github.com/samu/angular-table (function(){var a,b,c,d,e,f,g,h,i,j,k={}.hasOwnProperty,l=function(a,b){function c(){this.constructor=a}for(var d in b)k.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.customContent=b.customContent,this.attributes=b.attributes)}return a.prototype.createElement=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.renderTitle=function(a){return a.html(this.customContent||this.title)},a.prototype.renderAttributes=function(a){var b,c,d,e,f;if(this.customContent){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.renderSorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.renderWidth=function(a){return a.attr("width",this.width)},a.prototype.renderHtml=function(){var a;return a=this.createElement(),this.renderTitle(a),this.renderAttributes(a),this.renderSorting(a),this.renderWidth(a),a},a}(),i=function(){function a(a){this.configObjectName=a,this.itemsPerPage=""+this.configObjectName+".itemsPerPage",this.sortContext=""+this.configObjectName+".sortContext",this.fillLastPage=""+this.configObjectName+".fillLastPage",this.maxPages=""+this.configObjectName+".maxPages",this.currentPage=""+this.configObjectName+".currentPage",this.orderBy=""+this.configObjectName+".orderBy",this.paginatorLabels=""+this.configObjectName+".paginatorLabels"}return a}(),d=function(){function a(a,b,c){this.scope=a,this.configurationVariableNames=b,this.listName=c}return a.prototype.getList=function(){return this.scope.$eval(this.listName)},a.prototype.getItemsPerPage=function(){return this.scope.$eval(this.configurationVariableNames.itemsPerPage)||10},a.prototype.getCurrentPage=function(){return this.scope.$eval(this.configurationVariableNames.currentPage)||0},a.prototype.getMaxPages=function(){return this.scope.$eval(this.configurationVariableNames.maxPages)||void 0},a.prototype.getSortContext=function(){return this.scope.$eval(this.configurationVariableNames.sortContext)||"global"},a.prototype.setCurrentPage=function(a){return this.scope.$eval(""+this.configurationVariableNames.currentPage+"="+a)},a.prototype.getOrderBy=function(){return this.scope.$eval(this.configurationVariableNames.orderBy)||"orderBy"},a.prototype.getPaginatorLabels=function(){var a;return a={stepBack:"‹",stepAhead:"›",jumpBack:"«",jumpAhead:"»",first:"First",last:"Last"},this.scope.$eval(this.configurationVariableNames.paginatorLabels)||a},a}(),h=function(){function b(a,b){this.tableElement=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.createColumnConfigurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collectHeaderMarkup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={customContent:c.html(),attributes:c[0].attributes};return b},b.prototype.collectBodyMarkup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.createColumnConfigurations=function(){var b,c,d,e,f;for(c=this.collectHeaderMarkup(this.tableElement),b=this.collectBodyMarkup(this.tableElement),this.columnConfigurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.columnConfigurations.push(new a(d,c[d.attribute]))},b}(),e=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),f=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return l(b,a),b.prototype.compile=function(a,b,c){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(e),c=function(a){function b(a){this.configurationVariableNames=a,this.repeatString="item in sortedAndPaginatedList"}return l(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configurationVariableNames.fillLastPage),b.html(e),b.attr("ng-repeat","item in fillerArray"),c.append(b)},b.prototype.link=function(a,b,c,e){var f,g,h,i,j;return f=this.configurationVariableNames,j=new d(a,f,c.atList),h=function(a,b,c,d,e,f,g,h){var i,j;return a?(j=a,i=c*b-a.length,"global"===e?(j=h(d)(j,f,g),j=h("limitTo")(j,i),j=h("limitTo")(j,c)):(j=h("limitTo")(j,i),j=h("limitTo")(j,c),j=h(d)(j,f,g)),j):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sortedAndPaginatedList=h(j.getList(),j.getCurrentPage(),j.getItemsPerPage(),j.getOrderBy(),j.getSortContext(),a.predicate,a.descending,e),b=Math.ceil(j.getList().length/j.getItemsPerPage()),a.fillerArray=g(j.getList(),j.getCurrentPage(),b,j.getItemsPerPage())},a.$watch(f.currentPage,function(){return i()}),a.$watch(f.itemsPerPage,function(){return i()}),a.$watch(f.sortContext,function(){return i()}),a.$watchCollection(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a.numberOfPages=Math.ceil(j.getList().length/j.getItemsPerPage()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(e),g=function(){function a(a,b,c){this.element=a,this.tableConfiguration=b,this.configurationVariableNames=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.tableConfiguration.columnConfigurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.renderHtml());return b},a.prototype.setupHeader=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.getSetup=function(){return this.tableConfiguration.paginated?new c(this.configurationVariableNames):new f(this.configurationVariableNames,this.tableConfiguration.list)},a.prototype.compile=function(){return this.setupHeader(),this.setup=this.getSetup(),this.setup.compile(this.element)},a.prototype.setupInitialSorting=function(a){var b,c,d,e,f;for(e=this.tableConfiguration.columnConfigurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setupInitialSorting(a),a.getSortIcon||(a.getSortIcon=function(b,c){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),b=function(){function a(a,b,c,d){if(this.lowerBound=null!=a?a:0,this.upperBound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upperBound-this.length?a=this.upperBound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.resetParameters=function(a,b,c){if(this.lowerBound=a,this.upperBound=b,this.length=c,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realignGreedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realignGenerous=function(a){},a}(),j="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c,d){var e,f,j;return j=new h(b,c),e=new i(c.atConfig),f=new g(b,j,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:j,link:function(a,c,e){var f,g,h,j,k,l;return f=new i(e.atConfig),l=new d(a,f,e.atList),h=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},g=function(){return a.numberOfPages},j=function(b){return a.numberOfPages=b},k=function(b){var c,d;return l.getList()?l.getList().length>0?(c=Math.ceil(l.getList().length/l.getItemsPerPage()),j(c),d=a.showSectioning()?l.getMaxPages():c,a.pageSequence.resetParameters(0,c,d),l.setCurrentPage(h(l.getCurrentPage(),0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())):(j(1),a.pageSequence.resetParameters(0,1,1),l.setCurrentPage(0),a.pageSequence.realignGreedy(0)):void 0},a.showSectioning=function(){return l.getMaxPages()&&g()>l.getMaxPages()},a.getCurrentPage=function(){return l.getCurrentPage()},a.getPaginatorLabels=function(){return l.getPaginatorLabels()},a.stepPage=function(b){return b=parseInt(b),l.setCurrentPage(h(l.getCurrentPage()+b,0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())},a.goToPage=function(a){return l.setCurrentPage(a)},a.jumpBack=function(){return a.stepPage(-l.getMaxPages())},a.jumpAhead=function(){return a.stepPage(l.getMaxPages())},a.pageSequence=new b,a.$watch(f.itemsPerPage,function(){return k()}),a.$watch(f.maxPages,function(){return k()}),a.$watch(e.atList,function(){return k()}),a.$watch(""+e.atList+".length",function(){return k()}),k()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a,b,c){var d;if(d=a.attr("at-attribute"),!d)throw"at-implicit specified without at-attribute: "+a.html();return a.append("")}}}])}).call(this); \ No newline at end of file From c497afd3c9f212d33b04a79cbee6f78a959cacb1 Mon Sep 17 00:00:00 2001 From: Claudiu Date: Tue, 10 Nov 2015 18:17:52 -0500 Subject: [PATCH 187/190] Add descending param to getSortIcon --- coffee/configuration/column_configuration.coffee | 2 +- coffee/directives/table/table.coffee | 4 ++-- dist/angular-table.js | 6 +++--- dist/angular-table.min.js | 8 ++++++++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/coffee/configuration/column_configuration.coffee b/coffee/configuration/column_configuration.coffee index 502e56d..f4aab32 100644 --- a/coffee/configuration/column_configuration.coffee +++ b/coffee/configuration/column_configuration.coffee @@ -26,7 +26,7 @@ class ColumnConfiguration if @sortable element.attr("ng-click", "predicate = '#{@attribute}'; descending = !descending;") icon = angular.element("") - icon.attr("ng-class", "getSortIcon('#{@attribute}', predicate)") + icon.attr("ng-class", "getSortIcon('#{@attribute}', predicate, descending)") element.append(icon) renderWidth: (element) -> diff --git a/coffee/directives/table/table.coffee b/coffee/directives/table/table.coffee index 5d1242e..769aa39 100644 --- a/coffee/directives/table/table.coffee +++ b/coffee/directives/table/table.coffee @@ -38,8 +38,8 @@ class Table @setupInitialSorting($scope) if not $scope.getSortIcon - $scope.getSortIcon = (predicate, currentPredicate) -> + $scope.getSortIcon = (predicate, currentPredicate, descending) -> return "glyphicon glyphicon-minus" if predicate != $scope.predicate - if $scope.descending then "glyphicon glyphicon-chevron-down" else "glyphicon glyphicon-chevron-up" + if descending then "glyphicon glyphicon-chevron-down" else "glyphicon glyphicon-chevron-up" @setup.link($scope, $element, $attributes, $filter) diff --git a/dist/angular-table.js b/dist/angular-table.js index b399b7f..29a9f2c 100644 --- a/dist/angular-table.js +++ b/dist/angular-table.js @@ -49,7 +49,7 @@ if (this.sortable) { element.attr("ng-click", "predicate = '" + this.attribute + "'; descending = !descending;"); icon = angular.element(""); - icon.attr("ng-class", "getSortIcon('" + this.attribute + "', predicate)"); + icon.attr("ng-class", "getSortIcon('" + this.attribute + "', predicate, descending)"); return element.append(icon); } }; @@ -447,11 +447,11 @@ Table.prototype.post = function($scope, $element, $attributes, $filter) { this.setupInitialSorting($scope); if (!$scope.getSortIcon) { - $scope.getSortIcon = function(predicate, currentPredicate) { + $scope.getSortIcon = function(predicate, currentPredicate, descending) { if (predicate !== $scope.predicate) { return "glyphicon glyphicon-minus"; } - if ($scope.descending) { + if (descending) { return "glyphicon glyphicon-chevron-down"; } else { return "glyphicon glyphicon-chevron-up"; diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js index 05a13ab..c750ef2 100644 --- a/dist/angular-table.min.js +++ b/dist/angular-table.min.js @@ -2,4 +2,12 @@ // version: 1.0.6 // license: MIT // homepage: http://github.com/samu/angular-table +// author: Samuel Mueller +// version: 1.0.6 +// license: MIT +// homepage: http://github.com/samu/angular-table +// author: Samuel Mueller +// version: 1.0.6 +// license: MIT +// homepage: http://github.com/samu/angular-table (function(){var a,b,c,d,e,f,g,h,i,j,k={}.hasOwnProperty,l=function(a,b){function c(){this.constructor=a}for(var d in b)k.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.customContent=b.customContent,this.attributes=b.attributes)}return a.prototype.createElement=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.renderTitle=function(a){return a.html(this.customContent||this.title)},a.prototype.renderAttributes=function(a){var b,c,d,e,f;if(this.customContent){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.renderSorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.renderWidth=function(a){return a.attr("width",this.width)},a.prototype.renderHtml=function(){var a;return a=this.createElement(),this.renderTitle(a),this.renderAttributes(a),this.renderSorting(a),this.renderWidth(a),a},a}(),i=function(){function a(a){this.configObjectName=a,this.itemsPerPage=""+this.configObjectName+".itemsPerPage",this.sortContext=""+this.configObjectName+".sortContext",this.fillLastPage=""+this.configObjectName+".fillLastPage",this.maxPages=""+this.configObjectName+".maxPages",this.currentPage=""+this.configObjectName+".currentPage",this.orderBy=""+this.configObjectName+".orderBy",this.paginatorLabels=""+this.configObjectName+".paginatorLabels"}return a}(),d=function(){function a(a,b,c){this.scope=a,this.configurationVariableNames=b,this.listName=c}return a.prototype.getList=function(){return this.scope.$eval(this.listName)},a.prototype.getItemsPerPage=function(){return this.scope.$eval(this.configurationVariableNames.itemsPerPage)||10},a.prototype.getCurrentPage=function(){return this.scope.$eval(this.configurationVariableNames.currentPage)||0},a.prototype.getMaxPages=function(){return this.scope.$eval(this.configurationVariableNames.maxPages)||void 0},a.prototype.getSortContext=function(){return this.scope.$eval(this.configurationVariableNames.sortContext)||"global"},a.prototype.setCurrentPage=function(a){return this.scope.$eval(""+this.configurationVariableNames.currentPage+"="+a)},a.prototype.getOrderBy=function(){return this.scope.$eval(this.configurationVariableNames.orderBy)||"orderBy"},a.prototype.getPaginatorLabels=function(){var a;return a={stepBack:"‹",stepAhead:"›",jumpBack:"«",jumpAhead:"»",first:"First",last:"Last"},this.scope.$eval(this.configurationVariableNames.paginatorLabels)||a},a}(),h=function(){function b(a,b){this.tableElement=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.createColumnConfigurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collectHeaderMarkup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={customContent:c.html(),attributes:c[0].attributes};return b},b.prototype.collectBodyMarkup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.createColumnConfigurations=function(){var b,c,d,e,f;for(c=this.collectHeaderMarkup(this.tableElement),b=this.collectBodyMarkup(this.tableElement),this.columnConfigurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.columnConfigurations.push(new a(d,c[d.attribute]))},b}(),e=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),f=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return l(b,a),b.prototype.compile=function(a,b,c){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(e),c=function(a){function b(a){this.configurationVariableNames=a,this.repeatString="item in sortedAndPaginatedList"}return l(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configurationVariableNames.fillLastPage),b.html(e),b.attr("ng-repeat","item in fillerArray"),c.append(b)},b.prototype.link=function(a,b,c,e){var f,g,h,i,j;return f=this.configurationVariableNames,j=new d(a,f,c.atList),h=function(a,b,c,d,e,f,g,h){var i,j;return a?(j=a,i=c*b-a.length,"global"===e?(j=h(d)(j,f,g),j=h("limitTo")(j,i),j=h("limitTo")(j,c)):(j=h("limitTo")(j,i),j=h("limitTo")(j,c),j=h(d)(j,f,g)),j):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sortedAndPaginatedList=h(j.getList(),j.getCurrentPage(),j.getItemsPerPage(),j.getOrderBy(),j.getSortContext(),a.predicate,a.descending,e),b=Math.ceil(j.getList().length/j.getItemsPerPage()),a.fillerArray=g(j.getList(),j.getCurrentPage(),b,j.getItemsPerPage())},a.$watch(f.currentPage,function(){return i()}),a.$watch(f.itemsPerPage,function(){return i()}),a.$watch(f.sortContext,function(){return i()}),a.$watchCollection(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a.numberOfPages=Math.ceil(j.getList().length/j.getItemsPerPage()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(e),g=function(){function a(a,b,c){this.element=a,this.tableConfiguration=b,this.configurationVariableNames=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.tableConfiguration.columnConfigurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.renderHtml());return b},a.prototype.setupHeader=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.getSetup=function(){return this.tableConfiguration.paginated?new c(this.configurationVariableNames):new f(this.configurationVariableNames,this.tableConfiguration.list)},a.prototype.compile=function(){return this.setupHeader(),this.setup=this.getSetup(),this.setup.compile(this.element)},a.prototype.setupInitialSorting=function(a){var b,c,d,e,f;for(e=this.tableConfiguration.columnConfigurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setupInitialSorting(a),a.getSortIcon||(a.getSortIcon=function(b,c){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),b=function(){function a(a,b,c,d){if(this.lowerBound=null!=a?a:0,this.upperBound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upperBound-this.length?a=this.upperBound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.resetParameters=function(a,b,c){if(this.lowerBound=a,this.upperBound=b,this.length=c,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realignGreedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realignGenerous=function(a){},a}(),j="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c,d){var e,f,j;return j=new h(b,c),e=new i(c.atConfig),f=new g(b,j,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:j,link:function(a,c,e){var f,g,h,j,k,l;return f=new i(e.atConfig),l=new d(a,f,e.atList),h=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},g=function(){return a.numberOfPages},j=function(b){return a.numberOfPages=b},k=function(b){var c,d;return l.getList()?l.getList().length>0?(c=Math.ceil(l.getList().length/l.getItemsPerPage()),j(c),d=a.showSectioning()?l.getMaxPages():c,a.pageSequence.resetParameters(0,c,d),l.setCurrentPage(h(l.getCurrentPage(),0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())):(j(1),a.pageSequence.resetParameters(0,1,1),l.setCurrentPage(0),a.pageSequence.realignGreedy(0)):void 0},a.showSectioning=function(){return l.getMaxPages()&&g()>l.getMaxPages()},a.getCurrentPage=function(){return l.getCurrentPage()},a.getPaginatorLabels=function(){return l.getPaginatorLabels()},a.stepPage=function(b){return b=parseInt(b),l.setCurrentPage(h(l.getCurrentPage()+b,0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())},a.goToPage=function(a){return l.setCurrentPage(a)},a.jumpBack=function(){return a.stepPage(-l.getMaxPages())},a.jumpAhead=function(){return a.stepPage(l.getMaxPages())},a.pageSequence=new b,a.$watch(f.itemsPerPage,function(){return k()}),a.$watch(f.maxPages,function(){return k()}),a.$watch(e.atList,function(){return k()}),a.$watch(""+e.atList+".length",function(){return k()}),k()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a,b,c){var d;if(d=a.attr("at-attribute"),!d)throw"at-implicit specified without at-attribute: "+a.html();return a.append("")}}}])}).call(this); \ No newline at end of file From 9fd1e59e347c72c484ac4aac3bc3e0f2739edbd6 Mon Sep 17 00:00:00 2001 From: Claudiu Date: Fri, 13 Nov 2015 11:28:01 -0500 Subject: [PATCH 188/190] Update README.md I didn't notice the demo page at first - and it's much easier to look at the demo to figure out how to use ng-table at a glance - so I thought to make it more prominent. Plus other minor fixes which may be more aesthetic than objective. --- README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f4ba048..1fcca89 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # angular-table [![Build Status](https://travis-ci.org/samu/angular-table.png?branch=master)](https://travis-ci.org/samu/angular-table) -[DEMO](http://samu.github.io/angular-table/examples/examples.html) - Angular directive which allows to declare sortable tables and to add pagination with very little effort. @@ -17,8 +15,11 @@ Available via bower: `bower install at-table` This directive depends on angular only. No jQuery or Bootstrap required! It has been tested on angular 1.2, but it should also work with 1.1 releases. -## How -Lets assume we have an array containing objects representing people. A person object has the +## Usage Examples +See the live demo with usage examples [here](http://samu.github.io/angular-table/examples/examples.html). + +## Walkthrough +Let's assume we have an array containing objects representing people. A person object has the following format: ```javascript @@ -27,7 +28,7 @@ following format: The list contains about 100 entries and we would like to represent that data in a nice, sortable html table and eventually make it paginated so we don't have to scroll like a madman. With -`angular-table` in our toolbelt, this task becomes easy. Lets write some markup: +`angular-table` in our toolbelt, this task becomes easy. Let's write some markup: ```html @@ -41,7 +42,7 @@ html table and eventually make it paginated so we don't have to scroll like a ma
    ``` -[result](http://samu.github.io/angular-table/walkthrough/1.html) +[Result](http://samu.github.io/angular-table/walkthrough/1.html). This renders a simple html table with an automatically generated header, showing every entry in our list. Four attributes have been used that need further explanation: @@ -52,15 +53,15 @@ our list. Four attributes have been used that need further explanation: * `at-attribute` the attribute in each object the respective columns are dedicated to * `at-implicit` implicitly render the content of each object's attribute defined in `at-attribute` -Our table looks kind of unspectacular by now, so lets use some css, assuming we have twitter +Our table looks kind of unspectacular by now, so let's use some css, assuming we have twitter bootstrap in our sources: ```html ...
    ``` -[result](http://samu.github.io/angular-table/walkthrough/2.html) +[Result](http://samu.github.io/angular-table/walkthrough/2.html). -Now that looks better! Next, lets make the birthdate column sortable. We want to see the +Now that looks better! Next, let's make the birthdate column sortable. We want to see the youngest people first, therefore sort descending. We're also going to customize the content of the birthdate cell since the raw date format looks ugly: @@ -69,7 +70,7 @@ of the birthdate cell since the raw date format looks ugly: {{item.birthdate.substring(0, 10)}} ``` -[result](http://samu.github.io/angular-table/walkthrough/3.html) +[Result](http://samu.github.io/angular-table/walkthrough/3.html). And thats it, our table is sortable by birthdate instantly! We can make the other columns sortable aswell, by using the `at-sortable` attribute only. Also, note how we removed the @@ -91,7 +92,7 @@ done within seconds: We need to define two additional keywords in our table ... ... and we end up with a sortable, paginated table! -[result](http://samu.github.io/angular-table/walkthrough/4.html) +[Result](http://samu.github.io/angular-table/walkthrough/4.html). ## Contributing ### Pull Requests From acadafed545ec5633ecd41fd62e61b12cebcf9e0 Mon Sep 17 00:00:00 2001 From: Samuel Mueller Date: Sun, 15 Nov 2015 18:27:04 +0100 Subject: [PATCH 189/190] update version an recompile --- Gruntfile.coffee | 2 +- dist/angular-table.js | 2 +- dist/angular-table.min.js | 12 ++---------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Gruntfile.coffee b/Gruntfile.coffee index f845698..6f49668 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -1,4 +1,4 @@ -version = "1.0.6" +version = "1.0.7" banner = " // author: Samuel Mueller \n diff --git a/dist/angular-table.js b/dist/angular-table.js index 29a9f2c..15a760e 100644 --- a/dist/angular-table.js +++ b/dist/angular-table.js @@ -1,5 +1,5 @@ // author: Samuel Mueller -// version: 1.0.6 +// version: 1.0.7 // license: MIT // homepage: http://github.com/samu/angular-table (function() { diff --git a/dist/angular-table.min.js b/dist/angular-table.min.js index c750ef2..d5e9cdd 100644 --- a/dist/angular-table.min.js +++ b/dist/angular-table.min.js @@ -1,13 +1,5 @@ // author: Samuel Mueller -// version: 1.0.6 +// version: 1.0.7 // license: MIT // homepage: http://github.com/samu/angular-table -// author: Samuel Mueller -// version: 1.0.6 -// license: MIT -// homepage: http://github.com/samu/angular-table -// author: Samuel Mueller -// version: 1.0.6 -// license: MIT -// homepage: http://github.com/samu/angular-table -(function(){var a,b,c,d,e,f,g,h,i,j,k={}.hasOwnProperty,l=function(a,b){function c(){this.constructor=a}for(var d in b)k.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.customContent=b.customContent,this.attributes=b.attributes)}return a.prototype.createElement=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.renderTitle=function(a){return a.html(this.customContent||this.title)},a.prototype.renderAttributes=function(a){var b,c,d,e,f;if(this.customContent){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.renderSorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate)"),a.append(b)):void 0},a.prototype.renderWidth=function(a){return a.attr("width",this.width)},a.prototype.renderHtml=function(){var a;return a=this.createElement(),this.renderTitle(a),this.renderAttributes(a),this.renderSorting(a),this.renderWidth(a),a},a}(),i=function(){function a(a){this.configObjectName=a,this.itemsPerPage=""+this.configObjectName+".itemsPerPage",this.sortContext=""+this.configObjectName+".sortContext",this.fillLastPage=""+this.configObjectName+".fillLastPage",this.maxPages=""+this.configObjectName+".maxPages",this.currentPage=""+this.configObjectName+".currentPage",this.orderBy=""+this.configObjectName+".orderBy",this.paginatorLabels=""+this.configObjectName+".paginatorLabels"}return a}(),d=function(){function a(a,b,c){this.scope=a,this.configurationVariableNames=b,this.listName=c}return a.prototype.getList=function(){return this.scope.$eval(this.listName)},a.prototype.getItemsPerPage=function(){return this.scope.$eval(this.configurationVariableNames.itemsPerPage)||10},a.prototype.getCurrentPage=function(){return this.scope.$eval(this.configurationVariableNames.currentPage)||0},a.prototype.getMaxPages=function(){return this.scope.$eval(this.configurationVariableNames.maxPages)||void 0},a.prototype.getSortContext=function(){return this.scope.$eval(this.configurationVariableNames.sortContext)||"global"},a.prototype.setCurrentPage=function(a){return this.scope.$eval(""+this.configurationVariableNames.currentPage+"="+a)},a.prototype.getOrderBy=function(){return this.scope.$eval(this.configurationVariableNames.orderBy)||"orderBy"},a.prototype.getPaginatorLabels=function(){var a;return a={stepBack:"‹",stepAhead:"›",jumpBack:"«",jumpAhead:"»",first:"First",last:"Last"},this.scope.$eval(this.configurationVariableNames.paginatorLabels)||a},a}(),h=function(){function b(a,b){this.tableElement=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.createColumnConfigurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collectHeaderMarkup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={customContent:c.html(),attributes:c[0].attributes};return b},b.prototype.collectBodyMarkup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.createColumnConfigurations=function(){var b,c,d,e,f;for(c=this.collectHeaderMarkup(this.tableElement),b=this.collectBodyMarkup(this.tableElement),this.columnConfigurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.columnConfigurations.push(new a(d,c[d.attribute]))},b}(),e=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),f=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return l(b,a),b.prototype.compile=function(a,b,c){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(e),c=function(a){function b(a){this.configurationVariableNames=a,this.repeatString="item in sortedAndPaginatedList"}return l(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configurationVariableNames.fillLastPage),b.html(e),b.attr("ng-repeat","item in fillerArray"),c.append(b)},b.prototype.link=function(a,b,c,e){var f,g,h,i,j;return f=this.configurationVariableNames,j=new d(a,f,c.atList),h=function(a,b,c,d,e,f,g,h){var i,j;return a?(j=a,i=c*b-a.length,"global"===e?(j=h(d)(j,f,g),j=h("limitTo")(j,i),j=h("limitTo")(j,c)):(j=h("limitTo")(j,i),j=h("limitTo")(j,c),j=h(d)(j,f,g)),j):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sortedAndPaginatedList=h(j.getList(),j.getCurrentPage(),j.getItemsPerPage(),j.getOrderBy(),j.getSortContext(),a.predicate,a.descending,e),b=Math.ceil(j.getList().length/j.getItemsPerPage()),a.fillerArray=g(j.getList(),j.getCurrentPage(),b,j.getItemsPerPage())},a.$watch(f.currentPage,function(){return i()}),a.$watch(f.itemsPerPage,function(){return i()}),a.$watch(f.sortContext,function(){return i()}),a.$watchCollection(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a.numberOfPages=Math.ceil(j.getList().length/j.getItemsPerPage()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(e),g=function(){function a(a,b,c){this.element=a,this.tableConfiguration=b,this.configurationVariableNames=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.tableConfiguration.columnConfigurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.renderHtml());return b},a.prototype.setupHeader=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.getSetup=function(){return this.tableConfiguration.paginated?new c(this.configurationVariableNames):new f(this.configurationVariableNames,this.tableConfiguration.list)},a.prototype.compile=function(){return this.setupHeader(),this.setup=this.getSetup(),this.setup.compile(this.element)},a.prototype.setupInitialSorting=function(a){var b,c,d,e,f;for(e=this.tableConfiguration.columnConfigurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setupInitialSorting(a),a.getSortIcon||(a.getSortIcon=function(b,c){return b!==a.predicate?"glyphicon glyphicon-minus":a.descending?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),b=function(){function a(a,b,c,d){if(this.lowerBound=null!=a?a:0,this.upperBound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upperBound-this.length?a=this.upperBound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.resetParameters=function(a,b,c){if(this.lowerBound=a,this.upperBound=b,this.length=c,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realignGreedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realignGenerous=function(a){},a}(),j="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c,d){var e,f,j;return j=new h(b,c),e=new i(c.atConfig),f=new g(b,j,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:j,link:function(a,c,e){var f,g,h,j,k,l;return f=new i(e.atConfig),l=new d(a,f,e.atList),h=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},g=function(){return a.numberOfPages},j=function(b){return a.numberOfPages=b},k=function(b){var c,d;return l.getList()?l.getList().length>0?(c=Math.ceil(l.getList().length/l.getItemsPerPage()),j(c),d=a.showSectioning()?l.getMaxPages():c,a.pageSequence.resetParameters(0,c,d),l.setCurrentPage(h(l.getCurrentPage(),0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())):(j(1),a.pageSequence.resetParameters(0,1,1),l.setCurrentPage(0),a.pageSequence.realignGreedy(0)):void 0},a.showSectioning=function(){return l.getMaxPages()&&g()>l.getMaxPages()},a.getCurrentPage=function(){return l.getCurrentPage()},a.getPaginatorLabels=function(){return l.getPaginatorLabels()},a.stepPage=function(b){return b=parseInt(b),l.setCurrentPage(h(l.getCurrentPage()+b,0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())},a.goToPage=function(a){return l.setCurrentPage(a)},a.jumpBack=function(){return a.stepPage(-l.getMaxPages())},a.jumpAhead=function(){return a.stepPage(l.getMaxPages())},a.pageSequence=new b,a.$watch(f.itemsPerPage,function(){return k()}),a.$watch(f.maxPages,function(){return k()}),a.$watch(e.atList,function(){return k()}),a.$watch(""+e.atList+".length",function(){return k()}),k()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a,b,c){var d;if(d=a.attr("at-attribute"),!d)throw"at-implicit specified without at-attribute: "+a.html();return a.append("")}}}])}).call(this); \ No newline at end of file +(function(){var a,b,c,d,e,f,g,h,i,j,k={}.hasOwnProperty,l=function(a,b){function c(){this.constructor=a}for(var d in b)k.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};angular.module("angular-table",[]),a=function(){function a(a,b){this.attribute=a.attribute,this.title=a.title,this.sortable=a.sortable,this.width=a.width,this.initialSorting=a.initialSorting,b&&(this.customContent=b.customContent,this.attributes=b.attributes)}return a.prototype.createElement=function(){var a;return a=angular.element(document.createElement("th"))},a.prototype.renderTitle=function(a){return a.html(this.customContent||this.title)},a.prototype.renderAttributes=function(a){var b,c,d,e,f;if(this.customContent){for(e=this.attributes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.attr(b.name,b.value));return f}},a.prototype.renderSorting=function(a){var b;return this.sortable?(a.attr("ng-click","predicate = '"+this.attribute+"'; descending = !descending;"),b=angular.element(""),b.attr("ng-class","getSortIcon('"+this.attribute+"', predicate, descending)"),a.append(b)):void 0},a.prototype.renderWidth=function(a){return a.attr("width",this.width)},a.prototype.renderHtml=function(){var a;return a=this.createElement(),this.renderTitle(a),this.renderAttributes(a),this.renderSorting(a),this.renderWidth(a),a},a}(),i=function(){function a(a){this.configObjectName=a,this.itemsPerPage=""+this.configObjectName+".itemsPerPage",this.sortContext=""+this.configObjectName+".sortContext",this.fillLastPage=""+this.configObjectName+".fillLastPage",this.maxPages=""+this.configObjectName+".maxPages",this.currentPage=""+this.configObjectName+".currentPage",this.orderBy=""+this.configObjectName+".orderBy",this.paginatorLabels=""+this.configObjectName+".paginatorLabels"}return a}(),d=function(){function a(a,b,c){this.scope=a,this.configurationVariableNames=b,this.listName=c}return a.prototype.getList=function(){return this.scope.$eval(this.listName)},a.prototype.getItemsPerPage=function(){return this.scope.$eval(this.configurationVariableNames.itemsPerPage)||10},a.prototype.getCurrentPage=function(){return this.scope.$eval(this.configurationVariableNames.currentPage)||0},a.prototype.getMaxPages=function(){return this.scope.$eval(this.configurationVariableNames.maxPages)||void 0},a.prototype.getSortContext=function(){return this.scope.$eval(this.configurationVariableNames.sortContext)||"global"},a.prototype.setCurrentPage=function(a){return this.scope.$eval(""+this.configurationVariableNames.currentPage+"="+a)},a.prototype.getOrderBy=function(){return this.scope.$eval(this.configurationVariableNames.orderBy)||"orderBy"},a.prototype.getPaginatorLabels=function(){var a;return a={stepBack:"‹",stepAhead:"›",jumpBack:"«",jumpAhead:"»",first:"First",last:"Last"},this.scope.$eval(this.configurationVariableNames.paginatorLabels)||a},a}(),h=function(){function b(a,b){this.tableElement=a,this.attributes=b,this.id=this.attributes.id,this.config=this.attributes.atConfig,this.paginated=null!=this.attributes.atPaginated,this.list=this.attributes.atList,this.createColumnConfigurations()}return b.prototype.capitaliseFirstLetter=function(a){return a?a.charAt(0).toUpperCase()+a.slice(1):""},b.prototype.extractWidth=function(a){var b;return b=/([0-9]+px)/i.exec(a),b?b[0]:""},b.prototype.isSortable=function(a){var b;return b=/(sortable)/i.exec(a),b?!0:!1},b.prototype.getInitialSorting=function(a){var b;if(b=a.attr("at-initial-sorting")){if("asc"===b||"desc"===b)return b;throw"Invalid value for initial-sorting: "+b+". Allowed values are 'asc' or 'desc'."}return void 0},b.prototype.collectHeaderMarkup=function(a){var b,c,d,e,f,g;for(b={},d=a.find("tr"),g=d.find("th"),e=0,f=g.length;f>e;e++)c=g[e],c=angular.element(c),b[c.attr("at-attribute")]={customContent:c.html(),attributes:c[0].attributes};return b},b.prototype.collectBodyMarkup=function(a){var b,c,d,e,f,g,h,i,j,k;for(c=[],k=a.find("td"),i=0,j=k.length;j>i;i++)f=k[i],f=angular.element(f),b=f.attr("at-attribute"),g=f.attr("at-title")||this.capitaliseFirstLetter(f.attr("at-attribute")),e=void 0!==f.attr("at-sortable")||this.isSortable(f.attr("class")),h=this.extractWidth(f.attr("class")),d=this.getInitialSorting(f),c.push({attribute:b,title:g,sortable:e,width:h,initialSorting:d});return c},b.prototype.createColumnConfigurations=function(){var b,c,d,e,f;for(c=this.collectHeaderMarkup(this.tableElement),b=this.collectBodyMarkup(this.tableElement),this.columnConfigurations=[],e=0,f=b.length;f>e;e++)d=b[e],this.columnConfigurations.push(new a(d,c[d.attribute]))},b}(),e=function(){function a(){}return a.prototype.setupTr=function(a,b){var c,d;return c=a.find("tbody"),d=c.find("tr"),d.attr("ng-repeat",b),c},a}(),f=function(a){function b(a,b){this.list=b,this.repeatString="item in "+this.list+" | orderBy:predicate:descending"}return l(b,a),b.prototype.compile=function(a,b,c){return this.setupTr(a,this.repeatString)},b.prototype.link=function(){},b}(e),c=function(a){function b(a){this.configurationVariableNames=a,this.repeatString="item in sortedAndPaginatedList"}return l(b,a),b.prototype.compile=function(a){var b,c,d,e,f,g,h;for(c=this.setupTr(a,this.repeatString),f=a.find("td"),e="",g=0,h=f.length;h>g;g++)d=f[g],e+=" ";b=angular.element(document.createElement("tr")),b.attr("ng-show",this.configurationVariableNames.fillLastPage),b.html(e),b.attr("ng-repeat","item in fillerArray"),c.append(b)},b.prototype.link=function(a,b,c,e){var f,g,h,i,j;return f=this.configurationVariableNames,j=new d(a,f,c.atList),h=function(a,b,c,d,e,f,g,h){var i,j;return a?(j=a,i=c*b-a.length,"global"===e?(j=h(d)(j,f,g),j=h("limitTo")(j,i),j=h("limitTo")(j,c)):(j=h("limitTo")(j,i),j=h("limitTo")(j,c),j=h(d)(j,f,g)),j):[]},g=function(a,b,c,d){var e,f,g,h,i,j,k,l,m,n;if(d=parseInt(d),a.length<=0){for(m=[],g=h=0,j=d-1;j>=0?j>=h:h>=j;g=j>=0?++h:--h)m.push(g);return m}if(b===c-1){if(f=a.length%d,0!==f){for(e=d-f-1,n=[],g=i=k=a.length,l=a.length+e;l>=k?l>=i:i>=l;g=l>=k?++i:--i)n.push(g);return n}return[]}},i=function(){var b;return a.sortedAndPaginatedList=h(j.getList(),j.getCurrentPage(),j.getItemsPerPage(),j.getOrderBy(),j.getSortContext(),a.predicate,a.descending,e),b=Math.ceil(j.getList().length/j.getItemsPerPage()),a.fillerArray=g(j.getList(),j.getCurrentPage(),b,j.getItemsPerPage())},a.$watch(f.currentPage,function(){return i()}),a.$watch(f.itemsPerPage,function(){return i()}),a.$watch(f.sortContext,function(){return i()}),a.$watchCollection(c.atList,function(){return i()}),a.$watch(""+c.atList+".length",function(){return a.numberOfPages=Math.ceil(j.getList().length/j.getItemsPerPage()),i()}),a.$watch("predicate",function(){return i()}),a.$watch("descending",function(){return i()})},b}(e),g=function(){function a(a,b,c){this.element=a,this.tableConfiguration=b,this.configurationVariableNames=c}return a.prototype.constructHeader=function(){var a,b,c,d,e;for(b=angular.element(document.createElement("tr")),e=this.tableConfiguration.columnConfigurations,c=0,d=e.length;d>c;c++)a=e[c],b.append(a.renderHtml());return b},a.prototype.setupHeader=function(){var a,b,c;return b=this.element.find("thead"),b?(a=this.constructHeader(),c=angular.element(b).find("tr"),c.remove(),b.append(a)):void 0},a.prototype.getSetup=function(){return this.tableConfiguration.paginated?new c(this.configurationVariableNames):new f(this.configurationVariableNames,this.tableConfiguration.list)},a.prototype.compile=function(){return this.setupHeader(),this.setup=this.getSetup(),this.setup.compile(this.element)},a.prototype.setupInitialSorting=function(a){var b,c,d,e,f;for(e=this.tableConfiguration.columnConfigurations,f=[],c=0,d=e.length;d>c;c++)if(b=e[c],b.initialSorting){if(!b.attribute)throw"initial-sorting specified without attribute.";a.predicate=b.attribute,f.push(a.descending="desc"===b.initialSorting)}else f.push(void 0);return f},a.prototype.post=function(a,b,c,d){return this.setupInitialSorting(a),a.getSortIcon||(a.getSortIcon=function(b,c,d){return b!==a.predicate?"glyphicon glyphicon-minus":d?"glyphicon glyphicon-chevron-down":"glyphicon glyphicon-chevron-up"}),this.setup.link(a,b,c,d)},a}(),b=function(){function a(a,b,c,d){if(this.lowerBound=null!=a?a:0,this.upperBound=null!=b?b:1,null==c&&(c=0),this.length=null!=d?d:1,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";this.data=this.generate(c)}return a.prototype.generate=function(a){var b,c,d,e;for(a>this.upperBound-this.length?a=this.upperBound-this.length:a=a?d>=c:c>=d;b=d>=a?++c:--c)e.push(b);return e},a.prototype.resetParameters=function(a,b,c){if(this.lowerBound=a,this.upperBound=b,this.length=c,this.length>this.upperBound-this.lowerBound)throw"sequence is too long";return this.data=this.generate(this.data[0])},a.prototype.relocate=function(a){var b;return b=this.data[0]+a,this.data=this.generate(b,b+this.length)},a.prototype.realignGreedy=function(a){var b;return athis.data[this.length-1]?(b=a-(this.length-1),this.data=this.generate(b)):void 0},a.prototype.realignGenerous=function(a){},a}(),j="",angular.module("angular-table").directive("atTable",["$filter",function(a){return{restrict:"AC",scope:!0,compile:function(b,c,d){var e,f,j;return j=new h(b,c),e=new i(c.atConfig),f=new g(b,j,e),f.compile(),{post:function(b,c,d){return f.post(b,c,d,a)}}}}}]),angular.module("angular-table").directive("atPagination",[function(){return{restrict:"E",scope:!0,replace:!0,template:j,link:function(a,c,e){var f,g,h,j,k,l;return f=new i(e.atConfig),l=new d(a,f,e.atList),h=function(a,b,c){return a=Math.max(b,a),Math.min(c,a)},g=function(){return a.numberOfPages},j=function(b){return a.numberOfPages=b},k=function(b){var c,d;return l.getList()?l.getList().length>0?(c=Math.ceil(l.getList().length/l.getItemsPerPage()),j(c),d=a.showSectioning()?l.getMaxPages():c,a.pageSequence.resetParameters(0,c,d),l.setCurrentPage(h(l.getCurrentPage(),0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())):(j(1),a.pageSequence.resetParameters(0,1,1),l.setCurrentPage(0),a.pageSequence.realignGreedy(0)):void 0},a.showSectioning=function(){return l.getMaxPages()&&g()>l.getMaxPages()},a.getCurrentPage=function(){return l.getCurrentPage()},a.getPaginatorLabels=function(){return l.getPaginatorLabels()},a.stepPage=function(b){return b=parseInt(b),l.setCurrentPage(h(l.getCurrentPage()+b,0,g()-1)),a.pageSequence.realignGreedy(l.getCurrentPage())},a.goToPage=function(a){return l.setCurrentPage(a)},a.jumpBack=function(){return a.stepPage(-l.getMaxPages())},a.jumpAhead=function(){return a.stepPage(l.getMaxPages())},a.pageSequence=new b,a.$watch(f.itemsPerPage,function(){return k()}),a.$watch(f.maxPages,function(){return k()}),a.$watch(e.atList,function(){return k()}),a.$watch(""+e.atList+".length",function(){return k()}),k()}}}]),angular.module("angular-table").directive("atImplicit",[function(){return{restrict:"AC",compile:function(a,b,c){var d;if(d=a.attr("at-attribute"),!d)throw"at-implicit specified without at-attribute: "+a.html();return a.append("")}}}])}).call(this); \ No newline at end of file From b39bde1897190f48659d88631f486f0a752be003 Mon Sep 17 00:00:00 2001 From: Claudiu Date: Sun, 15 Nov 2015 16:28:47 -0500 Subject: [PATCH 190/190] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1fcca89..e6f2eb2 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ html table and eventually make it paginated so we don't have to scroll like a ma ``` -[Result](http://samu.github.io/angular-table/walkthrough/1.html). +[Result](http://samu.github.io/angular-table/walkthrough/1.html) This renders a simple html table with an automatically generated header, showing every entry in our list. Four attributes have been used that need further explanation: @@ -59,7 +59,7 @@ bootstrap in our sources: ```html ...
    ``` -[Result](http://samu.github.io/angular-table/walkthrough/2.html). +[Result](http://samu.github.io/angular-table/walkthrough/2.html) Now that looks better! Next, let's make the birthdate column sortable. We want to see the youngest people first, therefore sort descending. We're also going to customize the content @@ -70,7 +70,7 @@ of the birthdate cell since the raw date format looks ugly: {{item.birthdate.substring(0, 10)}} ``` -[Result](http://samu.github.io/angular-table/walkthrough/3.html). +[Result](http://samu.github.io/angular-table/walkthrough/3.html) And thats it, our table is sortable by birthdate instantly! We can make the other columns sortable aswell, by using the `at-sortable` attribute only. Also, note how we removed the @@ -92,7 +92,7 @@ done within seconds: We need to define two additional keywords in our table ... ... and we end up with a sortable, paginated table! -[Result](http://samu.github.io/angular-table/walkthrough/4.html). +[Result](http://samu.github.io/angular-table/walkthrough/4.html) ## Contributing ### Pull Requests