kuppayam 0.1.20 → 0.1.21

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: 1bb65251c46a6fd13aa91b87b1a885ccfa293f5b
4
- data.tar.gz: c1933eca8006da8da626437ec1d4381ad72bc21b
3
+ metadata.gz: 51d6eb55c8430b0caaecb27c7e149aabe0813fb2
4
+ data.tar.gz: 115e42565357390c76c66805ce8af86aedfb82b4
5
5
  SHA512:
6
- metadata.gz: 5d1a9fcfb4117eda53364986bc736ac76bcb5618e382018851121f82f5ac91b57ccdfddc454d6b4f7934ecd417a2a2878a5fc22df7f24b382857f5ba12f5378f
7
- data.tar.gz: 260e9aa8b403d82f1ef7de3fdea737367bc444f97ea354af09f24a3df166560bf4abadfa53e4c45c4e87878313398d70e9c582b932488ab782aeed3bddb9844d
6
+ metadata.gz: d194134231f2b3ecab6fd99725ebeb389bea243b86c06d982386999f73691d47d612c53119c28241d5406a8f630c550bd869ea514ce9ce071914f247b3042c76
7
+ data.tar.gz: 713ec7ef49b7970178bc9f31e1db2a1b0047a67b54b6939701bc78df53d8014cdffc57fd8d475c85fc7e91687cb5f1f58f5ef5e21e9b8b24a0a618aae71b85eb
@@ -3,13 +3,14 @@ module Kuppayam
3
3
 
4
4
  before_action :get_image_class
5
5
  before_action :get_resource
6
-
6
+
7
7
  def index
8
8
  get_collections
9
9
  end
10
10
 
11
11
  def show
12
12
  @image = Image::Base.find(params[:id])
13
+ get_image_configuration
13
14
  @r_object = @image = Image::Base.find(params[:id])
14
15
  unless @r_object
15
16
  set_notification(false, I18n.t('status.error'), I18n.t('status.not_found', item: "Image"))
@@ -18,15 +19,18 @@ module Kuppayam
18
19
  end
19
20
 
20
21
  def new
21
- @image = @image_class.new
22
+ @image = @image_class.new(imageable: @resource)
23
+ get_image_configuration
22
24
  end
23
25
 
24
26
  def edit
25
27
  @image = @image_class.find(params[:id])
28
+ get_image_configuration
26
29
  end
27
30
 
28
31
  def create
29
32
  @image = @image_class.new
33
+ get_image_configuration
30
34
  @image.imageable = @resource
31
35
  @image.image = params[:image]
32
36
  # @image.image_type = @image_class.name
@@ -37,6 +41,7 @@ module Kuppayam
37
41
 
38
42
  def update
39
43
  @image = @image_class.find(params[:id])
44
+ get_image_configuration
40
45
  @image.image = params[:image]
41
46
  @image.save
42
47
  set_flash_message("Image has been updated successfully", :success)
@@ -140,5 +145,21 @@ module Kuppayam
140
145
  @filter_ui_settings = {}
141
146
  end
142
147
 
148
+ def get_image_configuration
149
+ imageable = @image.imageable
150
+ hsh = {}
151
+ if imageable.respond_to?(:image_configuration)
152
+ hsh = imageable.image_configuration[@image_type]
153
+ elsif @image.class.respond_to?(:image_configuration)
154
+ hsh = @image.class.image_configuration
155
+ else
156
+ hsh = Image::Base.image_configuration
157
+ end
158
+ @form_upload_image_label = hsh[:form_upload_image_label]
159
+ @form_title = hsh[:form_title]
160
+ @form_sub_title = hsh[:form_sub_title]
161
+ @form_instructions = hsh[:form_instructions]
162
+ end
163
+
143
164
  end
144
165
  end
@@ -2,15 +2,6 @@ require 'filesize'
2
2
 
3
3
  class Image::Base < Kuppayam::ApplicationRecord
4
4
 
5
- # Constants
6
- UPLOAD_LIMIT = 1048576 # this is in bytes which is equivalent to 1 megabyte
7
-
8
- INSTRUCTIONS = [
9
- "the filename should be in .jpg / .jpeg or .png format",
10
- "the image dimensions are smaller than <strong>750 x 368 Pixels</strong>, (Portrait Format). (most cameras and camera phones will produce images bigger than this)",
11
- "the file size is less than 20 Kb, or bigger than <strong>1 MB</strong>"
12
- ]
13
-
14
5
  self.table_name = "images"
15
6
  self.inheritance_column = :image_type
16
7
 
@@ -40,8 +31,13 @@ class Image::Base < Kuppayam::ApplicationRecord
40
31
  end
41
32
 
42
33
  def check_file_size
