|
5 | 5 | } |
6 | 6 | <script> |
7 | 7 | var app = angular.module('soApp', []); |
8 | | - app.controller('soCtrl', ['$scope', '$http', '$timeout', |
9 | | - function ($scope, $http, $timeout) { |
10 | | - $scope.makeRequest = function (path) { |
11 | | - $http.get(path).success(function (response) { |
12 | | - $scope.questionsResult = response.Results; |
13 | | - }); |
14 | | - }; |
15 | | -
|
16 | | - $('input,select').change(function () { |
17 | | - $scope.makeRequest(constructUrl()); |
| 8 | + app.controller('soCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) { |
| 9 | + $scope.makeRequest = function (path) { |
| 10 | + $http.get(path).success(function (response) { |
| 11 | + $scope.questionsResult = response.Results; |
18 | 12 | }); |
| 13 | + }; |
19 | 14 |
|
20 | | - function processInputChange() { |
21 | | - if ($scope.titleSearchTimeout != null) { |
22 | | - $timeout.cancel($scope.titleSearchTimeout); |
23 | | - $scope.titleSearchTimeout = null; |
24 | | - } |
25 | | - $scope.titleSearchTimeout = $timeout(function () { |
26 | | - $scope.makeRequest(constructUrl()); |
27 | | - }, 200); |
28 | | - } |
29 | | -
|
30 | | - $scope.titleSearchTimeout = null; |
31 | | - var watch = ['titleSearch', 'scoreSelect', 'scoreVal', 'viewsSelect', 'viewsVal', 'answersSelect', 'answersVal', 'orderBySelect']; |
32 | | - angular.forEach(watch, function (input) { |
33 | | - $scope.$watch(input, processInputChange); |
34 | | - }); |
| 15 | + $('input,select').change(function () { |
| 16 | + $scope.makeRequest(constructUrl()); |
| 17 | + }); |
35 | 18 |
|
36 | | - function constructUrl(model) { |
37 | | - var path = '@(new StackOverflowQuery().ToGetUrl())' + |
38 | | - '?Score' + ($scope.scoreSelect || 'GreaterThan') + '=' + ($scope.scoreVal || 0) + |
39 | | - '&ViewCount' + ($scope.viewsSelect || 'GreaterThan') + '=' + ($scope.viewsVal || 0) + |
40 | | - '&AnswerCount' + ($scope.answersSelect || 'GreaterThan') + '=' + ($scope.answersVal || 0) + |
41 | | - '&OrderByDesc=' + ($scope.orderBySelect || 'Score'); |
42 | | - if ($scope.titleSearch) { |
43 | | - path += '&TitleContains=' + $scope.titleSearch; |
44 | | - } |
45 | | - return path; |
| 19 | + function processInputChange() { |
| 20 | + if ($scope.titleSearchTimeout != null) { |
| 21 | + $timeout.cancel($scope.titleSearchTimeout); |
| 22 | + $scope.titleSearchTimeout = null; |
46 | 23 | } |
47 | | -
|
48 | | - $scope.filterResult = function () { |
| 24 | + $scope.titleSearchTimeout = $timeout(function () { |
49 | 25 | $scope.makeRequest(constructUrl()); |
50 | | - }; |
| 26 | + }, 200); |
| 27 | + } |
| 28 | +
|
| 29 | + $scope.titleSearchTimeout = null; |
| 30 | + var watch = ['titleSearch', 'scoreSelect', 'scoreVal', 'viewsSelect', 'viewsVal', 'answersSelect', 'answersVal', 'orderBySelect']; |
| 31 | + angular.forEach(watch, function (input) { |
| 32 | + $scope.$watch(input, processInputChange); |
| 33 | + }); |
51 | 34 |
|
52 | | - $scope.scoreSelect = 'GreaterThan'; |
53 | | - $scope.viewsSelect = 'GreaterThan'; |
54 | | - $scope.answersSelect = 'GreaterThan'; |
55 | | - $scope.orderBySelect = 'Score'; |
56 | | - $scope.makeRequest('/questions'); |
| 35 | + function constructUrl(model) { |
| 36 | + var path = '@(new StackOverflowQuery().ToGetUrl())' + |
| 37 | + '?Score' + ($scope.scoreSelect || 'GreaterThan') + '=' + ($scope.scoreVal || 0) + |
| 38 | + '&ViewCount' + ($scope.viewsSelect || 'GreaterThan') + '=' + ($scope.viewsVal || 0) + |
| 39 | + '&AnswerCount' + ($scope.answersSelect || 'GreaterThan') + '=' + ($scope.answersVal || 0) + |
| 40 | + '&OrderByDesc=' + ($scope.orderBySelect || 'Score') + |
| 41 | + ($scope.titleSearch ? '&TitleContains=' + $scope.titleSearch : ''); |
| 42 | + return path; |
57 | 43 | } |
58 | | - ]); |
| 44 | +
|
| 45 | + $scope.filterResult = function () { |
| 46 | + $scope.makeRequest(constructUrl()); |
| 47 | + }; |
| 48 | +
|
| 49 | + $scope.scoreSelect = 'GreaterThan'; |
| 50 | + $scope.viewsSelect = 'GreaterThan'; |
| 51 | + $scope.answersSelect = 'GreaterThan'; |
| 52 | + $scope.orderBySelect = 'Score'; |
| 53 | + $scope.makeRequest('/questions'); |
| 54 | + }]); |
59 | 55 | </script> |
60 | 56 | <div ng-app="soApp"> |
61 | 57 | <div ng-controller="soCtrl"> |
|
0 commit comments