-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andy Leverenz
committed
Nov 20, 2018
1 parent
045c133
commit 499ad85
Showing
67 changed files
with
1,134 additions
and
19 deletions.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
|
@@ -12,5 +12,6 @@ | |
// | ||
//= require rails-ujs | ||
//= require activestorage | ||
//= require trix | ||
//= require turbolinks | ||
//= require_tree . |
Empty file.
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,29 @@ | ||
document.addEventListener("turbolinks:load", () => { | ||
const tabElements = document.querySelectorAll('#nav-tab .tab'); | ||
|
||
function onTabClick(event) { | ||
const activeTabs = document.querySelectorAll('.active'); | ||
|
||
activeTabs.forEach(function(tab) { | ||
tab.classList.toggle('active'); | ||
}); | ||
|
||
|
||
event.target.parentElement.classList.add('active'); | ||
|
||
event.preventDefault(); | ||
|
||
// show and hide tab panels | ||
var tabPanel = document.getElementById(event.target.href.split("#")[1]); | ||
tabPanel.classList.toggle('active'); | ||
} | ||
|
||
|
||
if(tabElements != null) { | ||
tabElements.forEach(function(tab) { | ||
tab.addEventListener('click', (event) => { | ||
onTabClick(event); | ||
}); | ||
}); | ||
} | ||
}); |
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,81 @@ | ||
document.addEventListener("turbolinks:load", function() { | ||
const public_key = document.querySelector("meta[name='stripe-public-key']").content; | ||
const stripe = Stripe(public_key); | ||
const elements = stripe.elements(); | ||
|
||
const style = { | ||
base: { | ||
color: '#32325d', | ||
lineHeight: '26px', | ||
fontFamily: '"Helvetica Neue", Helvetica, sans-serif', | ||
fontSmoothing: 'antialiased', | ||
fontSize: '16px', | ||
'::placeholder': { | ||
color: '#aab7c4' | ||
} | ||
}, | ||
invalid: { | ||
color: '#fa755a', | ||
iconColor: '#fa755a' | ||
} | ||
}; | ||
const cardElement = document.getElementById('card-element'); | ||
|
||
if(cardElement != null) { | ||
|
||
const card = elements.create('card', {style: style}); | ||
card.mount(cardElement); | ||
|
||
card.addEventListener('change', ({error}) => { | ||
const displayError = document.getElementById('card-errors'); | ||
if (error) { | ||
displayError.textContent = error.message; | ||
} else { | ||
displayError.textContent = ''; | ||
} | ||
}); | ||
|
||
|
||
const form = document.querySelector('.meeting-form'); | ||
form.addEventListener('submit', async (event) => { | ||
event.preventDefault(); | ||
|
||
const {token, error} = await stripe.createToken(card); | ||
|
||
if (error) { | ||
// Inform the customer that there was an error. | ||
const errorElement = document.getElementById('card-errors'); | ||
errorElement.textContent = error.message; | ||
} else { | ||
// Send the token to your server. | ||
stripeTokenHandler(token); | ||
} | ||
}); | ||
|
||
const stripeTokenHandler = (token) => { | ||
// Insert the token ID into the form so it gets submitted to the server | ||
const form = document.querySelector('.meeting-form'); | ||
const hiddenInput = document.createElement('input'); | ||
hiddenInput.setAttribute('type', 'hidden'); | ||
hiddenInput.setAttribute('name', 'stripeToken'); | ||
hiddenInput.setAttribute('value', token.id); | ||
form.appendChild(hiddenInput); | ||
|
||
["brand", "exp_month", "exp_year", "last4"].forEach(function(field) { | ||
addFieldToForm(form, token, field); | ||
}); | ||
|
||
// Submit the form | ||
form.submit(); | ||
} | ||
|
||
function addFieldToForm(form, token, field) { | ||
var hiddenInput = document.createElement('input'); | ||
hiddenInput.setAttribute('type', 'hidden'); | ||
hiddenInput.setAttribute('name', "user[card_" + field + "]"); | ||
hiddenInput.setAttribute('value', token.card[field]); | ||
form.appendChild(hiddenInput); | ||
} | ||
} | ||
|
||
}); |
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,5 @@ | ||
/* | ||
*= require simple_calendar | ||
*= require trix | ||
*= require_tree . | ||
*/ |
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,6 @@ | ||
.simple-calendar { | ||
.prev-month, | ||
.next-month { | ||
background: #efefef; | ||
} | ||
} |
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,3 @@ | ||
// Place all the styles related to the comments controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
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,3 @@ | ||
// Place all the styles related to the Meetings controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
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,45 @@ | ||
class CommentsController < ApplicationController | ||
before_action :authenticate_user! # authenticate before anyone can comment who is not logged in. | ||
before_action :set_comment, only: [:edit, :update, :show, :destroy] | ||
before_action :set_meeting | ||
|
||
def new | ||
@comment = Comment.new | ||
end | ||
|
||
def create | ||
@comment = @meeting.comments.create(params[:comment].permit(:reply, :meeting_id)) | ||
@comment.user_id = current_user.id | ||
|
||
respond_to do |format| | ||
if @comment.save | ||
format.html { redirect_to meeting_path(@meeting) } | ||
format.js # renders create.js.erb | ||
else | ||
format.html { redirect_to meeting_path(@meeting), notice: "Your comment did not save. Please try again." } | ||
format.js | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
@comment = @meeting.comments.find(params[:id]) | ||
@comment.destroy | ||
redirect_to meeting_path(@meeting) | ||
end | ||
|
||
private | ||
|
||
def set_meeting | ||
@meeting = Meeting.find(params[:meeting_id]) | ||
end | ||
|
||
def set_comment | ||
@comment = Comment.find(params[:id]) | ||
end | ||
|
||
def comment_params | ||
params.require(:comment).permit(:reply) | ||
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,117 @@ | ||
class MeetingsController < ApplicationController | ||
before_action :authenticate_user! | ||
before_action :set_meeting, only: [:show, :edit, :update, :destroy] | ||
before_action :must_be_admin, only: [:active_sessions] | ||
|
||
# GET /meetings | ||
# GET /meetings.json | ||
def index | ||
if current_user.admin? | ||
@meetings = Meeting.all | ||
else | ||
@meetings = current_user.meetings.where(user_id: current_user) | ||
end | ||
end | ||
|
||
# GET /meetings/1 | ||
# GET /meetings/1.json | ||
def show | ||
@comment = Comment.new | ||
end | ||
|
||
# GET /meetings/new | ||
def new | ||
@meeting = Meeting.new | ||
end | ||
|
||
# GET /meetings/1/edit | ||
def edit | ||
end | ||
|
||
# POST /meetings | ||
# POST /meetings.json | ||
def create | ||
@meeting = Meeting.new(meeting_params) | ||
@meeting.user_id = current_user.id | ||
|
||
token = params[:stripeToken] | ||
card_brand = params[:user][:card_brand] | ||
card_exp_month = params[:user][:card_exp_month] | ||
card_exp_year = params[:user][:card_exp_year] | ||
card_last4 = params[:user][:card_last4] | ||
|
||
charge = Stripe::Charge.create( | ||
amount: 19900, | ||
currency: "usd", | ||
description: "Consultly", | ||
source: token | ||
) | ||
|
||
current_user.stripe_id = charge.id | ||
current_user.card_brand = card_brand | ||
current_user.card_exp_month = card_exp_month | ||
current_user.card_exp_year = card_exp_year | ||
current_user.card_last4 = card_last4 | ||
current_user.save! | ||
|
||
respond_to do |format| | ||
if @meeting.save | ||
format.html { redirect_to @meeting, notice: 'Meeting was successfully created.' } | ||
format.json { render :show, status: :created, location: @meeting } | ||
MeetingMailer.with(meeting: @meeting, user: current_user).meeting_scheduled.deliver_later | ||
else | ||
format.html { render :new } | ||
format.json { render json: @meeting.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
|
||
rescue Stripe::CardError => e | ||
flash.alert = e.message | ||
render action: :new | ||
end | ||
|
||
# PATCH/PUT /meetings/1 | ||
# PATCH/PUT /meetings/1.json | ||
def update | ||
respond_to do |format| | ||
if @meeting.update(meeting_params) | ||
format.html { redirect_to @meeting, notice: 'Meeting was successfully updated.' } | ||
format.json { render :show, status: :ok, location: @meeting } | ||
else | ||
format.html { render :edit } | ||
format.json { render json: @meeting.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
# DELETE /meetings/1 | ||
# DELETE /meetings/1.json | ||
def destroy | ||
@meeting.destroy | ||
respond_to do |format| | ||
format.html { redirect_to meetings_url, notice: 'Meeting was successfully destroyed.' } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
def active_sessions | ||
@active_sessions = Meeting.where("end_time > ?", Time.now) | ||
end | ||
|
||
private | ||
# Use callbacks to share common setup or constraints between actions. | ||
def set_meeting | ||
@meeting = Meeting.find(params[:id]) | ||
end | ||
|
||
# Never trust parameters from the scary internet, only allow the white list through. | ||
def meeting_params | ||
params.require(:meeting).permit(:name, :start_time, :end_time, :user_id) | ||
end | ||
|
||
def must_be_admin | ||
unless current_user.admin? | ||
redirect_to meetings_path, alert: "You don't have access to this page" | ||
end | ||
end | ||
end |
Oops, something went wrong.