get block in angular from node!

This commit is contained in:
Gustavo Cortez 2014-01-07 18:12:37 -03:00
parent 89657e971e
commit 52f0120f39
10 changed files with 50 additions and 34 deletions

View File

@ -1,15 +1,13 @@
'use strict';
var Block = require('../models/Block');
//, _ = require('lodash');
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Block = mongoose.model('Block');
//, _ = require('lodash');
/**
* Find block by hash ...

View File

@ -1,5 +1,27 @@
'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Block = mongoose.model('Block');
exports.render = function(req, res) {
res.render('index');
};
/**
* List of blocks at HomePage
*/
exports.all = function(req, res) {
Block.find().limit(7).exec(function(err, blocks) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(blocks);
}
});
};

View File

@ -65,4 +65,4 @@ BlockSchema.statics.fromHash = function(hash, cb) {
}).exec(cb);
};
module.exports = mongoose.model('Block', BlockSchema);
mongoose.model('Block', BlockSchema);

View File

@ -24,6 +24,7 @@ script(type='text/javascript', src='/js/filters.js')
//Application Services
script(type='text/javascript', src='/js/services/global.js')
script(type='text/javascript', src='/js/services/index.js')
//Application Controllers
script(type='text/javascript', src='/js/controllers/index.js')

View File

@ -2,24 +2,3 @@ extends layouts/default
block content
section.container(data-ng-view)
section.container
p ˈmɪst(ə)ri/'
| noun
audio(src="https://ssl.gstatic.com/dictionary/static/sounds/de/0/mystery.mp3",preload="auto",data-dobid="aud",id="aud")
button(onclick="document.getElementById('aud').play()") Play
ol
li
strong something that is difficult or impossible to understand or explain.
p "the mysteries of outer space"
| synonyms: puzzle, enigma, conundrum, riddle, secret, unsolved problem, problem, question, question mark, closed book; secrecy or obscurity.
p "much of her past is shrouded in mystery"
| synonyms: secrecy, darkness, obscurity, ambiguity, ambiguousness, uncertainty, impenetrability, vagueness, nebulousness; More
li
strong a person or thing whose identity or nature is puzzling or unknown.
p "He's a bit of a mystery, said Nina"
li
strong a novel, play, or film dealing with a puzzling crime, especially a murder.
p "the 1920s murder mystery, The Ghost Train"
| synonyms: thriller, detective story/novel, murder story; More

View File

@ -5,12 +5,12 @@ module.exports = function(app) {
//Home route
var index = require('../app/controllers/index');
app.get('/', index.render);
app.get('/last_blocks', index.all);
//Block routes
var blocks = require('../app/controllers/blocks');
app.get('/block/:blockHash', blocks.show);
app.param('blockHash', blocks.block);

View File

@ -1,5 +1,6 @@
'use strict';
angular.module('mystery', ['ngCookies', 'ngResource', 'ngRoute', 'ui.bootstrap', 'ui.route', 'mystery.system']);
angular.module('mystery', ['ngCookies', 'ngResource', 'ngRoute', 'ui.bootstrap', 'ui.route', 'mystery.system', 'mystery.index']);
angular.module('mystery.system', []);
angular.module('mystery.system', []);
angular.module('mystery.index', []);

View File

@ -1,5 +1,10 @@
'use strict';
angular.module('mystery.system').controller('IndexController', ['$scope', 'Global', function ($scope, Global) {
angular.module('mystery.system').controller('IndexController', ['$scope', 'Global', 'Index', function ($scope, Global, Index) {
$scope.global = Global;
}]);
$scope.last_blocks = function() {
Index.query(function(blocks) {
$scope.blocks = blocks;
});
};
}]);

View File

@ -0,0 +1,5 @@
'use strict';
angular.module('mystery.index').factory('Index', ['$resource', function($resource) {
return $resource('/last_blocks');
}]);

View File

@ -1,5 +1,10 @@
<section data-ng-controller="IndexController">
<section data-ng-controller="IndexController" data-ng-init="last_blocks()">
<div class="page-header">
<h1>Hello BitPay!</h1>
</div>
<ul>
<li data-ng-repeat="block in blocks">
<span>{{block.hash}}</span>
</li>
</ul>
</section>