Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ng-tasty

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-tasty - npm Package Compare versions

Comparing version 0.3.1 to 0.3.3

2

bower.json
{
"name": "ng-tasty",
"version": "0.3.1",
"version": "0.3.3",
"homepage": "https://github.com/Zizzamia/ng-tasty",

@@ -5,0 +5,0 @@ "authors": [

@@ -5,3 +5,3 @@ /*

* Version: 0.3.1 - 2014-11-10
* Version: 0.3.3 - 2014-11-28
* License: MIT

@@ -279,3 +279,3 @@ */

'sortBy': 'sort-by',
'sortOrder': 'sort-order',
'sortOrder': 'sort-order'
},

@@ -290,2 +290,4 @@ listItemsPerPage: [5, 25, 50, 100],

this.$scope = $scope;
$scope.init = {};
$scope.query = {};

@@ -324,4 +326,6 @@ listScopeToWatch = ['filters', 'init', 'query', 'resource', 'resourceCallback'];

// Default configs
$scope.query = $scope.query || tableConfig.query;
$scope.init = $scope.init || {};
$scope.query.page = $scope.query.page || tableConfig.query.page;
$scope.query.count = $scope.query.count || tableConfig.query.count;
$scope.query.sortBy = $scope.query.sortBy || tableConfig.query.sortBy;
$scope.query.sortOrder = $scope.query.sortOrder || tableConfig.query.sortOrder;
$scope.init.count = $scope.init.count || tableConfig.init.count;

@@ -413,2 +417,6 @@ $scope.init.page = $scope.init.page || tableConfig.init.page;

};
if (!$scope.clientSide) {
$scope.header.sortBy = $scope.header.sortBy || resource.sortBy;
$scope.header.sortOrder = $scope.header.sortOrder || resource.sortOrder;
}
$scope.rows = resource.rows;

