CRUD DATABASE Using json source - json

I have this .json source where the path is /my.json:
{
"Aro":[
{
"Name" : "Jhon",
"Surname" : "Kenneth",
"mobile" : 329129293,
"email" : "jhon#gmail.com"
},
{
"Name" : "Jhon",
"Surname" : "Kenneth",
"mobile" : 329129293,
"email" : "jhon#gmail.com"
},
{
"Name" : "Jhon",
"Surname" : "Kenneth",
"mobile" : 329129293,
"email" : "jhon#gmail.com"
}],
"Are":[
{
"Name" : "Thor",
"Surname" : "zvalk",
"mobile" : 349229293,
"email" : "thor#gmail.com"
},
{
"Name" : "Thor",
"Surname" : "zvalk",
"mobile" : 349229293,
"email" : "thor#gmail.com"
},
{
"Name" : "Thor",
"Surname" : "zvalk",
"mobile" : 349229293,
"email" : "thor#gmail.com"
},
]
}
I want to use it as a source in a CRUD database table in HTML.
This table is able to sporting, adding, editing, removing, updating...

You can use CRUD DataGrid with jQuery EasyUI
http://www.jeasyui.com/tutorial/app/crud2.php

Related

MongoDB / Node: Insert part of a doc in a collection into a doc in another collection

thanks for reading. I am trying to get a big list of data I have stored in a mongodb database, to display on a frontend, using the mongoose module in NodeJS. I am wondering what's the best way to tackle this problem? My data looks like this...
Collection 1: caves
{
"_id" : ObjectId("564d2f6eb0896138247ff791"),
"name" : "ACME Cave",
"slug" : "acme-cave",
"timeCreated" : ISODate("2015-11-19T02:09:50.492+0000"),
"address" : {
"county" : "Somewhere",
"state" : "CA",
"country" : "USA"
}
}
Collection 2: locations
{
"_id" : ObjectId("564d2f6fb0896138247ff855"),
"latitude" : 54.5793621,
"longitude" : -74.9669167,
"parent_id" : ObjectId("564d2f6eb0896138247ff791"), <-- matches collection 1
"timeCreated" : ISODate("2015-11-19T02:09:51.413+0000"),
}
{
"_id" : ObjectId("564d2f6fb0896138247ff855"),
"latitude" : 48.5783611,
"longitude" : -72.9669167,
"parent_id" : ObjectId("564d2f6eb0896138247ff791"), <-- matches collection 1
"timeCreated" : ISODate("2015-11-19T02:09:51.413+0000"),
}
I would like to merge some of the children fields into the parent like so...
{
"_id" : ObjectId("564d2f6eb0896138247ff791"),
"name" : "ACME Cave",
"slug" : "acme-cave",
"timeCreated" : ISODate("2015-11-19T02:09:50.492+0000"),
"address" : {
"county" : "Somewhere",
"state" : "NY",
"country" : "USA"
},
locations: [
{
"_id" : ObjectId("564d2f6fb0896138247ff855"),
"latitude" : 54.5793621,
"longitude" : -74.9669167,
"parent_id" : ObjectId("564d2f6eb0896138247ff791"), <-- matches doc collection 1
"timeCreated" : ISODate("2015-11-19T02:09:51.413+0000"),
},
{
"_id" : ObjectId("564d2f6fb0896138247ff855"),
"latitude" : 48.5783611,
"longitude" : -72.9669167,
"parent_id" : ObjectId("564d2f6eb0896138247ff791"), <-- matches doc collection 1
"timeCreated" : ISODate("2015-11-19T02:09:51.413+0000"),
}
]
}
I have this snippet below which accomplishes this, but it doesn't seem right. Does anyone have any insight into doing this right?
Parent.find({}, {'locations': 1}).stream().on('data', function(parent) {
// add the location to the parent doc
Child.find({parent_id: {$in: parent._id}}, {'latitude': 1, 'longitude': 1}, function(err, child) {
parent.locations = child;
console.log(parent);
});
});
This returns the follwing JSON, which is the same as my output..
{
"_id" : ObjectId("564d2f6eb0896138247ff791"),
"name" : "ACME Cave",
"slug" : "acme-cave",
"timeCreated" : ISODate("2015-11-19T02:09:50.492+0000"),
"address" : {
"county" : "Somewhere",
"state" : "NY",
"country" : "USA"
},
locations: [
{
"_id" : ObjectId("564d2f6fb0896138247ff855"),
"latitude" : 54.5793621,
"longitude" : -74.9669167,
"parent_id" : ObjectId("564d2f6eb0896138247ff791"), <-- matches doc collection 1
"timeCreated" : ISODate("2015-11-19T02:09:51.413+0000"),
},
{
"_id" : ObjectId("564d2f6fb0896138247ff855"),
"latitude" : 48.5783611,
"longitude" : -72.9669167,
"parent_id" : ObjectId("564d2f6eb0896138247ff791"), <-- matches doc collection 1
"timeCreated" : ISODate("2015-11-19T02:09:51.413+0000"),
}
]
}
I have thought about rolling up these Schemas into 1 collection, but I cannot due to other features I'll be adding to the code, like storing pictures, and edits per children. I don't think using a single collection is wise, because I'll be storing too much information in a document.
Thanks for your help!
I think that you can use one-to-many with document references model. That is to say, store the location reference (only _id) inside the cave document.
{
"_id" : ObjectId("564d2f6eb0896138247ff791"),
"name" : "ACME Cave",
"slug" : "acme-cave",
"timeCreated" : ISODate("2015-11-19T02:09:50.492+0000"),
"address" : {
"county" : "Somewhere",
"state" : "NY",
"country" : "USA"
},
locations: [ 564d2f6fb0896138247ff855, 564d2f6fb0896138247ff855 ]
}

