feat: constants

This commit is contained in:
Dominik Pschenitschni 2022-06-23 03:14:58 +02:00
parent af630d3b8c
commit 8fb00653e4
No known key found for this signature in database
GPG key ID: B257AC0149F43A77
27 changed files with 61 additions and 94 deletions

View file

@ -92,7 +92,7 @@ import {useStore} from 'vuex'
import {useRouter} from 'vue-router'
import {QUICK_ACTIONS_ACTIVE} from '@/store/mutation-types'
import Rights from '@/models/constants/rights.json'
import {RIGHTS as Rights} from '@/models/constants/rights'
import Update from '@/components/home/update.vue'
import ListSettingsDropdown from '@/components/list/list-settings-dropdown.vue'

View file

@ -52,7 +52,7 @@ import {computed, onMounted, onUnmounted, ref} from 'vue'
import NotificationService from '@/services/notification'
import BaseButton from '@/components/base/BaseButton.vue'
import User from '@/components/misc/user.vue'
import names from '@/models/constants/notificationNames.json'
import NotificationModel, { NOTIFICATION_NAMES as names} from '@/models/notification'
import {closeWhenClickedOutside} from '@/helpers/closeWhenClickedOutside'
import {useStore} from 'vuex'
import {useRouter} from 'vue-router'

View file

@ -180,7 +180,7 @@ import {ref, watch, computed, shallowReactive} from 'vue'
import {useStore} from 'vuex'
import {useI18n} from 'vue-i18n'
import RIGHTS from '@/models/constants/rights.json'
import {RIGHTS} from '@/models/constants/rights'
import LinkShareModel from '@/models/linkShare'
import LinkShareService from '@/services/linkShare'

View file

@ -158,7 +158,7 @@ import TeamListService from '@/services/teamList'
import TeamService from '@/services/team'
import TeamModel from '@/models/team'
import RIGHTS from '@/models/constants/rights.json'
import {RIGHTS} from '@/models/constants/rights'
import Multiselect from '@/components/input/multiselect.vue'
import Nothing from '@/components/misc/nothing.vue'
import {success} from '@/message'

View file

@ -179,11 +179,11 @@ import EditTask from './edit-task.vue'
import TaskService from '../../services/task'
import TaskModel from '../../models/task'
import priorities from '../../models/constants/priorities'
import {PRIORITIES as priorities} from '@/models/constants/priorities'
import PriorityLabel from './partials/priorityLabel.vue'
import TaskCollectionService from '../../services/taskCollection'
import {mapState} from 'vuex'
import Rights from '../../models/constants/rights.json'
import {RIGHTS as Rights} from '@/models/constants/rights'
import FilterPopup from '@/components/list/partials/filter-popup.vue'
import BaseButton from '@/components/base/BaseButton.vue'

View file

