This commit is contained in:
Adrian Hinz 2019-05-15 12:20:44 +02:00
parent 25f09a3515
commit 6684552ceb
24 changed files with 187 additions and 33 deletions

View File

@ -13,7 +13,9 @@ module Admin
# GET /admin/courses/1 # GET /admin/courses/1
# GET /admin/courses/1.json # GET /admin/courses/1.json
def show; end def show
@weeks = @course.weeks
end
# GET /admin/courses/new # GET /admin/courses/new
def new def new
@ -76,7 +78,7 @@ module Admin
end end
def collection def collection
@courses = Course.by_name @courses = Course.name_asc
end end
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.

View File

@ -46,7 +46,7 @@ module SidemenuHelper
link_to(raw("#{icon_text}<span>#{I18n.t(text)}</span>"), link_to(raw("#{icon_text}<span>#{I18n.t(text)}</span>"),
link, class: "nav-link#{expand ? '' : ' collapsed'}", link, class: "nav-link#{expand ? '' : ' collapsed'}",
data: { toggle: 'collapse', target: "#collapse#{name}" }, data: { toggle: 'collapse', target: "#collapse#{name}" },
aria: { expanded: "#{expand}", controls: "collapse#{name}" }) aria: { expanded: expand.to_s, controls: "collapse#{name}" })
end end
end end
@ -61,13 +61,12 @@ module SidemenuHelper
def nav_link_submenu(a_name, submenu, for_active) def nav_link_submenu(a_name, submenu, for_active)
content_tag :li, class: 'nav-item' do content_tag :li, class: 'nav-item' do
expand = check_link_active(for_active) expand = check_link_active(for_active)
r = nav_link_to(a_name[0], a_name[1], '#', a_name[2], expand) concat nav_link_to(a_name[0], a_name[1], '#', a_name[2], expand)
r += content_tag(:div, inner_submenu(submenu), concat content_tag(:div, inner_submenu(submenu),
id: "collapse#{a_name[2]}", id: "collapse#{a_name[2]}",
class: "collapse#{expand ? ' show' : ''}", class: "collapse#{expand ? ' show' : ''}",
aria: { labelledby: "heading#{a_name[2]}" }, aria: { labelledby: "heading#{a_name[2]}" },
data: { parent: '#accordionSidebar' }) data: { parent: '#accordionSidebar' })
r
end end
end end
@ -78,12 +77,9 @@ module SidemenuHelper
# -> 'String' - to add header to menu # -> 'String' - to add header to menu
def inner_submenu(submenu) def inner_submenu(submenu)
content_tag :div, class: 'bg-white py-2 collapse-inner rounded' do content_tag :div, class: 'bg-white py-2 collapse-inner rounded' do
r = nil
submenu.each do |sub| submenu.each do |sub|
r += submenu_element(sub) unless r.nil? concat submenu_element(sub)
r = submenu_element(sub) if r.nil?
end end
r
end end
end end

View File

@ -0,0 +1,29 @@
# frozen_string_literal: true
# Helper for views
module ViewsHelper
def dropdown_link(name, menu_links)
content_tag(:div, class: 'dropdown no-arrow') do
concat link_for('#', name)
end
end
def link_for(href, text)
end
=begin
<div class="dropdown no-arrow">
<a class="dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400"></i>
</a>
<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink">
<div class="dropdown-header">Dropdown Header:</div>
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
=end
end

View File

@ -1,21 +1,25 @@
<table class="table table-bordered"> <% if @courses.blank? %>
<thead class="thead-dark"> <%= render partial: '/admin/shared/norecords' %>
<tr> <% else %>
<th>Nazwa</th> <table class="table table-bordered">
<th>Opis</th> <thead class="thead-dark">
<th class="fit">Akcje</th>
</tr>
</thead>
<tbody>
<% @courses.each do |course| %>
<tr> <tr>
<td><%= link_to course.name, [:admin, course] %></td> <th>Nazwa</th>
<td><%= course.description %></td> <th>Opis</th>
<td class="fit"> <th class="fit">Akcje</th>
<%= link_to raw('<i class="fa fa-pencil-alt"></i>'), edit_admin_course_path(course), { remote: true, class: 'btn btn-sm btn-info', title: t('edit') } %>
<%= link_to raw('<i class="fa fa-times"></i>'), [:admin, course], { remote: true, class: 'btn btn-sm btn-danger', method: :delete, data:{ confirm: t('confirm_delete') }, title: t('delete')} %>
</td>
</tr> </tr>
<% end %> </thead>
</tbody> <tbody>
</table> <% @courses.each do |course| %>
<tr>
<td><%= link_to course.name, [:admin, course] %></td>
<td><%= course.description %></td>
<td class="fit">
<%= link_to raw('<i class="fa fa-pencil-alt"></i>'), edit_admin_course_path(course), { remote: true, class: 'btn btn-sm btn-info', title: t('edit') } %>
<%= link_to raw('<i class="fa fa-times"></i>'), [:admin, course], { remote: true, class: 'btn btn-sm btn-danger', method: :delete, data:{ confirm: t('confirm_delete') }, title: t('delete')} %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

View File

