Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Code Block
languagejavascript
titleui.js
isc.FilterBuilder.create({
    "ID": "advancedFilter",
    "dataSource": "supplyItem",
    "topOperator": "and"
});

The ListGrid also requires additional code to add the FilterBuilder. This will require adding a vertical layout (VStack), together with the grid and the button needed to add for applying the filter on the ListGrid. Also going to add a horizontal layout (HStack) which will contain the two already existing buttons used for saving all data and creating a new record:

Code Block
languagejavascript
titleui.js
isc.ListGrid.create({
    "ID": "supplyItemGridsupplyItem",
    "width": 700, "height": 224, "alternateRecordStyles": true,
    "dataSource": supplyItem,
    "autoFetchData":true,
    "dataPageSize":20,
    "canEdit":true,
    "canRemoveRecords":true,
    "autoSaveEdits": false
});
isc.IButton.create({
    "ID": "filterButton",
    "title": "Filter",
    "click": function () {
        supplyItemGridsupplyItem.filterData(advancedFilter.getCriteria());
    }
});
isc.HStack.create({
    "membersMargin": 10,
    "ID": "gridButtons",
    "members": [
        isc.IButton.create({
            "top": 250,
            "title": "Edit New",
            "click": "supplyItemGridsupplyItem.startEditingNew()"
        }),
        isc.IButton.create({
            "top": 250,
            "left": 100,
            "title": "Save all",
            "click": "supplyItemGridsupplyItem.saveAllEdits()"
        })
    ]
});
isc.VStack.create({
    "membersMargin": 10,
    "members": [advancedFilter, filterButton, supplyItemGridsupplyItem, gridButtons]
});

Also note, the filter has been removed top of the grid, as it is being replaced with the FilterBuilder.

...

Code Block
languagephp
titleDataSource.php
private function fetch($request)
{               
	// get the DataSource
	$ds = $this->data_source;   
	$tbl_name = $ds['ID'];   
	// check the advanced cretira
	if(empty($request->advancedCriteria)) 
	{
		$query_result = $this->buildStandardCriteria($request); 
	} else
	{
		$query_result = $this->buildAdvancedCriteria($request);                
	}
	
	$query = "select * from $tbl_name s ";
	
	$query .= $query_result['query'];
   
	// sort by
	if( !empty($request->sortBy) )
	{
		// set the orderBy
		$query .= " order by ";
		
		// we start to build a coma separated list of items. First item won't have coma
		// but every possible next will do
		$seperator = "";
		foreach($request->sortBy as $index => $sort)
		{ 
			
			// if column name is with -, then ordering is descending, otherwise ascending
			if ( strpos($index, '-') === 0 )
			{
				$query .= $seperator . $sort . " ASC";
			} else
			{
				$query .= $seperator . substr($sort, 1) . " DESC";
			}
			$separator  = ',';
		}
	}
	
	//DSResponse
	$response = new DSResponse();                 
	$products = R::getAll($query, $query_result['value']);   
	// get the count                    
	$count = count($products);           
	$response->setData($products);
	$response->setStartRow($request->startRow);
	$response->setEndRow($request->endRow);            
	$response->setTotalRows($count);
	$response->setStatus(0);  
	
	// sanity check, if no rows, return 0
	if ($response->getEndRow() < 0 ) 
	{
		$response->setEndRow(0);
	}
	
	return $response;
 
}
 

Note a new method called buildAdvancedCriteria() is required which builds the query criteria from the AdvancedCriteria delivered by the FilterBuilder:

Code Block
languagephp
titleRPCManager.php
private function buildAdvancedCriteria($request)
{
	$advancedCriteria = $request->getAdvancedCriteria();
	if(!empty($advancedCriteria))
	{
		$criteria_query = $this->buildCriterion($advancedCriteria);
		$return = array();
		$query$return['query'] = ' where '.$criteria_query['query'];
		$return['value'] = $criteria_query['value'];
		return $query$return;
		
	}
	return null;            
} 

For parsing the tree itself, introduce a recursive function:

Code Block
languagephp
private function buildCriterion($advancedCriteria)
{               
	$criterias = $advancedCriteria['criteria'];
	$operator = $advancedCriteria['operator'];             
	$result = '';
	$query = '';
	$value = array();
	
	foreach($criterias as $c)
	{
		if(isset($c['fieldName']))                
			$fn = $c['fieldName'];
		
		if(isset($c['operator']))
			$op = $c['operator'];
						
		if(isset($c['value']))
		{      
			if ($c['value'] === TRUE )
				$val = '1';
			else if($c['value'] === FALSE)
				$val = '0';
			else
				$val = $c['value'];                    
		}                   
		
		if(isset($c['start']))    
			$start = $c['start'];
		
		if(isset($c['end']))    
			$end = $c['end'];
		
		if(isset($c['criteria']))    
			$criteria = $c['criteria'];
		else
			$criteria = null;
		
		if(empty($criteria))
		{
			switch($op)
			{
				case 'equals':                            
					$query = "$fn = '$val'?"; 
					array_push($value, $val);                                                       
					break;
				case 'notEqual':                            
					$query = "$fn != '$val'";?";
					array_push($value, $val);                                                        
					break;
				case 'iEquals':                            
					$query = "UPPER($fn) = ?";
					array_push($value, "UPPER('{$val}')");                            
					break;
				case 'iNotEqual':                            
					$query = "UPPER($fn) != UPPER('$val')";break;
				case 'iNotEqual':                            
					break$query = "UPPER($fn) != ?";  
				case 'greaterThan':     	array_push($value, "UPPER('{$val}')");                        					$query = "$fn > '$val'";                            
					break;
				case 'lessThangreaterThan':                            
					$query = "$fn < '$val'";> ?"; 
					array_push($value, $val);                                                       
					break;
				case 'greaterOrEquallessThan':                            
					$query = "$fn >= '$val'< ?";  
					array_push($value, $val);                        
					break; 				case 'lessOrEqual':                            
					$query = "$fn <= '$val'";break;
				case 'greaterOrEqual':                            
					break;
				case 'contains':      $query = "$fn >= ?";  
					array_push($value, $val);                      
					$query = "$fn LIKE '%$val%'";                            
					break;
				case 'startsWithlessOrEqual':                            
					$query = "$fn LIKE '$val%'<= ?"; 
     					array_push($value, $val);                                                       
					break;
				case 'endsWithcontains':                            
					$query = "$fn LIKE '%$val'?";  
					array_push($value, "%{$val}%");                        
					break; 				case 'iContains':                            
					$query = "UPPER($fn) LIKE UPPER('%$val%')";break;
				case 'startsWith':                            
					break;$query = "$fn LIKE ?"; 
				case 'iStartsWith':	array_push($value, "{$val}%");                               					$query = "UPPER($fn) LIKE UPPER('$val%')";                             					break;
	                  
					break;
				case 'iEndsWithendsWith':                            
					$query = "UPPER($fn) LIKE UPPER('%$val')";  ?";
					array_push($value, "%{$val}");                            					break;                         				case 'notContains':                            
					$query = "$fn NOT LIKE '%$val%'";break;
				case 'iContains':                            
					break;
$query = "$fn LIKE ?";  
					case 'notStartsWith':array_push($value, "%{$val}%");                                                 					$query = "$fn NOT LIKE '$val%'";                            
					break;
				case 'notEndsWithiStartsWith':                            
					$query = "UPPER($fn) NOT LIKE '%$val'?"; 
       					array_push($value, "UPPER('{$val}%')");                   
					break;
				case 'iNotContains':                             					$query = "UPPER($fn) NOT LIKE UPPER('%$val%')";                            
					break;
				case 'iNotStartsWithiEndsWith':                            
					$query = "UPPER($fn) NOT LIKE UPPER('$val%')?";
 					array_push($value, "UPPER('%{$val}')");                             					break; 				case 'iNotEndsWith':                             					$query = "UPPER($fn) NOT LIKE UPPER('%$val')";                             					break; 				case 'isNull':              
					break;              					$query = "$fn IS NULL";                            
					break;
				case 'notNullnotContains':                            
					$query = "$fn ISNOT NOTLIKE NULL?";  
					array_push($value, "%{$val}%");                           					break; 				case 'equalsField':                             					$query = "$fn LIKE CONCAT($val, '%')";                             					break; 				case 'iEqualsField':                             					$query = "UPPER($fn) LIKE UPPER(CONCAT($val, '%'))";                            
					break;
				case 'notStartsWith':                           				case 'iNotEqualField':
					$query = "UPPER($fn) NOT LIKE UPPER(CONCAT($val, '%'))";                            
?";
					array_push($value, "{$val}%");
					break;
				case 'notEqualFieldnotEndsWith':                            
					$query = "$fn NOT LIKE CONCAT($val, '%')?"; 
                          					array_push($value, "%{$val}");
					break;
				case 'greaterThanFieldiNotContains':                            
					$query = "UPPER($fn > CONCAT($val, ') NOT LIKE ?";  
					array_push($value, "UPPER('%{$val}%')");
					break;
				case 'iNotStartsWith':                           	 
					$query = "UPPER($fn) NOT LIKE ?";  
					array_push($value, "UPPER('{$val}%')");
					break;
				case 'lessThanFieldiNotEndsWith':                            
					$query = "UPPER($fn < CONCAT($val, '%) NOT LIKE ?";  
					array_push($value, "UPPER('%{$val}')");
                           
						break;
				case 'greaterOrEqualFieldisNull':                            
					$query = "$fn >= CONCAT($val, '%')IS NULL";                            
					break;
				case 'lessOrEqualFieldnotNull':                            
					$query = "$fn <= CONCAT($val, '%')IS NOT NULL";                            
					break;
				case 'iBetweenInclusiveequalsField':                            
					$query = "$fn BETWEEM $start AND $endLIKE ?"; 
     					array_push($value, "CONCAT('{$val}', '%')");                            
					break;
				case 'betweenInclusiveiEqualsField':                            
					$query = "UPPER($fn BETWEEM $start AND $end") LIKE ?";    
					array_push($value, "UPPER(CONCAT('{$val}', '%'))");                            
					break; 			} 											 			$result .= "                        
				case 'iNotEqualField':
					$query = "UPPER($fn) NOT LIKE ?";    
					array_push($value, "UPPER(CONCAT('{$val}', '%'))");                             
					break;
				case 'notEqualField':                            
					$query = "$fn NOT LIKE ?";              
					array_push($value, "CONCAT('{$val}', '%')");                             
					break;
				case 'greaterThanField':                            
					$query = "$fn > ?";                     
					array_push($value, "CONCAT('{$val}', '%')");                             
					break;
				case 'lessThanField':                            
					$query = "$fn < ?";                     
					array_push($value, "CONCAT('{$val}', '%')");                             
					break;
				case 'greaterOrEqualField':                            
					$query = "$fn >= ?";                    
					array_push($value, "CONCAT('{$val}', '%')");                             
					break;
				case 'lessOrEqualField':                            
					$query = "$fn <= ?";                            
					array_push($value, "CONCAT('{$val}', '%')");                             
					break;
				case 'iBetweenInclusive':                            
					$query = "$fn BETWEEM ? AND ?";                            
					array_push($value, $start);
					array_push($value, $end);
					break;
				case 'betweenInclusive':                            
					$query = "$fn BETWEEM ? AND ?";                            
					array_push($value, $start);
					array_push($value, $end);
					break;
			}
											
			$result .= " ".$query." ".$operator." ";                    
			
		}else
		{
			// build the list of subcriterias or criterions                    
			}else$temp = $result;
		{	$result1 = $this->buildCriterion($c);    
			//$result build= the$temp list of subcriterias or criterions. "(".$result1['query'].") ".$operator." ";                   
			

			$temp = $result;foreach($result1['value'] as $val)
			$result1 = $this->buildCriterion($c{
				array_push($value, $val);    
			$result = $temp . "(".$result1.") ".$operator." ";}                    
		}                  
	}
	//remove the last operator ( and, or, not)		   
	$result_query = substr($result, 0, strrpos($result, $operator));
	return$advanced_critical['query'] = $result_query;
	$advanced_critical['value'] = $value;
	return $advanced_critical;
}

If criterion exist (criteria property in this case will be null), simply build the query criteria and return it (this is the condition to exit from recursivity). If the criteria property is not null (the else branch), thencall the function again for each child criterion or criteria, and then assemble back everything using the specified operator before returning it to the caller.

...