Scribe.js/static/js/services/logs.js
2014-11-11 21:20:33 +01:00

61 lines
1.4 KiB
JavaScript

(function () {
'use strict';
window.app.factory('logs', [function () {
var files = [];
var basename = function (path) {
return path.split(/[\\/]/).pop();
};
var pathInFiles = function (search) {
var result = false;
files.forEach(function (elem) {
if (elem.path === search) {
result = true;
}
});
return result;
};
return {
getLogs : function () {
return files;
},
addLog : function (path, selected) {
if (!pathInFiles(path)) {
var file;
if (typeof path === 'string') {
file = {
name : basename(path),
path : path,
selected : selected || false
};
} else {
file = path;
}
files.push(file);
}
return files;
},
setLogs : function (newFiles) {
files = newFiles.filter(function (item) {
return !!item;
});
}
};
}]);
}());