@@ -586,8 +594,14 @@ if ($scope.paginationDirective && resource.pagination) {

scope.header.columns.forEach(function (column, index) {
width = parseFloat((100 / lenHeader).toFixed(2));
column.style = column.style || {};
sortable = true;
active = false;
isSorted = '';
if (scope.notSortBy) {
sortable = scope.notSortBy.indexOf(column.key) < 0;
// Not sort column when the key is present in the `notSortBy` list,
// and Not sort column when `notSortBy` is an empty list
if (angular.isArray(scope.notSortBy)) {
if (scope.notSortBy.length) {
sortable = scope.notSortBy.indexOf(column.key) < 0;
} else {
sortable = false;
}
}

@@ -609,3 +623,3 @@ if (column.key === scope.header.sortBy ||

'sortable': sortable,
'width': { 'width': width + '%' },
'style': column.style,
'isSorted': isSorted

@@ -622,3 +636,3 @@ });

scope.sortBy = function (column) {
if (scope.notSortBy && scope.notSortBy.indexOf(column.key) >= 0) {
if (!column.sortable) {
return false;

@@ -671,14 +685,3 @@ }

*/
.controller('TablePaginationController', ["$scope", "$attrs", "tableConfig", function($scope, $attrs, tableConfig) {
if (angular.isDefined($attrs.itemsPerPage)) {
$scope.itemsPerPage = $scope.$parent[$attrs.itemsPerPage];
}
if (angular.isDefined($attrs.listItemsPerPage)) {
$scope.listItemsPerPage = $scope.$parent[$attrs.listItemsPerPage];
}
// Default configs
$scope.itemsPerPage = $scope.itemsPerPage || tableConfig.itemsPerPage;
$scope.listItemsPerPage = $scope.listItemsPerPage || tableConfig.listItemsPerPage;
}])
.directive('tastyPagination', ["$filter", function($filter) {
.directive('tastyPagination', ["$filter", "$templateCache", "$http", "$compile", "$parse", "tableConfig", function($filter, $templateCache, $http, $compile, $parse, tableConfig) {
return {

@@ -688,4 +691,5 @@ restrict: 'AE',

scope: {},
templateUrl: 'template/table/pagination.html',
controller: 'TablePaginationController',
templateUrl: function(tElement, tAttrs) {
return tAttrs.templateUrl || 'template/table/pagination.html';
},
link: function (scope, element, attrs, tastyTable) {

@@ -695,4 +699,40 @@ 'use strict';

setPreviousRange, setRemainingRange,
setPaginationRanges;
setPaginationRanges, listScopeToWatch;
listScopeToWatch = ['itemsPerPage', 'listItemsPerPage'];
listScopeToWatch.forEach(function (scopeName) {
var lastValue, parentGet, compare, parentSet, parentValueWatch;
if (!attrs[scopeName]) {
return;
}
parentGet = $parse(attrs[scopeName]);
if (parentGet.literal) {
compare = equals;
} else {
compare = function(a,b) { return a === b || (a !== a && b !== b); };
}
parentSet = parentGet.assign;
lastValue = scope[scopeName] = parentGet(scope.$parent);
parentValueWatch = function parentValueWatch(parentValue) {
if (!compare(parentValue, scope[scopeName])) {
// we are out of sync and need to copy
if (!compare(parentValue, lastValue)) {
// parent changed and it has precedence
$scope[scopeName] = parentValue;
} else {
// if the parent can be assigned then do so
parentSet(scope.$parent, parentValue = scope[scopeName]);
}
}
return lastValue = parentValue;
};
parentValueWatch.$stateful = true;
scope.$parent.$watch($parse(attrs[scopeName], parentValueWatch), null, parentGet.literal);
});
// Default configs
scope.itemsPerPage = scope.itemsPerPage || tableConfig.itemsPerPage;
scope.listItemsPerPage = scope.listItemsPerPage || tableConfig.listItemsPerPage;
// Pagination it's called

@@ -815,3 +855,3 @@ tastyTable.activate('pagination');

' ng-class="classToShow(column)"\n' +
' ng-style="column.width" ng-click="sortBy(column)">\n' +
' ng-style="::column.style" ng-click="sortBy(column)">\n' +
' <span ng-bind="::column.name"></span>\n' +

@@ -837,6 +877,6 @@ ' <span ng-class="column.isSorted"></span>\n' +

' <li ng-class="classPageMinRange">\n' +
' <a href="#" ng-click="page.previous()">&laquo;</a>\n' +
' <a href ng-click="page.previous()">&laquo;</a>\n' +
' </li>\n' +
' <li ng-repeat="numPage in rangePage" ng-class="classNumPage(numPage)">\n' +
' <a href="#" ng-click="page.get(numPage)">\n' +
' <a href ng-click="page.get(numPage)">\n' +
' <span ng-bind="numPage"></span>\n' +

@@ -847,3 +887,3 @@ ' <span class="sr-only" ng-if="classNumPage(numPage)">(current)</span>\n' +

' <li ng-class="classPageMaxRange">\n' +
' <a href="#" ng-click="page.remaining()">&raquo;</a>\n' +
' <a href ng-click="page.remaining()">&raquo;</a>\n' +
' </li>\n' +

@@ -850,0 +890,0 @@ ' </ul>\n' +

@@ -5,5 +5,5 @@ /*

* Version: 0.3.1 - 2014-11-10
* Version: 0.3.3 - 2014-11-28
* License: MIT
*/
angular.module("ngTasty",["ngTasty.tpls","ngTasty.filter","ngTasty.service","ngTasty.table"]),angular.module("ngTasty.tpls",["template/table/head.html","template/table/pagination.html"]),angular.module("ngTasty.filter",["ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range"]),angular.module("ngTasty.filter.cleanFieldName",[]).filter("cleanFieldName",function(){return function(input){return input.replace(/[^a-zA-Z0-9-]+/g,"-")}}),angular.module("ngTasty.filter.filterInt",[]).filter("filterInt",function(){return function(input){return/^(\-|\+)?([0-9]+|Infinity)$/.test(input)?Number(input):0/0}}),angular.module("ngTasty.filter.range",[]).filter("range",["$filter",function($filter){return function(input,start,stop,step){if(start=$filter("filterInt")(start),stop=$filter("filterInt")(stop),step=$filter("filterInt")(step),isNaN(start)&&(start=0),isNaN(stop)&&(stop=start,start=0),isNaN(step)&&(step=1),step>0&&start>=stop||0>step&&stop>=start)return[];for(var i=start;step>0?stop>i:i>stop;i+=step)input.push(i);return input}}]),angular.module("ngTasty.service",["ngTasty.service.tastyUtil","ngTasty.service.debounce","ngTasty.service.setProperty","ngTasty.service.joinObjects","ngTasty.service.webSocket"]),angular.module("ngTasty.service.tastyUtil",["ngTasty.service.debounce","ngTasty.service.setProperty","ngTasty.service.joinObjects"]).factory("tastyUtil",["debounce","setProperty","joinObjects",function(debounce,setProperty,joinObjects){return{debounce:debounce,setProperty:setProperty,joinObjects:joinObjects}}]),angular.module("ngTasty.service.debounce",[]).factory("debounce",["$timeout",function($timeout){return function(func,wait){var timeout;return function(){var context=this,args=arguments;$timeout.cancel(timeout),timeout=$timeout(function(){timeout=null,func.apply(context,args)},wait)}}}]),angular.module("ngTasty.service.setProperty",[]).factory("setProperty",function(){return function(objOne,objTwo,attrname){return"undefined"!=typeof objTwo[attrname]&&null!==objTwo[attrname]&&(objOne[attrname]=objTwo[attrname]),objOne}}),angular.module("ngTasty.service.joinObjects",[]).factory("joinObjects",["setProperty",function(setProperty){return function(objOne,objTwo,listKeyNotJoin){listKeyNotJoin=listKeyNotJoin||[];for(var attrname in objTwo)listKeyNotJoin.indexOf(attrname)<0&&setProperty(objOne,objTwo,attrname);return objOne}}]),angular.module("ngTasty.service.webSocket",["ngTasty.service"]).factory("WebSocket",function(){return function(url){var blobURL=URL.createObjectURL(new Blob(["(",function(){var WSWorker=function(){var _ws,initialize=function(url){_ws=new WebSocket(url)},on=function(){_ws.onmessage=function(response){var data=JSON.parse(response.data);self.postMessage(data)}},send=function(data){_ws.send(data)};return{initialize:initialize,on:on,send:send}}();self.addEventListener("message",function(e){switch(e.data.cmd){case"ws_new":WSWorker.initialize(e.data.url);break;case"ws_on":WSWorker.on(e.data.event,e.data.cb);break;case"ws_send":WSWorker.send(JSON.stringify(e.data.data));break;default:console.log("Unknown command: "+e.data.cmd)}})}.toString(),")()"],{type:"application/javascript"})),_worker=new Worker(blobURL);return URL.revokeObjectURL(blobURL),_worker.postMessage({cmd:"ws_new",url:url}),{on:function(event,cb){_worker.postMessage({cmd:"ws_on"}),_worker.addEventListener("message",function(e){("all"===event||e.data.type===event)&&cb(e.data)})},send:function(data){_worker.postMessage({cmd:"ws_send",data:data})}}}}),angular.module("ngTasty.table",["ngTasty.filter.cleanFieldName","ngTasty.filter.range","ngTasty.service.tastyUtil"]).constant("tableConfig",{init:{count:5,page:1,sortBy:void 0,sortOrder:void 0},query:{page:"page",count:"count",sortBy:"sort-by",sortOrder:"sort-order"},listItemsPerPage:[5,25,50,100],itemsPerPage:5,bindOnce:!0}).controller("TableController",["$scope","$attrs","$timeout","$filter","$parse","tableConfig","tastyUtil",function($scope,$attrs,$timeout,$filter,$parse,tableConfig,tastyUtil){"use strict";var listScopeToWatch,initTable;if(this.$scope=$scope,listScopeToWatch=["filters","init","query","resource","resourceCallback"],listScopeToWatch.forEach(function(scopeName){var lastValue,parentGet,compare,parentSet,parentValueWatch;$attrs[scopeName]&&(parentGet=$parse($attrs[scopeName]),compare=parentGet.literal?equals:function(a,b){return a===b||a!==a&&b!==b},parentSet=parentGet.assign,lastValue=$scope[scopeName]=parentGet($scope.$parent),parentValueWatch=function(parentValue){return compare(parentValue,$scope[scopeName])||(compare(parentValue,lastValue)?parentSet($scope.$parent,parentValue=$scope[scopeName]):$scope[scopeName]=parentValue),lastValue=parentValue},parentValueWatch.$stateful=!0,$scope.$parent.$watch($parse($attrs[scopeName],parentValueWatch),null,parentGet.literal))}),$scope.query=$scope.query||tableConfig.query,$scope.init=$scope.init||{},$scope.init.count=$scope.init.count||tableConfig.init.count,$scope.init.page=$scope.init.page||tableConfig.init.page,$scope.init.sortBy=$scope.init.sortBy||tableConfig.init.sortBy,$scope.init.sortOrder=$scope.init.sortOrder||tableConfig.init.sortOrder,$scope.clientSide=!0,$scope.url="",$scope.header={columns:[]},$scope.rows=[],$scope.params={},$scope.pagination={count:$scope.init.count,page:$scope.init.page,pages:1,size:0},$scope.theadDirective=!1,$scope.paginationDirective=!1,!angular.isDefined($attrs.resource)&&!angular.isDefined($attrs.resourceCallback))throw"AngularJS tastyTable directive: need the resource or resource-callback attribute";if(angular.isDefined($attrs.resource)){if(!angular.isObject($scope.resource))throw"AngularJS tastyTable directive: the resource ("+$attrs.resource+") it's not an object";if(!$scope.resource.header&&!$scope.resource.rows)throw"AngularJS tastyTable directive: the resource ("+$attrs.resource+") has the property header or rows undefined"}if(angular.isDefined($attrs.resourceCallback)){if(!angular.isFunction($scope.resourceCallback))throw"AngularJS tastyTable directive: the resource-callback ("+$attrs.resourceCallback+") it's not a function";$scope.clientSide=!1}this.activate=function(directiveName){$scope[directiveName+"Directive"]=!0,$scope.params[directiveName]=!0},this.setParams=function(key,value){$scope.params[key]=value,["sortBy","sortOrder"].indexOf(key)>=0&&($scope.header[key]=value)},this.bindOnce=tableConfig.bindOnce,$scope.setDirectivesValues=function(resource){if(!angular.isObject(resource))throw"AngularJS tastyTable directive: the resource it's not an object";if(!resource.header&&!resource.rows)throw"AngularJS tastyTable directive: the resource has the property header or rows undefined";1===Object.keys(resource.header[0]).length&&(resource.header=resource.header.map(function(header){var key=Object.keys(header)[0];return{key:key,name:header[key]}})),$scope.header={columns:resource.header,sortBy:$scope.params.sortBy,sortOrder:$scope.params.sortOrder},$scope.rows=resource.rows,$scope.paginationDirective&&resource.pagination&&($scope.pagination.count=resource.pagination.count,$scope.pagination.page=resource.pagination.page,$scope.pagination.pages=resource.pagination.pages,$scope.pagination.size=resource.pagination.size)},$scope.buildClientResource=function(){var fromRow,toRow,rowToShow,reverse,listSortBy;$scope.theadDirective&&(reverse="asc"===$scope.header.sortOrder?!1:!0,listSortBy=[function(item){return item[$scope.header.sortBy]}],$scope.header.columns[0].key!==$scope.header.sortBy&&listSortBy.push(function(item){return item[$scope.header.columns[0].key]}),$scope.header.sortBy&&($scope.rows=$filter("orderBy")($scope.rows,listSortBy,reverse))),$attrs.filters&&($scope.rows=$filter("filter")($scope.rows,$scope.filters)),$scope.paginationDirective&&($scope.pagination.page=$scope.params.page,$scope.pagination.count=$scope.params.count,$scope.pagination.size=$scope.rows.length,$scope.pagination.pages=Math.ceil($scope.rows.length/$scope.pagination.count),toRow=$scope.pagination.count*$scope.pagination.page,fromRow=toRow-$scope.pagination.count,fromRow>=0&&toRow>=0&&(rowToShow=$scope.rows.slice(fromRow,toRow),$scope.rows=rowToShow))},$scope.buildUrl=function(params,filters){var urlQuery,value,listKeyNotJoin;return urlQuery={},listKeyNotJoin=["sortBy","sortOrder","page","count"],$scope.theadDirective&&(urlQuery=tastyUtil.setProperty(urlQuery,params,"sortBy"),urlQuery=tastyUtil.setProperty(urlQuery,params,"sortOrder")),$scope.paginationDirective&&(urlQuery=tastyUtil.setProperty(urlQuery,params,"page"),urlQuery=tastyUtil.setProperty(urlQuery,params,"count")),$attrs.filters&&(urlQuery=tastyUtil.joinObjects(urlQuery,filters,listKeyNotJoin)),Object.keys(urlQuery).map(function(key){return value=urlQuery[key],$scope.query[key]&&(key=$scope.query[key]),encodeURIComponent(key)+"="+encodeURIComponent(value)}).join("&")},$scope.updateClientSideResource=tastyUtil.debounce(function(){$scope.setDirectivesValues($scope.resource),$scope.buildClientResource()},60),$scope.updateServerSideResource=tastyUtil.debounce(function(){$scope.url=$scope.buildUrl($scope.params,$scope.filters),$scope.resourceCallback($scope.url,$scope.params).then(function(resource){$scope.setDirectivesValues(resource)})},60),initTable=function(){$scope.clientSide?($scope.params.sortBy=$scope.resource.sortBy||$scope.init.sortBy,$scope.params.sortOrder=$scope.resource.sortOrder||$scope.init.sortOrder,$scope.params.page=$scope.init.page,$scope.resource.pagination&&($scope.params.page=$scope.resource.pagination.page||$scope.init.page),$scope.updateClientSideResource()):($scope.params.sortBy=$scope.init.sortBy,$scope.params.sortOrder=$scope.init.sortOrder,$scope.params.page=$scope.init.page,$scope.updateServerSideResource())},$attrs.filters&&$scope.$watch("filters",function(newValue,oldValue){newValue!==oldValue&&($scope.clientSide?$scope.updateClientSideResource():$scope.updateServerSideResource())},!0),$scope.$watchCollection("params",function(newValue,oldValue){newValue!==oldValue&&($scope.clientSide?$scope.updateClientSideResource():$scope.updateServerSideResource())}),$scope.resource&&$scope.$watch("resource",function(newValue,oldValue){newValue!==oldValue&&($scope.params.sortBy=newValue.sortBy,$scope.params.sortOrder=newValue.sortOrder,$scope.updateClientSideResource())},!0),initTable()}]).directive("tastyTable",function(){return{restrict:"A",scope:!0,controller:"TableController"}}).directive("tastyThead",["$filter",function($filter){return{restrict:"AE",require:"^tastyTable",scope:{notSortBy:"="},templateUrl:"template/table/head.html",link:function(scope,element,attrs,tastyTable){"use strict";var iconUp,iconDown;tastyTable.activate("thead"),scope.bindOnce=tastyTable.bindOnce,scope.columns=[],iconUp="fa fa-sort-up",iconDown="fa fa-sort-down",scope.setColumns=function(){var lenHeader,width,active,sortable,sort,isSorted;scope.columns=[],lenHeader=scope.header.columns.length,scope.header.columns.forEach(function(column){width=parseFloat((100/lenHeader).toFixed(2)),sortable=!0,active=!1,isSorted="",scope.notSortBy&&(sortable=scope.notSortBy.indexOf(column.key)<0),(column.key===scope.header.sortBy||"-"+column.key===scope.header.sortBy)&&(active=!0),sort=$filter("cleanFieldName")(column.key),scope.header.sortBy==="-"+sort?isSorted=iconDown:scope.header.sortBy===sort&&(isSorted=iconUp),scope.columns.push({key:column.key,name:column.name,active:active,sortable:sortable,width:{width:width+"%"},isSorted:isSorted})}),"dsc"===scope.header.sortOrder&&scope.header.sortBy&&"-"!==scope.header.sortBy[0]&&(scope.header.sortBy="-"+scope.header.sortBy)},scope.sortBy=function(column){if(scope.notSortBy&&scope.notSortBy.indexOf(column.key)>=0)return!1;var columnName,sortOrder;columnName=$filter("cleanFieldName")(column.key),sortOrder=scope.header.sortBy===columnName?"dsc":"asc",tastyTable.setParams("sortBy",column.key),tastyTable.setParams("sortOrder",sortOrder)},scope.classToShow=function(column){var listClassToShow=[];return column.sortable&&listClassToShow.push("sortable"),column.active&&listClassToShow.push("active"),listClassToShow},tastyTable.$scope.$watchCollection("header",function(newValue,oldValue){newValue&&newValue!==oldValue&&(scope.header=newValue,scope.setColumns())})}}}]).controller("TablePaginationController",["$scope","$attrs","tableConfig",function($scope,$attrs,tableConfig){angular.isDefined($attrs.itemsPerPage)&&($scope.itemsPerPage=$scope.$parent[$attrs.itemsPerPage]),angular.isDefined($attrs.listItemsPerPage)&&($scope.listItemsPerPage=$scope.$parent[$attrs.listItemsPerPage]),$scope.itemsPerPage=$scope.itemsPerPage||tableConfig.itemsPerPage,$scope.listItemsPerPage=$scope.listItemsPerPage||tableConfig.listItemsPerPage}]).directive("tastyPagination",["$filter",function($filter){return{restrict:"AE",require:"^tastyTable",scope:{},templateUrl:"template/table/pagination.html",controller:"TablePaginationController",link:function(scope,element,attrs,tastyTable){"use strict";var getPage,setCount,setPaginationRange,setPreviousRange,setRemainingRange,setPaginationRanges;tastyTable.activate("pagination"),scope.pagination={},scope.pagMinRange=1,scope.pagMaxRange=1,getPage=function(numPage){tastyTable.setParams("page",numPage)},setCount=function(count){var maxItems,page;maxItems=count*scope.pagination.page,maxItems>scope.pagination.size&&(page=Math.ceil(scope.pagination.size/count),tastyTable.setParams("page",page)),tastyTable.setParams("count",count)},setPaginationRange=function(){var currentPage;currentPage=scope.pagination.page,currentPage>scope.pagination.pages&&(currentPage=scope.pagination.pages),scope.pagMinRange=currentPage-2>0?currentPage-2:1,scope.pagMaxRange=currentPage+2,scope.pagination.page=currentPage,setPaginationRanges()},setPreviousRange=function(){return scope.pagHideMinRange===!0||scope.pagMinRange<1?!1:(scope.pagMaxRange=scope.pagMinRange,scope.pagMinRange=scope.pagMaxRange-scope.itemsPerPage,setPaginationRanges(),void 0)},setRemainingRange=function(){return scope.pagHideMaxRange===!0||scope.pagMaxRange>scope.pagination.pages?!1:(scope.pagMinRange=scope.pagMaxRange,scope.pagMaxRange=scope.pagMinRange+scope.itemsPerPage,scope.pagMaxRange>scope.pagination.pages&&(scope.pagMaxRange=scope.pagination.pages),scope.pagMinRange=scope.pagMaxRange-scope.itemsPerPage,setPaginationRanges(),void 0)},setPaginationRanges=function(){scope.listItemsPerPageShow=[],scope.pagMinRange=scope.pagMinRange>0?scope.pagMinRange:1,scope.pagMaxRange=scope.pagMinRange+5,scope.pagMaxRange>scope.pagination.pages&&(scope.pagMaxRange=scope.pagination.pages+1),scope.pagHideMinRange=scope.pagMinRange<=1,scope.pagHideMaxRange=scope.pagMaxRange>=scope.pagination.pages,scope.classPageMinRange=scope.pagHideMinRange?"disabled":"",scope.classPageMaxRange=scope.pagHideMaxRange?"disabled":"";for(var i=scope.listItemsPerPage.length;i>=0;i--)if(scope.pagination.size>scope.listItemsPerPage[i]){scope.listItemsPerPageShow=scope.listItemsPerPage.slice(0,i+1);break}scope.rangePage=$filter("range")([],scope.pagMinRange,scope.pagMaxRange)},scope.classPaginationCount=function(count){return count==scope.pagination.count?"active":""},scope.classNumPage=function(numPage){return numPage==scope.pagination.page?"active":!1},scope.page={get:getPage,setCount:setCount,previous:setPreviousRange,remaining:setRemainingRange},tastyTable.$scope.$watchCollection("pagination",function(newValue,oldValue){newValue&&newValue!==oldValue&&(scope.pagination=newValue,setPaginationRange())}),scope.page.setCount(scope.itemsPerPage)}}}]),angular.module("template/table/head.html",[]).run(["$templateCache",function($templateCache){$templateCache.put("template/table/head.html",'<tr>\n <th ng-repeat="column in columns track by $index" \n ng-class="classToShow(column)"\n ng-style="column.width" ng-click="sortBy(column)">\n <span ng-bind="::column.name"></span>\n <span ng-class="column.isSorted"></span>\n </th> \n</tr>')}]),angular.module("template/table/pagination.html",[]).run(["$templateCache",function($templateCache){$templateCache.put("template/table/pagination.html",'<div class="row">\n <div class="col-xs-3 text-left">\n <div class="btn-group">\n <button type="button" class="btn btn-default" \n ng-repeat="count in listItemsPerPageShow" \n ng-class="classPaginationCount(count)" \n ng-click="page.setCount(count)" ng-bind="count"></button>\n </div>\n </div>\n <div class="col-xs-6 text-center">\n <ul class="pagination">\n <li ng-class="classPageMinRange">\n <a href="#" ng-click="page.previous()">&laquo;</a>\n </li>\n <li ng-repeat="numPage in rangePage" ng-class="classNumPage(numPage)">\n <a href="#" ng-click="page.get(numPage)">\n <span ng-bind="numPage"></span>\n <span class="sr-only" ng-if="classNumPage(numPage)">(current)</span>\n </a>\n </li>\n <li ng-class="classPageMaxRange">\n <a href="#" ng-click="page.remaining()">&raquo;</a>\n </li>\n </ul>\n </div>\n <div class="col-xs-3 text-right">\n <p>Page <span ng-bind="pagination.page"></span> \n of <span ng-bind="pagination.pages"></span>,\n of <span ng-bind="pagination.size"></span> entries</p>\n </div>\n</div>')}]);
angular.module("ngTasty",["ngTasty.tpls","ngTasty.filter","ngTasty.service","ngTasty.table"]),angular.module("ngTasty.tpls",["template/table/head.html","template/table/pagination.html"]),angular.module("ngTasty.filter",["ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range"]),angular.module("ngTasty.filter.cleanFieldName",[]).filter("cleanFieldName",function(){return function(input){return input.replace(/[^a-zA-Z0-9-]+/g,"-")}}),angular.module("ngTasty.filter.filterInt",[]).filter("filterInt",function(){return function(input){return/^(\-|\+)?([0-9]+|Infinity)$/.test(input)?Number(input):0/0}}),angular.module("ngTasty.filter.range",[]).filter("range",["$filter",function($filter){return function(input,start,stop,step){if(start=$filter("filterInt")(start),stop=$filter("filterInt")(stop),step=$filter("filterInt")(step),isNaN(start)&&(start=0),isNaN(stop)&&(stop=start,start=0),isNaN(step)&&(step=1),step>0&&start>=stop||0>step&&stop>=start)return[];for(var i=start;step>0?stop>i:i>stop;i+=step)input.push(i);return input}}]),angular.module("ngTasty.service",["ngTasty.service.tastyUtil","ngTasty.service.debounce","ngTasty.service.setProperty","ngTasty.service.joinObjects","ngTasty.service.webSocket"]),angular.module("ngTasty.service.tastyUtil",["ngTasty.service.debounce","ngTasty.service.setProperty","ngTasty.service.joinObjects"]).factory("tastyUtil",["debounce","setProperty","joinObjects",function(debounce,setProperty,joinObjects){return{debounce:debounce,setProperty:setProperty,joinObjects:joinObjects}}]),angular.module("ngTasty.service.debounce",[]).factory("debounce",["$timeout",function($timeout){return function(func,wait){var timeout;return function(){var context=this,args=arguments;$timeout.cancel(timeout),timeout=$timeout(function(){timeout=null,func.apply(context,args)},wait)}}}]),angular.module("ngTasty.service.setProperty",[]).factory("setProperty",function(){return function(objOne,objTwo,attrname){return"undefined"!=typeof objTwo[attrname]&&null!==objTwo[attrname]&&(objOne[attrname]=objTwo[attrname]),objOne}}),angular.module("ngTasty.service.joinObjects",[]).factory("joinObjects",["setProperty",function(setProperty){return function(objOne,objTwo,listKeyNotJoin){listKeyNotJoin=listKeyNotJoin||[];for(var attrname in objTwo)listKeyNotJoin.indexOf(attrname)<0&&setProperty(objOne,objTwo,attrname);return objOne}}]),angular.module("ngTasty.service.webSocket",["ngTasty.service"]).factory("WebSocket",function(){return function(url){var blobURL=URL.createObjectURL(new Blob(["(",function(){var WSWorker=function(){var _ws,initialize=function(url){_ws=new WebSocket(url)},on=function(){_ws.onmessage=function(response){var data=JSON.parse(response.data);self.postMessage(data)}},send=function(data){_ws.send(data)};return{initialize:initialize,on:on,send:send}}();self.addEventListener("message",function(e){switch(e.data.cmd){case"ws_new":WSWorker.initialize(e.data.url);break;case"ws_on":WSWorker.on(e.data.event,e.data.cb);break;case"ws_send":WSWorker.send(JSON.stringify(e.data.data));break;default:console.log("Unknown command: "+e.data.cmd)}})}.toString(),")()"],{type:"application/javascript"})),_worker=new Worker(blobURL);return URL.revokeObjectURL(blobURL),_worker.postMessage({cmd:"ws_new",url:url}),{on:function(event,cb){_worker.postMessage({cmd:"ws_on"}),_worker.addEventListener("message",function(e){("all"===event||e.data.type===event)&&cb(e.data)})},send:function(data){_worker.postMessage({cmd:"ws_send",data:data})}}}}),angular.module("ngTasty.table",["ngTasty.filter.cleanFieldName","ngTasty.filter.range","ngTasty.service.tastyUtil"]).constant("tableConfig",{init:{count:5,page:1,sortBy:void 0,sortOrder:void 0},query:{page:"page",count:"count",sortBy:"sort-by",sortOrder:"sort-order"},listItemsPerPage:[5,25,50,100],itemsPerPage:5,bindOnce:!0}).controller("TableController",["$scope","$attrs","$timeout","$filter","$parse","tableConfig","tastyUtil",function($scope,$attrs,$timeout,$filter,$parse,tableConfig,tastyUtil){"use strict";var listScopeToWatch,initTable;if(this.$scope=$scope,$scope.init={},$scope.query={},listScopeToWatch=["filters","init","query","resource","resourceCallback"],listScopeToWatch.forEach(function(scopeName){var lastValue,parentGet,compare,parentSet,parentValueWatch;$attrs[scopeName]&&(parentGet=$parse($attrs[scopeName]),compare=parentGet.literal?equals:function(a,b){return a===b||a!==a&&b!==b},parentSet=parentGet.assign,lastValue=$scope[scopeName]=parentGet($scope.$parent),parentValueWatch=function(parentValue){return compare(parentValue,$scope[scopeName])||(compare(parentValue,lastValue)?parentSet($scope.$parent,parentValue=$scope[scopeName]):$scope[scopeName]=parentValue),lastValue=parentValue},parentValueWatch.$stateful=!0,$scope.$parent.$watch($parse($attrs[scopeName],parentValueWatch),null,parentGet.literal))}),$scope.query.page=$scope.query.page||tableConfig.query.page,$scope.query.count=$scope.query.count||tableConfig.query.count,$scope.query.sortBy=$scope.query.sortBy||tableConfig.query.sortBy,$scope.query.sortOrder=$scope.query.sortOrder||tableConfig.query.sortOrder,$scope.init.count=$scope.init.count||tableConfig.init.count,$scope.init.page=$scope.init.page||tableConfig.init.page,$scope.init.sortBy=$scope.init.sortBy||tableConfig.init.sortBy,$scope.init.sortOrder=$scope.init.sortOrder||tableConfig.init.sortOrder,$scope.clientSide=!0,$scope.url="",$scope.header={columns:[]},$scope.rows=[],$scope.params={},$scope.pagination={count:$scope.init.count,page:$scope.init.page,pages:1,size:0},$scope.theadDirective=!1,$scope.paginationDirective=!1,!angular.isDefined($attrs.resource)&&!angular.isDefined($attrs.resourceCallback))throw"AngularJS tastyTable directive: need the resource or resource-callback attribute";if(angular.isDefined($attrs.resource)){if(!angular.isObject($scope.resource))throw"AngularJS tastyTable directive: the resource ("+$attrs.resource+") it's not an object";if(!$scope.resource.header&&!$scope.resource.rows)throw"AngularJS tastyTable directive: the resource ("+$attrs.resource+") has the property header or rows undefined"}if(angular.isDefined($attrs.resourceCallback)){if(!angular.isFunction($scope.resourceCallback))throw"AngularJS tastyTable directive: the resource-callback ("+$attrs.resourceCallback+") it's not a function";$scope.clientSide=!1}this.activate=function(directiveName){$scope[directiveName+"Directive"]=!0,$scope.params[directiveName]=!0},this.setParams=function(key,value){$scope.params[key]=value,["sortBy","sortOrder"].indexOf(key)>=0&&($scope.header[key]=value)},this.bindOnce=tableConfig.bindOnce,$scope.setDirectivesValues=function(resource){if(!angular.isObject(resource))throw"AngularJS tastyTable directive: the resource it's not an object";if(!resource.header&&!resource.rows)throw"AngularJS tastyTable directive: the resource has the property header or rows undefined";1===Object.keys(resource.header[0]).length&&(resource.header=resource.header.map(function(header){var key=Object.keys(header)[0];return{key:key,name:header[key]}})),$scope.header={columns:resource.header,sortBy:$scope.params.sortBy,sortOrder:$scope.params.sortOrder},$scope.clientSide||($scope.header.sortBy=$scope.header.sortBy||resource.sortBy,$scope.header.sortOrder=$scope.header.sortOrder||resource.sortOrder),$scope.rows=resource.rows,$scope.paginationDirective&&resource.pagination&&($scope.pagination.count=resource.pagination.count,$scope.pagination.page=resource.pagination.page,$scope.pagination.pages=resource.pagination.pages,$scope.pagination.size=resource.pagination.size)},$scope.buildClientResource=function(){var fromRow,toRow,rowToShow,reverse,listSortBy;$scope.theadDirective&&(reverse="asc"===$scope.header.sortOrder?!1:!0,listSortBy=[function(item){return item[$scope.header.sortBy]}],$scope.header.columns[0].key!==$scope.header.sortBy&&listSortBy.push(function(item){return item[$scope.header.columns[0].key]}),$scope.header.sortBy&&($scope.rows=$filter("orderBy")($scope.rows,listSortBy,reverse))),$attrs.filters&&($scope.rows=$filter("filter")($scope.rows,$scope.filters)),$scope.paginationDirective&&($scope.pagination.page=$scope.params.page,$scope.pagination.count=$scope.params.count,$scope.pagination.size=$scope.rows.length,$scope.pagination.pages=Math.ceil($scope.rows.length/$scope.pagination.count),toRow=$scope.pagination.count*$scope.pagination.page,fromRow=toRow-$scope.pagination.count,fromRow>=0&&toRow>=0&&(rowToShow=$scope.rows.slice(fromRow,toRow),$scope.rows=rowToShow))},$scope.buildUrl=function(params,filters){var urlQuery,value,listKeyNotJoin;return urlQuery={},listKeyNotJoin=["sortBy","sortOrder","page","count"],$scope.theadDirective&&(urlQuery=tastyUtil.setProperty(urlQuery,params,"sortBy"),urlQuery=tastyUtil.setProperty(urlQuery,params,"sortOrder")),$scope.paginationDirective&&(urlQuery=tastyUtil.setProperty(urlQuery,params,"page"),urlQuery=tastyUtil.setProperty(urlQuery,params,"count")),$attrs.filters&&(urlQuery=tastyUtil.joinObjects(urlQuery,filters,listKeyNotJoin)),Object.keys(urlQuery).map(function(key){return value=urlQuery[key],$scope.query[key]&&(key=$scope.query[key]),encodeURIComponent(key)+"="+encodeURIComponent(value)}).join("&")},$scope.updateClientSideResource=tastyUtil.debounce(function(){$scope.setDirectivesValues($scope.resource),$scope.buildClientResource()},60),$scope.updateServerSideResource=tastyUtil.debounce(function(){$scope.url=$scope.buildUrl($scope.params,$scope.filters),$scope.resourceCallback($scope.url,$scope.params).then(function(resource){$scope.setDirectivesValues(resource)})},60),initTable=function(){$scope.clientSide?($scope.params.sortBy=$scope.resource.sortBy||$scope.init.sortBy,$scope.params.sortOrder=$scope.resource.sortOrder||$scope.init.sortOrder,$scope.params.page=$scope.init.page,$scope.resource.pagination&&($scope.params.page=$scope.resource.pagination.page||$scope.init.page),$scope.updateClientSideResource()):($scope.params.sortBy=$scope.init.sortBy,$scope.params.sortOrder=$scope.init.sortOrder,$scope.params.page=$scope.init.page,$scope.updateServerSideResource())},$attrs.filters&&$scope.$watch("filters",function(newValue,oldValue){newValue!==oldValue&&($scope.clientSide?$scope.updateClientSideResource():$scope.updateServerSideResource())},!0),$scope.$watchCollection("params",function(newValue,oldValue){newValue!==oldValue&&($scope.clientSide?$scope.updateClientSideResource():$scope.updateServerSideResource())}),$scope.resource&&$scope.$watch("resource",function(newValue,oldValue){newValue!==oldValue&&($scope.params.sortBy=newValue.sortBy,$scope.params.sortOrder=newValue.sortOrder,$scope.updateClientSideResource())},!0),initTable()}]).directive("tastyTable",function(){return{restrict:"A",scope:!0,controller:"TableController"}}).directive("tastyThead",["$filter",function($filter){return{restrict:"AE",require:"^tastyTable",scope:{notSortBy:"="},templateUrl:"template/table/head.html",link:function(scope,element,attrs,tastyTable){"use strict";var iconUp,iconDown;tastyTable.activate("thead"),scope.bindOnce=tastyTable.bindOnce,scope.columns=[],iconUp="fa fa-sort-up",iconDown="fa fa-sort-down",scope.setColumns=function(){var lenHeader,active,sortable,sort,isSorted;scope.columns=[],lenHeader=scope.header.columns.length,scope.header.columns.forEach(function(column){column.style=column.style||{},sortable=!0,active=!1,isSorted="",angular.isArray(scope.notSortBy)&&(sortable=scope.notSortBy.length?scope.notSortBy.indexOf(column.key)<0:!1),(column.key===scope.header.sortBy||"-"+column.key===scope.header.sortBy)&&(active=!0),sort=$filter("cleanFieldName")(column.key),scope.header.sortBy==="-"+sort?isSorted=iconDown:scope.header.sortBy===sort&&(isSorted=iconUp),scope.columns.push({key:column.key,name:column.name,active:active,sortable:sortable,style:column.style,isSorted:isSorted})}),"dsc"===scope.header.sortOrder&&scope.header.sortBy&&"-"!==scope.header.sortBy[0]&&(scope.header.sortBy="-"+scope.header.sortBy)},scope.sortBy=function(column){if(!column.sortable)return!1;var columnName,sortOrder;columnName=$filter("cleanFieldName")(column.key),sortOrder=scope.header.sortBy===columnName?"dsc":"asc",tastyTable.setParams("sortBy",column.key),tastyTable.setParams("sortOrder",sortOrder)},scope.classToShow=function(column){var listClassToShow=[];return column.sortable&&listClassToShow.push("sortable"),column.active&&listClassToShow.push("active"),listClassToShow},tastyTable.$scope.$watchCollection("header",function(newValue,oldValue){newValue&&newValue!==oldValue&&(scope.header=newValue,scope.setColumns())})}}}]).directive("tastyPagination",["$filter","$templateCache","$http","$compile","$parse","tableConfig",function($filter,$templateCache,$http,$compile,$parse,tableConfig){return{restrict:"AE",require:"^tastyTable",scope:{},templateUrl:function(tElement,tAttrs){return tAttrs.templateUrl||"template/table/pagination.html"},link:function(scope,element,attrs,tastyTable){"use strict";var getPage,setCount,setPaginationRange,setPreviousRange,setRemainingRange,setPaginationRanges,listScopeToWatch;listScopeToWatch=["itemsPerPage","listItemsPerPage"],listScopeToWatch.forEach(function(scopeName){var lastValue,parentGet,compare,parentSet,parentValueWatch;attrs[scopeName]&&(parentGet=$parse(attrs[scopeName]),compare=parentGet.literal?equals:function(a,b){return a===b||a!==a&&b!==b},parentSet=parentGet.assign,lastValue=scope[scopeName]=parentGet(scope.$parent),parentValueWatch=function(parentValue){return compare(parentValue,scope[scopeName])||(compare(parentValue,lastValue)?parentSet(scope.$parent,parentValue=scope[scopeName]):$scope[scopeName]=parentValue),lastValue=parentValue},parentValueWatch.$stateful=!0,scope.$parent.$watch($parse(attrs[scopeName],parentValueWatch),null,parentGet.literal))}),scope.itemsPerPage=scope.itemsPerPage||tableConfig.itemsPerPage,scope.listItemsPerPage=scope.listItemsPerPage||tableConfig.listItemsPerPage,tastyTable.activate("pagination"),scope.pagination={},scope.pagMinRange=1,scope.pagMaxRange=1,getPage=function(numPage){tastyTable.setParams("page",numPage)},setCount=function(count){var maxItems,page;maxItems=count*scope.pagination.page,maxItems>scope.pagination.size&&(page=Math.ceil(scope.pagination.size/count),tastyTable.setParams("page",page)),tastyTable.setParams("count",count)},setPaginationRange=function(){var currentPage;currentPage=scope.pagination.page,currentPage>scope.pagination.pages&&(currentPage=scope.pagination.pages),scope.pagMinRange=currentPage-2>0?currentPage-2:1,scope.pagMaxRange=currentPage+2,scope.pagination.page=currentPage,setPaginationRanges()},setPreviousRange=function(){return scope.pagHideMinRange===!0||scope.pagMinRange<1?!1:(scope.pagMaxRange=scope.pagMinRange,scope.pagMinRange=scope.pagMaxRange-scope.itemsPerPage,setPaginationRanges(),void 0)},setRemainingRange=function(){return scope.pagHideMaxRange===!0||scope.pagMaxRange>scope.pagination.pages?!1:(scope.pagMinRange=scope.pagMaxRange,scope.pagMaxRange=scope.pagMinRange+scope.itemsPerPage,scope.pagMaxRange>scope.pagination.pages&&(scope.pagMaxRange=scope.pagination.pages),scope.pagMinRange=scope.pagMaxRange-scope.itemsPerPage,setPaginationRanges(),void 0)},setPaginationRanges=function(){scope.listItemsPerPageShow=[],scope.pagMinRange=scope.pagMinRange>0?scope.pagMinRange:1,scope.pagMaxRange=scope.pagMinRange+5,scope.pagMaxRange>scope.pagination.pages&&(scope.pagMaxRange=scope.pagination.pages+1),scope.pagHideMinRange=scope.pagMinRange<=1,scope.pagHideMaxRange=scope.pagMaxRange>=scope.pagination.pages,scope.classPageMinRange=scope.pagHideMinRange?"disabled":"",scope.classPageMaxRange=scope.pagHideMaxRange?"disabled":"";for(var i=scope.listItemsPerPage.length;i>=0;i--)if(scope.pagination.size>scope.listItemsPerPage[i]){scope.listItemsPerPageShow=scope.listItemsPerPage.slice(0,i+1);break}scope.rangePage=$filter("range")([],scope.pagMinRange,scope.pagMaxRange)},scope.classPaginationCount=function(count){return count==scope.pagination.count?"active":""},scope.classNumPage=function(numPage){return numPage==scope.pagination.page?"active":!1},scope.page={get:getPage,setCount:setCount,previous:setPreviousRange,remaining:setRemainingRange},tastyTable.$scope.$watchCollection("pagination",function(newValue,oldValue){newValue&&newValue!==oldValue&&(scope.pagination=newValue,setPaginationRange())}),scope.page.setCount(scope.itemsPerPage)}}}]),angular.module("template/table/head.html",[]).run(["$templateCache",function($templateCache){$templateCache.put("template/table/head.html",'<tr>\n <th ng-repeat="column in columns track by $index" \n ng-class="classToShow(column)"\n ng-style="::column.style" ng-click="sortBy(column)">\n <span ng-bind="::column.name"></span>\n <span ng-class="column.isSorted"></span>\n </th> \n</tr>')}]),angular.module("template/table/pagination.html",[]).run(["$templateCache",function($templateCache){$templateCache.put("template/table/pagination.html",'<div class="row">\n <div class="col-xs-3 text-left">\n <div class="btn-group">\n <button type="button" class="btn btn-default" \n ng-repeat="count in listItemsPerPageShow" \n ng-class="classPaginationCount(count)" \n ng-click="page.setCount(count)" ng-bind="count"></button>\n </div>\n </div>\n <div class="col-xs-6 text-center">\n <ul class="pagination">\n <li ng-class="classPageMinRange">\n <a href ng-click="page.previous()">&laquo;</a>\n </li>\n <li ng-repeat="numPage in rangePage" ng-class="classNumPage(numPage)">\n <a href ng-click="page.get(numPage)">\n <span ng-bind="numPage"></span>\n <span class="sr-only" ng-if="classNumPage(numPage)">(current)</span>\n </a>\n </li>\n <li ng-class="classPageMaxRange">\n <a href ng-click="page.remaining()">&raquo;</a>\n </li>\n </ul>\n </div>\n <div class="col-xs-3 text-right">\n <p>Page <span ng-bind="pagination.page"></span> \n of <span ng-bind="pagination.pages"></span>,\n of <span ng-bind="pagination.size"></span> entries</p>\n </div>\n</div>')}]);

@@ -5,3 +5,3 @@ /*

* Version: 0.3.1 - 2014-11-10
* Version: 0.3.3 - 2014-11-28
* License: MIT

@@ -278,3 +278,3 @@ */

'sortBy': 'sort-by',
'sortOrder': 'sort-order',
'sortOrder': 'sort-order'
},

@@ -289,2 +289,4 @@ listItemsPerPage: [5, 25, 50, 100],

this.$scope = $scope;
$scope.init = {};
$scope.query = {};

@@ -323,4 +325,6 @@ listScopeToWatch = ['filters', 'init', 'query', 'resource', 'resourceCallback'];

// Default configs
$scope.query = $scope.query || tableConfig.query;
$scope.init = $scope.init || {};
$scope.query.page = $scope.query.page || tableConfig.query.page;
$scope.query.count = $scope.query.count || tableConfig.query.count;
$scope.query.sortBy = $scope.query.sortBy || tableConfig.query.sortBy;
$scope.query.sortOrder = $scope.query.sortOrder || tableConfig.query.sortOrder;
$scope.init.count = $scope.init.count || tableConfig.init.count;

@@ -412,2 +416,6 @@ $scope.init.page = $scope.init.page || tableConfig.init.page;

};
if (!$scope.clientSide) {
$scope.header.sortBy = $scope.header.sortBy || resource.sortBy;
$scope.header.sortOrder = $scope.header.sortOrder || resource.sortOrder;
}
$scope.rows = resource.rows;

@@ -585,8 +593,14 @@ if ($scope.paginationDirective && resource.pagination) {

scope.header.columns.forEach(function (column, index) {
width = parseFloat((100 / lenHeader).toFixed(2));
column.style = column.style || {};
sortable = true;
active = false;
isSorted = '';
if (scope.notSortBy) {
sortable = scope.notSortBy.indexOf(column.key) < 0;
// Not sort column when the key is present in the `notSortBy` list,
// and Not sort column when `notSortBy` is an empty list
if (angular.isArray(scope.notSortBy)) {
if (scope.notSortBy.length) {
sortable = scope.notSortBy.indexOf(column.key) < 0;
} else {
sortable = false;
}
}

@@ -608,3 +622,3 @@ if (column.key === scope.header.sortBy ||

'sortable': sortable,
'width': { 'width': width + '%' },
'style': column.style,
'isSorted': isSorted

@@ -621,3 +635,3 @@ });

scope.sortBy = function (column) {
if (scope.notSortBy && scope.notSortBy.indexOf(column.key) >= 0) {
if (!column.sortable) {
return false;

@@ -670,14 +684,3 @@ }

*/
.controller('TablePaginationController', ["$scope", "$attrs", "tableConfig", function($scope, $attrs, tableConfig) {
if (angular.isDefined($attrs.itemsPerPage)) {
$scope.itemsPerPage = $scope.$parent[$attrs.itemsPerPage];
}
if (angular.isDefined($attrs.listItemsPerPage)) {
$scope.listItemsPerPage = $scope.$parent[$attrs.listItemsPerPage];
}
// Default configs
$scope.itemsPerPage = $scope.itemsPerPage || tableConfig.itemsPerPage;
$scope.listItemsPerPage = $scope.listItemsPerPage || tableConfig.listItemsPerPage;
}])
.directive('tastyPagination', ["$filter", function($filter) {
.directive('tastyPagination', ["$filter", "$templateCache", "$http", "$compile", "$parse", "tableConfig", function($filter, $templateCache, $http, $compile, $parse, tableConfig) {
return {

@@ -687,4 +690,5 @@ restrict: 'AE',

scope: {},
templateUrl: 'template/table/pagination.html',
controller: 'TablePaginationController',
templateUrl: function(tElement, tAttrs) {
return tAttrs.templateUrl || 'template/table/pagination.html';
},
link: function (scope, element, attrs, tastyTable) {

@@ -694,4 +698,40 @@ 'use strict';

setPreviousRange, setRemainingRange,
setPaginationRanges;
setPaginationRanges, listScopeToWatch;
listScopeToWatch = ['itemsPerPage', 'listItemsPerPage'];
listScopeToWatch.forEach(function (scopeName) {
var lastValue, parentGet, compare, parentSet, parentValueWatch;
if (!attrs[scopeName]) {
return;
}
parentGet = $parse(attrs[scopeName]);
if (parentGet.literal) {
compare = equals;
} else {
compare = function(a,b) { return a === b || (a !== a && b !== b); };
}
parentSet = parentGet.assign;
lastValue = scope[scopeName] = parentGet(scope.$parent);
parentValueWatch = function parentValueWatch(parentValue) {
if (!compare(parentValue, scope[scopeName])) {
// we are out of sync and need to copy
if (!compare(parentValue, lastValue)) {
// parent changed and it has precedence
$scope[scopeName] = parentValue;
} else {
// if the parent can be assigned then do so
parentSet(scope.$parent, parentValue = scope[scopeName]);
}
}
return lastValue = parentValue;
};
parentValueWatch.$stateful = true;
scope.$parent.$watch($parse(attrs[scopeName], parentValueWatch), null, parentGet.literal);
});
// Default configs
scope.itemsPerPage = scope.itemsPerPage || tableConfig.itemsPerPage;
scope.listItemsPerPage = scope.listItemsPerPage || tableConfig.listItemsPerPage;
// Pagination it's called

@@ -698,0 +738,0 @@ tastyTable.activate('pagination');

@@ -5,5 +5,5 @@ /*

* Version: 0.3.1 - 2014-11-10
* Version: 0.3.3 - 2014-11-28
* License: MIT
*/
angular.module("ngTasty",["ngTasty.filter","ngTasty.service","ngTasty.table"]),angular.module("ngTasty.filter",["ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range"]),angular.module("ngTasty.filter.cleanFieldName",[]).filter("cleanFieldName",function(){return function(input){return input.replace(/[^a-zA-Z0-9-]+/g,"-")}}),angular.module("ngTasty.filter.filterInt",[]).filter("filterInt",function(){return function(input){return/^(\-|\+)?([0-9]+|Infinity)$/.test(input)?Number(input):0/0}}),angular.module("ngTasty.filter.range",[]).filter("range",["$filter",function($filter){return function(input,start,stop,step){if(start=$filter("filterInt")(start),stop=$filter("filterInt")(stop),step=$filter("filterInt")(step),isNaN(start)&&(start=0),isNaN(stop)&&(stop=start,start=0),isNaN(step)&&(step=1),step>0&&start>=stop||0>step&&stop>=start)return[];for(var i=start;step>0?stop>i:i>stop;i+=step)input.push(i);return input}}]),angular.module("ngTasty.service",["ngTasty.service.tastyUtil","ngTasty.service.debounce","ngTasty.service.setProperty","ngTasty.service.joinObjects","ngTasty.service.webSocket"]),angular.module("ngTasty.service.tastyUtil",["ngTasty.service.debounce","ngTasty.service.setProperty","ngTasty.service.joinObjects"]).factory("tastyUtil",["debounce","setProperty","joinObjects",function(debounce,setProperty,joinObjects){return{debounce:debounce,setProperty:setProperty,joinObjects:joinObjects}}]),angular.module("ngTasty.service.debounce",[]).factory("debounce",["$timeout",function($timeout){return function(func,wait){var timeout;return function(){var context=this,args=arguments;$timeout.cancel(timeout),timeout=$timeout(function(){timeout=null,func.apply(context,args)},wait)}}}]),angular.module("ngTasty.service.setProperty",[]).factory("setProperty",function(){return function(objOne,objTwo,attrname){return"undefined"!=typeof objTwo[attrname]&&null!==objTwo[attrname]&&(objOne[attrname]=objTwo[attrname]),objOne}}),angular.module("ngTasty.service.joinObjects",[]).factory("joinObjects",["setProperty",function(setProperty){return function(objOne,objTwo,listKeyNotJoin){listKeyNotJoin=listKeyNotJoin||[];for(var attrname in objTwo)listKeyNotJoin.indexOf(attrname)<0&&setProperty(objOne,objTwo,attrname);return objOne}}]),angular.module("ngTasty.service.webSocket",["ngTasty.service"]).factory("WebSocket",function(){return function(url){var blobURL=URL.createObjectURL(new Blob(["(",function(){var WSWorker=function(){var _ws,initialize=function(url){_ws=new WebSocket(url)},on=function(){_ws.onmessage=function(response){var data=JSON.parse(response.data);self.postMessage(data)}},send=function(data){_ws.send(data)};return{initialize:initialize,on:on,send:send}}();self.addEventListener("message",function(e){switch(e.data.cmd){case"ws_new":WSWorker.initialize(e.data.url);break;case"ws_on":WSWorker.on(e.data.event,e.data.cb);break;case"ws_send":WSWorker.send(JSON.stringify(e.data.data));break;default:console.log("Unknown command: "+e.data.cmd)}})}.toString(),")()"],{type:"application/javascript"})),_worker=new Worker(blobURL);return URL.revokeObjectURL(blobURL),_worker.postMessage({cmd:"ws_new",url:url}),{on:function(event,cb){_worker.postMessage({cmd:"ws_on"}),_worker.addEventListener("message",function(e){("all"===event||e.data.type===event)&&cb(e.data)})},send:function(data){_worker.postMessage({cmd:"ws_send",data:data})}}}}),angular.module("ngTasty.table",["ngTasty.filter.cleanFieldName","ngTasty.filter.range","ngTasty.service.tastyUtil"]).constant("tableConfig",{init:{count:5,page:1,sortBy:void 0,sortOrder:void 0},query:{page:"page",count:"count",sortBy:"sort-by",sortOrder:"sort-order"},listItemsPerPage:[5,25,50,100],itemsPerPage:5,bindOnce:!0}).controller("TableController",["$scope","$attrs","$timeout","$filter","$parse","tableConfig","tastyUtil",function($scope,$attrs,$timeout,$filter,$parse,tableConfig,tastyUtil){"use strict";var listScopeToWatch,initTable;if(this.$scope=$scope,listScopeToWatch=["filters","init","query","resource","resourceCallback"],listScopeToWatch.forEach(function(scopeName){var lastValue,parentGet,compare,parentSet,parentValueWatch;$attrs[scopeName]&&(parentGet=$parse($attrs[scopeName]),compare=parentGet.literal?equals:function(a,b){return a===b||a!==a&&b!==b},parentSet=parentGet.assign,lastValue=$scope[scopeName]=parentGet($scope.$parent),parentValueWatch=function(parentValue){return compare(parentValue,$scope[scopeName])||(compare(parentValue,lastValue)?parentSet($scope.$parent,parentValue=$scope[scopeName]):$scope[scopeName]=parentValue),lastValue=parentValue},parentValueWatch.$stateful=!0,$scope.$parent.$watch($parse($attrs[scopeName],parentValueWatch),null,parentGet.literal))}),$scope.query=$scope.query||tableConfig.query,$scope.init=$scope.init||{},$scope.init.count=$scope.init.count||tableConfig.init.count,$scope.init.page=$scope.init.page||tableConfig.init.page,$scope.init.sortBy=$scope.init.sortBy||tableConfig.init.sortBy,$scope.init.sortOrder=$scope.init.sortOrder||tableConfig.init.sortOrder,$scope.clientSide=!0,$scope.url="",$scope.header={columns:[]},$scope.rows=[],$scope.params={},$scope.pagination={count:$scope.init.count,page:$scope.init.page,pages:1,size:0},$scope.theadDirective=!1,$scope.paginationDirective=!1,!angular.isDefined($attrs.resource)&&!angular.isDefined($attrs.resourceCallback))throw"AngularJS tastyTable directive: need the resource or resource-callback attribute";if(angular.isDefined($attrs.resource)){if(!angular.isObject($scope.resource))throw"AngularJS tastyTable directive: the resource ("+$attrs.resource+") it's not an object";if(!$scope.resource.header&&!$scope.resource.rows)throw"AngularJS tastyTable directive: the resource ("+$attrs.resource+") has the property header or rows undefined"}if(angular.isDefined($attrs.resourceCallback)){if(!angular.isFunction($scope.resourceCallback))throw"AngularJS tastyTable directive: the resource-callback ("+$attrs.resourceCallback+") it's not a function";$scope.clientSide=!1}this.activate=function(directiveName){$scope[directiveName+"Directive"]=!0,$scope.params[directiveName]=!0},this.setParams=function(key,value){$scope.params[key]=value,["sortBy","sortOrder"].indexOf(key)>=0&&($scope.header[key]=value)},this.bindOnce=tableConfig.bindOnce,$scope.setDirectivesValues=function(resource){if(!angular.isObject(resource))throw"AngularJS tastyTable directive: the resource it's not an object";if(!resource.header&&!resource.rows)throw"AngularJS tastyTable directive: the resource has the property header or rows undefined";1===Object.keys(resource.header[0]).length&&(resource.header=resource.header.map(function(header){var key=Object.keys(header)[0];return{key:key,name:header[key]}})),$scope.header={columns:resource.header,sortBy:$scope.params.sortBy,sortOrder:$scope.params.sortOrder},$scope.rows=resource.rows,$scope.paginationDirective&&resource.pagination&&($scope.pagination.count=resource.pagination.count,$scope.pagination.page=resource.pagination.page,$scope.pagination.pages=resource.pagination.pages,$scope.pagination.size=resource.pagination.size)},$scope.buildClientResource=function(){var fromRow,toRow,rowToShow,reverse,listSortBy;$scope.theadDirective&&(reverse="asc"===$scope.header.sortOrder?!1:!0,listSortBy=[function(item){return item[$scope.header.sortBy]}],$scope.header.columns[0].key!==$scope.header.sortBy&&listSortBy.push(function(item){return item[$scope.header.columns[0].key]}),$scope.header.sortBy&&($scope.rows=$filter("orderBy")($scope.rows,listSortBy,reverse))),$attrs.filters&&($scope.rows=$filter("filter")($scope.rows,$scope.filters)),$scope.paginationDirective&&($scope.pagination.page=$scope.params.page,$scope.pagination.count=$scope.params.count,$scope.pagination.size=$scope.rows.length,$scope.pagination.pages=Math.ceil($scope.rows.length/$scope.pagination.count),toRow=$scope.pagination.count*$scope.pagination.page,fromRow=toRow-$scope.pagination.count,fromRow>=0&&toRow>=0&&(rowToShow=$scope.rows.slice(fromRow,toRow),$scope.rows=rowToShow))},$scope.buildUrl=function(params,filters){var urlQuery,value,listKeyNotJoin;return urlQuery={},listKeyNotJoin=["sortBy","sortOrder","page","count"],$scope.theadDirective&&(urlQuery=tastyUtil.setProperty(urlQuery,params,"sortBy"),urlQuery=tastyUtil.setProperty(urlQuery,params,"sortOrder")),$scope.paginationDirective&&(urlQuery=tastyUtil.setProperty(urlQuery,params,"page"),urlQuery=tastyUtil.setProperty(urlQuery,params,"count")),$attrs.filters&&(urlQuery=tastyUtil.joinObjects(urlQuery,filters,listKeyNotJoin)),Object.keys(urlQuery).map(function(key){return value=urlQuery[key],$scope.query[key]&&(key=$scope.query[key]),encodeURIComponent(key)+"="+encodeURIComponent(value)}).join("&")},$scope.updateClientSideResource=tastyUtil.debounce(function(){$scope.setDirectivesValues($scope.resource),$scope.buildClientResource()},60),$scope.updateServerSideResource=tastyUtil.debounce(function(){$scope.url=$scope.buildUrl($scope.params,$scope.filters),$scope.resourceCallback($scope.url,$scope.params).then(function(resource){$scope.setDirectivesValues(resource)})},60),initTable=function(){$scope.clientSide?($scope.params.sortBy=$scope.resource.sortBy||$scope.init.sortBy,$scope.params.sortOrder=$scope.resource.sortOrder||$scope.init.sortOrder,$scope.params.page=$scope.init.page,$scope.resource.pagination&&($scope.params.page=$scope.resource.pagination.page||$scope.init.page),$scope.updateClientSideResource()):($scope.params.sortBy=$scope.init.sortBy,$scope.params.sortOrder=$scope.init.sortOrder,$scope.params.page=$scope.init.page,$scope.updateServerSideResource())},$attrs.filters&&$scope.$watch("filters",function(newValue,oldValue){newValue!==oldValue&&($scope.clientSide?$scope.updateClientSideResource():$scope.updateServerSideResource())},!0),$scope.$watchCollection("params",function(newValue,oldValue){newValue!==oldValue&&($scope.clientSide?$scope.updateClientSideResource():$scope.updateServerSideResource())}),$scope.resource&&$scope.$watch("resource",function(newValue,oldValue){newValue!==oldValue&&($scope.params.sortBy=newValue.sortBy,$scope.params.sortOrder=newValue.sortOrder,$scope.updateClientSideResource())},!0),initTable()}]).directive("tastyTable",function(){return{restrict:"A",scope:!0,controller:"TableController"}}).directive("tastyThead",["$filter",function($filter){return{restrict:"AE",require:"^tastyTable",scope:{notSortBy:"="},templateUrl:"template/table/head.html",link:function(scope,element,attrs,tastyTable){"use strict";var iconUp,iconDown;tastyTable.activate("thead"),scope.bindOnce=tastyTable.bindOnce,scope.columns=[],iconUp="fa fa-sort-up",iconDown="fa fa-sort-down",scope.setColumns=function(){var lenHeader,width,active,sortable,sort,isSorted;scope.columns=[],lenHeader=scope.header.columns.length,scope.header.columns.forEach(function(column){width=parseFloat((100/lenHeader).toFixed(2)),sortable=!0,active=!1,isSorted="",scope.notSortBy&&(sortable=scope.notSortBy.indexOf(column.key)<0),(column.key===scope.header.sortBy||"-"+column.key===scope.header.sortBy)&&(active=!0),sort=$filter("cleanFieldName")(column.key),scope.header.sortBy==="-"+sort?isSorted=iconDown:scope.header.sortBy===sort&&(isSorted=iconUp),scope.columns.push({key:column.key,name:column.name,active:active,sortable:sortable,width:{width:width+"%"},isSorted:isSorted})}),"dsc"===scope.header.sortOrder&&scope.header.sortBy&&"-"!==scope.header.sortBy[0]&&(scope.header.sortBy="-"+scope.header.sortBy)},scope.sortBy=function(column){if(scope.notSortBy&&scope.notSortBy.indexOf(column.key)>=0)return!1;var columnName,sortOrder;columnName=$filter("cleanFieldName")(column.key),sortOrder=scope.header.sortBy===columnName?"dsc":"asc",tastyTable.setParams("sortBy",column.key),tastyTable.setParams("sortOrder",sortOrder)},scope.classToShow=function(column){var listClassToShow=[];return column.sortable&&listClassToShow.push("sortable"),column.active&&listClassToShow.push("active"),listClassToShow},tastyTable.$scope.$watchCollection("header",function(newValue,oldValue){newValue&&newValue!==oldValue&&(scope.header=newValue,scope.setColumns())})}}}]).controller("TablePaginationController",["$scope","$attrs","tableConfig",function($scope,$attrs,tableConfig){angular.isDefined($attrs.itemsPerPage)&&($scope.itemsPerPage=$scope.$parent[$attrs.itemsPerPage]),angular.isDefined($attrs.listItemsPerPage)&&($scope.listItemsPerPage=$scope.$parent[$attrs.listItemsPerPage]),$scope.itemsPerPage=$scope.itemsPerPage||tableConfig.itemsPerPage,$scope.listItemsPerPage=$scope.listItemsPerPage||tableConfig.listItemsPerPage}]).directive("tastyPagination",["$filter",function($filter){return{restrict:"AE",require:"^tastyTable",scope:{},templateUrl:"template/table/pagination.html",controller:"TablePaginationController",link:function(scope,element,attrs,tastyTable){"use strict";var getPage,setCount,setPaginationRange,setPreviousRange,setRemainingRange,setPaginationRanges;tastyTable.activate("pagination"),scope.pagination={},scope.pagMinRange=1,scope.pagMaxRange=1,getPage=function(numPage){tastyTable.setParams("page",numPage)},setCount=function(count){var maxItems,page;maxItems=count*scope.pagination.page,maxItems>scope.pagination.size&&(page=Math.ceil(scope.pagination.size/count),tastyTable.setParams("page",page)),tastyTable.setParams("count",count)},setPaginationRange=function(){var currentPage;currentPage=scope.pagination.page,currentPage>scope.pagination.pages&&(currentPage=scope.pagination.pages),scope.pagMinRange=currentPage-2>0?currentPage-2:1,scope.pagMaxRange=currentPage+2,scope.pagination.page=currentPage,setPaginationRanges()},setPreviousRange=function(){return scope.pagHideMinRange===!0||scope.pagMinRange<1?!1:(scope.pagMaxRange=scope.pagMinRange,scope.pagMinRange=scope.pagMaxRange-scope.itemsPerPage,setPaginationRanges(),void 0)},setRemainingRange=function(){return scope.pagHideMaxRange===!0||scope.pagMaxRange>scope.pagination.pages?!1:(scope.pagMinRange=scope.pagMaxRange,scope.pagMaxRange=scope.pagMinRange+scope.itemsPerPage,scope.pagMaxRange>scope.pagination.pages&&(scope.pagMaxRange=scope.pagination.pages),scope.pagMinRange=scope.pagMaxRange-scope.itemsPerPage,setPaginationRanges(),void 0)},setPaginationRanges=function(){scope.listItemsPerPageShow=[],scope.pagMinRange=scope.pagMinRange>0?scope.pagMinRange:1,scope.pagMaxRange=scope.pagMinRange+5,scope.pagMaxRange>scope.pagination.pages&&(scope.pagMaxRange=scope.pagination.pages+1),scope.pagHideMinRange=scope.pagMinRange<=1,scope.pagHideMaxRange=scope.pagMaxRange>=scope.pagination.pages,scope.classPageMinRange=scope.pagHideMinRange?"disabled":"",scope.classPageMaxRange=scope.pagHideMaxRange?"disabled":"";for(var i=scope.listItemsPerPage.length;i>=0;i--)if(scope.pagination.size>scope.listItemsPerPage[i]){scope.listItemsPerPageShow=scope.listItemsPerPage.slice(0,i+1);break}scope.rangePage=$filter("range")([],scope.pagMinRange,scope.pagMaxRange)},scope.classPaginationCount=function(count){return count==scope.pagination.count?"active":""},scope.classNumPage=function(numPage){return numPage==scope.pagination.page?"active":!1},scope.page={get:getPage,setCount:setCount,previous:setPreviousRange,remaining:setRemainingRange},tastyTable.$scope.$watchCollection("pagination",function(newValue,oldValue){newValue&&newValue!==oldValue&&(scope.pagination=newValue,setPaginationRange())}),scope.page.setCount(scope.itemsPerPage)}}}]);
angular.module("ngTasty",["ngTasty.filter","ngTasty.service","ngTasty.table"]),angular.module("ngTasty.filter",["ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range"]),angular.module("ngTasty.filter.cleanFieldName",[]).filter("cleanFieldName",function(){return function(input){return input.replace(/[^a-zA-Z0-9-]+/g,"-")}}),angular.module("ngTasty.filter.filterInt",[]).filter("filterInt",function(){return function(input){return/^(\-|\+)?([0-9]+|Infinity)$/.test(input)?Number(input):0/0}}),angular.module("ngTasty.filter.range",[]).filter("range",["$filter",function($filter){return function(input,start,stop,step){if(start=$filter("filterInt")(start),stop=$filter("filterInt")(stop),step=$filter("filterInt")(step),isNaN(start)&&(start=0),isNaN(stop)&&(stop=start,start=0),isNaN(step)&&(step=1),step>0&&start>=stop||0>step&&stop>=start)return[];for(var i=start;step>0?stop>i:i>stop;i+=step)input.push(i);return input}}]),angular.module("ngTasty.service",["ngTasty.service.tastyUtil","ngTasty.service.debounce","ngTasty.service.setProperty","ngTasty.service.joinObjects","ngTasty.service.webSocket"]),angular.module("ngTasty.service.tastyUtil",["ngTasty.service.debounce","ngTasty.service.setProperty","ngTasty.service.joinObjects"]).factory("tastyUtil",["debounce","setProperty","joinObjects",function(debounce,setProperty,joinObjects){return{debounce:debounce,setProperty:setProperty,joinObjects:joinObjects}}]),angular.module("ngTasty.service.debounce",[]).factory("debounce",["$timeout",function($timeout){return function(func,wait){var timeout;return function(){var context=this,args=arguments;$timeout.cancel(timeout),timeout=$timeout(function(){timeout=null,func.apply(context,args)},wait)}}}]),angular.module("ngTasty.service.setProperty",[]).factory("setProperty",function(){return function(objOne,objTwo,attrname){return"undefined"!=typeof objTwo[attrname]&&null!==objTwo[attrname]&&(objOne[attrname]=objTwo[attrname]),objOne}}),angular.module("ngTasty.service.joinObjects",[]).factory("joinObjects",["setProperty",function(setProperty){return function(objOne,objTwo,listKeyNotJoin){listKeyNotJoin=listKeyNotJoin||[];for(var attrname in objTwo)listKeyNotJoin.indexOf(attrname)<0&&setProperty(objOne,objTwo,attrname);return objOne}}]),angular.module("ngTasty.service.webSocket",["ngTasty.service"]).factory("WebSocket",function(){return function(url){var blobURL=URL.createObjectURL(new Blob(["(",function(){var WSWorker=function(){var _ws,initialize=function(url){_ws=new WebSocket(url)},on=function(){_ws.onmessage=function(response){var data=JSON.parse(response.data);self.postMessage(data)}},send=function(data){_ws.send(data)};return{initialize:initialize,on:on,send:send}}();self.addEventListener("message",function(e){switch(e.data.cmd){case"ws_new":WSWorker.initialize(e.data.url);break;case"ws_on":WSWorker.on(e.data.event,e.data.cb);break;case"ws_send":WSWorker.send(JSON.stringify(e.data.data));break;default:console.log("Unknown command: "+e.data.cmd)}})}.toString(),")()"],{type:"application/javascript"})),_worker=new Worker(blobURL);return URL.revokeObjectURL(blobURL),_worker.postMessage({cmd:"ws_new",url:url}),{on:function(event,cb){_worker.postMessage({cmd:"ws_on"}),_worker.addEventListener("message",function(e){("all"===event||e.data.type===event)&&cb(e.data)})},send:function(data){_worker.postMessage({cmd:"ws_send",data:data})}}}}),angular.module("ngTasty.table",["ngTasty.filter.cleanFieldName","ngTasty.filter.range","ngTasty.service.tastyUtil"]).constant("tableConfig",{init:{count:5,page:1,sortBy:void 0,sortOrder:void 0},query:{page:"page",count:"count",sortBy:"sort-by",sortOrder:"sort-order"},listItemsPerPage:[5,25,50,100],itemsPerPage:5,bindOnce:!0}).controller("TableController",["$scope","$attrs","$timeout","$filter","$parse","tableConfig","tastyUtil",function($scope,$attrs,$timeout,$filter,$parse,tableConfig,tastyUtil){"use strict";var listScopeToWatch,initTable;if(this.$scope=$scope,$scope.init={},$scope.query={},listScopeToWatch=["filters","init","query","resource","resourceCallback"],listScopeToWatch.forEach(function(scopeName){var lastValue,parentGet,compare,parentSet,parentValueWatch;$attrs[scopeName]&&(parentGet=$parse($attrs[scopeName]),compare=parentGet.literal?equals:function(a,b){return a===b||a!==a&&b!==b},parentSet=parentGet.assign,lastValue=$scope[scopeName]=parentGet($scope.$parent),parentValueWatch=function(parentValue){return compare(parentValue,$scope[scopeName])||(compare(parentValue,lastValue)?parentSet($scope.$parent,parentValue=$scope[scopeName]):$scope[scopeName]=parentValue),lastValue=parentValue},parentValueWatch.$stateful=!0,$scope.$parent.$watch($parse($attrs[scopeName],parentValueWatch),null,parentGet.literal))}),$scope.query.page=$scope.query.page||tableConfig.query.page,$scope.query.count=$scope.query.count||tableConfig.query.count,$scope.query.sortBy=$scope.query.sortBy||tableConfig.query.sortBy,$scope.query.sortOrder=$scope.query.sortOrder||tableConfig.query.sortOrder,$scope.init.count=$scope.init.count||tableConfig.init.count,$scope.init.page=$scope.init.page||tableConfig.init.page,$scope.init.sortBy=$scope.init.sortBy||tableConfig.init.sortBy,$scope.init.sortOrder=$scope.init.sortOrder||tableConfig.init.sortOrder,$scope.clientSide=!0,$scope.url="",$scope.header={columns:[]},$scope.rows=[],$scope.params={},$scope.pagination={count:$scope.init.count,page:$scope.init.page,pages:1,size:0},$scope.theadDirective=!1,$scope.paginationDirective=!1,!angular.isDefined($attrs.resource)&&!angular.isDefined($attrs.resourceCallback))throw"AngularJS tastyTable directive: need the resource or resource-callback attribute";if(angular.isDefined($attrs.resource)){if(!angular.isObject($scope.resource))throw"AngularJS tastyTable directive: the resource ("+$attrs.resource+") it's not an object";if(!$scope.resource.header&&!$scope.resource.rows)throw"AngularJS tastyTable directive: the resource ("+$attrs.resource+") has the property header or rows undefined"}if(angular.isDefined($attrs.resourceCallback)){if(!angular.isFunction($scope.resourceCallback))throw"AngularJS tastyTable directive: the resource-callback ("+$attrs.resourceCallback+") it's not a function";$scope.clientSide=!1}this.activate=function(directiveName){$scope[directiveName+"Directive"]=!0,$scope.params[directiveName]=!0},this.setParams=function(key,value){$scope.params[key]=value,["sortBy","sortOrder"].indexOf(key)>=0&&($scope.header[key]=value)},this.bindOnce=tableConfig.bindOnce,$scope.setDirectivesValues=function(resource){if(!angular.isObject(resource))throw"AngularJS tastyTable directive: the resource it's not an object";if(!resource.header&&!resource.rows)throw"AngularJS tastyTable directive: the resource has the property header or rows undefined";1===Object.keys(resource.header[0]).length&&(resource.header=resource.header.map(function(header){var key=Object.keys(header)[0];return{key:key,name:header[key]}})),$scope.header={columns:resource.header,sortBy:$scope.params.sortBy,sortOrder:$scope.params.sortOrder},$scope.clientSide||($scope.header.sortBy=$scope.header.sortBy||resource.sortBy,$scope.header.sortOrder=$scope.header.sortOrder||resource.sortOrder),$scope.rows=resource.rows,$scope.paginationDirective&&resource.pagination&&($scope.pagination.count=resource.pagination.count,$scope.pagination.page=resource.pagination.page,$scope.pagination.pages=resource.pagination.pages,$scope.pagination.size=resource.pagination.size)},$scope.buildClientResource=function(){var fromRow,toRow,rowToShow,reverse,listSortBy;$scope.theadDirective&&(reverse="asc"===$scope.header.sortOrder?!1:!0,listSortBy=[function(item){return item[$scope.header.sortBy]}],$scope.header.columns[0].key!==$scope.header.sortBy&&listSortBy.push(function(item){return item[$scope.header.columns[0].key]}),$scope.header.sortBy&&($scope.rows=$filter("orderBy")($scope.rows,listSortBy,reverse))),$attrs.filters&&($scope.rows=$filter("filter")($scope.rows,$scope.filters)),$scope.paginationDirective&&($scope.pagination.page=$scope.params.page,$scope.pagination.count=$scope.params.count,$scope.pagination.size=$scope.rows.length,$scope.pagination.pages=Math.ceil($scope.rows.length/$scope.pagination.count),toRow=$scope.pagination.count*$scope.pagination.page,fromRow=toRow-$scope.pagination.count,fromRow>=0&&toRow>=0&&(rowToShow=$scope.rows.slice(fromRow,toRow),$scope.rows=rowToShow))},$scope.buildUrl=function(params,filters){var urlQuery,value,listKeyNotJoin;return urlQuery={},listKeyNotJoin=["sortBy","sortOrder","page","count"],$scope.theadDirective&&(urlQuery=tastyUtil.setProperty(urlQuery,params,"sortBy"),urlQuery=tastyUtil.setProperty(urlQuery,params,"sortOrder")),$scope.paginationDirective&&(urlQuery=tastyUtil.setProperty(urlQuery,params,"page"),urlQuery=tastyUtil.setProperty(urlQuery,params,"count")),$attrs.filters&&(urlQuery=tastyUtil.joinObjects(urlQuery,filters,listKeyNotJoin)),Object.keys(urlQuery).map(function(key){return value=urlQuery[key],$scope.query[key]&&(key=$scope.query[key]),encodeURIComponent(key)+"="+encodeURIComponent(value)}).join("&")},$scope.updateClientSideResource=tastyUtil.debounce(function(){$scope.setDirectivesValues($scope.resource),$scope.buildClientResource()},60),$scope.updateServerSideResource=tastyUtil.debounce(function(){$scope.url=$scope.buildUrl($scope.params,$scope.filters),$scope.resourceCallback($scope.url,$scope.params).then(function(resource){$scope.setDirectivesValues(resource)})},60),initTable=function(){$scope.clientSide?($scope.params.sortBy=$scope.resource.sortBy||$scope.init.sortBy,$scope.params.sortOrder=$scope.resource.sortOrder||$scope.init.sortOrder,$scope.params.page=$scope.init.page,$scope.resource.pagination&&($scope.params.page=$scope.resource.pagination.page||$scope.init.page),$scope.updateClientSideResource()):($scope.params.sortBy=$scope.init.sortBy,$scope.params.sortOrder=$scope.init.sortOrder,$scope.params.page=$scope.init.page,$scope.updateServerSideResource())},$attrs.filters&&$scope.$watch("filters",function(newValue,oldValue){newValue!==oldValue&&($scope.clientSide?$scope.updateClientSideResource():$scope.updateServerSideResource())},!0),$scope.$watchCollection("params",function(newValue,oldValue){newValue!==oldValue&&($scope.clientSide?$scope.updateClientSideResource():$scope.updateServerSideResource())}),$scope.resource&&$scope.$watch("resource",function(newValue,oldValue){newValue!==oldValue&&($scope.params.sortBy=newValue.sortBy,$scope.params.sortOrder=newValue.sortOrder,$scope.updateClientSideResource())},!0),initTable()}]).directive("tastyTable",function(){return{restrict:"A",scope:!0,controller:"TableController"}}).directive("tastyThead",["$filter",function($filter){return{restrict:"AE",require:"^tastyTable",scope:{notSortBy:"="},templateUrl:"template/table/head.html",link:function(scope,element,attrs,tastyTable){"use strict";var iconUp,iconDown;tastyTable.activate("thead"),scope.bindOnce=tastyTable.bindOnce,scope.columns=[],iconUp="fa fa-sort-up",iconDown="fa fa-sort-down",scope.setColumns=function(){var lenHeader,active,sortable,sort,isSorted;scope.columns=[],lenHeader=scope.header.columns.length,scope.header.columns.forEach(function(column){column.style=column.style||{},sortable=!0,active=!1,isSorted="",angular.isArray(scope.notSortBy)&&(sortable=scope.notSortBy.length?scope.notSortBy.indexOf(column.key)<0:!1),(column.key===scope.header.sortBy||"-"+column.key===scope.header.sortBy)&&(active=!0),sort=$filter("cleanFieldName")(column.key),scope.header.sortBy==="-"+sort?isSorted=iconDown:scope.header.sortBy===sort&&(isSorted=iconUp),scope.columns.push({key:column.key,name:column.name,active:active,sortable:sortable,style:column.style,isSorted:isSorted})}),"dsc"===scope.header.sortOrder&&scope.header.sortBy&&"-"!==scope.header.sortBy[0]&&(scope.header.sortBy="-"+scope.header.sortBy)},scope.sortBy=function(column){if(!column.sortable)return!1;var columnName,sortOrder;columnName=$filter("cleanFieldName")(column.key),sortOrder=scope.header.sortBy===columnName?"dsc":"asc",tastyTable.setParams("sortBy",column.key),tastyTable.setParams("sortOrder",sortOrder)},scope.classToShow=function(column){var listClassToShow=[];return column.sortable&&listClassToShow.push("sortable"),column.active&&listClassToShow.push("active"),listClassToShow},tastyTable.$scope.$watchCollection("header",function(newValue,oldValue){newValue&&newValue!==oldValue&&(scope.header=newValue,scope.setColumns())})}}}]).directive("tastyPagination",["$filter","$templateCache","$http","$compile","$parse","tableConfig",function($filter,$templateCache,$http,$compile,$parse,tableConfig){return{restrict:"AE",require:"^tastyTable",scope:{},templateUrl:function(tElement,tAttrs){return tAttrs.templateUrl||"template/table/pagination.html"},link:function(scope,element,attrs,tastyTable){"use strict";var getPage,setCount,setPaginationRange,setPreviousRange,setRemainingRange,setPaginationRanges,listScopeToWatch;listScopeToWatch=["itemsPerPage","listItemsPerPage"],listScopeToWatch.forEach(function(scopeName){var lastValue,parentGet,compare,parentSet,parentValueWatch;attrs[scopeName]&&(parentGet=$parse(attrs[scopeName]),compare=parentGet.literal?equals:function(a,b){return a===b||a!==a&&b!==b},parentSet=parentGet.assign,lastValue=scope[scopeName]=parentGet(scope.$parent),parentValueWatch=function(parentValue){return compare(parentValue,scope[scopeName])||(compare(parentValue,lastValue)?parentSet(scope.$parent,parentValue=scope[scopeName]):$scope[scopeName]=parentValue),lastValue=parentValue},parentValueWatch.$stateful=!0,scope.$parent.$watch($parse(attrs[scopeName],parentValueWatch),null,parentGet.literal))}),scope.itemsPerPage=scope.itemsPerPage||tableConfig.itemsPerPage,scope.listItemsPerPage=scope.listItemsPerPage||tableConfig.listItemsPerPage,tastyTable.activate("pagination"),scope.pagination={},scope.pagMinRange=1,scope.pagMaxRange=1,getPage=function(numPage){tastyTable.setParams("page",numPage)},setCount=function(count){var maxItems,page;maxItems=count*scope.pagination.page,maxItems>scope.pagination.size&&(page=Math.ceil(scope.pagination.size/count),tastyTable.setParams("page",page)),tastyTable.setParams("count",count)},setPaginationRange=function(){var currentPage;currentPage=scope.pagination.page,currentPage>scope.pagination.pages&&(currentPage=scope.pagination.pages),scope.pagMinRange=currentPage-2>0?currentPage-2:1,scope.pagMaxRange=currentPage+2,scope.pagination.page=currentPage,setPaginationRanges()},setPreviousRange=function(){return scope.pagHideMinRange===!0||scope.pagMinRange<1?!1:(scope.pagMaxRange=scope.pagMinRange,scope.pagMinRange=scope.pagMaxRange-scope.itemsPerPage,setPaginationRanges(),void 0)},setRemainingRange=function(){return scope.pagHideMaxRange===!0||scope.pagMaxRange>scope.pagination.pages?!1:(scope.pagMinRange=scope.pagMaxRange,scope.pagMaxRange=scope.pagMinRange+scope.itemsPerPage,scope.pagMaxRange>scope.pagination.pages&&(scope.pagMaxRange=scope.pagination.pages),scope.pagMinRange=scope.pagMaxRange-scope.itemsPerPage,setPaginationRanges(),void 0)},setPaginationRanges=function(){scope.listItemsPerPageShow=[],scope.pagMinRange=scope.pagMinRange>0?scope.pagMinRange:1,scope.pagMaxRange=scope.pagMinRange+5,scope.pagMaxRange>scope.pagination.pages&&(scope.pagMaxRange=scope.pagination.pages+1),scope.pagHideMinRange=scope.pagMinRange<=1,scope.pagHideMaxRange=scope.pagMaxRange>=scope.pagination.pages,scope.classPageMinRange=scope.pagHideMinRange?"disabled":"",scope.classPageMaxRange=scope.pagHideMaxRange?"disabled":"";for(var i=scope.listItemsPerPage.length;i>=0;i--)if(scope.pagination.size>scope.listItemsPerPage[i]){scope.listItemsPerPageShow=scope.listItemsPerPage.slice(0,i+1);break}scope.rangePage=$filter("range")([],scope.pagMinRange,scope.pagMaxRange)},scope.classPaginationCount=function(count){return count==scope.pagination.count?"active":""},scope.classNumPage=function(numPage){return numPage==scope.pagination.page?"active":!1},scope.page={get:getPage,setCount:setCount,previous:setPreviousRange,remaining:setRemainingRange},tastyTable.$scope.$watchCollection("pagination",function(newValue,oldValue){newValue&&newValue!==oldValue&&(scope.pagination=newValue,setPaginationRange())}),scope.page.setCount(scope.itemsPerPage)}}}]);
{
"name": "ng-tasty",
"version": "0.3.1",
"version": "0.3.3",
"description": "A lightweight, flexible, and tasty collection of reusable UI components for AngularJS.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -27,3 +27,3 @@ /**

'sortBy': 'sort-by',
'sortOrder': 'sort-order',
'sortOrder': 'sort-order'
},

@@ -38,2 +38,4 @@ listItemsPerPage: [5, 25, 50, 100],

this.$scope = $scope;
$scope.init = {};
$scope.query = {};

@@ -72,4 +74,6 @@ listScopeToWatch = ['filters', 'init', 'query', 'resource', 'resourceCallback'];

// Default configs
$scope.query = $scope.query || tableConfig.query;
$scope.init = $scope.init || {};
$scope.query.page = $scope.query.page || tableConfig.query.page;
$scope.query.count = $scope.query.count || tableConfig.query.count;
$scope.query.sortBy = $scope.query.sortBy || tableConfig.query.sortBy;
$scope.query.sortOrder = $scope.query.sortOrder || tableConfig.query.sortOrder;
$scope.init.count = $scope.init.count || tableConfig.init.count;

@@ -161,2 +165,6 @@ $scope.init.page = $scope.init.page || tableConfig.init.page;

};
if (!$scope.clientSide) {
$scope.header.sortBy = $scope.header.sortBy || resource.sortBy;
$scope.header.sortOrder = $scope.header.sortOrder || resource.sortOrder;
}
$scope.rows = resource.rows;

@@ -334,8 +342,14 @@ if ($scope.paginationDirective && resource.pagination) {

scope.header.columns.forEach(function (column, index) {
width = parseFloat((100 / lenHeader).toFixed(2));
column.style = column.style || {};
sortable = true;
active = false;
isSorted = '';
if (scope.notSortBy) {
sortable = scope.notSortBy.indexOf(column.key) < 0;
// Not sort column when the key is present in the `notSortBy` list,
// and Not sort column when `notSortBy` is an empty list
if (angular.isArray(scope.notSortBy)) {
if (scope.notSortBy.length) {
sortable = scope.notSortBy.indexOf(column.key) < 0;
} else {
sortable = false;
}
}

@@ -357,3 +371,3 @@ if (column.key === scope.header.sortBy ||

'sortable': sortable,
'width': { 'width': width + '%' },
'style': column.style,
'isSorted': isSorted

@@ -370,3 +384,3 @@ });

scope.sortBy = function (column) {
if (scope.notSortBy && scope.notSortBy.indexOf(column.key) >= 0) {
if (!column.sortable) {
return false;

@@ -419,14 +433,3 @@ }

*/
.controller('TablePaginationController', function($scope, $attrs, tableConfig) {
if (angular.isDefined($attrs.itemsPerPage)) {
$scope.itemsPerPage = $scope.$parent[$attrs.itemsPerPage];
}
if (angular.isDefined($attrs.listItemsPerPage)) {
$scope.listItemsPerPage = $scope.$parent[$attrs.listItemsPerPage];
}
// Default configs
$scope.itemsPerPage = $scope.itemsPerPage || tableConfig.itemsPerPage;
$scope.listItemsPerPage = $scope.listItemsPerPage || tableConfig.listItemsPerPage;
})
.directive('tastyPagination', function($filter) {
.directive('tastyPagination', function($filter, $templateCache, $http, $compile, $parse, tableConfig) {
return {

@@ -436,4 +439,5 @@ restrict: 'AE',

scope: {},
templateUrl: 'template/table/pagination.html',
controller: 'TablePaginationController',
templateUrl: function(tElement, tAttrs) {
return tAttrs.templateUrl || 'template/table/pagination.html';
},
link: function (scope, element, attrs, tastyTable) {

@@ -443,4 +447,40 @@ 'use strict';

setPreviousRange, setRemainingRange,
setPaginationRanges;
setPaginationRanges, listScopeToWatch;
listScopeToWatch = ['itemsPerPage', 'listItemsPerPage'];
listScopeToWatch.forEach(function (scopeName) {
var lastValue, parentGet, compare, parentSet, parentValueWatch;
if (!attrs[scopeName]) {
return;
}
parentGet = $parse(attrs[scopeName]);
if (parentGet.literal) {
compare = equals;
} else {
compare = function(a,b) { return a === b || (a !== a && b !== b); };
}
parentSet = parentGet.assign;
lastValue = scope[scopeName] = parentGet(scope.$parent);
parentValueWatch = function parentValueWatch(parentValue) {
if (!compare(parentValue, scope[scopeName])) {
// we are out of sync and need to copy
if (!compare(parentValue, lastValue)) {
// parent changed and it has precedence
$scope[scopeName] = parentValue;
} else {
// if the parent can be assigned then do so
parentSet(scope.$parent, parentValue = scope[scopeName]);
}
}
return lastValue = parentValue;
};
parentValueWatch.$stateful = true;
scope.$parent.$watch($parse(attrs[scopeName], parentValueWatch), null, parentGet.literal);
});
// Default configs
scope.itemsPerPage = scope.itemsPerPage || tableConfig.itemsPerPage;
scope.listItemsPerPage = scope.listItemsPerPage || tableConfig.listItemsPerPage;
// Pagination it's called

@@ -447,0 +487,0 @@ tastyTable.activate('pagination');

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc