workflow.import-node.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. /**
  17. * Import workflow action module
  18. * Enables selection of workflows.
  19. * Enables selection of actions within workflows.
  20. */
  21. var ImportNodeModule = function($, managed) {
  22. var module = function(options) {
  23. var self = this;
  24. self.nodes = ko.observableArray();
  25. self.workflows = ko.observableArray();
  26. self.selected_workflow = ko.observable();
  27. self.nodes_url = ko.computed(function() {
  28. return '/oozie/workflows/' + ((self.selected_workflow()) ? self.selected_workflow().id : 0) + '/actions';
  29. });
  30. self.workflows_url = ko.computed(function() {
  31. if (managed) {
  32. return '/oozie/workflows?managed=true';
  33. } else {
  34. return '/oozie/workflows?managed=false';
  35. }
  36. });
  37. module.prototype.initialize.apply(self, arguments);
  38. return self;
  39. };
  40. $.extend(module.prototype, {
  41. initialize: function(options) {
  42. var self = this;
  43. var options = options || {};
  44. if (options.workflows) {
  45. self.workflows.removeAll();
  46. $.each(options.workflows, function(index, workflow) {
  47. self.workflows.push(new WorkflowModel(workflow));
  48. });
  49. }
  50. if (options.nodes) {
  51. self.nodes.removeAll();
  52. $.each(options.nodes, function(index, node) {
  53. self.nodes.push(new NodeModel(node));
  54. });
  55. }
  56. },
  57. getAvailableNodes: function() {
  58. var self = this;
  59. return self.available_nodes;
  60. },
  61. fetchWorkflows: function(options) {
  62. var self = this;
  63. var request = $.extend({
  64. url: self.workflows_url(),
  65. dataType: 'json',
  66. type: 'GET',
  67. success: $.noop,
  68. error: $.noop
  69. }, options || {});
  70. $.ajax(request);
  71. },
  72. fetchNodes: function(options) {
  73. var self = this;
  74. var request = $.extend({
  75. url: self.nodes_url(),
  76. dataType: 'json',
  77. type: 'GET',
  78. success: $.noop,
  79. error: $.noop
  80. }, options || {});
  81. $.ajax(request);
  82. }
  83. });
  84. return module;
  85. };
  86. var ImportWorkflowAction = ImportNodeModule($, true);
  87. var ImportJobsubAction = ImportNodeModule($, false);