mirror of
https://github.com/mathew-kurian/Scribe.js
synced 2025-04-25 06:45:10 +00:00
61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
(function () {
|
|
|
|
'use strict';
|
|
|
|
/**
|
|
* Folder controller
|
|
*/
|
|
|
|
window.app.controller('folderController', [
|
|
'$scope',
|
|
'$rootScope',
|
|
'logs',
|
|
'folder',
|
|
function ($scope, $rootScope, logs, folder) {
|
|
|
|
//reset
|
|
$rootScope.sidebar = false;
|
|
$scope.onlyFiles = true;
|
|
|
|
//build each block
|
|
$scope.blocks = folder.map(function (item) {
|
|
|
|
if (item.type !== 'file') {
|
|
$scope.onlyFiles = false;
|
|
}
|
|
|
|
return {
|
|
message : item.name,
|
|
click : function () {
|
|
if (item.type === 'file') {
|
|
|
|
//Save all current files of the folder
|
|
//But select only the clicked one
|
|
var newFiles = folder.map(function (file) {
|
|
if (file.type === 'file') {
|
|
return {
|
|
selected : file.path === item.path,
|
|
name : file.name,
|
|
path : file.path
|
|
};
|
|
} else {
|
|
return null;
|
|
}
|
|
});
|
|
|
|
//save files and redirect
|
|
logs.setLogs(newFiles);
|
|
$rootScope.go('logs');
|
|
|
|
} else {
|
|
$rootScope.go('folder', {
|
|
path : item.path
|
|
});
|
|
}
|
|
}
|
|
};
|
|
});
|
|
}
|
|
]);
|
|
|
|
}());
|