| ]project-open[ Core : Dynamic Views
]project-open[ Core

# Dynamic Views

### Requirements

Frequent new modules need to extend the ListPages of important business objects (such as companies, projects, ...) by their additional columns. For example the P/O Timesheet module may need to add a column to the ProjectListPage with the amount of hours spend on every projects. The P/O Core module may not know about this future necessity in the moment is is implemented. So we want to allow a-posteriori extension of ListPages.

Dynamic Views are also required/desired when showing information about subclasses of objects, such as an EmployeeListPage. The EmployeeListPage may want to add a column such as "Monthly Salary", which does not make sense in the general UserListPage. Dynamic Views allow to have a single .tcl/.adp page showing different views, depending on URL runtime parameters.

### Design

To allow for dynamic extensibility, we keep all column information in a database table:

- Column Name
- Column Render TCL
  TCL code being dynamically called for each table cell to return the HTML code for this cell
- Extra Select
  SQL code to be included in the SELECT section of the SQL query.
- Extra Where
  SQL code to be included in the WHERE section of the SQL query.
- Visible For
  TCL code that needs to evaluate to "1" in order to show the column to the specific user. This field typically contains im_xxx_permission calls to validate the users access rights.

    create table im_view_columns (
           column_id				integer
    								constraint im_view_columns_pk
    								primary key,
           view_id				integer not null
    								constraint im_view_view_id_fk
    								references im_views,
           column_name			varchar(100) not null,
           -- tcl command being executed using "eval" for rendering the column
           column_render_tcl		varchar(4000),
           -- add to select statement for when the column name results from an "as" command
           -- for ex., you can customize viewing columns
           extra_select			varchar(4000),
           extra_where			varchar(4000),
           sort_order				integer not null,
           -- set of permission tokens that allow viewing this column,
           -- separated with spaces and OR-joined
           visible_for			varchar(1000)
    );

Im_views contains a mapping of names to view_ids and provides RI to im_view_columns:

- Visible For contains a TCL expressions that needs to evaluate to 1 in order for the current user to be allowed to access this view.

    create table im_views (
           view_id                  integer
                                    constraint im_views_pk
                                    primary key,
           view_name                varchar(100)
                                    constraint im_views_name_un
                                    not null unique,
           visible_for              varchar(1000)
    );

There is a typical ListPage example that shows how everything fits together.