advertnet 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +674 -0
- data/README +257 -0
- data/Rakefile +10 -0
- data/app/controllers/application.rb +40 -0
- data/app/controllers/container_controller.rb +83 -0
- data/app/controllers/content_controller.rb +61 -0
- data/app/controllers/furnitures_controller.rb +87 -0
- data/app/controllers/networks_controller.rb +269 -0
- data/app/controllers/objects_in_world_controller.rb +27 -0
- data/app/controllers/panels_controller.rb +186 -0
- data/app/helpers/application_helper.rb +31 -0
- data/app/helpers/container_helper.rb +2 -0
- data/app/helpers/content_helper.rb +2 -0
- data/app/helpers/furnitures_helper.rb +2 -0
- data/app/helpers/network_helper.rb +2 -0
- data/app/helpers/networks_helper.rb +2 -0
- data/app/helpers/objects_in_world_helper.rb +2 -0
- data/app/helpers/panels_helper.rb +2 -0
- data/app/models/container.rb +51 -0
- data/app/models/furniture.rb +60 -0
- data/app/models/mailer.rb +22 -0
- data/app/models/network.rb +38 -0
- data/app/models/object_in_world.rb +60 -0
- data/app/models/object_off_world.rb +77 -0
- data/app/models/panel.rb +136 -0
- data/app/models/panel_revision.rb +108 -0
- data/app/views/container/list.rhtml +27 -0
- data/app/views/container/show.rhtml +8 -0
- data/app/views/content/_form.rhtml +12 -0
- data/app/views/content/edit.rhtml +8 -0
- data/app/views/content/list.rhtml +26 -0
- data/app/views/content/new.rhtml +8 -0
- data/app/views/furnitures/list.rhtml +51 -0
- data/app/views/furnitures/show.rhtml +7 -0
- data/app/views/layouts/default.rhtml +30 -0
- data/app/views/mailer/avtouch.rhtml +1 -0
- data/app/views/networks/_form.rhtml +11 -0
- data/app/views/networks/_parameters_form.rhtml +8 -0
- data/app/views/networks/edit.rhtml +9 -0
- data/app/views/networks/list.rhtml +25 -0
- data/app/views/networks/new.rhtml +8 -0
- data/app/views/networks/show.rhtml +72 -0
- data/app/views/networks/show_parameters_form.rjs +5 -0
- data/app/views/objects_in_world/list.rhtml +30 -0
- data/app/views/objects_in_world/show.rhtml +8 -0
- data/app/views/panels/list.rhtml +48 -0
- data/app/views/panels/show.rhtml +8 -0
- data/bin/advertnet-install +144 -0
- data/config/boot.rb +45 -0
- data/config/database.yml.default +43 -0
- data/config/environment.rb +67 -0
- data/config/environments/development.rb +21 -0
- data/config/environments/production.rb +21 -0
- data/config/environments/test.rb +19 -0
- data/config/routes.rb +23 -0
- data/db/migrate/001_create_networks.rb +14 -0
- data/db/migrate/002_create_furnitures.rb +17 -0
- data/db/migrate/003_create_containers.rb +16 -0
- data/db/migrate/004_create_objects_in_world.rb +16 -0
- data/db/migrate/005_create_objects_off_world.rb +16 -0
- data/db/migrate/006_create_panels.rb +17 -0
- data/db/migrate/007_join_objects_in_world_panels.rb +17 -0
- data/db/migrate/008_join_objects_off_world_panels.rb +17 -0
- data/db/migrate/009_add_sessions.rb +19 -0
- data/db/migrate/010_add_or_rename_fields.rb +25 -0
- data/db/migrate/011_move_texture_to_object_in_world.rb +25 -0
- data/db/migrate/012_add_permanent_furniture_id.rb +18 -0
- data/db/migrate/013_create_panel_revisions.rb +42 -0
- data/db/schema.rb +102 -0
- data/doc/README_FOR_APP +108 -0
- data/lib/advertnet.rb +13 -0
- data/lib/second_life_validators.rb +89 -0
- data/lib/tasks/documentation.rake +16 -0
- data/lib/tasks/extract_fixtures.rake +23 -0
- data/lib/tasks/load_exported_fixtures.rake +14 -0
- data/public/404.html +30 -0
- data/public/500.html +30 -0
- data/public/dispatch.cgi +10 -0
- data/public/dispatch.fcgi +24 -0
- data/public/dispatch.rb +10 -0
- data/public/favicon.ico +0 -0
- data/public/images/rails.png +0 -0
- data/public/javascripts/application.js +2 -0
- data/public/javascripts/controls.js +833 -0
- data/public/javascripts/dragdrop.js +942 -0
- data/public/javascripts/effects.js +1088 -0
- data/public/javascripts/prototype.js +2515 -0
- data/public/robots.txt +1 -0
- data/public/stylesheets/application.css +25 -0
- data/public/stylesheets/scaffold.css +74 -0
- data/script/about +3 -0
- data/script/breakpointer +3 -0
- data/script/console +3 -0
- data/script/destroy +3 -0
- data/script/generate +3 -0
- data/script/performance/benchmarker +3 -0
- data/script/performance/profiler +3 -0
- data/script/plugin +3 -0
- data/script/process/inspector +3 -0
- data/script/process/reaper +3 -0
- data/script/process/spawner +3 -0
- data/script/runner +3 -0
- data/script/server +3 -0
- data/test/fixtures/containers.yml +44 -0
- data/test/fixtures/furnitures.yml +47 -0
- data/test/fixtures/mailer/avtouch +1 -0
- data/test/fixtures/networks.yml +31 -0
- data/test/fixtures/objects_in_world.yml +71 -0
- data/test/fixtures/objects_in_world_panels.yml +43 -0
- data/test/fixtures/objects_off_world.yml +55 -0
- data/test/fixtures/objects_off_world_panels.yml +20 -0
- data/test/fixtures/panel_revisions.yml +28 -0
- data/test/fixtures/panels.yml +79 -0
- data/test/functional/container_controller_test.rb +167 -0
- data/test/functional/content_controller_test.rb +91 -0
- data/test/functional/furnitures_controller_test.rb +134 -0
- data/test/functional/networks_controller_test.rb +248 -0
- data/test/functional/objects_in_world_controller_test.rb +42 -0
- data/test/functional/panels_controller_test.rb +173 -0
- data/test/test_helper.rb +53 -0
- data/test/unit/container_test.rb +53 -0
- data/test/unit/furniture_test.rb +68 -0
- data/test/unit/mailer_test.rb +40 -0
- data/test/unit/network_test.rb +42 -0
- data/test/unit/object_in_world_test.rb +33 -0
- data/test/unit/object_off_world_test.rb +26 -0
- data/test/unit/panel_revision_test.rb +148 -0
- data/test/unit/panel_test.rb +63 -0
- data/vendor/plugins/annotate_models/ChangeLog +46 -0
- data/vendor/plugins/annotate_models/README +31 -0
- data/vendor/plugins/annotate_models/lib/annotate_models.rb +132 -0
- data/vendor/plugins/annotate_models/tasks/annotate_models_tasks.rake +7 -0
- data/vendor/plugins/foreign_key_migrations/CHANGELOG +99 -0
- data/vendor/plugins/foreign_key_migrations/MIT-LICENSE +20 -0
- data/vendor/plugins/foreign_key_migrations/README +87 -0
- data/vendor/plugins/foreign_key_migrations/about.yml +5 -0
- data/vendor/plugins/foreign_key_migrations/init.rb +3 -0
- data/vendor/plugins/foreign_key_migrations/install.rb +1 -0
- data/vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/base.rb +22 -0
- data/vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/connection_adapters/abstract_adapter.rb +22 -0
- data/vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/connection_adapters/table_definition.rb +28 -0
- data/vendor/plugins/redhillonrails_core/CHANGELOG +154 -0
- data/vendor/plugins/redhillonrails_core/MIT-LICENSE +20 -0
- data/vendor/plugins/redhillonrails_core/README +139 -0
- data/vendor/plugins/redhillonrails_core/init.rb +19 -0
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb +54 -0
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/abstract_adapter.rb +31 -0
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/column.rb +21 -0
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb +26 -0
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/index_definition.rb +11 -0
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_adapter.rb +82 -0
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_column.rb +8 -0
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/postgresql_adapter.rb +107 -0
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/schema_statements.rb +23 -0
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/sqlite3_adapter.rb +9 -0
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/table_definition.rb +27 -0
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema.rb +27 -0
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb +47 -0
- metadata +290 -0
data/README
ADDED
@@ -0,0 +1,257 @@
|
|
1
|
+
= AdvertNet
|
2
|
+
|
3
|
+
A tool for managing multiple networks of advertising boards.
|
4
|
+
|
5
|
+
Copyright (C) 2007 Pragmatic Source
|
6
|
+
|
7
|
+
Authors:
|
8
|
+
* Farzad Farid <ffarid@pragmatic-source.com>: Main developper
|
9
|
+
* Yves Rougy <yrougy@gmail.com>: Development, Data modeling, first version of the application in PHP
|
10
|
+
* Loïc Dachary <loic@dachary.org>: Packaging, Testing.
|
11
|
+
|
12
|
+
This program is free software: you can redistribute it and/or modify
|
13
|
+
it under the terms of the GNU General Public License as published by
|
14
|
+
the Free Software Foundation, either version 3 of the License, or
|
15
|
+
(at your option) any later version.
|
16
|
+
|
17
|
+
This program is distributed in the hope that it will be useful,
|
18
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
+
GNU General Public License for more details.
|
21
|
+
|
22
|
+
You should have received a copy of the GNU General Public License
|
23
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
24
|
+
|
25
|
+
== INSTALLATION
|
26
|
+
|
27
|
+
=== Dependencies
|
28
|
+
|
29
|
+
This application needs a MySQL 5.0 database.
|
30
|
+
|
31
|
+
After installing MySQL, create 3 databases:
|
32
|
+
* advertnet_development
|
33
|
+
* advertnet_test
|
34
|
+
* advertnet_production
|
35
|
+
|
36
|
+
The default "<tt>config/database.yml</tt>" is configured to use the "+root+" account
|
37
|
+
<em>without a password</em>. You must eventually edit it in order to change the login
|
38
|
+
or add a password.
|
39
|
+
|
40
|
+
For example, you can create a user, for example +advertnet+ and give it
|
41
|
+
read/write access (select, insert, update, create table, drop table, alter
|
42
|
+
table, etc.) on the 3 databases.
|
43
|
+
|
44
|
+
=== Basic MySQL configuration
|
45
|
+
|
46
|
+
Run the following commands <em>as root</em> (for example on a Debian system):
|
47
|
+
|
48
|
+
for i in development test production ; do mysqladmin -u root create advertnet_$i ; done
|
49
|
+
|
50
|
+
Now create the SQL tables, run these commands from Advertnet's root directory:
|
51
|
+
|
52
|
+
rake db:migrate RAILS_ENV=development
|
53
|
+
rake db:migrate RAILS_ENV=production
|
54
|
+
|
55
|
+
=== Testing the configuration
|
56
|
+
|
57
|
+
To ensure that the application works correctly, first run the following commands:
|
58
|
+
|
59
|
+
rake db:test:prepare
|
60
|
+
rake test
|
61
|
+
|
62
|
+
*Note*: There is at least one unit test that is known to fails, other unit
|
63
|
+
tests and all functional tests should pass correctly.
|
64
|
+
|
65
|
+
= Rails documentation
|
66
|
+
|
67
|
+
You will find below the original, unmodified, Rails documentation.
|
68
|
+
|
69
|
+
To generate the application's technical documentation in HTML format, run:
|
70
|
+
|
71
|
+
rake doc:app_utf8
|
72
|
+
|
73
|
+
The whole documentation will then be available as HTML files in the "doc/app"
|
74
|
+
directory, starting at "index.html".
|
75
|
+
|
76
|
+
== Welcome to Rails
|
77
|
+
|
78
|
+
Rails is a web-application and persistence framework that includes everything
|
79
|
+
needed to create database-backed web-applications according to the
|
80
|
+
Model-View-Control pattern of separation. This pattern splits the view (also
|
81
|
+
called the presentation) into "dumb" templates that are primarily responsible
|
82
|
+
for inserting pre-built data in between HTML tags. The model contains the
|
83
|
+
"smart" domain objects (such as Account, Product, Person, Post) that holds all
|
84
|
+
the business logic and knows how to persist themselves to a database. The
|
85
|
+
controller handles the incoming requests (such as Save New Account, Update
|
86
|
+
Product, Show Post) by manipulating the model and directing data to the view.
|
87
|
+
|
88
|
+
In Rails, the model is handled by what's called an object-relational mapping
|
89
|
+
layer entitled Active Record. This layer allows you to present the data from
|
90
|
+
database rows as objects and embellish these data objects with business logic
|
91
|
+
methods. You can read more about Active Record in
|
92
|
+
link:files/vendor/rails/activerecord/README.html.
|
93
|
+
|
94
|
+
The controller and view are handled by the Action Pack, which handles both
|
95
|
+
layers by its two parts: Action View and Action Controller. These two layers
|
96
|
+
are bundled in a single package due to their heavy interdependence. This is
|
97
|
+
unlike the relationship between the Active Record and Action Pack that is much
|
98
|
+
more separate. Each of these packages can be used independently outside of
|
99
|
+
Rails. You can read more about Action Pack in
|
100
|
+
link:files/vendor/rails/actionpack/README.html.
|
101
|
+
|
102
|
+
|
103
|
+
== Getting started
|
104
|
+
|
105
|
+
1. At the command prompt, start a new rails application using the rails command
|
106
|
+
and your application name. Ex: rails myapp
|
107
|
+
(If you've downloaded rails in a complete tgz or zip, this step is already done)
|
108
|
+
2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
|
109
|
+
3. Go to http://localhost:3000/ and get "Welcome aboard: You’re riding the Rails!"
|
110
|
+
4. Follow the guidelines to start developing your application
|
111
|
+
|
112
|
+
|
113
|
+
== Web Servers
|
114
|
+
|
115
|
+
By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
|
116
|
+
Rails will use the WEBrick, the webserver that ships with Ruby. When you run script/server,
|
117
|
+
Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
|
118
|
+
that you can always get up and running quickly.
|
119
|
+
|
120
|
+
Mongrel is a Ruby-based webserver with a C-component (which requires compilation) that is
|
121
|
+
suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
|
122
|
+
getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
|
123
|
+
More info at: http://mongrel.rubyforge.org
|
124
|
+
|
125
|
+
If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
|
126
|
+
Mongrel and WEBrick and also suited for production use, but requires additional
|
127
|
+
installation and currently only works well on OS X/Unix (Windows users are encouraged
|
128
|
+
to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
|
129
|
+
http://www.lighttpd.net.
|
130
|
+
|
131
|
+
And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
|
132
|
+
web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
|
133
|
+
for production.
|
134
|
+
|
135
|
+
But of course its also possible to run Rails on any platform that supports FCGI.
|
136
|
+
Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
|
137
|
+
please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
|
138
|
+
|
139
|
+
|
140
|
+
== Debugging Rails
|
141
|
+
|
142
|
+
Have "tail -f" commands running on the server.log and development.log. Rails will
|
143
|
+
automatically display debugging and runtime information to these files. Debugging
|
144
|
+
info will also be shown in the browser on requests from 127.0.0.1.
|
145
|
+
|
146
|
+
|
147
|
+
== Breakpoints
|
148
|
+
|
149
|
+
Breakpoint support is available through the script/breakpointer client. This
|
150
|
+
means that you can break out of execution at any point in the code, investigate
|
151
|
+
and change the model, AND then resume execution! Example:
|
152
|
+
|
153
|
+
class WeblogController < ActionController::Base
|
154
|
+
def index
|
155
|
+
@posts = Post.find(:all)
|
156
|
+
breakpoint "Breaking out from the list"
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
So the controller will accept the action, run the first line, then present you
|
161
|
+
with a IRB prompt in the breakpointer window. Here you can do things like:
|
162
|
+
|
163
|
+
Executing breakpoint "Breaking out from the list" at .../webrick_server.rb:16 in 'breakpoint'
|
164
|
+
|
165
|
+
>> @posts.inspect
|
166
|
+
=> "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
|
167
|
+
#<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
|
168
|
+
>> @posts.first.title = "hello from a breakpoint"
|
169
|
+
=> "hello from a breakpoint"
|
170
|
+
|
171
|
+
...and even better is that you can examine how your runtime objects actually work:
|
172
|
+
|
173
|
+
>> f = @posts.first
|
174
|
+
=> #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
|
175
|
+
>> f.
|
176
|
+
Display all 152 possibilities? (y or n)
|
177
|
+
|
178
|
+
Finally, when you're ready to resume execution, you press CTRL-D
|
179
|
+
|
180
|
+
|
181
|
+
== Console
|
182
|
+
|
183
|
+
You can interact with the domain model by starting the console through <tt>script/console</tt>.
|
184
|
+
Here you'll have all parts of the application configured, just like it is when the
|
185
|
+
application is running. You can inspect domain models, change values, and save to the
|
186
|
+
database. Starting the script without arguments will launch it in the development environment.
|
187
|
+
Passing an argument will specify a different environment, like <tt>script/console production</tt>.
|
188
|
+
|
189
|
+
To reload your controllers and models after launching the console run <tt>reload!</tt>
|
190
|
+
|
191
|
+
To reload your controllers and models after launching the console run <tt>reload!</tt>
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
== Description of contents
|
196
|
+
|
197
|
+
app
|
198
|
+
Holds all the code that's specific to this particular application.
|
199
|
+
|
200
|
+
app/controllers
|
201
|
+
Holds controllers that should be named like weblogs_controller.rb for
|
202
|
+
automated URL mapping. All controllers should descend from ApplicationController
|
203
|
+
which itself descends from ActionController::Base.
|
204
|
+
|
205
|
+
app/models
|
206
|
+
Holds models that should be named like post.rb.
|
207
|
+
Most models will descend from ActiveRecord::Base.
|
208
|
+
|
209
|
+
app/views
|
210
|
+
Holds the template files for the view that should be named like
|
211
|
+
weblogs/index.rhtml for the WeblogsController#index action. All views use eRuby
|
212
|
+
syntax.
|
213
|
+
|
214
|
+
app/views/layouts
|
215
|
+
Holds the template files for layouts to be used with views. This models the common
|
216
|
+
header/footer method of wrapping views. In your views, define a layout using the
|
217
|
+
<tt>layout :default</tt> and create a file named default.rhtml. Inside default.rhtml,
|
218
|
+
call <% yield %> to render the view using this layout.
|
219
|
+
|
220
|
+
app/helpers
|
221
|
+
Holds view helpers that should be named like weblogs_helper.rb. These are generated
|
222
|
+
for you automatically when using script/generate for controllers. Helpers can be used to
|
223
|
+
wrap functionality for your views into methods.
|
224
|
+
|
225
|
+
config
|
226
|
+
Configuration files for the Rails environment, the routing map, the database, and other dependencies.
|
227
|
+
|
228
|
+
components
|
229
|
+
Self-contained mini-applications that can bundle together controllers, models, and views.
|
230
|
+
|
231
|
+
db
|
232
|
+
Contains the database schema in schema.rb. db/migrate contains all
|
233
|
+
the sequence of Migrations for your schema.
|
234
|
+
|
235
|
+
doc
|
236
|
+
This directory is where your application documentation will be stored when generated
|
237
|
+
using <tt>rake doc:app</tt>
|
238
|
+
|
239
|
+
lib
|
240
|
+
Application specific libraries. Basically, any kind of custom code that doesn't
|
241
|
+
belong under controllers, models, or helpers. This directory is in the load path.
|
242
|
+
|
243
|
+
public
|
244
|
+
The directory available for the web server. Contains subdirectories for images, stylesheets,
|
245
|
+
and javascripts. Also contains the dispatchers and the default HTML files. This should be
|
246
|
+
set as the DOCUMENT_ROOT of your web server.
|
247
|
+
|
248
|
+
script
|
249
|
+
Helper scripts for automation and generation.
|
250
|
+
|
251
|
+
test
|
252
|
+
Unit and functional tests along with fixtures. When using the script/generate scripts, template
|
253
|
+
test files will be generated for you and placed in this directory.
|
254
|
+
|
255
|
+
vendor
|
256
|
+
External libraries that the application depends on. Also includes the plugins subdirectory.
|
257
|
+
This directory is in the load path.
|
data/Rakefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
2
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
3
|
+
|
4
|
+
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
|
5
|
+
|
6
|
+
require 'rake'
|
7
|
+
require 'rake/testtask'
|
8
|
+
require 'rake/rdoctask'
|
9
|
+
|
10
|
+
require 'tasks/rails'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
class ApplicationController < ActionController::Base
|
5
|
+
# Pick a unique cookie name to distinguish our session data from others'
|
6
|
+
session :session_key => '_advertnet_session_id'
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
# Filtre de préparation des attributs Second Life.
|
11
|
+
#
|
12
|
+
# * Récupère les attributs Second Life de l'objet qui a appelé Rails.
|
13
|
+
# * Envoie une page d'erreur et arrête le traitement normal de l'action si les attributs sont absents de la requête HTTP.
|
14
|
+
#
|
15
|
+
# Ce filtre crée un attribut <tt>@slattrs</tt> contenant les clés suivantes :
|
16
|
+
# +key+:: Object Key
|
17
|
+
# +sim+:: Nom de la sim/région
|
18
|
+
# +position+:: Coordonnées dans la sim
|
19
|
+
# +name+:: Nom de l'objet appelant
|
20
|
+
#
|
21
|
+
# *Note* : +sim+ et +position+ sont au format SL, pas normalisés. Cf SecondLifeSimPosNormalizer.
|
22
|
+
def get_secondlife_attrs #:doc:
|
23
|
+
if request.env.include?("HTTP_X_SECONDLIFE_OBJECT_KEY")
|
24
|
+
@slattrs = {
|
25
|
+
:key => request.env["HTTP_X_SECONDLIFE_OBJECT_KEY"],
|
26
|
+
:sim => request.env["HTTP_X_SECONDLIFE_REGION"],
|
27
|
+
:position => request.env["HTTP_X_SECONDLIFE_LOCAL_POSITION"],
|
28
|
+
:name => request.env["HTTP_X_SECONDLIFE_OBJECT_NAME"]
|
29
|
+
}
|
30
|
+
else
|
31
|
+
# Envoie une erreur et arrête le traitement
|
32
|
+
render :text => "Missing Second Life environment",
|
33
|
+
:status => "409 Missing Second Life environment",
|
34
|
+
:layout => false,
|
35
|
+
:content_type => "text/plain"
|
36
|
+
return false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class ContainerController < ApplicationController
|
2
|
+
# Mise en page globale du site
|
3
|
+
layout "default"
|
4
|
+
|
5
|
+
# Renvoi vers l'action +list+
|
6
|
+
def index
|
7
|
+
list
|
8
|
+
render :action => 'list'
|
9
|
+
end
|
10
|
+
|
11
|
+
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
12
|
+
verify :method => :post, :only => [ :destroy, :register ],
|
13
|
+
:redirect_to => { :action => :list }
|
14
|
+
|
15
|
+
# Affiche une liste, en lecture seule, des Container SL.
|
16
|
+
def list
|
17
|
+
@container_pages, @containers = paginate :containers, :per_page => 10
|
18
|
+
end
|
19
|
+
|
20
|
+
# Enregistrement ou mise à jour d'un container et de ses objects in world.
|
21
|
+
# Cette action est appelée en +POST+ avec un seul paramètre, +content+.
|
22
|
+
# Le format de données est l'un des 2 suivants :
|
23
|
+
#
|
24
|
+
# * nom1|key1|type1,nom2|key2,type2,...
|
25
|
+
# * nom1|key1,nom2|key2,...
|
26
|
+
#
|
27
|
+
# Si le champ +type+ n'est pas donné, il prend la valeur par défaut "texture".
|
28
|
+
#
|
29
|
+
# Après la création ou mise à jour du container, tous ses objets sont mises à jour :
|
30
|
+
# * ceux qui n'existent plus sont supprimés
|
31
|
+
# * les objets à modifier sont mis à jour
|
32
|
+
# * les nouveaux objets sont créés
|
33
|
+
def register
|
34
|
+
# Récupère les paramètres fournis par Second Life
|
35
|
+
slattrs = get_secondlife_attrs
|
36
|
+
# Création ou mise à jour du container
|
37
|
+
container = Container.find_or_initialize_by_container_key(slattrs.delete(:key))
|
38
|
+
container.update_attributes!(slattrs)
|
39
|
+
# Maintenant création ou mise à jour des objets
|
40
|
+
# Les objets sont séparés par des virgules
|
41
|
+
objects = params[:content].split(/,/).collect { |line|
|
42
|
+
# Les champs sont séparés par une barre verticale
|
43
|
+
fields = line.split(/\|/)
|
44
|
+
# Conservation de la structure historique du script Webia en PHP,
|
45
|
+
# qui avait une version spéciale uniquement pour les textures,
|
46
|
+
# dont le champ type était donc implicite.
|
47
|
+
fields = fields + ["texture"] if fields.size == 2
|
48
|
+
object = ObjectInWorld.find_or_initialize_by_object_key(fields[1])
|
49
|
+
object.update_attributes!(:name => fields[0], :otype => fields[2], :container => container)
|
50
|
+
object
|
51
|
+
}
|
52
|
+
# Et on remplace les objets existants par ceux-là, avec une fonction qui
|
53
|
+
# optimise les ajouts/suppressions
|
54
|
+
container.objects_in_world.replace(objects)
|
55
|
+
|
56
|
+
render :nothing => true
|
57
|
+
end
|
58
|
+
|
59
|
+
# Affiche le détail d'un Container
|
60
|
+
def show
|
61
|
+
@container = Container.find(params[:id])
|
62
|
+
end
|
63
|
+
|
64
|
+
# Destruction d'un Container.
|
65
|
+
#
|
66
|
+
# *Important* : la version actuelle refuse de détruire un Container non vide.
|
67
|
+
def destroy
|
68
|
+
# XXX : Ce n'est pas propre, mais puisqu'on est obligé d'avoir ":dependent => :destroy"
|
69
|
+
# dans la relation entre un container et les objets in world, c'est dans le controleur
|
70
|
+
# qu'on doit s'assurer qu'il n'est pas interdit de supprimer un container plein...
|
71
|
+
container = Container.find(params[:id])
|
72
|
+
if container.objects_in_world.empty?
|
73
|
+
container.destroy
|
74
|
+
redirect_to :action => 'list'
|
75
|
+
else
|
76
|
+
# Interdiction de supprimer un conteneur plein
|
77
|
+
render :text => "Cannot delete a non-empty container.",
|
78
|
+
:status => "409 Container not empty",
|
79
|
+
:layout => false,
|
80
|
+
:content_type => "text/plain"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# == Gestion des ObjectOffWorld : URL, Media URL, etc.
|
2
|
+
#
|
3
|
+
# Ce contrôleur permet la création et la consultation des objets de type
|
4
|
+
# ObjectOffWorld.
|
5
|
+
class ContentController < ApplicationController
|
6
|
+
# Mise en page globale du site
|
7
|
+
layout "default"
|
8
|
+
|
9
|
+
# Renvoie vers l'action 'list'
|
10
|
+
def index
|
11
|
+
list
|
12
|
+
render :action => 'list'
|
13
|
+
end
|
14
|
+
|
15
|
+
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
|
16
|
+
verify :method => :post, :only => [ :destroy, :create, :update ],
|
17
|
+
:redirect_to => { :action => :index }
|
18
|
+
|
19
|
+
# Liste les ObjectOffWorld
|
20
|
+
def list
|
21
|
+
@object_off_world_pages, @objects_off_world = paginate :objects_off_world, :per_page => 10
|
22
|
+
end
|
23
|
+
|
24
|
+
# Affichage du formulaire de création d'un nouvel ObjectOffWorld
|
25
|
+
def new
|
26
|
+
@object_off_world = ObjectOffWorld.new
|
27
|
+
end
|
28
|
+
|
29
|
+
# Création du nouvel ObjectOffWorld
|
30
|
+
def create
|
31
|
+
@object_off_world = ObjectOffWorld.new(params[:object_off_world])
|
32
|
+
if @object_off_world.save
|
33
|
+
flash[:notice] = "Object '#{@object_off_world.name}' was successfully created."
|
34
|
+
redirect_to :action => 'list'
|
35
|
+
else
|
36
|
+
render :action => 'new'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Affichage du formulaire d'édition d'un ObjectOffWorld
|
41
|
+
def edit
|
42
|
+
@object_off_world = ObjectOffWorld.find(params[:id])
|
43
|
+
end
|
44
|
+
|
45
|
+
# Modification d'un ObjectOffWorld
|
46
|
+
def update
|
47
|
+
@object_off_world = ObjectOffWorld.find(params[:id])
|
48
|
+
if @object_off_world.update_attributes(params[:object_off_world])
|
49
|
+
flash[:notice] = "Object '#{@object_off_world.name}' was successfully updated."
|
50
|
+
redirect_to :action => 'list'
|
51
|
+
else
|
52
|
+
render :action => 'edit'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Suppression d'un ObjectOffWorld
|
57
|
+
def destroy
|
58
|
+
ObjectOffWorld.find(params[:id]).destroy
|
59
|
+
redirect_to :action => 'list'
|
60
|
+
end
|
61
|
+
end
|