edit_dataset_view.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var filters = require('views/common/filter_view');
  20. var sort = require('views/common/sort_view');
  21. var date = require('utils/date');
  22. App.MainMirroringEditDataSetView = Em.View.extend({
  23. name: 'mainMirroringEditDataSetView',
  24. templateName: require('templates/main/mirroring/edit_dataset'),
  25. datasetTypeOptions: [Em.I18n.t('mirroring.dataset.type.HDFS'), Em.I18n.t('mirroring.dataset.type.Hive')],
  26. targetClusterSelect: Em.Select.extend({
  27. classNames: ['target-cluster-select'],
  28. content: function () {
  29. if (!this.get('parentView.isLoaded')) return [];
  30. return App.TargetCluster.find().mapProperty('name').without(App.get('clusterName')).concat(Em.I18n.t('mirroring.dataset.addTargetCluster'));
  31. }.property('parentView.isLoaded'),
  32. change: function () {
  33. if (this.get('selection') === Em.I18n.t('mirroring.dataset.addTargetCluster')) {
  34. this.set('selection', this.get('content')[0]);
  35. App.router.get('mainMirroringController').manageClusters();
  36. }
  37. this.set('parentView.controller.formFields.datasetTargetClusterName', this.get('selection'))
  38. }
  39. }),
  40. repeatOptions: [Em.I18n.t('mirroring.dataset.repeat.minutes'), Em.I18n.t('mirroring.dataset.repeat.hours'), Em.I18n.t('mirroring.dataset.repeat.days'), Em.I18n.t('mirroring.dataset.repeat.months')],
  41. middayPeriodOptions: [Em.I18n.t('mirroring.dataset.middayPeriod.am'), Em.I18n.t('mirroring.dataset.middayPeriod.pm')],
  42. hourOptions: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'],
  43. minuteOptions: ['00', '05', '10', '15', '20', '25', '30', '35', '40', '45', '50', '55'],
  44. isLoaded: function () {
  45. return App.router.get('mainMirroringController.isLoaded');
  46. }.property('App.router.mainMirroringController.isLoaded'),
  47. fillForm: function () {
  48. var isEdit = this.get('controller.isEdit');
  49. var selectedDataset = App.router.get('mainMirroringController.selectedDataset');
  50. if (this.get('isLoaded') && selectedDataset && isEdit) {
  51. var dataset = App.Dataset.find().findProperty('name', selectedDataset.get('id'));
  52. var scheduleStartDate = dataset.get('scheduleStartDate');
  53. var scheduleEndDate = dataset.get('scheduleEndDate');
  54. var formFields = this.get('controller.formFields');
  55. formFields.set('datasetName', dataset.get('name'));
  56. formFields.set('datasetSourceDir', dataset.get('sourceDir'));
  57. formFields.set('datasetTargetDir', dataset.get('targetDir'));
  58. formFields.set('datasetTargetClusterName', dataset.get('targetClusterName'));
  59. formFields.set('datasetFrequency', dataset.get('frequency'));
  60. formFields.set('repeatOptionSelected', dataset.get('frequencyUnit'));
  61. formFields.set('datasetStartDate', scheduleStartDate.slice(5, 7) + '/' + scheduleStartDate.slice(8, 10) + '/' + scheduleStartDate.slice(0, 4));
  62. formFields.set('datasetEndDate', scheduleEndDate.slice(5, 7) + '/' + scheduleEndDate.slice(8, 10) + '/' + scheduleEndDate.slice(0, 4));
  63. var startHours = scheduleStartDate.slice(11, 13);
  64. var endHours = scheduleEndDate.slice(11, 13);
  65. formFields.set('hoursForStart', this.get('controller').toAMPMHours(startHours));
  66. formFields.set('hoursForEnd', this.get('controller').toAMPMHours(endHours));
  67. formFields.set('minutesForStart', scheduleStartDate.slice(14, 16));
  68. formFields.set('minutesForEnd', scheduleEndDate.slice(14, 16));
  69. formFields.set('middayPeriodForStart', startHours > 12 || startHours === '00' ? 'PM' : 'AM');
  70. formFields.set('middayPeriodForEnd', endHours > 12 || endHours === '00' ? 'PM' : 'AM');
  71. }
  72. }.observes('isLoaded', 'App.router.mainMirroringController.selectedDataset', 'controller.isEdit'),
  73. didInsertElement: function () {
  74. $('.datepicker').datepicker({
  75. format: 'mm/dd/yyyy'
  76. });
  77. this.fillForm();
  78. },
  79. willDestroyElement: function () {
  80. var controller = this.get('controller');
  81. Em.keys(this.get('controller.formFields')).forEach(function (key) {
  82. controller.removeObserver('formFields.' + key, controller, 'validate');
  83. }, this);
  84. this._super();
  85. },
  86. init: function () {
  87. this.get('controller').clearStep();
  88. this._super();
  89. }
  90. });