From b42c3392da90160a75bfce41b576648cf8bf869f Mon Sep 17 00:00:00 2001 From: Anthony Yeh Date: Tue, 28 Jul 2015 14:06:41 -0700 Subject: [PATCH] web/vtctld: Make vindex owner an autocomplete. --- web/vtctld/vschema/vschema.html | 54 +++++++++---- web/vtctld/vschema/vschema.js | 130 +++++++++++++++++++++++--------- 2 files changed, 136 insertions(+), 48 deletions(-) diff --git a/web/vtctld/vschema/vschema.html b/web/vtctld/vschema/vschema.html index 2b49a789f4..63cf143997 100644 --- a/web/vtctld/vschema/vschema.html +++ b/web/vtctld/vschema/vschema.html @@ -266,7 +266,7 @@ They are only used with the - +
@@ -285,14 +285,28 @@ They are only used with the
Required
Undefined Vindex Type
+
Owned primary vindex must have a functional type.
+
Owned non-primary vindex must have a lookup type.
- - - - + + + {{item}} + + No tables found matching "{{vindex.Owner}}". +
+
Undefined Table
+
+
+
@@ -305,10 +319,10 @@ They are only used with the
-
+ + type="submit" ng-disabled="vindexForm.$invalid"> Add Vindex add @@ -329,16 +343,30 @@ They are only used with the {{item}} No vindex types found matching "{{newVindexType}}". -
+
Undefined Vindex Type
+
Owned primary vindex must have a functional type.
+
Owned non-primary vindex must have a lookup type.
- - - - + + + {{item}} + + No tables found matching "{{newVindexOwner}}". +
+
Undefined Table
+
+
+
diff --git a/web/vtctld/vschema/vschema.js b/web/vtctld/vschema/vschema.js index 33e16f276a..aec7c85071 100644 --- a/web/vtctld/vschema/vschema.js +++ b/web/vtctld/vschema/vschema.js @@ -1,50 +1,50 @@ vindexInfo = {}; vindexInfo.types = { - "numeric": { - "Type": "functional", - "Unique": true, - "Params": [] + 'numeric': { + type: 'functional', + unique: true, + params: [] }, - "hash": { - "Type": "functional", - "Unique": true, - "Params": [ - "Table", "Column" + 'hash': { + type: 'functional', + unique: true, + params: [ + 'Table', 'Column' ] }, - "hash_autoinc": { - "Type": "functional", - "Unique": true, - "Params": [ - "Table", "Column" + 'hash_autoinc': { + type: 'functional', + unique: true, + params: [ + 'Table', 'Column' ] }, - "lookup_hash": { - "Type": "lookup", - "Unique": false, - "Params": [ - "Table", "From", "To" + 'lookup_hash': { + type: 'lookup', + unique: false, + params: [ + 'Table', 'From', 'To' ] }, - "lookup_hash_unique": { - "Type": "lookup", - "Unique": true, - "Params": [ - "Table", "From", "To" + 'lookup_hash_unique': { + type: 'lookup', + unique: true, + params: [ + 'Table', 'From', 'To' ] }, - "lookup_hash_autoinc": { - "Type": "lookup", - "Unique": false, - "Params": [ - "Table", "From", "To" + 'lookup_hash_autoinc': { + type: 'lookup', + unique: false, + params: [ + 'Table', 'From', 'To' ] }, - "lookup_hash_unique_autoinc": { - "Type": "lookup", - "Unique": true, - "Params": [ - "Table", "From", "To" + 'lookup_hash_unique_autoinc': { + type: 'lookup', + unique: true, + params: [ + 'Table', 'From', 'To' ] } }; @@ -97,6 +97,15 @@ app.controller('VSchemaCtrl', function($scope, $mdDialog, }); }; + $scope.tableSelector = function(keyspace, searchText) { + if (!keyspace.Tables) return []; + var items = Object.keys(keyspace.Tables).sort(); + if (!searchText) return items; + return items.filter(function(item) { + return item.indexOf(searchText) != -1; + }); + }; + $scope.classSelector = function(keyspace, searchText) { if (!keyspace.Classes) return []; var items = Object.keys(keyspace.Classes).sort(); @@ -223,7 +232,7 @@ app.controller('VSchemaCtrl', function($scope, $mdDialog, $scope.onVindexTypeChange = function(vindex, type) { if (type in vindexInfo.types) { - params = vindexInfo.types[type].Params; + params = vindexInfo.types[type].params; if (!vindex.Params) vindex.Params = {}; @@ -286,6 +295,57 @@ app.directive('vindexType', function() { return viewValue in vindexInfo.types; return true; }; + ctrl.$validators.vownedPrimaryFunctional = function(modelValue, viewValue) { + var form = scope.vindexForm; + var type = viewValue; + var owner = form.vindexOwner.$modelValue; + var vindex = form.vindex.$modelValue; + if (owner && scope.keyspace.Tables[owner] + && type && vindexInfo.types[type] + && vindexInfo.types[type].type != 'functional') { + // It's owned and non-functional. Make sure it isn't a primary. + var classname = scope.keyspace.Tables[owner]; + if (classname && scope.keyspace.Classes[classname]) { + var cls = scope.keyspace.Classes[classname]; + if (cls.ColVindexes && cls.ColVindexes[0] + && cls.ColVindexes[0].Name == vindex) + return false; + } + } + return true; + }; + ctrl.$validators.vownedNonPrimaryLookup = function(modelValue, viewValue) { + var form = scope.vindexForm; + var type = viewValue; + var owner = form.vindexOwner.$modelValue; + var vindex = form.vindex.$modelValue; + if (owner && scope.keyspace.Tables[owner] + && type && vindexInfo.types[type] + && vindexInfo.types[type].type != 'lookup') { + // It's owned and non-lookup. Make sure it is a primary. + var classname = scope.keyspace.Tables[owner]; + if (classname && scope.keyspace.Classes[classname]) { + var cls = scope.keyspace.Classes[classname]; + if (cls.ColVindexes && cls.ColVindexes[0] + && cls.ColVindexes[0].Name != vindex) + return false; + } + } + return true; + }; + } + }; +}); + +app.directive('vindexOwner', function() { + return { + require: 'ngModel', + link: function(scope, elem, attrs, ctrl) { + ctrl.$validators.vdefined = function(modelValue, viewValue) { + if (viewValue) + return viewValue in scope.keyspace.Tables; + return true; + }; } }; });