coordinator-editor.ko.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. // End dashboard lib
  17. var Dataset = function (vm, dataset) {
  18. var self = this;
  19. }
  20. var InputDataset = function (vm, input_dataset) {
  21. var self = this;
  22. }
  23. var OutputDataset = function (vm, output_dataset) {
  24. var self = this;
  25. }
  26. var Workflow = function (vm, workflow_json) {
  27. var self = this;
  28. }
  29. var Coordinator = function (vm, coordinator) {
  30. var self = this;
  31. self.id = ko.observable(typeof coordinator.id != "undefined" && coordinator.id != null ? coordinator.id : null);
  32. self.uuid = ko.observable(typeof coordinator.uuid != "undefined" && coordinator.uuid != null ? coordinator.uuid : UUID());
  33. self.name = ko.observable(typeof coordinator.name != "undefined" && coordinator.name != null ? coordinator.name : "");
  34. self.properties = ko.mapping.fromJS(typeof coordinator.properties != "undefined" && coordinator.properties != null ? coordinator.properties : {});
  35. self.variables = ko.observableArray([]);
  36. self.variablesUI = ko.observableArray(['parameter', 'input_path', 'output_path']);
  37. self.properties.workflow.subscribe(function(newVal) {
  38. if (newVal) {
  39. $.get("/desktop/api2/doc/get", {
  40. "uuid": self.properties.workflow().uuid()
  41. }, function (data) {
  42. // set wf
  43. }).fail(function (xhr, textStatus, errorThrown) {
  44. $(document).trigger("error", xhr.responseText);
  45. });
  46. }
  47. });
  48. self.addVariable = function() {
  49. var _var = {
  50. 'workflow_variable': '',
  51. 'dataset_type': 'parameter',
  52. 'dataset_variable': '',
  53. 'show_advanced': false,
  54. 'done_flag': '',
  55. 'timzone': 'America/Los_Angeles',
  56. 'range': 'single',
  57. 'frequency_number': 1,
  58. 'frequency_unit': 'DAYS',
  59. 'start': null,
  60. 'name': '',
  61. };
  62. self.variables.push(ko.mapping.fromJS(_var));
  63. };
  64. self.init = function() {
  65. // load
  66. };
  67. }
  68. var CoordinatorEditorViewModel = function (coordinator_json, credentials_json, workflows_json) {
  69. var self = this;
  70. self.isEditing = ko.observable(true);
  71. self.isEditing.subscribe(function(newVal){
  72. $(document).trigger("editingToggled");
  73. });
  74. self.toggleEditing = function () {
  75. self.isEditing(! self.isEditing());
  76. };
  77. self.coordinator = new Coordinator(self, coordinator_json);
  78. self.credentials = ko.mapping.fromJS(credentials_json);
  79. self.workflows = ko.mapping.fromJS(workflows_json);
  80. self.save = function () {
  81. $.post("/oozie/editor/coodinator/save/", {
  82. "coordinator": ko.mapping.toJSON(self.coordinator)
  83. }, function (data) {
  84. if (data.status == 0) {
  85. self.coordinator.id(data.id);
  86. $(document).trigger("info", data.message);
  87. if (window.location.search.indexOf("coordinator") == -1) {
  88. window.location.hash = '#coordinator=' + data.id;
  89. }
  90. }
  91. else {
  92. $(document).trigger("error", data.message);
  93. }
  94. }).fail(function (xhr, textStatus, errorThrown) {
  95. $(document).trigger("error", xhr.responseText);
  96. });
  97. };
  98. self.gen_xml = function () {
  99. $.post("/oozie/editor/coodinator/gen_xml/", {
  100. "coordinator": ko.mapping.toJSON(self.coordinator)
  101. }, function (data) {
  102. if (data.status == 0) {
  103. console.log(data.xml);
  104. }
  105. else {
  106. $(document).trigger("error", data.message);
  107. }
  108. }).fail(function (xhr, textStatus, errorThrown) {
  109. $(document).trigger("error", xhr.responseText);
  110. });
  111. };
  112. self.import_coordinators = function () {
  113. $.post("/oozie/editor/coodinator/import_coordinators/", {
  114. }, function (data) {
  115. if (data.status == 0) {
  116. console.log(data.json);
  117. }
  118. else {
  119. $(document).trigger("error", data.message);
  120. }
  121. }).fail(function (xhr, textStatus, errorThrown) {
  122. $(document).trigger("error", xhr.responseText);
  123. });
  124. };
  125. self.showSubmitPopup = function () {
  126. // If self.coordinator.id() == null, need to save wf for now
  127. $.get("/oozie/editor/coordinator/submit/" + self.coordinator.id(), {
  128. }, function (data) {
  129. $(document).trigger("showSubmitPopup", data);
  130. }).fail(function (xhr, textStatus, errorThrown) {
  131. $(document).trigger("error", xhr.responseText);
  132. });
  133. };
  134. };