Permalink
Browse files

Fix parallel change detection and integrate into wall maker

  • Loading branch information...
1 parent 26d229f commit 53a7e5ff311dfdfc68a13b57ad78f9043c25e97b @birtles birtles committed Mar 13, 2013
Showing with 28 additions and 16 deletions.
  1. +6 −5 wall/lib/walls.inc
  2. +22 −11 wall/public/wall-maker/js/manage-wall.js
View
@@ -310,7 +310,7 @@ function startNewSession($wallId, $sessionId, $datetime) {
}
// Close the latest session if it's open
- if (@$latestSession['endDate'] !== null) {
+ if (@$latestSession['endDate'] === null) {
closeLastSession($wallId, $sessionId, $datetime);
}
@@ -370,10 +370,11 @@ function getActiveSessionId($wallId) {
$qdate = $conn->quote($date, 'timestamp');
$res =& $conn->queryOne(
- 'SELECT sessionId FROM sessions WHERE'
- . ' wallId = ' . $conn->quote($wallId, 'integer')
- . ' AND beginDate <= ' . $qdate
- . ' AND (endDate IS NULL OR endDate > ' . $qdate . ')',
+ 'SELECT sessionId FROM sessions'
+ . ' WHERE wallId = ' . $conn->quote($wallId, 'integer')
+ . ' AND endDate IS NULL'
+ . ' ORDER BY sessionId DESC'
+ . ' LIMIT 1',
'integer');
if (PEAR::isError($res)) {
error_log($res->getMessage() . ', ' . $res->getDebugInfo());
@@ -159,11 +159,7 @@ var ManageWallController =
$("manage-eventLocation").value = response.eventLocation;
$("manage-eventDescr").value = response.eventDescr;
- // Operation
- $("manage-duration").value = response.duration == null
- ? ""
- : response.duration/1000;
- $("manage-defaultDuration").textContent = response.defaultDuration/1000;
+ // Sessions
this.updateSessionInfo(response.session);
// Design
@@ -181,6 +177,10 @@ var ManageWallController =
radio.dispatchEvent(evt);
}
}
+ $("manage-duration").value = response.duration == null
+ ? ""
+ : response.duration/1000;
+ $("manage-defaultDuration").textContent = response.defaultDuration/1000;
// Privacy
var dummypasscode = "";
@@ -250,14 +250,14 @@ var ManageWallController =
/*
* Error handling
*/
- showError: function(key, timeout) {
+ showError: function(key) {
// XXXl10n Hook this up to our localization
switch(key) {
case 'timeout':
msg = "接続できませんでした.";
break;
- case 'parallel-access-session':
+ case 'parallel-change':
msg = "Someone else has updated the session."
+ " Please confirm the updated session status.";
break;
@@ -270,7 +270,6 @@ var ManageWallController =
var messageBlock = this.errorBlock.querySelector('.errorMessage');
messageBlock.textContent = msg;
- // XXX Set timeout if needed
this.errorBlock.setAttribute('aria-hidden', 'false');
},
@@ -289,7 +288,7 @@ var ManageWallController =
startSession: function() {
this.startUpdateSessionInfo();
ParaPara.postRequest(WallMaker.rootUrl + '/api/startSession',
- {wallId: this.wallId},
+ {wallId: this.wallId, sessionId: this.sessionId},
this.updateSessionInfo.bind(this),
this.handleSessionError.bind(this)
);
@@ -298,15 +297,24 @@ var ManageWallController =
closeSession: function() {
this.startUpdateSessionInfo();
ParaPara.postRequest(WallMaker.rootUrl + '/api/closeSession',
- {wallId: this.wallId},
+ {wallId: this.wallId, sessionId: this.sessionId},
this.updateSessionInfo.bind(this),
this.handleSessionError.bind(this)
);
},
handleSessionError: function(key, detail) {
+ // In the case where we detect parallel changes, we use the updated
+ // information rather than restoring the old information
+ // (In this case we really should set a timeout on the error message but
+ // that seems like a bit too much work for something that won't happen
+ // often.)
+ if (key == 'parallel-change') {
+ this.updateSessionInfo(detail);
+ } else {
+ this.restoreSessionInfo();
+ }
this.showError(key);
- this.restoreSessionInfo();
},
startUpdateSessionInfo: function() {
@@ -340,20 +348,23 @@ var ManageWallController =
currentStatus.textContent = '終了';
statusBlock.classList.add('finished');
$("manage-closeSession").disabled = true;
+ this.sessionId = session.id;
} else if (session && session.start) {
// Open session
statusBlock.classList.remove('finished');
time.textContent = ParaPara.toLocalDate(session.start) + ' 開始';
currentStatus.textContent = '公開中';
statusBlock.classList.add('running');
$("manage-closeSession").disabled = false;
+ this.sessionId = session.id;
} else {
// No session
statusBlock.classList.remove('finished');
statusBlock.classList.remove('running');
time.textContent = '--';
currentStatus.textContent = '未発';
$("manage-closeSession").disabled = true;
+ this.sessionId = null;
}
document.querySelector(".wallStatus").classList.remove("updating");
},

0 comments on commit 53a7e5f

Please sign in to comment.