I was looking at trying to generate a form based on a Mongoose schema definition. I was having trouble finding where the schema info is tucked away. Where is the path type info etc kept in the object?
Or better, has anyone tried to do this already? I'm using Jade but something that pumps out HTML would also be good.
My little project creates complete CRUD for a mongoose schema. Its a little rough but
might be useful.
https://github.com/jspears/bobamo
It is very client side though, all the forms are generated (they can be overriden with static versions if it is not what you need). That is it doesn't use jade, but it does use underscore template on the client and jqtpl on the server to generate the javascript that makes the form.
Wow that was really unclear... The browser talks to the server via JSON/REST it loads this into an all javascript front end. This front end is generated on the node server on demand, to the client. So it easy to modify, and relatively cleanly sepeartes the data from the view.
I can recommend checking out Formage (npm: formage)
https://github.com/Empeeric/formage
You can get good ideas from this project.
If you're exporting out your models, ie
module.exports = mongoose.model("ModelName", Model)
Check in your module's .schema. That should have all the info you need.
Related
I don't seen any clear way to query an outside GraphQL endpoint (i.e. https://somewebsite.com/graphql) for data. Has anyone else done this, and how did you do it?
I assume it requires you to build a custom plugin, but that seems overkill for such a simple need. I have searched the docs and this issue doesn't really ever get addressed. 🤔
In Gatsby V2 you don't need to create your own plugin.
What you need is a plugin called gatsby-source-graphql
gatsby-source-graphql uses schema stitching to combine the schema of a
third-party API with the Gatsby schema.
You can find more info here.
The answer is, as you mentioned, writing a new source plugin. This is how Gatsby gets the data into it's internal GraphQL structure to then query.
Plugins are, at their core, just additions to the gatsby-node, gatsby-browser, and gatsby-ssr files. So you could write the logic needed at the top of your gatsby-node file to avoid abstracting it out into it's own plugin.
If you're not so into writing plugins for gatsby, like me, have a look here.
It explains in detail how you query any graphQL server via the Gatsby sourceNode API and the use of graphql-request.
Helped me to get data for e.g. from graph.cool as well as GraphCMS.
The problem though is that you always have to write 2 different kinds of graphQL queries, as they are usually not compatible to Gatsby's relay style queries. But still easier than building a whole plugin.
I am attempting to integrate Zend with MongoDB. I think I am almost there, but I need some help to complete the task. I am new to both zend and mongo, but reasonably experienced with PHP and MySQL.
Some details:
My Zend project is based on the skeleton tutorial at http://framework.zend.com/manual/2.0/en/user-guide/skeleton-application.html. This works fine on my computer, but is mysql-based.
I have installed MongoDB. I can write nosql on the command line and I can instantiate a MongoClient object in a PHP script, so those things seem to work and talk to each other.
I want to use mongo instead of mysql, and I have implemented Doctrine. I have no idea what Doctrine does, and I've been through several searches to try and find how to run mongo commands in zend. These facts lead me to conclude that I don't know what I'm doing.
So to the specifics of my question:
As I understand it, I should be instantiating a mongo object somewhere. If so, where should I put the instantiation in zend?
If not, presumably I need an existing instantiation of the mongo object to run various find/save commands from inside the model class, so if that's true, how do I access the existing mongo object?
Thanks for any help, and clarification questions are equally welcome.
Edited 13/12/2012 for clarification.
With the given answers it seems I am on the right track, and I can further clarify what I need:
Looking at the Doctrine Documentation linked below, I am still unclear where the document manager instantiation is supposed to occur. I would have expected it to go into a more generic location which is run on every page load. Also, most of the tutorials I find seem to refer to a file structure different given from the skeleton application, so when they say to put certain things in certain places, I'm not sure where they mean. For example, I keep seeing references to bootstrap files, but my only bootstrap files are in test directories.
My questions are these:
What code do I need to add into the indexAction function (which definitely responds when I go to the correct URL) if I simply want to print_r all the documents in a collection?
Do I need to add any other code elsewhere, if so where, and what code?
These are the different bits and what they do, working from the bottom up:
mongodb: data persistance
doctrineODM: Object Document Mapper. This maps mongo documents to php objects. It means you don't have to worry about doing any calls against mongo directly - you just work with plain old php objects. To use doctrineODM you need to define your model classes, and get the hang of using the DocumentManager - suggested, the Doctrine docs are quite good.
doctrineMongoODMModule: A module that integrates doctrine with zf2. The main thing it does is allow you to configure doctrine using zf2 config style, and gives you access to the DocumentManager via the zf2 ServiceManager. (I does quite a few other things too, but they are the main ones)
zf2 (mvc): Lets you define an interface so other things (like a web client) can manipulate your documents.
There is brilliant module doctrine-mongo-odm-module for mongoDB access.
Just add to composer.json
"require": {
....
"doctrine/doctrine-mongo-odm-module": "dev-master",
....
Doctrine documentation should help how to use it.
I am new to Zend and still learning.
I need to read some configuration data from the database and keep it in session. I want this data in all the pages, so I need to intercept all the request and check if the session contains the required data, if not I will fetch it from the database and put it in the session.
I would like to know the best place to put the code in. In Java we used to check that in a filter. I am guessing here I have to put this is in an Action Helper. Just wanted to check what options I have and what are the best practices.
Thanks for any suggestions.
for that purposes you may use Zend_Registry singleton class for providing accessibility of session data from every point of ZF-project. For storing session data there are also several classes, e.g. Zend_Session class
I would definitely put this in a Controller Plugin class. eg.
Application_Controllerplugins_SessConfig extends Zend_Controller_Plugin_Abstract
This way you can catch the request early on, and do whatever you want with the data...
This is another answer of mine on SSL routing, but the logic is the same for the plugin class: How to implement SSL in Zend MVC
i am about to implement a similar solution whereby an application instance (which is to be rolled out to various customers) needs certain settings-data to be editable by admin via cms and thus am storing it in the db. i am then going to retrieve and add these settings [as a sub-object] to the config class (which in turn is added to the registry in the bootstrap. this seems like the cleanest solution to me as then all config data are stored in the one place, regardless of their source being an ini file or the db.
i'd be interested to hear other opinions on how this is done.
rob ganly
I'm looking at embedding JasperReports into an existing web app for reporting. The webapp sits on top of an existing database which is ancient and complex, and really not suitable for report writers to use to write reports against directly.
What I want to look at is writing some kind of wrapper around our existing data access layer (written to make our life easier talking to aforementioned ancient and complex db). Does anyone have any experience of writing custom data sources for JasperResports, or of doing anything like this?
Updated
I guess I probably wasn't clear in my question - which is probably because my requirements aren't clear either. I want to provide some way that the end-users can use something like iReport to author reports against the database, and then to use JasperReportServer for scheduling/viewing of the reports. However, the database is really, really nasty and was never designed for use in this way. We've got a access layer around it that the webapp uses to talk to it. I want to keep my end users away from the DB altogether, and the idea of a custom data source that used the access layer seemed a good option. However, I've found very little documentation on how to do that. Maybe it's just a whole lot easier than I think it is, and I'm just trying to make a dead simple thing too complicated.
Updated
Thanks for the answers. I don't think my problem has been solved, but I think the answers have helped to inform the requirements phase.
Jasper reports allows you to use a "JavaBean" data source. You can load your data into any Java Bean structure and build the reports against that. Works well.
See the "Custom Data Source" section here.
Every JasperReports template can have two different data sources. One is hooking it directly to a database using some jdbc driver or, in your case, providing a collection of java beans (POJO's), usually list.
JasperReports template is similar to a method definition. It has a name, i.e. compiled JR object and parameters (data source and a list of input parameters of some of the most popular Java types).
My suggestion is to use iReport tool. Open some example that comes with the JasperReports bundle, analyze it and tweak it. It's not so complicated.
UPDATE
Letting customers authoring JasperReports templates, compiling and adding to the classpath means that you'll need to open your system too much. Usually clients provide description of a desired report and developer(s) create the data source and design the template. JasperReports can have parameters. If these parameters are exposed through UI users can change the behavior of reports in the runtime.
If you really need to allow more flexibility then use the API provided by JasperReports for authoring templates. I could imagine some simple DLS for advanced users to communicate with your system creating on-fly reports.
I'm currently using the Jira SOAP interface within a C# (I suppose the language used here isn't terribly important).
Basically, I'm creating an API and a Winform that wraps some of the functionality of the soap service so that our Devs can programmaticly add bugs when something goes wrong in our application.
As part of this, I need to know the custom field IDs that are in use in Jira, rather than hardcoding them (as they are still prone to the occasional change) I used the GetCustomFields() method in the jira-rpc api then filtered it, so that all the developer needs to know is the name of the field, then the ID is filled in for them automagically.
This all works fine, but with one quite important proviso: that you login to the SOAP/RPC service as a user with administrative privaliges.
The Jira documentation indicates that the soap/rpc service follows the usual workflows and security schemes, however I can't find anything anywhere that would appear to remove this restriction on enumerating custom fields (and quite why in any instance you would want someone to HAVE to be an administrator to gain this access, especially as the custom field id's tend to be in Jira's HTML source is beyond me)
Does anyone know if I've missed a setting somewhere? Or if there is some sort of work-around for this, short of hardcoding the custom field id's?
Or is this a case of having to delve in to Jira's RPC plugin and modifying the source for it in order to give me the functionality I require?
Cheers
Edit for the sake of google/posterity
Wow, all this time on, and it looks like Atlassian still haven't changed this behavior.
Worked around this by creating a custom dictionary that logs in as an administrative user, grabs the custom fields and then logs out. Not ideal, but it should work 'til atlassian change things
You're not missing anything - there's no way to get custom fields via standard SOAP API.
In JIRA Client, we learn about custom fields in two ways:
We download issues via RSS view of the issue navigator, or via XML representation of a specific issue. If a custom field is set for an issue, the XML will have its id, class and value (values).
From time to time we inspect the content of IssueNavigator search page - looking for searchers for the custom fields. Screen-scraping the HTML gives us not only ids of the custom fields but also possible values for enum fields.
This is hackery, of course, and it may go wrong, so a good API would have been a lot better.
In your case, I can suggest two solutions:
Create your own SOAP (or REST) remote API plugin that will give you just that info that you miss from the standard API. Since you're seemingly in control of your JIRA, you can install anything there.
Screen-scrape the "New Bug" page for the project and type of issue you need to submit. You'll get all the info - fields, options, default values, which field is required.