file_properties.html 18 KB

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