evoluteur / evolutility-models

Sample models, mock data, and scripts to manage models for Evolutility CRUD Apps.
MIT License
10 stars 3 forks source link
code-generation crud crud-api crud-app crud-application crud-functionality crud-operation evolutility low-code mda metadata metadata-driven metamodel mock-data model-driven-development models no-code

Evolutility-Models · GitHub license npm version

Evolutility models are DRY (Don't Repeat Yourself) descriptions of applications. These models contain all the metadata necessary to describe the backend (database tables and columns, validation...) and the UI (views, fields, validation...).

Contents

Metamodel

Models

Scripts

License

Cool things to do with Evolutility models:

Metamodel

The metamodel is the structure of the model (the model of models). I think about it as the vocabulary for making models.

Models describe objects with fields, Field groups, and collections (nested lists of objects).

For any object, all UI views (List, Cards, Edit, Charts...) share the same model. All Fields are present in the Edit and Browse views. Fields can be flagged as "inMany" to be included in List, Cards, and Charts views.

module.exports = {
    id: "todo",
    label: "To-Do List",
    name: "task",
    namePlural: "tasks",
    icon: "todo.png",
    titleField: "title",
    table: "task",
    fields: [
        {
            id: "title",
            label: "Title",
            type: "text",
            width: 100,
            required: true,
            inMany: true,
            inSearch: true,
            column: "title",
            maxLength: 255
        },
        {
            id: "duedate",
            type: "date",
            label: "Due Date",
            width: 38,
            inMany: true,
            column: "due_date"
        },
        ...
    ]
}

Object

Property Meaning UI DB
id Unique key to identify the entity (used as API parameter). X X
icon Icon file name for the entity (example: "cube.png"). X
world Application the object belongs to (e.g. "organizer"). X X
name Object name (singular) (e.g.: "contact"). X
namePlural Object name (plural) (e.g.: "contacts"). X
title Application name (e.g.: "Addressbook"). X X
fields Array of fields. X X
groups Array of groups. If not provided a single group will be used. X
collections Array of collections (displayed as Lists). X X
titleField Id of the field which value is used as record title. titleField can also be a function. X X
titleFunction Function to calculate the record title based it's data. Example: titleFunction = (d) => d.firstname + " " + d.lastname; X X
table Driving database table name (there are secondary tables for fields of type "lov"). X
pKey Name of the Primary key column (single column of type serial). Default to "id". In the data the key is always called "id". X
defaultViewMany Default view for Many records (possible values: list, cards, charts). X
defaultViewOne Default view for One record (possible values browse, edit). X

X: Indicate if the property is used in UI/DB models.

Field

For the backend, fields are columns in a database table. For the frontend, fields are textboxes, checkboxes, datepickers... in Edit view, and they are columns in List view.

Property Meaning UI DB
id Unique key for the field (can be the same as column but doesn't have to be). X X
type Field type to show in the UI. Possible field types:
  • boolean (yes/no)
  • date
  • datetime
  • decimal
  • document
  • email
  • image
  • integer
  • json
  • list (multiselect)
  • lov (list of values)
  • money
  • text
  • textmultiline
  • time
  • url
X X
label Field description (displayed with an asterisk for required fields). X
labelShort Optional shorter version of the labels (used in List and Cards views). X
required Determines if the field is required for saving. X X
readOnly Field value cannot be changed. X X
defaultValue Default field value for new records. X X
hideIfEmpty Hide field when empty in Browse view. X
dependantField ID of an optional dependant field. Used when selecting in one list changes the content of dependant list (among 2 fields of type "lov").records. X X
max, min Maximum/Minimum value allowed (only applies to numeric fields). X X
maxLength, minLength Maximum/Minimum length allowed (only applies to text fields). X X
regExp Regular expression used to validate the field value. X X
inMany Determines if the field is present (by default) in lists of records. X X
inSearch Determine if the field is used in text searches. X
height For fields of type "textmultiline", number of lines used in the field (in Browse and Edit views). X
width Field width in Browse and Edit views (in percent of parent width). Default: 100% X
help Optional help on the field. X
chartType Default charts type used for the field ("Bars", "Pie", or "Table"). The default value is "Bars". X
search Include field in search. X X
noFilter Exclude field from filters (only applies to fields of type integer, decimal, money, boolean, list of values which are "chartable"). X X
noCharts Exclude field from charts (only applies to fields of type integer, decimal, money, boolean, list of values which are "chartable"). X X
noStats Exclude field from stats. X X
column Database column name for the field. X
pii Flag for personally identifiable information. X
lovTable Table to join to for field value (only for fields of "lov" type). X
lovColumn Column name (in the lovTable) for field value (only for fields of "lov" type). X
lovIcon LOV items have icons (only for fields of "lov" type). X X
deleteTrigger Deleting records in the lovTable will trigger a cascade delete (this property is only used for creating the database). X
object Model id for the object to link to (only for fields of "lov" type). X X
unique Field value must be unique. X X

UI: The field will only be present in the UI model. DB: The field will only be present in the DB model.

Field Group

Field Groups are used to visually group fields on the page for browsing or editing.

Field Groups are only used in UI models and are optional. By default a single group holds all fields.

Property Meaning UI DB
id Unique key for the group. It is optional. X
type Type of group. Only "panel" is currently implemented ("tab" and "accordeon" will be added later). X
label Group title as displayed to the user. X
fields Array of field ids. X
width Width (in % of the container total width). X
help Optional help tooltip text. X
header Text to be displayed at the top of the group (just below the group title). X
footer Text to be displayed below the group. X

Collection

Multiple Master-Details can be specified with collections.

Property Meaning UI DB
id Unique key for the collection. X X
title Collection title. X
table Table to query for the details list. X
column Column in the details table to match against object's id. X
object Model id for the object to link to. When specified, "column" and "table" can be omitted. X X
hideIfEmpty Hide Collection when it is empty in Edit view (always hidden when empty in Browse view). X
order Direction to order by "asc" or "desc". X
orderBy SQL where clause, e.g. { orderBy="id" }. X
fields Array of fields. Collections are not editable so their fields do not need as many properties as the main object's fields. X X
help Optional help tooltip text. X
header Text to be displayed at the top of the collection. X
footer Text to be displayed below the collection. X

Sample models

Demo Apps

Models are description of objects and their properties/fields, field groups, and sometimes nested-collections.

Organizer

Music

Designer (Models of models)

With models of models, we can store models in the database (instead of JSON files) and have an app to build other apps.

Test

Scripts

Database

Generate SQL script to create a Postgres DB with tables for all models.

In the command line type the following:

# Install dependencies
npm install

# Create SQL for sample database w/ demo tables
npm run db

Note: The database creation and population scripts are logged in the files "/dist/sql/evol-db-schema-{datetime}.sql" and "/dist/sql/evol-db-data-{datetime}.sql".

Models

This project provides scripts to make UI-models for Evolutility-UI-React and DB-models for Evolutility-Server-Node from models.

# Install dependencies
npm install

# Generate DB and UI models
npm run models

## Generate UI models
npm run models_ui

## Generate DB models
npm run models_db

Generated models are saved in the directories "/dist/models-ui" and "/dist/models-db". The list of "full" models to generate from is specified in "/models/all_models.js".

Note: The full models can be used as they are by both UI and back-end (which ignore what they do not need in the models).

License

Copyright (c) 2024 Olivier Giulieri.

Evolutility-Models is released under the MIT license.