Skip to content
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

feat: create browse communities page #2861

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{# -*- coding: utf-8 -*-
alejandromumo marked this conversation as resolved.
Show resolved Hide resolved

This file is part of Invenio.
Copyright (C) 2024 CERN.

Invenio is free software; you can redistribute it and/or modify it
under the terms of the MIT License; see LICENSE file for more details.
#}

{% extends "invenio_communities/details/base.html" %}

{% set active_community_header_menu_item= 'browse' %}
{% set subcommunities_endpoint = community["links"]["subcommunities"] %}
{% set community_slug = community["slug"] %}

{%- block javascript %}
{{ super() }}
{{ webpack['invenio-communities-browse.js'] }}
{%- endblock %}

{%- block page_body %}
{{ super() }}
<div id='invenio-browse-config' data-api-endpoint='{{ subcommunities_endpoint }}'
class="ui container communities-frontpage rel-mt-3 rel-mb-2">
<div class="flex">
<h2 class="ui header mb-0 align-self-center">{{ _('Subcommunities') }}</h2>
<a class="align-self-center rel-ml-1" href="{{url_for('invenio_communities.communities_subcommunities', pid_value=community_slug)}}">
{{ _('See all')}}
</a>
</div>
<div class="ui divider hidden"></div>
<div id="subcommunities-container"></div>
</div>
{%- endblock page_body %}
18 changes: 18 additions & 0 deletions invenio_app_rdm/communities_ui/views/communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from flask import abort, g, redirect, request, url_for
from invenio_communities.views.communities import (
HEADER_PERMISSIONS,
MEMBERS_PERMISSIONS,
_get_roles_can_invite,
_get_roles_can_update,
render_community_theme_template,
)
from invenio_communities.views.decorators import pass_community
Expand Down Expand Up @@ -106,6 +109,21 @@ def communities_home(pid_value, community, community_ui):
)


@pass_community(serialize=True)
def communities_browse(pid_value, community, community_ui):
"""Community browse page."""
permissions = community.has_permissions_to(HEADER_PERMISSIONS)

return render_community_theme_template(
"invenio_communities/details/browse/index.html",
theme=community_ui.get("theme", {}),
community=community_ui,
permissions=permissions,
roles_can_update=_get_roles_can_update(community.id),
roles_can_invite=_get_roles_can_invite(community.id),
)


@pass_community(serialize=True)
def community_static_page(pid_value, community, community_ui, **kwargs):
"""Community static page."""
Expand Down
22 changes: 20 additions & 2 deletions invenio_app_rdm/communities_ui/views/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# under the terms of the MIT License; see LICENSE file for more details.
"""Communities UI blueprints module."""

from flask import Blueprint, current_app, render_template
from flask import Blueprint, current_app, render_template, request
from flask_login import current_user
from invenio_communities.communities.resources.serializer import (
UICommunityJSONSerializer,
Expand All @@ -20,7 +20,12 @@
from invenio_records_resources.services.errors import PermissionDeniedError

from ..searchapp import search_app_context
from .communities import communities_detail, communities_home, community_static_page
from .communities import (
communities_browse,
communities_detail,
communities_home,
community_static_page,
)


#
Expand Down Expand Up @@ -63,6 +68,14 @@ def record_permission_denied_error(error):
return render_template(current_app.config["THEME_403_TEMPLATE"]), 403


def _show_browse_page():
"""Whether the browse page should be visible in the menu."""
return (
current_app.config.get("COMMUNITIES_SHOW_BROWSE_MENU_ENTRY", False)
and request.community["children"]["allow"]
)


def create_ui_blueprint(app):
"""Register blueprint routes on app."""
routes = app.config["RDM_COMMUNITIES_ROUTES"]
Expand All @@ -85,6 +98,11 @@ def create_ui_blueprint(app):
view_func=communities_home,
)

blueprint.add_url_rule(
routes["community-browse"],
view_func=communities_browse,
)

blueprint.add_url_rule(
routes["community-static-page"],
view_func=community_static_page,
Expand Down
4 changes: 4 additions & 0 deletions invenio_app_rdm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,9 @@ def github_link_render(record):
}
"""Community requests search configuration (i.e list of community requests)"""

COMMUNITIES_SHOW_BROWSE_MENU_ENTRY = False
"""Toggle to show or hide the 'Browse' menu entry for communities."""

# Invenio-RDM-Records
# ===================

Expand All @@ -1014,6 +1017,7 @@ def github_link_render(record):
RDM_COMMUNITIES_ROUTES = {
"community-detail": "/communities/<pid_value>/records",
"community-home": "/communities/<pid_value>/",
"community-browse": "/communities/<pid_value>/browse",
"community-static-page": "/communities/<pid_value>/pages/<path:page_slug>",
}

Expand Down
10 changes: 10 additions & 0 deletions invenio_app_rdm/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from flask_menu import current_menu
from invenio_i18n import lazy_gettext as _

from .communities_ui.views.ui import _show_browse_page


def _is_branded_community():
"""Function used to check if community is branded."""
Expand Down Expand Up @@ -114,6 +116,14 @@ def init_menu(app):
expected_args=["pid_value"],
**dict(icon="home", permissions="can_read"),
)
communities.submenu("browse").register(
endpoint="invenio_communities.communities_browse",
text=_("Browse"),
order=15,
visible_when=_show_browse_page,
expected_args=["pid_value"],
**{"icon": "list", "permissions": "can_read"},
)
communities.submenu("search").register(
"invenio_app_rdm_communities.communities_detail",
text=_("Records"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* This file is part of Invenio.
* Copyright (C) 2024 CERN.
*
* Invenio is free software; you can redistribute it and/or modify it
* under the terms of the MIT License; see LICENSE file for more details.
*/

import React from "react";
import ReactDOM from "react-dom";
import _get from "lodash/get";

import { CommunitiesCardGroup } from "@js/invenio_communities/community";

const subCommunitiesContainer = document.getElementById("subcommunities-container");
const domContainer = document.getElementById("invenio-browse-config");
const apiEndpoint = _get(domContainer.dataset, "apiEndpoint");

if (subCommunitiesContainer) {
ReactDOM.render(
<CommunitiesCardGroup
fetchDataUrl={apiEndpoint}
emptyMessage="There are no child communities."
defaultLogo="/static/images/square-placeholder.png"
/>,
subCommunitiesContainer
);
}
1 change: 1 addition & 0 deletions invenio_app_rdm/theme/webpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"invenio-records-administration": "./js/invenio_app_rdm/administration/records/index.js",
"invenio-drafts-administration": "./js/invenio_app_rdm/administration/drafts/index.js",
"invenio-domains-administration": "./js/invenio_app_rdm/administration/domains/index.js",
"invenio-communities-browse": "./js/invenio_app_rdm/subcommunity/browse.js",
},
dependencies={
"@babel/runtime": "^7.9.0",
Expand Down