Skip to content
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

users comparison #12

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/routes.cr
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Amber::Server.configure do |app|
routes :web do
get "/", HomeController, :index
get "/about", HomeController, :about
get "/compare", HomeController, :compare
get "/races/:id", RacesController, :show
get "/users", UsersController, :index
get "/users/:id", UsersController, :show
Expand Down
22 changes: 22 additions & 0 deletions public/stylesheets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,28 @@ table td, table th {
}
}

.users-comparison-container {
display: flex;
}

.users-comparison-item {
padding: 20px;
border: 1px solid #ccc;
margin-right: 10px;
border-radius: 4px;
width: 24%;
}

.users-comparison-results {
display: flex;
flex-direction: column;
}

.users-comparison-result .line {
display: flex;
flex-direction: column;
}

.user-info {
padding: 10px 0;
}
20 changes: 20 additions & 0 deletions src/controllers/home_controller.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,27 @@ class HomeController < ApplicationController
render("index.slang")
end

def compare
# users = User.all.where { _id.in(user_ids) } # TODO: failed as Crystal compiler error
users = get_users
render("compare.slang")
end

def about
render("about.slang")
end

private def get_users
@params["user_ids"]? ?
User.all.find_by_sql("SELECT * FROM users WHERE id IN (#{template})", user_ids) :
[] of User
end

private def user_ids
@params["user_ids"].split(',').reject { |e| e == "" }.uniq.first(4)
end

private def template
user_ids.map_with_index { |_, i| "$#{i + 1}" }.join(',')
end
end
1 change: 1 addition & 0 deletions src/helpers/main_menu.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class MainMenu
"/" => "Мультиспорт Приморского края",
"/users" => "Спортсмены",
"/teams" => "Команды",
"/compare" => "Сравнение",
"/about" => "О сайте",
}
end
Expand Down
1 change: 1 addition & 0 deletions src/models/user.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class User < Jennifer::Model::Base
)

has_many :races, Race
has_many :results, Result

def self.search(name)
all.find_by_sql "SELECT users.* FROM users WHERE users.name ILIKE $1 ORDER BY users.name COLLATE \"C\"", ["%#{name}%"]
Expand Down
18 changes: 18 additions & 0 deletions src/views/home/compare.slang
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
h1 = "Сравнение"

.users-comparison-container
- users.each do |user|
.users-comparison-item
h2 = user.name
.users-comparison-results
- user.results.each do |result|
.users-comparison-result
.line
= result.race!.title
.line
= result.time

css:
.wide {
width: 95%;
}