Skip to content

Commit

Permalink
#32 fixed these issues: 'showing events', 'adding new event' and adde…
Browse files Browse the repository at this point in the history
…d documentation
  • Loading branch information
mohamed-moubarak committed May 2, 2015
1 parent 10d2992 commit 0604d5e
Show file tree
Hide file tree
Showing 11 changed files with 31,170 additions and 113 deletions.
4 changes: 0 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
yaml_db (0.3.0)
rails (>= 3.0, < 4.3)
rake (>= 0.8.7)

PLATFORMS
ruby
Expand All @@ -204,4 +201,3 @@ DEPENDENCIES
uglifier (>= 1.3.0)
validates_timeliness (~> 3.0)
web-console (~> 2.0)
yaml_db
79 changes: 49 additions & 30 deletions app/assets/stylesheets/events_stylesheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
margin-right: auto;
border-collapse: collapse;
}

th.left-border {
border-left: 1px solid black;
}

/*Styling days name header*/
.cal table > thead > tr > th {
border-left: 1px solid white;
}
Expand All @@ -32,11 +28,11 @@ th.left-border {
text-align: center;
font-size: 30px;
}

/*Styling the calendar row*/
.cal table > tbody > tr {
border: 1px solid cornflowerblue;
}

/*Styling the calendar borders*/
.cal table > tbody > tr > td {
border: 1px solid grey;
}
Expand All @@ -51,22 +47,22 @@ th.left-border {
text-align: center;
background-color: white;
}

/*Styling the calendar previous month*/
.prev-month {
background-color: lavender;
}

/*Styling the calendar next month*/
.next-month {
background-color: silver;
}

/*Styling the calendar buttons*/
.links {
border-radius: 10px;
border: 1px solid grey;
width: 100px;
text-align: center;
}

/*Styling the buttons table*/
td.links {
border-collapse: collapse;
border-radius: 10px;
Expand All @@ -76,65 +72,88 @@ td.links {
background-color: cornflowerblue;
color: white;
}

/*Styling the calendar header, *Month names* */
.calendar-header {
color: black;
color: #204056;
}

/*Styling the calendar header, h1*/
h1.schedule-title {
margin-left: 40%;
margin-left: auto;
font-size: 30px;

}

/* unvisited link */
/* unvisited link calendar buttons*/
.links a:link {
color: white;
}

/* visited link */
/* visited link calendar buttons */
.links a:visited {
color: white;
}

/* mouse over link */
/* mouse over link calendar buttons */
.links a:hover {
color: white;
}

/* selected link */
/* selected link calendar buttons */
.links a:active {
color: white;
}

/* unvisited link prev and next buttons*/
.calendar-header a:link {
color: black;
color: #204056;
}

/* visited link */
/* visited link prev and next buttons*/
.calendar-header a:visited {
color: black;
color: #204056;
}

/* mouse over link */
/* mouse over link prev and next buttons*/
.calendar-header a:hover {
color: black;
color: #204056;
}

/* selected link */
/* selected link prev and next buttons*/
.calendar-header a:active {
color: black;
color: #204056;
}
/* unvisited link event*/
.event a:link {
color: red;
text-decoration: none;
}

/* visited link event*/
.event a:visited {
color: red;
text-decoration: none;
}

/* mouse over link event*/
.event a:hover {
color: red;
text-decoration: none;
}

/* selected link event*/
.event a:active {
color: red;
text-decoration: none;
}
/* event styling*/
.event {
color: red;
font-weight: normal;
}

/* current month styling*/
.current-month {
color: black;
}

/* today styling*/
.today {
font-weight: bold;
font-size: 15px;
}
77 changes: 34 additions & 43 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,19 @@ def edit
# POST /events.json
def create


#creating new event with parameters
@event = Event.new(event_params)



#set the new event's current user and register
@event.User= current_user
@event.Register = Register.where(:name => @event.pet_name).first
buddies = Buddy.where(:user => current_user)
buddy_pets = []
buddy_pet = nil

# Start of the addition of records to food table
#counters= starting/ending dates.
#time is the dy and time for feeding to happen.
counter = @event.starts_at
counter2= @event.ends_at
time = @event.time
while counter<counter2 do
while counter<=counter2 do
counter=counter+1.day
time =time+1.day
amount_inbowl= @event.amount
Expand All @@ -65,18 +61,13 @@ def create
:ate => ate_random, :leftovers => left, :time => time)
end
# end of adding records to food table , Karim Farid.
buddies.each do |buddy|
if buddy.register == pet then
buddy_pet = pet
end
end
if pet.nil? || (!current_user.registers.include?(pet) && buddy_pet.nil?)
#Check conditions for creating events
buddy_pet = Buddy.where(:user => current_user, :register => @event.Register).first
if !editing_destroying_filter_condition then

flash[:notice] = "Check pet's name is correct!"
flash[:notice] = "Check pet's name is correct or you can create events for this pet!"
redirect_to new_event_path
else
else
respond_to do |format|
if @event.save
format.html { redirect_to @event, notice: 'Event was successfully created.' }
Expand All @@ -86,10 +77,10 @@ def create
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end

