Browse Source

switched nav to ng-href

tags/1.0.0
Robin Thoni 8 years ago
parent
commit
1968e3d67c

+ 9
- 12
app/app.js View File

15
 app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$locationProvider',
15
 app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$locationProvider',
16
     function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) {
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
         //$locationProvider.html5Mode(true);
19
         //$locationProvider.html5Mode(true);
29
 
20
 
30
         $stateProvider.state('home',{
21
         $stateProvider.state('home',{
31
             url:'/',
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
             templateUrl:'views/home.html',
31
             templateUrl:'views/home.html',
34
-            controller:'HomeController',
35
-            revolve:{}
32
+            controller:'HomeController'
36
         });
33
         });
37
 
34
 
38
         $urlRouterProvider.otherwise('/');
35
         $urlRouterProvider.otherwise('/');

+ 10
- 3
app/controllers/sidebar.controller.js View File

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

+ 4
- 2
app/views/sidebar.html View File

12
         </p>-->
12
         </p>-->
13
         <ul class="col-sm-12" lu-busy="sidebar">
13
         <ul class="col-sm-12" lu-busy="sidebar">
14
             <li ng-show="DataShareBusiness.CurrentGroups.length != 0">
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
                 </md-button>
18
                 </md-button>
18
             </li>
19
             </li>
19
             <li ng-repeat="group in getCurrentGroups()">
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
                     {{ group.Name }}
23
                     {{ group.Name }}
22
                 </md-button>
24
                 </md-button>
23
             </li>
25
             </li>

+ 4
- 2
app/views/toolbar.html View File

4
             <md-icon md-svg-icon="img/menu.svg"></md-icon>
4
             <md-icon md-svg-icon="img/menu.svg"></md-icon>
5
         </md-button>
5
         </md-button>
6
         <h2>
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
         </h2>
11
         </h2>
10
         <span flex></span>
12
         <span flex></span>
11
         <!--<md-button class="md-icon-button" aria-label="Favorite">
13
         <!--<md-button class="md-icon-button" aria-label="Favorite">

+ 59
- 1
sdk/Business/DataShareBusiness.js View File

1
 (function()
1
 (function()
2
 {
2
 {
3
     angular.module('appSdk')
3
     angular.module('appSdk')
4
-        .factory('DataShareBusiness', [function () {
4
+        .factory('DataShareBusiness', ['$location', function ($location) {
5
 
5
 
6
             var data = {
6
             var data = {
7
                 Groups: null,
7
                 Groups: null,
8
+
9
+                SearchSeparator: "~",
10
+
8
                 CurrentGroups: [],
11
                 CurrentGroups: [],
12
+
9
                 setCurrentGroup: function(group)
13
                 setCurrentGroup: function(group)
10
                 {
14
                 {
11
                     data.CurrentGroups = [];
15
                     data.CurrentGroups = [];
14
                         group = group.Parent;
18
                         group = group.Parent;
15
                     }
19
                     }
16
                     data.CurrentGroups.reverse();
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
                 upCurrentGroup: function()
76
                 upCurrentGroup: function()
19
                 {
77
                 {
20
                     if (data.CurrentGroups.length > 1) {
78
                     if (data.CurrentGroups.length > 1) {

Loading…
Cancel
Save