Skip to content

Commit

Permalink
Merge pull request #8 from oarepo/stojanovic/be-229-global-search-cha…
Browse files Browse the repository at this point in the history
…nge-api-url-to-apisearch-and-add-dependency

Stojanovic/be 229 global search change api url to apisearch and add dependency
  • Loading branch information
mirekys authored Jun 3, 2024
2 parents c26e6b6 + d77170f commit 840df49
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 106 deletions.
4 changes: 4 additions & 0 deletions babel.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

# Extraction from Python source files

[extractors]
jinja2 = jinja2.ext:babel_extract

[python: **.py]
encoding = utf-8

Expand All @@ -18,6 +21,7 @@ encoding = utf-8

[jinja2: **/templates/**.jinja]
encoding = utf-8
extensions = jinjax.jinjax.JinjaX

# Special case for jinjax translation strings
[jinja2: **/jinjax_messages.jinja]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"By Title":"Podle názvu","Best match":"Nejlepší shoda","Newest":"Nejnovější","Oldest":"Nejstarší","Records":"Nahráno","Communities":"Komunity","Requests":"Žádosti","profile":"profil","Search in my communities...":"Hledat v mých komunitách...","Restricted":"Omezený","Filter results":"Filtrovat výsledky","Edit":"Upravit","Uploaded on {{uploadDate}}":"Nahráno dne {{uploadDate}}","No creation date found.":"Nebylo nalezeno žádné datum vytvoření","No description":"Bez popisu","No title":"Bez názvu","Create new...":"Vytvořit nový...","Search in my uploads...":"Hledat v mých záznamech...","Expires at: {{- expiringDate}}":"Vyprší v: {{- expiringDate}}","Opened {{relativeTime}} by":"Otevřeno {{relativeTime}} uživatelem","Open":"Otevřeno","Closed":"Zavřeno","New request":"Nová žádost","My":"Moje","Others":"Ostatní","Search in my requests...":"Hledat v mých žádostech...","Opened by":"Otevřeno {{relativeTime}} uživatelem","Dashboard":"Přehled","Create new draft":"Vytvořit nový koncept","Edit record":"Úprava záznamu","Delete record":"Smazání záznamu","Publish record":"Vypublikování záznamů","Opened by {{creatorName}} on {{created}}.":"Otevřeno uživatelem {{creatorName}} na {{created}}.","Recepient: {{receiver}}.":"Příjemce: {{receiver}}"}
{"By Title":"Podle názvu","Best match":"Nejlepší shoda","Newest":"Nejnovější","Oldest":"Nejstarší","Records":"Nahráno","Communities":"Komunity","Requests":"Žádosti","profile":"profil","Search in my communities...":"Hledat v mých komunitách...","Restricted":"Omezený","Filter results":"Filtrovat výsledky","Edit":"Upravit","Uploaded on {{uploadDate}}":"Nahráno dne {{uploadDate}}","No creation date found.":"Nebylo nalezeno žádné datum vytvoření","No description":"Bez popisu","No title":"Bez názvu","Create new...":"Vytvořit nový...","Search in my uploads...":"Hledat v mých záznamech...","Expires at: {{- expiringDate}}":"Vyprší v: {{- expiringDate}}","Opened {{relativeTime}} by":"Otevřeno {{relativeTime}} uživatelem","Open":"Otevřeno","Closed":"Zavřeno","New request":"Nová žádost","My":"Moje","Others":"Ostatní","Search in my requests...":"Hledat v mých žádostech...","Opened by":"Otevřeno {{relativeTime}} uživatelem","Create new draft":"Vytvořit nový koncept","Edit record":"Úprava záznamu","Delete record":"Smazání záznamu","Publish record":"Vypublikování záznamů","Opened by {{creatorName}} on {{created}}.":"Otevřeno uživatelem {{creatorName}} na {{created}}.","Recepient: {{receiver}}.":"Příjemce: {{receiver}}","User Dashboard":"Nástěnka"}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{"User Dashboard":"Dashboard"}
Binary file modified oarepo_dashboard/i18n/translations/cs/LC_MESSAGES/messages.mo
Binary file not shown.
12 changes: 8 additions & 4 deletions oarepo_dashboard/i18n/translations/cs/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,6 @@ msgstr "Hledat v mých žádostech..."
msgid "Opened by"
msgstr "Otevřeno {{relativeTime}} uživatelem"

