Configure.cshtml 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421
  1. @*
  2. For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
  3. *@
  4. @using Edge.Core.Processor.Dispatcher;
  5. @model IEnumerable<ProcessorMetaDescriptor>;
  6. @{
  7. Layout = null;
  8. }
  9. @*<link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre.min.css">
  10. <link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre-exp.min.css">
  11. <link rel="stylesheet" href="https://unpkg.com/spectre.css/dist/spectre-icons.min.css">
  12. <script src="https://cdn.jsdelivr.net/npm/@@json-editor/json-editor@latest/dist/jsoneditor.min.js"></script>*@
  13. <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
  14. <link rel="stylesheet" href="~/lib/spectre/spectre.css" />
  15. <link rel="stylesheet" href="~/lib/spectre/spectre-exp.css" />
  16. <link rel="stylesheet" href="~/lib/spectre/spectre-icons.css" />
  17. <link rel="stylesheet" href="~/lib/spectre/spectre-icons.css" />
  18. <link rel="stylesheet" href="~/css/configure.css" />
  19. <script src="~/js/jsoneditor.js"></script>
  20. <script src="~/js/jquery-3.4.1.min.js"></script>
  21. <script src="~/js/jquery-ui.js"></script>
  22. <style type="text/css">
  23. a:hover {
  24. background: rgba(0, 148, 255, 0.37);
  25. color: white;
  26. }
  27. ul {
  28. list-style-type: none;
  29. }
  30. li {
  31. float: left;
  32. margin-right: 1%;
  33. }
  34. a {
  35. padding: 2px;
  36. }
  37. ::-webkit-scrollbar {
  38. display: none;
  39. }
  40. .tab {
  41. overflow: hidden;
  42. /*border: 1px solid #ccc;*/
  43. background-color: #f1f1f1;
  44. }
  45. .tab button {
  46. background-color: inherit;
  47. float: left;
  48. border: none;
  49. outline: none;
  50. cursor: pointer;
  51. padding: 14px 16px;
  52. transition: 0.3s;
  53. font-size: 17px;
  54. background: linear-gradient(-110deg, transparent 15px, #ddd 0);
  55. }
  56. /*Change background color of buttons on hover*/
  57. .tab button:hover {
  58. /*background-color: #ddd;*/
  59. background: linear-gradient(-110deg, transparent 15px, aliceblue 0);
  60. }
  61. /*Create an active/current tablink class*/
  62. .tab button.active {
  63. /*background-color: aliceblue;*/
  64. background: linear-gradient(-110deg, transparent 15px, aliceblue 0);
  65. }
  66. </style>
  67. @* main view of the configuration*@
  68. <div id="config_main" style="position:absolute;height:100%;width:100%;">
  69. <div id="config_header" style="position: relative; height: 6%; width: 100%;top:0px; border-bottom: double;">
  70. <ul id="tags" style="list-style: none; margin: 0; padding: 0;width:90%;">
  71. <li style="float:left;">
  72. <a asp-controller="Home" asp-action="Index">Home</a>
  73. </li>
  74. <li style="float:left;">
  75. |
  76. </li>
  77. @*<li id="li_all" name="tag" onclick="tagClick(this)"><a id="a_all">|</a></li>*@
  78. </ul>
  79. <input id="btn_restart" class="btn" type="button" value="Restart" onclick="ReloadProcessors(this.id)" style="position:absolute;right:1%;bottom:10%; border-left:dashed;border-right:none;border-bottom:none;border-top:none;" />
  80. <input id="btn_pre" class="btn" type="button" value="<<" onclick="previous(this.id)" style="position:absolute;right:8.5%;bottom:10%;border:none;" />
  81. <input id="btn_next" class="btn" type="button" value=">>" onclick="next(this.id)" style="position:absolute;right:6%;bottom:10%;border:none;" />
  82. @*<ul>
  83. <li class="nav-item" style="float:left;">
  84. <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
  85. </li>
  86. <li class="nav-item" style="float:left;">
  87. <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="WebApi">Web API</a>
  88. </li>
  89. <li class="nav-item" style="float:left;">
  90. <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="MqttApi">Mqtt API</a>
  91. </li>
  92. <li class="nav-item" style="float:left;">
  93. <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ProcessorMetaDescriptor">ProcessorMetaDescriptor</a>
  94. </li>
  95. <li class="nav-item" style="float:left;">
  96. <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Configure">Configure</a>
  97. </li>
  98. </ul>*@
  99. </div>
  100. <div id="page_body" style="position:relative;float:left;height:94%;width:100%;">
  101. <div id="processor_test_result_dialog" style="top: 130px;height: 20%; width: 60%;background-color:lightpink">
  102. <div id="processor_test_result_dialog_text"></div>
  103. </div>
  104. <div id="config_nav" style="position:relative;float:left;height:100%;width:16%;border-right:double;">
  105. <div style="border-bottom-style: double; height: 40%;overflow-y:auto;">
  106. <span style="background-color: bisque;width: 100%;">驅動(Drivers):</span>
  107. <ul id="config_nav_ul_device_processor" style="width: 90%; height: 100%; margin-top: 0px; margin-left: 5px;">
  108. @*@for (var i = 0; i < Model.Count(); i++)
  109. {
  110. var typeStr = Model.ToArray()[i].SourceEndpointFullTypeStr.Split(",")[1];
  111. <li id="processor_@i" name ="processor" style="width:100%;height:5%;" onclick="processorSelect(this)">@typeStr.Trim()</li>
  112. }*@
  113. </ul>
  114. </div>
  115. <div style="width: 100%; height: 60%;overflow-y:auto;">
  116. <span style="background-color: pink; width: 100%;">應用(Apps):</span>
  117. <ul id="config_nav_ul_app_processor" style="width: 90%; height: 100%; margin-top: 0px; margin-left: 5px;">
  118. @*@for (var i = 0; i < Model.Count(); i++)
  119. {
  120. var typeStr = Model.ToArray()[i].SourceEndpointFullTypeStr.Split(",")[1];
  121. <li id="processor_@i" name ="processor" style="width:100%;height:5%;" onclick="processorSelect(this)">@typeStr.Trim()</li>
  122. }*@
  123. </ul>
  124. </div>
  125. </div>
  126. <div id="config_body" style="position:relative;float:left;height:100%;width:84%;background-color:aliceblue;">
  127. <div id="config_body_filter" style="position:relative;float:left;width:100%;height:10%;">
  128. <div id="config_description" style="position:relative;float:left;overflow-y:auto;height:100%;width:99%;margin-left:1%;text-align:left;font-size:1rem;font:bold;border-bottom:groove;">
  129. <div id="config_description_subscribe" style="position:relative;float:left;height:50%;width:100%;"></div>
  130. <div id="config_description_details" style="position:relative; float:left; height:50%;width:100%;"></div>
  131. </div>
  132. @*用来作筛选可能*@
  133. <input id="config_add" type="button" value="Add" onclick="add()" style="position:absolute; right:1%; bottom:5%;border:none;" />
  134. </div>
  135. <div id="config_body_editorHolder" style="position: relative; float: left; width: 99%; height: 90%; margin-left: 1%;">
  136. @*配置部分*@
  137. </div>
  138. </div>
  139. </div>
  140. <div class="alarmInfoWrap hide">
  141. <div class="wrap-dialog hide">
  142. <div class="dialog">
  143. <div class="dialog-header">
  144. <span class="dialog-title"></span>
  145. </div>
  146. <div class="dialog-body">
  147. <span class="dialog-message"></span>
  148. </div>
  149. <div class="dialog-footer">
  150. <input type="button" class="btn" id="confirm" value="確認" />
  151. <input type="button" class="btn ml50" id="cancel" value="取消" />
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. <script>
  158. //读取到的当前数据库中的某个被选中
  159. var currentConfigurationFromDataBase = null;
  160. //当前被选中的Processor的schema
  161. var tempProcessor = null;
  162. var currentGroup = 0;
  163. //如果一个Group有多个metal processor descriptor的时候,一个被选中时,另一个需要被disabled
  164. var currentMPDDivMap = new Map();
  165. //用来存放某个具体的meta part descriptor配置editor
  166. //把processor index, group index, schemaStrs index and schema string index来构成editor map的key, 后面的schemaValue最好也是这样
  167. var currentSchemaStrEditorsMap = new Map();
  168. //存放每个editor value的map
  169. var schemaStrEdiorValueMap = new Map();
  170. //创建一个Map用来对应每个metal part schema 跟metal tab
  171. var metalPartTabSchemaMap = new Map();
  172. var tempConfig = null;
  173. var currentTagKey = "";
  174. var tempProcessors = null;
  175. var currenthref = window.location.href;
  176. var currentPath = window.location.pathname;
  177. var currentHP = currenthref.slice(0, currenthref.indexOf(currentPath) + 1);
  178. var currentPage = 0;
  179. function processorSelect(htmlElement) {
  180. console.log("processSelect");
  181. var editorHolder = document.getElementById("config_body_editorHolder");
  182. if (editorHolder === null || (htmlElement === null && tempProcessor === null)) { return; }
  183. clearChildHtmlElements(editorHolder);
  184. if (htmlElement !== null) {
  185. var procressorIndex = 0;
  186. if (Array.isArray(htmlElement.id.split("_"))) {
  187. procressorIndex = htmlElement.id.split("_")[1];
  188. }
  189. //var procressorIndex = htmlElement.id.slice(htmlElement.id.indexOf("_") + 1, htmlElement.id.indexOf("_") + 2);
  190. //var tempProcessors = JSON.parse(JSON.stringify(@Html.Raw(Json.Serialize(Model))));
  191. tempProcessor = tempProcessors[procressorIndex];
  192. updateLiBackground(htmlElement);
  193. }
  194. //if (document.getElementById("config_description")) {
  195. // document.getElementById("config_description").innerText = tempProcessor.description !== null ? tempProcessor.description : tempProcessor.sourceEndpointFullTypeStr;
  196. //}
  197. //查询的config名字需要跟保存时的一样
  198. var requestData = new Array();
  199. requestData.push(tempProcessor.sourceEndpointFullTypeStr);
  200. var tempUrl = this.currentHP + "u/?apitype=service&an=GetProcessorMetaConfigAsync&pn=ProcessorsDispatcher&en=Edge.Core.Processor.Dispatcher.DefaultDispatcher";
  201. //requestData.push(tempProcessor.sourceEndpointFullTypeStr.slice(0, tempProcessor.sourceEndpointFullTypeStr.indexOf(".")));
  202. $.ajax({
  203. url: tempUrl,
  204. datatype: "application/json",
  205. type: 'post',
  206. contentType: "application/json;charset=utf-8;",
  207. data: JSON.stringify(requestData),
  208. beforeSend: function () {
  209. },
  210. success: function (data) {
  211. var tempSavedConfigured = processorsMapViaTag.has("已配置") ? processorsMapViaTag.get("已配置") : null;
  212. var find = -1;
  213. if (tempSavedConfigured !== null) {
  214. tempSavedConfigured.forEach(function (p,index) {
  215. if (p.sourceEndpointFullTypeStr === tempProcessor.sourceEndpointFullTypeStr) find = index;
  216. });
  217. }
  218. if (data.length === 0 && find > -1) {
  219. processorsMapViaTag.get("已配置").splice(find,1);
  220. } else if (data.length > 0 && find === -1) {
  221. processorsMapViaTag.get("已配置").push(tempProcessor);
  222. }
  223. currentConfigurationFromDataBase = data;
  224. if (document.getElementById("config_description_subscribe")) {
  225. document.getElementById("config_description_subscribe").innerHTML = tempProcessor.displayName !== null ?
  226. tempProcessor.displayName + "共有" + (currentConfigurationFromDataBase === null ? "0" : currentConfigurationFromDataBase.length) + "條配置" : tempProcessor.sourceEndpointFullTypeStr;
  227. }
  228. if (document.getElementById("config_description_details"))
  229. document.getElementById("config_description_details").innerHTML = tempProcessor.description;
  230. BuildConfigTableForCurrentProcessor(currentConfigurationFromDataBase);
  231. console.log("get config data successfully");
  232. },
  233. error: function (err) {
  234. console.log(err);
  235. }
  236. });
  237. }
  238. function updateLiBackground(htmlElement) {
  239. if (htmlElement === null) return;
  240. var lis = document.getElementsByName(htmlElement.getAttribute("name"));
  241. if (lis === null) { return; }
  242. for (var i = 0; i < lis.length; i++) {
  243. if (lis[i] === htmlElement) {
  244. lis[i].style.background = "#0026ff"//"rgba(128, 128, 128, 0.35)";
  245. lis[i].style.color = "white";
  246. } else {
  247. lis[i].style.background = "white";
  248. lis[i].style.color = "black";
  249. }
  250. }
  251. }
  252. //当左侧某个processor被选中时,从数据库中读出该类processor所有的配置信息,生成一张表,可以通过表中的链接再创建配置页面
  253. function BuildConfigTableForCurrentProcessor(configDatas) {
  254. var editorHolder = document.getElementById("config_body_editorHolder");
  255. if (editorHolder === null) { return; }
  256. var configTable = document.createElement("table");
  257. configTable.style = "width:100%;height:100%;border-collapse:collapse;";
  258. var tableHead = document.createElement("thead");
  259. var headr = document.createElement("tr");
  260. tableHead.style = "display: table;width:100%;height:10%;table-layout:fixed;font-size: 1.2rem;";
  261. var tableData = document.createElement("td");
  262. tableData.style = "width:20%;text-align: center;";
  263. tableData.innerText = "Name";
  264. var tableData1 = document.createElement("td");
  265. tableData1.style = "width:25%;text-align: center;";
  266. tableData1.innerText = "Description";
  267. var tableData2 = document.createElement("td");
  268. tableData2.style = "width:20%;text-align: center;";
  269. tableData2.innerText = "Type";
  270. var tableData3 = document.createElement("td");
  271. tableData3.style = "width:20%;text-align: center;";
  272. tableData3.innerText = "Activated";
  273. var tableData4 = document.createElement("td");
  274. tableData4.style = "width:15%;text-align: center;";
  275. tableData4.innerText = "Operation";
  276. headr.appendChild(tableData);
  277. headr.appendChild(tableData1);
  278. headr.appendChild(tableData2);
  279. headr.appendChild(tableData3);
  280. headr.appendChild(tableData4);
  281. tableHead.appendChild(headr);
  282. configTable.appendChild(tableHead);
  283. var tableBody = document.createElement("tbody");
  284. tableBody.style = "height:90%;display: block;overflow:hidden;overflow-y: auto;";
  285. if (configDatas.length === 0) {
  286. var emptyRow = document.createElement("tr");
  287. emptyRow.style = "display:table;width:100%;height:10%;table-layout:fixed;font-size: 1.0rem;color:gray;text-align:left;";
  288. emptyRow.innerText = "當前有0條配置";
  289. tableBody.appendChild(emptyRow);
  290. }
  291. configDatas.forEach(function (config, index) {
  292. var tempr = document.createElement("tr");
  293. tempr.style = "display: table;width:100%;height:10%;table-layout:fixed;font-size: 1.0rem;";
  294. var temptableData = document.createElement("td");
  295. temptableData.style = "width:15%;text-align: center;";
  296. var Name_length = config.Name.length;
  297. temptableData.innerText = config.Name.slice(0, 5) + "..." + config.Name.slice(Name_length-5);
  298. var temptableData1 = document.createElement("td");
  299. temptableData1.style = "width:30%;text-align: center;";
  300. temptableData1.innerText = config.Description;
  301. var temptableData2 = document.createElement("td");
  302. temptableData2.style = "width:20%;text-align: center;";
  303. temptableData2.innerText = config.Type;
  304. var temptableData3 = document.createElement("td");
  305. temptableData3.style = "width:20%;text-align: center;";
  306. temptableData3.innerText = config.Activated;
  307. var temptableData4 = document.createElement("td");
  308. temptableData4.style = "width:15%;text-align: center;";
  309. var operationLink = document.createElement("a");
  310. operationLink.id = index.toString()+"_" + config.Id;
  311. operationLink.innerHTML = "編輯";
  312. operationLink.onclick = function (parameter) { showJsonEditorHodler(parameter) };
  313. var operationTestLink = document.createElement("a");
  314. operationTestLink.id = index.toString() + "_" + config.Id;
  315. operationTestLink.style = "margin-left:5%;";
  316. operationTestLink.innerHTML = "測試";
  317. operationTestLink.onclick = function (parameter) { TestProcessorMetaConfig(parameter) };
  318. var operationDeleteLink = document.createElement("a");
  319. operationDeleteLink.id = index.toString() + "_" + config.Id;
  320. operationDeleteLink.style = "margin-left:5%;";
  321. operationDeleteLink.innerHTML = "刪除";
  322. operationDeleteLink.onclick = function (parameter) { RemoveProcessorMetaConfig(parameter) };
  323. temptableData4.appendChild(operationLink);
  324. temptableData4.appendChild(operationDeleteLink);
  325. temptableData4.appendChild(operationTestLink);
  326. tempr.appendChild(temptableData);
  327. tempr.appendChild(temptableData1);
  328. tempr.appendChild(temptableData2);
  329. tempr.appendChild(temptableData3);
  330. tempr.appendChild(temptableData4);
  331. tableBody.appendChild(tempr);
  332. });
  333. configTable.appendChild(tableBody);
  334. editorHolder.appendChild(configTable);
  335. }
  336. //event is a mouse event currentTarget
  337. function showJsonEditorHodler(event) {
  338. if (tempProcessor === null) {
  339. console.log("the processor schema is null");
  340. alert("The Schema is null!!!");
  341. return;
  342. }
  343. //test to get config string
  344. var linkIndex = event.currentTarget.id;
  345. var configId = linkIndex.slice(linkIndex.indexOf("_") + 1);
  346. var configIndex = linkIndex.slice(0, linkIndex.indexOf("_"));
  347. tempConfig = currentConfigurationFromDataBase[configIndex];
  348. dialogBox("编辑配置", "确认编辑" + tempConfig.Description+"配置吗?", function () {
  349. updateEditorHolder(tempConfig);
  350. }, function () {
  351. tempConfig = null;
  352. });
  353. }
  354. //test the config to see if it can works ok
  355. function TestProcessorMetaConfig(event) {
  356. if (currentConfigurationFromDataBase === null) {
  357. console.log("currentConfigurationFromDataBase is null");
  358. alert("current config from DataBase is null!!!");
  359. return;
  360. }
  361. //test to get config string
  362. var linkIndex = event.currentTarget.id;
  363. var configIndex = linkIndex.slice(0, linkIndex.indexOf("_"));
  364. tempConfig = currentConfigurationFromDataBase[configIndex];
  365. dialogBox("测试配置", "确认测试" + tempConfig.Description + "配置吗?", function () {
  366. $(".ui-dialog").find(".ui-widget-header").css("background", "yellow");
  367. $("#processor_test_result_dialog_text").text("Please wait a while for the testing...");
  368. $("#processor_test_result_dialog")
  369. .dialog("option", "title", "Wait...")
  370. .dialog("option", "width", 500)
  371. .dialog('open');
  372. var requestData = new Array();
  373. requestData.push(tempConfig.Name);
  374. requestData.push(['no use']);
  375. var tempUrl = this.currentHP + "u/?apitype=service&an=TestProcessorMetaConfigAsync&pn=ProcessorsDispatcher&en=Edge.Core.Processor.Dispatcher.DefaultDispatcher";
  376. $.ajax({
  377. url: tempUrl,
  378. datatype: "application/json",
  379. type: 'post',
  380. contentType: "application/json;charset=utf-8;",
  381. data: JSON.stringify(requestData),
  382. beforeSend: function () {
  383. },
  384. success: function (data) {
  385. $("#processor_test_result_dialog").dialog('close');
  386. $(".ui-dialog").find(".ui-widget-header").css("background", "lightgreen");
  387. $("#processor_test_result_dialog_text").text("");
  388. $("#processor_test_result_dialog")
  389. .dialog("option", "title", "测试成功!!!")
  390. .dialog("option", "width", 500)
  391. .dialog('open');
  392. console.log("测试成功");
  393. },
  394. error: function (err) {
  395. $("#processor_test_result_dialog").dialog('close');
  396. $(".ui-dialog").find(".ui-widget-header").css("background", "red");
  397. $("#processor_test_result_dialog_text").text("" + err.responseText + "");
  398. $("#processor_test_result_dialog")
  399. .dialog("option", "title", "测试失败")
  400. .dialog("option", "width", 900)
  401. .dialog('open');
  402. //$("#config_body_dialog").dialog('open');
  403. //$("#config_body_dialog").html("测试失败: " + err.responseText);
  404. //alert("测试失败: " + err.responseText);
  405. console.log("测试失败: " + err.responseText);
  406. }
  407. });
  408. }, function () {
  409. tempConfig = null;
  410. });
  411. }
  412. //remove the config from DB
  413. function RemoveProcessorMetaConfig(event) {
  414. if (event.currentTarget === null || event.currentTarget.id === undefined)
  415. return
  416. var linkIndex = event.currentTarget.id;
  417. var configIndex = linkIndex.slice(0, linkIndex.indexOf("_"));
  418. tempConfig = currentConfigurationFromDataBase[configIndex];
  419. dialogBox("删除配置", "确认删除" + tempConfig.Description+"配置吗?", function () {
  420. //var linkIndex = event.currentTarget.id;
  421. var configId = linkIndex.slice(linkIndex.indexOf("_") + 1);
  422. var requestData = new Array();
  423. requestData.push(parseInt(configId));
  424. var tempUrl = this.currentHP + "u/?apitype=service&an=RemoveProcessorMetaConfigAsync&pn=ProcessorsDispatcher&en=Edge.Core.Processor.Dispatcher.DefaultDispatcher";
  425. $.ajax({
  426. url: tempUrl,
  427. datatype: "application/json",
  428. type: 'post',
  429. contentType: "application/json;charset=utf-8;",
  430. data: JSON.stringify(requestData),
  431. beforeSend: function () {
  432. },
  433. success: function (data) {
  434. alert("success")
  435. console.log("delete succuessfully");
  436. processorSelect(null);
  437. },
  438. error: function (err) {
  439. alert("刪除失敗:" + err.statusText + "\n" + err.responseText);
  440. console.log(err);
  441. }
  442. });
  443. }, function () {
  444. tempConfig = null;
  445. })
  446. }
  447. function updateEditorHolder(tempConfig) {
  448. if (tempProcessor === null) {
  449. console.log("the processor schema is null");
  450. alert("The Schema is null!!!");
  451. return;
  452. }
  453. //清掉editorBody中的所有子控件
  454. var editorbody = document.getElementById("config_body_editorHolder");
  455. if (editorbody === null) { console.log("config body div is null"); return; }
  456. buildEditorHolder();
  457. //var processorMeta = JSON.parse(tempProcessor);
  458. var mpgds = tempProcessor.metaPartsGroupDescriptors;
  459. if (!mpgds || mpgds.length === 0) { console.log("meta parts group is null in current processor:" + processorIndex); return; }
  460. metaGroupCount = mpgds.length;
  461. var btnNext = document.getElementById("next_group");
  462. if (btnNext) {
  463. btnNext.disabled = metaGroupCount > (currentGroup + 1) ? false : "disabled";
  464. }
  465. var btnSave = document.getElementById("save");
  466. if (btnSave) {
  467. btnSave.disabled = metaGroupCount > (currentGroup + 1) ? "disabled" : false;
  468. }
  469. var btnPre = document.getElementById("previous_group");
  470. if (btnPre) {
  471. btnPre.disabled = currentGroup > 0 ? false : "disabled";
  472. }
  473. console.log("1");
  474. editorHolder = document.getElementById("editor_holders");
  475. if (editorHolder === null) { console.log("editor_holders div is null"); return; }
  476. clearChildHtmlElements(editorHolder);
  477. var tempParts = new Map();
  478. if (tempConfig != null && tempConfig.SourceEndpointFullTypeStr.slice(0, tempConfig.SourceEndpointFullTypeStr.indexOf("Version=")) === tempProcessor.sourceEndpointFullTypeStr.slice(0, tempProcessor.sourceEndpointFullTypeStr.indexOf("Version="))) {
  479. this.tempConfig = tempConfig;
  480. tempConfig.Parts.forEach(function (p, index) {
  481. tempParts.set(p.FullTypeString.slice(0, p.FullTypeString.indexOf("Version=")), p);
  482. });
  483. }
  484. //var tempParts = tempConfigMap.has(processorMeta.description) ? tempConfigMap.get(processorMeta.description) : null;
  485. tempProcessor.metaPartsGroupDescriptors.forEach(function (mpgd, groupIndex) {
  486. if (currentGroup !== groupIndex) { return; }
  487. if (document.getElementById("config_description_subscribe")) {
  488. document.getElementById("config_description_subscribe").innerText = "";
  489. }
  490. var descriptionStr = "";
  491. currentMPDDivMap.clear();
  492. currentSchemaStrEditorsMap.clear();
  493. //build a metal part tab
  494. metalPartTabSchemaMap.clear();
  495. var tabsDiv = document.createElement("div");
  496. tabsDiv.id = "tabs_div_group" + groupIndex;
  497. tabsDiv.setAttribute("class", "tab");
  498. editorHolder.appendChild(tabsDiv);
  499. var tabEditorHolder = document.createElement("div");
  500. tabEditorHolder.id = "metaPart_editorHolder";
  501. editorHolder.appendChild(tabEditorHolder);
  502. var selectedtab = null;
  503. descriptionStr = "此metal group共支持" + mpgd.metaPartsDescriptors.length + "种方式,请选择下面一种进行配置";
  504. if (document.getElementById("config_description_subscribe")) {
  505. document.getElementById("config_description_subscribe").innerText = descriptionStr;
  506. }
  507. mpgd.metaPartsDescriptors.forEach(function (mpd, mpdIndex) {
  508. if (tabsDiv !== null) {
  509. var tabButton = document.createElement("button");
  510. tabButton.id = "group" + groupIndex + "_meta" + mpdIndex;
  511. tabButton.innerHTML = mpd.displayName;
  512. tabButton.setAttribute("class", "tablinks");
  513. tabButton.onclick = function (event) {
  514. metalPartTabSelect(event.currentTarget);
  515. };
  516. metalPartTabSchemaMap.set(tabButton.id, mpd);
  517. tabsDiv.appendChild(tabButton);
  518. if (schemaStrEdiorValueMap.has("group" + groupIndex + "_meta" + mpdIndex + "_schemaStrs0_strEditor0") ||
  519. schemaStrEdiorValueMap.has("group" + groupIndex + "_meta" + mpdIndex)) {
  520. selectedtab = tabButton;
  521. } else if (selectedtab === null && tempParts.has(mpd.fullTypeString.slice(0, mpd.fullTypeString.indexOf("Version="))))
  522. selectedtab = tabButton;
  523. }
  524. });
  525. if (selectedtab === null) selectedtab = document.getElementById("group" + groupIndex + "_meta0");
  526. metalPartTabSelect(selectedtab);
  527. //mpgd.metaPartsDescriptors.forEach(function (mpd, mpdIndex) {
  528. // //每个Group中可能又包含着多种meta part,比如底层通信中有串口通信/TCPIP,它们各自应该是互斥的
  529. // var groupMPDRadio = null;
  530. // var groupMPDRadioLabel = null;
  531. // var groupMPDdiv = null;
  532. // if (tabsDiv !== null) {
  533. // var tabButton = document.createElement("button");
  534. // tabButton.id = "group" + groupIndex + "_meta" + mpdIndex;
  535. // tabButton.innerHTML = mpd.displayName;
  536. // tabButton.setAttribute("class", "tablinks");
  537. // tabButton.onclick = function (event) {
  538. // metalPartTabSelect(event.currentTarget);
  539. // };
  540. // metalPartTabSchemaMap.set(tabButton.id, mpd);
  541. // tabsDiv.appendChild(tabButton);
  542. // }
  543. // if (mpgd.metaPartsDescriptors.length > 1) {
  544. // groupMPDRadio = document.createElement("input");
  545. // groupMPDRadio.type = "radio";
  546. // groupMPDRadio.name = "metaPartsDescriptor";
  547. // groupMPDRadio.id = "radio_group" + groupIndex + "_meta" + mpdIndex
  548. // groupMPDRadio.checked = mpdIndex === 0 ? true : false;
  549. // groupMPDRadio.style = "position:relative;float:left;margin-top:2px;";
  550. // groupMPDRadio.onclick = function (event) {
  551. // console.log("radio is clicked" + event.currentTarget.id);
  552. // radioClicked(event.currentTarget.id);
  553. // };
  554. // groupMPDRadioLabel = document.createElement("label");
  555. // groupMPDRadioLabel.style = "position:relative;float:left;margin-top:1px;";
  556. // groupMPDRadioLabel.innerHTML = mpd.description;
  557. // groupMPDRadioLabel.appendChild(groupMPDRadio);
  558. // groupMPDdiv = document.createElement("div");
  559. // groupMPDdiv.id = "div_group" + groupIndex + "_meta" + mpdIndex
  560. // groupMPDdiv.style = "position:relative;float:left;width:100%;border:double;";
  561. // currentMPDDivMap.set(groupMPDdiv.id, groupMPDdiv);
  562. // }
  563. // descriptionStr = descriptionStr === "" ? mpd.description : (descriptionStr + "\n" + mpd.description);
  564. // var tempSavedJsonString = tempParts !== null && tempParts.has(mpd.fullTypeString) ?
  565. // tempParts.get(mpd.fullTypeString).ParametersJsonArrayStr : null;
  566. // //var tempSavedJsonString = null;
  567. // mpd.parametersJsonSchemaStrings.forEach(function (schemaStrs, schemaIndex) {
  568. // //相当于一个接口有多种构造函数时会出现数组的情况,应该每种情况也是互斥的
  569. // schemaStrs.forEach(function (schemaStr, sIndex) {
  570. // var schemaDiv = document.createElement("div");
  571. // schemaDiv.id = "editor_schema_" + sIndex;
  572. // schemaDiv.style = "position:related;float:left;";
  573. // var schemaEditor = new JSONEditor(schemaDiv, {
  574. // theme: 'spectre',
  575. // iconlib: "spectre",
  576. // disable_edit_json: true,
  577. // disable_array_reorder: true,
  578. // array_controls_top: true,
  579. // disable_collapse: true,
  580. // disable_properties: true,
  581. // schema: JSON.parse(schemaStr)
  582. // });
  583. // //把processor index, group index, schemaStrs index and schema string index来构成editor map的key, 后面的schemaValue最好也是这样
  584. // var editorKey = "group" + groupIndex + "_meta" + mpdIndex + "_schemaStrs" + schemaIndex +
  585. // "_strEditor" + sIndex;
  586. // currentSchemaStrEditorsMap.set(editorKey, schemaEditor);
  587. // if (schemaStrEdiorValueMap.has(editorKey)) {
  588. // if (groupMPDRadio !== null) groupMPDRadio.checked = true;
  589. // schemaEditor.setValue(schemaStrEdiorValueMap.get(editorKey));
  590. // } else if (tempSavedJsonString != null) {
  591. // var tempTest = JSON.parse(tempSavedJsonString);
  592. // schemaEditor.setValue(tempTest[sIndex]);
  593. // }
  594. // //schemaEditors.push(schemaEditor);
  595. // if (groupMPDRadio !== null) {
  596. // groupMPDdiv.appendChild(schemaDiv);
  597. // //groupMPDRadio.appendChild(groupMPDdiv);
  598. // editorHolder.appendChild(groupMPDRadioLabel);
  599. // editorHolder.appendChild(groupMPDdiv);
  600. // } else {
  601. // editorHolder.appendChild(schemaDiv);
  602. // }
  603. // });
  604. // });// mpd.parametersJsonSchemaStrings.forEach
  605. //});
  606. //if (document.getElementById("config_description")) {
  607. // document.getElementById("config_description").innerText = descriptionStr;
  608. //}
  609. //add an active check box on the last group
  610. if (btnSave != null && btnSave.disabled === false) {
  611. var activate = document.createElement("input");
  612. activate.type = "checkbox";
  613. activate.id = "processor_activate";
  614. activate.style = "position:relative;float:left;margin:0.8%;";
  615. activate.checked = tempConfig !== null ? tempConfig.Activated:true;
  616. var lable = document.createElement("p");
  617. lable.innerText = "激活配置";
  618. var activateDiv = document.createElement("div");
  619. activateDiv.style = "position:relative;float:left;width:100%; margin:2px;";
  620. activateDiv.appendChild(activate);
  621. activateDiv.appendChild(lable);
  622. editorHolder.appendChild(activateDiv);
  623. var description = document.createElement("input");
  624. description.type = "text";
  625. description.id = "processor_description";
  626. description.style = "position:relative;float:left;margin:0.8%;";
  627. description.value = tempConfig !== null ? tempConfig.Description : "";
  628. var ds_lable = document.createElement("p");
  629. ds_lable.innerText = "描述";
  630. ds_lable.style = "position:relative;float:left;margin:0.8%;"
  631. var dsDiv = document.createElement("div");
  632. dsDiv.style = "position:relative;float:left;width:100%; margin:2px;";
  633. dsDiv.appendChild(ds_lable);
  634. dsDiv.appendChild(description);
  635. editorHolder.appendChild(dsDiv);
  636. }
  637. });
  638. //console.log("there are " + processorMetas.length + " processor metas, current index is:" + processorIndex);
  639. }
  640. function clearChildHtmlElements(htmlElement) {
  641. var nl = htmlElement.childNodes.length;
  642. for (var cn = 0; cn < nl; cn++) {
  643. var c = htmlElement.childNodes[0];
  644. htmlElement.removeChild(c);
  645. }
  646. }
  647. //添加用来放置根据schema生成的控件的div
  648. function buildEditorHolder() {
  649. //清掉editorBody中的所有子控件
  650. var editorbody = document.getElementById("config_body_editorHolder");
  651. if (editorbody === null) { console.log("config body div is null"); return; }
  652. //同一个processor不用全部清掉
  653. var editorHolder = document.getElementById("editor_holders");
  654. if (editorHolder !== null) { clearChildHtmlElements(editorHolder); return; }
  655. else { clearChildHtmlElements(editorbody); }
  656. //
  657. editorHolder = document.createElement("div");
  658. editorHolder.id = "editor_holders";
  659. editorHolder.style = "position:relative;float:left;width:100%;height:95%;overflow-y:auto;";
  660. var edtiorBtnsDiv = document.createElement("div");
  661. edtiorBtnsDiv.id = "editor_buttons";
  662. edtiorBtnsDiv.style = "position:relative;float:left;width:100%;height:5%;";
  663. var btnPre = document.createElement("input");
  664. btnPre.id = "previous_group";
  665. btnPre.type = "button";
  666. btnPre.value = "Previous";
  667. btnPre.style = "margin-left:3%;margin-right:3%;";
  668. btnPre.onclick = function () { preGroup(); };
  669. var btnNext = document.createElement("input");
  670. btnNext.id = "next_group";
  671. btnNext.type = "button";
  672. btnNext.value = "Next";
  673. btnNext.style = "margin-right:3%;";
  674. btnNext.onclick = function () { nextGroup(); };
  675. var btnSave = document.createElement("input");
  676. btnSave.id = "save";
  677. btnSave.type = "button";
  678. btnSave.value = "Save";
  679. btnSave.style = "margin-right:3%;";
  680. btnSave.onclick = function () { save(); };
  681. var btnCancel = document.createElement("input");
  682. btnCancel.id = "cancel";
  683. btnCancel.type = "button";
  684. btnCancel.value = "Cancel";
  685. btnCancel.style = "margin-right:3%;";
  686. btnCancel.onclick = function () { cancel(); };
  687. editorbody.appendChild(editorHolder);
  688. edtiorBtnsDiv.appendChild(btnPre);
  689. edtiorBtnsDiv.appendChild(btnSave);
  690. edtiorBtnsDiv.appendChild(btnCancel);
  691. edtiorBtnsDiv.appendChild(btnNext);
  692. editorbody.appendChild(edtiorBtnsDiv);
  693. }
  694. //Metal part tab select
  695. function metalPartTabSelect(htmlElement) {
  696. //update the tab's background clour
  697. var metalPartTabs = document.getElementsByClassName("tablinks");
  698. for (i = 0; i < metalPartTabs.length; i++) {
  699. metalPartTabs[i].className = metalPartTabs[i].className.replace(" active", "");
  700. }
  701. htmlElement.className += " active";
  702. //取出这个tab对应的metal part schema
  703. var metalPartSchema = metalPartTabSchemaMap.get(htmlElement.id);
  704. updateEditorHolderWithMetalPart(metalPartSchema, htmlElement);
  705. }
  706. //为单独的某个metal part构建页面
  707. //the JSONEditor result will appened to htmlElement
  708. function updateEditorHolderWithMetalPart(metalPart, metaTabElement) {
  709. clearChildHtmlElements(document.getElementById("metaPart_editorHolder"));
  710. var tempParts = new Map();
  711. if (tempConfig !== null) {
  712. tempConfig.Parts.forEach(function (p, index) {
  713. tempParts.set(p.FullTypeString.slice(0, p.FullTypeString.indexOf("Version=")), p);
  714. });
  715. }
  716. var descriptionStr = metalPart.description;
  717. var tempSavedJsonString = tempParts !== null && tempParts.has(metalPart.fullTypeString.slice(0, metalPart.fullTypeString.indexOf("Version="))) ?
  718. tempParts.get(metalPart.fullTypeString.slice(0, metalPart.fullTypeString.indexOf("Version="))).ParametersJsonArrayStr : null;
  719. currentSchemaStrEditorsMap.forEach(function (value, key) {
  720. if (schemaStrEdiorValueMap.has(key)) schemaStrEdiorValueMap.delete(key);
  721. });
  722. currentSchemaStrEditorsMap.clear();
  723. metalPart.parametersJsonSchemaStrings.forEach(function (schemaStrs, schemaIndex) {
  724. //相当于一个接口有多种构造函数时会出现数组的情况,应该每种情况也是互斥的
  725. schemaStrs.forEach(function (schemaStr, sIndex) {
  726. var schemaDiv = document.createElement("div");
  727. schemaDiv.id = "editor_schema_" + sIndex;
  728. schemaDiv.style = "position:related;float:left;";
  729. var schemaEditor = new JSONEditor(schemaDiv, {
  730. theme: 'spectre',
  731. iconlib: "spectre",
  732. ajax : true,
  733. disable_edit_json: true,
  734. disable_array_reorder: true,
  735. array_controls_top: true,
  736. disable_collapse: true,
  737. disable_properties: true,
  738. schema: JSON.parse(schemaStr)
  739. });
  740. //把processor index, group index, schemaStrs index and schema string index来构成editor map的key, 后面的schemaValue最好也是这样
  741. var editorKey = metaTabElement.id + "_schemaStrs" + schemaIndex +
  742. "_strEditor" + sIndex;
  743. currentSchemaStrEditorsMap.set(editorKey, schemaEditor);
  744. if (schemaStrEdiorValueMap.has(editorKey)) {
  745. //if (groupMPDRadio !== null) groupMPDRadio.checked = true;
  746. //schemaEditor.setValue(schemaStrEdiorValueMap.get(editorKey));
  747. schemaEditor.on('ready', () => {
  748. // Now the api methods will be available
  749. schemaEditor.setValue(schemaStrEdiorValueMap.get(editorKey));
  750. });
  751. } else if (tempSavedJsonString != null) {
  752. var tempTest = JSON.parse(tempSavedJsonString);
  753. schemaEditor.on('ready', () => {
  754. // Now the api methods will be available
  755. schemaEditor.setValue(tempTest[sIndex]);
  756. });
  757. //schemaEditor.setValue(tempTest[sIndex]);
  758. }
  759. document.getElementById("metaPart_editorHolder").appendChild(schemaDiv);
  760. });
  761. });
  762. //如果当前metal part没有可配置项时,currentSchemaStrEditorsMap里面没有内容,提示信息,无需配置
  763. if (currentSchemaStrEditorsMap.size === 0) {
  764. var tips = document.createElement("p");
  765. tips.innerHTML = metalPart.displayName + "不需要配置";
  766. tips.style = "position:relative;float:left;font-size: 0.8rem;color:gray;";
  767. document.getElementById("metaPart_editorHolder").appendChild(tips);
  768. //设置一个空的schemaEditor用以后续取值为“”空字符串
  769. currentSchemaStrEditorsMap.set(metaTabElement.id,"");
  770. }
  771. if (document.getElementById("config_description_details")) {
  772. document.getElementById("config_description_details").innerHTML = descriptionStr;
  773. }
  774. }
  775. function nextGroup() {
  776. var errorMessage = getCurrentGroupConfigValue();
  777. if (errorMessage !== "") {
  778. alert(errorMessage);
  779. } else {
  780. currentGroup = currentGroup + 1;
  781. updateEditorHolder(tempConfig);
  782. }
  783. }
  784. function preGroup() {
  785. getCurrentGroupConfigValue();
  786. currentGroup = currentGroup - 1;
  787. updateEditorHolder(tempConfig);
  788. }
  789. function getCurrentGroupConfigValue() {
  790. var errorMesage = "";
  791. currentSchemaStrEditorsMap.forEach(function (editor, key) {
  792. //当editor为空字符串时,意味着这个metal没有需要配置的参数
  793. if (editor === "") {
  794. if (schemaStrEdiorValueMap.has(key)) schemaStrEdiorValueMap.delete(key);
  795. schemaStrEdiorValueMap.set(key, "");
  796. return;
  797. }
  798. const errors = editor.validate();
  799. if (errors.length > 0) {
  800. console.error(errors[0]['message']);
  801. errorMesage = errors[0]['message'];
  802. }
  803. {
  804. var radioId = "radio_" + key.slice(0, key.indexOf("_schemaStrs"));
  805. if (document.getElementById(radioId) && !document.getElementById(radioId).checked) return;
  806. if (schemaStrEdiorValueMap.has(key)) schemaStrEdiorValueMap.delete(key);
  807. schemaStrEdiorValueMap.set(key, editor.getValue());
  808. }
  809. });
  810. return errorMesage;
  811. }
  812. function radioClicked(id) {
  813. var radio = document.getElementById(id);
  814. if (radio && radio.checked && currentMPDDivMap.size > 0) {
  815. var correspodingMPDDivId = "div" + id.slice(id.indexOf("_"));
  816. currentMPDDivMap.forEach(function (mpdDiv, key) {
  817. mpdDiv.style.dispaly = key === correspodingMPDDivId ? "" : "block";
  818. });
  819. }
  820. }
  821. function save() {
  822. if (tempProcessor === null) {
  823. console.log("processorIndex is out of range / processor is null");
  824. return;
  825. }
  826. //var currentProcessor = JSON.parse(processorMetas[processorIndex]);
  827. var groups = tempProcessor.metaPartsGroupDescriptors;
  828. if (groups === null) {
  829. console.log("there is no metaParts group in this processor");
  830. return;
  831. }
  832. getCurrentGroupConfigValue();
  833. // IEnumerable<ProcessorMetaPartsConfig> Parts
  834. var processorName = tempProcessor.sourceEndpointFullTypeStr.slice(0, tempProcessor.sourceEndpointFullTypeStr.indexOf("."))+"_0";
  835. if (tempConfig !== null) {
  836. processorName = tempConfig.Name;
  837. } else if (currentConfigurationFromDataBase !== null) {
  838. //processorName = tempProcessor.sourceEndpointFullTypeStr.slice(0, tempProcessor.sourceEndpointFullTypeStr.indexOf(".")) +
  839. // "_" + currentConfigurationFromDataBase.length;
  840. //for avoid too long name generated here, below some tweak
  841. processorName = tempProcessor.sourceEndpointFullTypeStr.replace(" ", "").substring(0, 40) +
  842. "_" + md5(tempProcessor.sourceEndpointFullTypeStr).substring(0, 16) +
  843. "_" + currentConfigurationFromDataBase.length;
  844. console.info("A ProcessorMetaConfig name is generated as: " + processorName)
  845. }
  846. var activated = false;
  847. var htmlElementActivate = document.getElementById("processor_activate");
  848. if (htmlElementActivate!== null) {
  849. activated = htmlElementActivate.checked;
  850. }
  851. var description_text = "";
  852. var htmlElementDescription = document.getElementById("processor_description");
  853. if (htmlElementDescription !== null) {
  854. description_text = htmlElementDescription.value;
  855. }
  856. var processorMetaConfig = {
  857. "Id": 0, "Name": processorName, "Description": description_text, "Type": tempProcessor.type,
  858. "Parts": [],
  859. "Activated": activated
  860. };
  861. //"processor" + processorIndex + "_group" + groupIndex + "_meta" + mpdIndex+"_schemaStrs" + schemaIndex +
  862. //"_strEditor" + sIndex;
  863. var tempParts = new Map();
  864. if (tempConfig != null) {
  865. if (tempConfig.SourceEndpointFullTypeStr.slice(0, tempConfig.SourceEndpointFullTypeStr.indexOf("Version=")) ===
  866. tempProcessor.sourceEndpointFullTypeStr.slice(0, tempProcessor.sourceEndpointFullTypeStr.indexOf("Version="))) {
  867. processorMetaConfig.Id = tempConfig.Id;
  868. tempConfig.Parts.forEach(function (p, index) {
  869. tempParts.set(p.FullTypeString.slice(0, p.FullTypeString.indexOf("Version=")), p);
  870. });
  871. }
  872. };
  873. groups.forEach(function (g, index) {
  874. var tempMetalGroupPart = { "Id": 0, "Type": g.groupType, "FullTypeString": "", "ParametersJsonArrayStr": "" };
  875. //当一个group有多种可选的metal part时,如果所选择的metal发生改变时,期望在做更新数据库时,仍然使用之前保存的配置的id
  876. var tempSavedConfigForThisGroup = null;
  877. g.metaPartsDescriptors.forEach(function (mpd, mpdIndex) {
  878. if (tempSavedConfigForThisGroup === null)
  879. tempSavedConfigForThisGroup = tempParts !== null && tempParts.has(mpd.fullTypeString.slice(0, mpd.fullTypeString.indexOf("Version="))) ? tempParts.get(mpd.fullTypeString.slice(0, mpd.fullTypeString.indexOf("Version="))) : null;
  880. if (schemaStrEdiorValueMap.has("group" + index + "_meta" + mpdIndex)) {
  881. tempMetalGroupPart.fullTypeString = mpd.fullTypeString;
  882. tempMetalGroupPart.ParametersJsonArrayStr = JSON.stringify(new Array());
  883. return;
  884. }
  885. mpd.parametersJsonSchemaStrings.forEach(function (schemaStrs, schemaIndex) {
  886. var tempSchemaValue = new Array();
  887. //相当于一个接口有多种构造函数时会出现数组的情况,应该每种情况也是互斥的
  888. schemaStrs.forEach(function (schemaStr, sIndex) {
  889. var tempKey = "group" + index + "_meta" + mpdIndex +
  890. "_schemaStrs" + schemaIndex + "_strEditor" + sIndex;
  891. if (schemaStrEdiorValueMap.has(tempKey)) {
  892. //如果这个schemaStr有对应的配置值,那么认为用户选择了这个metalPartsDescript
  893. if (tempMetalGroupPart.FullTypeString === "") { tempMetalGroupPart.FullTypeString = mpd.fullTypeString; }
  894. tempSchemaValue.push(schemaStrEdiorValueMap.get(tempKey));
  895. }
  896. });
  897. if (tempMetalGroupPart.ParametersJsonArrayStr === "" && tempSchemaValue.length > 0) {
  898. tempMetalGroupPart.ParametersJsonArrayStr = JSON.stringify(tempSchemaValue);
  899. }
  900. //if (tempParts !== null) {
  901. // tempMetalGroupPart.Id = tempParts.has(mpd.fullTypeString) ? tempParts.get(mpd.fullTypeString).Id : 0;
  902. //}
  903. });
  904. });
  905. if (tempSavedConfigForThisGroup !== null) tempMetalGroupPart.Id = tempSavedConfigForThisGroup.Id;
  906. processorMetaConfig.Parts.push(tempMetalGroupPart);
  907. });
  908. console.log(JSON.stringify(processorMetaConfig));
  909. var tempUrl = currentHP + "u/?apitype=service&an=UpsertProcessorMetaConfigAsync&pn=ProcessorsDispatcher&en=Edge.Core.Processor.Dispatcher.DefaultDispatcher";
  910. $.ajax({
  911. url: tempUrl,
  912. datatype: "application/json",
  913. type: 'post',
  914. contentType: "application/json;charset=utf-8;",
  915. data: JSON.stringify(processorMetaConfig),
  916. beforeSend: function () {
  917. },
  918. success: function (data) {
  919. alert("Config Saved Successfully!");
  920. clearCurrentDatas();
  921. processorSelect(null);
  922. console.log("successfully");
  923. },
  924. error: function (err) {
  925. alert("Failed to Save the config!");
  926. console.log(err);
  927. }
  928. });
  929. }
  930. function cancel() {
  931. clearCurrentDatas();
  932. processorSelect(null);
  933. }
  934. function add() {
  935. clearCurrentDatas();
  936. updateEditorHolder(null);
  937. }
  938. function clearCurrentDatas() {
  939. this.tempConfig = null;
  940. this.currentGroup = 0;
  941. this.currentMPDDivMap.clear();
  942. //用来存放某个具体的meta part descriptor配置editor
  943. //把processor index, group index, schemaStrs index and schema string index来构成editor map的key, 后面的schemaValue最好也是这样
  944. currentSchemaStrEditorsMap.clear();
  945. //存放每个editor value的map
  946. schemaStrEdiorValueMap.clear();
  947. }
  948. $(document).ready(function () {
  949. //查询的config名字需要跟保存时的一样
  950. var requestData = new Array();
  951. requestData.push("");
  952. var tempurl = currentHP+"u/?apitype=service&an=GetProcessorMetaConfigAsync&pn=ProcessorsDispatcher&en=Edge.Core.Processor.Dispatcher.DefaultDispatcher";
  953. console.log(tempurl);
  954. //requestData.push(tempProcessor.sourceEndpointFullTypeStr.slice(0, tempProcessor.sourceEndpointFullTypeStr.indexOf(".")));
  955. $.ajax({
  956. url: tempurl,
  957. datatype: "application/json",
  958. type: 'post',
  959. contentType: "application/json;charset=utf-8;",
  960. data: JSON.stringify(requestData),
  961. beforeSend: function () {
  962. },
  963. success: function (data) {
  964. var configMap = new Map();
  965. data.forEach(function (d, index) {
  966. if (!configMap.has(d.SourceEndpointFullTypeStr.slice(0, d.SourceEndpointFullTypeStr.indexOf("Version=")))) {
  967. configMap.set(d.SourceEndpointFullTypeStr.slice(0, d.SourceEndpointFullTypeStr.indexOf("Version=")), index);
  968. }
  969. });
  970. splitProcessorsViaTag(configMap);
  971. buildTags();
  972. updatePageBtnState();
  973. if (getQueyValue("tags") === "" || getQueyValue("pn") === "") {
  974. /*updateLeftSideBar("已配置");
  975. document.getElementById("li_已配置").style.background = "#0026ff"//"rgba(128, 128, 128, 0.35)";
  976. document.getElementById("li_已配置").style.color = "white";*/
  977. tagClick(document.getElementById("li_已配置"))
  978. } else {
  979. displayConfiguredProcessor(getQueyValue("pn"), getQueyValue("tags").split(",")[0]);
  980. }
  981. //var el = document.getElementById("li_all");
  982. //if (el === null) { return; }
  983. //tagClick(el);
  984. },
  985. error: function (err) {
  986. console.log(err);
  987. }
  988. });
  989. //var el = document.getElementById("processor_0");
  990. //if (el === null) { return; }
  991. //processorSelect(el);
  992. $("#processor_test_result_dialog").dialog({
  993. autoOpen: false,
  994. modal: true,
  995. //buttons: [
  996. // {
  997. // //text: "关闭",
  998. // icon: "ui-icon-heart",
  999. // click: function () {
  1000. // $(this).dialog("close");
  1001. // }
  1002. // // Uncommenting the following line would hide the text,
  1003. // // resulting in the label being used as a tooltip
  1004. // //showText: false
  1005. // }
  1006. //]
  1007. });
  1008. });
  1009. function getQueyValue(queryString) {
  1010. var queries = new String(decodeURIComponent(this.currenthref)).split("?");
  1011. var result = "";
  1012. if (queries && queries.length > 1) {
  1013. var temp = queries[1].split("&");
  1014. if (temp && Array.isArray(temp)) {
  1015. temp.forEach(function (q) {
  1016. var keyValuePairs = q.split("=");
  1017. if (keyValuePairs[0] === queryString) {
  1018. result = keyValuePairs[1];
  1019. return;
  1020. }
  1021. });
  1022. }
  1023. }
  1024. return result;
  1025. }
  1026. var processorsMapViaTag = new Map();
  1027. function splitProcessorsViaTag(configMap) {
  1028. var tempProcessors = JSON.parse(JSON.stringify(@Html.Raw(Json.Serialize(Model))));
  1029. var tags = getQueyValue("tags");
  1030. if (tags !== "") {
  1031. tags = tags.split(",");
  1032. }
  1033. var noTagProcessors = new Array();
  1034. var savedConfig = new Array();
  1035. tempProcessors.forEach(function (p) {
  1036. if (tags && Array.isArray(tags) && tags.length > 0) {
  1037. var found = false;
  1038. tags.forEach(function (tag) {
  1039. if (p.tags) {
  1040. p.tags.forEach(function (ptag) {
  1041. var tempTagObj = JSON.parse(ptag);
  1042. if (tempTagObj.TagKey === tag) { found = true; return; }
  1043. });
  1044. }
  1045. });
  1046. if (!found) return;
  1047. }
  1048. if (configMap != null && configMap.has(p.sourceEndpointFullTypeStr.slice(0, p.sourceEndpointFullTypeStr.indexOf("Version=")))) {
  1049. savedConfig.push(p);
  1050. }
  1051. if (p.tags != null) {
  1052. p.tags.forEach(function (t) {
  1053. var tagObj = JSON.parse(t);
  1054. if (processorsMapViaTag.has(tagObj.TagKey)) {
  1055. processorsMapViaTag.get(tagObj.TagKey).push(p);
  1056. } else {
  1057. var arr = new Array();
  1058. arr.push(p);
  1059. processorsMapViaTag.set(tagObj.TagKey, arr);
  1060. }
  1061. });
  1062. } else {
  1063. noTagProcessors.push(p);
  1064. }
  1065. });
  1066. processorsMapViaTag.set("已配置", savedConfig);
  1067. if (noTagProcessors.length > 0) processorsMapViaTag.set("其他", noTagProcessors);
  1068. }
  1069. function buildTags() {
  1070. var tagsUl = document.getElementById("tags");
  1071. var header = document.getElementById("config_header");
  1072. var count = 0;
  1073. clearTags(tagsUl);
  1074. var targetProcessorsMapViaTag = new Map();
  1075. if (processorsMapViaTag.size < 11) {
  1076. targetProcessorsMapViaTag = processorsMapViaTag;
  1077. } else {
  1078. processorsMapViaTag.forEach(function (value, key) {
  1079. count += 1;
  1080. if (count < (currentPage * 9 + 1) || count > (currentPage * 9 + 9)) return;
  1081. targetProcessorsMapViaTag.set(key, value);
  1082. })
  1083. targetProcessorsMapViaTag.set("已配置", processorsMapViaTag.get("已配置"));
  1084. }
  1085. targetProcessorsMapViaTag.forEach(function (value, key) {
  1086. var tagli = document.createElement("li");
  1087. tagli.id = "li_" + key;
  1088. tagli.setAttribute("name","tag");
  1089. //tagli.style = "float:left;";
  1090. //tagli.innerHTML = key === "无" ? key : key.slice(key.indexOf(":") + 1, key.indexOf("lang-en-us:"));
  1091. var taga = document.createElement("a");
  1092. taga.id = "a_" + key;
  1093. tagli.onclick = function (event) { tagClick(event.currentTarget); };
  1094. var displayedTagName = "";
  1095. if (Array.isArray(value) && value[0].tags && Array.isArray(value[0].tags)) {
  1096. value[0].tags.forEach(function (t) {
  1097. var temp = JSON.parse(t);
  1098. if (temp.TagKey === key) {
  1099. displayedTagName = temp.LocalizedTagName;
  1100. }
  1101. })
  1102. }
  1103. taga.innerHTML = displayedTagName === "" ? key : displayedTagName;/* === "其他" ? key : key.slice(key.indexOf(":") + 1, key.indexOf("lang-en-us:"));*/
  1104. tagli.appendChild(taga);
  1105. tagsUl.appendChild(tagli);
  1106. })
  1107. if (header !== null && header.offsetHeight < header.scrollHeight) {
  1108. header.style.height = "11%";
  1109. document.getElementById("page_body").style.height = "89%";
  1110. } else {
  1111. header.style.height = "6%"
  1112. document.getElementById("page_body").style.height = "94%";
  1113. }
  1114. }
  1115. function clearTags(htmlElement) {
  1116. var nl = htmlElement.childNodes.length;
  1117. for (var cn = 4; cn < nl; cn++) {
  1118. var c = htmlElement.childNodes[4];
  1119. htmlElement.removeChild(c);
  1120. }
  1121. }
  1122. function previous() {
  1123. currentPage = currentPage - 1;
  1124. updatePageBtnState();
  1125. buildTags();
  1126. tagClick(document.getElementById("li_已配置"))
  1127. }
  1128. function next() {
  1129. currentPage = currentPage + 1;
  1130. updatePageBtnState();
  1131. buildTags();
  1132. tagClick(document.getElementById("li_已配置"))
  1133. }
  1134. function updatePageBtnState() {
  1135. var totalPage = Math.ceil((processorsMapViaTag.size - 1) / 9);
  1136. var el_pre = document.getElementById("btn_pre");
  1137. var el_nxt = document.getElementById("btn_next");
  1138. if (currentPage === 0) {
  1139. el_pre.disabled = 'disabled';
  1140. } else {
  1141. el_pre.disabled = false;
  1142. }
  1143. if (currentPage < totalPage - 1) {
  1144. el_nxt.disabled = false;
  1145. } else {
  1146. el_nxt.disabled = 'disabled';
  1147. }
  1148. }
  1149. function tagClick(htmlElement) {
  1150. var tagId = htmlElement.id;
  1151. var tagKey = tagId.slice(tagId.indexOf("_") + 1);
  1152. clearCurrentDatas();
  1153. updateLiBackground(htmlElement);
  1154. updateLeftSideBar(tagKey);
  1155. // "processor_" + pindex + "_" + processor.type ;
  1156. var el = document.getElementById("processor_0_1");
  1157. if (el === null) el = document.getElementById("processor_0_0");
  1158. if (el === null) {
  1159. if (document.getElementById("config_description_subscribe")) {
  1160. document.getElementById("config_description_subscribe").innerHTML = "";
  1161. }
  1162. if (document.getElementById("config_description_details"))
  1163. document.getElementById("config_description_details").innerHTML = "當前選項沒有配置項";
  1164. var editorHolder = document.getElementById("config_body_editorHolder");
  1165. if (editorHolder != null)clearChildHtmlElements(editorHolder);
  1166. return;
  1167. }
  1168. processorSelect(el);
  1169. }
  1170. function displayConfiguredProcessor(processorName, tag) {
  1171. tempProcessors = processorsMapViaTag.get(tag);
  1172. var targetHtmlElement = null;
  1173. if (tempProcessors === null || tempProcessors === undefined || processorName === "" || tag === "") { return; }
  1174. updateLeftSideBar(tag);
  1175. document.getElementById("li_"+tag).style.background = "#0026ff"//"rgba(128, 128, 128, 0.35)";
  1176. document.getElementById("li_"+tag).style.color = "white";
  1177. tempProcessors.forEach(function (p, index) {
  1178. //如果sourceEndpointFullTypeStr中包含processor name则认为找到了需要显示的processor
  1179. if (p.sourceEndpointFullTypeStr.toUpperCase().indexOf(processorName.toUpperCase()) > -1) {
  1180. var targetId = "processor_" + index + "_" + p.type;
  1181. targetHtmlElement = document.getElementById(targetId);
  1182. return;
  1183. }
  1184. });
  1185. if (targetHtmlElement !== null) {
  1186. processorSelect(targetHtmlElement);
  1187. }
  1188. }
  1189. function updateLeftSideBar(tagKey) {
  1190. tempProcessors = processorsMapViaTag.get(tagKey);
  1191. if (tempProcessors === null || tempProcessors == undefined) { return; }
  1192. clearChildHtmlElements(document.getElementById("config_nav_ul_app_processor"));
  1193. clearChildHtmlElements(document.getElementById("config_nav_ul_device_processor"));
  1194. tempProcessors.forEach(function (processor, pindex) {
  1195. //processor.Type == 0 is DeviceProcessor, processor.Type==1 is AppProcessor
  1196. var navConfigUl = document.getElementById("config_nav_ul_app_processor");
  1197. if (processor.type === 0)
  1198. navConfigUl = document.getElementById("config_nav_ul_device_processor");
  1199. var lip = document.createElement("li");
  1200. lip.id = "processor_" + pindex + "_" + processor.type ;
  1201. lip.setAttribute("name","processor");
  1202. lip.style = "width:100%;white-space:nowrap;overflow-x:auto;";
  1203. lip.onclick = function (event) {
  1204. clearCurrentDatas();
  1205. processorSelect(event.currentTarget);
  1206. };
  1207. var ap = document.createElement("a");
  1208. ap.id = "aprocessor_" + pindex + "_" + processor.type;
  1209. ap.innerHTML = processor.displayName!==null?processor.displayName:processor.sourceEndpointFullTypeStr.split(",")[1];
  1210. lip.appendChild(ap);
  1211. //lip.innerHTML = processor.sourceEndpointFullTypeStr.split(",")[1];
  1212. navConfigUl.appendChild(lip);
  1213. });
  1214. }
  1215. function ReloadProcessors(id) {
  1216. var restartBtn = document.getElementById(id);
  1217. if (restartBtn === null) return;
  1218. restartBtn.disabled = "disabled";
  1219. var requestData = new Array();
  1220. requestData.push("Manual Restart from ConfigUI");
  1221. var tempurl = currentHP + "u/?apitype=service&an=ReloadProcessorsAsync&pn=ProcessorsDispatcher&en=Edge.Core.Processor.Dispatcher.DefaultDispatcher";
  1222. //requestData.push(tempProcessor.sourceEndpointFullTypeStr.slice(0, tempProcessor.sourceEndpointFullTypeStr.indexOf(".")));
  1223. $.ajax({
  1224. url: tempurl,
  1225. datatype: "application/json",
  1226. type: 'post',
  1227. contentType: "application/json;charset=utf-8;",
  1228. data: JSON.stringify(requestData),
  1229. beforeSend: function () {
  1230. },
  1231. success: function (data) {
  1232. console.log("Restart successfully, response data:" + data);
  1233. restartBtn.disabled = false;
  1234. alert("Restart Successfully");
  1235. },
  1236. error: function (err) {
  1237. console.log(err);
  1238. estartBtn.disabled = false;
  1239. alert("Restart failed due to:"+err);
  1240. }
  1241. });
  1242. }
  1243. function md5(inputString) {
  1244. var hc = "0123456789abcdef";
  1245. function rh(n) { var j, s = ""; for (j = 0; j <= 3; j++) s += hc.charAt((n >> (j * 8 + 4)) & 0x0F) + hc.charAt((n >> (j * 8)) & 0x0F); return s; }
  1246. function ad(x, y) { var l = (x & 0xFFFF) + (y & 0xFFFF); var m = (x >> 16) + (y >> 16) + (l >> 16); return (m << 16) | (l & 0xFFFF); }
  1247. function rl(n, c) { return (n << c) | (n >>> (32 - c)); }
  1248. function cm(q, a, b, x, s, t) { return ad(rl(ad(ad(a, q), ad(x, t)), s), b); }
  1249. function ff(a, b, c, d, x, s, t) { return cm((b & c) | ((~b) & d), a, b, x, s, t); }
  1250. function gg(a, b, c, d, x, s, t) { return cm((b & d) | (c & (~d)), a, b, x, s, t); }
  1251. function hh(a, b, c, d, x, s, t) { return cm(b ^ c ^ d, a, b, x, s, t); }
  1252. function ii(a, b, c, d, x, s, t) { return cm(c ^ (b | (~d)), a, b, x, s, t); }
  1253. function sb(x) {
  1254. var i; var nblk = ((x.length + 8) >> 6) + 1; var blks = new Array(nblk * 16); for (i = 0; i < nblk * 16; i++) blks[i] = 0;
  1255. for (i = 0; i < x.length; i++) blks[i >> 2] |= x.charCodeAt(i) << ((i % 4) * 8);
  1256. blks[i >> 2] |= 0x80 << ((i % 4) * 8); blks[nblk * 16 - 2] = x.length * 8; return blks;
  1257. }
  1258. var i, x = sb(inputString), a = 1732584193, b = -271733879, c = -1732584194, d = 271733878, olda, oldb, oldc, oldd;
  1259. for (i = 0; i < x.length; i += 16) {
  1260. olda = a; oldb = b; oldc = c; oldd = d;
  1261. a = ff(a, b, c, d, x[i + 0], 7, -680876936); d = ff(d, a, b, c, x[i + 1], 12, -389564586); c = ff(c, d, a, b, x[i + 2], 17, 606105819);
  1262. b = ff(b, c, d, a, x[i + 3], 22, -1044525330); a = ff(a, b, c, d, x[i + 4], 7, -176418897); d = ff(d, a, b, c, x[i + 5], 12, 1200080426);
  1263. c = ff(c, d, a, b, x[i + 6], 17, -1473231341); b = ff(b, c, d, a, x[i + 7], 22, -45705983); a = ff(a, b, c, d, x[i + 8], 7, 1770035416);
  1264. d = ff(d, a, b, c, x[i + 9], 12, -1958414417); c = ff(c, d, a, b, x[i + 10], 17, -42063); b = ff(b, c, d, a, x[i + 11], 22, -1990404162);
  1265. a = ff(a, b, c, d, x[i + 12], 7, 1804603682); d = ff(d, a, b, c, x[i + 13], 12, -40341101); c = ff(c, d, a, b, x[i + 14], 17, -1502002290);
  1266. b = ff(b, c, d, a, x[i + 15], 22, 1236535329); a = gg(a, b, c, d, x[i + 1], 5, -165796510); d = gg(d, a, b, c, x[i + 6], 9, -1069501632);
  1267. c = gg(c, d, a, b, x[i + 11], 14, 643717713); b = gg(b, c, d, a, x[i + 0], 20, -373897302); a = gg(a, b, c, d, x[i + 5], 5, -701558691);
  1268. d = gg(d, a, b, c, x[i + 10], 9, 38016083); c = gg(c, d, a, b, x[i + 15], 14, -660478335); b = gg(b, c, d, a, x[i + 4], 20, -405537848);
  1269. a = gg(a, b, c, d, x[i + 9], 5, 568446438); d = gg(d, a, b, c, x[i + 14], 9, -1019803690); c = gg(c, d, a, b, x[i + 3], 14, -187363961);
  1270. b = gg(b, c, d, a, x[i + 8], 20, 1163531501); a = gg(a, b, c, d, x[i + 13], 5, -1444681467); d = gg(d, a, b, c, x[i + 2], 9, -51403784);
  1271. c = gg(c, d, a, b, x[i + 7], 14, 1735328473); b = gg(b, c, d, a, x[i + 12], 20, -1926607734); a = hh(a, b, c, d, x[i + 5], 4, -378558);
  1272. d = hh(d, a, b, c, x[i + 8], 11, -2022574463); c = hh(c, d, a, b, x[i + 11], 16, 1839030562); b = hh(b, c, d, a, x[i + 14], 23, -35309556);
  1273. a = hh(a, b, c, d, x[i + 1], 4, -1530992060); d = hh(d, a, b, c, x[i + 4], 11, 1272893353); c = hh(c, d, a, b, x[i + 7], 16, -155497632);
  1274. b = hh(b, c, d, a, x[i + 10], 23, -1094730640); a = hh(a, b, c, d, x[i + 13], 4, 681279174); d = hh(d, a, b, c, x[i + 0], 11, -358537222);
  1275. c = hh(c, d, a, b, x[i + 3], 16, -722521979); b = hh(b, c, d, a, x[i + 6], 23, 76029189); a = hh(a, b, c, d, x[i + 9], 4, -640364487);
  1276. d = hh(d, a, b, c, x[i + 12], 11, -421815835); c = hh(c, d, a, b, x[i + 15], 16, 530742520); b = hh(b, c, d, a, x[i + 2], 23, -995338651);
  1277. a = ii(a, b, c, d, x[i + 0], 6, -198630844); d = ii(d, a, b, c, x[i + 7], 10, 1126891415); c = ii(c, d, a, b, x[i + 14], 15, -1416354905);
  1278. b = ii(b, c, d, a, x[i + 5], 21, -57434055); a = ii(a, b, c, d, x[i + 12], 6, 1700485571); d = ii(d, a, b, c, x[i + 3], 10, -1894986606);
  1279. c = ii(c, d, a, b, x[i + 10], 15, -1051523); b = ii(b, c, d, a, x[i + 1], 21, -2054922799); a = ii(a, b, c, d, x[i + 8], 6, 1873313359);
  1280. d = ii(d, a, b, c, x[i + 15], 10, -30611744); c = ii(c, d, a, b, x[i + 6], 15, -1560198380); b = ii(b, c, d, a, x[i + 13], 21, 1309151649);
  1281. a = ii(a, b, c, d, x[i + 4], 6, -145523070); d = ii(d, a, b, c, x[i + 11], 10, -1120210379); c = ii(c, d, a, b, x[i + 2], 15, 718787259);
  1282. b = ii(b, c, d, a, x[i + 9], 21, -343485551); a = ad(a, olda); b = ad(b, oldb); c = ad(c, oldc); d = ad(d, oldd);
  1283. }
  1284. return rh(a) + rh(b) + rh(c) + rh(d);
  1285. }
  1286. function dialogBox(title, message, yesCallback, noCallback) {
  1287. if (message) {
  1288. $('.dialog-title').html(title);
  1289. $('.dialog-message').html(message);
  1290. }
  1291. // 显示遮罩和对话框
  1292. $('.wrap-dialog').removeClass("hide");
  1293. $('.alarmInfoWrap').removeClass("hide");
  1294. // 确定按钮
  1295. $('#confirm').click(function () {
  1296. $('.wrap-dialog').addClass("hide");
  1297. $('.alarmInfoWrap').addClass("hide");
  1298. noCallback = null;
  1299. if (yesCallback !== null && yesCallback !== undefined) {
  1300. yesCallback();
  1301. yesCallback = null;
  1302. }
  1303. });
  1304. // 取消按钮
  1305. $('#cancel').click(function () {
  1306. yesCallback = null;
  1307. $('.wrap-dialog').addClass("hide");
  1308. $('.alarmInfoWrap').addClass("hide");
  1309. if (noCallback !== null && noCallback !== undefined) {
  1310. noCallback();
  1311. noCallback = null;
  1312. }
  1313. });
  1314. }
  1315. </script>