Skip to content

Commit ba323c8

Browse files
author
yaroslav8765
committed
fix: Add load .env.local in index.ts.hbs to fix undefined DB URL in resource command
1 parent 8a8b669 commit ba323c8

File tree

14 files changed

+487
-52
lines changed

14 files changed

+487
-52
lines changed

adminforth/commands/createApp/templates/index.ts.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import AdminForth from 'adminforth';
33
import usersResource from "./resources/adminuser.js";
44
import { fileURLToPath } from 'url';
55
import path from 'path';
6+
import dotenv from "dotenv";
7+
dotenv.config({ path: '.env.local' });
68

79
const ADMIN_BASE_URL = '';
810

adminforth/commands/createApp/utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export async function promptForMissingOptions(options) {
6161
questions.push({
6262
type: 'input',
6363
name: 'appName',
64-
message: 'Please specify the name of the app >',
64+
message: 'Please specify the name of the app (TEEEEEEEEEESTTTTT)>',
6565
default: 'adminforth-app',
6666
});
6767
};
@@ -108,9 +108,11 @@ function detectDbProvider(protocol) {
108108
return 'mongodb';
109109
} else if (protocol.startsWith('mysql')) {
110110
return 'mysql';
111+
} else if (protocol.startsWith('clickhouse')) {
112+
return 'clickhouse';
111113
}
112114

113-
const message = `Unknown database provider for ${protocol}. Only SQLite, PostgreSQL, and MongoDB are supported now.`;
115+
const message = `Unknown database provider for ${protocol}. Only SQLite, PostgreSQL, MongoDB, and ClickHouse are supported now.`;
114116
throw new Error(message);
115117
}
116118

dev-demo/.env.sample

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
AWS_ACCESS_KEY_ID=
22
AWS_SECRET_ACCESS_KEY=
3-
ADMINFORTH_SECRET=123
4-
NODE_ENV=development
53
OPENAI_API_KEY=1
64
HEAVY_DEBUG=
7-
HEAVY_DEBUG_QUERY=
8-
PORT=3000
9-
10-
DATABASE_FILE=./db.sqlite
11-
DATABASE_FILE_URL=file:${DATABASE_FILE}
5+
HEAVY_DEBUG_QUERY=

dev-demo/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
22
*.sqlite
3+
*.sqlite-journal
34
.env
45
db

