View Issue Details

IDProjectCategoryView StatusLast Update
0024146mantisbtfilterspublic2018-03-31 19:58
ReporterMarnix Assigned Toatrol  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionno change required 
Product Version2.12.0 
Summary0024146: Filtering in 'all projects' of custom dynamic fields doesn't work when selecting 'All projects'.
Description

When using an dynamic function as a listbox the options in the filter-box is gone. Only option 'any' is visible and selectable.

How am I able to fix this?
Any help is very much appreciated.

Thank you.

Steps To Reproduce

I have created one dynamic custom field of type 'enumeration' type using this function as an example:
https://www.mantisbt.org/wiki/doku.php/mantisbt:dynamic_enum_custom_fields
I have attached this particular dynamic field to multiple projects and sub-projects.

I made the this dynamic custom field also visible within the filter-box in the 'View all page'.

When I am on the page 'View all' and I have selected one of the projects, the filter is working like expected. The items are visible in de listbox.

But when I select 'All Projects' the listbox only contains the option 'Any'. So therefore I am not able to filter over multiple (sub)projects.

TagsNo tags attached.

Activities

atrol

atrol

2018-03-21 19:45

developer   ~0059270

Marnix,

This is not a bug or feature request for MantisBT (you are asking for help on how to write a custom function). I am therefore resolving this issue as "no change required".

Please use the forums to get support on customizing and using MantisBT (refer to http://www.mantisbt.org/support.php for links and further details)
When doing this, you should at least provide a screen shot of your custom field definition and the source code of your custom function.

Marnix

Marnix

2018-03-22 05:09

reporter   ~0059278

Last edited: 2018-03-22 05:27

Hi Atrol,

hmmm, i do not agree.

The function is working perfectly, but the items won't show in the filterbox when selecting a parent project or 'all projects'.
So therefore, in my opinion, this is an flaw.

I made an extra table in Mantis for this function, 'mantis_custom_field_component_table'
with the column; id, project_id, category, name.

1) when project_id = 0, it means it can be selected within any project.
2) when project_id = corresponding with the current project, it shows only within that project.

When in the parent 'view all' page on 'all projects' it shows only the items where project_id = 0. And not the items in the sub-projects.

What the function does:
It picks out the components (name) for that particular project (project_id), when reporting or updating an issue.

Code of the function:
To use this in a custom field type "=component" in the possible values field.

function custom_function_override_enum_component() {
    $t_project_id = helper_get_current_project();

    global $g_db;
    $t_enum = array();

    db_param_push();

    $query = 'SELECT DISTINCT name
              FROM {custom_field_component}
              WHERE project_id = ' . $t_project_id . ' OR project_id = 0
              ORDER BY category, name';

    $res = db_query_bound($query);  

    $count = $res->RecordCount();
    for ($i=0; $i<$count; $i++) {
        $row = db_fetch_array( $res);
        $t_enum[] = $row['name'];
    }

    $t_possible_values = implode( '|', $t_enum );

    return $t_possible_values; 
}

Below the SQL code for the extra table:

CREATE TABLE scrb_custom_field_component_table (
id int(10) UNSIGNED NOT NULL,
project_id int(10) NOT NULL DEFAULT '0',
product varchar(191) NOT NULL DEFAULT '',
name varchar(191) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO scrb_custom_field_component_table (id, project_id, category, name) VALUES
(1, 0, 'category 1', 'Other'),
(2, 1, 'category 2', 'component 1'),
(3, 1, 'category 2', 'component 2'),
(4, 1, 'category 3', 'component 3'),
(5, 1, 'category 3', 'component 4'),
(6, 2, 'category 3', 'component 5'),
(7, 2, 'category 4', 'component 6');

ALTER TABLE scrb_custom_field_component_table
ADD PRIMARY KEY (id);

========
What i would like (other topic, i know):
That it shows only the components (name) of the particular project (project_id) and for the category (category) that is selected when reporting or updating an issue. Unfortunately i don't know how to write this piece of code. Any help on this is very much appreciated. (I'll probably have to change category into category_id)

cproensa

cproensa

2018-03-22 05:19

developer   ~0059279

Is this a regression? something that worked in a previous version of mantis, but now it doesn't for latest version?

In the wiki page it says:
The enumeration will be empty if current project is ALL PROJECTS.
is that what you are describing?

I'm not familiar with those custom functions, so a detailed example of code will be helpful.

atrol

atrol

2018-03-22 05:32

developer   ~0059280

The function is working perfectly, but the items won't show in the filterbox when selecting a parent project or 'all projects'.

From what I see the functions does just what you implemented.

you have
WHERE project_id = ' . $t_project_id . ' OR project_id = 0
and $t_project_id is set to the current project which is 0 if you have selected All Projects

Marnix

Marnix

2018-03-22 17:55

reporter   ~0059291

Thanks for your feedback. That clarifies it indeed!

So i have changed the SQL statement with:
if ($t_project_id <> 0) {

$t_query2 = 'SELECT count(child_id) as count, child_id, parent_id 
            FROM {project_hierarchy} 
            GROUP BY child_id, parent_id';

$t_result = db_query( $t_query2 );
while( $t_row = db_fetch_array( $t_result ) ) {
    $t_count = (int)$t_row['count'];
    $t_child_id = (int)$t_row['child_id'];
    $t_parent_id = (int)$t_row['parent_id'];    
}

    $query = 'SELECT DISTINCT name
          FROM {custom_field_component}
          WHERE project_id = ' . $t_project_id . ' OR project_id = ' . $t_child_id . ' OR project_id = 0
          ORDER BY category, name';
} else {
    $query = 'SELECT DISTINCT name
          FROM {custom_field_component}
          ORDER BY category, name';
}

With this new if else statement i also included sub-projects.

I have also made progress on the listed items per category, but only when updating a bug, not when reporting a new bug. :(

But we can close this issue. I'll will share my solution in the forum.
Thanks again!