Select categories displayed in geonetwork homepage

158 Views Asked by At

In geonetwork 3.6 home page, I want to select which metadata categories are displayed. Geonetwork uses a facetted search with AngularJs (which I'm not familiar with) to select the category that are displayed. By default, all categories available are shown.

The code looks like:

<div class="row"> 

        <span data-ng-repeat="(key, facet) in searchInfo.facet['category']"  
              class="col-xs-12 col-sm-6 col-md-4 chips-card">
              <a href="#/search?facet.q=category%2F{{facet['@name']}}">
                <img class="pull-left img-thumbnail" src="http://localhost:8080/geonetwork/images/harvesting/odnature.png" alt="thumbnail image"></img>
              </a>
             <a class="pull-left clearfix"
               title="{{facet['@label']}}">

              <span class="badge-text pull-left">
                <span class="gn-icon-label">{{facet['@label']}}</span>
              </span>  
          </a>
        </span>  
     </div>

Instead of having all the categories I need to select only a few of them. I tried to filter by changing the ng-repeat element like:

<span data-ng-repeat="(key, facet) in searchInfo.facet['category'] == 'some_category'"

But no results. Is there a way to easily choose which elements are shown?

2

There are 2 best solutions below

0
Pop-A-Stash On BEST ANSWER

AngularJS has a filter syntax for ngRepeat:

<span data-ng-repeat="(key, facet) in searchInfo.facet['category'] | filter:'some_category'" ...>  

If you want to filter by more than one string, it's probably best to use a predicate function:

<span data-ng-repeat="(key, facet) in searchInfo.facet['category'] | filter:catSubset" ...>  

Define the predicate function in your controller:

$scope.catSubset = function(value, index, array) {
  if(value == "some_category" || value == "some_other_category") {
    return true;
  }
}

This is not supported by Internet Explorer (without a polyfill), but is easier to read/write:

var selectedCategories = [
    "some_category", 
    "some_other_category"
];
$scope.catSubset = function(value, index, array) {
  if(selectedCategories.includes(value)) {
    return true;
  }
}
0
Nicolas deville On

As the number of categories I need are quite limited, I changed the strategy and harcoded it instead of using filter options. Not an efficient solution if many categories are needed but for my case it's acceptable. I coded it this way:

<div class="col-sm-12 col-md-12" data-ng-show="browse !== ''"> <!-- set width of facet box on main page -->
      <h3>

      <div class="row">  <!-- box containing the different topics -->

        <!-- First category -->
        <div class="col-xs-12 col-sm-6 col-md-4 chips-card text-center">

              <a href="#/search?facet.q=keyword%2FMarine Spatial Plan%26type%2Fdataset&resultType=details">
                <img class="img-thumbnail" src="http://localhost:8080/geonetwork/images/harvesting/belgica-image.jpeg" alt="thumbnail image"></img>
                <p>Marine Spatial Plan</p>
              </a>
        </div>  


        <!-- Second category -->
        <div 
              class="col-xs-12 col-sm-6 col-md-4 chips-card text-center">

              <a href="#/search?facet.q=keyword%2FMarine Strategy Framework Directive%26type%2Fdataset&resultType=details">
                <img class="img-thumbnail" src="http://localhost:8080/geonetwork/images/harvesting/MSFD-logo.jpeg" alt="thumbnail image"></img>
                <p class="text-center">Marine Strategy Framework Directive</p>
              </a>
        </div>  

and so on.