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

New design copy #38

Open
wants to merge 5 commits into
base: deploy
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
19 changes: 17 additions & 2 deletions app/assets/javascripts/trainings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
$(document).ready(function(){
$('#clients_select').dropdown({onChange(value, text, selItem) {
// $('#clients_select').dropdown({onChange(value, text, selItem) {
$('.client-select').dropdown({onChange(value, text, selItem) {
join_clients(JSON.stringify(value));
}});

Expand All @@ -23,13 +24,27 @@ function join_clients(clients_ids) {
xhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
document.getElementById("clients_continer").innerHTML = this.responseText;
$('.exercises-types-select').dropdown({onChange(value, text, selItem) {
add_exercise_params(this.id, JSON.stringify(value));
}});
}
};
xhttp.open("POST", "/trainings/clients", true);
xhttp.send(form_data);
}


function add_exercise_params (elem_id, clients_ids) {
var form_data = new FormData();
form_data.append('erercises', clients_ids);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
document.getElementById(`exercise_continer_${elem_id}`).innerHTML = this.responseText;
}
};
xhttp.open("POST", "/trainings/exercises", true);
xhttp.send(form_data);
}

function add_exercise() {
$('.tiny.modal').modal('show');
Expand Down
23 changes: 23 additions & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,40 @@
.ui.raised.container.segment {
//#container-segment {
margin-top: 23px;
margin-right: auto !important;
margin-left: auto !important;
padding-top: 40px;
padding-bottom: 40px;
}

#bottom-segment {
width: calc(100% - 210px);
margin-left: 210px;
}

@media only screen and (max-width: 1144px) {
#fixed-sidebar {
display: none;
}
#kek {
margin-top: 4rem;
}
#toggle-sidebar,
#menu-sidebar {
display: flex;
}

#bottom-segment {
margin-left: auto;
width: 100%;
}

table.ui.unstackable.selectable.table {
overflow: scroll;
display: block;
width: 100%;
overflow-y: hidden;
}
}

@media only screen and (min-width: 1145px) {
Expand Down
1 change: 1 addition & 0 deletions app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def find_client
end

def client_params
# todo: check params
params[:status] = params[:status].to_i
params[:gender] = params[:gender].to_i
params[:metric_ids].map!(&:to_i)
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class PaymentsController < ApplicationController
def index
@payments_list = Transaction.where(client_id: client_id).order(created_at: :desc)
@payments_list = @payments_list.page(params[:page])
@result_balance = Client.find(client_id).cash
@client = client
@result_balance = client.cash
end

def create; end
Expand Down
49 changes: 36 additions & 13 deletions app/controllers/trainings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class TrainingsController < ApplicationController
before_action :find_training, only: %i[show edit update cancel destroy]
before_action :authenticate_user!
# protect_from_forgery with: :null_session
skip_before_action :verify_authenticity_token, only: %i[join_clients]
skip_before_action :verify_authenticity_token, only: %i[join_clients exercises]

def index

Expand All @@ -25,18 +25,41 @@ def show

def new
@clients = current_user.clients
@training = current_user.trainings.build
# todo: parse and set to calendar input
date = params[:date][0...10]
@day = date[8].to_i == 0 ? date[9] : date[8..9]
@month = date[5].to_i == 0 ? date[6] : date[5..6]
@year = date[0..3]
(current_user.trainings.find_by(status: 0))&.delete
training = current_user.trainings.build
redirect_url calendar_path, alert: "Couldn't create training" unless training.save
end

def join_clients
if params[:clients] && params[:clients].present?
training.clients.each do |client|
training.clients.destroy(client) unless JSON.parse(params[:clients]).include?(client.id.to_s)
end
if params[:clients]&.present?
@clients = current_user.clients.select do|client|
JSON.parse(params[:clients]).include?(client.id.to_s)
if client && JSON.parse(params[:clients]).include?(client.id.to_s)
client.trainings << training unless client.trainings.include?(training)
client
end
end
end
@exercises = ExerciseType.all
render layout: false
end

def training
@training ||= current_user.trainings.find_by(status: 0)
end

def client_with_current_training
current_user.clients.select do |client|
client if client && client.trainings.include?(training)
end
end

def exercises
if params[:erercises]&.present?
@exercises = ExerciseType.select do|exe|
JSON.parse(params[:erercises]).include?(exe.id.to_s)
end
end
render layout: false
Expand All @@ -62,13 +85,13 @@ def create
start_time = @training.time
end_time = start_time + 2.hours
summary = Client.find_by(id: @training.client_id).full_name
event = Google::Apis::CalendarV3::Event.new({
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)
end
rescue Google::Apis::AuthorizationError
Expand Down Expand Up @@ -103,12 +126,12 @@ def update
start_time = @training.time
end_time = start_time + 2.hours
summary = Client.find_by(id: @training.client_id).full_name
event = Google::Apis::CalendarV3::Event.new({
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
})
)
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 Down
3 changes: 0 additions & 3 deletions app/controllers/webhooks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
class WebhooksController < ApplicationController

def callback
puts
puts message[:text]
puts
if client && message_exist.nil? && message[:text]
client.messages.create(text: message[:text], update_id: webhook[:update_id])
send_broadcast
Expand Down
2 changes: 1 addition & 1 deletion app/models/training.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ class Training < ApplicationRecord
has_and_belongs_to_many :clients
has_many :exercises

enum status: %i[is_created planned complete canceled]
enum status: %i[creation planned complete canceled]
end
2 changes: 1 addition & 1 deletion app/views/clients/_navbar.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
a.item [class="#{'active' if active_section == :show}" href="#{client_path(@client)}" ] #{t('client_navigation.info')}
a.item [class="#{'active' if active_section == :stats}" href="#{client_stats_path(@client)}" ] #{t('client_navigation.stats')}
a.item [class="#{'active' if active_section == :messages}" href="#{client_messages_path(@client)}" ] #{t('client_navigation.messages')}
a.item [class="#{'active' if active_section == :diet}" href="#" ] #{t('client_navigation.diet')}
/ a.item [class="#{'active' if active_section == :diet}" href="#" ] #{t('client_navigation.diet')}
a.item [class="#{'active' if active_section == :payments}" href="#{client_payments_path(@client)}" ] #{t('client_navigation.payments')}
a.item [class="#{'active' if active_section == :diary}" href="#" ] #{t('client_navigation.diary')}

120 changes: 0 additions & 120 deletions app/views/layouts/_navigation.html.slim

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
Menu
</a>
</div>
<div class="pusher">
<div class="pusher" id="kek">
<%= render 'layouts/messages' %>
<%= yield %>
</div>
Expand Down
20 changes: 0 additions & 20 deletions app/views/layouts/application.html.slim

This file was deleted.

Loading