From e02d8b5d43ddcb72197e5e55ed15e3ab27abb13d Mon Sep 17 00:00:00 2001 From: panda Date: Sun, 27 Aug 2023 01:47:07 +0800 Subject: [PATCH] ui: support pinnedFilter metadata (#650) --- packages/ui-default/pages/problem_main.page.ts | 13 +++++++++++-- .../templates/partials/problem_search.html | 10 ++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/ui-default/pages/problem_main.page.ts b/packages/ui-default/pages/problem_main.page.ts index b97a56f7..123f1b93 100644 --- a/packages/ui-default/pages/problem_main.page.ts +++ b/packages/ui-default/pages/problem_main.page.ts @@ -13,6 +13,7 @@ import { } from 'vj/utils'; const list = []; +const filterTags = {}; const pinned: Record = { category: [], difficulty: [] }; const selections = { category: {}, difficulty: {} }; const selectedTags: Record = { category: [], difficulty: [] }; @@ -90,10 +91,13 @@ function handleTagSelected(ev) { let [type, selection] = ['category', $(ev.currentTarget).text()]; if ($(ev.currentTarget).attr('data-selection')) [type, selection] = $(ev.currentTarget).attr('data-selection').split(':'); const category = $(ev.currentTarget).attr('data-category'); + const filterType = $(ev.currentTarget).attr('data-filter'); const treeItem = category ? selections[type][category].children[selection] : selections[type][selection]; const shouldSelect = !(treeItem.$tag || treeItem.$legacy).hasClass('selected'); - if (shouldSelect) selectedTags[type].push(selection); - else selectedTags[type] = _.without(selectedTags[type], selection, ...(category ? [] : Object.keys(treeItem.children))); + if (shouldSelect) { + if (filterType) selectedTags[type] = _.without(selectedTags[type], ...filterTags[filterType]); + selectedTags[type].push(selection); + } else selectedTags[type] = _.without(selectedTags[type], selection, ...(category ? [] : Object.keys(treeItem.children))); updateSelection(); writeSelectionToInput(); loadQuery(); @@ -248,7 +252,12 @@ categoryDialog.clear = function () { function buildSearchContainer() { $('[data-pinned-container] [data-selection]').each((_index, _element) => { const [type, selection] = $(_element).attr('data-selection').split(':'); + const filterType = $(_element).attr('data-filter'); pinned[type].push(selection); + if (filterType) { + filterTags[filterType] ||= []; + filterTags[filterType].push(selection); + } selections[type][selection] = { $tag: $(_element), children: {}, diff --git a/packages/ui-default/templates/partials/problem_search.html b/packages/ui-default/templates/partials/problem_search.html index 26888f93..f9dd588f 100644 --- a/packages/ui-default/templates/partials/problem_search.html +++ b/packages/ui-default/templates/partials/problem_search.html @@ -1,16 +1,18 @@ -
{% set pinnedFilter = handler.domain.pinnedFilter|parseYaml %} {% set categories = (handler.domain.problemCategories or model.system.get('problem.categories'))|parseYaml %} -{% for k, v in pinnedFilter %} +
+ {% for k, v in pinnedFilter %}
{{ k }}:   
{%- for name, t in v -%} - {{ name }} + {% if name !== '__metadata__' %} + {{ name }} + {% endif %} {%- endfor -%}
-{% endfor %} + {% endfor %}
{{ _('Problem Category') }}: