AuraQ / AutoCompleteForMendix

An autocomplete widget for mendix
Apache License 2.0
8 stars 31 forks source link

Request: Add Microflow as datasoruce #15

Closed rrachuri closed 7 years ago

rrachuri commented 7 years ago

Hello,

Thanks for the great widget. I was wondering if it is possible to add Microflow as a data source to this widget.

Currently, the widget lets you constrain the data using 'xpath' and 'constrained by' but we cannot use them to filter data based on variables.

Below is an example of my use case:

I have a "CourseLookup" entity with attributes role type and associations to ScheduledCourse and LocationLookup. When a user wants to add a course, I want to filter the CourseLookup data based on the user role (user.UserRole=CourseLookup.RoleType), DateEnrolled (Course.DateEnrolled < ScheduledCourse.EndDate) and the state (User.State = LocationLookup.State) to which the user belongs.

image

Also, I noticed that the OnChange event is firing twice when there are multiple AutoComplete widgets.

Any help on this would be greatly appreciated.

lindski commented 7 years ago

Apologies for the delay in picking this up

Sourcing from a microflow should be possible but its a fair bit of work so probably not something I can look at for a little while.

I haven't seen the OnChange event firing twice for multiple instances... what version of Mendix are you running? Do you see the same behaviour in this repository's test project?

lindski commented 7 years ago

Hi, found a bit of time so have added support for searching via a microflow in this v3 branch.

There are still a couple of other enhancements I want to add in v3 but feel free to take a copy of the widget from the test project to try it out.

stephanbruijnis commented 7 years ago

Hi Lindski,

Good to see that you are still developing this widget! I've opened the v3 branch widget, this version has a search microflow which is executed on search. I was hoping for a version where you can select a microflow as DataSource and let the widget search within the results of this datasource microflow (instead of firing a microflow on each search). Can you tell me if you plan to develop this as well?

Much appreciated!

lindski commented 7 years ago

Hi Stephan

I hadn't thought of that as a possible use case until now but can certainly take a look... is there any reason why you want this particular functionality rather than executing the microflow on search?

Only concern I have with this would be performance when there are a lot of records.

Cheers!

iain

stephanbruijnis commented 7 years ago

Hi Iain,

Yes that is my main concern as well. The current flow used to determine the selectable objects is already quite heavy (selecting records from large tables). The app where I want to use the widget is used to enter orders, the forms with this widget will be used a lot. If it can be added as a feature that would be a great help!

Cheers Stephan

lindski commented 7 years ago

Hi Stephan

Ok cool, I understand. Let me have a look... for widget configuration I might just add an additional option of 'Cache Microflow Results'... when this is set to true, the search microflow is run once, on initialisation, and then uses the local cache, otherwise it runs the microflow for every search.

Cheers Iain

stephanbruijnis commented 7 years ago

If I understand correctly: The microflow should run on initialisation and update (if context is refreshed).

After the user enters some characters as search param. they should be filter the cached microflow results. That would be awesome =)

lindski commented 7 years ago

Hi Stephan

This took a bit longer than I'd hoped but I now have a version available that caches the results from a microflow.

The cache gets set when the widget is first initialised and is refreshed if the context changes. Any input from the user then runs the search against the local cache of objects.

I have split out the search into three types: XPath, Microflow and Microflow (Cached) which should (hopefully!) make it a bit clearer when configuring the widget.

I still want to add some more tests and update the documentation but if you wanted to have a look you can grab the version from the test project.

Cheers

Iain

stephanbruijnis commented 7 years ago

Nice, thank you! I will test it next week.

lindski commented 7 years ago

I have just made another update to the widget to include support for non persistable entities. This wasn't relevant before when we only supported XPath but now we support microflows it made sense to add it.

I couldn't find a way to identify whether an object is persistable or not to validate the widget config when XPath is selected so will make sure I add a note in the documentation.

Latest version available from the test project

stephanbruijnis commented 7 years ago

Thanks for the updates! They work great! The microflow (cached) even has a better User Experience than the xPath/Database implementation. The xPath does a refresh or something after entering a search parameter, which causes the list to 'flicker' microflow (cached) doesn't have this issue.

lindski commented 7 years ago

We found a couple of issues with this... the cache was being reloaded when the association changed (should just change with an object refresh) and searching against the cache wasn't case sensitive.

The above should be fixed in the latest commit

I'm also going to add a parameter that allows you to control whether to refresh the cache on an object refresh (there may be instances where you don't want to do this)... this will be an optional parameter and, if used, the developer can select a boolean attribute in the data context object.

lindski commented 7 years ago

V3 now available from the appstore

https://appstore.home.mendix.com/link/app/2695/AuraQ-Limited/AutoComplete-widget