voluntary_translation 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +3 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +29 -0
- data/app/assets/javascripts/voluntary_translation/stories.js.coffee +7 -0
- data/app/models/product/translation.rb +3 -0
- data/app/models/product/translation/column.rb +4 -0
- data/app/models/product/translation/story.rb +70 -0
- data/app/models/product/translation/task.rb +28 -0
- data/app/views/products/types/translation/stories/_form.html.erb +23 -0
- data/app/views/products/types/translation/stories/steps/_activate.html.erb +17 -0
- data/app/views/products/types/translation/stories/steps/_setup_tasks.html.erb +35 -0
- data/app/views/products/types/translation/workflow/tasks/_work_head.html.erb +19 -0
- data/config/locales/resources/product/translation/task/en.yml +6 -0
- data/config/locales/workflow/en.yml +6 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20131006062915_add_translation_product.rb +13 -0
- data/lib/tasks/voluntary_translation_tasks.rake +4 -0
- data/lib/voluntary_translation.rb +6 -0
- data/lib/voluntary_translation/engine.rb +5 -0
- data/lib/voluntary_translation/version.rb +3 -0
- metadata +88 -0
data/CHANGELOG.md
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 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,29 @@
|
|
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 = 'VoluntaryTranslation'
|
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("../dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
Bundler::GemHelper.install_tasks
|
29
|
+
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Place all the behaviors and hooks related to the matching controller here.
|
2
|
+
# All this logic will automatically be available in application.js.
|
3
|
+
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
4
|
+
jQuery ->
|
5
|
+
$('#story_output_language_tokens').tokenInput '/users/languages.json',
|
6
|
+
theme: 'facebook'
|
7
|
+
prePopulate: $('#story_output_language_tokens').data('load')
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class Product::Translation::Story < Story
|
2
|
+
has_many :columns, dependent: :destroy, class_name: 'Product::Translation::Column', inverse_of: :story
|
3
|
+
has_many :tasks, dependent: :destroy, class_name: 'Product::Translation::Task', inverse_of: :story
|
4
|
+
|
5
|
+
field :input_language, type: String
|
6
|
+
field :output_languages, type: Array
|
7
|
+
|
8
|
+
validates :input_language, presence: true
|
9
|
+
validates :output_languages, presence: true
|
10
|
+
|
11
|
+
attr_accessible :input_language, :output_languages, :output_language_tokens, :columns_attributes
|
12
|
+
|
13
|
+
accepts_nested_attributes_for :columns, allow_destroy: true, reject_if: ->(t) { t['key'].blank? or t['text'].blank? }
|
14
|
+
|
15
|
+
after_save :create_tasks
|
16
|
+
|
17
|
+
state_machine :state, initial: :new do
|
18
|
+
state :tasks_defined do
|
19
|
+
validates_associated :columns
|
20
|
+
validate :presence_of_columns
|
21
|
+
end
|
22
|
+
|
23
|
+
#after_transition on: :active, do: :create_tasks
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.for_user(user)
|
27
|
+
active.where(:output_languages.in => user.languages)
|
28
|
+
end
|
29
|
+
|
30
|
+
def output_language_tokens=(tokens)
|
31
|
+
self.output_languages = tokens.split(',')
|
32
|
+
end
|
33
|
+
|
34
|
+
def output_language_tokens
|
35
|
+
options = []
|
36
|
+
|
37
|
+
User.languages.each do |language|
|
38
|
+
next unless (output_languages || []).include?(language.second)
|
39
|
+
|
40
|
+
options << { id: language.second, name: language.first }
|
41
|
+
end
|
42
|
+
|
43
|
+
options
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def presence_of_tasks; ; end
|
49
|
+
|
50
|
+
def presence_of_columns
|
51
|
+
unless columns.any?
|
52
|
+
errors[:base] << I18n.t(
|
53
|
+
'activerecord.errors.models.story.attributes.base.missing_columns'
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_tasks
|
59
|
+
return unless state_changed? && state == 'active'
|
60
|
+
|
61
|
+
output_languages.each do |output_language|
|
62
|
+
columns.each do |column|
|
63
|
+
tasks.create!(
|
64
|
+
column_id: column.id, name: column.key, text: column.text,
|
65
|
+
input_language: input_language, output_language: output_language
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Product::Translation::Task < ::Task
|
2
|
+
belongs_to :story, class_name: 'Product::Translation::Story', inverse_of: :task
|
3
|
+
belongs_to :column, class_name: 'Product::Translation::Column', inverse_of: :task
|
4
|
+
|
5
|
+
field :input_language, type: String
|
6
|
+
field :output_language, type: String
|
7
|
+
|
8
|
+
validates :text, presence: true
|
9
|
+
validates :input_language, presence: true
|
10
|
+
validates :output_language, presence: true
|
11
|
+
|
12
|
+
attr_accessible :column_id, :input_language, :output_language
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
# validates :name, presence: true, uniqueness: { scope: [:story_id, :output_language] }
|
17
|
+
def name_valid?
|
18
|
+
return unless name_changed?
|
19
|
+
|
20
|
+
if name.present?
|
21
|
+
if Task.where(name: name, story_id: story_id, output_language: output_language).any?
|
22
|
+
errors.add(:name, I18n.t('errors.messages.taken'))
|
23
|
+
end
|
24
|
+
else
|
25
|
+
errors.add(:name, I18n.t('errors.messages.blank'))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<% content_for(:javascript_includes) { javascript_include_tag 'voluntary_translation/stories' } %>
|
2
|
+
|
3
|
+
<%= simple_form_for(@story, html: {class: 'form-vertical'}) do |f| %>
|
4
|
+
<%= render partial: 'shared/form/error_messages', locals: { resource: @story } %>
|
5
|
+
|
6
|
+
<% unless @story.new_record? %>
|
7
|
+
<div class="form-actions">
|
8
|
+
<%= f.button :submit %>
|
9
|
+
</div>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<div class="form-inputs">
|
13
|
+
<%= @story.project ? f.hidden_field(:project_id) : f.input(:project_id, collection: Project.all) %>
|
14
|
+
<%= f.input :name %>
|
15
|
+
<%= f.input :text, as: :text, input_html: {style: 'width:500px; height:100px;'} %>
|
16
|
+
<%= f.input :input_language, collection: all_language_options %>
|
17
|
+
<%= f.input :output_language_tokens, as: :string, input_html: { data: { load: resource.output_language_tokens } } unless Rails.env == 'test' %>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div class="form-actions">
|
21
|
+
<%= f.button :submit %>
|
22
|
+
</div>
|
23
|
+
<% end %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<%= simple_form_for(@story, html: {class: 'floating_form form-vertical'}) do |f| %>
|
2
|
+
<%= render partial: 'shared/form/error_messages', locals: { resource: @story } %>
|
3
|
+
<% if step == :activate %>
|
4
|
+
<input type="hidden" name="next_step" value="1"/>
|
5
|
+
<% end %>
|
6
|
+
<div class="form-inputs">
|
7
|
+
<%= render partial: 'columns/collection', locals: {
|
8
|
+
collection: @story.columns.select{|t| !t.new_record? },
|
9
|
+
options: { current_parent: @story, append_new_link: false }
|
10
|
+
}
|
11
|
+
%>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div class="form-actions">
|
15
|
+
<%= f.button :submit, t('general.events.activate') %>
|
16
|
+
</div>
|
17
|
+
<% end %>
|
@@ -0,0 +1,35 @@
|
|
1
|
+
<%= simple_form_for(@story, @step_presenter.form_options) do |f| %>
|
2
|
+
<%= render partial: 'shared/form/error_messages', locals: { resource: @story } %>
|
3
|
+
<% if step == :setup_tasks %>
|
4
|
+
<input type="hidden" name="next_step" value="1"/>
|
5
|
+
<% end %>
|
6
|
+
|
7
|
+
<div class="form-actions">
|
8
|
+
<div class="control-group string required" style="display: block">
|
9
|
+
<div class="controls">
|
10
|
+
<%= f.button :submit, t('stories.steps.setup_tasks.update') %>
|
11
|
+
|
12
|
+
|
13
|
+
<%= link_to_add_fields(
|
14
|
+
t('stories.steps.setup_tasks.add_column'), f, :columns, target: 'setup_columns_input'
|
15
|
+
) %>
|
16
|
+
</div>
|
17
|
+
</div>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div id="setup_columns_input" class="form-inputs">
|
21
|
+
<%= f.simple_fields_for :columns do |column_form| %>
|
22
|
+
<%= render_product_specific_partial_if_available(
|
23
|
+
column_form.object, 'stories/column_fields', f: column_form
|
24
|
+
) %>
|
25
|
+
<% end %>
|
26
|
+
</div>
|
27
|
+
|
28
|
+
<div class="form-actions">
|
29
|
+
<div class="control-group string required" style="display: block">
|
30
|
+
<div class="controls">
|
31
|
+
<%= f.button :submit, t('stories.steps.setup_tasks.update') %>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
</div>
|
35
|
+
<% end %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<h3><%= resource.name %></h3>
|
2
|
+
|
3
|
+
<strong><%= t('activerecord.attributes.general.state') %>:</strong> <%= resource.state %>
|
4
|
+
|
5
|
+
<strong><%= t('activerecord.attributes.task.input_language') %>:</strong> <%= resource.input_language %>
|
6
|
+
|
7
|
+
<strong><%= t('activerecord.attributes.task.output_language') %>:</strong> <%= resource.output_language %>
|
8
|
+
|
9
|
+
<h4><%= t('tasks.show.story_text') %></h4>
|
10
|
+
|
11
|
+
<%= resource.story.text %>
|
12
|
+
|
13
|
+
<% if resource.text.present? %>
|
14
|
+
<h4><%= t('tasks.show.text') %></h4>
|
15
|
+
|
16
|
+
<%= resource.text %>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<h4><%= t('activerecord.models.result') %></h4>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class AddTranslationProduct < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
area = Area.where(name: 'General').first
|
4
|
+
|
5
|
+
product = Product.new(name: 'Translation', text: 'Dummy', area_ids: [area.id])
|
6
|
+
product.user_id = User.where(name: 'Master').first.id
|
7
|
+
product.save!
|
8
|
+
end
|
9
|
+
|
10
|
+
def down
|
11
|
+
Product.where(name: 'Translation').first.destroy
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: voluntary_translation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mathias Gawlista
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: voluntary
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.1.0
|
30
|
+
description: Translation product for crowdsourcing engine voluntary.
|
31
|
+
email:
|
32
|
+
- gawlista@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- app/assets/javascripts/voluntary_translation/stories.js.coffee
|
38
|
+
- app/models/product/translation/column.rb
|
39
|
+
- app/models/product/translation/story.rb
|
40
|
+
- app/models/product/translation/task.rb
|
41
|
+
- app/models/product/translation.rb
|
42
|
+
- app/views/products/types/translation/stories/steps/_activate.html.erb
|
43
|
+
- app/views/products/types/translation/stories/steps/_setup_tasks.html.erb
|
44
|
+
- app/views/products/types/translation/stories/_form.html.erb
|
45
|
+
- app/views/products/types/translation/workflow/tasks/_work_head.html.erb
|
46
|
+
- config/locales/resources/product/translation/task/en.yml
|
47
|
+
- config/locales/workflow/en.yml
|
48
|
+
- config/routes.rb
|
49
|
+
- db/migrate/20131006062915_add_translation_product.rb
|
50
|
+
- lib/tasks/voluntary_translation_tasks.rake
|
51
|
+
- lib/voluntary_translation/engine.rb
|
52
|
+
- lib/voluntary_translation/version.rb
|
53
|
+
- lib/voluntary_translation.rb
|
54
|
+
- CHANGELOG.md
|
55
|
+
- MIT-LICENSE
|
56
|
+
- Rakefile
|
57
|
+
- README.rdoc
|
58
|
+
homepage: http://github.com/volontariat/voluntary_translation
|
59
|
+
licenses: []
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
hash: 792462451
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
hash: 792462451
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.8.23
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Translation product for crowdsourcing engine voluntary.
|
88
|
+
test_files: []
|