luanguimaraesla/PickAProject

View on GitHub
app/views/projects/_form.html.erb

Summary

Maintainability
Test Coverage
<div class="app-form">
  <%= nested_form_for @project, html: { class: "form-horizontal project" },
      url: { action: act, id: @project, user_id: current_user.id } do |f| %>
      <!-- Get possible errors in the empty project object -->
      <% if @project.errors.any? %>
      <div id="error_expl" class="panel panel-danger">
        <div class="panel-heading">
          <h3 class="panel-title"><%= pluralize(@project.errors.count, "error") + "prohibited this project from being saved:" %></h3>
        </div>
        <div class="panel-body">
          <ul>
          <!-- Print some errors -->
          <% @project.errors.full_messages.each do |msg| %>
            <li><%= msg %></li>
          <% end %>
          </ul>
        </div>
      </div>
    <% end %>

    <!-- Get title -->
    <div class="control-group">
      <%= f.label :title, :class => 'control-label' %>
      <div class="controls">
        <%= f.text_field :title, :class => 'form-control' %>
      </div>
    </div>

    <!-- Get category -->
    <div class="control-group accept-inline">
      <%= f.label :category, :class => 'control-label' %>
      <div class="controls">
        <%= f.select :category, options_for_select(@project.class::PERMITTED_CATEGORIES), {}, :class => 'form-control' %>
      </div>
    </div>

    <!-- Get level -->
    <!-- [TODO] limit options easy, medium, hard -->
    <div class="control-group accept-inline">
      <%= f.label :level, :class => 'control-label' %>
      <div class="controls">
        <%= f.select :level, options_for_select(@project.class::PERMITTED_LEVELS), {}, :class => 'form-control' %>
      </div>
    </div>

    <!-- Get status -->
    <div class="control-group accept-inline">
      <%= f.label :status, :class => 'control-label' %>
      <div class="controls">
        <%= f.select :status, @project.class::PERMITTED_STATUS, {}, :class => 'form-control' %>
      </div>
    </div>

    <!-- Get the image for this task -->
    <div class="control-group">
      <%= f.label :image_file, "Overview image", class: 'control-label' %>
      <div class="controls">
        <%= f.file_field :image_file, row: "2", class: 'form-control' %>
      </div>
    </div>
    <br />

    <!-- Get description. -->
    <div class="control-group">
      <%= f.label :description, "Overview", :class => 'control-label' %>
      <div class="controls">
        <%= f.text_area :description, :class => 'form-control' %>
      </div>
    </div>

    <!-- Get each task information. -->
    <div class="control-group task-form">
      <br>
      <h2 id="task-label">Tasks</h2>
      <br>
      <!-- Loop while user clicks on "Add a new task". -->
      <%= f.fields_for :tasks do |task_form| %>
        <div class="control-group">
          <hr>
          <h3 id="task-label">#task</h2>
          <!-- Get the title of the task. -->
          <%= task_form.label :title, class: 'control-label' %><br>
          <%= task_form.text_field :title, class: 'form-control' %><br>

          <div class="accept-inline">
            <!-- Get the image for this task -->
            <%= task_form.label :image_file, "Task image", class: 'control-label' %><br>
            <%= task_form.file_field :image_file %><br>
          </div>

          <!-- Get the difficult of the task, should be fibonacci (1, 21). -->
          <%= task_form.label :difficult, class: 'control-label' %><br>
          <%= task_form.select :difficult, [1, 2, 3, 5, 8, 13, 21],class: 'form-control difficult-align' %>
          <br><br><br>

          <!-- Get the description of the task. -->
          <%= task_form.label :description, class: 'control-label' %><br>
          <%= task_form.text_area :description, class: 'form-control' %><br>

          <!-- Add a button to remove created task's fields. -->
          <%= task_form.link_to_remove "Remove this task", class: 'btn btn-primary center-block' %>
        </div>
      <% end %>
      <!-- Add a button to create new empty task fields. -->
      <p><%= f.link_to_add "Add a new task", :tasks, class: 'btn btn-default center-block'%></p>
    </div>

    <br>
    <div class="submit-buttons">
      <!-- Buttons to submit or cancel form -->
      <%= f.submit nil, :class => 'btn btn-primary' %>
      <%= link_to t('.cancel', :default => t("helpers.links.cancel")),
                user_projects_path(current_user.id), :class => 'btn btn-default' %>
    </div>
  <% end %>
</div>