History navigation includes searches

James Peret 8 years ago
parent
commit
ca3f3f76dc

+ 4 - 0
app/scripts/controllers/app-ctrl.js

@@ -16,6 +16,10 @@ angular.module('codexApp.index', [])
16 16
       $timeout(function() {
17 17
         switch ($scope.view) {
18 18
           case "All Notes":
19
+            var note = {
20
+              type : "All Notes"
21
+            }
22
+            FileService.setCurrentNote(note);
19 23
             $scope.files = FileService.getAllNotes();
20 24
             var info = $scope.files.length + " Notes"
21 25
             $rootScope.$broadcast('footer:info', info);

+ 8 - 6
app/scripts/controllers/header-ctrl.js

@@ -47,18 +47,13 @@ angular.module('codexApp.header', [])
47 47
 
48 48
     // Go to the precious note
49 49
     $scope.goBack = function() {
50
-      $rootScope.$broadcast('window-view:change');
51 50
       FileService.goToPreviousNote();
52
-      $rootScope.$broadcast('note-view:reload');
53
-      FileService.changeController();
51
+
54 52
     }
55 53
 
56 54
     // Go to the next note
57 55
     $scope.goForward = function() {
58
-      $rootScope.$broadcast('window-view:change');
59 56
       FileService.goToNextNote();
60
-      $rootScope.$broadcast('note-view:reload');
61
-      FileService.changeController();
62 57
     }
63 58
 
64 59
     // Note View active button
@@ -120,6 +115,13 @@ angular.module('codexApp.header', [])
120 115
       console.log("> SEARCHING: " + $scope.search_text);
121 116
       var results = SearchService.search($scope.search_text);
122 117
       FileService.setSearchedFiles(results);
118
+      var current_note = {
119
+        path : "search",
120
+        type : "Folder",
121
+        title: $scope.search_text,
122
+        search_results: results
123
+      }
124
+      FileService.setCurrentNote(current_note)
123 125
       PrefsService.setCurrentView("Searched Files");
124 126
       //$scope.activateSidebarBtn(0);
125 127
       $rootScope.$broadcast('main-window:note-list');

+ 1 - 0
app/scripts/controllers/note-view-ctrl.js

@@ -33,6 +33,7 @@ angular.module('codexApp.noteView', [])
33 33
 
34 34
     $scope.loadNoteView = function() {
35 35
       filesystem.readFile($scope.note.path, function(err, data) {
36
+
36 37
         //$scope.note.data = String.fromCharCode.apply(null, data);
37 38
         $scope.note.data = new Buffer(data).toString('utf8')
38 39
         if(!$scope.$$phase) {

+ 24 - 2
app/scripts/services/file-service.js

@@ -1,5 +1,5 @@
1 1
 angular.module('codexApp')
2
-.service('FileService', [ '$rootScope', '$http', 'ThumbnailService', '$state',  function($rootScope, $http, ThumbnailService, $state) {
2
+.service('FileService', [ '$rootScope', '$http', 'ThumbnailService', '$state', 'PrefsService',  function($rootScope, $http, ThumbnailService, $state , PrefsService) {
3 3
 
4 4
   var defaultUserContentPath = "";
5 5
   var appDataPath = "";
@@ -541,6 +541,11 @@ angular.module('codexApp')
541 541
     if(note_history_index > 0) {
542 542
       note_history_index = note_history_index - 1;
543 543
       current_note = note_history[note_history_index];
544
+      if(current_note.path == "search"  || current_note.path == undefined){
545
+        changeController();
546
+      }
547
+      $rootScope.$broadcast('window-view:change');
548
+      $rootScope.$broadcast('note-view:reload');
544 549
     }
545 550
     console.log(current_note);
546 551
   }
@@ -549,6 +554,11 @@ angular.module('codexApp')
549 554
     if(note_history_index < (note_history.length - 1)){
550 555
       note_history_index = note_history_index + 1;
551 556
       current_note = note_history[note_history_index];
557
+      if(current_note.path == "search" || current_note.path == undefined){
558
+        changeController();
559
+      }
560
+      $rootScope.$broadcast('window-view:change');
561
+      $rootScope.$broadcast('note-view:reload');
552 562
     }
553 563
   }
554 564
 
@@ -570,7 +580,11 @@ angular.module('codexApp')
570 580
     return getNote(default_home_note);
571 581
   }
572 582
 
573
-  this.changeController = function(){
583
+  var changeController = function(){
584
+    console.log(current_note)
585
+    if(current_note.search_results){
586
+      searched_files = current_note.search_results;
587
+    }
574 588
     switch (current_note.type) {
575 589
       case "Markdown":
576 590
         $state.go("note-view");
@@ -578,9 +592,17 @@ angular.module('codexApp')
578 592
       case "Folder":
579 593
         $state.go("index");
580 594
         break;
595
+      case "All Notes":
596
+        PrefsService.setCurrentView("All Notes");
597
+        $state.go("index");
598
+        break;
581 599
     }
582 600
   }
583 601
 
602
+  this.changeController = function() {
603
+    changeController();
604
+  }
605
+
584 606
   this.deleteFile = function(file) {
585 607
     return deleteFile(file);
586 608
   }