index.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="apple-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. <meta name="theme-color" content="#4b75ff">
  8. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  9. <script src="../script/jquery.min.js"></script>
  10. <script src="../script/ao_module.js"></script>
  11. <script src="../script/semantic/semantic.min.js"></script>
  12. <script type="application/javascript" src="../script/clipboard.min.js"></script>
  13. <title>ARZ Serverless</title>
  14. <style>
  15. body{
  16. background-color:white;
  17. }
  18. /* Tooltip container */
  19. .tooltip {
  20. position: relative;
  21. display: inline-block;
  22. border-bottom: 1px dotted black; /* If you want dots under the hoverable text */
  23. }
  24. /* Tooltip text */
  25. .tooltip .tooltiptext {
  26. visibility: hidden;
  27. width: 120px;
  28. background-color: #555;
  29. color: #fff;
  30. text-align: center;
  31. padding: 5px 0;
  32. border-radius: 6px;
  33. /* Position the tooltip text */
  34. position: absolute;
  35. z-index: 1;
  36. bottom: 125%;
  37. left: 50%;
  38. margin-left: -60px;
  39. /* Fade in tooltip */
  40. opacity: 0;
  41. transition: opacity 0.3s;
  42. }
  43. /* Tooltip arrow */
  44. .tooltip .tooltiptext::after {
  45. content: "";
  46. position: absolute;
  47. top: 100%;
  48. left: 50%;
  49. margin-left: -5px;
  50. border-width: 5px;
  51. border-style: solid;
  52. border-color: #555 transparent transparent transparent;
  53. }
  54. </style>
  55. </head>
  56. <body>
  57. <br>
  58. <div class="ui container" style="height: 100% !important;">
  59. <div>
  60. <h2 class="ui header">
  61. <img src="img/desktop_icon.png">
  62. <div class="content">
  63. ARZ Serverless
  64. <div class="sub header">Allow external services to run AGI scripts</div>
  65. </div>
  66. </h2>
  67. </div>
  68. <div class="ui divider"></div>
  69. <div id="deleteSuceed" style="display:none;" class="ui green inverted segment"><i class="checkmark icon"></i>Deleted</div>
  70. <div>
  71. <table class="ui celled table">
  72. <thead>
  73. <tr>
  74. <th>UUID (access token)</th>
  75. <th>AGI Path</th>
  76. <th>Action</th>
  77. </tr>
  78. </thead>
  79. <tbody id="records">
  80. </tbody>
  81. </table>
  82. <div style="width: 100%" align="center">
  83. <div class="ui breadcrumb" id="pageIndexs">
  84. </div>
  85. </div>
  86. </div>
  87. <div class="ui divider"></div>
  88. <div id="updateSuceed" style="display:none;" class="ui green inverted segment"><i class="checkmark icon"></i>Added</div>
  89. <h4>Select AGI Script</h4>
  90. <p>Select a script to be executed by 3rd party application via RESTFUL request. <br>
  91. Note that the AGI script will be executed with <b>your user scope</b></p>
  92. <div class="ui action fluid input">
  93. <input id="agiPath" type="text" placeholder="Select Location" readonly="true">
  94. <button class="ui black button" onclick="openfileselector();"><i class="folder open icon"></i> Open</button>
  95. </div>
  96. <br>
  97. <button class="ui positive button" onclick="add();"><i class="ui checkmark icon"></i> Add</button>
  98. <br><br>
  99. </div>
  100. <script>
  101. $.getJSON( "/api/ajgi/listExt", function( data ) {
  102. $.each( data, function( key, val ) {
  103. appendTable(key, val.path);
  104. });
  105. if(Object.keys(data).length == 0) {
  106. $("#records").append(`<tr id="zeroRec"><td>No registered endpoint</td></tr>`);
  107. }
  108. });
  109. function openfileselector(){
  110. ao_module_openFileSelector(fileLoader, "user:/", "file",false, {filter:["agi"]});
  111. }
  112. function fileLoader(filedata){
  113. for (var i=0; i < filedata.length; i++){
  114. var filename = filedata[i].filename;
  115. var filepath = filedata[i].filepath;
  116. $("#agiPath").val(filepath);
  117. }
  118. }
  119. function add() {
  120. var path = $("#agiPath").val();
  121. $.getJSON( "/api/ajgi/addExt?path=" + path, function( data ) {
  122. if(data.error == undefined) {
  123. $("#updateSuceed").slideDown("fast").delay(3000).slideUp("fast");
  124. appendTable(data, path);
  125. }else{
  126. alert(data.error);
  127. }
  128. });
  129. }
  130. function delRecord(element) {
  131. $.getJSON( "/api/ajgi/rmExt?uuid=" + $(element).attr("uuid"), function( data ) {
  132. if(data == "OK") {
  133. $("#deleteSuceed").slideDown("fast").delay(3000).slideUp("fast");
  134. }else{
  135. alert(data.error);
  136. }
  137. });
  138. $(element).parent().parent().remove().slideUp("fast");
  139. if($("#records").html().trim() == '') {
  140. $("#records").append(`<tr id="zeroRec"><td>0 record returned.</td></tr>`);
  141. }
  142. }
  143. var tokenAccessPath = location.protocol + "//" + window.location.host + "/api/remote/";
  144. new ClipboardJS('.copyURL', {
  145. text: function(trigger) {
  146. var token = $(trigger).attr("token");
  147. var url = tokenAccessPath + token;
  148. console.log( $(trigger).find(".tooltiptext"));
  149. $(trigger).find(".tooltiptext").css({
  150. "visibility": "visible",
  151. "opacity": 1,
  152. });
  153. setTimeout(function(){
  154. $(trigger).find(".tooltiptext").css({
  155. "visibility": "hidden",
  156. "opacity": 0,
  157. });
  158. }, 3000);
  159. return url;
  160. }
  161. });
  162. function generateClipboardText(uuid) {
  163. return `
  164. <div>
  165. <div class="content" style="font-family: monospace;">
  166. ${uuid} <a style="margin-left: 12px; font-family: Arial;" token="${uuid}" class="copyURL tooltip">
  167. <i class="copy icon"></i> Copy
  168. <span class="tooltiptext"><i class="checkmark icon"></i> Copied</span>
  169. </a>
  170. </div>
  171. </div>
  172. `;
  173. }
  174. function appendTable(uuid, path) {
  175. $("#zeroRec").remove().slideUp("fast");
  176. $("#records").append(`<tr>
  177. <td>` + generateClipboardText(uuid) +`</td>
  178. <td>` + path + `</td>
  179. <td>
  180. <button class="ui icon negative button" uuid="` + uuid + `" onclick="delRecord(this)">
  181. <i class="close icon"></i>
  182. </button>
  183. </td>
  184. </tr>`);
  185. }
  186. </script>
  187. </body>
  188. </html>