Scribe.js/static/js/controllers/dateController.js

71 lines
2 KiB
JavaScript
Raw Normal View History

2014-11-11 21:20:33 +01:00
(function () {
'use strict';
2014-11-13 21:33:37 +01:00
/**
* Dates controller
*/
2014-11-11 21:20:33 +01:00
window.app.controller('dateController', [
'$scope',
'$rootScope',
2014-11-16 21:17:09 +01:00
'$location',
2014-11-11 21:20:33 +01:00
'$filter',
'logs',
'dates',
2014-11-16 21:17:09 +01:00
function ($scope, $rootScope, $location, $filter, logs, dates) {
2014-11-11 21:20:33 +01:00
2014-11-13 21:33:37 +01:00
//reset
2014-11-11 21:20:33 +01:00
$rootScope.sidebar = false;
2014-11-16 21:17:09 +01:00
/**
* $scope.nextPage
*
* Go to to a next page
*
* @param {int} next if < 0, goes to older dates, if > 0 goes to newer dates
*/
$scope.nextPage = function (next) {
var currentDate = $location.search().from || Date.now(),
day = 24 * 60 * 60 * 1000;
$rootScope.go(
'dates',
{
path : $location.search().path,
from : next * day + parseInt(currentDate, 10),
length : 10
}
);
};
2014-11-13 21:33:37 +01:00
//build blocks
2014-11-11 21:20:33 +01:00
$scope.blocks = dates.map(function (item) {
return {
type : 'date',
messageTop : $filter('date')(item.date, 'MMM'),
message : $filter('date')(item.date, 'd'),
messageBottom : $filter('date')(item.date, 'yyyy'),
click : function () {
2014-11-13 21:33:37 +01:00
//save files
2014-11-11 21:20:33 +01:00
logs.setLogs(item.files.map(function (el, index) {
return {
selected : index === 0, //select the first by default
name : el.name,
path : el.path
};
}));
2014-11-13 21:33:37 +01:00
//redirect
2014-11-11 21:20:33 +01:00
$rootScope.go('logs');
}
};
});
}
]);
}());