Weeks new and edit
This commit is contained in:
parent
bb948f9644
commit
866fb98550
|
|
@ -27,7 +27,8 @@ module Admin
|
|||
# POST /admin/weeks.json
|
||||
def create
|
||||
@week = Week.new(admin_week_params)
|
||||
|
||||
@course = Course.find(@week.course_id)
|
||||
params[:course_id] = @course.id
|
||||
respond_to do |format|
|
||||
if @week.save
|
||||
format.js { collection }
|
||||
|
|
@ -81,7 +82,7 @@ module Admin
|
|||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def admin_week_params
|
||||
params.require(:week).permit(:name, :description)
|
||||
params.require(:week).permit(:name, :description, :course_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# ErrorsHelper
|
||||
module ErrorsHelper
|
||||
def error_messages(object)
|
||||
return unless object.errors.any?
|
||||
|
||||
content_tag(:div, class: 'card bg-danger p-3 text-white') do
|
||||
concat error_messages_h4
|
||||
concat error_messages_ul(object)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def error_messages_h4
|
||||
content_tag(:h4) do
|
||||
concat content_tag(:i, '', class: 'fas fa-exclamation-circle')
|
||||
concat " #{I18n.t('errors_ocurred')}"
|
||||
end
|
||||
end
|
||||
|
||||
def error_messages_ul(object)
|
||||
content_tag(:ul, class: 'm-0') do
|
||||
object.errors.full_messages.each do |message|
|
||||
concat content_tag(:li, message)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Weeks
|
||||
class Week < ApplicationRecord
|
||||
belongs_to :course
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
scope :by_course, ->(c_id) { where(course_id: c_id) }
|
||||
scope :name_asc, -> { order('name ASC') }
|
||||
scope :name_desc, -> { order('name DESC') }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
<h1 class="h3 mb-1 text-gray-800">Kurs: <strong><%= @course.name %></strong></h1>
|
||||
<h1 class="h3 mb-1 text-gray-800">Kurs: <strong><%= @course.name %></strong> (<%= link_to raw(t('back')), admin_courses_path %>)</h1>
|
||||
<p class="mb-4"><%= @course.description %></p>
|
||||
<!-- Weeks -->
|
||||
<%= render partial: '/admin/weeks/partials/index' %>
|
||||
|
||||
<%= link_to 'Back', admin_courses_path %>
|
||||
|
|
|
|||
|
|
@ -1,4 +1 @@
|
|||
<h1 class="h3 mb-1 text-gray-800">Kursy</h1>
|
||||
<p class="mb-4">Tutaj jakiś opis.</p>
|
||||
<p id="notice"><%= notice %></p>
|
||||
<%= render partial: '/admin/weeks/partials/index' %>
|
||||
|
|
|
|||
|
|
@ -1,15 +1,8 @@
|
|||
<%= form_with(model: [:admin, week]) do |form| %>
|
||||
<% if week.errors.any? %>
|
||||
<div id="error_explanation">
|
||||
<h2><%= pluralize(week.errors.count, "error") %> prohibited this admin_week from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% week.errors.full_messages.each do |message| %>
|
||||
<li><%= message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<%= error_messages(week) %>
|
||||
<% end %>
|
||||
<%= form.hidden_field :course_id %>
|
||||
<div class="form-row">
|
||||
<div class="form-group col-md-6">
|
||||
<%= form.label :name %>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<div class="card shadow mb-4">
|
||||
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
|
||||
<h6 class="m-0 font-weight-bold text-primary">Lista tygodni</h6>
|
||||
<%= link_to raw('<i class="fa fa-plus"></i> Dodaj Nowy Tydzien'), new_admin_week_path, { remote: true, class: 'btn btn-sm btn-primary float-right' } %>
|
||||
<%= link_to raw('<i class="fa fa-plus"></i> Dodaj Nowy Tydzien'), new_admin_week_path(course_id: @course.id), { remote: true, class: 'btn btn-sm btn-primary float-right' } %>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div id="ajax_form"></div>
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ pl:
|
|||
logout: 'Wyloguj'
|
||||
login: 'Zaloguj'
|
||||
add: 'Dodaj'
|
||||
back: 'Wróc'
|
||||
actions: 'Akcje'
|
||||
information: 'Informacja'
|
||||
empty_list: 'Nie znaleziono żadnych elementów do wyświetlenia.'
|
||||
|
|
|
|||
|
|
@ -16,3 +16,4 @@ pl:
|
|||
week:
|
||||
name: 'Nazwa'
|
||||
description: 'Opis'
|
||||
course: 'Kurs'
|
||||
|
|
|
|||
Loading…
Reference in New Issue