I'm given a task to develop a couple of applications in ColdFusion that will share some of the data - same data but different presentation.
The first solution that comes in mind is to create a ColdFusion widget that as I understand breaks some MVC rules within ColdBox I am currently using. I need more of a view within another view with its own controller and model (all in CFML, no Ajax). My understanding is that MVC does not support such hierarchy whilst its inherent in HMVC.
Any suggestion on the graceful workaround and/or alternative HMVC framework?
You can use ColdBox Viewlets, which basically makes the views self sufficient when rendered. This means that you basically render the widget "renderView("widgets/myWidget")" Then inside of your widget, you will broadcast an event for data retrieval. Basically, calling the view's controller layer.
Then your widget will be ready for use and be bound only to its announced event.
I am not sure I am understanding your question correctly, but with mvc, you should be able to have two views using the same model. Or, you could split the model out into a different place using webservices or something like that, and then have your model in your two different apps connect to it to retrieve your data. Or am I misunderstanding?
Related
I have to implement reporting application that requires fetching data from existing ITS such as Jira.
I was able to login by extending StrongLoop's User model and calling REST API from JIRA.
Now, I want to share this codes by creating loopback component or something so that I could use this login method later on.
Please share your knowledge or best practice for creating loopback component.
Thanks
You probably want to look at writing a model "mixin", but without seeing your code it's hard to say exactly what that would look like. You might also just define an internal-only model that extends the built in User and then additional models that extend your new model and are actually implemented in the REST API.
I am getting started with Ember, and Django Rest Framework and I can't seem to peice together how to connect a model so that Ember can use the data in that model and create a simple drop down box. I have one model that I am starting with that is as such:
id
name
security
status
All I want to achieve is allowing Ember to use the data in this model and create a dropdown like so.
<select id="model">
<option value="model.ID">model.Name</option>
</select>
Can anyone help me with this? I am complete new to Ember and Django Rest.
Without going into a ton of detail, I've created a mini example of what you're looking for
http://emberjs.jsbin.com/Ozimatuj/2/edit
You'll note that I'm using mockjax, so instead of hitting any real endpoint, it's all mocked. Additionally I'd recommend using a client side record management solution (such as ember-data or ember-model). That's another discussion though.
In the application route (which correlates with the root of your app) it hits the model hook (which should return the model associated with that route. I'm returning a POJO of the users. That model is being assigned as the content of the application controller (automatically generated). The the application template is being built, and it's being backed by the application controller. Inside the application template we create an instance of ember select, and we tell it that the content backing it is model (which is the model/content in the application controller). We also say, use bind the user model (you could do id) and the name to the value and the label respectively.
I then bound the value of the select to selectedPerson, so anytime the value changes, the selectedPerson updates, the template which talks about that person will update. Magic. Ember does the rest.
This is a really broad question, so if you have any other questions, please ask a specific question, and I'd really recommend going through the getting started guide, it's really short, but will give you a decent foundation of terminology and methodology of Ember. http://emberjs.com/guides/getting-started/
For Ember Data I'd do a quick read the of the transition document for ED 1.0 beta.
https://github.com/emberjs/data/blob/master/TRANSITION.md
DS.DjangoRESTSerializer = DS.RESTSerializer.extend();
DS.DjangoRESTAdapter = DS.RESTAdapter.extend({
defaultSerializer: "DS/djangoREST"
});
I'm developing a web application that doesn't need database. All data comes via REST.
My question is: Is possible to use a model class (extended from AppModel) to manage data from a RESTfull service?, How to do that?, Does CakePHP any way to mapping directly a RESTfull web service?.
I have researched and I have found the $useTable attribute (http://book.cakephp.org/2.0/en/models/model-attributes.html#usetable) but I'm not sure if exists another way to do this in a better way.
My first idea is implement my own functions in a Model and put $useTable to false.
Thank you.
There is no such functionality that ships with CakePHP, but it's relatively easy to implement it on your own.
Check out datasources, they sit between the model and the data, but can also be used standalone, ie you can use datasource instances directly, or indirectly through the model layer (find/save/delete calls are using the datasource CRUD methods).
Checkout https://github.com/nodesagency/CakePHP-Rest-Datasource for some inspiration.
Consider a very simple dashboard application in Django. It has 2 models:
Page
Widget
Naturally, Page and Widget have a ManyToMany relationship.
Like any good dashboard implementation, the designers can change 3 things in a widget:
Data source that drives the widget
Placement of widget on the Page
Presentation of Data inside a widget
The Data is specified using a URL field in the Widget and is being served by a REST API based on Django REST Framework with the django-filter backend.
The Placement on the Page is catered using the excellent Gridster.
This leaves the Presentation part. I have two possible solutions:
Attach a template TextField with the Widget. Data will be fetched from web services in JSON format and rendered according to the template (handlebars) defined in Widget on the client side.
Pass the template name as query string in the URL to the REST API and render the Data using the user-specified template.
Now that the context is clearly defined (hopefully), following are my questions:
Is there any way I can choose the first solution and still be able to use the automatic forms generated by the DRF Serializers?
If not, and I choose the second solution, are there any potential pit-falls regarding security, code maintenance, code quality, testing and the like? Why have I not seen anyone else doing this i.e. letting the user select the template via query string?
Is there any other solution that I am missing?
Your first options seems most promising: fetch the data as JSON and insert it into templates on the client. All good.
So can you do that "and still be able to use the automatic forms generated by the DRF Serializers"? — Short answer, it depends what you mean by "automatic forms".
Serializers take a data dictionary, validate it and (for ModelSerializer subclasses) convert it into a (model) object instance for you. If by "automatic forms" you mean will you still be able to this validation behaviour, then the answer is yes. Create your JSON payload on the client and send an appropriate HTTP request to the API. Django Rest Framework's Serializers will work as expected.
If (though) by "automatic forms" you mean will you still be able to use the HTML forms that DRF provides in its web broweasble API, then the answer is no. The browseable API is built around an HTML renderer returning entire web pages. These include a pretty-printed representation of the JSON you'll be using as well as the web-forms that, on this assumption, you're interested in.
If you go this route you'll need to generate the forms on the client, using whatever model, view, template and binding features your chosen library (libraries?) offer(s).
I hope that helps. Good luck.
I'm calling a web service in a class and needs the result in some page in my project. How could I execute something in my page when the event in that class is fired? note: the calling is asynchronous.
You can do it easily using INotifyPropertyChanged in your view model. Simply bind the view model to your page and when anything changes in the background (e.g. asynchronously), the view should be updated.
Try to use MVVM in your applications and you will be good to go. Also, note you can place view model globally in the App class. This will make it easy to update from one place since everyone has access to App.