sqoop.connections.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. 'modelClass': ConnectionModel,
  42. 'base_url': '/sqoop/api/connections/',
  43. 'initialize': function() {
  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. });
  65. function fetch_connections(options) {
  66. $(document).trigger('load.connections', [options]);
  67. var request = $.extend({
  68. url: '/sqoop/api/connections/',
  69. dataType: 'json',
  70. type: 'GET',
  71. success: fetcher_success('connections', Connection, options)
  72. }, options || {});
  73. $.ajax(request);
  74. }
  75. return {
  76. 'ConnectionModel': ConnectionModel,
  77. 'Connection': Connection,
  78. 'fetchConnections': fetch_connections
  79. }
  80. })($);