addAndRemove.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <html>
  2. <head>
  3. <title>Subservices</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.min.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. <style>
  11. .ui.active.segment{
  12. background-color: #f5f5f5 !important;
  13. }
  14. .ui.segment.installedModule{
  15. cursor: pointer;
  16. margin: 0px !important;
  17. }
  18. .ui.segment.installedModule:hover{
  19. background-color: #e3e3e3;
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <br>
  25. <div class="ui container">
  26. <div class="ui container">
  27. <div class="ui header">
  28. <i class="add icon"></i>
  29. <div class="content">
  30. Add & Remove Module
  31. <div class="sub header">Install or Uninstall WebApp Modules from this Host</div>
  32. </div>
  33. </div>
  34. </div>
  35. <div class="ui divider"></div>
  36. <div class="ui red message" style="display:none;" id="errmsgbox">
  37. <h4 class="ui header">
  38. <i class="remove icon"></i>
  39. <div class="content">
  40. Module Installation Failed
  41. <div class="sub header" id="errmsg"></div>
  42. </div>
  43. </h4>
  44. </div>
  45. <div class="ui green message" style="display:none;" id="ok">
  46. <h4 class="ui header">
  47. <i class="checkmark icon"></i>
  48. <div class="content">
  49. Module Installation Completed
  50. <div class="sub header" >You should be able to see your new module in the list below.</div>
  51. </div>
  52. </h4>
  53. </div>
  54. <div class="ui blue segment">
  55. <h4 class="ui header">
  56. New WebApp
  57. <div class="sub header">Download new WebApp to your ArozOS Host</div>
  58. </h4>
  59. <div class="ui divider"></div>
  60. <h5>Install via Git Repository</h5>
  61. <p>Enter the Github repo link in the field below and click "Install"</p>
  62. <div class="ui small fluid action input" id="installViaGitInput">
  63. <input id="gitlink" type="text" placeholder="http://github.com/....">
  64. <button class="ui blue button" onclick="installViaGit();"><i class="download icon"></i> Install</button>
  65. </div>
  66. <div class="ui blue message" style="display:none;" id="installingDialog">
  67. <p><i class="ui loading spinner icon"></i> Module installing in the background. Please wait until this dialog is closed.</p>
  68. </div>
  69. <div class="ui divider"></div>
  70. <h4>Install via Zip File</h4>
  71. <p>Select your module zip file and upload it to the system for installation.</p>
  72. <div class="ui small fluid action input">
  73. <input type="text" id="installpendingFile" placeholder="New Module.zip">
  74. <button class="ui button" onclick="selectInstaller()"><i class="folder open icon"></i> Select Installer</button>
  75. <button class="ui blue button" onclick="InstallViaZipFile(this)"><i class="zip icon" ></i> Install</button>
  76. </div>
  77. </div>
  78. <div class="ui red segment">
  79. <h4 class="ui header">
  80. Remove WebApp
  81. <div class="sub header">Remove WebApp from your ArozOS Host</div>
  82. </h4>
  83. <div class="ui green message" id="succ" style="display:none;">
  84. <i class="check icon"></i> WebApp module uninstalled successfully.
  85. </div>
  86. <div class="ui divider"></div>
  87. <div id="modulelist">
  88. No Module Installed
  89. </div>
  90. </div>
  91. </div>
  92. <div id="loadingUI" class="ui dimmer">
  93. <div class="ui indeterminate text loader">Fetching Files</div>
  94. </div>
  95. <script>
  96. var moduleList = [];
  97. initModuleUninstallList();
  98. function bytesToSize(bytes) {
  99. var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
  100. if (bytes == 0) return '0 Byte';
  101. var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
  102. return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
  103. }
  104. function initModuleUninstallList(){
  105. $.get("../../system/module/install", function(data){
  106. console.log(data);
  107. moduleList = data;
  108. $("#modulelist").html("");
  109. data.forEach(mod => {
  110. var uninstallButtonClass = "";
  111. if (mod.Uninstallable == false){
  112. uninstallButtonClass = "disabled"
  113. }
  114. $("#modulelist").append(`<div class="ui basic segment installedModule" onclick="selectThisModule(event, this);">
  115. <img class="ui top aligned image" style="margin-right: 12px; width: 50px;" src="../../${mod.IconPath}">
  116. <div style="display:inline-block;">
  117. <b>${mod.Name}</b>
  118. <p>${mod.Desc}</p>
  119. <div style="position: absolute;top: 0.6em; right: 2em; text-align: right;">
  120. <b>${bytesToSize(mod.DiskSpace)}</b><br>
  121. <span>${mod.InstallDate}</span>
  122. </div>
  123. </div>
  124. <div style="text-align: right; display:none;" class="actionField">
  125. <button class="ui small ${uninstallButtonClass} button" name="${mod.Name}" onclick="removeModule(event,this);">Uninstall</button>
  126. <div class="ui red message errordialog" style="text-align:left; display:none;">
  127. <i class="remove icon"></i> WebApp Removal Failed: <span class="errmsg"></span>
  128. </div>
  129. </div>
  130. </div> `);
  131. });
  132. });
  133. }
  134. function removeModule(e, btn){
  135. var modulename = $(btn).attr("name");
  136. //Ask for confirmation
  137. if (confirm("Confirm permanently remove " + modulename + " ?")){
  138. $.ajax({
  139. url: "../../system/module/install",
  140. data: {opr: "remove", module: modulename},
  141. success: function(data){
  142. if (data.error !== undefined){
  143. $(btn).parent().find(".errmsg").text(data.error);
  144. $(btn).parent().find(".errordialog").slideDown("fast").delay(10000).slideUp("fast");
  145. }else{
  146. //Reload list
  147. initModuleUninstallList();
  148. //Reload desktop module list
  149. if (parent && parent.initModuleList != undefined){
  150. parent.initModuleList();
  151. }
  152. $("#succ").slideDown("fast").delay(3000).slideUp('fast');
  153. }
  154. }
  155. });
  156. }
  157. }
  158. function selectInstaller(){
  159. ao_module_openFileSelector(fileSelected, "user:/Desktop", "file",true, {
  160. filter: ["zip"]
  161. });
  162. }
  163. function fileSelected(filedata){
  164. for (var i=0; i < filedata.length; i++){
  165. var filename = filedata[i].filename;
  166. var filepath = filedata[i].filepath;
  167. $("#installpendingFile").val(filepath);
  168. }
  169. }
  170. function InstallViaZipFile(btn){
  171. //Select the upload module zip file
  172. var installerPath = $("#installpendingFile").val();
  173. if (installerPath == ""){
  174. $("#installpendingFile").parent().addClass("error");
  175. }else{
  176. $("#installpendingFile").parent().removeClass("error");
  177. }
  178. $(btn).addClass("loading");
  179. //Install it
  180. $.ajax({
  181. url: "../../system/modules/installViaZip",
  182. data: {path: installerPath},
  183. success: function(data){
  184. console.log(data);
  185. if (data.error !== undefined){
  186. $("#errmsg").text(data.error);
  187. $("#errmsgbox").slideDown("fast").delay(10000).slideUp("fast");
  188. }else{
  189. //Install completed.
  190. if (parent && parent.initModuleList != undefined){
  191. parent.initModuleList();
  192. }
  193. initModuleUninstallList();
  194. $("#ok").slideDown('fast').delay(5000).slideUp('fast');
  195. }
  196. $(btn).removeClass("loading");
  197. },
  198. error: function(){
  199. $(btn).removeClass("loading");
  200. alert("Installation failed due to unknown reason")
  201. }
  202. })
  203. }
  204. function installViaGit(){
  205. var url = $("#gitlink").val();
  206. $("#installingDialog").show();
  207. $("#installViaGitInput").addClass("disabled");
  208. $.ajax({
  209. url: "../../system/module/install",
  210. data: {opr: "gitinstall", url: url},
  211. success: function(data){
  212. console.log(data);
  213. if (data.error !== undefined){
  214. $("#errmsg").text(data.error);
  215. $("#errmsgbox").slideDown("fast").delay(10000).slideUp("fast");
  216. }else{
  217. //OK. Reload the list
  218. if (parent && parent.initModuleList != undefined){
  219. parent.initModuleList();
  220. }
  221. //Reload the uninstall list
  222. initModuleUninstallList();
  223. }
  224. $("#installingDialog").hide();
  225. $("#installViaGitInput").removeClass("disabled");
  226. },
  227. error: function(){
  228. $("#errmsg").text(data.error);
  229. $("#errmsgbox").slideDown("fast").delay(10000).slideUp("fast");
  230. $("#installingDialog").hide();
  231. $("#installViaGitInput").removeClass("disabled");
  232. }
  233. });
  234. }
  235. function selectThisModule(e, obj){
  236. e.preventDefault();
  237. $(".ui.segment.installedModule.active").removeClass('active');
  238. $(".actionField").hide();
  239. $(obj).addClass("active");
  240. $(obj).find(".actionField").show();
  241. }
  242. </script>
  243. </body>
  244. </html>