dev-demo/custom/PageForTests.vue

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
<template>
2+
<div class="px-4 py-4 bg-blue-50 dark:bg-gray-900 dark:shadow-none min-h-screen">
3+
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4">
4+
<!-- Total Apartments Chart -->
5+
<div class="max-w-md w-full bg-white rounded-lg shadow dark:bg-gray-800 p-4 md:p-5">
6+
<div>
7+
<h5 class="leading-none text-3xl font-bold text-gray-900 dark:text-white pb-2">{{ data.totalAparts }}</h5>
8+
<p class="text-base font-normal text-gray-500 dark:text-gray-400">
9+
{{ $t('Apartment last 7 days | Apartments last 7 days', data.totalAparts) }}
10+
</p>
11+
</div>
12+
<BarChart
13+
:data="apartsCountsByDaysChart"
14+
:series="[{ name: $t('Added apartments'), fieldName: 'count', color: COLORS[0] }]"
15+
:options="{ chart: { height: 130 }, yaxis: { stepSize: 1, labels: { show: false } }, grid: { show: false } }"
16+
/>
17+
</div>
18+
19+
<!-- Top Countries Pie -->
20+
<div class="max-w-md w-full bg-white rounded-lg shadow dark:bg-gray-800 p-4 md:p-5">
21+
<p class="text-base font-normal text-gray-500 dark:text-gray-400">{{ $t('Top countries') }}</p>
22+
<PieChart
23+
:data="topCountries"
24+
:options="{
25+
chart: { type: 'pie' },
26+
legend: { show: false },
27+
dataLabels: {
28+
enabled: true,
29+
formatter: (value, o) => o.w.config.labels[o.seriesIndex]
30+
}
31+
}"
32+
/>
33+
</div>
34+
35+
<!-- Listed vs Unlisted Count -->
36+
<div class="w-full bg-white rounded-lg shadow dark:bg-gray-800 p-4 md:p-5 lg:row-span-2 xl:col-span-2">
37+
<div class="grid grid-cols-2 py-3">
38+
<dl>
39+
<dt class="text-base font-normal text-gray-500 dark:text-gray-400 pb-1">{{ $t('Listed price') }}</dt>
40+
<dd class="leading-none text-xl font-bold dark:text-green-400" :style="{ color: COLORS[0] }">
41+
{{ formatCurrency(data.totalListedPrice) }}
42+
</dd>
43+
</dl>
44+
<dl>
45+
<dt class="text-base font-normal text-gray-500 dark:text-gray-400 pb-1">{{ $t('Unlisted price') }}</dt>
46+
<dd class="leading-none text-xl font-bold dark:text-red-500" :style="{ color: COLORS[1] }">
47+
{{ formatCurrency(data.totalUnlistedPrice) }}
48+
</dd>
49+
</dl>
50+
</div>
51+
52+
<BarChart
53+
:data="listedVsUnlistedCountByDays"
54+
:series="[
55+
{ name: $t('Listed Count'), fieldName: 'listed', color: COLORS[0] },
56+
{ name: $t('Unlisted Count'), fieldName: 'unlisted', color: COLORS[1] }
57+
]"
58+
:options="{
59+
chart: { height: 500 },
60+
xaxis: { labels: { show: true }, stepSize: 1 },
61+
yaxis: { labels: { show: true } },
62+
grid: { show: true },
63+
plotOptions: { bar: { horizontal: true } }
64+
}"
65+
/>
66+
</div>
67+
68+
<!-- Apartments by Rooms Pie -->
69+
<div class="max-w-md w-full bg-white rounded-lg shadow dark:bg-gray-800 p-4 md:p-5">
70+
<p class="text-base font-normal text-gray-500 dark:text-gray-400">{{ $t('Apartment by rooms') }}</p>
71+
<PieChart
72+
:data="apartsCountsByRooms"
73+
:options="{
74+
chart: { type: 'donut' },
75+
plotOptions: {
76+
pie: {
77+
donut: {
78+
labels: {
79+
total: {
80+
show: true,
81+
label: $t('Total square'),
82+
formatter: () => `${data.totalSquareMeters.toFixed(0)} m²`
83+
}
84+
}
85+
}
86+
}
87+
}
88+
}"
89+
/>
90+
</div>
91+
92+
</div>
93+
</div>
94+
</template>
95+
96+
<script setup lang="ts">
97+
import { ref, computed } from 'vue';
98+
import dayjs from 'dayjs';
99+
import { useI18n } from 'vue-i18n';
100+
import { AreaChart, BarChart, PieChart } from '@/afcl';
101+
102+
const { t } = useI18n();
103+
const COLORS = ['#4E79A7', '#F28E2B', '#E15759', '#76B7B2', '#59A14F'];
104+
105+
const data = {
106+
totalAparts: 32,
107+
totalListedPrice: 4560000,
108+
totalUnlistedPrice: 1230000,
109+
totalSquareMeters: 2345,
110+
apartsByDays: [
111+
{ day: '2025-07-17', count: 3 },
112+
{ day: '2025-07-16', count: 6 },
113+
{ day: '2025-07-15', count: 8 },
114+
{ day: '2025-07-14', count: 5 },
115+
{ day: '2025-07-13', count: 4 },
116+
{ day: '2025-07-12', count: 3 },
117+
{ day: '2025-07-11', count: 3 }
118+
],
119+
topCountries: [
120+
{ country: 'US', count: 12 },
121+
{ country: 'FR', count: 7 },
122+
{ country: 'DE', count: 5 },
123+
{ country: 'UA', count: 8 }
124+
],
125+
apartsCountsByRooms: [
126+
{ number_of_rooms: 1, count: 6 },
127+
{ number_of_rooms: 2, count: 10 },
128+
{ number_of_rooms: 3, count: 9 },
129+
{ number_of_rooms: 4, count: 7 }
130+
],
131+
listedVsUnlistedByDays: [
132+
{ day: '2025-07-17', listed: 3, unlisted: 1 },
133+
{ day: '2025-07-16', listed: 5, unlisted: 2 },
134+
{ day: '2025-07-15', listed: 4, unlisted: 3 }
135+
],
136+
listedVsUnlistedPriceByDays: [
137+
{ day: '2025-07-17', listedPrice: 1000000, unlistedPrice: 400000 },
138+
{ day: '2025-07-16', listedPrice: 900000, unlistedPrice: 350000 },
139+
{ day: '2025-07-15', listedPrice: 800000, unlistedPrice: 300000 }
140+
]
141+
};
142+
143+
const formatCurrency = (value: number) =>
144+
new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 }).format(value);
145+
146+
const apartsCountsByDaysChart = computed(() =>
147+
data.apartsByDays.slice().reverse().map(item => ({
148+
x: dayjs(item.day).format('DD MMM'),
149+
count: item.count
150+
}))
151+
);
152+
153+
const listedVsUnlistedPriceByDays = computed(() =>
154+
data.listedVsUnlistedPriceByDays.map(item => ({
155+
x: dayjs(item.day).format('DD MMM'),
156+
listedPrice: item.listedPrice.toFixed(2),
157+
unlistedPrice: item.unlistedPrice.toFixed(2)
158+
}))
159+
);
160+
161+
const listedVsUnlistedCountByDays = computed(() =>
162+
data.listedVsUnlistedByDays.map(item => ({
163+
x: dayjs(item.day).format('DD MMM'),
164+
listed: item.listed,
165+
unlisted: item.unlisted
166+
}))
167+
);
168+
169+
const apartsCountsByRooms = computed(() =>
170+
data.apartsCountsByRooms.map((item, i) => ({
171+
label: t(`{number_of_rooms} rooms`, { number_of_rooms: item.number_of_rooms }),
172+
amount: item.count,
173+
color: COLORS[i]
174+
}))
175+
);
176+
177+
const topCountries = computed(() =>
178+
data.topCountries.map((item, i) => ({
179+
label: item.country,
180+
amount: item.count,
181+
color: COLORS[i]
182+
}))
183+
);
184+
</script>

