move-modal.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. import Ember from 'ember';
  19. import OperationModal from '../mixins/operation-modal';
  20. export default Ember.Component.extend(OperationModal, {
  21. closeOnEscape: true,
  22. fileSelectionService: Ember.inject.service('files-selection'),
  23. fileOperationService: Ember.inject.service('file-operation'),
  24. selectedFiles: Ember.computed.alias('fileSelectionService.files'),
  25. selected: Ember.computed('selectedFiles', function () {
  26. return this.get('selectedFiles').objectAt(0);
  27. }),
  28. selectionName: '/',
  29. isUpdating: false,
  30. browseError: false,
  31. browseErrorMessege: '',
  32. hasError: false,
  33. shouldRetry: false,
  34. currentFailedPath: '',
  35. currentUnprocessedPaths: [],
  36. currentFailureMessage: '',
  37. movePaths: function (paths, destination) {
  38. this.set('isUpdating', true);
  39. this.get('fileOperationService').movePaths(paths, destination).then(
  40. (response) => {
  41. this.set('isUpdating', false);
  42. this.send('close');
  43. this.sendAction('refreshAction');
  44. }, (error) => {
  45. this.set('isUpdating', false);
  46. if (error.unprocessable === true) {
  47. this.set('hasError', true);
  48. this.set('currentFailedPath', error.failed);
  49. this.set('currentFailureMessage', error.message);
  50. this.set('shouldRetry', error.retry);
  51. this.set('currentUnprocessedPaths', error.unprocessed);
  52. } else {
  53. this.set('isUpdating', false);
  54. this.get('logger').danger("Failed to delete files and folders.", error);
  55. this.send('close');
  56. }
  57. });
  58. },
  59. reset: function () {
  60. this.set('browseError', false);
  61. this.set('browseErrorMessege', '');
  62. this.set('selectionName', '/');
  63. this.set('hasError', false);
  64. this.set('shouldRetry', false);
  65. this.set('isUpdating', false);
  66. this.set('currentFailedPath', '');
  67. this.set('currentFailureMessage', '');
  68. this.set('currentUnprocessedPaths', '');
  69. },
  70. actions: {
  71. didOpenModal: function () {
  72. this.reset();
  73. console.log("Move modal opened");
  74. },
  75. didCloseModal: function () {
  76. console.log("Move Modal did close.");
  77. },
  78. move: function () {
  79. var currentPathsToMove = this.get('selectedFiles').map((entry) => {
  80. return entry.get('path')
  81. });
  82. var destinationPath = (this.get('selectionName') !== '') ? this.get('selectionName') : '/';
  83. this.movePaths(currentPathsToMove, destinationPath);
  84. },
  85. retryError: function () {
  86. var newPaths = [this.get('currentFailedPath')];
  87. if (Ember.isArray(this.get('currentUnprocessedPaths'))) {
  88. newPaths.pushObjects(this.get('currentUnprocessedPaths'));
  89. }
  90. var destinationPath = (this.get('selectionName') !== '') ? this.get('selectionName') : '/';
  91. this.movePaths(newPaths, destinationPath);
  92. },
  93. skipAndRetry: function () {
  94. var destinationPath = (this.get('selectionName') !== '') ? this.get('selectionName') : '/';
  95. this.movePaths(this.get('currentUnprocessedPaths'), destinationPath);
  96. },
  97. skipAll: function () {
  98. this.send('close');
  99. this.sendAction('refreshAction');
  100. },
  101. pathSelected: function (path) {
  102. console.log(path);
  103. this.set('selectionName', path);
  104. this.set('browseError', false);
  105. },
  106. browseError: function (error) {
  107. this.set('browseError', true);
  108. this.set('browseErrorMessage', error.message);
  109. }
  110. }
  111. });