@ -1,6 +1,6 @@
<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></h1>
<p class="mb-4"><%= @course.description %></p> <p class="mb-4"><%= @course.description %></p>
<!-- Weeks --> <!-- Weeks -->
<%= render partial: '/admin/weeks/partials/index' %>
<%= link_to 'Back', admin_courses_path %> <%= link_to 'Back', admin_courses_path %>

View File

@ -0,0 +1,4 @@
<div class="alert alert-primary" role="alert">
<h4 class="alert-heading"><i class="fas fa-info-circle"></i> Informacja</h4>
<p>Nie znaleziono żadnych elementów do wyświetlenia.</p>
</div>

View File

@ -0,0 +1,2 @@
$('#ajax_form').slideUp();
$('#ajax_list').html("<%= escape_javascript(render('/admin/weeks/partials/weeks')) %>");

View File

@ -0,0 +1 @@
$('#ajax_list').html("<%= escape_javascript(render('/admin/weeks/partials/weeks')) %>");

View File

@ -0,0 +1 @@
<%= render '/admin/weeks/partials/edit' %>

View File

@ -0,0 +1,2 @@
$("#ajax_form").html("<%= escape_javascript(render('admin/weeks/partials/edit')) %>");
$("#ajax_form").slideDown();

View File

@ -0,0 +1,4 @@
<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' %>

View File

@ -0,0 +1 @@
json.array! @weeks, partial: '/admin/weeks/partials/admin_week', as: :week

View File

@ -0,0 +1 @@
<%= render partial: '/admin/weeks/partials/form' %>

View File

@ -0,0 +1,2 @@
$("#ajax_form").html("<%= escape_javascript(render('admin/weeks/partials/new')) %>");
$("#ajax_form").slideDown();

View File

@ -0,0 +1,2 @@
json.extract! week, :id, :name, :description, :created_at, :updated_at
json.url admin_week_url(week, format: :json)

View File

@ -0,0 +1,13 @@
<div class="row">
<div class="col">
<!-- Basic Card Example -->
<div class="card shadow mb-4 border-primary">
<div class="card-header text-white bg-primary">
<h6>Edycja Tygodnia</h6>
</div>
<div class="card-body">
<%= render '/admin/weeks/partials/form', week: @week %>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,25 @@
<%= 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>
<% end %>
<div class="form-row">
<div class="form-group col-md-6">
<%= form.label :name %>
<%= form.text_field :name, class: 'form-control' %>
</div>
<div class="form-group col-md-6">
<%= form.label :description %>
<%= form.text_area :description, class: 'form-control' %>
</div>
</div>
<%= form.submit 'Zapisz', class: 'btn btn-primary' %>
<% end %>

View File

@ -0,0 +1,19 @@
<div class="row">
<div class="col">
<!-- Basic Card Example -->
<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' } %>
</div>
<div class="card-body">
<div id="ajax_form"></div>
<div id="ajax_list">
<%= render partial: '/admin/weeks/partials/weeks' %>
</div>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,13 @@
<div class="row">
<div class="col">
<!-- Basic Card Example -->
<div class="card shadow mb-4 border-primary">
<div class="card-header text-white bg-primary">
<h6>Nowy Tydzien</h6>
</div>
<div class="card-body">
<%= render '/admin/weeks/partials/form', week: @week %>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,25 @@
<% if @weeks.blank? %>
<%= render partial: '/admin/shared/norecords' %>
<% else %>
<table class="table table-bordered">
<thead class="thead-dark">
<tr>
<th>Nazwa</th>
<th>Opis</th>
<th class="fit">Akcje</th>
</tr>
</thead>
<tbody>
<% @weeks.each do |week| %>
<tr>
<td><%= link_to week.name, [:admin, week] %></td>
<td><%= week.description %></td>
<td class="fit">
<%= link_to raw('<i class="fa fa-pencil-alt"></i>'), edit_admin_week_path(week), { remote: true, class: 'btn btn-sm btn-info', title: t('edit') } %>
<%= link_to raw('<i class="fa fa-times"></i>'), [:admin, week], { remote: true, class: 'btn btn-sm btn-danger', method: :delete, data:{ confirm: t('confirm_delete') }, title: t('delete')} %>
</td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

View File

@ -0,0 +1,6 @@
<h1 class="h3 mb-1 text-gray-800">week: <strong><%= @week.name %></strong></h1>
<p class="mb-4"><%= @week.description %></p>
<!-- Weeks -->
<%= link_to 'Back', admin_weeks_path %>

View File

@ -0,0 +1 @@
json.partial! "/admin/weeks/partials/admin_week", week: @week

View File

@ -0,0 +1,2 @@
$('#ajax_form').slideUp();
$('#ajax_list').html("<%= escape_javascript(render('/admin/weeks/partials/weeks')) %>");

View File

@ -1,11 +1,10 @@
Rails.application.routes.draw do Rails.application.routes.draw do
namespace :admin do
resources :courses
end
get 'tests/index' get 'tests/index'
get 'tests/test' get 'tests/test'
namespace :admin do namespace :admin do
resources :users resources :users
resources :courses
resources :weeks
end end
devise_for :users devise_for :users
get 'home/index' get 'home/index'