Skip to content

Commit

Permalink
Improved useability and added a test for scan-by-name.
Browse files Browse the repository at this point in the history
  • Loading branch information
iasoon committed Mar 25, 2015
1 parent 500455b commit 0b2a24e
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 18 deletions.
26 changes: 18 additions & 8 deletions app/assets/stylesheets/event.css.scss
Expand Up @@ -2,23 +2,33 @@
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
.field_with_errors {
display: inline;
display: inline;
}

.input-group {
width: 100%;
width: 100%;
}

.typeahead-scan-name {
#scan-by-name {
.typeahead-scan-name {
float: left;
}
}

.typeahead-scan-email {
.typeahead-scan-email {
color: #777;
float: right;
}
}

.typeahead-scan-email .tt-highlight {
color: brown;
.tt-highlight {
color: #3276B1;
text-decoration: none;
}

.tt-cursor {
background-color: #eee;
}

.tt-suggestion {
overflow: hidden;
}
}
8 changes: 3 additions & 5 deletions app/controllers/events_controller.rb
Expand Up @@ -93,16 +93,14 @@ def scan
def scan_barcode
@event = Event.find params.require(:id)
authorize! :update, @event
barcode = params.require(:code)
@registration = @event.registrations.find_by barcode: barcode
@registration = @event.registrations.find_by barcode: params.require(:code)
check_in
end

def scan_username
def scan_name
@event = Event.find params.require(:id)
authorize! :update, @event
username = params.require(:username)
@registration = @event.registrations.find_by name: username
@registration = @event.registrations.find_by name: params.require(:name)
check_in
end

Expand Down
8 changes: 4 additions & 4 deletions app/views/events/scan.html.erb
Expand Up @@ -43,11 +43,11 @@

<br/>

<%= form_tag scan_username_event_path(@event), remote: false do %>
<div class="input-group">
<%= form_tag scan_name_event_path(@event), remote: false do %>
<div id="scan-by-name" class="input-group">
<div class="input-group">
<input required type="text" class="form-control typeahead"
placeholder="Start searching by entering a name or an email" name="username" id="username">
placeholder="Start searching by entering a name or an email" name="name" id="name">
<span class="input-group-btn">
<button class="btn btn-primary" name="button" type="submit">
Submit
Expand All @@ -74,7 +74,7 @@ var registrations = new Bloodhound({

registrations.initialize();

$('#username').typeahead(
$('#name').typeahead(
{
hint: true,
highlight: true,
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -49,7 +49,7 @@
get 'scan'
get 'list_registrations'
post 'scan_barcode'
post 'scan_username'
post 'scan_name'
end

resources :periods
Expand Down
6 changes: 6 additions & 0 deletions test/controllers/event_controller_test.rb
Expand Up @@ -66,6 +66,12 @@ def setup
assert(flash[:success].include? "Person has been scanned")
end

test "validate correct name" do
post :scan_name, id: events(:codenight).id, name: 'Tom Naessens'
assert_response :success
assert(flash[:success].include? "Person has been scanned")
end

test "dont check in twice" do
post :scan_barcode, id: events(:codenight).id, code: '1234567891231'
assert_response :success
Expand Down

0 comments on commit 0b2a24e

Please sign in to comment.