Desktop markdown wiki app. Built with node, Electron Framework and AngularJS.

sidebar-ctrl.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * @ngdoc function
  3. * @name domainManagerApp.controller:AboutCtrl
  4. * @description
  5. * # AboutCtrl
  6. * Controller of the domainManagerApp
  7. */
  8. angular.module('codexApp.sidebar', [])
  9. .controller('SidebarCtrl',['$scope', '$rootScope', '$state', 'PrefsService', "FileService", function ($scope, $rootScope, $state, PrefsService, FileService) {
  10. console.log('-> Sidebar loaded')
  11. $scope.showSidebar = true;
  12. $scope.goToAllNotes = function() {
  13. PrefsService.setCurrentView("All Notes");
  14. $scope.activateSidebarBtn(0);
  15. $rootScope.$broadcast('main-window:note-list');
  16. $rootScope.$broadcast('window-view:change');
  17. $state.go("index");
  18. }
  19. $scope.goToAllFiles = function() {
  20. PrefsService.setCurrentView("All Files");
  21. $scope.activateSidebarBtn(1);
  22. $rootScope.$broadcast('main-window:file-list');
  23. $rootScope.$broadcast('window-view:change');
  24. $state.go("index");
  25. }
  26. $scope.goToNotebooks = function() {
  27. FileService.setCurrentNote(FileService.getNote(FileService.getNotesDir()));
  28. PrefsService.setCurrentView("Notebooks");
  29. $scope.activateSidebarBtn(2);
  30. $rootScope.$broadcast('main-window:file-list');
  31. $rootScope.$broadcast('window-view:change');
  32. $state.go("index");
  33. }
  34. $rootScope.$on('main-window:note-view', function(){
  35. $scope.activateSidebarBtn();
  36. });
  37. $rootScope.$on('sidebar:toogle', function() {
  38. if(!$scope.$$phase) {
  39. $scope.$apply(function(){
  40. $scope.toogleSidebar();
  41. });
  42. } else {
  43. $scope.toogleSidebar();
  44. }
  45. });
  46. $scope.toogleSidebar = function() {
  47. if( $scope.showSidebar == true){
  48. $scope.showSidebar = false;
  49. } else {
  50. $scope.showSidebar = true;
  51. }
  52. }
  53. $scope.sidebar = [
  54. {
  55. "view" : "All Notes",
  56. "active" : "active"
  57. },
  58. {
  59. "view" : "All Files",
  60. "active" : ""
  61. },
  62. {
  63. "view" : "Notebooks",
  64. "active" : ""
  65. }
  66. ]
  67. $scope.activateSidebarBtn = function(num) {
  68. if(!$scope.$$phase) {
  69. $scope.$apply(function(){
  70. for (var i = 0; i < $scope.sidebar.length; i++) {
  71. $scope.sidebar[i].active = "";
  72. }
  73. $scope.sidebar[num].active = "active";
  74. });
  75. } else {
  76. for (var i = 0; i < $scope.sidebar.length; i++) {
  77. $scope.sidebar[i].active = "";
  78. }
  79. if (typeof(num)==='undefined') return;
  80. $scope.sidebar[num].active = "active";
  81. }
  82. }
  83. }]);