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

Registering routing at component level #687

Open
drigolin opened this issue Oct 27, 2018 · 2 comments
Open

Registering routing at component level #687

drigolin opened this issue Oct 27, 2018 · 2 comments

Comments

@drigolin
Copy link

drigolin commented Oct 27, 2018

Frequently we are facing the issue to integrate a javascript library/componets into Prado and most of those use "simple" rest api call to interact with backend. Most of the time I wrap those call with a Prado Callback call but I was thinking that can be good to have a Prado Page and any components to handle a rest call (GET/POST) internally simply registering a route "relative" to the page where the component is placed.
As exampla:
A component during init can do something like:
$this->registerRoute("/datatable" + $this->getControlId() + "/getdata", **a callable **); Callable can be also a method/event of the component. PageState/ComponentState can be an issue, maybe can be passed as request paramenters or those handler will have limited access to pagestate.

if this component is inserted into a page with friendly-url enabled
/myapp/page/mypage

the rest call to url
/mypage/page/mypage/datatable/dt1245/getdata

will be handled by the specific code of the component.
This approach can make easier handling integration of third party library or manage some asynchronous loading of component contents or having only small part of the page code executed. To make things more complex a "page state" can be passed or not depending if the component need to interact with other components or not.

I would like to share my idea with the community to have feedback and suggestions and have opionions from more valuable developers.

@ctrlaltca
Copy link
Member

This is a quite common need while developing applications using 3rd party components.
I usually took one of these routes:

Response data

Using a prado callback to make the request and ResponseData to return the data, that then will need to be parsed in javascript, as implemented in TJuiAutoComplete.

  • pro: controls input and pagestate gets handled correctly, so you can use user-supplied values from controls and return the appropriate data.
  • con: as slow as a normal callback with full pagestate loading/saving, controls instantiation etc.

External service

Adding an external service in application.xml (eg. TJsonService, TSoapService, ..) that exports a few methods that will be called directly by javascript using ajax.
From the server-side point of view of the TPage, it's like no request was actually made.

  • pro: fast to load, no pagestate / page instantiation needed;
  • con: no handling of control inputs and pagestate, so you'll need to pass any needed values in the ajax call;

The solution you propose is intriguing, being a mix of these two approaches.
Prado has quite a rigid structure to handle responses (service -> page -> response), but thanks to the use of adapters it should be easy to implement this.
Adding a new "datatable" postback mode (current modes are postback and callback), a TDataTablePageAdapter to handle events and a TDataTableResponseAdapter to render the response.. it could work!

@drigolin
Copy link
Author

drigolin commented Oct 29, 2018

Hi @ctrlaltca "DataTable" is a very bad name :-D
I was thinking to somenthing like:

  • RESTBack isRESTBack?
  • RouteBack ?

I was thinking to that new approach to be able to integrate very well javascript framework like Vue.js or Angular.
In that way we can have the same fantastic event based structure of Prado from backend to frontend and the web component architecture of Prado can make very easy having reusable web component at frontend and backend level.

I was thinking to have somenthing like a TAngualarPage or TVueJsPage to make SPA development very easy using prado component template syntax to reuse both js code on frontend and php code on backed for event based processing of events.

But in the mean time let's simply start with a datatable...

@ctrlaltca ctrlaltca changed the title [ENH] Registering routing at component level Registering routing at component level Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants