Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/CONNECTOR-172/export-of-json-files #163

Merged
merged 12 commits into from
Jan 10, 2025
11 changes: 5 additions & 6 deletions src/store/modules/consumer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { defineStore } from 'pinia'
import { Consumer } from '../../entities/index.js'
import { MissingParameterError, ValidationError } from '../../services/errors/index.js'
Expand All @@ -11,13 +10,13 @@ export const useConsumerStore = defineStore('consumer', {
actions: {
setConsumerItem(consumerItem) {
this.consumerItem = consumerItem && new Consumer(consumerItem)
console.log('Active consumer item set to ' + consumerItem)
console.info('Active consumer item set to ' + consumerItem)
},
setConsumerList(consumerList) {
this.consumerList = consumerList.map(
(consumerItem) => new Consumer(consumerItem),
)
console.log('Consumer list set to ' + consumerList.length + ' items')
console.info('Consumer list set to ' + consumerList.length + ' items')
},
/* istanbul ignore next */ // ignore this for Jest until moved into a service
async refreshConsumerList(search = null) {
Expand Down Expand Up @@ -59,7 +58,7 @@ export const useConsumerStore = defineStore('consumer', {
throw new MissingParameterError('consumerItem')
}

console.log('Deleting consumer...')
console.info('Deleting consumer...')

const endpoint = `/index.php/apps/openconnector/api/consumers/${this.consumerItem.id}`

Expand Down Expand Up @@ -90,11 +89,11 @@ export const useConsumerStore = defineStore('consumer', {
const validationResult = consumerItem.validate()
if (!validationResult.success) {
console.error(validationResult.error)
console.log(consumerItem)
console.info(consumerItem)
throw new ValidationError(validationResult.error)
}

console.log('Saving consumer...')
console.info('Saving consumer...')

const isNewConsumer = !consumerItem.id
const endpoint = isNewConsumer
Expand Down
1 change: 0 additions & 1 deletion src/store/modules/consumer.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { setActivePinia, createPinia } from 'pinia'

import { useConsumerStore } from './consumer.js'
Expand Down
28 changes: 23 additions & 5 deletions src/store/modules/endpoints.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */
import { defineStore } from 'pinia'
import { Endpoint } from '../../entities/index.js'
import { MissingParameterError, ValidationError } from '../../services/errors/index.js'
import { importExportStore } from '../../store/store.js'

export const useEndpointStore = defineStore('endpoint', {
state: () => ({
Expand All @@ -11,13 +11,13 @@ export const useEndpointStore = defineStore('endpoint', {
actions: {
setEndpointItem(endpointItem) {
this.endpointItem = endpointItem && new Endpoint(endpointItem)
console.log('Active endpoint item set to ' + endpointItem)
console.info('Active endpoint item set to ' + endpointItem)
},
setEndpointList(endpointList) {
this.endpointList = endpointList.map(
(endpointItem) => new Endpoint(endpointItem),
)
console.log('Endpoint list set to ' + endpointList.length + ' items')
console.info('Endpoint list set to ' + endpointList.length + ' items')
},
/* istanbul ignore next */ // ignore this for Jest until moved into a service
async refreshEndpointList(search = null) {
Expand Down Expand Up @@ -59,7 +59,7 @@ export const useEndpointStore = defineStore('endpoint', {
throw new MissingParameterError('endpointItem')
}

console.log('Deleting endpoint...')
console.info('Deleting endpoint...')

const endpoint = `/index.php/apps/openconnector/api/endpoints/${endpointItem.id}`

Expand Down Expand Up @@ -88,7 +88,7 @@ export const useEndpointStore = defineStore('endpoint', {
throw new ValidationError(validationResult.error)
}

console.log('Saving endpoint...')
console.info('Saving endpoint...')

const isNewEndpoint = !endpointItem.id
const endpoint = isNewEndpoint
Expand Down Expand Up @@ -117,5 +117,23 @@ export const useEndpointStore = defineStore('endpoint', {

return { response, data, entity }
},
// Export an endpoint
exportEndpoint(endpointItem) {
if (!endpointItem) {
throw new Error('No endpoint item to export')
}
importExportStore.exportFile(
endpointItem.id,
endpointItem.name,
'endpoint',
)
.then(({ download }) => {
download()
})
.catch((err) => {
console.error('Error exporting endpoint:', err)
throw err
})
},
},
})
1 change: 0 additions & 1 deletion src/store/modules/endpoints.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { setActivePinia, createPinia } from 'pinia'

import { useEndpointStore } from './endpoints.js'
Expand Down
48 changes: 48 additions & 0 deletions src/store/modules/importExport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { defineStore } from 'pinia'

export const useImportExportStore = defineStore(
'importExport', {
state: () => ({
exportSource: '',
exportSourceResults: '',
exportSourceError: '',
}),
actions: {
setExportSource(exportSource) {
this.exportSource = exportSource
console.info('Active exportSource set to ' + exportSource)
},
async exportFile(id, title, type) {
const apiEndpoint = `/index.php/apps/openconnector/api/export/${type}/${id}`

if (!id) {
throw Error('Passed id is falsy')
}
const response = await fetch(
apiEndpoint,
{
method: 'GET',
headers: {
Accept: 'application/json',
},
},
)

const blob = await response.blob()

const download = () => {
const url = window.URL.createObjectURL(new Blob([blob]))
const link = document.createElement('a')
link.href = url

link.setAttribute('download', `${title}.json`)
document.body.appendChild(link)
link.click()
}

return { response, blob, download }
},

},
},
)
46 changes: 32 additions & 14 deletions src/store/modules/job.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import { defineStore } from 'pinia'
import { Job } from '../../entities/index.js'
import { importExportStore } from '../../store/store.js'

export const useJobStore = defineStore(
'job', {
Expand All @@ -16,29 +16,29 @@ export const useJobStore = defineStore(
actions: {
setJobItem(jobItem) {
this.jobItem = jobItem && new Job(jobItem)
console.log('Active job item set to ' + jobItem)
console.info('Active job item set to ' + jobItem)
},
setJobTest(jobTest) {
this.jobTest = jobTest
console.log('Job test set to ' + jobTest)
console.info('Job test set to ' + jobTest)
},
setJobRun(jobRun) {
this.jobRun = jobRun
console.log('Job run set to ' + jobRun)
console.info('Job run set to ' + jobRun)
},
setJobList(jobList) {
this.jobList = jobList.map(
(jobItem) => new Job(jobItem),
)
console.log('Job list set to ' + jobList.length + ' items')
console.info('Job list set to ' + jobList.length + ' items')
},
setJobLogs(jobLogs) {
this.jobLogs = jobLogs
console.log('Job logs set to ' + jobLogs.length + ' items')
console.info('Job logs set to ' + jobLogs.length + ' items')
},
setJobArgumentKey(jobArgumentKey) {
this.jobArgumentKey = jobArgumentKey
console.log('Active job argument key set to ' + jobArgumentKey)
console.info('Active job argument key set to ' + jobArgumentKey)
},
/* istanbul ignore next */ // ignore this for Jest until moved into a service
async refreshJobList(search = null) {
Expand Down Expand Up @@ -101,7 +101,7 @@ export const useJobStore = defineStore(
throw new Error('No job item to delete')
}

console.log('Deleting job...')
console.info('Deleting job...')

const endpoint = `/index.php/apps/openconnector/api/jobs/${this.jobItem.id}`

Expand All @@ -121,7 +121,7 @@ export const useJobStore = defineStore(
if (!this.jobItem) {
throw new Error('No job item to test')
}
console.log('Testing job...')
console.info('Testing job...')

const endpoint = `/index.php/apps/openconnector/api/jobs-test/${this.jobItem.id}`

Expand All @@ -136,7 +136,7 @@ export const useJobStore = defineStore(
.then((response) => response.json())
.then((data) => {
this.setJobTest(data)
console.log('Job tested')
console.info('Job tested')
// Refresh the job list
this.refreshJobLogs()
})
Expand All @@ -151,7 +151,7 @@ export const useJobStore = defineStore(
if (!id) {
throw new Error('No job item to run')
}
console.log('Running job...')
console.info('Running job...')

const endpoint = `/index.php/apps/openconnector/api/jobs-test/${id}`

Expand All @@ -165,7 +165,7 @@ export const useJobStore = defineStore(

const data = await response.json()
this.setJobRun(data)
console.log('Job run')
console.info('Job run')
// Refresh the job list
this.refreshJobLogs()

Expand All @@ -177,7 +177,7 @@ export const useJobStore = defineStore(
throw new Error('No job item to save')
}

console.log('Saving job...')
console.info('Saving job...')

const isNewJob = !jobItem.id
const endpoint = isNewJob
Expand Down Expand Up @@ -206,7 +206,7 @@ export const useJobStore = defineStore(
.then((response) => response.json())
.then((data) => {
this.setJobItem(data)
console.log('Job saved')
console.info('Job saved')
// Refresh the job list
return this.refreshJobList()
})
Expand All @@ -215,6 +215,24 @@ export const useJobStore = defineStore(
throw err
})
},
// Export a job
exportJob(jobItem) {
if (!jobItem) {
throw new Error('No job item to export')
}
importExportStore.exportFile(
jobItem.id,
jobItem.name,
'job',
)
.then(({ download }) => {
download()
})
.catch((err) => {
console.error('Error exporting job:', err)
throw err
})
},
},
},
)
1 change: 0 additions & 1 deletion src/store/modules/job.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { setActivePinia, createPinia } from 'pinia'

import { useJobStore } from './job.js'
Expand Down
15 changes: 7 additions & 8 deletions src/store/modules/log.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { defineStore } from 'pinia'
import { Log } from '../../entities/index.js'

Expand All @@ -13,21 +12,21 @@ export const useLogStore = defineStore(
actions: {
setLogItem(logItem) {
this.logItem = logItem && new Log(logItem)
console.log('Active log item set to ' + logItem)
console.info('Active log item set to ' + logItem)
},
setLogList(logList) {
this.logList = logList.map(
(logItem) => new Log(logItem),
)
console.log('Log list set to ' + logList.length + ' items')
console.info('Log list set to ' + logList.length + ' items')
},
setViewLogItem(logItem) {
this.viewLogItem = logItem
console.log('Active log item set to ' + logItem)
console.info('Active log item set to ' + logItem)
},
setActiveLogKey(activeLogKey) {
this.activeLogKey = activeLogKey
console.log('Active log key set to ' + activeLogKey)
console.info('Active log key set to ' + activeLogKey)
},
/* istanbul ignore next */ // ignore this for Jest until moved into a service
async refreshLogList(search = null) {
Expand Down Expand Up @@ -75,7 +74,7 @@ export const useLogStore = defineStore(
throw new Error('No log item to delete')
}

console.log('Deleting log...')
console.info('Deleting log...')

const endpoint = `/index.php/apps/openconnector/api/logs/${this.logItem.id}`

Expand All @@ -96,7 +95,7 @@ export const useLogStore = defineStore(
throw new Error('No log item to save')
}

console.log('Saving log...')
console.info('Saving log...')

const isNewLog = !this.logItem.id
const endpoint = isNewLog
Expand Down Expand Up @@ -125,7 +124,7 @@ export const useLogStore = defineStore(
.then((response) => response.json())
.then((data) => {
this.setLogItem(data)
console.log('Log saved')
console.info('Log saved')
// Refresh the log list
return this.refreshLogList()
})
Expand Down
1 change: 0 additions & 1 deletion src/store/modules/log.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
import { setActivePinia, createPinia } from 'pinia'

import { useLogStore } from './log.js'
Expand Down
Loading
Loading