rasmusbergpalm / jslate

Write your dashboards in pure html/js
jslate.com
244 stars 54 forks source link

Readonly inquiry #40

Closed rsoo closed 11 years ago

rsoo commented 11 years ago

Hi all,

First off I want to thank you guys for the wonderful work on the recent upgrades. I love the new export/import functionality and the readonly addition. This isn't an issue, just a cry for help. My sincerest appologies if this isn't the place for it.

I was wondering if I could get some more detail on how the readonly is implemented or a clue as to how/where I should look to adapt it to my project.

In my project, I created a new field in the dbviews table to store an individual widgets' preferences so that when it's reloaded/resized, my code makes a call to dbviews controller to get the preferences to see what was selected. On changes it just calls dbviews/update and saves the preferences.

However, it seems when I use the readonly feature, my calls to dbviews to get the preferences (a http GET) seem to return the source for the default home page. What I want to be able to do is to have the readonly be able to access the dbview's preferences so each widget knows what to display.

Any hint on where to look to implement my solution would be greatly appreciated.

Thanks a bunch!

rasmusbergpalm commented 11 years ago

Hi rsoo.

Thanks for the kind words. Much of the new stuff is done by @brianhks.

As with all CakePHP logic, you can look at the URL and figure out where to look in the code.

dashboards/readonly points to DashboardsController::readonly https://github.com/rasmusbergpalm/jslate/blob/master/app/Controller/DashboardsController.php#L65 As you can see it takes an id input, and if it's not found it throws an exception

brianhks commented 11 years ago

So it sounds like you are loading and saving the prefs at runtime. The idea is that for readonly pages they are just that read only so you shouldn't be saving prefs. So that leaves the loading of preferences: What kind of preferences are they and could they be loaded at render time? I'm thinking you could use the php code to render a js variable that is set to the preferences. You can use the wid construct to make the variable widget specific.

Just throwing out ideas.

rsoo commented 11 years ago

The preferences are just integer representations of toggled elements. (e.g. 1,4,5 = 1st 4th and 5th elements displayed). I believe if implemented properly your solution should work! Just to clarify if I'm interpreting your suggestion correctly: You're suggesting that in DashboardController/readonly function, I create a js variable using the wid to create a widget-specific name with its respective preferences. Then on the client side, dynamically get this variable?

brianhks commented 11 years ago

So the logic would be in view.ctp for the dashboard. In the first for loop I'd save off the wid something like this

$dbview['wid'] = $wid; //This may require adding & to the foreach I'm not quite certain.

Then around line 24 in the js section you loop through the dbviews again doing the following: echo "var prefs_$dbview['wid'];"

Then each widget will save its prefs in a variable prefs_${wid}

That should be the only modifications you have to do.

rsoo commented 11 years ago

Got it working, thanks a bunch for the fix!