<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.7.2" -->
<rss version="2.0">
    <channel>
        <title>Creating_a_Dashboard[ Search for &quot;&quot;]</title>
        <description></description>
        <link>http://xataface.com/wiki/index.php?-action=single_record_search&amp;-table=wiki&amp;page_id=%3D57&amp;-cursor=0&amp;-skip=0&amp;-limit=30&amp;-mode=list&amp;--subsearch=</link>
        <lastBuildDate>Sat, 25 May 2013 11:48:53 +0100</lastBuildDate>
        <generator>FeedCreator 1.7.2</generator>
        <item>
            <title>Creating_a_Dashboard</title>
            <link>http://www.xataface.com/wiki/Creating_a_Dashboard</link>
            <description>&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Field&lt;/th&gt;&lt;th&gt;Value&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page name&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;Creating_a_Dashboard&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page id&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;57&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Page title&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;Creating_a_Dashboard&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Content&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;
&lt;h2 id=&quot;toc0&quot;&gt;Creating a Dashboard for your Users&lt;/h2&gt;
&lt;table border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;&lt;tr&gt;&lt;td&gt;
&lt;div id=&quot;toc&quot;&gt;&lt;strong&gt;Table of Contents&lt;/strong&gt;
	&lt;div style=&quot;margin-left: 0em;&quot;&gt;&lt;a href=&quot;#toc0&quot;&gt;Creating a Dashboard for your Users&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc1&quot;&gt;Characteristics of a Dashboard&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc2&quot;&gt;Strategies: 8 ways to skin the cat&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 0em;&quot;&gt;&lt;a href=&quot;#toc3&quot;&gt;Our Sample Application&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 0em;&quot;&gt;&lt;a href=&quot;#toc4&quot;&gt;The Steps&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc5&quot;&gt;Step 1: Create a dummy &lt;em&gt;dashboard&lt;/em&gt; table&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc6&quot;&gt;Step 2: Make &lt;em&gt;dashboard&lt;/em&gt; table default&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc7&quot;&gt;Step 3: Create a Dashboard action and associated template&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 2em;&quot;&gt;&lt;a href=&quot;#toc8&quot;&gt;Creating Action PHP Class&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 2em;&quot;&gt;&lt;a href=&quot;#toc9&quot;&gt;Creating the Action's Template&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 2em;&quot;&gt;&lt;a href=&quot;#toc10&quot;&gt;Adding entry to the actions.ini file&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc11&quot;&gt;Step 4: Specify permissions&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc12&quot;&gt;Step 6: Make &lt;em&gt;dashboard&lt;/em&gt; the default action for the &lt;em&gt;dashboard&lt;/em&gt; table&lt;/a&gt;&lt;/div&gt;
	&lt;div style=&quot;margin-left: 1em;&quot;&gt;&lt;a href=&quot;#toc13&quot;&gt;Step 7: Try it out&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;

&lt;p&gt;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.&lt;/p&gt;


&lt;h3 id=&quot;toc1&quot;&gt;Characteristics of a Dashboard&lt;/h3&gt;
&lt;ol&gt;
    &lt;li&gt; Should be the default page when someone visits the application.&lt;/li&gt;
    &lt;li&gt; Should be customized to show menus and content that are relevant to the current user.  (i.e. different users may see different links and content on their dashboard).&lt;/li&gt;
    &lt;li&gt; Should contain at least some basic instructions so that the user understands what the application does when he visits the dashboard for the first time.&lt;/li&gt;
    &lt;li&gt; Should contain links to frequently used actions.&lt;/li&gt;
&lt;/ol&gt;


&lt;h3 id=&quot;toc2&quot;&gt;Strategies: 8 ways to skin the cat&lt;/h3&gt;
&lt;p&gt;There 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.&lt;/p&gt;

