Prechádzať zdrojové kódy

Added support module and custom error pages

Jacqueline Maldonado 7 rokov pred
rodič
commit
e8ac4e4797

+ 3 - 0
app/assets/javascripts/errors.coffee

@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/

+ 3 - 0
app/assets/javascripts/supports.coffee

@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://coffeescript.org/

+ 3 - 0
app/assets/stylesheets/errors.scss

@@ -0,0 +1,3 @@
+// Place all the styles related to the errors controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/

+ 3 - 0
app/assets/stylesheets/supports.scss

@@ -0,0 +1,3 @@
+// Place all the styles related to the supports controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/

+ 14 - 0
app/controllers/errors_controller.rb

@@ -0,0 +1,14 @@
+class ErrorsController < ApplicationController
+  def not_found
+    render(status: 404)
+  end
+
+  def internal_server_error
+    render(status: 500)
+  end
+
+  def show
+    status = params[:code] || 500
+    render status.to_s, status: status
+  end
+end

+ 20 - 0
app/controllers/supports_controller.rb

@@ -0,0 +1,20 @@
+class SupportsController < ApplicationController
+  ##--- Breadcrum_rails
+  add_breadcrumb I18n.t("breadcrumbs." + controller_name), :supports_path
+  add_breadcrumb "Soporte Técnico", :contact_support_path, only: :contact_support
+
+  def contact_support
+    if params[:support].present?
+      returns = false
+      params[:support].map { |x, y| returns = true if y.blank? }
+      respond_to do |format|
+        if returns
+          format.js { render "contact_support", locals: { notice: "Debe llenar todos los campos del formulario." } }
+        else
+          SupportMailer.contact_support(params[:support], current_user).deliver_now
+          format.js
+        end
+      end
+    end
+  end
+end

+ 2 - 0
app/helpers/errors_helper.rb

@@ -0,0 +1,2 @@
+module ErrorsHelper
+end

+ 2 - 0
app/helpers/supports_helper.rb

@@ -0,0 +1,2 @@
+module SupportsHelper
+end

+ 4 - 0
app/mailers/application_mailer.rb

@@ -0,0 +1,4 @@
+class ApplicationMailer < ActionMailer::Base
+  default from: "from@example.com"
+  layout 'mailer'
+end

+ 14 - 0
app/mailers/support_mailer.rb

@@ -0,0 +1,14 @@
+class SupportMailer < ApplicationMailer
+  default from: 'noreply@sml.mx'
+
+  def contact_support(params, user)
+    @user = user
+    @error_descriptor = params[:error_descriptor]
+    @comments = params[:comments]
+    @usertype = params[:usertype]
+    @sucursal = params[:sucursal]
+    mail(to: Rails.application.config.support_mails, subject: 'Soporte Técnico POS Boutique') do |format|
+      format.html
+    end
+  end
+end

+ 25 - 0
app/views/errors/internal_server_error.html.erb

@@ -0,0 +1,25 @@
+<div class="page-container">
+  <div class="page-content-wrapper">
+    <div class="page-head">
+      <div class="container-fluid">
+        <div class="page-title">
+          <h1>Error del sistema </h1>
+        </div>
+      </div>
+    </div>
+    <div class="page-content">
+      <div class="container-fluid">
+        <div class="row">
+          <div class="col-md-12">
+            <div class="portlet light bordered">
+              <div class="portlet-body">
+                Por favor contacte al administrador del sistema. </span>
+                <%= render "supports/contact_support" %>
+              </div>
+            </div>
+          </div>
+        </div>
+      </div>
+    </div>
+  </div>
+</div>

+ 11 - 0
app/views/errors/not_found.html.erb

@@ -0,0 +1,11 @@
+<div class="page-container">
+  <div class="page-content-wrapper">
+    <div class="page-head">
+      <div class="container-fluid">
+        <div class="page-title">
+          <h1>No se encontró la página </h1>
+        </div>
+      </div>
+    </div>
+  </div>
+</div>

+ 5 - 0
app/views/layouts/mailer.html.erb

@@ -0,0 +1,5 @@
+<html>
+  <body>
+    <%= yield %>
+  </body>
+</html>

+ 1 - 0
app/views/layouts/mailer.text.erb

@@ -0,0 +1 @@
+<%= yield %>

+ 31 - 0
app/views/support_mailer/contact_support.html.erb

