Skip to content

Commit

Permalink
Merge pull request #202 from datasci4health/development
Browse files Browse the repository at this point in the history
Fix (save case): fix save case author
  • Loading branch information
HeitorMatt authored Aug 30, 2020
2 parents 0955a12 + ac4dd5f commit a26df29
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/adonisjs/app/Controllers/Http/CaseController.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class CaseController {
async update ({ request, session, response }) {
try {
const params = request.all()

console.log('UPDATE STARTING........');
const endpointUrl =
Env.get('HARENA_MANAGER_URL') + '/api/v1/case/' + params.case_id

Expand Down
2 changes: 1 addition & 1 deletion src/adonisjs/public/author/js/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class AuthorManager {
.addEventListener("shown.bs.modal", this.updateSourceField);
*/
$('#settings-modal').on('shown.bs.modal', this.updateSourceField)

$('#btn-save-settings').on('click', await this.caseSave)
// this.caseLoadSelect();
}

Expand Down
102 changes: 65 additions & 37 deletions src/adonisjs/public/author/js/dcc-author-server-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Component following the Digital Content Component (DCC) model responsible for acting
* as a proxy between the authoring environment and the server.
*/

// const axios = require('axios');
class DCCAuthorServer {
constructor () {
this.loadModule = this.loadModule.bind(this)
Expand Down Expand Up @@ -131,51 +131,79 @@ class DCCAuthorServer {
* by the authoring environment.
********************************************************************/

const headerRead = {
async: true,
crossDomain: true,
method: 'GET',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + DCCCommonServer.token
}
}

const responseRead =
await fetch(DCCCommonServer.managerAddressAPI + 'case/' + caseId,
headerRead)

const jsonRead = await responseRead.json()
// const headerRead = {
// async: true,
// crossDomain: true,
// method: 'GET',
// headers: {
// 'Content-Type': 'application/json',
// Authorization: 'Bearer ' + DCCCommonServer.token
// }
// }
//
// const responseRead =
// await fetch(DCCCommonServer.managerAddressAPI + 'case/' + caseId,
// headerRead)
//
// const jsonRead = await responseRead.json()

// write the case

const header = {
async: true,
crossDomain: true,
// const header = {
// async: true,
// crossDomain: true,
// method: 'PUT',
// headers: {
// 'Content-Type': 'application/json',
// Authorization: 'Bearer ' + DCCCommonServer.token
// },
// body: JSON.stringify({
// title: document.getElementById('case_title').value,
// description: document.getElementById('description').value,
// language: document.getElementById('language').value,
// domain: document.getElementById('domain').value,
// specialty: document.getElementById('specialty').value,
// keywords: document.getElementById('keywords').value,
// source: message.source
// })
// }

const config = {
method: 'PUT',
url: DCCCommonServer.managerAddressAPI + 'case/' + caseId,
data: {
title: document.getElementById('case_title').value,
description: document.getElementById('description').value,
language: document.getElementById('language').value,
domain: document.getElementById('domain').value,
specialty: document.getElementById('specialty').value,
keywords: document.getElementById('keywords').value,
source: message.source
},
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + DCCCommonServer.token
},
body: JSON.stringify({
title: jsonRead.title,
description: jsonRead.description,
language: jsonRead.language,
domain: jsonRead.domain,
specialty: jsonRead.specialty,
keywords: jsonRead.keywords,
source: message.source
})
}
}
console.log('=== save request')
console.log(DCCCommonServer.managerAddressAPI + 'case/' + caseId)
const response =
await fetch(DCCCommonServer.managerAddressAPI + 'case/' + caseId, header)
console.log('=== save response')
console.log(response)
const jsonResponse = await response.json()
MessageBus.ext.publish(MessageBus.buildResponseTopic(topic, message),
jsonResponse.source)
axios(config)
.then(function (response) {
// return response.redirect('/')
console.log('=== save response')
console.log(response);
MessageBus.ext.publish(MessageBus.buildResponseTopic(topic, message),
response.data.source)
})
.catch(function (error) {
console.log('=== save error')
console.log(error)
})
// const response =
// await fetch(DCCCommonServer.managerAddressAPI + 'case/' + caseId, header)
// console.log(response)
// const jsonResponse = await response.json()
}else {
console.log('save failed else');
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/adonisjs/resources/views/author/author.edge
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
<script src="{{ assetsUrl('author/js/navigator.js') }}"></script>
<script src="{{ assetsUrl('author/js/author.js') }}"></script>

<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

</head>

<body onload="AuthorManager.author.start()">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
<div class="modal-content">
<div class="modal-body">
<h3>Settings</h3>
<form method="POST" action="{{ route('CaseController.update') }}">

{{ csrfField() }}
<form>

<input type="hidden" id="case_id" name="case_id" value="{{caseId}}">
<input type="hidden" id="case_source" name="case_source" value="{{caseSource}}">
Expand Down Expand Up @@ -52,7 +50,9 @@
</div>

<input type="hidden" id="source" name="source">
<button type="submit" class="btn btn-secondary" id="btn-save-settings" data-toggle="modal" data-target="#settings-modal">Save</button>
<button type="button" class="btn btn-secondary" id="btn-save-settings" data-toggle="modal" data-target="#settings-modal" >Save</button>
<dcc-trigger action="control/case/save" label="SAVE" location="btn-save-settings" xstyle="out"></dcc-trigger>

<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Cancel</button>
</form>
</div>
Expand Down

0 comments on commit a26df29

Please sign in to comment.