Creating_a_Dashboard[Permalink]Creating a Dashboard for your Users
Xataface allows you to build powerful data-driven applications quickly, but these applications may be daunting to your users if they don't know what they can do with the application. Most applications provide some sort of dashboard or control panel with some introductory instructions and links to commonly used actions in the application. This makes the application more intuitive for users so that they can start using it right away, even without instruction from the developer. Characteristics of a Dashboard
Strategies: 8 ways to skin the catThere are many viable strategies for adding a dashboard to your Xataface application. This article presents only one. It has been chosen because it satisfies all of the desired characteristics of a dashboard listed above, and it is easy to implement. This strategy involves the following components:
Our Sample ApplicationConsider our sample application, a publications management system for professors and research groups at a university. It allows users to manage their publications using either BibTex format or a web-based form, and embed those publications into their webpage in a slick sortable format. Currently, when the user accesses the application for the first time, they are shown the list tab of the bibliographies table. This isn't all that informative and it may not be obvious to the user that their first step should be to create a new bibliography via the new record button. Ideally we would like the user to go directly to a dashboard page with options to:
And we want some basic instructions so that the user knows what to do when they first access the page. The StepsTo create this dashboard we will follow the steps listed below (and mentioned above in the strategies section. Step 1: Create a dummy dashboard tableThis may seem unorthodox but it just happens to make our lives easier in the long run. By creating a dummy table we are able to cause that table to be listed first in the _tables section of the conf.ini file and thus be the default table when users visit our application.
Step 2: Make dashboard table defaultWe now modify the conf.ini file to list the dashboard table first:
Step 3: Create a Dashboard action and associated templateThis is the step where we actually create our dashboard action. There are three parts to this story: Creating Action PHP ClassThe actual action will be located in the actions/dashboard.php file of our application, and looks like:
All this does is loads the bibliographies records owned by the current user. Elsewhere we are using security filters so that the user can only see his bibliographies, which is why we don't need to specify any query here in the df_get_records_array function. It then passes those bibliographies to the dashboard.html template that we create next. Creating the Action's TemplateThe template for our action is located in the templates/dashboard.html file:
A few key things to notice in this template:
Adding entry to the actions.ini fileCurrently our dashboard action has no permissions attached to it so users can see it whether they are logged in or not. In this particular application we want to require users to log in, and we have set permissions for all logged in users to NO_ACCESS(). Unfortunately this permission setting is only helpful if our action requires a particular permission to access it. We'll require the 'view' permission for this action, by adding the following to the actions.ini file:
Step 4: Specify permissionsWe still want to specify permissions for our dashboard table to ensure that only logged in users can access the dashboard. So we create a delegate class for the dashboard table at tables/dashboard/dashboard.php with the following contents:
Note that we have defined the getUser() function elsewhere as a means of obtaining the current user and checking if a user is indeed logged in. Notice that this getPermissions? method returns all permissions only if the user is logged in. Otherwise it returns null, which means that it should use the same permissions as the rest of the application as defined in the Application Delegate Class. Step 6: Make dashboard the default action for the dashboard tableNow we just have one more detail that needs to be taken care of. We want the dashboard action to be the default action for the dashboard table only. By default we would see the list action which isn't helpful at all, so we will want to add a rule in our application delegate class to ensure that the user only sees our custom dashboard action if they access the dashboard table. We define a beforeHandleRequest() method in our conf/ApplicationDelegate.php (the application delegate class) file for this purpose:
This simply checks to see if the table is dashboard and changes the current action to dashboard if so. Step 7: Try it outAt this point, we are ready to try out our new dashboard to see how it works. When we load our application it should now go to the dashboard action that we created. We should also see Dashboard listed as the first table in the tables menu. This dashboard presents a major improvement to our application as it is now much more user friendly. blog comments powered by Disqus |