adminforth 1.6.2-next.3 → 1.6.2-next.4
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/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/spa/.eslintrc.cjs +14 -0
- package/dist/spa/README.md +39 -0
- package/dist/spa/env.d.ts +1 -0
- package/dist/spa/index.html +23 -0
- package/dist/spa/package-lock.json +5062 -0
- package/dist/spa/package.json +58 -0
- package/dist/spa/postcss.config.js +6 -0
- package/dist/spa/public/assets/favicon.png +0 -0
- package/dist/spa/src/App.vue +432 -0
- package/dist/spa/src/adminforth.ts +160 -0
- package/dist/spa/src/afcl/AreaChart.vue +160 -0
- package/dist/spa/src/afcl/BarChart.vue +170 -0
- package/dist/spa/src/afcl/Button.vue +27 -0
- package/dist/spa/src/afcl/Checkbox.vue +24 -0
- package/dist/spa/src/afcl/Dropzone.vue +128 -0
- package/dist/spa/src/afcl/Input.vue +41 -0
- package/dist/spa/src/afcl/Link.vue +17 -0
- package/dist/spa/src/afcl/LinkButton.vue +25 -0
- package/dist/spa/src/afcl/PieChart.vue +175 -0
- package/dist/spa/src/afcl/ProgressBar.vue +57 -0
- package/dist/spa/src/afcl/Select.vue +246 -0
- package/dist/spa/src/afcl/Skeleton.vue +26 -0
- package/dist/spa/src/afcl/Spinner.vue +9 -0
- package/dist/spa/src/afcl/Table.vue +116 -0
- package/dist/spa/src/afcl/Tooltip.vue +43 -0
- package/dist/spa/src/afcl/VerticalTabs.vue +49 -0
- package/dist/spa/src/afcl/index.ts +20 -0
- package/dist/spa/src/assets/base.css +2 -0
- package/dist/spa/src/assets/logo.svg +19 -0
- package/dist/spa/src/components/AcceptModal.vue +44 -0
- package/dist/spa/src/components/Breadcrumbs.vue +41 -0
- package/dist/spa/src/components/BreadcrumbsWithButtons.vue +25 -0
- package/dist/spa/src/components/CustomDatePicker.vue +180 -0
- package/dist/spa/src/components/CustomDateRangePicker.vue +218 -0
- package/dist/spa/src/components/CustomRangePicker.vue +156 -0
- package/dist/spa/src/components/Filters.vue +232 -0
- package/dist/spa/src/components/GroupsTable.vue +218 -0
- package/dist/spa/src/components/HelloWorld.vue +17 -0
- package/dist/spa/src/components/MenuLink.vue +41 -0
- package/dist/spa/src/components/ResourceForm.vue +260 -0
- package/dist/spa/src/components/ResourceListTable.vue +486 -0
- package/dist/spa/src/components/ShowTable.vue +81 -0
- package/dist/spa/src/components/SingleSkeletLoader.vue +13 -0
- package/dist/spa/src/components/SkeleteLoader.vue +18 -0
- package/dist/spa/src/components/ThreeDotsMenu.vue +43 -0
- package/dist/spa/src/components/Toast.vue +78 -0
- package/dist/spa/src/components/ValueRenderer.vue +141 -0
- package/dist/spa/src/components/icons/IconCalendar.vue +5 -0
- package/dist/spa/src/components/icons/IconCommunity.vue +7 -0
- package/dist/spa/src/components/icons/IconDocumentation.vue +7 -0
- package/dist/spa/src/components/icons/IconEcosystem.vue +7 -0
- package/dist/spa/src/components/icons/IconSupport.vue +7 -0
- package/dist/spa/src/components/icons/IconTime.vue +5 -0
- package/dist/spa/src/components/icons/IconTooling.vue +19 -0
- package/dist/spa/src/composables/useFrontendApi.ts +28 -0
- package/dist/spa/src/i18n.ts +54 -0
- package/dist/spa/src/index.scss +34 -0
- package/dist/spa/src/main.ts +22 -0
- package/dist/spa/src/renderers/CompactField.vue +46 -0
- package/dist/spa/src/renderers/CompactUUID.vue +46 -0
- package/dist/spa/src/renderers/CountryFlag.vue +65 -0
- package/dist/spa/src/renderers/HumanNumber.vue +58 -0
- package/dist/spa/src/renderers/RelativeTime.vue +42 -0
- package/dist/spa/src/renderers/URL.vue +18 -0
- package/dist/spa/src/router/index.ts +70 -0
- package/dist/spa/src/spa_types/core.ts +51 -0
- package/dist/spa/src/stores/core.ts +228 -0
- package/dist/spa/src/stores/filters.ts +27 -0
- package/dist/spa/src/stores/modal.ts +48 -0
- package/dist/spa/src/stores/toast.ts +30 -0
- package/dist/spa/src/stores/user.ts +79 -0
- package/dist/spa/src/types/Adapters.ts +26 -0
- package/dist/spa/src/types/Back.ts +1344 -0
- package/dist/spa/src/types/Common.ts +940 -0
- package/dist/spa/src/types/FrontendAPI.ts +189 -0
- package/dist/spa/src/utils.ts +184 -0
- package/dist/spa/src/views/CreateView.vue +167 -0
- package/dist/spa/src/views/EditView.vue +171 -0
- package/dist/spa/src/views/ListView.vue +442 -0
- package/dist/spa/src/views/LoginView.vue +199 -0
- package/dist/spa/src/views/PageNotFound.vue +20 -0
- package/dist/spa/src/views/ResourceParent.vue +50 -0
- package/dist/spa/src/views/ShowView.vue +209 -0
- package/dist/spa/src/websocket.ts +129 -0
- package/dist/spa/tailwind.config.js +19 -0
- package/dist/spa/tsconfig.app.json +14 -0
- package/dist/spa/tsconfig.json +11 -0
- package/dist/spa/tsconfig.node.json +19 -0
- package/dist/spa/vite.config.ts +52 -0
- package/package.json +1 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="-mb-2" ref="chart"></div>
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
import ApexCharts, { type ApexOptions } from 'apexcharts';
|
|
7
|
+
import { ref, type Ref, watch, computed, onUnmounted } from 'vue';
|
|
8
|
+
|
|
9
|
+
const chart: Ref<HTMLDivElement | null> = ref(null);
|
|
10
|
+
|
|
11
|
+
const props = defineProps<{
|
|
12
|
+
data: {
|
|
13
|
+
x: string,
|
|
14
|
+
[key: string]: any,
|
|
15
|
+
}[],
|
|
16
|
+
series: {
|
|
17
|
+
name: string,
|
|
18
|
+
fieldName: string,
|
|
19
|
+
color: string,
|
|
20
|
+
}[],
|
|
21
|
+
options: ApexOptions,
|
|
22
|
+
}>();
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const optionsBase = {
|
|
27
|
+
chart: {
|
|
28
|
+
height: 150,
|
|
29
|
+
type: "area",
|
|
30
|
+
fontFamily: "Inter, sans-serif",
|
|
31
|
+
dropShadow: {
|
|
32
|
+
enabled: false,
|
|
33
|
+
},
|
|
34
|
+
toolbar: {
|
|
35
|
+
show: false,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
tooltip: {
|
|
39
|
+
enabled: true,
|
|
40
|
+
x: {
|
|
41
|
+
show: false,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
fill: {
|
|
45
|
+
type: "gradient",
|
|
46
|
+
gradient: {
|
|
47
|
+
opacityFrom: 0.55,
|
|
48
|
+
opacityTo: 0,
|
|
49
|
+
shade: "#1C64F2",
|
|
50
|
+
gradientToColors: ["#1C64F2"],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
dataLabels: {
|
|
54
|
+
enabled: false,
|
|
55
|
+
},
|
|
56
|
+
stroke: {
|
|
57
|
+
width: 6,
|
|
58
|
+
},
|
|
59
|
+
grid: {
|
|
60
|
+
show: false,
|
|
61
|
+
strokeDashArray: 4,
|
|
62
|
+
padding: {
|
|
63
|
+
left: 3,
|
|
64
|
+
right: 3,
|
|
65
|
+
top: 3,
|
|
66
|
+
bottom: 3
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
series: [],
|
|
70
|
+
xaxis: {
|
|
71
|
+
categories: [],
|
|
72
|
+
labels: {
|
|
73
|
+
show: false,
|
|
74
|
+
},
|
|
75
|
+
axisBorder: {
|
|
76
|
+
show: false,
|
|
77
|
+
},
|
|
78
|
+
axisTicks: {
|
|
79
|
+
show: false,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
yaxis: {
|
|
83
|
+
show: false,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const options = computed(() => {
|
|
88
|
+
if (props.data?.length > 0) {
|
|
89
|
+
props.series.forEach((s) => {
|
|
90
|
+
if (props.data[0][s.fieldName] === undefined) {
|
|
91
|
+
throw new Error(`Field ${s.fieldName} not found even in first data point ${JSON.stringify(props.data[0])}, something is wrong`);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
const options = {
|
|
96
|
+
...optionsBase,
|
|
97
|
+
|
|
98
|
+
// shade and gradient take from first series
|
|
99
|
+
fill: {
|
|
100
|
+
...optionsBase.fill,
|
|
101
|
+
gradient: {
|
|
102
|
+
...optionsBase.fill.gradient,
|
|
103
|
+
shade: props.series[0].color,
|
|
104
|
+
gradientToColors: [props.series[0].color],
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
series: props.series.map((s) => ({
|
|
108
|
+
data: props.data?.map((item) => item[s.fieldName]) ?? [],
|
|
109
|
+
...s,
|
|
110
|
+
})),
|
|
111
|
+
xaxis: {
|
|
112
|
+
...optionsBase.xaxis,
|
|
113
|
+
categories: props.data?.map((item) => item.x) ?? [],
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// for each of ...props.options merge on lowest level. so if { chart: {height : 2} }, it should not replace chart level, only height level
|
|
118
|
+
function mergeOptions(options: any, newOptions: any) {
|
|
119
|
+
if (!newOptions) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
for (const key in newOptions) {
|
|
123
|
+
// and is not array
|
|
124
|
+
if (typeof newOptions[key] === 'object' && !Array.isArray(newOptions[key])) {
|
|
125
|
+
if (!options[key]) {
|
|
126
|
+
options[key] = {};
|
|
127
|
+
}
|
|
128
|
+
mergeOptions(options[key], newOptions[key]);
|
|
129
|
+
} else {
|
|
130
|
+
options[key] = newOptions[key];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
mergeOptions(options, props.options);
|
|
135
|
+
|
|
136
|
+
return options;
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
let apexChart: ApexCharts | null = null;
|
|
140
|
+
|
|
141
|
+
watch(() => [options.value, chart.value], (value) => {
|
|
142
|
+
if (!value || !chart.value) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
console.log('options changed', options.value);
|
|
146
|
+
if (apexChart) {
|
|
147
|
+
apexChart.updateOptions(options.value);
|
|
148
|
+
} else {
|
|
149
|
+
apexChart = new ApexCharts(chart.value, options.value);
|
|
150
|
+
apexChart.render();
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
onUnmounted(() => {
|
|
155
|
+
if (apexChart) {
|
|
156
|
+
apexChart.destroy();
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
</script>
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="-mb-2" ref="chart"></div>
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
import ApexCharts, { type ApexOptions } from 'apexcharts';
|
|
7
|
+
import { ref, type Ref, watch, computed, onUnmounted } from 'vue';
|
|
8
|
+
|
|
9
|
+
const chart: Ref<HTMLDivElement | null> = ref(null);
|
|
10
|
+
|
|
11
|
+
const props = defineProps<{
|
|
12
|
+
data: {
|
|
13
|
+
x: string,
|
|
14
|
+
[key: string]: any,
|
|
15
|
+
}[],
|
|
16
|
+
series: {
|
|
17
|
+
name: string,
|
|
18
|
+
fieldName: string,
|
|
19
|
+
color: string,
|
|
20
|
+
}[],
|
|
21
|
+
options: ApexOptions,
|
|
22
|
+
}>();
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const optionsBase = {
|
|
27
|
+
chart: {
|
|
28
|
+
sparkline: {
|
|
29
|
+
enabled: false,
|
|
30
|
+
},
|
|
31
|
+
type: "bar",
|
|
32
|
+
width: "100%",
|
|
33
|
+
// height: 150,
|
|
34
|
+
toolbar: {
|
|
35
|
+
show: false,
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
fill: {
|
|
39
|
+
opacity: 1,
|
|
40
|
+
},
|
|
41
|
+
plotOptions: {
|
|
42
|
+
bar: {
|
|
43
|
+
horizontal: false,
|
|
44
|
+
columnWidth: "80%",
|
|
45
|
+
borderRadiusApplication: "end",
|
|
46
|
+
borderRadius: 5,
|
|
47
|
+
dataLabels: {
|
|
48
|
+
position: "top",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
legend: {
|
|
53
|
+
show: false,
|
|
54
|
+
position: "bottom",
|
|
55
|
+
},
|
|
56
|
+
dataLabels: {
|
|
57
|
+
enabled: false,
|
|
58
|
+
},
|
|
59
|
+
tooltip: {
|
|
60
|
+
shared: true,
|
|
61
|
+
intersect: false,
|
|
62
|
+
formatter: function (value) {
|
|
63
|
+
return value
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
xaxis: {
|
|
67
|
+
labels: {
|
|
68
|
+
show: false,
|
|
69
|
+
style: {
|
|
70
|
+
fontFamily: "Inter, sans-serif",
|
|
71
|
+
cssClass: 'text-xs font-normal fill-gray-500 dark:fill-gray-400'
|
|
72
|
+
},
|
|
73
|
+
formatter: function (value) {
|
|
74
|
+
return value
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
categories: [],
|
|
78
|
+
axisTicks: {
|
|
79
|
+
show: false,
|
|
80
|
+
},
|
|
81
|
+
axisBorder: {
|
|
82
|
+
show: false,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
yaxis: {
|
|
86
|
+
labels: {
|
|
87
|
+
show: false,
|
|
88
|
+
style: {
|
|
89
|
+
fontFamily: "Inter, sans-serif",
|
|
90
|
+
cssClass: 'text-xs font-normal fill-gray-500 dark:fill-gray-400'
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
grid: {
|
|
95
|
+
show: false,
|
|
96
|
+
strokeDashArray: 4,
|
|
97
|
+
padding: {
|
|
98
|
+
left: 4, // 4 seams to be a safe value, otherwise labels overlap somewhy
|
|
99
|
+
right: 3,
|
|
100
|
+
top: 3,
|
|
101
|
+
bottom: 4,
|
|
102
|
+
// top: -20
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const options = computed(() => {
|
|
108
|
+
if (props.data?.length > 0) {
|
|
109
|
+
props.series.forEach((s) => {
|
|
110
|
+
if (props.data[0][s.fieldName] === undefined) {
|
|
111
|
+
throw new Error(`Field ${s.fieldName} not found even in first data point ${JSON.stringify(props.data[0])}, something is wrong`);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
const options = {
|
|
116
|
+
...optionsBase,
|
|
117
|
+
|
|
118
|
+
// shade and gradient take from first series
|
|
119
|
+
series: props.series.map((s) => ({
|
|
120
|
+
data: props.data?.map((item) => item[s.fieldName]) ?? [],
|
|
121
|
+
...s,
|
|
122
|
+
})),
|
|
123
|
+
xaxis: {
|
|
124
|
+
...optionsBase.xaxis,
|
|
125
|
+
categories: props.data?.map((item) => item.x) ?? [],
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// for each of ...props.options merge on lowest level. so if { chart: {height : 2} }, it should not replace chart level, only height level
|
|
130
|
+
function mergeOptions(options: any, newOptions: any) {
|
|
131
|
+
if (!newOptions) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
for (const key in newOptions) {
|
|
135
|
+
// and is not array
|
|
136
|
+
if (typeof newOptions[key] === 'object' && !Array.isArray(newOptions[key])) {
|
|
137
|
+
if (!options[key]) {
|
|
138
|
+
options[key] = {};
|
|
139
|
+
}
|
|
140
|
+
mergeOptions(options[key], newOptions[key]);
|
|
141
|
+
} else {
|
|
142
|
+
options[key] = newOptions[key];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
mergeOptions(options, props.options);
|
|
147
|
+
|
|
148
|
+
return options;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
let apexChart: ApexCharts | null = null;
|
|
152
|
+
|
|
153
|
+
watch(() => [options.value, chart.value], (value) => {
|
|
154
|
+
if (!value || !chart.value) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (apexChart) {
|
|
158
|
+
apexChart.updateOptions(options.value);
|
|
159
|
+
} else {
|
|
160
|
+
apexChart = new ApexCharts(chart.value, options.value);
|
|
161
|
+
apexChart.render();
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
onUnmounted(() => {
|
|
166
|
+
if (apexChart) {
|
|
167
|
+
apexChart.destroy();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
</script>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<button
|
|
3
|
+
v-bind="$attrs"
|
|
4
|
+
type="submit"
|
|
5
|
+
class="flex items-center justify-center gap-1 text-lightPrimaryContrast bg-lightPrimary dark:bg-darkPrimary hover:brightness-110
|
|
6
|
+
focus:ring-4 focus:outline-none focus:ring-lightPrimary focus:ring-opacity-50 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:focus:ring-darkPrimary dark:focus:ring-opacity-50"
|
|
7
|
+
:class="{
|
|
8
|
+
'cursor-default': props.disabled,
|
|
9
|
+
'opacity-50': props.disabled,
|
|
10
|
+
'pointer-events-none': props.disabled,
|
|
11
|
+
}"
|
|
12
|
+
>
|
|
13
|
+
<svg v-if="props.loader"
|
|
14
|
+
aria-hidden="true" class="w-4 h-4 text-gray-200 animate-spin dark:text-gray-600 fill-lightPrimary dark:fill-darkPrimary"
|
|
15
|
+
viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/><path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/></svg>
|
|
16
|
+
<slot></slot>
|
|
17
|
+
</button>
|
|
18
|
+
</template>
|
|
19
|
+
|
|
20
|
+
<script setup lang="ts">
|
|
21
|
+
|
|
22
|
+
const props = defineProps({
|
|
23
|
+
loader: Boolean,
|
|
24
|
+
disabled: Boolean,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
</script>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="flex items-center h-5">
|
|
3
|
+
<input :id="id"
|
|
4
|
+
ref="rememberInput"
|
|
5
|
+
type="checkbox"
|
|
6
|
+
:checked="props.modelValue"
|
|
7
|
+
@change="$emit('update:modelValue', $event.target.checked)"
|
|
8
|
+
class="w-4 h-4 border border-gray-300 rounded bg-gray-50 focus:ring-3 focus:ring-lightPrimary focus:ring-opacity-50 dark:bg-gray-700 dark:border-gray-600 dark:focus:ring-blue-600 dark:ring-offset-gray-800 dark:focus:ring-offset-gray-800 checked:bg-lightPrimary checked:dark:bg-darkPrimary" />
|
|
9
|
+
</div>
|
|
10
|
+
<label :for="id" class="ms-2 text-sm font-medium text-gray-900 dark:text-gray-300">
|
|
11
|
+
<slot></slot>
|
|
12
|
+
</label>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
|
|
17
|
+
const props = defineProps({
|
|
18
|
+
modelValue: Boolean,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
defineEmits(['update:modelValue']);
|
|
22
|
+
|
|
23
|
+
const id = `afcb-${Math.random().toString(36).substring(7)}`
|
|
24
|
+
</script>
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="flex items-center justify-center w-full"
|
|
3
|
+
@dragover.prevent="dragging = true"
|
|
4
|
+
@dragleave.prevent="dragging = false"
|
|
5
|
+
@drop.prevent="dragging = false; doEmit($event.dataTransfer.files)"
|
|
6
|
+
>
|
|
7
|
+
<label :id="id" class="flex flex-col items-center justify-center w-full h-32 border-2 border-dashed rounded-lg cursor-pointer dark:hover:bg-gray-800
|
|
8
|
+
hover:bg-gray-100 dark:hover:border-gray-500 dark:hover:bg-gray-600"
|
|
9
|
+
:class="{
|
|
10
|
+
'border-blue-600 dark:border-blue-400': dragging,
|
|
11
|
+
'border-gray-300 dark:border-gray-600': !dragging,
|
|
12
|
+
'bg-blue-50 dark:bg-blue-800': dragging,
|
|
13
|
+
'bg-gray-50 dark:bg-gray-800': !dragging,
|
|
14
|
+
}"
|
|
15
|
+
>
|
|
16
|
+
<div class="flex flex-col items-center justify-center pt-5 pb-6">
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
<svg v-if="!selectedFiles.length" class="w-8 h-8 mb-4 text-gray-500 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 16">
|
|
20
|
+
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 13h3a3 3 0 0 0 0-6h-.025A5.56 5.56 0 0 0 16 6.5 5.5 5.5 0 0 0 5.207 5.021C5.137 5.017 5.071 5 5 5a4 4 0 0 0 0 8h2.167M10 15V6m0 0L8 8m2-2 2 2"/>
|
|
21
|
+
</svg>
|
|
22
|
+
<div v-else class="flex items-center justify-center w-full mt-1 mb-4">
|
|
23
|
+
<template v-for="file in selectedFiles">
|
|
24
|
+
<p class="text-sm text-gray-500 dark:text-gray-400 flex items-center gap-1">
|
|
25
|
+
<IconFileSolid class="w-5 h-5" />
|
|
26
|
+
{{ file.name }} ({{ humanifySize(file.size) }})
|
|
27
|
+
</p>
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<p v-if="!selectedFiles.length" class="mb-2 text-sm text-gray-500 dark:text-gray-400"><span class="font-semibold">{{ $t('Click to upload') }}</span> {{ $t('or drag and drop') }}</p>
|
|
33
|
+
<p class="text-xs text-gray-500 dark:text-gray-400">
|
|
34
|
+
{{ props.extensions.join(', ').toUpperCase().replace(/\./g, '') }}
|
|
35
|
+
<template v-if="props.maxSizeBytes">
|
|
36
|
+
(Max size: {{ humanifySize(props.maxSizeBytes) }})
|
|
37
|
+
</template>
|
|
38
|
+
</p>
|
|
39
|
+
</div>
|
|
40
|
+
<input :id="id" type="file" class="hidden"
|
|
41
|
+
:accept="props.extensions.join(', ')"
|
|
42
|
+
@change="doEmit($event.target.files)"
|
|
43
|
+
:multiple="props.multiple || false"
|
|
44
|
+
/>
|
|
45
|
+
</label>
|
|
46
|
+
</div>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
<script setup lang="ts">
|
|
50
|
+
import { humanifySize } from '@/utils';
|
|
51
|
+
import { ref, type Ref } from 'vue';
|
|
52
|
+
import { IconFileSolid } from '@iconify-prerendered/vue-flowbite';
|
|
53
|
+
import { watch } from 'vue';
|
|
54
|
+
import adminforth from '@/adminforth';
|
|
55
|
+
|
|
56
|
+
const props = defineProps<{
|
|
57
|
+
extensions: string[],
|
|
58
|
+
maxSizeBytes: number,
|
|
59
|
+
multiple: boolean,
|
|
60
|
+
modelValue: FileList,
|
|
61
|
+
}>();
|
|
62
|
+
|
|
63
|
+
const emit = defineEmits(['update:modelValue']);
|
|
64
|
+
|
|
65
|
+
const id = `afcl-dropzone-${Math.random().toString(36).substring(7)}`;
|
|
66
|
+
|
|
67
|
+
const selectedFiles: Ref<{
|
|
68
|
+
name: string,
|
|
69
|
+
size: number,
|
|
70
|
+
mime: string,
|
|
71
|
+
}[]> = ref([]);
|
|
72
|
+
|
|
73
|
+
watch(() => props.modelValue, (files) => {
|
|
74
|
+
selectedFiles.value = Array.from(files).map(file => ({
|
|
75
|
+
name: file.name,
|
|
76
|
+
size: file.size,
|
|
77
|
+
mime: file.type,
|
|
78
|
+
}));
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
function doEmit(filesIn: FileList) {
|
|
82
|
+
|
|
83
|
+
const multiple = props.multiple || false;
|
|
84
|
+
const files = Array.from(filesIn);
|
|
85
|
+
const allowedExtensions = props.extensions.map(ext => ext.toLowerCase());
|
|
86
|
+
const maxSizeBytes = props.maxSizeBytes;
|
|
87
|
+
|
|
88
|
+
if (!files.length) return;
|
|
89
|
+
|
|
90
|
+
const validFiles: File[] = [];
|
|
91
|
+
|
|
92
|
+
files.forEach(file => {
|
|
93
|
+
const extension = file.name.split('.').pop()?.toLowerCase() || '';
|
|
94
|
+
const size = file.size;
|
|
95
|
+
|
|
96
|
+
if (!allowedExtensions.includes(`.${extension}`)) {
|
|
97
|
+
adminforth.alert({
|
|
98
|
+
message: `Sorry, the file type .${extension} is not allowed. Please upload a file with one of the following extensions: ${allowedExtensions.join(', ')}`,
|
|
99
|
+
variant: 'danger',
|
|
100
|
+
});
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (size > maxSizeBytes) {
|
|
104
|
+
adminforth.alert({
|
|
105
|
+
message: `Sorry, the file size ${humanifySize(size)} exceeds the maximum allowed size of ${humanifySize(maxSizeBytes)}.`,
|
|
106
|
+
variant: 'danger',
|
|
107
|
+
});
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
validFiles.push(file);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
if (!multiple) {
|
|
115
|
+
validFiles.splice(1);
|
|
116
|
+
}
|
|
117
|
+
selectedFiles.value = validFiles.map(file => ({
|
|
118
|
+
name: file.name,
|
|
119
|
+
size: file.size,
|
|
120
|
+
mime: file.type,
|
|
121
|
+
}));
|
|
122
|
+
|
|
123
|
+
emit('update:modelValue', validFiles);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const dragging = ref(false);
|
|
127
|
+
|
|
128
|
+
</script>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
|
|
3
|
+
<div class="flex z-0">
|
|
4
|
+
<span
|
|
5
|
+
v-if="$slots.prefix"
|
|
6
|
+
class="inline-flex items-center px-3 text-sm text-gray-900 bg-gray-200 border border-s-0 border-gray-300 rounded-e-md dark:bg-gray-600 dark:text-gray-400 dark:border-gray-600">
|
|
7
|
+
<slot name="prefix"></slot>
|
|
8
|
+
</span>
|
|
9
|
+
|
|
10
|
+
<!-- translate needed for bumping ring above prefix without z-index -->
|
|
11
|
+
<input
|
|
12
|
+
v-bind="$attrs"
|
|
13
|
+
:type="type"
|
|
14
|
+
@input="$emit('update:modelValue', $event.target?.value)"
|
|
15
|
+
:value="modelValue"
|
|
16
|
+
aria-describedby="helper-text-explanation"
|
|
17
|
+
class="inline-flex bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-0 focus:ring-lightPrimary focus:border-lightPrimary dark:focus:ring-darkPrimary dark:focus:border-darkPrimary
|
|
18
|
+
blue-500 focus:border-blue-500 block w-20 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white translate-y-0"
|
|
19
|
+
:class="{'rounded-l-md': !$slots.prefix, 'rounded-r-md': !$slots.suffix}"
|
|
20
|
+
>
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
<span
|
|
24
|
+
v-if="$slots.suffix"
|
|
25
|
+
class="inline-flex items-center px-3 text-sm text-gray-900 bg-gray-200 border border-s-0 border-gray-300 rounded-e-md dark:bg-gray-600 dark:text-gray-400 dark:border-gray-600 ">
|
|
26
|
+
<slot name="suffix"></slot>
|
|
27
|
+
</span>
|
|
28
|
+
|
|
29
|
+
</div>
|
|
30
|
+
</template>
|
|
31
|
+
|
|
32
|
+
<script setup lang="ts">
|
|
33
|
+
|
|
34
|
+
const props = defineProps({
|
|
35
|
+
type: String,
|
|
36
|
+
modelValue: String,
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
</script>
|
|
41
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<router-link
|
|
3
|
+
v-bind="$attrs"
|
|
4
|
+
:to="to"
|
|
5
|
+
class="text-lightPrimary underline dark:text-darkPrimary hover:no-underline hover:brightness-110
|
|
6
|
+
cursor-pointer"
|
|
7
|
+
>
|
|
8
|
+
<slot></slot>
|
|
9
|
+
</router-link>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script setup lang="ts">
|
|
13
|
+
|
|
14
|
+
defineProps<{
|
|
15
|
+
to: string,
|
|
16
|
+
}>()
|
|
17
|
+
</script>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<router-link
|
|
3
|
+
v-bind="$attrs"
|
|
4
|
+
:to="props.to"
|
|
5
|
+
type="submit"
|
|
6
|
+
class="flex items-center justify-center gap-1 text-lightPrimaryContrast bg-lightPrimary dark:bg-darkPrimary hover:brightness-110
|
|
7
|
+
focus:ring-4 focus:outline-none focus:ring-lightPrimary focus:ring-opacity-50 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:focus:ring-darkPrimary dark:focus:ring-opacity-50"
|
|
8
|
+
:class="{
|
|
9
|
+
'cursor-default': props.disabled,
|
|
10
|
+
'opacity-50': props.disabled,
|
|
11
|
+
'pointer-events-none': props.disabled,
|
|
12
|
+
}"
|
|
13
|
+
>
|
|
14
|
+
<slot></slot>
|
|
15
|
+
</router-link>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script setup lang="ts">
|
|
19
|
+
|
|
20
|
+
const props = defineProps<{
|
|
21
|
+
disabled: boolean,
|
|
22
|
+
to: string,
|
|
23
|
+
}>();
|
|
24
|
+
|
|
25
|
+
</script>
|