Skip to content

Commit 0604d5e

Browse files
#32 fixed these issues: 'showing events', 'adding new event' and added documentation
1 parent 10d2992 commit 0604d5e

File tree

11 files changed

+31170
-113
lines changed

11 files changed

+31170
-113
lines changed

Gemfile.lock

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@ GEM
177177
binding_of_caller (>= 0.7.2)
178178
railties (>= 4.0)
179179
sprockets-rails (>= 2.0, < 4.0)
180-
yaml_db (0.3.0)
181-
rails (>= 3.0, < 4.3)
182-
rake (>= 0.8.7)
183180

184181
PLATFORMS
185182
ruby
@@ -204,4 +201,3 @@ DEPENDENCIES
204201
uglifier (>= 1.3.0)
205202
validates_timeliness (~> 3.0)
206203
web-console (~> 2.0)
207-
yaml_db

app/assets/stylesheets/events_stylesheet.css

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
margin-right: auto;
77
border-collapse: collapse;
88
}
9-
10-
th.left-border {
11-
border-left: 1px solid black;
12-
}
13-
9+
/*Styling days name header*/
1410
.cal table > thead > tr > th {
1511
border-left: 1px solid white;
1612
}
@@ -32,11 +28,11 @@ th.left-border {
3228
text-align: center;
3329
font-size: 30px;
3430
}
35-
31+
/*Styling the calendar row*/
3632
.cal table > tbody > tr {
3733
border: 1px solid cornflowerblue;
3834
}
39-
35+
/*Styling the calendar borders*/
4036
.cal table > tbody > tr > td {
4137
border: 1px solid grey;
4238
}
@@ -51,22 +47,22 @@ th.left-border {
5147
text-align: center;
5248
background-color: white;
5349
}
54-
50+
/*Styling the calendar previous month*/
5551
.prev-month {
5652
background-color: lavender;
5753
}
58-
54+
/*Styling the calendar next month*/
5955
.next-month {
6056
background-color: silver;
6157
}
62-
58+
/*Styling the calendar buttons*/
6359
.links {
6460
border-radius: 10px;
6561
border: 1px solid grey;
6662
width: 100px;
6763
text-align: center;
6864
}
69-
65+
/*Styling the buttons table*/
7066
td.links {
7167
border-collapse: collapse;
7268
border-radius: 10px;
@@ -76,65 +72,88 @@ td.links {
7672
background-color: cornflowerblue;
7773
color: white;
7874
}
79-
75+
/*Styling the calendar header, *Month names* */
8076
.calendar-header {
81-
color: black;
77+
color: #204056;
8278
}
83-
79+
/*Styling the calendar header, h1*/
8480
h1.schedule-title {
85-
margin-left: 40%;
81+
margin-left: auto;
8682
font-size: 30px;
87-
8883
}
8984

90-
/* unvisited link */
85+
/* unvisited link calendar buttons*/
9186
.links a:link {
9287
color: white;
9388
}
9489

95-
/* visited link */
90+
/* visited link calendar buttons */
9691
.links a:visited {
9792
color: white;
9893
}
9994

100-
/* mouse over link */
95+
/* mouse over link calendar buttons */
10196
.links a:hover {
10297
color: white;
10398
}
10499

105-
/* selected link */
100+
/* selected link calendar buttons */
106101
.links a:active {
107102
color: white;
108103
}
109-
104+
/* unvisited link prev and next buttons*/
110105
.calendar-header a:link {
111-
color: black;
106+
color: #204056;
112107
}
113108

114-
/* visited link */
109+
/* visited link prev and next buttons*/
115110
.calendar-header a:visited {
116-
color: black;
111+
color: #204056;
117112
}
118113

119-
/* mouse over link */
114+
/* mouse over link prev and next buttons*/
120115
.calendar-header a:hover {
121-
color: black;
116+
color: #204056;
122117
}
123118

124-
/* selected link */
119+
/* selected link prev and next buttons*/
125120
.calendar-header a:active {
126-
color: black;
121+
color: #204056;
122+
}
123+
/* unvisited link event*/
124+
.event a:link {
125+
color: red;
126+
text-decoration: none;
127+
}
128+
129+
/* visited link event*/
130+
.event a:visited {
131+
color: red;
132+
text-decoration: none;
127133
}
128134

135+
/* mouse over link event*/
136+
.event a:hover {
137+
color: red;
138+
text-decoration: none;
139+
}
140+
141+
/* selected link event*/
142+
.event a:active {
143+
color: red;
144+
text-decoration: none;
145+
}
146+
/* event styling*/
129147
.event {
130148
color: red;
131149
font-weight: normal;
132150
}
133-
151+
/* current month styling*/
134152
.current-month {
135153
color: black;
136154
}
137-
155+
/* today styling*/
138156
.today {
139157
font-weight: bold;
158+
font-size: 15px;
140159
}

app/controllers/events_controller.rb

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,19 @@ def edit
3838
# POST /events.json
3939
def create
4040

41-
41+
#creating new event with parameters
4242
@event = Event.new(event_params)
43-
44-
45-
43+
#set the new event's current user and register
4644
@event.User= current_user
4745
@event.Register = Register.where(:name => @event.pet_name).first
48-
buddies = Buddy.where(:user => current_user)
49-
buddy_pets = []
50-
buddy_pet = nil
46+
5147
# Start of the addition of records to food table
5248
#counters= starting/ending dates.
5349
#time is the dy and time for feeding to happen.
5450
counter = @event.starts_at
5551
counter2= @event.ends_at
5652
time = @event.time
57-
while counter<counter2 do
53+
while counter<=counter2 do
5854
counter=counter+1.day
5955
time =time+1.day
6056
amount_inbowl= @event.amount
@@ -65,18 +61,13 @@ def create
6561
:ate => ate_random, :leftovers => left, :time => time)
6662
end
6763
# end of adding records to food table , Karim Farid.
68-
buddies.each do |buddy|
69-
if buddy.register == pet then
70-
buddy_pet = pet
71-
end
72-
end
73-
if pet.nil? || (!current_user.registers.include?(pet) && buddy_pet.nil?)
64+
#Check conditions for creating events
7465
buddy_pet = Buddy.where(:user => current_user, :register => @event.Register).first
7566
if !editing_destroying_filter_condition then
7667

77-
flash[:notice] = "Check pet's name is correct!"
68+
flash[:notice] = "Check pet's name is correct or you can create events for this pet!"
7869
redirect_to new_event_path
79-
else
70+
else
8071
respond_to do |format|
8172
if @event.save
8273
format.html { redirect_to @event, notice: 'Event was successfully created.' }
@@ -86,10 +77,10 @@ def create
8677
format.json { render json: @event.errors, status: :unprocessable_entity }
8778
end
8879
end
89-
90-
end
80+
end
9181
end
9282

83+
9384
# PATCH/PUT /events/1
9485
# PATCH/PUT /events/1.json
9586
def update
@@ -115,30 +106,30 @@ def destroy
115106
end
116107

117108
private
118-
# Use callbacks to share common setup or constraints between actions.
119-
def set_event
120-
@event = Event.find(params[:id])
121-
end
122-
123-
124-
def pet
125-
current_user.registers.find_by name: @event.pet_name
126-
end
127-
128-
# Never trust parameters from the scary internet, only allow the white list through.
129-
def event_params
130-
params.require(:event).permit(:pet_name, :amount, :starts_at, :ends_at, :time)
131-
end
109+
# Use callbacks to share common setup or constraints between actions.
110+
def set_event
111+
@event = Event.find(params[:id])
112+
end
132113

133-
def editing_destroying_filter_condition
134-
buddy_pet = Buddy.where(:user => current_user, :register => @event.Register).first
135-
((!@event.Register.nil? && @event.Register.User == current_user) || (!buddy_pet.nil? && buddy_pet.can_schedule))
136-
end
114+
#find the current user's pet.
115+
def pet
116+
current_user.registers.find_by name: @event.pet_name
117+
end
137118

