showxmindimport.ui.js 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580
  1. var mindmapMgr = undefined;
  2. $(document).ready(function()
  3. {
  4. mindmapMgr = new ztmindmap.Wraper({
  5. product: productID,
  6. branch: branch,
  7. typeKeys:{
  8. module: userConfig_module,
  9. scene: userConfig_scene,
  10. testcase: userConfig_case,
  11. stepGroup: userConfig_group,
  12. precondition: userConfig_precondition,
  13. pri: userConfig_pri
  14. }
  15. });
  16. $.get($.createLink('testcase', 'getXmindImport'),function(res)
  17. {
  18. var data = JSON.parse(res);
  19. if(ztmindmap.isArray(data))
  20. {
  21. var rootTopic = data[0].rootTopic;
  22. mindmapMgr.initFromJSON(rootTopic);
  23. }
  24. else
  25. {
  26. var sheet = data["xmap-content"]["sheet"];
  27. if(ztmindmap.isArray(sheet)) sheet = sheet[0];
  28. mindmapMgr.initFromSheet(sheet);
  29. }
  30. setTimeout(() => mindmapMgr.render(), 500)
  31. });
  32. $("#xmindmapSave").on("click",function(e)
  33. {
  34. var data = mindmapMgr.toJson();
  35. if(data.testcaseList.length == 0)
  36. {
  37. zui.Modal.alert(jsLng.caseNotExist);
  38. return;
  39. }
  40. var hasExist = false;
  41. for(i in data.sceneList)
  42. {
  43. if(hasExist) break;
  44. var scene = data.sceneList[i];
  45. if(typeof(scene.id) != 'undefined') hasExist = true;
  46. }
  47. for(i in data.testcaseList)
  48. {
  49. if(hasExist) break;
  50. var testcase = data.testcaseList[i];
  51. if(typeof(testcase.id) != 'undefined') hasExist = true;
  52. }
  53. if(hasExist)
  54. {
  55. var confirmActions = [{btnType: 'primary', class: 'btn-wide', key: 'confirm', text: importAndCoverLang}, {class: 'btn-wide', key: 'cancel', text: importAndInsertLang}];
  56. zui.Modal.confirm({message: noticeImport, actions: confirmActions, onResult: (confirmed) => {submitXmindImport(data, confirmed ? 0 : 1);}});
  57. return;
  58. }
  59. submitXmindImport(data);
  60. })
  61. });
  62. function submitXmindImport(data, insert)
  63. {
  64. if(typeof(insert) == 'undefined') insert = 1;
  65. var sceneList = JSON.stringify(data.sceneList);
  66. var testcaseList = JSON.stringify(data.testcaseList);
  67. var form = new FormData();
  68. form.append("insert", insert);
  69. form.append("productID", productID);
  70. form.append("branch", branch);
  71. form.append("sceneList", sceneList);
  72. form.append("testcaseList", testcaseList);
  73. $.ajaxSubmit({url: $.createLink('testcase', 'saveXmindImport'), data: form});
  74. }
  75. function setStories(){
  76. //do nothing
  77. }
  78. if(window.ztmindmap == undefined) window.ztmindmap = {};
  79. ztmindmap.ModuleManager = function(wraper){ this.wraper = wraper;}
  80. ztmindmap.ModuleManager.prototype.clearNodeDisplay = function($node, data){ $node.find(".suffix").hide();};
  81. ztmindmap.ModuleManager.prototype.getContextMenuList = function(data)
  82. {
  83. if(data.$.typeBy.import == true) return [];
  84. //如果上一个节点时模型,当前节点可以在 ”场景“ 和 ”测试用例间切换“
  85. var parentNode = this.wraper.findParentNode(data);
  86. if(parentNode.$.type == "module")
  87. {
  88. var menus = [];
  89. if(data.$.type == "testcase" || data.$.type == undefined) menus.push({action:"addScene", label:jsLng.set2Scene});
  90. if(data.$.type == "scene" || data.$.type == undefined) menus.push({action:"addTestcase", label:jsLng.set2Testcase});
  91. if(data.$.type != undefined) menus.push({action:"delType", label:jsLng.clearSetting});
  92. return menus;
  93. }
  94. return [];
  95. };
  96. ztmindmap.ModuleManager.prototype.delType = function($node,data)
  97. {
  98. this.wraper.changeNodeType($node,data,undefined);
  99. this.wraper.clearTypeAfter($node,data);
  100. //this.refreshDisplay();
  101. }
  102. ztmindmap.ModuleManager.prototype.addScene = function($node,data)
  103. {
  104. var moduleData = this.wraper.findParentData(data);
  105. data.$.moduleID = moduleData.$.moduleID;
  106. this.wraper.changeNodeType($node,data,"scene");
  107. this.wraper.clearTypeAfter($node,data);
  108. //this.refreshDisplay();
  109. }
  110. ztmindmap.ModuleManager.prototype.addTestcase = function($node,data)
  111. {
  112. this.wraper.changeNodeType($node,data,"testcase");
  113. this.wraper.clearTypeAfter($node,data);
  114. //this.refreshDisplay();
  115. }
  116. ztmindmap.ModuleManager.prototype.refreshNodeDisplay = function($node, data)
  117. {
  118. $node.find(".suffix").hide();
  119. if(data.$.moduleID != undefined)
  120. {
  121. $node.find(".suffix").show();
  122. $node.find(".suffix").find(".content").html(this.wraper.disKeys['module'] + ":" + data.$.moduleID);
  123. }
  124. }
  125. ztmindmap.ModuleManager.prototype.refreshDisplay = function(){ this.wraper.refreshDisplay();};
  126. if(window.ztmindmap == undefined) window.ztmindmap = {};
  127. ztmindmap.SceneManager = function(wraper)
  128. {
  129. this.wraper = wraper;
  130. this.proprMgr = new ztmindmap.SceneProperyManager(this);
  131. this.proprMgr.init();
  132. };
  133. ztmindmap.SceneManager.prototype.clearNodeDisplay = function($node, data)
  134. {
  135. $node.find(".suffix").hide();
  136. $node.find(".scene-indicator").hide();
  137. $node.removeAttr("title");
  138. data.tooltip = undefined;
  139. data.$.moduleID = undefined;
  140. $node.tooltip('destroy');
  141. };
  142. ztmindmap.SceneManager.prototype.refreshNodeDisplay = function($node, data)
  143. {
  144. $node.find(".scene-indicator").show();
  145. $node.find(".scene-indicator").removeClass("scene-indicator-yes");
  146. if(data.$.moduleID != undefined)
  147. {
  148. $node.attr("title",data.tooltip);
  149. $node.tooltip();
  150. $node.find(".scene-indicator").addClass("scene-indicator-yes");
  151. }
  152. if(data.$.sceneID != undefined)
  153. {
  154. $node.find(".suffix").show();
  155. $node.find(".suffix").find(".content").html(this.wraper.disKeys['scene'] + ":" + data.$.sceneID);
  156. }
  157. };
  158. ztmindmap.SceneManager.prototype.getContextMenuList = function(data)
  159. {
  160. var parentNode = this.wraper.findParentNode(data);
  161. if(parentNode.$.type == "scene" && (data.$.type != "testcase" && data.$.type != "scene"))
  162. return [{action:"addTestcase", label:jsLng.set2Testcase}];
  163. if(data.$.typeBy.import == true || data.$.type != "scene") return [];
  164. //如果有父场景(包括父父节点),当前节点禁止设置所属模块,只能最前面的场景节点设置
  165. var parents = this.wraper.findParentNodes(data);
  166. for(var i=0;i<parents.length;i++)
  167. {
  168. var item = parents[i];
  169. if(item.$.type == "scene") return [];
  170. }
  171. return [{action:"configModule", label:jsLng.setModule}];
  172. };
  173. ztmindmap.SceneManager.prototype.addTestcase = function($node,data)
  174. {
  175. this.wraper.changeNodeType($node,data,"testcase");
  176. this.wraper.clearTypeAfter($node,data);
  177. //this.refreshDisplay();
  178. }
  179. ztmindmap.SceneManager.prototype.configModule = function($node,data){ this.proprMgr.show($node,data);};
  180. ztmindmap.SceneManager.prototype.refreshDisplay = function(){ this.wraper.refreshDisplay();}
  181. ztmindmap.SceneProperyManager = function(mgr)
  182. {
  183. this.$modal = undefined;
  184. this.$node = undefined;
  185. this.data = undefined;
  186. this.mgr = mgr;
  187. };
  188. ztmindmap.SceneProperyManager.prototype.init = function()
  189. {
  190. var that = this;
  191. this.$modal = new zui.ModalBase('#moduleSelector', {show: false});
  192. this.$modal.$element.find("#sceneProperySave").on("click",function(){ that.save();});
  193. this.$modal.$element.find("#moduleSelectorCancel").on("click",function(){ that.$modal.hide();});
  194. };
  195. ztmindmap.SceneProperyManager.prototype.show = function($node,data)
  196. {
  197. this.$node = $node;
  198. this.data = data;
  199. if(data.$.type != "scene") return;
  200. var initScene = data.$.sceneID || 0;
  201. this.$modal.$element.find(".picker").zui('picker').$.setValue(initScene);
  202. this.$modal.show();
  203. };
  204. ztmindmap.SceneProperyManager.prototype.save = function()
  205. {
  206. var moduleID = this.$modal.$element.find("[name='module']").val();
  207. if(moduleID == undefined || moduleID == 0)
  208. {
  209. alert(jsLng.pickModule);
  210. return;
  211. }
  212. var moduleName = this.$modal.$element.find(".picker-single-selection").html();
  213. this.data.$.moduleID = moduleID;
  214. this.data.tooltip = moduleName;
  215. this.mgr.refreshNodeDisplay(this.$node,this.data);
  216. this.mgr.wraper.autoSetSceneModuleAfter(this.$node,this.data);
  217. this.mgr.refreshDisplay();
  218. this.$modal.hide();
  219. };
  220. if(window.ztmindmap == undefined) window.ztmindmap = {};
  221. ztmindmap.StepGroupManager = function(wraper){ this.wraper = wraper;};
  222. ztmindmap.StepGroupManager.prototype.clearNodeDisplay = function($node, data){ $node.find(".suffix").hide();};
  223. ztmindmap.StepGroupManager.prototype.refreshNodeDisplay = function($node, data)
  224. {
  225. $node.find(".suffix").hide();
  226. $node.find(".suffix").show();
  227. $node.find(".suffix").find(".content").html(this.wraper.disKeys['stepGroup']);
  228. };
  229. if(window.ztmindmap == undefined) window.ztmindmap = {};
  230. ztmindmap.PreconditionManager = function(wraper){ this.wraper = wraper; };
  231. ztmindmap.PreconditionManager.prototype.clearNodeDisplay = function($node, data){ $node.find(".suffix").hide();};
  232. ztmindmap.PreconditionManager.prototype.refreshNodeDisplay = function($node, data)
  233. {
  234. $node.find(".suffix").hide();
  235. $node.find(".suffix").show();
  236. $node.find(".suffix").find(".content").html(this.wraper.disKeys['precondition']);
  237. };
  238. if(window.ztmindmap == undefined) window.ztmindmap = {};
  239. /**
  240. * 设为场景:节点后面的自动推断, 按照最多4级来判断:测试用例 -> 步骤分组 ->步骤 -> 期望结果
  241. *
  242. * 清除前面场景:不做其他推断
  243. * 清除后面场景:直接子节点设置为测试用例
  244. * 清除当前场景:仅在只有一个场景的情况下有这个菜单,同时删除所有用例
  245. *
  246. * 设为废弃:当前节点及其后续节点全部丢掉
  247. * 重新启用:当前节点及其后续节点全部启用
  248. *
  249. * 清除场景: 操作不够明确,无法判断用户意图,这里不提供
  250. */
  251. ztmindmap.nodeTemplate =
  252. "<div data-toggle='tooltip' data-placement='bottom' id='node-{id}' class='mindmap-node' data-type='{type}' data-id='{id}' data-parent='{parent}'>" +
  253. " <div class='scene-indicator' style='display:none;'><i class='icon icon-flag'></i></div>" +
  254. " <a class='pri-level' style='display:none;'></a>" +
  255. " <div class='wrapper'>" +
  256. " <div class='text'>{text}</div>" +
  257. " <div class='caption'>{caption}</div>" +
  258. " <div class='btn-toggle'></div>" +
  259. " </div>" +
  260. " <div class='suffix'><span>[</span><span class='content'>M:10000</span><span>]</span></div>" +
  261. "</div>";
  262. ztmindmap.defaultTypeKeys = {
  263. module: "M",
  264. scene: "S",
  265. testcase: "C",
  266. stepGroup:"G",
  267. precondition:"pre",
  268. pri: "P"
  269. }
  270. ztmindmap.Wraper = function(params)
  271. {
  272. this.data = undefined;
  273. this.productID = params.product;
  274. this.branch = params.branch;
  275. this.typeKeys = $.extend({},ztmindmap.defaultTypeKeys,params.typeKeys);
  276. this.disKeys = $.extend({},ztmindmap.defaultTypeKeys,params.typeKeys);
  277. for(var key in this.typeKeys) this.typeKeys[key] = this.typeKeys[key].toLowerCase();
  278. this.nodeMgrs = {
  279. scene: new ztmindmap.SceneManager(this),
  280. testcase: new ztmindmap.TestcaseManager(this),
  281. module: new ztmindmap.ModuleManager(this),
  282. stepGroup: new ztmindmap.StepGroupManager(this),
  283. precondition: new ztmindmap.PreconditionManager(this)
  284. }
  285. };
  286. ztmindmap.Wraper.prototype.initFromJSON = function(root)
  287. {
  288. var rootNode = this.paserXmindNode(root,0);
  289. this.xmindJson2zendao(root,rootNode,1);
  290. this.data = rootNode;
  291. this.inheritImportProps();
  292. }
  293. ztmindmap.Wraper.prototype.initFromSheet = function(sheet)
  294. {
  295. var title = ztmindmap.isObject(sheet.title) ? sheet.title.text : sheet.title;
  296. var root = {id:sheet.id, text:title,children:[],type:"tmpTop"};
  297. this.xmindXml2zendao(sheet.topic, root, 0);
  298. this.data = root.children[0];
  299. this.inheritImportProps();
  300. };
  301. ztmindmap.Wraper.prototype.render = function()
  302. {
  303. var that = this;
  304. that.instance = createMindmap({
  305. hSpace:80,
  306. showToggleButton: true,
  307. nodeTeamplate: ztmindmap.nodeTemplate,
  308. data: that.data,
  309. enableDrag: false,
  310. subLineWidth: 2,
  311. afterNodeLoad: function(event)
  312. {
  313. var data = event.data;
  314. var $node = event.$node;
  315. that.refreshNodeDisplay($node,data);
  316. that.register($node,data);
  317. $node.on("contextmenu",function(e)
  318. {
  319. var contextMenuList = that.getContextMenuList(data);
  320. if(contextMenuList.length == 0) return;
  321. e.preventDefault();
  322. mindmap$.zui.ContextMenu.show(contextMenuList,{event:e,onClickItem:function(item)
  323. {
  324. if(item.type == undefined)
  325. that[item.action] && that[item.action]($node,data);
  326. else
  327. that.nodeMgrs[item.type][item.action] && that.nodeMgrs[item.type][item.action]($node, data);
  328. }});
  329. });
  330. }
  331. });
  332. for(var key in this.nodeMgrs)
  333. {
  334. this.nodeMgrs[key]["init"] && this.nodeMgrs[key]["init"]();
  335. }
  336. };
  337. ztmindmap.Wraper.prototype.refreshDisplay = function(){ this.instance.showNode();};
  338. ztmindmap.Wraper.prototype.getContextMenuList = function(data)
  339. {
  340. var contextMenuList = [];
  341. if(data.$.typeBy.import == false)
  342. {
  343. if(data.$.type != "scene")
  344. {
  345. var parents = this.findParentNodes(data);
  346. var canChangeToScene = true;
  347. for(var i=parents.length-1;i>=0;i--)
  348. {
  349. var item = parents[i];
  350. if(item.$.type == "testcase" || item.$.type == "stepGroup")
  351. {
  352. canChangeToScene = false;
  353. break;
  354. }
  355. }
  356. if(canChangeToScene == true) contextMenuList.push({ action: "setAsScene", label: jsLng.set2Scene});
  357. }
  358. if(data.$.type == "scene")
  359. {
  360. var removeBeforeScene = this.canRemoveSceneBefore(data);
  361. var removeAfterScene = this.canRemoveSceneAfter(data);
  362. if(removeBeforeScene == true) contextMenuList.push({ action: "clearBeforeScene", label: jsLng.clearBefore });
  363. if(removeAfterScene == true) contextMenuList.push({ action: "clearAfterScene", label: jsLng.clearAfter });
  364. if(removeBeforeScene == false && removeAfterScene == false && data.$.typeBy.import == false) contextMenuList.push({ action: "clearCurrentScene", label: jsLng.clearCurrent });
  365. }
  366. }
  367. for(var key in this.nodeMgrs)
  368. {
  369. var mgr = this.nodeMgrs[key];
  370. var menuList = mgr.getContextMenuList != undefined ? mgr.getContextMenuList(data) : [];
  371. if(menuList.length > 0 && contextMenuList.length >0) contextMenuList.push({type:"divider"});
  372. for(var i=0; i<menuList.length; i++)
  373. {
  374. var menuItem = menuList[i];
  375. menuItem.type = key;
  376. contextMenuList.push(menuItem);
  377. }
  378. }
  379. return contextMenuList;
  380. }
  381. ztmindmap.Wraper.prototype.setAsScene = function($node, data)
  382. {
  383. this.changeNodeType($node,data, "scene");
  384. this.autoReasoningAfter($node,data);
  385. //如果父节点也是场景
  386. let parent = this.findParentNode(data);
  387. if(parent.$.type == "scene" && parent.$.moduleID != undefined)
  388. {
  389. let $parent = mindmap$("#node-" + parent.id);
  390. this.copyScenePropertyAfter($parent,parent);
  391. }
  392. this.refreshDisplay();
  393. }
  394. ztmindmap.Wraper.prototype.copyScenePropertyAfter = function($node, data)
  395. {
  396. var children = data.children || [];
  397. for(var childData of children)
  398. {
  399. if(childData.$.type != "scene") continue;
  400. if(childData.$.typeBy.import == true) continue;
  401. childData.$.moduleID = data.$.moduleID;
  402. var $childNode = mindmap$("#node-" + childData.id);
  403. this.refreshNodeDisplay($childNode,childData);
  404. this.copyScenePropertyAfter($childNode,childData);
  405. }
  406. }
  407. ztmindmap.Wraper.prototype.clearTypeAfter = function($node, data)
  408. {
  409. var that = this;
  410. var children = data.children || [];
  411. for(var child of children)
  412. {
  413. var $child = mindmap$("#node-" + child.id);
  414. clearTypeImpl($child, child);
  415. }
  416. function clearTypeImpl($curNode, curData)
  417. {
  418. that.changeNodeType($curNode,curData,undefined);
  419. var curChildren = curData.children || [];
  420. for(var curChild of curChildren)
  421. {
  422. var $curChild = mindmap$("#node-" + curChild.id);
  423. clearTypeImpl($curChild, curChild);
  424. }
  425. }
  426. this.refreshDisplay();
  427. }
  428. ztmindmap.Wraper.prototype.clearBeforeScene = function($node, data)
  429. {
  430. var beforeScenes = this.findParentNodes(data);
  431. for(var sceneData of beforeScenes)
  432. {
  433. if(sceneData.$.type != "scene" || sceneData.$.typeBy.import == true) continue;
  434. var $sceneNode = mindmap$("#node-" + sceneData.id);
  435. this.changeNodeType($sceneNode,sceneData,undefined);
  436. }
  437. this.refreshDisplay();
  438. }
  439. ztmindmap.Wraper.prototype.clearAfterScene = function($node,data)
  440. {
  441. this.autoRemoveSceneAfer($node,data);
  442. var children = data.children || [];
  443. for(var child of children)
  444. {
  445. var $child = mindmap$("#node-" + child.id);
  446. this.changeNodeType($child,child,"testcase");
  447. }
  448. this.refreshDisplay();
  449. }
  450. ztmindmap.Wraper.prototype.clearCurrentScene = function($node, data)
  451. {
  452. if(data.$.typeBy.import == true) return;
  453. this.changeNodeType($node,data,undefined);
  454. this.autoRemoveSceneAfer($node,data);
  455. var parentData = this.findParentData(data);
  456. if(parentData.$.type == "scene")
  457. {
  458. this.changeNodeType($node,data,"testcase");
  459. }
  460. this.refreshDisplay();
  461. }
  462. /**
  463. * 从给定节点开始(给定节点是场景节点)自动推动后续场景节点
  464. * @param {*} $node 给定的场景节点$dom 元素
  465. * @param {*} data 给定的场景节点数据
  466. */
  467. ztmindmap.Wraper.prototype.autoReasoningAfter = function($node,data)
  468. {
  469. var children = data.children || [];
  470. for(var i=0; i<children.length; i++)
  471. {
  472. var childData = children[i];
  473. var $childNode = mindmap$("#node-" + childData.id);
  474. if(childData.$.typeBy.import == true) continue;
  475. if(childData.$.type == "scene") continue;
  476. //获取给定子节点的子元素长度(包括节点本身)
  477. var length = ztmindmap.getLengthOfNode(childData);
  478. //测试用例 -> 测试步骤 -> 预期
  479. //测试用例 -> 测试步骤分组 -> 测试步骤 -> 预期
  480. if(length > 4)
  481. {
  482. //本身 + 子元素长度 大于 4 的肯定不是测试用例,这里自动推断为场景
  483. childData.$.moduleID = data.$.moduleID;
  484. childData.tooltip = data.tooltip;
  485. this.changeNodeType($childNode,childData,"scene");
  486. this.autoReasoningAfter($childNode,childData);
  487. }
  488. else
  489. {
  490. //本身 + 子元素长度 小于等于 4 的可能是场景,也可能是测试用例,这里默认推断为测试用例
  491. //这里需要用户通过界面手动指定
  492. this.changeNodeType($childNode,childData,"testcase");
  493. }
  494. }
  495. }
  496. /**
  497. * 移除给点节点下面的所有场景 和 测试用例
  498. * @param {Object} $node 给定节点$Dom
  499. * @param {Object} data 给定节点数据
  500. */
  501. ztmindmap.Wraper.prototype.autoRemoveSceneAfer = function($node,data)
  502. {
  503. var children = data.children || [];
  504. for(var i=0; i<children.length; i++)
  505. {
  506. var childData = children[i];
  507. var $childNode = mindmap$("#node-" + childData.id);
  508. if(childData.$.typeBy.import == true) continue;
  509. //所有后续节点都先设置成 undefined
  510. this.changeNodeType($childNode,childData,undefined);
  511. this.autoRemoveSceneAfer($childNode,childData);
  512. }
  513. }
  514. /**
  515. * 自动设置后续所有的场景模块为指定节点的模块
  516. * @param {Object} $node 指定节点
  517. * @param {Object} data 指定节点的数据
  518. */
  519. ztmindmap.Wraper.prototype.autoSetSceneModuleAfter = function($node, data)
  520. {
  521. var children = data.children || [];
  522. for(var child of children)
  523. {
  524. if(child.$.type == "scene")
  525. {
  526. child.$.moduleID = data.$.moduleID;
  527. child.tooltip = data.tooltip;
  528. $child = mindmap$("#node-" + child.id);
  529. this.refreshNodeDisplay($child,child);
  530. this.autoSetSceneModuleAfter($child,child)
  531. }
  532. }
  533. this.refreshDisplay();
  534. }
  535. /**
  536. * 判断是否能删除给定场景节点前面的场景
  537. * 必须满足:
  538. * @param {Object} data
  539. */
  540. ztmindmap.Wraper.prototype.canRemoveSceneBefore = function(data)
  541. {
  542. var scenes = this.findParentNodes(data);
  543. for(var scene of scenes)
  544. {
  545. if(scene.$.type == "scene") return scene.$.typeBy.import == false;
  546. }
  547. return false;
  548. }
  549. ztmindmap.Wraper.prototype.canRemoveSceneAfter = function(data)
  550. {
  551. var children = data.children || [];
  552. for(var child of children)
  553. {
  554. if(child.$.type == "scene")
  555. {
  556. return child.$.typeBy.import == false;
  557. }
  558. else
  559. {
  560. if(this.canRemoveSceneAfter(child) == true) return true;
  561. }
  562. }
  563. return false;
  564. }
  565. /**
  566. * 获取所有的叶子节点数据
  567. */
  568. ztmindmap.Wraper.prototype.getLeafDatas = function()
  569. {
  570. var leafs = [];
  571. function findLeafs(data)
  572. {
  573. if(data.children == undefined || data.children.length == 0)
  574. leafs.push(data);
  575. else
  576. {
  577. var children = data.children || [];
  578. for(var child of children)
  579. {
  580. findLeafs(child);
  581. }
  582. }
  583. }
  584. findLeafs(this.data);
  585. return leafs;
  586. }
  587. ztmindmap.Wraper.prototype.findParentData = function(purData)
  588. {
  589. var parentList = this.findParentDatas(purData);
  590. return parentList.length >=2 ? parentList[parentList.length-2] : undefined;
  591. }
  592. /**
  593. * 查找给数据的父节点,父父数据的集合(包括当前叶子节点)
  594. * @param {Object} purData
  595. */
  596. ztmindmap.Wraper.prototype.findParentDatas = function(purData)
  597. {
  598. var results = [];
  599. function findParentDataPath(data)
  600. {
  601. if(data == purData) return true;
  602. var children = data.children || [];
  603. for(var child of children)
  604. {
  605. if(findParentDataPath(child) == true)
  606. {
  607. results.unshift(child);
  608. return true;
  609. }
  610. }
  611. return false;
  612. }
  613. var flag = findParentDataPath(this.data);
  614. if(flag == true) results.unshift(this.data);
  615. return results;
  616. }
  617. /**
  618. * 查找给数据的父节点,父父节点的集合
  619. * 倒序,使用的时候注意坑
  620. * @param {Object} data
  621. */
  622. ztmindmap.Wraper.prototype.findParentNodes = function(data)
  623. {
  624. var results = [];
  625. function findParentPath(iData)
  626. {
  627. if(iData.id == data.parent)
  628. {
  629. results.push(iData);
  630. return true;
  631. }
  632. var children = iData.children || [];
  633. for(var child of children)
  634. {
  635. if(findParentPath(child) == true)
  636. {
  637. results.push(child);
  638. return true;
  639. }
  640. }
  641. return false;
  642. }
  643. findParentPath(this.instance.data);
  644. return results;
  645. }
  646. /**
  647. * 查找给定数据的父节点
  648. * @param {Object} data 给定数据
  649. */
  650. ztmindmap.Wraper.prototype.findParentNode = function(data)
  651. {
  652. function findParentImpl(iData)
  653. {
  654. if(iData.id == data.parent) return iData;
  655. var children = iData.children || [];
  656. for(var child of children)
  657. {
  658. var result = findParentImpl(child);
  659. if(result != undefined) return result;
  660. }
  661. return undefined;
  662. }
  663. return findParentImpl(this.instance.data);
  664. }
  665. ztmindmap.Wraper.prototype.refreshNodeDisplay = function($node,data)
  666. {
  667. var mgr = this.nodeMgrs[data.$.type];
  668. mgr && mgr.refreshNodeDisplay && mgr.refreshNodeDisplay($node,data);
  669. }
  670. ztmindmap.Wraper.prototype.register = function($node, data)
  671. {
  672. var mgr = this.nodeMgrs[data.$.type];
  673. mgr && mgr.register && mgr.register($node,data);
  674. }
  675. ztmindmap.Wraper.prototype.changeNodeType = function($node,data,newType)
  676. {
  677. if(data.$.type == newType) return;
  678. var oldMgr = this.nodeMgrs[data.$.type];
  679. var newMgr = this.nodeMgrs[newType];
  680. data.$.type = newType;
  681. if(oldMgr != undefined)
  682. {
  683. oldMgr["clearNodeDisplay"] && oldMgr["clearNodeDisplay"]($node,data);
  684. oldMgr["unRegister"] && oldMgr["unRegister"]($node,data);
  685. }
  686. if(newMgr != undefined)
  687. {
  688. newMgr["refreshNodeDisplay"] && newMgr["refreshNodeDisplay"]($node,data);
  689. newMgr["register"] && newMgr["register"]($node,data);
  690. }
  691. };
  692. ztmindmap.Wraper.prototype.xmindXml2zendao = function(topic, parent,level)
  693. {
  694. var obj = this.paserXmindNode(topic,level);
  695. parent.children.push(obj);
  696. var joinChildren = [];
  697. if(topic.children != undefined)
  698. {
  699. var children = topic.children;
  700. if(ztmindmap.isObject(children)) children = [children];
  701. for(child of children)
  702. {
  703. var topicsList = child.topics;
  704. if(ztmindmap.isObject(topicsList)) topicsList = [topicsList];
  705. for(var topics of topicsList)
  706. {
  707. var topic = topics.topic;
  708. if(typeof topic == 'undefined') continue;
  709. if(ztmindmap.isObject(topic)) topic = [topic];
  710. for(var t of topic)
  711. {
  712. joinChildren.push(t);
  713. }
  714. }
  715. }
  716. }
  717. for(var i=0; i<joinChildren.length; i++)
  718. this.xmindXml2zendao(joinChildren[i],obj,level+1);
  719. };
  720. ztmindmap.Wraper.prototype.xmindJson2zendao = function(parentJson, parentNode,level)
  721. {
  722. if(parentJson.children == undefined) return;
  723. if(parentJson.children.attached == undefined) return;
  724. var children = parentJson.children;
  725. var attached = children.attached;
  726. if(ztmindmap.isArray(attached) == false)
  727. attached = [attached];
  728. for(var att of attached)
  729. {
  730. var obj = this.paserXmindNode(att,level);
  731. parentNode.children.push(obj);
  732. this.xmindJson2zendao(att,obj,level+1);
  733. }
  734. };
  735. /**
  736. * 导出的数据再次导入时,自动继承设置属性
  737. * 1)模块后面的所有场景继承模块的Id
  738. * 2)场景后面的所有子场景继承场景的模块
  739. * 3)场景之前的所有节点,前置设置为场景,并不容许删除(import=true, create=auto)
  740. */
  741. ztmindmap.Wraper.prototype.inheritImportProps = function()
  742. {
  743. if(this.data.$.typeBy.import == false || this.data.$.productID == undefined) return;
  744. var leafs = this.getLeafDatas();
  745. for(var leaf of leafs)
  746. {
  747. var strandList = this.findParentDatas(leaf);
  748. //两个场景之间的其他节点统一设置为场景节点
  749. checkOtherBetweenScene(strandList);
  750. //两个 import 之间的场景强制设置为 import
  751. checkImportBetweenImportScene(strandList);
  752. //module 或者 scene 节点后的所有场景节点模块都设置成 module or scene 节点对应的ID
  753. checkSceneAfterModuleNode(strandList);
  754. //最后一个场景的下一个节点默认识别为测试用例
  755. checkLastSceneAfter(strandList);
  756. }
  757. function checkLastSceneAfter(dataList)
  758. {
  759. var lastIndex = -1;
  760. for(var i=dataList.length-1;i>=0;i--)
  761. {
  762. if(dataList[i].$.type == "scene")
  763. {
  764. lastIndex = i;
  765. break;
  766. }
  767. }
  768. if(lastIndex < 0 || lastIndex == dataList.length-1) return;
  769. var nextData = dataList[lastIndex+1];
  770. nextData.$.type = "testcase";
  771. }
  772. function checkOtherBetweenScene(dataList)
  773. {
  774. var firstSceneIndex = -1;
  775. var lastSceneIndex = -1;
  776. for(var i=0;i<dataList.length;i++)
  777. {
  778. if(dataList[i].$.type == "scene")
  779. {
  780. firstSceneIndex = i;
  781. break;
  782. }
  783. }
  784. for(var i=dataList.length-1;i>=0;i--)
  785. {
  786. if(dataList[i].$.type == "scene")
  787. {
  788. lastSceneIndex = i;
  789. break;
  790. }
  791. }
  792. if(firstSceneIndex == lastSceneIndex)
  793. return;
  794. for(var i=firstSceneIndex;i<=lastSceneIndex;i++)
  795. {
  796. dataList[i].$.type = "scene";
  797. }
  798. }
  799. function checkSceneAfterModuleNode(dataList)
  800. {
  801. var referIndex = -1;
  802. for(var i=0;i<dataList.length;i++)
  803. {
  804. if(dataList[i].$.type == "module" || dataList[i].$.type == "scene")
  805. {
  806. referIndex = i;
  807. break;
  808. }
  809. }
  810. if(referIndex < 0) return;
  811. var moduleID = dataList[referIndex].$.moduleID;
  812. for(var i=referIndex + 1; i<dataList.length;i++)
  813. {
  814. if(dataList[i].$.type == "scene") dataList[i].$.moduleID = moduleID;
  815. }
  816. }
  817. function checkImportBetweenImportScene(dataList)
  818. {
  819. var firstSceneIndex = -1;
  820. var lastSceneIndex = -1;
  821. for(var i=0;i<dataList.length;i++)
  822. {
  823. if(dataList[i].$.type == "scene" && dataList[i].$.typeBy.import == true)
  824. {
  825. firstSceneIndex = i;
  826. break;
  827. }
  828. }
  829. for(var i=dataList.length-1;i>=0;i--)
  830. {
  831. if(dataList[i].$.type == "scene" && dataList[i].$.typeBy.import == true)
  832. {
  833. lastSceneIndex = i;
  834. break;
  835. }
  836. }
  837. if(firstSceneIndex == lastSceneIndex) return;
  838. for(var i=firstSceneIndex;i<=lastSceneIndex;i++)
  839. {
  840. dataList[i].$.typeBy.import = true;
  841. dataList[i].$.typeBy.create = "auto";
  842. }
  843. }
  844. }
  845. ztmindmap.Wraper.prototype.paserXmindNode = function(nodeData, level)
  846. {
  847. var titleInfo = ztmindmap.splitText(getNodeText(nodeData.title));
  848. var obj = { id:nodeData.id,
  849. text: titleInfo.text,
  850. type: level == 0 ? "root": (level == 1 ? "sub" : "node"),
  851. children:[],
  852. subSide:"right",
  853. $:{
  854. type: undefined,
  855. typeBy: { import:false, create: "auto" }
  856. }};
  857. var props = ztmindmap.kv2Obj(titleInfo.suffix);
  858. if(obj.type == "root" && titleInfo.suffix != undefined)
  859. this['setPropsInProduct'] && this['setPropsInProduct'](obj, titleInfo.suffix);
  860. else if(props[this.typeKeys.module] != undefined)
  861. this['setPropsInModule'] && this['setPropsInModule'](obj, props);
  862. else if(props[this.typeKeys.scene] != undefined)
  863. this['setPropsInScene'] && this['setPropsInScene'](obj, props);
  864. else if(props[this.typeKeys.testcase] != undefined)
  865. this['setPropsInTestcase'] && this['setPropsInTestcase'](obj, props);
  866. else if(props[this.typeKeys.precondition] != undefined)
  867. this['setPropsInPrecondition'] && this['setPropsInPrecondition'](obj, props);
  868. else if(props[this.typeKeys.stepGroup] != undefined)
  869. {
  870. obj.$.type = "stepGroup";
  871. obj.$.typeBy.import = true;
  872. }
  873. else if(typeof(nodeData.title) == 'string')
  874. {
  875. let varType = typeof(nodeData.title);
  876. if(varType == 'string') obj.text = nodeData.title;
  877. if(varType == 'object') obj.text = nodeData.title.text;
  878. }
  879. return obj;
  880. function getNodeText(v)
  881. {
  882. return ztmindmap.isObject(v) ? v.text : v;
  883. }
  884. };
  885. ztmindmap.Wraper.prototype.setPropsInProduct = function(obj, suffix)
  886. {
  887. if(ztmindmap.isID(suffix) == false) return;
  888. obj.readonly = true;
  889. obj.$.productID = suffix * 1;
  890. obj.$.type = "product";
  891. obj.$.typeBy.import = true;
  892. obj.$.typeBy.create = "auto";
  893. }
  894. ztmindmap.Wraper.prototype.setPropsInModule = function(obj, props)
  895. {
  896. var moduleID = props[this.typeKeys.module];
  897. obj.$.type = "module";
  898. obj.$.typeBy.create = "auto";
  899. if(ztmindmap.isID(moduleID) == true)
  900. {
  901. obj.readonly = true;
  902. obj.$.moduleID = moduleID;
  903. obj.$.typeBy.import = true;
  904. }
  905. }
  906. ztmindmap.Wraper.prototype.setPropsInScene = function(obj, props)
  907. {
  908. var sceneID = props[this.typeKeys.scene];
  909. obj.$.type = "scene";
  910. obj.$.typeBy.create = "auto";
  911. if(ztmindmap.isID(sceneID))
  912. {
  913. obj.$.sceneID = sceneID;
  914. obj.$.typeBy.import = true;
  915. }
  916. }
  917. ztmindmap.Wraper.prototype.setPropsInTestcase = function(obj, props)
  918. {
  919. var testcaseID = props[this.typeKeys.testcase];
  920. obj.$.type = "testcase";
  921. obj.$.pri = props[this.typeKeys['pri']] || 3;
  922. obj.$.typeBy.create = "auto";
  923. if(ztmindmap.isID(testcaseID))
  924. {
  925. obj.$.testcaseID = testcaseID;
  926. obj.$.typeBy.import = true;
  927. }
  928. }
  929. ztmindmap.Wraper.prototype.setPropsInPrecondition = function(obj, props)
  930. {
  931. var precondition = props[this.typeKeys.precondition];
  932. obj.$.type = "precondition";
  933. obj.$.typeBy.create = "auto";
  934. obj.$.typeBy.import = true;
  935. obj.$.precondition = precondition;
  936. }
  937. ztmindmap.Wraper.prototype.toJson = function()
  938. {
  939. var that = this;
  940. var sceneList = [];
  941. var testcaseList = [];
  942. var rootData = this.instance.data;
  943. function sceneToJson(data)
  944. {
  945. if(data.$.type == "scene") sceneList.push(that.singleSceneToJson(data));
  946. if(data.$.type == "testcase") return;
  947. var children = data.children || [];
  948. for(var child of children) sceneToJson(child);
  949. }
  950. function testcaseToJson(data)
  951. {
  952. if(data.$.type == "testcase")
  953. testcaseList.push(that.singleTestCaseToJson(data));
  954. else {
  955. var children = data.children || [];
  956. for(var child of children)
  957. testcaseToJson(child);
  958. }
  959. }
  960. sceneToJson(rootData);
  961. testcaseToJson(rootData);
  962. return {sceneList:sceneList, testcaseList:testcaseList};
  963. };
  964. ztmindmap.Wraper.prototype.singleSceneToJson = function(data)
  965. {
  966. var obj = {
  967. name: data.text,
  968. module: ztmindmap.toNum(data.$.moduleID,undefined),
  969. product: this.productID * 1,
  970. branch: this.branch * 1,
  971. tmpId: data.id,
  972. tmpPId: data.parent,
  973. }
  974. if(data.$.sceneID != undefined && data.$.sceneID != "") obj.id = data.$.sceneID * 1;
  975. return obj;
  976. };
  977. ztmindmap.Wraper.prototype.singleTestCaseToJson = function(data)
  978. {
  979. var parentNode = this.findParentNode(data);
  980. //获取测试用例数据
  981. var obj = {
  982. pri: ztmindmap.toNum(data.$.pri,3),
  983. name: data.text,
  984. //module: ztmindmap.toNum(scene.$.moduleID,0),
  985. product: this.productID * 1,
  986. branch: this.branch * 1,
  987. precondition:'',
  988. tmpId: data.id,
  989. tmpPId: data.parent,
  990. }
  991. if(parentNode.$.type == "scene")
  992. obj.module = ztmindmap.toNum(parentNode.$.moduleID,0);
  993. else if(parentNode.$.type == "module")
  994. obj.module = ztmindmap.toNum(parentNode.$.moduleID,0);
  995. else
  996. obj.module = 0;
  997. //设置测试用例的id
  998. if(data.$.testcaseID != undefined && data.$.testcaseID != "")
  999. obj.id = data.$.testcaseID * 1;
  1000. //获取测试用例的步骤
  1001. obj.stepList = [];
  1002. var children = data.children || [];
  1003. for(var child of children)
  1004. {
  1005. if(child.$.type == "precondition")
  1006. {
  1007. obj.precondition = child.text;
  1008. continue;
  1009. }
  1010. var step = {
  1011. type: "step",
  1012. desc: child.text,
  1013. tmpId: child.id,
  1014. tmpPId: child.parent,
  1015. }
  1016. obj.stepList.push(step);
  1017. var maxLng = ztmindmap.getLengthOfNode(child);
  1018. var nextChilds = child.children || [];
  1019. //child的子元素:
  1020. //1) 有且仅只有一个,这个子元素作为期望结果来处理
  1021. if(maxLng == 2 && child.$.type != "stepGroup")
  1022. {
  1023. step.expect = nextChilds[0].text;
  1024. step.type = "step";
  1025. continue;
  1026. }
  1027. //2) 有多个子元素, 当前元素是步骤分组, 这些子元素作为子步骤
  1028. if(maxLng > 2 || child.$.type == "stepGroup")
  1029. {
  1030. step.type = "group";
  1031. for(var nextChild of nextChilds)
  1032. {
  1033. var subStep = {
  1034. type: "item",
  1035. desc: nextChild.text,
  1036. tmpId: nextChild.id,
  1037. tmpPId: nextChild.parent
  1038. };
  1039. obj.stepList.push(subStep);
  1040. //如果后续只有一个子元素,作为期望的结果来处理。
  1041. var nextNextChild = nextChild.children || [];
  1042. if(nextNextChild.length == 1)
  1043. subStep.expect = nextNextChild[0].text;
  1044. if(nextNextChild.length > 1)
  1045. {
  1046. subStep.type = "group";
  1047. for(var thirdLevelNode of nextNextChild)
  1048. {
  1049. var thirdLevelStep = {
  1050. type: "item",
  1051. desc: thirdLevelNode.text,
  1052. tmpId: thirdLevelNode.id,
  1053. tmpPId: thirdLevelNode.parent
  1054. };
  1055. //如果后续只有一个子元素,作为期望的结果来处理,超过一个子元素,丢掉后面的子元素
  1056. var forthLevelNode = thirdLevelNode.children || [];
  1057. if(forthLevelNode.length == 1)
  1058. thirdLevelStep.expect = forthLevelNode[0].text;
  1059. obj.stepList.push(thirdLevelStep);
  1060. }
  1061. }
  1062. }
  1063. }
  1064. }
  1065. return obj;
  1066. };
  1067. if(window.ztmindmap == undefined) window.ztmindmap = {};
  1068. ztmindmap.TestcaseManager = function(wraper)
  1069. {
  1070. this.wraper = wraper;
  1071. this.priSelector = undefined;
  1072. }
  1073. ztmindmap.TestcaseManager.prototype.init = function()
  1074. {
  1075. this.priSelector = new ztmindmap.PriSelector(this);
  1076. }
  1077. ztmindmap.TestcaseManager.prototype.register = function($node, data)
  1078. {
  1079. let that = this;
  1080. $node.find(".pri-level").on("click",function(e)
  1081. {
  1082. that.priSelector.show($node,data);
  1083. });
  1084. };
  1085. ztmindmap.TestcaseManager.prototype.unRegister = function($node, data)
  1086. {
  1087. $node.find(".pri-level").unbind();
  1088. };
  1089. ztmindmap.TestcaseManager.prototype.getContextMenuList = function(data)
  1090. {
  1091. var parent = this.wraper.findParentNode(data);
  1092. if(parent == undefined || parent.$.type != "testcase" || data.$.type == "precondition")
  1093. return [];
  1094. if(data.$.type == "stepGroup")
  1095. return [{action:"removeStepGroup", label:jsLng.removeGroup}];
  1096. else
  1097. return [{action:"addStepGroup", label:jsLng.set2Group}];
  1098. };
  1099. ztmindmap.TestcaseManager.prototype.removeStepGroup = function($node,data)
  1100. {
  1101. this.wraper.changeNodeType($node,data,undefined);
  1102. this.refreshDisplay();
  1103. }
  1104. ztmindmap.TestcaseManager.prototype.addStepGroup = function($node,data)
  1105. {
  1106. this.wraper.changeNodeType($node,data,"stepGroup");
  1107. this.refreshDisplay();
  1108. }
  1109. ztmindmap.TestcaseManager.prototype.clearNodeDisplay = function($node, data)
  1110. {
  1111. $node.find(".suffix").hide();
  1112. $node.find(".pri-level").hide();
  1113. };
  1114. ztmindmap.TestcaseManager.prototype.refreshNodeDisplay = function($node, data)
  1115. {
  1116. $node.find(".pri-level").show();
  1117. $node.find(".pri-level").removeClass("pri-1");
  1118. $node.find(".pri-level").removeClass("pri-2");
  1119. $node.find(".pri-level").removeClass("pri-3");
  1120. $node.find(".pri-level").removeClass("pri-4");
  1121. if(data.$.pri == undefined)
  1122. {
  1123. $node.find(".pri-level").addClass("pri-empty");
  1124. $node.find(".pri-level").html("");
  1125. }
  1126. else
  1127. {
  1128. $node.find(".pri-level").removeClass("pri-empty");
  1129. $node.find(".pri-level").html(data.$.pri);
  1130. $node.find(".pri-level").addClass("pri-" + data.$.pri);
  1131. }
  1132. if(data.$.testcaseID != undefined)
  1133. {
  1134. $node.find(".suffix").show();
  1135. $node.find(".suffix").find(".content").html(this.wraper.disKeys['testcase'] + ":" + data.$.testcaseID);
  1136. }
  1137. };
  1138. ztmindmap.TestcaseManager.prototype.refreshDisplay = function()
  1139. {
  1140. this.wraper.refreshDisplay();
  1141. }
  1142. ztmindmap.PriSelector = function(mgr)
  1143. {
  1144. this.$gradeDom = undefined;
  1145. this.$node = undefined;
  1146. this.data = undefined;
  1147. this.mgr = mgr;
  1148. this.init();
  1149. };
  1150. ztmindmap.PriSelector.prototype.init = function()
  1151. {
  1152. var that = this;
  1153. var htmlStr = "";
  1154. htmlStr += "<div class='testcase-pri-root effect'>";
  1155. htmlStr += " <a pri='1' class='pri-1' href='javascript:void(0);'>1</a>";
  1156. htmlStr += " <a pri='2' class='pri-2' href='javascript:void(0);'>2</a>";
  1157. htmlStr += " <a pri='3' class='pri-3' href='javascript:void(0);'>3</a>";
  1158. htmlStr += " <a pri='4' class='pri-4' href='javascript:void(0);'>4</a>";
  1159. htmlStr += "</div>";
  1160. var $priDom = mindmap$(htmlStr);
  1161. mindmap$(".mindmap-container").append($priDom);
  1162. $priDom.find("a").on("click",function(e)
  1163. {
  1164. var pri = mindmap$(e.currentTarget).attr("pri");
  1165. that.data.$.pri = pri;
  1166. that.mgr.refreshNodeDisplay(that.$node,that.data);
  1167. that.mgr.refreshDisplay();
  1168. });
  1169. mindmap$(document).on("click",function(e)
  1170. {
  1171. that.hide();
  1172. })
  1173. $priDom.hide();
  1174. that.$priDom = $priDom;
  1175. };
  1176. ztmindmap.PriSelector.prototype.show = function($node, data)
  1177. {
  1178. this.$node = $node;
  1179. this.data = data;
  1180. var nodeLeft = $node.position().left - 15;
  1181. var nodeTop = $node.position().top;
  1182. var nodeHeight = $node.height();
  1183. this.$priDom.css({left:nodeLeft, top:nodeTop + nodeHeight + 10});
  1184. this.$priDom.show();
  1185. };
  1186. ztmindmap.PriSelector.prototype.hide = function($node, data)
  1187. {
  1188. this.$node = undefined;
  1189. this.data = undefined;
  1190. this.$priDom && this.$priDom.hide();
  1191. };
  1192. if(window.ztmindmap == undefined) window.ztmindmap = {};
  1193. ztmindmap.isArray = function(obj)
  1194. {
  1195. return Object.prototype.toString.call(obj) === '[object Array]';
  1196. }
  1197. ztmindmap.isObject = function(obj)
  1198. {
  1199. return Object.prototype.toString.call(obj) === '[object Object]';
  1200. };
  1201. ztmindmap.getLengthOfNode = function(data)
  1202. {
  1203. var maxLength = 0;
  1204. var children = data.children || [];
  1205. for(var i=0; i<children.length; i++)
  1206. {
  1207. var tmpLength = ztmindmap.getLengthOfNode(children[0]);
  1208. maxLength = Math.max(maxLength, tmpLength);
  1209. }
  1210. return maxLength + 1;
  1211. }
  1212. ztmindmap.toNum = function(v, defaultValue = undefined)
  1213. {
  1214. if(v == undefined || v == "")
  1215. return defaultValue ? defaultValue * 1 : defaultValue;
  1216. return v * 1;
  1217. }
  1218. ztmindmap.trim = function(str)
  1219. {
  1220. if(str == undefined) return undefined;
  1221. return str.replace(/(^\s*)|(\s*$)/g, "");
  1222. }
  1223. ztmindmap.splitText = function(str)
  1224. {
  1225. str = ztmindmap.trim(str);
  1226. if(str == undefined || str == "") return {text:undefined, suffix:undefined};
  1227. var last = str.substr(str.length-1,1);
  1228. if(last != "]" && last != "】") return {text:str, suffix:undefined};
  1229. var sIndex1 = str.lastIndexOf("[");
  1230. var sIndex2 = str.lastIndexOf("【");
  1231. var sIndex = Math.max(sIndex1,sIndex2);
  1232. if(sIndex < 0) return {text:str, suffix:undefined};
  1233. var text = str.substring(0, sIndex);
  1234. var suffix = str.substring(sIndex+1, str.length-1);
  1235. return {text:ztmindmap.trim(text), suffix:ztmindmap.trim(suffix)};
  1236. }
  1237. ztmindmap.kv2Obj = function(suffix)
  1238. {
  1239. if(suffix == undefined) return {};
  1240. suffix = suffix.replace(",",",");
  1241. suffix = suffix.replace(":",":");
  1242. suffix = suffix.toLowerCase();
  1243. var obj = {};
  1244. var kvList = suffix.split(",");
  1245. for(var kvStr of kvList)
  1246. {
  1247. var tmpKvStr = ztmindmap.trim(kvStr);
  1248. if(tmpKvStr == undefined || tmpKvStr == "") continue;
  1249. var kvSplit = tmpKvStr.split(":");
  1250. var key = undefined;
  1251. var value = undefined;
  1252. if(kvSplit.length == 1)
  1253. {
  1254. key = ztmindmap.trim(kvSplit[0]);
  1255. value = key;
  1256. }
  1257. else
  1258. {
  1259. key = ztmindmap.trim(kvSplit[0]);
  1260. value = ztmindmap.trim(kvSplit[1]);
  1261. }
  1262. obj[key] = value;
  1263. }
  1264. return obj;
  1265. }
  1266. ztmindmap.isID = function(str)
  1267. {
  1268. if(str == undefined || str == "") return false;
  1269. return /(^[1-9]\d*$)/.test(str);
  1270. }