tkh_menus 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9d2db02e4875f038bcec6574c3c5c1763bbd79ca
4
- data.tar.gz: b6d887a2de36f34319d32850ea3f6d01618150f9
3
+ metadata.gz: e152ddfbb8fb6b47007b7b3dbe91c2fa456f8901
4
+ data.tar.gz: e4aa5e8dda6208c361cc133ed0660f6403e9d83a
5
5
  SHA512:
6
- metadata.gz: 01a27b2b33ebad980aa99801fd7d526d9c641ca326d99502cc0e55d46f0a139c25a0dca5edb09b0ccc81db5d30d467acbabe0f457457f73831b9d0870463642c
7
- data.tar.gz: 5f1bbd8980ac83fb2e1e02af6e9d9652a0dc7b03f50a49469eb21d62d652f5a68ba51ba25ca3e45707b5723869491e747e69eda1ac8c84eccef67de702857d64
6
+ metadata.gz: a3243401af3ca4ca725d875db5bf1295e3173a319e36aab70b816b7b69733d395feec8fa6d8b294177791dc33c8241c8d1777c917461ad2863a0f5e9cc26ee33
7
+ data.tar.gz: 4c5d63422012986418115bb408231a4622b70d9bf8874f1259d302e361c2e75d3ae988fc6ce591dee7c0b990857a170abe97bf8b4454fd0dec568bcf860ceb2b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
 
4
4
 
5
+ ## 0.9.2
6
+
7
+ * Fixed up buttons in menus index view
8
+ * Added drag and drop reorder tab in menu section
9
+
5
10
 
6
11
  ## 0.9.1
7
12
 
@@ -42,6 +42,19 @@ class MenusController < ApplicationController
42
42
  redirect_to menus_url, notice: t('menus.destroy.notice')
43
43
  end
44
44
 
45
+ def reorder
46
+ menu = Menu.find(params[:id])
47
+ @menus = menu.self_and_siblings.ordered
48
+ switch_to_admin_layout
49
+ end
50
+
51
+ def sort
52
+ params[:menu].each_with_index do |id, index|
53
+ Menu.update(id, position: index+1)
54
+ end
55
+ render nothing: true
56
+ end
57
+
45
58
  private
46
59
 
47
60
  # Never trust parameters from the scary internet, only allow the white list through.
data/app/models/menu.rb CHANGED
@@ -33,6 +33,10 @@ class Menu < ActiveRecord::Base
33
33
  Menu.with_parent_id(id)
34
34
  end
35
35
 
36
+ def has_parent?
37
+ !parent_id.nil?
38
+ end
39
+
36
40
  def parent
37
41
  Menu.find(parent_id)
38
42
  end
@@ -42,7 +46,15 @@ class Menu < ActiveRecord::Base
42
46
  end
43
47
 
44
48
  def siblings
45
- Menu.with_parent_id(parent_id)
49
+ self_and_siblings - [self]
50
+ end
51
+
52
+ def self_and_siblings
53
+ if has_parent?
54
+ parent.children
55
+ else
56
+ Menu.orphans
57
+ end
46
58
  end
47
59
 
48
60
  ### autocomplete related instance methods
@@ -1,5 +1,6 @@
1
- <ul class="nav nav-tabs" id="admin-menu-tab">
1
+ <ul class="nav nav-tabs" id="admin-menu-tab">
2
2
  <%= content_tag :li, link_to(t('new'), new_menu_path), ({ class: 'active' } if controller.action_name.to_s == 'new' ) %>
3
3
  <%= content_tag :li, link_to(t('list'), menus_path), ({ class: 'active' } if controller.action_name.to_s == 'index' ) %>
4
- <%= content_tag :li, link_to(t('edit'), '#'), ({ class: 'active' }) if controller.action_name.to_s == 'edit' %>
4
+ <%= content_tag :li, link_to(t('edit'), '#'), ({ class: 'active' }) if controller.action_name.to_s == 'edit' %>
5
+ <%= content_tag :li, link_to(t('menus.reorder'), reorder_menu_path(Menu.orphans.first.id)), ({ class: 'active' } if controller.action_name.to_s == 'reorder' ) %>
5
6
  </ul>
@@ -11,15 +11,14 @@
11
11
  <th><%= t('actions') %></th>
12
12
  </tr>
13
13
  </thead>
14
-
14
+
15
15
  <tbody>
16
16
  <% @menus.each do |menu| %>
17
17
  <tr>
18
18
  <td><%= menu.name %></td>
19
19
  <td><%= menu.path %></td>
20
20
  <td><%= "#{menu.parent.id} - #{menu.parent.name}" unless menu.orphan? %></td>
21
- <td><%= link_to t('edit'), edit_menu_path(menu), class: 'btn btn-mini' %>
22
- <%= link_to t('delete'), menu, method: :delete, data: { confirm: t('are_you_sure') }, class: 'btn btn-mini btn-danger' %></td>
21
+ <td><%= link_to t('edit'), edit_menu_path(menu), class: 'btn btn-xs btn-default' %><%= link_to t('delete'), menu, method: :delete, data: { confirm: t('are_you_sure') }, class: 'btn btn-xs btn-danger' %></td>
23
22
  </tr>
24
23
  <% end %>
25
24
  </tbody>
@@ -0,0 +1,13 @@
1
+ <%= render 'tab_admin_menu' %>
2
+
3
+ <p>Please use this page to reorder menu items within one level and one section. For reorganizing the menu hierarchy you should edit the individual menu entry's 'parent id' field.</p>
4
+
5
+ <p>To change the position of menu items in this list use the little handle to drag entries up or down.</p>
6
+
7
+ <ul class="draggable" data-update-url="<%= sort_menus_path %>">
8
+ <% for menu in @menus %>
9
+ <%= content_tag_for :li, menu, class: 'handle' do %>
10
+ <%= image_tag 'admin/drag-handle.gif', :class => 'handle' %> <%= menu.id.to_s + ". " + menu.name.to_s -%>
11
+ <% end %>
12
+ <% end %>
13
+ </ul>
@@ -18,7 +18,7 @@
18
18
  </ul>
19
19
  <% end %>
20
20
  <% end -%>
21
-
21
+
22
22
  <% else # administrators can reorder menu pages %>
23
23
 
24
24
  <% if @page %>
@@ -27,7 +27,7 @@
27
27
  <ul class="draggable" data-update-url="<%= sort_pages_path %>">
28
28
  <% for page in @page.children.by_menu_position %>
29
29
  <%= content_tag :li, page, class: 'page', id: "page_#{page.id}" do %>
30
- <%= image_tag 'drag-handle.gif', :class => 'handle silhouette' %> <%= link_to page.nickname, page -%>
30
+ <%= image_tag 'admin/drag-handle.gif', :class => 'handle silhouette' %> <%= link_to page.nickname, page -%>
31
31
  <% end -%>
32
32
  <% end %>
33
33
  </ul>
@@ -38,11 +38,11 @@
38
38
  <ul class="draggable" data-update-url="<%= sort_pages_path %>">
39
39
  <% for page in @page.siblings.by_menu_position %>
40
40
  <%= content_tag :li, page, class: 'page', id: "page_#{page.id}" do %>
41
- <%= image_tag 'drag-handle.gif', :class => 'handle silhouette' %> <%= link_to page.nickname, page -%>
41
+ <%= image_tag 'admin/drag-handle.gif', :class => 'handle silhouette' %> <%= link_to page.nickname, page -%>
42
42
  <% end -%>
43
43
  <% end %>
44
44
  </ul>
45
45
  <% end %>
46
46
  <% end -%>
47
-
47
+
48
48
  <% end -%>
data/config/routes.rb CHANGED
@@ -1,5 +1,12 @@
1
1
  Rails.application.routes.draw do
2
2
  scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
3
- resources :menus
3
+ resources :menus do
4
+ member do
5
+ get :reorder
6
+ end
7
+ collection do
8
+ post :sort
9
+ end
10
+ end
4
11
  end
5
- end
12
+ end
@@ -1,5 +1,5 @@
1
1
  de:
2
-
2
+
3
3
  menus: 'Menüs'
4
4
 
5
5
  activerecord:
@@ -28,3 +28,5 @@ de:
28
28
  warning: 'Beim Speichern des Menüs ist ein Fehler aufgetreten'
29
29
  destroy:
30
30
  notice: 'Das Menü wurde gelöscht'
31
+
32
+ reorder: 'reorder'
@@ -6,7 +6,7 @@ es:
6
6
  models:
7
7
  menu: 'menu'
8
8
  menus: 'menus'
9
-
9
+
10
10
  attributes:
11
11
  menu:
12
12
  name: "name"
@@ -28,3 +28,6 @@ es:
28
28
  warning: 'There was a problem saving the menu'
29
29
  destroy:
30
30
  notice: 'The menu was deleted'
31
+
32
+
33
+ reorder: 'reorder'
@@ -1,25 +1,25 @@
1
1
  fr:
2
-
2
+
3
3
  menus: 'menus'
4
-
4
+
5
5
  activerecord:
6
6
  models:
7
7
  menu: 'menu'
8
8
  menus: 'les menus'
9
-
9
+
10
10
  attributes:
11
11
  menu:
12
12
  name: "nom"
13
13
  path: 'chemin'
14
14
  parent: 'parent du menu'
15
-
15
+
16
16
  menus:
17
17
  create_new: 'créer un nouveau menu'
18
18
  hint:
19
19
  name: 'doit être assez court pour se placer sur la barre de navigation sans encombre'
20
20
  path: "l'URL de la page web qui correspond a ce menu. Par exemple /blog ou http://tenthousandhours.eu"
21
21
  parent: 'pour les sous-menus de deuxième niveau'
22
-
22
+
23
23
  create:
24
24
  notice: 'Le menu a été créé.'
25
25
  warning: "Il y'a eu un probleme et le menu n'a pas été sauvegardé"
@@ -28,3 +28,5 @@ fr:
28
28
  warning: "Il y'a eu un probleme et les changements de ce menu n'ont pas été sauvegardés"
29
29
  destroy:
30
30
  notice: 'Le menu a été supprimé'
31
+
32
+ reorder: 'organiser'
@@ -1,3 +1,3 @@
1
1
  module TkhMenus
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
@@ -2,4 +2,5 @@
2
2
  # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
3
 
4
4
  en:
5
- hello: "Hello world"
5
+ menus:
6
+ reorder: 'reorder'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tkh_menus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Swami Atma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-25 00:00:00.000000000 Z
11
+ date: 2014-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -87,7 +87,7 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - app/assets/images/drag-handle.gif
90
+ - app/assets/images/admin/drag-handle.gif
91
91
  - app/assets/javascripts/drag-and-sort.js.coffee
92
92
  - app/controllers/menus_controller.rb
93
93
  - app/models/menu.rb
@@ -96,6 +96,7 @@ files:
96
96
  - app/views/menus/edit.html.erb
97
97
  - app/views/menus/index.html.erb
98
98
  - app/views/menus/new.html.erb
99
+ - app/views/menus/reorder.html.erb
99
100
  - app/views/shared/_context_menu.html.erb
100
101
  - app/views/shared/_context_menu_for_levels.html.erb
101
102
  - app/views/shared/_context_menu_for_pages.html.erb