Skip to content

Commit

Permalink
Show number of attendees that will be arranged in section arranger modal
Browse files Browse the repository at this point in the history
  • Loading branch information
tjgrathwell committed Dec 13, 2013
1 parent 507f6c2 commit c4d0ec9
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 30 deletions.
40 changes: 37 additions & 3 deletions app/assets/javascripts/views/section_organizer_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ Bridgetroll.Views.SectionOrganizer = (function () {
function addSectionView(section) {
var sectionView = new Bridgetroll.Views.Section({
section: section,
attendees: this.attendees
attendees: this.attendees,
workshopSessionId: _.last(this.sessions).id
});

this.addSubview(sectionView);
Expand Down Expand Up @@ -83,13 +84,46 @@ Bridgetroll.Views.SectionOrganizer = (function () {
this.render();
},

volunteers: function () {
return this.attendees.where({role_id: Bridgetroll.Enums.Role.VOLUNTEER})
},

students: function () {
return this.attendees.where({role_id: Bridgetroll.Enums.Role.STUDENT})
},

context: function () {
function checkedIn (collection) {
return collection.filter(function(a) { return a.get('checkins_count') > 0 });
}

var sessionsWithCheckinCounts = _.map(this.sessions, _.bind(function (session) {
session.checkedInVolunteers = checkedIn(this.volunteers()).filter(function (a) {
return _.include(a.get('checked_in_session_ids'), session.id);
}).length;
session.checkedInStudents = checkedIn(this.students()).filter(function (a) {
return _.include(a.get('checked_in_session_ids'), session.id);
}).length;

return session;
}, this));

return {
hasSections: this.sections.length > 0,
showUnassigned: this.showUnassigned,
showOS: this.showOS,
sessions: this.sessions,
polling: this.poller.polling()
sessions: sessionsWithCheckinCounts,
polling: this.poller.polling(),
checkedInCounts: {
indiscriminate: {
volunteers: this.volunteers().length,
students: this.students().length
},
any: {
volunteers: checkedIn(this.volunteers()).length,
students: checkedIn(this.students()).length
}
}
};
},

Expand Down
16 changes: 12 additions & 4 deletions app/assets/javascripts/views/section_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,28 @@ Bridgetroll.Views.Section = Bridgetroll.Views.Base.extend({
this._super('initialize', arguments);

this.section = options.section;

this.attendees = options.attendees;
this.workshopSessionId = options.workshopSessionId;
},

context: function () {
return {
title: this.section.get('name'),
students: _.pluck(this.students(), 'attributes'),
students: this.presentedStudents(),
volunteers: this.presentedVolunteers(),
destructable: !this.section.isUnassigned()
}
},

presentedStudents: function () {
return _.map(_.pluck(this.students(), 'attributes'), _.bind(function (student_attributes) {
student_attributes.workshop_checkins_count = _.include(student_attributes.checked_in_session_ids, this.workshopSessionId);
return student_attributes;
}, this));
},

presentedVolunteers: function () {
return _.map(_.pluck(this.volunteers(), 'attributes'), function (volunteer_attributes) {
return _.map(_.pluck(this.volunteers(), 'attributes'), _.bind(function (volunteer_attributes) {
var volunteer_letter;
if (volunteer_attributes.teaching && volunteer_attributes.taing) {
volunteer_letter = '?';
Expand All @@ -41,10 +48,11 @@ Bridgetroll.Views.Section = Bridgetroll.Views.Base.extend({
} else {
volunteer_letter = 'x';
}
volunteer_attributes.workshop_checkins_count = _.include(volunteer_attributes.checked_in_session_ids, this.workshopSessionId);
return _.extend({}, volunteer_attributes, {
volunteer_letter: volunteer_letter
});
});
}, this));
},

students: function () {
Expand Down
6 changes: 3 additions & 3 deletions app/assets/templates/section_organizer/section_organizer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@
<p>This is generally a good starting point for organizing the sections in your event, but you will still need to make manual tweaks afterwards.</p>
<p>When auto arranging, you can choose to arrange only:</p>
<label>
<input type="radio" name="auto-arrange-choice" value="any" checked> Attendees who have been checked-in to at least one session
<input type="radio" name="auto-arrange-choice" value="any" checked> Attendees who have been checked-in to at least one session ({{checkedInCounts.any.volunteers}} volunteers, {{checkedInCounts.any.students}} students)
</label>
{{#each sessions}}
<label>
<input type="radio" name="auto-arrange-choice" value="{{this.id}}"> Attendees who have been checked-in to {{this.name}}
<input type="radio" name="auto-arrange-choice" value="{{this.id}}"> Attendees who have been checked-in to {{this.name}} ({{this.checkedInVolunteers}} volunteers, {{this.checkedInStudents}} students)
</label>
{{/each}}
<label>
<input type="radio" name="auto-arrange-choice" value="indiscriminate"> All RSVP'd attendees <strong>(Not Recommended)</strong>
<input type="radio" name="auto-arrange-choice" value="indiscriminate"> All RSVP'd attendees ({{checkedInCounts.indiscriminate.volunteers}} volunteers, {{checkedInCounts.indiscriminate.students}} students) <strong>(Not Recommended)</strong>
</label>
</div>
<div class="modal-footer">
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def organize_sections
format.json do
render json: {
sections: @event.sections,
attendees: @event.rsvps_with_workshop_checkins
attendees: @event.rsvps_with_checkins
}
end
end
Expand Down
16 changes: 8 additions & 8 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ def ordered_rsvps(assoc)
end
end

def rsvps_with_workshop_checkins
rsvp_jsons = rsvps.where(waitlist_position: nil).includes(:user).as_json
workshop_checkins = RsvpSession.where(event_session_id: event_sessions.last.id, checked_in: true).map(&:rsvp_id)
rsvp_jsons.each do |rsvp_json|
rsvp_id = rsvp_json['id']
if rsvp_json['role_id'] == Role::ORGANIZER.id
rsvp_json['workshop_checkins_count'] = 1
def rsvps_with_checkins
attendee_rsvps = rsvps.where(waitlist_position: nil).includes(:user, :rsvp_sessions)
attendee_rsvps.map do |rsvp|
json = rsvp.as_json
if rsvp.role == Role::ORGANIZER
json['checked_in_session_ids'] = event_sessions.map(&:id)
else
rsvp_json['workshop_checkins_count'] = workshop_checkins.include?(rsvp_id) ? 1 : 0
json['checked_in_session_ids'] = rsvp.rsvp_sessions.where(checked_in: true).pluck(:event_session_id)
end
json
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/events/organize_sections.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script>
$(document).ready(function () {
var attendees = new Bridgetroll.Collections.Attendee(
<%= @event.rsvps_with_workshop_checkins.to_json.html_safe %>
<%= @event.rsvps_with_checkins.to_json.html_safe %>
);
var sections = new Bridgetroll.Collections.Section(
<%= @event.sections.to_json.html_safe %>
Expand Down
24 changes: 14 additions & 10 deletions spec/models/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,32 +205,36 @@
end
end

describe "#rsvps_with_workshop_checkins" do
describe "#rsvps_with_checkins" do
before do
@event = create(:event)
first_session = @event.event_sessions.first
first_session.update_attributes(ends_at: 6.months.from_now)
@first_session = @event.event_sessions.first
@first_session.update_attributes(ends_at: 6.months.from_now)

last_session = create(:event_session, event: @event, ends_at: 1.year.from_now)
@last_session = create(:event_session, event: @event, ends_at: 1.year.from_now)

@rsvp1 = create(:rsvp, event: @event)
create(:rsvp_session, event_session: first_session, rsvp: @rsvp1, checked_in: true)
create(:rsvp_session, event_session: @first_session, rsvp: @rsvp1, checked_in: true)

@rsvp2 = create(:rsvp, event: @event)
create(:rsvp_session, event_session: last_session, rsvp: @rsvp2)
create(:rsvp_session, event_session: @last_session, rsvp: @rsvp2)

@rsvp3 = create(:rsvp, event: @event)
create(:rsvp_session, event_session: last_session, rsvp: @rsvp3, checked_in: true)
create(:rsvp_session, event_session: @last_session, rsvp: @rsvp3, checked_in: true)

@event.reload
end

it 'counts attendances for the last session' do
attendee_rsvp_data = @event.rsvps_with_workshop_checkins
attendee_rsvp_data = @event.rsvps_with_checkins
attendee_rsvp_data.length.should == 3

workshop_attendees = attendee_rsvp_data.select { |rsvp| rsvp['workshop_checkins_count'] > 0 }
workshop_attendees.map { |att| att['id'] }.should == [@rsvp3.id]
workshop_attendees = attendee_rsvp_data.map { |rsvp| [rsvp['id'], rsvp['checked_in_session_ids']] }
workshop_attendees.should =~ [
[@rsvp1.id, [@first_session.id]],
[@rsvp2.id, []],
[@rsvp3.id, [@last_session.id]]
]
end
end

Expand Down

0 comments on commit c4d0ec9

Please sign in to comment.