model_info 0.0.4 → 0.0.5

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: e674b22de66146e149687964ad4ef5d31d3e16c6
4
- data.tar.gz: aa979d3a5ddb517ca402c1bb46420eef099be4a9
3
+ metadata.gz: 7d047b94cd0cff94dea2de1cd32dd2b0d5cc577a
4
+ data.tar.gz: 14a4a6a7f2e23d0b9a79e68504a86b297b2ef135
5
5
  SHA512:
6
- metadata.gz: 1b0714b8dd74e9d4a621a0701724d2375da0d91cb9ce1b749ed7717a00b8f85c7f8b35367b870e0e69f9c5ce45a65669e8e2abb5dfe28d94c663f4b864b5ffdf
7
- data.tar.gz: 45904640bd824a23bdf60825775b1605f20a16d03940ecd06ed577c1e81cdfcb3a77c69039b82a1b93b11f3981f439a4c1ac771b0a460464e73e0bebb047de93
6
+ metadata.gz: 1deb3b38ff2452351865c5fd8c9db8fa635ef6b738fae405f0a26141be3afb577c4e2234b5aec03dfa421ad4f83ff108e2f081ea56edb4fa5acbe4c0c0e85106
7
+ data.tar.gz: ee31540d40380546c60b68511eab44185c3fe5cdd966e3d7ec623de470500151937206b4d0080da2a4c5e932e1ca0f7100e74ec395f04c9387cb5b29707f4366
data/README.rdoc CHANGED
@@ -24,9 +24,28 @@ your_application_url */model_info/models*
24
24
 
25
25
  == Working Status
26
26
 
27
- This engine may break so many times but I am working on so many things such as handling all exceptions and the system breaks on polymorphic association.
27
+ The download option for PDF, EXCEL and DOCX would be provided in an initializer file to make it true or false and also I will provide site logo and title option in an initializer file.
28
28
 
29
- Also I am looking forward to provide the download option of each model's and associated model's data of (CSV,XML,PDF,JSON).
29
+ Flash notification will be implemented with *pnotify* gem.
30
30
 
31
+ == Bugs
31
32
 
33
+ This engine breaks on polymorphic association.
34
+
35
+ I am not handling the exceptions so it will break if you will fill bad data or something a model validates upon.
36
+
37
+ If your are using *devise* or *active_admin* then you need to be aware of layout and making it redirect to the page you want if there is any url hit without user login
38
+
39
+ for example:
40
+
41
+ <tt>
42
+ layout :determine_layout
43
+
44
+ protected
45
+ def determine_layout
46
+ current_user.nil? ? "devise":"application"
47
+ end
48
+ </tt>
49
+
50
+ It will collide with my layout so avoid doing this or make your invalid request redirect to the right path.
32
51
 
@@ -0,0 +1,11 @@
1
+ .top_block {
2
+ padding: 20px 0 11px;
3
+ }
4
+
5
+ .top_block h3 {
6
+ margin-top: 0;
7
+ }
8
+
9
+ .model_action a{
10
+ margin-bottom: 3px;
11
+ }
@@ -1,5 +1,5 @@
1
1
  module ModelInfo
2
- class ApplicationController < ActionController::Base
2
+ class ApplicationController < ::ApplicationController
3
3
 
4
4
  private
5
5
  def models_tab
