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.4.1 to 0.4.2

src/service/web-socket.js

5

bower.json
{
"name": "ng-tasty",
"version": "0.4.1",
"version": "0.4.2",
"homepage": "https://github.com/Zizzamia/ng-tasty",
"authors": [
"@zizzamia"
"@zizzamia",
"@proudlygeek"
],

@@ -8,0 +9,0 @@ "main": "./ng-tasty.js",

196

ng-tasty-tpls.js

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

* Version: 0.4.1 - 2014-12-10
* Version: 0.4.2 - 2014-12-22
* License: MIT
*/
angular.module("ngTasty", ["ngTasty.tpls", "ngTasty.component.table","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.websocket"]);
angular.module("ngTasty", ["ngTasty.tpls", "ngTasty.component.table","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.webSocket"]);
angular.module("ngTasty.tpls", ["ngTasty.tpls.table.head","ngTasty.tpls.table.pagination"]);

@@ -45,6 +45,9 @@ /**

})
.controller('TableController', ["$scope", "$attrs", "$timeout", "$filter", "tableConfig", "tastyUtil", function($scope, $attrs, $timeout, $filter, tableConfig, tastyUtil) {
.controller('TableController', ["$scope", "$attrs", "$filter", "tableConfig", "tastyUtil", function($scope, $attrs, $filter, tableConfig, tastyUtil) {
'use strict';
var listScopeToWatch, initTable, newScopeName;
var listScopeToWatch, initTable, newScopeName, initStatus,
updateClientSideResource, updateServerSideResource, setDirectivesValues,
buildClientResource, buildUrl;
this.$scope = $scope;
initStatus = {};
$scope.init = {};

@@ -115,2 +118,4 @@ $scope.query = {};

// for other directives to talk to this one.
this.start = false;
this.activate = function(directiveName) {

@@ -128,5 +133,41 @@ $scope[directiveName + 'Directive'] = true;

this.initTable = function (keyDirective) {
initStatus[keyDirective] = true;
if (!$scope.theadDirective && !$scope.paginationDirective) {
this.start = true;
} else if ($scope.theadDirective && $scope.paginationDirective) {
if (initStatus.thead && initStatus.pagination){
this.start = true;
}
} else if ($scope.theadDirective && !$scope.paginationDirective) {
if (initStatus.thead){
this.start = true;
}
} else if (!$scope.theadDirective && $scope.paginationDirective) {
if (initStatus.pagination){
this.start = true;
}
}
if (this.start) {
if ($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;
if ($scope.resource.pagination) {
$scope.params.page = $scope.resource.pagination.page || $scope.init.page;
}
$scope.$evalAsync(updateClientSideResource);
} else {
$scope.params.sortBy = $scope.init.sortBy;
$scope.params.sortOrder = $scope.init.sortOrder;
$scope.params.page = $scope.init.page;
$scope.$evalAsync(updateServerSideResource);
}
}
};
this.bindOnce = tableConfig.bindOnce;
$scope.setDirectivesValues = function (resource) {
setDirectivesValues = function (resource) {
if (!angular.isObject(resource)) {

@@ -141,3 +182,3 @@ throw 'AngularJS tastyTable directive: the bind-resource '+

// [feature request] simplified header for resources #37 by @WebReflection
if (Object.keys(resource.header[0]).length === 1) {
if (resource.header.length && Object.keys(resource.header[0]).length === 1) {
resource.header = resource.header.map(function (header) {

@@ -161,13 +202,24 @@ var key = Object.keys(header)[0];

$scope.rows = resource.rows;
if ($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;
if ($scope.paginationDirective) {
$scope.pagination.page = $scope.params.page;
$scope.pagination.count = $scope.params.count;
$scope.pagination.size = $scope.rows.length;
if (resource.pagination) {
if (resource.pagination.count) {
$scope.pagination.count = resource.pagination.count;
}
if (resource.pagination.page) {
$scope.pagination.page = resource.pagination.page;
}
if (resource.pagination.size) {
$scope.pagination.size = resource.pagination.size;
}
}
$scope.pagination.pages = Math.ceil($scope.pagination.size / $scope.pagination.count);
}
};
$scope.buildClientResource = function() {
buildClientResource = function(updateFrom) {
var fromRow, toRow, rowToShow, reverse, listSortBy;
if ($scope.theadDirective) {
if ($scope.theadDirective && $scope.header.columns.length) {
reverse = $scope.header.sortOrder === 'asc' ? false : true;

@@ -190,3 +242,7 @@ listSortBy = [function(item) {

if ($scope.paginationDirective) {
$scope.pagination.page = $scope.params.page;
if (updateFrom === 'filters') {
$scope.pagination.page = 1;
} else {
$scope.pagination.page = $scope.params.page;
}
$scope.pagination.count = $scope.params.count;

@@ -204,3 +260,3 @@ $scope.pagination.size = $scope.rows.length;

$scope.buildUrl = function(params, filters) {
buildUrl = function(params, filters) {
var urlQuery, value, url, listKeyNotJoin;

@@ -229,29 +285,12 @@ urlQuery = {};

$scope.updateClientSideResource = tastyUtil.debounce(function() {
$scope.setDirectivesValues($scope.resource);
$scope.buildClientResource();
}, 60);
updateClientSideResource = function (updateFrom) {
setDirectivesValues($scope.resource);
buildClientResource(updateFrom);
};
$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);
updateServerSideResource = function () {
$scope.url = buildUrl($scope.params, $scope.filters);
$scope.resourceCallback($scope.url, angular.copy($scope.params)).then(function (resource) {
setDirectivesValues(resource);
});
}, 60);
initTable = function () {
if ($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;
if ($scope.resource.pagination) {
$scope.params.page = $scope.resource.pagination.page || $scope.init.page;
}
$scope.updateClientSideResource();
} else {
$scope.params.sortBy = $scope.init.sortBy;
$scope.params.sortOrder = $scope.init.sortOrder;
$scope.params.page = $scope.init.page;
$scope.updateServerSideResource();
}
};

@@ -261,8 +300,8 @@

if ($attrs.bindFilters) {
$scope.$watch('filters', function (newValue, oldValue){
$scope.$watch('filters', function watchFilters (newValue, oldValue){
if (newValue !== oldValue) {
if ($scope.clientSide) {
$scope.updateClientSideResource();
$scope.$evalAsync(updateClientSideResource('filters'));
} else {
$scope.updateServerSideResource();
$scope.$evalAsync(updateServerSideResource);
}

@@ -272,8 +311,8 @@ }

}
$scope.$watchCollection('params', function (newValue, oldValue){
$scope.$watchCollection('params', function watchParams (newValue, oldValue){
if (newValue !== oldValue) {
if ($scope.clientSide) {
$scope.updateClientSideResource();
$scope.$evalAsync(updateClientSideResource('params'));
} else {
$scope.updateServerSideResource();
$scope.$evalAsync(updateServerSideResource);
}

@@ -283,13 +322,10 @@ }

if ($scope.resource) {
$scope.$watch('resource', function (newValue, oldValue){
$scope.$watch('resource', function watchResource (newValue, oldValue){
if (newValue !== oldValue) {
$scope.params.sortBy = newValue.sortBy;
$scope.params.sortOrder = newValue.sortOrder;
$scope.updateClientSideResource();
$scope.$evalAsync(updateClientSideResource('resource'));
}
}, true);
}
// Init table
initTable();
}])

@@ -300,3 +336,14 @@ .directive('tastyTable', function(){

scope: true,
controller: 'TableController'
controller: 'TableController',
link: function (scope, element, attrs, tastyTable) {
if (element.find('tasty-thead').length ||
element[0].querySelector('[tasty-thead]')) {
tastyTable.activate('thead');
}
if (element.find('tasty-pagination').length ||
element[0].querySelector('[tasty-pagination]')) {
tastyTable.activate('pagination');
}
tastyTable.initTable();
}
};

@@ -325,4 +372,2 @@ })

var iconUp, iconDown, newScopeName, listScopeToWatch;
// Thead it's called
tastyTable.activate('thead');
scope.bindOnce = tastyTable.bindOnce;

@@ -391,2 +436,6 @@ scope.columns = [];

}
if (!tastyTable.start) {
// Thead it's called
tastyTable.initTable('thead');
}
};

@@ -420,4 +469,4 @@

tastyTable.$scope.$watchCollection('header', function (newValue, oldValue){
if (newValue && (newValue !== oldValue)) {
tastyTable.$scope.$watchCollection('header', function watchHeader (newValue, oldValue){
if (newValue && ((newValue !== oldValue) || !tastyTable.start)) {
scope.header = newValue;

@@ -483,5 +532,2 @@ scope.setColumns();

// Pagination it's called
tastyTable.activate('pagination');
// Internal variable

@@ -560,2 +606,7 @@ scope.pagination = {};

scope.rangePage = $filter('range')([], scope.pagMinRange, scope.pagMaxRange);
if (!tastyTable.start) {
// Pagination it's called
tastyTable.initTable('pagination');
}
};

@@ -584,4 +635,4 @@

tastyTable.$scope.$watchCollection('pagination', function (newValue, oldValue){
if (newValue && (newValue !== oldValue)) {
tastyTable.$scope.$watchCollection('pagination', function watchPagination (newValue, oldValue){
if (newValue && ((newValue !== oldValue) || !tastyTable.start)) {
scope.pagination = newValue;

@@ -721,8 +772,8 @@ setPaginationRange();

.factory('debounce', ["$timeout", function($timeout) {
return function(func, wait, immediate) {
return function (func, wait, immediate) {
var timeout;
return function() {
return function debounce () {
var context = this, args = arguments;
$timeout.cancel(timeout);
timeout = $timeout(function() {
timeout = $timeout(function debounceTimeout () {
timeout = null;

@@ -778,5 +829,6 @@ func.apply(context, args);

'ngTasty.service.setProperty',
'ngTasty.service.joinObjects'
'ngTasty.service.joinObjects',
'ngTasty.service.webSocket'
])
.factory('tastyUtil', ["debounce", "setProperty", "joinObjects", "bindTo", function(debounce, setProperty, joinObjects, bindTo) {
.factory('tastyUtil', ["debounce", "setProperty", "joinObjects", "bindTo", "webSocket", function(debounce, setProperty, joinObjects, bindTo, webSocket) {
return {

@@ -786,11 +838,10 @@ 'bindTo': bindTo,

'setProperty': setProperty,
'joinObjects': joinObjects
'joinObjects': joinObjects,
'webSocket': webSocket
};
}]);
angular.module('ngTasty.service.webSocket', [
'ngTasty.service'
])
.factory('WebSocket', function() {
angular.module('ngTasty.service.webSocket', [])
.factory('webSocket', function() {
return function(url) {

@@ -860,3 +911,2 @@ var blobURL = URL.createObjectURL(new Blob(['(', function() {

};
};

@@ -863,0 +913,0 @@ });

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

* Version: 0.4.1 - 2014-12-10
* Version: 0.4.2 - 2014-12-22
* License: MIT
*/
angular.module("ngTasty",["ngTasty.tpls","ngTasty.component.table","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.websocket"]),angular.module("ngTasty.tpls",["ngTasty.tpls.table.head","ngTasty.tpls.table.pagination"]),angular.module("ngTasty.component.table",["ngTasty.filter.cleanFieldName","ngTasty.filter.range","ngTasty.service.tastyUtil","ngTasty.tpls.table.head","ngTasty.tpls.table.pagination"]).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","tableConfig","tastyUtil",function($scope,$attrs,$timeout,$filter,tableConfig,tastyUtil){"use strict";var listScopeToWatch,initTable,newScopeName;if(this.$scope=$scope,$scope.init={},$scope.query={},listScopeToWatch=["bindFilters","bindInit","bindQuery","bindResource","bindResourceCallback"],listScopeToWatch.forEach(function(scopeName){newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),$attrs[scopeName]&&tastyUtil.bindTo(scopeName,$scope,$attrs,newScopeName)}),$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.bindResource)&&!angular.isDefined($attrs.bindResourceCallback))throw"AngularJS tastyTable directive: need the bind-resource or bind-resource-callback attribute";if(angular.isDefined($attrs.bindResource)){if(!angular.isObject($scope.resource))throw"AngularJS tastyTable directive: the bind-resource ("+$attrs.bindResource+") it's not an object";if(!$scope.resource.header&&!$scope.resource.rows)throw"AngularJS tastyTable directive: the bind-resource ("+$attrs.bindResource+") has the property header or rows undefined"}if(angular.isDefined($attrs.bindResourceCallback)){if(!angular.isFunction($scope.resourceCallback))throw"AngularJS tastyTable directive: the bind-resource-callback ("+$attrs.bindResourceCallback+") 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 bind-resource it's not an object";if(!resource.header&&!resource.rows)throw"AngularJS tastyTable directive: the bind-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.bindFilters&&($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.bindFilters&&(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.bindFilters&&$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","tastyUtil",function($filter,tastyUtil){return{restrict:"AE",require:"^tastyTable",scope:{},templateUrl:"template/table/head.html",link:function(scope,element,attrs,tastyTable){"use strict";var iconUp,iconDown,newScopeName,listScopeToWatch;tastyTable.activate("thead"),scope.bindOnce=tastyTable.bindOnce,scope.columns=[],listScopeToWatch=["bindNotSortBy"],listScopeToWatch.forEach(function(scopeName){newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),attrs[scopeName]?tastyUtil.bindTo(scopeName,scope,attrs,newScopeName):attrs[newScopeName]&&(scope[newScopeName]="["===attrs[newScopeName][0]?JSON.parse(attrs[newScopeName]):attrs[newScopeName])}),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","tableConfig","tastyUtil",function($filter,$templateCache,$http,$compile,tableConfig,tastyUtil){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,newScopeName;listScopeToWatch=["bindItemsPerPage","bindListItemsPerPage","bindTemplateUrl"],listScopeToWatch.forEach(function(scopeName){newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),attrs[scopeName]?tastyUtil.bindTo(scopeName,scope,attrs,newScopeName):attrs[newScopeName]&&(scope[newScopeName]="itemsPerPage"===newScopeName?parseInt(attrs[newScopeName]):JSON.parse(attrs[newScopeName]))}),scope.templateUrl&&$http.get(scope.templateUrl,{cache:$templateCache}).success(function(templateContent){element.replaceWith($compile(templateContent)(scope))}),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("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",["ngTasty.filter.filterInt"]).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.bindTo",[]).factory("bindTo",["$parse",function($parse){return function(scopeName,scope,attrs,newScopeName){var lastValue,parentGet,compare,parentSet,parentValueWatch,isolateScopeName;attrs[scopeName]&&(parentGet=$parse(attrs[scopeName]),compare=parentGet.literal?equals:function(a,b){return a===b||a!==a&&b!==b},isolateScopeName=newScopeName?newScopeName:scopeName,parentSet=parentGet.assign,lastValue=scope[isolateScopeName]=parentGet(scope.$parent),parentValueWatch=function(parentValue){return compare(parentValue,scope[isolateScopeName])||(compare(parentValue,lastValue)?parentSet(scope.$parent,parentValue=scope[isolateScopeName]):scope[isolateScopeName]=parentValue),lastValue=parentValue},parentValueWatch.$stateful=!0,scope.$parent.$watch($parse(attrs[scopeName],parentValueWatch),null,parentGet.literal))}}]),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.joinObjects",["ngTasty.service.setProperty"]).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.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.tastyUtil",["ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.setProperty","ngTasty.service.joinObjects"]).factory("tastyUtil",["debounce","setProperty","joinObjects","bindTo",function(debounce,setProperty,joinObjects,bindTo){return{bindTo:bindTo,debounce:debounce,setProperty:setProperty,joinObjects:joinObjects}}]),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})}}}}),function(module){try{module=angular.module("ngTasty.tpls.table.head")}catch(e){module=angular.module("ngTasty.tpls.table.head",[])}module.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>')}])}(),function(module){try{module=angular.module("ngTasty.tpls.table.pagination")}catch(e){module=angular.module("ngTasty.tpls.table.pagination",[])}module.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.component.table","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.webSocket"]),angular.module("ngTasty.tpls",["ngTasty.tpls.table.head","ngTasty.tpls.table.pagination"]),angular.module("ngTasty.component.table",["ngTasty.filter.cleanFieldName","ngTasty.filter.range","ngTasty.service.tastyUtil","ngTasty.tpls.table.head","ngTasty.tpls.table.pagination"]).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","$filter","tableConfig","tastyUtil",function($scope,$attrs,$filter,tableConfig,tastyUtil){"use strict";var listScopeToWatch,newScopeName,initStatus,updateClientSideResource,updateServerSideResource,setDirectivesValues,buildClientResource,buildUrl;if(this.$scope=$scope,initStatus={},$scope.init={},$scope.query={},listScopeToWatch=["bindFilters","bindInit","bindQuery","bindResource","bindResourceCallback"],listScopeToWatch.forEach(function(scopeName){newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),$attrs[scopeName]&&tastyUtil.bindTo(scopeName,$scope,$attrs,newScopeName)}),$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.bindResource)&&!angular.isDefined($attrs.bindResourceCallback))throw"AngularJS tastyTable directive: need the bind-resource or bind-resource-callback attribute";if(angular.isDefined($attrs.bindResource)){if(!angular.isObject($scope.resource))throw"AngularJS tastyTable directive: the bind-resource ("+$attrs.bindResource+") it's not an object";if(!$scope.resource.header&&!$scope.resource.rows)throw"AngularJS tastyTable directive: the bind-resource ("+$attrs.bindResource+") has the property header or rows undefined"}if(angular.isDefined($attrs.bindResourceCallback)){if(!angular.isFunction($scope.resourceCallback))throw"AngularJS tastyTable directive: the bind-resource-callback ("+$attrs.bindResourceCallback+") it's not a function";$scope.clientSide=!1}this.start=!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.initTable=function(keyDirective){initStatus[keyDirective]=!0,$scope.theadDirective||$scope.paginationDirective?$scope.theadDirective&&$scope.paginationDirective?initStatus.thead&&initStatus.pagination&&(this.start=!0):$scope.theadDirective&&!$scope.paginationDirective?initStatus.thead&&(this.start=!0):!$scope.theadDirective&&$scope.paginationDirective&&initStatus.pagination&&(this.start=!0):this.start=!0,this.start&&($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.$evalAsync(updateClientSideResource)):($scope.params.sortBy=$scope.init.sortBy,$scope.params.sortOrder=$scope.init.sortOrder,$scope.params.page=$scope.init.page,$scope.$evalAsync(updateServerSideResource)))},this.bindOnce=tableConfig.bindOnce,setDirectivesValues=function(resource){if(!angular.isObject(resource))throw"AngularJS tastyTable directive: the bind-resource it's not an object";if(!resource.header&&!resource.rows)throw"AngularJS tastyTable directive: the bind-resource has the property header or rows undefined";resource.header.length&&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&&($scope.pagination.page=$scope.params.page,$scope.pagination.count=$scope.params.count,$scope.pagination.size=$scope.rows.length,resource.pagination&&(resource.pagination.count&&($scope.pagination.count=resource.pagination.count),resource.pagination.page&&($scope.pagination.page=resource.pagination.page),resource.pagination.size&&($scope.pagination.size=resource.pagination.size)),$scope.pagination.pages=Math.ceil($scope.pagination.size/$scope.pagination.count))},buildClientResource=function(updateFrom){var fromRow,toRow,rowToShow,reverse,listSortBy;$scope.theadDirective&&$scope.header.columns.length&&(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.bindFilters&&($scope.rows=$filter("filter")($scope.rows,$scope.filters)),$scope.paginationDirective&&($scope.pagination.page="filters"===updateFrom?1:$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))},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.bindFilters&&(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("&")},updateClientSideResource=function(updateFrom){setDirectivesValues($scope.resource),buildClientResource(updateFrom)},updateServerSideResource=function(){$scope.url=buildUrl($scope.params,$scope.filters),$scope.resourceCallback($scope.url,angular.copy($scope.params)).then(function(resource){setDirectivesValues(resource)})},$attrs.bindFilters&&$scope.$watch("filters",function(newValue,oldValue){newValue!==oldValue&&($scope.clientSide?$scope.$evalAsync(updateClientSideResource("filters")):$scope.$evalAsync(updateServerSideResource))},!0),$scope.$watchCollection("params",function(newValue,oldValue){newValue!==oldValue&&($scope.clientSide?$scope.$evalAsync(updateClientSideResource("params")):$scope.$evalAsync(updateServerSideResource))}),$scope.resource&&$scope.$watch("resource",function(newValue,oldValue){newValue!==oldValue&&($scope.params.sortBy=newValue.sortBy,$scope.params.sortOrder=newValue.sortOrder,$scope.$evalAsync(updateClientSideResource("resource")))},!0)}]).directive("tastyTable",function(){return{restrict:"A",scope:!0,controller:"TableController",link:function(scope,element,attrs,tastyTable){(element.find("tasty-thead").length||element[0].querySelector("[tasty-thead]"))&&tastyTable.activate("thead"),(element.find("tasty-pagination").length||element[0].querySelector("[tasty-pagination]"))&&tastyTable.activate("pagination"),tastyTable.initTable()}}}).directive("tastyThead",["$filter","tastyUtil",function($filter,tastyUtil){return{restrict:"AE",require:"^tastyTable",scope:{},templateUrl:"template/table/head.html",link:function(scope,element,attrs,tastyTable){"use strict";var iconUp,iconDown,newScopeName,listScopeToWatch;scope.bindOnce=tastyTable.bindOnce,scope.columns=[],listScopeToWatch=["bindNotSortBy"],listScopeToWatch.forEach(function(scopeName){newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),attrs[scopeName]?tastyUtil.bindTo(scopeName,scope,attrs,newScopeName):attrs[newScopeName]&&(scope[newScopeName]="["===attrs[newScopeName][0]?JSON.parse(attrs[newScopeName]):attrs[newScopeName])}),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),tastyTable.start||tastyTable.initTable("thead")},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&&tastyTable.start||(scope.header=newValue,scope.setColumns())})}}}]).directive("tastyPagination",["$filter","$templateCache","$http","$compile","tableConfig","tastyUtil",function($filter,$templateCache,$http,$compile,tableConfig,tastyUtil){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,newScopeName;listScopeToWatch=["bindItemsPerPage","bindListItemsPerPage","bindTemplateUrl"],listScopeToWatch.forEach(function(scopeName){newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),attrs[scopeName]?tastyUtil.bindTo(scopeName,scope,attrs,newScopeName):attrs[newScopeName]&&(scope[newScopeName]="itemsPerPage"===newScopeName?parseInt(attrs[newScopeName]):JSON.parse(attrs[newScopeName]))}),scope.templateUrl&&$http.get(scope.templateUrl,{cache:$templateCache}).success(function(templateContent){element.replaceWith($compile(templateContent)(scope))}),scope.itemsPerPage=scope.itemsPerPage||tableConfig.itemsPerPage,scope.listItemsPerPage=scope.listItemsPerPage||tableConfig.listItemsPerPage,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),tastyTable.start||tastyTable.initTable("pagination")},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&&tastyTable.start||(scope.pagination=newValue,setPaginationRange())}),scope.page.setCount(scope.itemsPerPage)}}}]),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",["ngTasty.filter.filterInt"]).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.bindTo",[]).factory("bindTo",["$parse",function($parse){return function(scopeName,scope,attrs,newScopeName){var lastValue,parentGet,compare,parentSet,parentValueWatch,isolateScopeName;attrs[scopeName]&&(parentGet=$parse(attrs[scopeName]),compare=parentGet.literal?equals:function(a,b){return a===b||a!==a&&b!==b},isolateScopeName=newScopeName?newScopeName:scopeName,parentSet=parentGet.assign,lastValue=scope[isolateScopeName]=parentGet(scope.$parent),parentValueWatch=function(parentValue){return compare(parentValue,scope[isolateScopeName])||(compare(parentValue,lastValue)?parentSet(scope.$parent,parentValue=scope[isolateScopeName]):scope[isolateScopeName]=parentValue),lastValue=parentValue},parentValueWatch.$stateful=!0,scope.$parent.$watch($parse(attrs[scopeName],parentValueWatch),null,parentGet.literal))}}]),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.joinObjects",["ngTasty.service.setProperty"]).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.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.tastyUtil",["ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.setProperty","ngTasty.service.joinObjects","ngTasty.service.webSocket"]).factory("tastyUtil",["debounce","setProperty","joinObjects","bindTo","webSocket",function(debounce,setProperty,joinObjects,bindTo,webSocket){return{bindTo:bindTo,debounce:debounce,setProperty:setProperty,joinObjects:joinObjects,webSocket:webSocket}}]),angular.module("ngTasty.service.webSocket",[]).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})}}}}),function(module){try{module=angular.module("ngTasty.tpls.table.head")}catch(e){module=angular.module("ngTasty.tpls.table.head",[])}module.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>')}])}(),function(module){try{module=angular.module("ngTasty.tpls.table.pagination")}catch(e){module=angular.module("ngTasty.tpls.table.pagination",[])}module.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,6 +5,6 @@ /*

* Version: 0.4.1 - 2014-12-10
* Version: 0.4.2 - 2014-12-22
* License: MIT
*/
angular.module("ngTasty", ["ngTasty.component.table","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.websocket"]);
angular.module("ngTasty", ["ngTasty.component.table","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.webSocket"]);
/**

@@ -44,6 +44,9 @@ * @ngdoc directive

})
.controller('TableController', ["$scope", "$attrs", "$timeout", "$filter", "tableConfig", "tastyUtil", function($scope, $attrs, $timeout, $filter, tableConfig, tastyUtil) {
.controller('TableController', ["$scope", "$attrs", "$filter", "tableConfig", "tastyUtil", function($scope, $attrs, $filter, tableConfig, tastyUtil) {
'use strict';
var listScopeToWatch, initTable, newScopeName;
var listScopeToWatch, initTable, newScopeName, initStatus,
updateClientSideResource, updateServerSideResource, setDirectivesValues,
buildClientResource, buildUrl;
this.$scope = $scope;
initStatus = {};
$scope.init = {};

@@ -114,2 +117,4 @@ $scope.query = {};

// for other directives to talk to this one.
this.start = false;
this.activate = function(directiveName) {

@@ -127,5 +132,41 @@ $scope[directiveName + 'Directive'] = true;

this.initTable = function (keyDirective) {
initStatus[keyDirective] = true;
if (!$scope.theadDirective && !$scope.paginationDirective) {
this.start = true;
} else if ($scope.theadDirective && $scope.paginationDirective) {
if (initStatus.thead && initStatus.pagination){
this.start = true;
}
} else if ($scope.theadDirective && !$scope.paginationDirective) {
if (initStatus.thead){
this.start = true;
}
} else if (!$scope.theadDirective && $scope.paginationDirective) {
if (initStatus.pagination){
this.start = true;
}
}
if (this.start) {
if ($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;
if ($scope.resource.pagination) {
$scope.params.page = $scope.resource.pagination.page || $scope.init.page;
}
$scope.$evalAsync(updateClientSideResource);
} else {
$scope.params.sortBy = $scope.init.sortBy;
$scope.params.sortOrder = $scope.init.sortOrder;
$scope.params.page = $scope.init.page;
$scope.$evalAsync(updateServerSideResource);
}
}
};
this.bindOnce = tableConfig.bindOnce;
$scope.setDirectivesValues = function (resource) {
setDirectivesValues = function (resource) {
if (!angular.isObject(resource)) {

@@ -140,3 +181,3 @@ throw 'AngularJS tastyTable directive: the bind-resource '+

// [feature request] simplified header for resources #37 by @WebReflection
if (Object.keys(resource.header[0]).length === 1) {
if (resource.header.length && Object.keys(resource.header[0]).length === 1) {
resource.header = resource.header.map(function (header) {

@@ -160,13 +201,24 @@ var key = Object.keys(header)[0];

$scope.rows = resource.rows;
if ($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;
if ($scope.paginationDirective) {
$scope.pagination.page = $scope.params.page;
$scope.pagination.count = $scope.params.count;
$scope.pagination.size = $scope.rows.length;
if (resource.pagination) {
if (resource.pagination.count) {
$scope.pagination.count = resource.pagination.count;
}
if (resource.pagination.page) {
$scope.pagination.page = resource.pagination.page;
}
if (resource.pagination.size) {
$scope.pagination.size = resource.pagination.size;
}
}
$scope.pagination.pages = Math.ceil($scope.pagination.size / $scope.pagination.count);
}
};
$scope.buildClientResource = function() {
buildClientResource = function(updateFrom) {
var fromRow, toRow, rowToShow, reverse, listSortBy;
if ($scope.theadDirective) {
if ($scope.theadDirective && $scope.header.columns.length) {
reverse = $scope.header.sortOrder === 'asc' ? false : true;

@@ -189,3 +241,7 @@ listSortBy = [function(item) {

if ($scope.paginationDirective) {
$scope.pagination.page = $scope.params.page;
if (updateFrom === 'filters') {
$scope.pagination.page = 1;
} else {
$scope.pagination.page = $scope.params.page;
}
$scope.pagination.count = $scope.params.count;

@@ -203,3 +259,3 @@ $scope.pagination.size = $scope.rows.length;

$scope.buildUrl = function(params, filters) {
buildUrl = function(params, filters) {
var urlQuery, value, url, listKeyNotJoin;

@@ -228,29 +284,12 @@ urlQuery = {};

$scope.updateClientSideResource = tastyUtil.debounce(function() {
$scope.setDirectivesValues($scope.resource);
$scope.buildClientResource();
}, 60);
updateClientSideResource = function (updateFrom) {
setDirectivesValues($scope.resource);
buildClientResource(updateFrom);
};
$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);
updateServerSideResource = function () {
$scope.url = buildUrl($scope.params, $scope.filters);
$scope.resourceCallback($scope.url, angular.copy($scope.params)).then(function (resource) {
setDirectivesValues(resource);
});
}, 60);
initTable = function () {
if ($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;
if ($scope.resource.pagination) {
$scope.params.page = $scope.resource.pagination.page || $scope.init.page;
}
$scope.updateClientSideResource();
} else {
$scope.params.sortBy = $scope.init.sortBy;
$scope.params.sortOrder = $scope.init.sortOrder;
$scope.params.page = $scope.init.page;
$scope.updateServerSideResource();
}
};

@@ -260,8 +299,8 @@

if ($attrs.bindFilters) {
$scope.$watch('filters', function (newValue, oldValue){
$scope.$watch('filters', function watchFilters (newValue, oldValue){
if (newValue !== oldValue) {
if ($scope.clientSide) {
$scope.updateClientSideResource();
$scope.$evalAsync(updateClientSideResource('filters'));
} else {
$scope.updateServerSideResource();
$scope.$evalAsync(updateServerSideResource);
}

@@ -271,8 +310,8 @@ }

}
$scope.$watchCollection('params', function (newValue, oldValue){
$scope.$watchCollection('params', function watchParams (newValue, oldValue){
if (newValue !== oldValue) {
if ($scope.clientSide) {
$scope.updateClientSideResource();
$scope.$evalAsync(updateClientSideResource('params'));
} else {
$scope.updateServerSideResource();
$scope.$evalAsync(updateServerSideResource);
}

@@ -282,13 +321,10 @@ }

if ($scope.resource) {
$scope.$watch('resource', function (newValue, oldValue){
$scope.$watch('resource', function watchResource (newValue, oldValue){
if (newValue !== oldValue) {
$scope.params.sortBy = newValue.sortBy;
$scope.params.sortOrder = newValue.sortOrder;
$scope.updateClientSideResource();
$scope.$evalAsync(updateClientSideResource('resource'));
}
}, true);
}
// Init table
initTable();
}])

@@ -299,3 +335,14 @@ .directive('tastyTable', function(){

scope: true,
controller: 'TableController'
controller: 'TableController',
link: function (scope, element, attrs, tastyTable) {
if (element.find('tasty-thead').length ||
element[0].querySelector('[tasty-thead]')) {
tastyTable.activate('thead');
}
if (element.find('tasty-pagination').length ||
element[0].querySelector('[tasty-pagination]')) {
tastyTable.activate('pagination');
}
tastyTable.initTable();
}
};

@@ -324,4 +371,2 @@ })

var iconUp, iconDown, newScopeName, listScopeToWatch;
// Thead it's called
tastyTable.activate('thead');
scope.bindOnce = tastyTable.bindOnce;

@@ -390,2 +435,6 @@ scope.columns = [];

}
if (!tastyTable.start) {
// Thead it's called
tastyTable.initTable('thead');
}
};

@@ -419,4 +468,4 @@

tastyTable.$scope.$watchCollection('header', function (newValue, oldValue){
if (newValue && (newValue !== oldValue)) {
tastyTable.$scope.$watchCollection('header', function watchHeader (newValue, oldValue){
if (newValue && ((newValue !== oldValue) || !tastyTable.start)) {
scope.header = newValue;

@@ -482,5 +531,2 @@ scope.setColumns();

// Pagination it's called
tastyTable.activate('pagination');
// Internal variable

@@ -559,2 +605,7 @@ scope.pagination = {};

scope.rangePage = $filter('range')([], scope.pagMinRange, scope.pagMaxRange);
if (!tastyTable.start) {
// Pagination it's called
tastyTable.initTable('pagination');
}
};

@@ -583,4 +634,4 @@

tastyTable.$scope.$watchCollection('pagination', function (newValue, oldValue){
if (newValue && (newValue !== oldValue)) {
tastyTable.$scope.$watchCollection('pagination', function watchPagination (newValue, oldValue){
if (newValue && ((newValue !== oldValue) || !tastyTable.start)) {
scope.pagination = newValue;

@@ -720,8 +771,8 @@ setPaginationRange();

.factory('debounce', ["$timeout", function($timeout) {
return function(func, wait, immediate) {
return function (func, wait, immediate) {
var timeout;
return function() {
return function debounce () {
var context = this, args = arguments;
$timeout.cancel(timeout);
timeout = $timeout(function() {
timeout = $timeout(function debounceTimeout () {
timeout = null;

@@ -777,5 +828,6 @@ func.apply(context, args);

'ngTasty.service.setProperty',
'ngTasty.service.joinObjects'
'ngTasty.service.joinObjects',
'ngTasty.service.webSocket'
])
.factory('tastyUtil', ["debounce", "setProperty", "joinObjects", "bindTo", function(debounce, setProperty, joinObjects, bindTo) {
.factory('tastyUtil', ["debounce", "setProperty", "joinObjects", "bindTo", "webSocket", function(debounce, setProperty, joinObjects, bindTo, webSocket) {
return {

@@ -785,11 +837,10 @@ 'bindTo': bindTo,

'setProperty': setProperty,
'joinObjects': joinObjects
'joinObjects': joinObjects,
'webSocket': webSocket
};
}]);
angular.module('ngTasty.service.webSocket', [
'ngTasty.service'
])
.factory('WebSocket', function() {
angular.module('ngTasty.service.webSocket', [])
.factory('webSocket', function() {
return function(url) {

@@ -859,4 +910,3 @@ var blobURL = URL.createObjectURL(new Blob(['(', function() {

};
};
});

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

* Version: 0.4.1 - 2014-12-10
* Version: 0.4.2 - 2014-12-22
* License: MIT
*/
angular.module("ngTasty",["ngTasty.component.table","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.websocket"]),angular.module("ngTasty.component.table",["ngTasty.filter.cleanFieldName","ngTasty.filter.range","ngTasty.service.tastyUtil","ngTasty.tpls.table.head","ngTasty.tpls.table.pagination"]).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","tableConfig","tastyUtil",function($scope,$attrs,$timeout,$filter,tableConfig,tastyUtil){"use strict";var listScopeToWatch,initTable,newScopeName;if(this.$scope=$scope,$scope.init={},$scope.query={},listScopeToWatch=["bindFilters","bindInit","bindQuery","bindResource","bindResourceCallback"],listScopeToWatch.forEach(function(scopeName){newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),$attrs[scopeName]&&tastyUtil.bindTo(scopeName,$scope,$attrs,newScopeName)}),$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.bindResource)&&!angular.isDefined($attrs.bindResourceCallback))throw"AngularJS tastyTable directive: need the bind-resource or bind-resource-callback attribute";if(angular.isDefined($attrs.bindResource)){if(!angular.isObject($scope.resource))throw"AngularJS tastyTable directive: the bind-resource ("+$attrs.bindResource+") it's not an object";if(!$scope.resource.header&&!$scope.resource.rows)throw"AngularJS tastyTable directive: the bind-resource ("+$attrs.bindResource+") has the property header or rows undefined"}if(angular.isDefined($attrs.bindResourceCallback)){if(!angular.isFunction($scope.resourceCallback))throw"AngularJS tastyTable directive: the bind-resource-callback ("+$attrs.bindResourceCallback+") 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 bind-resource it's not an object";if(!resource.header&&!resource.rows)throw"AngularJS tastyTable directive: the bind-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.bindFilters&&($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.bindFilters&&(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.bindFilters&&$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","tastyUtil",function($filter,tastyUtil){return{restrict:"AE",require:"^tastyTable",scope:{},templateUrl:"template/table/head.html",link:function(scope,element,attrs,tastyTable){"use strict";var iconUp,iconDown,newScopeName,listScopeToWatch;tastyTable.activate("thead"),scope.bindOnce=tastyTable.bindOnce,scope.columns=[],listScopeToWatch=["bindNotSortBy"],listScopeToWatch.forEach(function(scopeName){newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),attrs[scopeName]?tastyUtil.bindTo(scopeName,scope,attrs,newScopeName):attrs[newScopeName]&&(scope[newScopeName]="["===attrs[newScopeName][0]?JSON.parse(attrs[newScopeName]):attrs[newScopeName])}),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","tableConfig","tastyUtil",function($filter,$templateCache,$http,$compile,tableConfig,tastyUtil){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,newScopeName;listScopeToWatch=["bindItemsPerPage","bindListItemsPerPage","bindTemplateUrl"],listScopeToWatch.forEach(function(scopeName){newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),attrs[scopeName]?tastyUtil.bindTo(scopeName,scope,attrs,newScopeName):attrs[newScopeName]&&(scope[newScopeName]="itemsPerPage"===newScopeName?parseInt(attrs[newScopeName]):JSON.parse(attrs[newScopeName]))}),scope.templateUrl&&$http.get(scope.templateUrl,{cache:$templateCache}).success(function(templateContent){element.replaceWith($compile(templateContent)(scope))}),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("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",["ngTasty.filter.filterInt"]).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.bindTo",[]).factory("bindTo",["$parse",function($parse){return function(scopeName,scope,attrs,newScopeName){var lastValue,parentGet,compare,parentSet,parentValueWatch,isolateScopeName;attrs[scopeName]&&(parentGet=$parse(attrs[scopeName]),compare=parentGet.literal?equals:function(a,b){return a===b||a!==a&&b!==b},isolateScopeName=newScopeName?newScopeName:scopeName,parentSet=parentGet.assign,lastValue=scope[isolateScopeName]=parentGet(scope.$parent),parentValueWatch=function(parentValue){return compare(parentValue,scope[isolateScopeName])||(compare(parentValue,lastValue)?parentSet(scope.$parent,parentValue=scope[isolateScopeName]):scope[isolateScopeName]=parentValue),lastValue=parentValue},parentValueWatch.$stateful=!0,scope.$parent.$watch($parse(attrs[scopeName],parentValueWatch),null,parentGet.literal))}}]),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.joinObjects",["ngTasty.service.setProperty"]).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.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.tastyUtil",["ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.setProperty","ngTasty.service.joinObjects"]).factory("tastyUtil",["debounce","setProperty","joinObjects","bindTo",function(debounce,setProperty,joinObjects,bindTo){return{bindTo:bindTo,debounce:debounce,setProperty:setProperty,joinObjects:joinObjects}}]),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",["ngTasty.component.table","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.webSocket"]),angular.module("ngTasty.component.table",["ngTasty.filter.cleanFieldName","ngTasty.filter.range","ngTasty.service.tastyUtil","ngTasty.tpls.table.head","ngTasty.tpls.table.pagination"]).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","$filter","tableConfig","tastyUtil",function($scope,$attrs,$filter,tableConfig,tastyUtil){"use strict";var listScopeToWatch,newScopeName,initStatus,updateClientSideResource,updateServerSideResource,setDirectivesValues,buildClientResource,buildUrl;if(this.$scope=$scope,initStatus={},$scope.init={},$scope.query={},listScopeToWatch=["bindFilters","bindInit","bindQuery","bindResource","bindResourceCallback"],listScopeToWatch.forEach(function(scopeName){newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),$attrs[scopeName]&&tastyUtil.bindTo(scopeName,$scope,$attrs,newScopeName)}),$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.bindResource)&&!angular.isDefined($attrs.bindResourceCallback))throw"AngularJS tastyTable directive: need the bind-resource or bind-resource-callback attribute";if(angular.isDefined($attrs.bindResource)){if(!angular.isObject($scope.resource))throw"AngularJS tastyTable directive: the bind-resource ("+$attrs.bindResource+") it's not an object";if(!$scope.resource.header&&!$scope.resource.rows)throw"AngularJS tastyTable directive: the bind-resource ("+$attrs.bindResource+") has the property header or rows undefined"}if(angular.isDefined($attrs.bindResourceCallback)){if(!angular.isFunction($scope.resourceCallback))throw"AngularJS tastyTable directive: the bind-resource-callback ("+$attrs.bindResourceCallback+") it's not a function";$scope.clientSide=!1}this.start=!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.initTable=function(keyDirective){initStatus[keyDirective]=!0,$scope.theadDirective||$scope.paginationDirective?$scope.theadDirective&&$scope.paginationDirective?initStatus.thead&&initStatus.pagination&&(this.start=!0):$scope.theadDirective&&!$scope.paginationDirective?initStatus.thead&&(this.start=!0):!$scope.theadDirective&&$scope.paginationDirective&&initStatus.pagination&&(this.start=!0):this.start=!0,this.start&&($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.$evalAsync(updateClientSideResource)):($scope.params.sortBy=$scope.init.sortBy,$scope.params.sortOrder=$scope.init.sortOrder,$scope.params.page=$scope.init.page,$scope.$evalAsync(updateServerSideResource)))},this.bindOnce=tableConfig.bindOnce,setDirectivesValues=function(resource){if(!angular.isObject(resource))throw"AngularJS tastyTable directive: the bind-resource it's not an object";if(!resource.header&&!resource.rows)throw"AngularJS tastyTable directive: the bind-resource has the property header or rows undefined";resource.header.length&&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&&($scope.pagination.page=$scope.params.page,$scope.pagination.count=$scope.params.count,$scope.pagination.size=$scope.rows.length,resource.pagination&&(resource.pagination.count&&($scope.pagination.count=resource.pagination.count),resource.pagination.page&&($scope.pagination.page=resource.pagination.page),resource.pagination.size&&($scope.pagination.size=resource.pagination.size)),$scope.pagination.pages=Math.ceil($scope.pagination.size/$scope.pagination.count))},buildClientResource=function(updateFrom){var fromRow,toRow,rowToShow,reverse,listSortBy;$scope.theadDirective&&$scope.header.columns.length&&(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.bindFilters&&($scope.rows=$filter("filter")($scope.rows,$scope.filters)),$scope.paginationDirective&&($scope.pagination.page="filters"===updateFrom?1:$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))},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.bindFilters&&(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("&")},updateClientSideResource=function(updateFrom){setDirectivesValues($scope.resource),buildClientResource(updateFrom)},updateServerSideResource=function(){$scope.url=buildUrl($scope.params,$scope.filters),$scope.resourceCallback($scope.url,angular.copy($scope.params)).then(function(resource){setDirectivesValues(resource)})},$attrs.bindFilters&&$scope.$watch("filters",function(newValue,oldValue){newValue!==oldValue&&($scope.clientSide?$scope.$evalAsync(updateClientSideResource("filters")):$scope.$evalAsync(updateServerSideResource))},!0),$scope.$watchCollection("params",function(newValue,oldValue){newValue!==oldValue&&($scope.clientSide?$scope.$evalAsync(updateClientSideResource("params")):$scope.$evalAsync(updateServerSideResource))}),$scope.resource&&$scope.$watch("resource",function(newValue,oldValue){newValue!==oldValue&&($scope.params.sortBy=newValue.sortBy,$scope.params.sortOrder=newValue.sortOrder,$scope.$evalAsync(updateClientSideResource("resource")))},!0)}]).directive("tastyTable",function(){return{restrict:"A",scope:!0,controller:"TableController",link:function(scope,element,attrs,tastyTable){(element.find("tasty-thead").length||element[0].querySelector("[tasty-thead]"))&&tastyTable.activate("thead"),(element.find("tasty-pagination").length||element[0].querySelector("[tasty-pagination]"))&&tastyTable.activate("pagination"),tastyTable.initTable()}}}).directive("tastyThead",["$filter","tastyUtil",function($filter,tastyUtil){return{restrict:"AE",require:"^tastyTable",scope:{},templateUrl:"template/table/head.html",link:function(scope,element,attrs,tastyTable){"use strict";var iconUp,iconDown,newScopeName,listScopeToWatch;scope.bindOnce=tastyTable.bindOnce,scope.columns=[],listScopeToWatch=["bindNotSortBy"],listScopeToWatch.forEach(function(scopeName){newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),attrs[scopeName]?tastyUtil.bindTo(scopeName,scope,attrs,newScopeName):attrs[newScopeName]&&(scope[newScopeName]="["===attrs[newScopeName][0]?JSON.parse(attrs[newScopeName]):attrs[newScopeName])}),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),tastyTable.start||tastyTable.initTable("thead")},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&&tastyTable.start||(scope.header=newValue,scope.setColumns())})}}}]).directive("tastyPagination",["$filter","$templateCache","$http","$compile","tableConfig","tastyUtil",function($filter,$templateCache,$http,$compile,tableConfig,tastyUtil){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,newScopeName;listScopeToWatch=["bindItemsPerPage","bindListItemsPerPage","bindTemplateUrl"],listScopeToWatch.forEach(function(scopeName){newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),attrs[scopeName]?tastyUtil.bindTo(scopeName,scope,attrs,newScopeName):attrs[newScopeName]&&(scope[newScopeName]="itemsPerPage"===newScopeName?parseInt(attrs[newScopeName]):JSON.parse(attrs[newScopeName]))}),scope.templateUrl&&$http.get(scope.templateUrl,{cache:$templateCache}).success(function(templateContent){element.replaceWith($compile(templateContent)(scope))}),scope.itemsPerPage=scope.itemsPerPage||tableConfig.itemsPerPage,scope.listItemsPerPage=scope.listItemsPerPage||tableConfig.listItemsPerPage,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),tastyTable.start||tastyTable.initTable("pagination")},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&&tastyTable.start||(scope.pagination=newValue,setPaginationRange())}),scope.page.setCount(scope.itemsPerPage)}}}]),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",["ngTasty.filter.filterInt"]).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.bindTo",[]).factory("bindTo",["$parse",function($parse){return function(scopeName,scope,attrs,newScopeName){var lastValue,parentGet,compare,parentSet,parentValueWatch,isolateScopeName;attrs[scopeName]&&(parentGet=$parse(attrs[scopeName]),compare=parentGet.literal?equals:function(a,b){return a===b||a!==a&&b!==b},isolateScopeName=newScopeName?newScopeName:scopeName,parentSet=parentGet.assign,lastValue=scope[isolateScopeName]=parentGet(scope.$parent),parentValueWatch=function(parentValue){return compare(parentValue,scope[isolateScopeName])||(compare(parentValue,lastValue)?parentSet(scope.$parent,parentValue=scope[isolateScopeName]):scope[isolateScopeName]=parentValue),lastValue=parentValue},parentValueWatch.$stateful=!0,scope.$parent.$watch($parse(attrs[scopeName],parentValueWatch),null,parentGet.literal))}}]),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.joinObjects",["ngTasty.service.setProperty"]).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.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.tastyUtil",["ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.setProperty","ngTasty.service.joinObjects","ngTasty.service.webSocket"]).factory("tastyUtil",["debounce","setProperty","joinObjects","bindTo","webSocket",function(debounce,setProperty,joinObjects,bindTo,webSocket){return{bindTo:bindTo,debounce:debounce,setProperty:setProperty,joinObjects:joinObjects,webSocket:webSocket}}]),angular.module("ngTasty.service.webSocket",[]).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})}}}});
{
"name": "ng-tasty",
"version": "0.4.1",
"version": "0.4.2",
"description": "A lightweight, flexible, and tasty collection of reusable UI components for AngularJS.",

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

@@ -35,6 +35,9 @@ /**

})
.controller('TableController', function($scope, $attrs, $timeout, $filter, tableConfig, tastyUtil) {
.controller('TableController', function($scope, $attrs, $filter, tableConfig, tastyUtil) {
'use strict';
var listScopeToWatch, initTable, newScopeName;
var listScopeToWatch, initTable, newScopeName, initStatus,
updateClientSideResource, updateServerSideResource, setDirectivesValues,
buildClientResource, buildUrl;
this.$scope = $scope;
initStatus = {};
$scope.init = {};

@@ -105,2 +108,4 @@ $scope.query = {};

// for other directives to talk to this one.
this.start = false;
this.activate = function(directiveName) {

@@ -118,5 +123,41 @@ $scope[directiveName + 'Directive'] = true;

this.initTable = function (keyDirective) {
initStatus[keyDirective] = true;
if (!$scope.theadDirective && !$scope.paginationDirective) {
this.start = true;
} else if ($scope.theadDirective && $scope.paginationDirective) {
if (initStatus.thead && initStatus.pagination){
this.start = true;
}
} else if ($scope.theadDirective && !$scope.paginationDirective) {
if (initStatus.thead){
this.start = true;
}
} else if (!$scope.theadDirective && $scope.paginationDirective) {
if (initStatus.pagination){
this.start = true;
}
}
if (this.start) {
if ($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;
if ($scope.resource.pagination) {
$scope.params.page = $scope.resource.pagination.page || $scope.init.page;
}
$scope.$evalAsync(updateClientSideResource);
} else {
$scope.params.sortBy = $scope.init.sortBy;
$scope.params.sortOrder = $scope.init.sortOrder;
$scope.params.page = $scope.init.page;
$scope.$evalAsync(updateServerSideResource);
}
}
};
this.bindOnce = tableConfig.bindOnce;
$scope.setDirectivesValues = function (resource) {
setDirectivesValues = function (resource) {
if (!angular.isObject(resource)) {

@@ -131,3 +172,3 @@ throw 'AngularJS tastyTable directive: the bind-resource '+

// [feature request] simplified header for resources #37 by @WebReflection
if (Object.keys(resource.header[0]).length === 1) {
if (resource.header.length && Object.keys(resource.header[0]).length === 1) {
resource.header = resource.header.map(function (header) {

@@ -151,13 +192,24 @@ var key = Object.keys(header)[0];

$scope.rows = resource.rows;
if ($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;
if ($scope.paginationDirective) {
$scope.pagination.page = $scope.params.page;
$scope.pagination.count = $scope.params.count;
$scope.pagination.size = $scope.rows.length;
if (resource.pagination) {
if (resource.pagination.count) {
$scope.pagination.count = resource.pagination.count;
}
if (resource.pagination.page) {
$scope.pagination.page = resource.pagination.page;
}
if (resource.pagination.size) {
$scope.pagination.size = resource.pagination.size;
}
}
$scope.pagination.pages = Math.ceil($scope.pagination.size / $scope.pagination.count);
}
};
$scope.buildClientResource = function() {
buildClientResource = function(updateFrom) {
var fromRow, toRow, rowToShow, reverse, listSortBy;
if ($scope.theadDirective) {
if ($scope.theadDirective && $scope.header.columns.length) {
reverse = $scope.header.sortOrder === 'asc' ? false : true;

@@ -180,3 +232,7 @@ listSortBy = [function(item) {

if ($scope.paginationDirective) {
$scope.pagination.page = $scope.params.page;
if (updateFrom === 'filters') {
$scope.pagination.page = 1;
} else {
$scope.pagination.page = $scope.params.page;
}
$scope.pagination.count = $scope.params.count;

@@ -194,3 +250,3 @@ $scope.pagination.size = $scope.rows.length;

$scope.buildUrl = function(params, filters) {
buildUrl = function(params, filters) {
var urlQuery, value, url, listKeyNotJoin;

@@ -219,29 +275,12 @@ urlQuery = {};

$scope.updateClientSideResource = tastyUtil.debounce(function() {
$scope.setDirectivesValues($scope.resource);
$scope.buildClientResource();
}, 60);
updateClientSideResource = function (updateFrom) {
setDirectivesValues($scope.resource);
buildClientResource(updateFrom);
};
$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);
updateServerSideResource = function () {
$scope.url = buildUrl($scope.params, $scope.filters);
$scope.resourceCallback($scope.url, angular.copy($scope.params)).then(function (resource) {
setDirectivesValues(resource);
});
}, 60);
initTable = function () {
if ($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;
if ($scope.resource.pagination) {
$scope.params.page = $scope.resource.pagination.page || $scope.init.page;
}
$scope.updateClientSideResource();
} else {
$scope.params.sortBy = $scope.init.sortBy;
$scope.params.sortOrder = $scope.init.sortOrder;
$scope.params.page = $scope.init.page;
$scope.updateServerSideResource();
}
};

@@ -251,8 +290,8 @@

if ($attrs.bindFilters) {
$scope.$watch('filters', function (newValue, oldValue){
$scope.$watch('filters', function watchFilters (newValue, oldValue){
if (newValue !== oldValue) {
if ($scope.clientSide) {
$scope.updateClientSideResource();
$scope.$evalAsync(updateClientSideResource('filters'));
} else {
$scope.updateServerSideResource();
$scope.$evalAsync(updateServerSideResource);
}

@@ -262,8 +301,8 @@ }

}
$scope.$watchCollection('params', function (newValue, oldValue){
$scope.$watchCollection('params', function watchParams (newValue, oldValue){
if (newValue !== oldValue) {
if ($scope.clientSide) {
$scope.updateClientSideResource();
$scope.$evalAsync(updateClientSideResource('params'));
} else {
$scope.updateServerSideResource();
$scope.$evalAsync(updateServerSideResource);
}

@@ -273,13 +312,10 @@ }

if ($scope.resource) {
$scope.$watch('resource', function (newValue, oldValue){
$scope.$watch('resource', function watchResource (newValue, oldValue){
if (newValue !== oldValue) {
$scope.params.sortBy = newValue.sortBy;
$scope.params.sortOrder = newValue.sortOrder;
$scope.updateClientSideResource();
$scope.$evalAsync(updateClientSideResource('resource'));
}
}, true);
}
// Init table
initTable();
})

@@ -290,3 +326,14 @@ .directive('tastyTable', function(){

scope: true,
controller: 'TableController'
controller: 'TableController',
link: function (scope, element, attrs, tastyTable) {
if (element.find('tasty-thead').length ||
element[0].querySelector('[tasty-thead]')) {
tastyTable.activate('thead');
}
if (element.find('tasty-pagination').length ||
element[0].querySelector('[tasty-pagination]')) {
tastyTable.activate('pagination');
}
tastyTable.initTable();
}
};

@@ -315,4 +362,2 @@ })

var iconUp, iconDown, newScopeName, listScopeToWatch;
// Thead it's called
tastyTable.activate('thead');
scope.bindOnce = tastyTable.bindOnce;

@@ -381,2 +426,6 @@ scope.columns = [];

}
if (!tastyTable.start) {
// Thead it's called
tastyTable.initTable('thead');
}
};

@@ -410,4 +459,4 @@

tastyTable.$scope.$watchCollection('header', function (newValue, oldValue){
if (newValue && (newValue !== oldValue)) {
tastyTable.$scope.$watchCollection('header', function watchHeader (newValue, oldValue){
if (newValue && ((newValue !== oldValue) || !tastyTable.start)) {
scope.header = newValue;

@@ -473,5 +522,2 @@ scope.setColumns();

// Pagination it's called
tastyTable.activate('pagination');
// Internal variable

@@ -550,2 +596,7 @@ scope.pagination = {};

scope.rangePage = $filter('range')([], scope.pagMinRange, scope.pagMaxRange);
if (!tastyTable.start) {
// Pagination it's called
tastyTable.initTable('pagination');
}
};

@@ -574,4 +625,4 @@

tastyTable.$scope.$watchCollection('pagination', function (newValue, oldValue){
if (newValue && (newValue !== oldValue)) {
tastyTable.$scope.$watchCollection('pagination', function watchPagination (newValue, oldValue){
if (newValue && ((newValue !== oldValue) || !tastyTable.start)) {
scope.pagination = newValue;

@@ -578,0 +629,0 @@ setPaginationRange();

@@ -8,8 +8,8 @@ /**

.factory('debounce', function($timeout) {
return function(func, wait, immediate) {
return function (func, wait, immediate) {
var timeout;
return function() {
return function debounce () {
var context = this, args = arguments;
$timeout.cancel(timeout);
timeout = $timeout(function() {
timeout = $timeout(function debounceTimeout () {
timeout = null;

@@ -16,0 +16,0 @@ func.apply(context, args);

@@ -10,5 +10,6 @@ /**

'ngTasty.service.setProperty',
'ngTasty.service.joinObjects'
'ngTasty.service.joinObjects',
'ngTasty.service.webSocket'
])
.factory('tastyUtil', function(debounce, setProperty, joinObjects, bindTo) {
.factory('tastyUtil', function(debounce, setProperty, joinObjects, bindTo, webSocket) {
return {

@@ -18,4 +19,5 @@ 'bindTo': bindTo,

'setProperty': setProperty,
'joinObjects': joinObjects
'joinObjects': joinObjects,
'webSocket': webSocket
};
});
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