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

app-ctrl.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**
  2. * @ngdoc function
  3. * @name domainManagerApp.controller:AboutCtrl
  4. * @description
  5. * # AboutCtrl
  6. * Controller of the domainManagerApp
  7. */
  8. angular.module('codexApp.index', [])
  9. .controller('AppCtrl', ['$scope', '$rootScope', '$state', '$location', 'FileService', function ($scope, $rootScope, $state, $location, FileService) {
  10. $scope.files = FileService.getNotes();
  11. var remote = require('remote')
  12. var Menu = remote.require('menu')
  13. var MenuItem = remote.require('menu-item')
  14. // Build our new menu
  15. var menu = new Menu()
  16. menu.append(new MenuItem({
  17. label: "append",
  18. click: function() {
  19. // Trigger an alert when menu item is clicked
  20. alert('Deleted')
  21. }
  22. }))
  23. menu.append(new MenuItem({
  24. label: 'More Info...',
  25. click: function() {
  26. // Trigger an alert when menu item is clicked
  27. alert('Here is more information')
  28. }
  29. }))
  30. // Add the listener
  31. document.addEventListener('DOMContentLoaded', function () {
  32. document.querySelector('.js-context-menu').addEventListener('click', function (event) {
  33. menu.popup(remote.getCurrentWindow());
  34. })
  35. })
  36. var holder = document.getElementById('holder');
  37. holder.ondragover = function () {
  38. return false;
  39. };
  40. holder.ondragleave = holder.ondragend = function () {
  41. return false;
  42. };
  43. holder.ondrop = function (e) {
  44. e.preventDefault();
  45. var file = e.dataTransfer.files[0];
  46. console.log('File you dragged here is', file.path);
  47. document.getElementById('image-container').src = file.path
  48. return false;
  49. };
  50. $scope.openNote = function(note){
  51. //console.log($location.path());
  52. console.log("openning note " + note.title + " (" + note.id + ")");
  53. FileService.setCurrentNote(note)
  54. $rootScope.$broadcast('main-window:note-view');
  55. $state.go("note-view");
  56. //$location.path('/notes/' + 'test1')
  57. //console.log($location.path());
  58. }
  59. $rootScope.$on('file-service:files-loaded', function(){
  60. if(!$scope.$$phase) {
  61. $scope.$apply(function(){
  62. //$scope.itemSpacing();
  63. });
  64. } else {
  65. //$scope.itemSpacing();
  66. }
  67. })
  68. $rootScope.$on('$stateNotFound', function(event, unfoundState, fromState, fromParams){
  69. console.log(unfoundState.to); // "lazy.state"
  70. console.log(unfoundState.toParams); // {a:1, b:2}
  71. console.log(unfoundState.options); // {inherit:false} + default options
  72. })
  73. $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error){
  74. console.log('Change state error'); // "lazy.state"
  75. console.log(error)
  76. console.log(toState)
  77. console.log(toParams)
  78. console.log(fromState)
  79. console.log(fromParams)
  80. })
  81. $scope.itemSpacing = function(){
  82. var items = document.getElementsByClassName("file-view-item");
  83. for (var i = 0; i < items.length; i++) {
  84. items[i].style.margin = "15px";
  85. }
  86. }
  87. $scope.isImage = function(file_type) {
  88. if(file_type != 'Image') { return true; }
  89. else { return false; }
  90. }
  91. $scope.getImageURL = function(img_url) {
  92. return "../codex/" + FileService.absoluteToRelativeURL(FileService.getNotesDir(), img_url)
  93. }
  94. }]);