Future major features

Displaying information to users on redirect

 
This discussion has been locked because a year has elapsed since the last post. Please start a new discussion topic.
Picture of Andrew Nicols
Displaying information to users on redirect
Group Core developersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

Hi all,

As you may be aware I am the component lead for the Moodle forum.

One of my personal bug-bears in mod_forum is the fact that, after every post, you are redirected to a page informing you that you've just posted before you are then redirected back to the forum index.

This is poor for user experience because workflow is interrupted and the user distracted, and the message is only displayed for a short period (which may not be long enough).

You are redirected to this page purely so that we can display a message because we have no way of storing those messages from one page to the next (without all sorts of nasty hacks like adding the message or some metadata about the message to the URL).

The current behaviour

I've put together a proof-of-concept whereby we can store these kinds of messages in the user session such that they can be displayed on the subsequent page load. I've also applied these to all calls redirect() where the headers have not yet been sent, and have added an additional parameter to redirect() to let you specify the type of message being displayed. Previously redirect() only supported 'notification_redirect' which was rendered as a bootstrap alert. It is now possible to specify the constants for success, info, warning, and error.

The proposed behaviour

Because of existing naming conflicts (message = Moodle messaging; notificaiton = JS dialogues; and a related but different renderable), I have opted to name these `flashes`.

I have also added a public interface to the flash system:

\core\flash::add($message, $level);

With helpers for each level:

\core\flash::success($message);
\core\flash::info($message);
\core\flash::warning($message);
\core\flash::error($message);

These can be combined with a JS API to both display new messages, and to fetch and render messages currently in the session:

require(['core/flash'], function(flash) {
  // Fetch messages currently in the session and display them.
  flash.fetchFlashes();

  // Add a new message to the display (without storing it in the session).
  flash.addFlash({
    message: 'Example message',
    type:    'success'
  });
});

The flashes generated here are instances of the \core\output\notification renderable, which has also been updated as part of this change to add sanity. The output of these is provided by a set of mustache templates which can be modified by themes.

I'm aware that some will dislike the name - if you have a better suggestion, I'm all ears. Note that `messages` is used by other sub-systems and would lead to more confusion, and that `notification` is also doubled up with two different uses already. The term `flash` is used by Symfony and derivatives and does accurately describe the nature of the messages - e.g. that they are flashed up to the user once, and then removed from the queue.

This is still a work in progress, but I wanted to share my current work and start getting any feedback that others may have.

The work on this feature is under MDL-30811 where a working prototype is available for testing.

Cheers,

Andrew

 
Average of ratings: Useful (10)
Picture of Alistair Spark
Re: Displaying information to users on redirect
 

Very nice ! +1 for that

 
Average of ratings: -
Picture of Farhan Karmali
Re: Displaying information to users on redirect
Group Plugin developersGroup Testers

Looks lovely . How about naming them alert?

 
Average of ratings: Useful (1)
Picture of Andrew Nicols
Re: Displaying information to users on redirect
Group Core developersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

Thanks for the suggestions Farhan,

I originally named them alert, but this too is confusing and already used in a number of different ways (JS native alert, and Moodle's YUI alert dialgoue). I also don't feel that these are alerts. The word alert means to warn of a danger or problem whereas I want us to use these for information, success messages, etc. These are informational notices which are displayed to the user briefly.

Best wishes,

Andrew

 
Average of ratings: -
Picture of Ben Kelada
Re: Displaying information to users on redirect
 

yep brilliant, should have been implemented years ago ;)

could this potentially be used to solve the session logged out problem on public sites? e.g. when your session times out on the moodle forums you are redirected to the login page (even though this page is public), would be much better to "flash" the message saying your session has expired/you have been logged out, please log back in" and display the page you are on.


When i built this functionality for another site once, there was potentially an issue where the message would "pop" off the queue to display but then a redirect would happen and the message would be lost, so we had to make sure that on redirect if the message hadn't yet displayed it would be kept. Just raising the point without having looked at the actual code. It looks like you may have picked it up when redirecting before headers have been sent?



 
Average of ratings: Useful (2)
Picture of Andrew Nicols
Re: Displaying information to users on redirect
Group Core developersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

