New Feature Request: Add onReady Solution Property

Forum to discuss the new web client version of Servoy.

New Feature Request: Add onReady Solution Property

Postby sbutler » Fri Jul 01, 2016 9:23 pm

I've created a new feature request in Servoy's ticket system. You can view the details and on the right, click "Vote for this issue" to help add priority if you feel this would help you as well. https://support.servoy.com/browse/SVY-10107

Description:

We need something similar to the jQuery ready function. In angular, the equivalent would be something like the code below. I would like it to be a solution property, like onSolutionOpen, but would be named something like, onReady. It would also pass in the URL as the first argument, so you can retrieve any URL parameters needed.

Code: Select all
angular.element(document).ready(function () {
     $scope.handlers.onReady(window.location.href);
});


Example Use Case:
When implementing logic that take in URL arguments, like a Forgot Password, there isn't enough functionality to correctly handle the situation. So if you send the user a secure link to reset their password, like: http://myserver.com/solutions/mySolutio ... myArgument , the onSolutionOpen, onShow, and onLoad will only run once. So if the user closes the browser window and clicks the link again, no event in Servoy is fired.
The onReady event example above fires every time the application is shown in a browser window, even if the user closes and reopens, or clicks the refresh button.
Scott Butler
iTech Professionals, Inc.
SAN Partner

Servoy Consulting & Development
Servoy University- Training Videos
Servoy Components- Plugins, Beans, and Web Components
Servoy Guy- Tips & Resources
ServoyForge- Open Source Components
User avatar
sbutler
Servoy Expert
 
Posts: 759
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH

Re: New Feature Request: Add onReady Solution Property

Postby sbutler » Fri Jul 01, 2016 9:26 pm

The current work-around to this is using an NGComponent like below to do this. Its a bit clunky because you have to drop the component on your form and assign the Servoy method you want to run in order to get the event to fire. Would be more clean implemented as a Solution level property.

onReady.html:
Code: Select all
<!-- onReady Container -->


onReady.js:
Code: Select all
angular.module('baseuiOnReady',['servoy']).directive('baseuiOnReady', function() { 
    return {
      restrict: 'E',
      scope: {
         model: "=svyModel",
         handlers: "=svyHandlers",
         api: "=svyApi",
         svyServoyapi: "="
      },
      controller: function($scope, $element, $attrs) {
         angular.element(document).ready(function () {
            $scope.handlers.onReady(window.location.href);
         });
      },
      templateUrl: 'baseui/onReady/onReady.html'
    };
  })


onReady.spec:
Code: Select all
{
   "name": "baseui-on-Ready",
   "displayName": "onReady",
   "version": 1,
   "definition": "baseui/onReady/onReady.js",
   "libraries": [],
   "model":
   {
   
   },
   "handlers":
   {
      "onReady": "function"
   }
}
Scott Butler
iTech Professionals, Inc.
SAN Partner

Servoy Consulting & Development
Servoy University- Training Videos
Servoy Components- Plugins, Beans, and Web Components
Servoy Guy- Tips & Resources
ServoyForge- Open Source Components
User avatar
sbutler
Servoy Expert
 
Posts: 759
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH

Re: New Feature Request: Add onReady Solution Property

Postby jcompagner » Mon Jul 04, 2016 12:04 pm

why don't you use a service for this?
That is the easiest and very clean

do try to avoid "window" (use $window) so for document use $window.document
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Re: New Feature Request: Add onReady Solution Property

Postby pbakker » Mon Jul 04, 2016 3:03 pm

Scott,

Can't you handle your use-case with http://myserver.com/solutions/mySolutio ... myArgument
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Re: New Feature Request: Add onReady Solution Property

Postby sbutler » Mon Jul 04, 2016 6:15 pm

jcompagner wrote:why don't you use a service for this?
That is the easiest and very clean

do try to avoid "window" (use $window) so for document use $window.document


I first thought of a service. However there are 2 problems with that.

1. There isn't any way that I know of in the Servoy API to somehow allow the user to assign the Servoy method to the handler. So if I used a service, I would have to hard code the Servoy method name it runs, which I prefer to avoid. So using the component, it can be placed on a form, and then the user can assign their Servoy method to the handler.

2. I could have made an API call in the service, like setHandler that the user could call, and set what Servoy method they wanted. Then I would call it. However, that wouldn't be reliable I think. When would the user trigger that to run? Maybe onSolutionOpen, but would that fire before the onReady in the service? Seems to capable of reliability issues since the handler would be set at runtime instead of design time, and maybe not set soon enough in all situations.



pbakker wrote:Scott,

Can't you handle your use-case with http://myserver.com/solutions/mySolutio ... myArgument


2 problems with that.

1. That only works if the solution doesn't require login. The onOpen event will run on the Login Solution on first launch. You could make a special solution, not requiring login, but I think that would still be a bit of a security hole. I need to trigger an event on the link but in a login solution.

2. That doesn't handle the user clicking refresh on their browser. Servoy rewrites the URL after that loads, so a browser refresh wouldn't trigger the method to run again.


You could make an argument that the onShow function should really work the way I'm describing onReady. For example
- User opens a session, form shows. onShow runs.
- User closes the tab in their browser.
- User opens another tab, loads the solution again. Their session state remains, and the form they left off on is shown to them. However the onShow doesn't run! Its always been that way, dating back to the first version of the WebClient.

So, I didn't want to request a feature that would break existing functionality, in case some users rely on the onShow not running. However, if you think of normal web development, everyone uses the onReady style, so if the user has multiple windows, close and reopens, or does browser refreshes, your event will always run.

In simpler terms, think of it like this. There is no way in Servoy to always have a method run every time some form is shown to the user.
- onShow doens't run if the user clicks refresh, or closes and reopens tabs in browser
- onSolutionOpen only runs first time opening
- Using method args in the URL only run if they click that url, not if the click refresh, or closes and reopens tabs in browser.

For developers coming from other standards based Web Development backgrounds, that concept is pretty confusing. We should really have some event that more closely matches the jQuery onReady style event. Especially since the ngClient is Web only! I could understand not doing it in the Web/Smart client since apps were built for both desktop and browser. However the ngClient is Web Only, so we should really conform to standards that web developers are used to.
Scott Butler
iTech Professionals, Inc.
SAN Partner

Servoy Consulting & Development
Servoy University- Training Videos
Servoy Components- Plugins, Beans, and Web Components
Servoy Guy- Tips & Resources
ServoyForge- Open Source Components
User avatar
sbutler
Servoy Expert
 
Posts: 759
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH

Re: New Feature Request: Add onReady Solution Property

Postby jcompagner » Tue Jul 05, 2016 9:38 am

first don't use a api call
because that would be bad because then you will loose your state again
It should be a model property

{
callback: "function"
}

and in solution open the user can just set that property on the service

at the client side when the service is initialized and the model already has that property set call it directly
if not set then make a watch on it and when it is changed (set) call it.

If the page would be refreshed (f5 in browser) then the model is pushed again and you can call it right away gain.
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8833
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet


Return to Servoy NGClient

Who is online

Users browsing this forum: No registered users and 16 guests

cron