diff --git a/.gitignore b/.gitignore index 18b43c9..3963d4f 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,8 @@ # Ignore master key for decrypting credentials and more. /config/master.key + +/config/database.yml +/.idea +/log/* +/tmp/* diff --git a/.idea/.generators b/.idea/.generators deleted file mode 100644 index 1618976..0000000 --- a/.idea/.generators +++ /dev/null @@ -1,8 +0,0 @@ - - diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks deleted file mode 100644 index c6865d9..0000000 --- a/.idea/.rakeTasks +++ /dev/null @@ -1,7 +0,0 @@ - - diff --git a/.idea/garages.iml b/.idea/garages.iml deleted file mode 100644 index c26a132..0000000 --- a/.idea/garages.iml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index b0db9b0..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index ebba9e7..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 3971afe..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..ff312ca --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,34 @@ +AllCops: + TargetRubyVersion: 2.5.1 + Exclude: + - bundle/* + - bin/* + - vendor/* + - node_modules/* + - public/* + - db/* + - lib/* + - config/unicorn.rb + +Style/FrozenStringLiteralComment: + Exclude: + - db/migrate/*.rb + - config/**/* + - script/** + +Layout/DefEndAlignment: + AutoCorrect: true + +Documentation: + Enabled: false + +Metrics/LineLength: + Max: 100 + Exclude: + - config/initializers/** + - config/environments/** + - config/schedule.rb + +Style/ClassAndModuleChildren: + Enabled: false + diff --git a/Gemfile b/Gemfile index e10c878..17d31e2 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } @@ -18,8 +20,6 @@ gem 'uglifier', '>= 1.3.0' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.2' -# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks -gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.5' # Use Redis adapter to run Action Cable in production @@ -36,20 +36,49 @@ gem 'jbuilder', '~> 2.5' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.1.0', require: false +# Slim templates generator for Rails 3, 4 and 5 +gem 'slim-rails' + +# The AdminLTE Rails gem integrates AdminLTE theme with the Rails asset pipeline +gem 'adminlte2-rails' + +# A gem to automate using jQuery with Rails +gem 'bootstrap', '~> 4.3.1' +gem 'jquery-rails' +gem 'jquery-slimscroll-rails' +gem 'jquery-ui-rails' + +# The EmailAddress Gem to work with and validate email addresses. +gem 'validates_email_format_of' + +# A Scope & Engine based, clean, powerful, customizable and sophisticated paginator for Ruby webapps +gem 'kaminari' + +# Validates whether the specified value is a valid email address. +# Returns nil if the value is valid,otherwise returns an array +gem 'email_format' + +# Russian language support for Ruby and Rails, using I18n library. +gem 'russian', '~> 0.6.0' + +# Framework for handling and responding to web requests. +# It provides mechanisms for routing, defining controllers that implement actions, +# and generating responses by rendering views , which are templates of various formats. +gem 'actionpack', '~> 5.0', '>= 5.0.0.1' + group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console - gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + gem 'byebug', platforms: %i[mri mingw x64_mingw] end group :development do # Access an interactive console on exception pages or by calling 'console' anywhere in the code. - gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' + gem 'web-console', '>= 3.3.0' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end - # Windows does not include zoneinfo files, so bundle the tzinfo-data gem -gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] +gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] diff --git a/Gemfile.lock b/Gemfile.lock index d23a41c..9827054 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,15 +2,16 @@ GEM remote: https://rubygems.org/ specs: actioncable (5.2.3) - actionpack (= 5.2.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) actionmailer (5.2.3) - actionpack (= 5.2.3) - actionview (= 5.2.3) activejob (= 5.2.3) + activesupport (= 5.2.3) mail (~> 2.5, >= 2.5.4) + rack (~> 2.0) + rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) + rails-html-sanitizer (~> 1.0, >= 1.0.2) actionpack (5.2.3) actionview (= 5.2.3) activesupport (= 5.2.3) @@ -34,7 +35,6 @@ GEM activesupport (= 5.2.3) arel (>= 9.0) activestorage (5.2.3) - actionpack (= 5.2.3) activerecord (= 5.2.3) marcel (~> 0.3.1) activesupport (5.2.3) @@ -42,10 +42,22 @@ GEM i18n (>= 0.7, < 2) minitest (~> 5.1) tzinfo (~> 1.1) + adminlte2-rails (0.0.6) + bootstrap-sass (~> 3.3.4.1) arel (9.0.0) + autoprefixer-rails (9.6.1) + execjs + bcrypt (3.1.13) bindex (0.8.1) bootsnap (1.4.4) msgpack (~> 1.0) + bootstrap (4.3.1) + autoprefixer-rails (>= 9.1.0) + popper_js (>= 1.14.3, < 2) + sassc-rails (>= 2.0.0) + bootstrap-sass (3.3.4.1) + autoprefixer-rails (>= 5.0.0.1) + sass (>= 3.2.19) builder (3.2.3) byebug (11.0.1) coffee-rails (4.2.2) @@ -57,6 +69,15 @@ GEM coffee-script-source (1.12.2) concurrent-ruby (1.1.5) crass (1.0.4) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0, < 6.0) + responders + warden (~> 1.2.3) + email_format (1.0.0) + activemodel + email_regex + email_regex (0.0.1) erubi (1.8.0) execjs (2.7.0) ffi (1.11.1) @@ -66,6 +87,25 @@ GEM concurrent-ruby (~> 1.0) jbuilder (2.9.1) activesupport (>= 4.2.0) + jquery-rails (4.3.5) + rails-dom-testing (>= 1, < 3) + railties (>= 4.2.0) + thor (>= 0.14, < 2.0) + jquery-slimscroll-rails (1.0.9) + jquery-ui-rails (6.0.1) + railties (>= 3.2.16) + kaminari (1.1.1) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.1.1) + kaminari-activerecord (= 1.1.1) + kaminari-core (= 1.1.1) + kaminari-actionview (1.1.1) + actionview + kaminari-core (= 1.1.1) + kaminari-activerecord (1.1.1) + activerecord + kaminari-core (= 1.1.1) + kaminari-core (1.1.1) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -86,7 +126,9 @@ GEM nio4r (2.4.0) nokogiri (1.10.3) mini_portile2 (~> 2.4.0) + orm_adapter (0.5.0) pg (1.1.4) + popper_js (1.14.5) puma (3.12.1) rack (2.0.7) rack-test (1.1.0) @@ -94,7 +136,6 @@ GEM rails (5.2.3) actioncable (= 5.2.3) actionmailer (= 5.2.3) - actionpack (= 5.2.3) actionview (= 5.2.3) activejob (= 5.2.3) activemodel (= 5.2.3) @@ -110,7 +151,6 @@ GEM rails-html-sanitizer (1.0.4) loofah (~> 2.2, >= 2.2.2) railties (5.2.3) - actionpack (= 5.2.3) activesupport (= 5.2.3) method_source rake (>= 0.8.7) @@ -119,7 +159,11 @@ GEM rb-fsevent (0.10.3) rb-inotify (0.10.0) ffi (~> 1.0) + responders (2.4.1) + railties (>= 4.2.0, < 6.0) ruby_dep (1.5.0) + russian (0.6.0) + i18n (>= 0.5.0) sass (3.7.4) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -131,6 +175,21 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + sassc (2.0.1) + ffi (~> 1.9) + rake + sassc-rails (2.1.2) + railties (>= 4.0.0) + sassc (>= 2.0) + sprockets (> 3.0) + sprockets-rails + tilt + slim (4.0.1) + temple (>= 0.7.6, < 0.9) + tilt (>= 2.0.6, < 2.1) + slim-rails (3.2.0) + railties (>= 3.1) + slim (>= 3.0, < 5.0) spring (2.0.2) activesupport (>= 4.2) spring-watcher-listen (2.0.1) @@ -140,21 +199,22 @@ GEM concurrent-ruby (~> 1.0) rack (> 1, < 3) sprockets-rails (3.2.1) - actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + temple (0.8.1) thor (0.20.3) thread_safe (0.3.6) tilt (2.0.9) - turbolinks (5.2.0) - turbolinks-source (~> 5.2) - turbolinks-source (5.2.0) tzinfo (1.2.5) thread_safe (~> 0.1) uglifier (4.1.20) execjs (>= 0.3.0, < 3) + validates_email_format_of (1.6.3) + i18n + warden (1.2.8) + rack (>= 2.0.6) web-console (3.7.0) - actionview (>= 5.0) + actionview (~> 5.0) activemodel (>= 5.0) bindex (>= 0.4.0) railties (>= 5.0) @@ -166,20 +226,30 @@ PLATFORMS ruby DEPENDENCIES + actionpack (~> 5.0, >= 5.0.0.1) + adminlte2-rails bootsnap (>= 1.1.0) + bootstrap (~> 4.3.1) byebug coffee-rails (~> 4.2) + email_format jbuilder (~> 2.5) + jquery-rails + jquery-slimscroll-rails + jquery-ui-rails + kaminari listen (>= 3.0.5, < 3.2) pg (>= 0.18, < 2.0) puma (~> 3.11) rails (~> 5.2.3) + russian (~> 0.6.0) sass-rails (~> 5.0) + slim-rails spring spring-watcher-listen (~> 2.0.0) - turbolinks (~> 5) tzinfo-data uglifier (>= 1.3.0) + validates_email_format_of web-console (>= 3.3.0) RUBY VERSION diff --git a/Rakefile b/Rakefile index e85f913..488c551 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. diff --git a/app/assets/javascripts/admin.js b/app/assets/javascripts/admin.js new file mode 100644 index 0000000..27df5d9 --- /dev/null +++ b/app/assets/javascripts/admin.js @@ -0,0 +1,3 @@ +//= require application +//= require jquery.slimscroll.min +//= require_tree ./admin diff --git a/log/.keep b/app/assets/javascripts/admin/base.js similarity index 100% rename from log/.keep rename to app/assets/javascripts/admin/base.js diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 82e6f0f..6f39966 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,7 +10,10 @@ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // -//= require rails-ujs //= require activestorage -//= require turbolinks -//= require_tree . +//= require cable +//= require jquery +//= require jquery-ui +//= require jquery_ujs +//= require bootstrap-sprockets +//= require app diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss new file mode 100644 index 0000000..17cce7c --- /dev/null +++ b/app/assets/stylesheets/admin.scss @@ -0,0 +1,20 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's + * vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS + * files in this directory. Styles in this file should be added after the last require_* statement. + * It is generally better to create a new file per style scope. + * + *= require application + *= require_tree ./admin + */ + +@import "bootstrap-sprockets"; +@import "bootstrap"; +@import "AdminLTE/AdminLTE"; +@import "AdminLTE/skins/skin-blue"; diff --git a/tmp/.keep b/app/assets/stylesheets/admin/base.css similarity index 100% rename from tmp/.keep rename to app/assets/stylesheets/admin/base.css diff --git a/app/assets/stylesheets/admin_users.sass b/app/assets/stylesheets/admin_users.sass new file mode 100644 index 0000000..c6011ee --- /dev/null +++ b/app/assets/stylesheets/admin_users.sass @@ -0,0 +1,8 @@ +article.user + margin-bottom: 1em + padding: 1em 0 + border-bottom: 1px solid lightblue +h2 + margin-bottom: 0 + section.user-menu + padding: .5em 0 diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.scss similarity index 94% rename from app/assets/stylesheets/application.css rename to app/assets/stylesheets/application.scss index d05ea0f..fa1f050 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.scss @@ -10,6 +10,7 @@ * files in this directory. Styles in this file should be added after the last require_* statement. * It is generally better to create a new file per style scope. * - *= require_tree . + *= require jquery-ui *= require_self */ +@import "bootstrap"; diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index d672697..9aec230 100644 --- a/app/channels/application_cable/channel.rb +++ b/app/channels/application_cable/channel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Channel < ActionCable::Channel::Base end diff --git a/app/channels/application_cable/connection.rb b/app/channels/application_cable/connection.rb index 0ff5442..8d6c2a1 100644 --- a/app/channels/application_cable/connection.rb +++ b/app/channels/application_cable/connection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module ApplicationCable class Connection < ActionCable::Connection::Base end diff --git a/app/controllers/admin/base_controller.rb b/app/controllers/admin/base_controller.rb new file mode 100644 index 0000000..3a71646 --- /dev/null +++ b/app/controllers/admin/base_controller.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Admin::BaseController < ApplicationController + layout 'admin_lte_2' +end diff --git a/app/controllers/admin/main_controller.rb b/app/controllers/admin/main_controller.rb new file mode 100644 index 0000000..ff4ac67 --- /dev/null +++ b/app/controllers/admin/main_controller.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class Admin::MainController < Admin::BaseController + def show; end +end diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb new file mode 100644 index 0000000..378c9f5 --- /dev/null +++ b/app/controllers/admin/users_controller.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +class Admin::UsersController < Admin::BaseController + before_action :set_user, only: %i[show edit update destroy] + + def index + @users = User.order(:name).page(params[:page]).per(6) + end + + def show; end + + def new + @user = User.new + end + + def edit; end + + def create + @user = User.new(user_params) + if @user.save + redirect_to admin_users_path + else + render :new + end + end + + def update + @user = User.find(params[:id]) + if @user.update(user_params) + redirect_to admin_users_path + else + render :index + end + end + + def destroy + @user.destroy + redirect_to admin_users_path + end + + private + + def set_user + @user = User.find(params[:id]) + end + + def user_params + params.require(:user).permit(:name, :email) + end +end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09705d1..d56390e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,3 @@ -class ApplicationController < ActionController::Base -end +# frozen_string_literal: true + +class ApplicationController < ActionController::Base; end diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb new file mode 100644 index 0000000..0bad129 --- /dev/null +++ b/app/controllers/welcome_controller.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +class WelcomeController < ApplicationController + def show; end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be79..15b06f0 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + module ApplicationHelper end diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index a009ace..d92ffdd 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,2 +1,4 @@ +# frozen_string_literal: true + class ApplicationJob < ActiveJob::Base end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b223..d84cb6e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 10a4cba..71fbba5 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..c2a299a --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +class User < ApplicationRecord + validates :email, :name, presence: true + validates :email, uniqueness: true, email_format: true +end diff --git a/app/views/admin/main/show.html.slim b/app/views/admin/main/show.html.slim new file mode 100644 index 0000000..2a84b3c --- /dev/null +++ b/app/views/admin/main/show.html.slim @@ -0,0 +1 @@ +| Admin diff --git a/app/views/admin/users/create.html.erb b/app/views/admin/users/create.html.erb new file mode 100644 index 0000000..5d0c6ce --- /dev/null +++ b/app/views/admin/users/create.html.erb @@ -0,0 +1,16 @@ +

