瀏覽代碼

#780 Auto refresh for the shortcuts

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2926 a333f486-631f-4898-b8df-5754b55c2be0
romainq 11 年之前
父節點
當前提交
d548a42917

+ 7 - 3
application/displayblock.class.inc.php

@@ -204,6 +204,11 @@ class DisplayBlock
 		$bAutoReload = false;
 		if (isset($aExtraParams['auto_reload']))
 		{
+			if ($aExtraParams['auto_reload'] === true)
+			{
+				// Note: does not work in the switch (case true) because a positive number evaluates to true!!!
+				$aExtraParams['auto_reload'] = 'standard';
+			}
 			switch($aExtraParams['auto_reload'])
 			{
 				case 'fast':
@@ -213,16 +218,15 @@ class DisplayBlock
 				
 				case 'standard':
 				case 'true':
-				case true:
 				$bAutoReload = true;
 				$iReloadInterval = MetaModel::GetConfig()->GetStandardReloadInterval()*1000;
 				break;
 				
 				default:
-				if (is_numeric($aExtraParams['auto_reload']))
+				if (is_numeric($aExtraParams['auto_reload']) && ($aExtraParams['auto_reload'] > 0))
 				{
 					$bAutoReload = true;
-					$iReloadInterval = $aExtraParams['auto_reload']*1000;
+					$iReloadInterval = max(5, $aExtraParams['auto_reload'])*1000;
 				}
 				else
 				{

+ 42 - 1
application/shortcut.class.inc.php

@@ -166,6 +166,8 @@ class ShortcutOQL extends Shortcut
 		MetaModel::Init_Params($aParams);
 		MetaModel::Init_InheritAttributes();
 		MetaModel::Init_AddAttribute(new AttributeOQL("oql", array("allowed_values"=>null, "sql"=>"oql", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
+		MetaModel::Init_AddAttribute(new AttributeEnum("auto_reload", array("allowed_values"=>new ValueSetEnum('none,custom'), "sql"=>"auto_reload", "default_value"=>"none", "is_null_allowed"=>false, "depends_on"=>array())));
+		MetaModel::Init_AddAttribute(new AttributeInteger("auto_reload_sec", array("allowed_values"=>null, "sql"=>"auto_reload_sec", "default_value"=>60, "is_null_allowed"=>false, "depends_on"=>array())));
 
 		// Display lists
 		MetaModel::Init_SetZListItems('details', array('name', 'context', 'oql')); // Attributes to be displayed for the complete details
@@ -179,6 +181,21 @@ class ShortcutOQL extends Shortcut
 	{
 		$oPage->set_title($this->Get('name'));
 
+		switch($this->Get('auto_reload'))
+		{
+		case 'custom':
+			$iRate = (int)$this->Get('auto_reload_sec');
+			if ($iRate > 0)
+			{
+				// Must a string otherwise it can be evaluated to 'true' and defaults to "standard" refresh rate!
+				$aExtraParams['auto_reload'] = (string)$iRate;
+			}
+			break;
+
+		default:
+		case 'none':
+		}
+
 		$bSearchPane = true;
 		$bSearchOpen = false;
 		try
@@ -215,7 +232,22 @@ class ShortcutOQL extends Shortcut
 		$oField = new DesignerTextField('name', Dict::S('Class:Shortcut/Attribute:name'), $sDefault);
 		$oField->SetMandatory(true);
 		$oForm->AddField($oField);
-				
+
+		/*
+		$oField = new DesignerComboField('auto_reload', Dict::S('Class:ShortcutOQL/Attribute:auto_reload'), 'none');
+		$oAttDef = MetaModel::GetAttributeDef(__class__, 'auto_reload');
+		$oField->SetAllowedValues($oAttDef->GetAllowedValues());
+		$oField->SetMandatory(true);
+		$oForm->AddField($oField);
+		*/
+		$oField = new DesignerBooleanField('auto_reload', Dict::S('Class:ShortcutOQL/Attribute:auto_reload'), false);
+		$oForm->AddField($oField);
+
+		$oField = new DesignerTextField('auto_reload_sec', Dict::S('Class:ShortcutOQL/Attribute:auto_reload_sec'), MetaModel::GetConfig()->GetStandardReloadInterval());
+		$oField->SetValidationPattern('^$|^0*([5-9]|[1-9][0-9]+)$'); // Can be empty, or a number > 4
+		$oField->SetMandatory(false);
+		$oForm->AddField($oField);
+
 		//$oField = new DesignerLongTextField('oql', Dict::S('Class:Shortcut/Attribute:oql'), $sOQL);
 		//$oField->SetMandatory();
 		$oField = new DesignerHiddenField('oql', '', $sOQL);
@@ -240,9 +272,18 @@ class ShortcutOQL extends Shortcut
 		$oAppContext = new ApplicationContext();
 		$sContext = $oAppContext->GetForLink();
 
+		$sRateTitle = addslashes(Dict::S('Class:ShortcutOQL/Attribute:auto_reload_sec+'));
+
 		$oPage->add_ready_script(
 <<<EOF
 
+$("#attr_auto_reload_sec").attr('title', '$sRateTitle');
+$("#attr_auto_reload_sec").prop('disabled', !$(this).is(':checked'));
+
+$('#attr_auto_reload').change( function(ev) {
+	$("#attr_auto_reload_sec").prop('disabled', !$(this).is(':checked'));
+} );
+
 function ShortcutCreationOK() 
 {
 	var oForm = $('#shortcut_creation_dlg form');

+ 6 - 0
dictionaries/dictionary.itop.ui.php

@@ -1175,6 +1175,12 @@ When associated with a trigger, each action is given an "order" number, specifyi
 	'Class:ShortcutOQL+' => '',
 	'Class:ShortcutOQL/Attribute:oql' => 'Query',
 	'Class:ShortcutOQL/Attribute:oql+' => 'OQL defining the list of objects to search for',
+	'Class:ShortcutOQL/Attribute:auto_reload' => 'Automatic refresh',
+	'Class:ShortcutOQL/Attribute:auto_reload/Value:none' => 'Disabled',
+	'Class:ShortcutOQL/Attribute:auto_reload/Value:custom' => 'Custom rate',
+	'Class:ShortcutOQL/Attribute:auto_reload_sec' => 'Automatic refresh interval (seconds)',
+	'Class:ShortcutOQL/Attribute:auto_reload_sec+' => 'The minimum allowed is 5 seconds',
+
 	'UI:FillAllMandatoryFields' => 'Please fill all mandatory fields.',
 	
 	'UI:CSVImportConfirmTitle' => 'Please confirm the operation',

+ 6 - 0
pages/ajax.render.php

@@ -899,6 +899,12 @@ EOF
 		$oShortcut->Set("context", $sContext);
 		$oShortcut->Set("name", $aValues['name']);
 		$oShortcut->Set("oql", $aValues['oql']);
+		$iAutoReload = (int)$aValues['auto_reload_sec'];
+		if (($aValues['auto_reload']) && ($iAutoReload > 0))
+		{
+			$oShortcut->Set("auto_reload_sec", max(5, $iAutoReload));
+			$oShortcut->Set("auto_reload", 'custom');
+		}
 		$iId = $oShortcut->DBInsertNoReload();
 
 		// Add the menu node in the right place