Files
alfresco-ng2-components/lib/content-services/search/components/search-radio/search-radio.component.ts
Suzana Dirla fb11cc879d [ADF-3401] Search filters - fix facet update (#4249)
* [ADF-3401] refactoring - different way to call the facet parsers

* [ADF-3401] fix duplicate search call

* [ADF-3401] add new fields and buckets from the response

- If a facet is already displayed, just update the bucket count, else add the new facet to the responseFields
- this way any existing filters are preserved, the collapsed state is preserved, facet selection is preserved

* [ADF-3401] reset & clear all selections buttons

* [ADF-3401] delete facets that are not in the response

- for better UX, prevent deletion of items from the category where there is a selected item
- clean-up reset buttons

* [ADF-3401] apply filters to the newly created items

* [ADF-3401] update tests

* [ADF-3401] fix after rebase

* [ADF-3401] Code refactoring

* [ADF-3401] show count value inside tooltip

* [ADF-3401] translatable strings

* [ADF-3401] move 'Clear all selections' button to search-chip-list

* [ADF-3401] option to configure having a reset button for filters

* [ADF-3401] code cleanup and improvements after review

* Update lib/content-services/search/components/search-filter/search-filter.component.ts

Co-Authored-By: suzanadirla <dirla.silvia.suzana@gmail.com>

* [ADF-3401] Better namings

* fix failing e2e tests on search radio

* [ADF-3401] add documentation for search resetButton
2019-03-05 14:08:38 +00:00

93 lines
2.8 KiB
TypeScript

/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, ViewEncapsulation, OnInit, Input } from '@angular/core';
import { MatRadioChange } from '@angular/material';
import { SearchWidget } from '../../search-widget.interface';
import { SearchWidgetSettings } from '../../search-widget-settings.interface';
import { SearchQueryBuilderService } from '../../search-query-builder.service';
import { SearchFilterList } from '../search-filter/models/search-filter-list.model';
export interface SearchRadioOption {
name: string;
value: string;
}
@Component({
selector: 'adf-search-radio',
templateUrl: './search-radio.component.html',
styleUrls: ['./search-radio.component.scss'],
encapsulation: ViewEncapsulation.None,
host: { class: 'adf-search-radio' }
})
export class SearchRadioComponent implements SearchWidget, OnInit {
/** The value of the selected radio button. */
@Input()
value: string;
id: string;
settings: SearchWidgetSettings;
context: SearchQueryBuilderService;
options: SearchFilterList<SearchRadioOption>;
pageSize = 5;
constructor() {
this.options = new SearchFilterList<SearchRadioOption>();
}
ngOnInit() {
if (this.settings) {
this.pageSize = this.settings.pageSize || 5;
if (this.settings.options && this.settings.options.length > 0) {
this.options = new SearchFilterList<SearchRadioOption>(
this.settings.options, this.pageSize
);
}
}
const initialValue = this.getSelectedValue();
if (initialValue !== null) {
this.setValue(initialValue);
}
}
private getSelectedValue(): string {
const options: any[] = this.settings['options'] || [];
if (options && options.length > 0) {
let selected = options.find((opt) => opt.default);
if (!selected) {
selected = options[0];
}
return selected.value;
}
return null;
}
private setValue(newValue: string) {
this.value = newValue;
this.context.queryFragments[this.id] = newValue;
this.context.update();
}
changeHandler(event: MatRadioChange) {
this.setValue(event.value);
}
}