Skip to content

Commit

Permalink
add asana families (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
fwolfst committed Oct 19, 2020
1 parent 0e4a5ce commit 6309fc9
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 8 deletions.
5 changes: 5 additions & 0 deletions app/models/asana.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class Asana < ApplicationRecord
-> {where(asana_names: { language_code: AsanaName::SANSKRIT })},
class_name: 'AsanaName'

has_many :asana_asana_families, inverse_of: :asana
has_many :asana_families, through: :asana_asana_families, inverse_of: :asanas

has_one_attached :image

accepts_nested_attributes_for :asana_names,
allow_destroy: true, reject_if: :empty_name_or_language_code?
accepts_nested_attributes_for :german_asana_names,
Expand Down
9 changes: 9 additions & 0 deletions app/models/asana_asana_family.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-FileCopyrightText: 2020 Felix Wolfsteller
#
# SPDX-License-Identifier: AGPL-3.0-or-later

class AsanaAsanaFamily < ApplicationRecord
belongs_to :asana, inverse_of: :asana_asana_families
belongs_to :asana_family, inverse_of: :asana_asana_families
end

8 changes: 8 additions & 0 deletions app/models/asana_family.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: 2020 Felix Wolfsteller
#
# SPDX-License-Identifier: AGPL-3.0-or-later

class AsanaFamily < ApplicationRecord
has_many :asana_asana_families, inverse_of: :asana_family
has_many :asanas, through: :asana_asana_families, inverse_of: :asana_families
end
3 changes: 2 additions & 1 deletion app/models/site_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-or-later

class SiteSettings
IMAGE_SETTING_KEYS = %i[blog_background
IMAGE_SETTING_KEYS = %i[blog_background asana_lexicon_header_image
logo favicon favicon-png favicon-apple-touch
intro_background]
MARKDOWN_SETTING_KEYS = %i[intro explanation
Expand All @@ -23,6 +23,7 @@ def self.find_or_create_image_site_settings
IMAGE_SETTING_KEYS.each do |key|
find_or_create(key: key, kind: 'image')
end
# i18n-tasks-use t('site_settings.asana_lexicon_header_image.help')
# i18n-tasks-use t('site_settings.blog_background.help')
# i18n-tasks-use t('site_settings.favicon-png.help')
# i18n-tasks-use t('site_settings.favicon-apple-touch.help')
Expand Down
24 changes: 18 additions & 6 deletions app/views/admin/asanas/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@

= hidden_field_tag 'back_path', params[:back_path]

.field
= f.label :asana_family
= f.collection_select :asana_family_ids,
AsanaFamily.all,
:id, :name,
prompt: t('admin.asanas.select_asana_family'), multiple: true
= t('admin.forms.or_create_new')
= text_field_tag :new_family

.field
.columns
.column
.field
= f.label :german_name_true
-# i18n-tasks-use t('activerecord.attributes.asana.german_names')
= f.label :german_names
= f.fields_for :german_asana_names do |f_asana_name|
= render 'asana_name_fields', f: f_asana_name

Expand All @@ -33,12 +43,13 @@
= f.fields_for :asana_names,
@asana.german_asana_names.build, child_index: 'REPLACE' do |f|
= render 'asana_name_fields', f: f, disabled: true
.div{ data: { action: 'click->association_form#add' } }
.div{ data: { action: 'click->association_form#add' }, class: 'button'}
= t('actions.add')

.column
.field
= f.label :english_name_true
-# i18n-tasks-use t('activerecord.attributes.asana.english_names')
= f.label :english_names

= f.fields_for :english_asana_names do |f_asana_name|
= render 'asana_name_fields', f: f_asana_name
Expand All @@ -54,12 +65,13 @@
= f.fields_for :asana_names,
@asana.english_asana_names.build, child_index: 'REPLACE' do |f|
= render 'asana_name_fields', f: f, disabled: true
.div{ data: { action: 'click->association_form#add' } }
.div{ data: { action: 'click->association_form#add' }, class: 'button'}
= t('actions.add')

.column
.field
= f.label :sanskrit_name_true
-# i18n-tasks-use t('activerecord.attributes.asana.sanskrit_names')
= f.label :sanskrit_names

= f.fields_for :sanskrit_asana_names do |f_de_name|
= render 'asana_name_fields', f: f_de_name
Expand All @@ -75,7 +87,7 @@
= f.fields_for :asana_names,
@asana.sanskrit_asana_names.build, child_index: 'REPLACE' do |f|
= render 'asana_name_fields', f: f, disabled: true
.div{ data: { action: 'click->association_form#add' } }
.div{ data: { action: 'click->association_form#add' }, class: 'button'}
= t('actions.add')

.actions
Expand Down
6 changes: 5 additions & 1 deletion app/views/admin/asanas/_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
%th
-# images
-# links
-# family
%th
= t('activerecord.attributes.asana.asana_family')
%th
= t('activerecord.attributes.asana.german_asana_names.name')
%th
Expand All @@ -21,6 +22,9 @@
- asanas.each do |asana|
%tr
%td
%td
- asana.asana_families.each do |family|
= family.name
%td
- asana.asana_names.in_de.each do |name|
= name.name
Expand Down
5 changes: 5 additions & 0 deletions app/views/pages/asana_lexicon.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
%thead
%tr
%th
= t('activerecord.attributes.asana.asana_family')
%th
= t('activerecord.attributes.asana.german_asana_names.name')
%th
Expand All @@ -23,6 +24,10 @@
%tbody
- @asanas.each do |asana|
%tr
%td
- asana.asana_families.each do |family|
.asana-family
= family.name
%td
- asana.german_asana_names.each do |name|
.asana-name
Expand Down
1 change: 1 addition & 0 deletions config/locales/actions.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ de:
Edit: Bearbeiten
Save: Speichern
Show: Anzeigen
add: Hinzufügen
are_you_sure?: Bist du dir sicher?
delete: löschen
destroy: löschen
Expand Down
12 changes: 12 additions & 0 deletions config/locales/admin.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
---
de:
admin:
asana:
creation-success: Asana erstellt
deletion-success: Asana gelöscht
update-success: Asana aktualisiert
asanas:
all: Alle Asanas
edit: Asana bearbeiten
new: Neues Asana
select_asana_family: Asana-Famile auswählen
blog:
post:
edit: Blog Post bearbeiten
Expand Down Expand Up @@ -58,6 +67,9 @@ de:
trigger_now: "Triggern!"
what: Was
when: Wann
forms:
current_image: Aktuelles Bild
or_create_new: oder neu anlegen
items:
none: Keine
lessons:
Expand Down
4 changes: 4 additions & 0 deletions config/locales/models.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ de:
activerecord:
attributes:
asana:
asana_family: Familie
english_names: Englische Bezeichnungen
english_asana_names:
name: Englischer Name
german_names: Namen (deutsch)
german_asana_names:
name: Deutscher Name
image: Bild
sanskrit_names: Namen auf Sanskrit
sanskrit_asana_names:
name: Name auf Sanskrit
blog/post:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/site_settings.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ de:
about_us_right:
default: "# Über uns zwei"
help: Über-Uns-Seite (rechte Spalte)
asana_lexicon_header_image:
help: Header Bild für Asana Lexikon
about_us:
default: "# Über uns"
help: Über-Uns-Seite
Expand Down

0 comments on commit 6309fc9

Please sign in to comment.