diff --git a/familyark/app/public/js/buttons.js b/familyark/app/public/js/buttons.js index cee9229..7633341 100644 --- a/familyark/app/public/js/buttons.js +++ b/familyark/app/public/js/buttons.js @@ -2,51 +2,59 @@ $('document').ready(function(){ $( "#body" ).load( "/templates/home.html" ); // Botones - $("#home").click(function(){ - $( "#body" ).load( "/templates/home.html" ); - }); + $("#home").click(function(){ + $( "#body" ).load( "/templates/home.html" ); + }); $("#animals").click(function(){ $.get( "/animal", function( data ) { - $( "#body" ).html("

Yours Dinos



"); - $( "#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]; + $.get( "/species", function( species_r ) { + var species = {}; + species_r.data.map(function(item) { + species[item._id] = item.name + }); + + $( "#body" ).html("

Yours Dinos



"); + $( "#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, species[item.specie]]; + }); + $('#animals-table').DataTable({ + data: dataSet, + responsive: true, + columns: [ + { 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 '    '; + }} + ]}); }); - $('#animals-table').DataTable({ - data: dataSet, - responsive: true, - columns: [ - { title: "id", visible: false}, - { title: "Name" }, - { title: "Level" }, - { title: "Options", className: "options-table", orderable: false,data: null, targets: -1, "mRender": function(data, type, full) { - return '    '; - }} - ]}); }); }); - $("#species").click(function(){ - $.get( "/species", function( data ) { + $("#species").click(function(){ + $.get( "/species", function( data ) { $( "#body" ).html("

All Species

"); - dataSet = data.data.map(function(item) { + dataSet = data.data.map(function(item) { return [item.name, item.description]; }); $('#species-table').DataTable({ - data: dataSet, + data: dataSet, responsive: true, - columns: [ - { title: "Name" }, - { title: "Description" }, - { title: "Options", className: "options-table-species", orderable: false,data: null, targets: -1, "mRender": function(data, type, full) { - return '' - }} - ] + columns: [ + { title: "Name" }, + { title: "Description" }, + { title: "Options", className: "options-table-species", orderable: false,data: null, targets: -1, "mRender": function(data, type, full) { + return '' + }} + ] }); - }); - }); + }); + }); $("#about").click(function(){ $( "#body" ).load( "/templates/about.html" ); diff --git a/familyark/app/public/js/functions.js b/familyark/app/public/js/functions.js index 2a9737c..d029420 100644 --- a/familyark/app/public/js/functions.js +++ b/familyark/app/public/js/functions.js @@ -2,27 +2,27 @@ //Funtions function onSubmitAnimal(form){ - var data = {}; + var data = {}; $.map($(form).serializeArray(), function(n, i){ if(n['value']!= "") data[n['name']] = n['value']; else data[n['name']] = null; }); if(data._id){ - $.ajax({ - type: "PUT", - url: "/animal/"+data._id, - data: JSON.stringify(data), - success: function() { $("#animals").click() }, - contentType : "application/json" - }); + $.ajax({ + type: "PUT", + url: "/animal/"+data._id, + data: JSON.stringify(data), + success: function() { $("#animals").click() }, + contentType : "application/json" + }); }else{ $.ajax({ - type: "POST", - url: "/animal", - data: JSON.stringify(data), - success: function() { $("#animals").click() }, - contentType : "application/json" + type: "POST", + url: "/animal", + data: JSON.stringify(data), + success: function() { $("#animals").click() }, + contentType : "application/json" }); } return false; @@ -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); + $('#a-'+a+' option[value='+data.data[0][a]+']').attr('selected','selected'); }, 200) - }else{ - $('input[name='+key+']').val( data.data[0][key].$numberDecimal ? data.data[0][key].$numberDecimal : data.data[0][key]); + }else{ + $('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(""); + }) + }); + 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( "
"+i+": "+(val.$numberDecimal ? val.$numberDecimal : val)+"
"); - }); + var text = ""; + $.get( "/animal/"+ id, function( data ) { + var animal = data.data, + j = 1; + $.each(animal, function(i, val) { + text += ""; + if(j % 3 == 0) text += "" + j++; }); - });*/ - $.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) - }] - }) + text += "
"+i+""+(val ? val.$numberDecimal ? val.$numberDecimal : val : "")+"
"; + $("#a-name").html( ); + $("#data").append( text ); + // console.log(11) + get_parrents(animal); + // console.log(22) + get_childrens(animal); + // console.log(33) + }); + }); } @@ -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(""); + }) + }); + + $.get( "/animal/"+specie+"/Female", function( data ) { + data.data.map(function(item){ + if(item._id != id) $("#a-mother").append(""); + }) + }); +} + +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) + }) + }); +} \ No newline at end of file diff --git a/familyark/app/public/templates/animal-form.html b/familyark/app/public/templates/animal-form.html index 26028a0..b596f1e 100644 --- a/familyark/app/public/templates/animal-form.html +++ b/familyark/app/public/templates/animal-form.html @@ -1,155 +1,137 @@
-
Identication
-
- - -
- - -
-
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- - -
- -
Initial attributes
-
-
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
-
-
Actuality attributes
-
-
- - -
- -
- - +
Identication
+
+ + +
+ + +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ +
Initial attributes
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
Actuality attributes
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
Parenting attributes
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
Clan attributes
+
+
+ + +
+ +
+ + +
+ +
+ + +
- -
- - -
- -
- - -
- -
- - -
-
-
Parenting attributes
-
-
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
-
-
Clan attributes
-
-
- - -
- -
- - -
- -
- - -
-
- - - diff --git a/familyark/app/public/templates/animal-show.html b/familyark/app/public/templates/animal-show.html index 3857897..d599c56 100644 --- a/familyark/app/public/templates/animal-show.html +++ b/familyark/app/public/templates/animal-show.html @@ -1,6 +1,6 @@

Un dino

-
+
Aqui vendran graficas de cada atributo con el inicial y el actual, para que se pueda ver el crecimiento.
diff --git a/familyark/app/public/templates/home.html b/familyark/app/public/templates/home.html index 396ae96..7c4e27b 100644 --- a/familyark/app/public/templates/home.html +++ b/familyark/app/public/templates/home.html @@ -2,10 +2,7 @@

Your app for your dinos.

Inventory, breeding and family.

-


+


Oficial Servers Mutiplier Status

-
- -
-
- +
+
\ No newline at end of file diff --git a/familyark/app/server.js b/familyark/app/server.js index 95f26c0..59e1c51 100644 --- a/familyark/app/server.js +++ b/familyark/app/server.js @@ -24,7 +24,7 @@ http.createServer(app) router.get('/species', (req, res, next) => { species.find({}, (err, result) => { if (err) next(err) - else res.json({ data: result, status: 'ok' }) + else res.json({ data: result, status: 'ok' }) }) }) @@ -35,13 +35,36 @@ router.get('/animal', (req, res, next) => { }) }) +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, status: 'ok' }) + 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