infusionvlc/infusion

View on GitHub
app/views/meetups/show.html.erb

Summary

Maintainability
Test Coverage
<!-- Modal -->
<div class="modal fade" id="meetupReportModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-body">
        <%= render 'reports/form' %>
      </div>
    </div>
  </div>
</div>

<div class="jumbotron jumbotron-fluid">
  <div class="container">
    <h1><%= @meetup.title %></h1>
    <p class="lead"><%= meetup_votes(@meetup) %></p>
    <h2 aria-label=<%= I18n.t 'activerecord.attributes.meetup.categories' %>>
      <span class="badge badge-pill badge-info"><%= @meetup.average_rating %> <%= icon('fas', 'star') %></span>
      <% @meetup.categories.each do |cat| %>
        <%= link_to cat do %><span class="badge badge-pill badge-info blue"><%=cat.display_name %></span><% end %>
      <% end %>
    </h2>
  </div>
</div>
<br/>
<div class="row">
  <div class="col-md-8 col-sm-12 description">
    <h2 class="section-title"><%= I18n.t 'activerecord.attributes.meetup.description' %></h2>
    <p><%= sanitize @markdown.render(@meetup.description), attributes: %w(href target) if @meetup.description %></p>
    <h2 class="section-title"><%= I18n.t 'activerecord.attributes.meetup.requirements' %></h2>
    <p><%= sanitize @markdown.render(@meetup.requirements), attributes: %w(href target) if @meetup.requirements %></p>
    <% if @meetup.attachments.size > 0 %>
      <h2><%= I18n.t 'activerecord.attributes.meetup.attachments' %></h2>
      <% @meetup.attachments.each do |f| %>
        <p><%= file_icon(f) %> <%= link_to f.file.original_filename, f.file.url, target: "_blank" %></p>
      <% end %>
    <% end %>
    <% if @meetup.photos.size > 0 %>
      <h2 class="section-title"><%= I18n.t 'activerecord.attributes.meetup.photos' %></h2>
      <% @meetup.photos.each do |img| %>
        <div class="card" style="width: 18rem;">
          <%= image_tag img.file.url, class:'card-img-top' %>
          <div class="card-body">
            <h5 class="card-title"><%= img.attribution %></h5>
          </div>
        </div>
      <% end %>
    <% end %>

    <h2 class="section-title"><%= I18n.t 'meetup.sessions' %></h2>
    <% @meetup.sessions.each do |session| %>
      <div class="card">
        <div class="card-body">
          <% if session.event %>
            <h3><%= session.event.date %> @ <%= link_to session.location.name, session.location %></h3>
            <p><%= session.start.strftime('%H:%M') %> - <%= session.end.strftime('%H:%M') %></p>
          <% else %>
            <%= link_to I18n.t('session.ranking'), ranking_path %>
          <% end %>
          <% if session.took_place? %>
            <% if policy(session).vote? %>
              <br/>
              <p><%= I18n.t 'meetup.call_to_action_assisted' %></p>
              <%= link_to vote_meetup_session_path(@meetup, session), method: :post, class:'btn btn-success btn-lg btn-block' do %><%= icon('fas', 'check') %> <%= I18n.t 'main.assisted' %><% end %>
            <% elsif !user_signed_in? %>
              <p><%= I18n.t 'meetup.call_to_action_no_user_assisted' %></p>
              <%= link_to new_user_session_path, class:'btn btn-primary btn-lg btn-block' do %><%= icon('fas', 'sign-in') %> <%= I18n.t 'user.login' %><% end %>
            <% end %>
            <% if policy(session).comment? %>
              <div class="card">
                <div class="card-body">
                  <h3><%= I18n.t 'meetup.review' %></h3>
                  <%= form_for [@meetup, session, session.assistances.find_by_user_id(current_user.id)] do |f| %>
                    <div class="row">
                      <div class="field col-2">
                        <%= f.label :mark %><br />
                        <%= f.select :mark, [5,4,3,2,1], {}, class: 'form-control' %>
                      </div><br/>
                      <div class="field col-10">
                        <%= f.label :review %><br />
                        <%= f.text_field :review, autofocus: true, class: 'form-control', id:'new_field' %>
                      </div><br/>
                    </div><br/>
                    <%= f.submit class: 'btn btn-primary right', id:'new_comment' %>
                  <% end %>
                </div>
              </div>
            <% end %>
            <br/>
          <% elsif session.taking_place? %>
            <% if policy(session).vote? %>
              <br/>
              <p><%= I18n.t 'meetup.call_to_action_assist' %></p>
              <%= link_to vote_meetup_session_path(@meetup, session), method: :post, class:'btn btn-success btn-lg btn-block' do %><%= icon('fas', 'check') %> <%= I18n.t 'main.assist' %><% end %>
            <% elsif policy(session).unvote? %>
              <br/>
              <p><%= I18n.t 'meetup.unvote' %></p>
              <%= link_to unvote_meetup_session_path(@meetup, session), method: :post, class:'btn btn-warning btn-lg btn-block' do %><%= icon('fas', 'times') %> <%= I18n.t 'main.unvote' %><% end %>
            <% elsif !user_signed_in? %>
              <p><%= I18n.t 'meetup.call_to_action_no_user_assist' %></p>
              <%= link_to new_user_session_path, class:'btn btn-primary btn-lg btn-block' do %><%= icon('fas', 'sign-in') %> <%= I18n.t 'user.login' %><% end %>
            <% end %>
          <% else %>
            <% if policy(session).vote? %>
              <br/>
              <p><%= I18n.t 'meetup.call_to_action' %></p>
              <%= link_to vote_meetup_session_path(@meetup, session), method: :post, class:'btn btn-success btn-lg btn-block' do %><%= icon('fas', 'arrow-up') %> <%= I18n.t 'main.vote' %><% end %>
            <% elsif policy(session).unvote? %>
              <br/>
              <p><%= I18n.t 'meetup.unvote' %></p>
              <%= link_to unvote_meetup_session_path(@meetup, session), method: :post, class:'btn btn-warning btn-lg btn-block' do %><%= icon('fas', 'times') %> <%= I18n.t 'main.unvote' %><% end %>
            <% elsif user_signed_in? %>
              <p><%= I18n.t 'meetup.already_voted' %></p>
            <% else %>
              <p><%= I18n.t 'meetup.call_to_action_no_user' %></p>
              <%= link_to new_user_session_path, class:'btn btn-primary btn-lg btn-block' do %><%= icon('fas', 'sign-in') %> <%= I18n.t 'user.login' %><% end %>
            <% end %>
          <% end %>
        </div>
      </div>
    <% end %>

    <% if @meetup.took_place? %>
      <h2 class="section-title"><%= I18n.t 'meetup.reviews' %></h2>
      <% if @reviews.count == 0 %>
        <p><%= I18n.t 'meetup.no_reviews' %></p>
      <% end %>
    <% end %>


    <% @reviews.each do |review| %>
      <!-- Modal -->
      <div class="modal fade" id="reviewReportModal_<%= review.id %>" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-body">
              <%= render 'reports/review_form', review: review %>
            </div>
          </div>
        </div>
      </div>
      <div class="card">
        <div class="card-body">
          <% if policy(review).report? %>
            <% var_modal = "#reviewReportModal_" + review.id.to_s %>
            <%= link_to "#", data: {toggle: "modal", target: var_modal} , class:'right' do  %><% icon('fas', 'exclamation-triangle ') %><% end %>
          <% end %>
          <% if policy(review).edit? %>
            <a href='#' class='right edit_comment' id='edit_comment_<%= review.id %>'><%= icon('fas', 'pencil') %></a>
          <% end %>
          <div id='info_<%= review.id %>'>
            <%= render partial: 'review_info', locals: {review: review} %>
          </div>
          <div id='edit_form_<%= review.id %>' style='display: none'>
            <%= render partial: 'review_form', locals: {review: review} %>
          </div>
        </div>
        <div class="card-footer text-muted">
          <%= link_to review.user.username, "/#{review.user.username}" %> | <%= time_ago_in_words(review.updated_at) %>
        </div>
      </div>
      <br/>
    <% end %>
    <%= paginate @reviews, theme: 'twitter-bootstrap-4' %>
  </div>
  <div class="col-md-4 col-sm-12 ">
      <% if policy(@meetup).report? %>
        <button data-toggle="modal" data-target="#meetupReportModal" class="btn btn-warning btn-lg btn-block">
          <%= icon('fas', 'exclamation-triangle') %> <%= I18n.t 'report.report' %>
        </button>
      <% end %>

      <% if policy(@meetup).repeat? %>
          <%= link_to repeat_meetup_path(@meetup), method: :post, class:'btn btn-primary btn-lg btn-block' do %><%= icon('fas', 'redo') %> <%= I18n.t 'meetup.repeat' %><% end %>
      <% end %>

      <% if policy(@meetup).leave? %>
          <%= link_to leave_meetup_path(@meetup), method: :post, class:'btn btn-danger btn-lg btn-block' do %><%= icon('fas', 'sign-out') %> <%= I18n.t 'meetup.leave' %><% end %>
      <% end %>

      <% if policy(@meetup).edit? %>
        <%= link_to edit_meetup_path(@meetup), class:'btn btn-primary btn-lg btn-block' do %><%= icon('fas', 'pencil') %> <%= I18n.t 'meetup.edit' %><% end %>
        <% if policy(@meetup).destroy? %>
          <%= link_to meetup_path(@meetup), method: :delete, class:'btn btn-danger btn-lg btn-block' do %><%= icon('fas', 'times') %> <%= I18n.t 'meetup.destroy' %><% end %>
        <% end %>
      <% end %>

      <% if @meetup.video_url && @meetup.video_url.length > 0 %>
        <br/>
        <h2>YouTube</h2>
        <%= link_to image_tag("https://img.youtube.com/vi/#{video(@meetup)}/hqdefault.jpg", class: 'huge-logo'),
                    "https://www.youtube.com/watch?v=#{video(@meetup)}", target: '_blank' %>
        <br/>
      <% end %>
      <br/>
      <h3><%= I18n.t 'activerecord.attributes.meetup.holdings.other' %></h3>
      <% @meetup.hosts.each do |host| %>
          <div class="center">
            <%= link_to "/#{host.username}" do %>
              <div style="width: 45%; margin: 0 auto"><div class="avatar" style="background-image: url(<%= host.avatar.url %>)"></div></div><br/>
              <h2>
                <%= host.username %>
              </h2>
            <% end %>
            <br/>
          </div>
      <% end %>
    </div>
</div>