@@ -0,0 +1,49 @@
1
+ require_dependency "model_info/application_controller"
2
+ module ModelInfo
3
+ class DownloadsController < ApplicationController
4
+ before_filter :authenticate_request
5
+
6
+ def download_csv
7
+ csv_string = CSV.generate do |csv|
8
+ csv << params[:model_class].constantize.column_names
9
+ @model_data.each do |model|
10
+ values = model.attributes.values
11
+ csv.add_row values
12
+ end
13
+ end
14
+ send_data csv_string,
15
+ :type => 'text/csv; charset=iso-8859-1; header=present',
16
+ :disposition => "attachment; filename=#{params[:model_class]}-#{DateTime.now}.csv"
17
+ end
18
+
19
+ def download_json
20
+ send_data @model_data.to_json,
21
+ :type => 'text/json; charset=iso-8859-1; header=present',
22
+ :disposition => "attachment; filename=#{params[:model_class]}-#{DateTime.now}.json"
23
+ end
24
+
25
+ def download_xml
26
+ send_data @model_data.to_xml,
27
+ :type => 'text/xml; charset=iso-8859-1; header=present',
28
+ :disposiftion => "attachment; filename=#{params[:model_class]}-#{DateTime.now}.xml"
29
+ end
30
+
31
+ private
32
+
33
+ def authenticate_request
34
+ if params[:associated_model]
35
+ fetch_associated_model_data
36
+ else
37
+ fetch_model_data
38
+ end
39
+ end
40
+
41
+ def fetch_model_data
42
+ @model_data = params[:model_class].constantize.all
43
+ end
44
+
45
+ def fetch_associated_model_data
46
+ @model_data = params[:model_class].constantize.find(params[:model_object_id]).send(params[:associated_model])
47
+ end
48
+ end
49
+ end
@@ -4,49 +4,53 @@ module ModelInfo
4
4
  class ModelsController < ApplicationController
5
5
  before_action :models_tab
6
6
  before_action :fetch_model_name, only: [:create, :update]
7
-
7
+
8
8
  def index
9
9
  redirect_to model_display_url(model_class: @model_array.first)
10
10
  end
11
-
11
+
12
12
  def display
13
13
  @model_class, @page = params[:model_class],params[:page]
14
14
  @model_pagination = @model_class.constantize.page(@page).per(10)
15
15
  end
16
-
16
+
17
17
  def new
18
18
  @model_class = params[:model_class].constantize
19
19
  @model_data = @model_class.new
20
20
  end
21
-
21
+
22
22
  def create
23
23
  @model_class=params[:model_class].constantize
24
24
  @model_class.create(permit_params)
25
- redirect_to model_show_path(model_class: @model_class, model_object_id: @model_class.last.id)
25
+ if @model_class.last
26
+ redirect_to model_show_path(model_class: @model_class, model_object_id: @model_class.last.id)
27
+ else
28
+ redirect_to :back
29
+ end
26
30
  end
27
-
31
+
28
32
  def edit
29
33
  @model_class=params[:model_class].constantize
30
34
  @model_data=@model_class.find(params[:model_object_id])
31
35
  end
32
-
36
+
33
37
  def show
34
38
  @model_class=params[:model_class].constantize
35
39
  @model_data=@model_class.find(params[:model_object_id])
36
40
  end
37
-
41
+
38
42
  def update
39
43
  params[:model_class].constantize.find(params[@model_name][:id]).update(permit_params)
40
44
  redirect_to model_show_path(model_class: params[:model_class].constantize, model_object_id: params[@model_name][:id])
41
45
  end
42
-
46
+
43
47
  def destroy
44
48
  params[:model_class].constantize.find(params[:model_object_id]).destroy
45
49
  redirect_to :back
46
50
  end
47
-
51
+
48
52
  private
49
-
53
+
50
54
  def permit_params
51
55
  params.require(@model_name).permit!
52
56
  end
@@ -1,5 +1,5 @@
1
1
  <ul class="nav nav-tabs">
2
2
  <% for model_class in @model_array %>
3
- <li><%= link_to model_class, model_display_url(:model_class => model_class) %></li>
3
+ <li id="<%= model_class %>"><%= link_to model_class, model_display_url(:model_class => model_class) %></li>
4
4
  <% end %>
5
5
  </ul>
@@ -10,6 +10,8 @@
10
10
  </head>
11
11
 
12
12
  <body>
13
- <%= yield %>
13
+ <div class="container-fluid">
14
+ <%= yield %>
15
+ </div>
14
16
  </body>
15
17
  </html>
@@ -1,11 +1,11 @@
1
- <h3>Update Your Model's Data</h3>
1
+ <h3>Update Your Associated Data of <%= params[:associated_model_class] %> </h3>
2
2
  <div class="jumbotron">
