2014-11-11 21:20:33 +01:00
|
|
|
(function () {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
/**
|
|
|
|
* ScribeJS - WebPanel
|
|
|
|
*/
|
|
|
|
|
2014-11-11 21:20:33 +01:00
|
|
|
window.app = angular.module('scribe', ['ngRoute', 'ngResource', 'ngToggle', 'autocomplete']);
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
//Configure routes
|
2014-11-11 21:20:33 +01:00
|
|
|
app.config(['$routeProvider', function ($routeProvider) {
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
/**
|
|
|
|
* Routes :
|
|
|
|
*
|
|
|
|
* - /
|
|
|
|
* Home page. Choose the good logger
|
|
|
|
* - /dates/?path
|
2014-11-14 14:20:42 +01:00
|
|
|
* Choose the dates.
|
2014-11-13 21:33:37 +01:00
|
|
|
* - /folder/?path
|
2014-11-14 14:20:42 +01:00
|
|
|
* Explore directories.
|
2014-11-13 21:33:37 +01:00
|
|
|
* - /logs
|
|
|
|
* The logs viewer
|
|
|
|
*/
|
|
|
|
|
2014-11-11 21:20:33 +01:00
|
|
|
$routeProvider
|
|
|
|
|
|
|
|
.when('/', {
|
2014-11-14 14:20:42 +01:00
|
|
|
templateUrl : 'partials/folder.html',
|
2014-11-11 21:20:33 +01:00
|
|
|
controller : 'homeController'
|
|
|
|
})
|
|
|
|
|
|
|
|
.when('/dates/', {
|
2014-11-14 14:20:42 +01:00
|
|
|
templateUrl : 'partials/dates.html',
|
2014-11-11 21:20:33 +01:00
|
|
|
controller : 'dateController',
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
// resolve dates
|
2014-11-11 21:20:33 +01:00
|
|
|
resolve : {
|
|
|
|
dates : [
|
|
|
|
'ScribeAPI',
|
|
|
|
'$rootScope',
|
|
|
|
'$location',
|
|
|
|
function (ScribeAPI, $rootScope, $location) {
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
//query params
|
|
|
|
var from = $location.search().from || Date.now(), //timestamp
|
|
|
|
length = $location.search().length || 10, //number of dates to show
|
|
|
|
logWriter = $location.search().path; //which log writer to use ?
|
2014-11-11 21:20:33 +01:00
|
|
|
|
|
|
|
$rootScope.title = logWriter + ' dates';
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
//Get dates
|
2014-11-11 21:20:33 +01:00
|
|
|
return ScribeAPI.dateExplorer({
|
|
|
|
logFolder : logWriter,
|
|
|
|
from : from,
|
|
|
|
length : length
|
|
|
|
}).$promise;
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
.when('/folder/', {
|
2014-11-14 14:20:42 +01:00
|
|
|
templateUrl : 'partials/folder.html',
|
2014-11-11 21:20:33 +01:00
|
|
|
controller : 'folderController',
|
2014-11-13 21:33:37 +01:00
|
|
|
|
|
|
|
//resolve folder content
|
2014-11-11 21:20:33 +01:00
|
|
|
resolve : {
|
|
|
|
folder : [
|
|
|
|
'ScribeAPI',
|
|
|
|
'$rootScope',
|
|
|
|
'$location',
|
|
|
|
function (ScribeAPI, $rootScope, $location) {
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
//folder path
|
2014-11-11 21:20:33 +01:00
|
|
|
var path = $location.search().path;
|
|
|
|
|
|
|
|
$rootScope.title = path;
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
//Get folder content
|
2014-11-11 21:20:33 +01:00
|
|
|
return ScribeAPI.folderExplorer({
|
|
|
|
path : path
|
|
|
|
}).$promise;
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
.when('/logs/', {
|
|
|
|
templateUrl : 'partials/logs.html',
|
|
|
|
controller : 'logsController'
|
|
|
|
});
|
|
|
|
}]);
|
|
|
|
|
|
|
|
app.run([
|
|
|
|
'$rootScope',
|
|
|
|
'$location',
|
|
|
|
'$q',
|
|
|
|
'$window',
|
|
|
|
'ScribeAPI',
|
|
|
|
function ($rootScope, $location, $q, $window, ScribeAPI) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getAllLogsFiles
|
|
|
|
*
|
|
|
|
* Retrieve all logs files of all loggers
|
2014-11-13 21:33:37 +01:00
|
|
|
* All files path are stored in the history file of each logger
|
2014-11-11 21:20:33 +01:00
|
|
|
*
|
|
|
|
* @param {Array} loggers
|
|
|
|
* @return {promise}
|
|
|
|
*/
|
|
|
|
var getAllLogsFiles = function (loggers) {
|
|
|
|
|
|
|
|
var deferred = $q.defer(),
|
|
|
|
loggersHistory = [];
|
|
|
|
|
|
|
|
//First, get all history files
|
|
|
|
loggers.forEach(function (logger) {
|
|
|
|
loggersHistory.push(ScribeAPI.log({
|
|
|
|
path: logger + '/history.json'
|
|
|
|
}).$promise);
|
|
|
|
});
|
|
|
|
|
|
|
|
//Then, extract all files path (they're saved by date)
|
|
|
|
$q.all(loggersHistory).then(function (data) {
|
|
|
|
|
|
|
|
var files = [];
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
//extract the paths and push them in the `files` array
|
2014-11-11 21:20:33 +01:00
|
|
|
data.forEach(function (history) {
|
|
|
|
Object.keys(history[0].dates).forEach(function (date) {
|
|
|
|
files = files.concat(history[0].dates[date]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
//send the array
|
2014-11-11 21:20:33 +01:00
|
|
|
deferred.resolve(files);
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
/**
|
|
|
|
* $rootScope.mode
|
|
|
|
*
|
|
|
|
* Webpanel mode. Wether use folder or dates mode by default
|
|
|
|
*
|
|
|
|
* @type {String} 'folder' | 'dates'
|
|
|
|
*/
|
2014-11-11 21:20:33 +01:00
|
|
|
$rootScope.mode = 'dates';
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
/**
|
|
|
|
* $rootScope.title
|
|
|
|
*
|
|
|
|
* Page title
|
|
|
|
*
|
|
|
|
* @type {String}
|
|
|
|
*/
|
2014-11-11 21:20:33 +01:00
|
|
|
$rootScope.title = "ScribeJS";
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
/**
|
|
|
|
* $rootScope.sidebar
|
|
|
|
*
|
|
|
|
* Open/close sidebar
|
|
|
|
*
|
|
|
|
* @type {Boolean}
|
|
|
|
*/
|
2014-11-11 21:20:33 +01:00
|
|
|
$rootScope.sidebar = false;
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
/**
|
|
|
|
* $rootScope.logWriters
|
|
|
|
*
|
|
|
|
* Stores all logsWriters of the app
|
|
|
|
*
|
|
|
|
* @type {Array}
|
|
|
|
*/
|
2014-11-11 21:20:33 +01:00
|
|
|
$rootScope.logWriters = [];
|
2014-11-13 21:33:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* $rootScope.allLogsFiles
|
|
|
|
*
|
|
|
|
* Stores all files of all logWriters
|
|
|
|
*
|
|
|
|
* @type {Array}
|
|
|
|
*/
|
2014-11-11 21:20:33 +01:00
|
|
|
$rootScope.allLogsFiles = [];
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
//Get all logWriters
|
|
|
|
//Get all log files of atll logWriters
|
2014-11-11 21:20:33 +01:00
|
|
|
ScribeAPI.logWriters(function (logWriters) {
|
|
|
|
$rootScope.logWriters = logWriters;
|
|
|
|
getAllLogsFiles(logWriters).then(function (files) {
|
|
|
|
$rootScope.allLogsFiles = files;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
/**
|
|
|
|
* $rootScope.back
|
|
|
|
*
|
|
|
|
* History back
|
|
|
|
*
|
|
|
|
* @type {Function}
|
|
|
|
*/
|
2014-11-11 21:20:33 +01:00
|
|
|
$rootScope.back = function () {
|
|
|
|
$window.history.back();
|
|
|
|
};
|
|
|
|
|
2014-11-13 21:33:37 +01:00
|
|
|
/**
|
|
|
|
* $rootScope.go
|
|
|
|
*
|
|
|
|
* Wrapper for $location path and search
|
|
|
|
*
|
|
|
|
* @type {Function}
|
|
|
|
*/
|
2014-11-11 21:20:33 +01:00
|
|
|
$rootScope.go = function (path, search) {
|
|
|
|
$location.path(path);
|
|
|
|
if (search) {
|
|
|
|
$location.search(search);
|
|
|
|
} else {
|
|
|
|
$location.search({});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}());
|