Ng-repeat orderBy value

How can I order my ng-repeat by the like_count in my json?
I have given it a bash but I am clearly missing something.
This is the repeat
item(ng-repeat="item in items | limitTo:3 | orderBy:like_count)
This is the data structure:
{
"image_url" : "bde2cca8323d098edf43389119af7748.jpg",
"title" : "This is the title",
"like_count" : "15",
"creator" : {
"profile_img" : "john-doe.jpg",
"username" : "JD",
"url" : "/John-Doe",
"first_name" : "John",
"last_name" : "Doe",
"location" : "Sydney, Australia"
}
}, {
"image_url" : "bjk23482301232234112d3232345343.jpg",
"title" : "This is the title",
"like_count" : "89",
"creator" : {
"profile_img" : "Jane-doe.jpg",
"username" : "JD",
"url" : "/Jane-Doe",
"first_name" : "Jane",
"last_name" : "Doe",
"location" : "Melbourne, Australia"
}
}
Try this..
ng-repeat="item in items | limitTo:3 | orderBy:'like_count'

Kendo-UI - Creating a Dynamic Form via JSON

I have been able to successfully build out a dynamic form using JSON and Kendo.Observable, however I cannot initialize the dropdownlist values successfully within the same JSON. The only way I can get it to work is by binding the dropdown lists to a separate json request after creation. See the example below....
Here is an example of some JSON that works (no dropdown list)
{"fields": [
{"name" : "FirstName", "label" : "First Name", "type" : "text", "css" : "test"},
{"name" : "LastName", "label" : "Last Name", "type" : "text", "css" : "test"},
{"name" : "Email", "label" : "Email", "type" : "text", "css" : "test"},
{"name" : "Phone", "label" : "Phone", "type" : "text", "css" : "test"},
{"name" : "Subscribed", "label" : "Subscribed", "type" : "checkbox", "css" : "test"}
]}
Here is an example where I have added a dropdown, not going to post the whole thing, I have tried a number of different variations on the below to try and populate the select but can't find any that work
{"fields": [
{"name" : "Email", "label" : "Email", "type" : "text", "css" : "test"},
{"name" : "FirstName", "label" : "First Name", "type" : "text", "css" : "test"},
{"name" : "LastName", "label" : "Last Name", "type" : "text", "css" : "test"},
{"name" : "Company", "label" : "Company", "type" : "text", "css" : "test"},
{"name" : "ddlCountry", "label" : "Country", "type" : "select", "dataTextField" : "text", "dataValueField" : "value", "dataSource":[{"text" : "AF","value" : "Afghanistan"},{"text" : "AL","value" : "Albania"},{"text" : "DZ","value" : "Algeria"},{"text" : "AS","value" : "American Samoa"},{"text" : "AD","value" : "Andorra"},...etc...
and here is the script to bind it
$.ajax({
url: "http://localhost/go/getformjson",
type: "GET",
dataType: "json",
success: function (model) {
// convert the JSON to observable object
var viewModel = kendo.observable(model);
// bind the model to the container
kendo.bind($("#example"), viewModel);
}
});
You need to specify the data-text-field and data-value-field attributes:
<select data-bind="source: options" data-text-field="ddltext" data-value-field="ddlvalue" />
Here is updated version of your fiddle: http://jsfiddle.net/aUAJv/64/

jsTree - Setting href attributes in Json data

Im trying to create a 'jsTree' treeview that gets it's data from a .Net webservice.
Everything is working, except for the a-node's href attribute. Whatever I try, it always renders as '#'.
As I understand from the documentation, all attributes in any data object get copied to the a-node.
Below is an example of my current json object. Can anyway figure out why the href attribute isn't copied to the nodes?
[ { "attributes" : { "id" : "rootnode_2",
"rel" : "root2"
},
"children" : [ { "attributes" : { "id" : "childnode_9",
"rel" : "folder"
},
"children" : [ { "attributes" : { "id" : "childnode_23",
"rel" : "folder"
},
"children" : null,
"data" : { "href" : "http://www.google.com",
"title" : "Test_Below_1"
},
"state" : null
} ],
"data" : { "href" : "http://www.google.com",
"title" : "Test_1"
},
"state" : null
},
{ "attributes" : { "id" : "childnode_10",
"rel" : "folder"
},
"children" : [ { "attributes" : { "id" : "childnode_24",
"rel" : "folder"
},
"children" : null,
"data" : { "href" : "http://www.google.com",
"title" : "Test_Below_2"
},
"state" : null
} ],
"data" : { "href" : "http://www.google.com",
"title" : "Test_2"
},
"state" : null
}
],
"data" : { "href" : "http://www.google.com",
"title" : "Glatt"
},
"state" : "closed"
} ]
This is how I initialize the tree;
$("#jstreejson").jstree({
json_data : {
"data": treeObject
},
themes: {
"theme": "apple",
"dots": true,
"icons": true,
"url": "/Scripts/themes/apple/style.css"
},
plugins: ['core', 'themes', 'json', "json_data"]
});
So... I'm not sure that's entirely correct. You can't control the anchor attributes as far as I know, but what you can do add stuff to the attr hash in the json and then use the select_node.jstree event to open the desired link, i.e:
.bind("select_node.jstree", function (e,data) {
var href_address = data.rslt.obj.attr("whatever");
// open desired link
}

How to add Timestamp to Spring-Data-Mongo in Roo?

I have a Spring Roo project I am trying to create based on log4mongo-java appender and I want to get access to the data entries that looks like:
{
"_id" : ObjectId("4f16cd30b138685057c8ebcb"),
"timestamp" : ISODate("2012-01-18T13:46:24.704Z"),
"level" : "INFO", "thread" : "catalina-exec-8180-3",
"message" : "method execution[execution(TerminationComponent.terminateCall(..))]",
"loggerName" :
{ "fullyQualifiedClassName" : "component_logger",
"package" : ["component_logger"],
"className" : "component_logger"
},
"properties" : {
"cookieId" : "EDE44DC03EB65D91657885A34C80595E"
},
"fileName" : "LoggingAspect.java",
"method" : "logForComponent",
"lineNumber" : "81", "class" : {
"fullyQualifiedClassName" : "com.comcast.ivr.core.aspects.LoggingAspect",
"package" : ["com", "comcast", "ivr", "core", "aspects", "LoggingAspect"],
"className" : "LoggingAspect"
},
"host" : {
"process" : "2220#pacdcivrqaapp01",
"name" : "pacdcivrqaapp01",
"ip" : "24.40.31.85"
},
"applicationName" : "D2",
"eventType" : "Development"
}
The timestamp looks like:
"timestamp" : ISODate("2012-01-17T22:30:19.839Z")
How can I add a field in my Logging domain object to map this field?
That's just the JavaScript Date (according to the mongo docs, and as can be demonstrated in the shell), so try with java.util.Date.