end
end
end


# PATCH/PUT /events/1
# PATCH/PUT /events/1.json
def update
Expand All @@ -115,30 +106,30 @@ def destroy
end

private
# Use callbacks to share common setup or constraints between actions.
def set_event
@event = Event.find(params[:id])
end


def pet
current_user.registers.find_by name: @event.pet_name
end

# Never trust parameters from the scary internet, only allow the white list through.
def event_params
params.require(:event).permit(:pet_name, :amount, :starts_at, :ends_at, :time)
end
# Use callbacks to share common setup or constraints between actions.
def set_event
@event = Event.find(params[:id])
end

def editing_destroying_filter_condition
buddy_pet = Buddy.where(:user => current_user, :register => @event.Register).first
((!@event.Register.nil? && @event.Register.User == current_user) || (!buddy_pet.nil? && buddy_pet.can_schedule))
end
#find the current user's pet.
def pet
current_user.registers.find_by name: @event.pet_name
end

def editing_destroying_filter
unless editing_destroying_filter_condition
flash[:notice] = "You're not authorized to edit or delete!"
redirect_to events_path
end
end
end
# Never trust parameters from the scary internet, only allow the white list through.
def event_params
params.require(:event).permit(:pet_name, :amount, :starts_at, :ends_at, :time)
end
#condition for creating, editing, destroying privilages.
def editing_destroying_filter_condition
buddy_pet = Buddy.where(:user => current_user, :register => @event.Register).first
((!@event.Register.nil? && @event.Register.User == current_user) || (!buddy_pet.nil? && buddy_pet.can_schedule))
end
#filter for creating, editing and destroying
def editing_destroying_filter
unless editing_destroying_filter_condition
flash[:notice] = "You're not authorized to edit or delete!"
redirect_to events_path
end
end
end
17 changes: 17 additions & 0 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
<%#- Feeding_scehdule_form__view/Mohamed-Moubarak -%>

<div class="menu">
<div class="mm">



<div class="sign up">
<ul >
<!--links go here-->
<li><%= link_to 'My Pets' , registers_path %></li>
<li><%=link_to 'New Device', devices_path %></li>
<li><%=link_to 'New Reminder', new_reminder_path %></li>
<li><%=link_to 'My schedule', events_path %></li>
</ul>
</div> </div>
</div>

<%= form_for(@event) do |f| %>
<% if @event.errors.any? %>
<div id="error_explanation">
Expand Down
41 changes: 29 additions & 12 deletions app/views/events/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,43 +1,60 @@
<%#- Feeding_scehdule_index_view/Mohamed-Moubarak -%>

<link href='../app/assets/stylesheets/events_stylesheet.css' rel='stylesheet'>
<%#- Nav bar -%>
<div class="menu">
<div class="mm">



<div class="sign up">
<ul >
<!--links go here-->
<li><%= link_to 'My Pets' , registers_path %></li>
<li><%=link_to 'New Device', devices_path %></li>
<li><%=link_to 'New Reminder', new_reminder_path %></li>
<li><%=link_to 'My Schedule', events_path %></li>
</ul>
</div> </div>
</div>
<%#- notice -%>
<p id="notice"><%= notice %></p>

<h1 class="schedule-title">Feeding Schedule</h1>
<div class="cal">
<%= month_calendar do |date| %>
<%= month_calendar do |date| %><%#- month calendar genrating loop -%>
<div>
<%= date.day %>
<% counter = 0 %>
<% Event.all.each do |event| %>
<% Event.all.each do |event| %> <%#- generating events according to date -%>
<% buddy_pet = Buddy.where(:user => current_user, :register => event.Register).first %>
<% if (!event.Register.nil? && event.User == current_user) || (current_user.registers.include?(event.Register)) || (!buddy_pet.nil? && current_user == buddy_pet.user)%>
<% if event.starts_at <= date && event.ends_at >= date%>
<% counter += 1 %>
<% if event.starts_at <= date && event.ends_at >= date %> <%#- adding events related to date -%>
<% counter += 1 %>
<% if counter!= 0 %>
<div class="event">
<%= link_to ("Feed "+ event.pet_name + " " + event.amount.to_s + " gms."), event%>
</div>
<% end %>
<% end %>
<% end %>
<% end %>
<div class="event">
<% if counter!= 0 %>
<%= "You have " + counter.to_s + " events" %>
<% end %>
</div>
</div>
<% end %>
<br>
</div>

<table style="margin: auto;">
<table style="margin: auto;">
<tr>
<td class="links">
<div>
<%= link_to 'New Event', new_event_path %>
<%= link_to 'New Event', new_event_path %> <%#- New event button -%>
</div>
</td>
<td class="links">
<div>
<%= link_to 'Back', feeds_path %>
<%= link_to 'Back', feeds_path %> <%#- back button linking to feeds path -%>
</div>
</td>
</tr>
Expand Down
Loading

0 comments on commit 0604d5e

Please sign in to comment.