Skip to content

Commit fc93b2d

Browse files
committed
docs: update apartments configuration
1 parent 4721fca commit fc93b2d

1 file changed

Lines changed: 65 additions & 10 deletions

File tree

adminforth/documentation/docs/tutorial/001-gettingStarted.md

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ After the resource file is generated, extend it with display and validation sett
197197
To properly apply these changes, refer to the example below and adjust the configuration according to your settings
198198

199199
```ts title="./resources/apartments.ts"
200-
import { AdminForthDataTypes, AdminForthResourceInput } from 'adminforth';
200+
import { AdminForthResourceInput, AdminForthDataTypes } from 'adminforth';
201201

202202
export default {
203203
dataSource: 'maindb',
@@ -206,32 +206,41 @@ export default {
206206
resourceId: 'apartments'
207207
//diff-add
208208
resourceId: 'aparts', // resourceId is defaulted to table name but you can redefine it like this e.g.
209+
//diff-add
209210
// in case of same table names from different data sources
210211
label: 'Apartments', // label is defaulted to table name but you can change it
211212
//diff-add
212213
recordLabel: (r) => `🏡 ${r.title}`,
213214
columns: [
214215
{
215216
name: 'id',
217+
//diff-add
216218
type: AdminForthDataTypes.STRING,
217219
//diff-add
218220
label: 'Identifier', // if you wish you can redefine label, defaulted to uppercased name
219221
showIn: { // show column in filter and in show page
220-
//diff-add
222+
//diff-remove
223+
all:true,
224+
//diff-add
221225
list: false,
222226
//diff-add
223227
edit: false,
224228
//diff-add
225229
create: false,
226230
},
231+
//diff-add
227232
primaryKey: true,
228233
//diff-add
229234
fillOnCreate: ({ initialRecord, adminUser }) => Math.random().toString(36).substring(7), // called during creation to generate content of field, initialRecord is values user entered, adminUser object of user who creates record
230235
},
231236
{
232-
name: 'title',
237+
name: "title",
238+
//diff-add
233239
required: true,
234-
showIn: { all: true }, // all available options
240+
showIn: {
241+
all:true, // all available options
242+
},
243+
//diff-add
235244
type: AdminForthDataTypes.STRING,
236245
//diff-add
237246
maxLength: 255, // you can set max length for string fields
@@ -240,14 +249,24 @@ export default {
240249
},
241250
{
242251
name: 'created_at',
252+
//diff-add
243253
type: AdminForthDataTypes.DATETIME,
254+
//diff-add
244255
allowMinMaxQuery: true,
245-
showIn: { create: false },
256+
showIn: {
257+
//diff-remove
258+
all:true,
259+
//diff-add
260+
create: false,
261+
},
246262
//diff-add
247263
fillOnCreate: ({ initialRecord, adminUser }) => (new Date()).toISOString(),
248264
},
249265
{
250266
name: 'price',
267+
showIn: {
268+
all:true,
269+
},
251270
//diff-add
252271
inputSuffix: 'USD', // you can add a suffix to an input field that will be displayed when creating or editing records
253272
//diff-add
@@ -257,16 +276,25 @@ export default {
257276
},
258277
{
259278
name: 'square_meter',
279+
//diff-add
260280
label: 'Square',
281+
//diff-add
261282
allowMinMaxQuery: true,
283+
showIn: {
284+
all:true,
285+
},
262286
//diff-add
263287
minValue: 1, // you can set min /max value for number columns so users will not be able to enter more/less
264288
//diff-add
265289
maxValue: 1000,
266290
},
267291
{
268292
name: 'number_of_rooms',
293+
//diff-add
269294
allowMinMaxQuery: true,
295+
showIn: {
296+
all:true,
297+
},
270298
//diff-add
271299
enum: [
272300
//diff-add
@@ -284,11 +312,20 @@ export default {
284312
},
285313
{
286314
name: 'description',
315+
//diff-add
287316
sortable: false,
288-
showIn: { list: false },
317+
showIn: {
318+
//diff-remove
319+
all:true,
320+
//diff-add
321+
list: false,
322+
}
289323
},
290324
{
291325
name: 'country',
326+
showIn: {
327+
all:true,
328+
},
292329
//diff-add
293330
enum: [{
294331
//diff-add
@@ -362,18 +399,27 @@ export default {
362399
name: 'listed',
363400
//diff-add
364401
required: true, // will be required on create/edit
402+
showIn: {
403+
all:true,
404+
}
365405
},
366406
{
367407
name: 'realtor_id',
408+
//diff-add
368409
foreignResource: {
410+
//diff-add
369411
resourceId: 'adminuser',
370412
//diff-add
371413
searchableFields: ["id", "email"], // fields available for search in filter
414+
//diff-add
415+
},
416+
showIn: {
417+
all:true,
372418
}
373419
}
374420
],
375421
options: {
376-
listPageSize: 12,
422+
listPageSize: 10,
377423
//diff-add
378424
allowedActions: {
379425
//diff-add
@@ -439,8 +485,17 @@ export const admin = new AdminForth({
439485
},
440486
{
441487
label: 'Users',
442-
...
443-
}
488+
icon: 'flowbite:user-solid',
489+
resourceId: 'adminuser'
490+
},
491+
{
492+
label: "Apartments",
493+
icon: "flowbite:user-solid",
494+
//diff-remove
495+
resourceId: "apartments",
496+
//diff-add
497+
resourceId: "aparts",
498+
},
444499
],
445500
...
446501
});
@@ -467,7 +522,7 @@ async function seedDatabase() {
467522
//diff-add
468523
title: `Apartment ${i}`,
469524
//diff-add
470-
square_meter: (Math.random() * 100).toFixed(1),
525+
square_meter: Number((Math.random() * 100).toFixed(1)),
471526
//diff-add
472527
price: (Math.random() * 10000).toFixed(2),
473528
//diff-add

0 commit comments

Comments
 (0)