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

app-ctrl.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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', 'PrefsService', function ($scope, $rootScope, $state, $location, FileService, PrefsService) {
  10. $scope.setView = function() {
  11. $scope.view = PrefsService.getCurrentView();
  12. switch ($scope.view) {
  13. case "All Notes":
  14. $scope.files = FileService.getAllNotes();
  15. break;
  16. case "All Files":
  17. $scope.files = FileService.getAllFiles();
  18. break;
  19. case "Notebooks":
  20. $scope.files = FileService.getFolders();
  21. }
  22. }
  23. $scope.setView();
  24. $rootScope.$on('window-view:change', function(){
  25. $scope.setView();
  26. });
  27. var remote = require('remote')
  28. var Menu = remote.require('menu')
  29. var MenuItem = remote.require('menu-item')
  30. // Build our new menu
  31. var menu = new Menu()
  32. menu.append(new MenuItem({
  33. label: "append",
  34. click: function() {
  35. // Trigger an alert when menu item is clicked
  36. alert('Deleted')
  37. }
  38. }))
  39. menu.append(new MenuItem({
  40. label: 'More Info...',
  41. click: function() {
  42. // Trigger an alert when menu item is clicked
  43. alert('Here is more information')
  44. }
  45. }))
  46. // Add the listener
  47. document.addEventListener('DOMContentLoaded', function () {
  48. document.querySelector('.js-context-menu').addEventListener('click', function (event) {
  49. menu.popup(remote.getCurrentWindow());
  50. })
  51. })
  52. var holder = document.getElementById('holder');
  53. holder.ondragover = function () {
  54. return false;
  55. };
  56. holder.ondragleave = holder.ondragend = function () {
  57. return false;
  58. };
  59. holder.ondrop = function (e) {
  60. e.preventDefault();
  61. var file = e.dataTransfer.files[0];
  62. console.log('File you dragged here is', file.path);
  63. document.getElementById('image-container').src = file.path
  64. return false;
  65. };
  66. $scope.openNote = function(note){
  67. //console.log($location.path());
  68. console.log("openning note " + note.title + " (" + note.id + ")");
  69. FileService.setCurrentNote(note)
  70. $rootScope.$broadcast('main-window:note-view');
  71. $state.go("note-view");
  72. //$location.path('/notes/' + 'test1')
  73. //console.log($location.path());
  74. }
  75. $rootScope.$on('file-service:files-loaded', function(){
  76. if(!$scope.$$phase) {
  77. $scope.$apply(function(){
  78. //$scope.itemSpacing();
  79. });
  80. } else {
  81. //$scope.itemSpacing();
  82. }
  83. })
  84. $rootScope.$on('$stateNotFound', function(event, unfoundState, fromState, fromParams){
  85. console.log(unfoundState.to); // "lazy.state"
  86. console.log(unfoundState.toParams); // {a:1, b:2}
  87. console.log(unfoundState.options); // {inherit:false} + default options
  88. })
  89. $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error){
  90. console.log('Change state error'); // "lazy.state"
  91. console.log(error)
  92. console.log(toState)
  93. console.log(toParams)
  94. console.log(fromState)
  95. console.log(fromParams)
  96. })
  97. $scope.itemSpacing = function(){
  98. var items = document.getElementsByClassName("file-view-item");
  99. for (var i = 0; i < items.length; i++) {
  100. items[i].style.margin = "15px";
  101. }
  102. }
  103. $scope.isImage = function(file_type) {
  104. if(file_type != 'Image') { return true; }
  105. else { return false; }
  106. }
  107. $scope.getImageURL = function(img_url) {
  108. return "../codex/" + FileService.absoluteToRelativeURL(FileService.getNotesDir(), img_url)
  109. }
  110. }]);