file_versions.html 11 KB

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