coordinator-editor.ko.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 Coordinator = function (vm, coordinator) {
  18. var self = this;
  19. self.id = ko.observable(typeof coordinator.id != "undefined" && coordinator.id != null ? coordinator.id : null);
  20. self.uuid = ko.observable(typeof coordinator.uuid != "undefined" && coordinator.uuid != null ? coordinator.uuid : UUID());
  21. self.name = ko.observable(typeof coordinator.name != "undefined" && coordinator.name != null ? coordinator.name : "");
  22. self.properties = ko.mapping.fromJS(typeof coordinator.properties != "undefined" && coordinator.properties != null ? coordinator.properties : {});
  23. self.datasets = ko.observableArray([]);
  24. self.inputDatasets = ko.observableArray([]);
  25. self.outputDatasets = ko.observableArray([]);
  26. }
  27. var CoordinatorEditorViewModel = function (coordinator_json, credentials_json) {
  28. var self = this;
  29. self.isEditing = ko.observable(true);
  30. self.isEditing.subscribe(function(newVal){
  31. $(document).trigger("editingToggled");
  32. });
  33. self.toggleEditing = function () {
  34. self.isEditing(! self.isEditing());
  35. };
  36. self.coordinator = new Coordinator(self, coordinator_json);
  37. self.credentials = ko.mapping.fromJSON(credentials_json);
  38. self.save = function () {
  39. $.post("/oozie/editor/coodinator/save/", {
  40. "coordinator": ko.mapping.toJSON(self.coordinator)
  41. }, function (data) {
  42. if (data.status == 0) {
  43. self.coordinator.id(data.id);
  44. $(document).trigger("info", data.message);
  45. if (window.location.search.indexOf("coordinator") == -1) {
  46. window.location.hash = '#coordinator=' + data.id;
  47. }
  48. }
  49. else {
  50. $(document).trigger("error", data.message);
  51. }
  52. }).fail(function (xhr, textStatus, errorThrown) {
  53. $(document).trigger("error", xhr.responseText);
  54. });
  55. };
  56. self.gen_xml = function () {
  57. $.post("/oozie/editor/coodinator/gen_xml/", {
  58. "coordinator": ko.mapping.toJSON(self.coordinator)
  59. }, function (data) {
  60. if (data.status == 0) {
  61. console.log(data.xml);
  62. }
  63. else {
  64. $(document).trigger("error", data.message);
  65. }
  66. }).fail(function (xhr, textStatus, errorThrown) {
  67. $(document).trigger("error", xhr.responseText);
  68. });
  69. };
  70. self.import_coordinators = function () {
  71. $.post("/oozie/editor/coodinator/import_coordinators/", {
  72. }, function (data) {
  73. if (data.status == 0) {
  74. console.log(data.json);
  75. }
  76. else {
  77. $(document).trigger("error", data.message);
  78. }
  79. }).fail(function (xhr, textStatus, errorThrown) {
  80. $(document).trigger("error", xhr.responseText);
  81. });
  82. };
  83. self.showSubmitPopup = function () {
  84. // If self.coordinator.id() == null, need to save wf for now
  85. $.get("/oozie/editor/coordinator/submit/" + self.coordinator.id(), {
  86. }, function (data) {
  87. $(document).trigger("showSubmitPopup", data);
  88. }).fail(function (xhr, textStatus, errorThrown) {
  89. $(document).trigger("error", xhr.responseText);
  90. });
  91. };
  92. };