-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jobs): resource exports UI (V4-1114, V4-1163, V4-1164)
- Loading branch information
1 parent
b939c6e
commit c256fc8
Showing
31 changed files
with
591 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<template> | ||
<div> | ||
<v-card class="mb-4" outlined> | ||
<v-toolbar flat> | ||
<v-btn color="white" :title="$t(`common.action.back`)" :to="{ name: 'user.jobs' }"> | ||
<v-icon left> | ||
$back | ||
</v-icon>{{ $t(`common.action.back`) }} | ||
</v-btn> | ||
</v-toolbar> | ||
</v-card> | ||
<v-card :flat="isMobile" :outlined="!isMobile" :tile="isMobile"> | ||
<v-tabs background-color="primary" dark> | ||
<v-tab :key="$t('user.jobs.create')" :title="$t('user.jobs.create')"> | ||
{{ $t('user.jobs.create') }} | ||
</v-tab> | ||
</v-tabs> | ||
<v-container fluid> | ||
<v-form @keydown.native="clearError" @submit.prevent="submit"> | ||
<v-row> | ||
<v-col cols="12" md="6"> | ||
<v-card-title>{{ $t('user.jobs.title') }}</v-card-title> | ||
<v-card-text> | ||
<v-select | ||
v-model="form.type" | ||
hide-details="auto" | ||
:items="jobTypeList" | ||
:label="$t('user.jobs._')" | ||
name="job" | ||
outlined | ||
prepend-inner-icon="$jobs" | ||
@change="updateJob" | ||
/> | ||
</v-card-text> | ||
</v-col> | ||
<v-col cols="12" md="6"> | ||
<component | ||
:is="form.type" | ||
v-if="Object.keys(form.params).length" | ||
v-model="form.params" | ||
:disabled="disabledJobParams[form.type]" | ||
:errors="form.errors" | ||
name="params" | ||
@input="form.errors.clear(paramErrors)" | ||
/> | ||
</v-col> | ||
</v-row> | ||
<v-row> | ||
<v-col class="px-6" cols="12" md="6"> | ||
<v-btn | ||
block | ||
color="primary" | ||
:disabled="form.errors.any() || jobInProgress || isAppLoading" | ||
:title="$t('common.action.upload')" | ||
type="submit" | ||
x-large | ||
> | ||
<v-icon left> | ||
fas fa-play | ||
</v-icon>{{ $t('common.action.submit') }} | ||
</v-btn> | ||
</v-col> | ||
</v-row> | ||
<polls-job-list v-bind="{ jobs }" /> | ||
</v-form> | ||
</v-container> | ||
</v-card> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { computed, defineComponent, onMounted } from 'vue'; | ||
import type { GetJobParams, JobParams, UserJob } from '@intake24/common/types'; | ||
import type { JobAttributes } from '@intake24/common/types/http/admin'; | ||
import { formMixin } from '@intake24/admin/components/entry'; | ||
import { jobParams, PollsJobList, usePollsForJobs } from '@intake24/admin/components/jobs'; | ||
import { useForm } from '@intake24/admin/composables'; | ||
import { userJobs } from '@intake24/common/types'; | ||
import { useI18n } from '@intake24/i18n'; | ||
type UserJobForm = { | ||
type: UserJob; | ||
params: GetJobParams<UserJob>; | ||
}; | ||
export default defineComponent({ | ||
name: 'UserJobsSubmit', | ||
components: { ...jobParams, PollsJobList }, | ||
mixins: [formMixin], | ||
setup(_props) { | ||
const { i18n } = useI18n(); | ||
const jobTypeList = computed(() => | ||
userJobs.map(value => ({ value, text: i18n.t(`jobs.types.${value}._`) })), | ||
); | ||
const defaultJobsParams = computed<Pick<JobParams, UserJob>>(() => ({ | ||
ResourceExport: { resource: 'as-served-sets' }, | ||
})); | ||
const disabledJobParams = { | ||
ResourceExport: {}, | ||
}; | ||
const { clearError, form } = useForm<UserJobForm>({ | ||
data: { type: userJobs[0], params: defaultJobsParams.value[userJobs[0]] }, | ||
config: { resetOnSubmit: false }, | ||
}); | ||
const { jobs, jobInProgress, startPolling } = usePollsForJobs(userJobs); | ||
const paramErrors = computed(() => Object.keys(form.params).map(key => `params.${key}`)); | ||
onMounted(async () => { | ||
await startPolling(true); | ||
}); | ||
const updateJob = () => { | ||
form.errors.clear(); | ||
form.params = defaultJobsParams.value[form.type]; | ||
}; | ||
const submit = async () => { | ||
if (jobInProgress.value) | ||
return; | ||
const job = await form.post<JobAttributes>(`admin/user/jobs`); | ||
jobs.value.unshift(job); | ||
await startPolling(); | ||
}; | ||
return { | ||
defaultJobsParams, | ||
disabledJobParams, | ||
jobTypeList, | ||
clearError, | ||
paramErrors, | ||
form, | ||
jobs, | ||
jobInProgress, | ||
startPolling, | ||
submit, | ||
updateJob, | ||
}; | ||
}, | ||
}); | ||
</script> | ||
|
||
<style lang="scss" scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import browse from './browse.vue'; | ||
import create from './create.vue'; | ||
import read from './read.vue'; | ||
|
||
export default { browse, read }; | ||
export default { browse, create, read }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import browse from './browse.test'; | ||
import download from './download.test'; | ||
import read from './read.test'; | ||
import submit from './submit.test'; | ||
|
||
export default { | ||
browse, | ||
read, | ||
download, | ||
submit, | ||
}; |
48 changes: 48 additions & 0 deletions
48
apps/api/__tests__/integration/admin/user/jobs/submit.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { UserJobRequest } from '@intake24/common/types/http/admin'; | ||
import { suite } from '@intake24/api-tests/integration/helpers'; | ||
|
||
export default () => { | ||
const url = '/api/admin/user/jobs'; | ||
const permissions = ['as-served-sets|browse']; | ||
|
||
const input: UserJobRequest = { | ||
type: 'ResourceExport', | ||
params: { | ||
resource: 'as-served-sets', | ||
}, | ||
}; | ||
|
||
it('missing authentication / authorization', async () => { | ||
await suite.sharedTests.assertMissingAuthentication('post', url); | ||
}); | ||
|
||
describe('authenticated / resource authorized', () => { | ||
it('should return 400 for missing input data', async () => { | ||
await suite.sharedTests.assertInvalidInput('post', url, ['type', 'params']); | ||
}); | ||
|
||
it('should return 400 for invalid input data', async () => { | ||
await suite.sharedTests.assertInvalidInput( | ||
'post', | ||
url, | ||
['type', 'params'], | ||
{ | ||
input: { | ||
type: 'not-a-job-type', | ||
params: 'invalid-params', | ||
}, | ||
}, | ||
); | ||
}); | ||
|
||
it('should return 403 when missing permissions', async () => { | ||
await suite.sharedTests.assertMissingAuthorization('post', url, { input }); | ||
}); | ||
|
||
it('should return 200 and data', async () => { | ||
// await suite.util.setPermission('as-served-sets|browse'); | ||
await suite.util.setPermission(permissions); | ||
await suite.sharedTests.assertAcknowledged('post', url, { input, result: true }); | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.