Добавление пользователя

+<%= form_for @user, url: admin_user_path do |f| %> + +

+ Имя
+ <%= f.text_field :name %>

+

+ Имэйл + <%= f.text_field :email %> +

+

+ <%= f.submit 'Сохранить'%> + +

+<% end %> + diff --git a/app/views/admin/users/edit.html.erb b/app/views/admin/users/edit.html.erb new file mode 100644 index 0000000..c7ca183 --- /dev/null +++ b/app/views/admin/users/edit.html.erb @@ -0,0 +1,21 @@ +

Редактирование пользователя

+ + +<%= form_for :user, url: admin_user_path, method: :patch do |form| %> +

+ <%= form.label :name %>
+ <%= form.text_field :name %> +

+ +

+ <%= form.label :email %>
+ <%= form.text_field :email %> +

+ +

+ <%= form.submit 'Обновить' %> +

+ +<% end %> + +<%= link_to 'Назад', admin_user_path %> diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb new file mode 100644 index 0000000..32a6499 --- /dev/null +++ b/app/views/admin/users/index.html.erb @@ -0,0 +1,24 @@ +

Все пользователи

+ +<%= link_to 'На главную', home_path %>
+
+<%= link_to 'Новый пользователь', new_admin_user_path %>
+
+ + + + + + +<% @users.each do |user| %> + + + + + + <% end %> +
Name Email
<%= user.name %><%= user.email %><%= link_to ' Показать', admin_user_path(user) %>
+ +<%= paginate @users %> + + diff --git a/app/views/admin/users/index.js.erb b/app/views/admin/users/index.js.erb new file mode 100644 index 0000000..dba62d8 --- /dev/null +++ b/app/views/admin/users/index.js.erb @@ -0,0 +1,7 @@ +$('#users').append('<%= j render(@users) %>'); + +<% if @users.next_page %> + $('.pagination').replaceWith('<%= j will_paginate(@users, renderer: 'BootstrapPaginationHelper::LinkRenderer') %>'); +<% else %> + $('.pagintion').remove(); +<% end %> \ No newline at end of file diff --git a/app/views/admin/users/new.html.erb b/app/views/admin/users/new.html.erb new file mode 100644 index 0000000..1f81839 --- /dev/null +++ b/app/views/admin/users/new.html.erb @@ -0,0 +1,29 @@ +

Новый пользователь

+ +<%= form_for @user, url: admin_users_path do |f| %> + + <% if @user.errors.any? %> +
+

+ <%= pluralize(@user.errors.count, 'ошибки') %>, запрет на сохранение: +

+ +
+ <% end %> + + +

Имя
+ <%= f.text_field :name %>

+

Имэйл
+ <%= f.text_field :email %> +

+

+ <%= f.submit 'Сохранить'%> +

+ <% end %> + +<%= link_to 'Назад', admin_users_path %> \ No newline at end of file diff --git a/app/views/admin/users/show.html.erb b/app/views/admin/users/show.html.erb new file mode 100644 index 0000000..e3700b8 --- /dev/null +++ b/app/views/admin/users/show.html.erb @@ -0,0 +1,19 @@ +

Пользователь

+

+ Name: + <%= @user.name %> +

+ +

+ Email: + <%= @user.email %> +

+ <%= link_to 'Редактирование', edit_admin_user_path(@user), :class => 'btn btn-warning' %> +
<%= link_to 'Удалить', admin_user_path, + method: :delete, data: { confirm: 'Вы уверены?'} %> +
<%= link_to 'Назад', admin_users_path(@user),class: 'btn btn-outline-secondary' %> +
+ + diff --git a/app/views/layouts/_admin_lte_2_header.html.erb b/app/views/layouts/_admin_lte_2_header.html.erb new file mode 100644 index 0000000..f570e3b --- /dev/null +++ b/app/views/layouts/_admin_lte_2_header.html.erb @@ -0,0 +1,159 @@ + +
+ + + + + + +
diff --git a/app/views/layouts/_admin_lte_2_sidebar.html.erb b/app/views/layouts/_admin_lte_2_sidebar.html.erb new file mode 100644 index 0000000..9ea996a --- /dev/null +++ b/app/views/layouts/_admin_lte_2_sidebar.html.erb @@ -0,0 +1,33 @@ + + diff --git a/app/views/layouts/admin/_menu.html.slim b/app/views/layouts/admin/_menu.html.slim new file mode 100644 index 0000000..e484c48 --- /dev/null +++ b/app/views/layouts/admin/_menu.html.slim @@ -0,0 +1,12 @@ +adul.sidebar-menu + li.header HEADER + li.active_ + = link_to admin_users_path do + i.fa.fa-link + span users + li.active_ + = link_to admin_users_path do + span users + +/ lavrik - remove not used + diff --git a/app/views/layouts/admin_lte_2.html.erb b/app/views/layouts/admin_lte_2.html.erb new file mode 100644 index 0000000..317a59d --- /dev/null +++ b/app/views/layouts/admin_lte_2.html.erb @@ -0,0 +1,136 @@ + + + + + AdminLTE 2 | Dashboard + + + + <%= stylesheet_link_tag 'admin', media: 'all' %> + + + + <%= csrf_meta_tags %> + + + +
+ + <%= render partial: 'layouts/admin_lte_2_header' %> + + <%= render partial: 'layouts/admin_lte_2_sidebar' %> + + +
+ +
+

