Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add programming language icons #2138

Merged
merged 15 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/models/programming_language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
# id :bigint not null, primary key
# name :string(255) not null
# editor_name :string(255) not null
# icon :string(255)
# extension :string(255) not null
# created_at :datetime not null
# updated_at :datetime not null
#

class ProgrammingLanguage < ApplicationRecord
DEFAULT_ICON = 'file-document-edit-outline'.freeze

before_save :fill_fields

has_many :exercises, dependent: :restrict_with_error
Expand All @@ -19,4 +22,8 @@ def fill_fields
self.editor_name ||= name
self.extension ||= 'txt'
end

def icon
self[:icon] || DEFAULT_ICON
end
end
2 changes: 1 addition & 1 deletion app/views/activities/_activities_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<td class='type-icon'>
<% if activity.exercise? %>
<i class="mdi mdi-file-document-edit-outline mdi-18" title="<%= t "activities.index.type.exercise" %>"></i>
<i class="<%= "mdi mdi-#{activity.programming_language&.icon} mdi-18" %>" title="<%= "#{t "activities.index.type.exercise_language", language: activity.programming_language.name.titleize}" %>"></i>
<% elsif activity.content_page? %>
<i class="mdi mdi-book-open-variant mdi-18" title="<%= t "activities.index.type.content" %>"></i>
<% end %>
Expand Down
3 changes: 1 addition & 2 deletions app/views/activities/_series_activities_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
<%= raw "<i class='mdi mdi-eye-off mdi-18' title='#{t("activities.index.private")}'></i>" if activity.access_private? %>
<%= raw "<i class='mdi mdi-delete mdi-18' title='#{t("activities.index.removed")}'></i>" if activity.removed? %>
<%= raw "<i class='mdi mdi-alert-circle mdi-18' title='#{t("activities.index.invalid")}'></i>" if activity.not_valid? %>

<%= raw "<i class='mdi mdi-file-document-edit-outline mdi-18' title='#{t("activities.index.type.exercise")}'></i>" if activity.exercise? %>
<%= raw "<i class='mdi mdi-#{ activity.programming_language&.icon} mdi-18' title='#{t "activities.index.type.exercise_language", language: activity.programming_language.name.titleize}'></i>" if activity.exercise? %>
<%= raw "<i class='mdi mdi-book-open-variant mdi-18' title='#{t("activities.index.type.content")}'></i>" if activity.content_page? %>
</td>
<td class="link">
Expand Down
2 changes: 1 addition & 1 deletion app/views/evaluations/_exercises_progress_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<% local_assigns[:metadata][:per_exercise].each do |meta| %>
<tr>
<td class='type-icon'>
<i class="mdi mdi-file-document-edit-outline mdi-18" title="<%= t "activities.index.type.exercise" %>"></i>
<i class=<%"mdi mdi-#{meta[:exercise].programming_language&.icon} mdi-18"%> title="<%= "#{t "activities.index.type.exercise_language", language: meta[:exercise].programming_language.name.titleize}" %>"></i>
winniederidder marked this conversation as resolved.
Show resolved Hide resolved
</td>

<td>
Expand Down
2 changes: 1 addition & 1 deletion app/views/evaluations/_exercises_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<% local_assigns[:exercises].each do |exercise| %>
<tr>
<td class='type-icon'>
<i class="mdi mdi-file-document-edit-outline mdi-18" title="<%= t "activities.index.type.exercise" %>"></i>
<i class=<%"mdi mdi-#{exercise.programming_language&.icon} mdi-18"%> title="<%= "#{t "activities.index.type.exercise_language", language: exercise.programming_language.name.titleize}" %>"></i>
winniederidder marked this conversation as resolved.
Show resolved Hide resolved
</td>

<td>
Expand Down
1 change: 1 addition & 0 deletions config/locales/views/activities/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ en:
other: "%{count} users read this."
type:
exercise: Exercise
exercise_language: "%{language} exercise"
content: Reading activity
show:
code: Code
Expand Down
1 change: 1 addition & 0 deletions config/locales/views/activities/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ nl:
other: "%{count} gebruikers hebben dit gelezen."
type:
exercise: Oefening
exercise_language: "%{language} oefening"
content: Leesactiviteit
show:
code: Code
Expand Down
22 changes: 22 additions & 0 deletions db/migrate/20200803125737_add_icon_to_programming_languages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class AddIconToProgrammingLanguages < ActiveRecord::Migration[6.0]

ICON_MAP = {
'python' => 'language-python',
'sh' => 'bash',
'javascript' => 'language-javascript',
'bash' => 'bash',
'java' => 'language-java',
'prolog' => 'owl',
'haskell' => 'language-haskell',
'R' => 'language-r',
'csharp' => 'language-csharp',
'text' => nil
}
def change
add_column :programming_languages, :icon, :string

ProgrammingLanguage.all.each do |language|
language.update(icon: ICON_MAP[language.name])
end
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_07_01_135727) do
ActiveRecord::Schema.define(version: 2020_08_03_125737) do

create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
t.string "name", null: false
Expand Down Expand Up @@ -304,6 +304,7 @@
t.string "extension", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "icon"
t.index ["name"], name: "index_programming_languages_on_name", unique: true
end

Expand Down
17 changes: 17 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@
user: user
end

puts 'Creating programming languages'
ICON_MAP = {
'python' => 'language-python',
'sh' => 'bash',
'javascript' => 'language-javascript',
'bash' => 'bash',
'java' => 'language-java',
'prolog' => 'owl',
'haskell' => 'language-haskell',
'R' => 'language-r',
'csharp' => 'language-csharp',
'text' => nil
}
ICON_MAP.each do |language, icon|
ProgrammingLanguage.create name: language, icon: icon
end

puts 'Creating courses'

courses = []
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.