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

Add Notifications CMS functionality #3103

Open
wants to merge 60 commits into
base: dev
Choose a base branch
from

Conversation

jschultze
Copy link

@jschultze jschultze commented Sep 20, 2023

This pull request adds the Notifications mini-CMS functionality to VuFind. It is developed by effective WEBWORK GmbH in cooperation with hebis. Notifications allow the creation of simple, CMS-like "pages" that can be accessed via a new menu in the header area. Also short information "broadcasts" can be displayed in the header area and on the search home.

Markdown is used to compose the content, and different translations for all currently enabled languages are possible. Pages and broadcasts are edited from the Admin-area of DSpace.

TODO

  • Port database code to PostgreSQL

@demiankatz demiankatz added this to the 10.0 milestone Sep 20, 2023
@demiankatz
Copy link
Member

Thanks for sharing this, @jschultze! I'm currently focusing most of my time on finishing up the 9.1 release, but I will give this a review once development begins on 10.0.

@jschultze
Copy link
Author

Thanks @demiankatz !

There seems to be a request for additional functions that came up after WOLFcon - hebis jut informed me about that. I will look into it in the next week, and maybe I can include that in the pull request before you start with the review.

@demiankatz
Copy link
Member

Great, thanks, @jschultze!

composer.json Outdated Show resolved Hide resolved
Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jschultze, just a couple of very high-level observations from a quick look at the code. Since you said more changes might be coming soon, I haven't given this a deeper review yet, but I thought it might be helpful to at least get a conversation started here. :-)

config/vufind/permissions.ini Outdated Show resolved Hide resolved
module/VuFind/config/module.config.php Outdated Show resolved Hide resolved
@EreMaijala EreMaijala requested review from EreMaijala and removed request for EreMaijala November 7, 2023 14:09
@demiankatz
Copy link
Member

Based on discussion with @ThoWagen on today's Community Call, I have given this PR an "on hold" label since I know there is pending work that we expect to have added at some point in the future, and it's probably best to delay review until that is completed. Please let me know when you're ready and I'll be happy to remove the label and resume reviewing.

@jschultze
Copy link
Author

@demiankatz The functionality is ready and I will start looking into the first observations that you mentioned above.

…ion to "notifications.Admin". Login is required by default, usernames can be set to restrict the access even more. If the permission is not granted an error message will be displayed.
@demiankatz demiankatz removed the on hold label Dec 5, 2023
@demiankatz
Copy link
Member

Thanks, @jschultze, I'm removing the "on hold" label and will give this another review soon. I notice that there are some minor conflicts that need to be resolved here. Would you like help resolving these? If so, just let me know and I'll take care of them at the same time I do my review.

@demiankatz demiankatz changed the title VuFind Notifications CMS Add Notifications CMS functionality Dec 5, 2023
Copy link
Member

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jschultze, I had a few minutes free today, so I went ahead and resolved the merge conflicts as well as applying some of the standard style fix tools (php-cs-fixer and phpcbf). I didn't have time for a full review, but I skimmed through and raised a few more points for discussion (see below).

