不废话,直接上代码,请搜索 apply 为什需要在标准服务上掉呢。。。。 var app = angular.module('MyApp', ['ngResource','ngRoute','ngGrid']).config(function ($routeProvider) { $routeProvider .when('/store', { templateUrl: 'page/store.html', controller: '' }) .when('/schema', { templateUrl: 'page/schema.html', controller: '' }) .when('/storeinfo', { templateUrl: 'page/storeinfo.html', controller: '' }) }); var spacename =''; app.controller('storeManage', function ($scope) { $scope.storeView = true; $scope.schemaView = false; $scope.space = {name:"spaces",realname:""}; $scope.spaces = spaceModel; $scope.$on("storeChange", function (event, treeNode) { $scope.storeView = true; $scope.schemaView = false; $scope.$broadcast("storeChangeFromParent", treeNode); }); $scope.$on("schemaChange", function(event,treeNode){ $scope.storeView = false; $scope.schemaView = true; $scope.$broadcast("schemaChangeFromParent",treeNode); }); $scope.selectSpace=function(){ $("#spacemodal").modal(); } $scope.saveSpace = function(){ $scope.space = $scope.tempSpace; spacename = $scope.space.name; } $scope.cancelSpace = function(){ $scope.tempSpace = {}; } }); app.controller('storeTreeController', function ($scope) { }); app.controller('storeEdit',function($scope,$http,storeInstance,setMetaInstance,smeDeploySet,smeCreateSet,spaceSchema,StatusesConstant){ console.log("store controller init.........."); $scope.store = storeModel; $scope.indexInfo = indexModel; $scope.set = setModel; $scope.listElement = listElementModel; $scope.spaceSchemaList = spaceSchemaListModel; $scope.isBaseSchema = false; $scope.createStore = false; $scope.createSetMeta = false; $scope.firstShow = true; $scope.secondShow = false; console.log("show initial..............."); $scope.title = "查看数据集"; $scope.statuses = StatusesConstant; $("#schematree").hide(); $("#storetree").show(); $("#storePanel").show(); $("#schemaPanel").hide(); $scope.$on("storeChangeFromParent", function (event, treeNode) { if(treeNode.isParent == true){ $scope.title = "查看store"; $scope.firstShow = true; $scope.secondShow = false; $("#storePanel").show(); $("#schemaPanel").hide(); $scope.store = createStoreModel(); $scope.set = createSetModel(); $scope.$apply( storeInstance.get({setName:treeNode.name}).$promise.then( function(resolve){ $scope.store = resolve; if(typeof($scope.store.entitySetName) == "undefined"){ alert("获取store出错"); }else{ setMetaInstance.get({setMetaName:treeNode.name}).$promise.then( function(resolve){ $scope.set = resolve; if(typeof($scope.set.setName)=="undefined"){ $scope.set = createSetModel(); $scope.set.setName = $scope.store.entitySetName; $scope.createSetMeta = true; } }, function(reject){console.log("get SetMetadata failed"+reject)} ); } }, function(reject){console.log("get store failed")} )); $scope.set.appSpaceId = $scope.space.realname; $(".store_info").each(function(){ this.disabled = true; }); } }); $scope.createStore = function(){ $scope.store = createStoreModel(); $scope.set = createSetModel(); $scope.store.appSpaceId = $scope.space.realname; $scope.store.entitySetName = $scope.space.realname+"."; $("input,select,textarea").each(function(){ this.disabled = false; }); $scope.gridOptions.enableCellEdit = true; $scope.isCreate = true; $scope.firstShow = false; $scope.secondShow = true; $scope.title = "创建store"; } $scope.cancelStore = function(){ $scope.firstShow = true; $scope.secondShow = false; $(".store_info").each(function(){ this.disabled = true; }); $scope.title = "查看store"; } $scope.createStoreTable = function(){ smeDeploySet.deploy( {spaceName:$scope.space.realname}, function(data){ console.log("deploy success"); }, function(){ console.log("deploy failed"); }); } $scope.editStore = function(){ if($scope.store.entitySetName == ''){ alert("请先选择一个store"); return; } $(".ex_store_info").each(function(){ this.disabled = false; }); $scope.isCreate = false; $scope.firstShow = false; $scope.secondShow = true; $scope.title = "编辑store"; $scope.firstShow = false; $scope.secondShow = true; $scope.gridOptions.enableCellEdit = true; if($scope.set.entitySchemaList.length ==0){ $scope.createSetMeta = true; } }; $scope.saveStore = function(){ $scope.set.setName = $scope.store.entitySetName; $scope.set.appSpaceId = $scope.space.realname; if($scope.isCreate == true){ smeCreateSet.save({setName:$scope.store.entitySetName},$scope.store) if(typeof($scope.set.entitySchemaList)!="undefined" && $scope.set.entitySchemaList.length > 0){ setMetaInstance.put({setMetaName:$scope.set.setName},$scope.set) } } else{ storeInstance.save({setName:$scope.store.entitySetName},$scope.store); if(typeof($scope.set.entitySchemaList)!="undefined" && $scope.set.entitySchemaList.length > 0 ){ if($scope.createSetMeta == true){ setMetaInstance.put({setMetaName:$scope.set.setName},$scope.set); $scope.createSetMeta = false; }else setMetaInstance.save({setMetaName:$scope.set.setName},$scope.set); } } $scope.firstShow = true; $scope.secondShow = false; $scope.createSetMeta = false; $(".store_info").each(function(){ this.disabled = true; }); $scope.title = "查看数据集"; } $scope.createIndex = function(){ $("#input_index").show(); } $scope.quitIndex = function(){ $scope.indexInfo = ''; $("#input_index").hide(); } $scope.confirmIndex = function(){ $scope.store.index.push($scope.indexInfo); $scope.indexInfo = null; $("#input_index").hide(); } $scope.delIndex = function(index){ $scope.store.index.splice(index,1); }; $scope.createSchema = function(){ $("#input_schema").show(); var URL = "/MDE/DSE/EntitySchema?$filter=appSpace eq \'"+$scope.space.realname+"\'"; $http({ url:URL, method:"GET" }).success(function(data){ $scope.spaceSchemaList = data; }); } $scope.confirmSchema = function(){ var flag = true; var tempList = $scope.set.entitySchemaList; if(tempList.length > 1){ for(var i=0;i<tempList.length;i++){ if(tempList[i].schemaName == $scope.schemaName){ flag = false; alert("schema already exist"); } } } if(flag==true){ if($scope.isBaseSchema == "true"){ $scope.isBaseSchema = true; }else{ $scope.isBaseSchema = false; } $scope.set.entitySchemaList.push({ id: $scope.set.entitySchemaList.length+1, schemaName : $scope.schemaName, isBaseSchema:$scope.isBaseSchema } ); $("#input_schema").hide(); } } $scope.quitSchema = function(){ $scope.listElement = null; $("#input_schema").hide(); } $scope.delSchema = function(index){ $scope.set.entitySchemaList.splice(index,1); } $scope.pkeyTypes =dataTypeModel; $scope.storeTypes=storeTypeModel; $scope.markTypes = markTypeModel; $scope.indexTypes = dataTypeModel; // $scope.testData=[{col1:"fuck1",col2:"fuck2",col3:2,col4:"fuck4",col5:"fuck5"}, // {col1:"fuck12",col2:"fuck22",col3:1,col4:"fuck24",col5:"fuck25"}]; $scope.editDFV = function(){ console.log("edit dfv"); } $scope.deleteDFV = function(row){ $scope.store.defaultValues.remove(row.rowIndex); } $scope.selectCell ="<select ng-model='COL_FIELD' ng-class='\'colt\' + col.index' ng-input='COL_FIELD' ng-options='id as name for (id, name) in statuses' ng-blur='updateEntity(row)'></select>"; $scope.buttonCell = '<button class="btn btn-link" ng-click="deleteDFV(row)" ng-show="secondShow">删除</button>'; $scope.gridOptions = { data: 'store.defaultValues', enableCellEdit: true, columnDefs: [{field: "name",displayName:"名称"}, {field:"dType",displayName:"类型", editableCellTemplate: $scope.selectCell ,cellFilter: 'mapStatus'}, {field:"defaultValue",displayName:"默认值"}, {field:"evalExp",displayName:"表达式"}, {displayName:"操作",cellTemplate:$scope.buttonCell, enableCellEdit: false} ] }; $scope.createDefaultValue = function(){ // if(isNaN($scope.store.defaultValues)) $scope.store.defaultValues.unshift({name:null,dType:1,defaultValue:null,evalExp:null}); } $scope.updateEntity = function(row) { console.log("row",row); }; $scope.displayDefaultValue= function(row){ console.log($scope.store.defaultValues); } }); app.directive('ngBlur', function () { return function (scope, elem, attrs) { elem.bind('blur', function () { scope.$apply(attrs.ngBlur); }); }; }); app.filter('mapStatus', function( StatusesConstant ) { return function(input) { if (StatusesConstant[input]) { return StatusesConstant[input]; } else { return 'unknown'; } }; }) app.factory( 'StatusesConstant', function() { return { 1: 'preset', 2: 'evaljs' }; }); Array.prototype.remove=function(dx) { if(isNaN(dx)||dx>this.length){return false;} for(var i=0,n=0;i<this.length;i++) { if(this[i]!=this[dx]) { this[n++]=this[i] } } this.length-=1 } app.factory('storeInstance',['$http','$resource',function($http,$resource){ return $resource('/MDE/DSE/EntitySet(\':setName\')', {setName:'@setName'}, {create:{method:'PUT'},params:{},isArray:false} ) ; }]); app.factory('setMetaInstance',function($http,$resource){ return $resource( '/MDE/DSE/SetMetadata(\':setMetaName\')', {setMetaName:'@setMetaName'}, { put:{method:"PUT"}, params:{},isArray: false} ) });
html
<div class="row"> <div class="col-md-3"> <div class="zTreeDemoBackground left" ng-controller="storeTreeController"> <ul storetree id="treeDemo" class="ztree" showIcon="showIconForTree"></ul> </div> </div> <div ng-controller="storeEdit" id="storePanel" ng-show="storeView"> <div class="col-md-6"> <h4>{{title}}</h4> <div class="panel panel-info" > <div class="panel-heading "> 数据集管理 <button type="button" class="btn btn-primary btn-sm" ng-click="createStore()" ng-show="firstShow">新增</button> <button type="button" class="btn btn-primary btn-sm" ng-click="editStore()" ng-show="firstShow" >修改</button> <button type="button" class="btn btn-primary btn-sm" ng-click="saveStore()" ng-show="secondShow">保存</button> <button type="button" class="btn btn-primary btn-sm" ng-click="cancelStore()" ng-show="secondShow" >取消</button> <button type="button" class="btn btn-primary btn-sm" ng-click="createStoreTable()" ng-show="firstShow">发布</button> </div> <div class="panel-body"> <div class="panel panel-info"> <div class="panel-heading"> 数据集基础信息 </div> <div class="form-horizontal panel-body " style="padding-top: 40px;"> <div class="form-group " role="form" > <label class="col-md-2 control-label">数据集名称</label> <div class=" col-md-4"> <input type="text" class="form-control store_info" ng-model="store.entitySetName"> </div> <label class="col-md-2 control-label">AppSpaceId</label> <div class="col-md-4"> <input type="text" class="form-control store_info" ng-model="store.appSpaceId"> </div> </div> <div class="form-group"> <label class="col-md-2 control-label">主键</label> <div class="col-md-4"> <input type="text" class="form-control store_info ex_store_info" ng-model="store.pKey"> </div> <label class="col-md-2 control-label">主键类型</label> <div class="col-md-4"> <select ng-model="store.pkeyType" ng-options="o.id as o.name for o in pkeyTypes" class="form-control store_info ex_store_info"> <option >-- 请选择 --</option> </select> </div> </div> <div class="form-group"> <label class="col-md-2 control-label">存储类型</label> <div class="col-md-4"> <select ng-model="store._storageType" ng-options="o.id as o.name for o in storeTypes" class="form-control store_info ex_store_info"> <option >-- 请选择 --</option> </select> </div> </div> <div class="form-group"> <label class="col-md-2 control-label">描述</label> <div class="col-md-4"> <textarea class="form-control store_info ex_store_info" ng-model="store.description"></textarea> </div> </div> </div> <div class="panel panel-info" style="padding-top: 20px;"> <div class="panel-heading"> 索引信息 <button type="button" class="btn btn-primary btn-sm" ng-click="createIndex()" ng-show="secondShow">新增索引</button> </div><!-- panel-heading--> <div class="panel-body" > <table class="table display_table" > <col width="8%" /> <col width="15%" /> <col width="10%" /> <col width="15%" /> <col width="20%" /> <col width="20%" /> <col width="15%" /> <thead> <tr> <td>编号</td> <td>索引名称</td> <td>直接索引</td> <td>markType</td> <td>索引类型</td> <td>表达式</td> <td>   </td> </tr> </thead> <tbody> <tr id="input_index" style="display:none"> <td> </td> <td ><div><input type="text" ng-model="indexInfo.path" ></input></div></td> <td ><div><input type="text" ng-model="indexInfo.direct" ></input></div></td> <td ><select ng-model="indexInfo.markType " ng-options="o.id as o.name for o in markTypes" > <option ></option> </select> </td> <td > <select ng-model="indexInfo.indexDataType" class="selectdatatype" ng-options="o.id as o.name for o in indexTypes" > <option ></option> </select> </td> <td ><input type="text" ng-model="indexInfo.expression" ></input></td> <td ><button type="button" class="btn btn-primary btn-sm" ng-click=" confirmIndex()">确认</button> <button type="button" class="btn btn-primary btn-sm" ng-click="quitIndex()">取消</button> </td> </tr> <tr ng-repeat="o in store.index"> <td>{{$index+1}}</td> <td>{{o.path}}</td> <td>{{o.direct}}</td> <td ><select ng-model="o.markType" ng-options="o.id as o.name for o in markTypes" disabled="disabled"> <option ></option> </select> </td> <td > <select ng-model="o.indexDataType" class="selectdatatype" ng-options="o.id as o.name for o in indexTypes" disabled="disabled"> <option ></option> </select> </td> <td>{{o.expression}}</td> <td> <button type="button" class="btn btn-link btn-sm" ng-show="secondShow" ng-click="delIndex($index)">删除</button> </td> </tr> </tbody> </table> </div><!-- /.panel-body--> </div><!--panel--> <div class="panel panel-info" style="padding-top: 20px;" > <div class="panel-heading"> 默认值信息 <button type="button" class="btn btn-primary btn-sm" ng-click="createDefaultValue()" ng-show="secondShow">新增默认值</button> </div> <div> </div> <div class="panel-body"> <div class="gridStyle" ng-grid="gridOptions"></div> </div> </div> </div> </div> </div><!--mid-panel--> </div> <!--col-md-6--> <div class="col-md-3" ng-show="storeView"> <div class="panel panel-info" > <div class="panel-heading"> 所含Schema <button type="button" class="btn btn-primary btn-sm" ng-click="createSchema()" ng-show="secondShow">添加Schema</button> </div> <div class="panel-body"> <table class="table display_table"> <col width="10%" /> <col width="50%" /> <col width="20%" /> <col width="20%" /> <thead> <tr> <td> </td> <td>schema名称</td> <td>baseSchema</td> <td>   </td> </tr> </thead> <tr id="input_schema" style="display:none"> <td></td> <td > <select class="selectdatatype" ng-model="schemaName" > <option ng-repeat = "o in spaceSchemaList">{{o.id}}</option> </select> </td> <td> <select ng-model="isBaseSchema"> <option value="true">是</option> <option value="false">否</option> </select> </td> <td ><button type="button" class="btn btn-link" ng-click=" confirmSchema()">确认</button> <button type="button" class="btn btn-link" ng-click="quitSchema()">取消</button> </td> </tr> <tr ng-repeat="o in set.entitySchemaList"> <td>{{$index+1}}</td> <td>{{o.schemaName}}</td> <td>{{o.isBaseSchema}}</td> <td> <button type="button" class="btn btn-link" ng-click="delSchema($index)" ng-show="secondShow">删除</button> </td> </tr> </table> </div> </div> </div><!--right-bar--> </div> <div ng-controller="schemaEdit" id = "schemaPanel" ng-show="schemaView" > <div class="col-md-8"> <div class="panel panel-info"> <div class="panel-heading"> 实体元数据 </div> <div class="panel-body"> <div class="panel panel-info"> <div class="panel-heading"> 基本信息 </div> <div class="panel-body"> <div class="form-horizontal panel-body" style="padding-top: 40px;"> <div class="form-group" > <label class="col-md-2 control-label">id</label> <div class="col-md-4"> <input type="text" class="form-control schema_info" ng-model="schema.id"> </div> <label class="col-md-2 control-label">AppSpaceId</label> <div class="col-md-4"> <input type="text" class="form-control schema_info" ng-model="schema.appSpaceId"> </div> </div><!--form-group--> <div class="form-group"> <label class="col-md-2 control-label">实体集名称</label> <div class="col-md-4"> <input type="text" class="form-control schema_info" ng-model="schema.entitySetName"> </div> <label class="col-md-2 control-label">对象名</label> <div class="col-md-4"> <input type="text" class="form-control schema_info" ng-model="schema.entityName"> </div> </div><!--form-group--> <div class="form-group"> <label class="col-md-2 control-label">版本</label> <div class="col-md-4"> <input type="text" class="form-control schema_info" ng-model="schema.version"> </div> </div><!--form-group--> <div class="form-group"> <label class="col-md-2 control-label">描述</label> <div class="col-md-4"> <textarea class="form-control schema_info" ng-model="schema.description"></textarea> </div> </div><!--form-group--> </div><!--form--> </div><!--panel body--> <div class="panel panel-info"> <div class="panel-heading"> 详细信息 </div> <div class="panel-body"> <table class="table schema_table"> <col width="20%" /> <col width="15%" /> <col width="20%" /> <col width="20%" /> <col width="10%"/> <col width="15%"/> <thead> <tr> <td>名称</td> <td>pType</td> <td>复杂类型</td> <td>校验规则</td> <td>是否array</td> <td>  </td> </tr> </thead> <tbody> <tr id="input_property" ng-show='propertyShow'> <td ><input type="text" ng-model="property.name" ></input></td> <td ><input type="text" ng-model="property.pType" ></input></td> <td ><input type="text" ng-model="property.complexTypeName" ></input></td> <td ><input type="text" ng-model="property.verificationRegEx" ></input></td> </tr> <tr ng-repeat="o in schema.properties"> <td>{{o.name}}</td> <td><select ng-model="o.pType" ng-options="o.id as o.name for o in propertiesType" disabled="disabled"> <option ></option> </select></td> <td>{{o.complexTypeName}}</td> <td>{{o.verificationRegEx}}</td> <td>{{o.isArray}}</td> <td> </td> </tr> </tbody> </table> </div> </div> </div> </div> </div> </div> </div>