Selaa lähdekoodia

switched nav to ng-href

tags/1.0.0
Robin Thoni 8 vuotta sitten
vanhempi
commit
1968e3d67c

+ 9
- 12
app/app.js Näytä tiedosto

@@ -15,24 +15,21 @@ var app = angular.module('app', [
15 15
 app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$locationProvider',
16 16
     function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) {
17 17
 
18
-        /*$stateProvider.state('root', {
19
-            abstract: true,
20
-            template: '<div ui-view=""></div>',
21
-            resolve: {
22
-                groups: ['GroupsBusiness', function (GroupsBusiness) {
23
-                    return GroupsBusiness.loadAll();
24
-                }]
25
-            }
26
-        });*/
27 18
 
28 19
         //$locationProvider.html5Mode(true);
29 20
 
30 21
         $stateProvider.state('home',{
31 22
             url:'/',
32
-            //parent: 'root',
23
+            reloadOnSearch: false,
24
+            templateUrl:'views/home.html',
25
+            controller:'HomeController'
26
+        });
27
+
28
+        $stateProvider.state('thisweek',{
29
+            url:'/thisweek',
30
+            reloadOnSearch: false,
33 31
             templateUrl:'views/home.html',
34
-            controller:'HomeController',
35
-            revolve:{}
32
+            controller:'HomeController'
36 33
         });
37 34
 
38 35
         $urlRouterProvider.otherwise('/');

+ 10
- 3
app/controllers/sidebar.controller.js Näytä tiedosto

@@ -3,8 +3,8 @@
3 3
  */
4 4
 
5 5
 angular.module('app')
6
-    .controller('SideBarController', ['$scope', '$state', 'DataShareBusiness', 'GroupsBusiness',
7
-        function($scope, $state, DataShareBusiness, GroupsBusiness) {
6
+    .controller('SideBarController', ['$scope', '$state', 'DataShareBusiness', 'GroupsBusiness', '$location',
7
+        function($scope, $state, DataShareBusiness, GroupsBusiness, $location) {
8 8
 
9 9
             $scope.DataShareBusiness = DataShareBusiness;
10 10
 
@@ -12,7 +12,7 @@ angular.module('app')
12 12
             {
13 13
                 if (DataShareBusiness.CurrentGroups.length != 0) {
14 14
                     var e = DataShareBusiness.CurrentGroups[DataShareBusiness.CurrentGroups.length - 1];
15
-                    if (e.Groups.length == 0) {
15
+                    if (e.Groups == null || e.Groups.length == 0) {
16 16
                         return e.Parent.Groups;
17 17
                     }
18 18
                     return e.Groups;
@@ -20,6 +20,12 @@ angular.module('app')
20 20
                 return DataShareBusiness.Groups;
21 21
             };
22 22
 
23
+            $scope.$watch(function(){ return Object.keys($location.search())[0] }, function(){
24
+                if (DataShareBusiness.Groups != null) {
25
+                    DataShareBusiness.setFromSearchString(Object.keys($location.search())[0]);
26
+                }
27
+            });
28
+
23 29
             var promiseLoadGroups = {
24 30
                 id: "promiseLoadGroups",
25 31
                 loaderGroups: ["sidebar", "toolbar"]
@@ -27,5 +33,6 @@ angular.module('app')
27 33
             GroupsBusiness.loadAll(promiseLoadGroups).then(function(data)
28 34
             {
29 35
                 $scope.groups = data;
36
+                DataShareBusiness.setFromSearchString(Object.keys($location.search())[0]);
30 37
             });
31 38
         }]);

+ 4
- 2
app/views/sidebar.html Näytä tiedosto

@@ -12,12 +12,14 @@
12 12
         </p>-->
13 13
         <ul class="col-sm-12" lu-busy="sidebar">
14 14
             <li ng-show="DataShareBusiness.CurrentGroups.length != 0">
15
-                <md-button class="md-primary md-hue-1 md-group-button col-xs-12" ng-click="DataShareBusiness.upCurrentGroup()">
15
+                <md-button class="md-primary md-hue-1 md-group-button col-xs-12"
16
+                           ng-href="{{DataShareBusiness.getGroupUrl(DataShareBusiness.getCurrentGroup().Parent)}}">
16 17
                     ..
17 18
                 </md-button>
18 19
             </li>
19 20
             <li ng-repeat="group in getCurrentGroups()">
20
-                <md-button class="md-primary md-hue-1 md-group-button col-xs-12" ng-click="DataShareBusiness.setCurrentGroup(group)">
21
+                <md-button class="md-primary md-hue-1 md-group-button col-xs-12"
22
+                           ng-href="{{DataShareBusiness.getGroupUrl(group)}}">
21 23
                     {{ group.Name }}
22 24
                 </md-button>
23 25
             </li>

+ 4
- 2
app/views/toolbar.html Näytä tiedosto

@@ -4,8 +4,10 @@
4 4
             <md-icon md-svg-icon="img/menu.svg"></md-icon>
5 5
         </md-button>
6 6
         <h2>
7
-            <span ng-click="DataShareBusiness.setCurrentGroup(null)">/ </span>
8
-            <a href="" ng-click="DataShareBusiness.setCurrentGroup(group)" ng-repeat="group in DataShareBusiness.CurrentGroups">{{ group.Name }}{{ $last ? "" : " / " }}</a>
7
+            <a ng-href="{{DataShareBusiness.getGroupUrl(null)}}">{{ DataShareBusiness.SearchSeparator }} </a>
8
+            <a ng-href="{{DataShareBusiness.getGroupUrl(group)}}" ng-repeat="group in DataShareBusiness.CurrentGroups">
9
+                {{ group.Name }}{{ $last ? "" : " " + DataShareBusiness.SearchSeparator + " " }}
10
+            </a>
9 11
         </h2>
10 12
         <span flex></span>
11 13
         <!--<md-button class="md-icon-button" aria-label="Favorite">

+ 59
- 1
sdk/Business/DataShareBusiness.js Näytä tiedosto

@@ -1,11 +1,15 @@
1 1
 (function()
2 2
 {
3 3
     angular.module('appSdk')
4
-        .factory('DataShareBusiness', [function () {
4
+        .factory('DataShareBusiness', ['$location', function ($location) {
5 5
 
6 6
             var data = {
7 7
                 Groups: null,
8
+
9
+                SearchSeparator: "~",
10
+
8 11
                 CurrentGroups: [],
12
+
9 13
                 setCurrentGroup: function(group)
10 14
                 {
11 15
                     data.CurrentGroups = [];
@@ -14,7 +18,61 @@
14 18
                         group = group.Parent;
15 19
                     }
16 20
                     data.CurrentGroups.reverse();
21
+
22
+                    $location.search(data.getSearchString(-1));
23
+                },
24
+
25
+                getCurrentGroup: function()
26
+                {
27
+                    if (data.CurrentGroups.length == 0) {
28
+                        return null;
29
+                    }
30
+                    return data.CurrentGroups[data.CurrentGroups.length - 1];
31
+                },
32
+
33
+                getSearchString: function(group)
34
+                {
35
+                    if (group == -1 && data.CurrentGroups.length != 0) {
36
+                        group = data.CurrentGroups[data.CurrentGroups.length - 1];
37
+                    }
38
+                    if (group == null) {
39
+                        return "";
40
+                    }
41
+                    var search = [];
42
+                    while (group != null){
43
+                        search.push(group.Name);
44
+                        group = group.Parent;
45
+                    }
46
+                    return search.reverse().join(data.SearchSeparator);
47
+                },
48
+
49
+                getGroupUrl: function(group)
50
+                {
51
+                    var search = data.getSearchString(group);
52
+                    return "#" + $location.path() + $location.hash() + "?" + search;
17 53
                 },
54
+
55
+                setFromSearchString: function(string)
56
+                {
57
+                    if (string == null) {
58
+                        data.setCurrentGroup(null);
59
+                        return;
60
+                    }
61
+                    var group = {Groups: data.Groups};
62
+                    var names = string.split(data.SearchSeparator);
63
+                    names.forEach(function(name)
64
+                    {
65
+                        var g = group.Groups.find(function(g)
66
+                        {
67
+                            return g.Name == name;
68
+                        });
69
+                        if (g != null) {
70
+                            group = g;
71
+                        }
72
+                    });
73
+                    data.setCurrentGroup(group);
74
+                },
75
+
18 76
                 upCurrentGroup: function()
19 77
                 {
20 78
                     if (data.CurrentGroups.length > 1) {

Loading…
Peruuta
Tallenna