Commit f9a97f30 authored by David F.'s avatar David F.
Browse files

Merge branch '27-changement-titres-fixes-menus' into 'master'

Resolve "Changement de titres fixes des menus"

See merge request !21
parents 50e02bf5 e43dc13e
......@@ -51,6 +51,7 @@ body #page {
font-size: 90%;
font-weight: 600;
margin: 0 0 0.5em;
text-transform: uppercase;
}
a {
......
......@@ -25,12 +25,13 @@ class Menu < ActiveRecord::Base
acts_as_list
attr_accessible :title
attr_accessible :title, :uid
default_scope :order => "position ASC"
validates_presence_of :title
validates_uniqueness_of :title
validates_uniqueness_of :uid, allow_blank: true
def should_be_displayed?
unless pages.blank?
......@@ -53,4 +54,8 @@ class Menu < ActiveRecord::Base
where("title NOT LIKE ?", "Pied de page")
end
end
\ No newline at end of file
def destroyable?
!uid.present?
end
end
......@@ -22,61 +22,66 @@
%>
<nav id="main-nav" role="navigation">
<ul id="menus">
<%= menu_to "Accueil", root_path, class: 'menu_item' %>
<%= menu_to "Calendrier", calendar_path(year: Time.now.year, month: Time.now.month), class: 'menu_item' %>
<li class="menu_item">
<span class="menu_title">LETTRES D'INFORMATION</span>
<ul>
<% Newsletter.for_nav.each do |newsletter| %>
<%= menu_to newsletter.title, newsletter %>
<% end %>
<%= menu_to "Archives", newsletters_path %>
</ul>
</li>
<% Menu.sanitized.each do |menu| %>
<% if menu.should_be_displayed? %>
<% case menu.uid %>
<% when "home" %>
<%= menu_to menu.title, root_path, class: 'menu_item' %>
<% when "calendar" %>
<%= menu_to menu.title, calendar_path(year: Time.now.year, month: Time.now.month), class: 'menu_item' %>
<% when "newsletters" %>
<li class="menu_item">
<span class="menu_title"><%= menu.title %></span>
<ul>
<% Newsletter.for_nav.each do |newsletter| %>
<%= menu_to newsletter.title, newsletter %>
<% end %>
<%= menu_to "Archives", newsletters_path %>
</ul>
</li>
<% when "activity_categories" %>
<li class="menu_item">
<span class="menu_title"><%= menu.title %></span>
<ul>
<% ActivityCategory.all.each do |cat| %>
<%= menu_to cat.title, activity_category_path(cat) %>
<% end %>
</ul>
</li>
<% when "member_groups" %>
<% unless settings.member_groups.empty? %>
<li class="menu_item">
<span class="menu_title"><%= menu.title %></span>
<ul>
<% settings.member_groups.each do |group| %>
<%= menu_to group.title, member_group_path(group) %>
<% end %>
</ul>
</li>
<% end %>
<% when "member_zone" %>
<li class="menu_item">
<span class="menu_title"><%= menu.title %></span>
<ul>
<% if logged_in? %>
<%= menu_to "Ma fiche", current_member %>
<%= menu_to "Se déconnecter", logout_path %>
<% else %>
<%= menu_to "Se connecter", login_path %>
<% end -%>
</ul>
</li>
<% else %>
<% if menu.should_be_displayed? %>
<li class="menu_item">
<span class="menu_title"><%= menu.title.upcase %></span>
<span class="menu_title"><%= menu.title %></span>
<ul>
<% menu.public_pages.each do |page| %>
<%= menu_to page.title, page %>
<% end %>
</ul>
</li>
<% end %>
<% end %>
<li class="menu_item">
<span class="menu_title">ACTIVITÉS</span>
<ul>
<% ActivityCategory.all.each do |cat| %>
<%= menu_to cat.title, activity_category_path(cat) %>
<% end %>
</ul>
</li>
<% unless settings.member_groups.empty? %>
<li class="menu_item">
<span class="menu_title">OÙ PRATIQUER</span>
<ul>
<% settings.member_groups.each do |group| %>
<%= menu_to group.title, member_group_path(group) %>
<% end %>
</ul>
</li>
<% end %>
<% end %>
<li class="menu_item">
<span class="menu_title">ZONE MEMBRE</span>
<ul>
<% if logged_in? %>
<%= menu_to "Ma fiche", current_member %>
<%= menu_to "Se déconnecter", logout_path %>
<% else %>
<%= menu_to "Se connecter", login_path %>
<% end -%>
</ul>
</li>
</ul>
</nav>
......@@ -23,11 +23,11 @@
<% pages = menu.pages %>
<h2>
<%= link_to_function menu.title, "toggle_fields('#menu-#{menu.id}')", class: 'expendable' %>
(<%= pages.length %>)
<%= "(#{pages.length})" if menu.destroyable? %>
</h2>
<div id="menu-<%= menu.id %>" style="display:none;">
<p class="AdminCard-headingActions no_print">
<%= custom_delete_link menu, :short, class: %w(tight) %>
<%= custom_delete_link menu, :short, class: %w(tight) if menu.destroyable? %>
<%= custom_edit_link edit_menu_path(menu), :short, class: %w(tight) %>
<%= custom_move_up_link move_up_menu_path(menu), :short, class: %w(tight) unless menu.first? %>
<%= custom_move_down_link move_down_menu_path(menu), :short, class: %w(tight) unless menu.last? %>
......
class AddUidToMenus < ActiveRecord::Migration
def change
add_column :menus, :uid, :string
end
end
......@@ -20,7 +20,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
ActiveRecord::Schema.define(:version => 20160311135507) do
ActiveRecord::Schema.define(:version => 20170405130159) do
create_table "activities", :force => true do |t|
t.string "title"
......@@ -225,6 +225,7 @@ ActiveRecord::Schema.define(:version => 20160311135507) do
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "position"
t.string "uid"
end
create_table "newsletter_items", :force => true do |t|
......
......@@ -20,12 +20,20 @@
# You should have received a copy of the GNU Affero General Public License
# along with OLIGAA. If not, see <http://www.gnu.org/licenses/>.
#
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Mayor.create(:name => 'Daley', :city => cities.first)
# For settings
Website.create() unless Website.count > 0
Website.create()
# Fixed menus
fixed_menus = [
{ title: "Accueil", uid: "home"},
{ title: "Calendrier", uid: "calendar"},
{ title: "Lettres d'information", uid: "newsletters"},
{ title: "Activités", uid: "activity_categories"},
{ title: "Où pratiquer", uid: "member_groups"},
{ title: "Zone membre", uid: "member_zone"}
]
fixed_menus.each do |fixed_menu|
unless Menu.find_by_uid(fixed_menu[:uid])
Menu.create!(title: fixed_menu[:title], uid: fixed_menu[:uid])
end
end
......@@ -25,6 +25,10 @@ require "spec_helper"
feature "Authentication" do
before do
create :menu, title: "ZONE MEMBRE", uid: "member_zone"
end
let(:new_pass) { 'secret' }
def change_password
......@@ -110,4 +114,4 @@ feature "Authentication" do
page.should_not have_content "Vous devez aller sur votre profil pour modifier votre mot de passe!"
end
end
end
\ No newline at end of file
end
......@@ -30,11 +30,14 @@ feature "Use calendar" do
before do
@et = create :event_type
@event = create :event, begin_at: "02/07/2013 09:00", end_at: "02/07/2013 12:00", event_type: @et
end
scenario "I can see an event with dates on the calendar" do
visit calendar_path(year: 2013, month: 7)
create :menu, title: "Calendrier", uid: "calendar"
visit root_path
within "nav#main-nav" do
click_link "Calendrier"
end
within "section#content" do
page.should have_content @event.title
end
......
......@@ -479,6 +479,7 @@ feature "Manage members" do
before { login_as_member }
scenario "I can edit my information" do
create :menu, title: "Zone membre", uid: "member_zone"
new_name = "Nouvelle dénomination"
visit root_path
within "nav#main-nav" do
......
......@@ -110,7 +110,7 @@ feature "Manage menus" do
first('#page_list li').should have_content @menu2.title
end
scenario "I can move a menu down", :js do
visit pages_path
within "li", text: @menu1.title do
......@@ -123,5 +123,20 @@ feature "Manage menus" do
first('#page_list li').should have_content @menu2.title
end
end
context "regarding fixed menus", :js do
scenario "I cannot delete one" do
menu = create :menu, uid: "my_uid"
visit pages_path
within "#page_list" do
within 'li', text: menu.title do
click_link menu.title
within "p.AdminCard-headingActions" do
page.should_not have_link "Supprimer"
end
end
end
end
end
end
end
\ No newline at end of file
end
......@@ -367,6 +367,10 @@ feature "Manage newsletters" do
end
context "as a guest" do
before do
create :menu, title: "LETTRES D'INFORMATION", uid: "newsletters"
end
context "regarding a published newsletter" do
scenario "I can see it" do
newsletter = create :newsletter, published: true
......
......@@ -225,7 +225,7 @@ feature "Manage Pages" do
my_page = create :page, displayed: true, menu: create(:menu)
visit root_path
within "nav#main-nav" do
page.should have_selector("span.menu_title", text: my_page.menu.title.upcase)
page.should have_selector("span.menu_title", text: my_page.menu.title)
click_link my_page.title
end
......
......@@ -231,6 +231,7 @@ feature "Manage Settings" do
end
scenario "I can attach member groups" do
create :menu, title: "Où pratiquer", uid: "member_groups"
group1 = create :member_group
group2 = create :member_group
visit edit_settings_path
......@@ -243,7 +244,7 @@ feature "Manage Settings" do
page.should have_content "Les paramètres ont bien été mis à jour"
visit root_path
within "nav#main-nav" do
page.should have_selector("span.menu_title", text: "OÙ PRATIQUER")
page.should have_selector("span.menu_title", text: "Où pratiquer")
page.should_not have_content group1.title
page.should have_content group2.title
end
......
......@@ -29,6 +29,7 @@ describe Menu do
end
it { should validate_presence_of :title }
it { should validate_uniqueness_of :title }
it { should validate_uniqueness_of :uid }
end
context "scopes" do
......@@ -76,5 +77,11 @@ describe Menu do
Menu.sanitized.should_not include(@footer)
end
end
specify "#destroyable? returns if a menu is destroyable or not" do
menu = create :menu
menu.destroyable?.should be_true
menu.update_attribute(:uid, "my_uid")
menu.destroyable?.should be_false
end
end
end
\ No newline at end of file
end
......@@ -52,10 +52,7 @@ module FeatureMacros
end
def logout
visit root_path
within "nav#main-nav" do
click_link "Se déconnecter"
end
visit logout_path
end
def click_edit_link
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment