Skip to content

Commit 0370dcc

Browse files
author
Theresa Zobel
committed
Merge pull request #34 from openHPI/26_exercise_language
26 exercise language
2 parents 58afc29 + 5e1a53f commit 0370dcc

File tree

12 files changed

+58
-28
lines changed

12 files changed

+58
-28
lines changed

app/models/description.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class Description < ActiveRecord::Base
22
belongs_to :exercise
33

4+
LANGUAGES= ['en', 'de','fr', 'es', 'ja', 'cn']
45

56
end

app/models/exercise.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ def add_descriptions(description_array)
5757
description_array.try(:each) do |key, array|
5858
destroy = array[:_destroy]
5959
id = array[:id]
60+
6061
if id
6162
description = Description.find(id)
62-
destroy ? description.destroy : description.update(text: array[:text])
63+
destroy ? description.destroy : description.update(text: array[:text], language: array[:language])
6364
else
64-
descriptions << Description.create(text: array[:text]) unless destroy
65+
descriptions << Description.create(text: array[:text], language: array[:language]) unless destroy
6566
end
6667
end
6768
end

app/views/comments/comments_all.html.erb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@
1414
<tbody>
1515
<% @comments.each do |comment| %>
1616
<tr>
17-
<td><%= link_to comment.exercise.title, exercise_path(comment.exercise) %></td>
17+
<% if !comment.exercise %>
18+
<td> <%= 'Exercise undefined' %> </td>
19+
<% else %>
20+
<td><%= link_to comment.exercise.title, exercise_path(comment.exercise) %></td>
21+
<% end %>
1822
<td><%= comment.text %></td>
19-
<% if comment.user.first_name.nil? %>
23+
<% if !comment.user %>
24+
<td> <%= 'User undefined' %> </td>
25+
<% elsif comment.user.first_name.nil?%>
2026
<td><%= link_to "User#{comment.user.id}", user_path(comment.user)%></td>
2127
<% else %>
2228
<td><%= link_to comment.user.name, user_path(comment.user) %></td>

app/views/comments/index.html.erb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
<% @comments.each do |comment| %>
2626
<tr>
2727
<td><%= comment.text %></td>
28-
<% if comment.user.first_name.nil? %>
29-
<td><%= "User#{comment.user.id}"%></td>
28+
<% if !comment.user %>
29+
<td> <%= 'User undefined' %> </td>
30+
<% elsif comment.user.first_name.nil?%>
31+
<td><%= "User#{comment.user.id}"%></td>
3032
<% else %>
31-
<td><%= comment.user.name %></td>
33+
<td><%= comment.user.name%></td>
3234
<% end %>
3335
<td><%= comment.created_at %>
3436
<td><div class="actions btn-group" role="group">

app/views/exercises/_form.html.erb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@
3030
<div class="controls" style="margin-top: 10px; margin-bottom: 10px">
3131
<%= description.text_area :text, class:'form-control' %>
3232
<%= description.remove_nested_fields_link 'Remove Description', class:'btn btn-danger btn-xs' %>
33+
<div class="field">
34+
<%= f.label :language %><br>
35+
<%= description.collection_select :language, Description::LANGUAGES, :to_s, :to_s, include_blank: false %>
36+
</div>
3337
</div>
3438
<% end %>
3539
<%= f.add_nested_fields_link :descriptions, 'Add Description', class:'btn btn-success' %>
3640
</div>
3741

3842

43+
3944
<div class="form-group">
4045
<%= f.label :public, class: 'control-label' %>
4146
<div class='radio'>
@@ -51,7 +56,6 @@
5156
</div>
5257
</div>
5358
</div>
54-
5559
<h4>Files:</h4>
5660
<%= f.nested_fields_for :exercise_files do |file| %>
5761
<%= render 'file_form', f: f, file: file %>

app/views/exercises/exercises_all.html.erb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
<% @exercises.each do |exercise| %>
1616
<tr>
1717
<td><%= link_to exercise.title, exercise %></td>
18-
<% if defined? exercise.user %>
19-
<% if exercise.user.first_name.nil?%>
20-
<td><%= link_to "User#{exercise.user.id}", user_path(exercise.user)%></td>
21-
<% else %>
22-
<td><%= link_to exercise.user.name, user_path(exercise.user) %></td>
23-
<% end %>
18+
<% if !exercise.user %>
19+
<td> <%= 'User undefined' %> </td>
20+
<% elsif exercise.user.first_name.nil?%>
21+
<td><%= link_to "User#{exercise.user.id}", user_path(exercise.user)%></td>
2422
<% else %>
25-
<%= 'User undefined' %>
23+
<td><%= link_to exercise.user.name, user_path(exercise.user) %></td>
2624
<% end %>
2725
<td><%= exercise.created_at %> </td>
2826
<td><%= exercise.public ? 'public' : 'private' %> </td>

app/views/exercises/show.html.erb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
<dl class="dl-horizontal">
88
<dt><%= 'Title' %>:</dt>
99
<dd><%= @exercise.title %></dd>
10-
<dt><%= 'Description' %></dt>
11-
<dd><%= @exercise.description %></dd>
10+
<% @exercise.descriptions.each do |description|%>
11+
<dt><%= 'Description in' %> <%= description.language %>:</dt>
12+
<dd><%= description.text %></dd>
13+
<% end %>
1214
<dt><%= 'Visibility' %>:</dt>
1315
<dd><%= @exercise.public ? 'public' : 'private' %></dd>
1416
<dt><%= 'Created by' %>:</dt>
15-
<% if @exercise.user %>
16-
<% if @exercise.user.first_name.nil?%>
17+
<% if !@exercise.user %>
18+
<dd><%= 'User undefined' %></dd>
19+
<% elsif @exercise.user.first_name.nil?%>
1720
<dd><%= "User#{@exercise.user.id}"%></dd>
18-
<% else %>
19-
<dd><%= @exercise.user.name %></dd>
20-
<% end %>
2121
<% else %>
22-
<dd><%= 'User undefined' %></dd>
22+
<dd><%= @exercise.user.name %></dd>
2323
<% end %>
2424
<dt><%= 'Created at' %>:</dt>
2525
<dd><%= @exercise.created_at %></dd>
@@ -77,7 +77,9 @@
7777
<div class="actions btn-group" role="group">
7878
<% if can? :edit, @exercise %>
7979
<%= link_to 'Edit', edit_exercise_path(@exercise), class: 'btn btn-warning' %>
80-
<% end %>
80+
<%= link_to 'Delete', exercise_path(@exercise), class:'btn btn-danger', method: :delete, data: { confirm: 'Are you sure?' } %>
81+
82+
<% end %>
8183
<%= link_to 'Back', exercises_path, class: 'btn btn-default' %>
8284

8385
</div>

app/views/home/_exercises.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<div class="panel-body">
2424

2525
<div class="col-md-10">
26-
<%= exercise.description %>
26+
<%= exercise.descriptions.first.text %>
2727
</div>
2828

2929
<div class="btn-group-vertical pull-right" role="group" aria-label="...">

config/routes.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
get 'sessions/destroy'
1616

1717
get 'comments/comments_all'
18+
get 'exercises/exercises_all'
1819

1920
get 'exercises/:id/duplicate', to: 'exercises#duplicate', as: 'duplicate_exercise'
2021

@@ -35,8 +36,6 @@
3536
end
3637
end
3738

38-
get 'exercises/exercises_all'
39-
4039

4140

4241

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddLanguageToDescription < ActiveRecord::Migration
2+
def change
3+
add_column :descriptions, :language, :string, default: 'EN'
4+
end
5+
end

0 commit comments

Comments
 (0)