[evolvis-commits] r17747: - Added advanced search ready for merge.

messer at evolvis.org messer at evolvis.org
Wed Nov 30 19:04:26 CET 2011


Author: messer
Date: 2011-11-30 19:04:26 +0100 (Wed, 30 Nov 2011)
New Revision: 17747

Modified:
   branches/messer-51-suche/src/common/advanced_search/ASTokenizer.class.php
   branches/messer-51-suche/src/common/advanced_search/FusionForgeDFIProvider.class.php
   branches/messer-51-suche/src/www/tracker/browse.php
   branches/messer-51-suche/src/www/tracker/search.php
Log:
- Added advanced search ready for merge. 

Modified: branches/messer-51-suche/src/common/advanced_search/ASTokenizer.class.php
===================================================================
--- branches/messer-51-suche/src/common/advanced_search/ASTokenizer.class.php	2011-11-30 15:28:56 UTC (rev 17746)
+++ branches/messer-51-suche/src/common/advanced_search/ASTokenizer.class.php	2011-11-30 18:04:26 UTC (rev 17747)
@@ -14,13 +14,18 @@
 	public static $DFIProvider = null;
 	
     public static function tokenize($inputString, $params) {
+    	
+    	if(trim($inputString) == "") {
+    		return false;
+    	}
+    	
         $tokens       = array();
         $wordList     = explode(' ', $inputString);
         $curTerm      = '';
         $dfiList      = AStokenizer::$DFIProvider->getSimpleDFIList($params);
         
         foreach($wordList as $curWord) {
-            //Check if it is one of the tokens
+            //Check if it is one of the operators
             switch(strtoupper($curWord)) {
                 case 'EQUALS': {
                     //Check if $curTerm is not empty. If it is not, add an DFI Token.

Modified: branches/messer-51-suche/src/common/advanced_search/FusionForgeDFIProvider.class.php
===================================================================
--- branches/messer-51-suche/src/common/advanced_search/FusionForgeDFIProvider.class.php	2011-11-30 15:28:56 UTC (rev 17746)
+++ branches/messer-51-suche/src/common/advanced_search/FusionForgeDFIProvider.class.php	2011-11-30 18:04:26 UTC (rev 17747)
@@ -32,8 +32,12 @@
      */
     public function getDFIList($params) {
         $tracker_id = $params['tracker_id'];
-        $result     = array();
-        //$result     = array(array('ID', 'artifact_id'), array('Open Date', 'date'), array('Assigned To', 'assigned_to'), array('Creator', 'crated_by'));
+        //Don't forget the Standard fields.
+        $result     = array(array('ID', 'artifact_id'),
+                            array('Open Date', 'open_date'),
+                            array('Close Date', 'close_date'),
+                            array('Assigned to', 'assigned_to'),
+                            array('Submitted by', 'submitted_by'));
         
         $sql = "SELECT field_name, alias FROM artifact_extra_field_list WHERE group_artifact_id = $1";
         $dbRes = db_query_params($sql, array($tracker_id));
@@ -53,8 +57,12 @@
     public function getSimpleDFIList($params) {
     	$tracker_id = $params['tracker_id'];
         $result     = array();
-        //$result     = array(array('ID', 'artifact_id'), array('Open Date', 'date'), array('Assigned To', 'assigned_to'), array('Creator', 'crated_by'));
-        
+        $result     = array('ID',
+                            'Open Date',
+                            'Close Date',
+                            'Assigned to',
+                            'Submitted by');
+                            
         $sql = "SELECT field_name FROM artifact_extra_field_list WHERE group_artifact_id = $1";
         $dbRes = db_query_params($sql, array($tracker_id));
         

Modified: branches/messer-51-suche/src/www/tracker/browse.php
===================================================================
--- branches/messer-51-suche/src/www/tracker/browse.php	2011-11-30 15:28:56 UTC (rev 17746)
+++ branches/messer-51-suche/src/www/tracker/browse.php	2011-11-30 18:04:26 UTC (rev 17747)
@@ -24,6 +24,10 @@
 
 require_once $gfcommon.'tracker/ArtifactFactory.class.php';
 require_once $gfcommon.'tracker/ArtifactQuery.class.php';
+require_once $gfcommon.'advanced_search/FusionForgeDFIProvider.class.php';
+require_once $gfcommon.'advanced_search/ASFusionForgeParser.class.php';
+require_once $gfcommon.'advanced_search/AdvancedSearch.class.php';
+
 //
 //  make sure this person has permission to view artifacts
 //
@@ -141,15 +145,10 @@
 
 $art_arr = $af->getArtifacts();
 
-if (!$art_arr && $af->isError()) {
-	exit_error($af->getErrorMessage(),'tracker');
-}
-
 //build page title to make bookmarking easier
 //if a user was selected, add the user_name to the title
 //same for status
 use_javascript('/tabber/tabber.js');
-html_use_jqueryui();
 
 $ath->header(array('atid'=>$ath->getID(), 'title'=>$ath->getName()));
 
@@ -321,7 +320,7 @@
 print "</div>\n"; // end of about
 
 echo '
-<div id="tabber" class="tabber">
+<div id="tabber'.($af->query_type == 'advanced' ? ' tabbertabdefault' : '').'" class="tabber">
 	<div class="tabbertab" title="'._('Advanced queries').'">';
 
 if (session_loggedin()) {
@@ -339,109 +338,114 @@
 				array ($ath->getID()));
 }
 
+/**
+ * New advaced search begins here!
+ */
+$curSearch = getStringFromRequest('advanced_search');
+$queryName = "Query Name";
 
-if (db_numrows($res)>0) {
-	echo '<form action="'. getStringFromServer('PHP_SELF') .'" method="get">';
-	echo '<input type="hidden" name="group_id" value="'.$group_id.'" />';
-	echo '<input type="hidden" name="atid" value="'.$ath->getID().'" />';
-	echo '<input type="hidden" name="power_query" value="1" />';
-	echo '	<table width="100%" cellspacing="0">
-	<tr>
-	<td>
-	';
-	$optgroup['key'] = 'type';
-	$optgroup['values'][0] = 'Private queries';
-	$optgroup['values'][1] = 'Project queries';
-	echo '<span style="font-size:smaller">';
-	echo '<select name="query_id">';
-	echo '<option value="100">Select One</option>';
-	$current = '';
-	$selected = $af->getDefaultQuery();
-	while ($row = db_fetch_array($res)) {
-		if ($current != $row['type']) {
-			if ($current !== '') 
-				echo '</optgroup>';
-			$label = $row['type'] ? 'Project' : 'Private';
-			echo '<optgroup label="'.$label.'">';
-			$current = $row['type'];
+if(getIntFromRequest('load_request')) {
+
+		$sql = "SELECT query, name FROM AdvancedQuery WHERE id = $1;";
+		$result = db_query_params($sql, array(getIntFromRequest('saved_advanced_querys')));
+	
+		$curSearchArr = db_fetch_array($result);
+
+		$curSearch = $curSearchArr['query'];
+		$queryName = $curSearchArr['name'];
+}
+
+if(getStringFromRequest('search') == 'true') {
+	$parser = new ASFusionForgeParserTracker();
+	
+	AStokenizer::$DFIProvider = new FusionForgeDFIProvider();
+	
+	$parser->setParam('tracker_id', getIntFromRequest('atid'));
+	$art_arr = $parser->parse($curSearch, $ath);
+	
+	if($art_arr === false) {
+		$art_arr = null;
+	}
+	
+	if(getStringFromRequest('save_advanced_query') === 'true') {
+		//Check if a query for this user and this tracker allready exists. If yes just update the query.
+		$sql = "SELECT * FROM AdvancedQuery, user_has_query WHERE id = query_id AND name = $1 AND group_artifact_id = $2";
+		
+		$result = db_query_params($sql, array(getStringFromRequest('save_as'),
+											  getIntFromRequest('atid')));
+		
+		$num_rows = db_numrows($result);
+		
+		if($num_rows == 0) {
+			//No query existing. Save it
+			$sql = 'INSERT INTO AdvancedQuery(name, query) VALUES($1, $2);';
+		
+			$result = db_query_params($sql, array(getStringFromRequest('save_as'),
+								      $curSearch));
+		
+			$sql = 'INSERT INTO user_has_query VALUES($1, (SELECT CURRVAL(\'advancedquery_id_seq\')), $2);';
+		
+			db_query_params($sql, array(user_getid(), getIntFromRequest('atid')));
+		
+			echo _('Saved query with Name: ').getStringFromRequest('save_as');
+		} else {
+			$arr = db_fetch_array($result);
+			
+			$sql = 'UPDATE AdvancedQuery SET query = $1 WHERE id = $2';
+			
+			db_query_params($sql, array($curSearch,
+										$arr['id']));
 		}
-		echo '<option value="'.$row['artifact_query_id'].'"';
-		if ($row['artifact_query_id'] == $selected)
-			echo ' selected="selected"';
-		echo '>'. $row['query_name'] .'</option>'."\n";
 	}
-	if ($current !== '') 
-		echo '</optgroup>';
-	echo '</select>';
-	echo '</span>
-	<input type="submit" name="run" value="'._('Power Query').'" />
-	  <a href="/tracker/?atid='. $ath->getID().'&group_id='.$group_id.'&func=query">'.
-	_('Build Query').'</a>
-	</td></tr></table>
-	</form>';
-} else {
-	echo '<strong>
-	<a href="/tracker/?atid='. $ath->getID().'&group_id='.$group_id.'&func=query">'._('Build Query').'</a></strong>';
 }
+if (!$art_arr && $af->isError()) {
+	exit_error($af->getErrorMessage(),'tracker');
+}
 
-/**
- * New advaced search begins here!
- */
 ?>
-<script language="JavaScript" type="text/javascript">//<![CDATA[
-	jQuery(function() {
-		function split(val) {
-			return val.split(/ \s*/);
-		}
-		function extractLast(term) {
-			return split(term).pop();
-		}
 
-		jQuery("#advanced_search")
-			// don't navigate away from the field on tab when selecting an item
-			.bind("keydown", function(event) {
-				if (event.keyCode === jQuery.ui.keyCode.TAB &&
-				    jQuery(this).data("autocomplete").menu.active) {
-					event.preventDefault();
-				}
-			})
-			.autocomplete({
-				source: function(request, response) {
-					jQuery.getJSON("search.php?tracker_id=<?php echo $_GET['atid']; ?>&cur_input=" + request.term, {
-						term: extractLast(request.term)
-					}, response);
-				},
-				search: function() {
-					// custom minLength
-					var term = extractLast(this.value);
-					if (term.length < 0) {
-						return false;
-					}
-				},
-				focus: function() {
-					// prevent value inserted on focus
-					return false;
-				},
-				select: function(event, ui) {
-					var terms = split(this.value);
-					// remove the current input
-					terms.pop();
-					// add the selected item
-					terms.push(ui.item.value);
-					terms.push("");
-					this.value = terms.join(" ");
-					return false;
-				}
-			});
-	});
-//]]></script>
-<span class="ui-widget">
-	<label for="advanced_search"><?php echo _('Search').':'; ?> </label>
-	<input id="advanced_search" style="width: 500px;"/>
-	<input id="search" type="button" value="<?php echo _('Search'); ?>"/>
-	<input id="save" type="button" value="<?php echo _('Save'); ?>" />
-</span>
-<?php
+<form id="load_query_form" name="load_query_form" method="post" action="<?php echo getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&atid='.$ath->getID().'&search=true'; ?>">
+Load Query:
+<select name="saved_advanced_querys"> 
+	<option value="100">Select One</option>
+	<optgroup label="Tracker Querys">
+		<?php 
+			//Get all global querys. This includes System and Tracker querys.
+			$sql = "SELECT aq.id, aq.name FROM AdvancedQuery as aq, artifact_group_has_query as aghq
+					WHERE (aghq.group_artifact_id = $1 AND aq.id = aghq.query_id)";
+			
+			$result = db_query_params($sql, array(getIntFromRequest('atid')));
+			
+			while ($arr = db_fetch_array($result)) {
+				echo '<option value="'.$arr['id'].'">'.$arr['name'].'</option>';
+			}
+		?>
+	</optgroup>
+	<optgroup label="Private Querys">
+		<?php 
+			//Get all global querys. This includes System and Tracker querys.
+			$sql = "SELECT aq.id, aq.name FROM AdvancedQuery as aq, user_has_query as uhq
+					WHERE (uhq.user_id = $1 AND aq.id = uhq.query_id AND uhq.group_artifact_id = $2)";
+			
+			$result = db_query_params($sql, array(user_getid(),
+												  getIntFromRequest('atid')));
+			
+			while ($arr = db_fetch_array($result)) {
+				echo '<option value="'.$arr['id'].'">'.$arr['name'].'</option>';
+			}
+		?>
+	</optgroup>
+</select>
+<input type="hidden" name="load_request" id="load_request" value="1" />
+<input type="hidden" name="set" value="advanced" />
+<input type="submit" name="load_query" id="load_query" value="<?php echo _('Load'); ?>" />
+</form>
+<?php 
+
+AdvancedSearch::renderSearchBar(getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&atid='.$ath->getID().'&search=true',
+								"search.php?tracker_id={$_GET['atid']}&cur_input=",
+								$curSearch, $queryName);								
+
 /**
  * New advaced search ends here!
  */
@@ -449,7 +453,7 @@
 echo '
 	</div>
 	<div class="tabbertab'.($af->query_type == 'custom' ? ' tabbertabdefault' : '').'" title="'._('Simple Filtering and Sorting').'">
-	<form name="headerForm" action="'. getStringFromServer('PHP_SELF') .'?group_id='.$group_id.'&atid='.$ath->getID().'" method="post">
+	<form name="headerForm" action="'. getStringFromServer('PHP_SELF') .'?group_id='.$group_id.'&atid='.$ath->getID().'" method="post">like
 	<input type="hidden" name="query_id" value="-1" />
 	<input type="hidden" name="set" value="custom" />
 	<table width="100%" cellspacing="0">
@@ -490,7 +494,7 @@
 
 	<div>'.$paging_form.'</div>
 
-	<script language="JavaScript" type="text/javascript">//<![CDATA[
+	<script type="text/javascript">//<![CDATA[
 
 	function submitHeaderForm() {
 		document.headerForm.submit.click();

Modified: branches/messer-51-suche/src/www/tracker/search.php
===================================================================
--- branches/messer-51-suche/src/www/tracker/search.php	2011-11-30 15:28:56 UTC (rev 17746)
+++ branches/messer-51-suche/src/www/tracker/search.php	2011-11-30 18:04:26 UTC (rev 17747)
@@ -2,7 +2,6 @@
 
 require_once '/usr/share/gforge/common/advanced_search/FusionForgeDFIProvider.class.php';
 require_once '/usr/share/gforge/common/advanced_search/ASInputAnalyzer.class.php';
-//require_once '/usr/share/gforge/common/advanced_search/ASTokenizer.class.php';
 
 //Get the required paramters.
 $params = array();
@@ -19,3 +18,4 @@
 $autoComplete = $inputAnalyzer->analyzeInput($input, $params);
 
 echo json_encode($autoComplete);
+?>



More information about the evolvis-commits mailing list