Compare commits

..

No commits in common. "e87f7fb7312080ad5014ba78fb50209ae0115dfc" and "6dab6cb5b5be67398414b0367312c50e46d7af88" have entirely different histories.

40 changed files with 28 additions and 356 deletions

View File

@ -1,109 +0,0 @@
# frozen_string_literal: true
module Admin
# Lessons
class LessonsController < ApplicationController
before_action :set_object, only: %i[show edit update destroy]
# GET /admin/lessons
# GET /admin/lessons.json
def index
collection
end
# GET /admin/lessons/1
# GET /admin/lessons/1.json
def show; end
# GET /admin/lessons/new
def new
@lesson = Lesson.new(week_id: params[:week_id])
end
# GET /admin/lessons/1/edit
def edit; end
# POST /admin/lessons
# POST /admin/lessons.json
def create
@lesson = Lesson.new(admin_lesson_params)
@week = @lesson.week
@lesson.course = @week.course
@course = @week.course
params[:week_id] = @week.id
respond_to do |format|
if @lesson.save
format.js { collection }
format.html do
redirect_to [:admin, @lesson],
notice: 'Lesson was successfully created.'
end
format.json { render :show, status: :created, location: @lesson }
else
format.js { render :new }
format.html { render :new }
format.json do
render json: @lesson.errors, status: :unprocessable_entity
end
end
end
end
# PATCH/PUT /admin/lessons/1
# PATCH/PUT /admin/lessons/1.json
def update
respond_to do |format|
if @lesson.update(admin_lesson_params)
format.js { collection }
format.html do
redirect_to [:admin, @lesson],
notice: 'Lesson was successfully updated.'
end
format.json { render :show, status: :ok, location: @lesson }
else
format.js { render :edit }
format.html { render :edit }
format.json do
render json: @lesson.errors, status: :unprocessable_entity
end
end
end
end
# DELETE /admin/lessons/1
# DELETE /admin/lessons/1.json
def destroy
@lesson.destroy
respond_to do |format|
format.js { collection }
format.html do
redirect_to admin_lessons_url,
notice: 'Lesson was successfully destroyed.'
end
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_object
@lesson = Lesson.find(params[:id])
@week = @lesson.week
@course = @week.course
params[:week_id] = @week.id
end
def collection
@lessons = Lesson.by_week(params[:week_id]).page(params[:page])
@week = Week.find(params[:week_id])
end
# Never trust parameters from the scary internet,
# only allow the white list through.
def admin_lesson_params
params.require(:lesson).permit(:name, :description, :week_id, :video_id,
:informations)
end
end
end

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
module Admin
# Weeks
# Kursy
class WeeksController < ApplicationController
before_action :set_object, only: %i[show edit update destroy]
@ -13,9 +13,7 @@ module Admin
# GET /admin/weeks/1
# GET /admin/weeks/1.json
def show
@lessons = @week.lessons.page(params[:page])
end
def show; end
# GET /admin/weeks/new
def new
@ -29,22 +27,17 @@ module Admin
# POST /admin/weeks.json
def create
@week = Week.new(admin_week_params)
@course = @week.course
@course = @week.course# .find(@week.course_id)
params[:course_id] = @course.id
respond_to do |format|
if @week.save
format.js { collection }
format.html do
redirect_to [:admin, @week],
notice: 'Week was successfully created.'
end
format.html { redirect_to [:admin, @week], notice: 'Week was successfully created.' }
format.json { render :show, status: :created, location: @week }
else
format.js { render :new }
format.html { render :new }
format.json do
render json: @week.errors, status: :unprocessable_entity
end
format.json { render json: @week.errors, status: :unprocessable_entity }
end
end
end
@ -55,17 +48,12 @@ module Admin
respond_to do |format|
if @week.update(admin_week_params)
format.js { collection }
format.html do
redirect_to [:admin, @week],
notice: 'Week was successfully updated.'
end
format.html { redirect_to [:admin, @week], notice: 'Week was successfully updated.' }
format.json { render :show, status: :ok, location: @week }
else
format.js { render :edit }
format.html { render :edit }
format.json do
render json: @week.errors, status: :unprocessable_entity
end
format.json { render json: @week.errors, status: :unprocessable_entity }
end
end
end
@ -76,10 +64,7 @@ module Admin
@week.destroy
respond_to do |format|
format.js { collection }
format.html do
redirect_to admin_weeks_url,
notice: 'Week was successfully destroyed.'
end
format.html { redirect_to admin_weeks_url, notice: 'Week was successfully destroyed.' }
format.json { head :no_content }
end
end
@ -98,8 +83,7 @@ module Admin
@course = Course.find(params[:course_id])
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.
def admin_week_params
params.require(:week).permit(:name, :description, :course_id)
end

View File

@ -1,8 +1,2 @@
# frozen_string_literal: true
# Admin
module Admin
# CoursesHelper
module CoursesHelper
end
module Admin::CoursesHelper
end

View File

@ -1,8 +0,0 @@
# frozen_string_literal: true
# Admin
module Admin
# LesonsHelper
module LessonsHelper
end
end

View File

@ -1,8 +1,2 @@
# frozen_string_literal: true
# Admin
module Admin
# UsersHelper
module UsersHelper
end
module Admin::UsersHelper
end

View File

@ -1,8 +0,0 @@
# frozen_string_literal: true
# Admin
module Admin
# WeeksHelper
module WeeksHelper
end
end

View File

@ -1,8 +1,2 @@
# frozen_string_literal: true
# Main ApplicationHelper
module ApplicationHelper
def admin?
current_user.radmin?
end
end

View File

@ -23,8 +23,12 @@ class Lesson < ApplicationRecord
scope :name_desc, -> { order(name: :desc) }
# == Callbacks ============================================================
before_create :b_create
# == Class Methods ========================================================
# == Instance Methods =====================================================
def b_create
self.course = week.course
end
end

View File

@ -5,7 +5,7 @@ class User < ApplicationRecord
# == Constants ============================================================
# == Attributes ===========================================================
enum role: %i[ruser radmin]
# == Extensions ===========================================================
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable,

View File

@ -2,22 +2,5 @@
# Class for video links
class Video < ApplicationRecord
# == Constants ============================================================
# == Attributes ===========================================================
# == Extensions ===========================================================
# == Relationships ========================================================
belongs_to :video_account, optional: true
# == Validations ==========================================================
# == Scopes ===============================================================
# == Callbacks ============================================================
# == Class Methods ========================================================
# == Instance Methods =====================================================
belongs_to :video_account
end

View File

@ -10,7 +10,6 @@ class Week < ApplicationRecord
# == Relationships ========================================================
belongs_to :course
has_many :lessons
# == Validations ==========================================================
validates :name, presence: true

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,2 +0,0 @@
json.array! @lessons, partial: '/admin/lessons/partials/admin_lesson',
as: :lesson

View File

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

View File

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

View File

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

View File

@ -1,13 +0,0 @@
<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><%= t('lesson.edit') %></h6>
</div>
<div class="card-body">
<%= render '/admin/lessons/partials/form', lesson: @lesson %>
</div>
</div>
</div>
</div>

View File

@ -1,29 +0,0 @@
<%= form_with(model: [:admin, lesson]) do |form| %>
<% if lesson.errors.any? %>
<%= error_messages(lesson) %>
<% end %>
<%= form.hidden_field :week_id %>
<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>
<div class="form-row">
<div class="form-group col-md-6">
<%= form.label :video %>
<%= form.select :video_id, options_for_select(Video.all.map{|s|[s.name, s.id]}, selected: @lesson.video_id), { include_blank: true }, { class: 'form-control' } %>
</div>
<div class="form-group col-md-6">
<%= form.label :informations %>
<%= form.text_area :informations, class: 'form-control' %>
</div>
</div>
<%= form.submit t('save'), class: 'btn btn-primary' %>
<% end %>

View File

