summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThai Tran <tqtran@us.ibm.com>2015-01-07 12:41:25 -0800
committerThai Tran <tqtran@us.ibm.com>2015-01-07 12:41:25 -0800
commite0fbf69fb156b995547471d71c5c6a7f88989d47 (patch)
tree4d4b0c1a1ba79332a215075ec61ce79e678f4967
downloadxstatic-angular-smart-table-e0fbf69fb156b995547471d71c5c6a7f88989d47.tar.gz
Adding Richard's zip files to this repo.
-rw-r--r--MANIFEST.in7
-rw-r--r--PKG-INFO25
-rw-r--r--README.txt14
-rw-r--r--setup.py27
-rw-r--r--xstatic/__init__.py1
-rw-r--r--xstatic/pkg/__init__.py1
-rw-r--r--xstatic/pkg/angular_smart_table/__init__.py57
-rw-r--r--xstatic/pkg/angular_smart_table/data/smart-table.js422
8 files changed, 554 insertions, 0 deletions
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..c507fb4
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,7 @@
+include README.txt
+recursive-include xstatic/pkg/angular_smart_table *
+
+global-exclude *.pyc
+global-exclude *.pyo
+global-exclude *.orig
+global-exclude *.rej
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..53e78b9
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,25 @@
+Metadata-Version: 1.0
+Name: XStatic-smart-table
+Version: 1.4.5.3
+Summary: smart-table 1.4.5 (XStatic packaging standard)
+Home-page: https://github.com/lorenzofox3/Smart-Table
+Author: Richard Jones
+Author-email: r1chardj0n3s@gmail.com
+License: (same as smart-table)
+Description:
+ XStatic-smart-table
+ -------------------
+
+ smart-table javascript library packaged for setuptools (easy_install) / pip.
+
+ This package is intended to be used by **any** project that needs these files.
+
+ It intentionally does **not** provide any extra code except some metadata
+ **nor** has any extra requirements. You MAY use some minimal support code from
+ the XStatic base package, if you like.
+
+ You can find more info about the xstatic packaging way in the package
+ `XStatic`.
+
+Keywords: smart-table angular table angular_smart_table xstatic
+Platform: any
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..c452edd
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,14 @@
+
+XStatic-smart-table
+-------------------
+
+smart-table javascript library packaged for setuptools (easy_install) / pip.
+
+This package is intended to be used by **any** project that needs these files.
+
+It intentionally does **not** provide any extra code except some metadata
+**nor** has any extra requirements. You MAY use some minimal support code from
+the XStatic base package, if you like.
+
+You can find more info about the xstatic packaging way in the package
+`XStatic`.
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..d7ecd21
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,27 @@
+
+from xstatic.pkg import angular_smart_table as xs
+
+# The README.txt file should be written in reST so that PyPI can use
+# it to generate your project's PyPI page.
+long_description = open('README.txt').read()
+
+from setuptools import setup, find_packages
+
+setup(
+ name=xs.PACKAGE_NAME,
+ version=xs.PACKAGE_VERSION,
+ description=xs.DESCRIPTION,
+ long_description=long_description,
+ classifiers=xs.CLASSIFIERS,
+ keywords=xs.KEYWORDS,
+ maintainer=xs.MAINTAINER,
+ maintainer_email=xs.MAINTAINER_EMAIL,
+ license=xs.LICENSE,
+ url=xs.HOMEPAGE,
+ platforms=xs.PLATFORMS,
+ packages=find_packages(),
+ namespace_packages=['xstatic', 'xstatic.pkg', ],
+ include_package_data=True,
+ zip_safe=False,
+ install_requires=[],
+)
diff --git a/xstatic/__init__.py b/xstatic/__init__.py
new file mode 100644
index 0000000..de40ea7
--- /dev/null
+++ b/xstatic/__init__.py
@@ -0,0 +1 @@
+__import__('pkg_resources').declare_namespace(__name__)
diff --git a/xstatic/pkg/__init__.py b/xstatic/pkg/__init__.py
new file mode 100644
index 0000000..de40ea7
--- /dev/null
+++ b/xstatic/pkg/__init__.py
@@ -0,0 +1 @@
+__import__('pkg_resources').declare_namespace(__name__)
diff --git a/xstatic/pkg/angular_smart_table/__init__.py b/xstatic/pkg/angular_smart_table/__init__.py
new file mode 100644
index 0000000..32aec65
--- /dev/null
+++ b/xstatic/pkg/angular_smart_table/__init__.py
@@ -0,0 +1,57 @@
+
+"""
+XStatic resource package
+
+See package 'XStatic' for documentation and basic tools.
+"""
+
+# official name, upper/lowercase allowed, no spaces
+DISPLAY_NAME = 'smart-table'
+
+# name used for PyPi
+PACKAGE_NAME = 'XStatic-%s' % DISPLAY_NAME
+
+NAME = __name__.split('.')[-1] # package name (e.g. 'foo' or 'foo_bar')
+ # please use a all-lowercase valid python
+ # package name
+
+VERSION = '1.4.5' # version of the packaged files, please use the upstream
+ # version number
+BUILD = '3' # our package build number, so we can release new builds
+ # with fixes for xstatic stuff.
+PACKAGE_VERSION = VERSION + '.' + BUILD # version used for PyPi
+
+DESCRIPTION = "%s %s (XStatic packaging standard)" % (DISPLAY_NAME, VERSION)
+
+PLATFORMS = 'any'
+CLASSIFIERS = []
+KEYWORDS = 'smart-table angular table angular_smart_table xstatic'
+
+# XStatic-* package maintainer:
+MAINTAINER = 'Richard Jones'
+MAINTAINER_EMAIL = 'r1chardj0n3s@gmail.com'
+
+# this refers to the project homepage of the stuff we packaged:
+HOMEPAGE = 'https://github.com/lorenzofox3/Smart-Table'
+
+# this refers to all files:
+LICENSE = '(same as %s)' % DISPLAY_NAME
+
+from os.path import join, dirname
+BASE_DIR = join(dirname(__file__), 'data')
+# linux package maintainers just can point to their file locations like this:
+#BASE_DIR = '/usr/share/javascript/' + NAME
+
+# location of the Javascript file that's the entry point for this package, if
+# one exists, relative to BASE_DIR
+MAIN='smart-table.min.js'
+
+LOCATIONS = {
+ # CDN locations (if no public CDN exists, use an empty dict)
+ # if value is a string, it is a base location, just append relative
+ # path/filename. if value is a dict, do another lookup using the
+ # relative path/filename you want.
+ # your relative path/filenames should usually be without version
+ # information, because either the base dir/url is exactly for this
+ # version or the mapping will care for accessing this version.
+}
diff --git a/xstatic/pkg/angular_smart_table/data/smart-table.js b/xstatic/pkg/angular_smart_table/data/smart-table.js
new file mode 100644
index 0000000..d5cd473
--- /dev/null
+++ b/xstatic/pkg/angular_smart_table/data/smart-table.js
@@ -0,0 +1,422 @@
+/**
+* @version 1.4.5
+* @license MIT
+*/
+(function (ng, undefined){
+ 'use strict';
+
+ng.module('smart-table', []).run(['$templateCache', function ($templateCache) {
+ $templateCache.put('template/smart-table/pagination.html',
+ '<div class="pagination" ng-if="pages.length >= 2"><ul class="pagination">' +
+ '<li ng-repeat="page in pages" ng-class="{active: page==currentPage}"><a ng-click="selectPage(page)">{{page}}</a></li>' +
+ '</ul></div>');
+}]);
+
+
+ng.module('smart-table')
+ .controller('stTableController', ['$scope', '$parse', '$filter', '$attrs', function StTableController($scope, $parse, $filter, $attrs) {
+ var propertyName = $attrs.stTable;
+ var displayGetter = $parse(propertyName);
+ var displaySetter = displayGetter.assign;
+ var safeGetter;
+ var orderBy = $filter('orderBy');
+ var filter = $filter('filter');
+ var safeCopy = copyRefs(displayGetter($scope));
+ var tableState = {
+ sort: {},
+ search: {},
+ pagination: {
+ start: 0
+ }
+ };
+ var pipeAfterSafeCopy = true;
+ var ctrl = this;
+ var lastSelected;
+
+ function copyRefs(src) {
+ return [].concat(src);
+ }
+
+ function updateSafeCopy() {
+ safeCopy = copyRefs(safeGetter($scope));
+ if (pipeAfterSafeCopy === true) {
+ ctrl.pipe();
+ }
+ }
+
+ if ($attrs.stSafeSrc) {
+ safeGetter = $parse($attrs.stSafeSrc);
+ $scope.$watch(function () {
+ var safeSrc = safeGetter($scope);
+ return safeSrc ? safeSrc.length : 0;
+
+ }, function (newValue, oldValue) {
+ if (newValue !== safeCopy.length) {
+ updateSafeCopy();
+ }
+ });
+ $scope.$watch(function () {
+ return safeGetter($scope);
+ }, function (newValue, oldValue) {
+ if (newValue !== oldValue) {
+ updateSafeCopy();
+ }
+ });
+ }
+
+ /**
+ * sort the rows
+ * @param {Function | String} predicate - function or string which will be used as predicate for the sorting
+ * @param [reverse] - if you want to reverse the order
+ */
+ this.sortBy = function sortBy(predicate, reverse) {
+ tableState.sort.predicate = predicate;
+ tableState.sort.reverse = reverse === true;
+ tableState.pagination.start = 0;
+ return this.pipe();
+ };
+
+ /**
+ * search matching rows
+ * @param {String} input - the input string
+ * @param {String} [predicate] - the property name against you want to check the match, otherwise it will search on all properties
+ */
+ this.search = function search(input, predicate) {
+ var predicateObject = tableState.search.predicateObject || {};
+ var prop = predicate ? predicate : '$';
+ predicateObject[prop] = input;
+ // to avoid to filter out null value
+ if (!input) {
+ delete predicateObject[prop];
+ }
+ tableState.search.predicateObject = predicateObject;
+ tableState.pagination.start = 0;
+ return this.pipe();
+ };
+
+ /**
+ * this will chain the operations of sorting and filtering based on the current table state (sort options, filtering, ect)
+ */
+ this.pipe = function pipe() {
+ var pagination = tableState.pagination;
+ var filtered = tableState.search.predicateObject ? filter(safeCopy, tableState.search.predicateObject) : safeCopy;
+ if (tableState.sort.predicate) {
+ filtered = orderBy(filtered, tableState.sort.predicate, tableState.sort.reverse);
+ }
+ if (pagination.number !== undefined) {
+ pagination.numberOfPages = filtered.length > 0 ? Math.ceil(filtered.length / pagination.number) : 1;
+ pagination.start = pagination.start >= filtered.length ? (pagination.numberOfPages - 1) * pagination.number : pagination.start;
+ filtered = filtered.slice(pagination.start, pagination.start + pagination.number);
+ }
+ displaySetter($scope, filtered);
+ };
+
+ /**
+ * select a dataRow (it will add the attribute isSelected to the row object)
+ * @param {Object} row - the row to select
+ * @param {String} [mode] - "single" or "multiple" (multiple by default)
+ */
+ this.select = function select(row, mode) {
+ var rows = safeCopy;
+ var index = rows.indexOf(row);
+ if (index !== -1) {
+ if (mode === 'single') {
+ row.isSelected = row.isSelected !== true;
+ if (lastSelected) {
+ lastSelected.isSelected = false;
+ }
+ lastSelected = row.isSelected === true ? row : undefined;
+ } else {
+ rows[index].isSelected = !rows[index].isSelected;
+ }
+ }
+ };
+
+ /**
+ * take a slice of the current sorted/filtered collection (pagination)
+ *
+ * @param {Number} start - start index of the slice
+ * @param {Number} number - the number of item in the slice
+ */
+ this.slice = function splice(start, number) {
+ tableState.pagination.start = start;
+ tableState.pagination.number = number;
+ return this.pipe();
+ };
+
+ /**
+ * return the current state of the table
+ * @returns {{sort: {}, search: {}, pagination: {start: number}}}
+ */
+ this.tableState = function getTableState() {
+ return tableState;
+ };
+
+ /**
+ * Use a different filter function than the angular FilterFilter
+ * @param filterName the name under which the custom filter is registered
+ */
+ this.setFilterFunction = function setFilterFunction(filterName) {
+ filter = $filter(filterName);
+ };
+
+ /**
+ *User a different function than the angular orderBy
+ * @param sortFunctionName the name under which the custom order function is registered
+ */
+ this.setSortFunction = function setSortFunction(sortFunctionName) {
+ orderBy = $filter(sortFunctionName);
+ };
+
+ /**
+ * Usually when the safe copy is updated the pipe function is called.
+ * Calling this method will prevent it, which is something required when using a custom pipe function
+ */
+ this.preventPipeOnWatch = function preventPipe() {
+ pipeAfterSafeCopy = false;
+ };
+ }])
+ .directive('stTable', function () {
+ return {
+ restrict: 'A',
+ controller: 'stTableController',
+ link: function (scope, element, attr, ctrl) {
+
+ if (attr.stSetFilter) {
+ ctrl.setFilterFunction(attr.stSetFilter);
+ }
+
+ if (attr.stSetSort) {
+ ctrl.setSortFunction(attr.stSetSort);
+ }
+ }
+ };
+ });
+
+ng.module('smart-table')
+ .directive('stSearch', ['$timeout', function ($timeout) {
+ return {
+ require: '^stTable',
+ scope: {
+ predicate: '=?stSearch'
+ },
+ link: function (scope, element, attr, ctrl) {
+ var tableCtrl = ctrl;
+ var promise = null;
+ var throttle = attr.stDelay || 400;
+
+ scope.$watch('predicate', function (newValue, oldValue) {
+ if (newValue !== oldValue) {
+ ctrl.tableState().search = {};
+ tableCtrl.search(element[0].value || '', newValue);
+ }
+ });
+
+ //table state -> view
+ scope.$watch(function () {
+ return ctrl.tableState().search;
+ }, function (newValue, oldValue) {
+ var predicateExpression = scope.predicate || '$';
+ if (newValue.predicateObject && newValue.predicateObject[predicateExpression] !== element[0].value) {
+ element[0].value = newValue.predicateObject[predicateExpression] || '';
+ }
+ }, true);
+
+ // view -> table state
+ element.bind('input', function (evt) {
+ evt = evt.originalEvent || evt;
+ if (promise !== null) {
+ $timeout.cancel(promise);
+ }
+ promise = $timeout(function () {
+ tableCtrl.search(evt.target.value, scope.predicate || '');
+ promise = null;
+ }, throttle);
+ });
+ }
+ };
+ }]);
+
+ng.module('smart-table')
+ .directive('stSelectRow', function () {
+ return {
+ restrict: 'A',
+ require: '^stTable',
+ scope: {
+ row: '=stSelectRow'
+ },
+ link: function (scope, element, attr, ctrl) {
+ var mode = attr.stSelectMode || 'single';
+ element.bind('click', function () {
+ scope.$apply(function () {
+ ctrl.select(scope.row, mode);
+ });
+ });
+
+ scope.$watch('row.isSelected', function (newValue, oldValue) {
+ if (newValue === true) {
+ element.addClass('st-selected');
+ } else {
+ element.removeClass('st-selected');
+ }
+ });
+ }
+ };
+ });
+
+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);
+ }
+ }
+
+ if (ng.isFunction(getter(scope))) {
+ predicate = getter(scope);
+ }
+
+ element.bind('click', function sortClick() {
+ if (predicate) {
+ scope.$apply(sort);
+ }
+ });
+
+ 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 () {
+ return {
+ restrict: 'EA',
+ require: '^stTable',
+ scope: {
+ stItemsByPage: '=?',
+ stDisplayedPages: '=?'
+ },
+ templateUrl: function(element, attrs) {
+ if (attrs.stTemplate) {
+ return attrs.stTemplate;
+ }
+ return 'template/smart-table/pagination.html';
+ },
+ link: function (scope, element, attrs, ctrl) {
+
+ scope.stItemsByPage = scope.stItemsByPage ? +(scope.stItemsByPage) : 10;
+ scope.stDisplayedPages = scope.stDisplayedPages ? +(scope.stDisplayedPages) : 5;
+
+ scope.currentPage = 1;
+ scope.pages = [];
+
+ function redraw() {
+ var paginationState = ctrl.tableState().pagination;
+ var start = 1;
+ var end;
+ var i;
+ scope.currentPage = Math.floor(paginationState.start / paginationState.number) + 1;
+
+ start = Math.max(start, scope.currentPage - Math.abs(Math.floor(scope.stDisplayedPages / 2)));
+ end = start + scope.stDisplayedPages;
+
+ if (end > paginationState.numberOfPages) {
+ end = paginationState.numberOfPages + 1;
+ start = Math.max(1, end - scope.stDisplayedPages);
+ }
+
+ scope.pages = [];
+ scope.numPages = paginationState.numberOfPages;
+
+ for (i = start; i < end; i++) {
+ scope.pages.push(i);
+ }
+ }
+
+ //table state --> view
+ scope.$watch(function () {
+ return ctrl.tableState().pagination;
+ }, redraw, true);
+
+ //scope --> table state (--> view)
+ scope.$watch('stItemsByPage', function () {
+ scope.selectPage(1);
+ });
+
+ scope.$watch('stDisplayedPages', redraw);
+
+ //view -> table state
+ scope.selectPage = function (page) {
+ if (page > 0 && page <= scope.numPages) {
+ ctrl.slice((page - 1) * scope.stItemsByPage, scope.stItemsByPage);
+ }
+ };
+
+ //select the first page
+ ctrl.slice(0, scope.stItemsByPage);
+ }
+ };
+ });
+
+ng.module('smart-table')
+ .directive('stPipe', function () {
+ return {
+ require: 'stTable',
+ scope: {
+ stPipe: '='
+ },
+ link: {
+ pre: function (scope, element, attrs, ctrl) {
+
+ if (ng.isFunction(scope.stPipe)) {
+ ctrl.preventPipeOnWatch();
+ ctrl.pipe = function () {
+ return scope.stPipe(ctrl.tableState(), ctrl);
+ }
+ }
+ }
+ }
+ };
+ });
+
+})(angular); \ No newline at end of file