Retool: Create sidebar to dynamically change a container window's components - retool

I am trying to create a sidebar with a couple of buttons. I have one container and what I would like to do is on click of one of the buttons in the sidebar, it will show a different tabbed container that is within the main container component. For example, the container is called "main_window" and I want to add 3 tabbed containers called "foo", "bar", "fizz".
My thought was to create a [temporary state] (https://docs.retool.com/docs/temporary-state) called "window_selected" and assign a state per window. In other words:
{{state1.value}} == 1 then "foo"
{{state1.value}} == 2 then "bar"
{{state1.value}} == 3 then "fizz"
The docs also references setting these values running javascript code, but where do you actually run that code? For example, if I want to set a constructor for first load of the page, for example, to set state.setValue(value: 0) by default, where do I run this?
In the documentation it also states:
If you refresh your app (with a ⌘R), your temporary states will be lost. If you're looking to persist state between app refreshes, you should write back results to a database!
Therefore, I was considering using localstorage as I see there is a localstorage section, but the only reference to localstorage in the docs is here.
Where do I set values for localstorage? And, is there a way to run a transformer or query "onload"?
Ultimately, how do I create a dashboard where the page dynamically changes in a main window depending on which button I have highlighted in the sidebar.

We answered this question on our community forum here: https://community.retool.com/t/create-sidebar-to-dynamically-change-a-container-windows-components/2257

Related

Sitecore replicate changes throw all the pages

I'm trying to implement a menu in sitecore page. Menu that will be available in all the pages.
I can do a rendering that goes to some specific datasource and assign the rendering to a placeholder inside Design Layout of the layout.
However how can they edit the datasource (order, ammount of elements, etc..) item in page A that will be also replicated in page B.
Without going through all the pages to change order, color, text, items etc...
To do that you will want to create a new data template that holds the shareable content on it. So it would have fields for navigation items etc... any setting that you wanted to be shared across pages.
Then in your rendering, you can set the Datasource to this item. Any changes to that item would be reflected across all pages that use it.
You should add the rendering to the standard values of your page templates and set the Datasource to your main default navigation item, then all new pages will get the navigation ready setup.
You need design your view in such a way that it should be editable in experience editor mode.
If you have implemented using Glass Mapper there is good section on how to use Edit Frame.
Also you can check below community blog. for more details.
https://community.sitecore.net/technical_blogs/b/sitecorejohn_blog/posts/render-field-values-for-mvc-solutions-using-the-sitecore-asp-net-web-cms

How to make a statically binded rendering editable via Experience Editor (Sitecore MVC)

So I have a layout view within Sitecore Mvc, this view contained a Controller Rendering that pulls in a header and footer navigation. Example:
#Html.Sitecore().Rendering("/sitecore/layout/renderings/some_rendering")
This specifies a Controller Rendering I've defined in Sitecore. This works great, except when I'm in the experience editor. It doesn't give me the ability to select this rendering. If I create a Placeholder and then define these navigation elements to this placeholder dynamically via Sitecore, then I can, but these navigational elements exist on every page of this layout, so I would like them statically placed instead of using a Placeholder, but I would still like the user to be able to select the navigation element in the experience editor (so I can create custom command to interact with this navigation, such as creating new links, etc).
Does anyone have an idea that will help me achieve this?
Use Edit Frame for that and create Custom Edit Frame Button for operations like adding new element to the navigation.
And remember to pass Datarsource ID or Path as a second parameter to the Html.Sitecore().Rendering() method:
#Html.Sitecore().Rendering("/sitecore/layout/renderings/some_rendering", new { DataSource = "{some-id-or-path}" })
Here is set of blog posts which can help you to understand how Edit Frames work and how to add them in Sitecore MVC solution:
https://visionsincode.wordpress.com/2015/01/08/how-to-use-editframe-in-sitecore-mvc/
https://www.cmsbestpractices.com/how-to-properly-use-sitecore-edit-frames/
https://briancaos.wordpress.com/2011/11/28/using-sitecore-editframe-in-pageedit/
You won't be able to remove the component or move it around the page (yeah, it's statically bound to one place on your layout), but you will be able to edit it's properties and datasource.
You can try to use GlassMapper views and statically inherit the view from the GlassView.
Then you'll be able to use Editable method to render the field.
But the consideration you need to take is that you'll not be able to set a datasource to the component from the page editor or content editor.
Instead of injecting the rendering through the Rendering method you should be able to use standart MVC RenderPartial.
I've used this approach on one of the projects I've been on and it worked.

List of News Articles In Sitecore (Best Approach?)

