Commit 98af6edd authored by Nicholas J Anderson's avatar Nicholas J Anderson
Browse files

Added pagination

Did i do it rite?
parent 8e591991
......@@ -7,18 +7,20 @@ app = Flask(__name__)
def base_api():
return render_template('index.html')
@app.route('/all/<search>')
def search_all(search):
return jsonify(call_standard(search))
@app.route('/basic/all/<search>', defaults={'page':1})
@app.route('/basic/all/<search>/<page>')
def search_all(search, page):
return jsonify(call_standard(search, page=page))
@app.route('/basic/students/<search>', defaults={'page':1})
@app.route('/basic/students/<search>/<page>')
def search_students(search, page):
return jsonify(call_standard(search, group="students", page=page))
@app.route('/students/<search>')
def search_students(search):
return jsonify(call_standard(search, group="students"))
@app.route('/faculty/<search>')
def search_faculty(search):
return jsonify(call_standard(search, group="students"))
@app.route('/basic/faculty/<search>', defaults={'page':1})
@app.route('/basic/faculty/<search>/<page>')
def search_faculty(search, page):
return jsonify(call_standard(search, group="students", page=page))
if __name__ == "__main__":
import os
......
......@@ -63,7 +63,7 @@ dd {
<div class="row">
<div class="large-12 columns">
<div class="alert-box alert" ng-show="error && !dismissed">
{{error}}
<strong>{{error}}</strong>
<a href="#" ng-click="dismiss()" class="close">&times;</a>
</div>
</div>
......@@ -71,21 +71,29 @@ dd {
<div class="row">
<form ng-submit="doQuery();">
<div class="large-6 medium-12 columns">
<label>Query Group
<select ng-model="group" ng-change="updateUrl();">
<option value="all">Students and Faculty</option>
<option value="students">Students Only</option>
<option value="faculty">Faculty Only</option>
</select>
</label>
</div>
<div class="large-6 medium-12 columns">
<label>Query String
<input type="text" placeholder="Query String" ng-change="updateUrl();" ng-required ng-model="generalStr">
</label>
</div>
<input type="submit" style="display:none">
<div class="large-6 medium-12 columns">
<label>Query Group
<select ng-model="group" ng-change="updateUrl();">
<option value="all">Students and Faculty</option>
<option value="students">Students Only</option>
<option value="faculty">Faculty Only</option>
</select>
</label>
</div>
<div class="large-6 medium-12 columns">
<label>Query String
<input type="text" placeholder="Query String" ng-change="updateUrl();" ng-required ng-model="generalStr">
</label>
</div>
<div class="large-12 columns">
<label>Search Type
<select ng-model="type" ng-change="updateUrl();">
<option value="basic">Basic</option>
<option value="advanced">Advanced</option>
</select>
</label>
</div>
<input type="submit" style="display:none">
</form>
</div>
......@@ -96,7 +104,7 @@ dd {
<input type="text" ng-model="query" disabled>
</div>
<div class="small-2 columns">
<a href="#" class="button postfix" ng-click="doQuery();">Go!</a>
<a href="#" class="button postfix" ng-click="doQuery();" onclick="return false">Go!</a>
</div>
</div>
</div>
......@@ -123,6 +131,9 @@ dd {
<dd ng-show="{{!!result.major}}">{{result.major}}</dd>
</dl>
</div>
<div class="large-12 columns" ng-show="nextPage">
<a href="#" class="button" ng-click="doQuery()" onclick="return false;">Show More</a>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
......@@ -134,17 +145,27 @@ dd {
$scope.results = [];
$scope.group = "all";
$scope.generalStr = "";
$scope.type = "basic";
$scope.doQuery = function() {
$http.get(baseURL + "/" + $scope.group + "/" + $scope.generalStr).success(function(data) {
if ($scope.query != $scope.oldQuery) {
$scope.oldQuery = $scope.query;
$scope.nextPageNum = 1;
$scope.results = [];
}
$http.get($scope.query + "/" + $scope.nextPageNum).success(function(data) {
console.log(data);
$scope.results = data.results;
console.log($scope.results);
$scope.results = $scope.results.concat(data.results); // = angular.extend({}, $scope.results, data.results);
$scope.nextPage = data.hasNextPage
$scope.nextPageNum++;
}).error(function(data, status, headers, config) {
$scope.error = "Oops! Looks like that query didn't work!";
$scope.dismissed = false;
})
});
return false;
}
$scope.updateUrl = function() {
$scope.query = baseURL + "/" + $scope.group + "/" + $scope.generalStr;
$scope.query = baseURL + "/" + $scope.type + "/" + $scope.group + "/" + $scope.generalStr;
}
$scope.updateUrl()
$scope.dismiss = function() {
......@@ -157,4 +178,4 @@ dd {
</body>
</html>
{% endraw %}
\ No newline at end of file
{% endraw %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment