Skip to content

Commit

Permalink
Add priority and scheduledAt to jobs. (#163)
Browse files Browse the repository at this point in the history
Add priority and scheduledAt to jobs.
  • Loading branch information
sakulb authored Jan 22, 2024
1 parent 8657326 commit e8aa811
Show file tree
Hide file tree
Showing 10 changed files with 162 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"stylelint-config-standard-scss": "^13.0.0",
"typescript": "5.3.3",
"uuid": "^9.0.1",
"vite": "5.0.11",
"vite": "5.0.12",
"vite-plugin-dts": "^3.7.0",
"vite-plugin-vuetify": "^2.0.1",
"vitepress": "1.0.0-rc.36",
Expand Down
36 changes: 36 additions & 0 deletions src/components/job/AJobBaseCreateForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<script setup lang="ts">
import { computed } from 'vue'
import type { JobBase } from '@/types/Job'
import { useJobPriority } from '@/components/job/composables/jobPriority'
import ARow from '@/components/ARow.vue'
import AFormDatetimePicker from '@/components/form/AFormDatetimePicker.vue'
import { useI18n } from 'vue-i18n'
const modelValue = defineModel<JobBase>({ required: true })
const { priorityLabels, getPriorityColor } = useJobPriority()
const sliderColor = computed(() => {
return getPriorityColor(modelValue.value.priority)
})
const { t } = useI18n()
</script>

<template>
<ARow>
<AFormDatetimePicker
v-model="modelValue.scheduledAt"
:label="t('common.job.model.scheduledAt')"
/>
</ARow>
<ARow>
<VSlider
v-model="modelValue.priority"
:ticks="priorityLabels"
:max="2"
step="1"
show-ticks="always"
tick-size="3"
:color="sliderColor"
/>
</ARow>
</template>
7 changes: 7 additions & 0 deletions src/components/job/AJobDetailCommon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useI18n } from 'vue-i18n'
import ARow from '@/components/ARow.vue'
import AJobStatusChip from '@/components/job/AJobStatusChip.vue'
import ADatetime from '@/components/ADatetime.vue'
import AJobPriorityChip from '@/components/job/AJobPriorityChip.vue'
withDefaults(
defineProps<{
Expand Down Expand Up @@ -32,6 +33,12 @@ const { t } = useI18n()
<ARow :title="t('common.job.model.status')">
<AJobStatusChip :value="job.status" />
</ARow>
<ARow :title="t('common.job.model.priority')">
<AJobPriorityChip :priority="job.priority" />
</ARow>
<ARow :title="t('common.job.model.scheduledAt')">
<ADatetime :date-time="job.scheduledAt" />
</ARow>
<ARow :title="t('common.job.model.startedAt')">
<ADatetime :date-time="job.startedAt" />
</ARow>
Expand Down
25 changes: 25 additions & 0 deletions src/components/job/AJobPriorityChip.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script setup lang="ts">
import { computed } from 'vue'
import { useJobPriority } from '@/components/job/composables/jobPriority'
import AChipNoLink from '@/components/AChipNoLink.vue'
const props = defineProps<{
priority: number
}>()
const { getPriorityLabel, getPriorityColor } = useJobPriority()
const priorityColor = computed(() => {
return getPriorityColor(props.priority)
})
const priorityLabel = computed(() => {
return getPriorityLabel(props.priority)
})
</script>

<template>
<AChipNoLink
:color="priorityColor"
>
{{ priorityLabel }}
</AChipNoLink>
</template>
33 changes: 33 additions & 0 deletions src/components/job/composables/jobPriority.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { objectGetValueByPath } from '@/lib'

export const useJobPriority = () => {
const { t } = useI18n()
const priorityLabels = computed(() => {
return {
0: t('common.job.meta.priority.low'),
1: t('common.job.meta.priority.medium'),
2: t('common.job.meta.priority.high'),
}
})

const getPriorityColor = (priority: Number): string => {
switch (priority) {
case 0: return 'amber'
case 1: return 'primary'
case 2: return 'red'
default: return 'default'
}
}

const getPriorityLabel = (priority: Number): string => {
return objectGetValueByPath(priorityLabels.value, priority.toString()) ?? priority.toString()
}

return {
priorityLabels,
getPriorityColor,
getPriorityLabel,
}
}
4 changes: 4 additions & 0 deletions src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ import ALogoutView from '@/components/view/ALogoutView.vue'
import AUnauthorizedView from '@/components/view/AUnauthorizedView.vue'
import ANotFoundView from '@/components/view/ANotFoundView.vue'
import AJobDetailCommon from '@/components/job/AJobDetailCommon.vue'
import AJobPriorityChip from '@/components/job/AJobPriorityChip.vue'
import AJobBaseCreateForm from '@/components/job/AJobBaseCreateForm.vue'
import AAssetSelect from '@/components/dam/assetSelect/AAssetSelect.vue'
import ASortable from '@/components/sortable/ASortable.vue'
import ASortableNested from '@/components/sortable/ASortableNested.vue'
Expand Down Expand Up @@ -541,6 +543,8 @@ export {
ACurrentUserDropdown,
AFormRemoteAutocompleteWithCached,
AJobDetailCommon,
AJobPriorityChip,
AJobBaseCreateForm,
ASortable,
ASortableNested,
ASubjectSelect,
Expand Down
9 changes: 9 additions & 0 deletions src/locales/sk/common/job.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@
"model": {
"id": "Id",
"_resourceName": "Typ",
"priority": "Priorita",
"scheduledAt": "Čas spustenia",
"status": "Stav",
"startedAt": "Spustený",
"finishedAt": "Ukončený",
"result": "Výsledok",
"targetUserId": "Cieľový používateľ",
"anonymizeUser": "Anonymizuj používateľa"
},
"meta": {
"priority": {
"low": "Nízka",
"medium": "Normálna",
"high": "Vysoká"
}
},
"jobResource": {
"jobUserDataDelete": "Výmaz používateľových dát"
},
Expand Down
2 changes: 2 additions & 0 deletions src/model/factory/JobFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export function useCommonJobFactory() {
const createBase = (resourceName: JobBaseResource, system: string): JobBase => {
return {
id: 0,
scheduledAt: dateTimeNow(),
priority: 1,
status: JobStatus.Default,
result: '',
batchProcessedIterationCount: 0,
Expand Down
4 changes: 3 additions & 1 deletion src/types/Job.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import type { DatetimeUTCNullable, IntegerId, IntegerIdNullable } from '@/types/common'
import type { DatetimeUTC, DatetimeUTCNullable, IntegerId, IntegerIdNullable } from '@/types/common'
import type { AnzuUserAndTimeTrackingAware } from '@/types/AnzuUserAndTimeTrackingAware'
import type { JobBaseResource } from '@/model/valueObject/JobBaseResource'
import type { JobStatus } from '@/model/valueObject/JobStatus'

export interface JobBase<T extends JobBaseResource = JobBaseResource> extends AnzuUserAndTimeTrackingAware {
readonly id: IntegerId
scheduledAt: DatetimeUTC
priority: number
readonly status: JobStatus
readonly startedAt: DatetimeUTCNullable
readonly finishedAt: DatetimeUTCNullable
Expand Down
44 changes: 42 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ __metadata:
stylelint-config-standard-scss: "npm:^13.0.0"
typescript: "npm:5.3.3"
uuid: "npm:^9.0.1"
vite: "npm:5.0.11"
vite: "npm:5.0.12"
vite-plugin-dts: "npm:^3.7.0"
vite-plugin-vuetify: "npm:^2.0.1"
vitepress: "npm:1.0.0-rc.36"
Expand Down Expand Up @@ -6892,7 +6892,47 @@ __metadata:
languageName: node
linkType: hard

"vite@npm:5.0.11, vite@npm:^5.0.11":
"vite@npm:5.0.12":
version: 5.0.12
resolution: "vite@npm:5.0.12"
dependencies:
esbuild: "npm:^0.19.3"
fsevents: "npm:~2.3.3"
postcss: "npm:^8.4.32"
rollup: "npm:^4.2.0"
peerDependencies:
"@types/node": ^18.0.0 || >=20.0.0
less: "*"
lightningcss: ^1.21.0
sass: "*"
stylus: "*"
sugarss: "*"
terser: ^5.4.0
dependenciesMeta:
fsevents:
optional: true
peerDependenciesMeta:
"@types/node":
optional: true
less:
optional: true
lightningcss:
optional: true
sass:
optional: true
stylus:
optional: true
sugarss:
optional: true
terser:
optional: true
bin:
vite: bin/vite.js
checksum: ed0bb26a0d0c8e1dae0b70af9e36adffd7e15d80297443fe4da762596dc81570bad7f0291f590a57c1553f5e435338d8c7ffc483bd9431a95c09d9ac90665fad
languageName: node
linkType: hard

"vite@npm:^5.0.11":
version: 5.0.11
resolution: "vite@npm:5.0.11"
dependencies:
Expand Down

0 comments on commit e8aa811

Please sign in to comment.