You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2016/12/20 11:26:23 UTC

[27/50] [abbrv] kylin git commit: KYLIN 1875 update modify alias

KYLIN 1875 update modify alias

Signed-off-by: zhongjian <ji...@163.com>


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/f55cc5c4
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/f55cc5c4
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/f55cc5c4

Branch: refs/heads/master-hbase1.x
Commit: f55cc5c446e8878d059019561894cc70bd0ab89b
Parents: e7cc152
Author: chenzhx <34...@qq.com>
Authored: Wed Dec 14 16:33:31 2016 +0800
Committer: Li Yang <li...@apache.org>
Committed: Thu Dec 15 18:57:36 2016 +0800

----------------------------------------------------------------------
 webapp/app/css/AdminLTE.css                     |   5 +
 webapp/app/js/controllers/modelDataModel.js     | 141 ++++++++++++-------
 webapp/app/js/controllers/modelEdit.js          |   8 +-
 webapp/app/js/services/tree.js                  |   3 +
 .../app/partials/modelDesigner/data_model.html  |  25 ++--
 5 files changed, 119 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/f55cc5c4/webapp/app/css/AdminLTE.css
----------------------------------------------------------------------
diff --git a/webapp/app/css/AdminLTE.css b/webapp/app/css/AdminLTE.css
index 6688457..857dbf7 100644
--- a/webapp/app/css/AdminLTE.css
+++ b/webapp/app/css/AdminLTE.css
@@ -4744,6 +4744,11 @@ Gradient Background colors
   opacity: 1;
   filter: alpha(opacity=100);
 }
