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

header-ctrl.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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', function ($scope, $rootScope, $state, FileService) {
  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. $rootScope.$broadcast('window-view:change');
  41. FileService.goToPreviousNote();
  42. $rootScope.$broadcast('note-view:reload');
  43. FileService.changeController();
  44. }
  45. // Go to the next note
  46. $scope.goForward = function() {
  47. $rootScope.$broadcast('window-view:change');
  48. FileService.goToNextNote();
  49. $rootScope.$broadcast('note-view:reload');
  50. FileService.changeController();
  51. }
  52. // Note View active button
  53. $scope.activateNoteView = function() {
  54. $rootScope.$broadcast('window-view:change');
  55. $state.go("note-view");
  56. $scope.noteViewBtnClass = "active";
  57. $scope.noteEditBtnClass = "";
  58. }
  59. $scope.activateNoteEdit = function() {
  60. $rootScope.$broadcast('window-view:change');
  61. $state.go("note-edit");
  62. $scope.noteViewBtnClass = "";
  63. $scope.noteEditBtnClass = "active";
  64. }
  65. $rootScope.$on('main-window:note-list', function() {
  66. if(!$scope.$$phase) {
  67. $scope.$apply(function(){
  68. $scope.noteViewBtnClass = "";
  69. $scope.noteEditBtnClass = "";
  70. });
  71. } else {
  72. $scope.noteViewBtnClass = "";
  73. $scope.noteEditBtnClass = "";
  74. }
  75. });
  76. $rootScope.$on('main-window:note-view', function() {
  77. if(!$scope.$$phase) {
  78. $scope.$apply(function(){
  79. $scope.noteViewBtnClass = "active";
  80. $scope.noteEditBtnClass = "";
  81. });
  82. } else {
  83. $scope.noteViewBtnClass = "active";
  84. $scope.noteEditBtnClass = "";
  85. }
  86. });
  87. $rootScope.$on('main-window:note-edit', function() {
  88. if(!$scope.$$phase) {
  89. $scope.$apply(function(){
  90. $scope.noteViewBtnClass = "";
  91. $scope.noteEditBtnClass = "active";
  92. });
  93. } else {
  94. $scope.noteViewBtnClass = "";
  95. $scope.noteEditBtnClass = "active";
  96. }
  97. });
  98. }]);