sqoop.connections.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 connections = (function($) {
  17. var ConnectionModel = koify.Model.extend({
  18. 'id': -1,
  19. 'updated': null,
  20. 'created': null,
  21. 'name': null,
  22. 'connector': [],
  23. 'connector_id': 0,
  24. 'framework': [],
  25. 'initialize': function(attrs) {
  26. var self = this;
  27. var _attrs = $.extend(true, {}, attrs);
  28. _attrs = transform_keys(_attrs, {
  29. 'connector-id': 'connector_id'
  30. });
  31. _attrs = transform_values(_attrs, {
  32. 'connector': to_forms,
  33. 'framework': to_forms
  34. });
  35. return _attrs;
  36. }
  37. });
  38. var Connection = koify.Node.extend({
  39. 'identifier': 'connection',
  40. 'persists': true,
  41. 'model_class': ConnectionModel,
  42. 'base_url': '/sqoop/api/connections/',
  43. 'initialize': function(options) {
  44. var self = this;
  45. self.parent.initialize.apply(self, arguments);
  46. self.selected = ko.observable();
  47. self.persisted = ko.computed(function() {
  48. return self.id() > -1;
  49. });
  50. self.connectionString = ko.computed(function() {
  51. var connection_string = null;
  52. $.each(self.connector(), function(index, form) {
  53. if (form.name() == 'connection') {
  54. $.each(form.inputs(), function(index, input) {
  55. if (input.name() == 'connection.connectionString') {
  56. connection_string = input.value();
  57. }
  58. });
  59. }
  60. });
  61. return connection_string;
  62. });
  63. },
  64. 'map': function() {
  65. var self = this;
  66. var mapping_options = $.extend(true, {
  67. 'ignore': ['parent', 'initialize']
  68. }, forms.MapProperties);
  69. if ('__ko_mapping__' in self) {
  70. ko.mapping.fromJS(self.model, mapping_options, self);
  71. } else {
  72. var mapped = ko.mapping.fromJS(self.model, mapping_options);
  73. $.extend(self, mapped);
  74. }
  75. },
  76. });
  77. function fetch_connections(options) {
  78. $(document).trigger('load.connections', [options]);
  79. var request = $.extend({
  80. url: '/sqoop/api/connections/',
  81. dataType: 'json',
  82. type: 'GET',
  83. success: fetcher_success('connections', Connection, options)
  84. }, options || {});
  85. $.ajax(request);
  86. }
  87. return {
  88. 'ConnectionModel': ConnectionModel,
  89. 'Connection': Connection,
  90. 'fetchConnections': fetch_connections
  91. }
  92. })($);