file_versions.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <html>
  2. <head>
  3. <title locale="title/title">File Version History</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. .backgroundIcon{
  13. position: fixed;
  14. bottom: 0px;
  15. right: 0px;
  16. opacity: 0.3;
  17. margin-right: -8em;
  18. margin-bottom: -5em;
  19. z-index: -99;
  20. pointer-events: none;
  21. user-select: none;
  22. }
  23. </style>
  24. </head>
  25. <body id="filePropertiesWindow">
  26. <br>
  27. <div class="backgroundIcon">
  28. <img class="ui medium image" src="../../img/system/file-restore.svg">
  29. </div>
  30. <div class="ui container">
  31. <h3 class="ui header">
  32. <div class="content">
  33. <span locale="title/title">File Version History</span>
  34. <div class="sub header" locale="title/desc">Any file versions that is more than 30 days old will be automatically removed from the system.</div>
  35. </div>
  36. </h3>
  37. <button onclick="createSnapshot();" class="ui basic green button"><i class="ui add icon"></i> <span locale="button/newver">Create New Version</span></button>
  38. <div class="ui divider"></div>
  39. <div id="succ" style="display:none;" class="ui green message">
  40. <i class="ui checkmark icon"></i> <span id="msg">File Restore Succeed</span>
  41. </div>
  42. <div>
  43. <table class="ui very basic fluid celled table unstackable">
  44. <tbody id="versions">
  45. <tr>
  46. <td>
  47. <h4 class="ui header">
  48. <div class="content">
  49. <span locale="message/nofile/title">No File</span>
  50. <div locale="message/nofile/desc" class="sub header">Invalid usage</div>
  51. </div>
  52. </h4>
  53. </td>
  54. </tr>
  55. </tbody>
  56. </table>
  57. </div>
  58. <div class="ui divider"></div>
  59. <button class="ui red button" onclick="deleteAllVersions();"><i class="ui trash icon"></i> <span locale="button/removeAll">Remove All Version Histories</span></button>
  60. <br>
  61. </div>
  62. <script>
  63. var files = ao_module_loadInputFiles();
  64. var targetFile = "";
  65. var currentVersionList = [];
  66. if (files.length >= 1){
  67. targetFile = files[0];
  68. applocale.init("../../SystemAO/locale/file_versions.json", function(){
  69. applocale.translate();
  70. loadVersionHistory(targetFile);
  71. });
  72. setInterval(function(){
  73. checkHistoryListUpdate(targetFile);
  74. }, 3000)
  75. }else{
  76. //No file selected
  77. applocale.init("../../SystemAO/locale/file_versions.json", function(){
  78. applocale.translate();
  79. });
  80. }
  81. function checkHistoryListUpdate(vpath){
  82. $.ajax({
  83. url: "../../system/file_system/versionHistory",
  84. data: {path: vpath},
  85. method: "POST",
  86. success: function(data){
  87. if (data.error == undefined){
  88. if (currentVersionList.length != data.Versions.length){
  89. loadVersionHistory(vpath);
  90. }
  91. }
  92. }
  93. });
  94. }
  95. function loadVersionHistory(vpath){
  96. $("#versions").html("Loading...");
  97. $.ajax({
  98. url: "../../system/file_system/versionHistory",
  99. data: {path: vpath},
  100. method: "POST",
  101. success: function(data){
  102. if (data.error !== undefined){
  103. alert(data.error);
  104. }else{
  105. $("#versions").html("");
  106. currentVersionList = data.Versions;
  107. data.Versions.forEach(fileVersionEntry => {
  108. var filesize = ao_module_utils.formatBytes(fileVersionEntry.Filesize, 1);
  109. $("#versions").append(`<tr>
  110. <td>
  111. <h4 class="ui header">
  112. <div class="content">
  113. <span>${fileVersionEntry.Filename}</span>
  114. <div class="sub header">${fileVersionEntry.OverwriteTime} / ${filesize}</div>
  115. </div>
  116. </h4></td>
  117. <td>
  118. <div class="ui icon mini buttons">
  119. <button relpath="${fileVersionEntry.Relpath}" onclick="downloadVersion(this);" class="ui very basic icon button" title="${applocale.getString("title/download", "Download Version")}"><i class="ui blue download icon"></i></button>
  120. <button verid="${fileVersionEntry.HistoryID}" onclick="restoreVersion(this);" class="ui very basic icon button" title="${applocale.getString("title/restore", "Restore This Version")}"><i class="ui green history icon"></i></button>
  121. <button verid="${fileVersionEntry.HistoryID}" onclick="deleteVersion(this);" class="ui very basic icon button" title="${applocale.getString("title/delete", "Delete")}"><i class="ui red trash icon"></i></button>
  122. </div>
  123. </td>
  124. </tr>`);
  125. });
  126. if (data.Versions.length == 0){
  127. //This file has no version history
  128. $("#versions").html(`<tr>
  129. <td>
  130. <h4 class="ui header">
  131. <div class="content">
  132. <i class="ui history icon"></i><span> ${applocale.getString("message/nohist/title", "No History")}</span>
  133. <div class="sub header">${applocale.getString("message/nohist/desc", "This file has no previous version histories.")}</div>
  134. </div>
  135. </h4>
  136. </td>
  137. </tr>`);
  138. }
  139. applocale.translate();
  140. }
  141. }
  142. });
  143. }
  144. function downloadVersion(object){
  145. var relpath = $(object).attr("relpath");
  146. var dirname = targetFile.split("/");
  147. dirname.pop();
  148. var accessPath = dirname.join("/") + "/" + relpath;
  149. window.open("../../media/download?file=" + accessPath)
  150. }
  151. function createSnapshot(){
  152. //Create a snapshot of the current object
  153. $.ajax({
  154. url: "../../system/file_system/versionHistory",
  155. data: {path: targetFile, opr: "new"},
  156. method: "POST",
  157. success: function(data){
  158. if (data.error != undefined){
  159. alert(data.error)
  160. }else{
  161. msgbox(applocale.getString("msgbox/created","New Version Created"));
  162. loadVersionHistory(targetFile);
  163. }
  164. }
  165. });
  166. }
  167. function restoreVersion(object){
  168. var versionID = $(object).attr("verid");
  169. if (confirm(applocale.getString("warning/restore", "Restoring this file will remove all newer version histories of this file. Confirm?"))){
  170. $.ajax({
  171. url: "../../system/file_system/versionHistory",
  172. data: {path: targetFile, opr: "restore", histid: versionID},
  173. method: "POST",
  174. success: function(data){
  175. if (data.error != undefined){
  176. alert(data.error)
  177. }else{
  178. loadVersionHistory(targetFile);
  179. msgbox(applocale.getString("msgbox/restored","Restore Succeed"));
  180. }
  181. }
  182. });
  183. }
  184. }
  185. function msgbox(message){
  186. $("#msg").text(message);
  187. $("#succ").stop().finish().fadeIn("fast").delay(3000).fadeOut("fast");
  188. }
  189. function deleteVersion(object){
  190. var versionID = $(object).attr("verid");
  191. $.ajax({
  192. url: "../../system/file_system/versionHistory",
  193. data: {path: targetFile, opr: "delete", histid: versionID},
  194. method: "POST",
  195. success: function(data){
  196. if (data.error != undefined){
  197. alert(data.error)
  198. }else{
  199. loadVersionHistory(targetFile);
  200. }
  201. }
  202. });
  203. }
  204. function deleteAllVersions(object){
  205. var versionID = $(object).attr("verid");
  206. if (confirm(applocale.getString("warning/deleteall", "This operation will **PERMANENTLY DELETE ALL** version history of this file. Confirm?"))){
  207. $.ajax({
  208. url: "../../system/file_system/versionHistory",
  209. data: {path: targetFile, opr: "deleteAll", histid: versionID},
  210. method: "POST",
  211. success: function(data){
  212. if (data.error != undefined){
  213. alert(data.error)
  214. }else{
  215. msgbox(applocale.getString("msgbox/deletedall","All version history deleted"));
  216. loadVersionHistory(targetFile);
  217. }
  218. }
  219. });
  220. }
  221. }
  222. </script>
  223. </body>
  224. </html>