-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdefault.cshtml
More file actions
123 lines (116 loc) · 5.46 KB
/
Copy pathdefault.cshtml
File metadata and controls
123 lines (116 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
@using StackApis.ServiceModel
@inherits ViewPage
@{
ViewBag.Title = "ServiceStack Questions";
}
<script>
var app = angular.module('soApp', []);
app.controller('soCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
$scope.makeRequest = function (path) {
$http.get(path).success(function (response) {
$scope.questionsResult = response.Results;
});
};
$('input,select').change(function () {
$scope.makeRequest(constructUrl());
});
function processInputChange() {
if ($scope.titleSearchTimeout != null) {
$timeout.cancel($scope.titleSearchTimeout);
$scope.titleSearchTimeout = null;
}
$scope.titleSearchTimeout = $timeout(function () {
$scope.makeRequest(constructUrl());
}, 200);
}
$scope.titleSearchTimeout = null;
var watch = ['titleSearch', 'scoreSelect', 'scoreVal', 'viewsSelect', 'viewsVal', 'answersSelect', 'answersVal', 'orderBySelect'];
angular.forEach(watch, function (input) {
$scope.$watch(input, processInputChange);
});
function constructUrl(model) {
var path = '@(new StackOverflowQuery().ToGetUrl())' +
'?Score' + ($scope.scoreSelect || 'GreaterThan') + '=' + ($scope.scoreVal || 0) +
'&ViewCount' + ($scope.viewsSelect || 'GreaterThan') + '=' + ($scope.viewsVal || 0) +
'&AnswerCount' + ($scope.answersSelect || 'GreaterThan') + '=' + ($scope.answersVal || 0) +
'&OrderByDesc=' + ($scope.orderBySelect || 'Score') +
($scope.titleSearch ? '&TitleContains=' + $scope.titleSearch : '');
return path;
}
$scope.filterResult = function () {
$scope.makeRequest(constructUrl());
};
$scope.scoreSelect = 'GreaterThan';
$scope.viewsSelect = 'GreaterThan';
$scope.answersSelect = 'GreaterThan';
$scope.orderBySelect = 'Score';
$scope.makeRequest('/questions');
}]);
</script>
<div ng-app="soApp">
<div ng-controller="soCtrl">
<input type="text" name="titleSearch" ng-model="titleSearch" class="input-lg" placeholder="Title search" style="width:100%" />
<div class="col-sm-6 col-md-3 col-lg-3">
<form style="margin-top:32px">
<div>
<div class="form-group">
<select id="filterScoreBySelect" class="form-control" ng-model="scoreSelect">
<option value="GreaterThan">Score greater than</option>
<option value="LessThan">Score less than</option>
</select>
</div>
<div class="form-group">
<input id="scoreInput" class="form-control" type="number" placeholder="Score" ng-model="scoreVal" />
</div>
<div class="form-group">
<select id="filterViewsBySelect" class="form-control" ng-model="viewsSelect">
<option value="GreaterThan">Views greater than</option>
<option value="LessThan">Views less than</option>
</select>
</div>
<div class="form-group">
<input id="viewsInput" class="form-control" type="number" placeholder="Views" ng-model="viewsVal" />
</div>
<div class="form-group">
<select id="filterAnswersBySelect" class="form-control" ng-model="answersSelect">
<option value="GreaterThan">Answers greater than</option>
<option value="LessThan">Answers less than</option>
</select>
</div>
<div class="form-group">
<input id="answerInput" class=" form-control" type="number" placeholder="Answers" ng-model="answersVal"/>
</div>
<div class="form-group">
<label>
Order by <select id="orderByDescSelect" ng-model="orderBySelect">
<option value="Score">Score</option>
<option value="ViewCount">Views</option>
<option value="AnswerCount">Answers</option>
</select> descending
</label>
</div>
</div>
</form>
</div>
<div class="col-sm-6 col-md-9 col-lg-9">
<table class="table">
<thead>
<tr>
<th>Score</th>
<th>Answers</th>
<th>Title</th>
<th>Total Views</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="question in questionsResult">
<td ng-bind="question.Score"></td>
<td ng-bind="question.AnswerCount"></td>
<td><a href="{{question.Link}}">{{question.Title}}</a></td>
<td ng-bind="question.ViewCount"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>