added new blocklist page

This commit is contained in:
Mario Colque 2014-01-08 11:56:36 -03:00
parent f6d870bb5e
commit c967df577e
4 changed files with 46 additions and 3 deletions

View File

@ -23,7 +23,7 @@ exports.block = function(req, res, next, hash) {
/**
* Show block
* Show block
*/
exports.show = function(req, res) {
res.jsonp(req.block);
@ -44,3 +44,26 @@ exports.last_blocks = function(req, res) {
});
};
/**
* List of blocks by date
*/
exports.list = function(req, res) {
var findParam = {};
if (req.query.blockDate) {
findParam = {};
}
Block
.find(findParam)
.limit(5)
.exec(function(err, blocks) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(blocks);
}
});
};

View File

@ -7,6 +7,12 @@ angular.module('mystery').config(['$routeProvider',
when('/', {
templateUrl: 'views/index.html'
}).
when('/blocks', {
templateUrl: 'views/blocks/list.html'
}).
when('/blocks-date/:blockDate', {
templateUrl: 'views/blocks/list_date.html'
}).
otherwise({
redirectTo: '/'
});

View File

@ -2,7 +2,21 @@
angular.module('mystery.blocks').controller('BlocksController', ['$scope', '$routeParams', '$location', 'Global', 'Blocks', function ($scope, $routeParams, $location, Global, Blocks) {
$scope.global = Global;
$scope.list_blocks = function() {
Blocks.query(function(blocks) {
$scope.blocks = blocks;
});
};
$scope.list_blocks_date = function() {
Blocks.query({
blockDate: $routeParams.blockDate
}, function(blocks) {
$scope.blocks = blocks;
});
};
// for avoid warning. please remove when you use Blocks
$scope.blocks = Blocks;
}]);

View File

@ -1,5 +1,5 @@
'use strict';
angular.module('mystery.blocks').factory('Blocks', ['$resource', function($resource) {
return $resource;
return $resource('/api/blocks');
}]);