Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
refine sync page, fiexd #70
Browse files Browse the repository at this point in the history
  • Loading branch information
dead-horse committed Dec 11, 2013
1 parent 24e7de4 commit 0074e54
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions view/web/sync.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="sync">
<h1>Sync Package <span style="color:#09f;"><%= name %></span></h1>
<div id="sync-notify">
<div class="alert alert-success">Sync start, please wait patiently.</div>
<div class="alert alert-success">Sync started, please wait patiently.</div>
</div>
<h2>Log</h2>
<pre style="min-height: 400px;" id="sync-log"></pre>
Expand All @@ -12,14 +12,19 @@ <h2>Log</h2>
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',
dataType: 'json',
success: handleSyncSucess,
error: function (err) {
var alert = $('<div class="alert alert-error"></div>');
var message = 'Sync request error.';
var message = 'Sync request error. ';
if (err.status === 404) {
message += 'Package ' + name + ' not exist in official registry.';
}
Expand All @@ -35,6 +40,7 @@ <h2>Log</h2>
function handleSyncSucess(data) {
if (data.ok) {
timer = setInterval(getSyncLog.bind(null, data.logId), 2000);
location.hash = '#logid=' + data.logId;
return;
}
$notify.html('<div class="alert alert-error">Sync request error.</div>');
Expand All @@ -44,6 +50,7 @@ <h2>Log</h2>
var logs = '';
var successFlag = false;
var failFlag = false;
var hasFail = false;
function getSyncLog(id) {
$.ajax({
url: location.pathname + '/log/' + id + '?offset=' + offset,
Expand All @@ -54,16 +61,24 @@ <h2>Log</h2>
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);
Expand Down

0 comments on commit 0074e54

Please sign in to comment.