2021-02-10 17:09:55 +01:00
|
|
|
export function create_item_from_search_string(search_string) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const operator = Filter.parse(search_string);
|
|
|
|
const description = Filter.describe(operator);
|
2018-06-21 15:11:21 +02:00
|
|
|
return {
|
2018-07-14 16:10:00 +02:00
|
|
|
display_value: search_string,
|
2020-07-20 22:18:43 +02:00
|
|
|
description,
|
2018-06-21 15:11:21 +02:00
|
|
|
};
|
2021-02-10 17:09:55 +01:00
|
|
|
}
|
2018-06-21 15:11:21 +02:00
|
|
|
|
2021-02-10 17:09:55 +01:00
|
|
|
export function get_search_string_from_item(item) {
|
2018-07-14 16:10:00 +02:00
|
|
|
return item.display_value;
|
2021-02-10 17:09:55 +01:00
|
|
|
}
|
2018-06-21 15:11:21 +02:00
|
|
|
|
2021-02-10 17:09:55 +01:00
|
|
|
export function create_pills(pill_container) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const pills = input_pill.create({
|
2018-06-21 15:11:21 +02:00
|
|
|
container: pill_container,
|
2021-02-10 17:09:55 +01:00
|
|
|
create_item_from_text: create_item_from_search_string,
|
|
|
|
get_text_from_item: get_search_string_from_item,
|
2018-06-21 15:11:21 +02:00
|
|
|
});
|
|
|
|
return pills;
|
2021-02-10 17:09:55 +01:00
|
|
|
}
|
2018-06-21 15:11:21 +02:00
|
|
|
|
2021-02-10 17:09:55 +01:00
|
|
|
export function append_search_string(search_string, pill_widget) {
|
2020-06-19 18:09:37 +02:00
|
|
|
const operators = Filter.parse(search_string);
|
|
|
|
for (const operator of operators) {
|
|
|
|
const input = Filter.unparse([operator]);
|
|
|
|
pill_widget.appendValue(input);
|
|
|
|
}
|
2018-06-21 15:11:21 +02:00
|
|
|
if (pill_widget.clear_text !== undefined) {
|
|
|
|
pill_widget.clear_text();
|
|
|
|
}
|
2021-02-10 17:09:55 +01:00
|
|
|
}
|
2018-06-21 15:11:21 +02:00
|
|
|
|
2021-02-10 17:09:55 +01:00
|
|
|
export function get_search_string_for_current_filter(pill_widget) {
|
2019-11-02 00:06:25 +01:00
|
|
|
const items = pill_widget.items();
|
2020-07-02 01:39:34 +02:00
|
|
|
const search_strings = items.map((item) => item.display_value);
|
2020-07-15 01:29:15 +02:00
|
|
|
return search_strings.join(" ");
|
2021-02-10 17:09:55 +01:00
|
|
|
}
|