More
This commit is contained in:
@@ -8,12 +8,18 @@ $('document').ready(function(){
|
||||
|
||||
$("#animals").click(function(){
|
||||
$.get( "/animal", function( data ) {
|
||||
$.get( "/species", function( species_r ) {
|
||||
var species = {};
|
||||
species_r.data.map(function(item) {
|
||||
species[item._id] = item.name
|
||||
});
|
||||
|
||||
$( "#body" ).html("<h1>Yours Dinos</h1><button id='animal-add' class='btn btn-success btn-sm float-right'>+ New Dino</button><br><br><table id='animals-table'></table>");
|
||||
$( "#animal-add").click(function(){
|
||||
$( "#body" ).load( "/templates/animal-form.html" );
|
||||
})
|
||||
dataSet = data.data.map(function(item) {
|
||||
return [item._id, item.name, item.initial_level + " - " + item.level];
|
||||
return [item._id, item.name, item.initial_level + " - " + item.level, species[item.specie]];
|
||||
});
|
||||
$('#animals-table').DataTable({
|
||||
data: dataSet,
|
||||
@@ -22,12 +28,14 @@ $('document').ready(function(){
|
||||
{ title: "id", visible: false},
|
||||
{ title: "Name" },
|
||||
{ title: "Level" },
|
||||
{ title: "Specie" },
|
||||
{ title: "Options", className: "options-table", orderable: false,data: null, targets: -1, "mRender": function(data, type, full) {
|
||||
return '<button class="btn btn-primary btn-sm" onclick="showAnimal(\''+ full[0] +'\')">Show</button> <button class="btn btn-info btn-sm" onclick="editAnimal(\''+ full[0] +'\')">Edit</button> <button class="btn btn-danger btn-sm" onclick="removeAnimal(\''+full[0]+'\')">Remove</button>';
|
||||
}}
|
||||
]});
|
||||
});
|
||||
});
|
||||
});
|
||||
$("#species").click(function(){
|
||||
$.get( "/species", function( data ) {
|
||||
$( "#body" ).html("<h1>All Species</h1><table id='species-table'></table>");
|
||||
|
||||
@@ -30,61 +30,58 @@ function onSubmitAnimal(form){
|
||||
|
||||
function editAnimal(id){
|
||||
$( "#body" ).load( "/templates/animal-form.html", function(){
|
||||
var animal;
|
||||
$.get( "/animal/"+id, function( data ) {
|
||||
for(key in data.data[0])
|
||||
animal = data.data
|
||||
for(key in animal)
|
||||
{
|
||||
if(data.data[0].hasOwnProperty(key)){
|
||||
if(animal.hasOwnProperty(key)){
|
||||
if(key == "father" || key == "mother" || key == "specie" || key == "sex"){
|
||||
let a = key;
|
||||
setTimeout(function(){
|
||||
$('#a-'+a+' option[value='+data.data[0][a]+']').attr('selected','selected');
|
||||
console.log(data.data[0][a]);
|
||||
console.log(a);
|
||||
}, 200)
|
||||
}else{
|
||||
$('input[name='+key+']').val( data.data[0][key].$numberDecimal ? data.data[0][key].$numberDecimal : data.data[0][key]);
|
||||
$('input[name='+key+']').val( data.data[0][key] ? data.data[0][key].$numberDecimal ? data.data[0][key].$numberDecimal : data.data[0][key] : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$.get( "/species", function( data ) {
|
||||
data.data.map(function(item){
|
||||
$("#a-specie").append("<option value='"+item._id+"'>"+item.name+"</option>");
|
||||
})
|
||||
});
|
||||
paint_male_female(animal.specie, animal._id);
|
||||
|
||||
$("#a-specie").change(function(e){
|
||||
paint_male_female($( this ).val(), animal._id);
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function showAnimal(id){
|
||||
$( "#body" ).load( "/templates/animal-show.html", function(){
|
||||
/* $.get( "/animal/"+id, function( data ) {
|
||||
$.get( "/animal", function( animalsData ) {
|
||||
$.each(data.data[0], function(i, val) {
|
||||
$("#data").append( "<div>"+i+": "+(val.$numberDecimal ? val.$numberDecimal : val)+"</div>");
|
||||
var text = "<table><tr>";
|
||||
$.get( "/animal/"+ id, function( data ) {
|
||||
var animal = data.data,
|
||||
j = 1;
|
||||
$.each(animal, function(i, val) {
|
||||
text += "<td>"+i+"</td><td>"+(val ? val.$numberDecimal ? val.$numberDecimal : val : "")+"</td>";
|
||||
if(j % 3 == 0) text += "</tr><tr>"
|
||||
j++;
|
||||
});
|
||||
text += "</tr></table>";
|
||||
$("#a-name").html( );
|
||||
$("#data").append( text );
|
||||
// console.log(11)
|
||||
get_parrents(animal);
|
||||
// console.log(22)
|
||||
get_childrens(animal);
|
||||
// console.log(33)
|
||||
});
|
||||
});*/
|
||||
$.get('/animal/tree/' + id, function(data) {
|
||||
|
||||
var chart_config = [{
|
||||
container: "#tree",
|
||||
connectors: {
|
||||
type: 'step'
|
||||
}
|
||||
},
|
||||
{
|
||||
text: {
|
||||
name: data[0].name
|
||||
},
|
||||
//parent: data[0].ancestorsmother.filter(ancestor => ancestor.depth === 0),
|
||||
//parent: data[0].ancestorsfather.filter(ancestor => ancestor.depth === 0),
|
||||
//children: data[0].childrensmother.filter(ancestor => ancestor.depth === 0),
|
||||
//children: data[0].childrensfather.filter(ancestor => ancestor.depth === 0)
|
||||
},
|
||||
{
|
||||
text: {
|
||||
name: "test"
|
||||
},
|
||||
parent: data[0].ancestors.filter(ancestor => ancestor.depth === 0)
|
||||
}]
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
@@ -97,3 +94,35 @@ function removeAnimal(id){
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function paint_male_female(specie, id){
|
||||
$(".option").remove();
|
||||
$.get( "/animal/"+specie+"/Male", function( data ) {
|
||||
data.data.map(function(item){
|
||||
if(item._id != id) $("#a-father").append("<option class=\"option\" value='"+item._id+"'>"+item.name+" - "+ item.level +"</option>");
|
||||
})
|
||||
});
|
||||
|
||||
$.get( "/animal/"+specie+"/Female", function( data ) {
|
||||
data.data.map(function(item){
|
||||
if(item._id != id) $("#a-mother").append("<option class=\"option\" value='"+item._id+"'>"+item.name+" - "+ item.level +"</option>");
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function get_parrents(animal){
|
||||
$.get( "/animal/parrents/" + animal._id, function( data ) {
|
||||
data.data.map(function(item){
|
||||
console.log(item);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function get_childrens(animal){
|
||||
$.get( "/animal/childrens/" + animal._id, function( data ) {
|
||||
data.data.map(function(item){
|
||||
console.log(item)
|
||||
})
|
||||
});
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<form id="animal-form" onsubmit="return onSubmitAnimal(this)">
|
||||
<h5>Identication</h5>
|
||||
<div class="row">
|
||||
<h5>Identication</h5>
|
||||
<div class="row">
|
||||
<input type="hidden" class="form-control" name="_id" id="id">
|
||||
|
||||
<div class="form-group col-4">
|
||||
@@ -33,10 +33,10 @@
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h5>Initial attributes</h5>
|
||||
<div class="row">
|
||||
<h5>Initial attributes</h5>
|
||||
<div class="row">
|
||||
<div class="form-group col-2">
|
||||
<label for="a-initial_health">Initial Health</label>
|
||||
<input type="number" step="any" class="form-control" name="initial_health" id="a-inital_health" placeholder="Initial Health">
|
||||
@@ -61,9 +61,9 @@
|
||||
<label for="a-initial_velocity">Initial Velocity</label>
|
||||
<input type="number" step="any" class="form-control" name="initial_velocity" id="a-initial_velocity" placeholder="Initial Velocity">
|
||||
</div>
|
||||
</div>
|
||||
<h5>Actuality attributes</h5>
|
||||
<div class="row">
|
||||
</div>
|
||||
<h5>Actuality attributes</h5>
|
||||
<div class="row">
|
||||
<div class="form-group col-2">
|
||||
<label for="a-health">Health</label>
|
||||
<input type="number" step="any" class="form-control" name="health" id="a-health" placeholder="Health">
|
||||
@@ -88,9 +88,9 @@
|
||||
<label for="a-velocity">Velocity</label>
|
||||
<input type="number" step="any" class="form-control" name="velocity" id="a-velocity" placeholder="Velocity">
|
||||
</div>
|
||||
</div>
|
||||
<h5>Parenting attributes</h5>
|
||||
<div class="row">
|
||||
</div>
|
||||
<h5>Parenting attributes</h5>
|
||||
<div class="row">
|
||||
<div class="form-group col-3">
|
||||
<label for="a-father">Father</label>
|
||||
<select class="form-control" name="father" id="a-father" placeholder="Father"><option value="">None..</option></select>
|
||||
@@ -115,9 +115,9 @@
|
||||
<label for="a-mutations">Mutations</label>
|
||||
<input type="number" class="form-control" name="mutations" id="a-mutations" placeholder="Mutations">
|
||||
</div>
|
||||
</div>
|
||||
<h5>Clan attributes</h5>
|
||||
<div class="row">
|
||||
</div>
|
||||
<h5>Clan attributes</h5>
|
||||
<div class="row">
|
||||
<div class="form-group col-2">
|
||||
<label for="a-server">Server</label>
|
||||
<input type="text" class="form-control" name="server" id="a-server" placeholder="Server">
|
||||
@@ -132,24 +132,6 @@
|
||||
<label for="a-breeder">Breeder</label>
|
||||
<input type="text" class="form-control" name="breeder" id="a-breeder" placeholder="Breeder">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button id="animal-add-button" type="submit" class="btn btn-primary float-right">Submit</button>
|
||||
</form>
|
||||
|
||||
|
||||
<script>
|
||||
$('document').ready(function(){
|
||||
$.get( "/animal", function( data ) {
|
||||
data.data.map(function(item){
|
||||
$("#a-father, #a-mother").append("<option value='"+item._id+"'>"+item.name+" - "+ item.level +"</option>");
|
||||
})
|
||||
});
|
||||
$.get( "/species", function( data ) {
|
||||
data.data.map(function(item){
|
||||
$("#a-specie").append("<option value='"+item._id+"'>"+item.name+"</option>");
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<h1 class="a-name">Un dino</h1>
|
||||
<div class="row">
|
||||
<div id="data" class="col-6"></div>
|
||||
<div id="data" class="col-12"></div>
|
||||
<div id="tree" class="col-6"></div>
|
||||
<div id="chart" class="col-12"><h5>Aqui vendran graficas de cada atributo con el inicial y el actual, para que se pueda ver el crecimiento.</h5></div>
|
||||
</div>
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
<div class="text-center">
|
||||
<h4>Your app for your dinos.</h4>
|
||||
<h4>Inventory, breeding and family.</h4>
|
||||
<br><br><br>
|
||||
<br/><br/><br/>
|
||||
<h2>Oficial Servers Mutiplier Status</h1>
|
||||
<div id="info">
|
||||
|
||||
</div>
|
||||
<div id="info"></div>
|
||||
</div>
|
||||
|
||||
|
||||
+43
-19
@@ -35,13 +35,36 @@ router.get('/animal', (req, res, next) => {
|
||||
})
|
||||
})
|
||||
|
||||
router.get('/animal/:id', (req, res, next) => {
|
||||
animal.find({ _id: mongoose.Types.ObjectId(req.params.id) }, (err, result) => {
|
||||
router.get('/animal/childrens/:id', (req, res, next) => {
|
||||
animal.find({ $or: [ { father: req.params.id }, { mother: req.params.id } ] }, (err, result) => {
|
||||
if (err) next(err)
|
||||
else res.json({ data: result, status: 'ok' })
|
||||
})
|
||||
})
|
||||
|
||||
router.get('/animal/parrents/:id', (req, res, next) => {
|
||||
animal.find({ _id: req.params.id }, (err, result) => {
|
||||
if (err) next(err)
|
||||
else animal.find({ $or: [ { _id: result[0].father }, { _id: result[0].mother } ] }, (err, result2) => {
|
||||
if (err) next(err)
|
||||
else res.json({ data: result2, status: 'ok' })
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
router.get('/animal/:id', (req, res, next) => {
|
||||
animal.find({ _id: mongoose.Types.ObjectId(req.params.id) }, (err, result) => {
|
||||
if (err) next(err)
|
||||
else res.json({ data: result[0], status: 'ok' })
|
||||
})
|
||||
})
|
||||
|
||||
router.get('/animal/:specie/:sex', (req, res, next) => {
|
||||
animal.find({ specie: req.params.specie, sex: req.params.sex}, (err, result) => {
|
||||
if (err) next(err)
|
||||
else res.json({ data: result, status: 'ok' })
|
||||
})
|
||||
})
|
||||
|
||||
router.post('/animal', (req, res, next) => {
|
||||
let s1 = new animal(req.body)
|
||||
@@ -76,6 +99,7 @@ router.get('/info', (req, res, next) => {
|
||||
res.json(acc)
|
||||
});
|
||||
})
|
||||
|
||||
/*function recu(acc,item){
|
||||
if(item.mather != null){
|
||||
animal.find({ _id: mongoose.Types.ObjectId(item.mother) }, (err, result) => {
|
||||
@@ -86,23 +110,23 @@ router.get('/info', (req, res, next) => {
|
||||
|
||||
};
|
||||
*/
|
||||
router.get('/animal/tree/:id', (req, res, next) => {
|
||||
/* animal.find({ _id: mongoose.Types.ObjectId(req.params.id) }, (err, result) => {
|
||||
if (err) next(err)
|
||||
else res.json(recu([],result[0]))
|
||||
})
|
||||
*/
|
||||
animal.aggregate([{ $match: { _id: mongoose.Types.ObjectId(req.params.id) }},
|
||||
{ $graphLookup: { from: 'animals', startWith: ['$father', '$mother'], connectFromField: 'mother', connectToField: '_id', as: 'ancestorsmother', maxDepth: 99, depthField: 'depth' }},
|
||||
{ $graphLookup: { from: 'animals', startWith: ['$father', '$mother'], connectFromField: 'father', connectToField: '_id', as: 'ancestorsfather', maxDepth: 99, depthField: 'depth' }},
|
||||
{ $graphLookup: { from: 'animals', startWith: '$_id', connectFromField: '_id', connectToField: 'mother', as: 'childrensmother', maxDepth: 99, depthField: 'depth' }},
|
||||
{ $graphLookup: { from: 'animals', startWith: '$_id', connectFromField: '_id', connectToField: 'father', as: 'childrensfather', maxDepth: 99, depthField: 'depth' }},
|
||||
{ $project: { 'name': 1, 'sex': 1, 'father': 1, 'mother': 1, ancestors: { $setUnion: ['$ancestorsmother', '$ancestorsfather'] }, childrens: { $setUnion: ['$childrensmother', '$childrensfather'] }}
|
||||
}]).allowDiskUse(true).exec((err, connections) => {
|
||||
if (err) next(err)
|
||||
else res.json(connections)
|
||||
})
|
||||
})
|
||||
// router.get('/animal/tree/:id', (req, res, next) => {
|
||||
// /* animal.find({ _id: mongoose.Types.ObjectId(req.params.id) }, (err, result) => {
|
||||
// if (err) next(err)
|
||||
// else res.json(recu([],result[0]))
|
||||
// })
|
||||
// */
|
||||
// animal.aggregate([{ $match: { _id: mongoose.Types.ObjectId(req.params.id) }},
|
||||
// { $graphLookup: { from: 'animals', startWith: ['$father', '$mother'], connectFromField: 'mother', connectToField: '_id', as: 'ancestorsmother', maxDepth: 99, depthField: 'depth' }},
|
||||
// { $graphLookup: { from: 'animals', startWith: ['$father', '$mother'], connectFromField: 'father', connectToField: '_id', as: 'ancestorsfather', maxDepth: 99, depthField: 'depth' }},
|
||||
// { $graphLookup: { from: 'animals', startWith: '$_id', connectFromField: '_id', connectToField: 'mother', as: 'childrensmother', maxDepth: 99, depthField: 'depth' }},
|
||||
// { $graphLookup: { from: 'animals', startWith: '$_id', connectFromField: '_id', connectToField: 'father', as: 'childrensfather', maxDepth: 99, depthField: 'depth' }},
|
||||
// { $project: { 'name': 1, 'sex': 1, 'father': 1, 'mother': 1, ancestors: { $setUnion: ['$ancestorsmother', '$ancestorsfather'] }, childrens: { $setUnion: ['$childrensmother', '$childrensfather'] }}
|
||||
// }]).allowDiskUse(true).exec((err, connections) => {
|
||||
// if (err) next(err)
|
||||
// else res.json(connections)
|
||||
// })
|
||||
// })
|
||||
|
||||
app.use(bodyParser.urlencoded({
|
||||
extended: true
|
||||
|
||||
Reference in New Issue
Block a user