Browse Source

fixed search/params

tags/1.0.0
Robin Thoni 8 years ago
parent
commit
2d865d2c4b

+ 5
- 7
app/app.js View File

@@ -11,13 +11,11 @@ var app = angular.module('app', [
11 11
     'appSdk'
12 12
 ]);
13 13
 
14
-app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$locationProvider',
15
-    function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) {
16
-
17
-        //$locationProvider.html5Mode(true);
14
+app.config(['$stateProvider', '$urlRouterProvider',
15
+    function($stateProvider, $urlRouterProvider) {
18 16
 
19 17
         $stateProvider.state('home',{
20
-            url:'/',
18
+            url:'/?group',
21 19
             reloadOnSearch: false,
22 20
             templateUrl:'views/home.html',
23 21
             controller:'HomeController'
@@ -39,8 +37,8 @@ app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$locationP
39 37
             }
40 38
         };
41 39
     }])
42
-    .run(['$rootScope', '$state', '$location', 'DataShareBusiness', 'GroupsBusiness', '$mdDateLocale', '$filter',
43
-        function ($rootScope, $state, $location, DataShareBusiness, GroupsBusiness, $mdDateLocale, $filter) {
40
+    .run(['$rootScope', '$state', 'DataShareBusiness', 'GroupsBusiness', '$mdDateLocale', '$filter',
41
+        function ($rootScope, $state, DataShareBusiness, GroupsBusiness, $mdDateLocale, $filter) {
44 42
 
45 43
 
46 44
             var promiseLoadGroups = {

+ 7
- 5
app/controllers/home.controller.js View File

@@ -1,6 +1,6 @@
1 1
 angular.module('app')
2
-    .controller('HomeController', ['$scope', '$state', 'DataShareBusiness', 'WeeksBusiness', '$mdDialog', '$location',
3
-        function($scope, $state, DataShareBusiness, WeeksBusiness, $mdDialog, $location) {
2
+    .controller('HomeController', ['$scope', '$state', 'DataShareBusiness', 'WeeksBusiness', '$mdDialog',
3
+        function($scope, $state, DataShareBusiness, WeeksBusiness, $mdDialog) {
4 4
 
5 5
             $scope.DataShareBusiness = DataShareBusiness;
6 6
             $scope.dateFormat = DataShareBusiness.DateFormat;
@@ -142,7 +142,8 @@ angular.module('app')
142 142
 
143 143
             $scope.$watch(function(){return DataShareBusiness.Groups}, function()
144 144
             {
145
-                DataShareBusiness.setFromSearchString(Object.keys($location.search())[0]);
145
+                console.log($state.params.group);
146
+                DataShareBusiness.setFromSearchString($state.params.group);
146 147
             });
147 148
 
148 149
             $scope.$watch(function(){return DataShareBusiness.CurrentGroups}, $scope.loadWeeks);
@@ -158,9 +159,10 @@ angular.module('app')
158 159
                 }
159 160
             });
160 161
 
161
-            $scope.$watch(function(){ return $location.search().group }, function(){
162
+            $scope.$watch(function(){ return $state.params.group }, function(){
162 163
                 if (DataShareBusiness.Groups != null) {
163
-                    DataShareBusiness.setFromSearchString($location.search().group);
164
+                    console.log($state.params.group);
165
+                    DataShareBusiness.setFromSearchString($state.params.group);
164 166
                 }
165 167
             });
166 168
 

+ 1
- 2
app/controllers/sidebar.controller.js View File

@@ -45,8 +45,7 @@ angular.module('app')
45 45
             {
46 46
                 if (group != null) {
47 47
                     $scope.Search.value = "";
48
-                    console.log(group);
49
-                    DataShareBusiness.setCurrentGroup(group);
48
+                    DataShareBusiness.goToGroup(group);
50 49
                 }
51 50
             };
52 51
 

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

@@ -30,14 +30,14 @@
30 30
             <ul class="col-sm-12 sidebar-group-list">
31 31
                 <li ng-show="DataShareBusiness.CurrentGroups.length != 0" class="col-xs-12">
32 32
                     <md-button class="md-primary md-hue-1 md-group-button col-xs-12"
33
-                               ng-href="{{DataShareBusiness.getGroupUrl(DataShareBusiness.getCurrentGroup().Parent)}}">
33
+                               ui-sref="home({group: DataShareBusiness.getSearchString(DataShareBusiness.getCurrentGroup().Parent)})">
34 34
                         ..
35 35
                     </md-button>
36 36
                 </li>
37 37
                 <li ng-repeat="group in getCurrentGroups()" class="col-xs-12">
38 38
                     <md-button class="md-primary md-hue-1 md-group-button col-xs-12"
39 39
                                ng-class="{'md-group-button-checked': DataShareBusiness.getCurrentGroup().Id == group.Id}"
40
-                               ng-href="{{DataShareBusiness.getGroupUrl(group)}}">
40
+                               ui-sref="home({group: DataShareBusiness.getSearchString(group)})">
41 41
                         {{ group.Name }}
42 42
                     </md-button>
43 43
                 </li>

+ 13
- 10
sdk/Business/DataShareBusiness.js View File

@@ -14,20 +14,22 @@
14 14
 
15 15
                 TimeFormat: "HH'h'mm",
16 16
 
17
+                DateTimeFormat: "dd MMM yyyy HH'h'mm",
18
+
19
+                goToGroup: function(group)
20
+                {
21
+                    var search = data.getSearchString(group);
22
+                    $state.go('home', {group: search.length == 0 ? undefined : search});
23
+                },
24
+
17 25
                 setCurrentGroup: function(group)
18 26
                 {
19
-                    var g = group;
20 27
                     data.CurrentGroups = [];
21 28
                     while (group != null) {
22 29
                         data.CurrentGroups.push(group);
23 30
                         group = group.Parent;
24 31
                     }
25 32
                     data.CurrentGroups.reverse();
26
-
27
-                    $state.go('home').then(function() {
28
-                        var search = data.getSearchString(-1);
29
-                        $location.search({group: search.length == 0 ? undefined : search});
30
-                    });
31 33
                 },
32 34
 
33 35
                 getCurrentGroup: function()
@@ -66,13 +68,14 @@
66 68
                         search.push(group.Name);
67 69
                         group = group.Parent;
68 70
                     }
69
-                    return search.reverse().join(data.SearchSeparator);
71
+                    var str = search.reverse().join(data.SearchSeparator);
72
+                    return str;
70 73
                 },
71 74
 
72 75
                 getGroupUrl: function(group)
73 76
                 {
74 77
                     var search = data.getSearchString(group);
75
-                    return $state.href('home') + $location.hash() + (search.length != 0 ? "?group=" + search : "");
78
+                    return $state.href('home', {group:  (search.length != 0 ? search : undefined)});
76 79
                 },
77 80
 
78 81
                 setFromSearchString: function(string)
@@ -84,11 +87,11 @@
84 87
                         data.setCurrentGroup(null);
85 88
                         return;
86 89
                     }
87
-                    var group = {Groups: data.Groups};
90
+                    var group = null;
88 91
                     var names = string.split(data.SearchSeparator);
89 92
                     names.forEach(function(name)
90 93
                     {
91
-                        var g = group.Groups.find(function(g)
94
+                        var g = (group || data).Groups.find(function(g)
92 95
                         {
93 96
                             return g.Name == name;
94 97
                         });

Loading…
Cancel
Save