diff --git a/app/controllers/settings/group_categories_controller.rb b/app/controllers/settings/group_categories_controller.rb new file mode 100644 index 00000000..9826675b --- /dev/null +++ b/app/controllers/settings/group_categories_controller.rb @@ -0,0 +1,43 @@ +class Settings::GroupCategoriesController < Admin::BaseController + before_action :set_category, except: [:index, :new, :create] + + def index + @categories = GroupCategories.all + end + + def new + @category = GroupCategories.new + end + + def create + @category = GroupCategories.new(resource_params) + + if @category.save + log_action :create, @category + redirect_to settings_group_categories_path, notice: I18n.t('promotions.created_msg') + else + render :new + end + end + + def destroy + # : todo : + # don't destroy if any groups have this category + + @category.destroy! + log_action :destroy, @category + flash[:notice] = I18n.t('promotions.destroyed_msg') + redirect_to settings_group_categories_path + end + + private + + def set_category + @category = GroupCategories.find(params[:id]) + end + + def resource_params + params.permit(:text) + end + +end diff --git a/app/views/settings/group_categories/_group_categories.html.haml b/app/views/settings/group_categories/_group_categories.html.haml new file mode 100644 index 00000000..85cbd545 --- /dev/null +++ b/app/views/settings/group_categories/_group_categories.html.haml @@ -0,0 +1,5 @@ +%tr + %td= group_categories.created_at + %td= group_categories.text + %td + = table_link_to 'trash', t('group_categories.delete'), settings_group_categories_path(group_categories), method: :delete diff --git a/app/views/settings/group_categories/index.html.haml b/app/views/settings/group_categories/index.html.haml new file mode 100644 index 00000000..a2f3d886 --- /dev/null +++ b/app/views/settings/group_categories/index.html.haml @@ -0,0 +1,20 @@ +- content_for :page_title do + = t('group_categories.title') + += form_tag settings_group_categories_url, method: 'POST', class: 'simple_form' do + .fields-group + .input.string.optional + = text_field_tag :text, params[:text], class: 'string optional', placeholder: I18n.t("group_categories.text") + + .actions + %button= t('group_categories.create') + +.table-wrapper + %table.table + %thead + %tr + %th= t('categories.created_at') + %th= t('categories.text') + %th + %tbody + = render @categories \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index b5f2088d..b9308d85 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -74,6 +74,11 @@ en: title: Promotions monthly_funding: title: Monthly Funding + group_categories: + create: Create + delete: Delete + text: Text + title: Group Categories admin: account_actions: action: Perform action diff --git a/config/navigation.rb b/config/navigation.rb index f4c5cd9a..b3a2c00a 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -51,6 +51,7 @@ SimpleNavigation::Configuration.run do |navigation| s.item :moderation, safe_join([fa_icon('id-card-o fw'), t('verifications.moderation.title')]), settings_verifications_moderation_url, if: -> { current_user.admin? } s.item :promotions, safe_join([fa_icon('star fw'), t('promotions.title')]), settings_promotions_url, if: -> { current_user.admin? } s.item :monthly_funding, safe_join([fa_icon('money fw'), t('monthly_funding.title')]), settings_expenses_url, if: -> { current_user.admin? } + s.item :group_categories, safe_join([fa_icon('users fw'), t('group_categories.title')]), settings_group_categories_url, if: -> { current_user.admin? } end n.item :logout, safe_join([fa_icon('sign-out fw'), t('auth.logout')]), destroy_user_session_url, link_html: { 'data-method' => 'delete' } diff --git a/config/routes.rb b/config/routes.rb index 3fff49ab..f4e252a4 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -97,6 +97,7 @@ Rails.application.routes.draw do resources :promotions, only: [:index, :new, :create, :edit, :update, :destroy] resources :expenses, only: [:index, :new, :create, :edit, :update, :destroy] + resources :group_categories, only: [:index, :new, :create, :edit, :update, :destroy] namespace :verifications do get :moderation, to: 'moderation#index', as: :moderation