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

note-edit-ctrl.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @ngdoc function
  3. * @name domainManagerApp.controller:AboutCtrl
  4. * @description
  5. * # AboutCtrl
  6. * Controller of the domainManagerApp
  7. */
  8. angular.module('codexApp.noteEdit', [])
  9. .controller('NoteEditCtrl',['$scope', '$rootScope', '$state', '$timeout', 'FileService', function ($scope, $rootScope, $state, $timeout, FileService) {
  10. $scope.note = FileService.getCurrentNote();
  11. console.log('-> Editing File: ' + $scope.note.path)
  12. $scope.savedBeforeQuit = false;
  13. $rootScope.$on('window-view:change', function() {
  14. if($scope.raw_data != "" && $scope.raw_data != undefined) {
  15. if($scope.savedBeforeQuit == false) {
  16. $scope.savedBeforeQuit = true;
  17. FileService.saveFile($scope.note.path, $scope.raw_data)
  18. }
  19. }
  20. });
  21. $scope.loadFile = function() {
  22. var fs = require('fs');
  23. fs.readFile($scope.note.path, function(err, data) {
  24. $scope.note.data = new Buffer(data).toString('utf8')
  25. if(!$scope.$$phase) {
  26. $scope.$apply(function(){
  27. $scope.raw_data = $scope.note.data;
  28. });
  29. } else {
  30. $scope.raw_data = $scope.note.data;
  31. }
  32. });
  33. console.log($scope.raw_data);
  34. }
  35. if($scope.note.data != undefined || $scope.note.data != ""){
  36. $scope.loadFile();
  37. } else {
  38. $scope.raw_data = $scope.note.data;
  39. }
  40. $scope.aceLoaded = function(_editor) {
  41. _editor.setReadOnly(false);
  42. //console.log($scope.raw_data);
  43. };
  44. $scope.aceChanged = function(e) {
  45. //console.log("-> Note data changed.");
  46. };
  47. }]);