#: /home/dusanst/Projects/oarepo-dashboard/oarepo_dashboard/ui/__init__.py:185
msgid "Dashboard"
msgstr "Přehled"

msgid "Create new draft"
msgstr "Vytvořit nový koncept"

Expand All @@ -129,3 +125,11 @@ msgstr "Otevřeno uživatelem {{creatorName}} na {{created}}."

msgid "Recepient: {{receiver}}."
msgstr "Příjemce: {{receiver}}"

#: /home/dusanst/Projects/oarepo-dashboard/oarepo_dashboard/ui/dashboard_records/__init__.py:58
msgid "Dashboard"
msgstr ""

#: /home/dusanst/Projects/oarepo-dashboard/oarepo_dashboard/ui/dashboard_records/__init__.py:58
msgid "User Dashboard"
msgstr "Nástěnka"
Binary file modified oarepo_dashboard/i18n/translations/en/LC_MESSAGES/messages.mo
Binary file not shown.
4 changes: 4 additions & 0 deletions oarepo_dashboard/i18n/translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,7 @@ msgstr ""

msgid "Recepient: {{receiver}}."
msgstr ""

#: /home/dusanst/Projects/oarepo-dashboard/oarepo_dashboard/ui/dashboard_records/__init__.py:58
msgid "User Dashboard"
msgstr "Dashboard"
Binary file modified oarepo_dashboard/i18n/translations/messages.mo
Binary file not shown.
35 changes: 13 additions & 22 deletions oarepo_dashboard/i18n/translations/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-03-28 15:12+0100\n"
"POT-Creation-Date: 2024-06-01 21:05+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.14.0\n"
"Generated-By: Babel 2.10.3\n"

#: /home/dusanst/Projects/oarepo-dashboard/oarepo_dashboard/ui/dashboard_communities/__init__.py:46
#: /home/dusanst/Projects/oarepo-dashboard/oarepo_dashboard/ui/dashboard_communities/__init__.py:42
msgid "Communities"
msgstr ""

#: /home/dusanst/Projects/oarepo-dashboard/oarepo_dashboard/ui/dashboard_records/__init__.py:46
#: /home/dusanst/Projects/oarepo-dashboard/oarepo_dashboard/ui/dashboard_records/__init__.py:49
msgid "Records"
msgstr ""

#: /home/dusanst/Projects/oarepo-dashboard/oarepo_dashboard/ui/dashboard_records/__init__.py:54
msgid "Dashboard"
#: /home/dusanst/Projects/oarepo-dashboard/oarepo_dashboard/ui/dashboard_records/__init__.py:58
msgid "User Dashboard"
msgstr ""

#: /home/dusanst/Projects/oarepo-dashboard/oarepo_dashboard/ui/dashboard_requests/__init__.py:53
#: /home/dusanst/Projects/oarepo-dashboard/oarepo_dashboard/ui/dashboard_requests/__init__.py:47
msgid "Requests"
msgstr ""

Expand All @@ -42,27 +42,12 @@ msgstr ""
msgid "Restricted"
msgstr ""

msgid "My"
msgstr ""

msgid "Others"
msgstr ""

msgid "Open"
msgstr ""

msgid "Closed"
msgstr ""

msgid "Filter results"
msgstr ""

msgid "Create new draft"
msgstr ""

msgid "Create new..."
msgstr ""

msgid "Search in my uploads..."
msgstr ""

Expand All @@ -78,6 +63,12 @@ msgstr ""
msgid "Expires at: {{- expiringDate}}"
msgstr ""

msgid "My"
msgstr ""

msgid "Others"
msgstr ""

msgid "Search in my requests..."
msgstr ""

Expand Down
6 changes: 1 addition & 5 deletions oarepo_dashboard/ui/dashboard_communities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ class DashboardCommunitiesUIResourceConfig(RecordsUIResourceConfig):
application_id = "communities_dashboard"
templates = {
"search": "DashboardCommunitiesPage",
}
}

routes = {
"create": "/dummy-route",
"edit": "/dummy-route",
"search": "/",
"detail": "/dummy-route",
"export": "/dummy-route",
}
api_service = "communities"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
{%- block javascript %}
{{super()}}
{{webpack["dashboard_communities.js"]}}
{{webpack["components.js"]}}
{{webpack["components.css"]}}
{%- endblock javascript %}

{%- block page_body %}
Expand Down
8 changes: 8 additions & 0 deletions oarepo_dashboard/ui/dashboard_components/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
from oarepo_ui.resources.components import UIResourceComponent
from flask import current_app


class DashboardRecordsSearchComponent(UIResourceComponent):
def before_ui_search(self, *, search_options, view_args, extra_context, **kwargs):
search_options["overrides"]["dashboardRecordsCreateUrl"] = (
current_app.config.get("DASHBOARD_RECORD_CREATE_URL", "")
)


class DashboardRequestsSearchComponent(UIResourceComponent):
Expand Down
32 changes: 17 additions & 15 deletions oarepo_dashboard/ui/dashboard_records/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
from oarepo_ui.resources.config import (
RecordsUIResourceConfig,
)
from oarepo_ui.resources.resource import RecordsUIResource
from flask_menu import current_menu
from flask_login import current_user
from oarepo_runtime.i18n import lazy_gettext as _
from oarepo_global_search.ui.config import (
GlobalSearchUIResourceConfig,
GlobalSearchUIResource,
)
from oarepo_ui.resources import PermissionsComponent
from oarepo_dashboard.ui.dashboard_components.search import (
DashboardRecordsSearchComponent,
)


class DashboardRecordsUIResourceConfig(RecordsUIResourceConfig):
class DashboardRecordsUIResourceConfig(GlobalSearchUIResourceConfig):
url_prefix = "/me/records/"
blueprint_name = "records_dashboard"
template_folder = "templates"
Expand All @@ -17,19 +21,17 @@ class DashboardRecordsUIResourceConfig(RecordsUIResourceConfig):
}

routes = {
"create": "/dummy-route",
"edit": "/dummy-route",
"search": "/",
"detail": "/dummy-route",
"export": "/dummy-route",
}
api_service = "documents"
api_service = "records"

components = [DashboardRecordsSearchComponent, PermissionsComponent]

def search_endpoint_url(self, identity, api_config, overrides={}, **kwargs):
return f"/api/user{api_config.url_prefix}"
return "/api/user/search"


class DashboardRecordsUIResource(RecordsUIResource):
class DashboardRecordsUIResource(GlobalSearchUIResource):
pass


Expand All @@ -46,16 +48,16 @@ def init_menu():
"records_dashboard.search",
text=_("Records"),
order=1,
visible_when=lambda: current_user and current_user.is_authenticated
visible_when=lambda: current_user and current_user.is_authenticated,
)

# if you add dashboard to your project, the library adds itself to the main menu
main_menu_dashboard = current_menu.submenu("main.dashboard")
main_menu_dashboard.register(
"records_dashboard.search",
_("Dashboard"),
_("User Dashboard"),
order=1,
visible_when=lambda: current_user and current_user.is_authenticated
visible_when=lambda: current_user and current_user.is_authenticated,
)

return app_blueprint
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,15 @@ import {
SearchappSearchbarElement,
DynamicResultsListItem,
} from "@js/oarepo_ui";
import PropTypes from "prop-types";

const [{ overridableIdPrefix }] = parseSearchAppConfigs();

