Created
January 19, 2014 22:39
-
-
Save HudsonAfonso/8511963 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Defines our constants | |
PADRINO_ENV = ENV['PADRINO_ENV'] ||= ENV['RACK_ENV'] ||= 'development' unless defined?(PADRINO_ENV) | |
PADRINO_ROOT = File.expand_path('../..', __FILE__) unless defined?(PADRINO_ROOT) | |
# Load our dependencies | |
require 'rubygems' unless defined?(Gem) | |
require 'bundler/setup' | |
Bundler.require(:default, PADRINO_ENV) | |
Mongoid::History.modifier_class_name = 'Account' | |
#Mongoid::History.current_user_method = :current_account | |
## | |
# ## Enable devel logging | |
# | |
# Padrino::Logger::Config[:development][:log_level] = :devel | |
# Padrino::Logger::Config[:development][:log_static] = true | |
# | |
# ## Configure your I18n | |
# | |
I18n.default_locale = :pt_br | |
# | |
# ## Configure your HTML5 data helpers | |
# | |
# Padrino::Helpers::TagHelpers::DATA_ATTRIBUTES.push(:dialog) | |
# text_field :foo, :dialog => true | |
# Generates: <input type="text" data-dialog="true" name="foo" /> | |
# | |
# ## Add helpers to mailer | |
# | |
# Mail::Message.class_eval do | |
# include Padrino::Helpers::NumberHelpers | |
# include Padrino::Helpers::TranslationHelpers | |
# end | |
## | |
# Add your before (RE)load hooks here | |
# | |
Padrino.before_load do | |
[:default, :short,:long].each do |format| | |
Time::DATE_FORMATS[format] = lambda { |time| I18n.l(time, :format => format) } | |
Date::DATE_FORMATS[format] = lambda { |date| I18n.l(date, :format => format) } | |
end | |
Paperclip.options[:logger] = Padrino.logger | |
Paperclip::Attachment.default_options[:path] = Padrino.root('/public/:attachment/:id/:basename.:extension') | |
end | |
## | |
# Add your after (RE)load hooks here | |
# | |
Padrino.after_load do | |
end | |
module Padrino | |
module Helpers | |
module FormBuilder | |
class StandardFormBuilder | |
def label(field, options={}, &block) | |
options.reverse_merge!(:caption => "#{field_human_name(field)}") | |
@template.label_tag(field_id(field), options, &block) | |
end | |
end | |
end | |
end | |
end | |
Padrino.load! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-# coding: UTF-8 | |
.row | |
.col-md-6 | |
%fieldset | |
%legend Dados Gerais | |
.form-group | |
%label.col-md-4.control-label ID | |
.col-md-8 | |
%p.form-control-static='%04d' % @incident.number.to_s | |
.form-group | |
%label.col-md-4.control-label Solicitante | |
.col-md-8 | |
%p.form-control-static | |
="#{@incident.client.name} #{@incident.client.surname}" | |
%span.label.label-default{:style => 'font-weight: normal;'}=@incident.client.company_name | |
=text_field f, :description | |
.form-group | |
=f.label :module, :class => 'col-md-4 control-label' | |
.col-md-8 | |
=f.select :module, :options => ['CO', 'FI', 'MM', 'PP', 'QM', 'PM', 'SD', 'ABAP', 'Basis', 'Outros'], :class => 'form-control' | |
-if current_account.role != 'Cliente' and current_account.role != 'Consultor' | |
-error = @incident.errors.include?(:collaborator) | |
.form-group{:class => error ? 'has-error' : ''} | |
=f.label :collaborator, :class => 'col-md-4 control-label' | |
.col-md-8 | |
=f.select :collaborator__id, :options => ['', @collaborators.collect{|i| ["#{i.name} #{i.surname}", i.id]}].flatten(1), :class => 'form-control' | |
%span.help-block=error ? f.error_message_on(:collaborator, :class => 'text-error') : '' | |
-elsif @incident.collaborator | |
.form-group | |
%label.col-md-4.control-label Colaborador | |
.col-md-8 | |
%p.form-control-static | |
="#{@incident.collaborator.name} #{@incident.collaborator.surname}" | |
.form-group | |
=f.label :level, :class => 'col-md-4 control-label' | |
.col-md-8 | |
=f.select :level, :options => ['Suporte a Usuários de Negócio','Suporte a Usuários Funcionais','Suporte a Usuários Operacionais', 'Manutenções - Ajustes Menores', 'Manutenções - Ajustes Legais e Fiscais', 'Manutenções - Corretivas', 'Manutenções - Ajustes Preventivas' ], :class => 'form-control' | |
.form-group | |
=f.label :priority, :class => 'col-md-4 control-label' | |
.col-md-8 | |
=f.select :priority, :options => ['ADOPTI0 - Emergência (processo parado)', 'ADOPTI1 - Suporte à Produção', 'ADOPTI2 - Manutenções Menores', 'ADOPTI3 - Melhorias Menores'], :class => 'form-control' | |
.form-group | |
=f.label :status, :class => 'col-md-4 control-label' | |
.col-md-8 | |
=f.select :status, :options => ['Cancelado pelo Usuário','Aguardando por conhecimento da solução','Aguardando Aprovação pelo Usuário', 'Aprovado pelo Usuário', 'Em Análise / Estimativa', 'Em Desenvolviemnto', 'Pronto para transporte à Produção', 'Em testes pelos Funcionários', 'Em teste pelos Usuários - Cliente', 'Aguardando Aprovação dos Usuários - Testes', 'Testes aprovados pelos Usuários', 'Encerrado' ], :class => 'form-control' | |
%fieldset | |
%legend Datas | |
-if current_account.role == 'Cliente' | |
-if @incident.time_estimated | |
.form-group | |
%label.col-md-4.control-label Solicitando em | |
.col-md-8 | |
%p.form-control-static | |
%code=@incident.created_at.strftime("%F %H:%M") | |
-else | |
=text_field f, :time_estimated | |
.form-group | |
%label.col-md-4.control-label Solicitando em | |
.col-md-8 | |
%p.form-control-static | |
%code=@incident.created_at.strftime("%F %H:%M") | |
%fieldset | |
%legend Pessoas Envolvidas | |
=text_field f, :name_1 | |
=text_field f, :name_2 | |
=text_field f, :name_3 | |
.col-md-6 | |
%fieldset | |
%legend Log | |
.form-group | |
.col-md-12 | |
-@tracks.each do |track| | |
.note | |
.clearfix | |
.pull-left | |
-if track.modifier.class.to_s == 'Client' | |
%span.label.label-warning{:style => 'background-color: #E67E22'}="#{track.modifier.name} #{track.modifier.surname}" | |
-else | |
%span.label.label-default{:style => 'background-color: #34495E'}="#{track.modifier.name} #{track.modifier.surname}" | |
.pull-right | |
%abbr.timeago{:title => track.created_at.getutc.iso8601}=track.created_at.to_s | |
%pre=track.modified['notes'] | |
%fieldset | |
%legend Nota | |
.form-group | |
.col-md-12 | |
=f.text_area :_notes, :class => 'form-control', :rows => '9' | |
%fieldset | |
%legend Arquivos | |
%table.table.table-striped | |
%tbody | |
-docs = @incident.docs.flatten | |
-docs.pop | |
-docs.each do |doc| | |
%tr | |
%td | |
%a{:href => doc.attachment.url, :target => '_blank'}=doc.attachment_file_name | |
%td{:style => 'text-align: right;'}=doc.attachment_updated_at.strftime("%F %H:%M") | |
- f.fields_for :docs, :doc do |rf| | |
.form-group | |
.col-md-12 | |
.fileupload.fileupload-new{"data-provides" => "fileupload"} | |
%span.btn.btn-default.btn-file | |
%span.fileupload-new Adicionar Arquivo | |
%span.fileupload-exists Mudar | |
=rf.file_field :attachment | |
%span.fileupload-preview | |
%a.close.fileupload-exists{"data-dismiss" => "fileupload", :href => "#", :style => "float: none"} × | |
.row | |
.col-md-6 | |
.form-group | |
.col-md-offset-4.col-md-8 | |
=f.submit pat(:save), :class => 'btn btn-default btn-primary', :name => 'save_and_continue' | |
=f.submit "Cancelar", :onclick => "window.location='#{url(:incidents, :index)}';return false", :class => 'btn btn-link' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'mongoid-paperclip', :require => 'mongoid_paperclip' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Incident | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
include Mongoid::Paranoia | |
include Mongoid::Sequence | |
include Mongoid::History::Trackable | |
# => General Data | |
field :number, :type => Integer | |
sequence :number | |
field :description | |
belongs_to :client | |
belongs_to :collaborator | |
field :collaborator__id | |
field :module | |
has_many :docs | |
accepts_nested_attributes_for :docs, :allow_destroy => true | |
# => Processing Data | |
field :status | |
field :level | |
field :priority | |
# => Notes | |
field :notes | |
# => Dates | |
field :time_estimated, :type => Integer | |
# Related People | |
field :name_1 | |
field :name_2 | |
field :name_3 | |
belongs_to :updated_by, :class_name => "Account" | |
def self.resquested_start | |
self.created_at | |
end | |
def self.resquested_end | |
if self.status == 'Encerrado' | |
self.updated_at | |
end | |
end | |
def self.first_response_by | |
end | |
track_history :on => [:notes, :time_estimated], :track_create => true, :track_update => true, :track_destroy => false | |
end | |
class Doc | |
include Mongoid::Document | |
include Mongoid::Paperclip | |
belongs_to :incident | |
field :tmp | |
has_mongoid_attached_file :attachment, { | |
:url => '/:attachment/:id/:basename.:extension' | |
} | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'base64' | |
Backoffice::App.controllers :incidents do | |
get :index do | |
@title = t('models.incident.name') | |
@incidents = Incident.all | |
render 'incidents/index' | |
end | |
get :new do | |
@title = pat(:new_title, :model => t('models.incident.name')) | |
@incident = Incident.new | |
render 'incidents/new' | |
end | |
post :create do | |
@incident = Incident.new(params[:incident].merge(modifier: current_account)) | |
# setar status | |
@incident.status = 'Em Análise / Estimativa' | |
# adicionar cliente | |
client = Client.find(current_account.id) | |
client.incidents.push(@incident) | |
token = "#{@incident.id.to_s}@5210bdefeb2c248bec000001" #id | |
result = String.new | |
key = '44c75e4bef47af6d3566b8828add43535b3d76dcb3caa4be8eb64eccb9aacd40' | |
kl = key.length | |
i = 0 | |
n = token.length - 1 | |
for i in i..n | |
result << (token[i].ord ^ key[i % kl].ord) | |
end | |
token = Base64.urlsafe_encode64(result) | |
link = "http://#{request.env['HTTP_HOST']}/sessions/auth_token/#{token}" | |
link_txt = "http://#{request.env['HTTP_HOST']}/<wbr>sessions/auth_token/<wbr>#{token.scan(/.{1,30}/).join("<wbr>")}" | |
if @incident.save | |
email( | |
:from => 'AdopTI AMS <adopti@penseinteligente.com.br>', | |
:to => 'mr.void@gmail.com', | |
:subject => "Novo Incidente: #{@incident.description}", | |
:content_type => :html, | |
:body => email_body(@incident, link, link_txt) | |
) | |
@title = pat(:create_title, :model => "#{t('models.incident.name')} #{@incident.id}") | |
flash[:success] = pat(:create_success, :model => t('models.incident.name')) | |
params[:save_and_continue] ? redirect(url(:incidents, :index)) : redirect(url(:incidents, :edit, :id => @incident.id)) | |
else | |
@title = pat(:create_title, :model => t('models.incident.name')) | |
flash.now[:error] = pat(:create_error, :model => t('models.incident.name')) | |
render 'incidents/new' | |
end | |
end | |
get :edit, :with => :id do | |
@title = pat(:edit_title, :model => "#{t('models.incident.name')} #{params[:id]}") | |
@incident = Incident.find(params[:id]) | |
@incident.docs.build | |
if @incident | |
@tracks = @incident.history_tracks.where(:'modified.notes'.exists => true) | |
@collaborators = Collaborator.all | |
render 'incidents/edit' | |
else | |
flash[:warning] = pat(:create_error, :model => t('models.incident.name'), :id => "#{params[:id]}") | |
halt 404 | |
end | |
end | |
put :update, :with => :id do | |
notes = params[:incident].delete('_notes') | |
if notes != '' | |
params[:incident][:notes] = notes | |
end | |
if params[:incident][:docs_attributes] | |
att = params[:incident][:docs_attributes]['0'][:attachment] | |
class UploadedFile < OpenStruct; end | |
file = UploadedFile.new( | |
:original_filename => att[:filename], | |
:content_type => att[:type], | |
:head => "", | |
:tempfile => att[:tempfile], | |
:path => att[:tempfile].path | |
) | |
params[:incident][:docs_attributes]['0']['attachment'] = file | |
end | |
@title = pat(:update_title, :model => "#{t('models.incident.name')} #{params[:id]}") | |
@incident = Incident.find(params[:id]) | |
if @incident | |
@tracks = @incident.history_tracks.where(:'modified.notes'.exists => true) | |
@collaborators = Collaborator.all | |
if @incident.update_attributes(params[:incident].merge(modifier: current_account)) | |
Mongoid::History.disable do | |
if params[:incident][:collaborator__id] and not @incident.collaborator | |
collab = Collaborator.find(params[:incident][:collaborator__id]) | |
@incident.collaborator = collab | |
collab.incidents.push(@incident) | |
collab.update | |
token = "#{@incident.id.to_s}@#{params[:incident][:collaborator__id]}" #id | |
result = String.new | |
key = '44c75e4bef47af6d3566b8828add43535b3d76dcb3caa4be8eb64eccb9aacd40' | |
kl = key.length | |
i = 0 | |
n = token.length - 1 | |
for i in i..n | |
result << (token[i].ord ^ key[i % kl].ord) | |
end | |
token = Base64.urlsafe_encode64(result) | |
link = "http://#{request.env['HTTP_HOST']}/sessions/auth_token/#{token}" | |
link_txt = "http://#{request.env['HTTP_HOST']}/<wbr>sessions/auth_token/<wbr>#{token.scan(/.{1,30}/).join("<wbr>")}" | |
email( | |
:from => 'AdopTI AMS <adopti@penseinteligente.com.br>', | |
:to => collab.email, | |
:subject => "Novo Incidente: #{@incident.description}", | |
:content_type => :html, | |
:body => email_body(@incident, link, link_txt) | |
) | |
end | |
end | |
flash[:success] = pat(:update_success, :model => t('models.incident.name'), :id => "#{params[:id]}") | |
params[:save_and_continue] ? | |
redirect(url(:incidents, :index)) : | |
redirect(url(:incidents, :edit, :id => @incident.id)) | |
else | |
flash.now[:error] = pat(:update_error, :model => t('models.incident.name')) | |
render 'incidents/edit' | |
end | |
else | |
flash[:warning] = pat(:update_warning, :model => t('models.incident.name'), :id => "#{params[:id]}") | |
halt 404 | |
end | |
end | |
get :destroy, :with => :id do | |
@title = t('models.incident.name') | |
incident = Incident.find(params[:id]) | |
if incident | |
if incident != current_incident && incident.destroy | |
flash[:success] = pat(:delete_success, :model => t('models.incident.name'), :id => "#{params[:id]}") | |
else | |
flash[:error] = pat(:delete_error, :model => t('models.incident.name')) | |
end | |
redirect url(:incidents, :index) | |
else | |
flash[:warning] = pat(:delete_warning, :model => t('models.incident.name'), :id => "#{params[:id]}") | |
halt 404 | |
end | |
end | |
delete :destroy_many do | |
@title = t('models.incident.name') | |
unless params[:incident_ids] | |
flash[:error] = pat(:destroy_many_error, :model => t('models.incident.name')) | |
redirect(url(:incidents, :index)) | |
end | |
ids = params[:incident_ids].split(',').map(&:strip) | |
incidents = Incident.find(ids) | |
if incidents.include? current_incident | |
flash[:error] = pat(:delete_error, :model => t('models.incident.name')) | |
elsif incidents.each(&:destroy) | |
flash[:success] = pat(:destroy_many_success, :model => t('models.incident.name'), :ids => "#{ids.to_sentence}") | |
end | |
redirect url(:incidents, :index) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment