UIWindowItemProperties.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 UIWindowItemProperties(item_name, item_path, item_uid, left, top, width, height){
  22. let h = '';
  23. h += `<div class="item-props-tabview" style="display: flex; flex-direction: column; height: 100%;">`;
  24. // tabs
  25. h += `<div class="item-props-tab">`;
  26. h += `<div class="item-props-tab-btn antialiased disable-user-select item-props-tab-selected" data-tab="general">${i18n('general')}</div>`;
  27. h += `<div class="item-props-tab-btn antialiased disable-user-select item-props-tab-btn-versions" data-tab="versions">${i18n('versions')}</div>`;
  28. h += `</div>`;
  29. h+= `<div class="item-props-tab-content item-props-tab-content-selected" data-tab="general" style="border-top-left-radius:0;">`;
  30. h += `<table class="item-props-tbl">`;
  31. h += `<tr><td class="item-prop-label">Name</td><td class="item-prop-val item-prop-val-name"></td></tr>`;
  32. h += `<tr><td class="item-prop-label">Path</td><td class="item-prop-val item-prop-val-path"></td></tr>`;
  33. h += `<tr class="item-prop-original-name"><td class="item-prop-label">Original Name</td><td class="item-prop-val item-prop-val-original-name"></td></tr>`;
  34. h += `<tr class="item-prop-original-path"><td class="item-prop-label">Original Path</td><td class="item-prop-val item-prop-val-original-path"></td></tr>`;
  35. h += `<tr><td class="item-prop-label">Shortcut to</td><td class="item-prop-val item-prop-val-shortcut-to"></td></tr>`;
  36. h += `<tr><td class="item-prop-label">UID</td><td class="item-prop-val item-prop-val-uid"></td></tr>`;
  37. h += `<tr><td class="item-prop-label">Type</td><td class="item-prop-val item-prop-val-type"></td></tr>`;
  38. h += `<tr><td class="item-prop-label">Size</td><td class="item-prop-val item-prop-val-size"></td></tr>`;
  39. h += `<tr><td class="item-prop-label">Modified</td><td class="item-prop-val item-prop-val-modified"></td></tr>`;
  40. h += `<tr><td class="item-prop-label">Created</td><td class="item-prop-val item-prop-val-created"></td></tr>`;
  41. h += `<tr><td class="item-prop-label">Versions</td><td class="item-prop-val item-prop-val-versions"></td></tr>`;
  42. h += `<tr><td class="item-prop-label">Associated Websites</td><td class="item-prop-val item-prop-val-websites">`;
  43. h += `</td></tr>`;
  44. h += `<tr><td class="item-prop-label">${i18n('access_granted_to')}</td><td class="item-prop-val item-prop-val-permissions"></td></tr>`;
  45. h += `</table>`;
  46. h += `</div>`;
  47. h += `<div class="item-props-tab-content" data-tab="versions" style="padding: 20px;">`
  48. h += `<div class="item-props-version-list">`;
  49. h += `</div>`;
  50. h += `</div>`;
  51. h += `</div>`;
  52. const el_window = await UIWindow({
  53. title: `${item_name} properties`,
  54. app: item_uid+'-account',
  55. single_instance: true,
  56. icon: null,
  57. uid: null,
  58. is_dir: false,
  59. body_content: h,
  60. has_head: true,
  61. selectable_body: false,
  62. draggable_body: false,
  63. allow_context_menu: false,
  64. is_resizable: false,
  65. is_droppable: false,
  66. init_center: true,
  67. allow_native_ctxmenu: true,
  68. allow_user_select: true,
  69. left: left,
  70. top: top,
  71. height: height,
  72. onAppend: function(el_window){
  73. },
  74. width: 450,
  75. window_class: 'window-item-properties',
  76. window_css:{
  77. // height: 'initial',
  78. },
  79. body_css: {
  80. padding: '10px',
  81. width: 'initial',
  82. height: 'calc(100% - 50px)',
  83. 'background-color': 'rgb(241 242 246)',
  84. 'backdrop-filter': 'blur(3px)',
  85. 'content-box': 'content-box',
  86. }
  87. })
  88. // item props tab click handler
  89. $(el_window).find('.item-props-tab-btn').click(function(e){
  90. // unselect all tabs
  91. $(el_window).find('.item-props-tab-btn').removeClass('item-props-tab-selected');
  92. // select this tab
  93. $(this).addClass('item-props-tab-selected');
  94. // unselect all tab contents
  95. $(el_window).find('.item-props-tab-content').removeClass('item-props-tab-content-selected');
  96. // select this tab content
  97. $(el_window).find(`.item-props-tab-content[data-tab="${$(this).attr('data-tab')}"]`).addClass('item-props-tab-content-selected');
  98. })
  99. // /stat
  100. puter.fs.stat({
  101. uid: item_uid,
  102. returnSubdomains: true,
  103. returnPermissions: true,
  104. returnVersions: true,
  105. returnSize: true,
  106. success: function (fsentry){
  107. // hide versions tab if item is a directory
  108. if(fsentry.is_dir){
  109. $(el_window).find('[data-tab="versions"]').hide();
  110. }
  111. // name
  112. $(el_window).find('.item-prop-val-name').text(fsentry.name);
  113. // path
  114. $(el_window).find('.item-prop-val-path').text(item_path);
  115. // original name & path
  116. if(fsentry.metadata){
  117. try{
  118. let metadata = JSON.parse(fsentry.metadata);
  119. if(metadata.original_name){
  120. $(el_window).find('.item-prop-val-original-name').text(metadata.original_name);
  121. $(el_window).find('.item-prop-original-name').show();
  122. }
  123. if(metadata.original_path){
  124. $(el_window).find('.item-prop-val-original-path').text(metadata.original_path);
  125. $(el_window).find('.item-prop-original-path').show();
  126. }
  127. }catch(e){}
  128. }
  129. // shortcut to
  130. if(fsentry.shortcut_to && fsentry.shortcut_to_path){
  131. $(el_window).find('.item-prop-val-shortcut-to').text(fsentry.shortcut_to_path);
  132. }
  133. // uid
  134. $(el_window).find('.item-prop-val-uid').html(fsentry.id);
  135. // type
  136. $(el_window).find('.item-prop-val-type').html(fsentry.is_dir ? 'Directory' : (fsentry.type === null ? '-' : fsentry.type));
  137. // size
  138. $(el_window).find('.item-prop-val-size').html(fsentry.size === null || fsentry.size === undefined ? '-' : byte_format(fsentry.size));
  139. // modified
  140. $(el_window).find('.item-prop-val-modified').html(fsentry.modified === 0 ? '-' : timeago.format(fsentry.modified*1000));
  141. // created
  142. $(el_window).find('.item-prop-val-created').html(fsentry.created === 0 ? '-' : timeago.format(fsentry.created*1000));
  143. // subdomains
  144. if(fsentry.subdomains && fsentry.subdomains.length > 0 ){
  145. fsentry.subdomains.forEach(subdomain => {
  146. $(el_window).find('.item-prop-val-websites').append(`<p class="item-prop-website-entry" data-uuid="${html_encode(subdomain.uuid)}" style="margin-bottom:5px; margin-top:5px;"><a target="_blank" href="${html_encode(subdomain.address)}">${html_encode(subdomain.address)}</a> (<span class="disassociate-website-link" data-uuid="${html_encode(subdomain.uuid)}" data-subdomain="${extractSubdomain(subdomain.address)}">disassociate</span>)</p>`);
  147. });
  148. }
  149. else{
  150. $(el_window).find('.item-prop-val-websites').append('-');
  151. }
  152. // versions
  153. if(fsentry.versions && fsentry.versions.length > 0 ){
  154. fsentry.versions.reverse().forEach(version => {
  155. $(el_window).find('.item-props-version-list')
  156. .append(`<div class="item-prop-version-entry">${version.user? version.user.username : ''} &bull; ${timeago.format(version.timestamp*1000)}<p style="font-size:10px;">${version.id}</p></div>`);
  157. });
  158. }
  159. else{
  160. $(el_window).find('.item-props-version-list').append('-');
  161. }
  162. $(el_window).find(`.disassociate-website-link`).on('click', function(e){
  163. puter.hosting.update(
  164. $(e.target).attr('data-subdomain'),
  165. null).then(()=>{
  166. $(el_window).find(`.item-prop-website-entry[data-uuid="${$(e.target).attr('data-uuid')}"]`).remove();
  167. if($(el_window).find(`.item-prop-website-entry`).length === 0){
  168. $(el_window).find(`.item-prop-val-websites`).html('-');
  169. // remove the website badge from all instances of the dir
  170. $(`.item[data-uid="${item_uid}"]`).find('.item-has-website-badge').fadeOut(200);
  171. }
  172. }
  173. )
  174. })
  175. }
  176. })
  177. }
  178. export default UIWindowItemProperties