mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
[feature] manage event's age range
This commit is contained in:
parent
51cce7bbc3
commit
79b97eb113
@ -136,8 +136,8 @@ class EventsController
|
||||
##
|
||||
# Controller used in the events listing page (admin view)
|
||||
##
|
||||
Application.Controllers.controller "AdminEventsController", ["$scope", "$state", 'Event', 'Category', 'EventThemes', 'eventsPromise', 'categoriesPromise', 'themesPromise'
|
||||
, ($scope, $state, Event, Category, EventThemes, eventsPromise, categoriesPromise, themesPromise) ->
|
||||
Application.Controllers.controller "AdminEventsController", ["$scope", "$state", 'Event', 'Category', 'EventTheme', 'AgeRange', 'eventsPromise', 'categoriesPromise', 'themesPromise', 'ageRangesPromise'
|
||||
, ($scope, $state, Event, Category, EventTheme, AgeRange, eventsPromise, categoriesPromise, themesPromise, ageRangesPromise) ->
|
||||
|
||||
|
||||
|
||||
@ -164,6 +164,9 @@ Application.Controllers.controller "AdminEventsController", ["$scope", "$state",
|
||||
## List of events themes
|
||||
$scope.themes = themesPromise
|
||||
|
||||
## List of age ranges
|
||||
$scope.ageRanges = ageRangesPromise
|
||||
|
||||
##
|
||||
# Adds a bucket of events to the bottom of the page, grouped by month
|
||||
##
|
||||
@ -254,8 +257,8 @@ Application.Controllers.controller "AdminEventsController", ["$scope", "$state",
|
||||
getModel = (name) ->
|
||||
switch name
|
||||
when 'category' then [Category, $scope.categories]
|
||||
when 'theme' then [EventThemes, $scope.themes]
|
||||
#when 'age_range' then [AgeRange, $scope.ageRanges]
|
||||
when 'theme' then [EventTheme, $scope.themes]
|
||||
when 'age_range' then [AgeRange, $scope.ageRanges]
|
||||
else [null, []]
|
||||
|
||||
|
||||
|
@ -537,8 +537,11 @@ angular.module('application.router', ['ui.router']).
|
||||
categoriesPromise: ['Category', (Category) ->
|
||||
Category.query().$promise
|
||||
]
|
||||
themesPromise: ['EventThemes', (EventThemes) ->
|
||||
EventThemes.query().$promise
|
||||
themesPromise: ['EventTheme', (EventTheme) ->
|
||||
EventTheme.query().$promise
|
||||
]
|
||||
ageRangesPromise: ['AgeRange', (AgeRange) ->
|
||||
AgeRange.query().$promise
|
||||
]
|
||||
translations: [ 'Translations', (Translations) ->
|
||||
Translations.query('app.admin.events').$promise
|
||||
|
8
app/assets/javascripts/services/age_range.coffee
Normal file
8
app/assets/javascripts/services/age_range.coffee
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
Application.Services.factory 'AgeRange', ["$resource", ($resource)->
|
||||
$resource "/api/age_ranges/:id",
|
||||
{id: "@id"},
|
||||
update:
|
||||
method: 'PUT'
|
||||
]
|
@ -1,6 +1,6 @@
|
||||
'use strict'
|
||||
|
||||
Application.Services.factory 'EventThemes', ["$resource", ($resource)->
|
||||
Application.Services.factory 'EventTheme', ["$resource", ($resource)->
|
||||
$resource "/api/event_themes/:id",
|
||||
{id: "@id"},
|
||||
update:
|
@ -56,7 +56,7 @@
|
||||
</td>
|
||||
<td>
|
||||
<!-- form -->
|
||||
<form editable-form name="rowform" onbeforesave="saveElement('theme', $data, category.id)" ng-show="rowform.$visible" class="form-buttons form-inline" shown="inserted.theme == theme">
|
||||
<form editable-form name="rowform" onbeforesave="saveElement('theme', $data, theme.id)" ng-show="rowform.$visible" class="form-buttons form-inline" shown="inserted.theme == theme">
|
||||
<button type="submit" ng-disabled="rowform.$waiting" class="btn btn-warning">
|
||||
<i class="fa fa-check"></i>
|
||||
</button>
|
||||
@ -77,4 +77,43 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3 translate>{{ 'age_ranges' }}</h3>
|
||||
<button type="button" class="btn btn-warning m-b m-t" ng-click="addElement('age_range')" translate>{{ 'add_a_range' }}</button>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:80%" translate>{{ 'name' }}</th>
|
||||
<th style="width:20%"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="range in ageRanges">
|
||||
<td>
|
||||
<span editable-text="range.name" e-cols="100" e-name="name" e-form="rowform" e-required>
|
||||
{{ range.name }}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<!-- form -->
|
||||
<form editable-form name="rowform" onbeforesave="saveElement('age_range', $data, range.id)" ng-show="rowform.$visible" class="form-buttons form-inline" shown="inserted.age_range == range">
|
||||
<button type="submit" ng-disabled="rowform.$waiting" class="btn btn-warning">
|
||||
<i class="fa fa-check"></i>
|
||||
</button>
|
||||
<button type="button" ng-disabled="rowform.$waiting" ng-click="cancelElement('age_range', rowform, $index)" class="btn btn-default">
|
||||
<i class="fa fa-times"></i>
|
||||
</button>
|
||||
</form>
|
||||
<div class="buttons" ng-show="!rowform.$visible">
|
||||
<button class="btn btn-default" ng-click="rowform.$show()">
|
||||
<i class="fa fa-edit"></i> <span class="hidden-xs hidden-sm" translate>{{ 'edit' }}</span>
|
||||
</button>
|
||||
<button class="btn btn-danger" ng-click="removeElement('age_range', $index)">
|
||||
<i class="fa fa-trash-o"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
47
app/controllers/api/age_ranges_controller.rb
Normal file
47
app/controllers/api/age_ranges_controller.rb
Normal file
@ -0,0 +1,47 @@
|
||||
class API::AgeRangesController < API::ApiController
|
||||
before_action :authenticate_user!
|
||||
before_action :set_age_range, only: [:show, :update, :destroy]
|
||||
|
||||
def index
|
||||
authorize AgeRange
|
||||
@age_ranges = AgeRange.all
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def create
|
||||
authorize AgeRange
|
||||
@age_range = AgeRange.new(age_range_params)
|
||||
if @age_range.save
|
||||
render :show, status: :created, location: @age_range
|
||||
else
|
||||
render json: @age_range.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def update
|
||||
authorize AgeRange
|
||||
if @age_range.update(age_range_params)
|
||||
render :show, status: :ok, location: @age_range
|
||||
else
|
||||
render json: @age_range.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
authorize AgeRange
|
||||
@age_range.destroy
|
||||
head :no_content
|
||||
end
|
||||
|
||||
private
|
||||
def set_age_range
|
||||
@age_range = AgeRange.find(params[:id])
|
||||
end
|
||||
|
||||
def age_range_params
|
||||
params.require(:age_range).permit(:name)
|
||||
end
|
||||
end
|
7
app/policies/age_range_policy.rb
Normal file
7
app/policies/age_range_policy.rb
Normal file
@ -0,0 +1,7 @@
|
||||
class AgeRangePolicy < ApplicationPolicy
|
||||
%w(index create update destroy show).each do |action|
|
||||
define_method "#{action}?" do
|
||||
user.is_admin?
|
||||
end
|
||||
end
|
||||
end
|
3
app/views/api/age_ranges/index.json.jbuilder
Normal file
3
app/views/api/age_ranges/index.json.jbuilder
Normal file
@ -0,0 +1,3 @@
|
||||
json.array!(@age_ranges) do |ar|
|
||||
json.extract! ar, :id, :name
|
||||
end
|
1
app/views/api/age_ranges/show.json.jbuilder
Normal file
1
app/views/api/age_ranges/show.json.jbuilder
Normal file
@ -0,0 +1 @@
|
||||
json.extract! @age_range, :id, :name
|
@ -82,6 +82,8 @@ en:
|
||||
categories: "Categories"
|
||||
add_a_category: "Add a category"
|
||||
add_a_theme: "Add a theme"
|
||||
age_ranges: "Age ranges"
|
||||
add_a_range: "Add a range"
|
||||
|
||||
events_new:
|
||||
# add a new event
|
||||
|
@ -82,6 +82,8 @@ fr:
|
||||
categories: "Catégories"
|
||||
add_a_category: "Ajouter une catégorie"
|
||||
add_a_theme: "Ajouter une thématique"
|
||||
age_ranges: "Tranches d'âge"
|
||||
add_a_range: "Ajouter une tranche"
|
||||
|
||||
events_new:
|
||||
# ajouter un nouveau atelier/stage
|
||||
|
@ -89,6 +89,7 @@ Rails.application.routes.draw do
|
||||
resources :credits
|
||||
resources :categories
|
||||
resources :event_themes
|
||||
resources :age_ranges
|
||||
resources :statistics, only: [:index]
|
||||
resources :custom_assets, only: [:show, :create, :update]
|
||||
resources :tags
|
||||
|
@ -0,0 +1,3 @@
|
||||
class RenameRangeToNameFromAgeRange < ActiveRecord::Migration
|
||||
rename_column :age_ranges, :range, :name
|
||||
end
|
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160628134303) do
|
||||
ActiveRecord::Schema.define(version: 20160629091649) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@ -45,7 +45,7 @@ ActiveRecord::Schema.define(version: 20160628134303) do
|
||||
end
|
||||
|
||||
create_table "age_ranges", force: :cascade do |t|
|
||||
t.string "range"
|
||||
t.string "name"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user