-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vocabulary item view #347
base: master
Are you sure you want to change the base?
Vocabulary item view #347
Changes from all commits
d77a180
0b5aaaa
4d3365b
f7404c0
009be0a
fb36717
c0377de
dd1420d
ebd3363
9bf7e2a
ff50270
8965685
f405b4b
3601b15
b2a3c93
0fc61ae
43f25da
9de7fd2
a5e1f90
78bec3d
fe43685
edfdf53
22f7835
5657042
2555b8e
842f5c3
6c79b8b
ba10dcb
b0a4bb7
f210d7c
9056ac3
1cbf807
8cf3e43
99f299d
7475321
9d4ccbb
9a2a0d7
c9f79e8
75240e9
8147305
f6ba1dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright (C) 2020-2024 CERN. | ||
# Copyright (C) 2020-2021 CERN. | ||
# Copyright (C) 2024 Uni Münster. | ||
# | ||
# Invenio-Vocabularies is free software; you can redistribute it and/or | ||
# modify it under the terms of the MIT License; see LICENSE file for more | ||
# details. | ||
|
||
"""Vocabularies admin interface.""" | ||
from invenio_administration.views.base import ( | ||
AdminResourceEditView, | ||
AdminResourceListView, | ||
) | ||
from functools import partial | ||
|
||
from flask import current_app | ||
from invenio_administration.views.base import AdminResourceListView | ||
from invenio_search_ui.searchconfig import FacetsConfig, SortConfig, search_app_config | ||
|
||
|
||
class VocabulariesListView(AdminResourceListView): | ||
|
@@ -42,3 +43,95 @@ class VocabulariesListView(AdminResourceListView): | |
search_config_name = "VOCABULARIES_TYPES_SEARCH" | ||
search_facets_config_name = "VOCABULARIES_TYPES_FACETS" | ||
search_sort_config_name = "VOCABULARIES_TYPES_SORT_OPTIONS" | ||
|
||
|
||
class VocabularyDetailsListView(AdminResourceListView): | ||
"""Configuration for vocabularies list view.""" | ||
|
||
def get_api_endpoint(self, pid_value=None): | ||
"""Overwrite get_api_endpoint to accept pid_value.""" | ||
if pid_value in current_app.config.get( | ||
"VOCABULARIES_CUSTOM_VOCABULARY_TYPES", [] | ||
): | ||
return f"/api/{pid_value}" | ||
else: | ||
return f"/api/vocabularies/{pid_value}" | ||
|
||
def init_search_config(self, **kwargs): | ||
"""Build search view config.""" | ||
pid_value = kwargs.get("pid_value", "") | ||
custom_search_config = current_app.config[self.search_config_name].get( | ||
pid_value | ||
) | ||
|
||
if custom_search_config: | ||
available_sort_options = current_app.config[self.search_sort_config_name] | ||
available_facets = current_app.config.get(self.search_facets_config_name) | ||
|
||
return partial( | ||
search_app_config, | ||
config_name=self.get_search_app_name(**kwargs), | ||
available_facets=available_facets, | ||
sort_options=available_sort_options, | ||
endpoint=self.get_api_endpoint(**kwargs), | ||
headers=self.get_search_request_headers(**kwargs), | ||
sort=SortConfig( | ||
available_sort_options, | ||
custom_search_config["sort"], | ||
custom_search_config["sort_default"], | ||
custom_search_config["sort_default_no_query"], | ||
), | ||
facets=FacetsConfig(available_facets, custom_search_config["facets"]), | ||
) | ||
else: | ||
return super().init_search_config(**kwargs) | ||
|
||
def get(self, **kwargs): | ||
"""GET view method.""" | ||
parent_context = super().get_context(**kwargs) | ||
|
||
pid_value = kwargs.get("pid_value", "") | ||
vocab_admin_cfg = current_app.config["VOCABULARIES_ADMINISTRATION_CONFIG"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would like to suggest using class factory pattern here instead of moving it to a static dict config in the configuration variable. I understand the dict is imitating the AdminView class interface but if it is not really a class, then we diverge of the pattern of implementation of the administration module |
||
|
||
custom_config = vocab_admin_cfg.get(pid_value) | ||
|
||
if custom_config: | ||
parent_context.update(custom_config) | ||
else: | ||
parent_context.update( | ||
{"title": f"{pid_value.capitalize()} vocabulary items"} | ||
) | ||
|
||
return self.render(**parent_context) | ||
|
||
name = "vocabulary-type-items" | ||
url = "/vocabulary-types/<pid_value>" | ||
|
||
# INFO name of the resource's list view name, enables navigation between items view and types view. | ||
list_view_name = "vocabulary-types" | ||
|
||
resource_config = "vocabulary_admin_resource" | ||
search_request_headers = {"Accept": "application/json"} | ||
|
||
pid_path = "id" | ||
resource_name = "title['en']" | ||
|
||
# INFO only if disabled() (as a function) it's not in the sidebar, see https://github.com/inveniosoftware/invenio-administration/blob/main/invenio_administration/menu/menu.py#L54 | ||
disabled = lambda _: True | ||
|
||
template = "invenio_administration/search.html" | ||
|
||
display_delete = False | ||
display_create = False | ||
display_edit = True | ||
display_search = True | ||
|
||
# TODO: It would ne nicer to use the title's translation in the currently selected language and fall back to English if this doesn't exist | ||
item_field_list = { | ||
"title['en']": {"text": "Title [en]", "order": 0}, | ||
"created": {"text": "Created", "order": 1}, | ||
} | ||
|
||
search_config_name = "VOCABULARIES_TYPES_ITEMS_SEARCH" | ||
search_facets_config_name = "VOCABULARIES_TYPES_ITEMS_FACETS" | ||
search_sort_config_name = "VOCABULARIES_TYPES_ITEMS_SORT_OPTIONS" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered inheriting from both Details and List views?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet. Could you explain how that might help with our issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would ensure less ambiguity on where the methods are actually coming from, this class now only imitates the interface of AdminResourceDetails view in order to use some of its frontend functionalities, while it does not actually inherit from the class itself. It might create divergence on the implementation of these "virtually" inherited methods the code it will be harder to maintain.
So to answer your question, it does not solve immediate problems but prevents ambiguity in the future