dev-demo/index.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import apartmentBuyersResource from './resources/apartment_buyers.js';
88
import auditLogResource from './resources/audit_log.js';
99
import descriptionImageResource from './resources/description_image.js';
1010
import usersResource from './resources/users.js';
11-
// import gameResource from './resources/game.js';
12-
// import gamesUsersResource from './resources/games_users.js';
13-
// import gamesResource from './resources/games.js';
11+
import gameResource from './resources/game.js';
12+
import gamesUsersResource from './resources/games_users.js';
13+
import gamesResource from './resources/games.js';
1414
import translationsResource from './resources/translation.js';
1515
import clinicsResource from './resources/clinics.js';
1616
import providersResource from './resources/providers.js';
@@ -190,7 +190,7 @@ export const admin = new AdminForth({
190190
dataSources: [
191191
{
192192
id: 'maindb',
193-
url: process.env.DATABASE_URL,
193+
url: process.env.DATABASE_URL as string,
194194
},
195195
{
196196
id: 'pg',
@@ -202,7 +202,7 @@ export const admin = new AdminForth({
202202
},
203203
{
204204
id: 'ch',
205-
url: 'clickhouse://demo:demo@localhost:8125/demo',
205+
url: 'clickhouse://demo:demo@localhost:8124/demo',
206206
},
207207
{
208208
id: 'mysql',
@@ -219,22 +219,18 @@ export const admin = new AdminForth({
219219
clinicsResource,
220220
providersResource,
221221
apiKeysResource,
222-
// gamesResource,
223-
// gamesUsersResource,
224-
// gameResource,
222+
gamesResource,
223+
gamesUsersResource,
224+
gameResource,
225225
translationsResource,
226226
],
227227
menu: [
228228
{
229-
label: 'Dashboard',
229+
label: 'Tests',
230+
path: '/Tests',
231+
homepage: true,
230232
icon: 'flowbite:chart-pie-solid',
231-
component: '@@/Dash.vue',
232-
path: '/dashboard',
233-
// homepage: true,
234-
isStaticRoute:false,
235-
// meta:{
236-
// title: 'Dashboard',
237-
// }
233+
component: '@@/PageForTests.vue',
238234
},
239235
{
240236
label: 'Core',
@@ -261,11 +257,11 @@ export const admin = new AdminForth({
261257

262258
},
263259

264-
// {
265-
// label: 'Games',
266-
// icon: 'flowbite:caret-right-solid',
267-
// resourceId: 'game',
268-
// },
260+
{
261+
label: 'Games',
262+
icon: 'flowbite:caret-right-solid',
263+
resourceId: 'game',
264+
},
269265
// {
270266
// label: 'Games Users',
271267
// icon: 'flowbite:user-solid',

0 commit comments

Comments
 (0)