context = window rest = window.JK.Rest() logger = context.JK.logger @FindSessionRow = React.createClass({ createInstrument: (participant) -> instruments = [] existingTracks = [] for j in [0 .. participant.tracks.length] track = participant.tracks[j] if existingTracks.indexOf(track.instrument_id) < 0 existingTracks.push(track.instrument_id) logger.debug("Find:Finding instruments. Participant tracks:", participant.tracks) inst = context.JK.getInstrumentIcon24(track.instrument_id) instruments.push(``) instruments createInSessionUser: (participant) -> instruments = @createInstrument(participant) id = participant.user.id; name = participant.user.name; userId = id avatar_url = context.JK.resolveAvatarUrl(participant.user.photo_url) profile_url = "/client#/profile/" + id musician_name = name more_link = '' ` {musician_name}
{instruments}
{more_link}  ` createOpenSlot:(slot) -> `
{instrument} ({proficiency})
{more_link}  ` createRsvpUser: (user, session, isLast) -> instrumentLogoHtml = [] if user.instrument_list for j in [0 .. user.instrument_list.length] instrument = user.instrument_list[j]; inst = context.JK.getInstrumentIcon24(instrument.id); instrumentLogoHtml.push(``) moreLinkHtml = ''; if isLast moreLinkHtml = `more` instruments = @createInstrument(user) id = participant.user.id; name = participant.user.name; userId = id avatar_url = context.JK.resolveAvatarUrl(participant.user.photo_url) profile_url = "/client#/profile/" + id musician_name = name more_link = '' ` {musician_name}
{instruments}
{more_link}  ` inSessionUsersHtml: (session) -> inSessionUsers = [] result = [] if session.active_music_session && "participants" in session.active_music_session && session.active_music_session.participants.length > 0 for i in [0 .. session.active_music_session.participants.length] participant = session.active_music_session.participants[i] inSessionUsers.push(participant.user.id); result.push(@createInSessionUser(participant)) return [result, inSessionUsers] createRsvpUsers:( ) -> session = @props.session firstResults = [] lastResults = [] approvedRsvpCount = session.approved_rsvps.length if session.approved_rsvps first = session.approved_rsvps.slice(0, 3) last = session.approved_rsvps.slice(3) for i in [0..first] user = first[i] firstResults.push(@createRsvpUser(user, session, approvedRsvpCount > 3 && i == 2)) for i in [0..last] user = last[i] lastResults.push(@createRsvpUser(user, session, false)) [firstResults, lastResults] createOpenSlots: () -> session = @prop.session firstResults = [] remainingResults = [] if session['is_unstructured_rsvp?'] firstResults.push(@createOpenSlot({description: 'Any Instrument'})) if session.open_slots openSlotCount = session.open_slots.length for i in [0 .. openSlotCount] openSlot = session.open_slots[i] if i < 3 firstResults.push(@createOpenSlot(session.open_slots[i], openSlotCount > 3 && i == 2)) else remainingResults.push(@createOpenSlot(session.open_slots[i], false)) return [firstResults, remainingResults] showJoinLinks: (inSessionUsers) -> session = @prop.session showJoinLink = session.musician_access if session.approved_rsvps approvedRsvpCount = session.approved_rsvps.length for i in [0 .. approvedRsvpCount] # do not show the user in this section if he is already in the session if $.inArray(session.approved_rsvps[i].id, inSessionUsers) == -1 if session.approved_rsvps[i].id == context.JK.currentUserId showJoinLink = true else showJoinLink = true showJoinLink render: () -> session = @props.session id = session.id name = session.name description = session.description || "(No description)" genres = '(' + session.genres.join (', ') + ')' [in_session_musicians, inSessionUsers] = @inSessionUsersHtml() [rsvp_musicians_first_3, rsvp_musicians_remaining] = @createRsvpUsers() [open_slots_first_3, open_slots_remaining] = @createOpenSlots() showJoinLink = @showJoinLink(inSessionUsers) showListenLink = session.fan_access && session.active_music_session && session.active_music_session.mount join_link_display_style = {display: "none"} listen_link_display_style = {display: "none"} if showJoinLink join_link_display_style = {display: "block"} if showListenLink listen_link_display_style = {display: "inline-block"} listen_link_text = '' if !session.fan_access listen_link_text = '' else if session.active_music_session && session.active_music_session.mount listen_link_text = 'Listen' else listen_link_text = ''; `
{name} {genres}
{description}
In Session: {in_session_musicians}
RSVPs: {rsvp_musicians_first_3}
{rsvp_musicians_remaining}
Still Needed: {open_slots_first_3}
{open_slots_remaining}

{listen_link_text}?
Join
` })