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 {useRouter} from 'vue-router'
import {QUICK_ACTIONS_ACTIVE} from '@/store/mutation-types' 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 Update from '@/components/home/update.vue'
import ListSettingsDropdown from '@/components/list/list-settings-dropdown.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 NotificationService from '@/services/notification'
import BaseButton from '@/components/base/BaseButton.vue' import BaseButton from '@/components/base/BaseButton.vue'
import User from '@/components/misc/user.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 {closeWhenClickedOutside} from '@/helpers/closeWhenClickedOutside'
import {useStore} from 'vuex' import {useStore} from 'vuex'
import {useRouter} from 'vue-router' import {useRouter} from 'vue-router'

View file

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

View file

@ -158,7 +158,7 @@ import TeamListService from '@/services/teamList'
import TeamService from '@/services/team' import TeamService from '@/services/team'
import TeamModel from '@/models/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 Multiselect from '@/components/input/multiselect.vue'
import Nothing from '@/components/misc/nothing.vue' import Nothing from '@/components/misc/nothing.vue'
import {success} from '@/message' import {success} from '@/message'

View file

@ -179,11 +179,11 @@ import EditTask from './edit-task.vue'
import TaskService from '../../services/task' import TaskService from '../../services/task'
import TaskModel from '../../models/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 PriorityLabel from './partials/priorityLabel.vue'
import TaskCollectionService from '../../services/taskCollection' import TaskCollectionService from '../../services/taskCollection'
import {mapState} from 'vuex' 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 FilterPopup from '@/components/list/partials/filter-popup.vue'
import BaseButton from '@/components/base/BaseButton.vue' import BaseButton from '@/components/base/BaseButton.vue'

View file

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

View file

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

View file

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

View file

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

View file

@ -1,12 +1,13 @@
import {objectToCamelCase} from '@/helpers/case' import {objectToCamelCase} from '@/helpers/case'
import {omitBy, isNil} from '@/helpers/utils' import {omitBy, isNil} from '@/helpers/utils'
import type {Right} from '@/models/constants/rights'
export default class AbstractModel { export default class AbstractModel {
/** /**
* The max right the user has on this object, as returned by the x-max-right header from the api. * 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. * 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 AbstractModel from './abstractModel'
import UserModel from './user' import UserModel from './user'
import {RIGHTS, type Right} from '@/models/constants/rights'
export default class LinkShareModel extends AbstractModel { export default class LinkShareModel extends AbstractModel {
id: number id: number
@ -28,7 +29,7 @@ export default class LinkShareModel extends AbstractModel {
return { return {
id: 0, id: 0,
hash: '', hash: '',
right: 0, right: RIGHTS.READ,
sharedBy: UserModel, sharedBy: UserModel,
sharingType: 0, sharingType: 0,
listId: 0, listId: 0,

View file

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

View file

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

View file

@ -1,6 +1,6 @@
import AbstractModel from './abstractModel' import AbstractModel from './abstractModel'
import type UserModel from './user' 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 { export default class UserShareBaseModel extends AbstractModel {
userId: UserModel['id'] userId: UserModel['id']
@ -18,7 +18,7 @@ export default class UserShareBaseModel extends AbstractModel {
defaults() { defaults() {
return { return {
userId: '', userId: '',
right: 0, right: RIGHTS.READ,
created: null, created: null,
updated: null, updated: null,

View file

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

View file

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

View file

@ -230,7 +230,7 @@ import cloneDeep from 'lodash.clonedeep'
import BucketModel from '../../models/bucket' import BucketModel from '../../models/bucket'
import {mapState} from 'vuex' 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 {LOADING, LOADING_MODULE} from '@/store/mutation-types'
import ListWrapper from './ListWrapper.vue' import ListWrapper from './ListWrapper.vue'
import FilterPopup from '@/components/list/partials/filter-popup.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 AddTask from '@/components/tasks/add-task.vue'
import SingleTaskInList from '@/components/tasks/partials/singleTaskInList.vue' import SingleTaskInList from '@/components/tasks/partials/singleTaskInList.vue'
import { useTaskList } from '@/composables/taskList' 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 FilterPopup from '@/components/list/partials/filter-popup.vue'
import {HAS_TASKS} from '@/store/mutation-types' import {HAS_TASKS} from '@/store/mutation-types'
import Nothing from '@/components/misc/nothing.vue' import Nothing from '@/components/misc/nothing.vue'

View file

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

View file

@ -172,7 +172,7 @@ import TeamMemberService from '../../services/teamMember'
import type TeamMemberModel from '../../models/teamMember' import type TeamMemberModel from '../../models/teamMember'
import type UserModel from '../../models/user' import type UserModel from '../../models/user'
import UserService from '../../services/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 Multiselect from '@/components/input/multiselect.vue'
import {useRoute, useRouter} from 'vue-router' import {useRoute, useRouter} from 'vue-router'