Skip to content

Commit

Permalink
feat(search-setting): Add a button to check/uncheck all sources (#589)
Browse files Browse the repository at this point in the history
* refactor(ilayer) add fileds to result formatter

* feat(search-setting)Add a button to check/uncheck all sources

* Update fr.geo.json

* Update en.geo.json

Co-authored-by: Marc-André Barbeau <[email protected]>
  • Loading branch information
mbarbeau committed May 11, 2020
1 parent b3cb8b3 commit 92bbe07
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<mat-menu
#searchSettingsMenu="matMenu"
class="no-border-radius">
<div class="checkAllButton" *ngIf="getSearchSources().length>4">
<button mat-raised-button
(click)="checkUncheckAllSources($event)">{{!searchSourcesAllEnabled ? ('igo.geo.search.searchSources.unselectAll' | translate): ('igo.geo.search.searchSources.selectAll' | translate)}}</button>
</div>
<ng-container *ngFor="let source of getSearchSources()">
<span class="igo-search-settings-search-source">
<mat-checkbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { MediaService } from '@igo2/core';
export class SearchSettingsComponent implements OnInit {

public hasPointerReverseSearchSource: boolean = false;
public searchSourcesAllEnabled: boolean = false;

public buffer = [];
public lastKeyTime = Date.now();
Expand Down Expand Up @@ -88,7 +89,9 @@ export class SearchSettingsComponent implements OnInit {
.getSources()
.filter(sourceCanReverseSearch)
.filter(s => s.available && s.getId() !== 'map' && s.showInSettings);
return textSearchSources.concat(reverseSearchSources);
const sources = textSearchSources.concat(reverseSearchSources);
this.computeSourcesCheckAllBehavior(sources);
return sources;
}

/**
Expand Down Expand Up @@ -119,12 +122,12 @@ export class SearchSettingsComponent implements OnInit {
}

/**
* Defining the action to do for check/uncheck checkboxes
* Defining the action to do for check/uncheck checkboxes (settings)
* return true if all checkbox must be checked
* return false if all checkbox must be unchecked
* @internal
*/
computeCheckAllBehavior(setting: SearchSourceSettings) {
computeSettingCheckAllBehavior(setting: SearchSourceSettings) {
if (setting.allEnabled === undefined) {
if (setting.values.find(settingValue => settingValue.enabled)) {
setting.allEnabled = false;
Expand All @@ -136,20 +139,44 @@ export class SearchSettingsComponent implements OnInit {
}
}

/**
* Defining the action to do for check/uncheck checkboxes (sources)
* return true if all checkbox must be checked
* return false if all checkbox must be unchecked
* @internal
*/
computeSourcesCheckAllBehavior(sources: SearchSource[]) {
const enabledSourcesCnt = sources.filter(source => source.enabled).length;
const disabledSourcesCnt = sources.filter(source => !source.enabled).length;
this.searchSourcesAllEnabled = enabledSourcesCnt >= disabledSourcesCnt ? false : true;
}

/**
* Triggered when the check all / uncheck all type is clicked,
* @internal
*/
checkUncheckAll(event, source: SearchSource, setting: SearchSourceSettings) {
event.stopPropagation();
this.computeCheckAllBehavior(setting);
this.computeSettingCheckAllBehavior(setting);
setting.values.forEach(settingValue => {
settingValue.enabled = setting.allEnabled;
});
source.setParamFromSetting(setting);
this.searchSourceChange.emit(source);
}

/**
* Triggered when the check all / uncheck all type is clicked,
* @internal
*/
checkUncheckAllSources(event) {
event.stopPropagation();
this.getSearchSources().map(source => {
source.enabled = this.searchSourcesAllEnabled;
this.searchSourceChange.emit(source);
});
}

/**
* Triggered when a setting is checked (radiobutton style)
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/geo/src/lib/search/shared/sources/ilayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ILayerSearchResultFormatter {
constructor(private languageService: LanguageService) {}

formatResult(data: ILayerData): ILayerData {
const allowedKey = ['title', 'abstract', 'groupTitle', 'metadataUrl'];
const allowedKey = ['title', 'abstract', 'groupTitle', 'metadataUrl', 'downloadUrl', 'urlInfo', 'name'];

const property = Object.entries(data.properties)
.filter(([key]) => allowedKey.indexOf(key) !== -1)
Expand Down
7 changes: 6 additions & 1 deletion packages/geo/src/locale/en.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@
"title": "Title",
"type": "Type",
"url": "URL",
"metadataUrl": "Metadata"
"metadataUrl": "Metadata",
"name": "Layer name",
"urlInfo": "URL - WMS/WFS",
"downloadUrl": "Data download"
},
"type": {
"layer": "Layer",
Expand Down Expand Up @@ -298,6 +301,8 @@
"tooltip": "Based on every search source, show the summary of the pointer location. Use F2 to activate/desactivate."
},
"searchSources": {
"selectAll": "Select All",
"unselectAll": "Unselect All",
"settings": {
"results type": "Results type",
"ecmax": "Maximum deviation",
Expand Down
7 changes: 6 additions & 1 deletion packages/geo/src/locale/fr.geo.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@
"title": "Titre",
"type": "Type",
"url": "URL",
"metadataUrl": "Métadonnées"
"metadataUrl": "Métadonnées",
"name": "Nom de la couche",
"urlInfo": "Lien du service web WMS/WFS",
"downloadUrl": "Lien de téléchargement de la données"
},
"type": {
"layer": "Couche",
Expand Down Expand Up @@ -298,6 +301,8 @@
"tooltip": "Afficher les coordonnées du curseur ainsi que d'autres informations sur sa position en fonction des types de résultats activées. Utiliser F2 pour activer / désactiver."
},
"searchSources": {
"selectAll": "Tout sélectionner",
"unselectAll": "Tout désélectionner",
"settings": {
"results type": "Type de résultat",
"ecmax": "Écart maximal",
Expand Down

0 comments on commit 92bbe07

Please sign in to comment.