sqoop.connections.js 3.1 KB

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