View Issue Details

IDProjectCategoryView StatusLast Update
0011385mantisbtcustom fieldspublic2018-05-15 01:45
Reporteram-gtz Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
Product Version1.2.0rc2 
Summary0011385: Put custom fields on top of the report page (before category)
Description

We needed to insert custom fields on top of the report page instead of putting after the built-in fields of mantis.

Additional Information

The attached patch shows custom fields with a negative sequence number on top of the report. Custom fields with a sequence >=0 are shown as usual.

Tagsmantishub, patch
Attached Files
custom-fields-on-top.patch (5,980 bytes)   
diff -r -u mantis-120rc2-original/mantisbt-1.2.0rc2/bug_report_page.php mantis-120rc2-gtz/mantisbt-1.2.0rc2/bug_report_page.php
--- mantis-120rc2-original/mantisbt-1.2.0rc2/bug_report_page.php	2010-01-12 15:55:59.485813285 +0300
+++ mantis-120rc2-gtz/mantisbt-1.2.0rc2/bug_report_page.php	2010-01-12 16:22:07.008339052 +0300
@@ -170,6 +170,25 @@
 <?php
 	event_signal( 'EVENT_REPORT_BUG_FORM_TOP', array( $t_project_id ) );
 
+	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id , CUSTOM_FIELD_SEQUENCE_TOP);
+
+	foreach( $t_related_custom_field_ids as $t_id ) {
+		$t_def = custom_field_get_definition( $t_id );
+		if( ( $t_def['display_report'] || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
+			$t_custom_fields_found = true;
+?>
+	<tr <?php echo helper_alternate_class() ?>>
+		<td class="category">
+			<?php if($t_def['require_report']) {?><span class="required">*</span><?php } echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+		</td>
+		<td>
+			<?php print_custom_field_input( $t_def, ( $f_master_bug_id === 0 ) ? null : $f_master_bug_id ) ?>
+		</td>
+	</tr>
+<?php
+		}
+	} # foreach( $t_related_custom_field_ids as $t_id )
+	
 	if ( $tpl_show_category ) {
 ?>
 	<tr <?php echo helper_alternate_class() ?>>
@@ -437,8 +456,7 @@
 <?php
 	}
 
-	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
+	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id , CUSTOM_FIELD_SEQUENCE_BOTTOM);
 
 	foreach( $t_related_custom_field_ids as $t_id ) {
 		$t_def = custom_field_get_definition( $t_id );
diff -r -u mantis-120rc2-original/mantisbt-1.2.0rc2/core/custom_field_api.php mantis-120rc2-gtz/mantisbt-1.2.0rc2/core/custom_field_api.php
--- mantis-120rc2-original/mantisbt-1.2.0rc2/core/custom_field_api.php	2010-01-12 15:55:59.555807656 +0300
+++ mantis-120rc2-gtz/mantisbt-1.2.0rc2/core/custom_field_api.php	2010-01-12 16:22:25.998306841 +0300
@@ -792,18 +792,23 @@
 	return $row['id'];
 }
 
+define( 'CUSTOM_FIELD_SEQUENCE_ALL' , 0);  # retrive all custom fields
+define( 'CUSTOM_FIELD_SEQUENCE_TOP', 1);   # retrive custom fields to show on top (negative IDs)
+define( 'CUSTOM_FIELD_SEQUENCE_BOTTOM', 2);  # retrive custom fields to show on top (non-negative IDs)
+
 /**
  * Return an array of ids of custom fields bound to the specified project
  *
- * The ids will be sorted based on the sequence number associated with the binding
+ * If a p_project_id is given, the ids will be sorted based on the sequence number associated with the binding.
  * @param int $p_project_id project id
+ * @param int $p_sequence on of the CUSTOM_FIELD_SEQUENCE constants
  * @return array
  * @access public
  */
-function custom_field_get_linked_ids( $p_project_id = ALL_PROJECTS ) {
+function custom_field_get_linked_ids( $p_project_id = ALL_PROJECTS , $p_sequence = CUSTOM_FIELD_SEQUENCE_ALL) {
 	global $g_cache_cf_linked, $g_cache_custom_field;
 
-	if( !isset( $g_cache_cf_linked[$p_project_id] ) ) {
+	if( !isset( $g_cache_cf_linked[$p_project_id] ) or $p_sequence <> CUSTOM_FIELD_SEQUENCE_ALL ) {
 
 		$t_custom_field_table = db_get_table( 'mantis_custom_field_table' );
 		$t_custom_field_project_table = db_get_table( 'mantis_custom_field_project_table' );
@@ -848,10 +853,16 @@
 			} else {
 				$t_project_clause = '= ' . $p_project_id;
 			}
+			
+			$sequence_filters = 
+				array( CUSTOM_FIELD_SEQUENCE_ALL => "",
+						CUSTOM_FIELD_SEQUENCE_TOP => "AND sequence <0 ",
+						CUSTOM_FIELD_SEQUENCE_BOTTOM => "AND sequence >= 0" );
+			$sequence_filter = $sequence_filters[$p_sequence];
 			$query = "SELECT cft.id
 					  FROM $t_custom_field_table cft, $t_custom_field_project_table cfpt
 					  WHERE cfpt.project_id $t_project_clause AND
-							cft.id = cfpt.field_id
+							cft.id = cfpt.field_id $sequence_filter
 					  ORDER BY sequence ASC, name ASC";
 		}
 		$result = db_query( $query );
@@ -863,8 +874,8 @@
 			array_push( $t_ids, $row['id'] );
 		}
 		custom_field_cache_array_rows( $t_ids );
-
-		$g_cache_cf_linked[$p_project_id] = $t_ids;
+ 		if ( $p_sequence == CUSTOM_FIELD_SEQUENCE_ALL ) # cache only the full list
+			$g_cache_cf_linked[$p_project_id] = $t_ids;
 	} else {
 		$t_ids = $g_cache_cf_linked[$p_project_id];
 	}
diff -r -u mantis-120rc2-original/mantisbt-1.2.0rc2/lang/strings_english.txt mantis-120rc2-gtz/mantisbt-1.2.0rc2/lang/strings_english.txt
--- mantis-120rc2-original/mantisbt-1.2.0rc2/lang/strings_english.txt	2010-01-12 15:55:59.835807912 +0300
+++ mantis-120rc2-gtz/mantisbt-1.2.0rc2/lang/strings_english.txt	2010-01-12 15:33:56.105853400 +0300
@@ -1290,6 +1290,7 @@
 $s_linked_projects = 'Linked Projects';
 
 $s_custom_field_sequence = 'Sequence';
+$s_custom_field_sequence_help = 'Use negative numbers to display before on top of the report.';
 $s_custom_field_type_enum_string = '0:String,1:Numeric,2:Float,3:Enumeration,4:E-mail,5:Checkbox,6:List,7:Multiselection list,8:Date,9:Radio';
 
 $s_confirm_used_custom_field_deletion = 'This field is currently linked to at least one project. If you continue all values for this field will be permanently deleted. This action cannot be undone. If you do not want to delete this field, hit the Back button in your browser. To proceed, click the button below';
diff -r -u mantis-120rc2-original/mantisbt-1.2.0rc2/manage_custom_field_edit_page.php mantis-120rc2-gtz/mantisbt-1.2.0rc2/manage_custom_field_edit_page.php
--- mantis-120rc2-original/mantisbt-1.2.0rc2/manage_custom_field_edit_page.php	2010-01-12 15:55:59.505814500 +0300
+++ mantis-120rc2-gtz/mantisbt-1.2.0rc2/manage_custom_field_edit_page.php	2010-01-12 15:34:51.127655751 +0300
@@ -271,7 +271,8 @@
 		<?php echo lang_get( 'custom_field_sequence' ) ?>:
 	</td>
 	<td>
-		<input type="text" name="sequence" value="0" />
+		<input type="text" name="sequence" value="0" /> <br />
+		<?php echo lang_get( 'custom_field_sequence_help' ) ?>
 	</td>
 </tr>
 
