Comparing version 0.5.4 to 0.5.5
{ | ||
"name": "ng-tasty", | ||
"version": "0.5.4", | ||
"version": "0.5.5", | ||
"homepage": "https://github.com/Zizzamia/ng-tasty", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -5,6 +5,6 @@ /* | ||
* Version: 0.5.4 - 2015-05-04 | ||
* Version: 0.5.5 - 2015-06-15 | ||
* License: MIT | ||
*/ | ||
angular.module("ngTasty", ["ngTasty.tpls", "ngTasty.component.table","ngTasty.filter.camelize","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.filter.slugify","ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.throttle","ngTasty.service.webSocket"]); | ||
angular.module("ngTasty", ["ngTasty.tpls", "ngTasty.component.table","ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.throttle","ngTasty.service.webSocket","ngTasty.filter.camelize","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.filter.slugify"]); | ||
angular.module("ngTasty.tpls", ["ngTasty.tpls.table.head","ngTasty.tpls.table.pagination"]); | ||
@@ -95,3 +95,7 @@ /** | ||
Object.keys(tableConfig).forEach(function(key) { | ||
this.config[key] = $scope.theme[key] || tableConfig[key]; | ||
if (angular.isDefined($scope.theme[key])) { | ||
this.config[key] = $scope.theme[key]; | ||
} else { | ||
this.config[key] = tableConfig[key]; | ||
} | ||
}, this); | ||
@@ -701,2 +705,3 @@ } else { | ||
var maxItems, page; | ||
scope.itemsPerPage = count; | ||
maxItems = count * scope.pagination.page; | ||
@@ -727,3 +732,3 @@ if (maxItems > scope.pagination.size) { | ||
scope.pagMaxRange = scope.pagMinRange; | ||
scope.pagMinRange = scope.pagMaxRange - scope.itemsPerPage; | ||
scope.pagMinRange = scope.pagMaxRange - 5; | ||
setPaginationRanges(); | ||
@@ -733,11 +738,13 @@ }; | ||
setRemainingRange = function () { | ||
if (scope.pagHideMaxRange === true || scope.pagMaxRange > scope.pagination.pages) { | ||
if (scope.pagHideMaxRange === true || | ||
scope.pagMaxRange > scope.pagination.pages) { | ||
return false; | ||
} | ||
scope.pagMinRange = scope.pagMaxRange; | ||
scope.pagMaxRange = scope.pagMinRange + scope.itemsPerPage; | ||
if (scope.pagMaxRange > scope.pagination.pages) { | ||
scope.pagMaxRange = scope.pagination.pages; | ||
scope.pagMaxRange = scope.pagMinRange + 5; | ||
if (scope.pagMaxRange >= scope.pagination.pages) { | ||
scope.pagMaxRange = scope.pagination.pages + 1; | ||
scope.pagMinRange = scope.pagMaxRange - 5 + 1; | ||
} | ||
scope.pagMinRange = scope.pagMaxRange - scope.itemsPerPage; | ||
scope.pagMinRange = scope.pagMaxRange - 5; | ||
setPaginationRanges(); | ||
@@ -754,3 +761,3 @@ }; | ||
scope.pagHideMinRange = scope.pagMinRange <= 1; | ||
scope.pagHideMaxRange = scope.pagMaxRange >= scope.pagination.pages; | ||
scope.pagHideMaxRange = scope.pagMaxRange > scope.pagination.pages; | ||
scope.classPageMinRange = scope.pagHideMinRange ? 'disabled' : ''; | ||
@@ -765,3 +772,2 @@ scope.classPageMaxRange = scope.pagHideMaxRange ? 'disabled' : ''; | ||
} | ||
scope.rangePage = $filter('range')([], scope.pagMinRange, scope.pagMaxRange); | ||
@@ -1302,3 +1308,4 @@ | ||
' ng-style="::column.style" ng-click="sortBy(column)">\n' + | ||
' <span ng-bind="::column.name"></span>\n' + | ||
' <span ng-if="bindOnce" ng-bind="::column.name"></span>\n' + | ||
' <span ng-if="!bindOnce" ng-bind="column.name"></span>\n' + | ||
' <span ng-class="column.isSorted">\n' + | ||
@@ -1305,0 +1312,0 @@ ' <span ng-class="column.isSortedCaret" ng-if="::bootstrapIcon"></span>\n' + |
@@ -5,5 +5,5 @@ /* | ||
* Version: 0.5.4 - 2015-05-04 | ||
* Version: 0.5.5 - 2015-06-15 | ||
* License: MIT | ||
*/ | ||
angular.module("ngTasty",["ngTasty.tpls","ngTasty.component.table","ngTasty.filter.camelize","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.filter.slugify","ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.throttle","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"},bindOnce:!0,loadOnInit:!1,iconUp:"fa fa-sort-up",iconDown:"fa fa-sort-down",bootstrapIcon:!1,templateHeadUrl:"template/table/head.html",templateUrl:"template/table/pagination.html",listItemsPerPage:[5,25,50,100],itemsPerPage:5,watchResource:"reference"}).controller("TableController",["$scope","$attrs","$filter","tableConfig","tastyUtil",function($scope,$attrs,$filter,tableConfig,tastyUtil){var listScopeToWatch,newScopeName,initStatus,updateClientSideResource,updateServerSideResource,setDirectivesValues,buildClientResource,buildUrl,paramsInitialCycle,initNow;this.$scope=$scope,initStatus={},initNow=!0,paramsInitialCycle=!0,$scope.init={},$scope.query={},$scope.logs={buildClientResourceCount:0},$scope.theme={},listScopeToWatch=["bindFilters","bindFiltersComparator","bindInit","bindQuery","bindResource","bindResourceCallback","bindWatchResource","bindReload","bindTheme"],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]&&"watchResource"===newScopeName?$scope[newScopeName]=$attrs[newScopeName]:$attrs[newScopeName]&&"filtersComparator"===newScopeName&&($scope[newScopeName]=JSON.parse($attrs[newScopeName]))}),this.config={},angular.isObject($scope.theme)?Object.keys(tableConfig).forEach(function(key){this.config[key]=$scope.theme[key]||tableConfig[key]},this):this.config=tableConfig,$scope.query.page=$scope.query.page||this.config.query.page,$scope.query.count=$scope.query.count||this.config.query.count,$scope.query.sortBy=$scope.query.sortBy||this.config.query.sortBy,$scope.query.sortOrder=$scope.query.sortOrder||this.config.query.sortOrder,$scope.reload&&!this.config.loadOnInit&&(initNow=!1),$scope.init.count=$scope.init.count||this.config.init.count,$scope.init.page=$scope.init.page||this.config.init.page,$scope.init.sortBy=$scope.init.sortBy||this.config.init.sortBy,$scope.init.sortOrder=$scope.init.sortOrder||this.config.init.sortOrder,$scope.watchResource=$scope.watchResource||this.config.watchResource;var listImmutableKey=["filters","init","query","rows","header","pagination","params","sortOrder","sortBy","url"];if($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 new Error("AngularJS tastyTable directive: need the bind-resource or bind-resource-callback attribute");if(angular.isDefined($attrs.bindResource)){if(!angular.isObject($scope.resource))throw new Error("AngularJS tastyTable directive: the bind-resource ("+$attrs.bindResource+") is not an object");if(!$scope.resource.header&&!$scope.resource.rows)throw new Error("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 new Error("AngularJS tastyTable directive: the bind-resource-callback ("+$attrs.bindResourceCallback+") is not a function");$scope.clientSide=!1}if(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),initNow&&$scope.$evalAsync(updateClientSideResource)):($scope.params.sortBy=$scope.init.sortBy,$scope.params.sortOrder=$scope.init.sortOrder,$scope.params.page=$scope.init.page,initNow?$scope.$evalAsync(updateServerSideResource):$scope.reload&&($scope.url=buildUrl($scope.params,$scope.filters),$scope.reload=function(){$scope.resourceCallback($scope.url,angular.copy($scope.params)).then(function(resource){setDirectivesValues(resource)})})))},this.bindOnce=this.config.bindOnce,setDirectivesValues=function(resource){if(!angular.isObject(resource))throw new Error("AngularJS tastyTable directive: the resource response is not an object");if(!resource.header&&!resource.rows)throw new Error("AngularJS tastyTable directive: the resource response object has the property header or rows undefined");Object.keys(resource).forEach(function(key){listImmutableKey.indexOf(key)<0&&($scope[key]=resource[key])}),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.logs.buildClientResourceCount+=1,$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.filtersComparator)),$scope.paginationDirective&&($scope.pagination.count=$scope.params.count,$scope.pagination.size=$scope.rows.length,$scope.pagination.pages=Math.ceil($scope.rows.length/$scope.pagination.count),"filters"===updateFrom||$scope.pagination.page>$scope.pagination.pages?($scope.pagination.page=1,$scope.params.page=1):$scope.pagination.page=$scope.params.page,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){$scope.params.sortBy&&($scope.resource.sortBy=$scope.params.sortBy),$scope.params.sortOrder&&($scope.resource.sortOrder=$scope.params.sortOrder),$scope.params.page&&$scope.params.count&&($scope.resource.pagination=$scope.pagination,$scope.resource.pagination.page=$scope.params.page,$scope.resource.pagination.count=$scope.params.count),setDirectivesValues($scope.resource),buildClientResource(updateFrom)},updateServerSideResource=function(updateFrom){$scope.url=buildUrl($scope.params,$scope.filters),$scope.reload&&($scope.reload=function(){$scope.resourceCallback($scope.url,angular.copy($scope.params)).then(function(resource){setDirectivesValues(resource)})}),(!$scope.reload||$scope.reload&&"filters"!==updateFrom)&&$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("filters")))},!0),$scope.$watchCollection("params",function(newValue,oldValue){newValue!==oldValue&&(paramsInitialCycle===!1?$scope.clientSide?$scope.$evalAsync(updateClientSideResource("params")):$scope.$evalAsync(updateServerSideResource):paramsInitialCycle=!1)}),$scope.resource){var watchResource=function(newValue,oldValue){newValue!==oldValue&&($scope.params.sortBy=$scope.resource.sortBy||$scope.params.sortBy,$scope.params.sortOrder=$scope.resource.sortOrder||$scope.params.sortOrder,$scope.$evalAsync(updateClientSideResource("resource")),$scope.resource.reload||($scope.resource.reload=function(){$scope.$evalAsync(updateClientSideResource("resource"))}))};"reference"===$scope.watchResource?$scope.$watch("resource",watchResource):"collection"===$scope.watchResource?($scope.$watchCollection("resource.header",watchResource),$scope.$watchCollection("resource.rows",watchResource),$scope.$watchGroup(["resource.sortBy","resource.sortOrder","resource.pagination.count","resource.pagination.page","resource.pagination.pages","resource.pagination.size"],watchResource)):"equality"===$scope.watchResource&&($scope.$watch("resource.header",watchResource,!0),$scope.$watch("resource.rows",watchResource,!0),$scope.$watch("resource.sortBy",watchResource,!0),$scope.$watch("resource.sortOrder",watchResource,!0),$scope.$watch("resource.pagination.count",watchResource,!0),$scope.$watch("resource.pagination.page",watchResource,!0),$scope.$watch("resource.pagination.pages",watchResource,!0),$scope.$watch("resource.pagination.size",watchResource,!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","$templateCache","$http","$compile","tableConfig","tastyUtil",function($filter,$templateCache,$http,$compile,tableConfig,tastyUtil){return{restrict:"AE",require:"^tastyTable",scope:{},templateUrl:tableConfig.templateHeadUrl,link:function(scope,element,attrs,tastyTable){var newScopeName,listScopeToWatch;scope.bindOnce=tastyTable.bindOnce,scope.columns=[],scope.bootstrapIcon=tastyTable.config.bootstrapIcon,scope.iconUp=tastyTable.config.iconUp,scope.iconDown=tastyTable.config.iconDown,listScopeToWatch=["bindNotSortBy","bindBootstrapIcon","bindIconUp","bindIconDown","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]&&("["===attrs[newScopeName][0]?(attrs[newScopeName]=attrs[newScopeName].replace(/'/g,'"'),scope[newScopeName]=JSON.parse(attrs[newScopeName])):scope[newScopeName]=attrs[newScopeName])}),scope.templateUrl&&$http.get(scope.templateUrl,{cache:$templateCache}).success(function(templateContent){element.replaceWith($compile(templateContent)(scope))}),scope.setColumns=function(){var active,sortable,sort,isSorted,isSortedCaret;scope.columns=[],"dsc"===scope.header.sortOrder&&scope.header.sortBy&&"-"!==scope.header.sortBy[0]&&(scope.header.sortBy="-"+scope.header.sortBy),scope.header.columns.forEach(function(column){column.style=column.style||{},angular.isArray(column.class)||(column.class=[]),sortable=!0,active=!1,isSorted="",isSortedCaret="",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?tastyTable.config.bootstrapIcon?(isSorted="",isSortedCaret="caret"):isSorted=scope.iconDown:scope.header.sortBy===sort&&(tastyTable.config.bootstrapIcon?(isSorted="dropup",isSortedCaret="caret"):isSorted=scope.iconUp),scope.columns.push({key:column.key,name:column.name,active:active,sortable:sortable,"class":column.class,style:column.style,isSorted:isSorted,isSortedCaret:isSortedCaret})}),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"),column.class.forEach(function(className){listClassToShow.push(className)}),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:tableConfig.templateUrl,link:function(scope,element,attrs,tastyTable){var getPage,setCount,setPaginationRange,setPreviousRange,setRemainingRange,setPaginationRanges,listScopeToWatch,newScopeName;listScopeToWatch=["bindItemsPerPage","bindListItemsPerPage","bindTemplateUrl"],listScopeToWatch.forEach(function(scopeName){if(newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),attrs[scopeName])tastyUtil.bindTo(scopeName,scope,attrs,newScopeName);else if(attrs[newScopeName])if("itemsPerPage"===newScopeName)scope[newScopeName]=parseInt(attrs[newScopeName]);else try{scope[newScopeName]=JSON.parse(attrs[newScopeName])}catch(err){scope[newScopeName]=attrs[newScopeName]}}),scope.templateUrl&&$http.get(scope.templateUrl,{cache:$templateCache}).success(function(templateContent){element.replaceWith($compile(templateContent)(scope))}),scope.itemsPerPage=scope.itemsPerPage||tastyTable.config.itemsPerPage,scope.listItemsPerPage=scope.listItemsPerPage||tastyTable.config.listItemsPerPage,tastyTable.$scope.clientSide||(scope.itemsPerPage=tastyTable.$scope.init.count||scope.itemsPerPage),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+2);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.camelize",[]).filter("camelize",function(){var CAMELIZE_REGEX=/(?:^|[-_ ])(\w)/g;return function(input,first){var isString="string"==typeof input,firstLetter="undefined"==typeof first?!1:!!first;return"undefined"==typeof input||null===input||!isString&&isNaN(input)?"":isString?input.trim().replace(/ +(?= )/g,"").replace(CAMELIZE_REGEX,function(_,character,pos){return character&&(firstLetter||pos>0)?character.toUpperCase():character}):""+input}}),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.filter.slugify",[]).filter("slugify",function(){var makeString=function(object){return null==object?"":""+object},from="ąàáäâãåæăćčĉęèéëêĝĥìíïîĵłľńňòóöőôõðøśșšŝťțŭùúüűûñÿýçżźž",to="aaaaaaaaaccceeeeeghiiiijllnnoooooooossssttuuuuuunyyczzz",regex=new RegExp("["+from+"]","g");return function(str){return str=makeString(str).toString().toLowerCase().replace(regex,function(c){var index=from.indexOf(c);return to.charAt(index)||"-"}).replace(/[^\w\-\s]+/g,"").trim().replace(/\s+/g,"-").replace(/\-\-+/g,"-")}}),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?angular.equals:function(a,b){return a===b||a!==a&&b!==b},isolateScopeName=newScopeName?newScopeName:scopeName,parentSet=parentGet.assign||function(){throw lastValue=scope[scopeName]=parentGet(scopeName),"Expression "+attrs[attrName]+" is non-assignable!"},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,immediate){var args,context,debounceTimeout,timeout;return debounceTimeout=function(){timeout=null,immediate||func.apply(context,args)},function(){context=this,args=arguments;var callNow=immediate&&!timeout;$timeout.cancel(timeout),timeout=$timeout(debounceTimeout,wait),callNow&&func.apply(context,args)}}}]),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]&&(angular.isString(objTwo[attrname])?objTwo[attrname].length&&(objOne[attrname]=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.throttle","ngTasty.service.webSocket"]).factory("tastyUtil",["debounce","setProperty","joinObjects","bindTo","webSocket","throttle",function(debounce,setProperty,joinObjects,bindTo,webSocket,throttle){return{bindTo:bindTo,debounce:debounce,setProperty:setProperty,joinObjects:joinObjects,throttle:throttle,webSocket:webSocket}}]),angular.module("ngTasty.service.throttle",[]).factory("throttle",["$timeout",function($timeout){return function(fn,threshhold,scope){threshhold=threshhold||250;var last,promise;return function(){var context=scope||this,now=Date.now(),args=arguments;last&&last+threshhold>now?($timeout.cancel(promise),promise=$timeout(function(){last=now,fn.apply(context,args)},threshhold)):(last=now,fn.apply(context,args))}}}]),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();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">\n <span ng-class="column.isSortedCaret" ng-if="::bootstrapIcon"></span>\n </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()">«</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()">»</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.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.throttle","ngTasty.service.webSocket","ngTasty.filter.camelize","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.filter.slugify"]),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"},bindOnce:!0,loadOnInit:!1,iconUp:"fa fa-sort-up",iconDown:"fa fa-sort-down",bootstrapIcon:!1,templateHeadUrl:"template/table/head.html",templateUrl:"template/table/pagination.html",listItemsPerPage:[5,25,50,100],itemsPerPage:5,watchResource:"reference"}).controller("TableController",["$scope","$attrs","$filter","tableConfig","tastyUtil",function($scope,$attrs,$filter,tableConfig,tastyUtil){var listScopeToWatch,newScopeName,initStatus,updateClientSideResource,updateServerSideResource,setDirectivesValues,buildClientResource,buildUrl,paramsInitialCycle,initNow;this.$scope=$scope,initStatus={},initNow=!0,paramsInitialCycle=!0,$scope.init={},$scope.query={},$scope.logs={buildClientResourceCount:0},$scope.theme={},listScopeToWatch=["bindFilters","bindFiltersComparator","bindInit","bindQuery","bindResource","bindResourceCallback","bindWatchResource","bindReload","bindTheme"],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]&&"watchResource"===newScopeName?$scope[newScopeName]=$attrs[newScopeName]:$attrs[newScopeName]&&"filtersComparator"===newScopeName&&($scope[newScopeName]=JSON.parse($attrs[newScopeName]))}),this.config={},angular.isObject($scope.theme)?Object.keys(tableConfig).forEach(function(key){this.config[key]=angular.isDefined($scope.theme[key])?$scope.theme[key]:tableConfig[key]},this):this.config=tableConfig,$scope.query.page=$scope.query.page||this.config.query.page,$scope.query.count=$scope.query.count||this.config.query.count,$scope.query.sortBy=$scope.query.sortBy||this.config.query.sortBy,$scope.query.sortOrder=$scope.query.sortOrder||this.config.query.sortOrder,$scope.reload&&!this.config.loadOnInit&&(initNow=!1),$scope.init.count=$scope.init.count||this.config.init.count,$scope.init.page=$scope.init.page||this.config.init.page,$scope.init.sortBy=$scope.init.sortBy||this.config.init.sortBy,$scope.init.sortOrder=$scope.init.sortOrder||this.config.init.sortOrder,$scope.watchResource=$scope.watchResource||this.config.watchResource;var listImmutableKey=["filters","init","query","rows","header","pagination","params","sortOrder","sortBy","url"];if($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 new Error("AngularJS tastyTable directive: need the bind-resource or bind-resource-callback attribute");if(angular.isDefined($attrs.bindResource)){if(!angular.isObject($scope.resource))throw new Error("AngularJS tastyTable directive: the bind-resource ("+$attrs.bindResource+") is not an object");if(!$scope.resource.header&&!$scope.resource.rows)throw new Error("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 new Error("AngularJS tastyTable directive: the bind-resource-callback ("+$attrs.bindResourceCallback+") is not a function");$scope.clientSide=!1}if(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),initNow&&$scope.$evalAsync(updateClientSideResource)):($scope.params.sortBy=$scope.init.sortBy,$scope.params.sortOrder=$scope.init.sortOrder,$scope.params.page=$scope.init.page,initNow?$scope.$evalAsync(updateServerSideResource):$scope.reload&&($scope.url=buildUrl($scope.params,$scope.filters),$scope.reload=function(){$scope.resourceCallback($scope.url,angular.copy($scope.params)).then(function(resource){setDirectivesValues(resource)})})))},this.bindOnce=this.config.bindOnce,setDirectivesValues=function(resource){if(!angular.isObject(resource))throw new Error("AngularJS tastyTable directive: the resource response is not an object");if(!resource.header&&!resource.rows)throw new Error("AngularJS tastyTable directive: the resource response object has the property header or rows undefined");Object.keys(resource).forEach(function(key){listImmutableKey.indexOf(key)<0&&($scope[key]=resource[key])}),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.logs.buildClientResourceCount+=1,$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.filtersComparator)),$scope.paginationDirective&&($scope.pagination.count=$scope.params.count,$scope.pagination.size=$scope.rows.length,$scope.pagination.pages=Math.ceil($scope.rows.length/$scope.pagination.count),"filters"===updateFrom||$scope.pagination.page>$scope.pagination.pages?($scope.pagination.page=1,$scope.params.page=1):$scope.pagination.page=$scope.params.page,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){$scope.params.sortBy&&($scope.resource.sortBy=$scope.params.sortBy),$scope.params.sortOrder&&($scope.resource.sortOrder=$scope.params.sortOrder),$scope.params.page&&$scope.params.count&&($scope.resource.pagination=$scope.pagination,$scope.resource.pagination.page=$scope.params.page,$scope.resource.pagination.count=$scope.params.count),setDirectivesValues($scope.resource),buildClientResource(updateFrom)},updateServerSideResource=function(updateFrom){$scope.url=buildUrl($scope.params,$scope.filters),$scope.reload&&($scope.reload=function(){$scope.resourceCallback($scope.url,angular.copy($scope.params)).then(function(resource){setDirectivesValues(resource)})}),(!$scope.reload||$scope.reload&&"filters"!==updateFrom)&&$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("filters")))},!0),$scope.$watchCollection("params",function(newValue,oldValue){newValue!==oldValue&&(paramsInitialCycle===!1?$scope.clientSide?$scope.$evalAsync(updateClientSideResource("params")):$scope.$evalAsync(updateServerSideResource):paramsInitialCycle=!1)}),$scope.resource){var watchResource=function(newValue,oldValue){newValue!==oldValue&&($scope.params.sortBy=$scope.resource.sortBy||$scope.params.sortBy,$scope.params.sortOrder=$scope.resource.sortOrder||$scope.params.sortOrder,$scope.$evalAsync(updateClientSideResource("resource")),$scope.resource.reload||($scope.resource.reload=function(){$scope.$evalAsync(updateClientSideResource("resource"))}))};"reference"===$scope.watchResource?$scope.$watch("resource",watchResource):"collection"===$scope.watchResource?($scope.$watchCollection("resource.header",watchResource),$scope.$watchCollection("resource.rows",watchResource),$scope.$watchGroup(["resource.sortBy","resource.sortOrder","resource.pagination.count","resource.pagination.page","resource.pagination.pages","resource.pagination.size"],watchResource)):"equality"===$scope.watchResource&&($scope.$watch("resource.header",watchResource,!0),$scope.$watch("resource.rows",watchResource,!0),$scope.$watch("resource.sortBy",watchResource,!0),$scope.$watch("resource.sortOrder",watchResource,!0),$scope.$watch("resource.pagination.count",watchResource,!0),$scope.$watch("resource.pagination.page",watchResource,!0),$scope.$watch("resource.pagination.pages",watchResource,!0),$scope.$watch("resource.pagination.size",watchResource,!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","$templateCache","$http","$compile","tableConfig","tastyUtil",function($filter,$templateCache,$http,$compile,tableConfig,tastyUtil){return{restrict:"AE",require:"^tastyTable",scope:{},templateUrl:tableConfig.templateHeadUrl,link:function(scope,element,attrs,tastyTable){var newScopeName,listScopeToWatch;scope.bindOnce=tastyTable.bindOnce,scope.columns=[],scope.bootstrapIcon=tastyTable.config.bootstrapIcon,scope.iconUp=tastyTable.config.iconUp,scope.iconDown=tastyTable.config.iconDown,listScopeToWatch=["bindNotSortBy","bindBootstrapIcon","bindIconUp","bindIconDown","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]&&("["===attrs[newScopeName][0]?(attrs[newScopeName]=attrs[newScopeName].replace(/'/g,'"'),scope[newScopeName]=JSON.parse(attrs[newScopeName])):scope[newScopeName]=attrs[newScopeName])}),scope.templateUrl&&$http.get(scope.templateUrl,{cache:$templateCache}).success(function(templateContent){element.replaceWith($compile(templateContent)(scope))}),scope.setColumns=function(){var active,sortable,sort,isSorted,isSortedCaret;scope.columns=[],"dsc"===scope.header.sortOrder&&scope.header.sortBy&&"-"!==scope.header.sortBy[0]&&(scope.header.sortBy="-"+scope.header.sortBy),scope.header.columns.forEach(function(column){column.style=column.style||{},angular.isArray(column.class)||(column.class=[]),sortable=!0,active=!1,isSorted="",isSortedCaret="",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?tastyTable.config.bootstrapIcon?(isSorted="",isSortedCaret="caret"):isSorted=scope.iconDown:scope.header.sortBy===sort&&(tastyTable.config.bootstrapIcon?(isSorted="dropup",isSortedCaret="caret"):isSorted=scope.iconUp),scope.columns.push({key:column.key,name:column.name,active:active,sortable:sortable,"class":column.class,style:column.style,isSorted:isSorted,isSortedCaret:isSortedCaret})}),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"),column.class.forEach(function(className){listClassToShow.push(className)}),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:tableConfig.templateUrl,link:function(scope,element,attrs,tastyTable){var getPage,setCount,setPaginationRange,setPreviousRange,setRemainingRange,setPaginationRanges,listScopeToWatch,newScopeName;listScopeToWatch=["bindItemsPerPage","bindListItemsPerPage","bindTemplateUrl"],listScopeToWatch.forEach(function(scopeName){if(newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),attrs[scopeName])tastyUtil.bindTo(scopeName,scope,attrs,newScopeName);else if(attrs[newScopeName])if("itemsPerPage"===newScopeName)scope[newScopeName]=parseInt(attrs[newScopeName]);else try{scope[newScopeName]=JSON.parse(attrs[newScopeName])}catch(err){scope[newScopeName]=attrs[newScopeName]}}),scope.templateUrl&&$http.get(scope.templateUrl,{cache:$templateCache}).success(function(templateContent){element.replaceWith($compile(templateContent)(scope))}),scope.itemsPerPage=scope.itemsPerPage||tastyTable.config.itemsPerPage,scope.listItemsPerPage=scope.listItemsPerPage||tastyTable.config.listItemsPerPage,tastyTable.$scope.clientSide||(scope.itemsPerPage=tastyTable.$scope.init.count||scope.itemsPerPage),scope.pagination={},scope.pagMinRange=1,scope.pagMaxRange=1,getPage=function(numPage){tastyTable.setParams("page",numPage)},setCount=function(count){var maxItems,page;scope.itemsPerPage=count,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-5,setPaginationRanges(),void 0)},setRemainingRange=function(){return scope.pagHideMaxRange===!0||scope.pagMaxRange>scope.pagination.pages?!1:(scope.pagMinRange=scope.pagMaxRange,scope.pagMaxRange=scope.pagMinRange+5,scope.pagMaxRange>=scope.pagination.pages&&(scope.pagMaxRange=scope.pagination.pages+1,scope.pagMinRange=scope.pagMaxRange-5+1),scope.pagMinRange=scope.pagMaxRange-5,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+2);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.camelize",[]).filter("camelize",function(){var CAMELIZE_REGEX=/(?:^|[-_ ])(\w)/g;return function(input,first){var isString="string"==typeof input,firstLetter="undefined"==typeof first?!1:!!first;return"undefined"==typeof input||null===input||!isString&&isNaN(input)?"":isString?input.trim().replace(/ +(?= )/g,"").replace(CAMELIZE_REGEX,function(_,character,pos){return character&&(firstLetter||pos>0)?character.toUpperCase():character}):""+input}}),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.filter.slugify",[]).filter("slugify",function(){var makeString=function(object){return null==object?"":""+object},from="ąàáäâãåæăćčĉęèéëêĝĥìíïîĵłľńňòóöőôõðøśșšŝťțŭùúüűûñÿýçżźž",to="aaaaaaaaaccceeeeeghiiiijllnnoooooooossssttuuuuuunyyczzz",regex=new RegExp("["+from+"]","g");return function(str){return str=makeString(str).toString().toLowerCase().replace(regex,function(c){var index=from.indexOf(c);return to.charAt(index)||"-"}).replace(/[^\w\-\s]+/g,"").trim().replace(/\s+/g,"-").replace(/\-\-+/g,"-")}}),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?angular.equals:function(a,b){return a===b||a!==a&&b!==b},isolateScopeName=newScopeName?newScopeName:scopeName,parentSet=parentGet.assign||function(){throw lastValue=scope[scopeName]=parentGet(scopeName),"Expression "+attrs[attrName]+" is non-assignable!"},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,immediate){var args,context,debounceTimeout,timeout;return debounceTimeout=function(){timeout=null,immediate||func.apply(context,args)},function(){context=this,args=arguments;var callNow=immediate&&!timeout;$timeout.cancel(timeout),timeout=$timeout(debounceTimeout,wait),callNow&&func.apply(context,args)}}}]),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]&&(angular.isString(objTwo[attrname])?objTwo[attrname].length&&(objOne[attrname]=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.throttle","ngTasty.service.webSocket"]).factory("tastyUtil",["debounce","setProperty","joinObjects","bindTo","webSocket","throttle",function(debounce,setProperty,joinObjects,bindTo,webSocket,throttle){return{bindTo:bindTo,debounce:debounce,setProperty:setProperty,joinObjects:joinObjects,throttle:throttle,webSocket:webSocket}}]),angular.module("ngTasty.service.throttle",[]).factory("throttle",["$timeout",function($timeout){return function(fn,threshhold,scope){threshhold=threshhold||250;var last,promise;return function(){var context=scope||this,now=Date.now(),args=arguments;last&&last+threshhold>now?($timeout.cancel(promise),promise=$timeout(function(){last=now,fn.apply(context,args)},threshhold)):(last=now,fn.apply(context,args))}}}]),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();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-if="bindOnce" ng-bind="::column.name"></span>\n <span ng-if="!bindOnce" ng-bind="column.name"></span>\n <span ng-class="column.isSorted">\n <span ng-class="column.isSortedCaret" ng-if="::bootstrapIcon"></span>\n </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()">«</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()">»</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.5.4 - 2015-05-04 | ||
* Version: 0.5.5 - 2015-06-15 | ||
* License: MIT | ||
*/ | ||
angular.module("ngTasty", ["ngTasty.component.table","ngTasty.filter.camelize","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.filter.slugify","ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.throttle","ngTasty.service.webSocket"]); | ||
angular.module("ngTasty", ["ngTasty.component.table","ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.throttle","ngTasty.service.webSocket","ngTasty.filter.camelize","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.filter.slugify"]); | ||
/** | ||
@@ -94,3 +94,7 @@ * @ngdoc directive | ||
Object.keys(tableConfig).forEach(function(key) { | ||
this.config[key] = $scope.theme[key] || tableConfig[key]; | ||
if (angular.isDefined($scope.theme[key])) { | ||
this.config[key] = $scope.theme[key]; | ||
} else { | ||
this.config[key] = tableConfig[key]; | ||
} | ||
}, this); | ||
@@ -700,2 +704,3 @@ } else { | ||
var maxItems, page; | ||
scope.itemsPerPage = count; | ||
maxItems = count * scope.pagination.page; | ||
@@ -726,3 +731,3 @@ if (maxItems > scope.pagination.size) { | ||
scope.pagMaxRange = scope.pagMinRange; | ||
scope.pagMinRange = scope.pagMaxRange - scope.itemsPerPage; | ||
scope.pagMinRange = scope.pagMaxRange - 5; | ||
setPaginationRanges(); | ||
@@ -732,11 +737,13 @@ }; | ||
setRemainingRange = function () { | ||
if (scope.pagHideMaxRange === true || scope.pagMaxRange > scope.pagination.pages) { | ||
if (scope.pagHideMaxRange === true || | ||
scope.pagMaxRange > scope.pagination.pages) { | ||
return false; | ||
} | ||
scope.pagMinRange = scope.pagMaxRange; | ||
scope.pagMaxRange = scope.pagMinRange + scope.itemsPerPage; | ||
if (scope.pagMaxRange > scope.pagination.pages) { | ||
scope.pagMaxRange = scope.pagination.pages; | ||
scope.pagMaxRange = scope.pagMinRange + 5; | ||
if (scope.pagMaxRange >= scope.pagination.pages) { | ||
scope.pagMaxRange = scope.pagination.pages + 1; | ||
scope.pagMinRange = scope.pagMaxRange - 5 + 1; | ||
} | ||
scope.pagMinRange = scope.pagMaxRange - scope.itemsPerPage; | ||
scope.pagMinRange = scope.pagMaxRange - 5; | ||
setPaginationRanges(); | ||
@@ -753,3 +760,3 @@ }; | ||
scope.pagHideMinRange = scope.pagMinRange <= 1; | ||
scope.pagHideMaxRange = scope.pagMaxRange >= scope.pagination.pages; | ||
scope.pagHideMaxRange = scope.pagMaxRange > scope.pagination.pages; | ||
scope.classPageMinRange = scope.pagHideMinRange ? 'disabled' : ''; | ||
@@ -764,3 +771,2 @@ scope.classPageMaxRange = scope.pagHideMaxRange ? 'disabled' : ''; | ||
} | ||
scope.rangePage = $filter('range')([], scope.pagMinRange, scope.pagMaxRange); | ||
@@ -767,0 +773,0 @@ |
@@ -5,5 +5,5 @@ /* | ||
* Version: 0.5.4 - 2015-05-04 | ||
* Version: 0.5.5 - 2015-06-15 | ||
* License: MIT | ||
*/ | ||
angular.module("ngTasty",["ngTasty.component.table","ngTasty.filter.camelize","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.filter.slugify","ngTasty.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.throttle","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"},bindOnce:!0,loadOnInit:!1,iconUp:"fa fa-sort-up",iconDown:"fa fa-sort-down",bootstrapIcon:!1,templateHeadUrl:"template/table/head.html",templateUrl:"template/table/pagination.html",listItemsPerPage:[5,25,50,100],itemsPerPage:5,watchResource:"reference"}).controller("TableController",["$scope","$attrs","$filter","tableConfig","tastyUtil",function($scope,$attrs,$filter,tableConfig,tastyUtil){var listScopeToWatch,newScopeName,initStatus,updateClientSideResource,updateServerSideResource,setDirectivesValues,buildClientResource,buildUrl,paramsInitialCycle,initNow;this.$scope=$scope,initStatus={},initNow=!0,paramsInitialCycle=!0,$scope.init={},$scope.query={},$scope.logs={buildClientResourceCount:0},$scope.theme={},listScopeToWatch=["bindFilters","bindFiltersComparator","bindInit","bindQuery","bindResource","bindResourceCallback","bindWatchResource","bindReload","bindTheme"],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]&&"watchResource"===newScopeName?$scope[newScopeName]=$attrs[newScopeName]:$attrs[newScopeName]&&"filtersComparator"===newScopeName&&($scope[newScopeName]=JSON.parse($attrs[newScopeName]))}),this.config={},angular.isObject($scope.theme)?Object.keys(tableConfig).forEach(function(key){this.config[key]=$scope.theme[key]||tableConfig[key]},this):this.config=tableConfig,$scope.query.page=$scope.query.page||this.config.query.page,$scope.query.count=$scope.query.count||this.config.query.count,$scope.query.sortBy=$scope.query.sortBy||this.config.query.sortBy,$scope.query.sortOrder=$scope.query.sortOrder||this.config.query.sortOrder,$scope.reload&&!this.config.loadOnInit&&(initNow=!1),$scope.init.count=$scope.init.count||this.config.init.count,$scope.init.page=$scope.init.page||this.config.init.page,$scope.init.sortBy=$scope.init.sortBy||this.config.init.sortBy,$scope.init.sortOrder=$scope.init.sortOrder||this.config.init.sortOrder,$scope.watchResource=$scope.watchResource||this.config.watchResource;var listImmutableKey=["filters","init","query","rows","header","pagination","params","sortOrder","sortBy","url"];if($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 new Error("AngularJS tastyTable directive: need the bind-resource or bind-resource-callback attribute");if(angular.isDefined($attrs.bindResource)){if(!angular.isObject($scope.resource))throw new Error("AngularJS tastyTable directive: the bind-resource ("+$attrs.bindResource+") is not an object");if(!$scope.resource.header&&!$scope.resource.rows)throw new Error("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 new Error("AngularJS tastyTable directive: the bind-resource-callback ("+$attrs.bindResourceCallback+") is not a function");$scope.clientSide=!1}if(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),initNow&&$scope.$evalAsync(updateClientSideResource)):($scope.params.sortBy=$scope.init.sortBy,$scope.params.sortOrder=$scope.init.sortOrder,$scope.params.page=$scope.init.page,initNow?$scope.$evalAsync(updateServerSideResource):$scope.reload&&($scope.url=buildUrl($scope.params,$scope.filters),$scope.reload=function(){$scope.resourceCallback($scope.url,angular.copy($scope.params)).then(function(resource){setDirectivesValues(resource)})})))},this.bindOnce=this.config.bindOnce,setDirectivesValues=function(resource){if(!angular.isObject(resource))throw new Error("AngularJS tastyTable directive: the resource response is not an object");if(!resource.header&&!resource.rows)throw new Error("AngularJS tastyTable directive: the resource response object has the property header or rows undefined");Object.keys(resource).forEach(function(key){listImmutableKey.indexOf(key)<0&&($scope[key]=resource[key])}),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.logs.buildClientResourceCount+=1,$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.filtersComparator)),$scope.paginationDirective&&($scope.pagination.count=$scope.params.count,$scope.pagination.size=$scope.rows.length,$scope.pagination.pages=Math.ceil($scope.rows.length/$scope.pagination.count),"filters"===updateFrom||$scope.pagination.page>$scope.pagination.pages?($scope.pagination.page=1,$scope.params.page=1):$scope.pagination.page=$scope.params.page,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){$scope.params.sortBy&&($scope.resource.sortBy=$scope.params.sortBy),$scope.params.sortOrder&&($scope.resource.sortOrder=$scope.params.sortOrder),$scope.params.page&&$scope.params.count&&($scope.resource.pagination=$scope.pagination,$scope.resource.pagination.page=$scope.params.page,$scope.resource.pagination.count=$scope.params.count),setDirectivesValues($scope.resource),buildClientResource(updateFrom)},updateServerSideResource=function(updateFrom){$scope.url=buildUrl($scope.params,$scope.filters),$scope.reload&&($scope.reload=function(){$scope.resourceCallback($scope.url,angular.copy($scope.params)).then(function(resource){setDirectivesValues(resource)})}),(!$scope.reload||$scope.reload&&"filters"!==updateFrom)&&$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("filters")))},!0),$scope.$watchCollection("params",function(newValue,oldValue){newValue!==oldValue&&(paramsInitialCycle===!1?$scope.clientSide?$scope.$evalAsync(updateClientSideResource("params")):$scope.$evalAsync(updateServerSideResource):paramsInitialCycle=!1)}),$scope.resource){var watchResource=function(newValue,oldValue){newValue!==oldValue&&($scope.params.sortBy=$scope.resource.sortBy||$scope.params.sortBy,$scope.params.sortOrder=$scope.resource.sortOrder||$scope.params.sortOrder,$scope.$evalAsync(updateClientSideResource("resource")),$scope.resource.reload||($scope.resource.reload=function(){$scope.$evalAsync(updateClientSideResource("resource"))}))};"reference"===$scope.watchResource?$scope.$watch("resource",watchResource):"collection"===$scope.watchResource?($scope.$watchCollection("resource.header",watchResource),$scope.$watchCollection("resource.rows",watchResource),$scope.$watchGroup(["resource.sortBy","resource.sortOrder","resource.pagination.count","resource.pagination.page","resource.pagination.pages","resource.pagination.size"],watchResource)):"equality"===$scope.watchResource&&($scope.$watch("resource.header",watchResource,!0),$scope.$watch("resource.rows",watchResource,!0),$scope.$watch("resource.sortBy",watchResource,!0),$scope.$watch("resource.sortOrder",watchResource,!0),$scope.$watch("resource.pagination.count",watchResource,!0),$scope.$watch("resource.pagination.page",watchResource,!0),$scope.$watch("resource.pagination.pages",watchResource,!0),$scope.$watch("resource.pagination.size",watchResource,!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","$templateCache","$http","$compile","tableConfig","tastyUtil",function($filter,$templateCache,$http,$compile,tableConfig,tastyUtil){return{restrict:"AE",require:"^tastyTable",scope:{},templateUrl:tableConfig.templateHeadUrl,link:function(scope,element,attrs,tastyTable){var newScopeName,listScopeToWatch;scope.bindOnce=tastyTable.bindOnce,scope.columns=[],scope.bootstrapIcon=tastyTable.config.bootstrapIcon,scope.iconUp=tastyTable.config.iconUp,scope.iconDown=tastyTable.config.iconDown,listScopeToWatch=["bindNotSortBy","bindBootstrapIcon","bindIconUp","bindIconDown","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]&&("["===attrs[newScopeName][0]?(attrs[newScopeName]=attrs[newScopeName].replace(/'/g,'"'),scope[newScopeName]=JSON.parse(attrs[newScopeName])):scope[newScopeName]=attrs[newScopeName])}),scope.templateUrl&&$http.get(scope.templateUrl,{cache:$templateCache}).success(function(templateContent){element.replaceWith($compile(templateContent)(scope))}),scope.setColumns=function(){var active,sortable,sort,isSorted,isSortedCaret;scope.columns=[],"dsc"===scope.header.sortOrder&&scope.header.sortBy&&"-"!==scope.header.sortBy[0]&&(scope.header.sortBy="-"+scope.header.sortBy),scope.header.columns.forEach(function(column){column.style=column.style||{},angular.isArray(column.class)||(column.class=[]),sortable=!0,active=!1,isSorted="",isSortedCaret="",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?tastyTable.config.bootstrapIcon?(isSorted="",isSortedCaret="caret"):isSorted=scope.iconDown:scope.header.sortBy===sort&&(tastyTable.config.bootstrapIcon?(isSorted="dropup",isSortedCaret="caret"):isSorted=scope.iconUp),scope.columns.push({key:column.key,name:column.name,active:active,sortable:sortable,"class":column.class,style:column.style,isSorted:isSorted,isSortedCaret:isSortedCaret})}),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"),column.class.forEach(function(className){listClassToShow.push(className)}),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:tableConfig.templateUrl,link:function(scope,element,attrs,tastyTable){var getPage,setCount,setPaginationRange,setPreviousRange,setRemainingRange,setPaginationRanges,listScopeToWatch,newScopeName;listScopeToWatch=["bindItemsPerPage","bindListItemsPerPage","bindTemplateUrl"],listScopeToWatch.forEach(function(scopeName){if(newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),attrs[scopeName])tastyUtil.bindTo(scopeName,scope,attrs,newScopeName);else if(attrs[newScopeName])if("itemsPerPage"===newScopeName)scope[newScopeName]=parseInt(attrs[newScopeName]);else try{scope[newScopeName]=JSON.parse(attrs[newScopeName])}catch(err){scope[newScopeName]=attrs[newScopeName]}}),scope.templateUrl&&$http.get(scope.templateUrl,{cache:$templateCache}).success(function(templateContent){element.replaceWith($compile(templateContent)(scope))}),scope.itemsPerPage=scope.itemsPerPage||tastyTable.config.itemsPerPage,scope.listItemsPerPage=scope.listItemsPerPage||tastyTable.config.listItemsPerPage,tastyTable.$scope.clientSide||(scope.itemsPerPage=tastyTable.$scope.init.count||scope.itemsPerPage),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+2);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.camelize",[]).filter("camelize",function(){var CAMELIZE_REGEX=/(?:^|[-_ ])(\w)/g;return function(input,first){var isString="string"==typeof input,firstLetter="undefined"==typeof first?!1:!!first;return"undefined"==typeof input||null===input||!isString&&isNaN(input)?"":isString?input.trim().replace(/ +(?= )/g,"").replace(CAMELIZE_REGEX,function(_,character,pos){return character&&(firstLetter||pos>0)?character.toUpperCase():character}):""+input}}),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.filter.slugify",[]).filter("slugify",function(){var makeString=function(object){return null==object?"":""+object},from="ąàáäâãåæăćčĉęèéëêĝĥìíïîĵłľńňòóöőôõðøśșšŝťțŭùúüűûñÿýçżźž",to="aaaaaaaaaccceeeeeghiiiijllnnoooooooossssttuuuuuunyyczzz",regex=new RegExp("["+from+"]","g");return function(str){return str=makeString(str).toString().toLowerCase().replace(regex,function(c){var index=from.indexOf(c);return to.charAt(index)||"-"}).replace(/[^\w\-\s]+/g,"").trim().replace(/\s+/g,"-").replace(/\-\-+/g,"-")}}),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?angular.equals:function(a,b){return a===b||a!==a&&b!==b},isolateScopeName=newScopeName?newScopeName:scopeName,parentSet=parentGet.assign||function(){throw lastValue=scope[scopeName]=parentGet(scopeName),"Expression "+attrs[attrName]+" is non-assignable!"},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,immediate){var args,context,debounceTimeout,timeout;return debounceTimeout=function(){timeout=null,immediate||func.apply(context,args)},function(){context=this,args=arguments;var callNow=immediate&&!timeout;$timeout.cancel(timeout),timeout=$timeout(debounceTimeout,wait),callNow&&func.apply(context,args)}}}]),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]&&(angular.isString(objTwo[attrname])?objTwo[attrname].length&&(objOne[attrname]=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.throttle","ngTasty.service.webSocket"]).factory("tastyUtil",["debounce","setProperty","joinObjects","bindTo","webSocket","throttle",function(debounce,setProperty,joinObjects,bindTo,webSocket,throttle){return{bindTo:bindTo,debounce:debounce,setProperty:setProperty,joinObjects:joinObjects,throttle:throttle,webSocket:webSocket}}]),angular.module("ngTasty.service.throttle",[]).factory("throttle",["$timeout",function($timeout){return function(fn,threshhold,scope){threshhold=threshhold||250;var last,promise;return function(){var context=scope||this,now=Date.now(),args=arguments;last&&last+threshhold>now?($timeout.cancel(promise),promise=$timeout(function(){last=now,fn.apply(context,args)},threshhold)):(last=now,fn.apply(context,args))}}}]),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();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.service.bindTo","ngTasty.service.debounce","ngTasty.service.joinObjects","ngTasty.service.setProperty","ngTasty.service.tastyUtil","ngTasty.service.throttle","ngTasty.service.webSocket","ngTasty.filter.camelize","ngTasty.filter.cleanFieldName","ngTasty.filter.filterInt","ngTasty.filter.range","ngTasty.filter.slugify"]),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"},bindOnce:!0,loadOnInit:!1,iconUp:"fa fa-sort-up",iconDown:"fa fa-sort-down",bootstrapIcon:!1,templateHeadUrl:"template/table/head.html",templateUrl:"template/table/pagination.html",listItemsPerPage:[5,25,50,100],itemsPerPage:5,watchResource:"reference"}).controller("TableController",["$scope","$attrs","$filter","tableConfig","tastyUtil",function($scope,$attrs,$filter,tableConfig,tastyUtil){var listScopeToWatch,newScopeName,initStatus,updateClientSideResource,updateServerSideResource,setDirectivesValues,buildClientResource,buildUrl,paramsInitialCycle,initNow;this.$scope=$scope,initStatus={},initNow=!0,paramsInitialCycle=!0,$scope.init={},$scope.query={},$scope.logs={buildClientResourceCount:0},$scope.theme={},listScopeToWatch=["bindFilters","bindFiltersComparator","bindInit","bindQuery","bindResource","bindResourceCallback","bindWatchResource","bindReload","bindTheme"],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]&&"watchResource"===newScopeName?$scope[newScopeName]=$attrs[newScopeName]:$attrs[newScopeName]&&"filtersComparator"===newScopeName&&($scope[newScopeName]=JSON.parse($attrs[newScopeName]))}),this.config={},angular.isObject($scope.theme)?Object.keys(tableConfig).forEach(function(key){this.config[key]=angular.isDefined($scope.theme[key])?$scope.theme[key]:tableConfig[key]},this):this.config=tableConfig,$scope.query.page=$scope.query.page||this.config.query.page,$scope.query.count=$scope.query.count||this.config.query.count,$scope.query.sortBy=$scope.query.sortBy||this.config.query.sortBy,$scope.query.sortOrder=$scope.query.sortOrder||this.config.query.sortOrder,$scope.reload&&!this.config.loadOnInit&&(initNow=!1),$scope.init.count=$scope.init.count||this.config.init.count,$scope.init.page=$scope.init.page||this.config.init.page,$scope.init.sortBy=$scope.init.sortBy||this.config.init.sortBy,$scope.init.sortOrder=$scope.init.sortOrder||this.config.init.sortOrder,$scope.watchResource=$scope.watchResource||this.config.watchResource;var listImmutableKey=["filters","init","query","rows","header","pagination","params","sortOrder","sortBy","url"];if($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 new Error("AngularJS tastyTable directive: need the bind-resource or bind-resource-callback attribute");if(angular.isDefined($attrs.bindResource)){if(!angular.isObject($scope.resource))throw new Error("AngularJS tastyTable directive: the bind-resource ("+$attrs.bindResource+") is not an object");if(!$scope.resource.header&&!$scope.resource.rows)throw new Error("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 new Error("AngularJS tastyTable directive: the bind-resource-callback ("+$attrs.bindResourceCallback+") is not a function");$scope.clientSide=!1}if(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),initNow&&$scope.$evalAsync(updateClientSideResource)):($scope.params.sortBy=$scope.init.sortBy,$scope.params.sortOrder=$scope.init.sortOrder,$scope.params.page=$scope.init.page,initNow?$scope.$evalAsync(updateServerSideResource):$scope.reload&&($scope.url=buildUrl($scope.params,$scope.filters),$scope.reload=function(){$scope.resourceCallback($scope.url,angular.copy($scope.params)).then(function(resource){setDirectivesValues(resource)})})))},this.bindOnce=this.config.bindOnce,setDirectivesValues=function(resource){if(!angular.isObject(resource))throw new Error("AngularJS tastyTable directive: the resource response is not an object");if(!resource.header&&!resource.rows)throw new Error("AngularJS tastyTable directive: the resource response object has the property header or rows undefined");Object.keys(resource).forEach(function(key){listImmutableKey.indexOf(key)<0&&($scope[key]=resource[key])}),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.logs.buildClientResourceCount+=1,$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.filtersComparator)),$scope.paginationDirective&&($scope.pagination.count=$scope.params.count,$scope.pagination.size=$scope.rows.length,$scope.pagination.pages=Math.ceil($scope.rows.length/$scope.pagination.count),"filters"===updateFrom||$scope.pagination.page>$scope.pagination.pages?($scope.pagination.page=1,$scope.params.page=1):$scope.pagination.page=$scope.params.page,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){$scope.params.sortBy&&($scope.resource.sortBy=$scope.params.sortBy),$scope.params.sortOrder&&($scope.resource.sortOrder=$scope.params.sortOrder),$scope.params.page&&$scope.params.count&&($scope.resource.pagination=$scope.pagination,$scope.resource.pagination.page=$scope.params.page,$scope.resource.pagination.count=$scope.params.count),setDirectivesValues($scope.resource),buildClientResource(updateFrom)},updateServerSideResource=function(updateFrom){$scope.url=buildUrl($scope.params,$scope.filters),$scope.reload&&($scope.reload=function(){$scope.resourceCallback($scope.url,angular.copy($scope.params)).then(function(resource){setDirectivesValues(resource)})}),(!$scope.reload||$scope.reload&&"filters"!==updateFrom)&&$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("filters")))},!0),$scope.$watchCollection("params",function(newValue,oldValue){newValue!==oldValue&&(paramsInitialCycle===!1?$scope.clientSide?$scope.$evalAsync(updateClientSideResource("params")):$scope.$evalAsync(updateServerSideResource):paramsInitialCycle=!1)}),$scope.resource){var watchResource=function(newValue,oldValue){newValue!==oldValue&&($scope.params.sortBy=$scope.resource.sortBy||$scope.params.sortBy,$scope.params.sortOrder=$scope.resource.sortOrder||$scope.params.sortOrder,$scope.$evalAsync(updateClientSideResource("resource")),$scope.resource.reload||($scope.resource.reload=function(){$scope.$evalAsync(updateClientSideResource("resource"))}))};"reference"===$scope.watchResource?$scope.$watch("resource",watchResource):"collection"===$scope.watchResource?($scope.$watchCollection("resource.header",watchResource),$scope.$watchCollection("resource.rows",watchResource),$scope.$watchGroup(["resource.sortBy","resource.sortOrder","resource.pagination.count","resource.pagination.page","resource.pagination.pages","resource.pagination.size"],watchResource)):"equality"===$scope.watchResource&&($scope.$watch("resource.header",watchResource,!0),$scope.$watch("resource.rows",watchResource,!0),$scope.$watch("resource.sortBy",watchResource,!0),$scope.$watch("resource.sortOrder",watchResource,!0),$scope.$watch("resource.pagination.count",watchResource,!0),$scope.$watch("resource.pagination.page",watchResource,!0),$scope.$watch("resource.pagination.pages",watchResource,!0),$scope.$watch("resource.pagination.size",watchResource,!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","$templateCache","$http","$compile","tableConfig","tastyUtil",function($filter,$templateCache,$http,$compile,tableConfig,tastyUtil){return{restrict:"AE",require:"^tastyTable",scope:{},templateUrl:tableConfig.templateHeadUrl,link:function(scope,element,attrs,tastyTable){var newScopeName,listScopeToWatch;scope.bindOnce=tastyTable.bindOnce,scope.columns=[],scope.bootstrapIcon=tastyTable.config.bootstrapIcon,scope.iconUp=tastyTable.config.iconUp,scope.iconDown=tastyTable.config.iconDown,listScopeToWatch=["bindNotSortBy","bindBootstrapIcon","bindIconUp","bindIconDown","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]&&("["===attrs[newScopeName][0]?(attrs[newScopeName]=attrs[newScopeName].replace(/'/g,'"'),scope[newScopeName]=JSON.parse(attrs[newScopeName])):scope[newScopeName]=attrs[newScopeName])}),scope.templateUrl&&$http.get(scope.templateUrl,{cache:$templateCache}).success(function(templateContent){element.replaceWith($compile(templateContent)(scope))}),scope.setColumns=function(){var active,sortable,sort,isSorted,isSortedCaret;scope.columns=[],"dsc"===scope.header.sortOrder&&scope.header.sortBy&&"-"!==scope.header.sortBy[0]&&(scope.header.sortBy="-"+scope.header.sortBy),scope.header.columns.forEach(function(column){column.style=column.style||{},angular.isArray(column.class)||(column.class=[]),sortable=!0,active=!1,isSorted="",isSortedCaret="",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?tastyTable.config.bootstrapIcon?(isSorted="",isSortedCaret="caret"):isSorted=scope.iconDown:scope.header.sortBy===sort&&(tastyTable.config.bootstrapIcon?(isSorted="dropup",isSortedCaret="caret"):isSorted=scope.iconUp),scope.columns.push({key:column.key,name:column.name,active:active,sortable:sortable,"class":column.class,style:column.style,isSorted:isSorted,isSortedCaret:isSortedCaret})}),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"),column.class.forEach(function(className){listClassToShow.push(className)}),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:tableConfig.templateUrl,link:function(scope,element,attrs,tastyTable){var getPage,setCount,setPaginationRange,setPreviousRange,setRemainingRange,setPaginationRanges,listScopeToWatch,newScopeName;listScopeToWatch=["bindItemsPerPage","bindListItemsPerPage","bindTemplateUrl"],listScopeToWatch.forEach(function(scopeName){if(newScopeName=scopeName.substring(4),newScopeName=newScopeName.charAt(0).toLowerCase()+newScopeName.slice(1),attrs[scopeName])tastyUtil.bindTo(scopeName,scope,attrs,newScopeName);else if(attrs[newScopeName])if("itemsPerPage"===newScopeName)scope[newScopeName]=parseInt(attrs[newScopeName]);else try{scope[newScopeName]=JSON.parse(attrs[newScopeName])}catch(err){scope[newScopeName]=attrs[newScopeName]}}),scope.templateUrl&&$http.get(scope.templateUrl,{cache:$templateCache}).success(function(templateContent){element.replaceWith($compile(templateContent)(scope))}),scope.itemsPerPage=scope.itemsPerPage||tastyTable.config.itemsPerPage,scope.listItemsPerPage=scope.listItemsPerPage||tastyTable.config.listItemsPerPage,tastyTable.$scope.clientSide||(scope.itemsPerPage=tastyTable.$scope.init.count||scope.itemsPerPage),scope.pagination={},scope.pagMinRange=1,scope.pagMaxRange=1,getPage=function(numPage){tastyTable.setParams("page",numPage)},setCount=function(count){var maxItems,page;scope.itemsPerPage=count,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-5,setPaginationRanges(),void 0)},setRemainingRange=function(){return scope.pagHideMaxRange===!0||scope.pagMaxRange>scope.pagination.pages?!1:(scope.pagMinRange=scope.pagMaxRange,scope.pagMaxRange=scope.pagMinRange+5,scope.pagMaxRange>=scope.pagination.pages&&(scope.pagMaxRange=scope.pagination.pages+1,scope.pagMinRange=scope.pagMaxRange-5+1),scope.pagMinRange=scope.pagMaxRange-5,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+2);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.camelize",[]).filter("camelize",function(){var CAMELIZE_REGEX=/(?:^|[-_ ])(\w)/g;return function(input,first){var isString="string"==typeof input,firstLetter="undefined"==typeof first?!1:!!first;return"undefined"==typeof input||null===input||!isString&&isNaN(input)?"":isString?input.trim().replace(/ +(?= )/g,"").replace(CAMELIZE_REGEX,function(_,character,pos){return character&&(firstLetter||pos>0)?character.toUpperCase():character}):""+input}}),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.filter.slugify",[]).filter("slugify",function(){var makeString=function(object){return null==object?"":""+object},from="ąàáäâãåæăćčĉęèéëêĝĥìíïîĵłľńňòóöőôõðøśșšŝťțŭùúüűûñÿýçżźž",to="aaaaaaaaaccceeeeeghiiiijllnnoooooooossssttuuuuuunyyczzz",regex=new RegExp("["+from+"]","g");return function(str){return str=makeString(str).toString().toLowerCase().replace(regex,function(c){var index=from.indexOf(c);return to.charAt(index)||"-"}).replace(/[^\w\-\s]+/g,"").trim().replace(/\s+/g,"-").replace(/\-\-+/g,"-")}}),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?angular.equals:function(a,b){return a===b||a!==a&&b!==b},isolateScopeName=newScopeName?newScopeName:scopeName,parentSet=parentGet.assign||function(){throw lastValue=scope[scopeName]=parentGet(scopeName),"Expression "+attrs[attrName]+" is non-assignable!"},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,immediate){var args,context,debounceTimeout,timeout;return debounceTimeout=function(){timeout=null,immediate||func.apply(context,args)},function(){context=this,args=arguments;var callNow=immediate&&!timeout;$timeout.cancel(timeout),timeout=$timeout(debounceTimeout,wait),callNow&&func.apply(context,args)}}}]),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]&&(angular.isString(objTwo[attrname])?objTwo[attrname].length&&(objOne[attrname]=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.throttle","ngTasty.service.webSocket"]).factory("tastyUtil",["debounce","setProperty","joinObjects","bindTo","webSocket","throttle",function(debounce,setProperty,joinObjects,bindTo,webSocket,throttle){return{bindTo:bindTo,debounce:debounce,setProperty:setProperty,joinObjects:joinObjects,throttle:throttle,webSocket:webSocket}}]),angular.module("ngTasty.service.throttle",[]).factory("throttle",["$timeout",function($timeout){return function(fn,threshhold,scope){threshhold=threshhold||250;var last,promise;return function(){var context=scope||this,now=Date.now(),args=arguments;last&&last+threshhold>now?($timeout.cancel(promise),promise=$timeout(function(){last=now,fn.apply(context,args)},threshhold)):(last=now,fn.apply(context,args))}}}]),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();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.5.4", | ||
"version": "0.5.5", | ||
"description": "A lightweight, flexible, and tasty collection of reusable UI components for AngularJS.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -85,3 +85,7 @@ /** | ||
Object.keys(tableConfig).forEach(function(key) { | ||
this.config[key] = $scope.theme[key] || tableConfig[key]; | ||
if (angular.isDefined($scope.theme[key])) { | ||
this.config[key] = $scope.theme[key]; | ||
} else { | ||
this.config[key] = tableConfig[key]; | ||
} | ||
}, this); | ||
@@ -691,2 +695,3 @@ } else { | ||
var maxItems, page; | ||
scope.itemsPerPage = count; | ||
maxItems = count * scope.pagination.page; | ||
@@ -717,3 +722,3 @@ if (maxItems > scope.pagination.size) { | ||
scope.pagMaxRange = scope.pagMinRange; | ||
scope.pagMinRange = scope.pagMaxRange - scope.itemsPerPage; | ||
scope.pagMinRange = scope.pagMaxRange - 5; | ||
setPaginationRanges(); | ||
@@ -723,11 +728,13 @@ }; | ||
setRemainingRange = function () { | ||
if (scope.pagHideMaxRange === true || scope.pagMaxRange > scope.pagination.pages) { | ||
if (scope.pagHideMaxRange === true || | ||
scope.pagMaxRange > scope.pagination.pages) { | ||
return false; | ||
} | ||
scope.pagMinRange = scope.pagMaxRange; | ||
scope.pagMaxRange = scope.pagMinRange + scope.itemsPerPage; | ||
if (scope.pagMaxRange > scope.pagination.pages) { | ||
scope.pagMaxRange = scope.pagination.pages; | ||
scope.pagMaxRange = scope.pagMinRange + 5; | ||
if (scope.pagMaxRange >= scope.pagination.pages) { | ||
scope.pagMaxRange = scope.pagination.pages + 1; | ||
scope.pagMinRange = scope.pagMaxRange - 5 + 1; | ||
} | ||
scope.pagMinRange = scope.pagMaxRange - scope.itemsPerPage; | ||
scope.pagMinRange = scope.pagMaxRange - 5; | ||
setPaginationRanges(); | ||
@@ -744,3 +751,3 @@ }; | ||
scope.pagHideMinRange = scope.pagMinRange <= 1; | ||
scope.pagHideMaxRange = scope.pagMaxRange >= scope.pagination.pages; | ||
scope.pagHideMaxRange = scope.pagMaxRange > scope.pagination.pages; | ||
scope.classPageMinRange = scope.pagHideMinRange ? 'disabled' : ''; | ||
@@ -755,3 +762,2 @@ scope.classPageMaxRange = scope.pagHideMaxRange ? 'disabled' : ''; | ||
} | ||
scope.rangePage = $filter('range')([], scope.pagMinRange, scope.pagMaxRange); | ||
@@ -758,0 +764,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
180103
3711