From c4441bf3e7a25c17d6607e63380137ec52fe99da Mon Sep 17 00:00:00 2001 From: Istvan Fodor Date: Thu, 21 Jul 2016 11:03:19 +0200 Subject: [PATCH 1/4] Add ajax search feature --- .idea/jsLibraryMappings.xml | 6 + .idea/libraries/mdDataTable_node_modules.xml | 14 + .idea/mdDataTable.iml | 13 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 855 ++++++++++++++++++ .../main/directives/mdtTableDirective.js | 6 +- .../mdtAjaxPaginationHelperFactory.js | 10 +- demo/developmentArea.html | 32 +- demo/developmentArea.js | 146 +-- package.json | 14 +- 11 files changed, 977 insertions(+), 133 deletions(-) create mode 100644 .idea/jsLibraryMappings.xml create mode 100644 .idea/libraries/mdDataTable_node_modules.xml create mode 100644 .idea/mdDataTable.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..a7c1cb8 --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/libraries/mdDataTable_node_modules.xml b/.idea/libraries/mdDataTable_node_modules.xml new file mode 100644 index 0000000..32af1ea --- /dev/null +++ b/.idea/libraries/mdDataTable_node_modules.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/mdDataTable.iml b/.idea/mdDataTable.iml new file mode 100644 index 0000000..72791c7 --- /dev/null +++ b/.idea/mdDataTable.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9e57aec --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..29d5d77 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,855 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + $PROJECT_DIR$/gulpfile.js + + + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + + + + + + + + + + + + + + project + + + true + + + + DIRECTORY + + false + + + + + + + + + + + + 1469013878218 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/modules/main/directives/mdtTableDirective.js b/app/modules/main/directives/mdtTableDirective.js index c9a0417..691ad23 100644 --- a/app/modules/main/directives/mdtTableDirective.js +++ b/app/modules/main/directives/mdtTableDirective.js @@ -115,7 +115,8 @@ mdtRow: '=', mdtRowPaginator: '&?', mdtRowPaginatorErrorMessage:"@", - virtualRepeat: '=' + virtualRepeat: '=', + mdtTriggerRequest: '&?' }, controller: function mdtTableController($scope){ var vm = this; @@ -136,7 +137,8 @@ paginationSetting: $scope.paginatedRows, mdtRowOptions: $scope.mdtRow, mdtRowPaginatorFunction: $scope.mdtRowPaginator, - mdtRowPaginatorErrorMessage: $scope.mdtRowPaginatorErrorMessage + mdtRowPaginatorErrorMessage: $scope.mdtRowPaginatorErrorMessage, + mdtTriggerRequest: $scope.mdtTriggerRequest }); } } diff --git a/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js b/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js index cdc63a6..3412f45 100644 --- a/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js +++ b/app/modules/main/factories/mdtAjaxPaginationHelperFactory.js @@ -8,6 +8,7 @@ this.rowOptions = params.mdtRowOptions; this.paginatorFunction = params.mdtRowPaginatorFunction; this.mdtRowPaginatorErrorMessage = params.mdtRowPaginatorErrorMessage || 'Ajax error during loading contents.'; + this.mdtTriggerRequest = params.mdtTriggerRequest; if(params.paginationSetting && params.paginationSetting.hasOwnProperty('rowsPerPageValues') && @@ -27,6 +28,13 @@ //fetching the 1st page this.fetchPage(this.page); + + //triggering ajax call manually + if(this.mdtTriggerRequest) { + params.mdtTriggerRequest({ + loadPage: this.fetchPage.bind(this) + }); + } } mdtAjaxPaginationHelper.prototype.getStartRowIndex = function(){ @@ -112,7 +120,7 @@ this.rowsPerPage = rowsPerPage; this.page = 1; - this.fetchPage(this.page); + //this.fetchPage(this.page); }; return { diff --git a/demo/developmentArea.html b/demo/developmentArea.html index 7514875..d17197f 100644 --- a/demo/developmentArea.html +++ b/demo/developmentArea.html @@ -1,5 +1,25 @@
- + + + + Dessert (100g serving) Calories @@ -10,15 +30,5 @@ Calcium (%) Iron (%) - - {{nutrition.name}} - {{nutrition.calories}} - {{nutrition.fat}} - {{nutrition.carbs}} - {{nutrition.protein}} - {{nutrition.sodium}} - {{nutrition.calcium}} - {{nutrition.iron}} -
\ No newline at end of file diff --git a/demo/developmentArea.js b/demo/developmentArea.js index 9ccdf6c..951faff 100644 --- a/demo/developmentArea.js +++ b/demo/developmentArea.js @@ -2,118 +2,38 @@ 'use strict'; angular.module('developmentAreaApp', ['ngMaterial', 'mdDataTable']); - angular.module('developmentAreaApp').controller('DevelopmentAreaController', function($scope){ - $scope.nutritionList = [ - { - id: 601, - name: 'Frozen joghurt', - calories: 159, - fat: 6.0, - carbs: 24, - protein: 4.0, - sodium: 87, - calcium: '14%', - iron: '1%' - }, - { - id: 602, - name: 'Ice cream sandwitch', - calories: 237, - fat: 9.0, - carbs: 37, - protein: 4.3, - sodium: 129, - calcium: '84%', - iron: '1%' - }, - { - id: 603, - name: 'Eclair', - calories: 262, - fat: 16.0, - carbs: 24, - protein: 6.0, - sodium: 337, - calcium: '6%', - iron: '7%' - }, - { - id: 604, - name: 'Cupkake', - calories: 305, - fat: 3.7, - carbs: 67, - protein: 4.3, - sodium: 413, - calcium: '3%', - iron: '8%' - }, - { - id: 605, - name: 'Gingerbread', - calories: 356, - fat: 16.0, - carbs: 49, - protein: 2.9, - sodium: 327, - calcium: '7%', - iron: '16%' - }, - { - id: 606, - name: 'Jelly bean', - calories: 375, - fat: 0.0, - carbs: 94, - protein: 0.0, - sodium: 50, - calcium: '0%', - iron: '0%' - }, - { - id: 607, - name: 'Lollipop', - calories: 392, - fat: 0.2, - carbs: 98, - protein: 0, - sodium: 38, - calcium: '0%', - iron: '2%' - }, - { - id: 608, - name: 'Honeycomb', - calories: 408, - fat: 3.2, - carbs: 87, - protein: 6.5, - sodium: 562, - calcium: '0%', - iron: '45%' - }, - { - id: 609, - name: 'Donut', - calories: 452, - fat: 25.0, - carbs: 51, - protein: 4.9, - sodium: 326, - calcium: '2%', - iron: '22%' - }, - { - id: 610, - name: 'KitKat', - calories: 518, - fat: 26.0, - carbs: 65, - protein: 7, - sodium: 54, - calcium: '12%', - iron: '6%' - } - ]; + angular.module('developmentAreaApp').controller('DevelopmentAreaController', function($scope, $http){ + $scope.paginatorCallback = paginatorCallback; + $scope.manuallyTriggered = manuallyTriggered; + $scope.abcd = function(){ + loadPageCallback(1); + }; + + var loadPageCallback; + + function manuallyTriggered(loadPage){ + loadPageCallback = loadPage; + } + function paginatorCallback(page, pageSize){ + var offset = (page-1) * pageSize; + + return $http.post('https://api.nutritionix.com/v1_1/search', { + 'appId':'a03ba45f', + 'appKey':'b4c78c1472425c13f9ce0e5e45aa1e16', + 'offset': offset, + 'limit':pageSize, + 'query': '*', + 'fields': ['*'], + 'sort':{ + 'field':'nf_iron_dv', + 'order':'desc' + } + }).then(function(result){ + return { + results: result.data.hits, + totalResultCount: result.data.total + } + }); + } }); }()); \ No newline at end of file diff --git a/package.json b/package.json index 0b32143..e88b665 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "license": "MIT", "devDependencies": { "codeclimate-test-reporter": "~0.1.1", - "event-stream": "~3.3.2", - "fstream": "^1.0.8", + "event-stream": "~3.3.4", + "fstream": "^1.0.10", "glob": "~6.0.2", "gulp": "~3.9.0", "gulp-angular-filesort": "~1.1.1", @@ -30,6 +30,7 @@ "gulp-rimraf": "~0.2.0", "gulp-uglify": "~1.5.1", "gulp-watch": "~4.3.5", + "jasmine-core": "^2.4.1", "jasmine-reporters": "~2.1.0", "karma": "~0.13.15", "karma-coverage": "~0.5.3", @@ -45,12 +46,13 @@ "traceur": "~0.0.95" }, "dependencies": { - "jquery": "~2.1.4", - "lodash": "~3.10.1", "angular": "~1.4.8", - "angular-sanitize": "~1.4.8", "angular-animate": "~1.4.8", "angular-material": "1.0.2", - "angular-material-icons": "~v0.6.0" + "angular-material-icons": "~v0.6.0", + "angular-sanitize": "~1.4.8", + "jquery": "~2.1.4", + "lodash": "~3.10.1", + "phantomjs": "^2.1.7" } } From 7ff74aff09222e3ea63fa41648d2a51b8a1539ea Mon Sep 17 00:00:00 2001 From: Istvan Fodor Date: Thu, 21 Jul 2016 13:12:11 +0200 Subject: [PATCH 2/4] fixing search feature --- .gitignore | 1 + .idea/workspace.xml | 508 ++++++------------ .../mdtAddHtmlContentToCellDirective.js | 19 +- .../mdtAjaxPaginationHelperFactory.js | 2 +- app/modules/main/templates/generateRows.html | 3 +- demo/demoApp.js | 6 +- demo/developmentArea.html | 12 +- demo/developmentArea.js | 19 +- demo/index.html | 1 + dist/md-data-table-templates.js | 20 +- dist/md-data-table.js | 496 +++++++++-------- package.json | 2 +- 12 files changed, 469 insertions(+), 620 deletions(-) diff --git a/.gitignore b/.gitignore index a5a2c00..832ea8f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ build node_modules reports typings +.idea/ \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 29d5d77..c35061b 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,32 +2,17 @@ - + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + @@ -51,41 +36,51 @@ - - + + - - + + - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + - - + + @@ -94,28 +89,30 @@ - - - + + + + + - - + + - - + + - - + + - - + + @@ -124,11 +121,13 @@ - - + + - - + + + + @@ -137,18 +136,8 @@ - - - - - - - - - - - - + + @@ -163,13 +152,17 @@ @@ -277,240 +270,6 @@