Skip to content

Commit c17228a

Browse files
committed
feat(desk): remake entry column type
1 parent 78b2e60 commit c17228a

File tree

16 files changed

+338
-166
lines changed

16 files changed

+338
-166
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,6 @@ module.exports = {
6464
'@typescript-eslint/ban-types': 'off',
6565
'@typescript-eslint/no-non-null-assertion': 'off',
6666
'vue/multi-word-component-names': 'off',
67+
'vue/no-setup-props-destructure': 'off',
6768
},
6869
}

packages/core/entities/collection.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import uuid from 'uuid-random'
22

3+
export enum CollectionColumnType {
4+
text = 'text',
5+
number = 'number',
6+
select = 'select',
7+
relation = 'relation',
8+
script = 'script',
9+
entry = 'entry',
10+
}
11+
312
export interface CollectionColumn {
413
id: string
514
field: string
6-
type: 'text' | 'number' | 'select' | 'relation' | 'script'
15+
type: CollectionColumnType
716
label: string
817
readonly?: boolean
918
[key: string]: any

packages/core/entities/directory-entry.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ export default class DirectoryEntry {
2626
return path.split('/').pop() as string
2727
}
2828

29+
public static extname(...paths: string[]) {
30+
const basename = this.basename(...paths)
31+
32+
const [, extname] = basename.split('.')
33+
34+
return extname
35+
}
36+
2937
public static directory(...paths: string[]) {
3038
const path = this.normalize(...paths)
3139

packages/core/entities/view.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import uuid from 'uuid-random'
22

3-
import { CollectionColumn } from './collection'
4-
53
export default class View {
64
public id: string
75

@@ -10,7 +8,10 @@ export default class View {
108
}
119
}
1210

13-
interface ViewTableColumn extends CollectionColumn {}
11+
export interface ViewTableColumn {
12+
id: string // link with column
13+
width: number
14+
}
1415

1516
export class ViewTable extends View {
1617
public component = 'table'

packages/desktop/App.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
<script setup lang="ts">
2+
import { watch, ref } from 'vue'
3+
import { useRoute, useRouter } from 'vue-router'
4+
import { useState } from './composables/state'
5+
26
import NNotify from '@/modules/notify/components/NNotify.vue'
7+
8+
// save last navigation
9+
const router = useRouter()
10+
const route = useRoute()
11+
const loading = ref(false)
12+
13+
const lastRoute = useState('app:router:last', '/', {
14+
localStorage: true,
15+
})
16+
17+
router.push(lastRoute.value)
18+
19+
loading.value = false
20+
21+
watch(
22+
() => route.path,
23+
(v) => (lastRoute.value = v)
24+
)
325
</script>
426
<template>
527
<n-notify />
628

7-
<router-view />
29+
<router-view v-if="!loading" />
830
</template>

packages/desktop/electron/gateways/fs-crud-folder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export default class FolderCrud implements Crud {
7878
Object.assign(data, meta)
7979
}
8080

81+
data._filename = DirectoryEntry.normalize(collectionPath, entry.name)
82+
8183
items.push(new Item(data, entry.name))
8284
}
8385

packages/desktop/i18n/en-US.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ export default {
5858
apply: 'Apply',
5959
operation: 'Operation',
6060
clear: 'Clear',
61+
upload: 'Upload',
62+
filename: 'Filename',
63+
text: 'Text',
64+
number: 'Number',
65+
select: 'Select',
66+
relation: 'Relation',
6167
errors: {
6268
workspaceNotFound: '@:workspace not found: {0}',
6369
collectionNotFound: '@:collection not found: {1}',

packages/desktop/modules/collection/components/CColumn.vue

Lines changed: 46 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,72 @@
11
<script setup lang="ts">
2-
import { CollectionColumn } from '@core/entities/collection'
3-
4-
import { updateCollectionColumn, deleteCollectionColumn } from '@/composables/collection'
2+
import { CollectionColumn, CollectionColumnType } from '@core/entities/collection'
53
64
import { computed, ref, watch } from 'vue'
75
import { useStore } from '@/modules/collection/store'
86
97
import MEditor from '@/modules/monaco/components/MEditor.vue'
8+
import { useVModel } from '@vueuse/core'
9+
import { useNonReactive } from '@/composables/utils'
10+
import { useI18n } from 'vue-i18n'
1011
12+
// Props & emits
1113
const props = defineProps({
12-
collectionId: {
13-
type: String,
14+
modelValue: {
15+
type: Object as () => CollectionColumn,
1416
required: true,
1517
},
16-
column: {
17-
type: Object as () => CollectionColumn,
18+
collectionId: {
19+
type: String,
1820
required: true,
1921
},
2022
})
2123
22-
// type options
24+
const emit = defineEmits(['update:modelValue'])
2325
24-
interface Option {
25-
label: string
26-
value: CollectionColumn['type']
27-
}
26+
// form
27+
const tm = useI18n()
28+
const model = useVModel(props, 'modelValue', emit)
2829
29-
const types: Option[] = [
30-
{
31-
label: 'Text',
32-
value: 'text',
33-
},
34-
{
35-
label: 'Number',
36-
value: 'number',
37-
},
38-
{
39-
label: 'Select',
40-
value: 'select',
41-
},
42-
// {
43-
// label: 'Entry',
44-
// value: 'entry',
45-
// },
46-
{
47-
label: 'Relation',
48-
value: 'relation',
49-
},
50-
// {
51-
// label: 'Script',
52-
// value: 'script',
53-
// },
54-
]
55-
56-
const dialog = ref(false)
57-
58-
const payload = ref<Omit<CollectionColumn, ''>>({
30+
const payload = ref<CollectionColumn>({
5931
id: '',
6032
label: '',
6133
field: '',
62-
type: 'text',
34+
type: CollectionColumnType.text,
6335
content: '',
6436
options: undefined,
6537
collectionId: undefined,
6638
displayField: undefined,
6739
})
6840
41+
const types = Object.values(CollectionColumnType).map((v) => ({
42+
label: tm.t(v),
43+
value: v,
44+
}))
45+
46+
async function submit() {
47+
model.value = useNonReactive(payload.value)
48+
49+
dialog.value = false
50+
}
51+
52+
// icons
6953
const icons: Record<CollectionColumn['type'], any> = {
7054
text: 'font',
7155
number: 'hashtag',
7256
select: 'fa-regular fa-square-caret-down',
7357
relation: 'arrow-up',
7458
script: 'code',
59+
entry: 'file',
7560
}
7661
77-
function load() {
78-
Object.keys(payload.value).forEach((key) => {
79-
payload.value[key] = props.column[key]
80-
})
81-
}
82-
83-
watch(() => props.column, load, { immediate: true, deep: true })
84-
85-
async function submit() {
86-
if (payload.value.type !== 'select') {
87-
payload.value.options = undefined
88-
}
62+
// dialog
63+
const dialog = ref(false)
8964
90-
// await updateCollectionColumn(
91-
// props.workspaceId,
92-
// props.collectionId,
93-
// props.column.id,
94-
// payload.value
95-
// )
65+
watch(dialog, (value) => {
66+
if (!value) return
9667
97-
dialog.value = false
98-
}
68+
payload.value = useNonReactive(model.value)
69+
})
9970
10071
async function deleteColumn() {
10172
// await deleteCollectionColumn(props.workspaceId, props.collectionId, props.column.id)
@@ -127,14 +98,14 @@ const options = computed(() => {
12798
class="cursor-pointer text-t-secondary text-sm flex items-center overflow-hidden"
12899
v-bind="{ ...attrs, ...$attrs }"
129100
>
130-
<fa-icon :icon="icons[column.type] || 'font'" class="mr-2 text-xs" />
101+
<fa-icon :icon="icons[model.type] || 'font'" class="mr-2 text-xs" />
131102

132-
{{ column.label }}
103+
{{ model.label }}
133104
</div>
134105
</template>
135106

136107
<v-card width="500" color="b-secondary">
137-
<v-card-head>
108+
<v-card-head class="px-4">
138109
<v-card-title>
139110
{{ $t('editEntity', [$t('column')]) }}
140111
</v-card-title>
@@ -217,8 +188,16 @@ const options = computed(() => {
217188
</v-card>
218189
</is-drawer>
219190

191+
<div v-if="payload.type === 'entry'" class="mb-4">
192+
<is-input
193+
v-model="payload.filename"
194+
:label="$t('filename')"
195+
placeholder="thumbnail.jpg"
196+
/>
197+
</div>
198+
220199
<div>
221-
<v-btn class="w-full">{{ $t('save') }}</v-btn>
200+
<v-btn type="submit" class="w-full">{{ $t('save') }}</v-btn>
222201
</div>
223202
</w-form>
224203
</v-card-content>

0 commit comments

Comments
 (0)