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

Ft create recurring events 129620817 #192

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ public/uploads/tmp/*

/vendor/*

.DS_Store
# Ignore precompiled assets
/public/assets/*

#ignore test dir
test
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,6 @@ DEPENDENCIES
will_paginate (~> 3.0.6)
will_paginate-materialize
wkhtmltopdf-binary

BUNDLED WITH
1.12.5
34 changes: 30 additions & 4 deletions app/assets/javascripts/bind_event_to_preview_page.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
$(document).ready(function () {
var event_date = $('.parallax-container').data('countdown'),
end_date = $('.end_date').data('countdown'),
start_time = $('.start_time').data('countdown'),
end_time = $('.end_time').data('countdown'),
prev_color = '',
color = '',
map;

if (event_date) { countdown(convertDate(event_date)); }
if (event_date) { countdown(convertDate(event_date, start_time), end_date, end_time); }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NITPICK: This can be expanded out to more lines for better readability.


$('.preview').click(function () {
var map_val = $('#event_map_url').val(),
start_date = $('#event_start_date').val(),
end_date = $('#event_end_date').val();
end_date = $('#event_end_date').val(),
start_time = $('#event_start_time').val(),
end_time = $('#event_end_time').val(),
frequency = $('#event_recurring_event_attributes_frequency').val(),
week = $('#event_recurring_event_attributes_week').val(),
day = $('#event_recurring_event_attributes_day').val();

var rec_text;
if (frequency === 'Daily'){
rec_text = 'Every Day from ';
} else if (frequency === 'Weekly'){
rec_text = 'Every ' + day + ' from ';
} else if (frequency === 'Monthly'){
rec_text = 'Every ' + week + ' ' + day + ' of the Month, from ';
} else {
rec_text = '';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can make use of Switch-Case here for more optimization, as well as readability.

}

if (start_date) { countdown(convertDate(start_date, start_time), end_date, end_time); }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NITPICK: This can be expanded out to more lines for better readability.


if (start_date) { countdown(convertDate(start_date), end_date); }
if (map_val) {
map = map_val + '&output=embed';
} else {
Expand All @@ -26,7 +46,13 @@ $(document).ready(function () {
var title = $('#event_title').val() === '' ? 'Event title goes here' : $('#event_title').val();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NITPICK: avoid evaluating a DOM obj repeatedly, $('#event_title') can be assigned to a variable and then used concurrently after.

$('.our-event-title').html(title);
$('.our_event_description').html(description);
$('.our-event-date').html(start_date + ' to ' + end_date);
if (rec_text !== ''){
$('.our-event-date').html(start_date + ' - ' + end_date);
$('.our-event-time').html(rec_text + start_time + ' to ' + end_time);
} else {
$('.our-event-date').html(start_date + ', ' + start_time + ' - ' + end_date + ', ' + end_time);
$('.our-event-time').html('');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NITPICK: $('.our-event-date') and $('.our-event-time') can be assigned to variables for multiple usage.

}
$('.landing2').removeClass(prev_color);
$('.landing2').addClass(color);
$('.our-event-map-url').attr({ 'src': map });
Expand Down
33 changes: 27 additions & 6 deletions app/assets/javascripts/countdown.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
function convertDate(startdate) {
function convertDate(startDate, startTime) {
var date = new Date();
var dateStr = startdate.toString();
var date2 = new Date(dateStr.replace(/-/g, '/'));
var date2 = new Date(startDate);
var apm = startTime.toString().split(':')[1].match(/^(\d+)([A|P]M)$/)[2];
if (apm === 'AM'){
date2.setHours(startTime.split(':')[0]);
} else {
date2.setHours(+startTime.split(':')[0] + 12);
}
date2.setMinutes(startTime.split(':')[1].match(/^(\d+)[A|P]M$/)[1]);
var diff = Math.floor((date2 - date) / (60 * 1000));
return diff;
}
function countdown(val) {

function countdown(val, end_date, end_time) {
var endDate = new Date(end_date);
var apm = end_time.toString().split(':')[1].match(/^(\d+)([A|P]M)$/)[2];
if (apm === 'AM'){
endDate.setHours(end_time.split(':')[0]);
} else {
endDate.setHours(+end_time.split(':')[0] + 12);
}
endDate.setMinutes(end_time.split(':')[1].match(/^(\d+)[A|P]M$/)[1]);

var minutes = val;

$('#counter').css({
'font-size': '3rem',
'padding': '0 10px',
'color': '#fff',
'z-index': '100',
'background-color': 'rgba(0,0,0,0.2)'
});
if (minutes > 1) {

if (minutes > 0) {
function tick() {
var seconds = 60;
var mins = minutes;
Expand All @@ -35,7 +53,10 @@ function countdown(val) {
}
}
tick();
} else {
} else if ((new Date()) > endDate) {
counter.innerHTML = 'This event has ended';
} else {
counter.innerHTML = 'This event has started';
}

}
2 changes: 1 addition & 1 deletion app/assets/javascripts/materialize.min.js

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions app/assets/javascripts/recurring_events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
$(document).ready( function () {

$('.event-time-picker').pickatime({ twelvehour: true });
$('.event-time-picker').pickatime({ twelvehour: true });

$('.recur-lever').on('click', function (){
var status = !$('.recur-event').prop('checked');
if (status){
$('.recurring_event_space').removeClass('display-none');
} else {
$('.recurring_event_space').addClass('display-none');
$('.week-frequency').addClass('display-none');
$('.day-frequency').addClass('display-none');
$('#event_recurring_event_attributes_frequency').val('');
$('#event_recurring_event_attributes_week').val('');
$('#event_recurring_event_attributes_day').val('');
}
});

$('#event_recurring_event_attributes_frequency').on('change', function (){
if (this.value === 'Weekly'){
$('.week-frequency').addClass('display-none');
$('.day-frequency').removeClass('display-none');
$('#event_recurring_event_attributes_day').val('');
$('#event_recurring_event_attributes_week').val('');
} else if (this.value === 'Monthly') {
$('.week-frequency').removeClass('display-none');
$('.day-frequency').removeClass('display-none');
$('#event_recurring_event_attributes_day').val('');
$('#event_recurring_event_attributes_week').val('');
} else {
$('.week-frequency').addClass('display-none');
$('.day-frequency').addClass('display-none');
$('#event_recurring_event_attributes_day').val('');
$('#event_recurring_event_attributes_week').val('');
}
});

});
4 changes: 3 additions & 1 deletion app/assets/stylesheets/application.css.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ select .browser-default, #event_category_id {

.closecocoon {padding-top: 4.2% !important;}

.close-cocoon {padding-top: 3.0% !important;}

#highlight-view {
margin-top: 40px;
margin-bottom: 40px;
Expand Down Expand Up @@ -257,7 +259,7 @@ select .browser-default, #event_category_id {

.side-nav.right {
float: left;
padding-left: -20px;
padding-left: -20px;
}

.poptext {
Expand Down
14 changes: 12 additions & 2 deletions app/assets/stylesheets/events.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ input#event_photo_upload {display: none;}

::-webkit-input-placeholder {color: rgba(101,104,109,0.8);}

:-moz-placeholder {
:-moz-placeholder {
/* Firefox 18- */
color: rgba(101,104,109,0.8);
}

::-moz-placeholder {
::-moz-placeholder {
/* Firefox 19+ */
color: rgba(101,104,109,0.8);
}
Expand Down Expand Up @@ -393,3 +393,13 @@ input#event_photo_upload {display: none;}
}

.dashboard-pagination {margin: 15px;}

.recurring-event{
margin: 10px 0;
padding: 10px !important;
border: 1px solid #CCCCCC;
}

.display-none{
display: none;
}
1 change: 1 addition & 0 deletions app/controllers/bookings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def index
end

def create
# binding.pry
@booking = Booking.create(event: @event, user: current_user)
tickets = []
ticket_params.each do |ticket_type_id, quantity|
Expand Down
24 changes: 22 additions & 2 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class EventsController < ApplicationController

def new
@event = Event.new.decorate
build_recurring_event
@event.ticket_types.build
@roles = Event.get_roles
end
Expand All @@ -35,13 +36,15 @@ def show
@booking = @event.bookings.new
@booking.user = current_user
@event_ticket = @event.ticket_types
@recurring_event = @event.recurring_event unless @event.recurring_event.nil?
1.times { @booking.user_tickets.build }
respond_with @event
end

def edit
@roles = Event.get_roles
@highlights = @event.highlights
build_recurring_event unless @event.recurring_event
end

def enable
Expand Down Expand Up @@ -78,6 +81,7 @@ def create
flash[:notice] = if @event.save
create_successful_message("event")
else
build_recurring_event
@event.errors.full_messages.join("; ")
end
respond_with(@event)
Expand Down Expand Up @@ -126,11 +130,23 @@ def search_params

def event_params
params.require(:event).permit(
:title, :description, :start_date, :end_date, :category_id, :location,
:venue, :image, :template_id, :map_url, :event_template_id,
:title,
:description,
:start_date,
:end_date,
:start_time,
:end_time,
:category_id,
:location,
:venue,
:image,
:template_id,
:map_url,
:event_template_id,
ticket_types_attributes: [:id, :_destroy, :name, :quantity, :price],
highlights_attributes: [:id, :_destroy, :day, :title, :description,
:start_time, :end_time, :image, :image_title],
recurring_event_attributes: [:id, :_destroy, :frequency, :day, :week],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Nice indentation. good readability.

event_staffs_attributes: [:user_id, :role]
)
end
Expand Down Expand Up @@ -158,4 +174,8 @@ def subscription_status

def loading
end

def build_recurring_event
@event.build_recurring_event
end
end
2 changes: 1 addition & 1 deletion app/controllers/sponsors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class SponsorsController < ApplicationController
before_action :find_event, :all_sponsors
before_action :find_sponsor, only: [:edit, :update, :destroy]
respond_to :html, :js

layout "admin"
def index
@sponsors = @event.sponsors.group_by(&:level)
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/welcome_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ def index
respond_with @events
end

def about
end

def faq
end

Expand Down
14 changes: 12 additions & 2 deletions app/decorators/event_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ def image_url(version)

def start_date
return object.start_date.strftime("%b %d %Y") if object.start_date?
Time.zone.now.strftime("%b %d %Y")
# Time.zone.now.strftime("%b %d %Y")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid commenting obsolete codes... this is a candidate for removal.

end

def start_time
return object.start_time.strftime("%I:%M%p") if object.start_time?
# Time.now.strftime("%I:%M%p")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid commenting obsolete codes... this is a candidate for removal.

end

def event_template
Expand All @@ -28,7 +33,12 @@ def sponsors

def end_date
return object.end_date.strftime("%b %d %Y") if object.end_date?
Time.zone.now.strftime("%b %d %Y")
# Time.zone.now.strftime("%b %d %Y")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid commenting obsolete codes... this is a candidate for removal.

end

def end_time
return object.end_time.strftime("%I:%M%p") if object.end_time?
# Time.now.strftime("%I:%M%p")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid commenting obsolete codes... this is a candidate for removal.

end

def get_event_staffs
Expand Down
11 changes: 11 additions & 0 deletions app/helpers/events_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ def cummulative_rating(event)

private

def display_event_frequency(recurring_event)
if recurring_event.frequency == "Daily"
"Every Day from "
elsif recurring_event.frequency == "Weekly"
"Every " + recurring_event.day + " from "
else
"Every " + recurring_event.week + " " +
recurring_event.day + " of the Month, from "
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can make use of case-switch here.

end

def converter(amt)
number_to_currency(amt, unit: "$")
end
Expand Down
5 changes: 5 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Event < ActiveRecord::Base
has_many :ticket_types, dependent: :destroy
has_many :event_staffs, dependent: :destroy
has_many :highlights, dependent: :destroy
has_one :recurring_event, dependent: :destroy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for readability purposes... similar associations can be grouped... all has_many together .... and etc.

has_many :staffs, through: :event_staffs, source: "user"
accepts_nested_attributes_for :ticket_types,
allow_destroy: true, reject_if: :all_blank
Expand All @@ -13,6 +14,8 @@ class Event < ActiveRecord::Base
reject_if: :invalid_staff_info
accepts_nested_attributes_for :highlights,
allow_destroy: true, reject_if: :all_blank
accepts_nested_attributes_for :recurring_event,
allow_destroy: true, reject_if: :all_blank
has_many :bookings
has_many :user_tickets, through: :bookings
has_many :attendees, through: :bookings, source: "user"
Expand All @@ -32,6 +35,8 @@ class Event < ActiveRecord::Base
validates :description, presence: true, length: { in: 20..1000 }
validates :start_date, presence: true
validates :end_date, presence: true
validates :start_time, presence: true
validates :end_time, presence: true
validates :category_id, presence: true
validates :ticket_types, presence: true

Expand Down
10 changes: 10 additions & 0 deletions app/models/recurring_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class RecurringEvent < ActiveRecord::Base
belongs_to :event

FREQUENCY = %w(Daily Weekly Monthly).freeze
WEEK = %w(First Second Third Fourth).freeze
DAY = %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday).freeze

validates :day, presence: true, if: "frequency == 'Weekly'"
validates :week, presence: true, if: "frequency == 'Monthly'"
end
Loading