aecron.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="mobile-web-app-capable" content="yes">
  5. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
  6. <meta charset="UTF-8">
  7. <link rel="stylesheet" href="../../script/semantic/semantic.min.css">
  8. <script src="../../script/jquery.min.js"></script>
  9. <script src="../../script/semantic/semantic.min.js"></script>
  10. <script src="../arsm/js/moment.min.js"></script>
  11. <style>
  12. .hidden{
  13. display:none;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <div class="ui container">
  19. <div class="ui basic segment">
  20. <div class="ui header">
  21. <i class="calendar alternate outline icon"></i>
  22. <div class="content">
  23. System Schedular
  24. <div class="sub header">Schedule tasks to run while you are offline</div>
  25. </div>
  26. </div>
  27. </div>
  28. <div class="ui divider"></div>
  29. <table class="ui celled striped table">
  30. <thead>
  31. <tr>
  32. <th colspan="4">
  33. Scheduled Tasks
  34. </th>
  35. </tr>
  36. <tr>
  37. <th>
  38. Script
  39. </th>
  40. <th>
  41. Location
  42. </th>
  43. <th>
  44. Interval
  45. </th>
  46. <th>
  47. Base Time
  48. </th>
  49. </tr>
  50. </thead>
  51. <tbody id="scheduleList">
  52. </tbody>
  53. </table>
  54. <button id="schedulerButton" class="ui button" onclick="openSystemScheudler();">Open System Scheduler</button>
  55. </div>
  56. <script>
  57. initScheduleList();
  58. function initScheduleList(){
  59. $.ajax({
  60. url: "../../system/arsm/aecron/list",
  61. data: {},
  62. success: function(data){
  63. $("#scheduleList").html("");
  64. if (data.length == 0){
  65. $("#scheduleList").append(`<tr>
  66. <td colspan="4">
  67. No registered schedule.
  68. </td>
  69. </tr>`);
  70. }else{
  71. data.forEach(task => {
  72. var scriptName = task.ScriptFile.split("/").pop();
  73. $("#scheduleList").append(`<tr>
  74. <td class="collapsing">
  75. <i class="code file outline icon"></i> ${scriptName}
  76. </td>
  77. <td>${task.ScriptFile}</td>
  78. <td class="right aligned collapsing">Every ${parseSecondsToHumanReadableFormat(task.ExecutionInterval)}</td>
  79. <td class="right aligned collapsing">${moment.unix(task.BaseTime).format('LLL')}</td>
  80. </tr>`);
  81. });
  82. }
  83. }
  84. });
  85. }
  86. function parseSecondsToHumanReadableFormat(seconds){
  87. seconds = Number(seconds);
  88. var d = Math.floor(seconds / (3600*24));
  89. var h = Math.floor(seconds % (3600*24) / 3600);
  90. var m = Math.floor(seconds % 3600 / 60);
  91. var s = Math.floor(seconds % 60);
  92. var dDisplay = d > 0 ? d + (d == 1 ? " day " : " days ") : "";
  93. var hDisplay = h > 0 ? h + (h == 1 ? " hour " : " hours ") : "";
  94. var mDisplay = m > 0 ? m + (m == 1 ? " minute " : " minutes ") : "";
  95. var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
  96. return dDisplay + hDisplay + mDisplay + sDisplay;
  97. }
  98. //Check if the user has access right to the scheduler
  99. $.ajax({
  100. url : "../../system/modules/list",
  101. data: {},
  102. success: function(data){
  103. var allowAccess = false;
  104. data.forEach(moduleInfo => {
  105. if (moduleInfo.Name == "Tasks Scheduler"){
  106. //This user has access to task scheduler
  107. allowAccess = true;
  108. }
  109. });
  110. if (!allowAccess){
  111. $("#schedulerButton").hide();
  112. }
  113. }
  114. })
  115. function openSystemScheudler(){
  116. ao_module_newfw({
  117. url: "SystemAO/arsm/scheduler.html",
  118. appicon: "SystemAO/arsm/img/scheduler.png",
  119. title: "Task Scheduler"
  120. });
  121. }
  122. </script>
  123. </body>
  124. </html>