This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alban Peignier
committed
Jun 7, 2012
1 parent
1d72c64
commit 7c0ae62
Showing
32 changed files
with
563 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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://jashkenas.github.com/coffee-script/ |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Place all the styles related to the Exports controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ | ||
|
||
@import "common"; | ||
|
||
#workspace.exports.index | ||
{ | ||
.export:after { | ||
@include after_div_for_object; | ||
} | ||
|
||
.exports { | ||
margin-top: 20px; | ||
} | ||
|
||
.exports:after { | ||
@include content_to_clear; | ||
} | ||
|
||
.export { | ||
@include div_for_object; | ||
|
||
/* to create multi-column index */ | ||
width: 300px; | ||
float: left; | ||
padding-right: 10px; | ||
} | ||
} | ||
|
||
#workspace.exports.show { | ||
table { | ||
th { | ||
text-align: center; | ||
font-style: italic; | ||
} | ||
td.message, td.created_at, td.position { | ||
padding: 0 20px; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class ExportsController < ChouetteController | ||
|
||
respond_to :html, :xml, :json | ||
respond_to :zip, :only => :show | ||
|
||
belongs_to :referential | ||
|
||
def create | ||
create! do |success, failure| | ||
success.html { redirect_to referential_exports_path(@referential) } | ||
end | ||
end | ||
|
||
def show | ||
show! do |format| | ||
format.zip { send_file @export.file, :type => :zip } | ||
end | ||
end | ||
|
||
|
||
protected | ||
|
||
# FIXME why #resource_id is nil ?? | ||
def build_resource | ||
super.tap do |export| | ||
export.referential_id = @referential.id | ||
end | ||
end | ||
|
||
def collection | ||
@exports ||= end_of_association_chain.paginate(:page => params[:page]) | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module ExportsHelper | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
class Export < ActiveRecord::Base | ||
|
||
belongs_to :referential | ||
validates_presence_of :referential_id | ||
|
||
validates_inclusion_of :status, :in => %w{ pending completed failed } | ||
|
||
has_many :log_messages, :class_name => "ExportLogMessage", :order => :position, :dependent => :destroy | ||
|
||
serialize :options | ||
|
||
def self.option(name) | ||
name = name.to_s | ||
|
||
define_method(name) do | ||
self.options[name] | ||
end | ||
|
||
define_method("#{name}=") do |prefix| | ||
self.options[name] = prefix | ||
end | ||
end | ||
|
||
def options | ||
read_attribute(:options) || write_attribute(:options, {}) | ||
end | ||
|
||
@@root = "#{Rails.root}/tmp/exports" | ||
cattr_accessor :root | ||
|
||
after_destroy :destroy_file | ||
def destroy_file | ||
FileUtils.rm file if File.exists? file | ||
end | ||
|
||
def file | ||
"#{root}/#{id}.zip" | ||
end | ||
|
||
def name | ||
"#{self.class.model_name.human} #{id}" | ||
end | ||
|
||
def export_options | ||
{ :export_id => self.id, :output_file => file } | ||
end | ||
|
||
before_validation :define_default_attributes, :on => :create | ||
def define_default_attributes | ||
self.status ||= "pending" | ||
end | ||
|
||
after_create :delayed_export | ||
def delayed_export | ||
delay.export | ||
end | ||
|
||
def export | ||
FileUtils.mkdir_p root | ||
|
||
begin | ||
log_messages.create :key => :started | ||
|
||
# TODO | ||
# Make real export here | ||
|
||
update_attribute :status, "completed" | ||
rescue => e | ||
Rails.logger.error "Export #{id} failed : #{e}, #{e.backtrace}" | ||
update_attribute :status, "failed" | ||
end | ||
|
||
log_messages.create :key => status | ||
end | ||
|
||
def self.new(attributes = {}, options = {}, &block) | ||
if self == Export | ||
Object.const_get(attributes.delete(:type) || "NeptuneExport").new(attributes, options) | ||
else | ||
super | ||
end | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class ExportLogMessage < ActiveRecord::Base | ||
belongs_to :export | ||
|
||
acts_as_list :scope => :export | ||
|
||
validates_presence_of :key | ||
validates_inclusion_of :severity, :in => %w{info warning error} | ||
|
||
def arguments=(arguments) | ||
write_attribute :arguments, (arguments.to_json if arguments.present?) | ||
end | ||
|
||
def arguments | ||
@decoded_arguments ||= | ||
begin | ||
if (stored_arguments = raw_attributes).present? | ||
ActiveSupport::JSON.decode stored_arguments | ||
else | ||
{} | ||
end | ||
end | ||
end | ||
|
||
def raw_attributes | ||
read_attribute(:arguments) | ||
end | ||
|
||
before_validation :define_default_attributes, :on => :create | ||
def define_default_attributes | ||
self.severity ||= "info" | ||
end | ||
|
||
def full_message | ||
I18n.translate key, arguments.symbolize_keys.merge(:scope => "export_log_messages.messages") | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class NeptuneExport < Export | ||
|
||
def export_options | ||
super.merge(:format => :neptune) | ||
end | ||
|
||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<%= div_for(export, :class => :export) do %> | ||
<%= link_to(referential_export_path(@referential, export), :class => "preview") do %> | ||
<%= image_tag "export-#{export.status}.png" %> | ||
<% end %> | ||
<%= link_to(export.name, referential_export_path(@referential, export)) %> | ||
<div class="info"> | ||
<%= l export.created_at %> | ||
|
||
<div class="actions"> | ||
<%= link_to t("exports.actions.download"), referential_export_path(@referential, export, :format => :zip), :class => "download" %> | ||
<%= link_to t("actions.destroy"), referential_export_path(@referential, export), :method => :delete, :confirm => t('exports.actions.destroy_confirm'), :class => "remove" %> | ||
</div> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<%= title_tag t('.title') %> | ||
|
||
<div class="pagination"> | ||
<div class="page_info"> | ||
<%= page_entries_info @exports %> | ||
</div> | ||
<%= will_paginate @exports, :container => false %> | ||
</div> | ||
<div class="exports paginated_content"> | ||
<%= render :partial => "export", :collection => @exports %> | ||
</div> | ||
<div class="pagination"> | ||
<%= will_paginate @exports, :container => false %> | ||
</div> | ||
|
||
<% content_for :sidebar do %> | ||
<ul class="actions"> | ||
<li><%= link_to t('exports.actions.new'), new_referential_export_path(@referential), :class => "add" %></li> | ||
</ul> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<%= title_tag t(".title") %> | ||
|
||
<%= semantic_form_for [@referential, @export], :as => :export, :url => referential_exports_path(@referential) do |form| %> | ||
<%= form.buttons do %> | ||
<%= form.commit_button true %> | ||
<li><%= t('or') %></li> | ||
<li><%= link_to t('cancel'), :back %></li> | ||
<% end %> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<%= title_tag @export.name %> | ||
|
||
<div class="export_show"> | ||
<div class="summary"> | ||
<p> | ||
<label><%= Export.human_attribute_name(:created_at) %>: </label> | ||
<%= l @export.created_at %> | ||
</p> | ||
<p> | ||
<label><%= Export.human_attribute_name(:status) %>: </label> | ||
<%= t @export.status, :scope => "exports.statuses" %> | ||
</p> | ||
</div> | ||
|
||
<h3><%= t(".report") %></h3> | ||
<table> | ||
<tr> | ||
<th></th> | ||
<th><%= ExportLogMessage.human_attribute_name(:created_at) %></th> | ||
<th><%= ExportLogMessage.human_attribute_name(:position) %></th> | ||
<th><%= ExportLogMessage.human_attribute_name(:full_message) %></th> | ||
</tr> | ||
<% @export.log_messages.each do |message| %> | ||
<tr> | ||
<td class="severity"><%= image_tag "severity-#{message.severity}.png", :alt => t(message.severity, :scope => "export_log_messages.severities") %></td> | ||
<td class="created_at"><%= l message.created_at, :format => :short %></td> | ||
<td class="position"><%= message.position %></td> | ||
<td class="message"><%= message.full_message %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
</div> | ||
|
||
<% content_for :sidebar do %> | ||
<ul class="actions"> | ||
<li><%= link_to t('exports.actions.download'), referential_export_path(@referential, @export, :format => :zip), :class => "download" %></li> | ||
<li><%= link_to t('exports.actions.destroy'), referential_export_path(@referential, @export), :method => :delete, :confirm => t('exports.actions.destroy_confirm'), :class => "remove" %></li> | ||
</ul> | ||
<% 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
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
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
Oops, something went wrong.