Browse Source

Simplify label type addition page

refactor/labelTypePage
Hironsan 2 years ago
parent
commit
94d0456720
4 changed files with 22 additions and 45 deletions
  1. 6
      frontend/components/layout/TheSideBar.vue
  2. 20
      frontend/domain/models/label/label.ts
  3. 1
      frontend/nuxt.config.js
  4. 40
      frontend/pages/projects/_id/labels/add.vue

6
frontend/components/layout/TheSideBar.vue

@ -87,12 +87,6 @@ export default {
link: 'labels',
isVisible: this.isProjectAdmin && this.project.canDefineLabel
},
{
icon: mdiLabel,
text: 'Relations',
link: 'links',
isVisible: this.isProjectAdmin && this.project.canDefineRelation
},
{
icon: mdiAccount,
text: this.$t('members.members'),

20
frontend/domain/models/label/label.ts

@ -1,18 +1,18 @@
export class LabelItem {
constructor(
readonly id: number,
readonly text: string,
readonly prefixKey: string | null,
readonly suffixKey: string | null,
readonly backgroundColor: string,
readonly textColor: string = '#ffffff'
public id: number,
public text: string = '',
public prefixKey: string | null = null,
public suffixKey: string | null = null,
public backgroundColor: string = '#73D8FF',
public textColor: string = '#ffffff'
) {}
static create(
text: string,
prefixKey: string | null,
suffixKey: string | null,
backgroundColor: string
text: string = '',
prefixKey: string | null = null,
suffixKey: string | null = null,
backgroundColor: string = '#73D8FF'
): LabelItem {
return new LabelItem(0, text, prefixKey, suffixKey, backgroundColor)
}

1
frontend/nuxt.config.js

@ -46,6 +46,7 @@ export default {
'~/plugins/vue-shortkey.js',
'~/plugins/vue-konva.js',
'~/plugins/services.ts',
'~/plugins/repositories.ts',
'~/plugins/color.ts',
'~/plugins/role.ts'
],

40
frontend/pages/projects/_id/labels/add.vue

@ -18,8 +18,9 @@
<script lang="ts">
import Vue from 'vue'
import { LabelDTO } from '~/services/application/label/labelData'
import { ProjectDTO } from '~/services/application/project/projectData'
import { LabelItem } from '~/domain/models/label/label'
import { LabelRepository } from '~/domain/models/label/labelRepository'
import FormCreate from '~/components/label/FormCreate.vue'
export default Vue.extend({
@ -43,21 +44,8 @@ export default Vue.extend({
data() {
return {
editedItem: {
text: '',
prefixKey: null,
suffixKey: null,
backgroundColor: '#73D8FF',
textColor: '#ffffff'
} as LabelDTO,
defaultItem: {
text: '',
prefixKey: null,
suffixKey: null,
backgroundColor: '#73D8FF',
textColor: '#ffffff'
} as LabelDTO,
items: [] as LabelDTO[]
editedItem: LabelItem.create(),
items: [] as LabelItem[]
}
},
@ -66,32 +54,26 @@ export default Vue.extend({
return this.$route.params.id
},
service(): any {
repository(): LabelRepository {
const type = this.$route.query.type
if (type === 'category') {
return this.$services.categoryType
} else if (type === 'span') {
return this.$services.spanType
} else {
return this.$services.relationType
}
return this.$repositories[`${type}Type`]
}
},
async created() {
this.items = await this.service.list(this.projectId)
this.items = await this.repository.list(this.projectId)
},
methods: {
async save() {
await this.service.create(this.projectId, this.editedItem)
await this.repository.create(this.projectId, this.editedItem)
this.$router.push(`/projects/${this.projectId}/labels`)
},
async saveAndAnother() {
await this.service.create(this.projectId, this.editedItem)
this.editedItem = Object.assign({}, this.defaultItem)
this.items = await this.service.list(this.projectId)
await this.repository.create(this.projectId, this.editedItem)
this.editedItem = LabelItem.create()
this.items = await this.repository.list(this.projectId)
}
}
})

Loading…
Cancel
Save