Skip to content

Commit

Permalink
[BP] Search results / Configure related records type depending on tem…
Browse files Browse the repository at this point in the history
…plate. (geonetwork#7376)

* Search results / Configure related records type depending on template.

The search API provides the possibility to load related records
for each hits. This allows to easily display them in search results
but it also slow down a bit the search.

Currently only the `list.html` template was displaying them based
on the following configuration:

```
resultViewTpls: ...
grid: {
  related: ["parent", "children", "services", "datasets"]
},
```

but user may want to customize this depending on the result template.

This move the configuration to the `resultViewTpls` (and preserve
previous mechanism)

```
resultViewTpls: ...
              {
                tplUrl:
                  "../../catalog/components/" +
                  "search/resultsview/partials/viewtemplates/list.html",
                tooltip: "List",
                icon: "fa-bars",
                related: ["parent", "children", "services", "datasets"]
              },
```

so that user can more easily define which relations to load during
search depending on the result template used.

* Search / Optimize field based on current template

Each search results templates display a specific set of fields.
Add possibility to exclude unused fields from search to speed up search.

At some point, it could be better to declare all required fields for
rendering records on a per template basis on top of required fields
needed for the JS app logic (eg. privileges, status, draft).

* Batch edit / Properly init result template config.

* Search / Optimize field based on current template / Add admin UI config.
  • Loading branch information
fxprunayre authored and josegar74 committed Feb 1, 2024
1 parent ea48610 commit 5a9880e
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,28 +333,47 @@ <h2>{{('ui-mod-' + m) | translate}}</h2>
<tr data-ng-repeat="opt in mCfg[key] track by $index">
<td>
<div class="input-group">
<span class="input-group-addon">Icon </span>
<span class="input-group-addon"
>{{('ui-' + key + '-icon') | translate}}</span
>
<input
type="text"
class="form-control"
id="ui-tplIcon-{{$index}}"
data-ng-model="opt.icon"
/>
<span class="input-group-addon">Template URL </span>
<span class="input-group-addon"
>{{('ui-' + key + '-tplUrl') | translate}}</span
>
<input
type="text"
class="form-control"
id="ui-tplURL-{{$index}}"
data-ng-model="opt.tplUrl"
/>
<span class="input-group-addon">Tooltip </span>
<span class="input-group-addon"
>{{('ui-' + key + '-tooltip') | translate}}</span
>
<input
type="text"
class="form-control"
id="ui-tplTooltip-{{$index}}"
data-ng-model="opt.tooltip"
/>
</div>

<div class="row">
<label class="control-label"
>{{('ui-' + key + '-source') | translate}}</label
>
<gn-json-edit height="300" model="opt.source"></gn-json-edit>
</div>
<div class="row">
<label class="control-label"
>{{('ui-' + key + '-relatedTypes') | translate}}</label
>
<gn-json-edit height="300" model="opt.related"></gn-json-edit>
</div>
</td>
<td class="w-30-px">
<a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,19 @@
};
};

this.addSourceConfiguration = function (esParams, type) {
this.addSourceConfiguration = function (esParams, type, templateSource) {
if (type === undefined) {
type = "simplelist";
}
var source = typeof type === "string" ? this.configs[type].source : type;
var source =
typeof type === "string" ? angular.copy(this.configs[type].source, {}) : type;
if (templateSource) {
if (templateSource.exclude) {
source.includes = source.includes.filter(function (field) {
return templateSource.exclude.indexOf(field) === -1;
});
}
}
esParams._source = source;
if (this.configs[type].script_fields) {
esParams.script_fields = this.configs[type].script_fields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,13 @@
}
};

this.generateEsRequest = function (p, searchState, searchConfigId, filters) {
this.generateEsRequest = function (
p,
searchState,
searchConfigId,
filters,
templateSource
) {
var params = {};
var luceneQueryString = gnEsLuceneQueryParser.facetsToLuceneQuery(
searchState.filters
Expand Down Expand Up @@ -482,7 +488,7 @@
// "max_concurrent_group_searches": 4
// };
gnESFacet.addFacets(params, searchConfigId, searchState.languageConfig);
gnESFacet.addSourceConfiguration(params, searchConfigId);
gnESFacet.addSourceConfiguration(params, searchConfigId, templateSource);

return params;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
return {
require: "^ngSearchForm",
templateUrl:
"../../catalog/components/search/resultsview/partials/" + "templateswitcher.html",
"../../catalog/components/search/resultsview/partials/templateswitcher.html",
restrict: "A",
link: function ($scope, element, attrs, searchFormCtrl) {
$scope.setResultTemplate = function (t) {
$scope.resultTemplate = t.tplUrl;
$scope.resultTemplate = t;
searchFormCtrl.triggerSearch(true);
};
}
Expand Down Expand Up @@ -91,18 +91,6 @@
link: function (scope, element, attrs, controller) {
scope.mdService = gnMetadataActions;
scope.map = scope.$eval(attrs.map);
//scope.searchResults = scope.$eval(attrs.searchResults);

/** Display fa icons for categories
* TODO: Move to configuration */
scope.catIcons = {
featureCatalogs: "fa-table",
services: "fa-cog",
maps: "fa-globe",
staticMaps: "fa-globe",
datasets: "fa-file",
interactiveResources: "fa-rss"
};

if (scope.map) {
scope.hoverOL = new ol.layer.Vector({
Expand Down Expand Up @@ -177,13 +165,13 @@
}
});

scope.$watch("resultTemplate", function (templateUrl) {
if (angular.isUndefined(templateUrl)) {
scope.$watch("resultTemplate", function (templateConfig) {
if (angular.isUndefined(templateConfig)) {
return;
}
var template = angular.element(document.createElement("div"));
template.attr({
"ng-include": "resultTemplate"
"ng-include": "resultTemplate.tplUrl"
});
element.empty();
element.append(template);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
>
<i
data-ng-repeat="t in listOfResultTemplate"
data-ng-show="t.tplUrl == resultTemplate"
data-ng-show="t.tplUrl == resultTemplate.tplUrl"
title="{{t.tooltip | translate}}"
class="fa {{t.icon}}"
/>
Expand All @@ -17,7 +17,7 @@
<ul class="dropdown-menu">
<li
data-ng-repeat="t in listOfResultTemplate"
data-ng-hide="t.tplUrl == resultTemplate"
data-ng-hide="t.tplUrl == resultTemplate.tplUrl"
>
<a href="" data-ng-click="setResultTemplate(t);" title="{{t.tooltip | translate}}">
<i class="fa {{t.icon}}" />&nbsp; {{t.tooltip | translate}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@
finalParams,
$scope.searchObj.state,
$scope.searchObj.configId,
$scope.searchObj.filters
$scope.searchObj.filters,
$scope.resultTemplate && $scope.resultTemplate.source
);

function buildSearchKey(esParams) {
Expand All @@ -194,14 +195,39 @@
// console.log(dontComputeAggs, $scope.searchResults.searchKey, searchKey);
$scope.searchResults.searchKey = searchKey;

// For now, only the list result template renders related records
// based on UI config.
var template =
$scope.resultTemplate && $scope.resultTemplate.endsWith("list.html")
? "grid"
: "",
templateConfig = gnGlobalSettings.gnCfg.mods.search[template],
types = templateConfig && templateConfig.related ? templateConfig.related : [];
// In a search, list of related records can be added
// to each hits. This is configured depending
// on the current result template.
function getRelatedTypesForSearch() {
if (!$scope.resultTemplate) {
return [];
}
if ($scope.resultTemplate.related) {
if (!angular.isArray($scope.resultTemplate.related)) {
console.warn(
"Search results configuration error / The list of related type for the type " +
$scope.resultTemplate.tplUrl +
" must be an array. eg. '[\"children\"]'." +
" Current configuration is invalid: ",
$scope.resultTemplate.related
);
return [];
}
return $scope.resultTemplate.related;
} else {
// Old way of configuring related types (deprecated)
// which was not depending on the current template but
// only specific case for the list.html.
var template =
$scope.resultTemplate.tplUrl &&
$scope.resultTemplate.tplUrl.endsWith("list.html")
? "grid"
: "",
templateConfig = gnGlobalSettings.gnCfg.mods.search[template];
return templateConfig && templateConfig.related ? templateConfig.related : [];
}
}
var types = getRelatedTypesForSearch();

gnESClient
.search(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
"$scope",
"gnRelatedResources",
function ($scope, gnRelatedResources) {
$scope.resultTemplate =
"../../catalog/components/" +
"search/resultsview/partials/viewtemplates/grid4maps.html";
$scope.resultTemplate = {
tplUrl:
"../../catalog/components/" +
"search/resultsview/partials/viewtemplates/grid4maps.html"
};

$scope.loadMap = function (map, md) {
gnRelatedResources.getAction("MAP")(map, md);
Expand Down
27 changes: 24 additions & 3 deletions web-ui/src/main/resources/catalog/js/CatController.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,23 +655,30 @@
"../../catalog/components/" +
"search/resultsview/partials/viewtemplates/grid.html",
tooltip: "Grid",
icon: "fa-th"
icon: "fa-th",
related: []
},
{
tplUrl:
"../../catalog/components/" +
"search/resultsview/partials/viewtemplates/list.html",
tooltip: "List",
icon: "fa-bars"
icon: "fa-bars",
related: ["parent", "children", "services", "datasets"]
},
{
tplUrl:
"../../catalog/components/" +
"search/resultsview/partials/viewtemplates/table.html",
tooltip: "Table",
icon: "fa-table"
icon: "fa-table",
related: [],
source: {
exclude: ["resourceAbstract*", "Org*", "contact*"]
}
}
],
// Optional. If not set, the first resultViewTpls is used.
resultTemplate:
"../../catalog/components/" +
"search/resultsview/partials/viewtemplates/grid.html",
Expand Down Expand Up @@ -727,6 +734,7 @@
class: "fa-file-code-o"
}*/
],
// Deprecated (use configuration on resultViewTpls)
grid: {
related: ["parent", "children", "services", "datasets"]
},
Expand Down Expand Up @@ -1418,6 +1426,19 @@
getProxyUrl: function () {
return this.proxyUrl;
},
getDefaultResultTemplate: function () {
if (this.gnCfg.mods.search.resultTemplate) {
for (var i = 0; i < this.gnCfg.mods.search.resultViewTpls.length; i++) {
if (
this.gnCfg.mods.search.resultViewTpls[i].tplUrl ==
this.gnCfg.mods.search.resultTemplate
) {
return this.gnCfg.mods.search.resultViewTpls[i];
}
}
}
return this.gnCfg.mods.search.resultViewTpls[0];
},
// Removes the proxy path and decodes the layer url,
// so the layer can be printed with MapFish.
// Otherwise Mapfish rejects it, due to relative url.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@
icon: "fa-list"
}
];
gnSearchSettings.resultTemplate = gnSearchSettings.resultViewTpls[0].tplUrl;
gnSearchSettings.resultTemplate = gnSearchSettings.resultViewTpls[0];

// TODO: Improve for other standards
// Object used by directory directive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
}
];

gnSearchSettings.resultTemplate = gnSearchSettings.resultViewTpls[0].tplUrl;
gnSearchSettings.resultTemplate = gnSearchSettings.resultViewTpls[0];

$scope.facetsSummaryType = gnSearchSettings.facetsSummaryType = "manager";
$scope.facetConfig = gnGlobalSettings.gnCfg.mods.editor.facetConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

/* Default result view template */
$scope.resultTemplate =
gnSearchSettings.resultTemplate || gnSearchSettings.resultViewTpls[0].tplUrl;
gnSearchSettings.resultTemplate || gnSearchSettings.resultViewTpls[0];
/* Default advanced search form template */
$scope.advancedSearchTemplate =
gnSearchSettings.advancedSearchTemplate ||
Expand Down
5 changes: 5 additions & 0 deletions web-ui/src/main/resources/catalog/locales/en-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,11 @@
"ui-createPageTpl-horizontal": "Horizontal",
"ui-createPageTpl-vertical": "Vertical",
"ui-createPageTpl-other": "Custom",
"ui-resultViewTpls-icon": "Icon",
"ui-resultViewTpls-tplUrl": "HTML template URL",
"ui-resultViewTpls-tooltip": "Tooltip",
"ui-resultViewTpls-relatedTypes": "(optional) Related types to load",
"ui-resultViewTpls-source": "(optional) Fields to exclude",
"ui-languages": "List of languages",
"ui-filters": "Filters",
"ui-minUserProfileToCreateTemplate": "Which minimum profile is required to manage/create template?",
Expand Down
10 changes: 6 additions & 4 deletions web-ui/src/main/resources/catalog/views/default/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,11 @@
"$scope",
"gnRelatedResources",
function ($scope, gnRelatedResources) {
$scope.resultTemplate =
"../../catalog/components/" +
"search/resultsview/partials/viewtemplates/grid4maps.html";
$scope.resultTemplate = {
tplUrl:
"../../catalog/components/" +
"search/resultsview/partials/viewtemplates/grid4maps.html"
};
$scope.searchObj = {
permalink: false,
internal: true,
Expand Down Expand Up @@ -212,7 +214,7 @@
$scope.activeTab = "/home";
$scope.formatter = gnGlobalSettings.gnCfg.mods.search.formatter;
$scope.listOfResultTemplate = gnGlobalSettings.gnCfg.mods.search.resultViewTpls;
$scope.resultTemplate = gnSearchSettings.resultTemplate;
$scope.resultTemplate = gnGlobalSettings.getDefaultResultTemplate();
$scope.advandedSearchTemplate = gnSearchSettings.advancedSearchTemplate;
$scope.facetsSummaryType = gnSearchSettings.facetsSummaryType;
$scope.facetConfig = gnSearchSettings.facetConfig;
Expand Down

0 comments on commit 5a9880e

Please sign in to comment.