Commits

Juan Carlos Picado Herrera  committed bf8b68f

ENCUESTAME-150, widget suggest prototype

  • Participants
  • Parent commits 94dab6e

Comments (0)

Files changed (10)

File encuestame-business/src/main/java/org/encuestame/business/search/GlobalSearchItem.java

  */
 public class GlobalSearchItem {
 
+    private Long id;
+
     private String urlLocation;
 
     private Long score;
         this.itemSearchDescription = itemSearchDescription;
     }
 
+    /**
+     * @return the id
+     */
+    public Long getId() {
+        return id;
+    }
+
+    /**
+     * @param id the id to set
+     */
+    public void setId(Long id) {
+        this.id = id;
+    }
+
     /* (non-Javadoc)
      * @see java.lang.Object#hashCode()
      */

File encuestame-business/src/main/java/org/encuestame/business/service/SearchService.java

         hashset.addAll(profiles);
         hashset.addAll(tags);
         hashset.addAll(attachments);
-        return new ArrayList<GlobalSearchItem>(hashset);
+
+        final List<GlobalSearchItem> totalItems = new ArrayList<GlobalSearchItem>(hashset);
+        int x = 1;
+        for (int i = 0; i < totalItems.size(); i++) {
+            totalItems.get(i).setId(Long.valueOf(x));
+            x++;
+        }
+        return totalItems;
     }
 
     public List<GlobalSearchItem> globalKeywordSearch(String keyword,

File encuestame-mvc/src/main/java/org/encuestame/mvc/controller/search/json/QuickSearchJsonController.java

 import org.codehaus.jackson.map.JsonMappingException;
 import org.encuestame.business.search.GlobalSearchItem;
 import org.encuestame.mvc.controller.AbstractJsonController;
-import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
-import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
      * @throws JsonMappingException
      * @throws IOException
      */
-    @PreAuthorize("hasRole('ENCUESTAME_USER')")
     @RequestMapping(value = "api/search/quick-suggest.json", method = RequestMethod.GET)
     public ModelMap quickSuggestionSearchService(
             @RequestParam(value = "keyword", required = true) String keyword,
             final List<GlobalSearchItem> results = getSearchService()
                     .quickSearch(keyword, "English", 0, 10);
             log.debug("GlobalSearchItem results " + results.size());
-            final Map<String, Object> success = new HashMap<String, Object>();
-            success.put("suggest", results);
-            setItemResponse(success);
+            setItemReadStoreResponse("itemSearchTitle", "id", results);
         } catch (Exception e) {
             e.printStackTrace();
             log.error(e);

File encuestame-war/src/main/webapp/WEB-INF/spring/encuestame-quartz-context.xml

                 <!-- Reindex attachments -->
                 <bean id="attachmentsReindex" class="org.springframework.scheduling.quartz.CronTriggerBean">
                     <property name="jobDetail" ref="reindexingAttachmentsJobDetail" />
-                    <property name="cronExpression" value="0 0/45 * * * ?" />
+                    <property name="cronExpression" value="0 0/4 * * * ?" />
                     <!-- Every 5 minutes 0 0/5 * * * ? -->
                     <!-- 0 0 12 1/5 * ? Fire at 12pm (noon) every 5 days every month, starting on the first day of the month. -->
                 </bean>

File encuestame-war/src/main/webapp/resource/js/encuestame/org/core/commons.js

 
 encuestame.service.social.facebook = {};
 encuestame.service.social.linkedIn = {};
+
+//search
+
+encuestame.service.search = {};
+encuestame.service.search.suggest = encuestame.contextWidget()+"/api/search/quick-suggest.json";
+

File encuestame-war/src/main/webapp/resource/js/encuestame/org/core/commons/search/SearchMenu.js

 dojo.provide("encuestame.org.core.commons.search.SearchMenu");
 
+dojo.require("encuestame.org.core.shared.utils.Suggest");
+
+/**
+ * Search menu widget.
+ * This widget only return suggest float window with list of results based on keyword.
+ */
 dojo.declare(
     "encuestame.org.core.commons.search.SearchMenu",
-    [dijit._Widget, dijit._Templated],{
+    [encuestame.org.core.shared.utils.SuggestItem],{
         templatePath: dojo.moduleUrl("encuestame.org.core.commons.search", "templates/searchMenu.inc"),
 
-        widgetsInTemplate: true
+        /*
+         * enable widget on template.
+         */
+        widgetsInTemplate: true,
+
+        /*
+         * suggest widget referece.
+         */
+        suggestWidget : null,
+
+        /*
+         * store all items.
+         */
+        listItems : [],
+
+        /*
+         * post create process.
+         */
+        postCreate: function() {
+          //instance suggest widget.
+            this.suggestWidget = new encuestame.org.core.shared.utils.Suggest(
+                { url :encuestame.service.search.suggest,
+                  addButton : false,
+                  hideLabel: true,
+                  query :  {itemSearchTitle : "*"}});
+            //override build row method.
+            this.suggestWidget.buildRow = dojo.hitch(this, function(data){
+                  console.info("suggest buildRow...", data);
+                  this.newItemSuggest(data);
+              });
+            //append child widget dom node.
+            this._suggest.appendChild(this.suggestWidget.domNode);
+            //if suggest is not null we override pricessSelectedItem method.
+            if(this.suggestWidget){
+                this.suggestWidget.processSelectedItem = dojo.hitch(this, function(data){
+                    console.info("Processing Item Selected ...", data);
+                    this.newItemSuggest(data);
+                });
+            }
+        },
+
+        /*
+         * Create new suggest item.
+         * @param data suggested search item.
+         */
+        newItemSuggest : function(data){
+            var widget = new encuestame.org.core.commons.search.SearchSuggestItem(
+                    {
+                     data : data,
+                     parentWidget : this,
+                     suggestWidget : this.suggestWidget
+                     });
+            this.listItems.push(widget);
+            this.suggestWidget._suggestItems.appendChild(widget.domNode);
+            widget.processItem = this.suggestWidget.processSelectedItem;
+        }
+});
+
+/*
+ * Widget define item suggest box.
+ */
+dojo.declare(
+        "encuestame.org.core.commons.search.SearchSuggestItem",
+        [dijit._Widget, dijit._Templated],{
+        //template
+        templatePath: dojo.moduleUrl("encuestame.org.core.commons.search", "templates/searchSuggestItem.inc"),
+        //widgets in template
+        wigetsInTemplate: true,
+        //reference of suggest widget.
+        suggestWidget: null,
 
+        _goTo : function(event){
+            //TODO: do something when you click on it
+            this.suggestWidget.hide();
+        }
 });

File encuestame-war/src/main/webapp/resource/js/encuestame/org/core/commons/search/templates/searchMenu.inc

-<span>
-    <input type="text" name="search" id="search" size="20" class="defaultInputClass"
-                         value="SEARCH"
-                         onclick = "if(this.value=='SEARCH') this.value=''"/>
-</span>
+<div>
+   <div dojoAttachPoint="_suggest"></div>
+    <div class="wrapperHashTagItems">
+        <div dojoAttachPoint="_items"></div>
+    </div>
+</div>

File encuestame-war/src/main/webapp/resource/js/encuestame/org/core/commons/search/templates/searchSuggestItem.inc

+<div class="searchSuggestItem" dojoAttachEvent="onclick:_goTo">
+    <span>
+        ${data.itemSearchTitle}
+    </span>
+</div>

File encuestame-war/src/main/webapp/resource/js/encuestame/org/core/shared/utils/Suggest.js

 
         buttonWidget : null,
 
+        hideLabel : false,
+
         selectedItem : null,
 
         addButton : true,
 
         label : "Label",
 
+        query :  {hashTagName : "*"},
+
         searchParam: { limit : 10, keyword : ""},
 
         postCreate: function() {
                     this._suggestButton);
                     console.debug(this.buttonWidget);
                 }
+                if (this.hideLabel) {
+                   dojo.addClass(this._label,"defaultDisplayHide");
+                }
             } else {
                 console.error("Error");
             }
 
         callSuggest : function(){
             var fetch = {
-                    query: {hashTagName : "*"},
+                    query: this.query,
                     queryOptions: {
                         ignoreCase: this.ignoreCase,
                         deep: true
                     },
                     serverQuery: this.searchParam,
                     onComplete: dojo.hitch(this, function(result, dataObject){
+                        console.info("suggeest onComplete...", result);
                         this.evaluateItems(result);
                     }),
                     onError: function(errText){
 
         /** Evaluate Items. **/
         evaluateItems : function(data){
+            console.info("suggeest data.length...", data.length);
             if(data.length > 0){
                  dojo.empty(this._suggestItems);
                  var fadeArgs = {
             }
         },
 
+        /*
+         * hide with fade out the suggest box.
+         */
         hide : function(){
             var fadeArgs = {
                     node: this._suggestItems
             this.clear();
         },
 
-        /** Build Row. **/
+        /*
+         *  Build Row.
+         */
         buildRow : function(data){
+          console.info("suggeest buildRow...", data);
             var widget = new encuestame.org.core.shared.utils.SuggestItem(
                     {
                         data: { id : data.id, label : data.hashTagName},

File encuestame-war/src/main/webapp/resource/js/encuestame/org/core/shared/utils/template/suggest.inc

 <div class="suggest">
-    <label>${label}</label><br></br>
+    <label  dojoAttachPoint="_label">${label}</label><br></br>
     <input type="text" dojoAttachPoint="_suggest"
            dojoType="dijit.form.TextBox"
            trim="true" class="inputClass"></input>