mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-28 09:24:24 +01:00
add slugs to event filters + add categories into statistics + prevent remove linked elements in front
This commit is contained in:
parent
812d7a3c05
commit
c8b42f1b7f
@ -194,11 +194,14 @@ Application.Controllers.controller "AdminEventsController", ["$scope", "$state",
|
||||
if model == 'category' and getModel(model)[1].length == 1
|
||||
growl.error(_t('at_least_one_category_is_required_unable_to_delete_the_last_one'))
|
||||
return false
|
||||
if getModel(model)[1][index].related_to > 0
|
||||
growl.error(_t('unable_to_delete_ELEMENT_already_in_use_NUMBER_times', {ELEMENT:model, NUMBER:getModel(model)[1][index].related_to}, "messageformat"))
|
||||
return false
|
||||
dialogs.confirm
|
||||
resolve:
|
||||
object: ->
|
||||
title: _t('confirmation_required')
|
||||
msg: _t('do_you_really_want_to_delete_this_ELEMENT_used_NUMBER_times', {ELEMENT:model, NUMBER:getModel(model)[1][index].related_to}, "messageformat")
|
||||
msg: _t('do_you_really_want_to_delete_this_ELEMENT', {ELEMENT:model}, "messageformat")
|
||||
, -> # delete confirmed
|
||||
getModel(model)[0].delete getModel(model)[1][index]
|
||||
getModel(model)[1].splice(index, 1)
|
||||
|
@ -1,3 +1,6 @@
|
||||
class AgeRange < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :name, use: :slugged
|
||||
|
||||
has_many :events, dependent: :nullify
|
||||
end
|
||||
|
@ -1,8 +1,33 @@
|
||||
class Category < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :name, use: :slugged
|
||||
|
||||
has_and_belongs_to_many :events, join_table: :events_categories, dependent: :destroy
|
||||
|
||||
after_create :create_statistic_subtype
|
||||
after_update :update_statistic_subtype, if: :name_changed?
|
||||
after_destroy :remove_statistic_subtype
|
||||
|
||||
|
||||
def create_statistic_subtype
|
||||
index = StatisticIndex.where(es_type_key: 'event')
|
||||
StatisticSubType.create!({statistic_types: index.first.statistic_types, key: self.slug, label: self.name})
|
||||
end
|
||||
|
||||
def update_statistic_subtype
|
||||
index = StatisticIndex.where(es_type_key: 'event')
|
||||
subtype = StatisticSubType.joins(statistic_type_sub_types: :statistic_type).where(key: self.slug, statistic_types: { statistic_index_id: index.first.id }).first
|
||||
subtype.label = self.name
|
||||
subtype.save!
|
||||
end
|
||||
|
||||
def remove_statistic_subtype
|
||||
subtype = StatisticSubType.where(key: self.slug).first
|
||||
subtype.destroy!
|
||||
end
|
||||
|
||||
def safe_destroy
|
||||
if count > 1
|
||||
if Category.count > 1 && self.events.count == 0
|
||||
destroy
|
||||
else
|
||||
false
|
||||
|
@ -1,3 +1,6 @@
|
||||
class EventTheme < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :name, use: :slugged
|
||||
|
||||
has_and_belongs_to_many :events, join_table: :events_event_themes, dependent: :destroy
|
||||
end
|
||||
|
@ -84,7 +84,8 @@ en:
|
||||
add_a_theme: "Add a theme"
|
||||
age_ranges: "Age ranges"
|
||||
add_a_range: "Add a range"
|
||||
do_you_really_want_to_delete_this_ELEMENT_used_NUMBER_times: "Do you really want to delete this {ELEMENT, select, category{category} theme{theme} age_range{age range} other{element}}? {NUMBER, plural, =0{It is not currently associated with any events} one{Currently, it is associated with only one event} other{Currently, it is associated with {NUMBER} events}}." # messageFormat interpolation
|
||||
do_you_really_want_to_delete_this_ELEMENT: "Do you really want to delete this {ELEMENT, select, category{category} theme{theme} age_range{age range} other{element}}?" # messageFormat interpolation
|
||||
unable_to_delete_ELEMENT_already_in_use_NUMBER_times: "Unable to delete this {ELEMENT, select, category{category} theme{theme} age_range{age range} other{element}} because it is already associated with {NUMBER, plural, =0{no events} one{one event} other{{NUMBER} events}}." # messageFormat interpolation
|
||||
at_least_one_category_is_required_unable_to_delete_the_last_one: "At least one category is required. Unable to delete the last one."
|
||||
|
||||
events_new:
|
||||
|
@ -84,7 +84,8 @@ fr:
|
||||
add_a_theme: "Ajouter une thématique"
|
||||
age_ranges: "Tranches d'âge"
|
||||
add_a_range: "Ajouter une tranche"
|
||||
do_you_really_want_to_delete_this_ELEMENT_used_NUMBER_times: "Voulez-vous vraiment supprimer cette {ELEMENT, select, category{catégorie} theme{thématique} age_range{tranche d'âge} other{élément}} ? {NUMBER, plural, =0{Elle n'est actuellement associée à aucun évènement} one{Elle est actuellement associée à un seul évènement} other{Elle est actuellement associée à {NUMBER} évènements}}." # messageFormat interpolation
|
||||
do_you_really_want_to_delete_this_ELEMENT: "Voulez-vous vraiment supprimer cette {ELEMENT, select, category{catégorie} theme{thématique} age_range{tranche d'âge} other{élément}} ?" # messageFormat interpolation
|
||||
unable_to_delete_ELEMENT_already_in_use_NUMBER_times: "Impossible de supprimer cette {ELEMENT, select, category{catégorie} theme{thématique} age_range{tranche d'âge} other{élément}} car elle est actuellement associée à {NUMBER, plural, =0{aucun évènement} one{un évènement} other{{NUMBER} évènements}}." # messageFormat interpolation
|
||||
at_least_one_category_is_required_unable_to_delete_the_last_one: "Au moins une catégorie est requise. Impossible de supprimer la dernière."
|
||||
|
||||
events_new:
|
||||
|
6
db/migrate/20160630083438_add_slug_to_categories.rb
Normal file
6
db/migrate/20160630083438_add_slug_to_categories.rb
Normal file
@ -0,0 +1,6 @@
|
||||
class AddSlugToCategories < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :categories, :slug, :string
|
||||
add_index :categories, :slug, unique: true
|
||||
end
|
||||
end
|
6
db/migrate/20160630083556_add_slug_to_age_range.rb
Normal file
6
db/migrate/20160630083556_add_slug_to_age_range.rb
Normal file
@ -0,0 +1,6 @@
|
||||
class AddSlugToAgeRange < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :age_ranges, :slug, :string
|
||||
add_index :age_ranges, :slug, unique: true
|
||||
end
|
||||
end
|
6
db/migrate/20160630083759_add_slug_to_event_theme.rb
Normal file
6
db/migrate/20160630083759_add_slug_to_event_theme.rb
Normal file
@ -0,0 +1,6 @@
|
||||
class AddSlugToEventTheme < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :event_themes, :slug, :string
|
||||
add_index :event_themes, :slug, unique: true
|
||||
end
|
||||
end
|
11
db/schema.rb
11
db/schema.rb
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160629091649) do
|
||||
ActiveRecord::Schema.define(version: 20160630083759) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -48,8 +48,11 @@ ActiveRecord::Schema.define(version: 20160629091649) do
|
||||
t.string "name"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "slug"
|
||||
end
|
||||
|
||||
add_index "age_ranges", ["slug"], name: "index_age_ranges_on_slug", unique: true, using: :btree
|
||||
|
||||
create_table "assets", force: :cascade do |t|
|
||||
t.integer "viewable_id"
|
||||
t.string "viewable_type", limit: 255
|
||||
@ -92,8 +95,11 @@ ActiveRecord::Schema.define(version: 20160629091649) do
|
||||
t.string "name", limit: 255
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "slug"
|
||||
end
|
||||
|
||||
add_index "categories", ["slug"], name: "index_categories_on_slug", unique: true, using: :btree
|
||||
|
||||
create_table "components", force: :cascade do |t|
|
||||
t.string "name", limit: 255, null: false
|
||||
end
|
||||
@ -124,8 +130,11 @@ ActiveRecord::Schema.define(version: 20160629091649) do
|
||||
t.string "name"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "slug"
|
||||
end
|
||||
|
||||
add_index "event_themes", ["slug"], name: "index_event_themes_on_slug", unique: true, using: :btree
|
||||
|
||||
create_table "events", force: :cascade do |t|
|
||||
t.string "title", limit: 255
|
||||
t.text "description"
|
||||
|
Loading…
Reference in New Issue
Block a user