Repository: ignite Updated Branches: refs/heads/ignite-843 7ebc5fee8 -> 316b9421a
# GG-1223 Added export to csv, minor fixes. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/10a8b95d Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/10a8b95d Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/10a8b95d Branch: refs/heads/ignite-843 Commit: 10a8b95dfe570cb30bd131cedffbef013410606e Parents: e3b3c57 Author: Andrey <[email protected]> Authored: Fri Sep 4 16:57:42 2015 +0700 Committer: Andrey <[email protected]> Committed: Fri Sep 4 16:57:42 2015 +0700 ---------------------------------------------------------------------- .../src/main/js/controllers/common-module.js | 25 +++- .../src/main/js/controllers/sql-controller.js | 119 ++++++++++++++----- .../main/js/controllers/summary-controller.js | 13 +- modules/control-center-web/src/main/js/db.js | 6 +- .../src/main/js/public/stylesheets/style.scss | 7 ++ .../src/main/js/routes/agent.js | 22 ++++ .../main/js/views/configuration/summary.jade | 2 +- .../src/main/js/views/sql/sql.jade | 16 +-- .../main/js/views/templates/paragraph-rate.jade | 10 +- .../handlers/query/QueryCommandHandler.java | 4 +- 10 files changed, 162 insertions(+), 62 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/10a8b95d/modules/control-center-web/src/main/js/controllers/common-module.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/controllers/common-module.js b/modules/control-center-web/src/main/js/controllers/common-module.js index 021d624..8f75500 100644 --- a/modules/control-center-web/src/main/js/controllers/common-module.js +++ b/modules/control-center-web/src/main/js/controllers/common-module.js @@ -671,6 +671,21 @@ controlCenterModule.service('$common', [ return 'Save ' + objectName; return 'Nothing to save'; + }, + download: function (type, name, data) { + var file = document.createElement('a'); + + file.setAttribute('href', 'data:' + type +';charset=utf-8,' + data); + file.setAttribute('download', name); + file.setAttribute('target', '_self'); + + file.style.display = 'none'; + + document.body.appendChild(file); + + file.click(); + + document.body.removeChild(file); } } }]); @@ -1324,13 +1339,13 @@ controlCenterModule.factory('$focus', function ($timeout) { }); // Directive to auto-focus element. -controlCenterModule.directive('autoFocus', function($timeout) { +controlCenterModule.directive('autoFocus', function() { return { - restrict: 'AC', - link: function(scope, element) { - $timeout(function(){ + link: { + post: function postLink(scope, element) { + // this succeeds since the element has been rendered element[0].focus(); - }); + } } }; }); http://git-wip-us.apache.org/repos/asf/ignite/blob/10a8b95d/modules/control-center-web/src/main/js/controllers/sql-controller.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/controllers/sql-controller.js b/modules/control-center-web/src/main/js/controllers/sql-controller.js index 57b7a0b..bbadd25 100644 --- a/modules/control-center-web/src/main/js/controllers/sql-controller.js +++ b/modules/control-center-web/src/main/js/controllers/sql-controller.js @@ -39,6 +39,8 @@ controlCenterModule.controller('sqlController', ['$scope', '$window','$controlle {value: 'h', label: 'hours'} ]; + $scope.exportDropdown = [{ 'text': 'Export all', 'click': 'exportAll(paragraph)'}]; + $scope.aceInit = function (editor) { editor.setAutoScrollEditorIntoView(true); editor.$blockScrolling = Infinity; @@ -77,6 +79,14 @@ controlCenterModule.controller('sqlController', ['$scope', '$window','$controlle loadNotebook(); + var _saveNotebook = function (f) { + $http.post('/notebooks/save', $scope.notebook) + .success(f || function() {}) + .error(function (errMsg) { + $common.showError(errMsg); + }); + }; + $scope.renameNotebook = function (name) { if (!name) return; @@ -84,35 +94,24 @@ controlCenterModule.controller('sqlController', ['$scope', '$window','$controlle if ($scope.notebook.name != name) { $scope.notebook.name = name; - $http.post('/notebooks/save', $scope.notebook) - .success(function () { - var idx = _.findIndex($scope.$root.notebooks, function (item) { - return item._id == $scope.notebook._id; - }); + _saveNotebook(function () { + var idx = _.findIndex($scope.$root.notebooks, function (item) { + return item._id == $scope.notebook._id; + }); - if (idx >= 0) { - $scope.$root.notebooks[idx].name = name; + if (idx >= 0) { + $scope.$root.notebooks[idx].name = name; - $scope.$root.rebuildDropdown(); - } + $scope.$root.rebuildDropdown(); + } - $scope.notebook.edit = false; - }) - .error(function (errMsg) { - $common.showError(errMsg); - }); + $scope.notebook.edit = false; + }); } else $scope.notebook.edit = false }; - $scope.saveNotebook = function () { - $http.post('/notebooks/save', $scope.notebook) - .error(function (errMsg) { - $common.showError(errMsg); - }); - }; - $scope.removeNotebook = function () { $confirm.show('Are you sure you want to remove notebook: "' + $scope.notebook.name + '"?').then( function () { @@ -146,13 +145,7 @@ controlCenterModule.controller('sqlController', ['$scope', '$window','$controlle if (paragraph.name != newName) { paragraph.name = newName; - $http.post('/notebooks/save', $scope.notebook) - .success(function () { - paragraph.edit = false; - }) - .error(function (errMsg) { - $common.showError(errMsg); - }); + _saveNotebook(function () { paragraph.edit = false; }); } else paragraph.edit = false @@ -266,8 +259,6 @@ controlCenterModule.controller('sqlController', ['$scope', '$window','$controlle }; var _processQueryResult = function (item) { - $scope.saveNotebook(); - return function (res) { item.meta = []; @@ -287,6 +278,8 @@ controlCenterModule.controller('sqlController', ['$scope', '$window','$controlle }; $scope.execute = function (item) { + _saveNotebook(); + _appendOnLast(item); $http.post('/agent/query', {query: item.query, pageSize: item.pageSize, cacheName: item.cache.name}) @@ -297,6 +290,8 @@ controlCenterModule.controller('sqlController', ['$scope', '$window','$controlle }; $scope.explain = function (item) { + _saveNotebook(); + _appendOnLast(item); $http.post('/agent/query', {query: 'EXPLAIN ' + item.query, pageSize: item.pageSize, cacheName: item.cache.name}) @@ -307,6 +302,8 @@ controlCenterModule.controller('sqlController', ['$scope', '$window','$controlle }; $scope.scan = function (item) { + _saveNotebook(); + _appendOnLast(item); $http.post('/agent/scan', {pageSize: item.pageSize, cacheName: item.cache.name}) @@ -333,6 +330,56 @@ controlCenterModule.controller('sqlController', ['$scope', '$window','$controlle }); }; + var _export = function(meta, rows) { + var csvContent = ""; + + if (meta) { + csvContent += meta.map(function (col) { + return $scope.columnToolTip(col); + }).join(",") + '\n'; + } + + rows.forEach(function (row) { + if (Array.isArray(row)) { + csvContent += row.map(function (elem) { + return elem ? JSON.stringify(elem) : ""; + }).join(","); + } + else { + var first = true; + + for (var prop of meta) { + if (first) + first = false; + else + csvContent += ","; + + var elem = row[prop.fieldName]; + + csvContent += elem ? JSON.stringify(elem) : ""; + } + } + + csvContent += '\n'; + }); + + $common.download('application/octet-stream;charset=utf-8', 'export.csv', escape(csvContent)); + }; + + $scope.exportPage = function(paragraph) { + _export(paragraph.meta, paragraph.rows); + }; + + $scope.exportAll = function(paragraph) { + $http.post('/agent/query/getAll', {query: paragraph.query, cacheName: paragraph.cache.name}) + .success(function (item) { + _export(item.meta, item.rows); + }) + .error(function (errMsg) { + $common.showError(errMsg); + }); + }; + $scope.columnToolTip = function (col) { var res = []; @@ -357,6 +404,18 @@ controlCenterModule.controller('sqlController', ['$scope', '$window','$controlle return ""; }; + $scope.startRefresh = function (paragraph, value, unit) { + paragraph.rate = { value: value, unit: unit, ruined: true }; + + //TODO Start timer. + }; + + $scope.stopRefresh = function (paragraph) { + paragraph.rate.ruined = false; + + //TODO Stop timer. + }; + $scope.getter = function (value) { return value; }; http://git-wip-us.apache.org/repos/asf/ignite/blob/10a8b95d/modules/control-center-web/src/main/js/controllers/summary-controller.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/controllers/summary-controller.js b/modules/control-center-web/src/main/js/controllers/summary-controller.js index 2f1cec1..dfaa574 100644 --- a/modules/control-center-web/src/main/js/controllers/summary-controller.js +++ b/modules/control-center-web/src/main/js/controllers/summary-controller.js @@ -107,18 +107,7 @@ controlCenterModule.controller('summaryController', ['$scope', '$http', '$common $scope.download = function () { $http.post('summary/download', {_id: $scope.selectedItem._id, os: $scope.os}) .success(function (data) { - var file = document.createElement('a'); - - file.setAttribute('href', 'data:application/octet-stream;charset=utf-8,' + data); - file.setAttribute('download', $scope.selectedItem.name + '-configuration.zip'); - - file.style.display = 'none'; - - document.body.appendChild(file); - - file.click(); - - document.body.removeChild(file); + $common.download('application/octet-stream', $scope.selectedItem.name + '-configuration.zip', data); }) .error(function (errMsg) { $common.showError('Failed to generate zip: ' + errMsg); http://git-wip-us.apache.org/repos/asf/ignite/blob/10a8b95d/modules/control-center-web/src/main/js/db.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/db.js b/modules/control-center-web/src/main/js/db.js index 8aee6ec..216187c 100644 --- a/modules/control-center-web/src/main/js/db.js +++ b/modules/control-center-web/src/main/js/db.js @@ -351,7 +351,11 @@ var NotebookSchema = new Schema({ query: String, editor: Boolean, result: {type: String, enum: ['none', 'table', 'bar', 'pie', 'line', 'area']}, - pageSize: Number + pageSize: Number, + cache: { + name: String, + mode: {type: String, enum: ['PARTITIONED', 'REPLICATED', 'LOCAL']} + } }] }); http://git-wip-us.apache.org/repos/asf/ignite/blob/10a8b95d/modules/control-center-web/src/main/js/public/stylesheets/style.scss ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/public/stylesheets/style.scss b/modules/control-center-web/src/main/js/public/stylesheets/style.scss index 3b8ffc1..fed7ce3 100644 --- a/modules/control-center-web/src/main/js/public/stylesheets/style.scss +++ b/modules/control-center-web/src/main/js/public/stylesheets/style.scss @@ -753,6 +753,13 @@ div.affix.padding-top-dflt { margin-top: -8px; } +.popover .close { + position: absolute; + top: 5px; + right: 5px; + float: none; +} + label { font-weight: normal; margin-bottom: 0; http://git-wip-us.apache.org/repos/asf/ignite/blob/10a8b95d/modules/control-center-web/src/main/js/routes/agent.js ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/routes/agent.js b/modules/control-center-web/src/main/js/routes/agent.js index 0c5fa4a..eb586e8 100644 --- a/modules/control-center-web/src/main/js/routes/agent.js +++ b/modules/control-center-web/src/main/js/routes/agent.js @@ -78,6 +78,28 @@ router.post('/query', function (req, res) { } }); +/* Execute query getAll. */ +router.post('/query/getAll', function (req, res) { + var client = _client(req, res); + + if (client) { + // Create sql query. + var qry = new SqlFieldsQuery(req.body.query); + + // Set page size for query. + qry.setPageSize(1024); + + // Get query cursor. + var cursor = client.ignite().cache(req.body.cacheName).query(qry); + + cursor.getAll().then(function (rows) { + res.json({meta: cursor.fieldsMetadata(), rows: rows}); + }, function (err) { + res.status(500).send(err); + }); + } +}); + /* Execute query. */ router.post('/scan', function (req, res) { var client = _client(req, res); http://git-wip-us.apache.org/repos/asf/ignite/blob/10a8b95d/modules/control-center-web/src/main/js/views/configuration/summary.jade ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/views/configuration/summary.jade b/modules/control-center-web/src/main/js/views/configuration/summary.jade index 6c77a78..63a1c84 100644 --- a/modules/control-center-web/src/main/js/views/configuration/summary.jade +++ b/modules/control-center-web/src/main/js/views/configuration/summary.jade @@ -64,7 +64,7 @@ block content .col-xs-2.col-sm-2.col-md-1 label Generate: .col-xs-4.col-sm-3.col-md-3 - button.form-control(type='button' ng-model='configServer.javaClassServer' bs-select data-placeholder='{{detail.placeholder}}' bs-options='item.value as item.label for item in javaClassItems' data-sort='false') + button.form-control(type='button' ng-model='configServer.javaClassServer' bs-select data-placeholder='{{detail.placeholder}}' bs-options='item.value as item.label for item in javaClassItems' data-sort='false') div(ui-ace='{ onLoad: aceInit, mode: "java" }' ng-model='javaServer') div(bs-pane title='Dockerfile') .details-row http://git-wip-us.apache.org/repos/asf/ignite/blob/10a8b95d/modules/control-center-web/src/main/js/views/sql/sql.jade ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/views/sql/sql.jade b/modules/control-center-web/src/main/js/views/sql/sql.jade index 93c637e..75878be 100644 --- a/modules/control-center-web/src/main/js/views/sql/sql.jade +++ b/modules/control-center-web/src/main/js/views/sql/sql.jade @@ -96,13 +96,15 @@ block container button.btn.btn-default.base-control.tipLabel(ng-model='paragraph.pageSize' bs-options='item for item in pageSizes' bs-select) .panel-body(ng-show='paragraph.rows && paragraph.result === "table" && paragraph.rows') .row - .col-sm-8 - lable Page #: - b {{paragraph.page}} - | Results: - b {{paragraph.rows.length + paragraph.total}} - .col-sm-4 - button.btn.btn-primary.fieldButton(ng-click='nextPage(paragraph)' ng-disabled='!paragraph.queryId') Next page + lable Page #: + b {{paragraph.page}} + | Results: + b {{paragraph.rows.length + paragraph.total}} + button.btn.btn-primary.fieldButton(ng-click='nextPage(paragraph)' ng-disabled='!paragraph.queryId') Next page + .btn-group.fieldButton + button.btn.btn-primary.fieldButton(ng-click='exportPage(paragraph)' ) Export + button.btn.dropdown-toggle.btn-primary(id='export-item-dropdown' data-toggle='dropdown' data-container='body' bs-dropdown='exportDropdown' data-placement='bottom-right') + span.caret .table-responsive table.table.table-condensed(st-table='displayedCollection' st-safe-src='paragraph.rows') thead http://git-wip-us.apache.org/repos/asf/ignite/blob/10a8b95d/modules/control-center-web/src/main/js/views/templates/paragraph-rate.jade ---------------------------------------------------------------------- diff --git a/modules/control-center-web/src/main/js/views/templates/paragraph-rate.jade b/modules/control-center-web/src/main/js/views/templates/paragraph-rate.jade index 3f583cb..d9d8cdf 100644 --- a/modules/control-center-web/src/main/js/views/templates/paragraph-rate.jade +++ b/modules/control-center-web/src/main/js/views/templates/paragraph-rate.jade @@ -17,13 +17,15 @@ .popover(tabindex='-1' style='width: 200px') .arrow h3.popover-title(style='color: black') Refresh rate + button.close(id='paragraph-rate-close' type='button' ng-click='$hide()') × .popover-content form(name='popoverForm') .form-group(style='margin: 0; padding: 5px') .col-sm-4(style='padding: 0') - input.form-control(id='paragraph-rate' ng-model='paragraph.rate.value' type='number' required auto-focus) + input.form-control(id='paragraph-rate' ng-init='value = paragraph.rate.value' ng-model='value' type='number' required auto-focus) .col-sm-8(style='padding-left: 5px; padding-right: 0') - button.form-control(id='paragraph-unit' ng-model='paragraph.rate.unit' required placeholder='Time unit' bs-select bs-options='item.value as item.label for item in timeUnit' tabindex='0') + button.form-control(id='paragraph-unit' ng-init='unit = paragraph.rate.unit' ng-model='unit' required placeholder='Time unit' bs-select bs-options='item.value as item.label for item in timeUnit' tabindex='0') .form-actions(style='margin-top: 30px; padding: 5px') - button.btn.btn-primary(id='paragraph-rate-btn-set' ng-disabled='popoverForm.$invalid' type='button' ng-click='popover.saved=true;paragraph.rate.ruined=true; $hide()') Set - button.btn.btn-primary.btn-default(id='paragraph-rate-btn-stop' type='button' ng-click='paragraph.rate.ruined=false; $hide()') Stop + button.btn.btn-primary(id='paragraph-rate-start' ng-disabled='popoverForm.$invalid' type='button' ng-click='startRefresh(paragraph, value, unit); $hide()') Start + button.btn.btn-primary.btn-default(id='paragraph-rate-stop' type='button' ng-click='stopRefresh(paragraph); $hide()') Stop + http://git-wip-us.apache.org/repos/asf/ignite/blob/10a8b95d/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java index 5828216..4b7e5ec 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/query/QueryCommandHandler.java @@ -196,10 +196,10 @@ public class QueryCommandHandler extends GridRestCommandHandlerAdapter { break; case SCAN: CacheQueryFieldsMetaResult keyField = new CacheQueryFieldsMetaResult(); - keyField.setFieldName("Key"); + keyField.setFieldName("key"); CacheQueryFieldsMetaResult valField = new CacheQueryFieldsMetaResult(); - valField.setFieldName("Value"); + valField.setFieldName("value"); res.setFieldsMetadata(U.sealList(keyField, valField));