I am creating a Sitecore MVC site for a client and I need to create page that will list news articles for the company.
So far, I have created items that use a shared data template called “Article,” and I also have a sublayout (a view rendering) called “Article” that will display these items.
For the list itself, my plan was to create another component (a sublayout) call “News_List”, and to put a placeholder in it called “List”.
My question is this: can I allow the author to insert articles (e.g., N items of type “Article”) into this placeholder via the page editor?
Will SC allow you to insert multiple instances of the same component into a placeholder? Will this break anything?
I believe this is a pretty common question but I have not found a definitive answer. Thanks in advance…!
You can insert as many components (of the same type) in your placeholder as you want.. Just make sure to put the placeholder settings correctly and give it a decent name (not just "list" ;))
But are you sure you want to do this? Your editors will manually need to create a list of components for each article they want to add on the page. Doesn't sound to be very user (editor) friendly.. Maybe you should consider creating a list component that can get a list of articles as a datasource and show those. Or even select them automatically (but that might be not according to your business case)..
Yes, authors can add multiple instances of the same component into a single placeholder.
Assuming that the code of the component doesn't do any stupid things it's absolutely ok to do this.

How to ensure the same controller instance is referenced in two different places in ember

tl;dr: Ember is creating two instances of an ArrayController when I want only one. How do I ensure that my code is always referencing the same one?
The scenario
Using ember, I am trying to create a section of a page where potential buyers can select from two sets of options, then click a button to accept those options and redirect to another page based on their choices. Example:
However, when I click the button, it uses whatever was selected when the page first loaded, ignoring any actions in between.
Let's work through the code
When you click the Reserve Now button, it triggers an action on the LessonPackagesController:
#handlebars template
<a {{action bookLesson on="click"}}>Reserve Now</a>
Here's the action it triggers: (If you don't understand emberscript, imagine it's just pseudocode... that runs)
#LessonPackagesController
bookLesson: ->
window.location = #bookingUrl
The location it points to is currently outside the ember application, so I don't think transitionToRoute and its sibling methods are viable.
#bookingUrl is a computed property on the controller.
#LessonPackagesController
+computed chosenPackage lessonType
bookingUrl: ->
url = "/instructors/#{#id}/lesson_bookings/new"
url += "/#{#lessonType}"
url += "/#{#chosenPackage.name}" if #chosenPackage
url
To simplify, I've started out by setting #lessonType to a default ('private'), and we don't have to worry about how #id is being fetched, because it's working.
Before we get into the details of how #chosenPackage is updated, I put together some code that logs every time #chosenPackage is updated, confirming that both #chosenPackage and #bookingUrl are being updated as expected.
#LessonPackagesController
+observer chosenPackage
yolo: ->
console.log(#bookingUrl)
Whenever I click a lesson package, for example the six-lesson package, I see the following in my console: /instructors/58/lesson_bookings/new/private/six. This is exactly as I expected.
However, when I click the Reserve Now button, I get the following: /instructors/58/lesson_bookings/new/private. This is the #bookingUrl that exists before the #chosenPackage is updated.
The plot thickens
In further tests, I put a #content log in 'yolo', and found that the content was... an empty array. Putting this together with the null #chosenPackage in #bookLesson, I surmised that I was accessing two different instances of LessonPackagesController. Here's how I access it when updating the #chosenPackage (which triggers the #yolo function):
class App.LessonPackageController extends Ember.ObjectController
needs: ['lessonPackages']
selectMe: ->
#chosenPackage = this
+computed chosenPackage
chosen: ->
this == #chosenPackage
chosenPackageBinding: 'controllers.lessonPackages.chosenPackage'
chosenPackage: ''
I know that all the LessonPackageController instances interact with the same LessonPackagesController because selecting one will deselect the current chosen package. However, it happens to be different than the instance which #bookLesson is called on.
How do I ensure those two instances are in fact one instance, the same instance?

Ember.js adding and removing views from the DOM?

I am looking into ember.js, after working with SproutCore 1 previously. I am looking for some examples on how to add and remove views from the DOM as the user navigates the application.
For instance, I have an application that contains a set of cases and each case has a workflow. There are also administration pages, etc.
When the user starts up the app, a dashboard-like user interface is shown. From here the user is able to search or click on a case in order to bring up that case. At this point I want to do the following:
I want to remove the GUI for the Dashboard, and i want to show the GUI for the case - which is a complex GUI in itself with its own set of navigation rules etc.
Also, within the case I want to add and remove portions of the GUI as the user navigates and manipulates the case.
When the user clicks on the "Dashboard" link, I want the current GUI to be removed, and the dashboard to be added again.
As this will be a somewhat large application I am not sure if toggling the isVisible parameter is sufficient, or if other measures needs to be taken in order to not overload the user's browser.
Is there a guide, or an example that shows how to do this ?
WARNING: OUTDATED ANSWER
A view inherits from Ember.View which means it gets some key methods. append(), which appends to body, appendTo(arg) which takes an argument and remove().
The argument is a jQuery style selector of where to insert the element in the DOM.
// my view
App.PartsView = Ember.View.extend({
...
});
// create/insert my view
App.partsView = App.PartsView.create();
App.partsView.appendTo('#partcontainer');
In my code I have a <div id="partcontainer"></div>.
// remove from DOM
App.partsView.remove();
The documentation has a good part on Building a View Hierarchy and later a section on Ember.ContainerView depending on whether you want to do it all programatically or not.