43
- if image && image.file && image.file.size.to_f > self.class::UPLOAD_LIMIT
44
- errors.add(:image, "You cannot upload an image greater than #{Filesize.from(self.class::UPLOAD_LIMIT.to_s+ " b").pretty}")
34
+ if image && image.file
35
+ if image.file.size.to_f > self.max_upload_limit
36
+ errors.add(:image, "You cannot upload an image greater than #{Filesize.from(self.max_upload_limit.to_s+ " b").pretty}")
37
+ end
38
+ if image.file.size.to_f < self.min_upload_limit
39
+ errors.add(:image, "You cannot upload an image lesser than #{Filesize.from(self.min_upload_limit.to_s+ " b").pretty}")
40
+ end
45
41
  end
46
42
  end
47
43
 
@@ -49,4 +45,44 @@ class Image::Base < Kuppayam::ApplicationRecord
49
45
  "#{id} - #{self.class.name.split('::').last.titleize}"
50
46
  end
51
47
 
48
+ # Configuration
49
+ # -------------
50
+ def self.image_configuration
51
+ {
52
+ max_upload_limit: 10485760,
53
+ min_upload_limit: 100000,
54
+ resolutions: [550, 275],
55
+ form_upload_image_label: "Upload a new Image",
56
+ form_title: "Upload an Image",
57
+ form_sub_title: "Please read the instructions below:",
58
+ form_instructions: [
59
+ "the filename should be in .jpg / .jpeg or .png format",
60
+ "the image resolutions should be <strong>550 x 275 Pixels</strong>",
61
+ "the file size should be greater than 100 Kb and or lesser than <strong>10 MB</strong>",
62
+ "Note: most cameras and camera phones will produce images bigger than this"
63
+ ]
64
+ }
65
+ end
66
+
67
+ def get_image_configuration
68
+ imageable = self.imageable
69
+ hsh = {}
70
+ if imageable.respond_to?(:image_configuration)
71
+ hsh = imageable.image_configuration[self.image_type]
72
+ elsif self.class.respond_to?(:image_configuration)
73
+ hsh = self.class.image_configuration
74
+ else
75
+ hsh = Image::Base.image_configuration
76
+ end
77
+ hsh
78
+ end
79
+
80
+ def max_upload_limit
81
+ get_image_configuration[:max_upload_limit]
82
+ end
83
+
84
+ def min_upload_limit
85
+ get_image_configuration[:min_upload_limit]
86
+ end
87
+
52
88
  end
@@ -5,31 +5,20 @@
5
5
 
6
6
  <div class="modal-body">
7
7
 
8
+ <!-- Display Instructions - Get instructions from the imageable settings else display default instructions -->
9
+ <blockquote class="blockquote blockquote-red">
10
+ <p><strong><i class="linecons-lightbulb"></i><%= @form_sub_title %></strong></p>
11
+ <ul>
12
+ <% @form_instructions.each do |i| %>
13
+ <li><%= raw i %></li>
14
+ <% end %>
15
+ </ul>
16
+ </blockquote>
17
+
8
18
  <div id="image_form_error">
9
19
  <%= @image.errors[:base].to_sentence %>
10
20
  </div>
11
21
 
12
- <!-- <div style="padding:20px;background-color: yellow;">
13
- <strong><%#= @image.imageable.class.name %></strong>
14
- </div> -->
15
-
16
- <% begin %>
17
- <% if @image_type %>
18
-
19
- <blockquote class="blockquote blockquote-red">
20
- <p><strong><i class="linecons-lightbulb"></i> Please read the instructions below:</strong></p>
21
-
22
- <ul>
23
- <% eval("#{@image_type}::INSTRUCTIONS").each do |i| %>
24
- <li><%= raw i %></li>
25
- <% end %>
26
- </ul>
27
- </blockquote>
28
-
29
- <% end %>
30
- <% rescue %>
31
- <% end %>
32
-
33
22
  <%= hidden_field_tag :faction, @image.new_record? ? main_app.images_path : main_app.image_path(@image) %>
34
23
 
35
24
  <%= hidden_field_tag :fmethod, @image.new_record? ? "POST" : "PUT" %>
@@ -44,7 +33,7 @@
44
33
 
45
34
  <%= hidden_field_tag :multiple, params[:multiple] %>
46
35
 
47
- <%= theme_form_field(@image, :image, html_options: {type: 'file'}, label: "Upload New Image", param_name: "image") %>
36
+ <%= theme_form_field(@image, :image, html_options: {type: 'file'}, label: @form_upload_image_label, param_name: "image") %>
48
37
 
49
38
  </div>
50
39
 
@@ -1,8 +1,3 @@
1
- <% if @image_type %>
2
- heading = "Add <%= @image_type.split('::').last.titleize %>";
3
- <% else %>
4
- heading = "Add Image";
5
- <% end %>
6
-
1
+ heading = "<%= @form_title %>";
7
2
  bodyContent = "<%= escape_javascript(render(:partial=>'form')) %>";
8
- showImageUploadModal(heading, bodyContent);
3
+ showImageUploadModal(heading, bodyContent, true);
@@ -1,3 +1,3 @@
1
1
  module Kuppayam
2
- VERSION = '0.1.20'
2
+ VERSION = '0.1.21'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kuppayam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.20
4
+ version: 0.1.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - kpvarma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-08 00:00:00.000000000 Z
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails