Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzofox3 committed Oct 28, 2014
1 parent 13da8c9 commit d63eadf
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 139 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smart-table",
"version": "1.4.1",
"version": "1.4.2",
"homepage": "https://github.com/lorenzofox3/Smart-Table",
"authors": [
"lorenzofox3 <[email protected]>"
Expand Down
11 changes: 10 additions & 1 deletion changeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,13 @@ Note that if you want to search against a property name you have now to put in u

## version 1.4.1

* ability to skip natural ordering state (ie fix #192)
* ability to skip natural ordering state (ie fix #192)

## versiokn 1.4.2

* fix #200, `this` in a custom pipe function does not refer to the table controller anymore, and the signature of a custom pipe function is
```javascript
function(tableState, tableController){

}
```
114 changes: 58 additions & 56 deletions dist/smart-table.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,68 +252,68 @@ ng.module('smart-table')
};
});

ng.module('smart-table')
.directive('stSort', ['$parse', function ($parse) {
return {
restrict: 'A',
require: '^stTable',
link: function (scope, element, attr, ctrl) {

var predicate = attr.stSort;
var getter = $parse(predicate);
var index = 0;
var classAscent = attr.stClassAscent || 'st-sort-ascent';
var classDescent = attr.stClassDescent || 'st-sort-descent';
var stateClasses = [classAscent, classDescent];

//view --> table state
function sort() {
index++;
if (index % 3 === 0 && attr.stSkipNatural === undefined) {
//manual reset
index = 0;
ctrl.tableState().sort = {};
ctrl.tableState().pagination.start = 0;
ctrl.pipe();
} else {
ctrl.sortBy(predicate, index % 2 === 0);
}
}
ng.module('smart-table')
.directive('stSort', ['$parse', function ($parse) {
return {
restrict: 'A',
require: '^stTable',
link: function (scope, element, attr, ctrl) {

if (ng.isFunction(getter(scope))) {
predicate = getter(scope);
var predicate = attr.stSort;
var getter = $parse(predicate);
var index = 0;
var classAscent = attr.stClassAscent || 'st-sort-ascent';
var classDescent = attr.stClassDescent || 'st-sort-descent';
var stateClasses = [classAscent, classDescent];

//view --> table state
function sort() {
index++;
if (index % 3 === 0 && attr.stSkipNatural === undefined) {
//manual reset
index = 0;
ctrl.tableState().sort = {};
ctrl.tableState().pagination.start = 0;
ctrl.pipe();
} else {
ctrl.sortBy(predicate, index % 2 === 0);
}
}

element.bind('click', function sortClick() {
if (predicate) {
scope.$apply(sort);
}
});
if (ng.isFunction(getter(scope))) {
predicate = getter(scope);
}

if (attr.stSortDefault !== undefined) {
index = attr.stSortDefault === 'reverse' ? 1 : 0;
sort();
element.bind('click', function sortClick() {
if (predicate) {
scope.$apply(sort);
}
});

//table state --> view
scope.$watch(function () {
return ctrl.tableState().sort;
}, function (newValue) {
if (newValue.predicate !== predicate) {
index = 0;
element
.removeClass(classAscent)
.removeClass(classDescent);
} else {
index = newValue.reverse === true ? 2 : 1;
element
.removeClass(stateClasses[index % 2])
.addClass(stateClasses[index - 1]);
}
}, true);
if (attr.stSortDefault !== undefined) {
index = attr.stSortDefault === 'reverse' ? 1 : 0;
sort();
}
};
}]);

//table state --> view
scope.$watch(function () {
return ctrl.tableState().sort;
}, function (newValue) {
if (newValue.predicate !== predicate) {
index = 0;
element
.removeClass(classAscent)
.removeClass(classDescent);
} else {
index = newValue.reverse === true ? 2 : 1;
element
.removeClass(stateClasses[index % 2])
.addClass(stateClasses[index - 1]);
}
}, true);
}
};
}]);

ng.module('smart-table')
.directive('stPagination', function () {
Expand Down Expand Up @@ -393,7 +393,9 @@ ng.module('smart-table')

if (ng.isFunction(scope.stPipe)) {
ctrl.preventPipeOnWatch();
ctrl.pipe = ng.bind(ctrl, scope.stPipe, ctrl.tableState());
ctrl.pipe = function () {
scope.stPipe(ctrl.tableState(), ctrl);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/smart-table.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"name": "smart-table",
"version": "1.4.1",
"description": "",
"main": "dist/smart-table.debug.js",
"scripts": {
"test": "node ./node_modules/.bin/gulp karma-CI"
},
"author": "",
"license": "ISC",
"devDependencies": {
"gulp": "^3.8.7",
"gulp-concat": "^2.3.4",
"gulp-jshint": "^1.8.4",
"gulp-uglify": "^0.3.1",
"jshint-stylish": "^0.4.0",
"karma": "^0.12.21",
"karma-chrome-launcher": "^0.1.4",
"karma-coverage": "^0.2.6",
"karma-jasmine": "^0.1.5",
"karma-phantomjs-launcher": "^0.1.4"
}
"name": "smart-table",
"version": "1.4.2",
"description": "",
"main": "dist/smart-table.debug.js",
"scripts": {
"test": "node ./node_modules/.bin/gulp karma-CI"
},
"author": "",
"license": "ISC",
"devDependencies": {
"gulp": "^3.8.7",
"gulp-concat": "^2.3.4",
"gulp-jshint": "^1.8.4",
"gulp-uglify": "^0.3.1",
"jshint-stylish": "^0.4.0",
"karma": "^0.12.21",
"karma-chrome-launcher": "^0.1.4",
"karma-coverage": "^0.2.6",
"karma-jasmine": "^0.1.5",
"karma-phantomjs-launcher": "^0.1.4"
}
}
4 changes: 3 additions & 1 deletion src/stPipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ ng.module('smart-table')

if (ng.isFunction(scope.stPipe)) {
ctrl.preventPipeOnWatch();
ctrl.pipe = ng.bind(ctrl, scope.stPipe, ctrl.tableState());
ctrl.pipe = function () {
scope.stPipe(ctrl.tableState(), ctrl);
}
}
}
}
Expand Down
Loading

0 comments on commit d63eadf

Please sign in to comment.