bundle-editor.ko.js 4.0 KB

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