3
3
  <%= form_for @single_associated_data, url: association_update_path(associated_model: params[:associated_model],associated_model_class: params[:associated_model_class], data: params[:data]), method: :patch do |f| %>
4
4
  <% (@single_associated_data.attribute_names - %w(id serialized_options created_at updated_at)).each do |associated_model_column| %>
5
5
  <div class="form-group">
6
6
  <%= f.label associated_model_column %>
7
7
  <div class="form-group">
8
- <%= f.text_field associated_model_column %>
8
+ <%= f.text_field associated_model_column, :class => 'form-control' %>
9
9
  </div>
10
10
  </div>
11
11
  <% end %>
@@ -1,4 +1,11 @@
1
- <h3>Associated Data of <%= @model_class %> to <%= @associated_model %></h3>
1
+ <div class="top_block col-md-12">
2
+ <h3 class="pull-left">Associated Data of <%= @model_class %> to <%= @associated_model %></h3>
3
+ <div class="pull-right">
4
+ <% unless @macro == "has_one" || @macro == "belongs_to" %>
5
+ <b><%= link_to "Create associative record", association_new_path(model_class: @model_class, model_object_id: @model_object_id, associated_model: @associated_model,model_object_id: @model_object_id,model_class: @model_class,associated_model_class: @associated_model_class), class: 'btn btn-success'%></b>
6
+ <% end %>
7
+ </div>
8
+ </div>
2
9
  <table class="table table-hover">
3
10
  <tr>
4
11
  <% @associated_model_class.column_names.each do |k| %>
@@ -6,8 +13,8 @@
6
13
  <% end %>
7
14
  <th>Actions</th>
8
15
  </tr>
9
- <%if @macro == "has_one" || @macro== "belongs_to" %>
10
- <%if !@associated_data.nil? %>
16
+ <% if @macro == "has_one" || @macro== "belongs_to" %>
17
+ <% unless @associated_data.nil? %>
11
18
  <tr>
12
19
  <% @associated_model_class.column_names.each do |d|%>
13
20
  <td>
@@ -20,7 +27,7 @@
20
27
  <%= link_to 'delete', association_destroy_path(model_class: @model_class,model_object_id: @model_object_id,associated_model: @associated_model,associated_model_class: @associated_model_class,data: @associated_data.id), method: :delete , data: {confirm: "Are you sure?"}, class: 'btn btn-danger' %>
21
28
  </td>
22
29
  </tr>
23
- <%end%>
30
+ <% end %>
24
31
  <% else %>
25
32
  <% @associated_model_pagination.each do |y| %>
26
33
  <tr>
@@ -37,14 +44,12 @@
37
44
  </tr>
38
45
  <% end %>
39
46
  </table>
40
- <div align="right">
41
- <b><%= link_to 'Create associative record', association_new_path(model_class: @model_class, model_object_id: @model_object_id, associated_model: @associated_model,model_object_id: @model_object_id,model_class: @model_class,associated_model_class: @associated_model_class), class: 'btn btn-success'%></b>
47
+ <div class="downloads">
48
+ Download Associated Data: <%= link_to 'CSV', download_csv_path(associated_model: @associated_model, model_class: @model_class, model_object_id: @model_object_id), format: :csv %>
49
+ <%= link_to 'JSON', download_json_path(associated_model: @associated_model, model_class: @model_class, model_object_id: @model_object_id), format: :json %>
50
+ <%= link_to 'XML', download_xml_path(associated_model: @associated_model, model_class: @model_class, model_object_id: @model_object_id), format: :xml %>
42
51
  </div>
43
- <nav>
44
- <ul class="pagination">
45
- <li><%= paginate @associated_model_pagination %></li>
46
- <%= page_entries_info @associated_model_pagination %>
47
- </ul>
48
- </nav>
49
-
52
+ <div class="clearfix"></div>
53
+ <%= paginate @associated_model_pagination %>
54
+ <%= page_entries_info @associated_model_pagination %>
50
55
  <% end %>
@@ -1,4 +1,4 @@
1
- <h3>Add New Record</h3>
1
+ <h3>Add New Record in <%= params[:associated_model_class] %> </h3>
2
2
  <div class="jumbotron">
