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

Commit

Permalink
Topic reorganization and REST externalization.
Browse files Browse the repository at this point in the history
  • Loading branch information
santanche authored and santanche committed Mar 18, 2019
1 parent b7f8b9a commit d891f05
Show file tree
Hide file tree
Showing 29 changed files with 419 additions and 63 deletions.
1 change: 1 addition & 0 deletions notebook/cases/case001-development/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<link rel="stylesheet" type="text/css" href="css/templates-classic.css">

<script type="text/javascript" src="js/bus.js"></script>
<script type="text/javascript" src="js/bus-server-address.js"></script>
<script type="text/javascript" src="js/tracker.js"></script>
<script type="text/javascript" src="js/state.js"></script>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(function() {
MessageBus.serverAddress = "http://cloud.lis.ic.unicamp.br/harena/logger/latest";
})();
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class DCCPlayerServer {
const profile = this.getCurrentProfile();

const currentDateTime = new Date();
const casekey = profile.id + "#" + caseid + "#" + this.generateUID();
const caseuid = this.generateUID();
const casekey = profile.id + "#" + caseid + "#" + caseuid;
profile.cases.push(casekey);
this.setProfile(profile);
this.setRunningCasekey(casekey);
Expand All @@ -39,6 +40,8 @@ class DCCPlayerServer {
route : []
};
this.setCaseInstance(casekey, casetrack);

return {runningId: caseuid, track: casetrack};
}

