Browse Source

changed search usage

tags/1.0.0
Robin Thoni 8 years ago
parent
commit
260fe87fa3
4 changed files with 30 additions and 17 deletions
  1. 1
    11
      app/app.js
  2. 13
    2
      app/controllers/home.controller.js
  3. 10
    2
      app/views/freeroom.html
  4. 6
    2
      sdk/Business/DataShareBusiness.js

+ 1
- 11
app/app.js View File

@@ -42,23 +42,13 @@ app.config(['$stateProvider', '$urlRouterProvider', '$httpProvider', '$locationP
42 42
     .run(['$rootScope', '$state', '$location', 'DataShareBusiness', 'GroupsBusiness', '$mdDateLocale', '$filter',
43 43
         function ($rootScope, $state, $location, DataShareBusiness, GroupsBusiness, $mdDateLocale, $filter) {
44 44
 
45
-            $rootScope.$watch(function(){ return Object.keys($location.search())[0] }, function(){
46
-                if (DataShareBusiness.Groups != null && $state.current.name == "home") {
47
-                    DataShareBusiness.setFromSearchString(Object.keys($location.search())[0]);
48
-                }
49
-            });
50 45
 
51 46
             var promiseLoadGroups = {
52 47
                 id: "promiseLoadGroups",
53 48
                 loaderGroups: ["toolbar"],
54 49
                 groups: ["sidebar"]
55 50
             };
56
-            GroupsBusiness.loadAll(promiseLoadGroups).then(function(data)
57
-            {
58
-                if ($state.current.name == "home") {
59
-                    DataShareBusiness.setFromSearchString(Object.keys($location.search())[0]);
60
-                }
61
-            });
51
+            GroupsBusiness.loadAll(promiseLoadGroups);
62 52
 
63 53
             $mdDateLocale.firstDayOfWeek = 1;
64 54
             $mdDateLocale.formatDate = function(date) {

+ 13
- 2
app/controllers/home.controller.js View File

@@ -1,6 +1,6 @@
1 1
 angular.module('app')
2
-    .controller('HomeController', ['$scope', '$state', 'DataShareBusiness', 'WeeksBusiness', '$mdDialog',
3
-        function($scope, $state, DataShareBusiness, WeeksBusiness, $mdDialog) {
2
+    .controller('HomeController', ['$scope', '$state', 'DataShareBusiness', 'WeeksBusiness', '$mdDialog', '$location',
3
+        function($scope, $state, DataShareBusiness, WeeksBusiness, $mdDialog, $location) {
4 4
 
5 5
             $scope.DataShareBusiness = DataShareBusiness;
6 6
             $scope.dateFormat = DataShareBusiness.DateFormat;
@@ -140,6 +140,11 @@ angular.module('app')
140 140
                 return Math.round(($scope.getMonday(date1) - $scope.getMonday(date2)) / 604800000)
141 141
             };
142 142
 
143
+            $scope.$watch(function(){return DataShareBusiness.Groups}, function()
144
+            {
145
+                DataShareBusiness.setFromSearchString(Object.keys($location.search())[0]);
146
+            });
147
+
143 148
             $scope.$watch(function(){return DataShareBusiness.CurrentGroups}, $scope.loadWeeks);
144 149
 
145 150
             $scope.$watch(function(){return $scope.selectedDate}, function(newValue, oldValue)
@@ -153,6 +158,12 @@ angular.module('app')
153 158
                 }
154 159
             });
155 160
 
161
+            $scope.$watch(function(){ return $location.search().group }, function(){
162
+                if (DataShareBusiness.Groups != null) {
163
+                    DataShareBusiness.setFromSearchString($location.search().group);
164
+                }
165
+            });
166
+
156 167
             $scope.goToRelativeWeek = function(relativeWeek)
157 168
             {
158 169
                 $scope.selectedDate.setDate($scope.selectedDate.getDate() + (relativeWeek * 7));

+ 10
- 2
app/views/freeroom.html View File

@@ -1,4 +1,12 @@
1 1
 <div layout="column" layout-fill layout-align="top center">
2
-    <input class="form-control" mdc-datetime-picker="" date="true" time="true" type="text" id="datetime"
3
-           placeholder="Begin date" min-date="date" ng-model="Search.Begin" class=" md-input">
2
+    <div>
3
+        <md-input-container class="md-input-has-placeholder">
4
+            <input mdc-datetime-picker="" date="true" time="true" type="text" id="datetime"
5
+                   placeholder="From" min-date="date" ng-model="Search.Begin" class=" md-input">
6
+        </md-input-container>
7
+        <md-input-container class="md-input-has-placeholder">
8
+            <input mdc-datetime-picker="" date="true" time="true" type="text" id="datetime"
9
+                   placeholder="To" min-date="date" ng-model="Search.End" class=" md-input">
10
+        </md-input-container>
11
+    </div>
4 12
 </div>

+ 6
- 2
sdk/Business/DataShareBusiness.js View File

@@ -25,7 +25,8 @@
25 25
                     data.CurrentGroups.reverse();
26 26
 
27 27
                     $state.go('home').then(function() {
28
-                        $location.search(data.getSearchString(-1));
28
+                        var search = data.getSearchString(-1);
29
+                        $location.search({group: search.length == 0 ? undefined : search});
29 30
                     });
30 31
                 },
31 32
 
@@ -71,11 +72,14 @@
71 72
                 getGroupUrl: function(group)
72 73
                 {
73 74
                     var search = data.getSearchString(group);
74
-                    return $state.href('home') + $location.hash() + "?" + search;
75
+                    return $state.href('home') + $location.hash() + (search.length != 0 ? "?group=" + search : "");
75 76
                 },
76 77
 
77 78
                 setFromSearchString: function(string)
78 79
                 {
80
+                    if (data.Groups == null) {
81
+                        return;
82
+                    }
79 83
                     if (string == null) {
80 84
                         data.setCurrentGroup(null);
81 85
                         return;

Loading…
Cancel
Save