client_engine 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +32 -0
  5. data/app/assets/config/client_engine_manifest.js +2 -0
  6. data/app/assets/images/client_engine/default.png +0 -0
  7. data/app/assets/images/client_engine/default_registry.png +0 -0
  8. data/app/assets/javascripts/client_engine/application.js +18 -0
  9. data/app/assets/javascripts/client_engine/clients.js +30 -0
  10. data/app/assets/stylesheets/client_engine/application.css +21 -0
  11. data/app/assets/stylesheets/client_engine/bootstrap_and_overrides.css +6 -0
  12. data/app/assets/stylesheets/client_engine/clients.css +59 -0
  13. data/app/assets/stylesheets/client_engine/scaffold.css +80 -0
  14. data/app/controllers/client_engine/application_controller.rb +38 -0
  15. data/app/controllers/client_engine/clients_controller.rb +63 -0
  16. data/app/helpers/client_engine/application_helper.rb +5 -0
  17. data/app/helpers/client_engine/clients_helper.rb +176 -0
  18. data/app/jobs/client_engine/application_job.rb +4 -0
  19. data/app/mailers/client_engine/application_mailer.rb +6 -0
  20. data/app/models/client_engine/application_record.rb +5 -0
  21. data/app/models/client_engine/client.rb +28 -0
  22. data/app/models/client_engine/registry.rb +6 -0
  23. data/app/uploaders/client_engine/avatar_uploader.rb +14 -0
  24. data/app/views/client_engine/clients/_clients.html.erb +35 -0
  25. data/app/views/client_engine/clients/_form.html.erb +78 -0
  26. data/app/views/client_engine/clients/edit.html.erb +6 -0
  27. data/app/views/client_engine/clients/index.html.erb +12 -0
  28. data/app/views/client_engine/clients/index.js.erb +3 -0
  29. data/app/views/client_engine/clients/new.html.erb +3 -0
  30. data/app/views/client_engine/clients/show.html.erb +56 -0
  31. data/app/views/client_engine/registries/_client_panel.html.erb +26 -0
  32. data/app/views/layouts/client_engine/application.html.erb +18 -0
  33. data/config/locales/en.bootstrap.yml +35 -0
  34. data/config/routes.rb +6 -0
  35. data/db/migrate/20180814162729_create_client_engine_clients.rb +24 -0
  36. data/db/migrate/20180822174903_create_client_engine_registries.rb +15 -0
  37. data/lib/client_engine.rb +5 -0
  38. data/lib/client_engine/engine.rb +5 -0
  39. data/lib/client_engine/version.rb +3 -0
  40. data/lib/tasks/client_engine_tasks.rake +4 -0
  41. metadata +299 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fa01b70704d1688c05edd6100459278c6a8438d8
