View all notes or all files

James Peret 8 years ago
parent
commit
6d9dccea96

+ 7 - 2
app/index.html

@@ -28,6 +28,7 @@
28 28
     <script src="scripts/controllers/note-edit-ctrl.js"></script>
29 29
     <script src="scripts/services/file-service.js"></script>
30 30
     <script src="scripts/services/thumbnail-service.js"></script>
31
+    <script src="scripts/services/prefs-service.js"></script>
31 32
     <script src="scripts/services/date-formatter.js" charset="utf-8"></script>
32 33
 
33 34
     <script>
@@ -81,10 +82,14 @@
81 82
           <div class="pane pane-sm sidebar" ng-controller="SidebarCtrl" ng-show="showSidebar">
82 83
             <nav class="nav-group">
83 84
               <h5 class="nav-group-title">My Notes</h5>
84
-              <span class="nav-group-item active" ng-click="goToAllNotes()">
85
-                <span class="icon icon-archive"></span>
85
+              <span class="nav-group-item" ng-class="sidebar[0].active" ng-click="goToAllNotes()">
86
+                <span class="icon icon-folder"></span>
86 87
                 All Notes
87 88
               </span>
89
+              <span class="nav-group-item" ng-class="sidebar[1].active" ng-click="goToAllFiles()">
90
+                <span class="icon icon-archive"></span>
91
+                All Files
92
+              </span>
88 93
               <span class="nav-group-item">
89 94
                 <span class="icon icon-book"></span>
90 95
                 Notebooks

+ 17 - 2
app/scripts/controllers/app-ctrl.js

@@ -8,10 +8,25 @@
8 8
  * Controller of the domainManagerApp
9 9
  */
10 10
 angular.module('codexApp.index', [])
11
-  .controller('AppCtrl', ['$scope', '$rootScope', '$state', '$location', 'FileService', function ($scope,  $rootScope, $state, $location, FileService) {
11
+  .controller('AppCtrl', ['$scope', '$rootScope', '$state', '$location', 'FileService', 'PrefsService', function ($scope,  $rootScope, $state, $location, FileService, PrefsService) {
12
+
13
+    $scope.setView = function() {
14
+      $scope.view = PrefsService.getCurrentView();
15
+      switch ($scope.view) {
16
+        case "All Notes":
17
+          $scope.files = FileService.getAllNotes();
18
+          break;
19
+        case "All Files":
20
+          $scope.files = FileService.getAllFiles();
21
+          break;
22
+      }
23
+    }
12 24
 
13
-    $scope.files = FileService.getNotes();
25
+    $scope.setView();
14 26
 
27
+    $rootScope.$on('window-view:change', function(){
28
+      $scope.setView();
29
+    });
15 30
 
16 31
     var remote = require('remote')
17 32
     var Menu = remote.require('menu')

+ 38 - 1
app/scripts/controllers/sidebar-ctrl.js

@@ -8,18 +8,28 @@
8 8
  * Controller of the domainManagerApp
9 9
  */
10 10
 angular.module('codexApp.sidebar', [])
11
-  .controller('SidebarCtrl',['$scope', '$rootScope', '$state', function ($scope,  $rootScope, $state) {
11
+  .controller('SidebarCtrl',['$scope', '$rootScope', '$state', 'PrefsService', function ($scope,  $rootScope, $state, PrefsService) {
12 12
 
13 13
     console.log('-> Sidebar loaded')
14 14
 
15 15
     $scope.showSidebar = true;
16 16
 
17 17
     $scope.goToAllNotes = function() {
18
+      PrefsService.setCurrentView("All Notes");
19
+      $scope.activateSidebarBtn(0);
18 20
       $rootScope.$broadcast('main-window:note-list');
19 21
       $rootScope.$broadcast('window-view:change');
20 22
       $state.go("index");
21 23
     }
22 24
 
25
+    $scope.goToAllFiles = function() {
26
+      PrefsService.setCurrentView("All Files");
27
+      $scope.activateSidebarBtn(1);
28
+      $rootScope.$broadcast('main-window:file-list');
29
+      $rootScope.$broadcast('window-view:change');
30
+      $state.go("index");
31
+    }
32
+
23 33
     $rootScope.$on('sidebar:toogle', function() {
24 34
       if(!$scope.$$phase) {
25 35
         $scope.$apply(function(){
@@ -38,4 +48,31 @@ angular.module('codexApp.sidebar', [])
38 48
       }
39 49
     }
40 50
 
51
+    $scope.sidebar = [
52
+      {
53
+        "view" : "All Notes",
54
+        "active" : "active"
55
+      },
56
+      {
57
+        "view" : "All Files",
58
+        "active" : ""
59
+      }
60
+    ]
61
+
62
+    $scope.activateSidebarBtn = function(num) {
63
+      if(!$scope.$$phase) {
64
+        $scope.$apply(function(){
65
+          for (var i = 0; i < $scope.sidebar.length; i++) {
66
+            $scope.sidebar[i].active = "";
67
+          }
68
+          $scope.sidebar[num].active = "active";
69
+        });
70
+      } else {
71
+        for (var i = 0; i < $scope.sidebar.length; i++) {
72
+          $scope.sidebar[i].active = "";
73
+        }
74
+        $scope.sidebar[num].active = "active";
75
+      }
76
+    }
77
+
41 78
   }]);

+ 17 - 1
app/scripts/services/file-service.js

@@ -302,11 +302,27 @@ angular.module('codexApp')
302 302
     return 0;
303 303
   };
304 304
 
305
+  var filterNotes = function(files) {
306
+    var filtered = [];
307
+    for (var i = 0; i < files.length; i++) {
308
+      if(files[i].type == "Markdown") {
309
+        filtered.push(files[i]);
310
+      }
311
+    }
312
+    return filtered;
313
+  }
314
+
305 315
 
306 316
 
307 317
   // RESPONSE
308
-  this.getNotes = function() {
318
+  this.getAllFiles = function() {
319
+    notes = getAllFilesFromFolder();
320
+    return notes.sort(date_sort_asc);
321
+  }
322
+
323
+  this.getAllNotes = function() {
309 324
     notes = getAllFilesFromFolder();
325
+    notes = filterNotes(notes);
310 326
     return notes.sort(date_sort_asc);
311 327
   }
312 328
 

+ 14 - 0
app/scripts/services/prefs-service.js

@@ -0,0 +1,14 @@
1
+angular.module('codexApp')
2
+.service('PrefsService', [ '$rootScope', '$http',  function($rootScope, $http) {
3
+
4
+  var views = ["All Notes", "All Files"];
5
+  var current_view = "All Notes"
6
+
7
+  this.getCurrentView = function() {
8
+    return current_view;
9
+  }
10
+  this.setCurrentView = function(view) {
11
+    current_view = view;
12
+  }
13
+
14
+}])