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

Dockerize project #39

Open
wants to merge 8 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
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git
.dockerignore
.byebug_history
log/*
tmp/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/vendor/bundle/
/vendor/ruby/
/node_modules
/docker/ssl_keys


# minimal Rails specific artifacts
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ gem 'bootstrap', '~> 4.0.0'
gem 'jquery-rails'
gem 'bourbon'
gem 'foreman'
gem 'rails_12factor', group: :production
gem 'dotenv'
gem 'coffee-rails', '~> 4.2'
gem 'devise'
Expand Down
6 changes: 6 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,12 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_layout (1.0.42)
rails_serve_static_assets (0.0.5)
rails_stdout_logging (0.0.5)
railties (5.2.1)
actionpack (= 5.2.1)
activesupport (= 5.2.1)
Expand Down Expand Up @@ -429,6 +434,7 @@ DEPENDENCIES
puma (~> 3.11)
pundit
rails (~> 5.2.0)
rails_12factor
rails_layout
rspec-rails
sass-rails (~> 5.0)
Expand Down
2 changes: 0 additions & 2 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
//= require popper
//= require bootstrap-sprockets
//= require moment
////= require select2/dist/js/select2.full.js
//= require chart.js/dist/Chart.js
//= require cable
//= require moment
//= require jquery
Expand Down
9 changes: 4 additions & 5 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* It is generally better to create a new file per style scope.
*
*= require fullcalendar
//*= require select2/dist/css/select2.css
*= require_tree .
*= require_self

Expand All @@ -32,14 +31,14 @@
}

.main.ui.container {
//#main-container {
//#main-container {
display: flex;
flex-flow: row nowrap;
justify-content: center;
}

.ui.raised.container.segment {
//#container-segment {
//#container-segment {
margin-top: 23px;
margin-right: auto !important;
margin-left: auto !important;
Expand All @@ -52,7 +51,7 @@
margin-left: 210px;
}

@media only screen and (max-width: 1520px) {
@media only screen and (max-width: 1144px) {
#fixed-sidebar {
display: none;
}
Expand All @@ -77,7 +76,7 @@
}
}

@media only screen and (min-width: 1521px) {
@media only screen and (min-width: 1145px) {
#fixed-sidebar {
display: flex;
}
Expand Down
64 changes: 33 additions & 31 deletions app/controllers/trainings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@ class TrainingsController < ApplicationController
# protect_from_forgery with: :null_session
skip_before_action :verify_authenticity_token, only: %i[join_clients exercises]

def index
@training = Training.where(user_id: current_user.id).map do |training|
{
name: Client.find_by(id: training.client_id).full_name,
training: training
}
end
end

def show
@name = Client.find_by(id: @training.client_id).full_name
@sets = kit_constructor
end

def new
@clients = current_user.clients
(current_user.trainings.find_by(status: 0))&.delete
@date = params[:date]
training = current_user.trainings.build
redirect_url calendar_path, alert: "Couldn't create training" unless training.save
@date = params[:date]
@training = current_user.trainings.build
end

def join_clients
Expand Down Expand Up @@ -52,22 +65,15 @@ def exercises
render layout: false
end

def show
authorize @training
@name = Client.find_by(id: @training.client_id).full_name
@sets = kit_constructor
end

def client_list
current_user.clients.map do |client|
# Client.where(user_id: user).map do |client|
# Client.where(user_id: user).map do |client|
[client.first_name + ' ' + client.second_name, client.id]
end
end

def create
@training = current_user.trainings.build(training_params)
authorize @training
if @training.save
calendar_id = Calendar.find_by(user_id: current_user.id).calendar_id
begin
Expand All @@ -84,13 +90,13 @@ def create
end_time = start_time + 2.hours
summary = Client.find_by(id: @training.client_id).full_name
event = Google::Apis::CalendarV3::Event.new(
id: 'training' + @training.id.to_s + 'fitfree1asslcom',
start: Google::Apis::CalendarV3::EventDateTime.new(date_time: (start_time - 3.hours).to_datetime.rfc3339),
end: Google::Apis::CalendarV3::EventDateTime.new(date_time: (end_time - 3.hours).to_datetime.rfc3339),
summary: summary,
description: @training.description
)
service.insert_event(calendar_id, event)
id: 'training' + @training.id.to_s + 'fitfree1asslcom',
start: Google::Apis::CalendarV3::EventDateTime.new(date_time: (start_time - 3.hours).to_datetime.rfc3339),
end: Google::Apis::CalendarV3::EventDateTime.new(date_time: (end_time - 3.hours).to_datetime.rfc3339),
summary: summary,
description: @training.description
)
service.insert_event(calendar_id, event)
end
rescue Google::Apis::AuthorizationError
response = client.refresh!
Expand All @@ -105,15 +111,13 @@ def create
end

def edit
authorize @training
@list = client_list
@name = name(@training)
@sets = sets(@training, current_user)
end

def update
@training.update(status: :planned)
authorize @training
if @training.update(training_params)
calendar_id = Calendar.find_by(user_id: current_user.id).calendar_id
begin
Expand All @@ -130,11 +134,11 @@ def update
end_time = start_time + 2.hours
summary = Client.find_by(id: @training.client_id).full_name
event = Google::Apis::CalendarV3::Event.new(
start: Google::Apis::CalendarV3::EventDateTime.new(date_time: (start_time - 3.hours).to_datetime.rfc3339),
end: Google::Apis::CalendarV3::EventDateTime.new(date_time: (end_time - 3.hours).to_datetime.rfc3339),
summary: summary,
description: @training.description
)
start: Google::Apis::CalendarV3::EventDateTime.new(date_time: (start_time - 3.hours).to_datetime.rfc3339),
end: Google::Apis::CalendarV3::EventDateTime.new(date_time: (end_time - 3.hours).to_datetime.rfc3339),
summary: summary,
description: @training.description
)
if service.get_event(calendar_id, 'training' + @training.id.to_s + 'fitfree1asslcom')
service.patch_event(calendar_id, 'training' + @training.id.to_s + 'fitfree1asslcom', event)
end
Expand All @@ -157,12 +161,10 @@ def update
end

def cancel
authorize @training
@training.update(status: :canceled)
end

def destroy
authorize @training
calendar_id = Calendar.find_by(user_id: current_user.id).calendar_id
begin
if calendar_id
Expand All @@ -178,14 +180,14 @@ def destroy
service.delete_event(calendar_id, 'training' + @training.id.to_s + 'fitfree1asslcom')
end
end
TrainingsHelper::BackgroundProccess.delete_background_proc(@training.id) if @training.status == :planned
@training.destroy
redirect_to calendar_index_path
rescue Google::Apis::AuthorizationError
response = client.refresh!
session[:authorization] = session[:authorization].merge(response)
retry
end
TrainingsHelper::BackgroundProccess.delete_background_proc(@training.id) if @training.status == :planned
@training.destroy
redirect_to calendar_index_path
end

private
Expand Down Expand Up @@ -216,8 +218,8 @@ def create_background_proc(training_id)
def kit_constructor
sets = Kit.where(training_id: @training.id, user_id: current_user.id).map do |kit|
{
exercises: Exercise.where(kit_id: kit.id, user_id: current_user.id),
kit: kit
exercises: Exercise.where(kit_id: kit.id, user_id: current_user.id),
kit: kit
}
end
sets.each do |kit|
Expand Down
4 changes: 2 additions & 2 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<i class="users icon"></i>
<%= t('navigation.clients') %>
</a>
<a class="item" href="#">
<a class="item" href="<%= metrics_path %>">
<i class="cog icon"></i>
<%= t('navigation.settings') %>
</a>
Expand All @@ -55,7 +55,7 @@
<i class="users icon"></i>
<%= t('navigation.clients') %>
</a>
<a class="item" href="#">
<a class="item" href="<%= metrics_path %>">
<i class="cog icon"></i>
<%= t('navigation.settings') %>
</a>
Expand Down
25 changes: 18 additions & 7 deletions app/views/payments/index.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
= render 'clients/navbar', active_section: :payments

.ui.container
.main.ui.container
/todo: change depends screen size => .html.ui.top.attached.segment
.ui.raised.container.segment
.ui.top.attached.label
Expand All @@ -21,11 +21,22 @@
td.Date = payment.datetime.strftime("%B %d, %Y")
td.Price = payment.price
td.right.aligned.Cancel: button.negative.ui.button [onclick="document.location.replace('#{'payments/' + payment.id.to_s + '/delete'}')"] Ⓧ
center
.pagniation-wrapper align="center"
= paginate @payments_list
button.positive.ui.button [onclick="window.location='payments/create';"] #{t('.add')}

tfoot
tr
th colspan="3"
button.positive.ui.button [onclick="window.location='payments/create';"] Add
.ui.right.floated.pagination.menu
a.icon.item
i.left.chevron.icon
a.item 1
a.item 2
a.item 3
a.item 4
a.icon.item
i.right.chevron.icon
- else
h4 #{t('payments.index.no_payments')}
button.positive.ui.button [type="submit" onclick="window.location='payments/create';"] #{t('.add')}
button.positive.ui.button [type="submit" onclick="window.location='payments/create';"] #{t('payments.index.add')}
/todo: make pagination
= paginate @payments_list,
previous_label: 'Previous', next_label: 'Next', inner_window: 1, outer_window: 0
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Application < Rails::Application
config.i18n.default_locale = :en
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.2
config.active_job.queue_adapter = Rails.env.production? ? :sidekiq : :async
config.active_job.queue_adapter = :sidekiq
# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
Expand Down
6 changes: 6 additions & 0 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@

Sidekiq.configure_client do |config|
# accepts :expiration (optional)
config.redis = {
url: "redis://#{ENV["REDIS_HOST"]}:#{ENV["REDIS_PORT"]}"
}
Sidekiq::Status.configure_client_middleware config, expiration: 30.minutes
end

Sidekiq.configure_server do |config|
# accepts :expiration (optional)
config.redis = {
url: "redis://#{ENV["REDIS_HOST"]}:#{ENV["REDIS_PORT"]}"
}
Sidekiq::Status.configure_server_middleware config, expiration: 30.minutes

# accepts :expiration (optional)
Expand Down
2 changes: 1 addition & 1 deletion config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ test:
production:
admin_name: <%= ENV["ADMIN_NAME"] %>
admin_email: <%= ENV["ADMIN_EMAIL"] %>
admin_password: <%= ENV["ADMIN_PASSWORD"] %>
admin_password: 123456789
email_provider_username: <%= ENV["SENDGRID_USERNAME"] %>
email_provider_password: <%= ENV["SENDGRID_PASSWORD"] %>
domain_name: <%= ENV["DOMAIN_NAME"] %>
Expand Down
Loading