pwFoo Posted October 21, 2014 Share Posted October 21, 2014 Tried the dev branch and also the SystemNotifications module. Is there a documentation how to use it? How to use it for frontend users? Link to comment Share on other sites More sharing options...
Soma Posted October 21, 2014 Share Posted October 21, 2014 Nope, It's not even finished. Link to comment Share on other sites More sharing options...
pwFoo Posted October 21, 2014 Author Share Posted October 21, 2014 Hi Soma, I know it's under development. I want to do some tests But I'll wait until it's usable. 1 Link to comment Share on other sites More sharing options...
ryan Posted October 21, 2014 Share Posted October 21, 2014 Soma's right this is still in development, so things may change and it's too early to write up docs. But here's the basic concepts that probably won't change: Display notification on next request (these work whether SystemNotification is installed or not, but the output is of course different): $this->message("Message to display"); $this->warning("Warning to display"); $this->error("Error to display"); If outside of an object context, you'd replace $this with wire(). These notifications (above) have been with ProcessWire since the beginning (except for the warning one). The SystemNotifications module continues the same strategy and extends it. It enables notifications that go beyond just simple "display once on next request" notifications. It also enables you to send notifications to any user, regardless of whether they are logged in (they'll get the notifications when they next login). If the user happens to be logged in, they'll get it immediately–it will pop up on their screen without them even having to load a page. To use these persistent notifications you have to send them to a user ($user = any user): $user->notifications->message("Message to send"); $user->notifications->warning("Warning to send"); $user->notifications->error("Error to send"); $user->notifications->save(); // this is required to commit them They also have a Javascript API, for sending immediate notifications to the current user. These particular notifications do not persist across requests, so they are more like a JS-version of PW's "display once" notifications, except that they display immediately. Notifications.message("Message to send"); Notifications.warning("Warning to send"); Notifications.error("Error to send"); There's actually a lot more to it, as each notification can have various different flags and properties. Notifications that persist across requests can also be modified, which is great for things like progress bars or other kinds of state changes. Further, they can contain any amount of "details" content, even entire HTML blocks. This is all stuff we'll cover once these are finalized. 1 Link to comment Share on other sites More sharing options...
pwFoo Posted October 21, 2014 Author Share Posted October 21, 2014 Hi Ryan, thanks for your answer Notification demos work fine, but how I have to initialize the module to work in the frontend? Add notifications to the admin works fine. $notify = $users->get('<username>'); $notify->notifications->message("Just a test!"); $notify->notifications->save(); But haven't found out how to add the ajax messages to the frontend too. It' very interesting and a really nice feature. Great work! Link to comment Share on other sites More sharing options...
pwFoo Posted October 21, 2014 Author Share Posted October 21, 2014 At the moment it's seem to be ajax polling notification. Is additional a websocket connection planned / possible? Link to comment Share on other sites More sharing options...
ryan Posted October 22, 2014 Share Posted October 22, 2014 Notification demos work fine, but how I have to initialize the module to work in the frontend? The notifications are part of the admin. PW doesn't get involved with your front-end output, so it's not attempting to provide anything with regard to notifications on the front-end. However, you can still use the API to add notifications to any user, but they'll need to go to the admin before they will see them, unless you provide your own output code on your front-end. If you wanted to output notifications on the front-end of your site, it would actually be as simple as this: foreach($user->notifications as $no) { echo "<p>$no</p>"; } There are of course several other properties, methods and flags that you can access from the Notification ($no) object. But outputting a notification is basically just a matter of iterating through the $user->notifications field and outputting them all, or just the ones you want. So in this sense, it actually would be quite easy to utilize on the front-end, but like with anything in PW on the front-end, you have to decide how you want the output to be handled. At the moment it's seem to be ajax polling notification. Is additional a websocket connection planned / possible? Currently it's using the same method as the forum we're typing in (IP.Board). I have not kept up with websockets technology lately, but was under the impression we weren't there yet unless you had specific client-side and server-side libraries to handle it and provide the fallbacks, or were using node.js, etc. I'd gladly implement websockets in the future if they enable us to accomplish the same thing more efficiently, easily and reliably without bloat. Last I researched this, we weren't there yet, at least in our LAMP context. But you likely know more than I do about that technology at this point, so interested in hearing more. 3 Link to comment Share on other sites More sharing options...
pwFoo Posted October 22, 2014 Author Share Posted October 22, 2014 Hi Ryan, thanks. Websockets sounds interesting, but You're could be right to wait until it's more effiecient and easy. So may be it's a future option. If I do some tests I'll report it here, but don't know if I have the time to do it To use php for notifications is fine, but also would love to use ajax notifications in the frontend. First tests no javascript was load by the notifiactions module. Notifications.message("Message to send"); Notifications.warning("Warning to send"); Notifications.error("Error to send"); So I'll wait for the js api documentation to see how it work. Link to comment Share on other sites More sharing options...
sforsman Posted October 22, 2014 Share Posted October 22, 2014 @pwFoo: WebSockets are an overkill for something like this - they are designed for distributed messaging between multiple concurrent users for web applications that work in real-time. For this same reason, they require a special server designed for the purpose - the best currently being something running on top of node.js (like socket.io), a language which was designed for things like this from the ground up. Erlang would be another choice (it even has a socket.io port). In other words, you cannot handle WebSockets with just Apache and mod_php5. Ok, you could always run a PHP-based WS daemon like Ratchet, in the background, but I'm personally not a fan of PHP-based TCP-daemons. They are good for toying with new concepts though. And yes, I do know about the guy who wrote an SSH2 server with PHP, but still, you and I both probably stick with OpenSSH I don't even see this happening for quite some time because Apache was never designed for this kind of purpose. Neither was PHP. 1 Link to comment Share on other sites More sharing options...
adrian Posted October 22, 2014 Share Posted October 22, 2014 I thought about doing realtime with PHP using http://elephant.io/ but ended up going with nodejs and meteorjs. I hate being away from PW, but sometimes you gotta do whatcha gotta do Link to comment Share on other sites More sharing options...
sforsman Posted October 22, 2014 Share Posted October 22, 2014 I know what you mean adrian! And I have to admit, I've been in love with meteor.js for quite a while - but they were in alpha and beta for ages and I missed my chances of using it in production Link to comment Share on other sites More sharing options...
pwFoo Posted October 22, 2014 Author Share Posted October 22, 2014 I found php-websockets and would do some tests... https://github.com/ghedipunk/PHP-Websockets Link to comment Share on other sites More sharing options...
sforsman Posted October 22, 2014 Share Posted October 22, 2014 I found php-websockets and would do some tests... https://github.com/ghedipunk/PHP-Websockets It doesn't matter which PHP-based project you use because the concept stays the same - you still need something running in the background of the server, listening on a socket. If you really want to play using PHP, just use Ratchet. It's a lot more mature (meaning fully documented for an example). Link to comment Share on other sites More sharing options...
pwFoo Posted June 18, 2015 Author Share Posted June 18, 2015 Hi Ryan, any plans in the near future with the notifications module? I plan to use it for simple (ajax) user notifications in the frontend. So I would build a process module and some JS code to use ajax user notifications based on SystemNotifications. $user->notifications Regards 1 Link to comment Share on other sites More sharing options...
valan Posted February 26, 2016 Share Posted February 26, 2016 I'd like to add FB-like messages and notifications to PW admin menu. FB-like means: - admin frontend: js script that each min sends ajax requests to the server and depending on response, updates admin menu item element of DOM. Messages and notifications behave similarly to what we have at FB. - backend: script(s) that processes ajax request and return notifications data. Notifications data is stored in user template. Just to give you an idea re notifications, few examples of notifications that gets some user with "sales" role: - System Task: Prepare quote for order 23451 - System Task: Callback to user 54321 at 12pm - System Info: Order 98567 has been cancelled - User Message: Hey, bro can't find you contact. Please call me. - etc... Qs: 1. what would be a "right" way to add such "non-PW" menu item to admin menu? Hook during admin menu rendering? 2. there is pre-installed notification field in user account. I'm interested to understand if I can use it w/o custom coding OR extend existing core classes? Where to start digging? or where I can read more about it? Link to comment Share on other sites More sharing options...
Mike Rockett Posted September 2, 2016 Share Posted September 2, 2016 I'd like to use this for Jumplinks 2 (instead of an annoying popup), but every time Notification.message is called, the ghost popups keep incrementing. Eventually, sending one notification shows all the notifications that haven't been read from the pull-down yet. Any way around this? Link to comment Share on other sites More sharing options...
Mike Rockett Posted September 2, 2016 Share Posted September 2, 2016 Update: This doesn't change if I open the pull-down... Link to comment Share on other sites More sharing options...
adrian Posted September 2, 2016 Share Posted September 2, 2016 1 minute ago, Mike Rockett said: I'd like to use this for Jumplinks 2 But what if it's not installed? I am guessing you will revert to a popup? I am sure you won't, but please don't automatically install it Link to comment Share on other sites More sharing options...
Mike Rockett Posted September 2, 2016 Share Posted September 2, 2016 2 minutes ago, adrian said: But what if it's not installed? I am guessing you will revert to a popup? I am sure you won't, but please don't automatically install it Just figured I'd use it if it's installed... In this case, it's the jumplink state toggler (enable/disable), so the notification is a nice-to-have, but won't show if Notifications is not installed. 1 Link to comment Share on other sites More sharing options...
Mike Rockett Posted September 2, 2016 Share Posted September 2, 2016 Okay no, I think I'm going to skip this. Will use a subtle animation in the row to show that the state has changed. 1 Link to comment Share on other sites More sharing options...
Recommended Posts