3
3
  <%= form_for @associated_data, url: association_create_path, method: :post do |f| %>
4
4
  <% (@associated_data.class.column_names - %w(id created_at updated_at serialized_options)).each do |associated_model_column| %>
@@ -9,12 +9,12 @@
9
9
  <%= hidden_field_tag :model_class, params[:model_class]%>
10
10
  <%= hidden_field_tag :model_object_id, params[:model_object_id]%>
11
11
  <div class="form-group">
12
- <%= f.text_field associated_model_column %>
12
+ <%= f.text_field associated_model_column, :class => 'form-control'%>
13
13
  </div>
14
14
  </div>
15
15
  <% end %>
16
16
  <%= f.submit 'Save Changes', class:"btn btn-primary" %>
17
- <% end %>
17
+ <% end %>
18
18
  </div>
19
19
 
20
20
 
@@ -1,4 +1,4 @@
1
- <h3>View Your Associated Data</h3>
1
+ <h3>View Your Associated Data of <%= params[:associated_model_class] %></h3>
2
2
  <table class="table table-hover table-bordered">
3
3
  <tr>
4
4
  <th>Attribute</th>
@@ -1,4 +1,9 @@
1
- <h3><%= @model_class.humanize %></h3>
1
+ <div class="top_block col-md-12">
2
+ <h3 class="pull-left"><%= @model_class %></h3>
3
+ <div class="pull-right">
4
+ <b><%= link_to 'Add new Record', model_new_path(:model_class => @model_class), class: 'btn btn-success' %></b>
5
+ </div>
6
+ </div>
2
7
  <table class="table table-hover">
3
8
  <tr>
4
9
  <% @model_class.constantize.column_names.each do |k| %>
@@ -14,10 +19,10 @@
14
19
  <%= model_data.send(model_column_name.to_sym).class=='String' ? model_data.send(model_column_name.to_sym).truncate(14) : model_data.send(model_column_name.to_sym).to_s.truncate(14)%>
15
20
  </td>
16
21
  <% end %>
17
- <td>
18
- <%= link_to 'view', model_show_path(model_class: @model_class, model_object_id: model_data.id, page: @page), class: 'btn btn-info' %>
19
- <%= link_to 'edit', model_edit_path(model_class: @model_class, model_object_id: model_data.id), class: 'btn btn-warning' %>
20
- <%= link_to 'delete', model_destroy_path(model_class: @model_class, model_object_id: model_data.id), method: :delete, data: {confirm: "Are you sure?"}, class: 'btn btn-danger' %>
22
+ <td class="model_action">
23
+ <%= link_to 'View', model_show_path(model_class: @model_class, model_object_id: model_data.id, page: @page), class: 'btn btn-info' %>
24
+ <%= link_to 'Edit', model_edit_path(model_class: @model_class, model_object_id: model_data.id), class: 'btn btn-warning' %>
25
+ <%= link_to 'Delete', model_destroy_path(model_class: @model_class, model_object_id: model_data.id), method: :delete, data: {confirm: "Are you sure?"}, class: 'btn btn-danger' %>
21
26
  </td>
22
27
  <td>
23
28
  <% relationship_hash ={}, a1=[], a2=[]%>
@@ -37,9 +42,10 @@
37
42
  </tr>
38
43
  <% end %>
39
44
  </table>
40
- <div align="right">
41
- <b><%= link_to 'Add new Record', model_new_path(:model_class => @model_class), class: 'btn btn-success' %></b>
42
- </div>
45
+ Download: <%= link_to 'CSV', download_csv_path(model_class: @model_class), format: :csv %>
46
+ <%= link_to 'JSON', download_json_path(model_class: @model_class), format: :json %>
47
+ <%= link_to 'XML', download_xml_path(model_class: @model_class), format: :xml %>
48
+
43
49
  <nav>
44
50
  <ul class="pagination">
45
51
  <li><%= paginate @model_pagination %></li>
