Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#558 - Added basic user preferences. Next - need to add validation fo…
…r the inputs and design the settings modal.
- Loading branch information
Showing
7 changed files
with
248 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""add user preferences | ||
Revision ID: 2438f7d83478 | ||
Revises: 40f5c56adfee | ||
Create Date: 2016-03-08 21:20:42.234353 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '2438f7d83478' | ||
down_revision = '40f5c56adfee' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
'general_preferences', | ||
sa.Column('user_id', sa.Integer, sa.ForeignKey('users.id'), primary_key=True), | ||
sa.Column('minimum_displayed_severity', sa.Integer, nullable=True), | ||
sa.Column('resource_type', sa.String(64), nullable=True), | ||
) | ||
|
||
op.create_table( | ||
'report_preferences', | ||
sa.Column('user_id', sa.Integer, sa.ForeignKey('users.id'), primary_key=True), | ||
sa.Column('line_number', sa.Integer, primary_key=True), | ||
sa.Column('historical_report', sa.Boolean, default=False), | ||
sa.Column('how_many_months_back', sa.Integer, nullable=True), | ||
sa.Column('latitude', sa.Float), | ||
sa.Column('longitude', sa.Float), | ||
sa.Column('radius', sa.Float), | ||
sa.Column('minimum_severity', sa.Integer), | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_table('report_preferences') | ||
op.drop_table('general_preferences') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Created by Avik on 07-Mar-16. | ||
*/ | ||
var PreferencesDialog = Backbone.View.extend({ | ||
className: "preferences-dialog", | ||
events: { | ||
"click .save-button": "submit", | ||
"click .close-button": "close" | ||
}, | ||
render: function () { | ||
self = this; | ||
self.$el.append($("#preferences-dialog-template").html()); | ||
$(document.body).append(self.$el); | ||
$.get("preferences", function (data) { | ||
self.$el.find("#prefLat").val(data["lat"]); | ||
self.$el.find("#prefLon").val(data["lon"]); | ||
self.$el.find("#prefDistance").val(data["distance"]); | ||
self.$el.find("#prefAccidentSeverity").val(data["accident_severity"]); | ||
if (data["history_report"] == true) { | ||
self.$el.find("#prefHistoryReportTrue").prop('checked', true); | ||
} else { | ||
self.$el.find("#prefHistoryReportTrue").prop('checked', false); | ||
} | ||
self.$el.find("#prefHistoryReportTrue") | ||
self.modal = self.$el.find(".modal"); | ||
self.modal.modal("show"); | ||
return self; | ||
}); | ||
|
||
}, | ||
close: function () { | ||
this.modal.modal("hide"); | ||
}, | ||
submit: function () { | ||
var lat = this.$el.find("#prefLat").val(); | ||
var lon = this.$el.find("#prefLon").val(); | ||
var distance = this.$el.find("#prefDistance").val(); | ||
var accident_severity = this.$el.find("#prefAccidentSeverity :selected").val(); | ||
var history_report = this.$el.find("#prefHistoryReportTrue").is(":checked"); | ||
$.post("preferences", JSON.stringify({ 'lat': lat, 'lon': lon, 'distance': distance, 'accident_severity': accident_severity, 'history_report': history_report }), 'json'); | ||
this.close(); | ||
} | ||
}); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters