From dc96cbc482a18c3c1b32650a85eb37f9efe9a9cb Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Wed, 1 Dec 2010 15:21:29 +0000 Subject: [PATCH] - Ask for confirmation when doing a CSV import/synchro that is considered as "risky" (based on thresholds from the config file) - Added a "Restart" button to quickly start over a CSV import/synchro SVN:trunk[1004] --- core/config.class.inc.php | 33 +++++ dictionaries/dictionary.itop.ui.php | 1 + dictionaries/fr.dictionary.itop.ui.php | 1 + pages/csvimport.php | 165 ++++++++++++++++++++++++- 4 files changed, 197 insertions(+), 3 deletions(-) diff --git a/core/config.class.inc.php b/core/config.class.inc.php index a72c952b0..51ef33192 100644 --- a/core/config.class.inc.php +++ b/core/config.class.inc.php @@ -151,6 +151,39 @@ class Config 'source_of_value' => '', 'show_in_conf_sample' => false, ), + // Levels that trigger a confirmation in the CSV import/synchro wizard + 'csv_import_min_object_confirmation' => array( + 'type' => 'integer', + 'description' => 'Minimum number of objects to check for the confirmation percentages', + 'default' => 3, + 'value' => 3, + 'source_of_value' => '', + 'show_in_conf_sample' => false, + ), + 'csv_import_errors_percentage' => array( + 'type' => 'integer', + 'description' => 'Percentage of errors that trigger a confirmation in the CSV import', + 'default' => 50, + 'value' => 50, + 'source_of_value' => '', + 'show_in_conf_sample' => false, + ), + 'csv_import_modifications_percentage' => array( + 'type' => 'integer', + 'description' => 'Percentage of modifications that trigger a confirmation in the CSV import', + 'default' => 50, + 'value' => 50, + 'source_of_value' => '', + 'show_in_conf_sample' => false, + ), + 'csv_import_creations_percentage' => array( + 'type' => 'integer', + 'description' => 'Percentage of creations that trigger a confirmation in the CSV import', + 'default' => 50, + 'value' => 50, + 'source_of_value' => '', + 'show_in_conf_sample' => false, + ), ); public function IsProperty($sPropCode) diff --git a/dictionaries/dictionary.itop.ui.php b/dictionaries/dictionary.itop.ui.php index a213e742c..db93edd04 100644 --- a/dictionaries/dictionary.itop.ui.php +++ b/dictionaries/dictionary.itop.ui.php @@ -336,6 +336,7 @@ Dict::Add('EN US', 'English', 'English', array( 'UI:Button:Cancel' => 'Cancel', 'UI:Button:Apply' => 'Apply', 'UI:Button:Back' => ' << Back ', + 'UI:Button:Restart' => ' |<< Restart ', 'UI:Button:Next' => ' Next >> ', 'UI:Button:Finish' => ' Finish ', 'UI:Button:DoImport' => ' Run the Import ! ', diff --git a/dictionaries/fr.dictionary.itop.ui.php b/dictionaries/fr.dictionary.itop.ui.php index 3ce4c7df0..e189be551 100644 --- a/dictionaries/fr.dictionary.itop.ui.php +++ b/dictionaries/fr.dictionary.itop.ui.php @@ -338,6 +338,7 @@ Dict::Add('FR FR', 'French', 'Français', array( 'UI:Button:Cancel' => 'Annuler', 'UI:Button:Apply' => 'Appliquer', 'UI:Button:Back' => ' << Retour ', + 'UI:Button:Restart' => ' |<< Recommencer ', 'UI:Button:Next' => ' Suite >> ', 'UI:Button:Finish' => ' Terminer ', 'UI:Button:DoImport' => ' Lancer l\'import ! ', diff --git a/pages/csvimport.php b/pages/csvimport.php index 92a7409fd..d2ff49f00 100644 --- a/pages/csvimport.php +++ b/pages/csvimport.php @@ -524,6 +524,8 @@ try $sHtml .= "$sMessage"; $sHtml .= ''; } + + $iUnchanged = count($aRes) - $iErrors - $iModified - $iCreated; $sHtml .= ''; $oPage->add('
'); $oPage->add('
'); @@ -578,10 +580,43 @@ try $oPage->add('
'); $oPage->add($sHtml); $oPage->add('
'); - $oPage->add('

  '); + $oPage->add('

'); + if($bSimulate) + { + $oPage->add('  '); + } + $oPage->add('  '); + + $bShouldConfirm = false; if ($bSimulate) { - $oPage->add('

'); + // if there are *too many* changes, we should ask the user for a confirmation + if (count($aRes) >= utils::GetConfig()->Get('csv_import_min_object_confirmation')) + { + $fErrorsPercentage = (100.0*$iErrors)/count($aRes); + if ($fErrorsPercentage >= utils::GetConfig()->Get('csv_import_errors_percentage')) + { + $sMessage = sprintf("%.0f %% of the loaded objects will be modified.", $fErrorsPercentage); + $bShouldConfirm = true; + } + $fCreatedPercentage = (100.0*$iCreated)/count($aRes); + if ($fCreatedPercentage >= utils::GetConfig()->Get('csv_import_creations_percentage')) + { + $sMessage = sprintf("%.0f %% of the loaded objects will be modified.", $fCreatedPercentage); + $bShouldConfirm = true; + } + $fModifiedPercentage = (100.0*$iModified)/count($aRes); + if ($fModifiedPercentage >= utils::GetConfig()->Get('csv_import_modifications_percentage')) + { + $sMessage = sprintf("%.0f %% of the loaded objects will be modified.", $fModifiedPercentage); + $bShouldConfirm = true; + } + + } + $iCount = count($aRes); + //$oPage->add('

'); + $sConfirm = $bShouldConfirm ? 'true' : 'false'; + $oPage->add('

"); } else { @@ -589,6 +624,40 @@ try } $oPage->add('
'); $oPage->add('
'); + + + if ($bShouldConfirm) + { + $oPage->add('
'); + $oPage->add('

'.$sMessage.'

'); + $oPage->add('

Are you sure you want to do this ?

'); + $oPage->add('
'); + $oPage->add('
'); + $oPage->add_ready_script( +<<add_script( <<< EOF function CSVGoBack() @@ -598,10 +667,92 @@ function CSVGoBack() } +function CSVRestart() +{ + $('input[name=step]').val(1); + $('#wizForm').submit(); + +} + function ToggleRows(sCSSClass) { $('.'+sCSSClass).toggle(); } + +function DoSubmit(bConfirm) +{ + if (bConfirm) //Ask for a confirmation + { + $('#dlg_confirmation').dialog('open'); + } + else + { + // Submit the form + $('#wizForm').block(); + $('#wizForm').submit(); + } + return false; +} + +function CancelImport() +{ + $('#dlg_confirmation').dialog('close'); +} + +function RunImport() +{ + $('#dlg_confirmation').dialog('close'); + // Submit the form + $('#wizForm').block(); + $('#wizForm').submit(); +} + +function open_flash_chart_data() +{ + var oResult = { + "elements": [ + { + "type": "pie", + "tip": "#label# - #val# (#percent#)", + "font-size": 14, + "colours": + [ + "#FF6666", + "#6666FF", + "#66FF66", + "#666666", + ], + "values": + [ + { + "value": $iErrors, + "label": "Errors", + "alpha": 0.9 + }, + { + "value": $iModified, + "label": "Modified", + "alpha": 0.9 + }, + { + "value": $iCreated, + "label": "Created", + "alpha": 0.9 + }, + { + "value": $iUnchanged, + "label": "Unchanged", + "alpha": 0.9 + } + ] + } + ], + "x_axis": null, + "font-size": 14, + "bg_colour": "#EEEEEE" + }; + return JSON.stringify(oResult); +} EOF ); if ($iErrors > 0) @@ -716,7 +867,8 @@ EOF $oPage->add(''); } } - $oPage->add('

  '); + $oPage->add('

  '); + $oPage->add('  '); $oPage->add('

'); $oPage->add(''); $oPage->add(''); @@ -746,6 +898,13 @@ EOF } + function CSVRestart() + { + $('input[name=step]').val(1); + $('#wizForm').submit(); + + } + var ajax_request = null; function DoMapping()