@fishawack/lab-velocity 2.0.0-beta.15 → 2.0.0-beta.17
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/README.md +74 -0
- package/_Build/vue/modules/resource/index.js +33 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -422,3 +422,77 @@ Structure arrays take objects. The objects require a key only but have other opt
|
|
|
422
422
|
}
|
|
423
423
|
}
|
|
424
424
|
```
|
|
425
|
+
|
|
426
|
+
Generally speaking the only different between admin routes tends to do the columns which within a model are shared. Because of this you can use the utility method `columns` to automatically build out the table, description & form fields using the following syntax.
|
|
427
|
+
|
|
428
|
+
```js
|
|
429
|
+
import { Resource } from "@fishawack/lab-velocity";
|
|
430
|
+
import { Checkbox as VelCheckbox } from "@fishawack/lab-velocity";
|
|
431
|
+
|
|
432
|
+
{
|
|
433
|
+
api: `/api/posts`,
|
|
434
|
+
icon: `icon-visibility`,
|
|
435
|
+
permissions: {
|
|
436
|
+
create: ({ $store }) => $store.getters.can("write personas"),
|
|
437
|
+
edit: ({ $store }) => $store.getters.can("write personas"),
|
|
438
|
+
},
|
|
439
|
+
...Resource.columns(
|
|
440
|
+
[
|
|
441
|
+
{
|
|
442
|
+
key: "name",
|
|
443
|
+
sortable: true,
|
|
444
|
+
},
|
|
445
|
+
{
|
|
446
|
+
key: "description",
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
key: "is_experimental",
|
|
450
|
+
label: "Experimental",
|
|
451
|
+
render: {
|
|
452
|
+
write: () => h(VelCheckbox),
|
|
453
|
+
},
|
|
454
|
+
initial: ({ model }) => model?.is_experimental ?? false,
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
key: "nested",
|
|
458
|
+
label: "Nested",
|
|
459
|
+
render: {
|
|
460
|
+
read: ({ model }) =>
|
|
461
|
+
h("span", model?.nested.name ?? ""),
|
|
462
|
+
},
|
|
463
|
+
initial: ({ model }) =>
|
|
464
|
+
model?.nested.id ?? null,
|
|
465
|
+
},
|
|
466
|
+
]
|
|
467
|
+
),
|
|
468
|
+
},
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
The columns also takes an optional array as second parameter which defines which values to display on the table view.
|
|
472
|
+
|
|
473
|
+
```js
|
|
474
|
+
import { Resource } from "@fishawack/lab-velocity";
|
|
475
|
+
import { Checkbox as VelCheckbox } from "@fishawack/lab-velocity";
|
|
476
|
+
|
|
477
|
+
const columns [
|
|
478
|
+
{
|
|
479
|
+
key: "id"
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
key: "name"
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
key: "description"
|
|
486
|
+
}
|
|
487
|
+
];
|
|
488
|
+
|
|
489
|
+
{
|
|
490
|
+
api: `/api/posts`,
|
|
491
|
+
icon: `icon-visibility`,
|
|
492
|
+
permissions: {
|
|
493
|
+
create: ({ $store }) => $store.getters.can("write personas"),
|
|
494
|
+
edit: ({ $store }) => $store.getters.can("write personas"),
|
|
495
|
+
},
|
|
496
|
+
...Resource.columns(columns, ["id", "name"]),
|
|
497
|
+
},
|
|
498
|
+
```
|
|
@@ -110,6 +110,38 @@ export function meta(name = "default", properties = {}) {
|
|
|
110
110
|
);
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
export function columns(columns = {}, filter = []) {
|
|
114
|
+
return {
|
|
115
|
+
table: {
|
|
116
|
+
structure: columns
|
|
117
|
+
.filter((column) => filter.includes(column.key))
|
|
118
|
+
.map((column) => ({
|
|
119
|
+
...column,
|
|
120
|
+
render: column.render?.read,
|
|
121
|
+
})),
|
|
122
|
+
},
|
|
123
|
+
description: {
|
|
124
|
+
structure: columns.map((column) => ({
|
|
125
|
+
...column,
|
|
126
|
+
render: column.render?.read,
|
|
127
|
+
})),
|
|
128
|
+
},
|
|
129
|
+
form: {
|
|
130
|
+
fields: (props) =>
|
|
131
|
+
columns.reduce((fields, column) => {
|
|
132
|
+
fields[column.key] = column.initial
|
|
133
|
+
? column.initial(props)
|
|
134
|
+
: (props.model?.[column.key] ?? null);
|
|
135
|
+
return fields;
|
|
136
|
+
}, {}),
|
|
137
|
+
structure: columns.map((column) => ({
|
|
138
|
+
...column,
|
|
139
|
+
render: column.render?.write,
|
|
140
|
+
})),
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
113
145
|
// Export resource
|
|
114
146
|
export function routes(node, name, properties = {}) {
|
|
115
147
|
return [
|
|
@@ -156,4 +188,5 @@ export function routes(node, name, properties = {}) {
|
|
|
156
188
|
export default {
|
|
157
189
|
routes,
|
|
158
190
|
meta,
|
|
191
|
+
columns,
|
|
159
192
|
};
|