@dative-gpi/foundation-shared-components 1.0.20 → 1.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/fields/FSTimeStepField.vue +157 -0
- package/package.json +4 -4
- package/utils/time.ts +15 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<FSBaseField
|
|
3
|
+
:description="$props.description"
|
|
4
|
+
:hideHeader="$props.hideHeader"
|
|
5
|
+
:required="$props.required"
|
|
6
|
+
:editable="$props.editable"
|
|
7
|
+
:label="$props.label"
|
|
8
|
+
:messages="messages"
|
|
9
|
+
>
|
|
10
|
+
<FSRow>
|
|
11
|
+
<FSNumberField
|
|
12
|
+
:validationValue="$props.modelValue"
|
|
13
|
+
:editable="$props.editable"
|
|
14
|
+
:validateOn="validateOn"
|
|
15
|
+
:rules="$props.rules"
|
|
16
|
+
:hideHeader="true"
|
|
17
|
+
:messages="messages"
|
|
18
|
+
:modelValue="$props.modelValue.value"
|
|
19
|
+
@update:modelValue="$emit('update:modelValue', { value: $event, unit: $props.modelValue.unit })"
|
|
20
|
+
v-bind="$attrs"
|
|
21
|
+
>
|
|
22
|
+
<template
|
|
23
|
+
v-for="(_, name) in numberSlots"
|
|
24
|
+
v-slot:[name]="slotData"
|
|
25
|
+
>
|
|
26
|
+
<slot
|
|
27
|
+
:name="name"
|
|
28
|
+
v-bind="slotData"
|
|
29
|
+
/>
|
|
30
|
+
</template>
|
|
31
|
+
</FSNumberField>
|
|
32
|
+
<FSSelectField
|
|
33
|
+
class="fs-time-field-select"
|
|
34
|
+
:editable="$props.editable"
|
|
35
|
+
:hideHeader="true"
|
|
36
|
+
:clearable="false"
|
|
37
|
+
:items="units"
|
|
38
|
+
:modelValue="$props.modelValue.unit"
|
|
39
|
+
@update:modelValue="$emit('update:modelValue', { value: $props.modelValue.value, unit: $event })"
|
|
40
|
+
>
|
|
41
|
+
<template
|
|
42
|
+
v-for="(_, name) in selectSlots"
|
|
43
|
+
v-slot:[name]="slotData"
|
|
44
|
+
>
|
|
45
|
+
<slot
|
|
46
|
+
:name="name"
|
|
47
|
+
v-bind="slotData"
|
|
48
|
+
/>
|
|
49
|
+
</template>
|
|
50
|
+
</FSSelectField>
|
|
51
|
+
</FSRow>
|
|
52
|
+
</FSBaseField>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<script lang="ts">
|
|
56
|
+
import { computed, defineComponent, type PropType } from "vue";
|
|
57
|
+
|
|
58
|
+
import type { TimeUnit } from "@dative-gpi/foundation-shared-domain/models";
|
|
59
|
+
|
|
60
|
+
import { useRules, useSlots } from "@dative-gpi/foundation-shared-components/composables";
|
|
61
|
+
import { timeSteps } from "@dative-gpi/foundation-shared-components/utils";
|
|
62
|
+
|
|
63
|
+
import FSNumberField from "./FSNumberField.vue";
|
|
64
|
+
import FSSelectField from "./FSSelectField.vue";
|
|
65
|
+
import FSBaseField from "./FSBaseField.vue";
|
|
66
|
+
import FSRow from "../FSRow.vue";
|
|
67
|
+
|
|
68
|
+
export default defineComponent({
|
|
69
|
+
name: "FSTimeStepField",
|
|
70
|
+
components: {
|
|
71
|
+
FSNumberField,
|
|
72
|
+
FSSelectField,
|
|
73
|
+
FSBaseField,
|
|
74
|
+
FSRow
|
|
75
|
+
},
|
|
76
|
+
props: {
|
|
77
|
+
label: {
|
|
78
|
+
type: String as PropType<string | null>,
|
|
79
|
+
required: false,
|
|
80
|
+
default: null
|
|
81
|
+
},
|
|
82
|
+
description: {
|
|
83
|
+
type: String as PropType<string | null>,
|
|
84
|
+
required: false,
|
|
85
|
+
default: null
|
|
86
|
+
},
|
|
87
|
+
modelValue: {
|
|
88
|
+
type: Object as PropType<{ value: number, unit: TimeUnit }>,
|
|
89
|
+
required: true
|
|
90
|
+
},
|
|
91
|
+
allowedUnits: {
|
|
92
|
+
type: Array as PropType<TimeUnit[]>,
|
|
93
|
+
required: false,
|
|
94
|
+
default: () => []
|
|
95
|
+
},
|
|
96
|
+
hideHeader: {
|
|
97
|
+
type: Boolean,
|
|
98
|
+
required: false,
|
|
99
|
+
default: false
|
|
100
|
+
},
|
|
101
|
+
required: {
|
|
102
|
+
type: Boolean,
|
|
103
|
+
required: false,
|
|
104
|
+
default: false
|
|
105
|
+
},
|
|
106
|
+
rules: {
|
|
107
|
+
type: Array as PropType<any[]>,
|
|
108
|
+
required: false,
|
|
109
|
+
default: () => []
|
|
110
|
+
},
|
|
111
|
+
messages: {
|
|
112
|
+
type: Array as PropType<string[]>,
|
|
113
|
+
required: false,
|
|
114
|
+
default: null
|
|
115
|
+
},
|
|
116
|
+
editable: {
|
|
117
|
+
type: Boolean,
|
|
118
|
+
required: false,
|
|
119
|
+
default: true
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
emits: ["update:modelValue"],
|
|
123
|
+
setup(props) {
|
|
124
|
+
const { validateOn, getMessages } = useRules();
|
|
125
|
+
const { slots } = useSlots();
|
|
126
|
+
|
|
127
|
+
delete slots.label;
|
|
128
|
+
delete slots.description;
|
|
129
|
+
|
|
130
|
+
const numberSlots = computed((): any => {
|
|
131
|
+
return Object.keys(slots).filter(k => k.startsWith("number-")).reduce((acc, key) => {
|
|
132
|
+
acc[key.substring("number-".length)] = slots[key];
|
|
133
|
+
return acc;
|
|
134
|
+
}, {});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
const selectSlots = computed((): any => {
|
|
138
|
+
return Object.keys(slots).filter(k => k.startsWith("select-")).reduce((acc, key) => {
|
|
139
|
+
acc[key.substring("select-".length)] = slots[key];
|
|
140
|
+
return acc;
|
|
141
|
+
}, {});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const messages = computed((): string[] => props.messages ?? getMessages(props.modelValue, props.rules));
|
|
145
|
+
|
|
146
|
+
const units = computed(() => props.allowedUnits && props.allowedUnits.length ? timeSteps.filter(t => props.allowedUnits.includes(t.id)) : timeSteps);
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
numberSlots,
|
|
150
|
+
selectSlots,
|
|
151
|
+
validateOn,
|
|
152
|
+
messages,
|
|
153
|
+
units
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
</script>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dative-gpi/foundation-shared-components",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.21",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dative-gpi/foundation-shared-domain": "1.0.
|
|
14
|
-
"@dative-gpi/foundation-shared-services": "1.0.
|
|
13
|
+
"@dative-gpi/foundation-shared-domain": "1.0.21",
|
|
14
|
+
"@dative-gpi/foundation-shared-services": "1.0.21"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"@dative-gpi/bones-ui": "^0.0.75",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"sass": "1.71.1",
|
|
36
36
|
"sass-loader": "13.3.2"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "fd3fc21e8eff1096d820f66cce0f2fe3556a2cd7"
|
|
39
39
|
}
|
package/utils/time.ts
CHANGED
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import { useTranslations as useTranslationsProvider } from "@dative-gpi/bones-ui/composables";
|
|
2
2
|
|
|
3
|
+
import { TimeUnit } from "@dative-gpi/foundation-shared-domain/models"
|
|
4
|
+
|
|
3
5
|
const { $tr } = useTranslationsProvider();
|
|
4
6
|
|
|
7
|
+
export const timeSteps = [
|
|
8
|
+
{ id: TimeUnit.Second, label: $tr("ui.time-step.second.singular", "Second"), plural: $tr("ui.time-step.second.plural", "Seconds") },
|
|
9
|
+
{ id: TimeUnit.Minute, label: $tr("ui.time-step.minute.singular", "Minute"), plural: $tr("ui.time-step.minute.plural", "Minutes") },
|
|
10
|
+
{ id: TimeUnit.Hour, label: $tr("ui.time-step.hour.singular", "Hour"), plural: $tr("ui.time-step.hour.plural", "Hours") },
|
|
11
|
+
{ id: TimeUnit.Day, label: $tr("ui.time-step.day.singular", "Day"), plural: $tr("ui.time-step.day.plural", "Days") },
|
|
12
|
+
{ id: TimeUnit.Week, label: $tr("ui.time-step.week.singular", "Week"), plural: $tr("ui.time-step.week.plural", "Weeks") },
|
|
13
|
+
{ id: TimeUnit.Month, label: $tr("ui.time-step.month.singular", "Month"), plural: $tr("ui.time-step.month.plural", "Months") },
|
|
14
|
+
{ id: TimeUnit.Year, label: $tr("ui.time-step.year.singular", "Year"), plural: $tr("ui.time-step.year.plural", "Years") },
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
// TODO : remove everything below this line
|
|
5
20
|
export const timeScale: any[] = [
|
|
6
21
|
{ id: 1, label: $tr("ui.time-field.second.singular", "Second"), plural: $tr("ui.time-field.second.plural", "Seconds") },
|
|
7
22
|
{ id: 60, label: $tr("ui.time-field.minute.singular", "Minute"), plural: $tr("ui.time-field.minute.plural", "Minutes") },
|