Skip to content

Commit

Permalink
Refactor "author list" dialog (#5588)
Browse files Browse the repository at this point in the history
  • Loading branch information
duartegalvao committed Feb 1, 2023
1 parent b5fcb22 commit c72d9e0
Show file tree
Hide file tree
Showing 27 changed files with 631 additions and 230 deletions.
31 changes: 22 additions & 9 deletions indico/modules/events/abstracts/controllers/abstract_list.py
Expand Up @@ -29,11 +29,13 @@
from indico.modules.events.contributions.models.persons import AuthorType
from indico.modules.events.management.controllers.emails import (EmailRolesMetadataMixin, EmailRolesPreviewMixin,
EmailRolesSendMixin)
from indico.modules.events.persons.util import get_event_person_for_user
from indico.modules.events.registration.util import get_registered_event_persons
from indico.modules.events.util import get_field_values
from indico.modules.users.models.users import User
from indico.util.i18n import _, ngettext
from indico.web.args import use_kwargs
from indico.web.util import jsonify_data, jsonify_form, jsonify_template
from indico.web.util import jsonify_data, jsonify_form


class RHAbstractListBase(RHManageAbstractsBase):
Expand Down Expand Up @@ -222,22 +224,33 @@ def _membership_filter(self):
return Abstract.id.in_(abstract_ids)

def _process(self):
def _get_or_create_person_dict(person):
person_dict = abstract_persons_dict[person.identifier]
person_dict['identifier'] = person.identifier
person_dict['full_name'] = person.full_name
person_dict['email'] = person.email
person_dict['affiliation'] = person.affiliation
return person_dict

submitters = {abstract.submitter for abstract in self.abstracts}
abstract_persons = (AbstractPersonLink.query
.filter(AbstractPersonLink.abstract.has(self._membership_filter))
.all())
registered_persons = get_registered_event_persons(self.event)
abstract_persons_dict = defaultdict(lambda: {'speaker': False, 'submitter': False, 'primary_author': False,
'secondary_author': False})
for abstract_person in abstract_persons:
dict_key = abstract_person.person.user if abstract_person.person.user else abstract_person.person
person_roles = abstract_persons_dict[dict_key]
person_roles['speaker'] |= abstract_person.is_speaker
person_roles['primary_author'] |= abstract_person.author_type == AuthorType.primary
person_roles['secondary_author'] |= abstract_person.author_type == AuthorType.secondary
user_or_person = abstract_person.person.user if abstract_person.person.user else abstract_person.person
person_dict = _get_or_create_person_dict(user_or_person)
person_dict['speaker'] |= abstract_person.is_speaker
person_dict['primary_author'] |= abstract_person.author_type == AuthorType.primary
person_dict['secondary_author'] |= abstract_person.author_type == AuthorType.secondary
person_dict['registered'] = abstract_person.person in registered_persons
for submitter in submitters:
abstract_persons_dict[submitter]['submitter'] |= True
return jsonify_template('events/abstracts/management/abstract_person_list.html',
event_persons=abstract_persons_dict, event=self.event)
person_dict = _get_or_create_person_dict(submitter)
person_dict['submitter'] = True
person_dict['registered'] = get_event_person_for_user(self.event, submitter) in registered_persons
return jsonify(event_persons=[p for _, p in sorted(abstract_persons_dict.items())])


class RHManageAbstractsExportActionsBase(RHManageAbstractsActionsBase):
Expand Down
Expand Up @@ -162,15 +162,11 @@
</ul>
</div>
<div class="group">
<div class="i-button-wrapper">
<button class="i-button icon-users js-requires-selected-row disabled"
data-title="{% trans %}Author list{% endtrans %}"
data-href="{{ url_for('.person_list', event) }}"
data-params-selector="#abstract-list input[name=abstract_id]:checked"
data-method="POST"
data-ajax-dialog>
{%- trans %}Author list{% endtrans -%}
</button>
<div id="email-authors-container"
class="i-button-wrapper"
data-event-id="{{ event.id }}"
data-object-context="abstracts"
data-params-selector="#abstract-list input[name=abstract_id]:checked">
</div>
<div id="email-abstract-roles-container"
class="i-button-wrapper"
Expand Down Expand Up @@ -251,6 +247,7 @@
</div>

<script>
setupAuthorsListButton('#email-authors-container');
setupEmailContribAbstractRoles('#email-abstract-roles-container');
setupAbstractList();
setupAbstractJudgment({
Expand Down

This file was deleted.

Expand Up @@ -313,7 +313,6 @@ def _get_contribution_track_updates(self, track_id):
class RHContributionPersonList(RHContributionPersonListMixin, RHManageContributionsActionsBase):
"""List of persons in the contribution."""

template = 'events/contributions/management/contribution_person_list.html'
ALLOW_LOCKED = True

@property
Expand Down

This file was deleted.

Expand Up @@ -94,15 +94,11 @@
{%- trans %}Remove{% endtrans -%}
</button>
<div class="group">
<div class="i-button-wrapper">
<button class="i-button icon-users js-enable-if-checked disabled"
data-title="{% trans %}Author list{% endtrans %}"
data-href="{{ url_for('contributions.person_list', event) }}"
data-params-selector="#contribution-list input[name=contribution_id]:checked"
data-method="POST"
data-ajax-dialog>
{%- trans %}Author list{% endtrans -%}
</button>
<div id="email-authors-container"
class="i-button-wrapper"
data-event-id="{{ event.id }}"
data-object-context="contributions"
data-params-selector="#contribution-list input[name=contribution_id]:checked">
</div>
<div id="email-contrib-roles-container"
class="i-button-wrapper"
Expand Down Expand Up @@ -209,6 +205,7 @@
$('#search-input').val('#{{ selected_entry }}').trigger('change');
{% endif %}

setupAuthorsListButton('#email-authors-container');
setupEmailContribAbstractRoles('#email-contrib-roles-container');
setupContributionConfig();
setupContributionList({
Expand Down
17 changes: 15 additions & 2 deletions indico/modules/events/management/client/js/index.js
Expand Up @@ -17,6 +17,7 @@ import 'indico/modules/events/util/static_filters';

import './badges';

import {AuthorsListButton} from 'indico/modules/events/persons/AuthorsListButton';
import {EmailContribAbstractRolesButton} from 'indico/modules/events/persons/EmailContribAbstractRolesButton';
import {EmailParticipantRolesButton} from 'indico/modules/events/persons/EmailParticipantRolesButton';
import {$T} from 'indico/utils/i18n';
Expand All @@ -28,7 +29,7 @@ import {SeriesManagement} from './SeriesManagement';
(function(global) {
global.setupEmailButton = function setupEmailButton(field, trigger) {
const element = document.querySelector(field);
const {eventId, roleId, personSelector, userSelector} = element.dataset;
const {eventId, roleId, personSelector} = element.dataset;
const extraParams = {};
if (element.dataset.noAccount !== undefined) {
extraParams.noAccount = true;
Expand All @@ -41,7 +42,6 @@ import {SeriesManagement} from './SeriesManagement';
eventId={+eventId}
roleId={roleId && +roleId}
personSelector={personSelector}
userSelector={userSelector}
triggerSelector={trigger}
{...extraParams}
/>,
Expand All @@ -66,6 +66,19 @@ import {SeriesManagement} from './SeriesManagement';
);
};

global.setupAuthorsListButton = function setupAuthorsListButton(containerSelector) {
const element = document.querySelector(containerSelector);
const {eventId, objectContext, paramsSelector} = element.dataset;
ReactDOM.render(
<AuthorsListButton
eventId={+eventId}
objectContext={objectContext}
paramsSelector={paramsSelector}
/>,
element
);
};

global.setupEventManagementActionMenu = function setupEventManagementActionMenu() {
const moveContainer = document.querySelector('#event-action-move-container');
if (moveContainer) {
Expand Down
21 changes: 12 additions & 9 deletions indico/modules/events/management/controllers/base.py
Expand Up @@ -7,7 +7,7 @@

from collections import defaultdict

from flask import session
from flask import jsonify, session
from werkzeug.exceptions import Forbidden

from indico.modules.events.contributions.models.persons import (AuthorType, ContributionPersonLink,
Expand All @@ -17,7 +17,6 @@
from indico.modules.events.registration.util import get_registered_event_persons
from indico.modules.events.util import check_event_locked
from indico.util.i18n import _
from indico.web.util import jsonify_template


class ManageEventMixin:
Expand Down Expand Up @@ -67,10 +66,14 @@ def _process(self):
contribution_persons_dict = defaultdict(lambda: {'speaker': False, 'primary_author': False,
'secondary_author': False, 'not_registered': True})
for contrib_person in contribution_persons:
person_roles = contribution_persons_dict[contrib_person.person]
person_roles['speaker'] |= contrib_person.is_speaker
person_roles['primary_author'] |= contrib_person.author_type == AuthorType.primary
person_roles['secondary_author'] |= contrib_person.author_type == AuthorType.secondary
person_roles['not_registered'] = contrib_person.person not in registered_persons

return jsonify_template(self.template, event_persons=contribution_persons_dict, event=self.event)
person_dict = contribution_persons_dict[contrib_person.person.id]
person_dict['identifier'] = contrib_person.person.identifier
person_dict['full_name'] = contrib_person.person.full_name
person_dict['email'] = contrib_person.person.email
person_dict['affiliation'] = contrib_person.person.affiliation
person_dict['speaker'] |= contrib_person.is_speaker
person_dict['primary_author'] |= contrib_person.author_type == AuthorType.primary
person_dict['secondary_author'] |= contrib_person.author_type == AuthorType.secondary
person_dict['registered'] = contrib_person.person in registered_persons

return jsonify(event_persons=[p for __, p in sorted(contribution_persons_dict.items())])
Expand Up @@ -39,8 +39,7 @@
<div class="form-group-mail hide-if-locked">
<div id="persons-email"
data-event-id="{{ event.id }}"
data-user-selector="#person-list-table input[name=user_id][type=checkbox]:checked"
data-person-selector="#person-list-table input[name=person_id][type=checkbox]:checked">
data-person-selector="#person-list-table input[name=person_identifier][type=checkbox]:checked">
</div>
<button id="persons-email-trigger"
class="i-button icon-mail right highlight disabled js-requires-selected-row">
Expand Down
72 changes: 0 additions & 72 deletions indico/modules/events/management/templates/_event_person_list.html

This file was deleted.

15 changes: 7 additions & 8 deletions indico/modules/events/papers/templates/_paper_list.html
Expand Up @@ -354,14 +354,12 @@
</a>
</li>
</ul>
<button class="i-button icon-users js-enable-if-checked disabled"
data-title="{% trans %}Author list{% endtrans %}"
data-href="{{ url_for('contributions.person_list', event) }}"
data-params-selector="#assignment-list input[name=contribution_id]:checked"
data-method="POST"
data-ajax-dialog>
{%- trans %}Author list{% endtrans -%}
</button>
<div id="authors-list-container"
class="group"
data-event-id="{{ event.id }}"
data-object-context="contributions"
data-params-selector="#assignment-list input[name=contribution_id]:checked">
</div>
<button class="i-button icon-attachment js-requires-selected-row disabled js-submit-list-form"
data-href="{{ url_for('.download_papers', event) }}">
{%- trans %}Download papers{% endtrans -%}
Expand Down Expand Up @@ -394,5 +392,6 @@
$('#search-input').val('#{{ selected_entry }}').trigger('change');
{% endif %}
setupPaperAssignmentList();
setupAuthorsListButton('#authors-list-container');
</script>
{% endmacro %}

0 comments on commit c72d9e0

Please sign in to comment.