Main.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. o2.require("o2.widget.O2Identity", null, false);
  2. o2.require("o2.widget.ace", null, false);
  3. MWF.xApplication.ANN.Main = new Class({
  4. Extends: MWF.xApplication.Common.Main,
  5. Implements: [Options, Events],
  6. options: {
  7. "style1": "default",
  8. "style": "default",
  9. "name": "ANN",
  10. "icon": "icon.png",
  11. "width": "1100",
  12. "height": "600",
  13. "isResize": true,
  14. "isMax": true,
  15. "title": MWF.xApplication.ANN.LP.title
  16. },
  17. initialize: function(desktop, options){
  18. this.setOptions(options);
  19. this.desktop = desktop;
  20. this.path = "../x_component_"+this.options.name.replace(/\./g, "_")+"/$Main/";
  21. this.options.icon = this.path+this.options.style+"/"+this.options.icon;
  22. //this.cssPath =this.path+this.options.style+"/css.wcss";
  23. this.stylePath = this.path+this.options.style+"/style.css";
  24. this.viewPath = this.path+this.options.style+"/view.html";
  25. },
  26. onQueryLoad: function(){
  27. this.lp = MWF.xApplication.ANN.LP;
  28. this.models = [];
  29. },
  30. loadApplication: function(callback){
  31. this.content.loadAll({css: this.stylePath, "html": this.viewPath}, {"bind": this}, function(){
  32. this.node = this.content.getElement(".o2_ann_content");
  33. this.titleNode = this.content.getElement(".o2_ann_top");
  34. this.contentArea = this.content.getElement(".o2_ann_contentArea");
  35. this.listNode = this.content.getElement(".o2_ann_leftContent");
  36. this.contentNode = this.content.getElement(".o2_ann_rightContent");
  37. this.addAction = this.content.getElement(".o2_ann_topIcon");
  38. if (!o2.AC.isAdministrator()){
  39. this.addAction.destroy();
  40. this.addAction = null;
  41. }
  42. if (this.addAction) this.addAction.addEvent("click", this.createModel.bind(this));
  43. this.resizeFun = this.resize.bind(this);
  44. this.resizeFun();
  45. this.addEvent("resize", this.resizeFun);
  46. this.loadListModel();
  47. if (callback) callback();
  48. }.bind(this));
  49. },
  50. getDefaultData: function(){
  51. return {
  52. "neuralNetworkType": "mlp",
  53. "dataType": "processPlatform",
  54. "name": this.lp.unnamed,
  55. "description": "",
  56. "alias": "",
  57. "inValueScriptText": "",
  58. "outValueScriptText": "",
  59. "attachmentScriptText": "",
  60. "processList": [],
  61. "applicationList": [],
  62. "analyzeType": "default",
  63. "maxResult": 0,
  64. "propertyMap": {}
  65. }
  66. },
  67. checkSave: function(){
  68. if (this.currentModel && this.currentModel.context && (this.currentModel.context.status==="edit" || this.currentModel.context.status==="new")){
  69. this.notice(this.lp.checkSave, "error", this.contentNode, {"x": "left", "y": "top"});
  70. return false;
  71. }else{
  72. if (this.currentModel) this.currentModel.unselected();
  73. return true;
  74. }
  75. },
  76. createModel: function(){
  77. if (this.checkSave()) this.currentModel = new MWF.xApplication.ANN.Model(this.getDefaultData(), this);
  78. },
  79. resize: function(){
  80. var size = this.node.getSize();
  81. var titleSize = this.titleNode.getComputedSize();
  82. var h = size.y-titleSize.totalHeight;
  83. this.contentArea.setStyle("height", ""+h+"px");
  84. },
  85. loadListModel: function(){
  86. o2.Actions.get("x_query_assemble_designer").listModel(function(json){
  87. json.data.each(function(item){
  88. this.models.push(new MWF.xApplication.ANN.Model(item, this));
  89. }.bind(this));
  90. }.bind(this));
  91. }
  92. });
  93. MWF.xApplication.ANN.Model = new Class({
  94. initialize: function(data, app){
  95. this.data = data;
  96. this.app = app;
  97. this.lp = app.lp;
  98. this.listNode = this.app.listNode;
  99. this.container = new Element("div").inject(this.listNode);
  100. this.load();
  101. },
  102. reload: function(){
  103. o2.Actions.get("x_query_assemble_designer").getModel(this.data.id, function(json){
  104. this.data = json.data;
  105. if (this.context) this.context.data = this.data;
  106. this.node.getElement(".o2_ann_model_nodeContentName").set("text", this.data.name);
  107. this.node.getElement(".o2_ann_model_nodeContentDate").set("text", this.data.updateTime);
  108. var rightIcon = this.node.getElement(".o2_ann_model_nodeRight");
  109. rightIcon.set("title", this.lp.status[this.data.status||'idle']);
  110. rightIcon.setStyle("background-image", "url(../x_component_ANN/$Main/default/icon/"+(this.data.status || 'idle')+".png")
  111. }.bind(this));
  112. },
  113. load: function(){
  114. if (this.data.id){
  115. this.loadList(function(){
  116. this.loadEvent();
  117. }.bind(this));
  118. }else{
  119. this.loadCreate();
  120. }
  121. },
  122. loadList: function(callback){
  123. var viewPath = this.app.path+this.app.options.style+"/model.html";
  124. this.container.loadHtml(viewPath, {"bind": {"lp": this.lp, "data": this.data}}, function(){
  125. this.node = this.container.getFirst();
  126. // var rightIcon = this.node.getElement(".o2_ann_model_nodeRight");
  127. // rightIcon.set("title", this.lp.status[this.data.status||'idle']);
  128. // rightIcon.setStyle("background-image", "url(../x_component_ANN/$Main/default/icon/"+(this.data.status || 'idle')+".png")
  129. if (callback) callback();
  130. }.bind(this));
  131. },
  132. loadCreate: function(){
  133. this.loadList(function(){
  134. this.loadEvent();
  135. this.selected();
  136. }.bind(this));
  137. },
  138. loadEvent: function(){
  139. this.node.addEvents({
  140. "mouseover": function(){if (!this.isSelected) this.node.addClass("o2_ann_model_node_over")}.bind(this),
  141. "mouseout": function(){if (!this.isSelected) this.node.removeClass("o2_ann_model_node_over")}.bind(this),
  142. "click": function(){
  143. if (!this.isSelected){
  144. this.selected();
  145. }else{
  146. if (this.context) this.context.reload();
  147. }
  148. }.bind(this)
  149. });
  150. },
  151. getData: function(callback){
  152. o2.Actions.get("x_query_assemble_designer").getModel(this.data.id, function(json){
  153. this.data = json.data;
  154. if (callback) callback();
  155. }.bind(this));
  156. },
  157. selected: function(){
  158. if (this.app.checkSave()){
  159. this.node.addClass("o2_ann_model_node_selected");
  160. this.isSelected = true;
  161. this.app.currentModel = this;
  162. this.openModel();
  163. }
  164. },
  165. unselected: function(){
  166. this.isSelected = false;
  167. this.app.currentModel = null;
  168. this.node.removeClass("o2_ann_model_node_selected");
  169. this.node.removeClass("o2_ann_model_node_over");
  170. if (this.context) this.context.destroy();
  171. },
  172. openModel: function(){
  173. this.context = new MWF.xApplication.ANN.Model.Context(this);
  174. },
  175. destroy: function(){
  176. this.node.destroy();
  177. o2.release(this);
  178. }
  179. });
  180. MWF.xApplication.ANN.Model.Context = new Class({
  181. initialize: function(model){
  182. this.model = model;
  183. this.data = model.data;
  184. this.app = model.app;
  185. this.lp = model.lp;
  186. this.contentNode = this.app.contentNode;
  187. this.getData(this.load.bind(this));
  188. },
  189. getData: function(callback){
  190. if (this.data.id){
  191. o2.Actions.get("x_query_assemble_designer").getModel(this.data.id, function(json){
  192. this.data = json.data;
  193. if (callback) callback();
  194. }.bind(this));
  195. }else{
  196. if (callback) callback();
  197. }
  198. },
  199. reload: function(){
  200. this.contentNode.empty();
  201. this.getData(this.load.bind(this));
  202. },
  203. load: function(){
  204. this.status = "open";
  205. if (!this.data.id) this.status = "new";
  206. var viewPath = this.app.path+this.app.options.style+"/content.html";
  207. this.contentNode.loadHtml(viewPath, {"bind": {"lp": this.lp, "data": this.data}}, function(){
  208. this.node = this.contentNode.getFirst();
  209. this.toolbarNode = this.node.getFirst();
  210. this.content = this.node.getLast();
  211. this.lines = this.content.getElements(".o2_ann_modelContext_line");
  212. o2.widget.ace.load(function(){
  213. o2.load("../o2_lib/ace/src-min-noconflict/ext-static_highlight.js", function(){
  214. this.loadContent();
  215. this.loadToolbar();
  216. this.resizeFun = this.resize.bind(this);
  217. this.resizeFun();
  218. this.app.addEvent("resize", this.resizeFun);
  219. if (this.status==="new") this.edit();
  220. }.bind(this));
  221. }.bind(this));
  222. }.bind(this));
  223. },
  224. loadContent: function(){
  225. this.loadProcessList();
  226. this.loadApplicationList();
  227. this.loadCode(6, JSON.stringify(this.data.propertyMap,null,2));
  228. this.loadCode(7);
  229. this.loadCode(8);
  230. this.loadCode(9);
  231. this.loadStatus();
  232. },
  233. loadStatus: function(){
  234. this.statusNode = this.node.getElement(".o2_ann_modelContext_status");
  235. },
  236. loadProcessList: function(){
  237. if (this.data.processList){
  238. var node = this.lines[3].getLast().getFirst();
  239. this.data.processList.each(function(process){
  240. new o2.widget.O2Process({id: process}, node)
  241. }.bind(this));
  242. }
  243. },
  244. loadCode: function(i, text){
  245. var node = this.lines[i].getLast();
  246. if (text) node.set("text", text);
  247. var highlight = ace.require("ace/ext/static_highlight");
  248. highlight(node, {mode: "ace/mode/javascript", theme: "ace/theme/tomorrow", "fontSize": 16});
  249. },
  250. loadApplicationList: function(){
  251. if (this.data.applicationList){
  252. var node = this.lines[4].getLast();
  253. this.data.applicationList.each(function(application){
  254. new o2.widget.O2Application({id: application}, node)
  255. }.bind(this));
  256. }
  257. },
  258. destroy: function(){
  259. if (this.resizeFun) this.app.removeEvent("resize", this.resizeFun);
  260. this.contentNode.empty();
  261. o2.release(this);
  262. },
  263. "close": function(el,e){
  264. if (this.status!=="open"){
  265. var _self = this;
  266. this.app.confirm("infor", e, this.lp.closeTitle, this.lp.closeInfor, 380, 100, function(){
  267. if (_self.data.id){
  268. _self.model.unselected();
  269. }else{
  270. var model = _self.model;
  271. _self.model.unselected();
  272. model.destroy();
  273. }
  274. this.close();
  275. }, function(){this.close();});
  276. }else{
  277. this.model.unselected();
  278. }
  279. },
  280. loadToolbar: function(){
  281. MWF.require("MWF.widget.Toolbar", function() {
  282. this.toolbar = new MWF.widget.Toolbar(this.toolbarNode, {"style": "simple"}, this);
  283. this.toolbar.load();
  284. this.setToolbarDisabled();
  285. }.bind(this));
  286. },
  287. setToolbarDisabled: function(){
  288. if (this.toolbar){
  289. if (this.status==="edit"){
  290. this.toolbar.childrenButton[0].node.hide();
  291. this.toolbar.childrenButton[1].node.show();
  292. this.toolbar.childrenButton[6].node.show();
  293. if (this.data.status) {
  294. this.toolbar.childrenButton[2].node.hide();
  295. this.toolbar.childrenButton[3].node.hide();
  296. }else{
  297. this.toolbar.childrenButton[2].node.show();
  298. this.toolbar.childrenButton[3].node.show();
  299. this.toolbar.childrenButton[8].node.show();
  300. }
  301. if (this.data.status && this.data.status==="generating"){
  302. this.toolbar.childrenButton[4].node.show();
  303. this.toolbar.childrenButton[8].node.hide();
  304. }else{
  305. this.toolbar.childrenButton[4].node.hide();
  306. }
  307. if (this.data.status && this.data.status==="learning"){
  308. this.toolbar.childrenButton[5].node.show();
  309. this.toolbar.childrenButton[8].node.hide();
  310. }else{
  311. this.toolbar.childrenButton[5].node.hide();
  312. }
  313. }else if (this.status==="new"){
  314. this.toolbar.childrenButton[0].node.hide();
  315. this.toolbar.childrenButton[1].node.show();
  316. this.toolbar.childrenButton[6].node.hide();
  317. this.toolbar.childrenButton[2].node.hide();
  318. this.toolbar.childrenButton[3].node.hide();
  319. this.toolbar.childrenButton[4].node.hide();
  320. this.toolbar.childrenButton[5].node.hide();
  321. }else{
  322. this.toolbar.childrenButton[0].node.show();
  323. this.toolbar.childrenButton[1].node.hide();
  324. this.toolbar.childrenButton[6].node.show();
  325. if (this.data.status) {
  326. this.toolbar.childrenButton[2].node.hide();
  327. this.toolbar.childrenButton[3].node.hide();
  328. }else{
  329. this.toolbar.childrenButton[2].node.show();
  330. this.toolbar.childrenButton[3].node.show();
  331. this.toolbar.childrenButton[8].node.show();
  332. }
  333. if (this.data.status && this.data.status==="generating"){
  334. this.toolbar.childrenButton[4].node.show();
  335. this.toolbar.childrenButton[8].node.hide();
  336. }else{
  337. this.toolbar.childrenButton[4].node.hide();
  338. }
  339. if (this.data.status && this.data.status==="learning"){
  340. this.toolbar.childrenButton[5].node.show();
  341. this.toolbar.childrenButton[8].node.hide();
  342. }else{
  343. this.toolbar.childrenButton[5].node.hide();
  344. }
  345. }
  346. }
  347. },
  348. resize: function(){
  349. var size = this.contentNode.getSize();
  350. var toolbarSize = this.toolbarNode.getComputedSize();
  351. var h = size.y - toolbarSize.totalHeight;
  352. this.content.setStyle("height", ""+h+"px");
  353. },
  354. edit: function(){
  355. this.status = (!this.data.id) ? "new" : "edit";
  356. this.setToolbarDisabled();
  357. this.nameInput = this.editInput(0, "name");
  358. this.descriptionInput = this.editInput(1, "description");
  359. this.aliasInput = this.editInput(2, "alias");
  360. this.editProcessList(3);
  361. this.editApplicationList(4);
  362. this.analyzeInput = this.editSelect(5, ["default", "full"]);
  363. o2.require("o2.widget.ScriptArea", function(){
  364. this.propertyMapInput = this.editCode(6, "propertyMap");
  365. this.inValueScriptInput = this.editCode(7, "inValueScriptText");
  366. this.outValueScriptInput = this.editCode(8, "outValueScriptText");
  367. this.attachmentScriptInput = this.editCode(9), "attachmentScriptText";
  368. }.bind(this));
  369. },
  370. editInput: function(i, text){
  371. var node = this.lines[i].getLast();
  372. var value = node.get("text");
  373. node.empty();
  374. var input = new Element("input.o2_ann_modelContext_input", {
  375. "type": "text",
  376. "value": value,
  377. "placeholder": this.lp.placeholder[text]
  378. }).inject(node);
  379. return input;
  380. },
  381. editProcessList: function(i){
  382. var node = this.lines[i].getLast();
  383. var action = new Element("button.o2_ann_modelContext_button", {"text": this.lp.selectProcess}).inject(node);
  384. action.addEvent("click", function(e){
  385. MWF.xDesktop.requireApp("Selector", "package", function(){
  386. new MWF.O2Selector(this.app.content, {
  387. "type": "process", "values": this.data.processList,
  388. "onComplete": function(items){
  389. e.target.getPrevious().empty();
  390. this.data.processList = [];
  391. items.each(function(item){
  392. this.data.processList.push(item.data.id);
  393. }.bind(this));
  394. this.loadProcessList();
  395. }.bind(this)
  396. });
  397. }.bind(this));
  398. }.bind(this));
  399. },
  400. editApplicationList: function(i){
  401. var node = this.lines[i].getLast();
  402. var action = new Element("button.o2_ann_modelContext_button", {"text": this.lp.selectApplication}).inject(node);
  403. action.addEvent("click", function(e){
  404. MWF.xDesktop.requireApp("Selector", "package", function(){
  405. new MWF.O2Selector(this.app.content, {
  406. "type": "application", "values": this.data.applicationList,
  407. "onComplete": function(items){
  408. e.target.getPrevious().empty();
  409. this.data.applicationList = [];
  410. items.each(function(item){
  411. this.data.applicationList.push(item.data.id);
  412. }.bind(this));
  413. this.loadApplicationList();
  414. }.bind(this)
  415. });
  416. }.bind(this));
  417. }.bind(this));
  418. },
  419. editSelect: function(i, arr){
  420. var node = this.lines[i].getLast();
  421. var value = node.get("text");
  422. node.empty();
  423. var select = new Element("select").inject(node);
  424. arr.each(function(v){
  425. new Element("option", {"value": v, "text": v, "checked": (value===v)}).inject(select);
  426. });
  427. return select;
  428. },
  429. editCode: function(i, key){
  430. var node = this.lines[i].getLast();
  431. var value = (key==="propertyMap") ? JSON.stringify(this.data.propertyMap,null,2) : this.data[key];
  432. node.empty();
  433. var editor = new o2.widget.ScriptArea(node, {"title": "","maxObj": this.app.content, "isbind": false, "isload": true});
  434. editor.load({"code": value});
  435. return editor;
  436. },
  437. getModelData: function(){
  438. this.data.name = this.nameInput.get("value");
  439. this.data.description = this.descriptionInput.get("value");
  440. this.data.alias = this.aliasInput.get("value");
  441. this.data.analyzeType = this.analyzeInput.options[this.analyzeInput.selectedIndex].get("value");
  442. this.data.propertyMap = JSON.parse(this.propertyMapInput.editor.getValue());
  443. this.data.inValueScriptText = this.inValueScriptInput.editor.getValue();
  444. this.data.outValueScriptText = this.outValueScriptInput.editor.getValue();
  445. this.data.attachmentScriptText = this.attachmentScriptInput.editor.getValue();
  446. if (this.data.propertyMap) this.data.propertyMap = {};
  447. },
  448. save: function(){
  449. debugger;
  450. this.getModelData();
  451. if (!this.data.id){
  452. o2.Actions.get("x_query_assemble_designer").createModel(this.data, function(json){
  453. this.data.id = json.data.id;
  454. this.app.notice(this.lp.generate, "success");
  455. this.model.reload();
  456. this.reload();
  457. }.bind(this));
  458. }else{
  459. o2.Actions.get("x_query_assemble_designer").updateModel(this.data.id, this.data, function(){
  460. this.app.notice(this.lp.saveSuccess, "success");
  461. this.model.reload();
  462. this.reload();
  463. }.bind(this));
  464. }
  465. },
  466. generate: function(){
  467. o2.Actions.get("x_query_assemble_designer").generate(this.data.id,function(){
  468. this.app.notice(this.lp.generate, "success");
  469. this.model.reload();
  470. this.reload();
  471. }.bind(this));
  472. },
  473. learn: function(){
  474. o2.Actions.get("x_query_assemble_designer").learn(this.data.id, function(){
  475. this.app.notice(this.lp.learn, "success");
  476. this.model.reload();
  477. this.reload();
  478. }.bind(this));
  479. },
  480. stopGenerate: function(el, e){
  481. var _self = this;
  482. this.app.confirm("infor", e, this.lp.stopGenerateTitle, this.lp.stopGenerateInfor, 380, 100, function(){
  483. o2.Actions.get("x_query_assemble_designer").stopGenerating(_self.data.id, function(){
  484. this.app.notice(this.lp.stopGenerate, "success");
  485. this.model.reload();
  486. this.reload();
  487. }.bind(_self));
  488. this.close();
  489. }, function(){this.close();});
  490. },
  491. stopLearn: function(el, e){
  492. var _self = this;
  493. this.app.confirm("infor", e, this.lp.stopLearningTitle, this.lp.stopLearningInfor, 380, 100, function(){
  494. o2.Actions.get("x_query_assemble_designer").stopLearning(_self.data.id, function(){
  495. this.app.notice(this.lp.stopLearn, "success");
  496. this.model.reload();
  497. this.reload();
  498. }.bind(_self));
  499. this.close();
  500. }, function(){this.close();});
  501. },
  502. reset: function(el, e){
  503. var _self = this;
  504. this.app.confirm("infor", e, this.lp.resetStatusTitle, this.lp.resetStatusInfor, 380, 100, function(){
  505. o2.Actions.get("x_query_assemble_designer").resetStatus(_self.data.id, function(){
  506. this.app.notice(this.lp.resetStatus, "success");
  507. this.model.reload();
  508. this.reload();
  509. }.bind(_self));
  510. this.close();
  511. }, function(){this.close();});
  512. },
  513. remove: function(el, e){
  514. var _self = this;
  515. this.app.confirm("infor", e, this.lp.removeTitle, this.lp.removeInfor, 380, 100, function(){
  516. o2.Actions.get("x_query_assemble_designer").deleteModel(_self.data.id, function(){
  517. var text = this.lp.deleteModel.replace("{name}", this.data.name);
  518. this.app.notice(text, "success");
  519. var model = this.model;
  520. model.unselected();
  521. model.destroy();
  522. }.bind(_self));
  523. this.close();
  524. }, function(){this.close();});
  525. }
  526. });