kuppayam 0.1.15 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/kuppayam/utilities.js +9 -0
  3. data/app/controllers/kuppayam/base_controller.rb +1 -0
  4. data/app/helpers/filter_helper.rb +4 -3
  5. data/app/helpers/image_helper.rb +7 -10
  6. data/app/helpers/navigation_helper.rb +11 -2
  7. data/app/helpers/resource_helper.rb +32 -0
  8. data/app/helpers/resource_view_helper.rb +227 -0
  9. data/app/models/concerns/approvable.rb +47 -0
  10. data/app/models/concerns/featureable.rb +23 -0
  11. data/app/models/concerns/publishable.rb +46 -0
  12. data/app/models/image/cover_image.rb +3 -0
  13. data/app/models/image/gallery_image.rb +11 -0
  14. data/app/models/image/logo_image.rb +3 -0
  15. data/app/models/image/profile_image.rb +3 -0
  16. data/app/uploaders/cover_image_uploader.rb +22 -0
  17. data/app/uploaders/gallery_image_uploader.rb +22 -0
  18. data/app/uploaders/logo_image_uploader.rb +22 -0
  19. data/app/uploaders/profile_image_uploader.rb +22 -0
  20. data/app/views/kuppayam/api/docs/_navbar.html.erb +12 -0
  21. data/app/views/kuppayam/api/docs/_navigation.html.erb +12 -19
  22. data/app/views/kuppayam/api/docs/show.html.erb +70 -80
  23. data/app/views/kuppayam/images/_form.html.erb +7 -1
  24. data/app/views/kuppayam/images/_multiple_images.html.erb +29 -0
  25. data/app/views/kuppayam/images/create.html.erb +20 -7
  26. data/app/views/kuppayam/images/destroy.js.erb +10 -2
  27. data/app/views/kuppayam/images/update.html.erb +2 -2
  28. data/app/views/layouts/dashboard/_items.html.erb +20 -0
  29. data/app/views/layouts/kuppayam/docs.html.erb +31 -55
  30. data/config/initializers/validators.rb +5 -1
  31. data/lib/generators/kuppayam/resource_generator.rb +254 -0
  32. data/lib/generators/kuppayam/templates/controllers/resource_controller.rb +84 -0
  33. data/lib/generators/kuppayam/templates/db/migrate/create_resources.rb +14 -0
  34. data/lib/generators/kuppayam/templates/models/resource.rb +72 -0
  35. data/lib/generators/kuppayam/templates/spec/controllers/resource_controller_spec.rb +154 -0
  36. data/lib/generators/kuppayam/templates/spec/factories/resource.rb +42 -0
  37. data/lib/generators/kuppayam/templates/spec/models/resource_spec.rb +36 -0
  38. data/lib/generators/kuppayam/templates/views/_form.html.erb +63 -0
  39. data/lib/generators/kuppayam/templates/views/_index.html.erb +53 -0
  40. data/lib/generators/kuppayam/templates/views/_row.html.erb +26 -0
  41. data/lib/generators/kuppayam/templates/views/_show.html.erb +112 -0
  42. data/lib/generators/kuppayam/templates/views/index.html.erb +46 -0
  43. data/lib/generators/resource/resource_generator.rb +337 -0
  44. data/lib/kuppayam/action_view/form_helper.rb +10 -2
  45. data/lib/kuppayam/action_view/theme_helper.rb +4 -2
  46. data/lib/kuppayam/version.rb +1 -1
  47. metadata +58 -2
