get block in angular from node!
This commit is contained in:
parent
89657e971e
commit
52f0120f39
@ -1,15 +1,13 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var Block = require('../models/Block');
|
|
||||||
//, _ = require('lodash');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
var mongoose = require('mongoose'),
|
||||||
|
Block = mongoose.model('Block');
|
||||||
|
//, _ = require('lodash');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find block by hash ...
|
* Find block by hash ...
|
||||||
|
|||||||
@ -1,5 +1,27 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module dependencies.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var mongoose = require('mongoose'),
|
||||||
|
Block = mongoose.model('Block');
|
||||||
|
|
||||||
exports.render = function(req, res) {
|
exports.render = function(req, res) {
|
||||||
res.render('index');
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@ -65,4 +65,4 @@ BlockSchema.statics.fromHash = function(hash, cb) {
|
|||||||
}).exec(cb);
|
}).exec(cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = mongoose.model('Block', BlockSchema);
|
mongoose.model('Block', BlockSchema);
|
||||||
|
|||||||
@ -24,6 +24,7 @@ script(type='text/javascript', src='/js/filters.js')
|
|||||||
|
|
||||||
//Application Services
|
//Application Services
|
||||||
script(type='text/javascript', src='/js/services/global.js')
|
script(type='text/javascript', src='/js/services/global.js')
|
||||||
|
script(type='text/javascript', src='/js/services/index.js')
|
||||||
|
|
||||||
//Application Controllers
|
//Application Controllers
|
||||||
script(type='text/javascript', src='/js/controllers/index.js')
|
script(type='text/javascript', src='/js/controllers/index.js')
|
||||||
|
|||||||
@ -2,24 +2,3 @@ extends layouts/default
|
|||||||
|
|
||||||
block content
|
block content
|
||||||
section.container(data-ng-view)
|
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
|
|
||||||
|
|||||||
@ -5,12 +5,12 @@ module.exports = function(app) {
|
|||||||
//Home route
|
//Home route
|
||||||
var index = require('../app/controllers/index');
|
var index = require('../app/controllers/index');
|
||||||
app.get('/', index.render);
|
app.get('/', index.render);
|
||||||
|
app.get('/last_blocks', index.all);
|
||||||
|
|
||||||
//Block routes
|
//Block routes
|
||||||
|
|
||||||
var blocks = require('../app/controllers/blocks');
|
var blocks = require('../app/controllers/blocks');
|
||||||
app.get('/block/:blockHash', blocks.show);
|
app.get('/block/:blockHash', blocks.show);
|
||||||
|
|
||||||
|
|
||||||
app.param('blockHash', blocks.block);
|
app.param('blockHash', blocks.block);
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
'use strict';
|
'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', []);
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
'use strict';
|
'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.global = Global;
|
||||||
}]);
|
$scope.last_blocks = function() {
|
||||||
|
Index.query(function(blocks) {
|
||||||
|
$scope.blocks = blocks;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}]);
|
||||||
|
|||||||
5
public/js/services/index.js
Normal file
5
public/js/services/index.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
angular.module('mystery.index').factory('Index', ['$resource', function($resource) {
|
||||||
|
return $resource('/last_blocks');
|
||||||
|
}]);
|
||||||
@ -1,5 +1,10 @@
|
|||||||
<section data-ng-controller="IndexController">
|
<section data-ng-controller="IndexController" data-ng-init="last_blocks()">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1>Hello BitPay!</h1>
|
<h1>Hello BitPay!</h1>
|
||||||
</div>
|
</div>
|
||||||
|
<ul>
|
||||||
|
<li data-ng-repeat="block in blocks">
|
||||||
|
<span>{{block.hash}}</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user