Преглед изворни кода

add label search to fess-ss

yfujita пре 7 година
родитељ
комит
62fb4b540e

+ 5 - 5
src/main/assemblies/extension/fess-ss/package.json

@@ -9,15 +9,15 @@
   "author": "",
   "license": "ISC",
   "devDependencies": {
-    "babel-core": "^6.25.0",
-    "babel-loader": "^7.1.1",
-    "babel-polyfill": "^6.23.0",
+    "babel-core": "^6.26.0",
+    "babel-loader": "^7.1.2",
+    "babel-polyfill": "^6.26.0",
     "babel-preset-es2015": "^6.24.1",
     "babel-preset-stage-0": "^6.24.1",
-    "css-loader": "^0.28.4",
+    "css-loader": "^0.28.7",
     "extract-text-webpack-plugin": "^2.1.2",
     "handlebars": "^4.0.10",
-    "handlebars-loader": "^1.5.0",
+    "handlebars-loader": "^1.6.0",
     "jquery": "^3.2.1",
     "node-sass": "^4.5.3",
     "sass-loader": "^6.0.6",

+ 34 - 11
src/main/assemblies/extension/fess-ss/src/controller.js

@@ -7,6 +7,8 @@ export default class {
     this.fessUrl = FessJQuery('script#fess-ss').attr('fess-url');
     this.fessContextPath = this.fessUrl.slice(0, this.fessUrl.indexOf('/json'));
     this.searchPagePath = FessJQuery('script#fess-ss').attr('fess-search-page-path');
+    this.enableLabels = FessJQuery('script#fess-ss').attr('enable-labels') === 'true' ? true : false;
+    this.labelsCache = null
     this.urlParams = function() {
       var params = {};
       var array = location.search.replace(/\?/g, '').split('&');
@@ -93,27 +95,48 @@ export default class {
     }
 
     var sort = FessJQuery(".fessWrapper select.sort").val();
-    if (sort !== undefined) {
+    if (sort !== undefined && sort !== '') {
       params.sort = sort;
-    } else {
-      params.sort = 'score.desc';
+    }
+    var label = FessJQuery(".fessWrapper select.field-labels").val();
+    if (label !== undefined && label !== '') {
+      params['fields.label'] = label;
     }
 
     var $cls = this;
     this.FessModel.search(this.fessUrl, params).then(function(data){
-      var response = data.response;
-      if (response.record_count > 0) {
-        $cls.FessView.renderResult($cls.fessContextPath, data.response, params);
-        $fessResult.css('display', 'block');
-        $cls._bindPagination(data.response);
+      var searchResponse = data.response;
+      if ($cls.enableLabels && $cls.labelsCache === null) {
+        $cls.FessModel.getLabels($cls.fessUrl).then(function(data) {
+          $cls.labelsCache = data.response.result;
+          $cls._renderResult(searchResponse, params);
+        }, function(data) {
+          console.log("labels error: " + JSON.stringify(data));
+          $cls._renderResult(searchResponse, params);
+        });
       } else {
-        $cls.FessView.renderNoResult(data.response, params);
-        $fessResult.css('display', 'block');
+        $cls._renderResult(searchResponse, params);
       }
     }, function(data) {
       console.log("search error: " + JSON.stringify(data));
-      $cls.FessView.renderNoResult(data.response, params);
+      $cls.FessView.renderNoResult(searchResponse, params);
       $fessResult.css('display', 'block');
     });
   }
+
+  _renderResult(response, params) {
+    if (this.enableLabels && this.labelsCache !== null) {
+      response.labels = this.labelsCache;
+    }
+
+    var $fessResult = FessJQuery('.fessWrapper .fessResult');
+    if (response.record_count > 0) {
+      this.FessView.renderResult(this.fessContextPath, response, params);
+      $fessResult.css('display', 'block');
+      this._bindPagination(response);
+    } else {
+      this.FessView.renderNoResult(response, params);
+      $fessResult.css('display', 'block');
+    }
+  }
 }

+ 24 - 21
src/main/assemblies/extension/fess-ss/src/css/ss.scss

@@ -7,37 +7,40 @@
   }
   .form-control.sort {
     display: inline;
-    width: 50%;
+    width: 90%;
+  }
+  .media-body {
+    width: initial;
   }
   /* Large desktop */
   @media ( min-width : 74.9em) {
     .order-box {
-      width: 20%
+      width: 10%
     }
-    .description {
-      font-size: medium;
+    .labels-box {
+      width: 10%
     }
     .title {
       line-height: 32px;
       font-size: 18px;
     }
-    .site {
+    .site, .description, .result-header, .field-labels, .sort {
       font-size: medium;
     }
   }
   /* Large devices (desktops, less than 75em) */
   @media ( max-width : 74.9em) {
     .order-box {
-      width: 20%
+      width: 10%
     }
-    .description {
-      font-size: medium;
+    .labels-box {
+      width: 10%
     }
     .title {
       line-height: 32px;
       font-size: 18px;
     }
-    .site {
+    .site, .description, .result-header, .field-labels, .sort {
       font-size: medium;
     }
   }
@@ -45,16 +48,16 @@
   /* Medium devices (tablets, less than 62em) */
 	@media ( max-width : 61.9em) {
     .order-box {
-      width: 20%
+      width: 15%
     }
-    .description {
-      font-size: medium;
+    .labels-box {
+      width: 15%
     }
     .title {
       line-height: 32px;
       font-size: 18px;
     }
-    .site {
+    .site, .description, .result-header, .field-labels, .sort {
       font-size: medium;
     }
   }
@@ -62,16 +65,16 @@
   /* Small devices (landscape phones, less than 48em) */
   @media ( max-width : 47.9em) {
     .order-box {
-      width: 50%
+      width: 25%
     }
-    .description {
-      font-size: small;
+    .labels-box {
+      width: 25%
     }
     .title {
       line-height: 24px;
       font-size: 15px;
     }
-    .site {
+    .site, .description, .result-header, .field-labels, .sort {
       font-size: small;
     }
   }
@@ -79,16 +82,16 @@
   /* Extra small devices (portrait phones, less than 34em) */
   @media ( max-width : 360px) {
     .order-box {
-      width: 50%
+      width: 30%
     }
-    .description {
-      font-size: small;
+    .labels-box {
+      width: 30%
     }
     .title {
       line-height: 24px;
       font-size: 15px;
     }
-    .site {
+    .site, .description, .result-header, .field-labels, .sort {
       font-size: small;
     }
   }

+ 1 - 1
src/main/assemblies/extension/fess-ss/src/css/style-base.scss

@@ -4690,7 +4690,7 @@
   }
 
   .media-body {
-    //width: 10000px;
+    width: 10000px;
   }
 
   .media-left,

+ 4 - 0
src/main/assemblies/extension/fess-ss/src/fess-messages.js

@@ -6,6 +6,8 @@ export default class {
         'form.input.placeholder': '',
         'result.number': 'results',
         'result.second': 'second',
+        'result.label': 'Labels',
+        'result.label.all': 'All',
         'result.order': 'Order',
         'result.order.score': 'Relevance',
         'result.order.last_modified': 'Last modified',
@@ -18,6 +20,8 @@ export default class {
         'form.input.placeholder': '',
         'result.number': '件',
         'result.second': '秒',
+        'result.label': 'ラベル',
+        'result.label.all': '全て',
         'result.order': '表示順',
         'result.order.score': '関連度',
         'result.order.last_modified': '更新日時',

+ 15 - 0
src/main/assemblies/extension/fess-ss/src/model.js

@@ -18,4 +18,19 @@ export default class {
       });
     });
   }
+
+  getLabels(url) {
+    return new Promise(function(resolve, reject) {
+      FessJQuery.ajax({
+        url: url,
+        type: "GET",
+        dataType: "jsonp",
+        data: {type: 'label'}
+      }).done(function(data){
+        resolve(data);
+      }).fail(function(data){
+        reject(data);
+      });
+    });
+  }
 }

+ 24 - 2
src/main/assemblies/extension/fess-ss/src/templates/fess-no-result.hbs

@@ -1,11 +1,33 @@
 <div id="result">
   <div style="border-bottom:solid thin #eeeeee;padding-bottom:5px;margin-bottom:10px;">
-    <table width="100%">
+    <table width="100%" class="result-header">
       <tbody>
         <tr>
-          <td width="50%">
+          <td>
             {{record_count}} {result.number} ({{exec_time}}{result.second})
           </td>
+          {{#if labels}}
+          <td class="labels-box" align="right">
+            <div class="labels">
+              <select class="form-control field-labels">
+                <option value="" disabled selected style="display:none;">{result.label}</option>
+                <option value="">{result.label.all}</option>
+                {{#each labels}}
+                <option value="{{value}}">{{label}}</option>
+                {{/each}}
+              </select>
+            </div>
+          </td>
+          {{/if}}
+          <td class="order-box" align="right">
+            <div class="order">
+              <select class="form-control sort">
+                <option value="" disabled selected style="display:none;">{result.order}</option>
+                <option value="score.desc">{result.order.score}</option>
+                <option value="last_modified.desc">{result.order.last_modified}</option>
+              </select>
+            </div>
+          </td>
         </tr>
       </tbody>
     </table>

+ 15 - 2
src/main/assemblies/extension/fess-ss/src/templates/fess-result.hbs

@@ -1,15 +1,28 @@
 <div id="result">
   <div style="border-bottom:solid thin #eeeeee;padding-bottom:5px;margin-bottom:10px;">
-    <table width="100%">
+    <table width="100%" class="result-header">
       <tbody>
         <tr>
           <td>
             {{record_count}} {result.number} ({{exec_time}}{result.second})
           </td>
+          {{#if labels}}
+          <td class="labels-box" align="right">
+            <div class="labels">
+              <select class="form-control field-labels">
+                <option value="" disabled selected style="display:none;">{result.label}</option>
+                <option value="">{result.label.all}</option>
+                {{#each labels}}
+                <option value="{{value}}">{{label}}</option>
+                {{/each}}
+              </select>
+            </div>
+          </td>
+          {{/if}}
           <td class="order-box" align="right">
             <div class="order">
-              {result.order}:
               <select class="form-control sort">
+                <option value="" disabled selected style="display:none;">{result.order}</option>
                 <option value="score.desc">{result.order.score}</option>
                 <option value="last_modified.desc">{result.order.last_modified}</option>
               </select>

+ 18 - 1
src/main/assemblies/extension/fess-ss/src/view.js

@@ -73,9 +73,15 @@ export default class {
     var $pagination = this._createPagination(response.record_count, response.page_size, response.page_number, params);
     FessJQuery('.fessWrapper .paginationNav').append($pagination);
     if (FessJQuery('.fessWrapper .fessForm').length > 0) {
-      FessJQuery('.fessWrapper select.sort').val(params.sort);
+      if (params.sort !== undefined) {
+        FessJQuery('.fessWrapper select.sort').val(params.sort);
+      }
+      if (params['fields.label'] !== undefined){
+        FessJQuery('.fessWrapper select.field-labels').val(params['fields.label']);
+      }
     } else {
       FessJQuery('.fessWrapper .fessResult table .order').css('display', 'none');
+      FessJQuery('.fessWrapper .fessResult table .labels').css('display', 'none');
     }
     this._loadThumbnail(contextPath);
   }
@@ -84,6 +90,17 @@ export default class {
     var $fessResult = FessJQuery('.fessWrapper .fessResult');
     var html = noResultTemplate(response);
     $fessResult.html(this.FessMessages.render(html, response));
+    if (FessJQuery('.fessWrapper .fessForm').length > 0) {
+      if (params.sort !== undefined) {
+        FessJQuery('.fessWrapper select.sort').val(params.sort);
+      }
+      if (params['fields.label'] !== undefined){
+        FessJQuery('.fessWrapper select.field-labels').val(params['fields.label']);
+      }
+    } else {
+      FessJQuery('.fessWrapper .fessResult table .order').css('display', 'none');
+      FessJQuery('.fessWrapper .fessResult table .labels').css('display', 'none');
+    }
   }
 
   _createPagination(recordCount, pageSize, currentPage, params) {

+ 1 - 0
src/main/assemblies/extension/fess-ss/ss.html

@@ -14,6 +14,7 @@
     fess.charset = 'utf-8';
     fess.setAttribute('id', 'fess-ss');
     fess.setAttribute('fess-url', '//localhost:8080/json');
+    fess.setAttribute('enable-labels', 'true');
     var s = document.getElementsByTagName('script')[0];
     s.parentNode.insertBefore(fess, s);
   })();