Select to view content in your preferred language

Config Communication between Settings and Widget

1907
6
Jump to solution
03-02-2018 07:55 AM
NikolasSchmidt
Occasional Contributor

I'm having trouble getting a json created in the settings.js to communicate with the actual widget.js in my custom widget.

I've got a widget I'm working on that allows the user to specify some settings when it's first created in the Web Appbuilder. When the settings is closed, it creates a json representation of the settings and replaces the (initially empty) config.json file with the new one. This appears to function correctly when I log everything to the console in the settings.js, but when I try to load the config from the widget.js, all I'm seeing is the initially empty json. I'm not sure how I'm supposed to go about overriding the getConfig and setConfig functions in the settings.js to get the new json to replace the empty one. As it stands right now, those two methods exist in the settings.js and look like this:

setConfig: function(config){ this.config = config; },

getConfig: function() { this.config.users = outFinal; return this.config; },

where outFinal is the json. This is also the argument being passed to setConfig.

Anyone have any support regarding something like this? Am I on the right track or going in a completely incorrect direction?

Thank you!

0 Kudos
1 Solution

Accepted Solutions
NikolasSchmidt
Occasional Contributor

Robert and all,

Sorry for the delay, some other more immediate tasks arose that needed to be dealt with. I've managed to get a functional version up and running in-house, and have made that version available on Github in addition to attaching it to this post. I'm very willing to admit that this isn't entirely perfect, or optimal, or anything of the sort, - merely functional - though I'd like to improve upon it when able. I figured that by posting it on Github if there were others who were interesting in working off of this template or altering it that they might be able to do so. I have no idea when I'll be able to go about fixing it up, but it does what we needed it to do for now.

If anyone plans on implementing this, go into the setting/Setting.js file and update the line below the TODO with your Portal URL, as well as an email address or other POC in the else clause in onOpen in the Widget.js file. Applications built with this need to be housed on another web server accessible to your users, and a link to that server needs to be created as an item in your Portal.

If there are any other questions about the widget or why I made any decisions that I did, feel free to ask.

-Nikolas

View solution in original post

0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Emeritus

Nikolas,


  First thing, are you aware that the config that is used after you have made changes to the widgets settings dialog is not stored in the widgets folder where the original config.json was? The correct file is in the apps configs folder inside a folder with the widgets name.

0 Kudos
NikolasSchmidt
Occasional Contributor

Hello,

For my custom widget, I have a config.json sitting in the directory

 .\arcgis-web-appbuilder-2.7\WebAppBuilderForArcGIS\client\stemapp\widgets\<widget_name> 

and the Setting.js in

.\arcgis-web-appbuilder-2.7\WebAppBuilderForArcGIS\client\stemapp\widgets\<widget_name>\setting 

The setting.html and setting.js pages are a series of checkboxes with options that, when checked, are stored in an array. I turn this array into a .json. I'd like to have this .json be referenced by the widget when it's running in an application, and have this selection be unique for every instance of this widget instantiated on any application. I intend to do this by writing over the config.json, which I'm assuming is unique to each and any instance. Is this a correct assumption, and does this seem to be an effective way of going about doing this? Does altering the this.config in setting.js directly alter the config.json for that instance of the widget, or for the whole widget template?

Thank you!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Nikloas,

I'd like to have this .json be referenced by the widget when it's running in an application, and have this selection be unique for every instance of this widget instantiated on any application.

OK, that is standard behavior so yes.

I intend to do this by writing over the config.json, which I'm assuming is unique to each and any instance.

Is this a correct assumption, and does this seem to be an effective way of going about doing this?

Yes but the config.json in the widgets folder is not the file that gets changed saved to it as I explained in my previous reply.

Does altering the this.config in setting.js directly alter the config.json for that instance of the widget, or for the whole widget template?

It is for that instance of the widget, assuming that your getConfig function in the Settings.js is returning the this.config var.

0 Kudos
NikolasSchmidt
Occasional Contributor

My apologies, I didn't see that config file during testing because I never actually saved the application, I just added the widget and tried to test it immediately. That's actually pretty stupid of me, but I digress...

The config json is now correctly being passed to that file, but the changes to that content are not. I initially set the json string to some meaningless value by default, and I update the information in it when the user closes the settings frame, during which time I also call the getter and setter. The instance's config file still contains the default, meaningless values. I haven't looked into this yet, but I'm assuming that I'm running into some issues with the order in which things are being called and executed.I plan on creating a button for the user to manually save the config as opposed to updating it when the user closes the settings. Any other suggestions would be greatly appreciated, however.

Thank you!

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Nikolas,

   Can you zip up your settings or the whole widget and attach it for me to look at?

0 Kudos
NikolasSchmidt
Occasional Contributor

Robert and all,

Sorry for the delay, some other more immediate tasks arose that needed to be dealt with. I've managed to get a functional version up and running in-house, and have made that version available on Github in addition to attaching it to this post. I'm very willing to admit that this isn't entirely perfect, or optimal, or anything of the sort, - merely functional - though I'd like to improve upon it when able. I figured that by posting it on Github if there were others who were interesting in working off of this template or altering it that they might be able to do so. I have no idea when I'll be able to go about fixing it up, but it does what we needed it to do for now.

If anyone plans on implementing this, go into the setting/Setting.js file and update the line below the TODO with your Portal URL, as well as an email address or other POC in the else clause in onOpen in the Widget.js file. Applications built with this need to be housed on another web server accessible to your users, and a link to that server needs to be created as an item in your Portal.

If there are any other questions about the widget or why I made any decisions that I did, feel free to ask.

-Nikolas

0 Kudos