Page 1 of 1

Installing independent mini-modules as tabs in a master 'dashboard' module.

Posted: Tue Nov 02, 2010 3:27 pm
by Wishbone
Often, when creating a website for a client, I make a custom 'dashboard' module that controls various elements of the home page.

Take my racing club's website for example: http://portlandkarting.com (hey.. web design isn't my day job :) )

I created a "PKA Dashboard" module that has tabs that control:

* Announcements
* Quick Links
* Which calendar categories show up in the sidebar
* A weather chooser. There is HTML for various cities where we have races stored in the database. The admin chooses which weather element to show in the sidebar.
* A sidebar manager where the admin can design as many sidebars as he wants, choosing content and order, and can choose which one is default. Overriding the default and pointing to another sidebar definition can be controlled by the "Extra 1" field when editing content.

I like to have it all in a dashboard module, so as to have a one-stop-shop to control everything on the front page, instead of having 5 separate modules that the admin needs to find.

Since each website is different, I tend to mix and match elements of different website's dashboard functions into a new creation for that site. This is a bit of a pain because:

* Difficult to create versioned releases of sub-functionality
* Need to create a .module.php script, merging elements of all functions.
* Merging together the install/uninstall functions
* Make sure that actions don't have the same name, etc.

I had an idea a few nights ago and decided to try creating a dashboard module containing tabs for completely independent child modules. You can download my example below:

http://teamwishbone.com/sub_module_test.zip (Note: This was only tested in 1.6.6 "Bonde"  ::))

This allows me to have independent modules that can be installed separately with a minor configuration to the dashboard wrapper to control them all. In the example, the dashboard module is 'test_dashboard' and the child modules are 'test_1' and 'test_2'

The configuration change needed for the dashboard module is:

test_dashboard/sub_modules.php

Code: Select all

$sub_modules = array(
  'test_1',
  'test_2'
);
The above array contains the names of the child modules and the order of the tabs. The code to instantiate the child modules inside of tabs is relatively simple. Instead of hard-coding the tab names and include the function.*.php scripts for the content, I do a foreach on the above array, set up the tabs, and call a method of the child module to include it's function.admin_tab.php script. (can't include it directly. Needs to be in the context of it's own object)

Excerpt from test_dashboard/action.defaultadmin.php

Code: Select all

include(dirname(__FILE__).'/sub_modules.php');
echo $this->StartTabHeaders();
foreach ($sub_modules as $sub_module) {
  if ($gCms->modules[$sub_module]) {
    echo($this->SetTabHeader(
           $sub_module,
           $gCms->modules[$sub_module]['object']->Lang('friendlyname'),
           ($sub_module == $tab)?true:false
        ));
  }
}
echo $this->EndTabHeaders();

echo $this->StartTabContent();
foreach ($sub_modules as $sub_module) {
  if ($gCms->modules[$sub_module]) {
    echo $this->StartTab($sub_module, $params);
    $gCms->modules[$sub_module]['object']->LoadAdminTab();
    echo $this->EndTab();
  }
}
echo $this->EndTabContent();
In the child module, I tell it to not show up in the admin panel (HasAdmin() set to false), so as to not clutter up the admin panel, since they are showing up in the dashboard anyways.

There were a couple of minor issues that I had to work around. The 'save' action of both child modules uses the usual redirect back to the defaultadmin action with the success message. However, I had to redirect it back to the parent module's defaultadmin. The only way I could figure out how to do it was to hard code it with:

Code: Select all

$gCms->modules['test_dashboard']['object']->Redirect($id, 'defaultadmin', $returnid, $params);
Also, the success message returned in $params has to be in the Lang file for the dashboard, as that's where it's redirecting to. These two issues make the submodule not entirely independent.

Anyways, I have not tested this out in a real world application. The next time I create a custom control panel, I'll take the time and convert my various tabs into standalone modules and should be able to mix-n-match them into a custom dashboard in minutes!

I really have no idea how useful this will be, just sorta thinking/testing out loud. Just thought I'd share this idea.

Re: Installing independent mini-modules as tabs in a master 'dashboard' module.

Posted: Thu Nov 04, 2010 11:47 am
by tomgsd
This isn't a bad idea and I can certainly see the merits of something like this for clients.  Having a section of the admin area to control things that cannot be easily controlled through the standard content blocks is a good idea.

At the moment I tend to use the AdvancedContent module for page options though.  It allows me to create all kinds of different inputs that appear when editing the pages.  For example, I regularly use it to show a checkbox and say something like "Show Left Column" or "Show Contact Form".  Then it's just a bit of smarty logic in the template to show or hide that section of html.

There's also the {content_module} tag which compatible modules can use to provide additional options when editing pages.

I think that with these two you can have an everything (or at least most stuff) in one page solution that can also be customised on a per page basis.