Skip to content

DSL File Configuration

SerenaG edited this page Dec 28, 2014 · 1 revision

Inside the collections/ folder there are some sample DSL files to take the cue from. As previously described, it's possible to manually specify in which folder take your own files by changing the application's configuration editing the config.js file. collections/ folder is set by default. The configuration of a collection is done by the configuration of a DSL file and it can be done with any text editor.

The basic configuration have to comply with the following syntax:

collection(
    name: "NomeCollection",
    label: "CollectionLabel",
    id: "CollectionId",
    weight: CollectionWeight
) {
    index(
        perpage: DocumentsPerPage,
        populate: AttributePopulate,
        sortby: "DefaultSort",
        order: "DefaultSortOrder",
        query: CollectionQuery
    ) {
        column(
            name: "AttributeName",
            label: "ColumnLabel",
            sortable: IndexSortable,
            selectable: IndexSelectable,
            transformation: TransformationFunction
        )
        // ...
    }
    show(
        populate: AttributePopulate
    ) {
        row(
            name: "AttributeName",
            label: "RowLabel",
            transformation : TransformationFunction
        )
        // ...
    }
}

When the server starts, the application read the directory and sequentially get all the files with extension .dsl inside it. The DSL interpreter parses these files and interfaces with the API of MaaP to generate all the classes and the models required to configure the given collections.

If during this process some errors occurs about the file interpretation and the execution of the code, they will be reported in the application. Inside the file you can define function and field outside the DSL code, to refer it inside it. Each expression accepts lists of parameters in JavaScript style, like: nameParameter: valueParameter. Some parameters are required and others are optional, which are set to default values if none is given.

Collection configuration

This expression show how the collection has to be configured. The index-page and show-page configurations will derived from it.

  • name (required): this parameter accepts a string. It's the name of the reference collection in the MongoDB database;

  • label (optional): this parameter accepts a string. It's the name that will appear in the index-page. If not specified it is automatically initialized with the value of the parameter name;

  • id (optional): this parameter accepts a string. It's the identification of the collection's URI. By default this parameter takes the value of the name parameter. It is used if you want to refer the same collection from different configurations;

  • weight (optional): this parameter accepts an integer. It's the visualization order of the collection in the navigation bar of the application, and in the Dashboard collection list. If not specified it is automatically initialized with 0 (zero);

Index configuration

This expression show how the index-page has to be configured. A precise structure and displaying of the page will derive from this configuration.

  • perpage (optional): this parameter accepts an integer greater than zero. It's the number of documents that will be displaying for each page. If the sum of all documents is grater than this parameter, the index-page will be paginated. If not specified it is automatically set to 50;

  • populate (optional): this parameter accepts a string. It's the external attribute on which execute the populate function;

  • sortby (optional): this parameter accepts a string. It's the attribute on which execute the default order in case of no column has been specified with the parameter sortable: true;

  • order (optional): this parameter accepts a string with value "asc" o "desc". It's the type of order for the sortby parameter:

    • "asc" means that the order will be ascending;
    • "desc" means that the order will be descending.
  • query (optional): this parameter accepts a JSON object. It's contains the parameters and the values on which execute the G query.

Column configuration

This expression show the configuration of a table's column of the index-page.

  • name (required): this parameter accepts a string. It's the attribute's name of the reference collection in the MongoDB database;

  • label (optional): this parameter accepts a string. It's the header's name of the index-page's table column. If not specified it is automatically set to the value of the name parameter;

  • sortable (optional): this parameter accepts a boolean. It specify whether of not the index-page could be sorted on the basis of this column. If not specified it is set to false;

  • selectable (optional): this parameter accepts a boolean. It specify whether or not the element could be a link which redirect to the related document. If not specified it is set to false;

  • transformation (optional): this parameter is an element's transformation function. The function has to return a value that will overwrite the result of the query.

Show configuration

This expression show how the show-page has to be configured. A precise structure and displaying of the page will derive from this configuration.

  • populate (optional): this parameter accepts a string. It's the external attribute on which execute the populate function.

Row configuration

This expression show the configuration of a show-page's table row.

  • name (required): this parameter accepts a string. It's the attribute's name of the reference collection in the MongoDB database;

  • label (optional): this parameter accepts a string. It's the header's name of the show-page's table row. If not specified it is automatically set to the value of the name parameter;

  • transformation (optional): this parameter is an element's transformation function. The function has to return a value that will overwrite the result of the query.