cmdbViewCtrl.js 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661
  1. 'use strict';
  2. app.controller('cmdbViewCtrl', ["$rootScope","$scope", "$state", "$timeout", "$interval", "$aside", "SweetAlert", "toaster", "Restangular", "api_bpm_domain", "api_configure_data", "api_cmdb", "api_configure_form", function ($rootScope, $scope, $state, $timeout, $interval, $aside, SweetAlert, toaster, Restangular, api_bpm_domain, api_configure_data, api_cmdb, api_configure_form) {
  3. var width = $scope.width = 650;
  4. var height = $scope.height = 400;
  5. var apple_selected, tree, treedata_avm, treedata_geography;
  6. $scope.my_tree_handler = function (branch) {
  7. //var _ref;
  8. var classify=$scope.classify=branch.prefix.toLowerCase()+branch.sign;
  9. api_cmdb.query({'sign':classify}).then(function(data){
  10. var myData = Restangular.stripRestangular(data);
  11. console.log(myData.data.node);
  12. if(myData.data&&myData.status==200){
  13. var ret = myData.data;
  14. redrawSvg(myData);
  15. }
  16. });
  17. };
  18. $scope.my_data = [];
  19. function convertListToTree(data, treeMap){
  20. var idToNodeMap = {}; //Keeps track of nodes using id as key, for fast lookup
  21. var root = null; //Initially set our loop to null
  22. var parentNode = null;
  23. //loop over data
  24. for(var i = 0; i < data.length; i++) {
  25. var datum = data[i];
  26. //each node will have children, so let's give it a "children" poperty
  27. datum.children = [];
  28. //add an entry for this node to the map so that any future children can
  29. //lookup the parent
  30. idToNodeMap[datum.id] = datum;
  31. //Does this node have a parent?
  32. if(typeof datum.parent === "undefined" || datum.parent == null) {
  33. //Doesn't look like it, so this node is the root of the tree
  34. root = datum;
  35. treeMap[datum.id] = root;
  36. } else {
  37. //This node has a parent, so let's look it up using the id
  38. parentNode = idToNodeMap[datum.parent.id];
  39. //We don't need this property, so let's delete it.
  40. delete datum.parent;
  41. //Let's add the current node as a child of the parent node.
  42. parentNode.children.push(datum);
  43. }
  44. }
  45. return root;
  46. }
  47. function convertParentToChildList(data){
  48. var treeMap = {};
  49. var list=[];
  50. convertListToTree(data, treeMap);
  51. angular.forEach(treeMap,function(item){
  52. list.push(item);
  53. });
  54. return list;
  55. }
  56. $scope.my_tree = tree = {};
  57. $scope.try_async_load = function () {
  58. $scope.my_data = [];
  59. $scope.select_treedata = [];
  60. $scope.doing_async = true;
  61. api_configure_data.fetchDataList('ciclassify',{'idx':0,'sum':100}).then(function(result){
  62. //console.log(result['list']);
  63. $scope.select_treedata = $scope.my_data = convertParentToChildList(result['list']);
  64. $scope.doing_async = false;
  65. tree.expand_all();
  66. //console.log(treelist);
  67. });
  68. };
  69. $scope.select_treedata = [];
  70. $scope.propTypeOptions = [];
  71. $scope.try_async_load();
  72. $scope.onFilterCallback = function(item){
  73. //console.log(item);
  74. if(angular.isDefined(item.children)&&item.children.length>=1){
  75. //not valid
  76. }else{
  77. var tempclassify=item.prefix.toLowerCase()+item.sign;
  78. $scope.cifilter_classic=tempclassify;
  79. api_configure_form.renderTabForm(tempclassify).then(function(data){
  80. var myData = Restangular.stripRestangular(data);
  81. $scope.propTypeOptions = myData;
  82. });
  83. }
  84. }
  85. $scope.onPropTypeChange = function(form){
  86. $scope.propOptions = form.fields;
  87. }
  88. $scope.onPropChange = function(prop){
  89. $scope.cifilter_prop = prop;
  90. }
  91. $scope.searchCI = function(searchKey, propObj, ciclassify){
  92. //if(searchKey!=null&&searchKey.length>1){
  93. var searchData = {};
  94. if(angular.isUndefined(propObj)){
  95. propObj = $scope.cifilter_prop;
  96. }
  97. if(angular.isUndefined(ciclassify)){
  98. ciclassify = $scope.cifilter_classic;
  99. }
  100. searchData['sign']=ciclassify;
  101. if(angular.isDefined(propObj)){
  102. searchData[propObj.key] = searchKey;
  103. }
  104. api_cmdb.query(searchData).then(function(response){
  105. var data=Restangular.stripRestangular(response);
  106. //此处不清空nodes
  107. var node=data.data.node;
  108. var tempNode=[];
  109. //nodes 或者links 要去重
  110. for(var i=0;i<node.length;i++){
  111. var tmp=0;
  112. for(var j=0;j<nodes.length;j++){
  113. if(node[i].uuid==nodes[j].uuid){
  114. tmp++;
  115. break;
  116. }
  117. }
  118. if(tmp==0){
  119. tempNode.push(node[i]);
  120. }
  121. }
  122. for(var i=0;i<tempNode.length;i++){//nodes 不清空
  123. nodes.push(tempNode[i]);
  124. }
  125. restart();
  126. })
  127. //}
  128. }
  129. $scope.refresh = function(){
  130. nodes.length=0;
  131. links.length=0;
  132. restart();
  133. }
  134. $scope.remove = function(){
  135. if($scope.selected_link==null){
  136. SweetAlert.swal({
  137. title: "错误的操作!",
  138. text: "没有资产关系被选中!",
  139. type: "error"
  140. });
  141. }else if($scope.selected_node!=null){
  142. SweetAlert.swal({
  143. title: "错误的操作!",
  144. text: "资产不能在此处删除!",
  145. type: "error"
  146. });
  147. }else if($scope.selected_link.id==-1){
  148. SweetAlert.swal({
  149. title: "错误的操作!",
  150. text: "资产关系尚未提交,不能删除!",
  151. type: "error"
  152. });
  153. }else if($scope.selected_link!=null){
  154. var id=$scope.selected_link.id;
  155. var label = $scope.selected_link.name;
  156. for(var i=0;i<linkType.length;i++){
  157. if(linkType[i].type==$scope.selected_link.name){
  158. label=linkType[i].label;
  159. }
  160. }
  161. SweetAlert.swal({
  162. title: "确认删除资产关系-"+ label +"?" ,
  163. text: "删除资产关系-"+ label + "以后,你将不能恢复该数据!",
  164. type: "warning",
  165. cancelButtonText: "取消",
  166. showCancelButton: true,
  167. confirmButtonColor: "#DD6B55",
  168. confirmButtonText: "确认删除!"
  169. }, function (isConfirm) {
  170. if (isConfirm) {
  171. api_cmdb.removeRef(id).then(function(response){
  172. if(response&&response.status==200){
  173. links.splice(links.indexOf($scope.selected_link), 1);
  174. restart();
  175. }else{
  176. SweetAlert.swal({
  177. title: "系统错误!",
  178. text: "系统错误,请稍候重试或者联系管理员!",
  179. type: "error"
  180. });
  181. }
  182. });
  183. }
  184. });
  185. }
  186. }
  187. $scope.traversal = function(){
  188. if($scope.selected_node==null){
  189. SweetAlert.swal({
  190. title: "错误的操作!",
  191. text: "没有资产被选中!",
  192. type: "error"
  193. });
  194. }else{
  195. var uuid = $scope.selected_node.uuid;
  196. api_cmdb.traversal(uuid).then(function(response){
  197. var d=response.data;
  198. var node=d.node;
  199. var link=d.edge;
  200. var tempNode=[];
  201. var tempLink=[];
  202. //nodes 或者links 要去重
  203. for(var i=0;i<node.length;i++){
  204. var tmp=0;
  205. for(var j=0;j<nodes.length;j++){
  206. if(node[i].id==nodes[j].id){
  207. tmp++;
  208. break;
  209. }
  210. }
  211. if(tmp==0){
  212. tempNode.push(node[i]);
  213. }
  214. }
  215. for(var i=0;i<link.length;i++){
  216. var tmp=0;
  217. for(var j=0;j<links.length;j++){
  218. if(link[i].id==links[j].id){
  219. tmp++;
  220. break;
  221. }
  222. }
  223. if(tmp==0){
  224. tempLink.push(link[i]);
  225. }
  226. }
  227. //数据写入页面
  228. for(var i=0;i<tempNode.length;i++){//nodes 不清空
  229. nodes.push(tempNode[i]);
  230. }
  231. for(var i=0;i<tempLink.length;i++){//link 不清空
  232. links.push(tempLink[i]);
  233. }
  234. //links转换
  235. for(var i=0;i<links.length;i++){
  236. for(var j=0;j<nodes.length;j++){
  237. if(links[i].source==nodes[j].id){
  238. links[i].source=nodes[j];
  239. }
  240. if(links[i].target==nodes[j].id){
  241. links[i].target=nodes[j];
  242. }
  243. }
  244. }
  245. restart();
  246. })
  247. }
  248. }
  249. var svg = d3.select('#cmdbSVG').append('svg').attr('width', width).attr('height', height);
  250. // set up initial nodes and links
  251. // - nodes are known by 'id', not by index in array.
  252. // - reflexive edges are indicated on the node (as a bold black circle).
  253. // - links are always source < target; edge directions are set by 'left' and 'right'.
  254. var nodes = [],links = [];
  255. var treeNodes=[];
  256. //读取labels (node)
  257. var labels=[];
  258. //console.log(window.basePath);
  259. // d3.xhr(window.basePath+"/api/cm/labels").send("GET", function(error, json) {
  260. // if (!error){
  261. // labels=JSON.parse(json.responseText);
  262. // //加载资产类型下拉框
  263. // //treeNodes
  264. // for(var i=0;i<labels.length;i++){
  265. // var tmp=labels[i];
  266. // if(tmp.pid!=null){
  267. // tmp['pid']=tmp['pid'].id;
  268. // }else{
  269. // tmp['pid']=0;
  270. // }
  271. // treeNodes.push(tmp);
  272. // }
  273. // window.labelNodes = treeNodes;
  274. // $.fn.zTree.init($("#treeDemo"), setting, treeNodes);
  275. // //label 类型显示
  276. // d3.select("#rowDiv").selectAll('li')
  277. // .data(labels).enter()
  278. // .append('li')
  279. // .html(function(d){
  280. // return '<i class="icon iconfont">'+d.iconname+'</i><p>'+d.label+'</p>';
  281. // }).on('click',function(d){
  282. // //查询节点
  283. // query(d.sign,"");
  284. // });
  285. // }else{
  286. // jAlert("服务器请求异常",'提示');
  287. // }
  288. // });
  289. function hideLinkForm(hide){
  290. $scope.hideLink=hide;
  291. }
  292. function hideFeedForm(hide){
  293. $scope.hideFeed=hide;
  294. }
  295. function redrawSvg(json){
  296. nodes.length=0;//先清空
  297. links.length=0;
  298. var data=json.data;
  299. for(var i=0;i<data.node.length;i++){
  300. nodes.push(data.node[i]);
  301. }
  302. //TODO
  303. //hideFeedForm(true);;
  304. //hideLinkForm(true);
  305. restart();
  306. }
  307. $scope.query = function(){
  308. //if(d3.event.keyCode=13){
  309. queryProp("","");
  310. //}
  311. }
  312. var queryProp = function(label, prop){
  313. var data = {sign:label,q:prop};
  314. api_cmdb.query(data).then(function(response){
  315. if(response&&(response.status==200)){
  316. var data=response.data;
  317. //此处不清空nodes
  318. for(var i=0;i<data.node.length;i++){
  319. nodes.push(data.node[i]);
  320. }
  321. restart();
  322. }else{
  323. SweetAlert.swal({
  324. title: "提示!",
  325. text: "访问服务器出错!",
  326. type: "error"
  327. });
  328. }
  329. })
  330. }
  331. /*
  332. //查询输入框 回车事件
  333. d3.select("#query").on('keyup',function(){
  334. if(d3.event.keyCode==13){
  335. var q=this.value;
  336. query("",q);
  337. }
  338. });
  339. //label 查询或者条件查询
  340. function query(label,q){
  341. $.ajax({
  342. type: "GET",
  343. url: window.basePath +"/api/cmdb/ci",
  344. data: {lb :label ,q: q},
  345. dataType: "json",
  346. success:function(json){
  347. nodes.length=0;//先清空
  348. links.length=0;
  349. var data=json.data;
  350. for(var i=0;i<data.node.length;i++){
  351. nodes.push(data.node[i]);
  352. }
  353. hideFeedForm(true);;
  354. hideLinkForm(true);
  355. restart();
  356. },
  357. error:function(){
  358. SweetAlert.swal({
  359. title: "提示!",
  360. text: "访问服务器出错!",
  361. type: "error"
  362. });
  363. }
  364. });
  365. }
  366. */
  367. //读取status (节点 连线)
  368. var statuses=[];
  369. api_configure_data.fetchDataList('cistatus',{'idx':0,'sum':100}).then(function(result){
  370. if (result&&result.status==200){
  371. d3.select('#nodeStatus').selectAll('option')
  372. .data(statuses).enter()
  373. .append('option')
  374. .attr('value',function(d){return d.code;})
  375. .html(function(d){ return d.desc;});
  376. }else{
  377. SweetAlert.swal({
  378. title: "提示!",
  379. text: "服务器请求异常!",
  380. type: "error"
  381. });
  382. }
  383. });
  384. //读取types (node)
  385. // api_configure_data.fetchDataList('cistatus',{'idx':0,'sum':100}).then(function(result){
  386. // if (result&&result.status==200){
  387. // d3.select('#nodeType').selectAll('option')
  388. // .data(types).enter()
  389. // .append('option')
  390. // .attr('value',function(d){return d.source;})
  391. // .html(function(d){ return d.description;});
  392. // }else{
  393. // SweetAlert.swal({
  394. // title: "提示!",
  395. // text: "服务器请求异常!",
  396. // type: "error"
  397. // });
  398. // }
  399. // });
  400. /*
  401. //读取所有params
  402. initParams();
  403. var params=[];
  404. //更新加载最新的params
  405. function initParams(){
  406. d3.xhr(window.basePath+"/api/cm/dynparams").send("GET", function(error, json) {
  407. if (!error){
  408. params=JSON.parse(json.responseText);
  409. if(selected_node){
  410. shownode();
  411. }else if(selected_link){
  412. showLink();
  413. }
  414. }else{
  415. jAlert("服务器请求异常","提示");
  416. }
  417. });
  418. }
  419. */
  420. //查询relationship_type表 name 为表里的type,label为显示值
  421. var linkType=[];
  422. function fetchEdgeTypes(){
  423. api_configure_data.fetchDataList('ciedgetype',{'idx':0,'sum':100}).then(function(response){
  424. if(response){
  425. if(response['list']){
  426. linkType = response['list'];
  427. d3.select('#linkName').selectAll('option')
  428. .data(linkType).enter()
  429. .append('option')
  430. .attr('value',function(d){return d.type;})
  431. .html(function(d){ return d.label;});
  432. }else{
  433. SweetAlert.swal({
  434. title: "提示!",
  435. text: "服务器请求异常!",
  436. type: "error"
  437. });
  438. }
  439. }else{
  440. SweetAlert.swal({
  441. title: "提示!",
  442. text: "服务器请求异常!",
  443. type: "error"
  444. });
  445. }
  446. })
  447. }
  448. fetchEdgeTypes();
  449. //设置cost 只能输入整形 最大值为1
  450. // d3.select('#linkCost').on('keyup',function(){
  451. // this.value= this.value.replace(/[^\d.]/g,function(){jAlert('只能输入数字!',"提示");return '';});
  452. // if(this.value>1){
  453. // jAlert('最大输入值为1','提示');
  454. // this.value='';
  455. // return;
  456. // }
  457. // });
  458. //添加属性 属性类型
  459. var proTypes=[
  460. {id:1,key:'string',value:'文本类型'},
  461. {id:2,key:'date',value:'日期类型'},
  462. {id:3,key:'int',value:'数字类型'},
  463. {id:4,key:'float',value:'浮点类型'}
  464. ];
  465. // init D3 force layout
  466. var force = d3.layout.force()
  467. .nodes(nodes)
  468. .links(links)
  469. .size([width, height])
  470. .gravity(.05)
  471. .linkDistance(150)
  472. .linkStrength(2)
  473. .charge(-500)
  474. .on('tick', tick);
  475. // define arrow markers for graph links
  476. svg.append('svg:defs').append('svg:marker')
  477. .attr('id', 'end-arrow')
  478. .attr('viewBox', '0 -5 10 10')
  479. .attr('refX', 6)
  480. .attr('markerWidth', 3)
  481. .attr('markerHeight', 3)
  482. .attr('orient', 'auto')
  483. .append('svg:path')
  484. .attr('d', 'M0,-5L10,0L0,5')
  485. .attr('fill', '#000');
  486. svg.append('svg:defs').append('svg:marker')
  487. .attr('id', 'start-arrow')
  488. .attr('viewBox', '0 -5 10 10')
  489. .attr('refX', 4)
  490. .attr('markerWidth', 3)
  491. .attr('markerHeight', 3)
  492. .attr('orient', 'auto')
  493. .append('svg:path')
  494. .attr('d', 'M10,-5L0,0L10,5')
  495. .attr('fill', '#000');
  496. // line displayed when dragging new nodes
  497. var drag_line = svg.append('svg:path')
  498. .attr('class', 'link dragline hidden')
  499. .attr('d', 'M0,0L0,0');
  500. // handles to link and node element groups
  501. //(1)var path = svg.append('svg:g').selectAll('g')
  502. var path = svg.append('svg:g').selectAll('g'),
  503. circle = svg.append('svg:g').selectAll('g');
  504. // mouse event vars
  505. var selected_node = null,
  506. selected_link = null,
  507. mousedown_link = null,
  508. mousedown_node = null,
  509. mouseup_node = null;
  510. function resetMouseVars() {
  511. mousedown_node = null;
  512. mouseup_node = null;
  513. mousedown_link = null;
  514. }
  515. // update force layout (called automatically each iteration)
  516. function tick() {
  517. // draw directed edges with proper padding from node centers
  518. path.selectAll('path').attr('d', function(d) {
  519. var deltaX = d.target.x - d.source.x,
  520. deltaY = d.target.y - d.source.y,
  521. dist = Math.sqrt(deltaX * deltaX + deltaY * deltaY),
  522. normX = deltaX / dist,
  523. normY = deltaY / dist,
  524. sourcePadding = d.left ? 27 : 22,
  525. targetPadding = d.right ? 27 : 22,
  526. sourceX = d.source.x + (sourcePadding * normX),
  527. sourceY = d.source.y + (sourcePadding * normY),
  528. targetX = d.target.x - (targetPadding * normX),
  529. targetY = d.target.y - (targetPadding * normY);
  530. return 'M' + sourceX + ',' + sourceY + 'L' + targetX + ',' + targetY;
  531. });
  532. circle.attr('transform', function(d) {
  533. return 'translate(' + d.x + ',' + d.y + ')';
  534. });
  535. }
  536. // update graph (called when needed)
  537. function restart() {
  538. //绑定link 数据
  539. path.datum(links);
  540. // path (link) group
  541. path = path.data(links,function(d) { return d.id; });
  542. var p = path.enter().append('svg:g');
  543. //update existing links
  544. path.selectAll('path').classed('selected', function(d) { return d === selected_link; })
  545. .style('marker-start', function(d) { return d.left ? 'url(#start-arrow)' : ''; })
  546. .style('marker-end', function(d) { return d.right ? 'url(#end-arrow)' : ''; });
  547. // add new links
  548. p.append('svg:path')
  549. .attr('class', 'link')
  550. .attr('id', function(d) { return "path_" + d.id; })
  551. // .attr('startOffset', '0%')
  552. .classed('selected', function(d) { return d === selected_link; })
  553. .style('marker-start', function(d) { return d.left ? 'url(#start-arrow)' : ''; })
  554. .style('marker-end', function(d) { return d.right ? 'url(#end-arrow)' : ''; })
  555. .on('mousedown', function(d) {
  556. if(d3.event.ctrlKey) return;
  557. //去除没有提交的连线
  558. for(var i=0;i<links.length;i++){
  559. if(links[i].id==-1 && d.id!=-1){
  560. links.splice(i, 1);
  561. }
  562. }
  563. // select link
  564. mousedown_link = d;
  565. if(mousedown_link === selected_link) {
  566. selected_link = $scope.selected_link = null;
  567. selected_node = $scope.selected_node = null;
  568. // d3.select("#linkDetail").attr('style','display:none');
  569. hideLinkForm(true);//return ;
  570. } else {
  571. selected_link = $scope.selected_link = mousedown_link;
  572. selected_node = $scope.selected_node = null;
  573. //linkName
  574. //d3.select("#linkDetail").attr('style','display:inline-block;width:100%;');
  575. //showLink();
  576. //show("linkNamebox");//return ;
  577. openAside(selected_link, linkType);
  578. }
  579. selected_node = $scope.selected_node = null;
  580. restart();
  581. });
  582. p.append('svg:text')
  583. .attr('x', 30)
  584. .attr('y', 20)
  585. .attr('class','fontM')
  586. .append('textPath')
  587. .attr('xlink:xlink:href',function(d, i){ return "#path_" + d.id; })
  588. .html(function(d){
  589. for(var i=0;i<linkType.length;i++){
  590. if(linkType[i].type==d.name){
  591. return linkType[i].label;
  592. }
  593. }
  594. });
  595. // remove old links
  596. path.exit().remove();
  597. // circle (node) group
  598. // NB: the function arg is crucial here! nodes are known by id, not by index!
  599. circle.datum(nodes);
  600. circle = circle.data(nodes, function(d) { return d.id; });
  601. // update existing nodes (reflexive & selected visual states)
  602. circle.selectAll('circle')
  603. .style('fill', function(d) {return (d === selected_node) ?d3.rgb(colors(d.label)).brighter().toString() : colors(d.label); })
  604. .style('fill-opacity', 0.75) // add by xi
  605. .classed('reflexive', function(d) { return d.reflexive; });
  606. // add new nodes
  607. var g = circle.enter().append('svg:g');
  608. //g.append('svg:circle').attr('r',22).style('fill','rgb(255,255,255)').style('stroke','rgb(255,255,255)').style('stroke-width','2');
  609. //g.append('svg:circle').attr('r',24).style('fill','rgb(255,255,255)').style('stroke', function(d) { return d3.rgb(colors(d.label)).darker().toString(); }).style('stroke-width','2');
  610. g.append('svg:circle').attr('r',24).style('fill', function(d){ return (d === selected_node) ? 'rgb(153,153,153)' : 'rgb(255,255,255)';}).style('stroke', function(d) { return d3.rgb(colors(d.label)).darker().toString(); }).style('stroke-width','2');
  611. g.append('svg:circle')
  612. .attr('class', 'node')
  613. .attr('r', 18)
  614. .style('fill', function(d) { return (d === selected_node) ? d3.rgb(colors(d.label)).brighter().toString() : colors(d.label); })
  615. .style('stroke', function(d) { return d3.rgb(colors(d.label)).darker().toString(); })
  616. .style('fill-opacity', 0.25) //add by xj
  617. .style('stroke-opacity', 0.5) //add by xj
  618. .classed('reflexive', function(d) { return d.reflexive; });
  619. g.on('mouseover', function(d) {
  620. if(!mousedown_node || d === mousedown_node) return;
  621. // enlarge target node
  622. d3.select(this).attr('transform', 'scale(1.1)');
  623. })
  624. .on('mouseout', function(d) {
  625. if(!mousedown_node || d === mousedown_node) return;
  626. // unenlarge target node
  627. d3.select(this).attr('transform', '');
  628. })
  629. .on('mousedown', function(d) {
  630. if(d3.event.ctrlKey) return;
  631. hideLinkForm(true);
  632. //去除没有提交的连线
  633. for(var i=0;i<links.length;i++){
  634. if(links[i].id==-1 ){
  635. links.splice(i, 1);
  636. }
  637. }
  638. // select node
  639. mousedown_node = d;
  640. if(mousedown_node === selected_node) {
  641. selected_node = $scope.selected_node = null;
  642. hideFeedForm(true);;
  643. }else {
  644. selected_node = $scope.selected_node = mousedown_node;
  645. selected_link = $scope.selected_link = null;
  646. // 点击节点 查询关系及节点 /traversal/{id}/{relation}
  647. api_cmdb.findRefById(selected_node.id).then(function(result) {
  648. var d = result.data;
  649. var node = d.node;
  650. var link = d.edge;
  651. var tempNode = [];
  652. var tempLink = [];
  653. //nodes 或者links 要去重
  654. for (var i = 0; i < node.length; i++) {
  655. var tmp = 0;
  656. for (var j = 0; j < nodes.length; j++) {
  657. if (node[i].id == nodes[j].id) {
  658. tmp++;
  659. break;
  660. }
  661. }
  662. if (tmp == 0) {
  663. tempNode.push(node[i]);
  664. }
  665. }
  666. for (var i = 0; i < link.length; i++) {
  667. var tmp = 0;
  668. for (var j = 0; j < links.length; j++) {
  669. if (link[i].id == links[j].id) {
  670. tmp++;
  671. break;
  672. }
  673. }
  674. if (tmp == 0) {
  675. tempLink.push(link[i]);
  676. }
  677. }
  678. //数据写入页面
  679. for (var i = 0; i < tempNode.length; i++) { //nodes 不清空
  680. nodes.push(tempNode[i]);
  681. }
  682. for (var i = 0; i < tempLink.length; i++) { //link 不清空
  683. links.push(tempLink[i]);
  684. }
  685. //links转换
  686. for (var i = 0; i < links.length; i++) {
  687. for (var j = 0; j < nodes.length; j++) {
  688. if (links[i].source == nodes[j].id) {
  689. links[i].source = nodes[j];
  690. }
  691. if (links[i].target == nodes[j].id) {
  692. links[i].target = nodes[j];
  693. }
  694. }
  695. }
  696. restart();
  697. });
  698. /*
  699. // 点击节点 查询关系及节点 /traversal/{id}/{relation}
  700. $.ajax({
  701. type: "GET",
  702. url: window.basePath+"/api/cmdb/ci/"+selected_node.id+"/refs",
  703. dataType: "json",
  704. success:function(json){
  705. var d=json.data;
  706. var node=d.node;
  707. var link=d.edge;
  708. var tempNode=[];
  709. var tempLink=[];
  710. //nodes 或者links 要去重
  711. for(var i=0;i<node.length;i++){
  712. var tmp=0;
  713. for(var j=0;j<nodes.length;j++){
  714. if(node[i].id==nodes[j].id){
  715. tmp++;
  716. break;
  717. }
  718. }
  719. if(tmp==0){
  720. tempNode.push(node[i]);
  721. }
  722. }
  723. for(var i=0;i<link.length;i++){
  724. var tmp=0;
  725. for(var j=0;j<links.length;j++){
  726. if(link[i].id==links[j].id){
  727. tmp++;
  728. break;
  729. }
  730. }
  731. if(tmp==0){
  732. tempLink.push(link[i]);
  733. }
  734. }
  735. //数据写入页面
  736. for(var i=0;i<tempNode.length;i++){//nodes 不清空
  737. nodes.push(tempNode[i]);
  738. }
  739. for(var i=0;i<tempLink.length;i++){//link 不清空
  740. links.push(tempLink[i]);
  741. }
  742. //links转换
  743. for(var i=0;i<links.length;i++){
  744. for(var j=0;j<nodes.length;j++){
  745. if(links[i].source==nodes[j].id){
  746. links[i].source=nodes[j];
  747. }
  748. if(links[i].target==nodes[j].id){
  749. links[i].target=nodes[j];
  750. }
  751. }
  752. }
  753. restart();
  754. },
  755. error:function(){jAlert("访问服务器出错!",'提示');}
  756. });
  757. */
  758. //更改编辑内容
  759. //shownode();
  760. }
  761. // reposition drag line
  762. drag_line
  763. .style('marker-end', 'url(#end-arrow)')
  764. .classed('hidden', false)
  765. .attr('d', 'M' + mousedown_node.x + ',' + mousedown_node.y + 'L' + mousedown_node.x + ',' + mousedown_node.y);
  766. restart();
  767. })
  768. .on('mouseup', function(d) {
  769. if(!mousedown_node) return;
  770. // needed by FF
  771. drag_line
  772. .classed('hidden', true)
  773. .style('marker-end', '');
  774. // check for drag-to-self
  775. mouseup_node = d;
  776. if(mouseup_node === mousedown_node) { resetMouseVars(); return; }
  777. // unenlarge target node
  778. d3.select(this).attr('transform', '');
  779. // add link to graph (update if exists)
  780. // NB: links are strictly source < target; arrows separately specified by booleans
  781. var source, target, direction;
  782. if(mousedown_node.id < mouseup_node.id) {
  783. source = mousedown_node;
  784. target = mouseup_node;
  785. direction = 'right';
  786. } else {
  787. source = mouseup_node;
  788. target = mousedown_node;
  789. direction = 'left';
  790. }
  791. var link;
  792. link = links.filter(function(l) {
  793. return (l.source === source && l.target === target);
  794. })[0];
  795. if(link) {
  796. //变为双向 direction 方向
  797. link[direction] = true;
  798. //更新
  799. selected_link=link;
  800. var l= selected_link;
  801. var idVal=l.id;
  802. // 连线提交 TODO 双向提交 后台问题
  803. console.log("put relation type");
  804. //TODO
  805. api_cmdb.createRef({'id':l.id,'name':l.name,'source':l.source.id,'target':l.target.id,'left':l.left,'right':l.right}).then(function(resposne){
  806. if(response&&response.status==200){
  807. selected_link.name=linkName;
  808. links.push(selected_link);
  809. restart();
  810. }else{
  811. }
  812. })
  813. // $.ajax({
  814. // type: "PUT",
  815. // contentType:"application/json; charset=UTF-8",
  816. // url: window.basePath+"/api/cmdb/edge/"+idVal,
  817. // data: JSON.stringify({'id':l.id,'name':l.name,'source':l.source.id,'target':l.target.id,'left':l.left,'right':l.right}),
  818. // dataType: "json",
  819. // success:function(data){
  820. // if(data.status==200){
  821. // console.log(data.data.edge[0]);
  822. // selected_link.name=linkName;
  823. // //selected_link.status=linkStatus;
  824. // selected_link.cost=linkCost;
  825. // restart();
  826. // showLink();
  827. // }
  828. // },
  829. // error: function(data){jAlert("服务器请求异常",'提示');}
  830. // });
  831. } else {
  832. cancel();
  833. //添加连线
  834. link = {id:-1,source: source, target: target,name:'', left: false, right: false};
  835. link[direction] = true;
  836. selected_link=link;
  837. links.push(link);
  838. //d3.select("#linkDetail").attr('style','display:inline-block;width:100%;');
  839. //showLink();
  840. openAside(link, linkType);
  841. //show("linkNamebox");
  842. }
  843. // select new link
  844. selected_link = $scope.selected_link = link;
  845. selected_node = $scope.selected_node = null;
  846. restart();
  847. });
  848. // show node name
  849. g.append('svg:text')
  850. .attr('x', 0)
  851. .attr('y', 34)
  852. .attr('class', 'id')
  853. .text(function(d) { return d.name; });//TODO 改为 d.name
  854. //设置图片
  855. g.append('svg:foreignObject')
  856. .attr("width", 32)
  857. .attr("height", 32)
  858. .attr('x', "-16px")
  859. .attr('y', "-11px")
  860. .html(function(d){
  861. for(var i=0;i<labels.length;i++){
  862. if(d.label==labels[i].sign){
  863. return '<i class="icon iconfont">'+labels[i].iconname+'</i>';
  864. }
  865. }
  866. });
  867. // remove old nodes
  868. circle.exit().remove();
  869. // set the graph in motion
  870. force.start();
  871. }
  872. function mousedown() {
  873. // prevent I-bar on drag
  874. //d3.event.preventDefault();
  875. // because :active only works in WebKit?
  876. svg.classed('active', true);
  877. if(mousedown_node){
  878. viewNode(mousedown_node);
  879. }
  880. if(d3.event.ctrlKey || mousedown_node || mousedown_link) return;
  881. // insert new node at point 点击添加node
  882. // var point = d3.mouse(this),
  883. // node = {id: ++lastNodeId, reflexive: false};
  884. // node.x = point[0];
  885. // node.y = point[1];
  886. // nodes.push(node);
  887. restart();
  888. }
  889. function viewNode(node){
  890. var title = $scope.selected_node.name+"-["+$scope.selected_node.uuid+"]";
  891. if(!$scope.selected_node.props.state){$scope.selected_node.props.state="空"}
  892. else if($scope.selected_node.props.state){
  893. if($scope.selected_node.props.state=="1"){$scope.selected_node.props.state="未审核"}
  894. else if($scope.selected_node.props.state=="2"){$scope.selected_node.props.state="已审核"}
  895. else if($scope.selected_node.props.state=="3"){$scope.selected_node.props.state="不匹配"}
  896. else if($scope.selected_node.props.state=="4"){$scope.selected_node.props.state="丢失"}
  897. };
  898. if(!$scope.selected_node.name){$scope.selected_node.name="空"}
  899. if(!$scope.selected_node.status){$scope.selected_node.statu="空"}
  900. if(!$scope.selected_node.props.useradmin){$scope.selected_node.props.useradmin="空"}
  901. toaster.pop({
  902. // type: 'info',
  903. // title: title,
  904. body: '<br/><p>搜索代码:' + $scope.selected_node.uuid + '</p>' +
  905. '<p>资产标题:' + $scope.selected_node.name + '</p>' +
  906. '<p>状态:' + $scope.selected_node.status + '</p>' +
  907. '<p>审核状态:' + $scope.selected_node.props.state + '</p>' +
  908. '<p>维护人员:' + $scope.selected_node.props.useradmin + '</p>',
  909. bodyOutputType: 'trustedHtml',
  910. timeout: 3000
  911. })
  912. }
  913. function mousemove() {
  914. if(!mousedown_node) return;
  915. // update drag line
  916. drag_line.attr('d', 'M' + mousedown_node.x + ',' + mousedown_node.y + 'L' + d3.mouse(this)[0] + ',' + d3.mouse(this)[1]);
  917. restart();
  918. }
  919. function mouseup() {
  920. if(mousedown_node) {
  921. // hide drag line
  922. drag_line
  923. .classed('hidden', true)
  924. .style('marker-end', '');
  925. }
  926. // because :active only works in WebKit?
  927. svg.classed('active', false);
  928. // clear mouse event vars
  929. resetMouseVars();
  930. }
  931. function spliceLinksForNode(node) {
  932. var toSplice = links.filter(function(l) {
  933. return (l.source === node || l.target === node);
  934. });
  935. toSplice.map(function(l) {
  936. links.splice(links.indexOf(l), 1);
  937. });
  938. }
  939. // only respond once per keydown
  940. var lastKeyDown = -1;
  941. function keydown() {
  942. //d3.event.preventDefault();
  943. if(lastKeyDown !== -1) return;
  944. lastKeyDown = d3.event.keyCode;
  945. // ctrl
  946. if(d3.event.keyCode === 17) {
  947. circle.call(force.drag);
  948. svg.classed('ctrl', true);
  949. }
  950. if(!selected_node && !selected_link) return;
  951. switch(d3.event.keyCode) {
  952. case 8: // backspace
  953. // case 46: // delete
  954. // if(selected_node) {
  955. // nodes.splice(nodes.indexOf(selected_node), 1);
  956. // spliceLinksForNode(selected_node);
  957. // } else if(selected_link) {
  958. // links.splice(links.indexOf(selected_link), 1);
  959. // }
  960. // selected_link = null;
  961. // selected_node = null;
  962. // restart();
  963. // break;
  964. case 66: // B
  965. if(selected_link) {
  966. // set link direction to both left and right
  967. selected_link.left = true;
  968. selected_link.right = true;
  969. }
  970. restart();
  971. break;
  972. case 76: // L
  973. if(selected_link) {
  974. // set link direction to left only
  975. selected_link.left = true;
  976. selected_link.right = false;
  977. }
  978. restart();
  979. break;
  980. case 82: // R
  981. if(selected_node) {
  982. // toggle node reflexivity
  983. selected_node.reflexive = !selected_node.reflexive;
  984. } else if(selected_link) {
  985. // set link direction to right only
  986. selected_link.left = false;
  987. selected_link.right = true;
  988. }
  989. restart();
  990. break;
  991. }
  992. }
  993. function keyup() {
  994. lastKeyDown = -1;
  995. // ctrl
  996. if(d3.event.keyCode === 17) {
  997. circle
  998. .on('mousedown.drag', null)
  999. .on('touchstart.drag', null);
  1000. svg.classed('ctrl', false);
  1001. }
  1002. }
  1003. // app starts here
  1004. svg.on('mousedown', mousedown)
  1005. .on('mousemove', mousemove)
  1006. .on('mouseup', mouseup);
  1007. d3.select(window)
  1008. .on('keydown', keydown)
  1009. .on('keyup', keyup);
  1010. //restart();
  1011. //GT 颜色与数值对照表
  1012. function colors(sign){
  1013. //num=num>20?num%20:parseInt(num);
  1014. for(var i=0;i<labels.length;i++){
  1015. var entity=labels[i];
  1016. if(sign==entity.sign){
  1017. return entity.color;
  1018. }
  1019. if(i==labels.length-1 && sign!=entity.sign){
  1020. return '#ffeeee';
  1021. }
  1022. }
  1023. }
  1024. function postion(sign){
  1025. for(var i=0;i<labels.length;i++){
  1026. var entity=labels[i];
  1027. if(sign==entity.sign){
  1028. return i;
  1029. }
  1030. }
  1031. return 1;
  1032. }
  1033. //添加设备
  1034. function addnode() {
  1035. //先编辑提交 到数据库添加一条数据得到ID 后显示节点
  1036. var assetNo=d3.select("#nodeAssetNo").property('value');//资产编号
  1037. var name=d3.select("#nodeName").property('value');//资产名称
  1038. var type=d3.select("#nodeType").property('value');//资产类型
  1039. var label=d3.select("#nodeLabel").property('value');//label
  1040. var status=d3.select("#nodeStatus").property('value');//资产状态
  1041. $.ajax({
  1042. type: "POST",
  1043. contentType:"application/json; charset=UTF-8",
  1044. url: window.basePath+"/api/cmdb/ci",
  1045. data: JSON.stringify({'name':name,'status':status,'type':type,'label':label,'assetNo':assetNo,props:selected_node.props }),
  1046. dataType: "json",
  1047. success:function(data){
  1048. //成功后得到ID
  1049. if(data.status==200){
  1050. var node=data.data.node[0];
  1051. node.x = 634;
  1052. node.y = 265.5625;
  1053. nodes.push(node);
  1054. selected_node=node;
  1055. restart();
  1056. hideFeedForm(true);;
  1057. }
  1058. },
  1059. error: function(data){jAlert("服务器请求异常",'提示');}
  1060. });
  1061. }
  1062. //显示节点信息
  1063. function shownode(){
  1064. d3.select("#nodeAssetNo").property('value',selected_node.assetNo==undefined?"":selected_node.assetNo);//资产编号
  1065. d3.select("#nodeName").property('value',selected_node.name==undefined?"":selected_node.name);//资产名称
  1066. d3.select("#nodeType").property('value',selected_node.type==undefined?"":selected_node.type);//资产类型
  1067. d3.select("#nodeLabel").property('value',selected_node.label==undefined?"":selected_node.label);//label
  1068. for(var i=0;i<treeNodes.length;i++){
  1069. if(selected_node.label==treeNodes[i].sign){
  1070. d3.select("#citySel").property('value',treeNodes[i].label);
  1071. break;
  1072. }
  1073. }
  1074. d3.select("#nodeStatus").property('value',selected_node.status==undefined?"":selected_node.status);//资产状态
  1075. //先移除div中原来的标签
  1076. d3.select('#nodeTab').selectAll('tr').remove('tr');
  1077. if(selected_node.label){
  1078. var label=null;
  1079. /*
  1080. //根据选择‘节点’的label 查询label的ID
  1081. d3.xhr(window.basePath+"/api/cm/findLabel?sign="+selected_node.label).send("GET", function(error, json) {
  1082. if (!error){
  1083. label =JSON.parse(json.responseText);
  1084. if(selected_node.props){
  1085. var keys=[];
  1086. for(var key in selected_node.props){
  1087. keys.push(key);
  1088. }
  1089. //写入固定属性
  1090. for(var i=0;i<params.length;i++){
  1091. var p=params[i];
  1092. var num=0;
  1093. for(var j=0;j<keys.length;j++){
  1094. if(p.sourceType==1 && p.sourceId==label.id && p.key==keys[j]){//节点已有属性
  1095. num++;
  1096. break;
  1097. }
  1098. }
  1099. if(p.sourceType==1 && p.sourceId==label.id && p.fix==1 && num==0){//节点 中没有的固定属性
  1100. selected_node['props'][p.key]='';
  1101. }
  1102. }
  1103. keys=[];
  1104. for(var key in selected_node.props){
  1105. keys.push(key);
  1106. }
  1107. d3.select('#nodeTab').selectAll('tr')
  1108. .data(keys).enter()
  1109. .append('tr')//.nextSibling
  1110. .attr('id',function(d){
  1111. return 'tr'+d;
  1112. })
  1113. .html(function(d){//undefined
  1114. var str="";
  1115. if(label!=null){
  1116. if(d==""){//新增后props 属性
  1117. var strS="";
  1118. strS='<input type="text" id="input'+d+'" value="'+selected_node.props[d]+'" disabled/>';
  1119. str+='<td style="padding-left: 0px;width:145px;"><span id="span'
  1120. +d+'" style="width:50px;text-align:right;">未定义:</span><input type="hidden" id="select'+
  1121. d+'" style="width: 90px;margin-left: 52px;"/></td>'+
  1122. '<td style="padding-left: 21px;">'+strS+'</td><td>'
  1123. +'<input id="edtBtn'+d+'" name="edtBtn" type="button" style="background-image:url(css/img/tup/xiug.jpg);width:22px;height:22px;" onclick="edtBtnClk(\'text\',\''+d+'\',\'未定义\',\'0\')" />'
  1124. +'&nbsp;<input type="button" value="" style="background-image:url(css/img/tup/del.jpg);width:22px;height:22px;" onclick=\'delBtnClk("'+d+'")\'/></td>';
  1125. return str;
  1126. }
  1127. for(var i=0;i<params.length;i++){
  1128. var p=params[i];
  1129. //sourceType==1 类型为节点 key相等 labelId相同
  1130. if((p.sourceType==1 && d==p.key && p.sourceId==label.id)){//新增加行 动态属性
  1131. var strS="";
  1132. if(p.valueType=="date"){
  1133. strS='<input id="input'+d+'" placeholder="请输入日期" style="width: 151px;" class="laydate-icon" onClick="laydate({istime: true, format: \'YYYY-MM-DD hh:mm:ss\'})" value="'
  1134. +selected_node.props[d]+'" disabled>';
  1135. }else{
  1136. strS='<input type="text" id="input'+d+'" value="'+selected_node.props[d]+'" disabled/>';
  1137. }
  1138. if(p.fix==1){//固定属性 不允许编辑显示属性名 不允许删除
  1139. str+='<td style="padding-left: 0px;width:145px;"><span id="span'
  1140. +d+'">'+p.descName+':</span></td>'+
  1141. '<td style="padding-left: 21px;">'+
  1142. strS+'</td><td>'
  1143. +'<input id="edtBtn'+d+'" name="edtBtn" type="button" style="background-image:url(css/img/tup/xiug.jpg);width:22px;height:22px;" onclick="edtBtnClk(\''
  1144. +p.valueType+'\',\''+d+'\',\''+p.descName+'\',\''+p.fix+'\')" />'
  1145. +'&nbsp;</td>';
  1146. break;
  1147. }else{
  1148. //类型设置 读取JSON string date int float
  1149. str+='<td style="padding-left: 0px;width:145px;"><span id="span'
  1150. +d+'">'+p.descName+':</span><input type="hidden" id="select'+
  1151. d+'" style="width: 90px;margin-left: 52px;"/></td>'+
  1152. '<td style="padding-left: 21px;">'+
  1153. strS+'</td><td>'
  1154. +'<input id="edtBtn'+d+'" name="edtBtn" type="button" style="background-image:url(css/img/tup/xiug.jpg);width:22px;height:22px;" onclick="edtBtnClk(\''
  1155. +p.valueType+'\',\''+d+'\',\''+p.descName+'\',\''+p.fix+'\')" />'
  1156. +'&nbsp;<input type="button" value="" style="background-image:url(css/img/tup/del.jpg);width:22px;height:22px;" onclick=\'delBtnClk("'+d+'")\'/></td>';
  1157. break;
  1158. }
  1159. }
  1160. }
  1161. }
  1162. return str;
  1163. });
  1164. }
  1165. }else{
  1166. jAlert("服务器请求异常!",'提示');
  1167. }
  1168. });
  1169. */
  1170. }
  1171. }
  1172. //显示连线信息
  1173. //
  1174. var openAside = function (model, linkTypes) {
  1175. var modalInstance = $aside.open({
  1176. templateUrl: 'assets/views/system/tpl/asideContent.html',
  1177. placement: 'right',
  1178. size: 'sm',
  1179. backdrop: true,
  1180. controller: function ($scope, $modalInstance, ModelData, optionLinkTypes) {
  1181. $scope.modelData = ModelData;
  1182. $scope.linktypeOptions = optionLinkTypes;
  1183. if($scope.modelData.name!=""){
  1184. angular.forEach($scope.linktypeOptions,function(item){
  1185. if(item.type==$scope.modelData.name){
  1186. $scope.modelData.linkName=item;
  1187. }
  1188. })
  1189. }
  1190. $scope.ok = function (e) {
  1191. $modalInstance.close($scope.modelData);
  1192. //e.stopPropagation();
  1193. };
  1194. $scope.cancel = function (e) {
  1195. $modalInstance.dismiss();
  1196. //e.stopPropagation();
  1197. };
  1198. },
  1199. resolve: {
  1200. ModelData: function(){
  1201. return model;
  1202. },
  1203. optionLinkTypes: function(){
  1204. return linkTypes;
  1205. }
  1206. }
  1207. });
  1208. modalInstance.result.then(function (selectedItem) {
  1209. //TODO create Edge
  1210. console.log(selectedItem);
  1211. if(selectedItem.id==-1){
  1212. api_cmdb.createRef({'id':selectedItem.id,'name':selectedItem.linkName.type,'source':selectedItem.source.id,'target':selectedItem.target.id,'left':selectedItem.left,'right':selectedItem.right}).then(function(response){
  1213. if(response&&response.status==200){
  1214. //model.name=selectedItem.linkName.type;
  1215. var link = response.data.edge[0];
  1216. for (var j = 0; j < nodes.length; j++) {
  1217. if (link.source == nodes[j].id) {
  1218. link.source = nodes[j];
  1219. }
  1220. if (link.target == nodes[j].id) {
  1221. link.target = nodes[j];
  1222. }
  1223. }
  1224. links.push(link);
  1225. // selected_link.name=linkName;
  1226. // selected_link.cost=linkCost;
  1227. restart();
  1228. }else{
  1229. }
  1230. })
  1231. }else{
  1232. api_cmdb.putRef({'id':selectedItem.id,'name':selectedItem.linkName.type,'source':selectedItem.source.id,'target':selectedItem.target.id,'left':selectedItem.left,'right':selectedItem.right}, selectedItem.id).then(function(response){
  1233. if(response&&response.status==200){
  1234. //model=selectedItem;
  1235. angular.forEach(links,function(link,index){
  1236. if(link.name == model.name){
  1237. links[index]=response.data.edge[0];
  1238. for (var j = 0; j < nodes.length; j++) {
  1239. if (links[index].source == nodes[j].id) {
  1240. links[index].source = nodes[j];
  1241. }
  1242. if (links[index].target == nodes[j].id) {
  1243. links[index].target = nodes[j];
  1244. }
  1245. }
  1246. }
  1247. })
  1248. restart();
  1249. }else{
  1250. }
  1251. })
  1252. }
  1253. }, function () {
  1254. //console.log('Modal dismissed at: ' + new Date());
  1255. });
  1256. };
  1257. //
  1258. //
  1259. function showLink(){
  1260. var linkeName = $scope.linkName = selected_link.name==undefined?"":selected_link.name;
  1261. $scope.linkCost = selected_link.cost==undefined?"":selected_link.cost;
  1262. // d3.select("#linkName").property('value',selected_link.name==undefined?"":selected_link.name);
  1263. // d3.select("#linkCost").property('value',selected_link.cost==undefined?"":selected_link.cost);
  1264. //var linkeName=d3.select("#linkName").property('value');
  1265. //先移除div中原来的标签
  1266. d3.select('#linkTab').selectAll('tr').remove('tr');
  1267. var linkId;
  1268. //sourceTYpe=2 and sourceId=连线nameId
  1269. //当前选择的连线name Id
  1270. for(var i=0;i<linkType.length;i++){
  1271. if(linkeName==linkType[i].type){
  1272. linkId=linkType[i].id;
  1273. }
  1274. }
  1275. var props=selected_link.props;
  1276. var keys=[];
  1277. for(var key in props){
  1278. keys.push(key);
  1279. }
  1280. // //写入固定属性
  1281. // for(var i=0;i<params.length;i++){
  1282. // var p=params[i];
  1283. // var num=0;
  1284. // for(var j=0;j<keys.length;j++){
  1285. // if(p.sourceType==2 && p.sourceId==linkId && p.key==keys[j]){//连线已有属性
  1286. // num++;
  1287. // break;
  1288. // }
  1289. // }
  1290. // if(p.sourceType==2 && p.sourceId==linkId && p.fix==1 && num==0){//连线 中没有的固定属性
  1291. // selected_link['props'][p.key]='';
  1292. // }
  1293. // }
  1294. keys=[];
  1295. for(var key in selected_link.props){
  1296. keys.push(key);
  1297. }
  1298. if(keys){
  1299. d3.select('#linkTab').selectAll('tr')
  1300. .data(keys).enter()
  1301. .append('tr')//.nextSibling
  1302. .attr('id',function(d){
  1303. return 'trLink'+d;
  1304. }).html(function(d){
  1305. var str="";
  1306. if(d==""){//新增后props 属性
  1307. var strS="";
  1308. strS='<input type="text" id="inputLink'+d+'" value="'+props[d]+'" disabled/>';
  1309. str+='<td style="padding-left: 0px;width:145px;"><span id="spanLink'
  1310. +d+'" style="width:50px;text-align:right;">未定义:</span><input type="hidden" id="selectLink'+
  1311. d+'" style="width: 90px;margin-left: 52px;"/></td>'+
  1312. '<td style="padding-left: 21px;">'+//111111111111111111111 padding-left: 60px;
  1313. strS +'</td><td>'
  1314. +'<input id="edtBtnLink'+d+'" type="button" name="edtBtn" style="background-image:url(css/img/tup/xiug.jpg);width:22px;height:22px;" onclick="edtBtnLinkClk(\'text\',\''
  1315. +d+'\',\'未定义\',\'0\')" />'
  1316. +'&nbsp;<input type="button" value="" style="background-image:url(css/img/tup/del.jpg);width:22px;height:22px;" onclick=\'delBtnLinkClk("'+d+'")\'/></td>';
  1317. return str;
  1318. }
  1319. for(var j=0;j<params.length;j++){
  1320. var p=params[j];
  1321. if((p.sourceType==2 && d==p.key && p.sourceId==linkId)){//新增加行
  1322. var strS="";
  1323. if(p.valueType=="date"){
  1324. strS='<input id="inputLink'+d+'" placeholder="请输入日期" style="width: 151px;" class="laydate-icon" onClick="laydate({istime: true, format: \'YYYY-MM-DD hh:mm:ss\'})" value="'+props[d]+'" disabled>';
  1325. }else{
  1326. strS='<input type="text" id="inputLink'+d+'" value="'+props[d]+'" disabled/>';
  1327. }
  1328. if(p.fix==1){//固定属性 不允许编辑显示属性名 不允许删除
  1329. //类型设置 读取JSON string date int float 22222222222222222padding-left: 21px;
  1330. str+='<td style="width:145px;"><span id="spanLink'+d+'">'+p.descName+':</span></td>'+
  1331. '<td style="padding-left: 21px;">'+strS+'</td><td>'+'<input id="edtBtnLink'+d
  1332. +'" type="button" name="edtBtn" style="background-image:url(css/img/tup/xiug.jpg);width:22px;height:22px;" onclick="edtBtnLinkClk(\''
  1333. +p.valueType+'\',\''+d+'\',\''+p.descName+'\',\''+p.fix+'\')" />'
  1334. +'&nbsp;</td>';
  1335. break;
  1336. }else{
  1337. //类型设置 读取JSON string date int float
  1338. str+='<td style="width:145px;"><span id="spanLink'
  1339. +d+'">'+p.descName+':</span><input type="hidden" id="selectLink'+
  1340. d+'" style="width: 90px;margin-left: 52px;"/></td>'+
  1341. '<td style="padding-left: 21px;">'+//333333333333333 padding-left: 21px;
  1342. strS
  1343. +'</td><td>'
  1344. +'<input id="edtBtnLink'+d+'" type="button" name="edtBtn" style="background-image:url(css/img/tup/xiug.jpg);width:22px;height:22px;" onclick="edtBtnLinkClk(\''
  1345. +p.valueType+'\',\''+d+'\',\''+p.descName+'\',\''+p.fix+'\')" />'
  1346. +'&nbsp;<input type="button" value="" style="background-image:url(css/img/tup/del.jpg);width:22px;height:22px;" onclick=\'delBtnLinkClk("'+d+'")\'/></td>';
  1347. break;
  1348. }
  1349. }
  1350. }
  1351. return str;
  1352. });
  1353. }
  1354. hideLinkForm(false);
  1355. }
  1356. //删除(修改状态为报废)
  1357. function delnode_update(){
  1358. if(selected_node || selected_link){
  1359. jConfirm('确定删除?', '提示', function(r) {
  1360. if(r){
  1361. if(selected_node){//删除配置
  1362. //节点ID(节点删除执行成功,数据库节点未删除 ,删除节点关系时执行失败)
  1363. var id=selected_node.id;
  1364. var name=selected_node.name;
  1365. var type=selected_node.type;//资产类型
  1366. var label=selected_node.label; //资产类型
  1367. var assetNo=selected_node.assetNo;//资产编号
  1368. var props =selected_node.props;
  1369. var status=CMConstants.DISCARDE;
  1370. //删除后,状态变为废弃
  1371. $.ajax({
  1372. type: "PUT",
  1373. contentType:"application/json; charset=UTF-8",
  1374. url: window.basePath+"/api/cmdb/ci/"+id,
  1375. data: JSON.stringify({'id':id,'name':name,'status':status,'type':type,'label':label,'assetNo':assetNo,'props':props}),
  1376. dataType: "json",
  1377. success:function(data){
  1378. if(data.status==200){
  1379. jAlert("删除成功!",'提示');
  1380. selected_node.type=type;//资产类型
  1381. selected_node.status=status;
  1382. selected_node.label=label; //资产类型
  1383. selected_node.assetNo=assetNo; //资产编号
  1384. selected_node.props=props;
  1385. selected_node.name=name;
  1386. restart();
  1387. query(label,"");
  1388. //shownode();
  1389. }
  1390. },
  1391. error: function(data){jAlert("服务器请求异常",'提示');}
  1392. });
  1393. }
  1394. }else{
  1395. jAlert("请求异常",'提示');
  1396. }
  1397. });
  1398. }else{
  1399. jAlert('请先选择删除项!','提示');
  1400. }
  1401. }
  1402. //删除
  1403. function delnode(){
  1404. if(selected_node || selected_link){
  1405. jConfirm('确定删除?', '提示', function(r) {
  1406. if(r){
  1407. if(selected_node){//删除配置
  1408. //节点ID(节点删除执行成功,数据库节点未删除 ,删除节点关系时执行失败)
  1409. var id=selected_node.id;
  1410. //先删除节点关系
  1411. d3.xhr(window.basePath+"/api/cmdb/ci/"+id+"/refs").send("DELETE", function(error, json) {
  1412. if (!error){
  1413. if(json.status==200){
  1414. var edge=JSON.parse(json.responseText).data.edge;
  1415. for(var i=0;i<edge.length;i++){
  1416. for(var j=0;j<links.length;j++){
  1417. if(edge[i].id==links[j].id){
  1418. links.splice(j, 1);
  1419. break;
  1420. }
  1421. }
  1422. }
  1423. //再删除节点
  1424. d3.xhr(window.basePath+"/api/cmdb/ci/"+id).send("DELETE", function(error, json) {
  1425. if (!error){
  1426. if(json.status==200){
  1427. //删除节点
  1428. nodes.splice(nodes.indexOf(selected_node), 1);
  1429. jAlert("删除成功!",'提示');
  1430. hideFeedForm(true);;
  1431. }
  1432. restart();
  1433. }else{
  1434. jAlert("请求异常",'提示');
  1435. }
  1436. });
  1437. }
  1438. }else{
  1439. jAlert("请求异常",'提示');
  1440. }
  1441. });
  1442. }
  1443. //用户删除关系
  1444. if(selected_link){
  1445. //得到关系ID 删除关系
  1446. var id=selected_link.id;
  1447. d3.xhr(window.basePath+"/api/cmdb/edge/"+id).send("DELETE", function(error, json) {
  1448. if (!error){
  1449. links.splice(links.indexOf(selected_link), 1);
  1450. jAlert("删除成功!",'提示');
  1451. hideLinkForm(true);
  1452. restart();
  1453. }else{
  1454. jAlert("请求异常",'提示');
  1455. }
  1456. });
  1457. }
  1458. }
  1459. });
  1460. }else{
  1461. jAlert('请先选择删除项!','提示');
  1462. }
  1463. }
  1464. var CI ={};
  1465. CI.add = addnode;
  1466. window.CI = CI;
  1467. d3.select("#traversal").selectAll('a').data([{name:'遍历',id:'traversalBtn'}]).enter()
  1468. .append('a')
  1469. .html(function (d) { return d.name; })
  1470. .on('click', function (d) {
  1471. if(d.id=="traversalBtn"){
  1472. if(selected_node == null){
  1473. alert("没有选择节点。。。");
  1474. }else{
  1475. $.ajax({
  1476. type: "GET",
  1477. url: window.basePath+"/api/cmdb/traversal/"+selected_node.assetNo,
  1478. dataType: "json",
  1479. success:function(json){
  1480. var d=json.data;
  1481. var node=d.node;
  1482. var link=d.edge;
  1483. var tempNode=[];
  1484. var tempLink=[];
  1485. //nodes 或者links 要去重
  1486. for(var i=0;i<node.length;i++){
  1487. var tmp=0;
  1488. for(var j=0;j<nodes.length;j++){
  1489. if(node[i].id==nodes[j].id){
  1490. tmp++;
  1491. break;
  1492. }
  1493. }
  1494. if(tmp==0){
  1495. tempNode.push(node[i]);
  1496. }
  1497. }
  1498. for(var i=0;i<link.length;i++){
  1499. var tmp=0;
  1500. for(var j=0;j<links.length;j++){
  1501. if(link[i].id==links[j].id){
  1502. tmp++;
  1503. break;
  1504. }
  1505. }
  1506. if(tmp==0){
  1507. tempLink.push(link[i]);
  1508. }
  1509. }
  1510. //数据写入页面
  1511. for(var i=0;i<tempNode.length;i++){//nodes 不清空
  1512. nodes.push(tempNode[i]);
  1513. }
  1514. for(var i=0;i<tempLink.length;i++){//link 不清空
  1515. links.push(tempLink[i]);
  1516. }
  1517. //links转换
  1518. for(var i=0;i<links.length;i++){
  1519. for(var j=0;j<nodes.length;j++){
  1520. if(links[i].source==nodes[j].id){
  1521. links[i].source=nodes[j];
  1522. }
  1523. if(links[i].target==nodes[j].id){
  1524. links[i].target=nodes[j];
  1525. }
  1526. }
  1527. }
  1528. restart();
  1529. },
  1530. error:function(){alert("访问服务器出错!");}
  1531. });
  1532. }
  1533. }
  1534. });
  1535. d3.select("#layout").selectAll('a').data([{name:'布局',id:'layoutBtn'}]).enter()
  1536. .append('a')
  1537. .html(function (d) { return d.name; })
  1538. .on('click', function (d) {
  1539. if(d.id=="layoutBtn"){
  1540. var k = Math.sqrt(nodes.length / (width * height));
  1541. //var len = labels.length;
  1542. // nodes.forEach(function(o, i) {
  1543. // //console.log( "postion:" + postion(o.label) % len);
  1544. // o.x += postion(o.label) & 1 ? 140 : -140;
  1545. // o.y += postion(o.label) & 2 ? 140 : -140;
  1546. // console.log("[" +o.id + "-" + o.name + "]:" + o.label + "(" + o.x + "," + o.y + ");");
  1547. // });
  1548. force.charge((-10/k)*1.5);
  1549. force.gravity(100*k);
  1550. force.resume();
  1551. }
  1552. });
  1553. //添加node 点击事件
  1554. d3.select("#addsss").selectAll('a').data([{name:'添加',id:'addBtn'}]).enter()
  1555. .append('a')
  1556. .html(function (d) { return d.name; })
  1557. .on('click', function (d) {
  1558. if(d.id=="addBtn"){
  1559. selected_node={id:-1};
  1560. //内容置空
  1561. d3.select("#nodeAssetNo").property('value','');//资产编号
  1562. d3.select("#nodeName").property('value','');//资产名称
  1563. d3.select("#nodeType").property('value','');//资产类型
  1564. d3.select("#nodeLabel").property('value','');//label
  1565. d3.select("#nodeStatus").property('value','');//资产状态
  1566. d3.select('#nodeTab').selectAll('tr').remove();
  1567. show("feedbox");return false;
  1568. }
  1569. });
  1570. //删除
  1571. d3.select("#delsss").selectAll('a').data([{name:'删除',id:'delBtn'}]).enter()
  1572. .append('a')
  1573. .html(function (d) { return d.name; })
  1574. .on('click', function (d) {
  1575. if(d.id=="delBtn"){
  1576. //delnode();
  1577. delnode_update();
  1578. }
  1579. });
  1580. //修改
  1581. d3.select("#uppsss").selectAll('a').data([{name:'修改',id:'edtBtn'}]).enter()
  1582. .append('a')
  1583. .html(function (d) { return d.name; })
  1584. .on('click', function (d) {
  1585. if(d.id=="edtBtn"){
  1586. if(selected_node!=null){
  1587. show("feedbox");
  1588. return false;
  1589. }else{
  1590. jAlert("请选择设备",'提示');
  1591. }
  1592. }
  1593. });
  1594. //节点提交
  1595. d3.select("#subBtn").on('click',function(d){
  1596. var assetNo=d3.select("#nodeAssetNo").property('value');//资产编号
  1597. var label=d3.select("#nodeLabel").property('value');//label
  1598. var props =selected_node.props;
  1599. for(var key in props){
  1600. if(key==""){
  1601. jAlert("您有未定义属性,请删除或编辑!",'提示');
  1602. return;
  1603. }
  1604. }
  1605. if(assetNo==""){
  1606. jAlert("请输入资产编号!",'提示');
  1607. return;
  1608. }else if(label==null ||label==""){
  1609. jAlert("请选择资产类型!",'提示');
  1610. return;
  1611. }else{
  1612. //添加或者更新
  1613. if(selected_node.id==-1){//添加
  1614. addnode();
  1615. }else{//更新
  1616. var idVal=selected_node.id;
  1617. var name=d3.select("#nodeName").property('value');//资产名称
  1618. var type=d3.select("#nodeType").property('value');//资产类型
  1619. var status=d3.select("#nodeStatus").property('value');//资产状态
  1620. //节点提交
  1621. $.ajax({
  1622. type: "PUT",
  1623. contentType:"application/json; charset=UTF-8",
  1624. url: window.basePath+"/api/cmdb/ci/"+idVal,
  1625. data: JSON.stringify({'id':idVal,'name':name,'status':status,'type':type,'label':label,'assetNo':assetNo,'props':selected_node.props }),
  1626. dataType: "json",
  1627. success:function(data){
  1628. if(data.status==200){
  1629. jAlert("更新成功!",'提示');
  1630. selected_node.assetNo=assetNo;
  1631. selected_node.name=name;
  1632. selected_node.type=type;
  1633. selected_node.label=label;
  1634. selected_node.status=status;
  1635. restart();
  1636. //shownode();
  1637. }
  1638. },
  1639. error: function(data){jAlert("服务器请求异常",'提示');}
  1640. });
  1641. }
  1642. // restart();
  1643. }
  1644. });
  1645. //连线提交
  1646. d3.select("#subBtn1").on('click',function(d){
  1647. var linkName=d3.select("#linkName").property('value');
  1648. var linkCost=d3.select("#linkCost").property('value');
  1649. var idVal=selected_link.id;
  1650. var props =selected_link.props;
  1651. for(var key in props){
  1652. if(key==""){
  1653. jAlert("您有未定义属性,请删除或编辑!",'提示');
  1654. return;
  1655. }
  1656. }
  1657. if(idVal==-1){//添加
  1658. selected_link.name=linkName;
  1659. //selected_link.status=linkStatus;
  1660. selected_link.cost=linkCost;
  1661. var l=selected_link;
  1662. $.ajax({
  1663. type: "POST",
  1664. contentType:"application/json; charset=UTF-8",
  1665. url: window.basePath+"/api/cmdb/edge",
  1666. data: JSON.stringify({'id':l.id,'name':l.name,'status':l.status,'cost':l.cost,'left':l.left,'right':l.right,'source':l.source.id,'target':l.target.id,'props':l.props}),
  1667. dataType: "json",
  1668. success:function(data){
  1669. if(data.status==200){
  1670. var link=data.data.edge[0];
  1671. jAlert("添加成功!",'提示');
  1672. selected_link.id=link.id;
  1673. restart();
  1674. hideLinkForm(true);
  1675. }
  1676. },
  1677. error: function(data){jAlert("服务器请求异常",'提示');}
  1678. });
  1679. }else{
  1680. // 连线提交
  1681. $.ajax({
  1682. type: "PUT",
  1683. contentType:"application/json; charset=UTF-8",
  1684. url: window.basePath+"/api/cmdb/edge/"+idVal,
  1685. data: JSON.stringify({'id':idVal,'name':linkName,'cost':linkCost,'props':selected_link.props }),
  1686. dataType: "json",
  1687. success:function(data){
  1688. if(data.status==200){
  1689. jAlert("更新成功!",'提示');
  1690. selected_link.name=linkName;
  1691. //selected_link.status=linkStatus;
  1692. selected_link.cost=linkCost;
  1693. restart();
  1694. showLink();
  1695. }
  1696. },
  1697. error: function(data){jAlert("服务器请求异常",'提示');}
  1698. });
  1699. }
  1700. // restart();
  1701. });
  1702. //全局变量 正在编辑的属性ID
  1703. var etdBtnId="";
  1704. //编辑按钮点击事件
  1705. function edtBtnClk(type,etdId,value,fix){
  1706. var v=d3.select('#edtBtn'+etdId).property('name');
  1707. if(v=='edtBtn'){
  1708. d3.select('#input'+etdId).property('disabled','');//可编辑
  1709. if(type=="date"){//加载日期
  1710. //$("#input"+etdId).datepicker({dateFormat: 'yy-mm-dd'});$.datepicker.regional[ "zh-cn" ];
  1711. }else if(type=='int'){//只能为整型
  1712. d3.select('#input'+etdId).on('keyup',function(){
  1713. this.value= this.value.replace(/[^\d]/g, '');
  1714. });
  1715. }else if(type=='float'){
  1716. d3.select('#input'+etdId).on('keyup',function(){
  1717. this.value= this.value.replace(/[^\d.]/g,'');
  1718. });
  1719. }
  1720. //span文字隐藏 select2显示
  1721. // d3.select('.addtd').classed('addtds');
  1722. if(fix==0){//动态属性 显示名称隐藏
  1723. d3.select('#span'+etdId).attr('style','display:none');
  1724. }
  1725. //d3.select('tr#tr'+etdId + 'td + td').attr('style','padding-left:0px;');
  1726. //$('#select'+etdId).select2({ multiple: true, data:selectData});//分号选择
  1727. //根据用户选择的label 和节点类型查询
  1728. var t=d3.select('#nodeLabel').property('value');
  1729. var typeId="";//选中的资源label的ID
  1730. for(var i=0;i<labels.length;i++){
  1731. if(labels[i].sign==t){
  1732. typeId=labels[i].id;
  1733. break;
  1734. }
  1735. }
  1736. var res=[];
  1737. //改变属性
  1738. d3.select('#edtBtn'+etdId).property('name','edt');
  1739. d3.select('#edtBtn'+etdId).attr('style','background-image:url(css/img/tup/queding.jpg);width:22px;height:22px;');
  1740. $('#select'+etdId).select2({
  1741. ajax: {
  1742. url: window.basePath+'/api/cm/findByPro',//sourceType=1 节点
  1743. type:'GET',
  1744. dataType: 'json',
  1745. data: function(){
  1746. return {
  1747. sourceType : 1,
  1748. sourceId: typeId
  1749. };
  1750. },
  1751. results: function (data) {
  1752. res=data;
  1753. var bindData = [];
  1754. for(var i = 0;i < data.length;i++){
  1755. bindData.push({'id':data[i].key,'text':data[i].descName});
  1756. }
  1757. return {results: bindData};
  1758. }
  1759. },
  1760. createSearchChoice:function(term, data) { if ($(data).filter(function() { return this.text.localeCompare(term)===0; }).length===0) {return {id:term, text:term};} },
  1761. //multiple: true,//单选 or 多选
  1762. }).on("select2-selecting", function(e) {
  1763. etdBtnId=this.id.substr('select'.length);
  1764. var result = [];
  1765. for(var i = 0;i < res.length;i++){
  1766. result.push({'id':res[i].key,'text':res[i].descName});
  1767. }
  1768. if(result.length==0){
  1769. //置空
  1770. d3.select("#proType").property('value','');
  1771. d3.select("#proNo").property('value','');
  1772. d3.select('#overlay').style('display','block');
  1773. d3.select('#win').style('display','block');
  1774. return;
  1775. }
  1776. for(var i=0;i<result.length;i++){
  1777. if(e.choice.id==result[i].id && e.choice.text==result[i].text){//用户选择的是已有的属性
  1778. //写入nodes
  1779. var props=selected_node.props;
  1780. // 用户选择不能重复
  1781. for(var key in props){
  1782. if(e.val==key && e.val!=etdId){
  1783. jAlert("此资产已有此属性,请另外选择!",'提示',function(){
  1784. $('#select'+etdId).select2('data', {id:etdId,text:value});
  1785. });
  1786. return;
  1787. }
  1788. }
  1789. //用户选择验证通通过 写入到nodes中
  1790. for(var p in props){
  1791. if(p==etdId){
  1792. var text=props[p];
  1793. delete props[p];
  1794. selected_node.props[e.choice.id]=text;
  1795. shownode();//此处不重新加载(shownode) 会有问题
  1796. return;
  1797. }
  1798. }
  1799. }else if((i==result.length-1) && (e.choice!=result[i])){//用户新输入的
  1800. //置空
  1801. d3.select("#proType").property('value','');
  1802. d3.select("#proNo").property('value','');
  1803. d3.select('#overlay').style('display','block');
  1804. d3.select('#win').style('display','block');
  1805. return;
  1806. }
  1807. }
  1808. });
  1809. //绑定默认值
  1810. $('#select'+etdId).select2('data', {id:etdId,text:value});
  1811. }else{//确定
  1812. d3.select('#edtBtn'+etdId).property('name','edtBtn');
  1813. d3.select('#edtBtn'+etdId).attr('style','background-image:url(css/img/tup/xiug.jpg);width:22px;height:22px;');
  1814. //数据写入nodes
  1815. var props=selected_node.props;
  1816. for(var key in props){
  1817. if(key==etdId){
  1818. var text=d3.select('#input'+etdId).property('value');
  1819. var k=null;
  1820. if(fix==0){
  1821. k=d3.select('#select'+etdId).property('value');
  1822. }else{
  1823. k=etdId;
  1824. }
  1825. delete props[etdId];
  1826. props[k]=text;
  1827. shownode();
  1828. return;
  1829. }
  1830. }
  1831. }
  1832. }
  1833. //编辑按钮点击事件
  1834. function edtBtnLinkClk(type,etdId,value,fix){
  1835. var linkeName=d3.select('#linkName').property('value');
  1836. if(linkeName==""){
  1837. jAlert("请先选取连线名称!",'提示');
  1838. return;
  1839. }
  1840. var v=d3.select('#edtBtnLink'+etdId).property('name');
  1841. if(type=="date"){//加载日期
  1842. // $("#inputLink"+etdId).datepicker({dateFormat: 'yy-mm-dd'});$.datepicker.regional[ "zh-cn" ];
  1843. }else if(type=='int'){//只能为整型
  1844. d3.select('#inputLink'+etdId).on('keyup',function(){
  1845. this.value= this.value.replace(/[^\d]/g, '');
  1846. });
  1847. }else if(type=='float'){
  1848. d3.select('#inputLink'+etdId).on('keyup',function(){
  1849. this.value= this.value.replace(/[^\d.]/g,'');
  1850. });
  1851. }
  1852. if(v=='edtBtn'){
  1853. d3.select('#inputLink'+etdId).property('disabled','');//可编辑
  1854. //改变属性
  1855. d3.select('#edtBtnLink'+etdId).attr('style','background-image:url(css/img/tup/queding.jpg);width:22px;height:22px;');
  1856. d3.select('#edtBtnLink'+etdId).property('name','edt');
  1857. if(fix==0){//动态属性隐藏
  1858. //span文字隐藏 select2显示
  1859. d3.select('#spanLink'+etdId).attr('style','display:none');
  1860. }
  1861. //根据用户选择的name(连线名称) 查询
  1862. var linkId;//选中的name的ID 即属性表里的sourceId
  1863. for(var i=0;i<linkType.length;i++){
  1864. if(linkeName==linkType[i].type){
  1865. linkId=linkType[i].id;
  1866. }
  1867. }
  1868. var res=[];
  1869. $('#selectLink'+etdId).select2({
  1870. ajax: {
  1871. url: window.basePath+'/api/cm/findByPro',//sourceType=2 连线
  1872. type:'GET',
  1873. dataType: 'json',
  1874. data: function(){
  1875. return {
  1876. sourceType : 2,
  1877. sourceId: linkId
  1878. };
  1879. },
  1880. results: function (data) {
  1881. res=data;
  1882. var bindData = [];
  1883. for(var i = 0;i < data.length;i++){
  1884. bindData.push({'id':data[i].key,'text':data[i].descName});
  1885. }
  1886. return {results: bindData};
  1887. }
  1888. },
  1889. createSearchChoice:function(term, data) { if ($(data).filter(function() { return this.text.localeCompare(term)===0; }).length===0) {return {id:term, text:term};} },
  1890. }).on("select2-selecting", function(e) {
  1891. etdBtnId=this.id.substr('selectLink'.length);
  1892. var result = [];
  1893. for(var i = 0;i < res.length;i++){
  1894. result.push({'id':res[i].key,'text':res[i].descName});
  1895. }
  1896. if(result.length==0){//如果没有属性 弹出添加属性框
  1897. //置空
  1898. d3.select("#proType").property('value','');
  1899. d3.select("#proNo").property('value','');
  1900. d3.select('#overlay').style('display','block');
  1901. d3.select('#win').style('display','block');
  1902. return;
  1903. }
  1904. //console.log ("selecting val="+ e.val+" choice="+ JSON.stringify(e.choice));
  1905. for(var i=0;i<result.length;i++){
  1906. if(e.choice.id==result[i].id && e.choice.text==result[i].text){//用户选择的是已有的属性
  1907. //nodes props
  1908. var props=selected_link.props;
  1909. // 用户选择不能重复
  1910. for(var key in props){
  1911. if(e.val==key && e.val!=etdId){
  1912. jAlert("此资产已有此属性,请另外选择!",'提示',function(){
  1913. //绑定默认值
  1914. $('#selectLink'+etdId).select2('data', {id:etdId,text:value});
  1915. });
  1916. return;
  1917. }
  1918. }
  1919. //用户选择验证通过 写入到nodes中
  1920. for(var p in props){
  1921. if(p==etdId){
  1922. delete props[etdId];
  1923. selected_link.props[e.choice.id]=e.choice.text;
  1924. showLink();//此处不重新加载(shownode) 会有问题
  1925. return;
  1926. }
  1927. }
  1928. }else if((i==result.length-1) && (e.choice!=result[i])){//用户新输入的
  1929. //置空
  1930. d3.select("#proType").property('value','');
  1931. d3.select("#proNo").property('value','');
  1932. d3.select('#overlay').style('display','block');
  1933. d3.select('#win').style('display','block');
  1934. return;
  1935. }
  1936. }
  1937. });;
  1938. //绑定默认值
  1939. $('#selectLink'+etdId).select2('data', {id:etdId,text:value});
  1940. }else{//确定
  1941. d3.select('#edtBtnLink'+etdId).property('name','edtBtn');
  1942. d3.select('#edtBtnLink'+etdId).attr('style','background-image:url(css/img/tup/xiug.jpg);width:22px;height:22px;');
  1943. //数据写入links
  1944. var props=selected_link.props;
  1945. for(var key in props){
  1946. if(key==etdId){
  1947. var k=null;
  1948. var text=d3.select('#inputLink'+etdId).property('value');
  1949. if(k==0){
  1950. k=d3.select('#selectLink'+etdId).property('value');
  1951. }else{
  1952. k=etdId;
  1953. }
  1954. delete props[etdId];
  1955. props[k]=text;
  1956. showLink();
  1957. return;
  1958. }
  1959. }
  1960. showLink();
  1961. }
  1962. }
  1963. //节点属性删除按钮点击事件
  1964. function delBtnClk(delId){
  1965. jConfirm('确定删除?', '提示', function(r) {
  1966. if(r){
  1967. //提交的时候只删除数据,不删除属性表数据
  1968. //删除表格
  1969. d3.select('#tr'+delId).selectAll('td').remove('td');
  1970. //删除node属性
  1971. var props=selected_node.props;
  1972. for(var key in props){
  1973. if(delId==key){
  1974. delete props[key];//删除node中元素
  1975. return;
  1976. }
  1977. }
  1978. }
  1979. });
  1980. }
  1981. //连线属性删除按钮点击事件
  1982. function delBtnLinkClk(delId){
  1983. jConfirm('确定删除?', '提示', function(r) {
  1984. //提交的时候只删除数据,不删除属性表数据
  1985. if(r){
  1986. //删除表格
  1987. d3.select('#trLink'+delId).selectAll('td').remove('td');
  1988. //删除node属性
  1989. var props=selected_link.props;
  1990. for(var key in props){
  1991. if(delId==key){
  1992. delete props[delId];//删除link中元素
  1993. return;
  1994. }
  1995. }
  1996. }
  1997. });
  1998. }
  1999. //连线名 的选择事件 选择后将 值写入到 selected_node
  2000. d3.select('#linkName').on('change',function(){
  2001. var num=0;
  2002. for(var key in selected_link.props){
  2003. num++;
  2004. break;
  2005. }
  2006. var tType=this;
  2007. if(num>0){
  2008. jConfirm('更换名称选项,动态属性将会被删除,是否继续?', '提示', function(r) {
  2009. if(r){
  2010. selected_link.name=tType.value;
  2011. selected_link.props={};
  2012. showLink();
  2013. selected_link['props']={};
  2014. fixPro(tType.value);
  2015. }else{
  2016. tType.value=selected_link.name;
  2017. return;
  2018. }
  2019. });
  2020. }else{
  2021. selected_link.name=tType.value;
  2022. selected_link['props']={};
  2023. fixPro(tType.value);
  2024. }
  2025. });
  2026. //加载固定属性(节点/连线)
  2027. function fixPro(label){
  2028. if(selected_node){//操作节点
  2029. var labelId=null;
  2030. //根据选择‘节点’的label 查询label的ID
  2031. d3.xhr(window.basePath+"/api/cm/findLabel?sign="+label).send("GET",
  2032. function(error, json) {
  2033. if (!error){
  2034. labelId =JSON.parse(json.responseText).id;
  2035. $.ajax({
  2036. type: "GET",
  2037. url: window.basePath+"/api/cm/findByPro",
  2038. data: {sourceType : 1,sourceId: labelId},
  2039. dataType: "json",
  2040. success:function(data){
  2041. var keys=[];
  2042. for(var i = 0;i < data.length;i++){
  2043. var entity=data[i];
  2044. if(entity.fix==1){
  2045. var key=entity.key;
  2046. keys.push(key);
  2047. selected_node['props'][key]='';
  2048. }
  2049. }
  2050. //先移除div中原来的标签
  2051. d3.select('#nodeTab').selectAll('tr').remove('tr');
  2052. d3.select('#nodeTab').selectAll('tr')
  2053. .data(keys).enter()
  2054. .append('tr')
  2055. .attr('id',function(d){
  2056. return 'tr'+d;
  2057. })
  2058. .html(function(d){ //undefined
  2059. var str="";
  2060. //新增加行
  2061. var strS="";
  2062. for(var i = 0;i < data.length;i++){
  2063. var entity=data[i];
  2064. if(entity.fix==1 && entity.key==d){//固态属性 并且key相等
  2065. if(entity.valueType=="date"){
  2066. strS='<input id="input'+d+'" placeholder="请输入日期" style="width: 151px;" class="laydate-icon" onClick="laydate({istime: true, format: \'YYYY-MM-DD hh:mm:ss\'})" value="'
  2067. +'" disabled>';
  2068. }else{
  2069. strS='<input type="text" id="input'+d+'" value="" disabled/>';
  2070. }
  2071. //类型设置 读取JSON string date int float
  2072. str+='<td style="padding-left: 0px;width:145px;"><span id="span'
  2073. +d+'">'+entity.descName+':</span></td>'+
  2074. '<td style="padding-left: 21px;">'+strS+'</td><td>'+'<input id="edtBtn'+d
  2075. +'" name="edtBtn" type="button" style="background-image:url(css/img/tup/xiug.jpg);width:22px;height:22px;" onclick="edtBtnClk(\''
  2076. +entity.valueType+'\',\''+d+'\',\''+entity.descName+'\',\''+entity.fix+'\')" />'+'&nbsp;</td>';
  2077. break;
  2078. }
  2079. }
  2080. return str;
  2081. });
  2082. },
  2083. error:function(data){jAlert("服务器访问异常!",'提示');}
  2084. });
  2085. }
  2086. });
  2087. }else if(selected_link){//操作连线
  2088. var sourceId=null;
  2089. for(var i=0;i<linkType.length;i++){
  2090. if(label==linkType[i].type){
  2091. sourceId=linkType[i].id;
  2092. }
  2093. }
  2094. if(sourceId!=null){
  2095. $.ajax({
  2096. type: "GET",
  2097. url: window.basePath+"/api/cm/findByPro",
  2098. data: {sourceType : 2,sourceId: sourceId},
  2099. dataType: "json",
  2100. success:function(data){
  2101. var keys=[];
  2102. for(var i = 0;i < data.length;i++){
  2103. var entity=data[i];
  2104. if(entity.fix==1){
  2105. var key=entity.key;
  2106. keys.push(key);
  2107. selected_link['props'][key]='';
  2108. }
  2109. }
  2110. //先移除div中原来的标签
  2111. d3.select('#linkTab').selectAll('tr').remove('tr');
  2112. d3.select('#linkTab').selectAll('tr')
  2113. .data(keys).enter()
  2114. .append('tr')
  2115. .attr('id',function(d){
  2116. return 'tr'+d;
  2117. })
  2118. .html(function(d){ //undefined
  2119. var str="";
  2120. //固态属性
  2121. var strS="";
  2122. for(var i = 0;i < data.length;i++){
  2123. var entity=data[i];
  2124. if(entity.fix==1 && entity.key==d){//固态属性 并且key相等
  2125. if(entity.valueType=="date"){
  2126. strS='<input id="inputLink'+d+'" placeholder="请输入日期" style="width: 151px;" class="laydate-icon" onClick="laydate({istime: true, format: \'YYYY-MM-DD hh:mm:ss\'})" value="" disabled>';
  2127. }else{
  2128. strS='<input type="text" id="inputLink'+d+'" value="" disabled/>';
  2129. }
  2130. //类型设置 读取JSON string date int float
  2131. str+='<td style="padding-left: 0px;width:145px;"><span id="spanLink'+d+'">'+entity.descName+':</span></td>'+
  2132. '<td style="padding-left: 21px;">'+strS+'</td><td>'+'<input id="edtBtnLink'+d
  2133. +'" type="button" name="edtBtn" style="background-image:url(css/img/tup/xiug.jpg);width:22px;height:22px;" onclick="edtBtnLinkClk(\''
  2134. +entity.valueType+'\',\''+d+'\',\''+entity.descName+'\',\''+entity.fix+'\')" />'
  2135. +'&nbsp;</td>';
  2136. break;
  2137. }
  2138. }
  2139. return str;
  2140. });
  2141. },
  2142. error:function(data){jAlert("服务器访问异常!",'提示');}
  2143. });
  2144. }
  2145. }
  2146. }
  2147. //节点'添加属性' 点击事件
  2148. d3.select('#addBtn').on('click',function(){
  2149. var label=d3.select('#nodeLabel').property('value');
  2150. if(""!=label){
  2151. addRow();
  2152. }else{
  2153. jAlert('请先选择资产类型!','提示');
  2154. }
  2155. });
  2156. //添加属性行
  2157. function addRow(){
  2158. if(selected_node.props){
  2159. selected_node.props['']='未定义';
  2160. }else{
  2161. selected_node['props']={'':'未定义'};
  2162. }
  2163. //用户写入的记录下来
  2164. updJson();
  2165. shownode();
  2166. }
  2167. //刷新时记录用户输入
  2168. function updJson(){
  2169. if(selected_node){
  2170. selected_node.assetNo=d3.select("#nodeAssetNo").property('value');
  2171. selected_node.name=d3.select("#nodeName").property('value');
  2172. selected_node.type=d3.select("#nodeType").property('value');
  2173. selected_node.label=d3.select("#nodeLabel").property('value');
  2174. selected_node.status=d3.select("#nodeStatus").property('value');
  2175. }else if(selected_link){
  2176. selected_link.name=d3.select("#linkName").property('value');
  2177. selected_link.cost=d3.select("#linkCost").property('value');
  2178. }
  2179. }
  2180. //=============弹出层添加属性begin=======================================
  2181. //加载属性类型
  2182. d3.select('#proType').selectAll('option')
  2183. .data(proTypes).enter()
  2184. .append('option')
  2185. .attr('value',function(d){return d.key;})
  2186. .html(function(d){ return d.value;});
  2187. //提交
  2188. d3.select('#addSubBtn').on('click',function(){
  2189. if(selected_node){
  2190. var proType=d3.select("#proType").property('value');
  2191. var proNo=d3.select("#proNo").property('value');
  2192. var desName=d3.select("#select"+etdBtnId).property('value');//正在编辑select2的值
  2193. //插入前先查询节点‘英文编号’的此label 此简称是否存在
  2194. var t=d3.select('#nodeLabel').property('value');
  2195. var labelId="";//选中的资源label的ID
  2196. for(var i=0;i<labels.length;i++){
  2197. if(labels[i].sign==t){
  2198. labelId=labels[i].id;
  2199. break;
  2200. }
  2201. }
  2202. $.ajax({
  2203. type: "GET",
  2204. url: window.basePath+"/api/cm/findByPros",
  2205. data: {sourceType : 1,sourceId: labelId,keyname:proNo},
  2206. dataType: "text",
  2207. success:function(data){
  2208. if(data==0){//数据库中没有此属性 允许插入
  2209. //插入操作 返回实体
  2210. $.ajax({
  2211. type: "POST",
  2212. contentType:"application/json; charset=UTF-8",
  2213. url: window.basePath+"/api/cm/dynparam",
  2214. data: JSON.stringify({ descName:desName, key:proNo, sourceId:labelId, sourceType:1, valueType:proType,fix:0}),//JSON.stringify(entity),fix:0动态属性
  2215. dataType: "json",
  2216. success:function(data){
  2217. //插入成功后改变正在编辑的
  2218. var props=selected_node.props;
  2219. for(var key in props){
  2220. if(key==etdBtnId){
  2221. delete props[key];
  2222. props[proNo]=desName;
  2223. //层隐藏
  2224. d3.select('#overlay').style('display','none');
  2225. d3.select('#win').style('display','none');
  2226. //更新属性
  2227. initParams();
  2228. restart();
  2229. return;
  2230. }
  2231. }
  2232. },
  2233. error: function(data){jAlert("服务器请求异常",'提示');}
  2234. });
  2235. }else{
  2236. jAlert("此属性编号已存在,请重新输入编号!",'提示');
  2237. }
  2238. },
  2239. error:function(data){jAlert("服务器访问异常!",'提示');}
  2240. });
  2241. }else if(selected_link){
  2242. var proType=d3.select("#proType").property('value');
  2243. var proNo=d3.select("#proNo").property('value');
  2244. var desName=d3.select("#selectLink"+etdBtnId).property('value');//正在编辑select2的值
  2245. //插入前先查询节点‘英文编号’的此label 此简称是否存在
  2246. var linkeName=d3.select('#linkName').property('value');
  2247. var linkId;//选中的name的ID 即属性表里的sourceId
  2248. for(var i=0;i<linkType.length;i++){
  2249. if(linkeName==linkType[i].type){
  2250. linkId=linkType[i].id;
  2251. }
  2252. }
  2253. $.ajax({
  2254. type: "GET",
  2255. url: window.basePath+"/api/cm/findByPros",
  2256. data: {sourceType : 2,sourceId: linkId,keyname:proNo},
  2257. dataType: "text",
  2258. success:function(data){
  2259. if(data==0){//数据库中没有此属性 允许插入
  2260. //插入操作 返回实体
  2261. $.ajax({
  2262. type: "POST",
  2263. contentType:"application/json; charset=UTF-8",
  2264. url: window.basePath+"/api/cm/dynparam",
  2265. data: JSON.stringify({ descName:desName, key:proNo, sourceId:linkId, sourceType:2, valueType:proType,fix:0}),//JSON.stringify(entity),
  2266. dataType: "json",
  2267. success:function(data){
  2268. //插入成功后改变正在编辑的
  2269. //params=JSON.parse(json.responseText);
  2270. var props=selected_link.props;
  2271. for(var key in props){
  2272. if(key==etdBtnId){
  2273. delete props[key];
  2274. props[proNo]=desName;
  2275. //层隐藏
  2276. d3.select('#overlay').style('display','none');
  2277. d3.select('#win').style('display','none');
  2278. //更新属性
  2279. initParams();
  2280. return;
  2281. }
  2282. }
  2283. },
  2284. error: function(data){jAlert("服务器请求异常",'提示');}
  2285. });
  2286. }else{
  2287. jAlert("此属性编号已存在,请重新输入编号!",'提示');
  2288. }
  2289. },
  2290. error:function(data){jAlert("服务器访问异常!",'提示');}
  2291. });
  2292. }
  2293. });
  2294. //取消
  2295. d3.select('#addResBtn').on('click',function(){
  2296. d3.select('#overlay').style('display','none');
  2297. d3.select('#win').style('display','none');
  2298. });
  2299. //关闭
  2300. d3.select('#close').on('click',function(){
  2301. d3.select('#overlay').style('display','none');
  2302. d3.select('#win').style('display','none');
  2303. });
  2304. //=================添加属性end==============================================
  2305. //连线'添加属性' 点击事件
  2306. d3.select('#addBtn1').on('click',function(){
  2307. addRow1();
  2308. });
  2309. //添加节点
  2310. function addRow1(){
  2311. if(selected_link){
  2312. if(selected_link.props){
  2313. selected_link.props['']='未定义';
  2314. }else{
  2315. selected_link['props']={'':'未定义'};
  2316. }
  2317. updJson();
  2318. showLink();
  2319. }
  2320. }
  2321. function cancel(){
  2322. for(var i=0;i<links.length;i++){//确保用户不提交的时候不出错
  2323. if(links[i].id==-1){
  2324. // delete links[i];
  2325. links.splice(i, 1);
  2326. break;
  2327. }
  2328. }
  2329. };
  2330. //取消1
  2331. d3.select('#addResBtn1').on('click',function(){
  2332. d3.select('#overlay1').style('display','none');
  2333. d3.select('#win1').style('display','none');
  2334. });
  2335. //数据导入
  2336. d3.select("#importData").on("click",function(){
  2337. d3.select('#overlay1').style('display','block');
  2338. d3.select('#win1').style('display','block');
  2339. });
  2340. //上传
  2341. d3.select("#importBtn").on("click",function(){
  2342. var name=d3.select("#importFile").property('value');
  2343. var suffix=name.substring(name.lastIndexOf(".")+1,name.length);
  2344. if(suffix!="xls" && suffix!="xlsx"){
  2345. jAlert("请选择EXCEL文件!",'提示');
  2346. return;
  2347. }else{
  2348. var form=$("#myform")[0];
  2349. form.method="POST";
  2350. form.action=window.basePath +"/api/cm/importFile";
  2351. form.submit();
  2352. jAlert("上传成功!",'提示');
  2353. d3.select('#overlay1').style('display','none');
  2354. d3.select('#win1').style('display','none');
  2355. }
  2356. });
  2357. }]);