PackageMapValidateWidget.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2013 HPCC Systems.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ############################################################################## */
  16. define([
  17. "dojo/_base/declare",
  18. "dojo/_base/lang",
  19. "dojo/dom",
  20. "dojo/dom-attr",
  21. "dojo/dom-class",
  22. "dojo/topic",
  23. "dijit/layout/_LayoutWidget",
  24. "dijit/_TemplatedMixin",
  25. "dijit/_WidgetsInTemplateMixin",
  26. "dijit/registry",
  27. "hpcc/WsPackageMaps",
  28. "dojo/text!../templates/PackageMapValidateWidget.html",
  29. "dijit/form/Form",
  30. "dijit/form/Button",
  31. "dijit/form/RadioButton",
  32. "dijit/form/Select",
  33. "dijit/form/SimpleTextarea"
  34. ], function (declare, lang, dom, domAttr, domClass, topic,
  35. _LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin, registry,
  36. WsPackageMaps, template) {
  37. return declare("PackageMapValidateWidget", [_LayoutWidget, _TemplatedMixin, _WidgetsInTemplateMixin], {
  38. templateString: template,
  39. baseClass: "PackageMapValidateWidget",
  40. validateForm: null,
  41. targetSelect: null,
  42. packageContent: null,
  43. validateResult: null,
  44. validateButton: null,
  45. targets: null,
  46. processes: new Array(),
  47. initalized: false,
  48. buildRendering: function (args) {
  49. this.inherited(arguments);
  50. },
  51. postCreate: function (args) {
  52. this.inherited(arguments);
  53. this.validateForm = registry.byId(this.id + "ValidatePM");
  54. this.targetSelect = registry.byId(this.id + "TargetSelect");
  55. this.processSelect = registry.byId(this.id + "ProcessSelect");
  56. this.packageContent = registry.byId(this.id + "Package");
  57. this.validateButton = registry.byId(this.id + "Validate");
  58. this.validateResult = registry.byId(this.id + "ValidateResult");
  59. },
  60. startup: function (args) {
  61. this.inherited(arguments);
  62. },
  63. resize: function (args) {
  64. this.inherited(arguments);
  65. },
  66. layout: function (args) {
  67. this.inherited(arguments);
  68. },
  69. init: function (params) {
  70. if (this.initalized)
  71. return;
  72. this.initalized = true;
  73. this.validateResult.set('style', 'visibility:hidden');
  74. if (params.targets == undefined)
  75. return;
  76. this.initSelection(params.targets);
  77. },
  78. initSelections: function (targets) {
  79. this.targets = targets;
  80. if (this.targets.length > 0) {
  81. for (var i = 0; i < this.targets.length; ++i)
  82. this.targetSelect.options.push({label: this.targets[i].Name, value: this.targets[i].Name});
  83. this.targetSelect.set("value", this.targets[0].Name);
  84. if (this.targets[0].Processes != undefined)
  85. this.updateProcessSelections(this.targets[0].Name);
  86. }
  87. },
  88. addProcessSelections: function (processes) {
  89. for (var i = 0; i < processes.length; ++i) {
  90. var process = processes[i];
  91. if ((this.processes != null) && (this.processes.indexOf(process) != -1))
  92. continue;
  93. this.processes.push(process);
  94. this.processSelect.options.push({label: process, value: process});
  95. }
  96. },
  97. updateProcessSelections: function (targetName) {
  98. this.processSelect.removeOption(this.processSelect.getOptions());
  99. this.processSelect.options.push({label: 'ANY', value: '' });
  100. for (var i = 0; i < this.targets.length; ++i) {
  101. var target = this.targets[i];
  102. if ((target.Processes != undefined) && ((targetName == '') || (targetName == target.Name)))
  103. this.addProcessSelections(target.Processes.Item);
  104. }
  105. this.processSelect.set("value", '');
  106. },
  107. addArrayToText: function (arrayTitle, arrayItems, text) {
  108. if ((arrayItems.Item != undefined) && (arrayItems.Item.length > 0)) {
  109. text += arrayTitle + ":\n";
  110. for (i=0;i<arrayItems.Item.length;i++)
  111. text += " " + arrayItems.Item[i] + "\n";
  112. text += "\n";
  113. }
  114. return text;
  115. },
  116. validateResponseToText: function (response) {
  117. var text = "";
  118. if (!lang.exists("Errors", response) || (response.Errors.length < 1))
  119. text += "No errors found\n";
  120. else
  121. text = this.addArrayToText("Error(s)", response.Errors, text);
  122. if (!lang.exists("Warnings", response) || (response.Warnings.length < 1))
  123. text += "No warnings found\n";
  124. else
  125. text = this.addArrayToText("Warning(s)", response.Warnings, text);
  126. text += "\n";
  127. text = this.addArrayToText("Queries without matching package", response.queries.Unmatched, text);
  128. text = this.addArrayToText("Packages without matching queries", response.packages.Unmatched, text);
  129. text = this.addArrayToText("Files without matching package definitions", response.files.Unmatched, text);
  130. return text;
  131. },
  132. _onChangeTarget: function (event) {
  133. this.processes.length = 0;
  134. this.targetSelected = this.targetSelect.getValue();
  135. this.updateProcessSelections(this.targetSelected);
  136. },
  137. _onValidate: function (event) {
  138. var request = { target: this.targetSelect.getValue() };
  139. var type = this.validateForm.attr('value').ValidateType;
  140. if (type == 'ActivePM') {
  141. request['active'] = true;
  142. request['process'] = this.processSelect.getValue();
  143. } else {
  144. var content = this.packageContent.getValue();
  145. if (content == '') {
  146. alert('Package content not set');
  147. return;
  148. }
  149. request['content'] = content;
  150. }
  151. var context = this;
  152. this.validateResult.setValue("");
  153. this.validateButton.set("disabled", true);
  154. WsPackageMaps.validatePackage(request, {
  155. load: function (response) {
  156. var responseText = context.validateResponseToText(response);
  157. if (responseText == '')
  158. context.validateResult.setValue("(Empty)");
  159. else {
  160. responseText = '=====Validate Result=====\n\n' + responseText;
  161. context.validateResult.setValue(responseText);
  162. }
  163. context.validateResult.set('style', 'visibility:visible');
  164. context.validateButton.set("disabled", false);
  165. },
  166. error: function (errMsg, errStack) {
  167. context.showErrors(errMsg, errStack);
  168. context.validateButton.set("disabled", false);
  169. }
  170. });
  171. },
  172. showErrors: function (errMsg, errStack) {
  173. dojo.publish("hpcc/brToaster", {
  174. Severity: "Error",
  175. Source: errMsg,
  176. Exceptions: [{ Message: errStack }]
  177. });
  178. }
  179. });
  180. });