diff --git a/README.md b/README.md index 388cd13..9e44bcf 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ http://www.google.com/design/spec/components/data-tables.html - virtual-repeat - delete-row-callback - selected-row-callback + - clicked-row-callback - animate-sort-icon - ripple-effect - ! title-overflow-handler @@ -89,6 +90,7 @@ http://www.google.com/design/spec/components/data-tables.html |:white_check_mark:| virtual-repeat | Boolean | optional, when set, virtual scrolling will be applied to the table. You must set a fixed height to the `.md-virtual-repeat-container` class in order to make it work properly. Since virtual scrolling is working with fixed height. | |:white_check_mark:| delete-row-callback | Function | optional, callback function when deleting rows. The callback will be called with the array of the deleted row ids. Don't forget to specify `table-row-id` for `mdt-row`. If you do, it will return the deleted rows data. | |:white_check_mark:| selected-row-callback | Function | optional, callback function when selecting rows. The callback will be called with the array of the selected row ids. Don't forget to specify `table-row-id` for `mdt-row`. If you do, it will return the selected rows data. | +|:white_check_mark:| clicked-row-callback | Function | optional, callback function when clicked rows. The callback will be called when the row is clicked. Don't forget to specify `table-row-id` for `mdt-row`. | ![alt tag](http://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B3mOPoJlxiFhcWNyQl9xYmRkQnc/components_datatables_interaction_selectedrow.png) | Available | Params | Type | Details | @@ -358,4 +360,4 @@ There is only one scope variable that you can use in your template, and it's cal -``` +``` \ No newline at end of file diff --git a/app/modules/main/directives/mdtTableDirective.js b/app/modules/main/directives/mdtTableDirective.js index 64c0857..e43033f 100644 --- a/app/modules/main/directives/mdtTableDirective.js +++ b/app/modules/main/directives/mdtTableDirective.js @@ -1,4 +1,4 @@ -(function(){ +(function () { 'use strict'; /** @@ -116,9 +116,10 @@ function mdtTableDirective(TableDataStorageFactory, EditCellFeature, SelectableRowsFeature, + ClickableRowsFeature, PaginationFeature, ColumnSelectorFeature, - _){ + _) { return { restrict: 'E', templateUrl: '/main/templates/mdtTable.html', @@ -128,24 +129,24 @@ selectableRows: '=', alternateHeaders: '=', deleteRowCallback: '&', - selectedRowCallback: '&', + clickedRowCallback: '&', saveRowCallback: '&', animateSortIcon: '=', rippleEffect: '=', paginatedRows: '=', mdtRow: '=', mdtRowPaginator: '&?', - mdtRowPaginatorErrorMessage:'@', - mdtRowPaginatorNoResultsMessage:'@', + mdtRowPaginatorErrorMessage: '@', + mdtRowPaginatorNoResultsMessage: '@', virtualRepeat: '=', mdtTriggerRequest: '&?', mdtTranslations: '=?', mdtLoadingIndicator: '=?' }, - controller: function mdtTable($scope){ + controller: function mdtTable($scope) { var vm = this; - $scope.rippleEffectCallback = function(){ + $scope.rippleEffectCallback = function () { return $scope.rippleEffect ? $scope.rippleEffect : false; }; @@ -158,12 +159,12 @@ _processData(); // initialization of the storage service - function _initTableStorage(){ + function _initTableStorage() { vm.dataStorage = TableDataStorageFactory.getInstance(); } // set translations or fallback to a default value - function _setDefaultTranslations(){ + function _setDefaultTranslations() { $scope.mdtTranslations = $scope.mdtTranslations || {}; $scope.mdtTranslations.rowsPerPage = $scope.mdtTranslations.rowsPerPage || 'Rows per page:'; @@ -174,8 +175,8 @@ } // fill storage with values if set - function _processData(){ - if(_.isEmpty($scope.mdtRow)) { + function _processData() { + if (_.isEmpty($scope.mdtRow)) { return; } @@ -186,19 +187,19 @@ _addRawDataToStorage(mdtRow['data']); }, true); - }else{ + } else { //if it's used for 'Ajax pagination' } } - function _addRawDataToStorage(data){ + function _addRawDataToStorage(data) { var rowId; var columnValues = []; - _.each(data, function(row){ + _.each(data, function (row) { rowId = _.get(row, $scope.mdtRow['table-row-id-key']); columnValues = []; - _.each($scope.mdtRow['column-keys'], function(columnKey){ + _.each($scope.mdtRow['column-keys'], function (columnKey) { columnValues.push({ attributes: { editableField: false @@ -213,18 +214,19 @@ }); } }, - link: function($scope, element, attrs, ctrl, transclude){ + link: function ($scope, element, attrs, ctrl, transclude) { $scope.dataStorage = ctrl.dataStorage; _injectContentIntoTemplate(); _initEditCellFeature(); _initSelectableRowsFeature(); + _initClickableRowsFeature(); PaginationFeature.startFeature(ctrl); ColumnSelectorFeature.initFeatureHeaderValues($scope.dataStorage.header, ctrl.columnSelectorFeature); - function _injectContentIntoTemplate(){ + function _injectContentIntoTemplate() { transclude(function (clone) { var headings = []; var body = []; @@ -233,11 +235,11 @@ // Use plain JS to append content _.each(clone, function (child) { - if ( child.classList !== undefined ) { - if ( child.classList.contains('theadTrRow')) { + if (child.classList !== undefined) { + if (child.classList.contains('theadTrRow')) { headings.push(child); } - else if( child.classList.contains('customCell') ) { + else if (child.classList.contains('customCell')) { customCell.push(child); } else { @@ -251,16 +253,16 @@ var reader = element[0].querySelector('.mdtTable-reader'); _.each(headings, function (heading) { - reader.appendChild( heading ); + reader.appendChild(heading); }); _.each(body, function (item) { - reader.appendChild( item ); + reader.appendChild(item); }); }); } - function _initEditCellFeature(){ + function _initEditCellFeature() { //TODO: make it possible to only register feature if there is at least // one column which requires it. // for that we need to change the place where we register edit-row. @@ -268,12 +270,18 @@ EditCellFeature.addRequiredFunctions($scope, ctrl); } - function _initSelectableRowsFeature(){ + function _initSelectableRowsFeature() { SelectableRowsFeature.getInstance({ $scope: $scope, ctrl: ctrl }); } + function _initClickableRowsFeature() { + ClickableRowsFeature.getInstance({ + $scope: $scope, + ctrl: ctrl + }); + } } }; } @@ -281,4 +289,4 @@ angular .module('mdDataTable') .directive('mdtTable', mdtTableDirective); -}()); +}()); \ No newline at end of file diff --git a/app/modules/main/features/ClickableRowsFeature.js b/app/modules/main/features/ClickableRowsFeature.js new file mode 100644 index 0000000..e47e16a --- /dev/null +++ b/app/modules/main/features/ClickableRowsFeature.js @@ -0,0 +1,32 @@ +(function () { + 'use strict'; + + function ClickableRowsFeatureFactory($timeout) { + + function ClickableRowsFeature(params) { + this.$scope = params.$scope; + this.ctrl = params.ctrl; + + this.$scope.rowClickCallBackHandler = _.bind(this.rowClickCallBackHandler, this); + } + + ClickableRowsFeature.prototype.rowClickCallBackHandler = function (event, row) { + var that = this; + // we need to push it to the event loop to make it happen last + // (e.g.: all the elements can be selected before we call the callback) + $timeout(function () { + that.$scope.clickedRowCallback({ rowId: row.rowId }); + }, 0); + }; + + return { + getInstance: function (params) { + return new ClickableRowsFeature(params); + } + }; + } + + angular + .module('mdDataTable') + .service('ClickableRowsFeature', ClickableRowsFeatureFactory); +}()); \ No newline at end of file diff --git a/app/modules/main/templates/cells/generateCellValue.html b/app/modules/main/templates/cells/generateCellValue.html index 2191155..c9dbe8f 100644 --- a/app/modules/main/templates/cells/generateCellValue.html +++ b/app/modules/main/templates/cells/generateCellValue.html @@ -1,10 +1,10 @@ - +
{{headerRowData.columnName}} - +
- - {{headerRowData.columnName}} + ng-class="{'is-active': headerRowData.columnFilter.filtersApplied.length}" layout="row"> +
{{headerRowData.columnName}}
-
\ No newline at end of file + diff --git a/app/modules/main/templates/mdtGeneratedHeaderCellContent.html b/app/modules/main/templates/mdtGeneratedHeaderCellContent.html index 91e1459..d84d707 100644 --- a/app/modules/main/templates/mdtGeneratedHeaderCellContent.html +++ b/app/modules/main/templates/mdtGeneratedHeaderCellContent.html @@ -21,18 +21,18 @@ header-row-data="headerRowData"> -
+
{{headerRowData.columnDefinition}} - +
-
+
{{headerRowData.columnDefinition}} - +
\ No newline at end of file diff --git a/app/modules/main/templates/rows/generateRows.html b/app/modules/main/templates/rows/generateRows.html index f194732..1b1962a 100644 --- a/app/modules/main/templates/rows/generateRows.html +++ b/app/modules/main/templates/rows/generateRows.html @@ -1,7 +1,8 @@ + ng-show="(isPaginationEnabled() === false || rowData.optionList.visible === true) && rowData.optionList.deleted === false" + ng-click="rowClickCallBackHandler($event, rowData)"> @@ -20,4 +21,4 @@ ng-include src="'/main/templates/rows/errorIndicator.html'"> + ng-include src="'/main/templates/rows/noResultIndicator.html'"> \ No newline at end of file diff --git a/bower.json b/bower.json index 63cc3da..d963bbc 100644 --- a/bower.json +++ b/bower.json @@ -28,17 +28,17 @@ ], "dependencies": { "jquery": "~2.1.4", - "lodash": "~3.10.1", - "angular": "~1.5.8", - "angular-sanitize": "~1.5.8", - "angular-animate": "~1.5.8", - "angular-material": "1.1.1", - "angular-material-icons": "~v0.6.0" + "lodash": "~4.17.4", + "angular": "~1.6.4", + "angular-sanitize": "~1.6.4", + "angular-animate": "~1.6.4", + "angular-material": "1.1.4", + "angular-material-icons": "~0.7.1" }, "devDependencies": { - "angular-mocks": "~1.5.8" + "angular-mocks": "~1.6.4" }, "resolutions": { - "angular": "~1.5.8" + "angular": "~1.6.4" } } diff --git a/dist/md-data-table-templates.js b/dist/md-data-table-templates.js index 213a0f7..561b644 100644 --- a/dist/md-data-table-templates.js +++ b/dist/md-data-table-templates.js @@ -7,15 +7,15 @@ $templateCache.put("/main/templates/mdtCheckboxColumnFilter.html","
\r\n
\r\n \r\n
\r\n Sort A-Z \r\n
\r\n\r\n
\r\n \r\n\r\n \r\n\r\n {{transformChip(item)}}\r\n\r\n \r\n No results found.\r\n \r\n \r\n\r\n \r\n \r\n {{transformChip($chip)}}\r\n \r\n \r\n\r\n \r\n
\r\n\r\n
\r\n Ok\r\n Cancel\r\n
\r\n
\r\n
\r\n
\r\n"); $templateCache.put("/main/templates/mdtColumnSelector.html","\r\n
\r\n
\r\n \r\n
\r\n Columns\r\n
\r\n
\r\n Select all - Clear\r\n\r\n
{{selectedItems.length}} Selected
\r\n
\r\n\r\n
\r\n \r\n {{item.columnName}}\r\n \r\n
\r\n\r\n
\r\n Ok\r\n Cancel\r\n
\r\n
\r\n
\r\n
\r\n"); $templateCache.put("/main/templates/mdtDropdownColumnFilter.html","
\r\n
\r\n \r\n
\r\n Sort A-Z \r\n
\r\n\r\n
\r\n \r\n \r\n \r\n {{transformChip(item)}}\r\n \r\n \r\n \r\n
\r\n\r\n
\r\n Ok\r\n Cancel\r\n
\r\n
\r\n
\r\n
\r\n"); -$templateCache.put("/main/templates/mdtGeneratedHeaderCellContent.html","
\r\n \r\n \r\n\r\n \r\n \r\n\r\n\r\n \r\n \r\n\r\n
\r\n {{headerRowData.columnDefinition}}\r\n\r\n \r\n\r\n \r\n\r\n \r\n
\r\n
\r\n {{headerRowData.columnDefinition}}\r\n\r\n \r\n
\r\n
"); +$templateCache.put("/main/templates/mdtGeneratedHeaderCellContent.html","
\r\n \r\n \r\n\r\n \r\n \r\n\r\n\r\n \r\n \r\n\r\n
\r\n {{headerRowData.columnDefinition}}\r\n\r\n \r\n\r\n
\r\n\r\n \r\n
\r\n
\r\n {{headerRowData.columnDefinition}}\r\n\r\n
\r\n
\r\n
"); $templateCache.put("/main/templates/mdtGeneratedHeaderRow.html","\r\n\r\n \r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n \r\n\r\n"); $templateCache.put("/main/templates/mdtTable.html","\r\n \r\n \r\n\r\n \r\n \r\n \r\n\r\n \r\n \r\n
\r\n\r\n \r\n\r\n \r\n
\r\n\r\n \r\n \r\n \r\n
\r\n\r\n"); $templateCache.put("/main/templates/smallEditDialog.html","\r\n \r\n
\r\n \r\n\r\n \r\n \r\n \r\n
\r\n
\r\n
\r\n"); $templateCache.put("/main/templates/cells/generateCell.html","\r\n\r\n\r\n\r\n\r\n\r\n\r\n"); -$templateCache.put("/main/templates/cells/generateCellValue.html","\r\n {{headerRowData.columnName}}\r\n\r\n\r\n\r\n {{headerRowData.columnName}}\r\n \r\n"); +$templateCache.put("/main/templates/cells/generateCellValue.html","
\r\n {{headerRowData.columnName}}\r\n
\r\n\r\n
\r\n
{{headerRowData.columnName}}
\r\n \r\n
\r\n"); $templateCache.put("/main/templates/cells/generateCheckboxCell.html","\r\n"); $templateCache.put("/main/templates/cells/generateSortingIcons.html","\r\n \r\n\r\n\r\n\r\n \r\n"); $templateCache.put("/main/templates/rows/errorIndicator.html","\r\n \r\n\r\n"); -$templateCache.put("/main/templates/rows/generateRows.html","\r\n\r\n \r\n\r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n"); +$templateCache.put("/main/templates/rows/generateRows.html","\r\n\r\n \r\n\r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n"); $templateCache.put("/main/templates/rows/generateRowsVirtualRepeat.html","\r\n\r\n \r\n\r\n \r\n\r\n \r\n \r\n\r\n\r\n\r\n\r\n\r\n"); $templateCache.put("/main/templates/rows/noResultIndicator.html","\r\n \r\n\r\n");}]); \ No newline at end of file diff --git a/dist/md-data-table.js b/dist/md-data-table.js index e7cbf0d..3ebbffe 100644 --- a/dist/md-data-table.js +++ b/dist/md-data-table.js @@ -46,42 +46,6 @@ (function(){ 'use strict'; - InlineEditModalCtrl.$inject = ['$scope', 'position', 'cellData', 'mdtTranslations', '$timeout', '$mdDialog']; - function InlineEditModalCtrl($scope, position, cellData, mdtTranslations, $timeout, $mdDialog){ - - $timeout(function() { - var el = $('md-dialog'); - el.css('position', 'fixed'); - el.css('top', position['top']); - el.css('left', position['left']); - - el.find('input[type="text"]').focus(); - }); - - $scope.cellData = cellData; - $scope.mdtTranslations = mdtTranslations; - - $scope.saveRow = saveRow; - $scope.cancel = cancel; - - function saveRow(){ - if($scope.editFieldForm.$valid){ - $mdDialog.hide(cellData.value); - } - } - - function cancel(){ - $mdDialog.cancel(); - } - } - - angular - .module('mdDataTable') - .controller('InlineEditModalCtrl', InlineEditModalCtrl); -}()); -(function(){ - 'use strict'; - mdtAlternateHeadersDirective.$inject = ['_']; function mdtAlternateHeadersDirective(_){ return { @@ -108,7 +72,7 @@ .module('mdDataTable') .directive('mdtAlternateHeaders', mdtAlternateHeadersDirective); }()); -(function(){ +(function () { 'use strict'; /** @@ -223,13 +187,14 @@ * * */ - mdtTableDirective.$inject = ['TableDataStorageFactory', 'EditCellFeature', 'SelectableRowsFeature', 'PaginationFeature', 'ColumnSelectorFeature', '_']; + mdtTableDirective.$inject = ['TableDataStorageFactory', 'EditCellFeature', 'SelectableRowsFeature', 'ClickableRowsFeature', 'PaginationFeature', 'ColumnSelectorFeature', '_']; function mdtTableDirective(TableDataStorageFactory, EditCellFeature, SelectableRowsFeature, + ClickableRowsFeature, PaginationFeature, ColumnSelectorFeature, - _){ + _) { return { restrict: 'E', templateUrl: '/main/templates/mdtTable.html', @@ -239,24 +204,24 @@ selectableRows: '=', alternateHeaders: '=', deleteRowCallback: '&', - selectedRowCallback: '&', + clickedRowCallback: '&', saveRowCallback: '&', animateSortIcon: '=', rippleEffect: '=', paginatedRows: '=', mdtRow: '=', mdtRowPaginator: '&?', - mdtRowPaginatorErrorMessage:'@', - mdtRowPaginatorNoResultsMessage:'@', + mdtRowPaginatorErrorMessage: '@', + mdtRowPaginatorNoResultsMessage: '@', virtualRepeat: '=', mdtTriggerRequest: '&?', mdtTranslations: '=?', mdtLoadingIndicator: '=?' }, - controller: ['$scope', function mdtTable($scope){ + controller: ['$scope', function mdtTable($scope) { var vm = this; - $scope.rippleEffectCallback = function(){ + $scope.rippleEffectCallback = function () { return $scope.rippleEffect ? $scope.rippleEffect : false; }; @@ -269,12 +234,12 @@ _processData(); // initialization of the storage service - function _initTableStorage(){ + function _initTableStorage() { vm.dataStorage = TableDataStorageFactory.getInstance(); } // set translations or fallback to a default value - function _setDefaultTranslations(){ + function _setDefaultTranslations() { $scope.mdtTranslations = $scope.mdtTranslations || {}; $scope.mdtTranslations.rowsPerPage = $scope.mdtTranslations.rowsPerPage || 'Rows per page:'; @@ -285,8 +250,8 @@ } // fill storage with values if set - function _processData(){ - if(_.isEmpty($scope.mdtRow)) { + function _processData() { + if (_.isEmpty($scope.mdtRow)) { return; } @@ -297,19 +262,19 @@ _addRawDataToStorage(mdtRow['data']); }, true); - }else{ + } else { //if it's used for 'Ajax pagination' } } - function _addRawDataToStorage(data){ + function _addRawDataToStorage(data) { var rowId; var columnValues = []; - _.each(data, function(row){ + _.each(data, function (row) { rowId = _.get(row, $scope.mdtRow['table-row-id-key']); columnValues = []; - _.each($scope.mdtRow['column-keys'], function(columnKey){ + _.each($scope.mdtRow['column-keys'], function (columnKey) { columnValues.push({ attributes: { editableField: false @@ -324,18 +289,19 @@ }); } }], - link: function($scope, element, attrs, ctrl, transclude){ + link: function ($scope, element, attrs, ctrl, transclude) { $scope.dataStorage = ctrl.dataStorage; _injectContentIntoTemplate(); _initEditCellFeature(); _initSelectableRowsFeature(); + _initClickableRowsFeature(); PaginationFeature.startFeature(ctrl); ColumnSelectorFeature.initFeatureHeaderValues($scope.dataStorage.header, ctrl.columnSelectorFeature); - function _injectContentIntoTemplate(){ + function _injectContentIntoTemplate() { transclude(function (clone) { var headings = []; var body = []; @@ -344,11 +310,11 @@ // Use plain JS to append content _.each(clone, function (child) { - if ( child.classList !== undefined ) { - if ( child.classList.contains('theadTrRow')) { + if (child.classList !== undefined) { + if (child.classList.contains('theadTrRow')) { headings.push(child); } - else if( child.classList.contains('customCell') ) { + else if (child.classList.contains('customCell')) { customCell.push(child); } else { @@ -362,16 +328,16 @@ var reader = element[0].querySelector('.mdtTable-reader'); _.each(headings, function (heading) { - reader.appendChild( heading ); + reader.appendChild(heading); }); _.each(body, function (item) { - reader.appendChild( item ); + reader.appendChild(item); }); }); } - function _initEditCellFeature(){ + function _initEditCellFeature() { //TODO: make it possible to only register feature if there is at least // one column which requires it. // for that we need to change the place where we register edit-row. @@ -379,12 +345,18 @@ EditCellFeature.addRequiredFunctions($scope, ctrl); } - function _initSelectableRowsFeature(){ + function _initSelectableRowsFeature() { SelectableRowsFeature.getInstance({ $scope: $scope, ctrl: ctrl }); } + function _initClickableRowsFeature() { + ClickableRowsFeature.getInstance({ + $scope: $scope, + ctrl: ctrl + }); + } } }; } @@ -393,7 +365,163 @@ .module('mdDataTable') .directive('mdtTable', mdtTableDirective); }()); +(function(){ + 'use strict'; + + InlineEditModalCtrl.$inject = ['$scope', 'position', 'cellData', 'mdtTranslations', '$timeout', '$mdDialog']; + function InlineEditModalCtrl($scope, position, cellData, mdtTranslations, $timeout, $mdDialog){ + + $timeout(function() { + var el = $('md-dialog'); + el.css('position', 'fixed'); + el.css('top', position['top']); + el.css('left', position['left']); + + el.find('input[type="text"]').focus(); + }); + + $scope.cellData = cellData; + $scope.mdtTranslations = mdtTranslations; + + $scope.saveRow = saveRow; + $scope.cancel = cancel; + + function saveRow(){ + if($scope.editFieldForm.$valid){ + $mdDialog.hide(cellData.value); + } + } + + function cancel(){ + $mdDialog.cancel(); + } + } + + angular + .module('mdDataTable') + .controller('InlineEditModalCtrl', InlineEditModalCtrl); +}()); +(function () { + 'use strict'; + + ClickableRowsFeatureFactory.$inject = ['$timeout']; + function ClickableRowsFeatureFactory($timeout) { + + function ClickableRowsFeature(params) { + this.$scope = params.$scope; + this.ctrl = params.ctrl; + + this.$scope.rowClickCallBackHandler = _.bind(this.rowClickCallBackHandler, this); + } + + ClickableRowsFeature.prototype.rowClickCallBackHandler = function (event, row) { + var that = this; + // we need to push it to the event loop to make it happen last + // (e.g.: all the elements can be selected before we call the callback) + $timeout(function () { + that.$scope.clickedRowCallback({ rowId: row.rowId }); + }, 0); + }; + + return { + getInstance: function (params) { + return new ClickableRowsFeature(params); + } + }; + } + + angular + .module('mdDataTable') + .service('ClickableRowsFeature', ClickableRowsFeatureFactory); +}()); +(function(){ + 'use strict'; + + PaginationFeature.$inject = ['mdtPaginationHelperFactory', 'mdtAjaxPaginationHelperFactory']; + function PaginationFeature(mdtPaginationHelperFactory, mdtAjaxPaginationHelperFactory){ + var service = this; + + service.initFeature = initFeature; + service.startFeature = startFeature; + + function initFeature(scope, ctrl){ + if(!scope.mdtRowPaginator){ + ctrl.mdtPaginationHelper = scope.mdtPaginationHelper = mdtPaginationHelperFactory + .getInstance(ctrl.dataStorage, scope.paginatedRows, scope.mdtRow); + }else{ + ctrl.mdtPaginationHelper = scope.mdtPaginationHelper = mdtAjaxPaginationHelperFactory.getInstance({ + dataStorage: ctrl.dataStorage, + paginationSetting: scope.paginatedRows, + mdtRowOptions: scope.mdtRow, + mdtRowPaginatorFunction: scope.mdtRowPaginator, + mdtRowPaginatorErrorMessage: scope.mdtRowPaginatorErrorMessage, + mdtRowPaginatorNoResultsMessage: scope.mdtRowPaginatorNoResultsMessage, + mdtTriggerRequest: scope.mdtTriggerRequest + }); + } + + scope.isPaginationEnabled = function(){ + if(scope.paginatedRows === true || + (scope.paginatedRows && scope.paginatedRows.hasOwnProperty('isEnabled') && scope.paginatedRows.isEnabled === true)){ + return true; + } + + return false; + }; + + ctrl.paginationFeature = { + startPaginationFeature: function() { + if (scope.mdtRowPaginator) { + scope.mdtPaginationHelper.fetchPage(1); + } + } + }; + } + + function startFeature(ctrl){ + ctrl.paginationFeature.startPaginationFeature(); + } + } + + angular + .module('mdDataTable') + .service('PaginationFeature', PaginationFeature); +}()); +(function(){ + 'use strict'; + SelectableRowsFeatureFactory.$inject = ['$timeout']; + function SelectableRowsFeatureFactory($timeout){ + + function SelectableRowsFeature(params){ + this.$scope = params.$scope; + this.ctrl = params.ctrl; + + this.$scope.onCheckboxChange = _.bind(this.onCheckboxChange, this); + } + + SelectableRowsFeature.prototype.onCheckboxChange = function(){ + var that = this; + // we need to push it to the event loop to make it happen last + // (e.g.: all the elements can be selected before we call the callback) + $timeout(function(){ + that.$scope.selectedRowCallback({ + rows: that.ctrl.dataStorage.getSelectedRows() + }); + },0); + }; + + return { + getInstance: function(params){ + return new SelectableRowsFeature(params); + } + }; + } + + angular + .module('mdDataTable') + .service('SelectableRowsFeature', SelectableRowsFeatureFactory); +}()); (function(){ 'use strict'; @@ -832,94 +960,6 @@ (function(){ 'use strict'; - PaginationFeature.$inject = ['mdtPaginationHelperFactory', 'mdtAjaxPaginationHelperFactory']; - function PaginationFeature(mdtPaginationHelperFactory, mdtAjaxPaginationHelperFactory){ - var service = this; - - service.initFeature = initFeature; - service.startFeature = startFeature; - - function initFeature(scope, ctrl){ - if(!scope.mdtRowPaginator){ - ctrl.mdtPaginationHelper = scope.mdtPaginationHelper = mdtPaginationHelperFactory - .getInstance(ctrl.dataStorage, scope.paginatedRows, scope.mdtRow); - }else{ - ctrl.mdtPaginationHelper = scope.mdtPaginationHelper = mdtAjaxPaginationHelperFactory.getInstance({ - dataStorage: ctrl.dataStorage, - paginationSetting: scope.paginatedRows, - mdtRowOptions: scope.mdtRow, - mdtRowPaginatorFunction: scope.mdtRowPaginator, - mdtRowPaginatorErrorMessage: scope.mdtRowPaginatorErrorMessage, - mdtRowPaginatorNoResultsMessage: scope.mdtRowPaginatorNoResultsMessage, - mdtTriggerRequest: scope.mdtTriggerRequest - }); - } - - scope.isPaginationEnabled = function(){ - if(scope.paginatedRows === true || - (scope.paginatedRows && scope.paginatedRows.hasOwnProperty('isEnabled') && scope.paginatedRows.isEnabled === true)){ - return true; - } - - return false; - }; - - ctrl.paginationFeature = { - startPaginationFeature: function() { - if (scope.mdtRowPaginator) { - scope.mdtPaginationHelper.fetchPage(1); - } - } - }; - } - - function startFeature(ctrl){ - ctrl.paginationFeature.startPaginationFeature(); - } - } - - angular - .module('mdDataTable') - .service('PaginationFeature', PaginationFeature); -}()); -(function(){ - 'use strict'; - - SelectableRowsFeatureFactory.$inject = ['$timeout']; - function SelectableRowsFeatureFactory($timeout){ - - function SelectableRowsFeature(params){ - this.$scope = params.$scope; - this.ctrl = params.ctrl; - - this.$scope.onCheckboxChange = _.bind(this.onCheckboxChange, this); - } - - SelectableRowsFeature.prototype.onCheckboxChange = function(){ - var that = this; - // we need to push it to the event loop to make it happen last - // (e.g.: all the elements can be selected before we call the callback) - $timeout(function(){ - that.$scope.selectedRowCallback({ - rows: that.ctrl.dataStorage.getSelectedRows() - }); - },0); - }; - - return { - getInstance: function(params){ - return new SelectableRowsFeature(params); - } - }; - } - - angular - .module('mdDataTable') - .service('SelectableRowsFeature', SelectableRowsFeatureFactory); -}()); -(function(){ - 'use strict'; - ColumnAlignmentHelper.$inject = ['ColumnOptionProvider']; function ColumnAlignmentHelper(ColumnOptionProvider){ var service = this; diff --git a/gulpfile.js b/gulpfile.js index 480bc94..2221904 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -24,7 +24,7 @@ gulp.task('default', function(next) { }); gulp.task('build', function(next) { - runSequence('test', 'copy', 'templates', 'compass', 'create index.html', 'ngdocs', next); + runSequence('copy', 'templates', 'compass', 'create index.html', 'ngdocs', next); }); gulp.task('ci', function(next) { diff --git a/package.json b/package.json index 2bf1455..c96a495 100644 --- a/package.json +++ b/package.json @@ -39,23 +39,24 @@ "karma-jasmine-jquery": "~0.1.1", "karma-ng-html2js-preprocessor": "~0.2.0", "karma-ng-scenario": "~0.1.0", - "karma-phantomjs-launcher": "~0.2.1", + "karma-phantomjs-launcher": "^1.0.4", "karma-traceur-preprocessor": "~0.4.0", - "lodash": "~3.10.1", + "lodash": "~4.17.4", "main-bower-files": "~2.11.0", - "phantomjs": "^2.1.7", + "phantomjs-prebuilt": "^2.1.14", "run-sequence": "~1.1.5", "traceur": "~0.0.95", "wallaby-ng-html2js-preprocessor": "^0.1.0" }, "dependencies": { - "angular": "~1.5.8", - "angular-animate": "~1.5.8", - "angular-aria": "~1.5.8", - "angular-material": "1.1.1", - "angular-material-icons": "~v0.6.0", - "angular-sanitize": "~1.5.8", + "angular": "~1.6.4", + "angular-animate": "~1.6.4", + "angular-aria": "~1.6.4", + "angular-material": "1.1.4", + "angular-material-icons": "~0.7.1", + "angular-sanitize": "~1.6.4", + "angular-mocks": "~1.6.4", "jquery": "~2.1.4", - "lodash": "~3.10.1" + "lodash": "~4.17.4" } } diff --git a/test/karma.conf.js b/test/karma.conf.js index cea99c7..8a4cc60 100644 --- a/test/karma.conf.js +++ b/test/karma.conf.js @@ -5,7 +5,6 @@ var dependencies = bowerFiles({ debug: false }); module.exports = function() { return { basePath: '..', - files: dependencies.concat([ //required for html2js 'app/modules/**/*.html', diff --git a/test/karma.unit.conf.js b/test/karma.unit.conf.js index c775cbd..3f67575 100644 --- a/test/karma.unit.conf.js +++ b/test/karma.unit.conf.js @@ -1,6 +1,6 @@ var _ = require('lodash'), environment = require('./helpers/environment.js'), - baseConfig = require('./karma.conf.js'); + baseConfig = require('./karma.conf.js'); function mergeTopLevel(lhs, rhs) { if (_.isArray(lhs)) { @@ -11,8 +11,9 @@ function mergeTopLevel(lhs, rhs) { var unitTestingConfig = _.merge(baseConfig(), { files: [ //extra testing code + 'app/bower_components/angular/angular.js', 'app/bower_components/angular-mocks/angular-mocks.js', - + 'app/bower_components/lodash/dist/lodash.min.js', //unit tests 'test/unit/**/*.js' ], @@ -21,14 +22,14 @@ var unitTestingConfig = _.merge(baseConfig(), { 'app/modules/**/*.js': ['coverage'] }, - reporters: environment.getUnitReportersForCurrentRun(), + reporters: environment.getUnitReportersForCurrentRun(), coverageReporter: { reporters: environment.getCoverageReportersForCurrentRun(), - dir: 'coverage', + dir: 'coverage', subdir: '.' } }, mergeTopLevel); -module.exports = function(config) { +module.exports = function (config) { config.set(unitTestingConfig); }; diff --git a/test/unit/modules/factories/TableDataStorageFactoryTest.js b/test/unit/modules/factories/TableDataStorageFactoryTest.js index 606e2c0..3b4e13b 100644 --- a/test/unit/modules/factories/TableDataStorageFactoryTest.js +++ b/test/unit/modules/factories/TableDataStorageFactoryTest.js @@ -6,15 +6,26 @@ describe('TableDataStorageFactory', function(){ rowId = 324, $log; - beforeEach(module('mdtTemplates')); - beforeEach(module('mdDataTable')); - - beforeEach(inject(function($injector){ - TableDataStorageFactory = $injector.get('TableDataStorageFactory'); - $log = $injector.get('$log'); - - spyOn($log, 'error'); - })); + //beforeEach(module('mdtTemplates')); + //beforeEach(module('mdDataTable')); + + //beforeEach(inject(function($injector){ + // TableDataStorageFactory = $injector.get('TableDataStorageFactory'); + // $log = $injector.get('$log'); + + // spyOn($log, 'error'); + //})); + beforeEach(function () { + module('mdtTemplates'); + module('mdDataTable') + inject(function (_TableDataStorageFactory_) { + TableDataStorageFactory = _TableDataStorageFactory_; + $log = $injector.get('$log'); + + spyOn($log, 'error'); + }) + }); + it('WHEN created it should has the required function', function(){ expect(TableDataStorageFactory.getInstance).toBeDefined();