diff --git a/view/web/sync.html b/view/web/sync.html index 598daad6b..5363b72f8 100644 --- a/view/web/sync.html +++ b/view/web/sync.html @@ -1,7 +1,7 @@

Sync Package <%= name %>

-
Sync start, please wait patiently.
+
Sync started, please wait patiently.

Log


@@ -12,6 +12,11 @@ 

Log

var timer; var name = '<%= name %>'; $(function() { + var checkLogId = location.hash.match(/logid=(\d+)/); + var logid = checkLogId ? checkLogId[1] : ''; + if (logid) { + return getSyncLog(logid); + } $.ajax({ url: location.pathname, type: 'PUT', @@ -19,7 +24,7 @@

Log

success: handleSyncSucess, error: function (err) { var alert = $('
'); - var message = 'Sync request error.'; + var message = 'Sync request error. '; if (err.status === 404) { message += 'Package ' + name + ' not exist in official registry.'; } @@ -35,6 +40,7 @@

Log

function handleSyncSucess(data) { if (data.ok) { timer = setInterval(getSyncLog.bind(null, data.logId), 2000); + location.hash = '#logid=' + data.logId; return; } $notify.html('
Sync request error.
'); @@ -44,6 +50,7 @@

Log

var logs = ''; var successFlag = false; var failFlag = false; + var hasFail = false; function getSyncLog(id) { $.ajax({ url: location.pathname + '/log/' + id + '?offset=' + offset, @@ -54,16 +61,24 @@

Log

return; } offset += data.log.split('\n').length; - logs += data.log; + logs = logs + '\n' + data.log; if (data.log.indexOf('Success: [') >= 0) { successFlag = true; } if (data.log.indexOf('Fail: [') >= 0) { failFlag = true; + var failInfo = data.log.match(/Fail: \[ (.*?) \]/); + if (failInfo && failInfo[1]) { + hasFail = true; + } } if (successFlag && failFlag) { logs += '\nSync package ' + name + ' complete!'; + if (hasFail) { + logs += ' But some packages sync failed, you can refresh to sync again.'; + location.hash = ''; + } clearInterval(timer); } $log.html(logs);