From 6309fc98e0ce8ba28c7ecbf7aa962dab5ebc421d Mon Sep 17 00:00:00 2001 From: Felix Wolfsteller Date: Mon, 19 Oct 2020 08:21:07 +0200 Subject: [PATCH] add asana families (#35) --- app/models/asana.rb | 5 +++++ app/models/asana_asana_family.rb | 9 +++++++++ app/models/asana_family.rb | 8 ++++++++ app/models/site_settings.rb | 3 ++- app/views/admin/asanas/_form.html.haml | 24 ++++++++++++++++++------ app/views/admin/asanas/_table.html.haml | 6 +++++- app/views/pages/asana_lexicon.html.haml | 5 +++++ config/locales/actions.de.yml | 1 + config/locales/admin.de.yml | 12 ++++++++++++ config/locales/models.de.yml | 4 ++++ config/locales/site_settings.de.yml | 2 ++ 11 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 app/models/asana_asana_family.rb create mode 100644 app/models/asana_family.rb diff --git a/app/models/asana.rb b/app/models/asana.rb index 4022fd2..bf6eda7 100644 --- a/app/models/asana.rb +++ b/app/models/asana.rb @@ -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, diff --git a/app/models/asana_asana_family.rb b/app/models/asana_asana_family.rb new file mode 100644 index 0000000..4578cc4 --- /dev/null +++ b/app/models/asana_asana_family.rb @@ -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 + diff --git a/app/models/asana_family.rb b/app/models/asana_family.rb new file mode 100644 index 0000000..45125b9 --- /dev/null +++ b/app/models/asana_family.rb @@ -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 diff --git a/app/models/site_settings.rb b/app/models/site_settings.rb index c9840bd..d74c309 100644 --- a/app/models/site_settings.rb +++ b/app/models/site_settings.rb @@ -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 @@ -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') diff --git a/app/views/admin/asanas/_form.html.haml b/app/views/admin/asanas/_form.html.haml index 3532e53..5b6110d 100644 --- a/app/views/admin/asanas/_form.html.haml +++ b/app/views/admin/asanas/_form.html.haml @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/app/views/admin/asanas/_table.html.haml b/app/views/admin/asanas/_table.html.haml index bcbe97b..efd3101 100644 --- a/app/views/admin/asanas/_table.html.haml +++ b/app/views/admin/asanas/_table.html.haml @@ -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 @@ -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 diff --git a/app/views/pages/asana_lexicon.html.haml b/app/views/pages/asana_lexicon.html.haml index 4a1f932..cd9c9f5 100644 --- a/app/views/pages/asana_lexicon.html.haml +++ b/app/views/pages/asana_lexicon.html.haml @@ -13,6 +13,7 @@ %thead %tr %th + = t('activerecord.attributes.asana.asana_family') %th = t('activerecord.attributes.asana.german_asana_names.name') %th @@ -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 diff --git a/config/locales/actions.de.yml b/config/locales/actions.de.yml index 6b253e6..f635d34 100644 --- a/config/locales/actions.de.yml +++ b/config/locales/actions.de.yml @@ -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 diff --git a/config/locales/admin.de.yml b/config/locales/admin.de.yml index 3104565..871a5b2 100644 --- a/config/locales/admin.de.yml +++ b/config/locales/admin.de.yml @@ -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 @@ -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: diff --git a/config/locales/models.de.yml b/config/locales/models.de.yml index 8f158d4..c496c04 100644 --- a/config/locales/models.de.yml +++ b/config/locales/models.de.yml @@ -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: diff --git a/config/locales/site_settings.de.yml b/config/locales/site_settings.de.yml index b2e4963..e408076 100644 --- a/config/locales/site_settings.de.yml +++ b/config/locales/site_settings.de.yml @@ -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