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

header-ctrl.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * @ngdoc function
  3. * @name domainManagerApp.controller:AboutCtrl
  4. * @description
  5. * # AboutCtrl
  6. * Controller of the domainManagerApp
  7. */
  8. angular.module('codexApp.header', [])
  9. .controller('HeaderCtrl',['$scope', '$rootScope', '$state', 'FileService', 'SearchService', 'PrefsService', function ($scope, $rootScope, $state, FileService, SearchService, PrefsService) {
  10. console.log('-> Header loaded')
  11. $scope.noteViewBtnClass = "";
  12. $scope.noteEditBtnClass = "";
  13. // Create New Note
  14. $scope.createNewNote = function() {
  15. dialog.showSaveDialog({ defaultPath: FileService.getDefaultNotesDir(), filters: [ { name: 'markdown', extensions: ['md'] }] }, function (fileName) {
  16. var fs = require('fs');
  17. if (fileName === undefined) return;
  18. fs.writeFile(fileName, "", function (err) {
  19. console.log("-> CREATE NEW NOTE: " + fileName)
  20. var note = FileService.getNote(fileName);
  21. FileService.setCurrentNote(note)
  22. console.log(note)
  23. $scope.activateNoteEdit();
  24. });
  25. });
  26. }
  27. // Toogle sidebar
  28. $scope.toogleSidebar = function() {
  29. $rootScope.$broadcast('sidebar:toogle');
  30. }
  31. // Go To Home note
  32. $scope.goToHome = function() {
  33. $rootScope.$broadcast('window-view:change');
  34. FileService.setCurrentNote(FileService.getDefaultNote());
  35. $rootScope.$broadcast('note-view:reload');
  36. $state.go("note-view");
  37. }
  38. // Go to the precious note
  39. $scope.goBack = function() {
  40. FileService.goToPreviousNote();
  41. }
  42. // Go to the next note
  43. $scope.goForward = function() {
  44. FileService.goToNextNote();
  45. }
  46. // Note View active button
  47. $scope.activateNoteView = function() {
  48. $rootScope.$broadcast('window-view:change');
  49. $state.go("note-view");
  50. $scope.noteViewBtnClass = "active";
  51. $scope.noteEditBtnClass = "";
  52. }
  53. $scope.activateNoteEdit = function() {
  54. $rootScope.$broadcast('window-view:change');
  55. $state.go("note-edit");
  56. $scope.noteViewBtnClass = "";
  57. $scope.noteEditBtnClass = "active";
  58. }
  59. $rootScope.$on('main-window:note-list', function() {
  60. if(!$scope.$$phase) {
  61. $scope.$apply(function(){
  62. $scope.noteViewBtnClass = "";
  63. $scope.noteEditBtnClass = "";
  64. });
  65. } else {
  66. $scope.noteViewBtnClass = "";
  67. $scope.noteEditBtnClass = "";
  68. }
  69. });
  70. $rootScope.$on('main-window:note-view', function() {
  71. if(!$scope.$$phase) {
  72. $scope.$apply(function(){
  73. $scope.noteViewBtnClass = "active";
  74. $scope.noteEditBtnClass = "";
  75. });
  76. } else {
  77. $scope.noteViewBtnClass = "active";
  78. $scope.noteEditBtnClass = "";
  79. }
  80. });
  81. $rootScope.$on('main-window:note-edit', function() {
  82. if(!$scope.$$phase) {
  83. $scope.$apply(function(){
  84. $scope.noteViewBtnClass = "";
  85. $scope.noteEditBtnClass = "active";
  86. });
  87. } else {
  88. $scope.noteViewBtnClass = "";
  89. $scope.noteEditBtnClass = "active";
  90. }
  91. });
  92. // Search Functions
  93. SearchService.init();
  94. $scope.fileSearch = function(){
  95. console.log("> SEARCHING: " + $scope.search_text);
  96. var results = SearchService.search($scope.search_text);
  97. FileService.setSearchedFiles(results);
  98. var current_note = {
  99. path : "search",
  100. type : "Folder",
  101. title: $scope.search_text,
  102. search_results: results
  103. }
  104. FileService.setCurrentNote(current_note)
  105. PrefsService.setCurrentView("Searched Files");
  106. //$scope.activateSidebarBtn(0);
  107. $rootScope.$broadcast('main-window:note-list');
  108. $rootScope.$broadcast('window-view:change');
  109. $state.go("index");
  110. }
  111. }]);