sqoop.submissions.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 submissions = (function($) {
  17. var submission_registry = {};
  18. var SubmissionModel = koify.Model.extend({
  19. 'job': -1,
  20. 'progress': 0.0,
  21. 'status': 'NEVER_EXECUTED',
  22. 'creation_date': 0,
  23. 'last_update_date': 0,
  24. 'external_id': null,
  25. 'external_link': null,
  26. 'initialize': function(attrs) {
  27. var self = this;
  28. var _attrs = $.extend(true, {}, attrs || {});
  29. _attrs = transform_keys(_attrs, {
  30. 'creation-date': 'creation_date',
  31. 'last-update-date': 'last_update_date',
  32. 'external-id': 'external_id',
  33. 'external-link': 'external_link'
  34. });
  35. return _attrs;
  36. }
  37. });
  38. var Submission = koify.Node.extend({
  39. 'identifier': 'submission',
  40. 'persists': false,
  41. 'model_class': SubmissionModel,
  42. 'base_url': '/sqoop/api/submissions/',
  43. 'initialize': function() {
  44. var self = this;
  45. self.parent.initialize.apply(self, arguments);
  46. self.createdFormatted = ko.computed(function() {
  47. if (self.creation_date()) {
  48. return moment(self.creation_date()).format('MM/DD/YYYY hh:mm A');
  49. } else {
  50. return 0;
  51. }
  52. });
  53. self.updatedFormatted = ko.computed(function() {
  54. if (self.last_update_date()) {
  55. return moment(self.last_update_date()).format('MM/DD/YYYY hh:mm A');
  56. } else {
  57. return 0;
  58. }
  59. });
  60. self.progressFormatted = ko.computed(function() {
  61. return (self.progress() * 2 * 100) + "%";
  62. });
  63. self.selected = ko.observable();
  64. }
  65. });
  66. function fetch_submissions(options) {
  67. $(document).trigger('load.submissions', [options]);
  68. var request = $.extend({
  69. url: '/sqoop/api/submissions/',
  70. dataType: 'json',
  71. type: 'GET',
  72. success: fetcher_success('submissions', Submission, options)
  73. }, options || {});
  74. $.ajax(request);
  75. }
  76. function put_submission(submission) {
  77. if (submission_registry[submission.job()]) {
  78. if (submission_registry[submission.job()].creation_date() < submission.creation_date() ||
  79. (submission_registry[submission.job()].creation_date() == submission.creation_date() && submission_registry[submission.job()].last_update_date() < submission.last_update_date())) {
  80. submission_registry[submission.job()] = submission;
  81. }
  82. } else {
  83. submission_registry[submission.job()] = submission;
  84. }
  85. }
  86. function get_submission(job_id) {
  87. return submission_registry[job_id];
  88. }
  89. function set_default_submission(job_id) {
  90. var submission = get_submission(job_id);
  91. if (!submission) {
  92. put_submission(new Submission({modelDict: {job: job_id}}));
  93. }
  94. return get_submission(job_id);
  95. }
  96. $(document).on('loaded.submissions', function(e, nodes, options) {
  97. $.each(nodes, function(index, submission) {
  98. put_submission(submission);
  99. });
  100. });
  101. return {
  102. 'SubmissionModel': SubmissionModel,
  103. 'Submission': Submission,
  104. 'fetchSubmissions': fetch_submissions,
  105. 'putSubmission': put_submission,
  106. 'getSubmission': get_submission,
  107. 'setDefaultSubmission': set_default_submission
  108. }
  109. })($);