custom-fields-on-top.patch (5,980 bytes)   
issue11385-custom-field-order-patchrev2.patch (6,073 bytes)   
diff -u -r mantis-120rc2-original/mantisbt-1.2.0rc2/bug_report_page.php mantis-120rc2-gtz/mantisbt-1.2.0rc2/bug_report_page.php
--- mantis-120rc2-original/mantisbt-1.2.0rc2/bug_report_page.php	2010-01-12 15:55:59.485813285 +0300
+++ mantis-120rc2-gtz/mantisbt-1.2.0rc2/bug_report_page.php	2010-01-14 09:27:47.010647678 +0300
@@ -170,6 +170,26 @@
 <?php
 	event_signal( 'EVENT_REPORT_BUG_FORM_TOP', array( $t_project_id ) );
 
+	$t_custom_fields_found = false;
+	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id , CUSTOM_FIELD_SEQUENCE_TOP);
+
+	foreach( $t_related_custom_field_ids as $t_id ) {
+		$t_def = custom_field_get_definition( $t_id );
+		if( ( $t_def['display_report'] || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
+			$t_custom_fields_found = true;
+?>
+	<tr <?php echo helper_alternate_class() ?>>
+		<td class="category">
+			<?php if($t_def['require_report']) {?><span class="required">*</span><?php } echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
+		</td>
+		<td>
+			<?php print_custom_field_input( $t_def, ( $f_master_bug_id === 0 ) ? null : $f_master_bug_id ) ?>
+		</td>
+	</tr>
+<?php
+		}
+	} # foreach( $t_related_custom_field_ids as $t_id )
+	
 	if ( $tpl_show_category ) {
 ?>
 	<tr <?php echo helper_alternate_class() ?>>
@@ -437,8 +459,8 @@
 <?php
 	}
 
-	$t_custom_fields_found = false;
-	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );
+	$t_custom_fields_found = false;	
+	$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id , CUSTOM_FIELD_SEQUENCE_BOTTOM);
 
 	foreach( $t_related_custom_field_ids as $t_id ) {
 		$t_def = custom_field_get_definition( $t_id );
diff -u -r mantis-120rc2-original/mantisbt-1.2.0rc2/core/custom_field_api.php mantis-120rc2-gtz/mantisbt-1.2.0rc2/core/custom_field_api.php
--- mantis-120rc2-original/mantisbt-1.2.0rc2/core/custom_field_api.php	2010-01-12 15:55:59.555807656 +0300
+++ mantis-120rc2-gtz/mantisbt-1.2.0rc2/core/custom_field_api.php	2010-01-12 16:22:25.998306841 +0300
@@ -792,18 +792,23 @@
 	return $row['id'];
 }
 
+define( 'CUSTOM_FIELD_SEQUENCE_ALL' , 0);  # retrive all custom fields
+define( 'CUSTOM_FIELD_SEQUENCE_TOP', 1);   # retrive custom fields to show on top (negative IDs)
+define( 'CUSTOM_FIELD_SEQUENCE_BOTTOM', 2);  # retrive custom fields to show on top (non-negative IDs)
+
 /**
  * Return an array of ids of custom fields bound to the specified project
  *
- * The ids will be sorted based on the sequence number associated with the binding
+ * If a p_project_id is given, the ids will be sorted based on the sequence number associated with the binding.
  * @param int $p_project_id project id
+ * @param int $p_sequence on of the CUSTOM_FIELD_SEQUENCE constants
  * @return array
  * @access public
  */
-function custom_field_get_linked_ids( $p_project_id = ALL_PROJECTS ) {
+function custom_field_get_linked_ids( $p_project_id = ALL_PROJECTS , $p_sequence = CUSTOM_FIELD_SEQUENCE_ALL) {
 	global $g_cache_cf_linked, $g_cache_custom_field;
 
-	if( !isset( $g_cache_cf_linked[$p_project_id] ) ) {
+	if( !isset( $g_cache_cf_linked[$p_project_id] ) or $p_sequence <> CUSTOM_FIELD_SEQUENCE_ALL ) {
 
 		$t_custom_field_table = db_get_table( 'mantis_custom_field_table' );
 		$t_custom_field_project_table = db_get_table( 'mantis_custom_field_project_table' );
@@ -848,10 +853,16 @@
 			} else {
 				$t_project_clause = '= ' . $p_project_id;
 			}
+			
+			$sequence_filters = 
+				array( CUSTOM_FIELD_SEQUENCE_ALL => "",
+						CUSTOM_FIELD_SEQUENCE_TOP => "AND sequence <0 ",
+						CUSTOM_FIELD_SEQUENCE_BOTTOM => "AND sequence >= 0" );
+			$sequence_filter = $sequence_filters[$p_sequence];
 			$query = "SELECT cft.id
 					  FROM $t_custom_field_table cft, $t_custom_field_project_table cfpt
 					  WHERE cfpt.project_id $t_project_clause AND
-							cft.id = cfpt.field_id
+							cft.id = cfpt.field_id $sequence_filter
 					  ORDER BY sequence ASC, name ASC";
 		}
 		$result = db_query( $query );
@@ -863,8 +874,8 @@
 			array_push( $t_ids, $row['id'] );
 		}
 		custom_field_cache_array_rows( $t_ids );
-
-		$g_cache_cf_linked[$p_project_id] = $t_ids;
+ 		if ( $p_sequence == CUSTOM_FIELD_SEQUENCE_ALL ) # cache only the full list
+			$g_cache_cf_linked[$p_project_id] = $t_ids;
 	} else {
 		$t_ids = $g_cache_cf_linked[$p_project_id];
 	}
diff -u -r mantis-120rc2-original/mantisbt-1.2.0rc2/lang/strings_english.txt mantis-120rc2-gtz/mantisbt-1.2.0rc2/lang/strings_english.txt
--- mantis-120rc2-original/mantisbt-1.2.0rc2/lang/strings_english.txt	2010-01-12 15:55:59.835807912 +0300
+++ mantis-120rc2-gtz/mantisbt-1.2.0rc2/lang/strings_english.txt	2010-01-14 09:30:41.198369160 +0300
@@ -1290,6 +1290,7 @@
 $s_linked_projects = 'Linked Projects';
 
 $s_custom_field_sequence = 'Sequence';
+$s_custom_field_sequence_help = 'Use negative numbers to display field on the report page before the standard fields.';
 $s_custom_field_type_enum_string = '0:String,1:Numeric,2:Float,3:Enumeration,4:E-mail,5:Checkbox,6:List,7:Multiselection list,8:Date,9:Radio';
 
 $s_confirm_used_custom_field_deletion = 'This field is currently linked to at least one project. If you continue all values for this field will be permanently deleted. This action cannot be undone. If you do not want to delete this field, hit the Back button in your browser. To proceed, click the button below';
diff -u -r mantis-120rc2-original/mantisbt-1.2.0rc2/manage_custom_field_edit_page.php mantis-120rc2-gtz/mantisbt-1.2.0rc2/manage_custom_field_edit_page.php
--- mantis-120rc2-original/mantisbt-1.2.0rc2/manage_custom_field_edit_page.php	2010-01-12 15:55:59.505814500 +0300
+++ mantis-120rc2-gtz/mantisbt-1.2.0rc2/manage_custom_field_edit_page.php	2010-01-12 15:34:51.127655751 +0300
@@ -271,7 +271,8 @@
 		<?php echo lang_get( 'custom_field_sequence' ) ?>:
 	</td>
 	<td>
-		<input type="text" name="sequence" value="0" />
+		<input type="text" name="sequence" value="0" /> <br />
+		<?php echo lang_get( 'custom_field_sequence_help' ) ?>
 	</td>
 </tr>
 
Horizontal.JPG (51,636 bytes)   
Horizontal.JPG (51,636 bytes)   

Relationships

related to 0004227 acknowledged Roadmap 1.0 - Templates 
related to 0017625 closedvboctor Support controlling order and visibility of custom and native fields 
has duplicate 0006220 closedvboctor Change order of fields 
has duplicate 0014404 closedatrol custom fields above Category field on Report Issue page 
has duplicate 0006151 closedvboctor Give higher priority to custom fields in page? 
has duplicate 0019604 closedatrol How can I move my Custom Fields when Report Issue 
has duplicate 0024427 closedatrol Layout change on the default registration screen 