generateUID() {
Expand Down
18 changes: 10 additions & 8 deletions notebook/cases/case001-development/html/js/dccs/dcc-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ class DCCBlock extends DCCBase {
}

connectedCallback() {
if (!this.hasAttribute("xstyle") && window.messageBus.ext.hasSubscriber("dcc/request/xstyle")) {
window.messageBus.ext.subscribe("dcc/xstyle/" + this.id, this.defineXstyle);
window.messageBus.ext.publish("dcc/request/xstyle", this.id);
if (!this.hasAttribute("xstyle") && window.messageBus.int.hasSubscriber("dcc/request/xstyle")) {
window.messageBus.int.subscribe("dcc/xstyle/" + this.id, this.defineXstyle);
window.messageBus.int.publish("dcc/request/xstyle", this.id);
this._pendingRequests++;
}
if (!this.hasAttribute("location") &&
window.messageBus.ext.hasSubscriber("dcc/request/location")) {
window.messageBus.ext.subscribe("dcc/location/" + this.id, this.defineLocation);
window.messageBus.ext.publish("dcc/request/location", this.id);
window.messageBus.int.hasSubscriber("dcc/request/location")) {
window.messageBus.int.subscribe("dcc/location/" + this.id, this.defineLocation);
window.messageBus.int.publish("dcc/request/location", this.id);
this._pendingRequests++;
}
this._checkRender();
}

defineXstyle(topic, message) {
window.messageBus.ext.unsubscribe("dcc/xstyle/" + this.id, this.defineXstyle);
window.messageBus.int.unsubscribe("dcc/xstyle/" + this.id, this.defineXstyle);
this.xstyle = message;
this._pendingRequests--;
this._checkRender();
}

defineLocation(topic, message) {
window.messageBus.ext.unsubscribe("dcc/location/" + this.id, this.defineLocation);
window.messageBus.int.unsubscribe("dcc/location/" + this.id, this.defineLocation);
this.location = message;
this._pendingRequests--;
this._checkRender();
Expand Down Expand Up @@ -151,13 +151,15 @@ class DCCBlock extends DCCBase {
return presentation;
}

/*
_computeTrigger() {
if (this.hasAttribute("label") || this.hasAttribute("action")) {
let eventLabel = (this.hasAttribute("action")) ? this.action : "navigate/trigger";
let message = (this.hasAttribute("link")) ? this.link : this.label;
window.messageBus.ext.publish(eventLabel, message);
}
}
*/
}

(function() {
Expand Down
22 changes: 11 additions & 11 deletions notebook/cases/case001-development/html/js/dccs/dcc-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@ class DCCTalk extends DCCBase {
}

connectedCallback() {
if (window.messageBus.ext.hasSubscriber("dcc/request/talk-sequence")) {
window.messageBus.ext.subscribe("dcc/talk-sequence/" + this.id, this.defineSequence);
window.messageBus.ext.publish("dcc/request/talk-sequence", this.id);
if (window.messageBus.int.hasSubscriber("dcc/request/talk-sequence")) {
window.messageBus.int.subscribe("dcc/talk-sequence/" + this.id, this.defineSequence);
window.messageBus.int.publish("dcc/request/talk-sequence", this.id);
this._pendingRequests++;
}
if (!this.hasAttribute("xstyle") && window.messageBus.ext.hasSubscriber("dcc/request/xstyle")) {
window.messageBus.ext.subscribe("dcc/xstyle/" + this.id, this.defineXstyle);
window.messageBus.ext.publish("dcc/request/xstyle", this.id);
if (!this.hasAttribute("xstyle") && window.messageBus.int.hasSubscriber("dcc/request/xstyle")) {
window.messageBus.int.subscribe("dcc/xstyle/" + this.id, this.defineXstyle);
window.messageBus.int.publish("dcc/request/xstyle", this.id);
this._pendingRequests++;
}
this._checkRender();
}

defineSequence(topic, message) {
window.messageBus.ext.unsubscribe("dcc/talk-sequence/" + this.id, this.defineSequence);
window.messageBus.int.unsubscribe("dcc/talk-sequence/" + this.id, this.defineSequence);
this.sequence = message;
this._pendingRequests--;
this._checkRender();
}

defineXstyle(topic, message) {
window.messageBus.ext.unsubscribe("dcc/xstyle/" + this.id, this.defineXstyle);
window.messageBus.int.unsubscribe("dcc/xstyle/" + this.id, this.defineXstyle);
this.xstyle = message;
this._pendingRequests--;
this._checkRender();
Expand Down Expand Up @@ -147,16 +147,16 @@ class DCCDialog extends DCCBase {
}

connectedCallback() {
window.messageBus.ext.subscribe("dcc/request/talk-sequence", this.requestSequence);
window.messageBus.int.subscribe("dcc/request/talk-sequence", this.requestSequence);
}

disconnectedCallback() {
window.messageBus.ext.unsubscribe("dcc/request/talk-sequence", this.requestSequence);
window.messageBus.int.unsubscribe("dcc/request/talk-sequence", this.requestSequence);
}

requestSequence(topic, message) {
this._sequence++;
window.messageBus.ext.publish("dcc/talk-sequence/" + message, this._sequence);
window.messageBus.int.publish("dcc/talk-sequence/" + message, this._sequence);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@ class DCCStateSelector extends DCCBase {
this._renderInterface();
}

connectedCallback() {
async connectedCallback() {
this._presentation.addEventListener("mouseover", this._showState);
this._presentation.addEventListener("mouseout", this._hideState);
this._presentation.addEventListener("click", this._changeState);

// <TODO> limited: considers only one group per page
this.completeId = this.id;
if (!this.hasAttribute("states") && window.messageBus.int.hasSubscriber("dcc/request/selector-states")) {
this.context = await window.messageBus.int.request("dcc/selector-context/request", this.id, "dcc/selector-context/" + this.id);
this.completeId = this.context.message + "." + this.id;

window.messageBus.int.subscribe("dcc/selector-states/" + this.id, this.defineStates);
window.messageBus.int.publish("dcc/request/selector-states", this.id);
this._pendingRequests++;
}

this._checkRender();

window.messageBus.ext.publish("var/" + this.id + "/subinput/ready",
window.messageBus.ext.publish("var/" + this.completeId + "/subinput/ready",
{sourceType: DCCStateSelector.elementTag,
content: this.innerHTML});
}
Expand Down Expand Up @@ -144,7 +148,7 @@ class DCCStateSelector extends DCCBase {
if (this.states != null) {
const statesArr = this.states.split(",");
this._currentState = (this._currentState + 1) % statesArr.length;
window.messageBus.ext.publish("var/" + this.id + "/state_changed",
window.messageBus.ext.publish("var/" + this.completeId + "/state_changed",
{sourceType: DCCInput.elementTag,
state: statesArr[this._currentState]});
}
Expand All @@ -158,24 +162,32 @@ class DCCStateSelector extends DCCBase {
class DCCGroupSelector extends DCCBase {
constructor() {
super();
this.requestContext = this.requestContext.bind(this);
this.requestStates = this.requestStates.bind(this);
}

connectedCallback() {
window.messageBus.int.subscribe("dcc/selector-context/request", this.requestContext);
window.messageBus.int.subscribe("dcc/request/selector-states", this.requestStates);

window.messageBus.ext.publish("var/" + this.context + "/group_input/ready",
DCCGroupSelector.elementTag);
}

disconnectedCallback() {
window.messageBus.int.unsubscribe("dcc/selector-context/request", this.requestContext);
window.messageBus.int.unsubscribe("dcc/request/selector-states", this.requestStates);
}


requestStates(topic, message) {
window.messageBus.int.publish("dcc/selector-states/" + message, this.states);
}

requestContext(topic, message) {
window.messageBus.int.publish("dcc/selector-context/" + message, this.context);
}

/*
* Property handling
*/
Expand Down
12 changes: 6 additions & 6 deletions notebook/cases/case001-development/html/js/dccs/dcc-styler.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ class DCCStyler extends DCCBase {

connectedCallback() {
if (this.hasAttribute("xstyle")) {
window.messageBus.ext.subscribe("dcc/request/xstyle", this.requestXstyle);
window.messageBus.int.subscribe("dcc/request/xstyle", this.requestXstyle);
}

if (this.hasAttribute("locations")) {
this._locationSet = this.locations.split(";");
window.messageBus.ext.subscribe("dcc/request/location", this.requestLocation);
window.messageBus.int.subscribe("dcc/request/location", this.requestLocation);
}
}

disconnectedCallback() {
window.messageBus.ext.unsubscribe("dcc/request/xstyle", this.requestXstyle);
window.messageBus.ext.unsubscribe("dcc/request/location", this.requestLocation);
window.messageBus.int.unsubscribe("dcc/request/xstyle", this.requestXstyle);
window.messageBus.int.unsubscribe("dcc/request/location", this.requestLocation);
}

/*
Expand Down Expand Up @@ -50,11 +50,11 @@ class DCCStyler extends DCCBase {
}

requestXstyle(topic, message) {
window.messageBus.ext.publish("dcc/xstyle/" + message, this.xstyle);
window.messageBus.int.publish("dcc/xstyle/" + message, this.xstyle);
}

requestLocation(topic, message) {
window.messageBus.ext.publish("dcc/location/" + message,
window.messageBus.int.publish("dcc/location/" + message,
(this._locationSet.length > 0) ? this._locationSet.shift() : "");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ class DCCTrigger extends DCCBlock {

_computeTrigger() {
if (this.hasAttribute("label") || this.hasAttribute("action")) {
let eventLabel = (this.hasAttribute("action")) ? this.action : "navigate/trigger";
let message = (this.hasAttribute("link")) ? this.link : this.label;
window.messageBus.ext.publish(eventLabel, message);
const message = (this.hasAttribute("link")) ? this.link : this.label;
const topic = (this.hasAttribute("action")) ? this.action : "knot/" + message + "/navigate";
window.messageBus.ext.publish(topic, message);
}
}
}
Expand Down
36 changes: 24 additions & 12 deletions notebook/cases/case001-development/html/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class PlayerManager {
this.controlEvent = this.controlEvent.bind(this);
window.messageBus.ext.subscribe("control/#", this.controlEvent);
this.navigateEvent = this.navigateEvent.bind(this);
window.messageBus.ext.subscribe("navigate/#", this.navigateEvent);
window.messageBus.ext.subscribe("knot/+/navigate", this.navigateEvent);

// <TODO> temporary
this.produceReport = this.produceReport.bind(this);
Expand Down Expand Up @@ -46,22 +46,27 @@ class PlayerManager {
navigateEvent(topic, message) {
this.trackTrigger(message);
// window.messageBus.ext.publish("checkout", message);
if (this._currentKnot != null) {
window.messageBus.ext.publish("control/input/submit"); // <TODO> provisory
window.messageBus.ext.publish("knot/" + this._currentKnot + "/end");
}
switch (topic) {
case "navigate/knot/previous": if (this._history.length > 0) {
case "knot/</navigate": if (this._history.length > 0) {
this._history.pop();
const last = this._history[this._history.length - 1];
this.loadKnot(last);
}
break;
case "navigate/knot/start": this.startCase();
const startKnot = this._server.getStartKnot();
this._history.push(startKnot);
this.loadKnot(startKnot);
break;
case "navigate/trigger": window.messageBus.ext.publish("control/input/submit"); // <TODO> provisory
this._history.push(message);
this.loadKnot(message);
break;
case "knot/<</navigate": this.startCase();
const startKnot = this._server.getStartKnot();
this._history.push(startKnot);
this.loadKnot(startKnot);
break;
default: if (MessageBus.matchFilter(topic, "knot/+/navigate")) {
this._history.push(message);
this.loadKnot(message);
}
break;
}
/*
switch (topic) {
Expand Down Expand Up @@ -93,6 +98,7 @@ class PlayerManager {
this._knotScript = document.createElement("script");
this._knotScript.src = "knots/" + knotName + ".js";
document.head.appendChild(this._knotScript);
window.messageBus.ext.publish("knot/" + knotName + "/start");
}

presentKnot(knot) {
Expand Down Expand Up @@ -176,7 +182,13 @@ class PlayerManager {
* Start the tracking record of a case
*/
startCase() {
this._server.generateRunningCase();
// <TODO> this._runningCase is provisory
const runningCase = this._server.generateRunningCase();

console.log("************* Running case");
console.log(runningCase);

window.messageBus.ext.defineRunningCase(runningCase);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
id="Path_320" />
</g>
<foreignObject>
<dcc-trigger action="navigate/knot/previous" label="Previous Knot" xstyle="out-image" location="back-arrow"></dcc-trigger>
<dcc-trigger action="knot/</navigate" label="Previous Knot" xstyle="out-image" location="back-arrow"></dcc-trigger>
</foreignObject>
<g
style="fill:none;stroke:#ffffff"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
id="Path_320" />
</g>
<foreignObject>
<dcc-trigger action="navigate/knot/previous" label="Previous Knot" xstyle="out-image" location="back-arrow"></dcc-trigger>
<dcc-trigger action="knot/</navigate" label="Previous Knot" xstyle="out-image" location="back-arrow"></dcc-trigger>
</foreignObject>
<text
style="font-size:20px;font-family:Tahoma, Geneva, sans-serif;fill:#ffffff"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
id="Path_320" />
</g>
<foreignObject>
<dcc-trigger action="navigate/knot/previous" label="Previous Knot" xstyle="out-image" location="back-arrow"></dcc-trigger>
<dcc-trigger action="knot/</navigate" label="Previous Knot" xstyle="out-image" location="back-arrow"></dcc-trigger>
</foreignObject>
<text
style="font-size:20px;font-family:Tahoma, Geneva, sans-serif;fill:#ffffff"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
id="Path_320" />
</g>
<foreignObject>
<dcc-trigger action="navigate/knot/previous" label="Previous Knot" xstyle="out-image" location="back-arrow"></dcc-trigger>
<dcc-trigger action="knot/</navigate" label="Previous Knot" xstyle="out-image" location="back-arrow"></dcc-trigger>
</foreignObject>
<text
style="font-size:20px;font-family:Tahoma, Geneva, sans-serif;fill:#ffffff"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
id="Path_320" />
</g>
<foreignObject>
<dcc-trigger action="navigate/knot/previous" label="Previous Knot" xstyle="out-image" location="back-arrow"></dcc-trigger>
<dcc-trigger action="knot/</navigate" label="Previous Knot" xstyle="out-image" location="back-arrow"></dcc-trigger>
</foreignObject>
<text
style="font-size:20px;font-family:Tahoma, Geneva, sans-serif;fill:#ffffff"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
id="Path_320" />
</g>
<foreignObject>
<dcc-trigger action="navigate/knot/previous" label="Previous Knot" xstyle="out-image" location="back-arrow"></dcc-trigger>
<dcc-trigger action="knot/</navigate" label="Previous Knot" xstyle="out-image" location="back-arrow"></dcc-trigger>
</foreignObject>
<text
style="font-size:20px;font-family:Tahoma, Geneva, sans-serif;fill:#ffffff"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
id="Path_320" />
</g>
<foreignObject>
<dcc-trigger action="navigate/knot/previous" label="Previous Knot" xstyle="out-image" location="back-arrow"></dcc-trigger>
<dcc-trigger action="knot/</navigate" label="Previous Knot" xstyle="out-image" location="back-arrow"></dcc-trigger>
</foreignObject>
<g
style="fill:#ffffff;stroke:#707070"
Expand Down
Loading

0 comments on commit d891f05

Please sign in to comment.