@ -21,7 +21,7 @@
</template>
<script setup lang="ts">
import priorities from '@/models/constants/priorities'
import {PRIORITIES as priorities} from '@/models/constants/priorities'
defineProps({
priority: {

View file

@ -5,19 +5,19 @@
@change="updateData"
:disabled="disabled || undefined"
>
<option :value="priorities.UNSET">{{ $t('task.priority.unset') }}</option>
<option :value="priorities.LOW">{{ $t('task.priority.low') }}</option>
<option :value="priorities.MEDIUM">{{ $t('task.priority.medium') }}</option>
<option :value="priorities.HIGH">{{ $t('task.priority.high') }}</option>
<option :value="priorities.URGENT">{{ $t('task.priority.urgent') }}</option>
<option :value="priorities.DO_NOW">{{ $t('task.priority.doNow') }}</option>
<option :value="PRIORITIES.UNSET">{{ $t('task.priority.unset') }}</option>
<option :value="PRIORITIES.LOW">{{ $t('task.priority.low') }}</option>
<option :value="PRIORITIES.MEDIUM">{{ $t('task.priority.medium') }}</option>
<option :value="PRIORITIES.HIGH">{{ $t('task.priority.high') }}</option>
<option :value="PRIORITIES.URGENT">{{ $t('task.priority.urgent') }}</option>
<option :value="PRIORITIES.DO_NOW">{{ $t('task.priority.doNow') }}</option>
</select>
</div>
</template>
<script setup lang="ts">
import {ref, watch} from 'vue'
import priorities from '@/models/constants/priorities.json'
import {PRIORITIES} from '@/models/constants/priorities'
const priority = ref(0)

View file

@ -144,8 +144,7 @@ import {defineComponent} from 'vue'
import TaskService from '../../../services/task'
import TaskModel from '../../../models/task'
import TaskRelationService from '../../../services/taskRelation'
import relationKinds from '../../../models/constants/relationKinds'
import TaskRelationModel from '../../../models/taskRelation'
import TaskRelationModel, {RELATION_KINDS} from '@/models/taskRelation'
import BaseButton from '@/components/base/BaseButton.vue'
import Multiselect from '@/components/input/multiselect.vue'
@ -157,7 +156,7 @@ export default defineComponent({
relatedTasks: {},
taskService: new TaskService(),
foundTasks: [],
relationKinds: relationKinds,
relationKinds: RELATION_KINDS,
newTaskRelationTask: new TaskModel(),
newTaskRelationKind: 'related',
taskRelationService: new TaskRelationService(),

View file

@ -18,17 +18,14 @@
<div class="control">
<div class="select">
<select @change="updateData" v-model="task.repeatMode" id="repeatMode">
<option :value="repeatModes.REPEAT_MODE_DEFAULT">{{ $t('misc.default') }}</option>
<option :value="repeatModes.REPEAT_MODE_MONTH">{{ $t('task.repeat.monthly') }}</option>
<option :value="repeatModes.REPEAT_MODE_FROM_CURRENT_DATE">{{
$t('task.repeat.fromCurrentDate')
}}
</option>
<option :value="TASK_REPEAT_MODES.REPEAT_MODE_DEFAULT">{{ $t('misc.default') }}</option>
<option :value="TASK_REPEAT_MODES.REPEAT_MODE_MONTH">{{ $t('task.repeat.monthly') }}</option>
<option :value="TASK_REPEAT_MODES.REPEAT_MODE_FROM_CURRENT_DATE">{{ $t('task.repeat.fromCurrentDate') }}</option>
</select>
</div>
</div>
</div>
<div class="is-flex" v-if="task.repeatMode !== repeatModes.REPEAT_MODE_MONTH">
<div class="is-flex" v-if="task.repeatMode !== TASK_REPEAT_MODES.REPEAT_MODE_MONTH">
<p class="pr-4">
{{ $t('task.repeat.each') }}
</p>
@ -66,10 +63,10 @@
<script setup lang="ts">
import {ref, reactive, watch} from 'vue'
import repeatModes from '@/models/constants/taskRepeatModes.json'
import TaskModel from '@/models/task'
import {error} from '@/message'
import {useI18n} from 'vue-i18n'
import type TaskModel from '@/models/task'
import {TASK_REPEAT_MODES, type RepeatAfter} from '@/models/task'
const props = defineProps({
modelValue: {
@ -104,7 +101,7 @@ watch(
)
function updateData() {
if (task.value.repeatMode !== repeatModes.REPEAT_MODE_DEFAULT && repeatAfter.amount === 0) {
if (!task.value || task.value.repeatMode !== TASK_REPEAT_MODES.REPEAT_MODE_DEFAULT && repeatAfter.amount === 0) {
return
}
@ -118,8 +115,8 @@ function updateData() {
emit('change')
}
function setRepeatAfter(amount: number, type) {
Object.assign(repeatAfter, {amount, type})
function setRepeatAfter(amount: number, type: RepeatAfter['type']) {
Object.assign(repeatAfter, { amount, type})
updateData()
}
</script>

View file

@ -1,12 +1,13 @@
import {objectToCamelCase} from '@/helpers/case'
import {omitBy, isNil} from '@/helpers/utils'
import type {Right} from '@/models/constants/rights'
export default class AbstractModel {
/**
* The max right the user has on this object, as returned by the x-max-right header from the api.
*/
maxRight: number | null = null
maxRight: Right | null = null
/**
* The abstract constructor takes an object and merges its data with the default data of this model.

View file

@ -1,7 +0,0 @@
{
"TASK_COMMENT": "task.comment",
"TASK_ASSIGNED": "task.assigned",
"TASK_DELETED": "task.deleted",
"LIST_CREATED": "list.created",
"TEAM_MEMBER_ADDED": "team.member.added"
}

View file

@ -1,8 +0,0 @@
{
"UNSET": 0,
"LOW": 1,
"MEDIUM": 2,
"HIGH": 3,
"URGENT": 4,
"DO_NOW": 5
}

View file

@ -0,0 +1,8 @@
export const PRIORITIES = {
'UNSET': 0,
'LOW': 1,
'MEDIUM': 2,
'HIGH': 3,
'URGENT': 4,
'DO_NOW': 5,
} as const

View file

@ -1,12 +0,0 @@
[
"subtask",
"parenttask",
"related",
"duplicates",
"blocking",
"blocked",
"precedes",
"follows",
"copiedfrom",
"copiedto"
]

View file

@ -1,5 +0,0 @@
{
"READ": 0,
"READ_WRITE": 1,
"ADMIN": 2
}

View file

@ -0,0 +1,7 @@
export const RIGHTS = {
'READ': 0,
'READ_WRITE': 1,
'ADMIN': 2,
} as const
export type Right = typeof RIGHTS[keyof typeof RIGHTS]

View file

@ -1,5 +0,0 @@
{
"REPEAT_MODE_DEFAULT": 0,
"REPEAT_MODE_MONTH": 1,
"REPEAT_MODE_FROM_CURRENT_DATE": 2
}

View file

@ -1,5 +1,6 @@
import AbstractModel from './abstractModel'
import UserModel from './user'
import {RIGHTS, type Right} from '@/models/constants/rights'
export default class LinkShareModel extends AbstractModel {
id: number
@ -28,7 +29,7 @@ export default class LinkShareModel extends AbstractModel {
return {
id: 0,
hash: '',
right: 0,
right: RIGHTS.READ,
sharedBy: UserModel,
sharingType: 0,
listId: 0,

View file

@ -1,6 +1,7 @@
import AbstractModel from './abstractModel'
import UserModel from './user'
import TeamMemberModel from './teamMember'
import {RIGHTS, type Right} from '@/models/constants/rights'
export default class TeamModel extends AbstractModel {
id: 0
@ -32,7 +33,7 @@ export default class TeamModel extends AbstractModel {
name: '',
description: '',
members: [],
right: 0,
right: RIGHTS.READ,
createdBy: {},
created: null,

View file

@ -1,6 +1,6 @@
import AbstractModel from './abstractModel'
import type TeamModel from './team'
import type {Right} from '@/models/constants/rights'
import {RIGHTS, type Right} from '@/models/constants/rights'
/**
* This class is a base class for common team sharing model.
@ -22,7 +22,7 @@ export default class TeamShareBaseModel extends AbstractModel {
defaults() {
return {
teamId: 0,
right: 0,
right: RIGHTS.READ,
created: null,
updated: null,

View file

@ -1,6 +1,6 @@
import AbstractModel from './abstractModel'
import type UserModel from './user'
import type {Right} from '@/models/constants/rights'
import {RIGHTS, type Right} from '@/models/constants/rights'
export default class UserShareBaseModel extends AbstractModel {
userId: UserModel['id']
@ -18,7 +18,7 @@ export default class UserShareBaseModel extends AbstractModel {
defaults() {
return {
userId: '',
right: 0,
right: RIGHTS.READ,
created: null,
updated: null,

View file

@ -3,7 +3,7 @@ import {beforeEach, afterEach, describe, it, expect, vi} from 'vitest'
import {parseTaskText} from './parseTaskText'
import {getDateFromText, getDateFromTextIn} from '../helpers/time/parseDate'
import {calculateDayInterval} from '../helpers/time/calculateDayInterval'
import priorities from '../models/constants/priorities.json'
import {PRIORITIES} from '@/models/constants/priorities.ts'
describe('Parse Task Text', () => {
beforeEach(() => {
@ -571,12 +571,12 @@ describe('Parse Task Text', () => {
})
describe('Priority', () => {
for (const p in priorities) {
for (const p in PRIORITIES) {
it(`should parse priority ${p}`, () => {
const result = parseTaskText(`Lorem Ipsum !${priorities[p]}`)
const result = parseTaskText(`Lorem Ipsum !${PRIORITIES[p]}`)
expect(result.text).toBe('Lorem Ipsum')
expect(result.priority).toBe(priorities[p])
expect(result.priority).toBe(PRIORITIES[p])
})
}
it(`should not parse an invalid priority`, () => {

View file

@ -1,5 +1,5 @@
import {parseDate} from '../helpers/time/parseDate'
import _priorities from '../models/constants/priorities.json'
import {PRIORITIES} from '@/models/constants/priorities'
const VIKUNJA_PREFIXES: Prefixes = {
label: '*',
@ -27,16 +27,7 @@ export const PREFIXES = {
[PrefixMode.Todoist]: TODOIST_PREFIXES,
}
const priorities: Priorites = _priorities
interface Priorites {
UNSET: number,
LOW: number,
MEDIUM: number,
HIGH: number,
URGENT: number,
DO_NOW: number,
}
const priorities = PRIORITIES
enum RepeatType {
Hours = 'hours',

View file

@ -230,7 +230,7 @@ import cloneDeep from 'lodash.clonedeep'
import BucketModel from '../../models/bucket'
import {mapState} from 'vuex'
import Rights from '../../models/constants/rights.json'
import {RIGHTS as Rights} from '@/models/constants/rights'
import {LOADING, LOADING_MODULE} from '@/store/mutation-types'
import ListWrapper from './ListWrapper.vue'
import FilterPopup from '@/components/list/partials/filter-popup.vue'

View file

@ -144,7 +144,7 @@ import EditTask from '@/components/tasks/edit-task.vue'
import AddTask from '@/components/tasks/add-task.vue'
import SingleTaskInList from '@/components/tasks/partials/singleTaskInList.vue'
import { useTaskList } from '@/composables/taskList'
import Rights from '../../models/constants/rights.json'
import {RIGHTS as Rights} from '@/models/constants/rights'
import FilterPopup from '@/components/list/partials/filter-popup.vue'
import {HAS_TASKS} from '@/store/mutation-types'
import Nothing from '@/components/misc/nothing.vue'

View file

@ -427,8 +427,8 @@ import {defineComponent} from 'vue'
import TaskService from '../../services/task'
import TaskModel from '../../models/task'
import priorites from '../../models/constants/priorities.json'
import rights from '../../models/constants/rights.json'
import { PRIORITIES as priorites } from '@/models/constants/priorities'
import {RIGHTS as rights} from '@/models/constants/rights'
import PrioritySelect from '../../components/tasks/partials/prioritySelect.vue'
import PercentDoneSelect from '../../components/tasks/partials/percentDoneSelect.vue'
@ -520,7 +520,6 @@ export default defineComponent({
// Used to avoid flashing of empty elements if the task content is not yet loaded.
visible: false,
priorities: priorites,
activeFields: {
assignees: false,
priority: false,

View file

@ -172,7 +172,7 @@ import TeamMemberService from '../../services/teamMember'
import type TeamMemberModel from '../../models/teamMember'
import type UserModel from '../../models/user'
import UserService from '../../services/user'
import Rights from '../../models/constants/rights.json'
import {RIGHTS as Rights} from '@/models/constants/rights'
import Multiselect from '@/components/input/multiselect.vue'
import {useRoute, useRouter} from 'vue-router'