Repository: incubator-ignite Updated Branches: refs/heads/ignite-843 d3637e8aa -> 797666d82
# IGNITE-843 WIP on caches page. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/797666d8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/797666d8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/797666d8 Branch: refs/heads/ignite-843 Commit: 797666d82fdf0f9e568603425cd3155477faa2de Parents: d3637e8 Author: AKuznetsov <akuznet...@gridgain.com> Authored: Wed Jun 3 18:19:15 2015 +0700 Committer: AKuznetsov <akuznet...@gridgain.com> Committed: Wed Jun 3 18:19:15 2015 +0700 ---------------------------------------------------------------------- .../public/javascripts/controllers/caches.js | 137 +++++++--------- modules/webconfig/nodejs/routes/caches.js | 23 ++- modules/webconfig/nodejs/views/caches.jade | 157 ++++++++++++------- 3 files changed, 177 insertions(+), 140 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/797666d8/modules/webconfig/nodejs/public/javascripts/controllers/caches.js ---------------------------------------------------------------------- diff --git a/modules/webconfig/nodejs/public/javascripts/controllers/caches.js b/modules/webconfig/nodejs/public/javascripts/controllers/caches.js index 1bb33fd..9d3240e 100644 --- a/modules/webconfig/nodejs/public/javascripts/controllers/caches.js +++ b/modules/webconfig/nodejs/public/javascripts/controllers/caches.js @@ -15,116 +15,93 @@ * limitations under the License. */ -configuratorModule.controller('cachesController', ['$scope', '$modal', '$http', '$filter', 'ngTableParams', - function($scope, $modal, $http, $filter, ngTableParams) { - $scope.editColumn = {}; +configuratorModule.controller('cachesController', ['$scope', '$http', function($scope, $http) { + $scope.templates = [ + {value: {}, label: 'None'}, + {value: {mode: 'PART', atomicy: 'ATOMIC'}, label: 'Partitioned'}, + {value: {mode: 'REPL', atomicy: 'ATOMIC'}, label: 'Replicated'}, + {value: {mode: 'LOCAL', atomicy: 'ATOMIC'}, label: 'Local'} + ]; - $scope.editCache = {}; + $scope.atomicities = [ + {value: 'ATOMIC', label: 'Atomic'}, + {value: 'TRANSACTIONAL', label: 'Transactional'} + ]; $scope.modes = [ - {value: 'PARTITIONED', label: 'PARTITIONED'}, - {value: 'REPLICATED', label: 'REPLICATED'}, - {value: 'LOCAL', label: 'LOCAL'} + {value: 'PARTITIONED', label: 'Partitioned'}, + {value: 'REPLICATED', label: 'Replicated'}, + {value: 'LOCAL', label: 'Local'} ]; - $scope.atomicities = [ - {value: 'ATOMIC', label: 'ATOMIC'}, - {value: 'TRANSACTIONAL', label: 'TRANSACTIONAL'} - ]; + $scope.caches = []; // When landing on the page, get caches and show them. $http.get('/rest/caches') .success(function(data) { $scope.spaces = data.spaces; $scope.caches = data.caches; - - $scope.cachesTable = new ngTableParams({ - page: 1, // Show first page. - count: Number.MAX_VALUE, // Count per page. - sorting: {name: 'asc'} // Initial sorting. - }, { - total: $scope.caches.length, // Length of data. - counts: [], - getData: function($defer, params) { - // Use build-in angular filter. - var orderedData = params.sorting() ? - $filter('orderBy')($scope.caches, params.orderBy()) : - $scope.caches; - - var page = params.page(); - var cnt = params.count(); - - $defer.resolve(orderedData.slice(page - 1 * cnt, page * cnt)); - } - }); }); - // Add new cache. - $scope.addCache = function() { - $scope.caches.push({space: $scope.spaces[0]._id, mode: 'PARTITIONED', backups: 1, atomicity: 'ATOMIC'}); + $scope.selectItem = function(item) { + $scope.selectedItem = item; - $scope.cachesTable.reload(); + $scope.backupItem = angular.copy(item); }; - $scope.beginEditCache = function(column, cache) { - $scope.revertCache(); - - $scope.currentCache = cache; + // Add new cache. + $scope.createItem = function() { + var item = angular.copy($scope.create.template); - $scope.editColumn = column; + item.name = 'Cache ' + ($scope.caches.length + 1); + item.space = $scope.spaces[0]._id; - $scope.editCache = angular.copy(cache); - }; - $scope.revertCache = function() { - if ($scope.editColumn && $scope.currentCache) { - $scope.caches[$scope.caches.indexOf($scope.currentCache)] = $scope.editCache; + $http.post('/rest/caches/save', item) + .success(function(_id) { + item._id = _id; - $scope.currentCache = undefined; + console.log(_id) - $scope.editColumn = undefined; + $scope.caches.push(item); - $scope.cachesTable.reload(); - } + $scope.selectItem(item); + }) + .error(function(errorMessage) { + console.log('Error: ' + errorMessage); + }); }; - $scope.submit = function() { - if ($scope.editColumn && $scope.currentCache) { - var cache = $scope.currentCache; + $scope.removeItem = function(item) { + $http.post('/rest/caches/remove', {_id: item._id}) + .success(function() { + var index = $scope.caches.indexOf(item); - var data = { - _id: cache._id, - space: cache.space, - name: cache.name, - mode: cache.mode, - backups: cache.backups, - atomicity: cache.atomicity - }; + if (index !== -1) { + $scope.caches.splice(index, 1); - $scope.currentCache = undefined; + if ($scope.selectedItem == item) { + $scope.selectedItem = undefined; - $scope.editColumn = undefined; - - $http.post('/rest/caches/save', data) - .success(function(data) { - $scope.spaces = data.spaces; - $scope.caches = data.caches; - - $scope.cachesTable.reload(); - }) - .error(function(errorMessage) { - console.log('Error: ' + errorMessage); - }); - } + $scope.backupItem = undefined; + } + } + }) + .error(function(errorMessage) { + console.log('Error: ' + errorMessage); + }); }; - $scope.deleteCache = function(cache) { - $http.post('/rest/caches/remove', {_id: cache._id}) - .success(function(data) { - $scope.spaces = data.spaces; - $scope.caches = data.caches; + // Save cache in db. + $scope.saveItem = function(item) { + $http.post('/rest/caches/save', item) + .success(function() { + var cache = $scope.caches.find(function(cache) { + return cache._id == item._id; + }); - $scope.cachesTable.reload(); + if (cache) + angular.extend(cache, item); }) .error(function(errorMessage) { console.log('Error: ' + errorMessage); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/797666d8/modules/webconfig/nodejs/routes/caches.js ---------------------------------------------------------------------- diff --git a/modules/webconfig/nodejs/routes/caches.js b/modules/webconfig/nodejs/routes/caches.js index d559e9f..1d43d8d 100644 --- a/modules/webconfig/nodejs/routes/caches.js +++ b/modules/webconfig/nodejs/routes/caches.js @@ -57,12 +57,23 @@ router.get('/', function(req, res) { * Save cache. */ router.post('/save', function(req, res) { - db.upsert(db.Cache, req.body, function(err) { - if (err) - return res.status(500).send(err); + if (req.body._id) + db.Cache.update({_id: req.body._id}, req.body, {upsert: true}, function(err) { + if (err) + return res.send(err); - selectAll(req, res); - }); + res.sendStatus(200); + }); + else { + var cache = new db.Cache(req.body); + + cache.save(function(err, cache) { + if (err) + return res.send(err.message); + + res.send(cache._id); + }); + } }); /** @@ -73,7 +84,7 @@ router.post('/remove', function(req, res) { if (err) return res.send(err); - selectAll(req, res); + res.sendStatus(200); }) }); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/797666d8/modules/webconfig/nodejs/views/caches.jade ---------------------------------------------------------------------- diff --git a/modules/webconfig/nodejs/views/caches.jade b/modules/webconfig/nodejs/views/caches.jade index f026538..357e01e 100644 --- a/modules/webconfig/nodejs/views/caches.jade +++ b/modules/webconfig/nodejs/views/caches.jade @@ -15,63 +15,112 @@ limitations under the License. extends layout-sidebar + append scripts script(src='/javascripts/controllers/caches.js') + block content - div.docs-header + .docs-header h1 Caches p Create and configure Ignite caches. hr - div.docs-body(ng-controller='cachesController') - div.block-edit-parameters - div.btn-group - button(ng-click='addCache()' class=['btn', 'btn-default', 'fa', 'fa-plus'] )  Add - table(ng-table="cachesTable" class=['table', 'table-bordered', 'table-hover']) - tr(ng-repeat="cache in $data") - td(data-title="'#'" class=['text-center', 'vcenter'] style='width: 50px') {{$index + 1}} - td(data-title="'Name'" sortable="'name'" class=['text-center', 'col-sm-2']) - div(ng-if='!(editColumn == "name" && currentCache == cache)') - span(ng-if='cache.name') {{cache.name}} - span.pull-right(type='button' ng-click='beginEditCache("name", cache);') - i(class=['fa', 'fa-pencil']) - div.input-group(ng-if='editColumn == "name" && currentCache == cache') - input.form-control(type='text' ng-model='cache.name') - span.input-group-addon - i(class=['fa', 'fa-repeat'] ng-click='revert();') - i(class=['fa', 'fa-save'] ng-click='submit();' style='margin-left: 10px;') - td(data-title="'Mode'" sortable="'mode'" class=['text-center', 'col-sm-4']) - div(ng-if='!(editColumn == "mode" && currentCache == cache)') - span(ng-if='cache.mode') {{cache.mode}} - span.pull-right(type='button') - i(class=['fa', 'fa-pencil'] ng-click='beginEditCache("mode", cache);' style='margin-left: 10px;') - div.input-group(ng-if='editColumn == "mode" && currentCache == cache') - button(class=['btn', 'btn-default', 'form-control', 'pull-right'] style='width: 85%' data-placement='bottom-center' ng-model='cache.mode' data-template='/select' data-placeholder='Choose mode' bs-options='mode.value as mode.label for mode in modes' bs-select) - span.caret - span.input-group-addon - i(class=['fa', 'fa-repeat'] ng-click='revertCache();') - i(class=['fa', 'fa-save'] ng-click='submit();' style='margin-left: 10px;') - td(data-title="'Backups'" sortable="'backups'" class=['text-center', 'col-sm-1']) - div(ng-if='!(editColumn == "backups" && currentCache == cache)') - span(ng-if='cache.backups') {{cache.backups}} - span.pull-right(type='button' ng-click='beginEditCache("backups", cache);') - i(class=['fa', 'fa-pencil']) - div.input-group(ng-if='editColumn == "name" && currentCache == cache') - input.form-control(type='text' ng-model='cache.name') - span.input-group-addon - i(class=['fa', 'fa-repeat'] ng-click='revert();') - i(class=['fa', 'fa-save'] ng-click='submit();' style='margin-left: 10px;') - td(data-title="'Atomicity'" sortable="'atomicity'" class=['text-center', 'col-sm-4']) - div(ng-if='!(editColumn == "atomicity" && currentCache == cache)') - span(ng-if='cache.atomicity') {{cache.atomicity}} - span.pull-right(type='button') - i(class=['fa', 'fa-pencil'] ng-click='beginEditCache("atomicity", cache);' style='margin-left: 10px;') - div.input-group(ng-if='editColumn == "atomicity" && currentCache == cache') - button(class=['btn', 'btn-default', 'form-control', 'pull-right'] style='width: 85%' data-placement='bottom-center' ng-model='cache.atomicity' data-template='/select' data-placeholder='Choose atomicity' bs-options='atomicity.value as atomicity.label for atomicity in atomicities' bs-select) - span.caret - span.input-group-addon - i(class=['fa', 'fa-repeat'] ng-click='revertCache();') - i(class=['fa', 'fa-save'] ng-click='submit();' style='margin-left: 10px;') - td.col-sm-1(data-title="'Delete'") - center - span(type='button' ng-click='deleteCache(Cache)') - i(class=['fa', 'fa-remove']) \ No newline at end of file + .docs-body(ng-controller='cachesController') + button(ng-click='createItem()' class=['btn', 'btn-primary'] ng-disabled='!create.template')  Add cache + span from template:  + button(class=['btn', 'btn-default'] ng-init="create.template = templates[0].value" ng-model='create.template' data-template='/select' data-placeholder='Choose cache template' bs-options='item.value as item.label for item in templates' bs-select) + h3(ng-hide='caches.length == 0') Caches + .links + table.col-sm-12(st-table='rowCollection' st-safe-src='caches') + tbody + tr(ng-repeat='row in rowCollection') + td.col-sm-6(ng-class="{active: row == selectedItem}") + a(ng-click='selectItem(row)') {{row.name}}, {{row.cache.mode | displayValue:modes:'Cache mode not set'}} + .row.col-sm-12 + hr + form.form-horizontal(name='editForm' ng-if='backupItem') + h3 General + .settings-row + span.col-sm-2 Name: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.name') + .settings-row + span.col-sm-2 Discovery: + .col-sm-3 + button.form-control(style='text-align: left' ng-model='backupItem.discovery.kind' data-template='/select' data-placeholder='Choose discovery' bs-options='item.value as item.label for item in discoveries' bs-select) + .panel(bs-collapse data-start-collapsed='true') + .panel-collapse(bs-collapse-target) + h3 Cache configuration + .settings-row + input(type='checkbox' ng-model='backupItem.cacheSanityCheckEnabled') + span Enable cache sanity check. + h3 Marshaller + .settings-row + span.col-sm-2 Keep alive time: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.marshCacheKeepAliveTime' placeholder='10,000') + .settings-row + span.col-sm-2 Pool size: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.marshCachePoolSize' placeholder='max(8, availableProcessors) * 2') + h3 Network + .settings-row + span.col-sm-2 Timeout: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.netTimeout' placeholder='5,000') + .settings-row + span.col-sm-2 Send retry delay: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.sndRetryDelay' placeholder='1,000') + .settings-row + span.col-sm-2 Send retry count: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.sndRetryCnt' placeholder='3') + h3 Peer Class Loading + .settings-row + input(type='checkbox' ng-model='backupItem.p2pEnabled') + span Enable peer class loading. + .settings-row + span.col-sm-2 Local class path exclude: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.p2pLocClsPathExcl' placeholder='[]') + .settings-row + span.col-sm-2 Missed resources cache size: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.p2pMissedCacheSize' placeholder='100') + .settings-row + span.col-sm-2 Pool size: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.p2pPoolSize' placeholder='availableProcessors') + h3 Thread pools size + .settings-row + span.col-sm-2 Public: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.pubPoolSize' placeholder='max(8, availableProcessors) * 2') + .settings-row + span.col-sm-2 System: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.sysPoolSize' placeholder='max(8, availableProcessors) * 2') + .settings-row + span.col-sm-2 Management: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.mgmtPoolSize' placeholder='4') + .settings-row + span.col-sm-2 Igfs: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.igfsPoolSize' placeholder='availableProcessors') + h3 Utility + .settings-row + span.col-sm-2 Keep alive time: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.utilityCacheKeepAliveTime' placeholder='10,000') + .settings-row + span.col-sm-2 Pool size: + .col-sm-3 + input.form-control(type='text' ng-model='backupItem.utilityCachePoolSize' placeholder='max(8, availableProcessors) * 2') + .panel-heading + .panel-title + span(bs-collapse-toggle) + a(ng-click='expanded = true' ng-hide='expanded') Show advanced settings... + a(ng-click='expanded = false' ng-show='expanded') Hide advanced settings... + button.btn.btn-primary(ng-click='saveItem(backupItem)' ng-disabled='editForm.$invalid') Save + button.btn.btn-primary(ng-click='removeItem(selectedItem)' ng-disabled='editForm.$invalid') Remove \ No newline at end of file