Activities

am-gtz

am-gtz

2010-01-14 01:42

reporter   ~0024143

I fixed some minor mistakes in my patch.

am-gtz

am-gtz

2010-01-20 04:15

reporter   ~0024201

This patch is now maintained on mantisforge:

http://git.mantisforge.org/w/mantisbt/gtz-et.git?a=shortlog;h=refs/heads/issue11385

am-gtz

am-gtz

2010-01-28 02:01

reporter   ~0024266

I added a related patch:

0001-Autofocus-the-first-element-in-the-form-instead-of-c.patch

Autofocus the first element in the form instead of category_id. Handlers of EVENT_REPORT_BUG_FORM_TOP may have added elements before the category!

squarebox

squarebox

2010-02-22 20:16

reporter   ~0024461

Just a general comment that i too didn't like the placement of the custom fields after the built in fields and would like a more robust way to dictate where in the page to display the custom fields. Where as am-gtz placed his custom field above category, i've placed mine above the reporter field.

This flexibility change would probably require all fields to be assigned a sequence number so that users could specify exactly where to display the custom fields. It may be easier to think of it in terms of group of fields instead of individual fields in terms of ordering. For instance being able to the custom field in front of Id, Reporter, summary, or attached files would be significantly easier to code and still provide a great deal of customizability.

am-gtz

am-gtz

2010-02-23 00:48

reporter   ~0024463

As squarebox mentioned, it would be much more flexible to be able to place custom fields at each position.

We need to place some custom fields on top, and some on the bottom --- so it is not sufficient to just specify the pos. of all custom fields as a whole.

dhx

dhx

2010-02-26 21:03

reporter   ~0024559

AFAIK Paul (grangeway on this bug tracker) is currently reimplementing columns_api/etc so that you can select and reorder fields on the view/update/report/etc pages in the same way you can select and reorder columns on view_all_bug_page. This would provide all the flexibility requested by squarebox in a more standardised way than the patch attached to this bug report uses.

squarebox

squarebox

2010-03-04 21:24

reporter   ~0024645

Last edited: 2010-03-04 21:26

would like to add 1 more request if possible, the ability to display the custom fields horizontally as well as vertically. There may be the need by some people who may want to have it displayed vertically on the edit screen and horizontally in the display screen, albeit weird from an HCI perspective.

i.e. horizontally like ID, Project, Category
Vertically being fields that consume a whole row like reporter and assigned to

this is of some use when you have small custom fields that display nicely horizontally.

I've attached a screenshot of the customization i did to display custom fields in my environment.

am-gtz

am-gtz

2010-03-05 01:23

reporter   ~0024646

Yes ... I agree. In general I would suggest to make those forms not so <table> dependent and try to go for <div>s to allow a better floating and customization.

@dhx: Did you see any mantis issue concerning grangeway's developments? Is he reading this one?

squarebox

squarebox

2010-03-08 20:16

reporter   ~0024676

Last edited: 2010-03-08 20:22

this is probably relate if not a duplicate of bug 0006220, albeit a bug that's 5 years old...

as well as encompasses bug 0006785

and should probably be added to bug 0004227

just mentioning these cause they haven't been touched in ages and might be a good oppurtunity to close out alot of similiar outstanding bugs and such.

vboctor

vboctor

2014-10-24 22:24

manager   ~0041645

As of now, we have a way to manage which of the native fields should be visible. However, we don't support re-ordering such fields.

For custom fields, we provide the ability to control their visibility and order relative to each other.

We don't provide a way to define the order of custom fields and native fields relative to each other.

Based on users trying out MantisBT, it seems that often users would like to change order of native fields and interleave custom fields between them. Hence, some standard approach to enable that would be make sense.

mauro.perino

mauro.perino

2016-01-29 06:57

reporter   ~0052435

I am very interested to have the custom field in a horizontal position.
Like Horizontal.JPG
How can I do?