From b2ea485e439a2a287b4a389b223863817631dd4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C4=8Corov=C4=8D=C3=A1k?= Date: Wed, 29 May 2024 11:00:22 +0200 Subject: [PATCH 01/73] Request detail init --- .gitignore | 6 +++-- oarepo_requests/resolvers/ui.py | 21 +++++++++--------- .../ui/{__init__.py => __init__ .py} | 0 .../oarepo_requests_ui/RequestDetail.jinja | 15 +++++++++++++ .../request-detail/index.js | 11 ++++++++++ oarepo_requests/ui/theme/webpack.py | 1 + oarepo_requests/ui/views.py | 22 +++++++++++++++++-- setup.cfg | 2 +- 8 files changed, 62 insertions(+), 16 deletions(-) rename oarepo_requests/ui/{__init__.py => __init__ .py} (100%) create mode 100644 oarepo_requests/ui/templates/semantic-ui/oarepo_requests_ui/RequestDetail.jinja create mode 100644 oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/index.js diff --git a/.gitignore b/.gitignore index a5f3201c..398fc710 100644 --- a/.gitignore +++ b/.gitignore @@ -90,5 +90,7 @@ dist/ tests/thesis thesis -**/ui/theme/**/todo.md -node_modules \ No newline at end of file +todo.md +node_modules + +dummy-record.js \ No newline at end of file diff --git a/oarepo_requests/resolvers/ui.py b/oarepo_requests/resolvers/ui.py index 73c5a95a..4c3c3426 100644 --- a/oarepo_requests/resolvers/ui.py +++ b/oarepo_requests/resolvers/ui.py @@ -76,10 +76,10 @@ def _get_id(self, result): def _search_many(self, identity, values, *args, **kwargs): result = [] - for user in values: + for group in values: try: - user = current_groups_service.read(identity, user) - result.append(user) + group = current_groups_service.read(identity, group) + result.append(group) except PermissionDeniedError: pass return result @@ -87,23 +87,22 @@ def _search_many(self, identity, values, *args, **kwargs): def _search_one(self, identity, reference, *args, **kwargs): value = list(reference.values())[0] try: - user = current_groups_service.read(identity, value) - return user + group = current_groups_service.read(identity, value) + return group except PermissionDeniedError: return None def _resolve(self, record, reference): - # todo; this is copyied from user - if record.data["username"] is None: # username undefined? - if "email" in record.data: - label = record.data["email"] + if record.data["name"] is None: + if "id" in record.data: + label = record.data["id"] else: label = fallback_label_result(reference) else: - label = record.data["username"] + label = record.data["name"] ret = { "reference": reference, - "type": "user", + "type": "group", "label": label, } if "links" in record.data and "self" in record.data["links"]: diff --git a/oarepo_requests/ui/__init__.py b/oarepo_requests/ui/__init__ .py similarity index 100% rename from oarepo_requests/ui/__init__.py rename to oarepo_requests/ui/__init__ .py diff --git a/oarepo_requests/ui/templates/semantic-ui/oarepo_requests_ui/RequestDetail.jinja b/oarepo_requests/ui/templates/semantic-ui/oarepo_requests_ui/RequestDetail.jinja new file mode 100644 index 00000000..07a0a960 --- /dev/null +++ b/oarepo_requests/ui/templates/semantic-ui/oarepo_requests_ui/RequestDetail.jinja @@ -0,0 +1,15 @@ +{#def record #} + +{%- extends config.BASE_TEMPLATE %} + +{%- block javascript %} + {{super()}} + {{webpack["oarepo_requests_ui_request_detail.js"]}} + {{webpack["oarepo_requests_ui_components.js"]}} + {{webpack["oarepo_requests_ui_components.css"]}} +{%- endblock javascript %} + +{%- block page_body %} +
{{ record | pprint }}
+
+{%- endblock page_body %} diff --git a/oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/index.js b/oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/index.js new file mode 100644 index 00000000..f0ab6728 --- /dev/null +++ b/oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/index.js @@ -0,0 +1,11 @@ +import React from "react"; +import ReactDOM from "react-dom"; + +const recordRequestsAppDiv = document.getElementById("request-detail"); + +let request = JSON.parse(recordRequestsAppDiv.dataset?.request); + +ReactDOM.render( +
Hello World!
, + recordRequestsAppDiv +); \ No newline at end of file diff --git a/oarepo_requests/ui/theme/webpack.py b/oarepo_requests/ui/theme/webpack.py index 7dbcd021..530ef1d9 100644 --- a/oarepo_requests/ui/theme/webpack.py +++ b/oarepo_requests/ui/theme/webpack.py @@ -8,6 +8,7 @@ "semantic-ui": dict( entry={ "oarepo_requests_ui_record_requests": "./js/oarepo_requests_ui/record-requests/index.js", + "oarepo_requests_ui_request_detail": "./js/oarepo_requests_ui/request-detail/index.js", "oarepo_requests_ui_components": "./js/oarepo_requests_ui/custom-components.js", }, dependencies={}, diff --git a/oarepo_requests/ui/views.py b/oarepo_requests/ui/views.py index 9c2a462b..082e851e 100644 --- a/oarepo_requests/ui/views.py +++ b/oarepo_requests/ui/views.py @@ -1,3 +1,21 @@ -from flask import Blueprint +from oarepo_ui.resources.config import RecordsUIResourceConfig +from oarepo_ui.resources.resource import RecordsUIResource -blueprint = Blueprint("oarepo_requests_ui", __name__, template_folder="templates") +class RequestUIResourceConfig(RecordsUIResourceConfig): + url_prefix = "/requests" + blueprint_name = "oarepo_requests_ui" + template_folder = "templates" + templates = { + "detail": "RequestDetail", + } + api_service = "requests" + ui_serializer_class = "oarepo_requests.resources.ui.OARepoRequestsUIJSONSerializer" + + +class RequestUIResource(RecordsUIResource): + pass + + +def create_blueprint(app): + """Register blueprint for this resource.""" + return RequestUIResource(RequestUIResourceConfig()).as_blueprint() diff --git a/setup.cfg b/setup.cfg index bff81c10..ba9391b2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,7 +42,7 @@ invenio_base.api_blueprints = invenio_base.blueprints = oarepo_requests = oarepo_requests.views.app:create_app_blueprint oarepo_requests_events = oarepo_requests.views.app:create_app_events_blueprint - oarepo_requests_ui = oarepo_requests.ui.views:blueprint + oarepo_requests_ui = oarepo_requests.ui.views:create_blueprint invenio_assets.webpack = oarepo_requests_ui_theme = oarepo_requests.ui.theme.webpack:theme invenio_i18n.translations = From 1fd93174b7b961c271a551b94e656104086d47b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20=C4=8Corov=C4=8D=C3=A1k?= Date: Wed, 29 May 2024 13:37:23 +0200 Subject: [PATCH 02/73] Initial UI --- .../oarepo_requests_ui/RequestDetail.jinja | 14 ++- .../record-requests/components/index.js | 3 +- .../components/RequestDetail.jsx | 104 +++++++++++++++++ .../components/SideRequestInfo.jsx | 46 ++++++++ .../request-detail/components/index.js | 2 + .../request-detail/index.js | 8 +- .../request-detail/types.d.ts | 107 ++++++++++++++++++ 7 files changed, 274 insertions(+), 10 deletions(-) create mode 100644 oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/components/RequestDetail.jsx create mode 100644 oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/components/SideRequestInfo.jsx create mode 100644 oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/components/index.js create mode 100644 oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/types.d.ts diff --git a/oarepo_requests/ui/templates/semantic-ui/oarepo_requests_ui/RequestDetail.jinja b/oarepo_requests/ui/templates/semantic-ui/oarepo_requests_ui/RequestDetail.jinja index 07a0a960..7ebbec5b 100644 --- a/oarepo_requests/ui/templates/semantic-ui/oarepo_requests_ui/RequestDetail.jinja +++ b/oarepo_requests/ui/templates/semantic-ui/oarepo_requests_ui/RequestDetail.jinja @@ -1,6 +1,13 @@ {#def record #} -{%- extends config.BASE_TEMPLATE %} +{%- set title = _("Request") ~ " | " ~ _("NR Document repository") %} + +{% extends "oarepo_ui/detail.html" %} + +{%- block page_body %} +
+
{{ record | pprint }}
+{%- endblock page_body %} {%- block javascript %} {{super()}} @@ -8,8 +15,3 @@ {{webpack["oarepo_requests_ui_components.js"]}} {{webpack["oarepo_requests_ui_components.css"]}} {%- endblock javascript %} - -{%- block page_body %} -
{{ record | pprint }}
-
-{%- endblock page_body %} diff --git a/oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/record-requests/components/index.js b/oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/record-requests/components/index.js index 9272a0c3..1387b4f8 100644 --- a/oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/record-requests/components/index.js +++ b/oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/record-requests/components/index.js @@ -5,4 +5,5 @@ export { RecordRequests } from "./RecordRequests"; export { RequestModalContent } from "./RequestModalContent"; export { CreateRequestModalContent } from "./CreateRequestModalContent"; export { RequestList } from "./RequestList"; -export { ModalContentSideInfo } from "./ModalContentSideInfo"; \ No newline at end of file +export { ModalContentSideInfo } from "./ModalContentSideInfo"; +export * from "./common"; \ No newline at end of file diff --git a/oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/components/RequestDetail.jsx b/oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/components/RequestDetail.jsx new file mode 100644 index 00000000..08c517d3 --- /dev/null +++ b/oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/components/RequestDetail.jsx @@ -0,0 +1,104 @@ +import React from "react"; +import PropTypes from "prop-types"; + +import { i18next } from "@translations/oarepo_requests_ui/i18next"; +import { Button, Grid, List, Form, Divider, Comment, Header, Container, Icon } from "semantic-ui-react"; +import _isEmpty from "lodash/isEmpty"; +import _sortBy from "lodash/sortBy"; + +import { ReadOnlyCustomFields } from "@js/oarepo_requests/components"; +import { SideRequestInfo } from "."; + +export const RequestDetail = ({ request }) => { + const requestModalHeader = !_isEmpty(request?.title) ? request.title : (!_isEmpty(request?.name) ? request.name : request.type); + const renderReadOnlyData = !_isEmpty(request?.payload); + + return ( + + + +
{requestModalHeader}
+ {request?.description && + + {request.description} + + } +
+ + + {submitButton ?? React.cloneElement(triggerButton, { type: "submit", form: "submit-request-form" })} + + + )} + + + ); +}; + +ConfirmModal.propTypes = { + request: PropTypes.object.isRequired, + requestModalHeader: PropTypes.string, + handleSubmit: PropTypes.func, + triggerButton: PropTypes.element, + submitButton: PropTypes.element, +}; \ No newline at end of file diff --git a/oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/components/RequestDetail.jsx b/oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/components/RequestDetail.jsx index 08c517d3..a56f7521 100644 --- a/oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/components/RequestDetail.jsx +++ b/oarepo_requests/ui/theme/assets/semantic-ui/js/oarepo_requests_ui/request-detail/components/RequestDetail.jsx @@ -7,7 +7,7 @@ import _isEmpty from "lodash/isEmpty"; import _sortBy from "lodash/sortBy"; import { ReadOnlyCustomFields } from "@js/oarepo_requests/components"; -import { SideRequestInfo } from "."; +import { SideRequestInfo, ActionButtons } from "."; export const RequestDetail = ({ request }) => { const requestModalHeader = !_isEmpty(request?.title) ? request.title : (!_isEmpty(request?.name) ? request.name : request.type); @@ -25,9 +25,7 @@ export const RequestDetail = ({ request }) => { } -