Hi Ben,

could this potentially be used to solve the session logged out problem on public sites? e.g. when your session times out on the moodle forums you are redirected to the login page (even though this page is public), would be much better to "flash" the message saying your session has expired/you have been logged out, please log back in" and display the page you are on.

Yes - we could use this to inform users that they have been logged out.

When i built this functionality for another site once, there was potentially an issue where the message would "pop" off the queue to display but then a redirect would happen and the message would be lost, so we had to make sure that on redirect if the message hadn't yet displayed it would be kept. Just raising the point without having looked at the actual code. It looks like you may have picked it up when redirecting before headers have been sent?

I'm a little confused as to whether you're asking or stating here.

With the way in which this is designed, messages are not popped off the stack until display time.

In the case of the redirect() function, if the headers have not been sent, then the message is added straight to the session and a header-only redirect is issued. This means that there will be no fetching of the flash.

If the headers have already been sent, then the message is displayed on that page, alongside a timeout. The timeout can be specified by the caller:

redirect($url, $message, 42);

If no timeout was specified, and there was a message, a three-second timeout is used. We should perhaps consider increasing that timeout to at least 5 seconds.

Flashes are also fetched from the session on the page -- perhaps we should disable that, but I'm not fully sold on that idea. It may be better to extend the timeout according to the number of flashes in the session.

Andrew

 
Average of ratings: -
C'est moi :-)
Re: Displaying information to users on redirect
Group Documentation writersGroup Particularly helpful MoodlersGroup TestersGroup Translators

Hi Andrew,

This proposition/improvment is quite nice, and i really hop it will be in next Moodle version smile

If it could also better handle loggout users, and reconnection to the previous point, it would be very useful! smile

Séverin

PS : perhaps notice(s) could be another name for this feature?

 
Average of ratings: Useful (2)
Picture of Andrew Nicols
Re: Displaying information to users on redirect
Group Core developersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

Hi,

Can you clarify what you mean by handle logout and connection to the previous point please?

The flashes are persisted across sessions until they are seen. How would you like to see this improved?

Thanks,

Andrew

 
Average of ratings: -
C'est moi :-)
Re: Displaying information to users on redirect
Group Documentation writersGroup Particularly helpful MoodlersGroup TestersGroup Translators

Hi Andrew,

Sorry if i wasn't clear enough ; i was just meaning "+1" about Ben's question/proposition and your answer about how to handle logout (cause session expired) and re-connexion.

Séverin

 
Average of ratings: Useful (1)
Picture of Andrew Nicols
Re: Displaying information to users on redirect
Group Core developersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

Hi Séverin,

I'm afraid that this is beyond the scope of the work I'm doing here. It could be used for some of this, but I'm not entirely sure how this would work.

Best wishes,

Andrew

 
Average of ratings: -
Picture of Philipp Hager
Re: Displaying information to users on redirect
 

This is indeed very usefull.


You could also extend the messages with little close buttons/icons, so the user can dismiss them from the view, if he wants to read something on rather smal screens, or for some other reason.

Maybe that's more of an change request for notification-rendering itself, but it just came to my mind. Bootstrap already features dismissable alerts (I don't know if moodle loads bootstraps JS files also). Just a spark of an not-really-thought-through idea smile

Ressource: http://getbootstrap.com/components/#alerts-dismissible

 
Average of ratings: Useful (1)
Picture of Andrew Nicols
Re: Displaying information to users on redirect
Group Core developersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

Hi Phillipp,

As it happens, I have already added the close buttons and made the alerts dismissable using the Bootstrap JS smile Whether these are shown is configurable  from the renderable.

I have also added some aria assertiveness.

Andrew

 
Average of ratings: -
Dan at desk in Moodle HQ, Perth
Re: Displaying information to users on redirect
Group Core developersGroup Moodle Course Creator Certificate holdersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

