Extension talk:IssueTracker/Clif's hacks

(Moved here from --Nakohdo 19:02, 2 February 2011 (UTC))

= Clif's Issue Tracker Hacks - Nov 12, 2009 = Here are a bunch of field and functionality changes I have developed for Issue Tracker in order to make it better fit my needs. Some of these directly address previous functionality requests, and some are just things I wanted the tool to do. I hope you find them useful.

--Clif 10:29, 13 November 2009 (UTC)

Hack #1: Remove Lowercase Group Name Restriction
If you'd prefer not to have the extension dictate your group names, go to the hasPermission function in IssueTrackerAction.php and change to

Hack #2: Adding Fields (Priority and Severity)
I'll try to make this a good general overview of adding your own fields, and for those of you who have requested these specific fields in the past, you should be able to use this code as is.

Step 2: Add the set and get functions for the field arrays
In IssueTracker.config.php, add these two declarations somewhere above the setPermissions function:

Next, add the following function to set up the severity array:

If the "default" key/value pairs caught your eye, that's good, it means you're paying attention. That's part of Hack #3, so think of this as two hacks for the price of one. ;)

Now the get function:

Here's the same thing for the priority field:

Step 3: Add the new fields to the Model functions
In Models\IssueTrackerModelDefault.php, find the addIssue function and add the new fields to it:

Of course, we need to add them to the updateIssue function as well:

Step 4: Add the get functions to the Add and View Actions
Open Actions\IssueTrackerActionAdd.php and Actions\IssueTrackerActionView.php and look for the protected function _setDefaultVars functions. Add these two lines to both files:

Step 5: Add the get functions to the List and Edit Action
This is only slightly different from step 4. Open Actions\IssueTrackerActionList.php and find the protected function _setDefaultVars function. Add the following two lines:

Open Actions\IssueTrackerActionEdit.php and find the public function editAction function. Add the following two lines: . Add the following two lines:

We're almost there. :)

Step 6: Add the field names to the internationalization file
In IssueTracker.i18n.php, add the following field label definitions:

Step 7: Adding the new fields to the View pages
Let's look at the edit view (edit.html) first, as the table rows you'll be adding are structurally identical to the ones for status and type.

You'll probably want to adjust the values for tabindex depending on where you insert your fields.

The new table row code for the add view (add.html) is slightly different because it incorporates part of hack #4 for setting default field values.

Hopefully you're realizing by now that creating any new dropdown fields is pretty much a matter of search and replace in these code snippets.

Adding the new fields to the view View is a piece of cake Cake:

I didn't add colored backgrounds to these fields because I didn't want my wiki pages to look like a bag of skittles. If you're into that sort of thing, you can add colors by mimicking the code for the status and issue type fields in add.html, view.html and IssueTracker.config.php.

Moving on to list.html, first add the column headers:

And finally, the value columns. I put mine before the status column:

And that's it. Like I said, this should work for any dropdown field you want to add, so knock yourself out.

Hack #3: Setting default field values in IssueTracker.config.php
All of the necessary code for this hack was included in Hack #2, but here's a quick rundown of the required changes.

Step 1: Adding the "default" key/value pair
In IssueTracker.config.php, find the dropdown field(s) you want to define default values for and add a new "default" key to each field value array, with a value of "true" or "false". Obviously "true" is used to tell Issue Tracker which value is the default, so only one option should be set to "true".

Step 2: Setting up add.html to use the default values
Again, find the field or fields you want to default to a certain value. Change the table row blocks for those fields from:

to:

That's it.

Hack #4: Setting a field default using a tag argument
So let's say you want to have a dropdown field default to a specific value depending on the project. For example, I added a field called "websystem" so I could associate bugs or tasks with different internal systems like website, admin, intranet, etc. If I have a project page set up for a project that only affects the website, I want the field to default to "website". The hack works by adding the attribute "defaultsystem" to the issues tag with a value matching the name of the websystem which will be the default.

Of course, "defaultsystem" could actually be named whatever you want - "defaultcategory", "defaultassignee", etc. This is a good time to mention that attribute names are forced to lowercase, so if you name your attribute "defaultCategory" and try to reference it that way in the code, it won't work. Conversely, the value of the attribute should match your field array value exactly. So if the value is "Website" then your attribute would need to be defaultsystem="Website".

On to the code.

Step 1: Add a default for your default
In Actions\IssueTrackerActionAdd.php, you'll need to add a line to the _setDefaultVars function that looks like this:

Simple so far. A few lines down, in the _setHookPreferences function, add this block:

Step 2: Setting up add.html to use the default
The code for this is just slightly different from the code used in Hack #3.

Hack #5: Changing the default list sort order
I want my issue list sorted by priority, severity and issue id, in that order. Having the most important issues at the top make it easier to see what you should be working on first. Including issue id in the ordering criteria ensures that older issues get attention before newer ones having the same priority and severity.

This one's actually fairly simple. In Models\IssueTrackerModelDefault.php, find the getIssues function somewhere around line 30 and change your "Order By" option from this:

to:

... or whatever else you want to order by.

Hack #6: Replacing the summary field with an HTML editor
I got tired of either dealing with one huge summary paragraph or hand-coding HTML into that little textarea pretty quick. Adding a WYSIWYG editor is actually really easy, and you'll kick yourself for not having done it before. We're going to be using the Yahoo YUI SimpleEditor because it covers all the bases and is easy to implement.

Step 1:Replace the stylesheets and JavaScript in add.html and edit.html
You're going to be making the exact same changes to both files, so I'm just going to show the changes once.

At the very top of the file (pick one), you're going to replace this code:

with this:

Step 2: Apply the yui-skin-sam class name to a parent element
Add the YUI class to the parent

Step 3: Make a minor adjustment to the textarea tag
This change gets rid of the jTagEditor class (for the code you just ripped out) and renames the field id so Yahoo can take over your computer and turn you into a zombie geek as you spend the next 3 hours transfixed by the coolness of copying images and text from web pages and pasting them right into your new summary field. Just be sure to do all this stuff to that other file so disappointment doesn't hit you in the chest like a sledgehammer when you find yourself staring at that pitiful little textarea again.

Change this:

to this:

... and don't say I didn't warn you.

That's all I have time for now. Enjoy, and thanks to Federico for building such a great extension.

--Clif 10:29, 13 November 2009 (UTC)