model_info 0.0.6 → 0.0.7

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: 0d60909947007c4b0fb00761dc286434e8ca1503
4
- data.tar.gz: 6e1a6d29bf32c967605fea4579044fe5e1ca7a03
3
+ metadata.gz: 9c92fd753c984c611f1f6126f0b6665bc749f5c1
4
+ data.tar.gz: 6fb95331e4a1c2180e8f297c07aaabd07b96f715
5
5
  SHA512:
6
- metadata.gz: 6bbf5e531deafd2f1820f3c8cf2ec88955ef39b60e307d977ead423d65b45ef771db6d058c034d9476c8725fb01377f61acafbc7028267d4518d05c7a4fe40cf
7
- data.tar.gz: 067b3566e0fddd8e0f5dcc2796deaa396f250dc3141fb04e636eb97e2cdbd257805a3a00e0405ec20f8fbc23dc64f5e044e89628a215b382f963885896acc4f1
6
+ metadata.gz: 3e9bb0441873c38e750a69f9b0ff0d180ec704d5846cad9a439296d5bdb461824c0374ecc4d8a3da03d114157d12e316558e72d7728d76a1f2e06ac4857c0a87
7
+ data.tar.gz: da6e65c3fdb797f3d496f385a09ba7583f62fe7a08595521455aca483f427eb835eb258c8b48349b81340b2106a532b98efef0c5736f1517462279b4258f63c8
@@ -1,7 +1,7 @@
1
1
  = ModelInfo
2
2
 
3
- ModelInfo gem provides all *models*(available in your application including engine's model) CRUD and all *associations* of a model and their CRUD.
4
-
3
+ ModelInfo provides the UI interface for the CRUD of all models (including engine's) and their associated models.
4
+ It also provides you the download link for CSV and JSON format of Model's data.
5
5
  == Installation
6
6
 
7
7
  Add this line to your application's Gemfile:
@@ -14,42 +14,8 @@ And then execute:
14
14
 
15
15
  == Usage
16
16
 
17
- To use this gem you just need to mount it in your route file *config/routes.rb*
18
-
19
- <tt> mount ModelInfo::Engine => '/model_info' </tt>
20
-
21
- Then to go to the dashboard hit the url as:
22
-
23
- your_application_url */model_info/models* you will get all models of your application
24
-
25
- == Downloads
26
-
27
- You can download *CSV* *JSON* and *XML* formats of your model and associated model.
28
-
29
- == Working Status
30
-
31
- 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.
32
-
33
- Flash notification will be implemented with *pnotify* gem.
34
-
35
- == Bugs
36
-
37
- This engine breaks on polymorphic association.
38
-
39
- I am not handling the exceptions so it will break if you will fill bad data or something a model validates upon.
40
-
41
- 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
42
-
43
- for example:
44
-
45
- <tt>
46
- layout :determine_layout
47
-
48
- protected
49
- def determine_layout
50
- current_user.nil? ? "devise":"application"
51
- end
52
- </tt>
17
+ After successful installation of gem the UI interface will be available on
53
18
 
54
- It will collide with my layout so avoid doing this or make your invalid request redirect to the right path.
19
+ your_application_url */model_info/models*
55
20
 
21
+ example: localhost:3000/model_info
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
17
+ APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
18
18
  load 'rails/tasks/engine.rake'
19
19
 
20
20
 
@@ -1,23 +1,32 @@
1
1
  module ModelInfo
2
2
  class ApplicationController < ::ApplicationController
3
+ #========================= Example =================================#
4
+ #class Employee < ApplicationRecord
5
+ # has_many :projects
6
+ #end
7
+ #============================ Naming Conventions ====================#
8
+ # model_class 'Employee'
9
+ # model_name 'employee'
10
+ # model_object_id '1'
11
+ # model_data '#<Employee id: 1, name: "rooh", salary: 138001, month: "jan", created_at: "2018-08-29 07:47:43", updated_at: "2018-09-12 09:35:09", manager_id: 8, lock_version: 4>'
12
+ # associated_model_class 'Project'
13
+ # associated_model_name 'projects'
14
+ # associated_model_object_id '1'
15
+ # associated_model_data '#<Project id: nil, name: nil, employee_id: 1, created_at: nil, updated_at: nil, properties: nil>'
16
+
17
+ before_action :models_tab
3
18
 
4
19
  private
5
20
  def models_tab
6
21
  array=[], @model_array=[]
7
22
  Rails.application.eager_load!
8
- array=ActiveRecord::Base.descendants.collect{|x| x.to_s if x.table_exists?}.compact
23
+ array=ActiveRecord::Base.descendants.collect { |x| x.to_s if x.table_exists? }.compact
9
24
  array.each do |x|
10
- if x.split('::').last.split('_').first != "HABTM"
25
+ if x.split('::').last.split('_').first != 'HABTM'
11
26
  @model_array.push(x)
12
27
  end
13
28
  @model_array.delete('ActiveRecord::SchemaMigration')
14
29
  end
15
30
  end
16
-
17
- def fetch_model_name
18
- params.each do |k, v|
19
- @model_name = k.to_s if params[k].is_a?(Hash)
20
- end
21
- end
22
31
  end
23
32
  end
@@ -2,48 +2,80 @@ require_dependency "model_info/application_controller"
2
2
 
3
3
  module ModelInfo
4
4
  class AssociationsController < ApplicationController
5
- before_action :models_tab
6
- before_action :fetch_model_name, only: [:create, :update]
5
+ before_action :set_variables_in_session, only: [:index]
6
+ before_action :set_instance_variables
7
+ before_action :set_associated_model_data, only: [:show, :edit, :update]
7
8
 
8
9
  def new
9
- @model_data=params[:model_class].constantize.find(params[:model_object_id])
10
- @associated_data=@model_data.send(params[:associated_model]).build
10
+ @associated_model_data = @model_data.send(@associated_model_name).build
11
11
  end
12
12
 
13
13
  def index
14
- @model_class, @model_object_id, @associated_model,@associated_model_class,@macro, @page = params[:model_class].constantize, params[:model_object_id], params[:associated_model], params[:associated_model_class].constantize, params[:macro], params[:page]
15
- @models_data=@model_class.find(params[:model_object_id])
16
- @associated_data=@models_data.send(@associated_model)
17
- @macro == "has_one" || @macro == "belongs_to" ? @associated_model_pagination = 1 : @associated_model_pagination = @associated_data.page(params[:page]).per(10)
14
+ @macro, @page = params[:macro], params[:page]
15
+ @associated_model_data = @model_data.send(@associated_model_name)
16
+ if @macro == 'has_one' || @macro == 'belongs_to'
17
+ @associated_model_pagination = 1
18
+ else
19
+ @associated_model_pagination = @associated_model_data.page(params[:page]).per(10)
20
+ end
18
21
  end
19
22
 
20
23
  def create
21
- @associated_data=params[:model_class].constantize.find(params[:model_object_id]).send(params[:associated_model]).create(permit_params)
22
- redirect_to association_show_path(associated_model_class: params[:associated_model_class].constantize, data: @associated_data.id)
24
+ @associated_model_data = @model_data.send(@associated_model_name).build(permit_params)
25
+ if @associated_model_data.save
26
+ redirect_to association_show_path(associated_model_object_id: @associated_model_data.id)
27
+ else
28
+ flash[:error] = @associated_model_data.errors.full_messages
29
+ redirect_back(fallback_location: request.referrer)
30
+ end
23
31
  end
24
32
 
25
33
  def show
26
- @associated_model_class=params[:associated_model_class].constantize
27
- @single_associated_data=@associated_model_class.find(params[:data])
28
34
  end
29
35
 
30
36
  def edit
31
- @single_associated_data=params[:associated_model_class].constantize.find(params[:data])
32
37
  end
33
38
 
34
39
  def update
35
- params[:associated_model_class].constantize.find(params[:data]).update(permit_params)
36
- redirect_to association_show_path(associated_model_class: params[:associated_model_class].constantize, data: params[:data])
40
+ if @associated_model_data.update(permit_params)
41
+ redirect_to association_show_path(associated_model_object_id: params[:associated_model_object_id])
42
+ else
43
+ flash[:error] = @associated_model_data.errors.full_messages
44
+ redirect_back(fallback_location: request.referrer)
45
+ end
37
46
  end
38
47
 
39
48
  def destroy
40
- params[:associated_model_class].constantize.find(params[:data]).destroy
41
- redirect_to :back
49
+ @associated_model_class.find(params[:associated_model_object_id]).destroy
50
+ redirect_back(fallback_location: request.referrer)
42
51
  end
43
52
 
44
53
  private
54
+ def set_variables_in_session
55
+ session['param_set'] =
56
+ {
57
+ model_class: params[:model_class],
58
+ model_object_id: params[:model_object_id],
59
+ associated_model_class: params[:associated_model_class],
60
+ associated_model_name: params[:associated_model_name]
61
+ }
62
+ end
63
+
64
+ def set_instance_variables
65
+ @model_class = (session[:param_set][:model_class] || session['param_set']['model_class']).constantize
66
+ @model_name = @model_class.to_s.downcase
67
+ @model_object_id = session[:param_set][:model_object_id] || session['param_set']['model_object_id']
68
+ @model_data = @model_class.find(@model_object_id)
69
+ @associated_model_class = (session[:param_set][:associated_model_class] || session['param_set']['associated_model_class']).constantize
70
+ @associated_model_name = session[:param_set][:associated_model_name] || session['param_set']['associated_model_name']
71
+ end
72
+
73
+ def set_associated_model_data
74
+ @associated_model_data = @associated_model_class.find(params[:associated_model_object_id])
75
+ end
76
+
45
77
  def permit_params
46
- params.require(@model_name).permit!
78
+ params.require(@associated_model_class.to_s.downcase).permit!
47
79
  end
48
80
  end
49
81
  end
@@ -1,11 +1,12 @@
1
1
  require_dependency "model_info/application_controller"
2
2
  module ModelInfo
3
3
  class DownloadsController < ApplicationController
4
- before_filter :authenticate_request
4
+ before_action :set_model_instance
5
+ before_action :authenticate_request
5
6
 
6
7
  def download_csv
7
8
  csv_string = CSV.generate do |csv|
8
- csv << params[:model_class].constantize.column_names
9
+ csv << @model_class.column_names
9
10
  @model_data.each do |model|
10
11
  values = model.attributes.values
11
12
  csv.add_row values
@@ -13,33 +14,42 @@ module ModelInfo
13
14
  end
14
15
  send_data csv_string,
15
16
  :type => 'text/csv; charset=iso-8859-1; header=present',
16
- :disposition => "attachment; filename=#{params[:model_class]}-#{DateTime.now}.csv"
17
+ :disposition => "attachment; filename=#{@model_name}-#{DateTime.now}.csv"
17
18
  end
18
19
 
19
20
  def download_json
20
21
  send_data @model_data.to_json,
21
22
  :type => 'text/json; charset=iso-8859-1; header=present',
22
- :disposition => "attachment; filename=#{params[:model_class]}-#{DateTime.now}.json"
23
+ :disposition => "attachment; filename=#{@model_name}-#{DateTime.now}.json"
23
24
  end
24
25
 
25
26
  def download_xml
26
27
  send_data @model_data.to_xml,
27
28
  :type => 'text/xml; charset=iso-8859-1; header=present',
28
- :disposiftion => "attachment; filename=#{params[:model_class]}-#{DateTime.now}.xml"
29
+ :disposiftion => "attachment; filename=#{@model_name}-#{DateTime.now}.xml"
29
30
  end
30
31
 
31
32
  private
32
33
 
34
+ def set_model_instance
35
+ @model_class = params[:model_class].try(:constantize)
36
+ @model_name = @model_class.to_s.downcase
37
+ end
38
+
33
39
  def authenticate_request
34
- params[:associated_model] ? fetch_associated_model_data : fetch_model_data
40
+ if params[:associated_model_name]
41
+ fetch_associated_model_data
42
+ else
43
+ fetch_model_data
44
+ end
35
45
  end
36
46
 
37
47
  def fetch_model_data
38
- @model_data = params[:model_class].constantize.all
48
+ @model_data = @model_class.all
39
49
  end
40
50
 
41
51
  def fetch_associated_model_data
42
- @model_data = params[:model_class].constantize.find(params[:model_object_id]).send(params[:associated_model])
52
+ @model_data = @model_class.find(params[:model_object_id]).send(params[:associated_model_name])
43
53
  end
44
54
  end
45
55
  end
@@ -1,58 +1,62 @@
1
- require_dependency "model_info/application_controller"
1
+ require_dependency 'model_info/application_controller'
2
2
 
3
3
  module ModelInfo
4
4
  class ModelsController < ApplicationController
5
- before_action :models_tab
6
- before_action :fetch_model_name, only: [:create, :update]
7
-
8
- def index
9
- redirect_to model_display_url(model_class: @model_array.first)
10
- end
11
-
5
+ before_action :model_class_and_name
6
+ before_action :set_model_data, only: [:show, :edit, :update]
7
+
12
8
  def display
13
- @model_class, @page = params[:model_class],params[:page]
9
+ @model_class, @page = params[:model_class] || @model_array.try(:first), params[:page] || 1
14
10
  @model_pagination = @model_class.constantize.page(@page).per(10)
15
11
  end
16
-
12
+
17
13
  def new
18
- @model_class = params[:model_class].constantize
19
14
  @model_data = @model_class.new
20
15
  end
21
-
16
+
22
17
  def create
23
- @model_class=params[:model_class].constantize
24
- @model_class.create(permit_params)
25
- if @model_class.last
26
- redirect_to model_show_path(model_class: @model_class, model_object_id: @model_class.last.id)
18
+ @model_data = @model_class.new(permit_params)
19
+ if @model_data.save
20
+ redirect_to model_show_path(model_class: @model_class, model_object_id: @model_data.id)
27
21
  else
28
- redirect_to :back
22
+ flash[:error] = @model_data.errors.full_messages
23
+ redirect_back(fallback_location: request.referrer)
29
24
  end
30
25
  end
31
-
26
+
32
27
  def edit
33
- @model_class=params[:model_class].constantize
34
- @model_data=@model_class.find(params[:model_object_id])
35
28
  end
36
-
29
+
37
30
  def show
38
- @model_class=params[:model_class].constantize
39
- @model_data=@model_class.find(params[:model_object_id])
40
31
  end
41
-
32
+
42
33
  def update
43
- params[:model_class].constantize.find(params[@model_name][:id]).update(permit_params)
44
- redirect_to model_show_path(model_class: params[:model_class].constantize, model_object_id: params[@model_name][:id])
34
+ if @model_data.update(permit_params)
35
+ redirect_to model_show_path(model_class: @model_class, model_object_id: @model_data.id)
36
+ else
37
+ flash[:error] = @model_data.errors.full_messages
38
+ redirect_back(fallback_location: request.referrer)
39
+ end
45
40
  end
46
-
41
+
47
42
  def destroy
48
- params[:model_class].constantize.find(params[:model_object_id]).destroy
49
- redirect_to :back
43
+ @model_class.find(params[:model_object_id]).destroy
44
+ redirect_back(fallback_location: request.referrer)
50
45
  end
51
-
46
+
52
47
  private
53
-
48
+
54
49
  def permit_params
55
50
  params.require(@model_name).permit!
56
51
  end
52
+
53
+ def model_class_and_name
54
+ @model_class = params[:model_class].try(:constantize)
55
+ @model_name = @model_class.to_s.downcase
56
+ end
57
+
58
+ def set_model_data
59
+ @model_data=@model_class.find(params[:model_object_id])
60
+ end
57
61
  end
58
- end
62
+ end
@@ -1,4 +1,47 @@
1
1
  module ModelInfo
2
2
  module AssociationsHelper
3
+
4
+ def associated_model_column_names
5
+ @associated_model_class.column_names
6
+ end
7
+
8
+ def association_download_param
9
+ {
10
+ associated_model_name: @associated_model_name,
11
+ model_class: @model_class,
12
+ model_object_id: @model_object_id
13
+ }
14
+ end
15
+
16
+ def association_actions(associated_model_data)
17
+ content_tag :td do
18
+ concat link_to 'View',
19
+ association_show_path(page: @page, associated_model_object_id: associated_model_data),
20
+ class: 'btn btn-info'
21
+ concat ' '
22
+ concat link_to 'Edit',
23
+ association_edit_path(associated_model_object_id: associated_model_data),
24
+ class: 'btn btn-warning'
25
+ concat ' '
26
+ concat link_to 'Delete',
27
+ association_destroy_path(associated_model_object_id: associated_model_data),
28
+ method: :delete,
29
+ data: {confirm: 'Are you sure?'},
30
+ class: 'btn btn-danger'
31
+ end
32
+ end
33
+
34
+ def association_download_actions
35
+ if @associated_model_class.any?
36
+ content_tag :div, class: 'association_downloads' do
37
+ capture do
38
+ concat 'Download Associated Model Data: '
39
+ concat link_to 'CSV', download_csv_path(association_download_param), format: :csv
40
+ concat ' '
41
+ concat link_to 'JSON', download_json_path(association_download_param), format: :json
42
+ end
43
+ end
44
+ end
45
+ end
3
46
  end
4
47
  end
@@ -0,0 +1,57 @@
1
+ module ModelInfo
2
+ module ModelsHelper
3
+
4
+ def model_column_names
5
+ @model_class.constantize.column_names
6
+ end
7
+
8
+ def model_reflection_on_associations
9
+ @model_class.constantize.reflect_on_all_associations
10
+ end
11
+
12
+ def model_column_value(model_data, model_column_name)
13
+ column_value = model_data.send(model_column_name.to_sym)
14
+ column_value.class =='String' ? column_value.truncate(14) : column_value.to_s.truncate(14)
15
+ end
16
+
17
+ def model_actions(model_data)
18
+ content_tag :td, class: 'model_action' do
19
+ capture do
20
+ concat link_to 'View', model_show_path(model_class: @model_class, model_object_id: model_data.id, page: @page), class: 'btn btn-info'
21
+ concat link_to 'Edit', model_edit_path(model_class: @model_class, model_object_id: model_data.id), class: 'btn btn-warning'
22
+ concat 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'
23
+ end
24
+ end
25
+ end
26
+
27
+ def model_download_actions
28
+ if @model_class.constantize.any?
29
+ content_tag :div, class: 'model_downloads' do
30
+ capture do
31
+ concat 'Download: '
32
+ concat link_to 'CSV', download_csv_path(model_class: @model_class), format: :csv
33
+ concat ' '
34
+ concat link_to 'JSON', download_json_path(model_class: @model_class), format: :json
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ # associations_hash = {
41
+ # [:projects, :has_many]=>"Project",
42
+ # [:histories, :has_many]=>"History",
43
+ # [:subordinates, :has_many]=>"Employee"
44
+ # }
45
+ def associations_hash
46
+ relationship_hash ={}, active_record_name=[], klass_name=[]
47
+ model_reflection_on_associations.each do |reflection|
48
+ if reflection.options[:polymorphic]
49
+ active_record_name.push(reflection.active_record.name)
50
+ else
51
+ klass_name.push(reflection.klass.name)
52
+ end
53
+ end
54
+ relationship_hash = model_reflection_on_associations.map { |x| [x.name, x.macro] }.zip(active_record_name+klass_name).inject({}) { |h, e| h[e.first] = e.last; h }
55
+ end
56
+ end
57
+ end
@@ -1,7 +1,7 @@
1
- <nav class="navbar navbar-default navbar-static-top">
2
- <div class="container-fluid">
3
- <div class="navbar-header">
4
- <a class="navbar-brand" href='#'>ModelInfo</a>
1
+ <nav class='navbar navbar-default navbar-static-top'>
2
+ <div class='container-fluid'>
3
+ <div class='navbar-header'>
4
+ <%= link_to 'ModelInfo', root_path, class: 'navbar-brand' %>
5
5
  </div>
6
6
  </div>
7
7
  </nav>
@@ -1,5 +1,8 @@
1
- <ul class="nav nav-tabs">
1
+ <ul class='nav nav-tabs'>
2
2
  <% for model_class in @model_array %>
3
- <li id="<%= model_class %>"><%= link_to model_class, model_display_url(:model_class => model_class) %></li>
3
+ <li class='models_tab' id="<%= model_class %>"><%= link_to model_class, model_display_path(model_class: model_class) %></li>
4
4
  <% end %>
5
- </ul>
5
+ </ul>
6
+ <script>
7
+ $('#'+'<%= @model_class %>').addClass('active');
8
+ </script>
@@ -2,11 +2,11 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>ModelInfo</title>
5
- <%= stylesheet_link_tag "model_info/application", media: "all" %>
5
+ <%= stylesheet_link_tag "model_info/application", media: "all" %>
6
6
  <%= javascript_include_tag "model_info/application" %>
7
7
  <%= csrf_meta_tags %>
8
8
  <%= render :partial => 'layouts/model_info/header' %>
9
- <%= render :partial => 'layouts/model_info/models_header'%>
9
+ <%= render :partial => 'layouts/model_info/models_header' %>
10
10
  </head>
11
11
 
12
12
  <body>
@@ -1,14 +1,9 @@
1
- <h3>Update Your Associated Data of <%= params[:associated_model_class] %> </h3>
2
- <div class="jumbotron">
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
- <% (@single_associated_data.attribute_names - %w(id serialized_options created_at updated_at)).each do |associated_model_column| %>
5
- <div class="form-group">
6
- <%= f.label associated_model_column %>
7
- <div class="form-group">
8
- <%= f.text_field associated_model_column, :class => 'form-control' %>
9
- </div>
10
- </div>
11
- <% end %>
12
- <%= f.submit 'Save Changes', class:"btn btn-primary" %>
13
- <% end %>
14
- </div>
1
+ <h3>Update Your Associated Data of <%= @associated_model_class %> </h3>
2
+ <%= render partial: 'model_info/shared/form',
3
+ locals:
4
+ {
5
+ model_class: @associated_model_class,
6
+ model_data: @associated_model_data,
7
+ url: association_update_path(associated_model_object_id: @associated_model_data.id),
8
+ }
9
+ %>
@@ -1,55 +1,47 @@
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>
1
+ <div class='top_block col-md-12'>
2
+ <h3 class='pull-left'>Associated Data of <%= @model_class %> to <%= @associated_model_class %></h3>
3
+
4
+ <div class='pull-right'>
5
+ <% unless @macro == 'has_one' || @macro == 'belongs_to' %>
6
+ <b><%= link_to 'Create associative record', association_new_path, class: 'btn btn-success' %></b>
6
7
  <% end %>
7
8
  </div>
8
9
  </div>
9
- <table class="table table-hover">
10
+
11
+ <table class='table table-hover'>
10
12
  <tr>
11
- <% @associated_model_class.column_names.each do |k| %>
12
- <th><%= k %></th>
13
+ <% associated_model_column_names.each do |column_name| %>
14
+ <th><%= column_name %></th>
13
15
  <% end %>
14
16
  <th>Actions</th>
15
17
  </tr>
16
- <% if @macro == "has_one" || @macro== "belongs_to" %>
17
- <% unless @associated_data.nil? %>
18
+ <% if @macro == 'has_one' || @macro== 'belongs_to' %>
19
+ <% unless @associated_model_data.nil? %>
18
20
  <tr>
19
- <% @associated_model_class.column_names.each do |d|%>
21
+ <% associated_model_column_names.each do |d| %>
20
22
  <td>
21
- <%= @associated_data.send(d).class=='String' ? @associated_data.send(d).truncate(14): @associated_data.send(d).to_s.truncate(14) %>
23
+ <%= @associated_model_data.send(d).class=='String' ? @associated_model_data.send(d).truncate(14) : @associated_model_data.send(d).to_s.truncate(14) %>
22
24
  </td>
23
- <%end%>
24
- <td>
25
- <%= link_to 'view', association_show_path(associated_model_class: @associated_model_class, page: @page, data: @associated_data.id), class: 'btn btn-info' %>
26
- <%= link_to 'edit', association_edit_path(model_class: @model_class,model_object_id: @model_object_id,associated_model: @associated_model,associated_model_class: @associated_model_class, page: @page, data: @associated_data.id), class: 'btn btn-warning' %>
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' %>
28
- </td>
25
+ <% end %>
26
+ <%= association_actions(@associated_model_data) %>
29
27
  </tr>
30
28
  <% end %>
31
29
  <% else %>
32
30
  <% @associated_model_pagination.each do |y| %>
33
31
  <tr>
34
- <% @associated_model_class.column_names.each do |k| %>
32
+ <% associated_model_column_names.each do |k| %>
35
33
  <td>
36
- <%= y.send(k.to_sym).class=='String' ?y.send(k.to_sym).truncate(14):y.send(k.to_sym).to_s.truncate(14) %>
34
+ <%= y.send(k.to_sym).class=='String' ? y.send(k.to_sym).truncate(14) : y.send(k.to_sym).to_s.truncate(14) %>
37
35
  </td>
38
36
  <% end %>
39
- <td>
40
- <%= link_to 'view', association_show_path(associated_model_class: @associated_model_class, data: y, page: @page), class: 'btn btn-info' %>
41
- <%= link_to 'edit', association_edit_path(model_class: @model_class,model_object_id: @model_object_id,associated_model: @associated_model,associated_model_class: @associated_model_class, data: y, page: @page), class: 'btn btn-warning' %>
42
- <%= link_to 'delete', association_destroy_path(associated_model_class: @associated_model_class, data: y.id), data: {confirm: "Are you sure?"}, method: :delete ,class: 'btn btn-danger' %>
43
- </td>
37
+ <%= association_actions(y) %>
44
38
  </tr>
45
39
  <% end %>
46
40
  </table>
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 %>
51
- </div>
52
- <div class="clearfix"></div>
41
+
42
+ <%= association_download_actions %>
43
+
44
+ <div class='clearfix'></div>
53
45
  <%= paginate @associated_model_pagination %>
54
- <%= page_entries_info @associated_model_pagination %>
46
+ <%= rel_next_prev_link_tags @associated_model_pagination unless @associated_model_pagination.empty? %>
55
47
  <% end %>
@@ -1,22 +1,14 @@
1
- <h3>Add New Record in <%= params[:associated_model_class] %> </h3>
2
- <div class="jumbotron">
3
- <%= form_for @associated_data, url: association_create_path, method: :post do |f| %>
4
- <% (@associated_data.class.column_names - %w(id created_at updated_at serialized_options)).each do |associated_model_column| %>
5
- <div class="form-group">
6
- <%= f.label associated_model_column %>
7
- <%= hidden_field_tag :associated_model_class, params[:associated_model_class]%>
8
- <%= hidden_field_tag :associated_model, params[:associated_model]%>
9
- <%= hidden_field_tag :model_class, params[:model_class]%>
10
- <%= hidden_field_tag :model_object_id, params[:model_object_id]%>
11
- <div class="form-group">
12
- <%= f.text_field associated_model_column, :class => 'form-control'%>
13
- </div>
14
- </div>
15
- <% end %>
16
- <%= f.submit 'Save Changes', class:"btn btn-primary" %>
17
- <% end %>
18
- </div>
1
+ <h3>Add New Record in <%= @model_class %> </h3>
2
+ <%= render partial: 'model_info/shared/form',
3
+ locals:
4
+ {
5
+ model_class: @associated_model_class,
6
+ model_data: @associated_model_data,
7
+ url: association_create_path,
8
+ new: true
9
+ }
19
10
 
11
+ %>
20
12
 
21
13
 
22
14
 
@@ -1,19 +1,8 @@
1
- <h3>View Your Associated Data of <%= params[:associated_model_class] %></h3>
2
- <table class="table table-hover table-bordered">
3
- <tr>
4
- <th>Attribute</th>
5
- <th>Value</th>
6
- </tr>
7
- <% @associated_model_class.column_names.each do |associated_model_column| %>
8
- <tr>
9
- <th><%= associated_model_column %></th>
10
- <td><%= @single_associated_data.send(associated_model_column) %></td>
11
- </tr>
12
- <% end %>
13
- <tr>
14
- <th>Actions</th>
15
- <td>
16
- <%= link_to 'Back', :back %>
17
- </td>
18
- </tr>
19
- </table>
1
+ <h3>View Your Associated Data of <%= @associated_model_class %></h3>
2
+ <%= render partial: 'model_info/shared/show',
3
+ locals:
4
+ {
5
+ model_class: @associated_model_class,
6
+ model_data: @associated_model_data
7
+ }
8
+ %>
@@ -1,55 +1,51 @@
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>
1
+ <div class='top_block col-md-12'>
2
+ <h3 class='pull-left'><%= @model_class %></h3>
3
+
4
+ <div class='pull-right'>
5
+ <b><%= link_to 'Add new Record', model_new_path(model_class: @model_class), class: 'btn btn-success' %></b>
5
6
  </div>
6
7
  </div>
7
- <table class="table table-hover">
8
+
9
+ <table class='table table-hover'>
8
10
  <tr>
9
- <% @model_class.constantize.column_names.each do |k| %>
10
- <th><%= k %></th>
11
+ <% model_column_names.each do |column_name| %>
12
+ <th><%= column_name %></th>
11
13
  <% end %>
12
14
  <th>Actions</th>
13
15
  <th>Association Relationship</th>
14
16
  </tr>
15
17
  <% @model_pagination.each do |model_data| %>
16
18
  <tr>
17
- <% @model_class.constantize.column_names.each do |model_column_name| %>
19
+ <% model_column_names.each do |model_column_name| %>
18
20
  <td>
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)%>
21
+ <%= model_column_value(model_data, model_column_name) %>
20
22
  </td>
21
23
  <% end %>
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' %>
26
- </td>
24
+ <%= model_actions(model_data) %>
27
25
  <td>
28
- <% relationship_hash ={}, a1=[], a2=[]%>
29
- <% @model_class.constantize.reflect_on_all_associations.each do |reflection|%>
30
- <% reflection.options[:polymorphic] ? a1.push(reflection.active_record.name) : a2.push(reflection.klass.name) %>
31
- <% end %>
32
- <% relationship_hash = @model_class.constantize.reflect_on_all_associations.map{|x| [x.name, x.macro]}.zip(a1+a2).inject({}){|h,e| h[e.first] = e.last; h}%>
33
-
34
- <% if relationship_hash.empty? %>
35
- <%= 'Sorry no relationship!'%>
26
+ <% if associations_hash.empty? %>
27
+ <%= "Sorry no association exist for #{@model_class}" %>
36
28
  <% else %>
37
- <% relationship_hash.each do |k,v| %>
38
- <%= link_to "#{k.last} #{k.first} |" , associations_index_path(associated_model: k.first, model_object_id: model_data.id, model_class: @model_class, associated_model_class: v, macro: k.last) %>
29
+ <% associations_hash.each do |association_name_and_macro, model_class| %>
30
+ <%= link_to "#{association_name_and_macro.last} #{association_name_and_macro.first} |",
31
+ associations_index_path(associated_model_name: association_name_and_macro.first,
32
+ model_object_id: model_data.id,
33
+ model_class: @model_class,
34
+ associated_model_class: model_class,
35
+ macro: association_name_and_macro.last) %>
39
36
  <% end %>
40
37
  <% end %>
41
38
  </td>
42
39
  </tr>
43
40
  <% end %>
44
41
  </table>
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 %>
42
+
43
+ <%= model_download_actions %>
48
44
 
49
45
  <nav>
50
- <ul class="pagination">
46
+ <ul class='pagination'>
51
47
  <li><%= paginate @model_pagination %></li>
52
- <%= page_entries_info @model_pagination %>
48
+ <%= rel_next_prev_link_tags @model_pagination unless @model_pagination.empty? %>
53
49
  </ul>
54
50
  </nav>
55
51
 
@@ -1,14 +1,9 @@
1
- <h3>Update Your <%= @model_class.name %> Data</h3>
2
- <div class="jumbotron">
3
- <%= form_for @model_data, url: model_update_path(model_class: @model_class), method: :patch do |f| %>
4
- <% (@model_class.column_names - %w(serialized_options created_at updated_at)).each do |resource_field| %>
5
- <div class="form-group">
6
- <%= f.label resource_field %>
7
- <div class="form-group">
8
- <%= f.text_field resource_field, :class => 'form-control' %>
9
- </div>
10
- </div>
11
- <% end %>
12
- <%= f.submit 'Save Changes', class:"btn btn-primary" %>
13
- <% end %>
14
- </div>
1
+ <h3>Update Your <%= @model_class %> Data</h3>
2
+ <%= render partial: 'model_info/shared/form',
3
+ locals:
4
+ {
5
+ model_class: @model_class,
6
+ model_data: @model_data,
7
+ url: model_update_path(model_object_id: @model_data.id)
8
+ }
9
+ %>
@@ -1,21 +1,13 @@
1
- <h3>Add New Record in <%= @model_class.name %> </h3>
2
-
3
- <div class="jumbotron">
4
- <%= form_for @model_data, url: model_create_path, method: :post , class: 'form' do |f| %>
5
- <% (@model_data.class.column_names - %w(id serialized_options created_at updated_at)).each do |data_field| %>
6
- <div class="form-group">
7
- <%= f.label data_field %>
8
- <%= hidden_field_tag :model_class, @model_class %>
9
- <div class="form-group">
10
- <%= f.text_field data_field, :class => 'form-control' %>
11
- </div>
12
- </div>
13
- <% end %>
14
- <%= f.submit 'Create Record', class:"btn btn-primary" %>
15
- <% end %>
16
- </div>
17
-
18
-
1
+ <h3>Add New Record in <%= @model_class %> </h3>
2
+ <%= render partial: 'model_info/shared/form',
3
+ locals:
4
+ {
5
+ model_class: @model_class,
6
+ model_data: @model_data,
7
+ url: model_create_path,
8
+ new: true
9
+ }
10
+ %>
19
11
 
20
12
 
21
13
 
@@ -1,19 +1,8 @@
1
- <h3>View Your <%= @model_class.name%> Data</h3>
2
- <table class="table table-hover table-bordered">
3
- <tr>
4
- <th>Attribute</th>
5
- <th>Value</th>
6
- </tr>
7
- <% @model_class.column_names.each do |model_column_name| %>
8
- <tr>
9
- <th><%= model_column_name %></th>
10
- <td><%= @model_data.send(model_column_name) %></td>
11
- </tr>
12
- <% end %>
13
- <tr>
14
- <th>Actions</th>
15
- <td>
16
- <%= link_to 'Back', :back %>
17
- </td>
18
- </tr>
19
- </table>
1
+ <h3>View Your <%= @model_class %> Data</h3>
2
+ <%= render partial: 'model_info/shared/show',
3
+ locals:
4
+ {
5
+ model_class: @model_class,
6
+ model_data: @model_data
7
+ }
8
+ %>
@@ -0,0 +1,15 @@
1
+ <div class='flash_messages'>
2
+ <%= content_tag(:div, :class => 'alert alert-danger') do %>
3
+ <%= content_tag :ul do %>
4
+ <% flash.each do |key, value| %>
5
+ <% if value.is_a?(Array) %>
6
+ <% flash[key].each do |error| %>
7
+ <%= content_tag :li, error %>
8
+ <% end %>
9
+ <% else %>
10
+ <%= content_tag :li, value %>
11
+ <% end %>
12
+ <% end %>
13
+ <% end %>
14
+ <% end %>
15
+ </div>
@@ -0,0 +1,15 @@
1
+ <%= render 'model_info/shared/flash_messages' unless flash.empty? %>
2
+ <div class='jumbotron'>
3
+ <%= form_for model_data, url: url, method: local_assigns[:new] ? :post : :patch do |f| %>
4
+ <% (model_data.class.column_names - %w(id serialized_options created_at updated_at)).each do |attribute| %>
5
+ <div class='form-group'>
6
+ <%= f.label attribute %>
7
+ <%= hidden_field_tag :model_class, model_class %>
8
+ <div class='form-group'>
9
+ <%= f.text_field attribute, :class => 'form-control' %>
10
+ </div>
11
+ </div>
12
+ <% end %>
13
+ <%= f.submit local_assigns[:new] ? 'Create Record' : 'Save Changes', class: 'btn btn-primary' %>
14
+ <% end %>
15
+ </div>
@@ -0,0 +1,18 @@
1
+ <table class='table table-hover table-bordered'>
2
+ <tr>
3
+ <th>Attribute</th>
4
+ <th>Value</th>
5
+ </tr>
6
+ <% model_class.column_names.each do |model_column_name| %>
7
+ <tr>
8
+ <th><%= model_column_name %></th>
9
+ <td><%= model_data.send(model_column_name) %></td>
10
+ </tr>
11
+ <% end %>
12
+ <tr>
13
+ <th>Actions</th>
14
+ <td>
15
+ <%= link_to 'Back', :back %>
16
+ </td>
17
+ </tr>
18
+ </table>
@@ -1,5 +1,7 @@
1
1
  ModelInfo::Engine.routes.draw do
2
2
 
3
+ root to: 'models#display'
4
+
3
5
  get 'model_display', to: 'models#display'
4
6
  get 'models',to: 'models#index'
5
7
  get 'model_new',to: 'models#new'
@@ -1,3 +1,3 @@
1
- require "model_info/engine"
1
+ require 'model_info/engine'
2
2
  module ModelInfo
3
3
  end
@@ -3,5 +3,15 @@ require 'csv'
3
3
  module ModelInfo
4
4
  class Engine < ::Rails::Engine
5
5
  isolate_namespace ModelInfo
6
+
7
+ initializer 'model_info', before: :load_config_initializers do |app|
8
+ Rails.application.routes.append do
9
+ mount ModelInfo::Engine, at: '/model_info'
10
+ end
11
+
12
+ config.paths['db/migrate'].expanded.each do |expanded_path|
13
+ Rails.application.config.paths['db/migrate'] << expanded_path
14
+ end
15
+ end
6
16
  end
7
17
  end
@@ -1,3 +1,3 @@
1
1
  module ModelInfo
2
- VERSION = "0.0.6"
2
+ VERSION = '0.0.7'
3
3
  end
metadata CHANGED
@@ -1,32 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_info
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - nitanshu verma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-25 00:00:00.000000000 Z
11
+ date: 2018-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bootstrap
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: kaminari
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - ">="
31
+ - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '0'
33
+ version: '1.1'
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - ">="
38
+ - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '0'
27
- description: ModelInfo gem build on a thought where you should not write a single
28
- line of code and you can CRUD each model(including engine's) and their associated
29
- models.
40
+ version: '1.1'
41
+ description: ModelInfo provides the UI interface for the CRUD of all models (including
42
+ engine's) and their associated models. It also enables the admin to download the
43
+ CSV and JSON format data of all the Models and their associated Models.
30
44
  email:
31
45
  - nitanshu1991@gmail.com
32
46
  executables: []
@@ -51,6 +65,7 @@ files:
51
65
  - app/controllers/model_info/models_controller.rb
52
66
  - app/helpers/model_info/application_helper.rb
53
67
  - app/helpers/model_info/associations_helper.rb
68
+ - app/helpers/model_info/models_helper.rb
54
69
  - app/views/layouts/model_info/_header.html.erb
55
70
  - app/views/layouts/model_info/_models_header.html.erb
56
71
  - app/views/layouts/model_info/application.html.erb
@@ -62,6 +77,9 @@ files:
62
77
  - app/views/model_info/models/edit.html.erb
63
78
  - app/views/model_info/models/new.html.erb
64
79
  - app/views/model_info/models/show.html.erb
80
+ - app/views/model_info/shared/_flash_messages.html.erb
81
+ - app/views/model_info/shared/_form.html.erb
82
+ - app/views/model_info/shared/_show.html.erb
65
83
  - config/routes.rb
66
84
  - lib/model_info.rb
67
85
  - lib/model_info/engine.rb
@@ -87,8 +105,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
105
  version: '0'
88
106
  requirements: []
89
107
  rubyforge_project:
90
- rubygems_version: 2.4.8
108
+ rubygems_version: 2.4.6
91
109
  signing_key:
92
110
  specification_version: 4
93
- summary: ModelInfo provides the CRUD of all model's and their associated model's
111
+ summary: ModelInfo provides the UI interface for the CRUD of all models (including
112
+ engine's) and their associated models.
94
113
  test_files: []