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

Rw 1058 round 3 #968

Merged
merged 14 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
2 changes: 2 additions & 0 deletions config/user.role.contributor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
- node
- reliefweb_files
- reliefweb_form
- reliefweb_revisions
id: contributor
label: Contributor
weight: 9
Expand All @@ -24,4 +25,5 @@ permissions:
- 'edit own image_report media'
- 'edit own report content'
- 'update media'
- 'view entity history'
- 'view own unpublished media'
11 changes: 7 additions & 4 deletions html/modules/custom/reliefweb_entities/src/Entity/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,14 @@ public function preSave(EntityStorageInterface $storage) {
}
}

// Update the entity status based on the user posting rights.
$this->updateModerationStatusFromPostingRights();

// Change the status to `embargoed` if there is an embargo date.
if (!empty($this->field_embargo_date->value) && $this->getModerationStatus() !== 'draft') {
if (!empty($this->field_embargo_date->value) && in_array($this->getModerationStatus(), [
'to-review',
'published',
])) {
$this->setModerationStatus('embargoed');

$message = strtr('Embargoed (to be automatically published on @date).', [
Expand All @@ -258,9 +264,6 @@ public function preSave(EntityStorageInterface $storage) {
// Prepare notifications.
$this->preparePublicationNotification();

// Update the entity status based on the user posting rights.
$this->updateModerationStatusFromPostingRights();

// Update the entity status based on the source(s) moderation status.
$this->updateModerationStatusFromSourceStatus();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,6 @@ protected function alterFieldsForContributors(array &$form, FormStateInterface $
// Hide fields.
$form['field_bury']['#access'] = FALSE;
$form['field_feature']['#access'] = FALSE;
$form['field_notify']['#access'] = FALSE;
attiks marked this conversation as resolved.
Show resolved Hide resolved

$form['field_headline']['#access'] = FALSE;
$form['field_headline_title']['#access'] = FALSE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,33 @@
margin: 0 8px;
}
.field--type-reliefweb-user-posting-rights label span,
.field--type-reliefweb-user-posting-rights label select {
.field--type-reliefweb-user-posting-rights label select,
.field--type-reliefweb-user-posting-rights label input[type="text"] {
display: inline-block;
margin: 0 8px 0 0;
vertical-align: middle;
}
.field--type-reliefweb-user-posting-rights label select {
.field--type-reliefweb-user-posting-rights label select,
.field--type-reliefweb-user-posting-rights [data-filters] label input[type="text"] {
width: auto;
}
.field--type-reliefweb-user-posting-rights div[data-filters] ~ ul li {
display: none;
flex-wrap: wrap;
align-items: center;
}

.field--type-reliefweb-user-posting-rights div[data-filters][data-job="all"][data-training="all"][data-report="all"] ~ ul li {
display: flex;
}

.field--type-reliefweb-user-posting-rights div[data-filters]:not([data-name=""]) ~ ul li {
display: none !important;
}
.field--type-reliefweb-user-posting-rights div[data-filters]:not([data-name=""]) ~ ul li[data-user-filtered] {
display: flex !important;
}

.field--type-reliefweb-user-posting-rights div[data-filters][data-job="0"] ~ ul li[data-job="0"] {
display: flex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,27 @@
return label;
},

/**
* Create a filter for users.
*/
createUserFilter: function () {
let name = 'name';

var select = document.createElement('input');
select.setAttribute('type', 'text');
select.setAttribute('data-name', name);

var span = document.createElement('span');
span.appendChild(document.createTextNode(t('user id, name, email')));

var label = document.createElement('label');
label.appendChild(span);
label.appendChild(select);
label.className = name;

return label;
},

/**
* Create the user notes field.
*/
Expand Down Expand Up @@ -118,6 +139,7 @@
container.setAttribute('data-job', data.job);
container.setAttribute('data-training', data.training);
container.setAttribute('data-report', data.report);
container.setAttribute('data-name', [data.id, data.name, data.mail].join(', '));

// User info.
var info = document.createElement('div');
Expand Down Expand Up @@ -208,6 +230,7 @@
container.setAttribute('data-job', 'all');
container.setAttribute('data-training', 'all');
container.setAttribute('data-report', 'all');
container.setAttribute('data-name', '');

var title = document.createElement('span');
title.appendChild(document.createTextNode(t('Filter: ')));
Expand All @@ -218,6 +241,9 @@
container.appendChild(this.createSelect('training', '', false, true));
container.appendChild(this.createSelect('report', '', false, true));

// User filter.
container.appendChild(this.createUserFilter());

return container;
},

Expand Down Expand Up @@ -259,6 +285,7 @@

// Handle change events on the different select elements in the form.
container.addEventListener('change', this.handleChange.bind(this));
container.addEventListener('keyup', this.handleChange.bind(this));

// Handle focus out events from notes fields.
container.addEventListener('focusout', this.handleFocusOut.bind(this));
Expand Down Expand Up @@ -525,6 +552,29 @@
parent = this.getParentElement(target, 'LI');
}

// Set the attribute to the value of the select element.
parent.setAttribute('data-' + name, target.value);
parent.setAttribute('data-modified', '');
this.updateData();
}
}
else if (target && target.tagName === 'INPUT') {
var name = target.getAttribute('data-name');
var parent = target.parentNode.parentNode;

// Filter on user name.
if (parent.hasAttribute('data-filters') && name === 'name') {
let grandParent = parent.parentNode;
if (grandParent.querySelectorAll('li[data-user-filtered]').length > 0) {
Array.from(grandParent.querySelectorAll('li[data-user-filtered]'))
.forEach(e => e.removeAttribute('data-user-filtered'));
}

if (target.value !== '') {
Array.from(grandParent.querySelectorAll('li[data-name*="' + target.value + '"]'))
.forEach(e => e.setAttribute('data-user-filtered', ''));
}

// Set the attribute to the value of the select element.
parent.setAttribute('data-' + name, target.value);
parent.setAttribute('data-modified', '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
}%}

{% set submission_sections = {
'editorial-flags': 'Notify'|t,
'actions': 'Save'|t,
'edit-revision-information': 'Revisions'|t,
}%}
Expand Down Expand Up @@ -128,6 +129,11 @@
{{ form.field_feature }}
{{ form.field_notify }}
</fieldset>
{% else %}
<fieldset id="editorial-flags">
<legend>{% trans %}Notify{% endtrans %}</legend>
{{ form.field_notify }}
</fieldset>
{% endif %}

<fieldset id="actions">
Expand Down
Loading