Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add datetime #52

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions migrations/versions/2bda7a5154fb_.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def upgrade():
)
op.create_table('ride',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created', sa.DateTime(), nullable=False),
sa.Column('num_passengers', sa.Integer(), nullable=False),
sa.Column('start_latitude', sa.Float(), nullable=False),
sa.Column('start_longitude', sa.Float(), nullable=False),
Expand Down
4 changes: 4 additions & 0 deletions steerclear/api/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from steerclear import db
import sqlalchemy.types as types
from datetime import datetime
from pytz import timezone

"""
Model class for the Ride object
"""
class Ride(db.Model):
id = db.Column(db.Integer, primary_key=True)
created = db.Column(db.DateTime, default=datetime.now())
num_passengers = db.Column(db.Integer, nullable=False)

start_latitude = db.Column(db.Float, nullable=False)
Expand All @@ -30,6 +32,7 @@ def __repr__(self):
return "<Ride(ID %r, Passengers %r, Pickup <%r, %r>, Dropoff <%r, %r>, ETP %r, Duration %r, ETD %r)>" % \
(
self.id,
self.created,
self.num_passengers,
self.start_latitude,
self.start_longitude,
Expand All @@ -43,6 +46,7 @@ def __repr__(self):
def as_dict(self):
return {
'id': self.id,
'created': self.created,
'num_passengers': self.num_passengers,
'start_latitude': self.start_latitude,
'start_longitude': self.start_longitude,
Expand Down
1 change: 1 addition & 0 deletions steerclear/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# response format for Ride objects
ride_fields = {
'id': fields.Integer(),
'created': fields.DateTime(dt_format='iso8601'),
'num_passengers': fields.Integer(),
'start_latitude': fields.Float(),
'start_longitude': fields.Float(),
Expand Down
3 changes: 1 addition & 2 deletions steerclear/driver_portal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ def heartbeat():

@driver_portal_bp.route('/index')
@login_required
@admin_permission.require(http_exception=403)
def index():
if not admin_permission.can():
return redirect(url_for('.heartbeat'))
return render_template('index.html')

@driver_portal_bp.route('/privacy-policy', defaults={'path': 'index.html'})
Expand Down
33 changes: 25 additions & 8 deletions steerclear/login/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
redirect,
current_app,
session,
request
request,
flash
)
from flask.ext.login import (
login_user,
Expand Down Expand Up @@ -115,6 +116,8 @@ def login():
if request.method == 'GET':
return render_template('login.html', action=url_for('.login'))

error = None

# POST request. attempt to login
# must validate LoginForm and CAS server
form = LoginForm()
Expand All @@ -124,15 +127,28 @@ def login():
user = User.query.filter_by(username=form.username.data).first()
if user:

# login user
login_user(user)
admin_role = Role.query.filter_by(name='admin').first()
if admin_role in user.roles:

# login user
login_user(user)

# Tell Flask-Principal the identity changed
identity_changed.send(current_app._get_current_object(),
identity=Identity(user.id))

return redirect(url_for('driver_portal.index'))

else:
error = "Account does not have admin privileges."

else:
error = "This William and Mary account is not registered with Steer-Clear."

# Tell Flask-Principal the identity changed
identity_changed.send(current_app._get_current_object(),
identity=Identity(user.id))
else:
error = "Invalid login credentials for William and Mary CAS."

return redirect(url_for('driver_portal.index'))
return render_template('login.html', action=url_for('.login')), 400
return render_template('login.html', action=url_for('.login'), error=error), 400

"""
logout
Expand All @@ -153,6 +169,7 @@ def logout():
identity_changed.send(current_app._get_current_object(),
identity=AnonymousIdentity())

flash('Logout successful.')
return redirect(url_for('.login'))

"""
Expand Down
30 changes: 29 additions & 1 deletion steerclear/static/css/steerclear-theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@

/*Rides Queue*/

.no-rides-notice {
text-align: center;
margin-top: 70px;
}

.rides {
background-color: rgba(80, 80, 80, 0.15) !important;
margin-top: 12px;
Expand Down Expand Up @@ -96,6 +101,21 @@
cursor: initial !important;
}

.timestamp-first {
float: left;
width: 44px;
margin-top: 22px;
font-size: 18px;
color: rgba(190, 190, 190, 1);
}

.timestamp {
float: left;
width: 44px;
margin-top: 16px;
color: rgba(190, 190, 190, 1);
}

.header-logo-small {
height: 150px;
}
Expand All @@ -104,7 +124,15 @@
position: absolute;
right: 14px;
top: 12px;
width: 36px;
width: 50px;
border-style: outset;
border-width: 5px;
padding: 3px 3px 3px 3px;
border-color: rgba(80, 80, 80, 0.25);
}

.logout-button:hover {
border-style: inset;
}

.header-body {
Expand Down
36 changes: 22 additions & 14 deletions steerclear/static/js/controllers/rides_controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
app.controller('RidesController', ['$scope', 'RidesService', function($scope, RidesService){
app.controller('RidesController', ['$scope', 'RidesService', '$window', function($scope, RidesService, $window){

$scope.filter = "both"

Expand Down Expand Up @@ -29,15 +29,16 @@ app.controller('RidesController', ['$scope', 'RidesService', function($scope, Ri
}
}

updateData = function() {
RidesService.getRides().then(function(data){
for (var i =0; i < data.rides.length; i++){
data.rides[i].pickup_address = data.rides[i].pickup_address || "Start Address Not Found";
data.rides[i].dropoff_address = data.rides[i].dropoff_address || "End Address Not Found";
};
$scope.originalRides = angular.copy(data.rides);
$scope.filterRides($scope.filter);
});
updateData = function() {
RidesService.getRides().then(function(data){
for (var i =0; i < data.rides.length; i++){
data.rides[i].pickup_address = data.rides[i].pickup_address || "Start Address Not Found";
data.rides[i].dropoff_address = data.rides[i].dropoff_address || "End Address Not Found";
};
$scope.originalRides = angular.copy(data.rides);
$scope.filterRides($scope.filter);
});
console.log($scope.rides)
};

updateData();
Expand All @@ -47,7 +48,7 @@ app.controller('RidesController', ['$scope', 'RidesService', function($scope, Ri
$scope.iOS = /iPad|iPhone|iPod/.test(navigator.platform);
url = "maps.google.com?&daddr=" + dlat + "," + dlong
if (slat & slong) {
url = url + "&saddr=" + slat + "," + slong;
url = url + "&saddr=" + slat + "," + slong;
}
url += "&zoom=15";
if ($scope.iOS) {
Expand Down Expand Up @@ -79,6 +80,13 @@ app.controller('RidesController', ['$scope', 'RidesService', function($scope, Ri
}
};

$scope.logout = function () {
console.log("THing");
if (confirm('Are you sure you want to log out?')){
$window.location.href = '/logout';
}
};



//For demo purposes....
Expand All @@ -87,12 +95,12 @@ app.controller('RidesController', ['$scope', 'RidesService', function($scope, Ri
"num_passengers": 4,
"start_latitude": 37.273485,
"start_longitude": -76.719628,
"end_latitude": 37 + Math.random(),
"end_longitude": -76.2 + Math.random(),
"end_latitude": 37.273,
"end_longitude": -76.719628,
"phone": 15555555555
};

if (document.location.hostname == "localhost" || document.location.hostname == "127.0.0.1")
RidesService.createRide(ride)
RidesService.createRide(ride)

}]);
69 changes: 38 additions & 31 deletions steerclear/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<html lang="en">
<head>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
Expand All @@ -18,24 +18,27 @@
<link rel="stylesheet" href="/static/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="/static/css/steerclear-theme.css">

</head>
</head>

<body class="body" ng-app="SteerClear">
<body class="body" ng-app="SteerClear" ng-controller="RidesController" ng-cloak>
<div class="header-body">
<a href="/logout"><img src="static/assets/logout.png" class="logout-button"></img></a>
<img ng-click="logout()" src="static/assets/logout.png" class="logout-button"></img>
<img src="static/assets/logo_very_small.png" class="center-block header-logo-small"></img>
</div>
<div class="header-bar"></div>
</div>
<div class="header-bar"></div>

<div class="container" ng-controller="RidesController">
<div class="container-fluid">

<ul class="nav nav-tabs ride-tabs">
<li role="presentation" ng-class="{'active': filter == 'on_campus'}" ng-click="filterRides('on_campus')"><a href="#">On Campus</a></li>
<li role="presentation" ng-class="{'active': filter == 'both'}" ng-click="filterRides('both')"><a href="#">All Rides</a></li>
<li role="presentation" ng-class="{'active': filter == 'off_campus'}" ng-click="filterRides('off_campus')"><a href="#">Off Campus</a></li>
</ul>
</ul>

<h2 class="no-rides-notice" ng-if="!rides.length">No ride requests at the moment.</h2>

<div class="col-xs-12" ng-show="rides[0]">
<div class="col-xs-12" ng-show="rides[0]">
<div class="timestamp-first"><p>{[{rides[0].created | date:'h:mm'}]}</p></div>
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-lg row-button" type="button" ng-click="deleteRide(rides[0])">
Expand All @@ -54,31 +57,35 @@
</button>
</span>
</div>
</div>
</div>

<div class="col-xs-offset-1 col-xs-10">
<div class="input-group" ng-repeat="ride in rides track by ride.id" ng-show="!$first">
<span class="input-group-btn">
<button class="btn row-button" type="button" ng-click="deleteRide(ride)">
<span class="glyphicon glyphicon-remove button-icon"></span>
</button>
</span>
<div ng-click="gps(ride.start_latitude, ride.start_longitude)" title="Open in Google Maps"><input class="form-control rides" ng-placeholder="ride.pickup_address" disabled></input></div>
<div ng-click="gps(ride.end_latitude, ride.end_longitude)" title="Open in Google Maps"><input class="form-control rides" ng-placeholder="ride.dropoff_address" disabled></input></div>
<span class="input-group-btn">
<button class="btn row-button passengers" type="button" title="Number of Passengers">{[{ride.num_passengers}]}</button>
<button class="btn row-button" type="button" ng-click="finishRide(ride)" title="Finish Ride">
<span class="glyphicon glyphicon-check button-icon"></span>
</button>
<button class="btn row-button" type="button" ng-click="notify(ride)" title="Text this pickup you're coming">
<span class="glyphicon glyphicon-phone button-icon"></span>
</button>
</span>

<div class="col-xs-offset-1 col-xs-10">
<div ng-repeat="ride in rides track by ride.id" ng-show="!$first">
<div class="timestamp"><p>{[{ride.created | date:'h:mm'}]}</p></div>
<div class="input-group">
<span class="input-group-btn">
<button class="btn row-button" type="button" ng-click="deleteRide(ride)">
<span class="glyphicon glyphicon-remove button-icon"></span>
</button>
</span>
<div ng-click="gps(ride.start_latitude, ride.start_longitude)" title="Open in Google Maps"><input class="form-control rides" ng-placeholder="ride.pickup_address" disabled></input></div>
<div ng-click="gps(ride.end_latitude, ride.end_longitude)" title="Open in Google Maps"><input class="form-control rides" ng-placeholder="ride.dropoff_address" disabled></input></div>
<span class="input-group-btn">
<button class="btn row-button passengers" type="button" title="Number of Passengers">{[{ride.num_passengers}]}</button>
<button class="btn row-button" type="button" ng-click="finishRide(ride)" title="Finish Ride">
<span class="glyphicon glyphicon-check button-icon"></span>
</button>
<button class="btn row-button" type="button" ng-click="notify(ride)" title="Text this pickup you're coming">
<span class="glyphicon glyphicon-phone button-icon"></span>
</button>
</span>
</div>
</div>
</div>
</div>
</div>

<div class="footer-bar"></div>
<div class="footer-bar"></div>


<!-- Bootstrap core JavaScript
Expand All @@ -95,5 +102,5 @@
<script src="static/js/controllers/rides_controller.js"></script>
<script src="static/js/services/rides_service.js"></script>
<script src="static/js/directives/ng-placeholder.js"></script>
</body>
</body>
</html>
17 changes: 16 additions & 1 deletion steerclear/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,25 @@

<div class="container">

{% with messages = get_flashed_messages() %}
{% if messages %}
<ul class=flashes>
{% for message in messages %}
<div class="alert alert-success .col-xs-4" role="alert">{{ message }}</div>
{% endfor %}
</ul>
{% endif %}
{% endwith %}

{% if error %}
<div class="alert alert-danger .col-xs-4" role="alert">{{ error }}</div>
{% endif %}


<form id="form" class="form-signin" action="{{action}}" method="POST">

<div class="inputs">
<input type="text" name="username" class="form-control login-username login-transparent" placeholder="Username" required autofocus>
<input type="text" name="username" class="form-control login-username login-transparent" placeholder="Username (@email.wm.edu)" required autofocus>
<input type="password" name="password" class="form-control login-password login-transparent" placeholder="Password" required>
</div>
<div class="button-container">
Expand Down
2 changes: 1 addition & 1 deletion tests/driver_portal_tests/views_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ def test_get_index_admin_user(self):
def test_get_index_student_user(self):
self._login(self.student_user)
response = self.client.get(url_for('driver_portal.index'))
self.assertRedirects(response, url_for('driver_portal.heartbeat'))
self.assertEquals(response.status_code, 403)