progress.ui.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. * 获取应用安装进度。
  3. * Get solution install progress.
  4. *
  5. * @access public
  6. * @return void
  7. */
  8. function getInstallProgress()
  9. {
  10. $.get($.createLink('install', 'ajaxProgress', 'id='+ solutionID)).done(function(response)
  11. {
  12. var res = JSON.parse(response);
  13. if(res.result == 'success')
  14. {
  15. var installed = true;
  16. for(var index in res.data)
  17. {
  18. var cloudApp = res.data[index];
  19. if(cloudApp.status == 'waiting')
  20. {
  21. $('.arrow.app-' + cloudApp.id).removeClass('active');
  22. $('.step.app-' + cloudApp.id + ' .step-no').removeClass('active');
  23. }
  24. else
  25. {
  26. $('.arrow.app-' + cloudApp.id).addClass('active');
  27. $('.step.app-' + cloudApp.id + ' .step-no').addClass('active');
  28. }
  29. if(cloudApp.status == 'installing' || cloudApp.status == 'installed')
  30. {
  31. $('#' + cloudApp.alias + '-status').text(installLabel);
  32. }
  33. if(cloudApp.status == 'configured')
  34. {
  35. $('#' + cloudApp.alias + '-status').text(configLabel);
  36. }
  37. if(cloudApp.status != 'installed' && cloudApp.status != 'configured')
  38. {
  39. installed = false;
  40. }
  41. if(cloudApp.status == 'error')
  42. {
  43. $('.error-message').text(res.message);
  44. $('.progress.loading').hide();
  45. }
  46. if(res.logs.hasOwnProperty(cloudApp.chart))
  47. {
  48. if(!shownLogs.hasOwnProperty(cloudApp.chart)) shownLogs[cloudApp.chart] = [];
  49. var logs = res.logs[cloudApp.chart]
  50. for(var j in logs)
  51. {
  52. if(shownLogs[cloudApp.chart].indexOf(logs[j].content) == -1)
  53. {
  54. term.write(logs[j].content + '\n');
  55. shownLogs[cloudApp.chart].push(logs[j].content);
  56. }
  57. }
  58. }
  59. }
  60. if(installed)
  61. {
  62. clearInterval(logTimer);
  63. $('.progress-message').text(notices.installationSuccess);
  64. if(!isModal)
  65. {
  66. loadPage($.createLink('install', 'step6'));
  67. }
  68. else
  69. {
  70. zui.Modal.alert(notices.installationSuccess).then(() => {
  71. const modal = zui.Modal.query('#installProgress');
  72. if(modal) modal.hide();
  73. loadPage($.createLink('space', 'browse'));
  74. })
  75. }
  76. }
  77. }
  78. else
  79. {
  80. $('#retryInstallBtn').removeClass('hidden');
  81. $('#skipInstallBtn').removeClass('primary');
  82. $('#skipInstallBtn').text(skipLang);
  83. $('#cancelInstallBtn').addClass('hidden');
  84. var errMessage = res.message;
  85. if(res.message instanceof Array) errMessage = res.message.join('<br/>');
  86. if(res.message instanceof Object) errMessage = Object.values(res.message).join('<br/>');
  87. $('.error-message').text(errMessage);
  88. clearInterval(logTimer);
  89. }
  90. });
  91. }
  92. window.retryInstall = function()
  93. {
  94. $('#retryInstallBtn').attr('disabled', true);
  95. zui.Modal.confirm(notices.confirmReinstall).then((result) =>
  96. {
  97. $('#retryInstallBtn').removeAttr('disabled');
  98. if(!result) return;
  99. $('#retryInstallBtn').addClass('hidden');
  100. $('#skipInstallBtn').text(backgroundLang);
  101. $('#skipInstallBtn').addClass('primary');
  102. $('#cancelInstallBtn').removeClass('hidden');
  103. $('.error-message').text('');
  104. $.get($.createLink('install', 'ajaxInstall', 'id=' + solutionID));
  105. });
  106. }
  107. window.cancelInstall = function()
  108. {
  109. $('#cancelInstallBtn').attr('disabled', true);
  110. zui.Modal.confirm(notices.cancelInstall).then((result) =>
  111. {
  112. $('#cancelInstallBtn').removeAttr('disabled');
  113. if(!result) return;
  114. clearInterval(logTimer);
  115. toggleLoading('#mainContent', true);
  116. $.ajaxSubmit({
  117. url: $.createLink('install', 'ajaxUninstall', 'id=' + solutionID),
  118. onComplete: function()
  119. {
  120. toggleLoading('#mainContent', false);
  121. }
  122. });
  123. });
  124. }
  125. $(function()
  126. {
  127. if(startInstall) $.get($.createLink('install', 'ajaxInstall', 'id=' + solutionID));
  128. $.getLib(config.webRoot + 'js/xterm/xterm.js', {root: false}, function()
  129. {
  130. term = new Terminal({convertEol: true, rows: 20});
  131. term.open(document.getElementById('terminal'));
  132. });
  133. if(typeof logTimer != 'undefined') clearInterval(logTimer);
  134. logTimer = setInterval(getInstallProgress, 4000);
  135. });