// TODO: currently, we don't support multiple models, so create new
// can be just a regular button, not a dropdown with options
// to be revisited
// const schemesList = [
// {
// key: "docs",
// text: <a href="/docs/_new">New doc</a>,
// value: "docs",
// // major hack for first item in dropdown being automatically highlighted :0
// selected: false,
// active: false,
// },
// {
// key: "communities",
// text: <a href="/communities/new">New comm</a>,
// value: "communities",
// },
// ];
const [
{
overridableIdPrefix,
dashboardRecordsCreateUrl,
permissions: { can_create },
},
] = parseSearchAppConfigs();

const UserDashboardSearchAppResultViewWAppName = parametrize(
UserDashboardSearchAppResultView,
Expand All @@ -41,31 +29,37 @@ const UserDashboardSearchAppResultViewWAppName = parametrize(
}
);

const ExtraContent = () => (
<Grid.Column textAlign="right">
<Button
as="a"
href="/docs/_new"
type="button"
labelPosition="left"
icon="plus"
content={i18next.t("Create new draft")}
primary
/>
{/* <Dropdown
button
className="icon primary tiny"
placeholder="Choose an option"
labeled
icon="plus"
options={[]}
text={i18next.t("Create new...")}
/> */}
</Grid.Column>
);
const CreateNewDraftButton = ({ dashboardRecordsCreateUrl }) => {
!dashboardRecordsCreateUrl &&
console.error(
"DASHBOARD_RECORD_CREATE_URL was not provided in invenio.cfg"
);
return (
can_create && (
<Grid.Column textAlign="right">
<Button
as="a"
href={dashboardRecordsCreateUrl}
type="button"
labelPosition="left"
icon="plus"
content={i18next.t("Create new draft")}
primary
/>
</Grid.Column>
)
);
};

CreateNewDraftButton.propTypes = {
dashboardRecordsCreateUrl: PropTypes.string,
};

export const DashboardUploadsSearchLayout = UserDashboardSearchAppLayoutHOC({
placeholder: i18next.t("Search in my uploads..."),
extraContent: ExtraContent,
extraContent: parametrize(CreateNewDraftButton, {
dashboardRecordsCreateUrl: dashboardRecordsCreateUrl,
}),
appName: overridableIdPrefix,
});
export const componentOverrides = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
{%- block javascript %}
{{super()}}
{{webpack["dashboard_records.js"]}}
{{webpack["components.js"]}}
{{webpack["components.css"]}}
{%- endblock javascript %}

{%- block page_body %}
Expand Down
10 changes: 2 additions & 8 deletions oarepo_dashboard/ui/dashboard_requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,14 @@ class DashboardRequestsUIResourceConfig(RecordsUIResourceConfig):
}

routes = {
"create": "/dummy-route",
"edit": "/dummy-route",
"search": "/",
"detail": "/dummy-route",
"export": "/dummy-route",
}
api_service = "requests"

components = [
DashboardRequestsSearchComponent,
]
components = [DashboardRequestsSearchComponent]

def search_endpoint_url(self, identity, api_config, overrides={}, **kwargs):
return "/api/requests/"
return "/api/user/requests"


class DashboardRequestsUIResource(RecordsUIResource):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function RequestsResultsItemTemplateDashboard({ result }) {
ComputerTabletRequestsListItem
);
const MobileRequestsItemWithState = withState(MobileRequestsListItem);
// TODO: remove docs dependency
const detailPageUrl = `/docs/${result?.topic?.reference?.documents}`;
return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
{%- block javascript %}
{{super()}}
{{webpack["dashboard_requests.js"]}}
{{webpack["components.js"]}}
{{webpack["components.css"]}}
{%- endblock javascript %}

{%- block page_body %}
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-dashboard
version = 1.0.5
version = 1.0.6
description = Support for user dashboard (records, communities, requests)
authors = Mirek Simek <[email protected]>
readme = README.md
Expand Down

0 comments on commit 840df49

Please sign in to comment.