138-
def editing_destroying_filter
139-
unless editing_destroying_filter_condition
140-
flash[:notice] = "You're not authorized to edit or delete!"
141-
redirect_to events_path
142-
end
143-
end
144-
end
119+
# Never trust parameters from the scary internet, only allow the white list through.
120+
def event_params
121+
params.require(:event).permit(:pet_name, :amount, :starts_at, :ends_at, :time)
122+
end
123+
#condition for creating, editing, destroying privilages.
124+
def editing_destroying_filter_condition
125+
buddy_pet = Buddy.where(:user => current_user, :register => @event.Register).first
126+
((!@event.Register.nil? && @event.Register.User == current_user) || (!buddy_pet.nil? && buddy_pet.can_schedule))
127+
end
128+
#filter for creating, editing and destroying
129+
def editing_destroying_filter
130+
unless editing_destroying_filter_condition
131+
flash[:notice] = "You're not authorized to edit or delete!"
132+
redirect_to events_path
133+
end
134+
end
135+
end

app/views/events/_form.html.erb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11

22
<%#- Feeding_scehdule_form__view/Mohamed-Moubarak -%>
3+
4+
<div class="menu">
5+
<div class="mm">
6+
7+
8+
9+
<div class="sign up">
10+
<ul >
11+
<!--links go here-->
12+
<li><%= link_to 'My Pets' , registers_path %></li>
13+
<li><%=link_to 'New Device', devices_path %></li>
14+
<li><%=link_to 'New Reminder', new_reminder_path %></li>
15+
<li><%=link_to 'My schedule', events_path %></li>
16+
</ul>
17+
</div> </div>
18+
</div>
19+
320
<%= form_for(@event) do |f| %>
421
<% if @event.errors.any? %>
522
<div id="error_explanation">

app/views/events/index.html.erb

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,60 @@
11
<%#- Feeding_scehdule_index_view/Mohamed-Moubarak -%>
2+
23
<link href='../app/assets/stylesheets/events_stylesheet.css' rel='stylesheet'>
4+
<%#- Nav bar -%>
5+
<div class="menu">
6+
<div class="mm">
7+
8+
39

10+
<div class="sign up">
11+
<ul >
12+
<!--links go here-->
13+
<li><%= link_to 'My Pets' , registers_path %></li>
14+
<li><%=link_to 'New Device', devices_path %></li>
15+
<li><%=link_to 'New Reminder', new_reminder_path %></li>
16+
<li><%=link_to 'My Schedule', events_path %></li>
17+
</ul>
18+
</div> </div>
19+
</div>
20+
<%#- notice -%>
421
<p id="notice"><%= notice %></p>
522

623
<h1 class="schedule-title">Feeding Schedule</h1>
724
<div class="cal">
8-
<%= month_calendar do |date| %>
25+
<%= month_calendar do |date| %><%#- month calendar genrating loop -%>
926
<div>
1027
<%= date.day %>
1128
<% counter = 0 %>
12-
<% Event.all.each do |event| %>
29+
<% Event.all.each do |event| %> <%#- generating events according to date -%>
1330

1431
<% buddy_pet = Buddy.where(:user => current_user, :register => event.Register).first %>
1532
<% if (!event.Register.nil? && event.User == current_user) || (current_user.registers.include?(event.Register)) || (!buddy_pet.nil? && current_user == buddy_pet.user)%>
16-
<% if event.starts_at <= date && event.ends_at >= date%>
17-
<% counter += 1 %>
33+
<% if event.starts_at <= date && event.ends_at >= date %> <%#- adding events related to date -%>
34+
<% counter += 1 %>
35+
<% if counter!= 0 %>
36+
<div class="event">
37+
<%= link_to ("Feed "+ event.pet_name + " " + event.amount.to_s + " gms."), event%>
38+
</div>
39+
<% end %>
1840
<% end %>
1941
<% end %>
2042
<% end %>
21-
<div class="event">
22-
<% if counter!= 0 %>
23-
<%= "You have " + counter.to_s + " events" %>
24-
<% end %>
25-
</div>
2643
</div>
2744
<% end %>
2845
<br>
2946
</div>
3047

31-
<table style="margin: auto;">
48+
<table style="margin: auto;">
3249
<tr>
3350
<td class="links">
3451
<div>
35-
<%= link_to 'New Event', new_event_path %>
52+
<%= link_to 'New Event', new_event_path %> <%#- New event button -%>
3653
</div>
3754
</td>
3855
<td class="links">
3956
<div>
40-
<%= link_to 'Back', feeds_path %>
57+
<%= link_to 'Back', feeds_path %> <%#- back button linking to feeds path -%>
4158
</div>
4259
</td>
4360
</tr>

0 commit comments

Comments
 (0)