Skip to content

Commit bb06c27

Browse files
author
Silvan T. Golega
committed
header of page: headline, info about current week, links to next and previous weeks
1 parent de2d6ed commit bb06c27

File tree

6 files changed

+81
-7
lines changed

6 files changed

+81
-7
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.haswidthofcontents {
2+
/* http://foohack.com/2007/11/cross-browser-support-for-inline-block-styling/ */
3+
display:-moz-inline-stack;
4+
display:inline-block;
5+
zoom:1;
6+
*display:inline;
7+
}
8+
9+
h1 {
10+
text-align: center;
11+
text-transform: uppercase;
12+
}
13+
h2 {
14+
text-align: center;
15+
font-variant: small-caps;
16+
}
17+
.navigation {
18+
text-align: center;
19+
position: relative;
20+
margin: 20px;
21+
.left, .center, .right {
22+
display: inline-block;
23+
}
24+
.left, .right {
25+
position: absolute;
26+
}
27+
.left {
28+
left: 0px;
29+
}
30+
.right {
31+
right: 0px;
32+
}
33+
}

app/controllers/application_controller.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ def abbr
2020
def date
2121
@year = params[:year]
2222
@week = params[:week]
23+
@monday = Week.get_monday @year, @week
24+
@next_week = Week.next_week @year, @week
25+
@previous_week = Week.previous_week @year, @week
2326
@workers = Worker.all
2427
@projects = Project.all
2528
@new_worker = Worker.new

app/models/week.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ def self.included(base)
99
end
1010
end
1111

12+
def self.get_monday year, week
13+
Date.commercial(year.to_i, week.to_i, 1)
14+
end
15+
1216
# returns true if object responds to from_year, from_week and attributes
1317
def is_week_model?
1418
return self.respond_to?(:from_year) &&
@@ -19,16 +23,24 @@ def is_week_model?
1923
self.attributes.respond_to?(:to_a)
2024
end
2125

26+
def self.previous_week year, week
27+
previous_week = Week.get_monday(year, week) - 1.week
28+
{:year => previous_week.cwyear, :week => previous_week.cweek}
29+
end
30+
31+
def self.next_week year, week
32+
next_week = Week.get_monday(year, week) + 1.week
33+
{:year => next_week.cwyear, :week => next_week.cweek}
34+
end
35+
2236
def previous_week
2337
return nil unless self.is_week_model?
24-
previous_week = Date.commercial(self.from_year, self.from_week, 1) - 1.week
25-
{:year => previous_week.cwyear, :week => previous_week.cweek}
38+
Week.previous_week self.from_year, self.from_week
2639
end
2740

2841
def next_week
2942
return nil unless self.is_week_model?
30-
next_week = Date.commercial(self.from_year, self.from_week, 1) + 1.week
31-
{:year => next_week.cwyear, :week => next_week.cweek}
43+
Week.next_week self.from_year, self.from_week
3244
end
3345

3446
# find the last previous item where all belongs_to relations have the same targets

app/views/layouts/_header.html.erb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<h1>Caps</h1>
2+
<h2>Capacity Planner</h2>
3+
<div class="navigation">
4+
<div class="left">
5+
<%= link_to t(:'layout.previous_week'),
6+
url_for(:year => @previous_week[:year], :week => @previous_week[:week]) %>
7+
</div>
8+
<div class="center">
9+
<div><%= t :'layout.showing_week_of_year', {:year => @year, :week => @week, :date => @date} %></div>
10+
<div><%= t :'layout.week_starts_at', :date => l(@monday, :format => :long) %></div>
11+
<div><%= t :'layout.today_is',
12+
{ :weekday => l(Date.today, :format => "%A"),
13+
:date => l(Date.today, :format => :long)} %></div>
14+
</div>
15+
<div class="right">
16+
<%= link_to t(:'layout.next_week'),
17+
url_for(:year => @next_week[:year], :week => @next_week[:week]) %>
18+
</div>
19+
</div>

app/views/layouts/application.html.erb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
<%= csrf_meta_tags %>
88
</head>
99
<body>
10-
11-
<%= yield %>
12-
10+
<div class="haswidthofcontents">
11+
<%= render "layouts/header" %>
12+
<%= yield %>
13+
</div>
1314
</body>
1415
</html>

config/locales/en.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ en:
55
total_assignments: "Total Assignments"
66
availability: "Availability"
77
workload: "Workload"
8+
layout:
9+
showing_week_of_year: "Showing week %{week} of year %{year}."
10+
week_starts_at: "This work week starts on Monday, %{date}"
11+
today_is: "Today is %{weekday}, %{date}"
12+
next_week: "Next week"
13+
previous_week: "Previous week"

0 commit comments

Comments
 (0)