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

Commit

Permalink
Merge pull request #15 from datasci4health/dev
Browse files Browse the repository at this point in the history
Able to create multilevels knots editing
  • Loading branch information
marcosfmmota authored Mar 19, 2019
2 parents 2d7082a + fde9a05 commit a9bd09e
Show file tree
Hide file tree
Showing 216 changed files with 4,094 additions and 1,409 deletions.
24 changes: 24 additions & 0 deletions basics/async-javascript/promise.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>

<script>
async function f() {

let promise = new Promise((resolve, reject) => {
setTimeout(() => resolve("done!"), 1000)
});

let result = await promise; // wait till the promise resolves (*)

console.log(result);
alert(result); // "done!"
}</script>

</head>
<body onload="f()">

</body>
</html>
10 changes: 6 additions & 4 deletions notebook/author/author.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<link href="js/quill-1-3-6/quill.snow.css" rel="stylesheet">

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

<script type="text/javascript" src="../dccs/components/dcc-base.js"></script>
<script type="text/javascript" src="../dccs/components/dcc-block.js"></script>
Expand All @@ -31,23 +32,24 @@
<script type="text/javascript" src="js/quill-1-3-6/quill.min.js"></script>

<script type="text/javascript" src="js/dcc-author-server-proxy.js"></script>
<script type="text/javascript" src="js/dcc-author-server-address.js"></script>
<script type="text/javascript" src="js/author.js"></script>
</head>
<body>
<div class="sty-main-panel">
<div class="sty-control-panel std-border">
<div class="control-button"><dcc-trigger action="control/load" label="Load" image="icons/icon-load.svg"></dcc-trigger></div>
<div class="control-button"><dcc-trigger action="control/save" label="Save" image="icons/icon-save.svg"></dcc-trigger></div>
<div class="control-button"><dcc-trigger action="control/case/load" label="Load" image="icons/icon-load.svg"></dcc-trigger></div>
<div class="control-button"><dcc-trigger action="control/case/save" label="Save" image="icons/icon-save.svg"></dcc-trigger></div>
<!--
<div class="control-button"><dcc-trigger action="control/new-knot" label="New Knot" image="icons/icon-new-knot.svg"></dcc-trigger></div>
-->
<div class="control-button"><dcc-trigger action="control/knot/edit" label="Edit Knot" image="icons/icon-edit-knot.svg"></dcc-trigger></div>
<div class="control-button"><dcc-trigger action="control/play" label="Play" image="icons/icon-play.svg"></dcc-trigger></div>
<div class="control-button"><dcc-trigger action="control/case/play" label="Play" image="icons/icon-play.svg"></dcc-trigger></div>
<!--
<div class="control-button"><dcc-trigger action="control/knot-up" label="Knot Up" image="icons/icon-knot-up.svg"></dcc-trigger></div>
<div class="control-button"><dcc-trigger action="control/knot-down" label="Knot Down" image="icons/icon-knot-down.svg"></dcc-trigger></div>
-->
<div class="control-button"><dcc-trigger action="control/config" label="Config" image="icons/icon-config.svg"></dcc-trigger></div>
<div class="control-button"><dcc-trigger action="control/config/edit" label="Config" image="icons/icon-config.svg"></dcc-trigger></div>
<div class="sty-message-space" id="message-space"></div>
</div>
<div class="sty-work-panel">
Expand Down
Binary file removed notebook/author/images/1.png
Binary file not shown.
Binary file removed notebook/author/images/10.png
Binary file not shown.
Binary file removed notebook/author/images/11.png
Binary file not shown.
Binary file removed notebook/author/images/12.png
Binary file not shown.
Binary file removed notebook/author/images/13.png
Binary file not shown.
Binary file removed notebook/author/images/14.png
Binary file not shown.
Binary file removed notebook/author/images/15.png
Binary file not shown.
Binary file removed notebook/author/images/16.png
Binary file not shown.
Binary file removed notebook/author/images/17.png
Binary file not shown.
Binary file removed notebook/author/images/18.png
Binary file not shown.
Binary file removed notebook/author/images/19.png
Binary file not shown.
Binary file removed notebook/author/images/2.png
Binary file not shown.
Binary file removed notebook/author/images/20.png
Binary file not shown.
Binary file removed notebook/author/images/21.png
Binary file not shown.
Binary file removed notebook/author/images/22.png
Binary file not shown.
Binary file removed notebook/author/images/23.png
Binary file not shown.
Binary file removed notebook/author/images/3.png
Binary file not shown.
Binary file removed notebook/author/images/4.png
Binary file not shown.
Binary file removed notebook/author/images/5.png
Binary file not shown.
Binary file removed notebook/author/images/6.png
Binary file not shown.
Binary file removed notebook/author/images/7.png
Binary file not shown.
Binary file removed notebook/author/images/8.png
Binary file not shown.
Binary file removed notebook/author/images/9.png
Binary file not shown.
Binary file added notebook/author/images/ampliacao-eletro.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed notebook/author/images/anger-no.png
Binary file not shown.
Binary file removed notebook/author/images/anger.png
Diff not rendered.
Binary file removed notebook/author/images/bacteria.gif
Diff not rendered.
Binary file added notebook/author/images/case-forklift.png
Binary file added notebook/author/images/ekg-description.png
Binary file added notebook/author/images/ekg-detail-01.png
Binary file added notebook/author/images/ekg-detail-02.png
Binary file added notebook/author/images/ekg-original.png
Binary file removed notebook/author/images/end.jpg
Diff not rendered.
Binary file removed notebook/author/images/fight.gif
Diff not rendered.
Binary file removed notebook/author/images/fingers-ok.png
Diff not rendered.
Binary file removed notebook/author/images/fingers-shaking.png
Diff not rendered.
Binary file added notebook/author/images/hospital-background.png
Binary file removed notebook/author/images/lumbriga.gif
Diff not rendered.
Binary file removed notebook/author/images/members-loss.png
Diff not rendered.
Binary file removed notebook/author/images/members-ok.png
Diff not rendered.
Binary file added notebook/author/images/nurse_agnes.png
Binary file removed notebook/author/images/pain-chest.png
Diff not rendered.
Binary file removed notebook/author/images/pain-no.png
Diff not rendered.
Binary file removed notebook/author/images/paralysis-no.png
Diff not rendered.
Binary file removed notebook/author/images/paralysis.png
Diff not rendered.
Binary file added notebook/author/images/patient-icon.png
178 changes: 178 additions & 0 deletions notebook/author/images/patient-in-bed.svg

Large diffs are not rendered by default.

Binary file added notebook/author/images/patient.png
Binary file added notebook/author/images/patient_jakob.png
Binary file removed notebook/author/images/presentation.png
Diff not rendered.
Binary file added notebook/author/images/supervisor_harry.png
Binary file removed notebook/author/images/tongue-red.png
Diff not rendered.
Binary file removed notebook/author/images/tongue-yellow.png
Diff not rendered.
Binary file removed notebook/author/images/treatment-right.png
Diff not rendered.
Binary file removed notebook/author/images/treatment-wrong.png
Diff not rendered.
Binary file removed notebook/author/images/virus.gif
Diff not rendered.
156 changes: 106 additions & 50 deletions notebook/author/js/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,40 @@ class AuthorManager {

this.controlEvent = this.controlEvent.bind(this);
window.messageBus.ext.subscribe("control/#", this.controlEvent);

this.selectKnot = this.selectKnot.bind(this);
window.messageBus.ext.subscribe("knot/+/selected", this.selectKnot);

this._caseLoadSelected = this._caseLoadSelected.bind(this);
this._templateFamilySelected = this._templateFamilySelected.bind(this);
}

/*
* `control/case/load`
* `control/case/save`
* `control/case/play`
* `control/knot/edit`
* `control/config/edit`
* `knot/<knot>/selected`
*/
controlEvent(topic, message) {
switch (topic) {
case "control/load": this.selectCase();
break;
case "control/save": this.saveCase();
break;
case "control/case/load": this.selectCase();
break;
case "control/case/save": this.saveCase();
break;
case "control/knot/edit": this.editKnot();
break;
case "control/play": this.playCase();
break;
case "control/config": this.config();
break;
case "control/knot/selected": this.knotSelected(message);
break;
break;
case "control/case/play": this.playCase();
break;
case "control/config/edit": this.config();
break;
/*
case "control/knot/selected": this.selectKnot(message);
break;
*/
}
}

Expand All @@ -48,11 +63,13 @@ class AuthorManager {
*/
async selectCase() {
this._resourcePicker = new DCCResourcePicker();
this._resourcePicker.resource = "case";

window.messageBus.ext.subscribe("dcc/resource-picker/selected", this._caseLoadSelected);
window.messageBus.ext.subscribe("control/case/selected", this._caseLoadSelected);

const cases = await this._server.casesList(this._resourcePicker);
this._resourcePicker.addSelectList(cases);
// const cases = await this._server.casesList(this._resourcePicker);
const cases = await window.messageBus.ext.request("case/*/get", "", "case/*");
this._resourcePicker.addSelectList(cases.message);
let knotPanel = document.querySelector("#knot-panel");
knotPanel.appendChild(this._resourcePicker);
}
Expand All @@ -61,28 +78,36 @@ class AuthorManager {
* ACTION: control-load (2)
*/
async _caseLoadSelected(topic, message) {
window.messageBus.ext.unsubscribe("dcc/resource-picker/selected", this._caseLoadSelected);
this._currentCaseName = message;
let caseMd = await this._server.loadCase(this._currentCaseName);
window.messageBus.ext.unsubscribe("control/case/selected", this._caseLoadSelected);
this._currentCaseName = message.selected;
// let caseMd = await this._server.loadCase(this._currentCaseName);
const caseMd = await window.messageBus.ext.request("case/" + this._currentCaseName + "/get", "",
"case/" + this._currentCaseName);
let navigationPanel = document.querySelector("#navigation-panel");
let knotPanel = document.querySelector("#knot-panel");
knotPanel.removeChild(this._resourcePicker);

this._compiledCase = this._translator.compileMarkdown(this._currentCaseName, caseMd);
this._compiledCase = this._translator.compileMarkdown(this._currentCaseName, caseMd.message);
this._knots = this._compiledCase.knots;

for (let kn in this._knots) {
if (this._knots[kn].type == "knot") {
let miniature = document.createElement("div");
miniature.classList.add("navigation-knot");
miniature.classList.add("std-border");
miniature.innerHTML = "<h2><dcc-trigger action='control/knot/selected' xstyle='none' " +
"label = '" + this._knots[kn].title + "'>"
"</dcc-trigger></h2>";
const dot = this._knots[kn].title.lastIndexOf(".");
const title = (dot == -1) ? this._knots[kn].title : this._knots[kn].title.substring(dot);
if (this._knots[kn].render)
miniature.innerHTML = "<h3><dcc-trigger action='knot/" + kn + "/selected' xstyle='none' " +
"label = '" + title + "'>" +
"</dcc-trigger></h3>";
else
miniature.innerHTML = "<h2 style='background-color: lightgray'>" + title + "</h2>";
navigationPanel.appendChild(miniature);
}

}
console.log(this._knots);
}

/*
Expand All @@ -104,9 +129,12 @@ class AuthorManager {
async saveCase() {
if (this._currentCaseName != null && this._compiledCase != null) {
let md =this._translator.assembleMarkdown(this._compiledCase);
const versionFile = await this._server.saveCase(this._currentCaseName, md);
// const versionFile = await this._server.saveCase(this._currentCaseName, md);
const versionFile = await window.messageBus.ext.request("case/" + this._currentCaseName + "/set",
{format: "markdown", source: md},
"case/" + this._currentCaseName + "/version");

console.log("Case saved! Previous version: " + versionFile);
console.log("Case saved! Previous version: " + versionFile.message);
document.querySelector("#message-space").innerHTML = "Saved";
setTimeout(this._clearMessage, 2000);

Expand All @@ -124,7 +152,10 @@ class AuthorManager {
async playCase() {
let message = document.querySelector("#message-space");
message.innerHTML = "Preparing...";
await this._server.prepareCaseHTML(this._currentTemplateFamily, this._currentCaseName);
// await this._server.prepareCaseHTML(this._currentTemplateFamily, this._currentCaseName);
await window.messageBus.ext.request("case/" + this._currentCaseName + "/prepare",
this._currentTemplateFamily,
"case/" + this._currentCaseName + "/prepare/status");

this._templateSet = {};
/*
Expand All @@ -134,31 +165,44 @@ class AuthorManager {
*/

const htmlSet = Object.assign(
{"entry": "",
"signin": "",
"register": "",
"report": ""},
{"entry": {render: true},
"signin": {render: true},
"register": {render: true},
"report": {render: true}},
this._knots);
const total = Object.keys(htmlSet).length;
let processing = 0;
for (let kn in htmlSet) {
processing++;
message.innerHTML = "Processed: " + processing + "/" + total;
let htmlName = kn.replace(/ /igm, "_");
let finalHTML = "";
if (processing > 4)
finalHTML = await this._generateHTMLBuffer(kn);
else
finalHTML = await this._server.loadTemplate(this._currentTemplateFamily, kn);
// finalHTML = this._templateSet.player.replace("{knot}", finalHTML);
finalHTML = AuthorManager.jsonKnot.replace("{knot}", finalHTML);
await this._server.saveKnotHTML(this._currentCaseName,
htmlName + ".js", finalHTML);
message.innerHTML = "Processed: " + processing + "/" + total;
if (htmlSet[kn].render) {
// let htmlName = kn.replace(/ /igm, "_");
let finalHTML = "";
if (processing > 4)
finalHTML = await this._generateHTMLBuffer(kn);
else
finalHTML = await this._loadTemplate(this._currentTemplateFamily, kn);
// finalHTML = this._templateSet.player.replace("{knot}", finalHTML);
finalHTML = AuthorManager.jsonKnot.replace("{knot}", finalHTML);

await window.messageBus.ext.request("knot/" + kn + "/set",
{caseId: this._currentCaseName,
format: "html",
source: finalHTML},
"knot/" + kn + "/set/status");
/*
await this._server.saveKnotHTML(this._currentCaseName,
kn + ".js", finalHTML);
*/
}
}
message.innerHTML = "Finalizing...";

let caseJSON = this._translator.generateCompiledJSON(this._compiledCase);
await this._server.saveCaseScript(this._currentCaseName, "case.js", caseJSON);
// await this._server.saveCaseScript(this._currentCaseName, "case.js", caseJSON);
await window.messageBus.ext.request("case/" + this._currentCaseName + "/set",
{format: "json", source: caseJSON},
"case/" + this._currentCaseName + "/set/status");

message.innerHTML = "";

Expand All @@ -171,30 +215,35 @@ class AuthorManager {
*/
async config() {
this._resourcePicker = new DCCResourcePicker();
this._resourcePicker.resource = "template";

window.messageBus.ext.subscribe("control/template_family/selected", this._templateFamilySelected);

window.messageBus.ext.subscribe("dcc/resource-picker/selected", this._templateFamilySelected);
// const families = await this._server.templateFamiliesList(this._resourcePicker);
const families = await window.messageBus.ext.request("template_family/*/get", "", "template_family/*");

const families = await this._server.templateFamiliesList(this._resourcePicker);
this._resourcePicker.addSelectList(families);
this._resourcePicker.addSelectList(families.message);
document.querySelector("#knot-panel").appendChild(this._resourcePicker);
}

/*
* ACTION: config (2)
*/
async _templateFamilySelected(topic, message) {
window.messageBus.ext.unsubscribe("dcc/resource-picker/selected", this._templateFamilySelected);
this._currentTemplateFamily = message;
window.messageBus.ext.unsubscribe("control/template/selected", this._templateFamilySelected);
this._currentTemplateFamily = message.selected;
document.querySelector("#knot-panel").removeChild(this._resourcePicker);
}

/*
* ACTION: knot-selected
*/
async knotSelected(knotTitle) {
if (this._knots[knotTitle]) {
async selectKnot(topic, message) {
// console.log("selected - topic: " + topic + "; message: " + message);
const knotId = MessageBus.extractLevel(topic, 2);
if (knotId != null) {
this._checkKnotModification();
this._knotSelected = knotTitle;
this._knotSelected = knotId;
this._htmlKnot = await this._generateHTML(this._knotSelected);
this._renderKnot();
}
Expand Down Expand Up @@ -231,13 +280,13 @@ class AuthorManager {
for (let tp in templates)
if (!this._templateSet[templates[tp]]) {
const templ = await
this._server.loadTemplate(this._currentTemplateFamily, templates[tp]);
this._loadTemplate(this._currentTemplateFamily, templates[tp]);
if (templ != "")
this._templateSet[templates[tp]] = templ;
else {
if (!this._templateSet["knot"])
this._templateSet["knot"] = await
this._server.loadTemplate(this._currentTemplateFamily, "knot");
this._loadTemplate(this._currentTemplateFamily, "knot");
this._templateSet[templates[tp]] = this._templateSet["knot"];
}
}
Expand All @@ -248,6 +297,13 @@ class AuthorManager {
return finalHTML;
}

async _loadTemplate(templateFamily, templateName) {
const templateObj = await window.messageBus.ext.request(
"template/" + templateFamily + "." + templateName + "/get", "",
"template/" + templateFamily + "." + templateName);
return templateObj.message;
}

_renderKnot() {
let knotPanel = document.querySelector("#knot-panel");

Expand Down
4 changes: 4 additions & 0 deletions notebook/author/js/dcc-author-server-address.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(function() {
DCCAuthorServer.serverAddress = "http://cloud.lis.ic.unicamp.br/case-notebook/v1/server/";
// DCCAuthorServer.serverAddress = "http://127.0.0.1:8888/";
})();
Loading

0 comments on commit a9bd09e

Please sign in to comment.