@@ -1,14 +1,14 @@
1
- <h3>Update Your Model's Data</h3>
1
+ <h3>Update Your <%= @model_class.name %> Data</h3>
2
2
  <div class="jumbotron">
3
3
  <%= form_for @model_data, url: model_update_path(model_class: @model_class), method: :patch do |f| %>
4
4
  <% (@model_class.column_names - %w(serialized_options created_at updated_at)).each do |resource_field| %>
5
5
  <div class="form-group">
6
6
  <%= f.label resource_field %>
7
7
  <div class="form-group">
8
- <%= f.text_field resource_field %>
8
+ <%= f.text_field resource_field, :class => 'form-control' %>
9
9
  </div>
10
10
  </div>
11
11
  <% end %>
12
12
  <%= f.submit 'Save Changes', class:"btn btn-primary" %>
13
- <% end %>
13
+ <% end %>
14
14
  </div>
@@ -1,17 +1,18 @@
1
- <h3>Add New Record</h3>
1
+ <h3>Add New Record in <%= @model_class.name %> </h3>
2
+
2
3
  <div class="jumbotron">
3
- <%= form_for @model_data, url: model_create_path, method: :post do |f| %>
4
+ <%= form_for @model_data, url: model_create_path, method: :post , class: 'form' do |f| %>
4
5
  <% (@model_data.class.column_names - %w(id serialized_options created_at updated_at)).each do |data_field| %>
5
6
  <div class="form-group">
6
7
  <%= f.label data_field %>
7
8
  <%= hidden_field_tag :model_class, @model_class %>
8
9
  <div class="form-group">
9
- <%= f.text_field data_field %>
10
+ <%= f.text_field data_field, :class => 'form-control' %>
10
11
  </div>
11
12
  </div>
12
13
  <% end %>
13
- <%= f.submit 'Save Changes', class:"btn btn-primary" %>
14
- <% end %>
14
+ <%= f.submit 'Create Record', class:"btn btn-primary" %>
15
+ <% end %>
15
16
  </div>
16
17
 
17
18
 
@@ -19,3 +20,4 @@
19
20
 
20
21
 
21
22
 
23
+
@@ -1,4 +1,4 @@
1
- <h3>View Your Data</h3>
1
+ <h3>View Your <%= @model_class.name%> Data</h3>
2
2
  <table class="table table-hover table-bordered">
3
3
  <tr>
4
4
  <th>Attribute</th>
data/config/routes.rb CHANGED
@@ -16,4 +16,8 @@ ModelInfo::Engine.routes.draw do
16
16
  get 'association_edit',to: 'associations#edit'
17
17
  patch 'association_update',to: 'associations#update'
18
18
  delete 'association_destroy',to: 'associations#destroy'
19
+
20
+ get 'download_csv', to: 'downloads#download_csv'
21
+ get 'download_json', to: 'downloads#download_json'
22
+ get 'download_xml', to: 'downloads#download_xml'
19
23
  end
@@ -1,5 +1,6 @@
1
1
  require 'kaminari'
2
2
  require 'bootstrap'
3
+ require 'csv'
3
4
  module ModelInfo
4
5
  class Engine < ::Rails::Engine
5
6
  isolate_namespace ModelInfo
@@ -1,3 +1,3 @@
1
1
  module ModelInfo
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - nitanshu verma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-24 00:00:00.000000000 Z
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bootstrap
@@ -58,8 +58,10 @@ files:
58
58
  - app/assets/stylesheets/model_info/bootstrap.css
59
59
  - app/assets/stylesheets/model_info/bootstrap.min.css
60
60
  - app/assets/stylesheets/model_info/fetch_model_infos.css
61
+ - app/assets/stylesheets/model_info/sytle.css.scss
61
62
  - app/controllers/model_info/application_controller.rb
62
63
  - app/controllers/model_info/associations_controller.rb
64
+ - app/controllers/model_info/downloads_controller.rb
63
65
  - app/controllers/model_info/models_controller.rb
64
66
  - app/helpers/model_info/application_helper.rb
65
67
  - app/helpers/model_info/associations_helper.rb