simple_showcase_admin 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/assets/javascripts/simple_showcase_admin/application.js +3 -0
- data/app/assets/javascripts/simple_showcase_admin/sort.js.coffee +29 -0
- data/app/assets/stylesheets/simple_showcase_admin/application.css.scss +6 -0
- data/app/controllers/simple_showcase_admin/categories_controller.rb +13 -2
- data/app/controllers/simple_showcase_admin/items_controller.rb +8 -0
- data/app/models/simple_showcase_admin/category.rb +4 -1
- data/app/models/simple_showcase_admin/item.rb +4 -1
- data/app/views/layouts/simple_showcase_admin/application.html.haml +2 -1
- data/app/views/simple_showcase_admin/categories/index.html.haml +2 -2
- data/app/views/simple_showcase_admin/categories/show.html.haml +4 -4
- data/config/routes.rb +4 -1
- data/db/migrate/015_add_row_order_to_category.rb +5 -0
- data/db/migrate/016_add_row_order_to_items.rb +5 -0
- data/lib/simple_showcase_admin/engine.rb +2 -0
- data/lib/simple_showcase_admin/version.rb +1 -1
- data/test/dummy/config/application.rb +2 -0
- metadata +37 -2
@@ -0,0 +1,29 @@
|
|
1
|
+
jQuery ->
|
2
|
+
|
3
|
+
# this is a small hack; when a tr is dragged with jQuery UI sortable
|
4
|
+
# the cells lose their width
|
5
|
+
if $('#sortable').length > 0
|
6
|
+
cells = $('.table').find('tr')[0].cells.length
|
7
|
+
desired_width = 940 / cells + 'px'
|
8
|
+
$('.table td').css('width', desired_width)
|
9
|
+
|
10
|
+
$('#sortable').sortable(
|
11
|
+
axis: 'y'
|
12
|
+
items: '.item'
|
13
|
+
|
14
|
+
# highlight the row on drop to indicate an update
|
15
|
+
stop: (e, ui) ->
|
16
|
+
ui.item.children('td').effect('highlight', {}, 1000)
|
17
|
+
update: (e, ui) ->
|
18
|
+
item_id = ui.item.data('item-id')
|
19
|
+
console.log(item_id)
|
20
|
+
console.log($(this).data('update-url'))
|
21
|
+
position = ui.item.index()
|
22
|
+
$.ajax(
|
23
|
+
type: 'POST'
|
24
|
+
url: $(this).data('update-url')
|
25
|
+
dataType: 'json'
|
26
|
+
data: { id: item_id, row_order_position: position }
|
27
|
+
)
|
28
|
+
)
|
29
|
+
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SimpleShowcaseAdmin
|
2
2
|
class CategoriesController < SimpleShowcaseAdmin::ApplicationController
|
3
3
|
def index
|
4
|
-
@categories = SimpleShowcaseAdmin::Category.page(params[:page]).per(10)
|
4
|
+
@categories = SimpleShowcaseAdmin::Category.rank(:row_order).page(params[:page]).per(10)
|
5
5
|
end
|
6
6
|
|
7
7
|
def new
|
@@ -14,7 +14,7 @@ module SimpleShowcaseAdmin
|
|
14
14
|
|
15
15
|
def show
|
16
16
|
@category = SimpleShowcaseAdmin::Category.find(params[:id])
|
17
|
-
@items = Item.where(category_id: @category.id).page(params[:page]).per(10)
|
17
|
+
@items = Item.where(category_id: @category.id).rank(:row_order).page(params[:page]).per(10)
|
18
18
|
end
|
19
19
|
|
20
20
|
def create
|
@@ -40,5 +40,16 @@ module SimpleShowcaseAdmin
|
|
40
40
|
@catagory.destroy
|
41
41
|
redirect_to categories_path
|
42
42
|
end
|
43
|
+
|
44
|
+
def sort
|
45
|
+
@category = SimpleShowcaseAdmin::Category.find(params[:id])
|
46
|
+
|
47
|
+
@category.row_order_position = params[:row_order_position]
|
48
|
+
puts "\n\n\n\n\n@category"
|
49
|
+
puts @category.inspect
|
50
|
+
@category.save!
|
51
|
+
|
52
|
+
render nothing: true
|
53
|
+
end
|
43
54
|
end
|
44
55
|
end
|
@@ -44,5 +44,13 @@ module SimpleShowcaseAdmin
|
|
44
44
|
@item.destroy
|
45
45
|
redirect_to category_path(params[:category_id]), notice: "Successfully deleted #{@item.title}"
|
46
46
|
end
|
47
|
+
|
48
|
+
def sort
|
49
|
+
@item = SimpleShowcaseAdmin::Item.find(params[:id])
|
50
|
+
@item.row_order_position = params[:row_order_position]
|
51
|
+
@item.save!
|
52
|
+
|
53
|
+
render nothing: true
|
54
|
+
end
|
47
55
|
end
|
48
56
|
end
|
@@ -2,12 +2,15 @@ require 'friendly_id'
|
|
2
2
|
|
3
3
|
module SimpleShowcaseAdmin
|
4
4
|
class Category < ActiveRecord::Base
|
5
|
-
attr_accessible :category, :slug
|
5
|
+
attr_accessible :category, :slug, :row_order_position
|
6
6
|
has_many :items, dependent: :destroy
|
7
7
|
|
8
8
|
extend FriendlyId
|
9
9
|
friendly_id :category, use: :slugged
|
10
10
|
|
11
|
+
include RankedModel
|
12
|
+
ranks :row_order
|
13
|
+
|
11
14
|
validates_presence_of :category
|
12
15
|
validates_uniqueness_of :category
|
13
16
|
|
@@ -5,11 +5,14 @@ module SimpleShowcaseAdmin
|
|
5
5
|
belongs_to :category
|
6
6
|
has_many :photos, dependent: :destroy
|
7
7
|
accepts_nested_attributes_for :photos, reject_if: proc { |a| a[:id].blank? && a[:image].blank? }, allow_destroy: true
|
8
|
-
attr_accessible :photos_attributes, :title, :description
|
8
|
+
attr_accessible :photos_attributes, :title, :description, :row_order_position
|
9
9
|
|
10
10
|
extend FriendlyId
|
11
11
|
friendly_id :title, use: :slugged
|
12
12
|
|
13
|
+
include RankedModel
|
14
|
+
ranks :row_order
|
15
|
+
|
13
16
|
validates_presence_of :title
|
14
17
|
validates_presence_of :description
|
15
18
|
|
@@ -22,7 +22,8 @@
|
|
22
22
|
%li= link_to 'Create a Category', [:new, :category]
|
23
23
|
- SimpleShowcaseAdmin::Category.all.each do |c|
|
24
24
|
%li= link_to c.category, [ c]
|
25
|
-
|
25
|
+
|
26
|
+
- if SimpleShowcaseAdmin::Config.featured_image and !featured_photo_exists
|
26
27
|
%li.warning.label.label-important(rel="popover" data-content="You can select an image to be featured by editing a product and selecting 'Featured?' for one of the associated images." data-original-title="Please Select An Image To Be Featured.")
|
27
28
|
%i.icon-info-sign.icon-white
|
28
29
|
No Feature Photo Has Been Selected!
|
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
= paginate @categories
|
9
9
|
|
10
|
-
%table.table.table-bordered.table-striped
|
10
|
+
%table.table.table-bordered.table-striped#sortable{:data => {update_url: sort_categories_path}}
|
11
11
|
%thead
|
12
12
|
%tr
|
13
13
|
%th Category
|
@@ -15,7 +15,7 @@
|
|
15
15
|
|
16
16
|
%tbody
|
17
17
|
- @categories.each do |category|
|
18
|
-
%tr
|
18
|
+
%tr{data: {item_id: "#{category.id}"}, class: 'item'}
|
19
19
|
%td= category.category
|
20
20
|
%td
|
21
21
|
= link_to 'View', category_path(category), :class => 'btn'
|
@@ -29,7 +29,7 @@
|
|
29
29
|
|
30
30
|
= paginate @items
|
31
31
|
|
32
|
-
%table.table.table-bordered.table-striped
|
32
|
+
%table.table.table-bordered.table-striped#sortable{:data => {update_url: sort_category_items_path(@category)}}
|
33
33
|
%thead
|
34
34
|
%tr
|
35
35
|
%th Title
|
@@ -38,12 +38,12 @@
|
|
38
38
|
|
39
39
|
%tbody
|
40
40
|
- @items.each do |item|
|
41
|
-
%tr
|
41
|
+
%tr{data: {item_id: "#{item.id}"}, class: 'item'}
|
42
42
|
%td= item.title
|
43
43
|
%td= item.description.truncate(150)
|
44
44
|
%td.right
|
45
|
-
= link_to 'View', [
|
45
|
+
= link_to 'View', [@category, item], :class => 'btn'
|
46
46
|
= link_to 'Edit', [:edit, @category, item], :class => 'btn btn-primary'
|
47
|
-
= link_to 'Delete', [
|
47
|
+
= link_to 'Delete', [@category, item], :confirm => 'Are you sure?', :method => :delete, :class => 'btn btn-danger'
|
48
48
|
|
49
49
|
= paginate @items
|
data/config/routes.rb
CHANGED
@@ -5,7 +5,10 @@ SimpleShowcaseAdmin::Engine.routes.draw do
|
|
5
5
|
get 'logout' => 'sessions#destroy', :as => 'logout'
|
6
6
|
|
7
7
|
resources :categories do
|
8
|
-
|
8
|
+
post :sort, on: :collection
|
9
|
+
resources :items do
|
10
|
+
post :sort, on: :collection
|
11
|
+
end
|
9
12
|
end
|
10
13
|
resources :details
|
11
14
|
resources :sessions
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_showcase_admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-11-
|
12
|
+
date: 2013-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -169,6 +169,22 @@ dependencies:
|
|
169
169
|
- - ! '>='
|
170
170
|
- !ruby/object:Gem::Version
|
171
171
|
version: '0'
|
172
|
+
- !ruby/object:Gem::Dependency
|
173
|
+
name: jquery-ui-rails
|
174
|
+
requirement: !ruby/object:Gem::Requirement
|
175
|
+
none: false
|
176
|
+
requirements:
|
177
|
+
- - ! '>='
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
type: :runtime
|
181
|
+
prerelease: false
|
182
|
+
version_requirements: !ruby/object:Gem::Requirement
|
183
|
+
none: false
|
184
|
+
requirements:
|
185
|
+
- - ! '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
172
188
|
- !ruby/object:Gem::Dependency
|
173
189
|
name: haml
|
174
190
|
requirement: !ruby/object:Gem::Requirement
|
@@ -281,6 +297,22 @@ dependencies:
|
|
281
297
|
- - ! '>='
|
282
298
|
- !ruby/object:Gem::Version
|
283
299
|
version: '0'
|
300
|
+
- !ruby/object:Gem::Dependency
|
301
|
+
name: ranked-model
|
302
|
+
requirement: !ruby/object:Gem::Requirement
|
303
|
+
none: false
|
304
|
+
requirements:
|
305
|
+
- - ! '>='
|
306
|
+
- !ruby/object:Gem::Version
|
307
|
+
version: '0'
|
308
|
+
type: :runtime
|
309
|
+
prerelease: false
|
310
|
+
version_requirements: !ruby/object:Gem::Requirement
|
311
|
+
none: false
|
312
|
+
requirements:
|
313
|
+
- - ! '>='
|
314
|
+
- !ruby/object:Gem::Version
|
315
|
+
version: '0'
|
284
316
|
- !ruby/object:Gem::Dependency
|
285
317
|
name: rspec-rails
|
286
318
|
requirement: !ruby/object:Gem::Requirement
|
@@ -325,6 +357,7 @@ files:
|
|
325
357
|
- app/assets/javascripts/simple_showcase_admin/application.js
|
326
358
|
- app/assets/javascripts/simple_showcase_admin/jquery.photo_featured.js
|
327
359
|
- app/assets/javascripts/simple_showcase_admin/jquery.photos.js
|
360
|
+
- app/assets/javascripts/simple_showcase_admin/sort.js.coffee
|
328
361
|
- app/assets/stylesheets/simple_showcase_admin/application.css.scss
|
329
362
|
- app/controllers/simple_showcase_admin/application_controller.rb
|
330
363
|
- app/controllers/simple_showcase_admin/categories_controller.rb
|
@@ -373,6 +406,8 @@ files:
|
|
373
406
|
- db/migrate/012_add_item_id_to_photos.rb
|
374
407
|
- db/migrate/013_add_featured_to_photos.rb
|
375
408
|
- db/migrate/014_add_landscape_to_photos.rb
|
409
|
+
- db/migrate/015_add_row_order_to_category.rb
|
410
|
+
- db/migrate/016_add_row_order_to_items.rb
|
376
411
|
- lib/generators/simple_showcase_admin/install_generator.rb
|
377
412
|
- lib/simple_showcase_admin/configuration.rb
|
378
413
|
- lib/simple_showcase_admin/engine.rb
|