Skip to content

Commit

Permalink
Merge pull request #244 from datasci4health/development
Browse files Browse the repository at this point in the history
refactor (text editor): text editor
  • Loading branch information
HeitorMatt authored Sep 17, 2020
2 parents 86e2cf0 + 4a4a9a5 commit 974370a
Show file tree
Hide file tree
Showing 24 changed files with 359 additions and 231 deletions.
12 changes: 10 additions & 2 deletions src/adonisjs/app/Controllers/Http/CaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class CaseController {
specialty: params.specialty,
keywords: params.keywords,
source: markdown,
original_date: params.creationDate
original_date: params.creationDate,
complexity: params.complexity,
institution: params.institution
},
headers: {
Authorization: 'Bearer ' + token
Expand Down Expand Up @@ -130,6 +132,7 @@ class CaseController {

async update ({ request, session, response }) {
try {
console.log('update ---------------------------- ')
const params = request.all()
// console.log('UPDATE STARTING........')
const endpointUrl =
Expand All @@ -147,6 +150,8 @@ class CaseController {
specialty: params.specialty,
keywords: params.keywords,
originalDate: params.originalDate,
complexity: params.complexity,
institution: params.institution,
source: params.source
},
headers: {
Expand Down Expand Up @@ -193,10 +198,12 @@ class CaseController {
const caseSpecialty = responseContent.specialty
const caseKeywords = responseContent.keywords
const caseOriginalDate = responseContent.original_date
const caseComplexity = responseContent.complexity

const caseSource = responseContent.source.replace(/"/gm, '\\"')

return view.render('author.author',
{ caseId, caseTitle, caseDescription, caseLanguage, caseInstitution, caseDomain, caseSpecialty, caseKeywords, caseOriginalDate, caseSource })
{ caseId, caseTitle, caseDescription, caseLanguage, caseInstitution, caseDomain, caseSpecialty, caseKeywords, caseOriginalDate, caseSource, caseComplexity })
})
.catch(function (error) {
console.log(error)
Expand All @@ -223,6 +230,7 @@ class CaseController {

await axios(config)
.then(function (endpointResponse) {
console.log('here')
console.log(endpointResponse.data)
// return view.render('author.author')

Expand Down
190 changes: 101 additions & 89 deletions src/adonisjs/app/Controllers/Http/QuestController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,95 +5,107 @@ const axios = use('axios')
const view = use('View')

class QuestController {
async getCasesByQuestAuthor({ request, response }) {
try{
const params = request.all()
console.log('------------------------COR DA QUEST');
console.log(params.color);
var responseData = [];
let endpoint_url = Env.get("HARENA_MANAGER_URL") + "/api/v1/author/quest/cases"

var config = {
method: 'get',
url: endpoint_url,
data: {
questId: params.id
},
headers: {
'Authorization': 'Bearer ' + request.cookie('token')
}
};


await axios(config)
.then(function (endpoint_response) {
console.log('============ Retrieving cases for selected quests');
console.log(endpoint_response.data);
const busResponse = []
for (const c in endpoint_response.data) {
busResponse.push({
id: endpoint_response.data[c].id,
title: endpoint_response.data[c].title,

})

}
responseData[0] = busResponse;
})

.catch(function (error) {
console.log(error);
});
} catch(e){
console.log(e)
}

return view.render('author.drafts-cases', { cases: responseData[0]});

}

async getQuestsAuthor({ request, response }) {
try{
var responseData = [];
let endpoint_url = Env.get("HARENA_MANAGER_URL") + "/api/v1/author/quests"

var config = {
method: 'get',
url: endpoint_url,
headers: {
'Authorization': 'Bearer ' + request.cookie('token')
}
};


await axios(config)
.then(function (endpoint_response) {
console.log('============ Retrieving quests');
console.log(endpoint_response.data);
const busResponse = []
for (const c in endpoint_response.data) {
busResponse.push({
id: endpoint_response.data[c].id,
title: endpoint_response.data[c].title,
color: endpoint_response.data[c].color,
url: endpoint_response.data[c].url,

})

}
responseData[0] = busResponse;
})

.catch(function (error) {
console.log(error);
});
} catch(e){
console.log(e)
}

return view.render('author.drafts-quest', { quests: responseData[0]});

}
async getCasesByQuestAuthor ({ request, response }) {
try {
const params = request.all()

// console.log('------------------------COR DA QUEST')
// console.log(params.color)
var responseData = []
const endpoint_url = Env.get('HARENA_MANAGER_URL') + '/api/v1/author/quest/cases'

var config = {
method: 'get',
url: endpoint_url,
data: {
questId: params.id
},
headers: {
'Authorization': 'Bearer ' + request.cookie('token')
}
}

await axios(config)
.then(function (endpoint_response) {
console.log('============ Retrieving cases for selected quests')
console.log(endpoint_response.data)
const busResponse = []
for (const c in endpoint_response.data) {
busResponse.push({
id: endpoint_response.data[c].id,
title: endpoint_response.data[c].title

})
}

function sortAlphabetically (a, b) {
if (a.title < b.title) {
return -1
}
if (a.title > b.title) {
return 1
}
return 0
}
responseData[0] = busResponse.sort(sortAlphabetically)

})

.catch(function (error) {
console.log(error)
})
} catch (e) {
console.log(e)
}

return view.render('author.drafts-cases', { cases: responseData[0] })

}

async getQuestsAuthor ({ request, response }) {
try {
var responseData = []

let endpoint_url = Env.get("HARENA_MANAGER_URL") + "/api/v1/author/quests"

var config = {
method: 'get',
url: endpoint_url,
headers: {

'Authorization': 'Bearer ' + request.cookie('token')
}
}

await axios(config)
.then(function (endpoint_response) {
console.log('============ Retrieving quests')
console.log(endpoint_response.data)
const busResponse = []
for (const c in endpoint_response.data) {
busResponse.push({
id: endpoint_response.data[c].id,
title: endpoint_response.data[c].title,
color: endpoint_response.data[c].color,
url: endpoint_response.data[c].url,

})

}
responseData[0] = busResponse
})

.catch(function (error) {
console.log(error)
})

} catch (e) {

console.log(e)
}

return view.render('author.drafts-quest', { quests: responseData[0] })
}

async getCasesByQuest ({ request, response }) {
try {
Expand Down
19 changes: 17 additions & 2 deletions src/adonisjs/public/author/css/author.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
@charset "UTF-8";

#inplace-editor-wrapper{

border-color: #004270;
border-radius: 9px;
border-style: solid;
border-width: 13px;
border-bottom-width: 30px;

}

.sty-main-panel {
/* the main box (body) occupies all the visible area */
position: absolute;
Expand Down Expand Up @@ -133,8 +143,8 @@
}

.sty-knot-panel {
flex: 55%;
min-width: 20%;
/* flex: 55%;
min-width: 20%; */
overflow: scroll;
height: 100%;
}
Expand Down Expand Up @@ -175,6 +185,11 @@
overflow: hidden;
display: flex;
flex-direction: column;


z-index: 2;
position: relative;

}

/*
Expand Down
16 changes: 8 additions & 8 deletions src/adonisjs/public/author/js/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class AuthorManager {
caseid = params.match(/id=([\w-]+)/i)
caseid = (caseid == null) ? null : caseid[1]
}
if (mode != null && mode.toLowerCase() == 'advanced') { document.querySelector('#advanced-mode').style.display = 'initial' }
if (mode != null && mode.toLowerCase() === 'advanced') { document.querySelector('#advanced-mode').style.display = 'initial' }

// build singletons
Panels.start()
Expand Down Expand Up @@ -201,7 +201,7 @@ class AuthorManager {
break
case 'control/leave/drafts': await this.caseSave()
// window.location.href = 'draft.html';
window.location.href = '/drafts'
window.location.href = '/drafts/quests'
break
}
}
Expand All @@ -223,7 +223,7 @@ class AuthorManager {
'Select a case to load or start a new case.',
'list', 'Select', 'New', cases.message)

if (caseId == 'New') { this.caseNew() } else { this._caseLoad(caseId) }
if (caseId === 'New') { this.caseNew() } else { this._caseLoad(caseId) }

/*
const sticky = document.querySelector("#sticky-top");
Expand Down Expand Up @@ -401,20 +401,20 @@ class AuthorManager {
_checkKnotModification (nextState) {
// (1) render slide; (2) edit knot; (3) edit case
let modified = false
if (this._renderState == 2) {
if (this._renderState === 2) {
if (this._editor != null) {
const editorText = this._retrieveEditorText()
if (this._knots[this._knotSelected]._source != editorText) {
if (this._knots[this._knotSelected]._source !== editorText) {
modified = true
this._knots[this._knotSelected]._source = editorText
Translator.instance.extractKnotAnnotations(this._knots[this._knotSelected])
Translator.instance.compileKnotMarkdown(this._knots, this._knotSelected)
}
}
} else if (this._renderState == 3) {
} else if (this._renderState === 3) {
if (this._editor != null) {
const editorText = this._retrieveEditorText()
if (!this._originalMd || this._originalMd != editorText) {
if (!this._originalMd || this._originalMd !== editorText) {
modified = true
if (nextState != 3) { delete this._originalMd }
this._compile(editorText)
Expand Down Expand Up @@ -461,7 +461,7 @@ class AuthorManager {
// this._removeFloatingMenu();
// let knotid = MessageBus.extractLevel(topic, 3);
const knotid =
(message == null || message == '') ? this._knotSelected : message
(message == null || message === '') ? this._knotSelected : message
if (knotid != null) {
/*
console.log("=== miniatureF");
Expand Down
2 changes: 2 additions & 0 deletions src/adonisjs/public/author/js/dcc-author-server-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ class DCCAuthorServer {
domain: document.getElementById('domain').value,
specialty: document.getElementById('specialty').value,
keywords: document.getElementById('keywords').value,
institution: document.getElementById('institution').value,
complexity: document.getElementById('complexity').value,
source: message.source
},
headers: {
Expand Down
8 changes: 4 additions & 4 deletions src/adonisjs/public/author/js/draft.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class DraftManager {

this._boxesPanel = document.querySelector('#case-boxes')
// this._draftSelect(authorState.userid, advanced);
document.getElementsByClassName('buttons-container').length > 0 ?
this._draftQuestCasesSelect(advanced) : this._draftSelect(advanced)
document.getElementsByClassName('buttons-container').length > 0
? this._draftQuestCasesSelect(advanced) : this._draftSelect(advanced)
}

async _draftSelect (advanced) {
Expand Down Expand Up @@ -50,13 +50,13 @@ class DraftManager {
Basic.service.authorPropertyStore('caseId', this.id.substring(1))
// window.location.href = "http://0.0.0.0:10010/author/author.html";
window.location.href =
'author?id=' + this.id.substring(1)
'/author?id=' + this.id.substring(1)
}
)
previewButton.addEventListener('click',
function () {
Basic.service.authorPropertyStore('caseId', this.id.substring(1))
window.location.href = 'player/case?id=' +
window.location.href = '/player/case?id=' +
this.id.substring(1) +
'&preview'
}
Expand Down
2 changes: 1 addition & 1 deletion src/adonisjs/public/dccs/components/dcc-visual.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class DCCVisual extends DCCBase {
}

_attachTriggerPresentation (event, trigger, presentation) {
if (event == 'click') { presentation.style.cursor = 'pointer' }
if (event === 'click') { presentation.style.cursor = 'pointer' }
presentation.addEventListener(event, trigger)
}

Expand Down
Loading

0 comments on commit 974370a

Please sign in to comment.