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

header-ctrl.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. // Note View active button
  28. $scope.activateNoteView = function() {
  29. $rootScope.$broadcast('window-view:change');
  30. $state.go("note-view");
  31. $scope.noteViewBtnClass = "active";
  32. $scope.noteEditBtnClass = "";
  33. }
  34. $scope.activateNoteEdit = function() {
  35. $rootScope.$broadcast('window-view:change');
  36. $state.go("note-edit");
  37. $scope.noteViewBtnClass = "";
  38. $scope.noteEditBtnClass = "active";
  39. }
  40. $rootScope.$on('main-window:note-list', function() {
  41. if(!$scope.$$phase) {
  42. $scope.$apply(function(){
  43. $scope.noteViewBtnClass = "";
  44. $scope.noteEditBtnClass = "";
  45. });
  46. } else {
  47. $scope.noteViewBtnClass = "";
  48. $scope.noteEditBtnClass = "";
  49. }
  50. });
  51. $rootScope.$on('main-window:note-view', function() {
  52. if(!$scope.$$phase) {
  53. $scope.$apply(function(){
  54. $scope.noteViewBtnClass = "active";
  55. $scope.noteEditBtnClass = "";
  56. });
  57. } else {
  58. $scope.noteViewBtnClass = "active";
  59. $scope.noteEditBtnClass = "";
  60. }
  61. });
  62. }]);