file_properties.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <html>
  2. <head>
  3. <title locale="title/title">File Properties</title>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">
  6. <link rel="stylesheet" href="../../script/semantic/semantic.css">
  7. <script type="text/javascript" src="../../script/jquery.min.js"></script>
  8. <script type="text/javascript" src="../../script/semantic/semantic.min.js"></script>
  9. <script type="text/javascript" src="../../script/ao_module.js"></script>
  10. <script type="text/javascript" src="../../script/applocale.js"></script>
  11. <style>
  12. body{
  13. overflow:hidden;
  14. }
  15. </style>
  16. </head>
  17. <body id="filePropertiesWindow">
  18. <br>
  19. <div class="ui container">
  20. <h3 class="ui header">
  21. <span locale="title/title">File Properties</span>
  22. <div class="sub header" locale="title/desc">Basic File Information</div>
  23. </h3>
  24. <div class="ui divider"></div>
  25. <div id="properties">
  26. </div>
  27. <br>
  28. <button style="display:none;" class="ui small blue fluid button singleFileOnly" onclick="changeDefaultWebApp();" locale="button/changeDefault">Change Default WebApp</button>
  29. <button style="margin-top: 4px;" class="ui small fluid button linuxonly" onclick="openFilePermissionPanel();" locale="button/changeFilePermission">Change File Permissions</button>
  30. <br>
  31. </div>
  32. <div id="filesizeLoader" class="ui active dimmer">
  33. <div class="ui indeterminate text loader" locale="loader/loadingFileSize">Calculating File Size</div>
  34. </div>
  35. <script>
  36. //Initiate the view model
  37. var files = ao_module_loadInputFiles();
  38. var fileProperties = [];
  39. var fileInfo = {};
  40. function initFileProperties(){
  41. $("#properties").html("");
  42. if (files.length == 1){
  43. //There are only 1 file to be shown
  44. getFileProp(files[0], renderSingleObject);
  45. }else if (files.length > 1){
  46. for (var i =0; i < files.length; i++){
  47. getFileProp(files[i], function(data){
  48. fileProperties.push(data);
  49. if (fileProperties.length == files.length){
  50. renderMultipleObjects();
  51. }
  52. });
  53. }
  54. }
  55. }
  56. applocale.init("../locale/file_properties.json", function(){
  57. applocale.translate();
  58. initFileProperties();
  59. });
  60. //Hide windows / linux only operations
  61. $.get("/system/info/getArOZInfo", function(data){
  62. if (data.HostOS == "windows"){
  63. $(".linuxonly").hide();
  64. }else{
  65. $(".windowsonly").hide();
  66. }
  67. });
  68. function getFileProp(vpath, callback){
  69. $.ajax({
  70. url: "../../system/file_system/getProperties",
  71. data: {path: vpath},
  72. method: "POST",
  73. success: function(data){
  74. callback(data);
  75. fileInfo = data;
  76. //Initialize system theme
  77. fpw_loadPreference("file_explorer/theme",function(data){
  78. if (data.error === undefined){
  79. if (data == "darkTheme"){
  80. fpw_toggleDarkTheme();
  81. }else{
  82. //White theme. Do nothing
  83. }
  84. }
  85. });
  86. }
  87. })
  88. }
  89. function openFilePermissionPanel(){
  90. var hashPassthrough = encodeURIComponent(JSON.stringify(files));
  91. ao_module_newfw({
  92. url: "SystemAO/file_system/file_permission.html#" + hashPassthrough,
  93. width: 340,
  94. height: 480,
  95. appicon: "SystemAO/file_system/img/properties.png",
  96. title: "File Permissions",
  97. });
  98. }
  99. function renderMultipleObjects(){
  100. hideLoader();
  101. var filesizeSum = sumProperties(fileProperties, "Filesize");
  102. $("#properties").append(ui_getInput(fileProperties[0].VirtualDirname + "/", "Root Name"));
  103. var filecount = 0;
  104. var foldercount = 0;
  105. for (var i =0; i < fileProperties.length; i++){
  106. if (fileProperties[i].IsDirectory){
  107. foldercount++;
  108. }else{
  109. filecount++;
  110. }
  111. }
  112. $("#properties").append(ui_getText(applocale.getString("selection/multi", "Multiple selections")));
  113. $("#properties").append(ui_getText(filecount + applocale.getString("counter/files", " Files")));
  114. $("#properties").append(ui_getText(foldercount + applocale.getString("counter/folders", " Folders")));
  115. //Append other properties as table
  116. $("#properties").append(ui_getTable(
  117. [],
  118. [
  119. ["Virtual Directory", fileProperties[0].VirtualDirname + "/"],
  120. ["Storage Directory", fileProperties[0].StorageDirname + "/"],
  121. ["Total Size", bytesToSize(filesizeSum) + ` (${filesizeSum} bytes)`],
  122. ]
  123. ));
  124. }
  125. function sumProperties(data, propName){
  126. var sum = 0;
  127. for (var i = 0; i < data.length; i++){
  128. sum += data[i][propName];
  129. }
  130. return sum;
  131. }
  132. //Render one object property to the ui element
  133. function renderSingleObject(data){
  134. hideLoader();
  135. if (data.error !== undefined){
  136. //Something went wrong
  137. $("#properties").append(`<h4 class="ui header">
  138. <i class="question icon"></i>
  139. <div class="content">
  140. File Properties Unknown
  141. <div class="sub header">The system were unable to read the selected file properties.</div>
  142. </div>
  143. </h4>
  144. <div class="ui divider"></div>
  145. <small>${data.error}</small>
  146. `);
  147. }else{
  148. //Append Filename
  149. var filesizeText = "File Size";
  150. if (data.IsDirectory){
  151. $("#properties").append(ui_getInput(data.Basename, "Folder Name"));
  152. filesizeText = "Folder Size";
  153. }else{
  154. $("#properties").append(ui_getInput(data.Basename, "File Name"));
  155. }
  156. //Append MIME Type
  157. $("#properties").append(ui_getText(data.MimeType));
  158. //Get the default opener
  159. if (!data.IsDirectory){
  160. //Check if this file is shortcut
  161. if ( data.Basename.split(".").pop() == "shortcut"){
  162. //This is shortcut file
  163. $("#properties").append(ui_getTable(
  164. [],
  165. [
  166. ["Virtual Path", data.VirtualPath],
  167. ["Storage Path", data.StoragePath],
  168. ["Permission", data.Permission],
  169. ["Last Modified", generateDisplayLastModTime(data.LastModTime)],
  170. ["File Type", "System Shortcut"],
  171. ["Owner",data.Owner],
  172. ]
  173. ));
  174. }else{
  175. //Normal Files
  176. $(".singleFileOnly").show();
  177. $.ajax({
  178. url: "../../system/modules/getDefault",
  179. method: "GET",
  180. data: {
  181. opr: "launch",
  182. ext: "." + data.Basename.split(".").pop(),
  183. mode: "launch"
  184. },
  185. success: function(openerinfo) {
  186. //Check if the module is set.
  187. var defaultWebAppField = ["Default WebApp",`<img class="ui mini spaced image" style="margin-left: 0px; padding-right: 8px;" src="../../${openerinfo.IconPath}">` + openerinfo.Name];
  188. if ( openerinfo.Name == undefined){
  189. //Not set.
  190. defaultWebAppField = ["Default WebApp", `<a href="#" onclick="changeDefaultWebApp();">Set Default WebApp</a>`];
  191. }
  192. //Append other properties as table
  193. $("#properties").append(ui_getTable(
  194. [],
  195. [
  196. defaultWebAppField,
  197. ["Virtual Path", data.VirtualPath],
  198. ["Storage Path", data.StoragePath],
  199. [filesizeText, bytesToSize(data.Filesize) + ` (${data.Filesize} bytes)`],
  200. ["Permission", data.Permission],
  201. ["Last Modified", generateDisplayLastModTime(data.LastModTime)],
  202. ["File Type", "File"],
  203. ["Owner",data.Owner],
  204. ]
  205. ));
  206. }
  207. });
  208. }
  209. }else{
  210. $("#properties").append(ui_getTable(
  211. [],
  212. [
  213. ["Virtual Path", data.VirtualPath],
  214. ["Storage Path", data.StoragePath],
  215. [filesizeText, bytesToSize(data.Filesize) + ` (${data.Filesize} bytes)`],
  216. ["Permission", data.Permission],
  217. ["Last Modified", generateDisplayLastModTime(data.LastModTime)],
  218. ["File Type", "Folder"],
  219. ["Owner",data.Owner],
  220. ]
  221. ));
  222. }
  223. }
  224. }
  225. function hideLoader(){
  226. $("#filesizeLoader").hide();
  227. $("body").css('overflow-y',"auto");
  228. }
  229. //Model rendering scripts
  230. function ui_getInput(value, placeholder="", type="text"){
  231. return `<div class="ui fluid small input">
  232. <input type="${type}" placeholder="${placeholder}" value="${value}" readonly="true">
  233. </div>`
  234. }
  235. function ui_getText(value, color="black"){
  236. return `<p style="color:${color}; margin-bottom:0px;">${value}</p>`;
  237. }
  238. function ui_getDivider(){
  239. return `<div class="ui divider"></div>`;
  240. }
  241. //head is a 1D array and table is 2D array
  242. function ui_getTable(heads, table){
  243. html = `<table class="ui very basic fluid table">`;
  244. if (heads.length > 0){
  245. html += `<thead><tr>`;
  246. for (var i =0; i < heads.length; i++){
  247. html += `<th>${heads[i]}</th>`;
  248. }
  249. html += `</tr></thead>`;
  250. }
  251. html += `<tbody>`;
  252. for (var i =0; i < table.length; i++){
  253. html += `<tr>`;
  254. for (var j =0; j < table[i].length; j++){
  255. var keyString = table[i][j];
  256. if (j == 0 && applocale){
  257. keyString = applocale.getString("properties/key/" + keyString.trim(), keyString);
  258. }
  259. html += `<td style="word-break: break-all;">${keyString}</td>`
  260. }
  261. html += `</tr>`;
  262. }
  263. html += `</tbody>
  264. </table>`;
  265. return html
  266. }
  267. function bytesToSize(bytes) {
  268. var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  269. if (bytes == 0) return '0 Byte';
  270. var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
  271. return Math.round(bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i];
  272. }
  273. /*
  274. Updates Oct 2020 - Matching File Explorer Theme on other file system tabs
  275. */
  276. function fpw_toggleDarkTheme(){
  277. $("#filePropertiesWindow").css({
  278. "background-color":"#242330",
  279. "color":"white",
  280. });
  281. $("#filePropertiesWindow td,.header,p,div").css({
  282. "color":"white",
  283. });
  284. $("#filePropertiesWindow .input").addClass("inverted transparent big")
  285. }
  286. function fpw_loadPreference(key, callback){
  287. $.get("../../system/file_system/preference?key=" + key,function(data){
  288. callback(data);
  289. });
  290. }
  291. /*
  292. Updates 30 Jan 2021: Added change of file opener
  293. */
  294. //Open Opener Selector for the given file
  295. function changeDefaultWebApp(){
  296. var ext = fileInfo.Ext;
  297. var openFileList = [];
  298. var openFileObject = {
  299. filepath: fileInfo.VirtualPath,
  300. filename: fileInfo.Basename,
  301. }
  302. openFileList.push(openFileObject);
  303. var openParamter = encodeURIComponent(JSON.stringify(openFileObject));
  304. ao_module_newfw({
  305. url: "SystemAO/file_system/defaultOpener.html#" + openParamter,
  306. width: 320,
  307. height: 510,
  308. appicon: "SystemAO/file_system/img/opener.png",
  309. title: "Default WebApp for " + ext,
  310. parent: ao_module_windowID,
  311. callback: "handleRefresh"
  312. });
  313. }
  314. function handleRefresh(){
  315. //Default opener changed. Update the display
  316. initFileProperties();
  317. }
  318. /*
  319. Updates 9 April 2021: Added day compare for last modification days
  320. */
  321. function generateDisplayLastModTime(lastModTime){
  322. //Try to split the date into js date format
  323. var dateInfo = (lastModTime.split(" ")[0]).split("-");
  324. var modTime = new Date(dateInfo[0],dateInfo[1],dateInfo[2]);
  325. var diff = calcDate(new Date(), modTime);
  326. var displayText = "Unknown";
  327. if (diff[2] > 0){
  328. //years
  329. displayText = diff[2] + applocale.getString("lastmod/time/year", " year");
  330. if (diff[2] > 1){
  331. displayText += applocale.getString("lastmod/time/s", "s")
  332. }
  333. displayText += applocale.getString("lastmod/time/ago", " ago");
  334. }else if (diff[1] > 0){
  335. //months
  336. displayText = diff[1] + applocale.getString("lastmod/time/month", " month");
  337. if (diff[1] > 1){
  338. displayText += applocale.getString("lastmod/time/s", "s")
  339. }
  340. displayText += applocale.getString("lastmod/time/ago", " ago");
  341. }else if (diff [0] > 0){
  342. //days
  343. displayText = diff[0] + applocale.getString("lastmod/time/days", " day");
  344. if (diff[0] > 1){
  345. displayText += applocale.getString("lastmod/time/s", "s");
  346. }
  347. displayText += applocale.getString("lastmod/time/ago", " ago");
  348. }else{
  349. //just now
  350. displayText = applocale.getString("lastmod/time/today", "Today");
  351. }
  352. return displayText + " (" + lastModTime + ")";
  353. }
  354. function calcDate(date1 = new Date(),date2) {
  355. var diff = Math.floor(date1.getTime() - date2.getTime());
  356. var day = 1000 * 60 * 60 * 24;
  357. var days = Math.floor(diff/day);
  358. var months = Math.floor(days/31);
  359. var years = Math.floor(months/12);
  360. return [days, months, years];
  361. }
  362. </script>
  363. </body>
  364. </html>