+.model_graph svg{
+  width:1100px !important;
+  height:600px !important;
+}
+
 
 /*
  * Misc: print

http://git-wip-us.apache.org/repos/asf/kylin/blob/f55cc5c4/webapp/app/js/controllers/modelDataModel.js
----------------------------------------------------------------------
diff --git a/webapp/app/js/controllers/modelDataModel.js b/webapp/app/js/controllers/modelDataModel.js
index a09101b..b6edd43 100644
--- a/webapp/app/js/controllers/modelDataModel.js
+++ b/webapp/app/js/controllers/modelDataModel.js
@@ -22,7 +22,7 @@ KylinApp.controller('ModelDataModelCtrl', function ($location,$scope, $modal,cub
     $scope.modelsManager = modelsManager;
     angular.forEach($scope.modelsManager.selectedModel.lookups,function(joinTable){
       if(!joinTable.alias){
-           joinTable.alias=VdmUtil.removeNameSpace(joinTable.table);
+        joinTable.alias=VdmUtil.removeNameSpace(joinTable.table);
       }
     });
     $scope.init = function (){
@@ -110,10 +110,21 @@ KylinApp.controller('ModelDataModelCtrl', function ($location,$scope, $modal,cub
     $scope.editLookup = function (lookup) {
         $scope.lookupState.editingIndex = lookupList.indexOf(lookup);
         $scope.lookupState.editing = true;
-
         // Make a copy of model will be editing.
         $scope.newLookup = angular.copy(lookup);
+        $scope.newLookup.join.pk_type = [];
+        $scope.newLookup.join.fk_type = [];
+        $scope.newLookup.join.isCompatible=[];
         $scope.newLookup.joinTable=VdmUtil.getNameSpaceTopName($scope.newLookup.join.foreign_key[0]);
+        angular.forEach($scope.newLookup.join.primary_key,function(pk,index){
+            $scope.newLookup.join.pk_type[index] = TableModel.getColumnType(VdmUtil.removeNameSpace(pk),$scope.newLookup.table);
+            $scope.newLookup.join.fk_type[index] = TableModel.getColumnType(VdmUtil.removeNameSpace($scope.newLookup.join.foreign_key[index]),$scope.aliasTableMap[$scope.newLookup.joinTable]);
+            if($scope.newLookup.join.pk_type[index]!==$scope.newLookup.join.fk_type[index]){
+               $scope.newLookup.join.isCompatible[index]=false;
+            }else{
+               $scope.newLookup.join.isCompatible[index]=true;
+            }
+        });
         $scope.openLookupModal();
     };
 
@@ -129,24 +140,51 @@ KylinApp.controller('ModelDataModelCtrl', function ($location,$scope, $modal,cub
 
     $scope.doneEditLookup = function () {
         // Copy edited model to destination model.
-        $scope.aliasTableMap[VdmUtil.removeNameSpace($scope.modelsManager.selectedModel.fact_table)]=$scope.modelsManager.selectedModel.fact_table;
-        $scope.aliasName=[VdmUtil.removeNameSpace($scope.modelsManager.selectedModel.fact_table)];
         angular.copy($scope.newLookup, lookupList[$scope.lookupState.editingIndex]);
-        angular.forEach(lookupList,function(joinTable){
-          $scope.aliasName.push(joinTable.alias);
-          $scope.aliasTableMap[joinTable.alias]=joinTable.table;
-         // $scope.tableAliasMap[joinTable.alias]=joinTable.table;
-        });
+        var oldAlias=$scope.aliasName[$scope.lookupState.editingIndex+1];
+        var newAlias=$scope.newLookup.alias;
+        if(oldAlias!=newAlias){
+          $scope.aliasName[$scope.lookupState.editingIndex+1]=newAlias;
+          for(var i=0;i<$scope.newLookup.join.primary_key.length;i++){
+            $scope.newLookup.join.primary_key[i]=$scope.newLookup.join.primary_key[i].replace(oldAlias+'.',newAlias+'.');
+          }
+
+          delete $scope.aliasTableMap[oldAlias];
+          $scope.aliasTableMap[newAlias]=$scope.newLookup.table;
+
+          for(var i=0;i<lookupList.length;i++){
+            for(var j=0;j<lookupList[i].join.foreign_key.length;j++){
+             lookupList[i].join.foreign_key[j]=lookupList[i].join.foreign_key[j].replace(oldAlias+'.',newAlias+'.');
+            }
+          }
+
+          for(var i=0;i<modelsManager.selectedModel.dimensions.length;i++){
+            if(modelsManager.selectedModel.dimensions[i].table==oldAlias){
+              modelsManager.selectedModel.dimensions[i].table=newAlias;
+            }
+          }
+
+          if($scope.newLookup.kind=="FACT"){
+            for(var i=0;i< modelsManager.selectedModel.metrics.length;i++){
+               modelsManager.selectedModel.metrics[i]= modelsManager.selectedModel.metrics[i].replace(oldAlias+'.',newAlias+'.');
+            }
+            modelsManager.selectedModel.partition_desc.partition_date_column = modelsManager.selectedModel.partition_desc.partition_date_column.replace(oldAlias+'.',newAlias+'.');
+          }
+        }
+        angular.copy($scope.newLookup,lookupList[$scope.lookupState.editingIndex]);
 
         $scope.resetParams();
     };
     $scope.changeFactTable = function () {
-        delete $scope.aliasTableMap[VdmUtil.removeNameSpace($scope.modelsManager.selectedModel.fact_table)];
+        $scope.aliasTableMap={};
         $scope.aliasTableMap[VdmUtil.removeNameSpace($scope.FactTable.root)]=$scope.FactTable.root;
-        delete $scope.tableAliasMap[$scope.modelsManager.selectedModel.fact_table];
+        $scope.tableAliasMap={};
         $scope.tableAliasMap[$scope.FactTable.root]=VdmUtil.removeNameSpace($scope.FactTable.root);
-        $scope.aliasName.splice($scope.aliasName.indexOf(VdmUtil.removeNameSpace($scope.modelsManager.selectedModel.fact_table)),1);
-        $scope.aliasName.push(VdmUtil.removeNameSpace($scope.FactTable.root));
+        $scope.aliasName=[VdmUtil.removeNameSpace($scope.FactTable.root)];
+        modelsManager.selectedModel.lookups = [];
+        modelsManager.selectedModel.dimensions = [];
+        modelsManager.selectedModel.metrics= [];
+        modelsManager.selectedModel.partition_desc.partition_date_column = null;
         $scope.modelsManager.selectedModel.fact_table=$scope.FactTable.root;
     }
     $scope.changeJoinTable = function () {
@@ -158,7 +196,7 @@ KylinApp.controller('ModelDataModelCtrl', function ($location,$scope, $modal,cub
 
     $scope.removeLookup = function (lookup) {
         var dimExist = _.some(modelsManager.selectedModel.dimensions,function(item,index){
-            return item.alias===lookup.alias;
+            return item.table===lookup.alias;
         });
         if(dimExist) {
             SweetAlert.swal({
@@ -172,7 +210,7 @@ KylinApp.controller('ModelDataModelCtrl', function ($location,$scope, $modal,cub
             }, function (isConfirm) {
                 if (isConfirm) {
                     for (var i = modelsManager.selectedModel.dimensions.length - 1; i >= 0; i--) {
-                        if (modelsManager.selectedModel.dimensions[i].alias === lookup.alias) {
+                        if (modelsManager.selectedModel.dimensions[i].table === lookup.alias) {
                             modelsManager.selectedModel.dimensions.splice(i, 1);
                         }
                     }
@@ -187,13 +225,13 @@ KylinApp.controller('ModelDataModelCtrl', function ($location,$scope, $modal,cub
     }
 
     $scope.changeKey = function(index){
-         var join_table = $scope.newLookup.jointable;
+         var join_table = $scope.newLookup.joinTable;
          var lookup_table = $scope.newLookup.table;
          var pk_column = $scope.newLookup.join.primary_key[index];
          var fk_column = $scope.newLookup.join.foreign_key[index];
          if(pk_column!=='null'&&fk_column!=='null'){
-             $scope.newLookup.join.pk_type[index] = TableModel.getColumnType(pk_column,lookup_table);
-             $scope.newLookup.join.fk_type[index] = TableModel.getColumnType(fk_column,join_table);
+            $scope.newLookup.join.pk_type[index] = TableModel.getColumnType(VdmUtil.removeNameSpace(pk_column),$scope.newLookup.table);
+            $scope.newLookup.join.fk_type[index] = TableModel.getColumnType(VdmUtil.removeNameSpace(fk_column),$scope.aliasTableMap[$scope.newLookup.joinTable]);
             if($scope.newLookup.join.pk_type[index]!==$scope.newLookup.join.fk_type[index]){
                $scope.newLookup.join.isCompatible[index]=false;
             }else{
@@ -226,34 +264,43 @@ KylinApp.controller('ModelDataModelCtrl', function ($location,$scope, $modal,cub
     };
 
     $scope.checkLookupForm = function(){
-            var errors = [];
-            // null validate
-            for(var i = 0;i<$scope.newLookup.join.primary_key.length;i++){
-                if($scope.newLookup.join.primary_key[i]==='null'){
-                    errors.push("Primary Key can't be null.");
-                    break;
-                }
-            }
-            for(var i = 0;i<$scope.newLookup.join.foreign_key.length;i++){
-                if($scope.newLookup.join.foreign_key[i]==='null'){
-                    errors.push("Foreign Key can't be null.");
-                    break;
-                }
-            }
-
-            var errorInfo = "";
-            angular.forEach(errors,function(item){
-                errorInfo+="\n"+item;
-            });
-            if(errors.length){
-//                SweetAlert.swal('Warning!', errorInfo, '');
-                SweetAlert.swal('', errorInfo, 'warning');
-                return false;
-            }else{
-                return true;
-            }
-
+      var errors = [];
+      for(var i = 0;i<$scope.newLookup.join.primary_key.length;i++){
+        if($scope.newLookup.join.primary_key[i]==='null'){
+          errors.push("Primary Key can't be null.");
+          break;
+        }
+      }
+      for(var i = 0;i<$scope.newLookup.join.foreign_key.length;i++){
+        if($scope.newLookup.join.foreign_key[i]==='null'){
+          errors.push("Foreign Key can't be null.");
+          break;
+        }
+      }
+      if($scope.aliasName.indexOf($scope.newLookup.alias)!=-1&&$scope.lookupState.editing == false){
+        errors.push("Table Alias ["+$scope.newLookup.alias+"] already exist!");
+      }
+      if($scope.aliasName.indexOf($scope.newLookup.alias)!=-1&&$scope.aliasName[$scope.lookupState.editingIndex+1] != $scope.newLookup.alias){
+        errors.push("Table Alias ["+$scope.newLookup.alias+"] already exist!");
+      }
+      var errorInfo = "";
+      angular.forEach(errors,function(item){
+        errorInfo+="\n"+item;
+      });
+      if(errors.length){
+        SweetAlert.swal('', errorInfo, 'warning');
+        return false;
+      }else{
+        return true;
+      }
     };
-
-
+    $scope.filterNotRoot = function (item) {
+      return item.name!==modelsManager.selectedModel.fact_table;
+    };
+/*    $scope.$watch('$scope.newLookup.alias', function (newValue, oldValue) {
+      if (newValue&&$scope.lookupState.editing ) {
+        console.log(newValue);
+        console.log(oldValue);
+      }
+    });*/
 });

