This tool generates HTML view for a database table; to be added to Node++ project. Requires also adding compatible DAO/ORM class to the project.
Live demo
You can try view generated for products live.
Authorization
You can define up to 4 levels of authorization. Middle levels can have further restrictions if column is defined: only the records belonging to the current user will be accessible. For example, the table may have columns sales_rep
and cust_id
. These columns can be specified for the Middle and Low levels, respectively. Then the sales rep will be able to access only the records belonging to their customers, that is records with sales_rep=<user ID>
, and the customer will only be able to access theirs.
In order for authorization to work properly, the table has to have single column as a primary key – either integer or string – and it needs to be the first column in the table definition.
Changing authorization rules after the files have been generated
Session levels and access permissions can easily be changed at any time by defining macros outside the generated files (see generated *.h
file). On the other hand, binding columns affect generated logic so in the case change is required, re-generating will be better than manually changing previously generated code.
Customizations' macros
Use macros in npp_app.h
:
#define VIEW_<table>_<action>_<device>_<feature>_<column>
Both table and column should be uppercase. Action means for example LIST
, DETAILS
, EDIT
. Device type can be DSK
or MOB
. Device or column might not always be present.
Columns' labels
By default, all columns' labels are simply capitalized columns' names. To change this define:
#define VIEW_PRODUCTS_QUANTITY "In Stock"
Styling
Most of the rendered HTMLs are based on tables. There is a group of macros as the placeholders for CSS's class="xyz"
to style many aspects of them, including separate classes for odd and even rows. See generated header file for the complete list.
Columns' visibility
By default, all columns except of TEXT and BLOB types will be shown on the list. If you want to hide some of them, you can set those which would be hidden – separately for the desktop and phone screen.
#define VIEW_PRODUCTS_LIST_DSK_HIDE_QUANTITY /* quantity will not be shown on the list on desktop */
#define VIEW_PRODUCTS_LIST_MOB_HIDE_QUANTITY /* quantity will not be shown on the list on the phone */
You can also make columns read-only:
#define VIEW_PRODUCTS_EDIT_READ_ONLY_QUANTITY
Enumerators
It's possible to automatically handle small lists as combo boxes. How to use it:
- Column type must be
char(1)
. npp_app.h
must contain value-description pairs as macros.
For example, if products
had a column allowed_abroad char(1)
then in npp_app.h
:
#define VIEW_PRODUCTS_ENUM_ALLOWED_ABROAD_01_VAL 'Y'
#define VIEW_PRODUCTS_ENUM_ALLOWED_ABROAD_01_DESC "Yes"
#define VIEW_PRODUCTS_ENUM_ALLOWED_ABROAD_02_VAL 'N'
#define VIEW_PRODUCTS_ENUM_ALLOWED_ABROAD_02_DESC "No"
Instead of showing Y
or N
, there would be Yes
and No
as the values. In the edit form, instead of input box there would be a combo box.
Maximum number of options for each column is 10.
Plug-ins
Sometimes there's a need for additional actions' buttons or additional columns from joined tables to be shown with the current record. Manually adding such a code would make it difficult to generate the views again. To solve this there are several places in the generated code for such custom injections. You can add to npp_app.h
:
List view
#define VIEW_PRODUCTS_LIST_BEFORE_TABLE code to be called before HTML table, i.e. for additional actions' buttons
#define VIEW_PRODUCTS_LIST_DISABLE_NEW hides New Record button
#define VIEW_PRODUCTS_LIST_DSK_BEFORE_HEADERS code to be called inside the HTML table row, before the first header (th)
#define VIEW_PRODUCTS_LIST_DSK_AFTER_HEADERS code to be called inside the HTML table row, after the headers set (th)
#define VIEW_PRODUCTS_LIST_DSK_BEFORE_COLUMNS code to be called inside the HTML table row, before the first column
#define VIEW_PRODUCTS_LIST_DSK_AFTER_COLUMNS code to be called inside the HTML table row, after the columns
and corresponding VIEW_PRODUCTS_LIST_MOB_xxx
set
Details view
#define VIEW_PRODUCTS_DETAILS_BEFORE_TABLE code to be called before HTML table, i.e. for additional actions' buttons
#define VIEW_PRODUCTS_DETAILS_BEFORE_COLUMNS code to be called inside the HTML table, before the first column
#define VIEW_PRODUCTS_DETAILS_AFTER_COLUMNS code to be called inside the HTML table, after the columns
Edit
#define VIEW_PRODUCTS_EDIT_BEFORE_COLUMNS code to be called inside the HTML table, before the first column
#define VIEW_PRODUCTS_EDIT_AFTER_COLUMNS code to be called inside the HTML table, after the columns
On save
#define VIEW_PRODUCTS_ON_SAVE code to be called when saving the record, inside the try block
On remove
#define VIEW_PRODUCTS_ON_REMOVE code to be called when removing the record, inside the try block
All above placeholders are after permission checking.
Filtering
As apparently there's no standard for filtering URLs, I decided to optimize it for clarity and shortness. I tried to avoid special characters that would force ugly URL encoding. Here's the summary:
Order can be specified by o
parameter, i.e.:
Descending order is indicated by od
parameter, i.e.: