New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactoring #13
Merged
Merged
Refactoring #13
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f930382
add books sort service
mazelka 2c0a6cd
fixed routes and tests
mazelka 2663e6b
merge soft delete
mazelka 5b72613
merge internationalization
mazelka e344479
fix authors after merge
mazelka d4c8544
add sorting by review on pupolar books, add missed translations to re…
mazelka 02ea86f
remove useless methods
mazelka b08da64
add partial for books
mazelka 4c8c6af
add partial for address
mazelka 03794b8
add jquery for address and settings
mazelka dc1a359
remove logs
mazelka File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
ActiveAdmin.register Author do | ||
permit_params :first_name, :last_name, :biography | ||
actions :all, except: [:show, :destroy] | ||
actions :all | ||
|
||
index do | ||
selectable_column | ||
id_column | ||
column :first_name | ||
column :last_name | ||
actions defaults: true do |author| | ||
link_to t('.delete'), author_path(author), method: :delete, data: { confirm: "#{t('.confirm_part1')} #{author.books.count} #{t('.confirm_part2')}" } | ||
actions defaults: false do |author| | ||
item t('.edit'), edit_admin_author_path(author), class: 'member_link' | ||
item t('.delete'), admin_author_path(author), method: :delete, data: { confirm: "#{t('.confirm_part1')} #{author.books.count} #{t('.confirm_part2')}" }, class: 'member_link' | ||
end | ||
end | ||
|
||
form do |f| | ||
f.inputs do | ||
f.input :first_name | ||
f.input :last_name | ||
f.input :biography | ||
end | ||
f.actions | ||
end | ||
|
||
filter :first_name | ||
filter :last_name | ||
|
||
controller do | ||
def destroy | ||
Author.find(params[:id]).discard | ||
flash[:notice] = 'Author has been deleted.' | ||
redirect_to admin_authors_path | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,2 @@ | ||
class AuthorsController < ApplicationController | ||
def destroy | ||
Author.find(params[:id]).discard | ||
flash[:notice] = t('.admin.messages.author_deleted') | ||
redirect_to admin_authors_path | ||
end | ||
|
||
private | ||
|
||
def author_params | ||
params.require(:author).permit(:first_name, :last_name, :biography) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
class CategoriesController < ApplicationController | ||
def show | ||
@books = Category.find(params[:id]).books.order('created_at').page(params[:page]).per(12) | ||
books_count | ||
popular_categories | ||
render 'books/index' | ||
end | ||
|
||
private | ||
|
||
def category_params | ||
params.require(:category).permit(:id, :title, :text) | ||
end | ||
|
||
def books_count | ||
@all_books = Book.all.count | ||
end | ||
|
||
def popular_categories | ||
@popular_categories = Category.all.sort { |b, a| a.books.count <=> b.books.count }[0...5] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
class HomeController < ApplicationController | ||
def index | ||
@latest_books = Book.order('created_at').last(3) | ||
@bestsellers = Category.all.select { |category| category.books.count.positive? }.map do |category| | ||
category.books.max { |book| book.reviews.count } | ||
end[0...4] | ||
@latest_books = Book.latest | ||
@bestsellers = BestSellersBooks.call | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,24 @@ | ||
class QuickRegistrationsController < ApplicationController | ||
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i | ||
|
||
def show_lazy_login | ||
def index | ||
@customer = Customer.new | ||
render 'login' | ||
end | ||
|
||
def lazy_sign_up | ||
def create | ||
if email_valid?(params[:customer][:email]) | ||
generated_password = Devise.friendly_token.first(8) | ||
customer = Customer.new(email: params[:customer][:email], password: generated_password) | ||
customer.save(validate: false) | ||
sign_in(:customer, customer) | ||
redirect_to cart_path | ||
redirect_to carts_path | ||
customer.send_reset_password_instructions | ||
else | ||
flash[:notice] = t('quick_registrations.login.invalid_email') | ||
redirect_to login_path | ||
end | ||
end | ||
|
||
def email_valid?(email) | ||
email.match(VALID_EMAIL_REGEX) | ||
!Customer.find_by(email: email).present? && email.match(VALID_EMAIL_REGEX) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class BestSellersBooks | ||
def self.call | ||
new.call | ||
end | ||
|
||
def call | ||
Category.all.select { |category| category.books.count.positive? }.map do |category| | ||
category.books.max { |book| book.reviews.count } | ||
end[0...4] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class BooksSorting | ||
def initialize | ||
@books = Book.all | ||
end | ||
|
||
def sort(sort = 'created_at', direction = 'asc') | ||
@books = Book.order("#{sort} #{direction}") | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be extracted to service like OrdersFilter