All files / realm/blong-access/meta/model accessCapabilityModel.ts

100% Statements 151/151
100% Branches 2/2
100% Functions 1/1
100% Lines 151/151

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 1521x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 1x  
import {model} from '@feasibleone/blong';
 
/**
 * accessCapabilityModel — capability management (Browse/New/Open).
 *
 * `capabilityName` is the display name (lives in `core_resource.resourceName`)
 * and is provided by the custom `access.capability.find/get/add/edit` handlers.
 *
 * The `action` detail is a pivot grid over the `access.crudEntity` dropdown
 * (distinct entities with standard-CRUD actions): each entity is ONE row with
 * boolean columns for the CRUD verbs. Ticking a cell includes the matching
 * `access<Entity><Predicate>` action in the capability (`hasAction` edges).
 * Actions with non-CRUD predicates appear in the "Other Actions" card inside
 * the same Action tab (read-only list with a `granted` toggle), not in a
 * separate tab.
 */
export default model(
    () =>
        async function accessCapabilityModel() {
            return {
                subject: 'access',
                object: 'capability',
                objectTitle: 'Capability',
                public: true,
                nameField: 'capability.capabilityName',
 
                schema: {
                    properties: {
                        capability: {
                            properties: {
                                capabilityName: {
                                    title: 'Name',
                                    filter: true,
                                    sort: true,
                                },
                                description: {
                                    title: 'Description',
                                    widget: {type: 'textArea'},
                                },
                                // server schema defined:
                                // capabilityId: {},
                            },
                            widget: {
                                columns: ['capabilityName', 'description'],
                            },
                        },
                        action: {
                            // The CRUD pivot card in the "Action" tab is untitled, so
                            // its table label must be suppressed too (it would duplicate
                            // the tab label).
                            title: '',
                            items: {
                                properties: {
                                    entityName: {
                                        title: 'Entity',
                                        readOnly: true,
                                    },
                                    find: {title: 'Find', type: 'boolean'},
                                    get: {title: 'Get', type: 'boolean'},
                                    add: {title: 'Add', type: 'boolean'},
                                    edit: {title: 'Edit', type: 'boolean'},
                                    remove: {title: 'Remove', type: 'boolean'},
                                },
                            },
                            widget: {
                                type: 'table',
                                keyField: 'entityName',
                                pivot: {
                                    dropdown: 'access.crudEntity',
                                    join: {
                                        value: 'entityName',
                                        label: 'entityName',
                                    },
                                },
                                columns: ['entityName', 'find', 'get', 'add', 'edit', 'remove'],
                            },
                        },
                        otherAction: {
                            items: {
                                properties: {
                                    actionId: {},
                                    actionName: {
                                        title: 'Other Action',
                                        readOnly: true,
                                    },
                                    granted: {
                                        title: 'Granted',
                                        type: 'boolean',
                                    },
                                },
                            },
                            widget: {
                                type: 'table',
                                columns: ['actionName', 'granted'],
                                actions: {
                                    allowAdd: false,
                                    allowEdit: true,
                                    allowDelete: false,
                                },
                            },
                        },
                    },
                },
 
                details: [{object: 'action'}],
 
                cards: {
                    browse: {
                        label: 'Capabilities',
                        widgets: ['capability'],
                    },
                    edit: {
                        label: 'Capability Details',
                        className: 'col-12 md:col-8',
                        widgets: ['capability.capabilityName', 'capability.description'],
                    },
                    // The CRUD pivot card inside the "Action" tab — no title because
                    // the tab itself is labelled "Action" (and holds this card plus
                    // the "Other Actions" card below it).
                    'details-action': {
                        label: '',
                    },
                    otherAction: {
                        label: 'Other Actions',
                        widgets: ['otherAction'],
                    },
                },
 
                // Custom edit layout: the "Action" tab stacks the CRUD pivot card
                // and the "Other Actions" card; everything else keeps the defaults.
                // (An `items` object layout resolves to a tabs layout — no `type`.)
                layouts: {
                    edit: {
                        items: [
                            {id: 'edit', label: 'Capability', widgets: ['edit']},
                            {
                                id: 'action',
                                label: 'Action',
                                widgets: ['details-action', 'otherAction'],
                            },
                        ],
                    },
                },
 
                browser: {
                    title: 'Capabilities',
                    icon: 'pi pi-lock',
                },
            };
        },
);