harvey 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +28 -0
- data/app/controllers/widgets_controller.rb +22 -0
- data/app/helpers/widgets_helper.rb +2 -0
- data/app/models/asset.rb +8 -0
- data/app/models/company.rb +14 -0
- data/app/models/document.rb +12 -0
- data/app/models/image.rb +12 -0
- data/app/models/tenant_model.rb +20 -0
- data/app/models/widget.rb +8 -0
- data/app/views/widgets/_form.html.erb +75 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20110811022046_create_companies.rb +16 -0
- data/db/migrate/20111010170545_create_assets.rb +14 -0
- data/db/migrate/20111010171238_create_widgets.rb +13 -0
- data/lib/harvey.rb +4 -0
- data/lib/harvey/engine.rb +4 -0
- data/lib/harvey/version.rb +3 -0
- data/lib/has_attachment/controller.rb +42 -0
- data/lib/has_attachment/routes.rb +17 -0
- data/lib/tasks/harvey_tasks.rake +4 -0
- metadata +141 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
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.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Harvey'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
Bundler::GemHelper.install_tasks
|
28
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class WidgetsController < AuthorizableController
|
2
|
+
|
3
|
+
around_filter :load_and_render_widget
|
4
|
+
|
5
|
+
def load
|
6
|
+
end
|
7
|
+
|
8
|
+
def save
|
9
|
+
@widget.attributes = params[:widget]
|
10
|
+
if @widget.save
|
11
|
+
#success
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def load_and_render_widget(&block)
|
17
|
+
@widget = Widget.find_or_initialize_by_company(current_company)
|
18
|
+
yield
|
19
|
+
render "_form"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/app/models/asset.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
class Document < Asset
|
2
|
+
include ActionView::Helpers::NumberHelper
|
3
|
+
has_attached_file :data
|
4
|
+
validates_attachment_presence :data
|
5
|
+
validates_attachment_size :data, :less_than => 5.megabytes
|
6
|
+
def to_hash
|
7
|
+
hash = attributes
|
8
|
+
hash[:url] = data.url
|
9
|
+
hash[:filesize] = number_to_human_size(data_file_size)
|
10
|
+
hash
|
11
|
+
end
|
12
|
+
end
|
data/app/models/image.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
class Image < Asset
|
2
|
+
has_attached_file :data, :styles => { :thumb => '272x272>' }
|
3
|
+
validates_attachment_presence :data
|
4
|
+
validates_attachment_content_type :data, :content_type => ['image/jpeg', 'image/png', 'image/gif', 'image/pjpeg']
|
5
|
+
|
6
|
+
def to_hash
|
7
|
+
hash = attributes
|
8
|
+
hash[:url] = data.url
|
9
|
+
hash[:thumbnail_url] = data.url(:thumb)
|
10
|
+
hash
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module TenantModel
|
2
|
+
|
3
|
+
class << self
|
4
|
+
protected
|
5
|
+
def current_scoped_methods
|
6
|
+
last = scoped_methods.last
|
7
|
+
last.respond_to?(:call) ? relation.scoping { last.call } : last
|
8
|
+
end
|
9
|
+
end
|
10
|
+
def self.included(base)
|
11
|
+
base.module_eval do
|
12
|
+
belongs_to :company
|
13
|
+
|
14
|
+
before_create do
|
15
|
+
self.company = Company.current
|
16
|
+
end
|
17
|
+
default_scope lambda { where(:company_id => Company.current) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class Widget < ActiveRecord::Base
|
2
|
+
include TenantModel
|
3
|
+
|
4
|
+
has_many :images, :as => :attachable, :class_name => 'Image', :dependent => :destroy
|
5
|
+
has_attached_file :logo, :styles => { :medium => "300x300>", :thumb => "100x100>" }
|
6
|
+
|
7
|
+
accepts_nested_attributes_for :images, :allow_destroy => true
|
8
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
<div id="box1" class="box box-100">
|
2
|
+
<div class="boxin">
|
3
|
+
<div class="tabs">
|
4
|
+
<div class="header">
|
5
|
+
<h3><%= title_tag :bonus %></h3>
|
6
|
+
<ul>
|
7
|
+
<li><a rel="basic" href="#" class="active"><%= title_tag :basic_data %></a></li>
|
8
|
+
<li><a rel="tab_comprise" href="#"><%= title_tag :comprise %></a></li>
|
9
|
+
<li><a rel="tab_items" href="#"><%= Bonus.human_attribute_name :bonus_items %></a></li>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<%= render :partial => "shared/error_messages", :locals => {:entity => @bonus} %>
|
14
|
+
<div class='msg msg-alert'><p><strong>Salvo com sucesso.</strong></p>
|
15
|
+
|
16
|
+
<%= form_for(@bonus, :html => {:class => "fields"}) do |f| %>
|
17
|
+
<div id="basic" class="content active-tab">
|
18
|
+
<fieldset>
|
19
|
+
|
20
|
+
<div class="two-column required">
|
21
|
+
<%= f.label :name %>
|
22
|
+
<%= f.text_field :name %>
|
23
|
+
</div>
|
24
|
+
|
25
|
+
<div class="four-column required">
|
26
|
+
<%= f.label :start_date %>
|
27
|
+
<%= f.text_field :start_date, :class => "date-time" %>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<div class="four-column required">
|
31
|
+
<%= f.label :end_date %>
|
32
|
+
<%= f.text_field :end_date, :class => "date-time" %>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div class="two-column column-align-left">
|
36
|
+
<fieldset class="fieldset-margin-top10">
|
37
|
+
<legend><%= title_tag :bonus_type, :bonus %></legend>
|
38
|
+
<%= f.radio_button(:bonus_type, BonusType::PRODUCT) %>
|
39
|
+
<%= f.label 'bonus_type_product', (title_tag :product), :class => "check" %>
|
40
|
+
|
41
|
+
<%= f.radio_button(:bonus_type, BonusType::PRODUCT_GROUP) %>
|
42
|
+
<%= f.label 'bonus_type_product_group', (title_tag :product_group), :class => "check" %>
|
43
|
+
</fieldset>
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div class="two-column">
|
47
|
+
<fieldset class="fieldset-margin-top10">
|
48
|
+
<legend><%= title_tag :numeric_control, :bonus %></legend>
|
49
|
+
<%= f.radio_button(:numeric_control, NumericControl::SINGLE) %>
|
50
|
+
<%= f.label 'numeric_control_single', NumericControl.t('single'), :class => "check" %>
|
51
|
+
|
52
|
+
<%= f.radio_button(:numeric_control, NumericControl::SUM) %>
|
53
|
+
<%= f.label 'numeric_control_sum', NumericControl.t('sum'), :class => "check" %>
|
54
|
+
</fieldset>
|
55
|
+
</div>
|
56
|
+
|
57
|
+
</fieldset>
|
58
|
+
</div>
|
59
|
+
|
60
|
+
<div id="tab_items" class="content">
|
61
|
+
<%= render :partial => "bonuses/tab/items", :locals => {:f => f } %>
|
62
|
+
</div>
|
63
|
+
|
64
|
+
<div class="ui-action">
|
65
|
+
<%= link_to (title_tag :cancel), bonuses_path, :class => "button altbutton" %>
|
66
|
+
<%= save_button f %>
|
67
|
+
</div>
|
68
|
+
|
69
|
+
<% end %>
|
70
|
+
</div>
|
71
|
+
</div>
|
72
|
+
</div>
|
73
|
+
|
74
|
+
<script type="text/javascript">
|
75
|
+
</script>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateCompanies < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :companies do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :subdomain
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :companies, :subdomain, :unique => true
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.down
|
14
|
+
drop_table :companies
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreateAssets < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :assets do |t|
|
4
|
+
t.string :data_file_name
|
5
|
+
t.string :data_content_type
|
6
|
+
t.integer :data_file_size
|
7
|
+
t.integer :attachable_id
|
8
|
+
t.string :attachable_type
|
9
|
+
t.string :description
|
10
|
+
t.integer :company_id
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateWidgets < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :widgets do |t|
|
4
|
+
t.integer :company_id
|
5
|
+
t.string :logo_file_name
|
6
|
+
t.string :logo_content_type
|
7
|
+
t.integer :logo_file_size
|
8
|
+
t.datetime :logo_updated_at
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/harvey.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module HasAttachment
|
2
|
+
module Controller
|
3
|
+
|
4
|
+
def images
|
5
|
+
serve :image
|
6
|
+
end
|
7
|
+
|
8
|
+
def upload_image
|
9
|
+
upload :image
|
10
|
+
end
|
11
|
+
|
12
|
+
def documents
|
13
|
+
serve :document
|
14
|
+
end
|
15
|
+
|
16
|
+
def upload_document
|
17
|
+
upload :document
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def object
|
22
|
+
@object ||= retrieve_object
|
23
|
+
end
|
24
|
+
|
25
|
+
def model_as_symbol
|
26
|
+
@model_as_symbol ||= object.class.to_s.underscore.singularize.to_sym
|
27
|
+
end
|
28
|
+
|
29
|
+
def upload type
|
30
|
+
attachment = object.send(type.to_s.pluralize).new(params[model_as_symbol][type.to_s])
|
31
|
+
if attachment.save
|
32
|
+
render :json => [attachment.to_hash], :content_type => 'text/html'
|
33
|
+
else
|
34
|
+
render :json => {:result => 'error'}, :content_type => 'text/html', :status => 500
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def serve type
|
39
|
+
respond_with object.send(type.to_s.pluralize).map(&:to_hash)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: harvey
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Pedro Nascimento
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-11 00:00:00.000000000 -03:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
requirement: &2162329000 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.1.1.rc2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2162329000
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: jquery-rails
|
28
|
+
requirement: &2162328000 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2162328000
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: paperclip
|
39
|
+
requirement: &2162326840 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *2162326840
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rspec-rails
|
50
|
+
requirement: &2162326100 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *2162326100
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: sqlite3
|
61
|
+
requirement: &2162325460 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *2162325460
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: shoulda-matchers
|
72
|
+
requirement: &2162324800 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *2162324800
|
81
|
+
description: Widget and more for our apps.
|
82
|
+
email:
|
83
|
+
- pnascimento@gmail.com
|
84
|
+
executables: []
|
85
|
+
extensions: []
|
86
|
+
extra_rdoc_files: []
|
87
|
+
files:
|
88
|
+
- app/controllers/widgets_controller.rb
|
89
|
+
- app/helpers/widgets_helper.rb
|
90
|
+
- app/models/asset.rb
|
91
|
+
- app/models/company.rb
|
92
|
+
- app/models/document.rb
|
93
|
+
- app/models/image.rb
|
94
|
+
- app/models/tenant_model.rb
|
95
|
+
- app/models/widget.rb
|
96
|
+
- app/views/widgets/_form.html.erb
|
97
|
+
- config/routes.rb
|
98
|
+
- db/migrate/20110811022046_create_companies.rb
|
99
|
+
- db/migrate/20111010170545_create_assets.rb
|
100
|
+
- db/migrate/20111010171238_create_widgets.rb
|
101
|
+
- lib/harvey/engine.rb
|
102
|
+
- lib/harvey/version.rb
|
103
|
+
- lib/harvey.rb
|
104
|
+
- lib/has_attachment/controller.rb
|
105
|
+
- lib/has_attachment/routes.rb
|
106
|
+
- lib/tasks/harvey_tasks.rake
|
107
|
+
- MIT-LICENSE
|
108
|
+
- Rakefile
|
109
|
+
- README.rdoc
|
110
|
+
has_rdoc: true
|
111
|
+
homepage: http://www.primesystems.com.br
|
112
|
+
licenses: []
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ! '>='
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
hash: -1756637549639957450
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
none: false
|
128
|
+
requirements:
|
129
|
+
- - ! '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
segments:
|
133
|
+
- 0
|
134
|
+
hash: -1756637549639957450
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 1.6.2
|
138
|
+
signing_key:
|
139
|
+
specification_version: 3
|
140
|
+
summary: Harvey is your pal.
|
141
|
+
test_files: []
|