I have MapsController that uses data from Colonias model (MapsController returns a bunch of vars needed for Maps view to work). Then I render Maps view.
I also have ChartsController that uses data from Colonias model, too. It returns vars needed for Charts view to work.
I want to render Charts view inside Maps view. In order to do it I'd have to call ChartsController action from MapsController.
Yii::$app->runAction('ChartsController/Topten');
So that MapsController would be able to return vars for Maps view plus Charts view vars. Then it is possible to render Charts inside Maps.
But calling actions from other controllers is NOT a GOOD PRACTICE. Both Maps and Charts use data from Colonias model (and some other models). Both use the same view (Charts inside Maps). But they have different Controller.
I decided to have two different controllers because data is extracted and treated differently although it is from the same model.
I have read articles about GOOD PRACTICE but nothing refers to this...
How would you do it??? Would you use only One controller for everything??? Is it correct/Incorrect to have a large controller(joining Maps and Charts controller)? What it is the best way to do it in order to GOOD PRACTICE? Thanks
Related
I have a use case where I want to implement custom search functionality for a Shopify site. So instead of using getting a JSON with Ajax and making a html and replacing the html. Is there a way where I can override the search.results data that the .liquid files are using.
So when I make a search in /search?q=xyz, I want to get the data from my API, and use that data to render the product-item.liquid. This way I don't have to worry about the UI of the product-item for different themes.
Yes. You can easily do this. You would install an App in your shop, and create an endpoint you would call with your search criteria. The end point is handled by a Shopify App Proxy, that securely allows you to callback the App. You could return Liquid as results, or just JSON as you wish. It is a standard and simple pattern for you to use.
See here: https://help.shopify.com/api/tutorials/application-proxies
I have always worked with Web APIs, so I don't know how to handle this very basic problem in .NET Core MVC (I am only familiar with MVC conceptually). My problem:
I need a user to select an option from a dropdown on the front end and then show some data based on the option (after fetching it).
If I were writing an SPA consuming an API, I would simply make a call to the backend to get the data and then generate the html to display it on the front end.
How is this handled in MVC? Isn't the convention to return entirely new views? How are things like these handled?
I just need a pointer in the right direction conceptually - I can figure out the code.
Edit: Should I just pretend it's an SPA despite it being a view and create an API endpoint in the same app that provides the view and consume it from the cshtml?
It works exactly the same way. You make an AJAX call to fetch some data. You can either return the data directly, and utilize JS to render the HTML or return HTML directly. Either way, you use the AJAX callback to replace the appropriate content on the page.
Even in older ASP.NET MVC projects it worked this way, though you basically had to decide whether you were going to use an MVC controller or a Web Api controller to do the work. Either would work, but there were advantages/disadvantages to each approach. MVC/Web Api could always coexist in the same project.
In ASP.NET Core, the difference is purely semantic. There's really no such thing as MVC and Web Api anymore - just ASP.NET Core. A controller is a controller is a controller, so just add an endpoint and go to town.
I need to get all the properties from all the objects in the currently loaded model.
If I have a list of all the dbIds, I can use the Autodesk.Viewing.Viewer3D.getProperties(dbid,onSuccessCallback,onErrorCallback) method to retrieve them.
Is there a way to get a list of the dbIds of all the objects in the viewer? Or is there a better way to achieve this?
Here is how you can get all the dbIds in the model:
Get all database id's in the model
Now we also have a function to retrieve properties for multiple elements in the Viewer:
getBulkProperties method
I think the above two things are all you need.
You can also use the following Model Derivatives API endpoint to get the list of all the properties for a model: GET :urn/metadata/:guid/properties
This can be done without loading the model in the viewer but needs to be performed server side for security reason. You can expose an endpoint from your own server to your webpage.
How do I view existing realtime collaboration data model? I call getRoot method:
var collaborative_model = rtpg.realtimeDoc.getModel().getRoot()
When I vew collaborative_model object in debug, I see cryptic properties only. Not sure if or how my model is saved.
Can I do some kind of variable dump of the model?
You can use https://gist.github.com/cowsrule/6348393 as a mostly plug-and-play dumper for the realtime API collaborative objects. As this relies on internals of the realtime API it will need to be updated (read: break) the next time they update the API.
To use, include on your webpage and set window.remoteDoc to be your realtime document.
To call, pass in the ID of the CollaborativeObject you are interested in inspecting.
The root is just a CollaborativeMap, so you can use the standard map methods to explore its values.
The relevant methods there for digging into the model are keys() and values().
A lot of these data model classes have obfuscated methods that are a part of the internal implementation. The best way to see what methods are publicly available is to look at the API reference.
We are currently trying to set up routes in such a way that the returned content-type can be set using a route parameter. The routing is all working properly now, but there is one problem. If one requests html, then the normal view script is rendered. The data we provide to this script can be anything from a string to a collection of objects, and the view script decides what to show to the user.
If however JSON response is requested, then we just provide the data returned from our controller as JSON. However, some data should not be made publicly available to the user, and hence some filtering is required. Is there any possibility to use JSON view scripts (as in ZF1 with context-switch) in order to support such filtering? Or maybe another method?
There is no such thing as a JSON script which lets you decide what to render and what not. You have to provide the proper data in the view model such that only the data is given that is eligible to be displayed.
I have been thinking about a hook in the JSON renderer so you can filter the view model's data based on the context of the request, but such thing does not exist yet. Unfortunately, you have to select the data in your controller or model.