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 6 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
12 changes: 8 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,15 @@ 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(), [
'draft',
'pending',
'refused',
])) {
$this->setModerationStatus('embargoed');

$message = strtr('Embargoed (to be automatically published on @date).', [
Expand All @@ -258,9 +265,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 @@ -41,9 +41,18 @@
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="all"]) ~ ul li {
display: none !important;
}
.field--type-reliefweb-user-posting-rights div[data-filters]:not([data-name="all"]) ~ 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,43 @@
return label;
},

/**
* Create a filter for users.
*/
createUserSelect: function () {
orakili marked this conversation as resolved.
Show resolved Hide resolved
let data = this.getFieldData();
let name = 'name';

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

var span = document.createElement('span');
span.appendChild(document.createTextNode(name));

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

var option = document.createElement('option');
option.appendChild(document.createTextNode(t('Any')));
option.setAttribute('value', 'all');
option.setAttribute('selected', '');
select.appendChild(option);

// List alphabetically.
data = data.sort((a, b) => a.name.localeCompare(b.name));
for (var i = 0; i < data.length; i++) {
var option = document.createElement('option');
option.appendChild(document.createTextNode(data[i].name));
option.setAttribute('value', data[i].name);
select.appendChild(option);
}

label.appendChild(select);
label.className = name;

return label;
},

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

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

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

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

return container;
},

Expand Down Expand Up @@ -516,7 +558,7 @@
var name = target.getAttribute('data-name');

// Update the rights attributes of the user row.
if (name === 'job' || name === 'training' || name === 'report') {
if (name === 'job' || name === 'training' || name === 'report' || name === 'name') {
var parent = target.parentNode.parentNode;

// If the parent is not the filter container, then it's a select
Expand All @@ -529,6 +571,17 @@
parent.setAttribute('data-' + name, target.value);
parent.setAttribute('data-modified', '');
this.updateData();

// Filter on user name.
if (parent.hasAttribute('data-filters') && name === 'name') {
let grandParent = parent.parentNode;
if (grandParent.querySelector('li[data-user-filtered]')) {
grandParent.querySelector('li[data-user-filtered]').removeAttribute('data-user-filtered');
}
if (target.value !== 'all') {
grandParent.querySelector('li[data-name="' + target.value + '"]').setAttribute('data-user-filtered', '');
}
}
}
}
},
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