file_properties.html 18 KB

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