#572 Make entity definition declarative
Closed: Fixed None Opened 13 years ago by admiyo.

Earlier implementations of the entity definitions were almost pure JSON stryl Javascript. While this had some significant drawbacks, it made it very clear how to define a new entity. The current scheme is much more Objecxt oriented and flexible, but has lost some of the clarity. Here are some tasks to restore it:

All UI containters (facets, dialoges etc) take an entity name, and use that when calculating the labels for all fields.

Creating any type of Widget is done from the UI container and passes along the entity name.

Remove all references to 'label' and instead us 'key'. keys are I18N lookups.

Where possible, remove code from the init methods. Ideally, we would have no init methods. Having methods named init and create is confusing. The work performed in the init method should be done in either the factory function body or in the create method.

create_entity returns a reference to the newly created entity.
entity will have, at a minimum, methods named search, details, and add_dialog. These will create the search and details facet, and the add_dialog, and then return references to the entity object. Those functions will take arrays

entity.search_facet gets a method called simply "column" which is shorthand for add_column(create_column)) and which returns the facet, so column definitions can be chained.

entity.details_facet gets a method named list_section which will be a rename and refactoring of ipa_stanza. ipa_stanza.input will be renamed text.

The end state should look something like this:
IPA.add_entity({name: 'hostgroup'}).
search().
column({name:'cn'}).
column({name:'description'}).
entity().
details().
section({name:'identity', label:'Hostgroup Details'}).
text({name:'cn'}).
text({name: 'description'})).
entity().
add_dialog().
text({ name: 'cn'}).
text({ name: 'description'})

Note that this requires the 'entity' call to chain the various facets together. There may be a better approach.

The declarative approach will still support custom facets. entity.facet(custom_facet(entity)) will return the facet. The convention is to call 'custom_facet(entity)' and pass along the parent object, as that is pretty much what details and search will do. Custom facets will need to support the entity() method to allow the declarative chaining posted above.


The declarative entity definition can be implemented on top of the existing object-oriented framework. This way we don't lose the benefits of OO design.

Currently when the entities are created the metadata is not available yet, so label assignments cannot be done during entity creation. The init() method is called after the metadata is loaded by IPA.init(), that way it can read I18N labels. Removing init() would require moving the entity creations after IPA.init().

The create() method is used to create HTML objects for that instance inside an HTML container. This is different than the instance creation itself. init() is invoked once when the code is loaded. create() can be invoked multiple times depending on user activity.

Metadata Update from @admiyo:
- Issue assigned to admiyo
- Issue set to the milestone: FreeIPA 2.0 - 2011/01 (cleanup)

7 years ago

Login to comment on this ticket.

Metadata