• Document Up to Date
  • Updated On 4.0.1

Crafter Studio Dashboard Plugin Example

The dashboard contains different dashlets that show at a glance all items currently in workflow, all items recently modified by the current user, etc. Dashlets shown vary depending on the user’s role. For more information on the Dashboard, see here

Studio Dashboard

Let’s take a look at an example of creating a Dashboard plugin in Studio using a project called My Editorial created using the Website Editorial blueprint.

  1. The first thing we have to do is to create the folder structure where we will be placing the JS file for our dashboard plugin. We’ll follow the convention listed in UI Plugin Directory Structure. For our example, CATEGORY is dashboard and the NAME is test-dashboard

    In a local folder, create the descriptor file for your plugin craftercms-plugin.yaml with the plugin.id set to org.craftercms.plugin.exampletoolbar, then create the following folder structure:

    Dashboard Plugin Directory Structure

    We will be placing the JS file implementing the toolbar plugin under the test-toolbar folder For our example, the <plugin-folder> is located here: /users/myuser/myplugins/toolbar-plugin

  2. We’ll create the JavaScript file for our plugin by following the instructions in the plugin example here which will generate the index.js file.

    Inside the test-dashboard folder, create two empty files, index.css and script.js, and place the index.js file in it.

  3. To setup our dashboard plugin to be automatically wired in the corresponding configuration file in Studio (which for a dashboard, is the User Interface Configuration file) during the installation, add the following to your craftercms-plugin.yaml descriptor file

     2  - type: preview-app
     3    parentXpath: /siteUi/widget[@id='craftercms.components.Dashboard']
     4    testXpath: //plugin[@id='org.craftercms.plugin.dashboard']
     5    element:
     6      name: configuration
     7      children:
     8      - name: widgets
     9        children:
    10        - name: widget
    11          attributes:
    12          - name: id
    13            value: org.craftercms.sampleComponentLibraryPlugin.components.reactComponent
    14          children:
    15          - name: plugin
    16            attributes:
    17            - name: id
    18              value: org.craftercms.plugin.dashboard
    19            - name: type
    20              value: dashboard
    21            - name: name
    22              value: test-dashboard
    23            - name: file
    24              value: index.js
    26 |

    Remember to use the same value used in plugin.id (found at the top of the descriptor file) for the installation section plugin.id which for our example is org.craftercms.plugin

  4. After placing your plugin files and setting up auto-wiring, the plugin may now be installed for testing/debugging using the crafter-cli command copy-plugin.

    Dashboard plugin directory/files

    When running a crafter-cli command, the connection to CrafterCMS needs to be setup via the add-environment command. Once the connection has been established, we can now install the plugin to the project my-editorial by running the following:

    ./crafter-cli copy-plugin -e local -s my-editorial --path /users/myuser/myplugins/dashboard-plugin

  5. Let’s take a look at our plugin in action by clicking on the CrafterCMS logo at the top left of your browser to open the sidebar, then click on Dashboard:

    Dashboard plugin in action

    You may also open the Dashboard anywhere via the Launcher, which is opened by clicking the apps icon on the top right:

    Open Dashboard from the Launcher

    Here’s the auto-wired section in the configuration after installing the plugin:

     2  ...
     3  <widget id="craftercms.components.Dashboard">
     4    <configuration>
     5      <widgets>
     6        <widget id="craftercms.components.AwaitingApprovalDashlet">
     7          <permittedRoles>
     8            <role>admin</role>
     9            <role>developer</role>
    10            <role>publisher</role>
    11          </permittedRoles>
    12        </widget>
    13        ...
    14        <widget id="org.craftercms.sampleComponentLibraryPlugin.components.reactComponent">
    15          <plugin id="org.craftercms.plugin.dashboard"
    16                  type="dashboard"
    17                  name="test-dashboard"
    18                  file="index.js"/>
    19        </widget>
    20        ...