bundle-editor.ko.js 3.9 KB

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