4
+ data.tar.gz: 16e4e3025d77612a4b8b88c6e8737846e0c32140
5
+ SHA512:
6
+ metadata.gz: 98c97f9015971a5cfad425684b448d9482f3b62ec96a5b57ed6af2093c9720284612cd4cffb00b7e45e87f5f9b39d1e90dbe980b08a52b9acd4435a0a69e2f3c
7
+ data.tar.gz: 505d56202eebed08dca63d190488e9e819af5099edcad1c5c4454a70d001b8060b1ce5ef6a20aa0643976d1faf62deebd1617dc8ff25dbcb2e5920d78a0eb328
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Facundo A. Díaz Martínez
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # ClientEngine
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'client_engine'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install client_engine
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ClientEngine'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/client_engine .js
2
+ //= link_directory ../stylesheets/client_engine .css
@@ -0,0 +1,18 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require jquery-ui
16
+ //= require twitter/bootstrap
17
+ //= require activestorage
18
+ //= require_tree .
@@ -0,0 +1,30 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
3
+
4
+ function remoteSubmit(form_id){
5
+ $.get($(form_id).attr("action"), $(form_id).serialize(), null, "script");
6
+ return false;
7
+ };
8
+
9
+ $(document).ready(function(){
10
+ $("#client_document").on("focusout", function(){
11
+ url = "/cliente/get_client_data_from_afip?document=" + $(this).val();
12
+ $.get(url, function(data, status){
13
+ console.log(data)
14
+ $("#client_first_name").val(data["first_name"]);
15
+ $("#client_last_name").val(data["last_name"]);
16
+ $("#client_birthday").val(data["birthday"]);
17
+ $("#client_city").val(data["city"]);
18
+ $("#client_locality").val(data["locality"]);
19
+ $("#client_address").val(data["address"]);
20
+ $("#client_country").val("Argentina");
21
+ });
22
+ return false
23
+ });
24
+
25
+ $(".clickable-row").click(function() {
26
+ window.location = $(this).data("url");
27
+ });
28
+ })
29
+
30
+
@@ -0,0 +1,21 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require font-awesome
14
+ *= require_tree .
15
+ *= require_self
16
+ */
17
+
18
+ tr.clickable-row:hover {
19
+ cursor: pointer;
20
+ background-color: rgba(0,0,0,.2)
21
+ }
@@ -0,0 +1,6 @@
1
+ /*
2
+ =require twitter-bootstrap-static/bootstrap
3
+
4
+ Static version of css will use Glyphicons sprites by default
5
+ =require twitter-bootstrap-static/sprites
6
+ */
@@ -0,0 +1,59 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
5
+
6
+ #document{
7
+ margin-bottom: 15px;
8
+ }
9
+
10
+ #document > .form-group > .form-control{
11
+ width: 100% !important;
12
+ }
13
+
14
+ #document > .form-group:nth-child(1){
15
+ width: 24.3%;
16
+ }
17
+
18
+ #document > .form-group:nth-child(2){
19
+ width: 75%;
20
+ }
21
+
22
+ .client-img {
23
+ width: 50px;
24
+ border-radius: 100%;
25
+ }
26
+
27
+ .registry-img{
28
+ width: 100%;
29
+ }
30
+
31
+ .thumbnail > .caption > h3{
32
+ text-align: center;
33
+ }
34
+
35
+ .large_text{
36
+ white-space: nowrap;
37
+ overflow: hidden;
38
+ text-overflow: ellipsis;
39
+ }
40
+
41
+ a.btn:visited {
42
+ color: white !important;
43
+ }
44
+
45
+ .title > h4 {
46
+ margin-top: 0px;
47
+ }
48
+
49
+ .created_at{
50
+ float: right;
51
+ }
52
+
53
+ .debe{
54
+ color: red;
55
+ }
56
+
57
+ .haber{
58
+ color: green;
59
+ }
@@ -0,0 +1,80 @@
1
+ body {
2
+ background-color: #fff;
3
+ color: #333;
4
+ margin: 33px;
5
+ }
6
+
7
+ body, p, ol, ul, td {
8
+ font-family: verdana, arial, helvetica, sans-serif;
9
+ font-size: 13px;
10
+ line-height: 18px;
11
+ }
12
+
13
+ pre {
14
+ background-color: #eee;
15
+ padding: 10px;
16
+ font-size: 11px;
17
+ }
18
+
19
+ a {
20
+ color: #000;
21
+ }
22
+
23
+ a:visited {
24
+ color: #666;
25
+ }
26
+
27
+ a:hover {
28
+ color: #fff;
29
+ background-color: #000;
30
+ }
31
+
32
+ th {
33
+ padding-bottom: 5px;
34
+ }
35
+
36
+ td {
37
+ padding: 0 5px 7px;
38
+ }
39
+
40
+ div.field,
41
+ div.actions {
42
+ margin-bottom: 10px;
43
+ }
44
+
45
+ #notice {
46
+ color: green;
47
+ }
48
+
49
+ .field_with_errors {
50
+ padding: 2px;
51
+ background-color: red;
52
+ display: table;
53
+ }
54
+
55
+ #error_explanation {
56
+ width: 450px;
57
+ border: 2px solid red;
58
+ padding: 7px 7px 0;
59
+ margin-bottom: 20px;
60
+ background-color: #f0f0f0;
61
+ }
62
+
63
+ #error_explanation h2 {
64
+ text-align: left;
65
+ font-weight: bold;
66
+ padding: 5px 5px 5px 15px;
67
+ font-size: 12px;
68
+ margin: -7px -7px 0;
69
+ background-color: #c00;
70
+ color: #fff;
71
+ }
72
+
73
+ #error_explanation ul li {
74
+ font-size: 12px;
75
+ list-style: square;
76
+ }
77
+
78
+ label {
79
+ display: block;
80
+ }
@@ -0,0 +1,38 @@
1
+ module ClientEngine
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ helper_method :sort_column, :sort_direction
5
+
6
+ def sort_column(class_name)
7
+ params[:sort] ||= ""
8
+ if params[:sort].split(".").count > 1
9
+ clase = Object.const_get (params[:sort].split(".").last(2).first.titleize.gsub(" ", ""))
10
+ if clase.column_names.include?(params[:sort].split(".").last.to_s)
11
+ [params[:sort].split(".").last(2).first.pluralize, params[:sort].split(".").last].join(".")
12
+ else
13
+ "#{class_name.titleize.parameterize.underscore.pluralize}.updated_at"
14
+ end
15
+ else
16
+ clase = Object.const_get (class_name)
17
+ clase.column_names.include?(params[:sort]) ? "#{class_name.titleize.parameterize.underscore.pluralize}.#{params[:sort].to_s}" : "#{class_name.titleize.parameterize.underscore.pluralize}.updated_at"
18
+ end
19
+ end
20
+
21
+
22
+ def sort_direction
23
+ %w[asc desc].include?(params[:direction]) ? params[:direction] : "desc"
24
+ end
25
+
26
+ def get_client_data_from_afip
27
+ timeout_in_seconds = 5
28
+ begin
29
+ Timeout::timeout(timeout_in_seconds) do
30
+ response = [::Afip::Padron.new(dni: params[:document], tipo: "F").get_data, ::Afip::Padron.new(dni: params[:document], tipo: "M").get_data] unless params[:document].blank?
31
+ render status: 200, json: response.compact.first
32
+ end
33
+ rescue
34
+ render json: ["",""]
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,63 @@
1
+ require_dependency "client_engine/application_controller"
2
+
3
+ module ClientEngine
4
+ class ClientsController < ApplicationController
5
+ before_action :set_client, only: [:show, :edit, :update, :destroy]
6
+
7
+ # GET /clients
8
+ def index
9
+ @clients = current_user.clients.search(params[:search]).paginate(page: params[:page], per_page: 10)
10
+ end
11
+
12
+ # GET /clients/1
13
+ def show
14
+ end
15
+
16
+ # GET /clients/new
17
+ def new
18
+ @client = Client.new
19
+ end
20
+
21
+ # GET /clients/1/edit
22
+ def edit
23
+ end
24
+
25
+ # POST /clients
26
+ def create
27
+ @client = Client.new(client_params)
28
+ @client.company_id = current_user.company_id
29
+
30
+ if @client.save
31
+ redirect_to @client, notice: 'Client was successfully created.'
32
+ else
33
+ render :new
34
+ end
35
+ end
36
+
37
+ # PATCH/PUT /clients/1
38
+ def update
39
+ if @client.update(client_params)
40
+ redirect_to @client, notice: 'Client was successfully updated.'
41
+ else
42
+ render :edit
43
+ end
44
+ end
45
+
46
+ # DELETE /clients/1
47
+ def destroy
48
+ @client.destroy
49
+ redirect_to clients_url, notice: 'Client was successfully destroyed.'
50
+ end
51
+
52
+ private
53
+ # Use callbacks to share common setup or constraints between actions.
54
+ def set_client
55
+ @client = Client.find(params[:id])
56
+ end
57
+
58
+ # Only allow a trusted parameter "white list" through.
59
+ def client_params
60
+ params.require(:client).permit(:first_name, :last_name, :phone, :email, :address, :document, :document_type, :birthday, :country, :city, :locality, :iva_category, :balance)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,5 @@
1
+ module ClientEngine
2
+ module ApplicationHelper
3
+ include FontAwesome::Rails::IconHelper
4
+ end
5
+ end
@@ -0,0 +1,176 @@
1
+ module ClientEngine
2
+ module ClientsHelper
3
+
4
+ ### BEGIN SORTABLE ###
5
+ def sortable(column,class_name, title = nil)
6
+ title ||= column.titleize
7
+ if column.split(".").count >= 2
8
+ css_class = (
9
+ (column.split(".").last.to_s == sort_column(class_name).split(".").last.to_s) &&
10
+ (column.split(".").last(2).first.pluralize.to_s == sort_column(class_name).split(".").last(2).first.pluralize.to_s)
11
+ ) ? "#{sort_direction}" : nil
12
+ css_class = css_class == "asc" ? "long-arrow-down" : (css_class == "desc" ? "long-arrow-up" : nil)
13
+ else
14
+ css_class = column.split(".").last.to_s == sort_column(class_name).split(".").last.to_s ? "#{sort_direction}" : nil
15
+ css_class = css_class == "asc" ? "long-arrow-down" : (css_class == "desc" ? "long-arrow-up" : nil)
16
+ end
17
+ column.split(".").to_s
18
+ sort_column(class_name).split(".").to_s
19
+ css_class
20
+
21
+ direction = (column.split(".").last.to_s == sort_column(class_name).split(".").last.to_s && sort_direction == "asc") ? "desc" : "asc"
22
+ link_to "#{fa_icon(css_class)} #{title}".html_safe, {sort: column, direction: direction, search: params[:search]}, {remote: true}
23
+ end
24
+ ### END SORTABLE #####
25
+
26
+ ### BEGIN HELPER TITULO ###
27
+ def titulo icono,texto
28
+ @icono = icono
29
+ @texto = texto
30
+ content_for :title do
31
+ content_tag :div, class: :row do
32
+ concat(title_row)
33
+ end
34
+ end
35
+ end
36
+
37
+ def title_row
38
+ content_tag :div,class:'col-xs-10 col-sm-11 col-md-11' do
39
+ concat(title)
40
+ end
41
+ end
42
+
43
+ def title
44
+ content_tag :h1 do
45
+ concat(fa_icon(@icono))
46
+ concat(" " + @texto)
47
+ end
48
+ end
49
+ ### END HELPER TITULO #####
50
+
51
+ ### BEGIN SEARCH FORM CLIENTE ###
52
+ def search_form_client path, link_text, link_path
53
+ @path = path
54
+ @link_text = link_text
55
+ @link_path = link_path
56
+
57
+ content_tag :div, id:'buscador' do
58
+ concat(row)
59
+ end
60
+ end
61
+
62
+ def row
63
+ content_tag :div, class: 'row' do
64
+ concat(column_div_form)
65
+ concat(column_div_link)
66
+ end
67
+ end
68
+
69
+ def column_div_form
70
+ content_tag :div, class: 'col-xs-12 col-sm-8 col-md-8' do
71
+ concat(form)
72
+ end
73
+ end
74
+
75
+ def column_div_link
76
+ content_tag :div, class:'col-xs-12 col-sm-4 col-md-4', style: 'text-align: right;' do
77
+ concat(link)
78
+ end
79
+ end
80
+
81
+ def form
82
+ form_tag @path, :method => 'get', :id => "search_form", remote: true do
83
+ content_tag :div, class:' form-inline' do
84
+ concat( input_groups)
85
+ end
86
+ end
87
+ end
88
+
89
+ def link
90
+ if !@link_path.nil? && @modal_id.nil?
91
+ link_to "#{fa_icon('plus')} #{@link_text}".html_safe, @link_path, class:'btn btn-primary full-btn margin-btn'
92
+ elsif !@link_path.nil? && !@modal_id.nil?
93
+ link_to "#{fa_icon('plus')} #{@link_text}".html_safe, @link_path, class:'btn btn-primary full-btn margin-btn', remote: true, "data-toggle" => "modal", "data-target" => @modal_id
94
+ end
95
+ end
96
+
97
+ def input_groups
98
+ content_tag :div, class:'input-group' do
99
+ concat(content_tag :div, 'Buscar', class:'input-group-addon')
100
+ concat(text_field_tag :search, params[:search], class: 'form-control', size: 50, onkeyup: 'remoteSubmit("#search_form");', autofocus: true )
101
+ concat(input_group_addon)
102
+ end
103
+ end
104
+
105
+ def input_group_addon
106
+ content_tag :div, class: 'input-group-addon' do
107
+ concat(content_tag :span,'', class:'glyphicon glyphicon-search', aria:{hidden:'true'})
108
+ end
109
+ end
110
+ ### END SEARCH FORM CLIENTE #####
111
+
112
+
113
+ ### BEGIN PAGINATE ####
114
+ def paginate resource, options = nil
115
+ if not options
116
+ @resource = resource
117
+ content_tag :div, style: 'text-align: center;' do
118
+ concat(will_paginate_helper)
119
+ concat(javascript_paginate_helper)
120
+ end
121
+ end
122
+ end
123
+ def will_paginate_helper
124
+ will_paginate @resource, :page_links => true,
125
+ :inner_window => 1,
126
+ :outer_window => 1,
127
+ :previous_label => '← Anterior',
128
+ :next_label => 'Siguiente →',
129
+ renderer: BootstrapPagination::Rails
130
+ end
131
+
132
+ def javascript_paginate_helper
133
+ javascript_tag("$('ul.pagination a').click(function(){$.getScript(this.href); return false; });")
134
+ end
135
+ ### END PAGINATE #####
136
+
137
+ ### BEGIN ERROR EXPLANATION ###
138
+ def error_explanation object
139
+ @object = object
140
+ if not object.nil?
141
+ content_tag :div do
142
+ concat(errors_flash)
143
+ end
144
+ end
145
+ end
146
+
147
+ def errors_flash
148
+ if @object.errors.any?
149
+ content_tag :div, class: "alert alert-danger", role:"alert" do
150
+ concat("<strong>Se produjeron los siguientes errores:</strong>".html_safe)
151
+ concat(error_explanation_loop)
152
+ end
153
+ end
154
+ end
155
+
156
+
157
+ def error_explanation_loop
158
+ content_tag :ul do
159
+ @object.errors.full_messages.each do |message|
160
+ concat(li_message(message))
161
+ end
162
+ end
163
+ end
164
+
165
+ def li_message message
166
+ content_tag :li do
167
+ "#{message}"
168
+ end
169
+ end
170
+ ### BEGIN ERROR EXPLANATION ######
171
+
172
+ def correo(client)
173
+ link_to client.email , "mailto:"+client.email, target:"_top"
174
+ end
175
+ end
176
+ end