[Fusionforge-commits] FusionForge branch master updated. v6.0.5-1348-g95f75df

Franck Villaume nerville at libremir.placard.fr.eu.org
Tue Jan 17 20:52:48 CET 2017


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, master has been updated
       via  95f75df20b3813a75caac60dcf5de34f4e35011c (commit)
      from  343cab8166e2ffe89df41d8aa47842f24f2a48d1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=95f75df20b3813a75caac60dcf5de34f4e35011c

commit 95f75df20b3813a75caac60dcf5de34f4e35011c
Author: St├ęphane-Eymeric Bredthauer <sebredthauer at gmail.com>
Date:   Tue Jan 17 20:07:22 2017 +0100

    Tracker: Update artifact data on unit convertion modification

diff --git a/src/common/tracker/ArtifactExtraField.class.php b/src/common/tracker/ArtifactExtraField.class.php
index 0532502..86efa44 100644
--- a/src/common/tracker/ArtifactExtraField.class.php
+++ b/src/common/tracker/ArtifactExtraField.class.php
@@ -55,7 +55,7 @@ define ("ARTIFACT_EXTRAFIELDTYPEGROUP_SINGLECHOICE", serialize (array (ARTIFACT_
 define ("ARTIFACT_EXTRAFIELDTYPEGROUP_MULTICHOICE", serialize (array (ARTIFACT_EXTRAFIELDTYPE_CHECKBOX, ARTIFACT_EXTRAFIELDTYPE_MULTISELECT)));
 define ("ARTIFACT_EXTRAFIELDTYPEGROUP_CHOICE", serialize (array_merge(unserialize(ARTIFACT_EXTRAFIELDTYPEGROUP_SINGLECHOICE), unserialize(ARTIFACT_EXTRAFIELDTYPEGROUP_MULTICHOICE))));
 define ("ARTIFACT_EXTRAFIELDTYPEGROUP_SPECALCHOICE", serialize(array(ARTIFACT_EXTRAFIELDTYPE_USER, ARTIFACT_EXTRAFIELDTYPE_RELEASE)));
-define ("ARTIFACT_EXTRAFIELDTYPEGROUP_VALUE", serialize (array (ARTIFACT_EXTRAFIELDTYPE_TEXT,ARTIFACT_EXTRAFIELDTYPE_TEXTAREA,ARTIFACT_EXTRAFIELDTYPE_RELATION,ARTIFACT_EXTRAFIELDTYPE_INTEGER,ARTIFACT_EXTRAFIELDTYPE_FORMULA,ARTIFACT_EXTRAFIELDTYPE_DATETIME)));
+define ("ARTIFACT_EXTRAFIELDTYPEGROUP_VALUE", serialize (array (ARTIFACT_EXTRAFIELDTYPE_TEXT,ARTIFACT_EXTRAFIELDTYPE_TEXTAREA,ARTIFACT_EXTRAFIELDTYPE_RELATION,ARTIFACT_EXTRAFIELDTYPE_INTEGER,ARTIFACT_EXTRAFIELDTYPE_FORMULA,ARTIFACT_EXTRAFIELDTYPE_DATETIME, ARTIFACT_EXTRAFIELDTYPE_EFFORT)));
 
 class ArtifactExtraField extends FFError {
 
@@ -574,7 +574,8 @@ class ArtifactExtraField extends FFError {
 			if (in_array($type,unserialize(ARTIFACT_EXTRAFIELDTYPEGROUP_SPECALCHOICE)) && $default=='100' ||
 					$type==ARTIFACT_EXTRAFIELDTYPE_INTEGER && $default=='0' ||
 					$type==ARTIFACT_EXTRAFIELDTYPE_TEXT && trim($default)=='' ||
-					$type==ARTIFACT_EXTRAFIELDTYPE_TEXTAREA && trim($default)=='') {
+					$type==ARTIFACT_EXTRAFIELDTYPE_TEXTAREA && trim($default)=='' ||
+					$type==ARTIFACT_EXTRAFIELDTYPE_EFFORT && intVal($default)==0) {
 				$return = $this->resetDefaultValues();
 			} else {
 				$efID = $this->getID();
diff --git a/src/common/tracker/EffortUnit.class.php b/src/common/tracker/EffortUnit.class.php
index 4b64164..007d301 100644
--- a/src/common/tracker/EffortUnit.class.php
+++ b/src/common/tracker/EffortUnit.class.php
@@ -211,7 +211,7 @@ class EffortUnit extends FFError {
 	/**
 	 * getMultiplier - get this unit base multiplier.
 	 *
-	 * @return	float	unit base multiplier.
+	 * @return	integer	unit base multiplier.
 	 */
 	function getConversionFactor() {
 		return $this->data_array['conversion_factor'];
@@ -290,10 +290,10 @@ class EffortUnit extends FFError {
 										unit_set_id = $3
 									)
 								UPDATE artifact_extra_field_data AS d
-								SET field_data = $4*CAST(SUBSTRING(field_data FROM \'#"%#"U%\' FOR \'#\') AS INTEGER) || \'U\' || $5
+								SET field_data = CAST(SUBSTRING(field_data FROM \'#"%#"U%\' FOR \'#\') AS INTEGER) || \'U\' || $4
 								FROM t
 								WHERE d.data_id = t.data_id',
-								array(ARTIFACT_EXTRAFIELDTYPE_EFFORT,'%U'.$this->getID(), $this->getEffortUnitSet()->getID(), $this->getConversionFactor(),$this->getToUnit()));
+								array(ARTIFACT_EXTRAFIELDTYPE_EFFORT,'%U'.$this->getID(), $this->getEffortUnitSet()->getID(), $this->getToUnit()));
 		if (!$res) {
 			$this->setError(_('Error deleting Effort Unit')._(': ').db_error());
 			db_rollback();
@@ -319,6 +319,7 @@ class EffortUnit extends FFError {
 			$this->setError(sprintf(_('Unit name %s already exist'),$name));
 			return false;
 		}
+		$old_conversion_factor = $this->getConversionFactor();
 		db_begin();
 		if(array_key_exists('user', $importData)){
 			$user = $importData['user'];
@@ -330,21 +331,45 @@ class EffortUnit extends FFError {
 		} else {
 			$time = time();
 		}
+
 		$res = db_query_params('UPDATE effort_unit SET unit_name=$1, conversion_factor=$2, to_unit=$3, modified_date=$4, modified_by=$5 WHERE unit_id=$6',
 				array(htmlspecialchars($name), $conversion_factor, $to_unit, $time, $user, $this->getID()));
 		if (!$res || db_affected_rows($res) < 1) {
-			$this->setError(_('Error')._(':').' '._('Cannot update Effort Unit')._(':').' '.db_error());
+			$this->setError(_('Error')._(':').' '._('Cannot update Effort Unit1')._(':').' '.db_error());
 			db_rollback();
 			return false;
 		}
-
+		if ($old_conversion_factor != $conversion_factor) {
+			$units = array_merge(array($this), $this->getUnitsDependingOn());
+			foreach ($units as $unit) {
+				$res = db_query_params('WITH t AS (
+										SELECT data_id
+											FROM artifact_extra_field_data
+											INNER JOIN artifact_extra_field_list USING (extra_field_id)
+											INNER JOIN artifact_group_list USING (group_artifact_id)
+										WHERE
+											field_type = $1 AND
+											field_data like $2 AND
+											unit_set_id = $3
+										)
+									UPDATE artifact_extra_field_data AS d
+									SET field_data = (CAST(SUBSTRING(field_data FROM \'#"%#"U%\' FOR \'#\') AS INTEGER)*$4)/$5 || \'U\' || $6
+									FROM t
+									WHERE d.data_id = t.data_id',
+						array(ARTIFACT_EXTRAFIELDTYPE_EFFORT,'%U'.$unit->getID(), $this->EffortUnitSet->getID(), $conversion_factor, $old_conversion_factor, $unit->getID()));
+				if (!$res) {
+					$this->setError(_('Error')._(':').' '._('Cannot update Effort Unit2')._(':').' '.db_error());
+					db_rollback();
+					return false;
+				}
+			}
+		}
 		if (!$this->fetchData($this->getID())) {
 			db_rollback();
 			return false;
 		}
 		db_commit();
 		return true;
-
 	}
 
 	function updatePosition($unit_position) {
@@ -407,4 +432,27 @@ class EffortUnit extends FFError {
 		$id = $this->create($name, $conversion_factor, $to_unit_id, $position, $is_base_unit);
 		return $id;
 	}
+
+	function getConversionFactorForBaseUnit() {
+		$factor = $this->getConversionFactor();
+		$toUnitId = $this->getToUnit();
+		$toUnit = new EffortUnit($this->EffortUnitSet,$toUnitId);
+		if (!$toUnit->isBaseUnit()) {
+			$factor *= $toUnit->getConversionFactorForBaseUnit();
+		}
+		return $factor;
+	}
+
+	function getUnitsDependingOn(){
+		$unitsDependingOn = array();
+		$effortUnitFactory = new EffortUnitFactory($this->EffortUnitSet);
+		$units = $effortUnitFactory->getUnits();
+		foreach ($units as $unit) {
+			if ($unit->getToUnit()==$this->getID()) {
+				$unitsDependingOn[] = $unit;
+				$unitsDependingOn = array_merge($unitsDependingOn, $unit->getUnitsDependingOn());
+			}
+		}
+		return $unitsDependingOn;
+	}
 }
diff --git a/src/common/tracker/EffortUnitFactory.class.php b/src/common/tracker/EffortUnitFactory.class.php
index 29c584f..b14e7f7 100644
--- a/src/common/tracker/EffortUnitFactory.class.php
+++ b/src/common/tracker/EffortUnitFactory.class.php
@@ -147,7 +147,8 @@ class EffortUnitFactory extends FFError {
 	function encodedToValue($encoded){
 		$value = 0;
 		if (preg_match('/^(\d+)U(\d+)$/',$encoded,$matches)) {
-			$value = intval($matches[1]);
+			$unit = new EffortUnit($this->EffortUnitSet, $matches[2]);
+			$value = intval(intval($matches[1])/$unit->getConversionFactorForBaseUnit());
 		}
 		return $value;
 	}
@@ -174,10 +175,11 @@ class EffortUnitFactory extends FFError {
 	}
 
 	function encodedToString($encoded) {
-		$units = $this->getUnitsArr();
 		if (preg_match('/^(\d+)U(\d+)$/',$encoded,$matches)) {
-			$string = intval($matches[1]).' '.$units[$matches[2]];
+			$unit = new EffortUnit($this->EffortUnitSet, $matches[2]);
+			$string = intval(intval($matches[1])/$unit->getConversionFactorForBaseUnit()).' '.$unit->getName();
 		} else {
+			$units = $this->getUnitsArr();
 			$string = '0 '.reset($units);
 		}
 		return $string;
diff --git a/src/common/tracker/include/ArtifactTypeHtml.class.php b/src/common/tracker/include/ArtifactTypeHtml.class.php
index 58b965a..1dc916d 100644
--- a/src/common/tracker/include/ArtifactTypeHtml.class.php
+++ b/src/common/tracker/include/ArtifactTypeHtml.class.php
@@ -1168,7 +1168,15 @@ class ArtifactTypeHtml extends ArtifactType {
 	function renderEffort ($extra_field_id, $contents, $size, $maxlength, $attrs = array()) {
 		$effortUnitSet = New EffortUnitSet($this, $this->getEffortUnitSet());
 		$effortUnitFactory = New EffortUnitFactory($effortUnitSet);
-		$units = $effortUnitFactory->getUnitsArr();
+		$units = $effortUnitFactory->getUnits();
+		$vals = array();
+		$texts = array();
+		$factors = array();
+		foreach ($units as $unit) {
+			$vals [] = $unit->getID();
+			$texts [] = $unit->getName();
+			$opts_attrs []['data-factor'] = $unit->getConversionFactorForBaseUnit();
+		}
 		$value = $effortUnitFactory->encodedToValue($contents);
 		$unitId = $effortUnitFactory->encodedToUnitId($contents);
 		if (isset($attrs['class'])) {
@@ -1177,9 +1185,9 @@ class ArtifactTypeHtml extends ArtifactType {
 			$attrs['class'] = 'effort';
 		}
 		$attrs['data-effortid'] = $extra_field_id;
-		$return = html_e('input', array('type'=>'hidden', 'name'=>'extra_fields['.$extra_field_id.']', 'value'=>$contents));
+		$return = html_e('input', array('type'=>'hidden', 'name'=>'extra_fields['.$extra_field_id.']', 'value'=>$value.'U'.$unitId));
 		$return .= html_e('input', array_merge(array('type'=>'number', 'name'=>'value['.$extra_field_id.']', 'value'=>$value, 'size'=>$size, 'maxlength'=>$maxlength, 'min'=>0), $attrs));
-		$return .= html_build_select_box_from_array($units, 'unit['.$extra_field_id.']', $unitId, false, $attrs);
+		$return .= html_build_select_box_from_arrays($vals, $texts, 'unit['.$extra_field_id.']', $unitId, false, '', false, '', false, $attrs, $opts_attrs);
 		return $return;
 	}
 
@@ -1295,10 +1303,15 @@ class ArtifactTypeHtml extends ArtifactType {
 		}
 		return false;
 	};
-	$(".effort").on('change', function(){
+	$("input.effort").on('change', function(){
+		var effortid = $(this).data("effortid");
+		$("input[name='extra_fields["+effortid+"]']").val($("input[name='value["+effortid+"]']").val()*$("select[name='unit["+effortid+"]'] option:selected").data('factor')+'U'+$("select[name='unit["+effortid+"]']").val());
+	});
+	$("select.effort").on('change', function(){
 		var effortid = $(this).data("effortid");
 		console.log(effortid);
-		$("input[name='extra_fields["+effortid+"]']").val($("input[name='value["+effortid+"]']").val()+'U'+$("select[name='unit["+effortid+"]']").val())
+		$("input[name='value["+effortid+"]']").val(parseInt(parseInt($("input[name='extra_fields["+effortid+"]']").val())/$("select[name='unit["+effortid+"]'] option:selected").data('factor')));
+		$("input[name='extra_fields["+effortid+"]']").val($("input[name='value["+effortid+"]']").val()*$("select[name='unit["+effortid+"]'] option:selected").data('factor')+'U'+$("select[name='unit["+effortid+"]']").val());
 	});
 	$("input[type='radio'].readonly, input[type='checkbox'].readonly").on('click', function(){
 		return false;
diff --git a/src/common/tracker/views/form-updateextrafield.php b/src/common/tracker/views/form-updateextrafield.php
index adb9e51..8a4d939 100644
--- a/src/common/tracker/views/form-updateextrafield.php
+++ b/src/common/tracker/views/form-updateextrafield.php
@@ -188,6 +188,13 @@ if (!$ac || !is_object($ac)) {
 			echo $ath->renderReleaseField($ac->getID(),$ac->getDefaultValues(),true,'none');
 			echo html_ac(html_ap() - 1);
 			break;
+		case ARTIFACT_EXTRAFIELDTYPE_EFFORT:
+			echo $ath->javascript();
+			echo html_ao('p');
+			echo html_e('label', array('for'=>'extra_fields['.$ac->getID().']'),_('Default value'));
+			echo $ath->renderEffort($ac->getID(),$ac->getDefaultValues(),$ac->getAttribute1(), $ac->getAttribute2());
+			echo html_ac(html_ap() - 1);
+			break;
 	}
 
 	if (in_array($efType, array(ARTIFACT_EXTRAFIELDTYPE_TEXT, ARTIFACT_EXTRAFIELDTYPE_INTEGER, ARTIFACT_EXTRAFIELDTYPE_TEXTAREA))) {

-----------------------------------------------------------------------

Summary of changes:
 src/common/tracker/ArtifactExtraField.class.php    |  5 +-
 src/common/tracker/EffortUnit.class.php            | 60 +++++++++++++++++++---
 src/common/tracker/EffortUnitFactory.class.php     |  8 +--
 .../tracker/include/ArtifactTypeHtml.class.php     | 23 +++++++--
 src/common/tracker/views/form-updateextrafield.php |  7 +++
 5 files changed, 87 insertions(+), 16 deletions(-)


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list