# ignite-843 Add cache selection in cluster. Fixed dropdown.
Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/d4f63cf5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/d4f63cf5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/d4f63cf5 Branch: refs/heads/ignite-843 Commit: d4f63cf5d103ac4492235c61fae95b80560b3339 Parents: 9a545b1 Author: Andrey <[email protected]> Authored: Thu Jun 4 17:04:17 2015 +0700 Committer: Andrey <[email protected]> Committed: Thu Jun 4 17:04:17 2015 +0700 ---------------------------------------------------------------------- modules/webconfig/nodejs/db.js | 35 +++++++------------- .../public/javascripts/controllers/clusters.js | 10 +++--- .../public/javascripts/controllers/common.js | 7 ++++ modules/webconfig/nodejs/routes/clusters.js | 17 +++++++--- modules/webconfig/nodejs/views/caches.jade | 2 +- modules/webconfig/nodejs/views/clusters.jade | 7 ++-- .../nodejs/views/templates/select.jade | 10 +++--- 7 files changed, 45 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d4f63cf5/modules/webconfig/nodejs/db.js ---------------------------------------------------------------------- diff --git a/modules/webconfig/nodejs/db.js b/modules/webconfig/nodejs/db.js index f84b322..929467e 100644 --- a/modules/webconfig/nodejs/db.js +++ b/modules/webconfig/nodejs/db.js @@ -52,6 +52,17 @@ var DiscoveryObj = { addresses: [String] }; +// Define cache model. +var CacheSchema = new Schema({ + space: { type: ObjectId, ref: 'Space' }, + name: String, + mode: { type: String, enum: ['PARTITIONED', 'REPLICATED', 'LOCAL'] }, + backups: Number, + atomicity: { type: String, enum: ['ATOMIC', 'TRANSACTIONAL'] } +}); + +exports.Cache = mongoose.model('Cache', CacheSchema); + // Define discovery model. exports.Discovery = mongoose.model('Discovery', new Schema(DiscoveryObj)); @@ -62,6 +73,7 @@ var ClusterSchema = new Schema({ kind: { type: String, enum: ['Vm', 'Multicast', 'S3', 'Cloud', 'GoogleStorage', 'Jdbc', 'SharedFs'] }, addresses: [String] }, + caches: [{ type: ObjectId, ref: 'Cache' }], pubPoolSize: Number, sysPoolSize: Number, mgmtPoolSize: Number, @@ -71,29 +83,6 @@ var ClusterSchema = new Schema({ // Define cluster model. exports.Cluster = mongoose.model('Cluster', ClusterSchema); -ClusterSchema.pre('remove', function(next) { - var discovery = false; - - if (this._doc && this._doc.discovery) discovery = {_id:this._doc.discovery._id}; - - Discovery.remove(discovery, function(err) { - if (err) - next(err); - - next(); - }); -}); - -// Define cache model. -exports.Cache = mongoose.model('Cache', new Schema({ - space: { type: ObjectId, ref: 'Space' }, - name: String, - mode: { type: String, enum: ['PARTITIONED', 'REPLICATED', 'LOCAL'] }, - backups: Number, - atomicity: { type: String, enum: ['ATOMIC', 'TRANSACTIONAL'] }, - clusters: [{ type: ObjectId, ref: 'Cluster' }] -})); - exports.upsert = function(model, data, cb){ if (data._id) { var id = data._id; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d4f63cf5/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js ---------------------------------------------------------------------- diff --git a/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js b/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js index 50e6388..db9a22a 100644 --- a/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js +++ b/modules/webconfig/nodejs/public/javascripts/controllers/clusters.js @@ -47,11 +47,10 @@ configuratorModule.controller('clustersController', ['$scope', '$modal', '$http' {value: 'EVTS_IGFS', label: 'Igfs'} ]; - $scope.caches = [ - {value: '1', label: 'Cache1'}, - {value: '2', label: 'Cache2'}, - {value: '3', label: 'Cache3'}, - {value: '4', label: 'Cache4'} + $scope.cacheModes = [ + {value: 'LOCAL', label: 'LOCAL'}, + {value: 'REPLICATED', label: 'REPLICATED'}, + {value: 'PARTITIONED', label: 'PARTITIONED'} ]; $scope.clusters = []; @@ -71,6 +70,7 @@ configuratorModule.controller('clustersController', ['$scope', '$modal', '$http' // When landing on the page, get clusters and show them. $http.get('/rest/clusters') .success(function(data) { + $scope.caches = data.caches; $scope.spaces = data.spaces; $scope.clusters = data.clusters; }); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d4f63cf5/modules/webconfig/nodejs/public/javascripts/controllers/common.js ---------------------------------------------------------------------- diff --git a/modules/webconfig/nodejs/public/javascripts/controllers/common.js b/modules/webconfig/nodejs/public/javascripts/controllers/common.js index 8457b86..b1fa0af 100644 --- a/modules/webconfig/nodejs/public/javascripts/controllers/common.js +++ b/modules/webconfig/nodejs/public/javascripts/controllers/common.js @@ -17,6 +17,13 @@ var configuratorModule = angular.module('ignite-web-configurator', ['smart-table', 'mgcrea.ngStrap']); +configuratorModule.config(function($selectProvider) { + angular.extend($selectProvider.defaults, { + allText: 'Select All', + noneText: 'Clear All' + }); +}); + // Decode name using map(value, label). configuratorModule.filter('displayValue', function () { return function (v, m, dflt) { http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d4f63cf5/modules/webconfig/nodejs/routes/clusters.js ---------------------------------------------------------------------- diff --git a/modules/webconfig/nodejs/routes/clusters.js b/modules/webconfig/nodejs/routes/clusters.js index cd33d5e..b8f123b 100644 --- a/modules/webconfig/nodejs/routes/clusters.js +++ b/modules/webconfig/nodejs/routes/clusters.js @@ -32,16 +32,25 @@ function selectAll(req, res) { if (err) return res.status(500).send(err); - var space_ids = spaces.map(function(value, index) { + var space_ids = spaces.map(function(value) { return value._id; }); - // Get all clusters for spaces. - db.Cluster.find({space: {$in: space_ids}}, function (err, clusters) { + db.Cache.find({space: {$in: space_ids}}, '_id name', function (err, caches) { if (err) return res.status(500).send(err); - res.json({spaces: spaces, clusters: clusters}); + // Get all clusters for spaces. + db.Cluster.find({space: {$in: space_ids}}, function (err, clusters) { + if (err) + return res.status(500).send(err); + + var cachesJson = caches.map(function(cache) { + return {value: cache._id, label: cache.name}; + }); + + res.json({spaces: spaces, caches: cachesJson, clusters: clusters}); + }); }); }); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d4f63cf5/modules/webconfig/nodejs/views/caches.jade ---------------------------------------------------------------------- diff --git a/modules/webconfig/nodejs/views/caches.jade b/modules/webconfig/nodejs/views/caches.jade index 4da18ab..b0b7a71 100644 --- a/modules/webconfig/nodejs/views/caches.jade +++ b/modules/webconfig/nodejs/views/caches.jade @@ -33,7 +33,7 @@ block content 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}") + td.col-sm-6(ng-class="{active: row._id == selectedItem._id}") a(ng-click='selectItem(row)') {{$index + 1}}. {{row.name}}, {{row.mode | displayValue:modes:'Cache mode not set'}}, {{row.atomicity | displayValue:atomicities:'Cache atomicity not set'}} .row.col-sm-12 hr http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d4f63cf5/modules/webconfig/nodejs/views/clusters.jade ---------------------------------------------------------------------- diff --git a/modules/webconfig/nodejs/views/clusters.jade b/modules/webconfig/nodejs/views/clusters.jade index eed2029..63eaa90 100644 --- a/modules/webconfig/nodejs/views/clusters.jade +++ b/modules/webconfig/nodejs/views/clusters.jade @@ -33,11 +33,8 @@ block content table.col-sm-12(st-table='rowCollection' st-safe-src='clusters') tbody tr(ng-repeat='row in rowCollection') - td.col-sm-6(ng-class="{active: row == selectedItem}") + td.col-sm-6(ng-class="{active: row._id == selectedItem._id}") a(ng-click='selectItem(row)') {{$index + 1}}. {{row.name}}, {{row.discovery.kind | displayValue:discoveries:'Discovery not set'}} - //td - // span(type='button' ng-click='removeItem(row)') - // i(class=['fa', 'fa-remove']) .row.col-sm-12 hr form.form-horizontal(name='editForm' ng-if='backupItem') @@ -62,7 +59,7 @@ block content .settings-row span.col-sm-2 Cache mode: .col-sm-3 - input.form-control(type='text' ng-model='backupItem.atomic.cacheMode' placeholder='PARTITIONED') + button.form-control(style='text-align: left' ng-model='backupItem.atomic.cacheMode' data-template='/select' data-placeholder='PARTITIONED' bs-options='item.value as item.label for item in cacheModes' bs-select) .settings-row span.col-sm-2 Sequence reserve size: .col-sm-3 http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/d4f63cf5/modules/webconfig/nodejs/views/templates/select.jade ---------------------------------------------------------------------- diff --git a/modules/webconfig/nodejs/views/templates/select.jade b/modules/webconfig/nodejs/views/templates/select.jade index 7f93bfd..1f9ad9f 100644 --- a/modules/webconfig/nodejs/views/templates/select.jade +++ b/modules/webconfig/nodejs/views/templates/select.jade @@ -15,11 +15,11 @@ limitations under the License. ul.select.dropdown-menu(tabindex='-1', ng-show='$isVisible()', role='select') - li(ng-if='$showAllNoneButtons') - .btn-group(style='margin-left: 5px') - button.btn.btn-default.btn-xs(type='button', ng-click='$selectAll()') {{$allText}} - button.btn.btn-default.btn-xs(type='button', ng-click='$selectNone()') {{$noneText}} li(role='presentation', ng-repeat='match in $matches') a(style='cursor: default;', role='menuitem', tabindex='-1', ng-click='$select($index, $event)') i.pull-right(class='{{$iconCheckmark}}', ng-if='$isMultiple && $isActive($index)') - span(ng-bind='match.label') \ No newline at end of file + span(ng-bind='match.label') + li(ng-if='$showAllNoneButtons || $matches.length > 5') + hr(style='margin: 5px 0') + a(ng-click='$selectAll()') {{$allText}} + a(ng-click='$selectNone()') {{$noneText}} \ No newline at end of file
