123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- * @ngdoc function
- * @name domainManagerApp.controller:AboutCtrl
- * @description
- * # AboutCtrl
- * Controller of the domainManagerApp
- */
- angular.module('codexApp.header', [])
- .controller('HeaderCtrl',['$scope', '$rootScope', '$state', 'FileService', 'SearchService', 'PrefsService', function ($scope, $rootScope, $state, FileService, SearchService, PrefsService) {
- console.log('-> Header loaded')
- $scope.noteViewBtnClass = "";
- $scope.noteEditBtnClass = "";
-
- $scope.createNewNote = function() {
- dialog.showSaveDialog({ defaultPath: FileService.getDefaultNotesDir(), filters: [ { name: 'markdown', extensions: ['md'] }] }, function (fileName) {
- var fs = require('fs');
- if (fileName === undefined) return;
- fs.writeFile(fileName, "", function (err) {
- console.log("-> CREATE NEW NOTE: " + fileName)
- var note = FileService.getNote(fileName);
- FileService.setCurrentNote(note)
- console.log(note)
- $scope.activateNoteEdit();
- });
- });
- }
-
- $scope.toogleSidebar = function() {
- $rootScope.$broadcast('sidebar:toogle');
- }
-
- $scope.goToHome = function() {
- $rootScope.$broadcast('window-view:change');
- FileService.setCurrentNote(FileService.getDefaultNote());
- $rootScope.$broadcast('note-view:reload');
- $state.go("note-view");
- }
-
- $scope.goBack = function() {
- FileService.goToPreviousNote();
- }
-
- $scope.goForward = function() {
- FileService.goToNextNote();
- }
-
- $scope.activateNoteView = function() {
- $rootScope.$broadcast('window-view:change');
- $state.go("note-view");
- $scope.noteViewBtnClass = "active";
- $scope.noteEditBtnClass = "";
- }
- $scope.activateNoteEdit = function() {
- $rootScope.$broadcast('window-view:change');
- $state.go("note-edit");
- $scope.noteViewBtnClass = "";
- $scope.noteEditBtnClass = "active";
- }
- $rootScope.$on('main-window:note-list', function() {
- if(!$scope.$$phase) {
- $scope.$apply(function(){
- $scope.noteViewBtnClass = "";
- $scope.noteEditBtnClass = "";
- });
- } else {
- $scope.noteViewBtnClass = "";
- $scope.noteEditBtnClass = "";
- }
- });
- $rootScope.$on('main-window:note-view', function() {
- if(!$scope.$$phase) {
- $scope.$apply(function(){
- $scope.noteViewBtnClass = "active";
- $scope.noteEditBtnClass = "";
- });
- } else {
- $scope.noteViewBtnClass = "active";
- $scope.noteEditBtnClass = "";
- }
- });
- $rootScope.$on('main-window:note-edit', function() {
- if(!$scope.$$phase) {
- $scope.$apply(function(){
- $scope.noteViewBtnClass = "";
- $scope.noteEditBtnClass = "active";
- });
- } else {
- $scope.noteViewBtnClass = "";
- $scope.noteEditBtnClass = "active";
- }
- });
-
- SearchService.init();
- $scope.fileSearch = function(){
- console.log("> SEARCHING: " + $scope.search_text);
- var results = SearchService.search($scope.search_text);
- FileService.setSearchedFiles(results);
- var current_note = {
- path : "search",
- type : "Folder",
- title: $scope.search_text,
- search_results: results
- }
- FileService.setCurrentNote(current_note)
- PrefsService.setCurrentView("Searched Files");
-
- $rootScope.$broadcast('main-window:note-list');
- $rootScope.$broadcast('window-view:change');
- $state.go("index");
- }
- }]);
|