From 26d7b0594305e31f551c2fa8706f0881a62c3dc3 Mon Sep 17 00:00:00 2001 From: Vittorio Meloni Date: Thu, 3 Aug 2023 14:18:42 +0200 Subject: [PATCH 1/8] WIP: handle file attachement in the negotiation creation --- src/components/NegotiationForm.vue | 11 +++++++++++ src/store/actions.js | 24 +++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/components/NegotiationForm.vue b/src/components/NegotiationForm.vue index 8b3f524..63190e9 100644 --- a/src/components/NegotiationForm.vue +++ b/src/components/NegotiationForm.vue @@ -56,6 +56,14 @@ class="form-control" :required="criteria.required" /> + { - return response.data.id - }) - .catch(() => { - return null + const attachmentId = response.data.id + data.attachments = [{ + id: attachmentId + }] + return axios.post(NEGOTIATION_PATH, data, {headers : getBearerHeaders(state.oidc.access_token)}) + .then((response) => { + return response.data.id + }) + .catch(() => { + return null + }) }) }, retrieveNegotiationsByRole({ state, commit }, { userRole }) { From 837c567b951ac6acd68f079fc6558ecc4ba39693 Mon Sep 17 00:00:00 2001 From: Vittorio Meloni Date: Thu, 3 Aug 2023 14:51:50 +0200 Subject: [PATCH 2/8] feat: adds code to create attachments in the negotiation --- src/components/NegotiationForm.vue | 8 ++++-- src/store/actions.js | 44 +++++++++++++++++------------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/components/NegotiationForm.vue b/src/components/NegotiationForm.vue index 63190e9..b208f6a 100644 --- a/src/components/NegotiationForm.vue +++ b/src/components/NegotiationForm.vue @@ -138,6 +138,7 @@ export default { notificationBody: "", negotiationCriteria: {}, accessCriteria: undefined, + files: [] } }, computed: { @@ -178,7 +179,8 @@ export default { await this.createNegotiation({ data: { requests: [this.requestId], - payload: this.negotiationCriteria + payload: this.negotiationCriteria, + files: this.files } }).then((negotiationId) => { if (negotiationId) { @@ -188,8 +190,8 @@ export default { } }) }, - handleFileUpload(event, section, criteria) { - this.negotiationCriteria[section][criteria] = event.target.files[0] + handleFileUpload(event) { + this.files.push(event.target.files[0]) }, showNotification(variant, header, body) { this.notificationVariant = variant diff --git a/src/store/actions.js b/src/store/actions.js index fc2ed65..cfd6eb0 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -44,28 +44,34 @@ export default { }) }, - createNegotiation({ state }, { data }) { - const formData = new FormData() - - formData.append("file", data["payload"]["ethics-vote"]["ethics-vote-attachment"]) + async createNegotiation({ state, commit }, { data }) { + if (data.files.length > 0) { + const formData = new FormData() + formData.append("file", data.files[0]) + const uploadFileHeaders = getBearerHeaders(state.oidc.access_token) + + uploadFileHeaders["Content-type"] = "multipart/form-data" + const attachmentsIds = await axios.post("/api/v3/attachments", formData, uploadFileHeaders) + .then((response) => { + return [{ + id: response.data.id + }] + }) + .catch(() => { + commit("setNotification", "There was an error saving the attachment") + return null + }) + data.attachments = attachmentsIds + } - const uploadFileHeaders = {headers : getBearerHeaders(state.oidc.access_token)} - uploadFileHeaders["Content-type"] = "multipart/form-data" - return axios.post("/api/v3/attachments", - formData, uploadFileHeaders) + return axios.post(NEGOTIATION_PATH, data, {headers : getBearerHeaders(state.oidc.access_token)}) .then((response) => { - const attachmentId = response.data.id - data.attachments = [{ - id: attachmentId - }] - return axios.post(NEGOTIATION_PATH, data, {headers : getBearerHeaders(state.oidc.access_token)}) - .then((response) => { - return response.data.id - }) - .catch(() => { - return null - }) + return response.data.id }) + .catch(() => { + commit("setNotification", "There was an error saving the Negotiation") + }) + }, retrieveNegotiationsByRole({ state, commit }, { userRole }) { return axios.get(`${NEGOTIATION_PATH}`, {headers : getBearerHeaders(state.oidc.access_token), params : {userRole : userRole}}) From e65650ae7c9083a8dce313fda96071dfa46eace5 Mon Sep 17 00:00:00 2001 From: Vittorio Meloni Date: Thu, 3 Aug 2023 15:05:39 +0200 Subject: [PATCH 3/8] feat: adds support to no attachments --- src/store/actions.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/store/actions.js b/src/store/actions.js index cfd6eb0..8848c77 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -63,6 +63,7 @@ export default { }) data.attachments = attachmentsIds } + data.files = undefined return axios.post(NEGOTIATION_PATH, data, {headers : getBearerHeaders(state.oidc.access_token)}) .then((response) => { From 067d15539fc4c686358b5f0db83f05bb66cdb33d Mon Sep 17 00:00:00 2001 From: Vittorio Meloni Date: Thu, 3 Aug 2023 16:41:34 +0200 Subject: [PATCH 4/8] feat: adds the attachments info into the access criteria field --- oidc_mock/config/clients.json | 2 +- src/components/NegotiationForm.vue | 16 ++++++++---- src/store/actions.js | 42 ++++++++++++++++-------------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/oidc_mock/config/clients.json b/oidc_mock/config/clients.json index cccb0f4..cc7832d 100644 --- a/oidc_mock/config/clients.json +++ b/oidc_mock/config/clients.json @@ -7,7 +7,7 @@ "AllowAccessTokensViaBrowser": true, "RedirectUris": ["http://localhost:8080/logged-in"], "AllowedScopes": ["openid", "profile", "email", "permissions"], - "IdentityTokenLifetime": 3600, + "IdentityTokenLifetime": 36000, "AccessTokenLifetime": 3600, "ClientClaimsPrefix": "" } diff --git a/src/components/NegotiationForm.vue b/src/components/NegotiationForm.vue index b208f6a..25fefa1 100644 --- a/src/components/NegotiationForm.vue +++ b/src/components/NegotiationForm.vue @@ -86,7 +86,12 @@ class="input-group mb-3" > - {{ negotiationCriteria[section.name][criteria.name] }} + + {{ negotiationCriteria[section.name][criteria.name].name }} + + + {{ negotiationCriteria[section.name][criteria.name] }} + @@ -138,7 +143,6 @@ export default { notificationBody: "", negotiationCriteria: {}, accessCriteria: undefined, - files: [] } }, computed: { @@ -180,7 +184,6 @@ export default { data: { requests: [this.requestId], payload: this.negotiationCriteria, - files: this.files } }).then((negotiationId) => { if (negotiationId) { @@ -190,8 +193,11 @@ export default { } }) }, - handleFileUpload(event) { - this.files.push(event.target.files[0]) + isAttachment(value) { + return value instanceof File || value instanceof Object + }, + handleFileUpload(event, section, criteria) { + this.negotiationCriteria[section][criteria] = event.target.files[0] }, showNotification(variant, header, body) { this.notificationVariant = variant diff --git a/src/store/actions.js b/src/store/actions.js index 8848c77..709b6fe 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -45,26 +45,30 @@ export default { }, async createNegotiation({ state, commit }, { data }) { - if (data.files.length > 0) { - const formData = new FormData() - formData.append("file", data.files[0]) - const uploadFileHeaders = getBearerHeaders(state.oidc.access_token) - - uploadFileHeaders["Content-type"] = "multipart/form-data" - const attachmentsIds = await axios.post("/api/v3/attachments", formData, uploadFileHeaders) - .then((response) => { - return [{ - id: response.data.id - }] - }) - .catch(() => { - commit("setNotification", "There was an error saving the attachment") - return null - }) - data.attachments = attachmentsIds + data.attachments = [] + for (const [sectionName, criteriaList] of Object.entries(data.payload)) { + for (const [criteriaName, criteriaValue] of Object.entries(criteriaList)) { + if (criteriaValue instanceof File) { + const formData = new FormData() + formData.append("file", criteriaValue) + const uploadFileHeaders = getBearerHeaders(state.oidc.access_token) + uploadFileHeaders["Content-type"] = "multipart/form-data" + + const attachmentsIds = await axios.post("/api/v3/attachments", formData, uploadFileHeaders) + .then((response) => { + return response.data + }) + .catch(() => { + commit("setNotification", "There was an error saving the attachment") + return null + }) + + data.payload[sectionName][criteriaName] = attachmentsIds + data.attachments.push(attachmentsIds) + } + } } - data.files = undefined - + console.log(data) return axios.post(NEGOTIATION_PATH, data, {headers : getBearerHeaders(state.oidc.access_token)}) .then((response) => { return response.data.id From 6dfdec9b0bb374f4c7df3429367c089fbfbeea83 Mon Sep 17 00:00:00 2001 From: Vittorio Meloni Date: Thu, 3 Aug 2023 17:26:44 +0200 Subject: [PATCH 5/8] feat: adds attachmnet visualization in negotiation page --- src/components/NegotiationForm.vue | 6 +++--- src/store/actions.js | 6 +++++- src/views/NegotiationPage.vue | 31 ++++++++++++++++-------------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/components/NegotiationForm.vue b/src/components/NegotiationForm.vue index 25fefa1..64f0cf7 100644 --- a/src/components/NegotiationForm.vue +++ b/src/components/NegotiationForm.vue @@ -38,7 +38,7 @@ v-for="section in accessCriteria.sections" :key="section.name" :title="section.label" - class="form-step border rounded px-2 py-3 mb-2" + class="form-step border rounded-2 px-2 py-3 mb-2" >
{{ section.label }}
diff --git a/src/store/actions.js b/src/store/actions.js index 709b6fe..596bb53 100644 --- a/src/store/actions.js +++ b/src/store/actions.js @@ -68,7 +68,6 @@ export default { } } } - console.log(data) return axios.post(NEGOTIATION_PATH, data, {headers : getBearerHeaders(state.oidc.access_token)}) .then((response) => { return response.data.id @@ -128,8 +127,13 @@ export default { return null }) }, +<<<<<<< HEAD retrieveNegotiationById({ state, commit }, { negotiationId }) { return axios.get(`${NEGOTIATION_PATH}/${negotiationId}`, {headers : getBearerHeaders(state.oidc.access_token)}) +======= + async retrieveNegotiationById({ state, commit }, { negotiationId }) { + return axios.get(`${NEGOTIATION_PATH}/${negotiationId}`, getBearerHeaders(state.oidc.access_token)) +>>>>>>> 9ea582b (feat: adds attachmnet visualization in negotiation page) .then((response) => { return response.data }) diff --git a/src/views/NegotiationPage.vue b/src/views/NegotiationPage.vue index 44d0b7f..1bca41e 100644 --- a/src/views/NegotiationPage.vue +++ b/src/views/NegotiationPage.vue @@ -46,21 +46,26 @@
- + {{ key.toUpperCase() }}
- {{ subelement }} + + {{ subelement.name }} + + + {{ subelement }} +
RESOURCE STATUS @@ -155,7 +160,7 @@