+ Page Header + Optional description +

+ +
+ + +
+ <% if notice %> +
+ + + <%= notice %> +
+ <% end %> + + <% if alert %> +
+ + + <%= alert %> +
+ <% end %> + <%= yield %> +
+
+ + + + + + +
+ +
+ + <%= javascript_include_tag 'admin' %> + + diff --git a/app/views/layouts/admin_lte_2_login.html.erb b/app/views/layouts/admin_lte_2_login.html.erb new file mode 100644 index 0000000..efbe691 --- /dev/null +++ b/app/views/layouts/admin_lte_2_login.html.erb @@ -0,0 +1,55 @@ + + + + + AdminLTE 2 | Log in + + + + <%= stylesheet_link_tag 'application', media: 'all' %> + + + + <%= csrf_meta_tags %> + + +
+ +
+ + <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> +
+ <%= f.text_field :email, class: 'form-control', autofocus: true %> + +
+ +
+ <%= f.password_field :password, class: 'form-control', autocomplete: 'off' %> + +
+
+
+
+ +
+
+
+ <%= f.submit 'Log in', class: 'btn btn-primary btn-block btn-flat' %> + +
+
+ + <% end %> +
+
+ +<%= javascript_include_tag 'application' %> + + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 05c6a74..a799015 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,11 +5,13 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> - <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> - <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> + <%= stylesheet_link_tag 'application', media: 'all' %> + <%= javascript_include_tag 'application' %> +
<%= yield %> +
diff --git a/app/views/welcome/show.html.erb b/app/views/welcome/show.html.erb new file mode 100644 index 0000000..a8cf4ee --- /dev/null +++ b/app/views/welcome/show.html.erb @@ -0,0 +1,2 @@ +

Hello, Users!

+<%= link_to 'Пользователи', admin_root_path %> \ No newline at end of file diff --git a/bin/bundle b/bin/bundle index f19acf5..2dbb717 100755 --- a/bin/bundle +++ b/bin/bundle @@ -1,3 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) load Gem.bin_path('bundler', 'bundle') diff --git a/bin/rails b/bin/rails index 5badb2f..3504c3f 100755 --- a/bin/rails +++ b/bin/rails @@ -1,6 +1,8 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + begin - load File.expand_path('../spring', __FILE__) + load File.expand_path('spring', __dir__) rescue LoadError => e raise unless e.message.include?('spring') end diff --git a/bin/rake b/bin/rake index d87d5f5..1fe6cf0 100755 --- a/bin/rake +++ b/bin/rake @@ -1,6 +1,8 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + begin - load File.expand_path('../spring', __FILE__) + load File.expand_path('spring', __dir__) rescue LoadError => e raise unless e.message.include?('spring') end diff --git a/bin/setup b/bin/setup index 94fd4d7..da1b834 100755 --- a/bin/setup +++ b/bin/setup @@ -1,6 +1,7 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'fileutils' -include FileUtils # path to your application root. APP_ROOT = File.expand_path('..', __dir__) @@ -10,6 +11,7 @@ def system!(*args) end chdir APP_ROOT do + include FileUtils # This script is a starting point to setup your application. # Add necessary setup steps to this file. diff --git a/bin/spring b/bin/spring index fb2ec2e..9bd27ec 100755 --- a/bin/spring +++ b/bin/spring @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true # This file loads spring without using Bundler, in order to be fast. # It gets overwritten when you run the `spring binstub` command. @@ -8,7 +9,7 @@ unless defined?(Spring) require 'bundler' lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) - spring = lockfile.specs.detect { |spec| spec.name == "spring" } + spring = lockfile.specs.detect { |spec| spec.name == 'spring' } if spring Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path gem 'spring', spring.version diff --git a/bin/update b/bin/update index 58bfaed..5385ee1 100755 --- a/bin/update +++ b/bin/update @@ -1,6 +1,7 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + require 'fileutils' -include FileUtils # path to your application root. APP_ROOT = File.expand_path('..', __dir__) @@ -10,6 +11,7 @@ def system!(*args) end chdir APP_ROOT do + include FileUtils # This script is a way to update your development environment automatically. # Add necessary update steps to this file. diff --git a/bin/yarn b/bin/yarn index 460dd56..dd36daa 100755 --- a/bin/yarn +++ b/bin/yarn @@ -1,11 +1,13 @@ #!/usr/bin/env ruby +# frozen_string_literal: true + APP_ROOT = File.expand_path('..', __dir__) Dir.chdir(APP_ROOT) do begin - exec "yarnpkg", *ARGV + exec 'yarnpkg', *ARGV rescue Errno::ENOENT - $stderr.puts "Yarn executable was not detected in the system." - $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" + warn 'Yarn executable was not detected in the system.' + warn 'Download Yarn at https://yarnpkg.com/en/docs/install' exit 1 end end diff --git a/config.ru b/config.ru index f7ba0b5..842bccc 100644 --- a/config.ru +++ b/config.ru @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is used by Rack-based servers to start the application. require_relative 'config/environment' diff --git a/config/application.rb b/config/application.rb index ecd2afc..00eaf25 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,16 +1,16 @@ require_relative 'boot' -require "rails" +require 'rails' # Pick the frameworks you want: -require "active_model/railtie" -require "active_job/railtie" -require "active_record/railtie" -require "active_storage/engine" -require "action_controller/railtie" -require "action_mailer/railtie" -require "action_view/railtie" -require "action_cable/engine" -require "sprockets/railtie" +require 'active_model/railtie' +require 'active_job/railtie' +require 'active_record/railtie' +require 'active_storage/engine' +require 'action_controller/railtie' +require 'action_mailer/railtie' +require 'action_view/railtie' +require 'action_cable/engine' +require 'sprockets/railtie' # require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems @@ -19,6 +19,8 @@ module Garages class Application < Rails::Application + config.to_prepare do + end # Initialize configuration defaults for originally generated Rails version. config.load_defaults 5.2 @@ -29,5 +31,11 @@ class Application < Rails::Application # Don't generate system test files. config.generators.system_tests = nil + + config.paths['config/routes.rb'].concat Dir[Rails.root.join('config/routes/*.rb')] + + config.generators do |g| + g.template_engine :slim + end end end diff --git a/config/database.yml b/config/database.yml deleted file mode 100644 index dd15d87..0000000 --- a/config/database.yml +++ /dev/null @@ -1,85 +0,0 @@ -# PostgreSQL. Versions 9.1 and up are supported. -# -# Install the pg driver: -# gem install pg -# On OS X with Homebrew: -# gem install pg -- --with-pg-config=/usr/local/bin/pg_config -# On OS X with MacPorts: -# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config -# On Windows: -# gem install pg -# Choose the win32 build. -# Install PostgreSQL and put its /bin directory on your path. -# -# Configure Using Gemfile -# gem 'pg' -# -default: &default - adapter: postgresql - encoding: unicode - # For details on connection pooling, see Rails configuration guide - # http://guides.rubyonrails.org/configuring.html#database-pooling - pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> - -development: - <<: *default - database: garages_development - - # The specified database role being used to connect to postgres. - # To create additional roles in postgres see `$ createuser --help`. - # When left blank, postgres will use the default role. This is - # the same name as the operating system user that initialized the database. - #username: garages - - # The password associated with the postgres role (username). - #password: - - # Connect on a TCP socket. Omitted by default since the client uses a - # domain socket that doesn't need configuration. Windows does not have - # domain sockets, so uncomment these lines. - #host: localhost - - # The TCP port the server listens on. Defaults to 5432. - # If your server runs on a different port number, change accordingly. - #port: 5432 - - # Schema search path. The server defaults to $user,public - #schema_search_path: myapp,sharedapp,public - - # Minimum log levels, in increasing order: - # debug5, debug4, debug3, debug2, debug1, - # log, notice, warning, error, fatal, and panic - # Defaults to warning. - #min_messages: notice - -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: - <<: *default - database: garages_test - -# As with config/secrets.yml, you never want to store sensitive information, -# like your database password, in your source code. If your source code is -# ever seen by anyone, they now have access to your database. -# -# Instead, provide the password as a unix environment variable when you boot -# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database -# for a full rundown on how to provide these environment variables in a -# production deployment. -# -# On Heroku and other platform providers, you may have a full connection URL -# available as an environment variable. For example: -# -# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" -# -# You can use this database configuration with: -# -# production: -# url: <%= ENV['DATABASE_URL'] %> -# -production: - <<: *default - database: garages_production - username: garages - password: <%= ENV['GARAGES_DATABASE_PASSWORD'] %> diff --git a/config/environments/production.rb b/config/environments/production.rb index 334c3a4..d816847 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -54,7 +54,7 @@ config.log_level = :debug # Prepend all log lines with the following tags. - config.log_tags = [ :request_id ] + config.log_tags = [:request_id] # Use a different cache store in production. # config.cache_store = :mem_cache_store @@ -83,7 +83,7 @@ # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') - if ENV["RAILS_LOG_TO_STDOUT"].present? + if ENV['RAILS_LOG_TO_STDOUT'].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 4b828e8..c9bf3b0 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -11,4 +11,4 @@ # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in the app/assets # folder are already added. -# Rails.application.config.assets.precompile += %w( admin.js admin.css ) +Rails.application.config.assets.precompile += %w[admin.js admin.scss] diff --git a/config/locales/en.yml b/config/locales/en.yml index decc5a8..a664552 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -31,3 +31,7 @@ en: hello: "Hello world" + views: + pagination: + previous: "< Previous" + next: "Next >" diff --git a/config/locales/ru/adminlte.yml b/config/locales/ru/adminlte.yml new file mode 100644 index 0000000..c757344 --- /dev/null +++ b/config/locales/ru/adminlte.yml @@ -0,0 +1,154 @@ +ru: + common: + errors: 'При заполении формы возниели ошибки' + back: 'Назад' + admin: + users: + index: + name: 'Все пользователи' + new: + name: 'Новый пользователь' + submit: + '%{action} пользователя' + edit: + name: 'Редактирование' + active_admin: + dashboard: "Панель управления" + dashboard_welcome: + welcome: "Добро пожаловать в Active Admin. Это стандартная страница управления сайтом." + call_to_action: "Чтобы добавить сюда что-нибудь загляните в 'app/admin/dashboard.rb'" + view: "Открыть" + edit: "Изменить" + delete: "Удалить" + delete_confirmation: "Вы уверены, что хотите удалить это?" + new_model: "Создать %{model}" + edit_model: "Изменить %{model}" + delete_model: "Удалить %{model}" + details: "%{model} подробнее" + cancel: "Отмена" + empty: "Пусто" + previous: "Пред." + next: "След." + download: "Загрузка:" + has_many_new: "Добавить %{model}" + has_many_delete: "Удалить" + has_many_remove: "Убрать" + filters: + buttons: + filter: "Фильтровать" + clear: "Очистить" + predicates: + contains: "Содержит" + equals: "Равно" + starts_with: "Начинается с" + ends_with: "Заканчивается" + greater_than: "больше" + less_than: "меньше" + from: "От" + to: "До" + search_status: + headline: "Статус поиска:" + current_scope: "Область:" + current_filters: "Текущий фильтр:" + no_current_filters: "Ни один" + status_tag: + "yes": "Да" + "no": "Нет" + "unset": "Нет" + main_content: "Создайте %{model}#main_content для отображения содержимого." + logout: "Выйти" + powered_by: "Работает на %{active_admin} %{version}" + sidebars: + filters: "Фильтры" + search_status: "Статус поиска" + pagination: + empty: "%{model} не найдено" + one: "Результат: 1 %{model}" + one_page: "Результат: %{n} %{model}" + multiple: "Результат: %{model} %{from} - %{to} из %{total}" + multiple_without_total: "Результат: %{model} %{from} - %{to}" + entry: + one: "запись" + few: "записи" + many: "записей" + other: "записей" + any: "Любой" + blank_slate: + content: "Пока нет %{resource_name}." + link: "Создать" + dropdown_actions: + button_label: "Oперации" + batch_actions: + button_label: "Групповые операции" + default_confirmation: "Вы уверены, что вы хотите это сделать?" + delete_confirmation: "Вы уверены, что хотите удалить %{plural_model}?" + succesfully_destroyed: + one: "Успешно удалено: 1 %{model}" + few: "Успешно удалено: %{count} %{plural_model}" + many: "Успешно удалено: %{count} %{plural_model}" + other: "Успешно удалено: %{count} %{plural_model}" + selection_toggle_explanation: "(Отметить всё / Снять выделение)" + action_label: "%{title} выбранное" + labels: + destroy: "Удалить" + comments: + created_at: "Дата создания" + resource_type: "Тип ресурса" + author_type: "Тип автора" + body: "Текст" + author: "Автор" + add: "Добавить Комментарий" + delete: "Удалить Комментарий" + delete_confirmation: "Вы уверены, что хотите удалить этот комментарий?" + resource: "Ресурс" + no_comments_yet: "Пока нет комментариев." + author_missing: "Аноним" + title_content: "Комментарии (%{count})" + errors: + empty_text: "Комментарий не сохранен, текст не должен быть пустым." + devise: + username: + title: "Имя пользователя" + email: + title: "Эл. почта" + subdomain: + title: "Поддомен" + password: + title: "Пароль" + sign_up: + title: "Зарегистрироваться" + submit: "Зарегистрироваться" + login: + title: "Войти" + remember_me: "Запомнить меня" + submit: "Войти" + reset_password: + title: "Забыли пароль?" + submit: "Сбросить пароль" + change_password: + title: "Изменение пароля" + submit: "Изменение пароля" + unlock: + title: "Повторно отправить инструкции по разблокировке" + submit: "Повторно отправить инструкции по разблокировке" + resend_confirmation_instructions: + title: "Выслать повторно письмо с активацией" + submit: "Выслать повторно письмо с активацией" + links: + sign_up: "Зарегистрироваться" + sign_in: "Войти" + forgot_your_password: "Забыли пароль?" + sign_in_with_omniauth_provider: "Войти с помощью %{provider}" + resend_unlock_instructions: "Повторная отправка инструкций разблокировки" + resend_confirmation_instructions: "Повторная отправка инструкций подтверждения" + unsupported_browser: + headline: "Пожалуйста, обратите внимание, что Active Admin больше не поддерживает старые версии Internet Explorer начиная с версии IE 8" + recommendation: "Мы рекомендуем обновить версию вашего браузера (Internet Explorer, Google Chrome, или Firefox)." + turn_off_compatibility_view: "Если вы используете IE 9 или новее, убедитесь, что вы выключили опцию \"Просмотр в режиме совместимости\"." + access_denied: + message: "Вы не авторизованы для выполнения данного действия." + index_list: + table: "Таблица" + block: "Список" + grid: "Сетка" + blog: "Блог" diff --git a/config/puma.rb b/config/puma.rb index a5eccf8..f123039 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -4,16 +4,16 @@ # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 } threads threads_count, threads_count # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # -port ENV.fetch("PORT") { 3000 } +port ENV.fetch('PORT') { 3000 } # Specifies the `environment` that Puma will run in. # -environment ENV.fetch("RAILS_ENV") { "development" } +environment ENV.fetch('RAILS_ENV') { 'development' } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked webserver processes. If using threads and workers together diff --git a/config/routes.rb b/config/routes.rb index 787824f..99b4ea5 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,3 +1,7 @@ Rails.application.routes.draw do - # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html + def draw(routes_name) + instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb"))) + end + draw :admin + root 'welcome#show', as: 'home' end diff --git a/config/routes/admin.rb b/config/routes/admin.rb new file mode 100644 index 0000000..28625b6 --- /dev/null +++ b/config/routes/admin.rb @@ -0,0 +1,7 @@ +Rails.application.routes.draw do + namespace :admin do + root 'main#show' + + resources :users + end +end diff --git a/db/migrate/20190814192414_create_users.rb b/db/migrate/20190814192414_create_users.rb new file mode 100644 index 0000000..4dfb09c --- /dev/null +++ b/db/migrate/20190814192414_create_users.rb @@ -0,0 +1,10 @@ +class CreateUsers < ActiveRecord::Migration[5.2] + def change + create_table :users do |t| + t.string :name, null: false + t.string :email, null: false + + t.timestamps null: false + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 2611543..c8e5523 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -10,9 +12,14 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 0) do - +ActiveRecord::Schema.define(version: 20_190_814_192_414) do # These are extensions that must be enabled in order to support this database - enable_extension "plpgsql" + enable_extension 'plpgsql' + create_table 'users', force: :cascade do |t| + t.string 'name', null: false + t.string 'email', null: false + t.datetime 'created_at', null: false + t.datetime 'updated_at', null: false + end end diff --git a/db/seeds.rb b/db/seeds.rb index 1beea2a..ebd1889 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). #