module/VuFind/sql/mysql.sql Outdated Show resolved Hide resolved
themes/bootstrap3/js/notifications.js Outdated Show resolved Hide resolved
@@ -0,0 +1,6 @@
/*! jQuery UI - v1.13.2 - 2023-02-20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How critical is jQuery UI to this PR? We are currently in the early stages of removing all jQuery dependencies from the codebase, so I'm reluctant to add a major new dependency if it can be avoided...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is only used to enable a tab for each configured language in the edit forms for pages and broadcasts. The reordering of entries in the list view to change the displayed order is done with the DataTables library.

Is it just a problem using jQuery UI particularly, so that I can try and find a smaller, independent library for the tabs? Or should additional JavaScript libraries be avoided?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have tabbed interfaces in a couple of places (most notably on the record page) without introducing additional dependencies. I confess that I can't remember exactly how those are implemented, but it might be worth looking for precedent before adding something new. Or, if adding something new is valuable, maybe it should be applied to all tabbed interfaces for consistency.

In any case, I'm certainly not completely opposed to adding a dependency if it's a significant time saver or improves the user experience. I just try to avoid them unless absolutely necessary because they often lead to future technical debt.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently trying to refactor the notifications language-tabs to the way tabs are implemented on the record page.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not get the tabs from the detail view to work in the notifications context, so I build a small JS/CSS tab navigation myself. jQuery UI is removed.

The less and sass files are included. Should all the generated files be committed too?

/themes/bootprint3/css/compiled.css
/themes/bootstrap3/css/compiled.css
/themes/bootstrap3/css/vendor/simple-keyboard/index.css
/themes/bootstrap3/js/vendor/chart.js
/themes/bootstrap3/js/vendor/simple-keyboard/index.js
/themes/bootstrap3/js/vendor/simple-keyboard-layouts/index.js
/themes/local_theme_example/css/compiled.css
/themes/sandal/css/compiled.css

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@demiankatz composer update-npm-dependencies (or npm run updateDeps for a single theme) doesn't allow you to do it for a single package and can cause side-effects unless you're careful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, @EreMaijala. I guess we need to decide on a strategy here. I think there are two general approaches:

1.) We pin all dependencies, and add composer/npm tasks to help identify pinned dependencies that are eligible for upgrades.

2.) We leave dependencies unpinned, and I open a separate PR to upgrade and test everything, and then we merge that separately to remove extraneous changes from this PR.

Any preference?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I've opened #3522 to bring things up to date independently of this PR... but I'm still open to discussing long term strategy independent of that. :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@demiankatz I don't have a strong preference, but pinning would be consistent with composer dependencies and would avoid the situation here where just trying to add or update one dependency will easily cause side-effects.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It occurs to me that the best solution might be to start committing the lock file. Can you think of any reason not to?

themes/bootstrap3/js/vendor/datatables.min.js Outdated Show resolved Hide resolved
@jschultze
Copy link
Author

@demiankatz @sturkel89 I committed fixes for the comments regarding translation keys and the configuration file.

Regarding the sticky date: I tried to replicate the behaviour on my local machine wit a Firefox set to "English (US)" as language. This results in a form that seems to display the dates right:

Bildschirmfoto 2024-09-26 um 13 25 10

Creating and editing the dates works without any problems. What I can only see if I delete all date info by hand are empty fields with just the placeholder "mm/dd/yyyy" displayed. When I create a new broadcast, the current date is set as the default value. So I can't really recreate this bug on my side.

What I found, and maybe is a solution: in the Form-class for Broadcasts a standard format was configured for start- and end-date.

'options' => [
                'label' => $this->translate('broadcasts_startdate'),
                'format' => 'Y-m-d',
            ],

I removed that option. The behaviour does not change, but maybe that was the detail that fixes the forms in your environment also.

@sturkel89
Copy link
Contributor

@jschultze I'm still finding that when I EDIT an existing broadcast, the dates immediately go blank. That is the only problem I'm concerned with.

Here's the broadcast in dashboard view:
image
Then I click the Edit icon, and here's what I see:

image

The text, the checkbox for "visible on every page", and the color choice of blue are all still there and ready to be edited. But the dates have reverted to the placeholder mm/dd/yyyy. I would expect the dates I selected previously to still be present in this editing view. Do you have a different experience of this? I see the same thing in Firefox and Chrome on Windows.

@demiankatz
Copy link
Member

I wonder if this problem has something to do with locale settings...

@sturkel89
Copy link
Contributor

I tested the branch again with the locale settings changed to de_DE. The date settings for notification broadcasts still reset to MM/DD/YYYY when I went to edit my test broadcast. So, I don't think that locale settings are the explanation for this behavior.

@jschultze , when you create and then edit a test broadcast, do you find that the dates that were set initially are present when you switch to the editing view?

@demiankatz demiankatz modified the milestones: 10.1, 11.0 Oct 8, 2024
@demiankatz
Copy link
Member

Since time is running short for 10.1, I have moved this to the 11.0 milestone.

@jschultze
Copy link
Author

@sturkel89 Yes, editing an existing broadcast keeps the dates:

Bildschirmfoto 2024-10-18 um 13 16 40

Chrome, set to de_DE:

Bildschirmfoto 2024-10-18 um 13 16 49

Firefox, set to en_US:

Bildschirmfoto 2024-10-18 um 13 17 49

Copy link
Member

@maccabeelevine maccabeelevine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great feature addition and I hope to see it completed so I can use it!

Evaluating only the issue that @sturkel89 reported, I am seeing the same problem. When editing an existing broadcast, I lose the dates. I did some research below into why it's happening but I don't know anything about Laminas Form so can't say how to solve it for real.

$view->languages = $this->config['Notifications']['languages'];

if ($broadcast_id != 'NEW') {
$broadcast = $broadcastsTable->getBroadcastsDataByBroadcastId($broadcast_id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After loading $broadcast, I see that the startdate and enddate elements are datetimes i.e. 2024-11-05 00:00:00, which makes sense since the schema defines those fields as datetimes. There is some logic within Laminas form which is corrupting that (I think) so that in FormElement->render(), the $renderedType ends up as "<input type="date" name="startdate" class="form-control" value="2024-11-05&#x20;00&#x3A;00&#x3A;00">", which I think is what messes up the display.

I can fix this right after this line by truncating off the time parts:

            foreach(['startdate', 'enddate'] as $dateField) {
                $broadcast[$dateField] = explode(' ', $broadcast[$dateField])[0];
            }

But there must be a better way to resolve this. I'm not sure if the schema has to use datetime in the first place if the UI accepts only date values, unless this is trying to be flexible in case we do store times in the future.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maccabeelevine Thanks for the test! I was about to try this change, but checked the generated HTML on my local system first for the corrupted HTML. And here seems to be the difference to your test and those of @sturkel89 . I get this HTML:

<input type="date" name="startdate" class="form-control" value="2024-07-11">

So I checked my local database and the schema is date not datetime. I'm sorry that I missed this before and I can not recall why this setting does not match the schema given in mysql.sql!

@demiankatz Will a date be enough, or would you think it should be possible to set exact times? We tested this functionality with two communities (hebis and Qcovery) and I don't think that setting the exact time has been missed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can imagine there might be arguments for either granularity, but if your existing user base has found date granularity acceptable, it seems reasonable to at least start there. If we need date/time, nothing is stopping us from adding it as a future option. (Of course, if it's trivially easy, maybe it's worth adding a config setting now... but I suspect it is not trivially easy, and I don't want to make the workload here even larger!).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started working on additional time settings, but realized that it will probably be better to get the first version on this feature finalized - assuming that the whole community will have ideas for further development in the future and we will be working on this anyhow.

I changed the settings in mysql.sql from datetime to time and added the three small changes that @maccabeelevine proposed (although setting 0 as default for priority).

public function insertOrUpdateBroadcast($data, $broadcastData = null, $broadcast_id = null)
{
foreach ($this->config['Notifications']['languages'] as $language) {
if ($broadcastData['id_' . $language] == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get an exception on this line, I believe it should be

if (($broadcastData['id_' . $language] ?? null) == null) {

or maybe just

if (!($broadcastData['id_' . $language] ?? null)) {


$broadcast->visibility = $data['visibility'];
$broadcast->visibility_global = $data['visibility_global'];
$broadcast->priority = $data['priority'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get an exception here, no priority field. I was able to get past it with

            $broadcast->priority = $data['priority'] ?? -1;

but there may be a better default.

Comment on lines 107 to 108
$broadcast->change_date = $data['change_date'];
$broadcast->create_date = $data['create_date'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got errors on these fields as well and had to protect them with ?? null.

@demiankatz
Copy link
Member

Thanks for the progress, @jschultze (and thanks for the assist in getting us unstuck, @maccabeelevine). How would you like to proceed from here? Would more testing be helpful? Do you want to start working on bringing the code more up to date? Do you need assistance in any particular areas?

@jschultze
Copy link
Author

@demiankatz If the code is now working on your side, I would start with the update of the code to the current state of VuFind, yes.

@demiankatz demiankatz requested a review from sturkel89 November 11, 2024 13:04
@demiankatz
Copy link
Member

Thanks, @jschultze! @sturkel89, can you give this another look when time permits?

Copy link
Contributor

@sturkel89 sturkel89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fixed!! I've set up a couple of broadcast messages, and when I click the edit icon I see that all of the elements of the broadcast are available to be edited, including the dates!

I tested changing the dates, and the new dates saved correctly. As far as I can tell, all is working properly now. Thanks, @maccabeelevine and @jschultze!

@jschultze
Copy link
Author

Thanks for the test, @sturkel89 I will start with to update the code to the current version of VuFind.

# Conflicts:
#	composer.json
#	composer.lock
#	module/VuFind/src/VuFind/Db/Table/PluginManager.php
#	themes/bootprint3/css/compiled.css
#	themes/bootstrap3/css/compiled.css
#	themes/bootstrap3/js/vendor/simple-keyboard-layouts/index.js
#	themes/bootstrap3/package.json
#	themes/bootstrap3/templates/admin/menu.phtml
#	themes/bootstrap3/theme.config.php
#	themes/local_theme_example/css/compiled.css
#	themes/sandal/css/compiled.css
#	themes/sandal/less/search.less
#	themes/sandal/scss/search.scss
@jschultze
Copy link
Author

@demiankatz I merged the current dev branch into this pull request and added support for the bootstrap5 theme.

Copy link
Contributor

@sturkel89 sturkel89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed this PR with special consideration of the updates to the new themes.

FRONT PAGE ISSUES

Notification banners that are supposed to appear on the front page are NOT functional in the new themes, although they appear normal in the legacy themes.

bootstrap3:
image

sandal:
image

In the new themes, the banners DO NOT APPEAR on the front page, at all.

sandal5:
image


OTHER PAGES ISSUES

Notifications banners appear in both legacy and new themes in VuFind subpages (i.e., item pages, results list pages) but their formatting is different between legacy and new themes.

Notification banners stretch across the screen in the legacy themes:

bootstrap3:
image

sandal:
image

In both new themes, the banners appear in the top corner, pushing the Theme and Language dropdowns to the middle of the screen.

bootstrap5:
image

sandal5:
image

Also, the other issues I noted in my earlier reviews are still problems:

  • I can't get any popover explanations for some of the icons on the management page (eyeball, globe)
  • Clicking the X in the notification banner does not make it disappear.

NOTIFICATIONS PAGES

Notifications pages are functional, in that the text links to the notifications pages appear on the home page and the other pages in all themes.

The locations of the links are a little awkward in the new themes. In the legacy themes, the links are aligned with the word or icon for VuFind. In the new themes, they are in the middle of the page but above the VuFind.

bootstrap3:
image

Same browser, bootstrap5:
image

sandal:
image

Same browser, sandal5:
image

With narrower screens, the break points for hiding the notification page links inside the hamburger menu are different between legacy and new themes. There are many different breaking points and variations, so I didn't document them.

EreMaijala pushed a commit to EreMaijala/vufind that referenced this pull request Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature new language strings adds new text in need of translation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants