bit_core 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/app/models/bit_core/slide.rb +0 -9
- data/app/models/bit_core/slideshow.rb +31 -1
- data/lib/bit_core/version.rb +1 -1
- data/spec/dummy/config/database.yml +1 -0
- data/spec/dummy/log/test.log +2244 -0
- data/spec/models/bit_core/slide_spec.rb +0 -13
- data/spec/models/bit_core/slideshow_spec.rb +44 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fc8f82c0070900575127dc85046ca7f02923e25
|
4
|
+
data.tar.gz: ebb2257d29c38e76d1aa06bb9b817ecbb57fd2c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a35f2bf37f8c18ed4de50b112387bf390ddc06eb689d87862495e3a46c3dad6274c3d43b2171aba55e0995054097f577df2a12472a38db31b19c859c72dc262
|
7
|
+
data.tar.gz: c3244449083c1ae2e35cb270ee68d16a4514e5819bd722d76a37e0883ec6733eb1670be51f6debc067d59569f1bd23d22718bffb644082bc08b7204ab43ec101
|
data/Rakefile
CHANGED
@@ -12,15 +12,6 @@ module BitCore
|
|
12
12
|
validates :position, numericality: { greater_than_or_equal_to: 1 }
|
13
13
|
validates :position, uniqueness: { scope: :bit_core_slideshow_id }
|
14
14
|
|
15
|
-
def self.update_positions(ids)
|
16
|
-
transaction do
|
17
|
-
connection.execute "SET CONSTRAINTS bit_core_slide_position DEFERRED"
|
18
|
-
ids.each_with_index do |id, index|
|
19
|
-
where(id: id).update_all(position: index + 1)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
15
|
def render_body
|
25
16
|
return "" if body.nil?
|
26
17
|
|
@@ -7,10 +7,40 @@ module BitCore
|
|
7
7
|
foreign_key: :bit_core_slideshow_id,
|
8
8
|
dependent: :destroy,
|
9
9
|
inverse_of: :slideshow
|
10
|
-
has_one :content_provider,
|
10
|
+
has_one :content_provider,
|
11
|
+
as: :source_content,
|
12
|
+
inverse_of: :source_content,
|
13
|
+
dependent: :nullify
|
11
14
|
|
12
15
|
validates :title, presence: true
|
13
16
|
|
14
17
|
accepts_nested_attributes_for :slides
|
18
|
+
|
19
|
+
def add(slide_params)
|
20
|
+
slide = slides.build(slide_params)
|
21
|
+
slide.position = slides.count + 1
|
22
|
+
|
23
|
+
slide
|
24
|
+
end
|
25
|
+
|
26
|
+
def remove(slide)
|
27
|
+
return false unless slide.destroy
|
28
|
+
|
29
|
+
(slide.position + 1..slides.last.position).each do |pos|
|
30
|
+
slides.find_by_position(pos).update(position: pos - 1)
|
31
|
+
end
|
32
|
+
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
def sort(ordered_ids)
|
37
|
+
self.class.transaction do
|
38
|
+
self.class.connection.execute "SET CONSTRAINTS " \
|
39
|
+
"bit_core_slide_position DEFERRED"
|
40
|
+
ordered_ids.each_with_index do |id, idx|
|
41
|
+
slides.find(id).update_attribute(:position, idx + 1)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
15
45
|
end
|
16
46
|
end
|
data/lib/bit_core/version.rb
CHANGED