diff --git a/Gemfile b/Gemfile index 3d89962..0a27c86 100644 --- a/Gemfile +++ b/Gemfile @@ -38,6 +38,7 @@ gem 'jbuilder', '~> 2.5' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +gem 'will_paginate', '~> 3.1.0' #Devise {autorisation} gem 'devise' diff --git a/Gemfile.lock b/Gemfile.lock index 2f12bc5..0cfdba0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -171,6 +171,7 @@ GEM websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) + will_paginate (3.1.5) PLATFORMS ruby @@ -195,6 +196,7 @@ DEPENDENCIES tzinfo-data uglifier (>= 1.3.0) web-console (>= 3.3.0) + will_paginate (~> 3.1.0) BUNDLED WITH 1.14.6 diff --git a/app/assets/javascripts/auth.coffee b/app/assets/javascripts/auth.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/auth.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/javascripts/zhanr.coffee b/app/assets/javascripts/zhanr.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/app/assets/javascripts/zhanr.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/auth.scss b/app/assets/stylesheets/auth.scss new file mode 100644 index 0000000..f1fe4c6 --- /dev/null +++ b/app/assets/stylesheets/auth.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Auth controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/zhanr.scss b/app/assets/stylesheets/zhanr.scss new file mode 100644 index 0000000..a26475e --- /dev/null +++ b/app/assets/stylesheets/zhanr.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Zhanr controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/auth_controller.rb b/app/controllers/auth_controller.rb new file mode 100644 index 0000000..037dafd --- /dev/null +++ b/app/controllers/auth_controller.rb @@ -0,0 +1,77 @@ +class AuthController < ApplicationController +before_action :set_auth, only: [:show, :edit, :update, :destroy] + + # GET /books + # GET /books.json + def index + @auths = Auth.all + end + + + + # GET /books/1 + # GET /books/1.json + def show + + end + + # GET /books/new + def new + @auth = Auth.new + end + + # GET /books/1/edit + def edit + end + + # POST /books + # POST /books.json + def create + @auth = Auth.new(book_params) + + respond_to do |format| + if @auth.save + format.html { redirect_to @auth, notice: 'Автор успішно доданий' } + format.json { render :show, status: :created, location: @auth } + else + format.html { render :new } + format.json { render json: @auth.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /books/1 + # PATCH/PUT /books/1.json + def update + respond_to do |format| + if @book.update(book_params) + format.html { redirect_to @auth, notice: 'Автор успішно змінений' } + format.json { render :show, status: :ok, location: @auth } + else + format.html { render :edit } + format.json { render json: @auth.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /books/1 + # DELETE /books/1.json + def destroy + @book.destroy + respond_to do |format| + format.html { redirect_to auths_url, notice: 'Книга успішно видалена' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_book + @book = Auth.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def book_params + params.require(:auth).permit(:auth, :book) + end +end diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 7fc78cf..fe33d72 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -9,8 +9,11 @@ def index else @books = Book.all end + end + + # GET /books/1 # GET /books/1.json def show diff --git a/app/controllers/zhanr_controller.rb b/app/controllers/zhanr_controller.rb new file mode 100644 index 0000000..d3d026c --- /dev/null +++ b/app/controllers/zhanr_controller.rb @@ -0,0 +1,2 @@ +class ZhanrController < ApplicationController +end diff --git a/app/helpers/auth_helper.rb b/app/helpers/auth_helper.rb new file mode 100644 index 0000000..31afc3a --- /dev/null +++ b/app/helpers/auth_helper.rb @@ -0,0 +1,2 @@ +module AuthHelper +end diff --git a/app/helpers/zhanr_helper.rb b/app/helpers/zhanr_helper.rb new file mode 100644 index 0000000..0ab8be9 --- /dev/null +++ b/app/helpers/zhanr_helper.rb @@ -0,0 +1,2 @@ +module ZhanrHelper +end diff --git a/app/models/auth.rb b/app/models/auth.rb new file mode 100644 index 0000000..6d17857 --- /dev/null +++ b/app/models/auth.rb @@ -0,0 +1,3 @@ +class Auth < ApplicationRecord + validates :auth, :book, :presence => true +end diff --git a/app/models/zhanr.rb b/app/models/zhanr.rb new file mode 100644 index 0000000..dfe1087 --- /dev/null +++ b/app/models/zhanr.rb @@ -0,0 +1,2 @@ +class Zhanr < ApplicationRecord +end diff --git a/app/views/auth/_auth.json.jbuilder b/app/views/auth/_auth.json.jbuilder new file mode 100644 index 0000000..5238e80 --- /dev/null +++ b/app/views/auth/_auth.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! book, :id, :auth, :book +json.url book_url(book, format: :json) diff --git a/app/views/auth/_form.html.erb b/app/views/auth/_form.html.erb new file mode 100644 index 0000000..ae5c15a --- /dev/null +++ b/app/views/auth/_form.html.erb @@ -0,0 +1,48 @@ +<% if session[:lang] == "ua" + text ={ + :auth => "Назва", + :book => "Автор", + :submit => "Підтвердити" + } + elsif session[:lang] == "en" + text ={ + :auth => "Name", + :book => "Author", + :submit => "Submit" + } + elsif session[:lang] == "ru" + text ={ + :auth => "Название", + :book => "Автор", + :submit => "Подтвердить" + } + end +%> +
+ <%= form_for(auth) do |f| %> + <% if auth.errors.any? %> +
+

<%= pluralize(auth.errors.count, "error") %> prohibited this auth from being saved:

+ + +
+ <% end %> + +
+ + <%= f.text_field :auth, :class => "form-control" %> +
+ +
+ + <%= f.text_field :book, :class => "form-control" %> +
+
+ > +
+ <% end %> +
\ No newline at end of file diff --git a/app/views/auth/edit.html.erb b/app/views/auth/edit.html.erb new file mode 100644 index 0000000..9721745 --- /dev/null +++ b/app/views/auth/edit.html.erb @@ -0,0 +1,28 @@ +<% if session[:lang] == "ua" + text ={ + :h1 => "Редагування книги", + :show => "Показати", + :back => "Назад" + } + elsif session[:lang] == "en" + text ={ + :h1 => "Editing a book", + :show => "Show", + :back => "Back" + } + elsif session[:lang] == "ru" + text ={ + :h1 => "Редактирования книги", + :show => "Показать", + :back => "Назад" + } + end +%> +
+

<%= text[:h1] %>

+ + <%= render 'form', book: @book %> + + <%= link_to text[:show], @book %> | + <%= link_to text[:back], books_path %> +
\ No newline at end of file diff --git a/app/views/auth/index.html.erb b/app/views/auth/index.html.erb new file mode 100644 index 0000000..9299935 --- /dev/null +++ b/app/views/auth/index.html.erb @@ -0,0 +1,77 @@ +<% if session[:lang] == "ua" + text ={ + :label_T => "Назва", + :label_A => "Автор", + :label_Z => "Жанр", + :label_Q => "Кількість сторінок", + :label_D => "Опис", + :label_I => "Адреса до картинки", + :h1 => "Книги", + :show => "Показати", + :edit => "Редагувати", + :delete => "Видалити", + :question => "Ви впевнені?", + :new => "Додати нову книгу", + :back => "Назад" + } + elsif session[:lang] == "en" + text ={ + :label_T => "Name", + :label_A => "Author", + :label_Z => "Genre", + :label_Q => "Number of pages", + :label_D => "Description", + :label_I => "Address to the picture", + :h1 => "Books", + :show => "Show", + :edit => "Edit", + :delete => "Remove", + :question => "Are you sure?", + :new => "Add new book", + :back => "Back" + } + elsif session[:lang] == "ru" + text ={ + :label_T => "Название", + :label_A => "Автор", + :label_Z => "Жанр", + :label_Q => "Количество страниц", + :label_D => "Описание", + :label_I => "Адрес к картинке", + :h1 => "Книги", + :show => "Показать", + :edit => "Редактировать", + :delete => "Удалить", + :question => "Вы уверены?", + :new => "Добавить новую книгу", + :back => "Назад" + } + end +%> + +

<%= notice %>

+ +

<%= text[:h1] %>

+
+
+ <% @books.each do |book| %> +
+
+
+

<%= link_to book.title, book, :class => "product" %>

+

<%= book.auth %>

+
+ + +
+

+ <%= book.mini_description %>
+ <%= link_to 'Видалити', book, method: :delete, data: { confirm: 'Ви впевнені?' } %> +

+
+
+
+ <% end %> +
+
+ \ No newline at end of file diff --git a/app/views/auth/index.json.jbuilder b/app/views/auth/index.json.jbuilder new file mode 100644 index 0000000..7ee9cfe --- /dev/null +++ b/app/views/auth/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @books, partial: 'books/book', as: :book diff --git a/app/views/auth/new.html.erb b/app/views/auth/new.html.erb new file mode 100644 index 0000000..fcac47d --- /dev/null +++ b/app/views/auth/new.html.erb @@ -0,0 +1,24 @@ +<% if session[:lang] == "ua" + text ={ + :h1 => "Додати нову книгу", + :back => "Назад" + } + elsif session[:lang] == "en" + text ={ + :h1 => "Add new book", + :back => "Back" + } + elsif session[:lang] == "ru" + text ={ + :h1 => "Добавить новую книгу", + :back => "Назад" + } + end +%> +
+

<%= text[:h1] %>

+ + <%= render 'form', auth: @auth %> + + <%= link_to text[:back], auths_path %> +
\ No newline at end of file diff --git a/app/views/auth/show.html.erb b/app/views/auth/show.html.erb new file mode 100644 index 0000000..db92848 --- /dev/null +++ b/app/views/auth/show.html.erb @@ -0,0 +1,72 @@ +<% if session[:lang] == "ua" + text ={ + :label_T => "Назва", + :label_A => "Автор", + :label_Z => "Жанр", + :label_Q => "Кількість сторінок", + :label_D => "Опис", + :label_I => "Адреса до картинки", + :edit => "Редагувати", + :back => "Назад" + } + elsif session[:lang] == "en" + text ={ + :label_T => "Name", + :label_A => "Author", + :label_Z => "Genre", + :label_Q => "Number of pages", + :label_D => "Description", + :label_I => "Address to the picture", + :edit => "Edit", + :back => "Back" + } + elsif session[:lang] == "ru" + text ={ + :label_T => "Название", + :label_A => "Автор", + :label_Z => "Жанр", + :label_Q => "Количество страниц", + :label_D => "Описание", + :label_I => "Адрес к картинке", + :edit => "Редактировать", + :back => "Назад" + } + end +%> +
+

<%= notice %>

+
+

+ <%= @book.title %> +

+ +

+ <%= @book.auth %> +

+
+
+

+ <%= text[:label_Z] %> + <%= @book.zhanr %> +

+ +

+ <%= text[:label_Q] %> + <%= @book.pages_qty %> +

+ +

+ <%= text[:label_D] %> + <%= @book.description %> +

+ +

+ <%= text[:label_I] %> + <%= @book.image_url %> +

+
+
+ <%= link_to text[:edit], edit_book_path(@book) %> | + <%= link_to text[:back], books_path %> +
+
diff --git a/app/views/auth/show.json.jbuilder b/app/views/auth/show.json.jbuilder new file mode 100644 index 0000000..c1e5174 --- /dev/null +++ b/app/views/auth/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "books/book", book: @book diff --git a/app/views/books/index.html.erb b/app/views/books/index.html.erb index ad52fc9..9299935 100644 --- a/app/views/books/index.html.erb +++ b/app/views/books/index.html.erb @@ -48,6 +48,7 @@ } end %> +

<%= notice %>

<%= text[:h1] %>

@@ -73,3 +74,4 @@ <% end %> + \ No newline at end of file diff --git a/app/views/books/show.html.erb b/app/views/books/show.html.erb index 3ad4cfe..db92848 100644 --- a/app/views/books/show.html.erb +++ b/app/views/books/show.html.erb @@ -69,4 +69,4 @@ <%= link_to text[:edit], edit_book_path(@book) %> | <%= link_to text[:back], books_path %> - \ No newline at end of file + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 954b7fe..03448fa 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -72,6 +72,7 @@
  • <%= link_to text[:registration], sign_up_path %>
  • <%= link_to text[:autorisation], sign_in_path %>
  • <%= link_to text[:exit], sign_out_path %>
  • +