0.2.0 • Published 2 years ago

evolutility-models v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Evolutility-Models · GitHub license

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

Sample 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, groups of fields, 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.gif",
	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

PropertyMeaningUIDB
idUnique key to identify the entity (used as API parameter).XX
iconIcon file name for the entity (example: "cube.gif").X
worldApplication the object belongs to (e.g. "organizer").XX
nameObject name (singular) (e.g.: "contact").X
namePluralObject name (plural) (e.g.: "contacts").X
titleApplication name (e.g.: "Addressbook").XX
fieldsArray of fields.XX
groupsArray of groups. If not provided a single group will be used.X
collectionsArray of collections (displayed as Lists).XX
titleFieldId of the field which value is used as record title. titleField can also be a function.XX
tableDriving database table name (there are secondary tables for fields of type "lov").X
pKeyName of the Primary key column (single column of type serial). Default to "id". In the data the key is always called "id".X
defaultViewManyDefault view for Many records (possible values: list, cards, charts).X
defaultViewOneDefault 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.

PropertyMeaningUIDB
idUnique key for the field (can be the same as column but doesn't have to be).XX
typeField type to show in the UI. Possible field types: boolean (yes/no)datedatetimedecimaldocumentemailimageintegerjsonlist (multiselect)lov (list of values)moneytexttextmultilinetimeurlXX
labelField description (displayed with an asterisk for required fields).X
labelShortOptional shorter version of the labels (used in List and Cards views).X
requiredDetermines if the field is required for saving.XX
readOnlyField value cannot be changed.XX
defaultValueDefault field value for new records.XX
max, minMaximum/Minimum value allowed (only applies to numeric fields).XX
maxLength, minLengthMaximum/Minimum length allowed (only applies to text fields).XX
regExpRegular expression used to validate the field value.XX
inManyDetermines if the field is present (by default) in lists of records.XX
inSearchDetermine if the field is used in text searches.X
heightFor fields of type "textmultiline", number of lines used in the field (in Browse and Edit views).X
widthField width in Browse and Edit views (in percent of parent width). Default: 100%X
helpOptional help on the field.X
chartTypeDefault charts type used for the field ("Bars", "Pie", or "Table"). The default value is "Bars".X
searchInclude field in search.XX
noFilterExclude field from filters (only applies to fields of type integer, decimal, money, boolean, list of values which are "chartable").XX
noChartsExclude field from charts (only applies to fields of type integer, decimal, money, boolean, list of values which are "chartable").XX
noStatsExclude field from stats.XX
columnDatabase column name for the field.X
lovTableTable to join to for field value (only for fields of "lov" type).X
lovColumnColumn name (in the lovTable) for field value (only for fields of "lov" type).X
lovIconLOV items have icons (only for fields of "lov" type).XX
deleteTriggerDeleting records in the lovTable will trigger a cascade delete (this property is only used for creating the database).X
objectModel id for the object to link to (only for fields of "lov" type).XX
onlyUIThe field will only be present in the UI model.
onlyDBThe field will only be present in the DB model.

Group

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

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

PropertyMeaningUIDB
idUnique key for the group. It is optional.X
typeType of group. Only "panel" is currently implemented ("tab" and "accordeon" will be added later).X
labelGroup title as displayed to the user.X
fieldsArray of field ids.X
widthWidth (in % of the container total width).X
headerText to be displayed at the top of the group (just below the group title).X
footerText to be displayed at the bottom of the group.X

Collection

Multiple Master-Details can be specified with collections.

PropertyMeaningUIDB
idUnique key for the collection.XX
titleCollection title.X
tableTable to query for the details list.X
columnColumn in the details table to match against object's id.X
objectModel id for the object to link to. When specified, "column" and "table" can be omitted.XX
orderDirection to order by "asc" or "desc".X
orderBySQL where clause, e.g. { orderBy="id" }.X
fieldsArray of fields. Collections are not editable so their fields do not need as many properties as the main object's fields.XX

Sample models

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

Organizer

Music

Other models

Test

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.

Models for Designer

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) 2022 Olivier Giulieri.

Evolutility-Models is released under the MIT license.