UIWindowDownloadProgress.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * Copyright (C) 2024 Puter Technologies Inc.
  3. *
  4. * This file is part of Puter.
  5. *
  6. * Puter is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published
  8. * by the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. import UIWindow from './UIWindow.js'
  20. // todo do this using uid rather than item_path, since item_path is way mroe expensive on the DB
  21. async function UIWindowDownloadProgress(options){
  22. let h = '';
  23. h += `<div data-download-operation-id="${options.operation_id}">`;
  24. h += `<div>`;
  25. // Spinner
  26. h +=`<svg style="float:left; margin-right: 7px;" xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24"><title>circle anim</title><g fill="#212121" class="nc-icon-wrapper"><g class="nc-loop-circle-24-icon-f"><path d="M12 24a12 12 0 1 1 12-12 12.013 12.013 0 0 1-12 12zm0-22a10 10 0 1 0 10 10A10.011 10.011 0 0 0 12 2z" fill="#212121" opacity=".4"></path><path d="M24 12h-2A10.011 10.011 0 0 0 12 2V0a12.013 12.013 0 0 1 12 12z" data-color="color-2"></path></g><style>.nc-loop-circle-24-icon-f{--animation-duration:0.5s;transform-origin:12px 12px;animation:nc-loop-circle-anim var(--animation-duration) infinite linear}@keyframes nc-loop-circle-anim{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}</style></g></svg>`;
  27. // Progress report
  28. h +=`<div style="margin-bottom:20px; float:left; padding-top:3px; font-size:15px; overflow: hidden; width: calc(100% - 40px); text-overflow: ellipsis; white-space: nowrap;">`;
  29. // msg
  30. h += `<span class="upload-progress-msg">${i18n('downloading')} <strong>${options.item_name ?? ''}</strong></span>`;
  31. h += `</div>`;
  32. // Progress
  33. h += `<div class="download-progress-bar-container" style="clear:both; margin-top:20px; border-radius:3px;">`;
  34. h += `<div class="download-progress-bar"></div>`;
  35. h += `</div>`;
  36. // Cancel
  37. h += `<button style="float:right; margin-top: 15px; margin-right: -2px;" class="button button-small download-cancel-btn">Cancel</button>`;
  38. h +=`</div>`;
  39. h += `</div>`;
  40. const el_window = await UIWindow({
  41. title: `Upload`,
  42. icon: window.icons[`app-icon-uploader.svg`],
  43. uid: null,
  44. is_dir: false,
  45. body_content: h,
  46. has_head: false,
  47. selectable_body: false,
  48. draggable_body: true,
  49. allow_context_menu: false,
  50. is_resizable: false,
  51. is_droppable: false,
  52. init_center: true,
  53. allow_native_ctxmenu: false,
  54. allow_user_select: false,
  55. window_class: 'window-upload-progress',
  56. width: 450,
  57. dominant: true,
  58. window_css:{
  59. height: 'initial',
  60. },
  61. body_css: {
  62. padding: '22px',
  63. width: 'initial',
  64. 'background-color': 'rgba(231, 238, 245, .95)',
  65. 'backdrop-filter': 'blur(3px)',
  66. }
  67. });
  68. // cancel download button clicked
  69. $(el_window).find('.download-cancel-btn').on('click', function(){
  70. operation_cancelled[options.operation_id] = true;
  71. $(el_window).close();
  72. })
  73. return el_window;
  74. }
  75. export default UIWindowDownloadProgress