1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

ability to link filters to events

This commit is contained in:
Sylvain 2016-06-29 17:05:42 +02:00
parent 09bcd7df2c
commit e13870555b
7 changed files with 94 additions and 17 deletions

View File

@ -7,7 +7,6 @@
# in the various events' admin controllers.
#
# Provides :
# - $scope.categories = [{Category}]
# - $scope.datePicker = {}
# - $scope.submited(content)
# - $scope.cancel()
@ -23,13 +22,7 @@
# - $state (Ui-Router) [ 'app.public.events_list' ]
##
class EventsController
constructor: ($scope, $state, Event, Category) ->
## Retrieve the list of categories from the server (course, workshop, ...)
Category.query().$promise.then (data)->
$scope.categories = data.map (d) ->
id: d.id
name: d.name
constructor: ($scope, $state) ->
## default parameters for AngularUI-Bootstrap datepicker
$scope.datePicker =
@ -286,8 +279,8 @@ Application.Controllers.controller "ShowEventReservationsController", ["$scope",
##
# Controller used in the event creation page
##
Application.Controllers.controller "NewEventController", ["$scope", "$state", "$locale", 'Event', 'Category', 'CSRF', '_t'
, ($scope, $state, $locale, Event, Category, CSRF, _t) ->
Application.Controllers.controller "NewEventController", ["$scope", "$state", "$locale", 'CSRF', 'categoriesPromise', 'themesPromise', 'ageRangesPromise', '_t'
, ($scope, $state, $locale, CSRF, categoriesPromise, themesPromise, ageRangesPromise, _t) ->
CSRF.setMetaTags()
## API URL where the form will be posted
@ -296,6 +289,15 @@ Application.Controllers.controller "NewEventController", ["$scope", "$state", "$
## Form action on the above URL
$scope.method = 'post'
## List of categories for the events
$scope.categories = categoriesPromise
## List of events themes
$scope.themes = themesPromise
## List of age ranges
$scope.ageRanges = ageRangesPromise
## Default event parameters
$scope.event =
event_files_attributes: []
@ -320,7 +322,7 @@ Application.Controllers.controller "NewEventController", ["$scope", "$state", "$
$scope.currencySymbol = $locale.NUMBER_FORMATS.CURRENCY_SYM;
## Using the EventsController
new EventsController($scope, $state, Event, Category)
new EventsController($scope, $state)
]
@ -328,8 +330,8 @@ Application.Controllers.controller "NewEventController", ["$scope", "$state", "$
##
# Controller used in the events edition page
##
Application.Controllers.controller "EditEventController", ["$scope", "$state", "$stateParams", "$locale", 'Event', 'Category', 'CSRF', 'eventPromise'
, ($scope, $state, $stateParams, $locale, Event, Category, CSRF, eventPromise) ->
Application.Controllers.controller "EditEventController", ["$scope", "$state", "$stateParams", "$locale", 'CSRF', 'eventPromise', 'categoriesPromise', 'themesPromise', 'ageRangesPromise'
, ($scope, $state, $stateParams, $locale, CSRF, eventPromise, categoriesPromise, themesPromise, ageRangesPromise) ->
### PUBLIC SCOPE ###
@ -347,6 +349,15 @@ Application.Controllers.controller "EditEventController", ["$scope", "$state", "
## currency symbol for the current locale (cf. angular-i18n)
$scope.currencySymbol = $locale.NUMBER_FORMATS.CURRENCY_SYM;
## List of categories for the events
$scope.categories = categoriesPromise
## List of events themes
$scope.themes = themesPromise
## List of age ranges
$scope.ageRanges = ageRangesPromise
### PRIVATE SCOPE ###
@ -364,7 +375,7 @@ Application.Controllers.controller "EditEventController", ["$scope", "$state", "
$scope.event.end_date = moment($scope.event.end_date).toDate()
## Using the EventsController
new EventsController($scope, $state, Event, Category)
new EventsController($scope, $state)

View File

@ -562,6 +562,15 @@ angular.module('application.router', ['ui.router']).
templateUrl: '<%= asset_path "events/new.html" %>'
controller: 'NewEventController'
resolve:
categoriesPromise: ['Category', (Category) ->
Category.query().$promise
]
themesPromise: ['EventTheme', (EventTheme) ->
EventTheme.query().$promise
]
ageRangesPromise: ['AgeRange', (AgeRange) ->
AgeRange.query().$promise
]
translations: [ 'Translations', (Translations) ->
Translations.query(['app.admin.events_new', 'app.shared.event']).$promise
]
@ -575,6 +584,15 @@ angular.module('application.router', ['ui.router']).
eventPromise: ['Event', '$stateParams', (Event, $stateParams)->
Event.get(id: $stateParams.id).$promise
]
categoriesPromise: ['Category', (Category) ->
Category.query().$promise
]
themesPromise: ['EventTheme', (EventTheme) ->
EventTheme.query().$promise
]
ageRangesPromise: ['AgeRange', (AgeRange) ->
AgeRange.query().$promise
]
translations: [ 'Translations', (Translations) ->
Translations.query(['app.admin.events_edit', 'app.shared.event']).$promise
]

View File

@ -80,7 +80,7 @@
<div class="widget panel b-a m m-t-lg">
<div class="panel-heading b-b small">
<h3 translate>{{ 'event_type' }}</h3>
<h3 translate>{{ 'event_type' }} *</h3>
</div>
<div class="widget-content no-bg wrapper">
<input type="hidden" name="event[category_ids][]" value="" />
@ -96,6 +96,40 @@
</div>
</div>
<div class="widget panel b-a m m-t-lg">
<div class="panel-heading b-b small">
<h3 translate>{{ 'event_theme' }}</h3>
</div>
<div class="widget-content no-bg wrapper">
<input type="hidden" name="event[event_theme_ids][]" value="" />
<ui-select ng-model="event.event_theme_ids" name="event[event_theme_ids][]">
<ui-select-match>
<span ng-bind="$select.selected.name"></span>
<input type="hidden" name="event[event_theme_ids][]" value="{{$select.selected.id}}" />
</ui-select-match>
<ui-select-choices repeat="t.id as t in (themes | filter: $select.search)">
<span ng-bind-html="t.name | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
</div>
</div>
<div class="widget panel b-a m m-t-lg">
<div class="panel-heading b-b small">
<h3 translate>{{ 'age_range' }}</h3>
</div>
<div class="widget-content no-bg wrapper">
<ui-select ng-model="event.age_range_id" name="event[age_range_id][]">
<ui-select-match>
<span ng-bind="$select.selected.name"></span>
<input type="hidden" name="event[age_range_id]" value="{{$select.selected.id}}" />
</ui-select-match>
<ui-select-choices repeat="a.id as a in (ageRanges | filter: $select.search)">
<span ng-bind-html="a.name | highlight: $select.search"></span>
</ui-select-choices>
</ui-select>
</div>
</div>
<div class="widget panel b-a m m-t-lg">
<div class="panel-heading b-b small">
<h3 translate>{{ 'dates_and_opening_hours' }}</h3>

View File

@ -64,7 +64,8 @@ class API::EventsController < API::ApiController
def event_params
event_preparams = params.required(:event).permit(:title, :description, :start_date, :start_time, :end_date, :end_time,
:amount, :reduced_amount, :nb_total_places, :availability_id,
:all_day, :recurrence, :recurrence_end_at, :category_ids, category_ids: [],
:all_day, :recurrence, :recurrence_end_at, :category_ids, :event_theme_ids,
:age_range_id, event_theme_ids: [], category_ids: [],
event_image_attributes: [:attachment], event_files_attributes: [:id, :attachment, :_destroy])
start_date = Time.zone.parse(event_preparams[:start_date])
end_date = Time.zone.parse(event_preparams[:end_date])

View File

@ -1,4 +1,4 @@
json.extract! event, :id, :title, :description
json.extract! event, :id, :title, :description, :age_range_id
json.event_image event.event_image.attachment_url if event.event_image
json.event_files_attributes event.event_files do |f|
json.id f.id
@ -10,6 +10,14 @@ json.categories event.categories do |c|
json.id c.id
json.name c.name
end
json.event_theme_ids event.event_theme_ids
json.event_themes event.event_themes do |e|
json.name e.name
end
json.age_range_id event.age_range_id
json.age_range do
json.name event.age_range.name
end if event.age_range
json.start_date event.availability.start_at
json.start_time event.availability.start_at
json.end_date event.availability.end_at
@ -28,3 +36,4 @@ json.amount (event.amount / 100.0) if event.amount
json.reduced_amount (event.reduced_amount / 100.0) if event.reduced_amount
json.nb_total_places event.nb_total_places
json.nb_free_places event.nb_free_places || event.nb_total_places

View File

@ -184,6 +184,8 @@ en:
standard_rate: "Standard rate"
0_=_free: "0 = free"
tickets_available: "Tickets available"
event_theme: "Event theme"
age_range: "Age range"
plan:
# subscription plan edition form

View File

@ -184,6 +184,8 @@ fr:
standard_rate: "Tarif standard"
0_=_free: "0 = gratuit"
tickets_available: "Places disponibles"
event_theme: "Thème de l'évènement"
age_range: "Tranche d'âge"
plan:
# formulaire d'édition d'une formule d'abonnement