http://git-wip-us.apache.org/repos/asf/kylin/blob/f55cc5c4/webapp/app/js/controllers/modelEdit.js
----------------------------------------------------------------------
diff --git a/webapp/app/js/controllers/modelEdit.js b/webapp/app/js/controllers/modelEdit.js
index 4d1e12c..fd78d03 100644
--- a/webapp/app/js/controllers/modelEdit.js
+++ b/webapp/app/js/controllers/modelEdit.js
@@ -19,7 +19,7 @@
 'use strict';
 
 
-KylinApp.controller('ModelEditCtrl', function ($scope, $q, $routeParams, $location, $templateCache, $interpolate, MessageService, TableService, CubeDescService, ModelService, loadingRequest, SweetAlert,$log,cubeConfig,CubeDescModel,ModelDescService,MetaModel,TableModel,ProjectService,ProjectModel,modelsManager,VdmUtil) {
+KylinApp.controller('ModelEditCtrl', function ($scope, $q, $routeParams, $location, $templateCache, $interpolate, MessageService, TableService, CubeDescService, ModelService, loadingRequest, SweetAlert,$log,cubeConfig,CubeDescModel,ModelDescService,MetaModel,TableModel,ProjectService,ProjectModel,modelsManager, CubeService, VdmUtil) {
     //add or edit ?
     var absUrl = $location.absUrl();
     $scope.tableAliasMap={};
@@ -93,9 +93,9 @@ KylinApp.controller('ModelEditCtrl', function ($scope, $q, $routeParams, $locati
       ModelDescService.query({model_name: modelName}, function (model) {
         if (model) {
           modelsManager.selectedModel = model;
-          if($scope.modelsManager.selectedModel.partition_desc.partition_time_column){
-            $scope.partitionColumn.hasSeparateTimeColumn = true;
-          }
+          CubeService.list({modelName:model.name}, function (_cubes) {
+              $scope.cubesLength = _cubes.length;
+          });
           modelsManager.selectedModel.project = ProjectModel.getProjectByCubeModel(modelName);
           if(!ProjectModel.getSelectedProject()){
             ProjectModel.setSelectedProject(modelsManager.selectedModel.project);

http://git-wip-us.apache.org/repos/asf/kylin/blob/f55cc5c4/webapp/app/js/services/tree.js
----------------------------------------------------------------------
diff --git a/webapp/app/js/services/tree.js b/webapp/app/js/services/tree.js
index 08e290b..20de19b 100755
--- a/webapp/app/js/services/tree.js
+++ b/webapp/app/js/services/tree.js
@@ -47,6 +47,9 @@ KylinApp.service('ModelGraphService', function (VdmUtil) {
         model.graph = (!!model.graph) ? model.graph : {};
 
         angular.forEach(model.lookups,function (lookup, index) {
+          if(!lookup.alias){
+            lookup.alias=VdmUtil.removeNameSpace(lookup.table);
+          }
           if (lookup.join && lookup.join.primary_key.length > 0) {
             var  dimensionNode={
                 "type": lookup.kind,

http://git-wip-us.apache.org/repos/asf/kylin/blob/f55cc5c4/webapp/app/partials/modelDesigner/data_model.html
----------------------------------------------------------------------
diff --git a/webapp/app/partials/modelDesigner/data_model.html b/webapp/app/partials/modelDesigner/data_model.html
index f1192f4..e032cf9 100644
--- a/webapp/app/partials/modelDesigner/data_model.html
+++ b/webapp/app/partials/modelDesigner/data_model.html
@@ -29,7 +29,7 @@
               <select chosen ng-model="FactTable.root" ng-if="state.mode=='edit'"
                       ng-options="table.name as table.name for table in tableModel.selectProjectTables"
                       style="width:100%;" ng-change="changeFactTable()"
-                      name="table_name"
+                      name="table_name"   ng-disabled="cubesLength>0"
                       ng-required="true"
                       data-placeholder="Fact Table Name"
                       class="chosen-select">
@@ -92,17 +92,18 @@
                     <ul class="list-unstyled">
                         <li ng-repeat="pk in lookup.join.primary_key track by $index">
                             <code>{{lookup.join.foreign_key[$index]}} = {{pk}}</code>
+
                         </li>
                     </ul>
                 </td>
                 <td ng-if="state.mode=='edit'">
                     <!-- edit button -->
-                    <button class="btn btn-xs btn-info" ng-disabled="lookupState.editing"
-                            ng-click="editLookup(lookup)" tooltip="Edit Lookup"><i class="fa fa-pencil"></i>
+                    <button class="btn btn-xs btn-info" ng-disabled="lookupState.editing||cubesLength>0"
+                            ng-click="editLookup(lookup)" ><i class="fa fa-pencil"></i>
                     </button>
                     <!-- remove button -->
-                    <button class="btn btn-xs btn-danger" ng-disabled="lookupState.editing"
-                            ng-click="removeLookup(lookup)" tooltip="Remove Lookup"><i class="fa fa-trash-o"></i>
+                    <button class="btn btn-xs btn-danger" ng-disabled="lookupState.editing||cubesLength>0"
+                            ng-click="removeLookup(lookup)" ><i class="fa fa-trash-o"></i>
                     </button>
                 </td>
             </tr>
@@ -126,17 +127,17 @@
                             <div>
                               <select chosen ng-model="newLookup.joinTable" style="width: 45%"
                                       ng-options="table as table for table in aliasName"
-                                      name="table_name"
+                                      name="table_name"  ng-disabled="lookupState.editing"
                                       ng-required="true"
                                       data-placeholder="Join Table Name"
                                       class="chosen-select">
                                 <option value=""> &#45;&#45; Select Join Table &#45;&#45; </option>
                               </select>
                               <small class="help-block" ng-show="lookup_form.table_name.$invalid && (lookup_form.table_name.$dirty||forms.model_info_form.$submitted)">Table name required</small>
-                              <b>&nbsp;</b>
+                              <b>&nbsp;&nbsp;&nbsp;</b>
                               <select chosen ng-model="newLookup.table" style="width: 45%"
-                                      ng-options="table.name as table.name for table in tableModel.selectProjectTables"
-                                      name="table_name"
+                                      ng-options="table.name as table.name for table in tableModel.selectProjectTables|filter:filterNotRoot"
+                                      name="table_name"  ng-disabled="lookupState.editing"
                                       ng-required="true"  ng-change="changeJoinTable()"
                                       data-placeholder="Join Table Name"
                                       class="chosen-select">
@@ -146,7 +147,6 @@
 
                             </div>
                             <div class="space-4"></div>
-                            <small class="help-block red" ng-show="newLookup.join.isCompatible[$index]==false"><i class="fa fa-exclamation-triangle"></i> <b>Column Type incompatible {{newLookup.join.foreign_key[$index]}}[{{newLookup.join.fk_type[$index]}}], {{newLookup.join.primary_key[$index]}} [{{newLookup.join.pk_type[$index]}}]</b></small>
                           </div>
                         </div>
                       </div>
@@ -154,8 +154,9 @@
                         <div class="row">
                             <label class="col-sm-3 control-label font-color-default"><b>Alias</b></label>
                             <div class="col-sm-6">
-                              <input type="text" class="form-control " placeholder="Input Table Alias" ng-required="true"
-                                     ng-model="newLookup.alias" ng-change="changeAlias()" ng-disabled="">
+                              <input type="text" class="form-control " name="joinTable_alias" placeholder="Input Table Alias" ng-required="true"
+                                     ng-model="newLookup.alias" ng-change="changeAlias()"  ng-pattern="/^\w+$/">
+                              <small class="help-block red" ng-show="!lookup_form.joinTable_alias.$error.required&&lookup_form.joinTable_alias.$invalid && (lookup_form.joinTable_alias.$dirty||lookup_form.$submitted)"><i class="fa fa-exclamation-triangle"></i>&nbsp;&nbsp; Alias is invalid.</small>
                             </div>
                         </div>
                     </div>