@ -1,19 +0,0 @@
<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"><%= t('lesson.list') %></h6>
<%= link_to raw("<i class=\"fa fa-plus\"></i> #{t('lesson.add_new')}"), new_admin_lesson_path(week_id: @week.id), { 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/lessons/partials/lessons' %>
</div>
</div>
</div>
</div>
</div>

View File

@ -1,26 +0,0 @@
<% if @lessons.blank? %>
<%= render partial: '/admin/shared/norecords' %>
<% else %>
<table class="table table-bordered">
<thead class="thead-dark">
<tr>
<th><%= t('lesson.table.name') %></th>
<th><%= t('lesson.table.description') %></th>
<th class="fit"><%= t('actions') %></th>
</tr>
</thead>
<tbody>
<% @lessons.each do |lesson| %>
<tr>
<td><%= link_to lesson.name, [:admin, lesson] %></td>
<td><%= lesson.description %></td>
<td class="fit">
<%= link_to raw('<i class="fa fa-pencil-alt"></i>'), edit_admin_lesson_path(lesson), { remote: true, class: 'btn btn-sm btn-info', title: t('edit') } %>
<%= link_to raw('<i class="fa fa-times"></i>'), [:admin, lesson], { remote: true, class: 'btn btn-sm btn-danger', method: :delete, data:{ confirm: t('confirm_delete') }, title: t('delete')} %>
</td>
</tr>
<% end %>
</tbody>
</table>
<%= paginate @lessons, params: { controller: 'admin/lessons', action: :index , week_id: @week.id}, remote: true, theme: 'twitter-bootstrap-4', pagination_class: 'justify-content-center' %>
<% end %>

View File

@ -1,13 +0,0 @@
<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><%= t('lesson.new') %></h6>
</div>
<div class="card-body">
<%= render '/admin/lessons/partials/form', lesson: @lesson %>
</div>
</div>
</div>
</div>

View File

@ -1,4 +0,0 @@
<h1 class="h3 mb-1 text-gray-800"><%= t('course.title_show') %>: <strong><%= @week.course.name %></strong></h1>
<h1 class="h3 mb-1 text-gray-800"><%= t('week.title_show') %>: <strong><%= @week.name %></strong></h1>
<h1 class="h3 mb-1 text-gray-800"><%= t('lesson.title_show') %>: <strong><%= @lesson.name %></strong> (<%= link_to raw(t('back')), admin_week_path(@week) %>)</h1>
<p class="mb-4"><%= @lesson.description %></p>

View File

@ -1 +0,0 @@
json.partial! "/admin/lessons/partials/admin_lesson", lesson: @lesson

View File

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

View File

@ -3,7 +3,7 @@
<!-- Basic Card Example -->
<div class="card shadow mb-4 border-primary">
<div class="card-header text-white bg-primary">
<h6><%= t('week.edit') %></h6>
<h6>Edycja Tygodnia</h6>
</div>
<div class="card-body">
<%= render '/admin/weeks/partials/form', week: @week %>

View File

@ -1,6 +1,6 @@
<%= form_with(model: [:admin, week]) do |form| %>
<% if week.errors.any? %>
<%= error_messages(week) %>
<%= error_messages(week) %>
<% end %>
<%= form.hidden_field :course_id %>
<div class="form-row">

View File

@ -3,7 +3,7 @@
<!-- 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"><%= t('week.list') %></h6>
<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(course_id: @course.id), { remote: true, class: 'btn btn-sm btn-primary float-right' } %>
</div>
<div class="card-body">

View File

@ -3,7 +3,7 @@
<!-- Basic Card Example -->
<div class="card shadow mb-4 border-primary">
<div class="card-header text-white bg-primary">
<h6><%= t('week.new') %></h6>
<h6>Nowy Tydzien</h6>
</div>
<div class="card-body">
<%= render '/admin/weeks/partials/form', week: @week %>

View File

@ -4,9 +4,9 @@
<table class="table table-bordered">
<thead class="thead-dark">
<tr>
<th><%= t('week.table.name') %></th>
<th><%= t('week.table.description') %></th>
<th class="fit"><%= t('actions') %></th>
<th>Nazwa</th>
<th>Opis</th>
<th class="fit">Akcje</th>
</tr>
</thead>
<tbody>

View File

@ -1,4 +1,3 @@
<h1 class="h3 mb-1 text-gray-800"><%= t('course.title_show') %>: <strong><%= @course.name %></strong></h1>
<h1 class="h3 mb-1 text-gray-800"><%= t('week.title_show') %>: <strong><%= @week.name %></strong> (<%= link_to raw(t('back')), admin_course_path(@course) %>)</h1>
<p class="mb-4"><%= @week.description %></p>
<%= render partial: '/admin/lessons/partials/index' %>

View File

@ -36,9 +36,9 @@ Rails.application.configure do
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'akademiatechnologii.pl',
user_name: 'akademiatechnologii.pl@gmail.com',
password: '123456%$#@!Adi',
domain: 'akadeniatechnologii.pl',
user_name: 'akadeniatechnologii@gmail.com',
password: '12345%$#@!Adi',
authentication: 'plain',
enable_starttls_auto: true
}

View File

@ -1,25 +0,0 @@
pl:
lesson:
title: 'Lekcje'
title_show: 'Lekcja'
title_desc: 'Tworzenie lekcji dla tygodnia'
list: 'Lista lekcji'
add_one: 'Dodaj pojedynczo'
add_many: 'Dodaj wiele'
add_new: 'Dodaj nową lekcję'
edit: 'Edycja lekcji'
new: 'Nowa lekcja'
table:
name: 'Nazwa'
description: 'Opis'
files: 'Załączniki'
activerecord:
attributes:
lesson:
name: 'Nazwa'
description: 'Opis'
course: 'Kurs'
video: Plik Wideo
week: 'Tydzień'
informations: 'Dodatkowe Informacje'
file: 'Plik'

View File

@ -5,7 +5,6 @@ Rails.application.routes.draw do
resources :users
resources :courses
resources :weeks
resources :lessons
end
devise_for :users
get 'home/index'

View File

@ -1,5 +0,0 @@
class AddRoleToUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :role, :integer, default: 0
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_12_10_124145) do
ActiveRecord::Schema.define(version: 2019_05_02_114629) do
create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name", null: false
@ -129,7 +129,6 @@ ActiveRecord::Schema.define(version: 2019_12_10_124145) do
t.datetime "locked_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "role", default: 0
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true