-
Notifications
You must be signed in to change notification settings - Fork 251
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
Client and Server parts separation. Better API support. #31
Comments
@servocoder this all sounds great to me! apiConnector seems like a good name to me, but if anyone has a better suggestion I'm game for that too. If it's ok with you, I'm going to add a bit to the API documentation on the wiki this week as I work through these as well. I had to do quite a bit of trial and error to figure some stuff out, then I realized it would be good to just add it to the documentation to make developers working on other connectors lives easier(hopefully anyways). |
@jlaustill Sure, It would be great to have clear and detailed API for developers. Thanks for your contribution. |
Hi, I think it's a very good idea to separate client and server (separation of concerns) but (there is always a but ) During the last 3 weeks, there were at least 2 commits that broke API's connectors (in minor version change), this is not good. I think we should avoid breaking the API, I would even say that , we must never change the API (on a minor version change). That gives an instability impression and in the long run, there will only be the PHP connector up to date. I suggest :
I will separate the discussion in 4 points :
What do you think of this approach @servocoder @jlaustill @gmkll ? |
@fabriceci I think that is a FANTASTIC idea! The more I'm getting into this the more a new major version seems extremely appropriate! |
I agree to create dev repo. |
@servocoder no worries, the concern isn't about forcing us to update our connectors, but more so about the public appearance of our stability in the master branch that other people will download. I highly encourage you to code like hell in the new dev branch and force us to keep up as long as we are going down the route of more standardized code and a better, more stable future :) |
@servocoder no worries, I didn’t say that for my case. We should reach a state where a connector should almost never be updated. To have a more standardized API or even to finish the way you started (the complete separation between the client and the server), there will be other steps that unfortunately will break connectors. That's why I proposed to make this time a big step and open a discussion on a major new release (divided in 4 themes). We can work slowly in the dev branch or create another one without disturbing the current version) Do you have an opinion about that? |
In order to be in a place where the connectors rarely need updated, the codebase will need to be in a very consistent, standards-based place. I think that consolidating the ajax requests into two functions, apiGet, and apiPut, will bring to light a lot of the places that are currently inconsistent. servocoder's last commit was a nice step in this direction. He consolidated the url generation into one function. I will bring this into the example apiGet function I wrote in the next few days. Another step in the right direction would be following the REST api json standard, found here. Basically, this would mean returning objects that looked like this
and then the consolidated ajax functions would have a standard way to deal with errors. Basically, if (doc.errors) { In this format, the errors array only exists if there are errors, so it's super easy to deal with them. Then pass back the data. This also makes dealing with the errors and data in your api at lot easier. There is a lot more to the standard, but that is the basics. This kind of a change should absolutely happen in a dev branch, one endpoint at a time. Currently, I think there are a few bugs we should concentrate on to get the existing code stable on the main branch. Then work on the new changes in dev. But I'm curious to see what your thoughts are on that y'all :) |
Ok, I have updated repo to v1.0.6 and it's a stable release. |
@fabriceci Please confirm that I can remove @jlaustill I have created new issue #37 for json API standardization, can you take a lead and, perhaps, come with a new PR on that? |
@servocoder absolutely. I'll start by getting the functions set up, but I have one question first. The entire filemanager.js is in a function, and therefore has its own scope. But I would still like to put new functions in an object so it is more obvious what is being used and to have less of a chance of conflict. For my example, I went with the name var _$ = {}; But I can go with any name at all, other options I can think of are Do y'all have a preference? |
@servocoder yes indeed. @jlaustill When I read your question, I though, as we are in the big step, I'm not a ninja in JavaScript, but I saw that's a good practice to put the plugin functions into a single object (prototype), especially for testability. First, standardize the API, and then think about what we can improve in the JS (and for now just create a object function like the others) What do you think?
|
Well yeah, I also have some thoughts about how to keep the FM plugin, I even would go further and make some of FM functions public and so on. But let's be consistent and postpone all this stuff for now. We have more important things for now like API standardization, config file division and so on. This subject is interesting but we will consider it after the main stuff is done. |
Yeah, I don't think I explained myself very well here, sorry. I was referring to an internal object, one that would be internal to the fm object you coded an example of @fabriceci . The object I'm referring to would live inside that object, like so ` var fm = function (options) { ` The purpose of the object would be purely to contain functions written as utilities for fm verses functions of fm. So this is very simple and just cleans up the code. Sorry if I made this seem like a much bigger scope thing :) |
@jlaustill Which functions/variables you are going to put to that internal object? Give a few examples, so I can get your point better. |
For sure. Basically, anything that is a utility function, and reused internally. I think of it as my libraries personal jquery. So a few examples just looking through the code would be _$.isDocumentFile But things that would not belong in this object would be the unique functions of fm itself. In the future, these may be functions you expose as public for instance, or maybe not. var selectItem etc etc. These unique functions would use the utility functions. The gain is twofold, first, it is obvious when making changes to, say, _$.apiGet, that this change will affect the code all over the place, and not just in that function. Second, it's a beginning to work toward OOP principles and start to define scopes, just a tiny step in that direction. For now, I only want to put the new functions I write into it, thus ensuring that I don't cause any side effects with existing code, and to make it clear what has been moved and what hasn't down the road as we start to implement the new consolidated api features one endpoint at a time. I am really bad at describing things without a whiteboard, thanks for your patience 💯 |
@jlaustill Thanks for the explanations. |
I think it not off topic to let you know, that I have started some ajax call refactoring using deferred promises in PR #21. I started with changes in loading configurations as this should of course happen before any other calls (this includes calling the file_exists function as a promise). Non synchronous calls are much more standard conform. I also started to put most stuff in a scoped object "fm", but will remove this from the PR, as @servocoder suggested to not interfere with any other ongoing changes, as I understand previous comments here. I support the proceeding here, which is much more thorough than mine to be sure! But I will invest some more effort, if it´s worth doing, to merge the recent changes into the PR´s filemanager.js as well the Java Connector. I´ll need about 1-2 days to get it finished. Any ideas about this? |
@gmkll can you provide an example of your ajax deferred promises? I would like to see how you are doing that. Promises are sort of a new thing in my world that I have avoided because of browser support. I tend not to use things until they are extremely well supported. So this could be a great learning opportunity for me. |
just have a look at my forked repos fm.js! I use jQuery.Deferred() types. I think it is a bit tricky at the beginnig, but if you get it, things work very well. I regularily use it in my client side code. The nice thing is, that since jQuery 1.5 $.ajax is a promise itself. You have to get used to work with states, which are linked to deferred objects. The state is pending, until it´s resolved, which you could control yourself or you get it set as in |
@gmkll oh wow, that looks freakin awesome, I guess I know what I'm learning today! |
I have an issue concerning
BTW Thanks for your structuring comment, @fabriceci! May be the 4 points should become tags/labels? E.g. "API change", "client and server separation", "refactoring", the last is already one. In the API it´s mentioned, that "readfile GET is intended to use when it's not possible to get file by direct URL (e.g. protected file)." I still think, FM should be able to support both at least for selectItem, although it may be not more the case (see discussion links below). In the first case the connector would provide a URL (relative or not, by default I would assume it´s ready to use), in the second case, its an API call to the connector (mode "readfile"). @servocoder made the point, that it may be too complicated for the frontend developer to decide, what to do (cft. comments in issue #27, this, this). But I think, it could easily be resolved, if (at the core) the item property "protected" is evaluated. In case of The workflow would be:
In all other cases the server´s API calls are used. I think, its a reasonable workflow. What do you think? I could think of an extra property externalPath, but this would break the API. More Info
|
Yeah, it was in that way. Now And don't care of
Btw, what is the issue? I can see only suggestions. |
I agree totally with
The Java-Connector does not yet support any authorization mode, but it may be, some work seem to be in progress? At least - Sorry, the "I have an issue" statement just means I want to discuss more about this topic ;-) |
and
look as opposite statements ) |
I could live with the client side option only. A relative direct URL would just be any relative (normalized) URL based on document root, but not to the FileManager. If selected the client (Tiny/CKEDITOR...) has a FileManager-independent (relative) URL to the image/file. It´s true, you have then lost one indirection, and the image has to be matched on the server (where the client editor lives). Nevertheless, it seems to me, that´s not a very uncommon use case, but feel free to point me to better/other solutions. |
I completely forgot : that's the reason why I needed an absolute path. @servocoder when you select a file in the file manager through a WYSIWYG, the file manager should return the direct URL (in almost all cases). The most obvious case when you need to select an image/file is when you are in a CMS environment. Get an image through a connector is heavy for the server . If the website's traffic is high, that will be very bad for performance, a server language is not good to serve files. I think the cleanest solution is to make an additional Ajax request when you click on the select button. The manager will ask "can I have the select path" to the server and the connector will be able to decide what path it return (relative or not). What do you think of this? |
@servocoder, what about in my last post? Without this I'm stuck on a old version :( ! What do you think to add an ajax call for the select function? |
@fabriceci I am currently working on separation config files and thinking over the absolute path problem. I think the better option is to set preview mode (connector path VS absolute path) of the images and media files in the configuration options. So all the files paths will be treated in the same way. Here what I have come to in the config file:
If you perform your connector in the same way as PHP connector you probably saw that it's possible to change "userfiles" folder (root folder for user files). So one user may have his file as /sam/images/file.jpg and another one as /john/images/file.jpg. In the current version of FM you will get only "/images/file.jpg" part in the "Path" param of the response, so we need server to return that user-based folder name (/sam or /john) to build the correct absolute path. We have 2 options for that:
|
While writing the answer I have realized that the second option looks more complicated. Return "PreviewPath" in the response for each file seems a simplier solution. But "init" request may be useful to check some info from server or even override some config options at the client-side. Anyway I want to know what do you think on that. The main idea that I don't want to make "absolute path" feature exclusively for "select" feature. If you want absolute paths during the selection then I can suppose you want them all over the FM. That is why it should be defined in the config. The only thing we need is to choose the way how to get the last part for the absolute path from server. |
Capability to preview images and media files with absolute path along with connector path has been implemented at the dev branch. Since there were no suggestion I have come to the second option and that is how it works: You can see new section in the config file:
Absolute path enabled by default and works with the default FM files structure. |
Solved with the RichFilemanager release v2.0.0 |
Hello there.
Thanks to the explanations and ideas of @jlaustill and other contributors. I have made a number of modifications at the client side and PHP connector (API description will be adapted as well). The changes came from the point that FM client-side should be separated from server-side (connector) as much as possible. The lower conjuction the better. All developers and maintainers must follow this way while working on their connectors. The list of changes you can see below.
fileConnector
option from server-side;getinfo
response;One minor thing I also want to change is to rename
fileConnector
toapiConnector
option in config file, or something like that. The name should better reflect the meaning. Currently it's hard to understand whatfileConnector
is intended for from its title. Please, share your suggestion, if you have the other one for this option.Also I suppose
normalizePath
function could be removed from JS file because now connector should return relative path solely. But before do this I want to hear @gmkll, @fabriceci opinions on this, becausenormalizePath
was implemented initially for Java connector needs.@gmkll, @fabriceci, @jlaustill
Be aware of these modifications and welcome to discussion.
@gmkll, please update your PR to the last changes and will merge it.
The text was updated successfully, but these errors were encountered: