Skip to content

Commit

Permalink
Merge pull request #7 from datasci4health/development
Browse files Browse the repository at this point in the history
Everithing working together
  • Loading branch information
santanche authored May 12, 2019
2 parents a38565d + 5f95043 commit 4dd31f6
Show file tree
Hide file tree
Showing 68 changed files with 1,275 additions and 288 deletions.
4 changes: 4 additions & 0 deletions src/adonisjs/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ DB_DATABASE=adonis

SESSION_DRIVER=cookie
HASH_DRIVER=bcrypt
HARENA_SPACE_URL=http://${HOST}:10010
HARENA_SPACE_API_VERSION=v1
HARENA_MANAGER_URL=http://${HOST}:10020
HARENA_MANAGER_API_VERSION=v1
HARENA_LOGGER_URL=http://${HOST}:10030
HARENA_LOGGER_API_VERSION=v1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<script src="../infra/basic.js"></script>
<script src="../infra/bus.js"></script>
<script src="../infra/bus-server-address.js"></script>
<script src="../infra/dcc-common-server-proxy.js"></script>
<script src="../infra/dcc-common-server-address.js"></script>

Expand Down
39 changes: 19 additions & 20 deletions src/adonisjs/public/author/js/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,7 @@ class AuthorManager {
const caseId = await DCCNoticeInput.displayNotice(
"Select a case to load or start a new case.",
"list", "Select", "New", cases.message);
/*
if (this._temporaryCase && saved == "No")
console.log("deleting..." + this._currentCaseId);
*/

console.log("Selected: " + caseId);
if (caseId == "New")
this.caseNew();
else
Expand Down Expand Up @@ -122,11 +117,14 @@ class AuthorManager {
this._temporaryCase = true;
const caseId = await MessageBus.ext.request("data/case//new");

const blankMd =
await MessageBus.ext.request("data/template/basic.blank/get");
await this._themeSelect();
let template = await this._templateSelect();

const templateMd =
await MessageBus.ext.request("data/template/" + template.replace("/", ".") + "/get");

const status = await MessageBus.ext.request("data/case/" + caseId.message + "/set",
{format: "markdown", source: blankMd.message});
{format: "markdown", source: templateMd.message});

this._caseLoad(caseId.message);
}
Expand Down Expand Up @@ -191,10 +189,6 @@ class AuthorManager {
* ACTION: control/knot/new
*/
async knotNew() {
const templates = await MessageBus.ext.request("data/template/*/list");
const template = await DCCNoticeInput.displayNotice(
"Select a template for your knot.",
"list", "Select", "Cancel", templates.message);
const knotId = "Knot_" + this._knotGenerateCounter;
let newKnot = {type: "knot",
title: "Knot " + this._knotGenerateCounter,
Expand All @@ -210,6 +204,14 @@ class AuthorManager {
await this._navigator.mountPlainCase(this, this._compiledCase.knots);
MessageBus.ext.publish("knot/" + this._knotSelected + "/selected");
}

async _templateSelect() {
const templateList = await MessageBus.ext.request("data/template/*/list");
const template = await DCCNoticeInput.displayNotice(
"Select a template for your knot.",
"list", "Select", "Cancel", templateList.message);
return template;
}

/*
* ACTION: control-edit
Expand All @@ -229,14 +231,6 @@ class AuthorManager {
* ACTION: control-play
*/
async casePlay() {
/*
this._messageSpace.innerHTML = "Preparing...";
const dirPlay = await MessageBus.ext.request(
"case/" + this._currentCaseId + "/prepare",
this._translator.currentThemeFamily,
"case/" + this._currentCaseId + "/prepare/directory");
*/

this._translator.newThemeSet();

const htmlSet = Object.assign(
Expand Down Expand Up @@ -287,6 +281,11 @@ class AuthorManager {
* ACTION: config
*/
async config() {
this._themeSelect();
}


async _themeSelect() {
const families = await MessageBus.ext.request("data/theme_family/*/list");
this._translator.currentThemeFamily = await DCCNoticeInput.displayNotice(
"Select a theme to be applied.",
Expand Down
103 changes: 42 additions & 61 deletions src/adonisjs/public/author/js/dcc-author-server-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

class DCCAuthorServer {
constructor() {
this.casesList = this.casesList.bind(this);
MessageBus.ext.subscribe("data/case/*/list", this.casesList);
this.loadModule = this.loadModule.bind(this);
MessageBus.ext.subscribe("data/module/+/get", this.loadModule);
this.loadTemplate = this.loadTemplate.bind(this);
Expand All @@ -21,10 +19,8 @@ class DCCAuthorServer {
this.themeFamiliesList = this.themeFamiliesList.bind(this);
MessageBus.ext.subscribe("data/theme_family/*/list", this.themeFamiliesList);

this.modelsList = this.modelsList.bind(this);
MessageBus.ext.subscribe("data/template/*/get", this.modelsList);
// this.renameCase = this.renameCase.bind(this);
// MessageBus.ext.subscribe("case/+/rename", this.renameCase);
this.templatesList = this.templatesList.bind(this);
MessageBus.ext.subscribe("data/template/*/list", this.templatesList);
this.prepareCaseHTML = this.prepareCaseHTML.bind(this);
MessageBus.ext.subscribe("case/+/prepare", this.prepareCaseHTML);
this.saveKnotHTML = this.saveKnotHTML.bind(this);
Expand All @@ -35,60 +31,48 @@ class DCCAuthorServer {

// wrapper of the services

async themeFamiliesList() {
const response = await fetch(DCCCommonServer.serverAddress + "theme-families-list", {
method: "POST",
headers:{
"Content-Type": "application/json"
}
});
const jsonResponse = await response.json();
const families = jsonResponse.themeFamiliesList;
let finalFamiliesList = {};
for (var f in families)
finalFamiliesList[families[f]] = "icons/mono-slide.svg";
MessageBus.ext.publish("theme_family/*", finalFamiliesList);
}

async modelsList() {
const response = await fetch(DCCCommonServer.serverAddress + "models-list", {
method: "POST",
headers:{
"Content-Type": "application/json"
}
});
const jsonResponse = await response.json();
const models = jsonResponse.modelsList;
let finalModelsList = {};
for (var f in models)
finalModelsList[models[f]] = "icons/mono-slide.svg";
MessageBus.ext.publish("model/*", finalModelsList);
async themeFamiliesList(topic, message) {
var header = {
"async": true,
"crossDomain": true,
"method": "GET",
"headers": {
"Content-Type": "application/json",
}
}
const response = await fetch("../themes/themes.json", header);
let jsonResponse = await response.json();
let busResponse = {};
for (var t in jsonResponse)
busResponse[jsonResponse[t].path] = {
name: t,
icon: "../themes/" + jsonResponse[t].path + "/images/" + jsonResponse[t].icon
};
MessageBus.ext.publish(MessageBus.buildResponseTopic(topic, message),
busResponse);
}

async casesList(topic, message) {
async templatesList(topic, message) {
var header = {
"async": true,
"crossDomain": true,
"method": "POST",
"method": "GET",
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer " + DCCCommonServer.instance.token
},
"body": JSON.stringify({"filterBy": "user",
"filter": message.filter})
}
}
const response = await fetch(DCCCommonServer.serverAddress + "case/list", header);
const jsonResponse = await response.json();
const response = await fetch("../templates/templates.json", header);
let jsonResponse = await response.json();
let busResponse = {};
for (var c in jsonResponse)
busResponse[jsonResponse[c].id] = {
name: jsonResponse[c].name,
icon: "icons/mono-slide.svg"
for (var t in jsonResponse)
busResponse[jsonResponse[t].path] = {
name: t,
icon: "../templates/" + jsonResponse[t].path + ".png"
};
MessageBus.ext.publish(MessageBus.buildResponseTopic(topic, message),
busResponse);
}

async newCase(topic, message) {
var header = {
"async": true,
Expand All @@ -100,13 +84,13 @@ class DCCAuthorServer {
}
};
const response =
await fetch(DCCCommonServer.serverAddress + "case/new", header);
await fetch(DCCCommonServer.managerAddressAPI + "case/new", header);
const jsonResponse = await response.json();
MessageBus.ext.publish(MessageBus.buildResponseTopic(topic, message),
jsonResponse.id);
jsonResponse.uuid);

/*
const response = await fetch(DCCCommonServer.serverAddress + "new-case", {
const response = await fetch(DCCCommonServer.managerAddressAPI + "new-case", {
method: "POST",
headers:{
"Content-Type": "application/json"
Expand All @@ -132,13 +116,13 @@ class DCCAuthorServer {
source: message.source})
};
const response =
await fetch(DCCCommonServer.serverAddress + "case/" + caseId, header);
await fetch(DCCCommonServer.managerAddressAPI + "case/" + caseId, header);
const jsonResponse = await response.json();
MessageBus.ext.publish(MessageBus.buildResponseTopic(topic, message),
jsonResponse.source);

/*
const response = await fetch(DCCCommonServer.serverAddress + "save-case", {
const response = await fetch(DCCCommonServer.managerAddressAPI + "save-case", {
method: "POST",
body: JSON.stringify({"caseName": caseName,
"caseText": message.source}),
Expand All @@ -155,7 +139,7 @@ class DCCAuthorServer {
/*
async renameCase(topic, message) {
const oldName = MessageBus.extractLevel(topic, 2);
const response = await fetch(DCCCommonServer.serverAddress + "rename-case", {
const response = await fetch(DCCCommonServer.managerAddressAPI + "rename-case", {
method: "POST",
body: JSON.stringify({"oldName": oldName,
"newName": message.newName}),
Expand Down Expand Up @@ -185,10 +169,7 @@ class DCCAuthorServer {
}

async loadTemplate(topic, message) {
const templateCompleteName = MessageBus.extractLevel(topic, 3);
const separator = templateCompleteName.indexOf(".");
const templateFamily = templateCompleteName.substring(0, separator);
const templateName = templateCompleteName.substring(separator+1);
let templatePath = MessageBus.extractLevel(topic, 3).replace(".", "/");
var header = {
"async": true,
"crossDomain": true,
Expand All @@ -197,7 +178,7 @@ class DCCAuthorServer {
"Content-Type": "text/plain",
}
}
const response = await fetch("../templates/" + templateFamily + "/" + templateName +
const response = await fetch("../templates/" + templatePath +
".md", header);
let textResponse = await response.text();
MessageBus.ext.publish(MessageBus.buildResponseTopic(topic, message),
Expand All @@ -206,7 +187,7 @@ class DCCAuthorServer {

async prepareCaseHTML(topic, themeFamily) {
const caseName = MessageBus.extractLevel(topic, 2);
const response = await fetch(DCCCommonServer.serverAddress + "prepare-case-html", {
const response = await fetch(DCCCommonServer.managerAddressAPI + "prepare-case-html", {
method: "POST",
body: JSON.stringify({"themeFamily": themeFamily,
"caseName": caseName}),
Expand All @@ -221,7 +202,7 @@ class DCCAuthorServer {
async saveKnotHTML(topic, message) {
const knotId = MessageBus.extractLevel(topic, 2);

const response = await fetch(DCCCommonServer.serverAddress + "save-knot-html", {
const response = await fetch(DCCCommonServer.managerAddressAPI + "save-knot-html", {
method: "POST",
body: JSON.stringify({"caseName": message.caseId,
"knotFile": knotId + ".js",
Expand All @@ -239,7 +220,7 @@ class DCCAuthorServer {
const caseId = MessageBus.extractLevel(topic, 2);

// <TODO> change the name of the service
const response = await fetch(DCCCommonServer.serverAddress + "save-case-script", {
const response = await fetch(DCCCommonServer.managerAddressAPI + "save-case-script", {
method: "POST",
body: JSON.stringify({"caseName": caseId,
"scriptFile": "case.js",
Expand Down
4 changes: 2 additions & 2 deletions src/adonisjs/public/infra/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ class Basic {
let userid = null;
let errorMessage = "";
while (userid == null) {
/*
const userEmail =
await DCCNoticeInput.displayNotice(errorMessage +
"<h3>Signin</h3><h4>inform your email:</h4>",
"input");
const userPass =
await DCCNoticeInput.displayNotice("<h3>Signin</h3><h4>inform your password:</h4>",
"password");
*/

/*
let userEmail = "jacinto@example.com";
let userPass = "jacinto";
*/

let loginReturn = await MessageBus.ext.request("data/user/login",
{email: userEmail,
Expand Down
4 changes: 0 additions & 4 deletions src/adonisjs/public/infra/bus-server-address.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/adonisjs/public/infra/bus.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MessageBus {
extTopic = this._runningCase.runningId + "/" + topic;
}

const response = await fetch(MessageBus.serverAddress + "/message", {
const response = await fetch(DCCCommonServer.loggerAddressAPI + "message", {
method: "POST",
body: JSON.stringify({"topic": extTopic,
"payload": extMessage
Expand Down Expand Up @@ -174,7 +174,7 @@ class MessageBus {
MessageBus._stamp = 1;

MessageBus.int = new MessageBus(false);
MessageBus.ext = new MessageBus(false);
MessageBus.ext = new MessageBus(true);
/*
window.messageBus = {
int: new MessageBus(false),
Expand Down
Loading

0 comments on commit 4dd31f6

Please sign in to comment.