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

Commit

Permalink
#3 experimental functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
steffchep committed Feb 16, 2018
1 parent 18d9022 commit 89ec0a6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ <h2 class="dark">
</td>
<td>
<div>
<input type="number" :disabled="!talk.availableSeats" width="4" :value="talk.occupiedSeats"><span>/{{talk.availableSeats}} </span> <button :disabled="!talk.availableSeats" class="setOccupied" @click="">Set</button>
<input type="number" :data-id="index" :disabled="!talk.availableSeats" width="4" :value="talk.occupiedSeats"><span>/{{talk.availableSeats}} </span> <button :data-id="index" :disabled="!talk.availableSeats" class="setOccupied" @click="update">Set</button>
</div>
<div>
<input type="checkbox" :id="index" :disabled="!talk.availableSeats" v-model="talk.fullyBooked" @click="updateEmptyOrFull"><label v-bind:for="index"></label>
<input type="checkbox" :id="index" :data-id="index" :disabled="!talk.availableSeats" v-model="talk.fullyBooked" @click="toggleFull"><label v-bind:for="index"></label>
</div>
</td>
</tr>
Expand Down
66 changes: 45 additions & 21 deletions src/main/webapp/js/store/talks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,28 @@ define(['store', 'computed', 'request', 'popups', 'dataHelper', 'scrollHelper'],
}, onError);
}

function confirmAndUpdateOccupiedSeats(event) {
var id = event.currentTarget.id;
var theTalk = computed.talks()[id];
if (!store.loggedIn) {
popups.alert("Please Log In", "You must be logged in to do this.");
return;
function confirmAndUpdate(theTalk, newValueForSeats) {
function isFullyBooked(occupied, available) {
var threshold = 0.95;
if (occupied === 0 || available === 0) {
return false;
}
console.log (occupied + "/" + available + "=" + (occupied / available));
return occupied / available >= threshold;
}
}

function confirmAndSetEmptyOrFull(event) {
var id = event.currentTarget.id;
var theTalk = computed.talks()[id];
if (!store.loggedIn) {
popups.alert("Please Log In", "You must be logged in to do this.");
setTimeout(function() {
theTalk.fullyBooked = !theTalk.fullyBooked;
}, 50);
return;
}

var status = theTalk.fullyBooked ? "Fully booked" : "Free";
var message = "<span>Room: </span><em class=\"dark\">"
+ theTalk.roomName
+ "</em>\n<span>Time: </span><em class=\"dark\">" + theTalk.formattedStart
+ "</em>\n\n<span>Occupied seats: </span><em>"+ theTalk.occupiedSeats
+ "</em>\n\n<span>New Status: </span><em class=\"" + status.replace(" ", "") + "\">"
+ status
+ "</em>\n\nContinue?";

var previousSeats = theTalk.occupiedSeats;
theTalk.occupiedSeats = newValueForSeats;
theTalk.fullyBooked = isFullyBooked(newValueForSeats, theTalk.availableSeats);

popups.confirm(
"Confirm Status Change",
message,
Expand All @@ -57,7 +51,8 @@ define(['store', 'computed', 'request', 'popups', 'dataHelper', 'scrollHelper'],
store.loading = false;
},
function(err) {
theTalk.fullyBooked = !theTalk.fullyBooked;
theTalk.fullyBooked = isFullyBooked(previousSeats, theTalk.availableSeats);
theTalk.availableSeats = previousSeats;
onError(err);
},
store.token
Expand All @@ -70,6 +65,34 @@ define(['store', 'computed', 'request', 'popups', 'dataHelper', 'scrollHelper'],
}
);
}

function confirmAndUpdateOccupiedSeats(event) {
var id = event.currentTarget.getAttribute("data-id");
var theTalk = computed.talks()[id];
var newValue = document.querySelector("input[data-id='" + id +"']").value;
if (!store.loggedIn) {
popups.alert("Please Log In", "You must be logged in to do this.");
document.querySelector("input[data-id='" + id +"']").value = theTalk.availableSeats;
return;
}

confirmAndUpdate(theTalk, newValue)
}

function confirmAndToggleFull(event) {
var id = event.currentTarget.getAttribute("data-id");
console.log("id=" + id);
var theTalk = computed.talks()[id];
if (!store.loggedIn) {
popups.alert("Please Log In", "You must be logged in to do this.");
setTimeout(function() {
theTalk.fullyBooked = !theTalk.fullyBooked;
}, 50);
return;
}

confirmAndUpdate(theTalk, (theTalk.fullyBooked ? theTalk.availableSeats : 0));
}

function loadTalks() {
store.loading = true;
Expand Down Expand Up @@ -100,7 +123,8 @@ define(['store', 'computed', 'request', 'popups', 'dataHelper', 'scrollHelper'],

return {
emptyOnEsc: emptyOnEsc,
updateEmptyOrFull: confirmAndSetEmptyOrFull,
update: confirmAndUpdateOccupiedSeats,
toggleFull: confirmAndToggleFull,
sendWithBearer: sendWithBearer,
refresh: loadTalks
}
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/js/utils/dataHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ define(['moment'], function(moment) {
if (event) {
event.fullyBooked = delta[i].fullyBooked;
event.numberOfFavorites = delta[i].numberOfFavorites;
event.occupiedSeats = delta[i].numberOccupied;
}
}
return events;
Expand Down
10 changes: 7 additions & 3 deletions src/main/webapp/js/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ define(['dataHelper'], function (helper) {
return (urls.conferenceUrl !== null && urls.bookingsUrl !== null && urls.adminUrl !== null && urls.keyCloakUrl !== null) || urls.errorState;
}

function httpRequest(url, method, onSuccess, onError, headers) {
function httpRequest(url, method, onSuccess, onError, headers, data) {
if (urls.errorState) {
if (onError) {
onError({status: 0, statusMessage: "error during initializiation"});
Expand Down Expand Up @@ -41,7 +41,7 @@ define(['dataHelper'], function (helper) {
}
}
};
xhttp.send();
xhttp.send(data);
}

function initialize(callback) {
Expand Down Expand Up @@ -143,7 +143,11 @@ define(['dataHelper'], function (helper) {
if (keycloakToken) {
headers.Authorization = "Bearer " + keycloakToken;
}
httpRequest(urls.adminUrl + "/" + talk.id, talk.fullyBooked ? "POST" : "DELETE", onSuccess, onError, headers);
var data = {
fullyBooked: talk.fullyBooked,
numberOccupied: talk.numberOccupied
};
httpRequest(urls.adminUrl + "/capacity/" + talk.id, "POST", onSuccess, onError, headers, data);
}

return {
Expand Down

0 comments on commit 89ec0a6

Please sign in to comment.