From 6aa3ac3156fb8a4ddbe0839406988b7bfaea6488 Mon Sep 17 00:00:00 2001 From: Thijn Date: Thu, 17 Oct 2024 12:10:37 +0200 Subject: [PATCH 01/55] finished synchro test frontend --- src/modals/Modals.vue | 3 + .../Synchronization/TestSynchronization.vue | 97 +++++ src/store/modules/synchronization.js | 352 ++++++++++-------- .../SynchronizationDetails.vue | 15 +- 4 files changed, 299 insertions(+), 168 deletions(-) create mode 100644 src/modals/Synchronization/TestSynchronization.vue diff --git a/src/modals/Modals.vue b/src/modals/Modals.vue index 49c39f5..179fda5 100644 --- a/src/modals/Modals.vue +++ b/src/modals/Modals.vue @@ -20,6 +20,7 @@ + @@ -48,6 +49,7 @@ import EditMapping from './Mapping/EditMapping.vue' import DeleteMapping from './Mapping/DeleteMapping.vue' import EditSynchronization from './Synchronization/EditSynchronization.vue' import DeleteSynchronization from './Synchronization/DeleteSynchronization.vue' +import TestSynchronization from './Synchronization/TestSynchronization.vue' import EditJobArgument from './JobArgument/EditJobArgument.vue' import DeleteJobArgument from './JobArgument/DeleteJobArgument.vue' import EditSourceConfiguration from './SourceConfiguration/EditSourceConfiguration.vue' @@ -78,6 +80,7 @@ export default { EditMapping, DeleteSynchronization, EditSynchronization, + TestSynchronization, EditJobArgument, DeleteJobArgument, EditSourceConfiguration, diff --git a/src/modals/Synchronization/TestSynchronization.vue b/src/modals/Synchronization/TestSynchronization.vue new file mode 100644 index 0000000..09812b3 --- /dev/null +++ b/src/modals/Synchronization/TestSynchronization.vue @@ -0,0 +1,97 @@ + + + + + + diff --git a/src/store/modules/synchronization.js b/src/store/modules/synchronization.js index edbec97..acadf98 100644 --- a/src/store/modules/synchronization.js +++ b/src/store/modules/synchronization.js @@ -2,184 +2,208 @@ import { defineStore } from 'pinia' import { Synchronization } from '../../entities/index.js' -export const useSynchronizationStore = defineStore( - 'synchronization', { - state: () => ({ - synchronizationItem: false, - synchronizationList: [], - synchronizationContracts: [], - synchronizationLogs: [], - }), - actions: { - setSynchronizationItem(synchronizationItem) { - this.synchronizationItem = synchronizationItem && new Synchronization(synchronizationItem) - console.log('Active synchronization item set to ' + synchronizationItem) - }, - setSynchronizationList(synchronizationList) { - this.synchronizationList = synchronizationList.map( - (synchronizationItem) => new Synchronization(synchronizationItem), +export const useSynchronizationStore = defineStore('synchronization', { + state: () => ({ + synchronizationItem: false, + synchronizationList: [], + synchronizationContracts: [], + synchronizationTest: null, + synchronizationLogs: [], + }), + actions: { + setSynchronizationItem(synchronizationItem) { + this.synchronizationItem = synchronizationItem && new Synchronization(synchronizationItem) + console.log('Active synchronization item set to ' + synchronizationItem) + }, + setSynchronizationList(synchronizationList) { + this.synchronizationList = synchronizationList.map( + (synchronizationItem) => new Synchronization(synchronizationItem), + ) + console.log('Synchronization list set to ' + synchronizationList.length + ' items') + }, + setSynchronizationContracts(synchronizationContracts) { + this.synchronizationContracts = synchronizationContracts.map( + (synchronizationContract) => new SynchronizationContract(synchronizationContract), + ) + console.log('Synchronization contracts set to ' + synchronizationContracts.length + ' items') + }, + setSynchronizationLogs(synchronizationLogs) { + this.synchronizationLogs = synchronizationLogs.map( + (synchronizationLog) => new SynchronizationLog(synchronizationLog), + ) + console.log('Synchronization logs set to ' + synchronizationLogs.length + ' items') + }, + /* istanbul ignore next */ // ignore this for Jest until moved into a service + async refreshSynchronizationList(search = null) { + // @todo this might belong in a service? + let endpoint = '/index.php/apps/openconnector/api/synchronizations' + if (search !== null && search !== '') { + endpoint = endpoint + '?_search=' + search + } + return fetch(endpoint, { + method: 'GET', + }) + .then( + (response) => { + response.json().then( + (data) => { + this.setSynchronizationList(data.results) + }, + ) + }, ) - console.log('Synchronization list set to ' + synchronizationList.length + ' items') - }, - setSynchronizationContracts(synchronizationContracts) { - this.synchronizationContracts = synchronizationContracts.map( - (synchronizationContract) => new SynchronizationContract(synchronizationContract), + .catch( + (err) => { + console.error(err) + }, ) - console.log('Synchronization contracts set to ' + synchronizationContracts.length + ' items') - }, - setSynchronizationLogs(synchronizationLogs) { - this.synchronizationLogs = synchronizationLogs.map( - (synchronizationLog) => new SynchronizationLog(synchronizationLog), + }, + /* istanbul ignore next */ // ignore this for Jest until moved into a service + async refreshSynchronizationContracts(search = null) { + // @todo this might belong in a service? + let endpoint = `/index.php/apps/openconnector/api/synchronizations-contracts/${this.synchronizationItem.id}` + if (search !== null && search !== '') { + endpoint = endpoint + '?_search=' + search + } + return fetch(endpoint, { + method: 'GET', + }) + .then( + (response) => { + response.json().then( + (data) => { + this.setSynchronizationContracts(data.results) + }, + ) + }, ) - console.log('Synchronization logs set to ' + synchronizationLogs.length + ' items') - }, - /* istanbul ignore next */ // ignore this for Jest until moved into a service - async refreshSynchronizationList(search = null) { - // @todo this might belong in a service? - let endpoint = '/index.php/apps/openconnector/api/synchronizations' - if (search !== null && search !== '') { - endpoint = endpoint + '?_search=' + search - } - return fetch(endpoint, { - method: 'GET', - }) - .then( - (response) => { - response.json().then( - (data) => { - this.setSynchronizationList(data.results) - }, - ) - }, - ) - .catch( - (err) => { - console.error(err) - }, - ) - }, - /* istanbul ignore next */ // ignore this for Jest until moved into a service - async refreshSynchronizationContracts(search = null) { - // @todo this might belong in a service? - let endpoint = `/index.php/apps/openconnector/api/synchronizations-contracts/${this.synchronizationItem.id}` - if (search !== null && search !== '') { - endpoint = endpoint + '?_search=' + search - } - return fetch(endpoint, { + .catch( + (err) => { + console.error(err) + }, + ) + }, + /* istanbul ignore next */ // ignore this for Jest until moved into a service + async refreshSynchronizationLogs(search = null) { + // @todo this might belong in a service? + let endpoint = `/index.php/apps/openconnector/api/synchronizations-logs/${this.synchronizationItem.id}` + if (search !== null && search !== '') { + endpoint = endpoint + '?_search=' + search + } + return fetch(endpoint, { + method: 'GET', + }) + .then( + (response) => { + response.json().then( + (data) => { + this.setSynchronizationLogs(data.results) + }, + ) + }, + ) + .catch( + (err) => { + console.error(err) + }, + ) + }, + // New function to get a single synchronization + async getSynchronization(id) { + const endpoint = `/index.php/apps/openconnector/api/synchronizations/${id}` + try { + const response = await fetch(endpoint, { method: 'GET', }) - .then( - (response) => { - response.json().then( - (data) => { - this.setSynchronizationContracts(data.results) - }, - ) - }, - ) - .catch( - (err) => { - console.error(err) - }, - ) - }, - /* istanbul ignore next */ // ignore this for Jest until moved into a service - async refreshSynchronizationLogs(search = null) { - // @todo this might belong in a service? - let endpoint = `/index.php/apps/openconnector/api/synchronizations-logs/${this.synchronizationItem.id}` - if (search !== null && search !== '') { - endpoint = endpoint + '?_search=' + search - } - return fetch(endpoint, { - method: 'GET', + const data = await response.json() + this.setSynchronizationItem(data) + return data + } catch (err) { + console.error(err) + throw err + } + }, + // Delete a synchronization + deleteSynchronization() { + if (!this.synchronizationItem || !this.synchronizationItem.id) { + throw new Error('No synchronization item to delete') + } + + console.log('Deleting synchronization...') + + const endpoint = `/index.php/apps/openconnector/api/synchronizations/${this.synchronizationItem.id}` + + return fetch(endpoint, { + method: 'DELETE', + }) + .then((response) => { + this.refreshSynchronizationList() }) - .then( - (response) => { - response.json().then( - (data) => { - this.setSynchronizationLogs(data.results) - }, - ) - }, - ) - .catch( - (err) => { - console.error(err) - }, - ) - }, - // New function to get a single synchronization - async getSynchronization(id) { - const endpoint = `/index.php/apps/openconnector/api/synchronizations/${id}` - try { - const response = await fetch(endpoint, { - method: 'GET', - }) - const data = await response.json() - this.setSynchronizationItem(data) - return data - } catch (err) { - console.error(err) + .catch((err) => { + console.error('Error deleting synchronization:', err) throw err - } - }, - // Delete a synchronization - deleteSynchronization() { - if (!this.synchronizationItem || !this.synchronizationItem.id) { - throw new Error('No synchronization item to delete') - } + }) + }, + // Create or save a synchronization from store + saveSynchronization(synchronizationItem) { + if (!synchronizationItem) { + throw new Error('No synchronization item to save') + } + + console.log('Saving synchronization...') - console.log('Deleting synchronization...') + const isNewSynchronization = !synchronizationItem?.id + const endpoint = isNewSynchronization + ? '/index.php/apps/openconnector/api/synchronizations' + : `/index.php/apps/openconnector/api/synchronizations/${synchronizationItem.id}` + const method = isNewSynchronization ? 'POST' : 'PUT' - const endpoint = `/index.php/apps/openconnector/api/synchronizations/${this.synchronizationItem.id}` + return fetch( + endpoint, + { + method, + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(synchronizationItem), + }, + ) + .then((response) => response.json()) + .then((data) => { + this.setSynchronizationItem(data) + console.log('Synchronization saved') - return fetch(endpoint, { - method: 'DELETE', + this.refreshSynchronizationList() }) - .then((response) => { - this.refreshSynchronizationList() - }) - .catch((err) => { - console.error('Error deleting synchronization:', err) - throw err - }) - }, - // Create or save a synchronization from store - saveSynchronization(synchronizationItem) { - if (!synchronizationItem) { - throw new Error('No synchronization item to save') - } + .catch((err) => { + console.error('Error saving synchronization:', err) + throw err + }) + }, + // Test a synchronization + async testSynchronization() { + if (!this.synchronizationItem) { + throw new Error('No synchronization item to test') + } - console.log('Saving synchronization...') + console.log('Testing synchronization...') - const isNewSynchronization = !synchronizationItem?.id - const endpoint = isNewSynchronization - ? '/index.php/apps/openconnector/api/synchronizations' - : `/index.php/apps/openconnector/api/synchronizations/${synchronizationItem.id}` - const method = isNewSynchronization ? 'POST' : 'PUT' + const endpoint = `/index.php/apps/openconnector/api/synchronization-test/${this.synchronizationItem.id}` - return fetch( - endpoint, - { - method, - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(synchronizationItem), - }, - ) - .then((response) => response.json()) - .then((data) => { - this.setSynchronizationItem(data) - console.log('Synchronization saved') + const response = await fetch(endpoint, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + }) + + const data = await response.json() + this.synchronizationTest = data + + console.log('Synchronization tested') + this.refreshSynchronizationLogs() - this.refreshSynchronizationList() - }) - .catch((err) => { - console.error('Error saving synchronization:', err) - throw err - }) - }, + return { response, data } }, }, -) +}) diff --git a/src/views/Synchronization/SynchronizationDetails.vue b/src/views/Synchronization/SynchronizationDetails.vue index 477d35c..9b31ca2 100644 --- a/src/views/Synchronization/SynchronizationDetails.vue +++ b/src/views/Synchronization/SynchronizationDetails.vue @@ -21,6 +21,12 @@ import { synchronizationStore, navigationStore } from '../../store/store.js' Edit + + + Test + @@ -66,6 +67,7 @@ import EditMappingCast from './mappingCast/EditMappingCast.vue' import DeleteMappingCast from './mappingCast/DeleteMappingCast.vue' import ViewJobLog from './Log/ViewJobLog.vue' import ViewSynchronizationLog from './Log/ViewSynchronizationLog.vue' +import ViewSynchronizationContract from './Log/ViewSynchronizationContract.vue' export default { name: 'Modals', @@ -99,6 +101,7 @@ export default { DeleteMappingCast, ViewJobLog, ViewSynchronizationLog, + ViewSynchronizationContract, }, setup() { return { diff --git a/src/views/Synchronization/SynchronizationDetails.vue b/src/views/Synchronization/SynchronizationDetails.vue index 54ec6d1..c2920f2 100644 --- a/src/views/Synchronization/SynchronizationDetails.vue +++ b/src/views/Synchronization/SynchronizationDetails.vue @@ -131,9 +131,9 @@ import { synchronizationStore, navigationStore, logStore } from '../../store/sto
- @@ -143,10 +143,10 @@ import { synchronizationStore, navigationStore, logStore } from '../../store/sto :size="44" />