@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
+  </head>
+  <body>
+    <h1>SOPORTE TÉCNICO </h1>
+    <p>
+      Por favor analice la siguiente información y hágala llegar a los encargados de POS Boutique
+      <br>
+      <table>
+        <thead>
+          <th>Registró</th>
+          <th>Sucursal</th>
+          <th>Tipo de usuario</th>
+          <th>Descripción del error</th>
+          <th>Observaciones/Comentarios</th>
+        </thead>
+        <tbody>
+          <tr>
+            <td><%= @user.full_name %><br><small><%= @user.userid %></small></td>
+            <td><%= @sucursal %></td>
+            <td class="text-center"><%= @usertype %></td>
+            <td><%= @error_descriptor %></td>
+            <td><%= @comments %></td>
+          </tr>
+        </tbody>
+      </table>
+    </p>
+  </body>
+</html>

+ 41 - 0
app/views/supports/_contact_support.html.erb

@@ -0,0 +1,41 @@
+<%= form_tag(contact_support_path, { method: "get", remote: true, id: "contact_support_form", class: "form-horizontal" }) do %>
+  <div class="portlet-body form">
+    <div class="form-body col-md-offset-1">
+      <div class="note note-danger">
+        <h4 class="block">Por favor llene el siguiente formulario, describiendo el problema y el proceso que le llevó a él lo más detalladamente posible. Al terminar, presione Enviar.</h4>
+      </div>
+      <div class="form-group ">
+        <%= label :sucursal, "", { class: "col-md-2 col-sm-2 control-label" } do %>Sucursal <span class="required">*</span> <% end %>
+        <div class="col-md-4 col-sm-5">
+          <%= text_field_tag :sucursal, "", class: "form-control input-large", name: "support[sucursal]" %>
+        </div>
+      </div>
+      <div class="form-group">
+        <%= label :usertype, "", { class: "col-md-2 col-sm-2 control-label" } do %>Tipo de pefil <span class="required">*</span> <span class="tooltips" title="El tipo de perfil con el que se experimentó el error"><i class="fa fa-question-circle"></i></span> <% end %>
+        <div class="col-md-4 col-sm-4">
+          <%= select_tag :usertype, options_for_select(Rails.application.config.usertypes_for_admin), { class: 'form-control input-medium', name: "support[usertype]" } %>
+        </div>
+      </div>
+      <div class="form-group">
+        <%= label :error_descriptor, "", { class: "col-md-2 col-sm-2 control-label" } do %>Descripción del error <span class="required">*</span> <% end %>
+        <div class="col-md-4 col-sm-4">
+          <%= text_area_tag :error_descriptor, "", class: "form-control", name: "support[error_descriptor]", rows: 5 %>
+        </div>
+      </div>
+      <div class="form-group">
+        <%= label :comments, "", { class: "col-md-2 col-sm-2 control-label" } do %>Observaciones <span class="required">*</span> <% end %>
+        <div class="col-md-4 col-sm-4">
+          <%= text_area_tag :comments, "", class: "form-control", name: "support[comments]", rows: 5 %>
+        </div>
+      </div>
+    </div>
+    <div class="form-actions">
+      <div class="row">
+        <div class="col-md-offset-3 col-md-9 col-sm-offset-2 col-sm-3">
+          <%= submit_tag 'Enviar', { class: "btn green" } %>
+          <%= link_to 'Cancelar', root_path, { class: "btn default" } %>
+        </div>
+      </div>
+    </div>
+  </div>
+<% end %>

+ 28 - 0
app/views/supports/contact_support.html.erb

@@ -0,0 +1,28 @@
+<div class="page-container">
+  <div class="page-content-wrapper">
+    <div class="page-head">
+      <div class="container-fluid">
+        <div class="page-title">
+          <h1>Soporte Técnico</h1>
+        </div>
+      </div>
+    </div>
+    <div class="page-content">
+      <div class="container-fluid">
+        <ul class="page-breadcrumb breadcrumb">
+
+        </ul>
+        <div class="page-content-inner">
+          <div class="note note-warning hidden" id="notice">
+            <h4 class="block"></h4>
+          </div>
+          <div class="portlet light">
+            <div class="portlet-body ">
+              <%= render 'contact_support' %>
+            </div>
+          </div>
+        </div>
+      </div>
+    </div>
+  </div>
+</div>

+ 7 - 0
app/views/supports/contact_support.js.erb

@@ -0,0 +1,7 @@
+<% if notice %>
+  $("#notice").removeClass("hidden");
+  $("#notice").html("<%= notice %>");
+<% else %>
+  location.reload();
+  alert("La información ha sido enviada al administrador del sitio.");
+<% end %>

+ 5 - 0
config/application.rb

@@ -22,6 +22,7 @@ module Pos
     # config.i18n.default_locale = :de
 
     # Do not swallow errors in after_commit/after_rollback callbacks.
+    config.exceptions_app = self.routes
     config.action_view.embed_authenticity_token_in_remote_forms = true
     config.active_record.raise_in_transactional_callbacks = true
     config.usertypes_for_super = {
@@ -43,5 +44,9 @@ module Pos
       "Almacenista" => "S",
       "Caja" => "C"
     }
+
+    config.support_mails = [
+      "daniel.mendoza@sml.mx"
+    ]
   end
 end

+ 10 - 8
config/environments/development.rb

@@ -44,16 +44,18 @@ Rails.application.configure do
 	# config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
 	config.action_mailer.default_url_options = { :host => 'localhost:3000' }
 	config.active_support.deprecation = :log
+	config.action_mailer.delivery_method = :smtp
 
 	config.action_mailer.smtp_settings ={
-		:address            => 'mail.sml.mx',
-		:port               => 25,
-		:tls                => false,
-		:domain             => 'sml.mx',
-		:authentication     => :login,
-		:user_name          => 'noreply@sml.mx',
-		:password           => 'NoReply123',
-		:enable_starttls_auto => false
+		address:               'smtp.sml.mx',
+		port:                  587,
+		tls:                   false,
+		domain:                'sml.mx',
+		authentication:        :login,
+		user_name:             'noreply@sml.mx',
+		password:              'NoReply123',
+		enable_starttls_auto:  false,
+		return_response:       true
 	}
 
 

+ 20 - 0
config/navigation.rb

@@ -123,6 +123,11 @@ SimpleNavigation::Configuration.run do |navigation|
         sub_nav.item :divider_after_list_transfers, '#', divider: true
         sub_nav.item :list_users, 'Usuarios del sistema', users_path
       end
+      # soporte
+      primary.item :support, { icon: "fa fa-fw fa-group", text: "Soporte" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
+        sub_nav.dom_attributes = { class: "dropdown-menu pull-left" }
+        sub_nav.item :send_info, "Soporte técnico", contact_support_path
+      end
     end
 
     if current_user.usertype == 'G'
@@ -201,6 +206,11 @@ SimpleNavigation::Configuration.run do |navigation|
         sub_nav.item :divider_after_list_transfers, '#', divider: true
         sub_nav.item :list_users, 'Usuarios del sistema', users_path
       end
+      # soporte
+      primary.item :support, { icon: "fa fa-fw fa-group", text: "Soporte" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
+        sub_nav.dom_attributes = { class: "dropdown-menu pull-left" }
+        sub_nav.item :send_info, "Soporte técnico", contact_support_path
+      end
     end
 
     if current_user.usertype == 'C'
@@ -249,6 +259,11 @@ SimpleNavigation::Configuration.run do |navigation|
         sub_nav.item :new_transfer, 'Nuevo traspaso', new_transfer_path
         sub_nav.item :list_expenses, 'Lista de traspasos', transfers_path
       end
+      # soporte
+      primary.item :support, { icon: "fa fa-fw fa-group", text: "Configuración" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
+        sub_nav.dom_attributes = { class: "dropdown-menu pull-left" }
+        sub_nav.item :send_info, "Soporte técnico", contact_support_path
+      end
     end
 
     if current_user.usertype == 'S'
@@ -270,6 +285,11 @@ SimpleNavigation::Configuration.run do |navigation|
         sub_nav.item :initial_stock, 'Inventario inicial', products_initial_stock_path(current_user.warehouse_id)
         sub_nav.item :stock_adjustment, 'Ajuste de inventario', products_stock_path(current_user.warehouse_id)
       end
+      # soporte
+      primary.item :support, { icon: "fa fa-fw fa-group", text: "Soporte" }, '#', class: 'menu-dropdown classic-menu-dropdown' do |sub_nav|
+        sub_nav.dom_attributes = { class: "dropdown-menu pull-left" }
+        sub_nav.item :send_info, "Soporte técnico", contact_support_path
+      end
     end
 
     class BootstrapBreadcrumbs < SimpleNavigation::Renderer::Base

+ 6 - 0
config/routes.rb

@@ -14,6 +14,9 @@ Rails.application.routes.draw do
     sign_up: 'cmon_let_me_in'
   }
 
+  match "/404", to: "errors#not_found", via: :all
+  match "/500", to: "errors#internal_server_error", via: :all
+
   devise_scope :user do
     get "login", to: "devise/sessions#new"
     get "logout", to: "devise/sessions#destroy"
@@ -248,5 +251,8 @@ Rails.application.routes.draw do
 
   ## reports
   get "min_max" => "reports#min_max"
+
+  ## soporte
+  get "contact_support" => "supports#contact_support"
 end
 # rubocop:enable Metrics/BlockLength