@@ -0,0 +1,46 @@
1
+ module Publishable
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ # Constants
6
+ PUBLISHED = "published"
7
+ UNPUBLISHED = "unpublished"
8
+ REMOVED = "removed"
9
+ ARCHIVED = "archived"
10
+
11
+ STATUS = {"Published" => PUBLISHED, "Unpublished" => UNPUBLISHED, "Archived" => ARCHIVED, "Removed" => REMOVED}
12
+ STATUS_REVERSE = {PUBLISHED => "Published", UNPUBLISHED => "Unpublished", ARCHIVED => "Archived", REMOVED => "Removed"}
13
+ STATUS_UI_CLASS = {PUBLISHED => "success", UNPUBLISHED => "default", ARCHIVED => "default", REMOVED => "danger"}
14
+
15
+ included do
16
+
17
+ validates :status, :presence=> true, :inclusion => {:in => STATUS_REVERSE.keys, :presence_of => :status, :message => "%{value} is not a valid status" }
18
+
19
+ state_machine :status, initial: UNPUBLISHED do
20
+ event :publish do
21
+ transition [UNPUBLISHED, ARCHIVED] => PUBLISHED
22
+ end
23
+ event :unpublish do
24
+ transition [PUBLISHED, REMOVED, ARCHIVED] => UNPUBLISHED
25
+ end
26
+ event :remove do
27
+ transition [PUBLISHED, UNPUBLISHED, ARCHIVED] => REMOVED
28
+ end
29
+ event :archive do
30
+ transition [PUBLISHED, UNPUBLISHED, REMOVED] => ARCHIVED
31
+ end
32
+ end
33
+
34
+ scope :published, -> { where(status: PUBLISHED) }
35
+ scope :unpublished, -> { where(status: UNPUBLISHED) }
36
+ scope :removed, -> { where(status: REMOVED) }
37
+ scope :archived, -> { where(status: ARCHIVED) }
38
+
39
+ scope :status, lambda { |status| where("LOWER(status)='#{status}'") }
40
+ end
41
+
42
+ def display_status
43
+ STATUS_REVERSE[self.status]
44
+ end
45
+
46
+ end
@@ -0,0 +1,3 @@
1
+ class Image::CoverImage < Image::Base
2
+ mount_uploader :image, CoverImageUploader
3
+ end
@@ -0,0 +1,11 @@
1
+ class Image::GalleryImage < Image::Base
2
+
3
+ INSTRUCTIONS = [
4
+ "the filename should be in .jpg / .jpeg or .png format",
5
+ "the image dimensions are smaller than 750 pixels by 368 pixels, (Portrait Format). (most cameras and camera phones will produce images bigger than this)",
6
+ "the file size is less than 20 Kb, or bigger than <strong>1 MB</strong>"
7
+ ]
8
+
9
+ mount_uploader :image, GalleryImageUploader
10
+
11
+ end
@@ -0,0 +1,3 @@
1
+ class Image::LogoImage < Image::Base
2
+ mount_uploader :image, LogoImageUploader
3
+ end
@@ -0,0 +1,3 @@
1
+ class Image::ProfileImage < Image::Base
2
+ mount_uploader :image, ProfileImageUploader
3
+ end
@@ -0,0 +1,22 @@
1
+ class CoverImageUploader < ImageUploader
2
+
3
+ def store_dir
4
+ "uploads/cover_images/#{model.id}"
5
+ end
6
+
7
+ version :large do
8
+ process :resize_to_fill => [750, 368]
9
+ end
10
+
11
+ version :medium do
12
+ process :resize_to_fill => [550, 294]
13
+ end
14
+
15
+ version :small do
16
+ process :resize_to_fill => [300, 160]
17
+ end
18
+
19
+ version :tiny do
20
+ process :resize_to_fill => [100, 54]
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ class GalleryImageUploader < ImageUploader
2
+
3
+ def store_dir
4
+ "uploads/gallery_images/#{model.id}"
5
+ end
6
+
7
+ version :large do
8
+ process :resize_to_fill => [500, 500]
9
+ end
10
+
11
+ version :medium do
12
+ process :resize_to_fill => [200, 200]
13
+ end
14
+
15
+ version :small do
16
+ process :resize_to_fill => [140, 140]
17
+ end
18
+
19
+ version :tiny do
20
+ process :resize_to_fill => [80, 80]
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ class LogoImageUploader < ImageUploader
2
+
3
+ def store_dir
4
+ "uploads/logo_images/#{model.id}"
5
+ end
6
+
7
+ version :large do
8
+ process :resize_to_fill => [750, 368]
9
+ end
10
+
11
+ version :medium do
12
+ process :resize_to_fill => [550, 294]
13
+ end
14
+
15
+ version :small do
16
+ process :resize_to_fill => [300, 160]
17
+ end
18
+
19
+ version :tiny do
20
+ process :resize_to_fill => [100, 54]
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ class ProfileImageUploader < ImageUploader
2
+
3
+ def store_dir
4
+ "uploads/profile_images/#{model.id}"
5
+ end
6
+
7
+ version :large do
8
+ process :resize_to_fill => [400, 400]
9
+ end
10
+
11
+ version :medium do
12
+ process :resize_to_fill => [200, 200]
13
+ end
14
+
15
+ version :small do
16
+ process :resize_to_fill => [100, 100]
17
+ end
18
+
19
+ version :tiny do
20
+ process :resize_to_fill => [50, 50]
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ <% if @tab_items %>
2
+ <ul class="nav nav-tabs">
3
+ <% @tab_items.each do |key, val| %>
4
+ <li class="nav-item <%= nav_class(val[:nav_class], true) %>">
5
+ <%= link_to val[:url], class: "nav-link" do %>
6
+ <i class="<%= val[:icon_class] %>"></i>
7
+ <span><%= val[:text] %></span>
8
+ <% end %>
9
+ </li>
10
+ <% end %>
11
+ </ul>
12
+ <% end %>
@@ -1,19 +1,12 @@
1
- <ul class="nav tabs-vertical">
2
- <li class="<%= nav_active?('docs/end_point_1') ? 'active' : '' %>">
3
- <a href="/docs/api/v1/end_point_1">
4
- <i class="fa-globe visible-xs"></i>
5
- <span class="hidden-xs">API End Point 1</span>
6
- </a>
7
- </li>
8
- <li class="<%= nav_active?('docs/end_point_2') ? 'active' : '' %>">
9
- <a href="/docs/api/v1/end_point_1">
10
- <i class="fa-globe visible-xs"></i>
11
- <span class="hidden-xs">API End Point 2</span>
12
- </a>
13
- </li>
14
- </ul>
15
-
16
- <style type="text/css">
17
- .panel-positive h4.panel-title a { color: #68b828 !important; }
18
- .panel-negative h4.panel-title a { color: #cc3f44 !important; }
19
- </style>
1
+ <div class="gallery-sidebar">
2
+ <ul class="list-unstyled">
3
+ <% @nav_items.each do |key, val| %>
4
+ <li class="<%= nav_class(val[:nav_class]) %>">
5
+ <%= link_to val[:url] do %>
6
+ <i class="<%= val[:icon_class] %>"></i>
7
+ <span><%= val[:text] %></span>
8
+ <% end %>
9
+ </li>
10
+ <% end %>
11
+ </ul>
12
+ </div>
@@ -1,94 +1,84 @@
1
- <div class="tabs-vertical-env">
2
-
3
- <%= render partial: "kuppayam/api/docs/navigation" %>
4
-
5
- <div class="tab-content">
6
- <div class="tab-pane active" id="<%= params[:action] %>">
7
-
8
- <h3><span class="text-success"><%= @title %></span></h3>
9
- <p><code><strong><%= @request_type %></strong> <%= request.base_url %><%= @end_point %></code></p>
1
+ <h3><span class="text-success"><%= @title %></span></h3>
2
+ <p><code><strong><%= @request_type %></strong> <%= request.base_url %><%= @end_point %></code></p>
10
3
 
11
- <% if @description %>
12
- <p class="text-primary"><%= @description %></p>
13
- <% end %>
4
+ <% if @description %>
5
+ <p class="text-primary"><%= @description %></p>
6
+ <% end %>
14
7
 
15
- <% if @warning %>
16
- <p class="alert alert-danger mt-40"><%= @warning %></p>
17
- <% end %>
8
+ <% if @warning %>
9
+ <p class="alert alert-danger mt-40"><%= @warning %></p>
10
+ <% end %>
18
11
 
19
- <% if @info %>
20
- <p class="alert alert-info mt-40"><%= @info %></p>
21
- <% end %>
12
+ <% if @info %>
13
+ <p class="alert alert-info mt-40"><%= @info %></p>
14
+ <% end %>
22
15
 
23
- <br>
16
+ <br>
24
17
 
25
- <% if @input_headers && @input_headers.any? %>
26
- <h4 style="color:#4b4b4b">Headers</h4>
18
+ <% if @input_headers && @input_headers.any? %>
19
+ <h4 style="color:#4b4b4b">Headers</h4>
27
20
 
28
- <div class="table-responsive table-scrollable">
29
- <table class="table table-striped table-condensed table-bordered">
30
- <thead>
31
- <tr>
32
- <th>Key</th>
33
- <th>Value</th>
34
- <th>Description</th>
35
- </tr>
36
- </thead>
21
+ <div class="table-responsive table-scrollable">
22
+ <table class="table table-striped table-condensed table-bordered">
23
+ <thead>
24
+ <tr>
25
+ <th>Key</th>
26
+ <th>Value</th>
27
+ <th>Description</th>
28
+ </tr>
29
+ </thead>
37
30
 
38
- <tbody>
39
- <% @input_headers.each do |key, value| %>
40
- <tr>
41
- <td style="width:160px;"><%= key.to_s.titleize %></td>
42
- <td style="width:160px;"><%= value[:value] %></td>
43
- <td><%= value[:description] %></td>
44
- </tr>
45
- <% end %>
46
- </tbody>
47
- </table>
48
- </div>
31
+ <tbody>
32
+ <% @input_headers.each do |key, value| %>
33
+ <tr>
34
+ <td style="width:160px;"><%= key.to_s.titleize %></td>
35
+ <td style="width:160px;"><%= value[:value] %></td>
36
+ <td><%= value[:description] %></td>
37
+ </tr>
49
38
  <% end %>
39
+ </tbody>
40
+ </table>
41
+ </div>
42
+ <% end %>
50
43
 
51
- <% if @input_params && @input_params.any? %>
52
- <h4 style="color:#4b4b4b">Input Parameters</h4>
44
+ <% if @input_params && @input_params.any? %>
45
+ <h4 style="color:#4b4b4b">Input Parameters</h4>
53
46
 
54
- <div class="table-responsive table-scrollable">
55
- <table class="table table-striped table-condensed table-bordered">
56
- <thead>
57
- <tr>
58
- <th>Name</th>
59
- <th>Mandatory</th>
60
- <th>Description</th>
61
- <th>Example</th>
62
- <th>Default</th>
63
- </tr>
64
- </thead>
47
+ <div class="table-responsive table-scrollable">
48
+ <table class="table table-striped table-condensed table-bordered">
49
+ <thead>
50
+ <tr>
51
+ <th>Name</th>
52
+ <th>Mandatory</th>
53
+ <th>Description</th>
54
+ <th>Example</th>
55
+ <th>Default</th>
56
+ </tr>
57
+ </thead>
65
58
 
66
- <tbody>
67
- <% @input_params.each do |key, value| %>
68
- <tr>
69
- <td style="width:160px;"><%= key.to_s.camelcase %></td>
70
- <td style="width:100px;"><%= value[:mandatory] %></td>
71
- <td><%= value[:description] %></td>
72
- <td style="width:200px;"><%= value[:example] %></td>
73
- <td style="width:100px;"><%= value[:default] %></td>
74
- </tr>
75
- <% end %>
76
- </tbody>
77
- </table>
78
- </div>
59
+ <tbody>
60
+ <% @input_params.each do |key, value| %>
61
+ <tr>
62
+ <td style="width:160px;"><%= key.to_s.camelcase %></td>
63
+ <td style="width:100px;"><%= value[:mandatory] %></td>
64
+ <td><%= value[:description] %></td>
65
+ <td style="width:200px;"><%= value[:example] %></td>
66
+ <td style="width:100px;"><%= value[:default] %></td>
67
+ </tr>
79
68
  <% end %>
69
+ </tbody>
70
+ </table>
71
+ </div>
72
+ <% end %>
80
73
 
81
- <% if @examples && @examples.any? %>
82
- <br><br><br>
83
- <h4 style="color:#4b4b4b">Examples</h4>
84
- <br>
74
+ <% if @examples && @examples.any? %>
75
+ <br><br><br>
76
+ <h4 style="color:#4b4b4b">Examples</h4>
77
+ <br>
85
78
 
86
- <div class="panel-group panel-group-joined">
87
- <% @examples.each do |e| %>
88
- <%= render partial: "#{@example_path}/#{params[:action]}/#{e}" %>
89
- <% end %>
90
- </div>
91
- <% end %>
92
- </div>
93
- </div>
94
- </div>
79
+ <div class="panel-group panel-group-joined">
80
+ <% @examples.each do |e| %>
81
+ <%= render partial: "#{@example_path}/#{params[:action]}/#{e}" %>
82
+ <% end %>
83
+ </div>
84
+ <% end %>
@@ -9,6 +9,10 @@
9
9
  <%= @image.errors[:base].to_sentence %>
10
10
  </div>
11
11
 
12
+ <div style="padding:20px;background-color: yellow;">
13
+ <strong><%= @image.imageable.class.name %></strong>
14
+ </div>
15
+
12
16
  <% begin %>
13
17
  <% if @image_type %>
14
18
 
@@ -37,8 +41,10 @@
37
41
  <%= hidden_field_tag :redirect_url, params[:redirect_url] %>
38
42
 
39
43
  <%= hidden_field_tag :image_type, params[:image_type] %>
44
+
45
+ <%= hidden_field_tag :multiple, params[:multiple] %>
40
46
 
41
- <%= theme_form_field(@image, :image, html_options: {type: 'file'}, label: "Upload new Image", param_name: "image") %>
47
+ <%= theme_form_field(@image, :image, html_options: {type: 'file'}, label: "Upload New Image", param_name: "image") %>
42
48
 
43
49
  </div>
44
50
 
@@ -0,0 +1,29 @@
1
+ <%
2
+ unless defined?(images)
3
+ images = []
4
+ end
5
+ unless defined?(image_size)
6
+ image_size = "image.small.url"
7
+ end
8
+ %>
9
+ <div id="div_multiple_images_index" class="row">
10
+ <% images.each do |ci| %>
11
+
12
+ <% img_url = image_url(ci, image_size, height: "auto", class: "img-inline") %>
13
+
14
+ <% delete_url = main_app.url_for([:image, id: ci.id, imageable_id: ci.imageable_id, imageable_type: ci.imageable_type, image_type: ci.class.name, multiple: true])
15
+ remove_btn_display = raw(theme_fa_icon("trash") + theme_button_text("Remove"))
16
+ %>
17
+
18
+ <div class="col-md-3 col-sm-12 col-xs-12"
19
+ style="border-right:1px solid #f1f1f1;"
20
+ id="<%= ci.id %>-multiple-image">
21
+
22
+ <%= image_tag(img_url, width: "100%", height: "auto", class: "img-inline") %>
23
+ <%= link_to(remove_btn_display, delete_url,
24
+ class: "btn btn-danger btn-block btn-only-hover btn-xs mt-20",
25
+ remote: true, method: :delete) %>
26
+ </div>
27
+
28
+ <% end %>
29
+ </div>
@@ -22,15 +22,28 @@
22
22
 
23
23
  <% else %>
24
24
 
25
- this.parent.closeImageUploadModal();
25
+ <% if params[:multiple] && ["true", "t", "yes", "1"].include?(params[:multiple]) %>
26
26
 
27
- //var heading = "Crop Image";
28
- //var bodyContent = "<%#= escape_javascript(render(:partial=>"crop_form")) %>";
29
- //this.parent.showModal(heading, bodyContent);
30
- //this.parent.cropImage("form_crop_photo");
27
+ this.parent.closeImageUploadModal();
31
28
 
32
- this.parent.$(".-large-image").attr("src", "<%= @image.image.large.url %>");
33
- this.parent.$(".-small-image").attr("src", "<%= @image.image.small.url %>");
29
+ <% images = @image.class.where("imageable_id = ? AND imageable_type = ?", @image.imageable_id, @image.imageable_type).all %>
30
+
31
+ this.parent.$("#div_multiple_images_index").replaceWith("<%= escape_javascript(render(:partial=>"#{@resource_options[:view_path]}/multiple_images", locals: {images: images, object: @image.imageable})) %>")
32
+
33
+ <% else %>
34
+
35
+ this.parent.closeImageUploadModal();
36
+
37
+ //var heading = "Crop Image";
38
+ //var bodyContent = "<%#= escape_javascript(render(:partial=>"crop_form")) %>";
39
+ //this.parent.showModal(heading, bodyContent);
40
+ //this.parent.cropImage("form_crop_photo");
41
+
42
+ this.parent.$(".<%= @image.imageable_id %>-large-image").attr("src", "<%= @image.image.large.url %>");
43
+ this.parent.$(".<%= @image.imageable_id %>-small-image").attr("src", "<%= @image.image.small.url %>");
44
+ <% end %>
45
+
46
+
34
47
 
35
48
  <% end %>
36
49