From f2c5ee035a5730509fe76ac00230cd1e1b7c468b Mon Sep 17 00:00:00 2001 From: Heitor Mattosinho Date: Sun, 30 Aug 2020 14:54:13 -0300 Subject: [PATCH 1/5] fix (author save): Modal save fixed --- .../app/Controllers/Http/CaseController.js | 2 +- .../author/js/dcc-author-server-proxy.js | 42 +++++++++---------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/adonisjs/app/Controllers/Http/CaseController.js b/src/adonisjs/app/Controllers/Http/CaseController.js index 4e5d1ee34..de25d53c3 100644 --- a/src/adonisjs/app/Controllers/Http/CaseController.js +++ b/src/adonisjs/app/Controllers/Http/CaseController.js @@ -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 diff --git a/src/adonisjs/public/author/js/dcc-author-server-proxy.js b/src/adonisjs/public/author/js/dcc-author-server-proxy.js index 6dacdcfaa..76ffc5222 100644 --- a/src/adonisjs/public/author/js/dcc-author-server-proxy.js +++ b/src/adonisjs/public/author/js/dcc-author-server-proxy.js @@ -131,21 +131,21 @@ 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 @@ -158,12 +158,12 @@ class DCCAuthorServer { 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, + 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 }) } From 5fca8ff94b87b3af9e251695a3fb9066933245d7 Mon Sep 17 00:00:00 2001 From: Heitor Mattosinho Date: Sun, 30 Aug 2020 15:35:16 -0300 Subject: [PATCH 2/5] fix(): change fetch to axios --- .../author/js/dcc-author-server-proxy.js | 57 ++++++++++++++----- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/src/adonisjs/public/author/js/dcc-author-server-proxy.js b/src/adonisjs/public/author/js/dcc-author-server-proxy.js index 76ffc5222..1d343148b 100644 --- a/src/adonisjs/public/author/js/dcc-author-server-proxy.js +++ b/src/adonisjs/public/author/js/dcc-author-server-proxy.js @@ -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) @@ -149,15 +149,29 @@ class DCCAuthorServer { // 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', - headers: { - 'Content-Type': 'application/json', - Authorization: 'Bearer ' + DCCCommonServer.token - }, - body: JSON.stringify({ + url: DCCCommonServer.managerAddressAPI + 'case/' + caseId, + data: { title: document.getElementById('case_title').value, description: document.getElementById('description').value, language: document.getElementById('language').value, @@ -165,17 +179,30 @@ class DCCAuthorServer { specialty: document.getElementById('specialty').value, keywords: document.getElementById('keywords').value, source: message.source - }) + }, + headers: { + Authorization: 'Bearer ' + DCCCommonServer.token + } } + await axios(config) + .then(function () { + console.log('AXIOS UPDATE ============================'); + // return response.redirect('/') + }) + .catch(function (error) { + console.log(error) + }) console.log('=== save request') console.log(DCCCommonServer.managerAddressAPI + 'case/' + caseId) - const response = - await fetch(DCCCommonServer.managerAddressAPI + 'case/' + caseId, header) + // const response = + // await fetch(DCCCommonServer.managerAddressAPI + 'case/' + caseId, header) console.log('=== save response') - console.log(response) - const jsonResponse = await response.json() + // console.log(response) + // const jsonResponse = await response.json() MessageBus.ext.publish(MessageBus.buildResponseTopic(topic, message), - jsonResponse.source) + message.source) + }else { + console.log('save failed else'); } } From 89add06d799dd5174b11f979fdcd98575f9a969c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Santanch=C3=A8?= Date: Sun, 30 Aug 2020 16:06:38 -0300 Subject: [PATCH 3/5] feat (case save): using axios --- .../author/js/dcc-author-server-proxy.js | 19 ++++++++++--------- .../resources/views/author/author.edge | 2 ++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/adonisjs/public/author/js/dcc-author-server-proxy.js b/src/adonisjs/public/author/js/dcc-author-server-proxy.js index 1d343148b..208733384 100644 --- a/src/adonisjs/public/author/js/dcc-author-server-proxy.js +++ b/src/adonisjs/public/author/js/dcc-author-server-proxy.js @@ -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'); +// const axios = require('axios'); class DCCAuthorServer { constructor () { this.loadModule = this.loadModule.bind(this) @@ -184,23 +184,24 @@ class DCCAuthorServer { Authorization: 'Bearer ' + DCCCommonServer.token } } - await axios(config) - .then(function () { - console.log('AXIOS UPDATE ============================'); + console.log('=== save request') + console.log(DCCCommonServer.managerAddressAPI + 'case/' + caseId) + 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) }) - 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), - message.source) }else { console.log('save failed else'); } diff --git a/src/adonisjs/resources/views/author/author.edge b/src/adonisjs/resources/views/author/author.edge index 6017625ce..809c83062 100644 --- a/src/adonisjs/resources/views/author/author.edge +++ b/src/adonisjs/resources/views/author/author.edge @@ -72,6 +72,8 @@ + + From eae3b4bbd535d739fb239756da689c73ea06827d Mon Sep 17 00:00:00 2001 From: Heitor Mattosinho Date: Sun, 30 Aug 2020 17:31:39 -0300 Subject: [PATCH 4/5] refactor (modal save): save button disabled --- .../resources/views/layout/partials/settings-modal.edge | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/adonisjs/resources/views/layout/partials/settings-modal.edge b/src/adonisjs/resources/views/layout/partials/settings-modal.edge index 99611a20a..5f36e3dc9 100644 --- a/src/adonisjs/resources/views/layout/partials/settings-modal.edge +++ b/src/adonisjs/resources/views/layout/partials/settings-modal.edge @@ -4,10 +4,8 @@ From ac4dd5f8f2a52ced13cfb3b051536e13a44c3d8f Mon Sep 17 00:00:00 2001 From: Heitor Mattosinho Date: Sun, 30 Aug 2020 18:57:25 -0300 Subject: [PATCH 5/5] refactor (save case): save case button modal to dcc --- src/adonisjs/public/author/js/author.js | 2 +- .../resources/views/layout/partials/settings-modal.edge | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/adonisjs/public/author/js/author.js b/src/adonisjs/public/author/js/author.js index 80e48224d..a1dab379e 100644 --- a/src/adonisjs/public/author/js/author.js +++ b/src/adonisjs/public/author/js/author.js @@ -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(); } diff --git a/src/adonisjs/resources/views/layout/partials/settings-modal.edge b/src/adonisjs/resources/views/layout/partials/settings-modal.edge index 5f36e3dc9..5daef48c9 100644 --- a/src/adonisjs/resources/views/layout/partials/settings-modal.edge +++ b/src/adonisjs/resources/views/layout/partials/settings-modal.edge @@ -5,7 +5,7 @@ - + + +