&lt;p&gt;This strategy involves the following components:&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt; Create a dummy &lt;em&gt;dashboard&lt;/em&gt; table.&lt;/li&gt;
    &lt;li&gt; Create a dashboard action and associated template.&lt;/li&gt;
    &lt;li&gt; Make sure our dashboard action is the default action for our application (more complex than just using the default_action&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=default_action&quot;&gt;?&lt;/a&gt; directive in the &lt;a href=&quot;/wiki/conf.ini_file&quot;&gt;conf.ini file&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;


&lt;h2 id=&quot;toc3&quot;&gt;Our Sample Application&lt;/h2&gt;
&lt;p&gt;Consider 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 &lt;em&gt;list&lt;/em&gt; tab of the &lt;em&gt;bibliographies&lt;/em&gt; 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 &lt;em&gt;new record&lt;/em&gt; button.  Ideally we would like the user to go directly to a dashboard page with options to:&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt; Add New Bibliography&lt;/li&gt;
    &lt;li&gt; Edit an Existing Bibliography&lt;/li&gt;
    &lt;li&gt; Embed a Bibliography into their Webpage&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And we want some basic instructions so that the user knows what to do when they first access the page.&lt;/p&gt;


&lt;h2 id=&quot;toc4&quot;&gt;The Steps&lt;/h2&gt;
&lt;p&gt;To create this dashboard we will follow the steps listed below (and mentioned above in the &lt;em&gt;strategies&lt;/em&gt; section.&lt;/p&gt;


&lt;h3 id=&quot;toc5&quot;&gt;Step 1: Create a dummy &lt;em&gt;dashboard&lt;/em&gt; table&lt;/h3&gt;
&lt;p&gt;This 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 &lt;em&gt;_tables&lt;/em&gt; section of the &lt;a href=&quot;/wiki/conf.ini_file&quot;&gt;conf.ini file&lt;/a&gt; and thus be the default table when users visit our application.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;CREATE TABLE dashboard (
    dashboard_id int(11) not null auto_increment primary key
);
INSERT INTO dashboard values (1);&lt;/code&gt;&lt;/pre&gt;


&lt;h3 id=&quot;toc6&quot;&gt;Step 2: Make &lt;em&gt;dashboard&lt;/em&gt; table default&lt;/h3&gt;
&lt;p&gt;We now modify the conf.ini file to list the &lt;em&gt;dashboard&lt;/em&gt; table first: 
&lt;pre&gt;&lt;code&gt;[_tables]
    dashboard=Dashboard
    bibliographies=Bibliographies&lt;/code&gt;&lt;/pre&gt;

&lt;/p&gt;


&lt;h3 id=&quot;toc7&quot;&gt;Step 3: Create a Dashboard action and associated template&lt;/h3&gt;
&lt;p&gt;This is the step where we actually create our dashboard action.  There are three parts to this story:&lt;/p&gt;


&lt;h4 id=&quot;toc8&quot;&gt;Creating Action PHP Class&lt;/h4&gt;
&lt;p&gt;The actual action will be located in the &lt;em&gt;actions/dashboard.php&lt;/em&gt; file of our application, and looks like:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;&amp;lt;?php
class actions_dashboard {
    function handle(&amp;amp;$params){
        $bibs = df_get_records_array('bibliographies', array());
        df_display(array('bibliographies'=&amp;gt;$bibs), 'dashboard.html');
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;All this does is loads the &lt;em&gt;bibliographies&lt;/em&gt; records owned by the current user. Elsewhere we are using security filters so that the user can only see &lt;em&gt;his&lt;/em&gt; bibliographies, which is why we don't need to specify any query here in the &lt;em&gt;df_get_records_array&lt;/em&gt; function.&lt;/p&gt;

&lt;p&gt;It then passes those bibliographies to the &lt;em&gt;dashboard.html&lt;/em&gt; template that we create next.&lt;/p&gt;


&lt;h4 id=&quot;toc9&quot;&gt;Creating the Action's Template&lt;/h4&gt;
&lt;p&gt;The template for our action is located in the &lt;em&gt;templates/dashboard.html&lt;/em&gt; file: 
&lt;pre&gt;&lt;code&gt;{use_macro file=&amp;quot;Dataface_Main_Template.html&amp;quot;}
    {fill_slot name=&amp;quot;main_column&amp;quot;}
        &amp;lt;h1&amp;gt;Welcome to the BibTeX Publication Management System (BPMS)&amp;lt;/h1&amp;gt;
        
        &amp;lt;p&amp;gt;This system allows you to manage your publications and publish
        them on the web.  Some common actions you may perform with this system
        include:
            &amp;lt;ul&amp;gt;
                &amp;lt;li&amp;gt;&amp;lt;img src=&amp;quot;{$ENV.DATAFACE_URL}/images/add_icon.gif&amp;quot;/&amp;gt;
                    &amp;lt;a href=&amp;quot;{$ENV.DATAFACE_SITE_HREF}?-table=bibliographies&amp;amp;-action=new&amp;quot;&amp;gt;
                        Create New Bibliography&amp;lt;/a&amp;gt;
                &amp;lt;/li&amp;gt;
                &amp;lt;li&amp;gt;&amp;lt;img src=&amp;quot;{$ENV.DATAFACE_URL}/images/edit.gif&amp;quot;/&amp;gt; 
                   Edit existing bibliography: 
                   &amp;lt;select onchange=&amp;quot;window.location.href=this.options[this.selectedIndex].value&amp;quot;&amp;gt;
                    &amp;lt;option value=&amp;quot;&amp;quot;&amp;gt;Select ...&amp;lt;/option&amp;gt;
                    {foreach from=$bibliographies item=bibliography}
                        &amp;lt;option value=&amp;quot;{$bibliography-&amp;gt;getURL('-action=edit')}&amp;quot;&amp;gt;
                            {$bibliography-&amp;gt;getTitle()}
                        &amp;lt;/option&amp;gt;
                    
                    {/foreach}
                &amp;lt;/select&amp;gt;
                &amp;lt;/li&amp;gt;
                &amp;lt;li&amp;gt;&amp;lt;img src=&amp;quot;{$ENV.DATAFACE_URL}/images/file.gif&amp;quot;/&amp;gt; 
                    Embed your bibliography in a webpage:
                    &amp;lt;select onchange=&amp;quot;window.location.href=this.options[this.selectedIndex].value&amp;quot;&amp;gt;
                    &amp;lt;option value=&amp;quot;&amp;quot;&amp;gt;Select ...&amp;lt;/option&amp;gt;
                    {foreach from=$bibliographies item=bibliography}
                        &amp;lt;option value=&amp;quot;{$bibliography-&amp;gt;getURL('-action=view')}#embed&amp;quot;&amp;gt;
                            {$bibliography-&amp;gt;getTitle()}
                        &amp;lt;/option&amp;gt;
                    
                {/foreach}
                &amp;lt;/select&amp;gt;
                &amp;lt;/li&amp;gt;
                
            &amp;lt;/ul&amp;gt;
    {/fill_slot}
{/use_macro}&lt;/code&gt;&lt;/pre&gt;

&lt;/p&gt;

&lt;p&gt;A few key things to notice in this template:&lt;/p&gt;

&lt;ol&gt;
    &lt;li&gt; It extends the &lt;em&gt;Dataface_Main_Template.html&lt;/em&gt; template placing its content in the &lt;em&gt;main_column&lt;/em&gt; slot.  This allows our action to still display within the header and footer of our application.&lt;/li&gt;
    &lt;li&gt; It makes use of the {$ENV.DATAFACE_SITE_URL} and {$ENV.DATAFACE_SITE_HREF} variables to refer to the site's base url and create links to the desired common actions.&lt;/li&gt;
    &lt;li&gt; It provides a direct link to the &lt;em&gt;new bibliography record&lt;/em&gt; form.&lt;/li&gt;
    &lt;li&gt; It uses some slick javascript combined with select lists to allow the user to select any of his current bibliogaphies and edit them, or embed them into a webpage.&lt;/li&gt;
&lt;/ol&gt;


&lt;h4 id=&quot;toc10&quot;&gt;Adding entry to the actions.ini file&lt;/h4&gt;
&lt;p&gt;Currently 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:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;[dashboard]
    permission=view&lt;/code&gt;&lt;/pre&gt;


&lt;h3 id=&quot;toc11&quot;&gt;Step 4: Specify permissions&lt;/h3&gt;
&lt;p&gt;We still want to specify permissions for our &lt;em&gt;dashboard&lt;/em&gt; table to ensure that only logged in users can access the dashboard.  So we create a delegate class for the &lt;em&gt;dashboard&lt;/em&gt; table at &lt;em&gt;tables/dashboard/dashboard.php&lt;/em&gt; with the following contents:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;&amp;lt;?php
class tables_dashboard {
    function getPermissions(&amp;amp;$record){
        if ( getUser() ){
            return Dataface_PermissionsTool::ALL();
        }
        return null;
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;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.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Notice that this getPermissions&lt;a href=&quot;/wiki/index.php?-action=new&amp;-table=wiki&amp;page_name=getPermissions&quot;&gt;?&lt;/a&gt; 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 &lt;a href=&quot;/wiki/Application_Delegate_Class&quot;&gt;Application Delegate Class&lt;/a&gt;.&lt;/p&gt;


&lt;h3 id=&quot;toc12&quot;&gt;Step 6: Make &lt;em&gt;dashboard&lt;/em&gt; the default action for the &lt;em&gt;dashboard&lt;/em&gt; table&lt;/h3&gt;
&lt;p&gt;Now we just have one more detail that needs to be taken care of.  We want the &lt;em&gt;dashboard&lt;/em&gt; action to be the default action for the &lt;em&gt;dashboard&lt;/em&gt; table only.  By default we would see the &lt;em&gt;list&lt;/em&gt; 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 &lt;em&gt;dashboard&lt;/em&gt; action if they access the &lt;em&gt;dashboard&lt;/em&gt; table.  We define a beforeHandleRequest() method in our conf/ApplicationDelegate.php (the application delegate class) file for this purpose:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;&amp;lt;?php
class conf_ApplicationDelegate {
    
...
    function beforeHandleRequest(){
        ...
        $app =&amp;amp; Dataface_Application::getInstance();
    $query =&amp;amp; $app-&amp;gt;getQuery();
    if ( $query['-table'] == 'dashboard' and ($query['-action'] == 'browse' or $query['-action'] == 'list') ){
        $query['-action'] = 'dashboard';
    }
        
        
    }
    
    ...
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This simply checks to see if the table is &lt;em&gt;dashboard&lt;/em&gt; and changes the current action to &lt;em&gt;dashboard&lt;/em&gt; if so.&lt;/p&gt;


&lt;h3 id=&quot;toc13&quot;&gt;Step 7: Try it out&lt;/h3&gt;
&lt;p&gt;At 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 &lt;em&gt;Dashboard&lt;/em&gt; listed as the first table in the tables menu.&lt;/p&gt;

&lt;p&gt;This dashboard presents a major improvement to our application as it is now much more user friendly.&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://media.weblite.ca/files/photos/pub-dashboard.png?max_width=640&quot;/&gt;
&lt;/p&gt;

&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Keywords&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;dashboard&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=&quot;top&quot;&gt;Language&lt;/td&gt;&lt;td valign=&quot;top&quot;&gt;en&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</description>
            <author>Creating_a_Dashboard</author>
        </item>
    </channel>
</rss>
