New activeCollab Module: Project Menu Object Count | activeCollab – Project Management and Collaboration Tool

I’ve created a new module: Project Menu Object Count.

I wanted to know how many items there were in each tab so I could get right to the goods. And I didn’t like clicking through the tabs, waiting to find out if there were any tickets, pages, files, etc…

So the Project Menu Object Count module was born.
It will update the visible menus tabs when in a project appending them with the number of items for that object type. For example, if you have 12 milestones in a project, that tab would read “Milestones (12)”. It leverages the API in hopes that it will continue to function in future releases.

Here are my tabs before:

Here is a screen shot of tabs with Project Menu Object Count installed:

Notes / Compatibility:
Tested with aC version 2.3.2 and the standard theme.

This module uses jQuery to identify the available projects for the current user by lopping through the visible tabs. The benefit of using jQuery is that it doesn’t slow down the page load time. The disadvantage is that it has been developed and tested in the default aC theme and may not work in other themes if they implement custom id’s for menu tabs. That being said, the script isn’t too strict. It simply looks for a dom block with the id: #tabs and the li’s contained with in. i.e. $(‘#tabs li’).each(…);
The id of those list items should also be standardized. The milestones tab, for example uses this html:

<li>

This script extracts the object type from that ID: “milestones” and passes that to the API to get a count of items.

Limitations: the current API (shipped with aC 2.3.2) does not return the number of pages. Two patches have been submitted to aC support that would fix the problem, and both are included with the module zip file.

Dependencies:
jQuery
aC API
javascript variables populated by the system:
App.data.active_project_id
App.data.homepage_url

Installation instructions:
In order to install the Project Menu Object Count module and run it successfully you need to follow the following instructions.
——————————————————————————–
Step 1. Unzip the projectmenuobjectcount.zip provided.

Step 2. Copy the public/assets/modules/projectmenuobjectcount folder to activecollab >> application >> modules in your site. We have placed it in the similar structure for your better understanding.

Step 3. Copy the public/assets/modules/projectmenuobjectcount folder to your publicassetsmodules folder

Step 4. Login in your system and you will find the new Module ready to be installed

Step 5. After installation, please go to main administration page and click on the Project Menu Object Count icon and enable it.
================================================================================

After installation you will see object count appended to your menu tabs.

================================================================================

The module structure is a simple as possible.
It contains the two requisite files: init.php and module.class.php on the application side. These don’t declare anything special just the bare-bones requirements.
The public side contains the module icons and one .js file: main.js.

Keep in mind that this was built to suit my specific use case and may not work for everyone.
Try it out, see what you think. I find it really valuable.

The initial release is version = “2.3.x-1.0”.
The initial release is version = “2.3.x-1.0”.
Cost: free.
Zip file: http://www.activecollab.com/forums/attachments/get/1175/


Here’s the main.js code:

$(document).ready(function(){  /*run after jQuery loads*/
	var currentProjectID = App.data.active_project_id;
	var currentHomepageUrl = App.data.homepage_url;
	$('#tabs li').each(
		function(){
			tab = ''; //set default
			tab = $(this).attr('id'); //get object name from tab id
			tabName = ''; //set default
			tabName = tab.replace('page_tab_',''); //extract name from id
			function popTabCount(tab, tabName){
				$.getJSON(currentHomepageUrl+"/api.php?path_info=/projects/"+currentProjectID+"/"+tabName+"&amp;format=json",
					function(json) {
						if (json == null){
							//could show a 0 here.
							//jsonDataLength = "0";
						} else {
							if(typeof(json[0].type)!=="undefined" &amp;&amp; (tabName.search(json[0].type.toLowerCase())!==-1) || (tabName == 'people')){
								jsonDataLength = json.length;
								$('#'+tab).find('a span').not(' .count').append(' <i>('+jsonDataLength+')</i>');
							} else {
								//could show a 0 here.
								//jsonDataLength = "0";
							} //end if typeof(json[0].type)!=="undefined" ...
						} //end if (json == null)
						//$('#'+tab).find('.count').text('('+jsonDataLength+')').show(); //moved up into if()
					} //end function json
				); //end getJSON()
			} //end function popTabCount()
			popTabCount(tab, tabName);
		} //end function
	); //end each
}); //end ready

Posted on aC here: New Module for your review: Project Menu Object Count | activeCollab – Project Management and Collaboration Tool.

Leave a Comment