-
Notifications
You must be signed in to change notification settings - Fork 1
Simple task model

First the namespace:
create namespace tasks
Status values are defined as an enum, one create the enum in the tasks namespace.
create enum task_status [ready, in_progress, finished] > tasks
Let's add some values to the enum
task_status.enum << [draft, in_analysis, cancelled]
Create the TaskEvent entity in the tasks namespace scope.
create entity task_event > tasks
Let's define some basic attributes on the entity task_event scope only and not in the namespace or global scope. Mandatory field !, zero or one: ?.
create attribute event_date! date > task_event
create attribute comment? string > task_event
create attribute new_status? task_status > task_event
Attribute event_type is a nested enum within task_event:
create attribute event_type! [status_changed, comment_added] > task_event
Add a new event type, i.e. a new value to the event_type enum.
task_event.event_type.enum << [task_created]
create entity task > tasks
Create an alias with multiple ($*) placeholder to help in attribute creation, think of it as macro.
alias ca = create attribute $* > task
ca title! string
ca description? string
ca status! task_status
ca tags+ string
ca history* task_event
Mandatory field !, zero or one: ?, one or more: +, zero or more: *
Update the denormalized status whenever the history is modified:
task.history.onchange = function (event) {
var entity = event.entity;
var last_event = entity.history.last;
// not all event have the new_status attribute filled
if(last_event.event_type == 'status_changed)
entity.status = last_event.new_status
}
Note the ' to indicate the following is a symbol: 'status_changed denotes a value of the enum