bundle-editor.ko.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. var Bundle = function (vm, bundle) {
  17. var self = this;
  18. self.id = ko.observable(typeof bundle.id != "undefined" && bundle.id != null ? bundle.id : null);
  19. self.uuid = ko.observable(typeof bundle.uuid != "undefined" && bundle.uuid != null ? bundle.uuid : UUID());
  20. self.name = ko.observable(typeof bundle.name != "undefined" && bundle.name != null ? bundle.name : "");
  21. self.coordinators = ko.mapping.fromJS(typeof bundle.coordinators != "undefined" && bundle.coordinators != null ? bundle.coordinators : []);
  22. self.properties = ko.mapping.fromJS(typeof bundle.properties != "undefined" && bundle.properties != null ? bundle.properties : {});
  23. self.addCoordinator = function(coordinator_uuid) {
  24. self.getCoordinatorParameters(coordinator_uuid);
  25. };
  26. self.getCoordinatorParameters = function(uuid) {
  27. $.get("/oozie/editor/coordinator/parameters/", {
  28. "uuid": uuid,
  29. }, function (data) {
  30. var _var = {
  31. 'coordinator': uuid,
  32. 'properties': data.parameters
  33. };
  34. self.coordinators.push(ko.mapping.fromJS(_var));
  35. }).fail(function (xhr, textStatus, errorThrown) {
  36. $(document).trigger("error", xhr.responseText);
  37. });
  38. };
  39. }
  40. var BundleEditorViewModel = function (bundle_json, coordinators_json, can_edit_json) {
  41. var self = this;
  42. self.canEdit = ko.mapping.fromJS(can_edit_json);
  43. self.isEditing = ko.observable(bundle_json.id == null);
  44. self.isEditing.subscribe(function(newVal){
  45. $(document).trigger("editingToggled");
  46. });
  47. self.toggleEditing = function () {
  48. self.isEditing(! self.isEditing());
  49. };
  50. self.bundle = new Bundle(self, bundle_json);
  51. self.coordinators = ko.mapping.fromJS(coordinators_json);
  52. self.coordinatorModalFilter = ko.observable("");
  53. self.filteredModalCoordinators = ko.computed(function() {
  54. var _filter = self.coordinatorModalFilter().toLowerCase();
  55. if (!_filter) {
  56. return self.coordinators();
  57. }
  58. else {
  59. return ko.utils.arrayFilter(self.coordinators(), function(coord) {
  60. return coord.name().toLowerCase().indexOf(_filter.toLowerCase()) > -1;
  61. });
  62. }
  63. }, self);
  64. self.getCoordinatorById = function (uuid) {
  65. var _coords = ko.utils.arrayFilter(self.coordinators(), function(coord) {
  66. return coord.uuid() == uuid;
  67. });
  68. if (_coords.length > 0){
  69. return _coords[0];
  70. }
  71. return null;
  72. }
  73. self.addBundledCoordinator = function (uuid) {
  74. self.bundle.addCoordinator(uuid);
  75. };
  76. self.save = function () {
  77. $.post("/oozie/editor/bundle/save/", {
  78. "bundle": ko.mapping.toJSON(self.bundle)
  79. }, function (data) {
  80. if (data.status == 0) {
  81. self.bundle.id(data.id);
  82. $(document).trigger("info", data.message);
  83. if (window.location.search.indexOf("bundle") == -1) {
  84. window.location.hash = '#bundle=' + data.id;
  85. }
  86. }
  87. else {
  88. $(document).trigger("error", data.message);
  89. }
  90. }).fail(function (xhr, textStatus, errorThrown) {
  91. $(document).trigger("error", xhr.responseText);
  92. });
  93. };
  94. self.showSubmitPopup = function () {
  95. // If self.bundle.id() == null, need to save wf for now
  96. $(".jHueNotify").hide();
  97. logGA('submit');
  98. $.get("/oozie/editor/bundle/submit/" + self.bundle.id(), {
  99. }, function (data) {
  100. $(document).trigger("showSubmitPopup", data);
  101. }).fail(function (xhr, textStatus, errorThrown) {
  102. $(document).trigger("error", xhr.responseText);
  103. });
  104. };
  105. };
  106. function logGA(page) {
  107. if (typeof trackOnGA == 'function') {
  108. trackOnGA('oozie/editor/bundle/' + page);
  109. }
  110. }