1. The idea itself makes sense and I recall a number of previous discussions of the same idea over the years (I have been trying to find one thread in particular on this topic but have so far been unsuccessful.) The earliest discussion I can find of this concept is this one from Petr proposing the same idea 10 years ago, and Mark Nielsen implemented a patch for it in MDL-6470 (i'm sure there was further Moodlerooms work on it at a later stage too, but I can't find it).


2. As you predicted, I do not like the naming \core\flash at all. As Tim Hunt wrote in the developer chat recently:

>When thinking about names, it always helps to think about how generic the words are. E.g. instance has very low semantic content. workshop is higher, but not very high within the workshop namspace.

In this case, the addition of the word 'notification' would help a great deal.

 
Average of ratings: Useful (2)
Picture of Andrew Nicols
Re: Displaying information to users on redirect
Group Core developersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

Hi Dan,

Thanks for the links to the older discussions.

The issue I raised was back in 2011 and I was surprised that no other issues existed discussing that functionality already (at least, none that I could find).

Regarding the naming I had been trying to keep the naming short, and to the point, but as you point out it needs to be understandable at the same time. Concatenating two words is probably the best option, so how about something like:

  • notificationflash
  • flashnotification
  • flashnotice

I think my preference is for flashnotification, or possibly flashnotice.

Cheers,

Andrew

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Displaying information to users on redirect
Group Core developersGroup Documentation writersGroup Particularly helpful MoodlersGroup Plugin developers

The think about all these names is the word 'flash'. I don't think I have ever seen it used in this context.

What it is, is a notification, or a message, to the user. In Moodle, messages are something else, so that seems out.

We use notification in other ways (e.g. $OUTPUT->notification) but this is similar. I would go with notification.

 
Average of ratings: -
Picture of Andrew Nicols
Re: Displaying information to users on redirect
Group Core developersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

Hi Tim,

As I mentioned before, sadly `notification` on it's own is currently out. This is my preferred option, but it's currently in use by core/notification for AMD dialogues.

That said, we could move the existing notifications to core/dialogue and provide a deprecation layer. That would kill off this really annoying technical debt now in 3.1 while it's not used too much.

Thoughts?

Andrew

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Displaying information to users on redirect
Group Core developersGroup Documentation writersGroup Particularly helpful MoodlersGroup Plugin developers

notification is not used anywhere in Moodle php code. I had not spotted that it was used in JS, but if so, I agree it should be cleaned up.

 
Average of ratings: Useful (1)
Picture of Andrew Nicols
Re: Displaying information to users on redirect
Group Core developersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

Thanks Tim,

I've renamed notification -> dialogue and added a b/c layer with deprecation notice.s

I've then renamed flash -> notification.

This seems like the optimum result smile

 
Average of ratings: -
Me!
Re: Displaying information to users on redirect
Group Core developersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers
Hi - I just had a conversation with Andrew about the naming and I disagreed with the proposal.

People are starting to use AMD more and more, and the notification.exception is used very heavily - there is no real benefit in making everyone change from notification to dialogue - and it's actually wrong IMO. (The fact that the exception is displayed in a dialogue is an implementation detail. The purpose of the function is to display a notification). notification has 3 methods in it - and 2 of them are perfectly correct, "confirm" is not really a notification, but is similar enough to the other 2 to leave it where it is IMO.

In the CBE code, we have a new dialogue amd module on the way (that wraps the yui dialogue) and is a real dialogue (I want to open an window and put content into it).

A better solution would be to merge these flash messages functions into the existing notification module and not deprecate/move anything.
 
Average of ratings: Useful (2)
Tim at Lone Pine Koala Sanctuary
Re: Displaying information to users on redirect
Group Core developersGroup Documentation writersGroup Particularly helpful MoodlersGroup Plugin developers

Yes. A namespace / core subsystem is a relatively large thing. No problem having the different types of notification in one namespace.

 
Average of ratings: -
Picture of Andrew Nicols
Re: Displaying information to users on redirect
Group Core developersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developersGroup Testers

Thanks Damyon,

I've merged the JS notifications so they're all in one file once more.

Hopefully this finalises the naming issue, and we can push this forward towards integration.

Andrew

 
Average of ratings: -