diff --git a/app/assets/javascripts/controllers/admin/events.coffee b/app/assets/javascripts/controllers/admin/events.coffee index d501f6a1b..242145c22 100644 --- a/app/assets/javascripts/controllers/admin/events.coffee +++ b/app/assets/javascripts/controllers/admin/events.coffee @@ -136,7 +136,8 @@ class EventsController ## # Controller used in the events listing page (admin view) ## -Application.Controllers.controller "AdminEventsController", ["$scope", "$state", 'Event', 'eventsPromise', ($scope, $state, Event, eventsPromise) -> +Application.Controllers.controller "AdminEventsController", ["$scope", "$state", 'Event', 'Category', 'eventsPromise', 'categoriesPromise' +, ($scope, $state, Event, Category, eventsPromise, categoriesPromise) -> @@ -151,6 +152,9 @@ Application.Controllers.controller "AdminEventsController", ["$scope", "$state", ## Current virtual page $scope.page = 2 + ## List of categories for the events + $scope.categories = categoriesPromise + ## # Adds a bucket of events to the bottom of the page, grouped by month ## @@ -161,6 +165,52 @@ Application.Controllers.controller "AdminEventsController", ["$scope", "$state", $scope.page += 1 + ## + # Saves a new categoty / Update an existing one to the server (form validation callback) + # @param data {Object} category name + # @param [data] {number} category id, in case of update + ## + $scope.saveCategory = (data, id) -> + if id? + Category.update {id: id}, data + else + Category.save data, (resp)-> + $scope.categories[$scope.categories.length-1].id = resp.id + + + + ## + # Deletes the category at the specified index + # @param index {number} category index in the $scope.categories array + ## + $scope.removeCategory = (index) -> + Category.delete $scope.categories[index] + $scope.categories.splice(index, 1) + + + + ## + # Creates a new empty entry in the $scope.categories array + ## + $scope.addCategory = -> + $scope.inserted = + name: '' + $scope.categories.push($scope.inserted) + + + + ## + # Removes the newly inserted but not saved category / Cancel the current category modification + # @param rowform {Object} see http://vitalets.github.io/angular-xeditable/ + # @param index {number} category index in the $scope.categories array + ## + $scope.cancelCategory = (rowform, index) -> + if $scope.categories[index].id? + rowform.$cancel() + else + $scope.categories.splice(index, 1) + + ### PRIVATE SCOPE ### diff --git a/app/assets/javascripts/controllers/main_nav.coffee.erb b/app/assets/javascripts/controllers/main_nav.coffee.erb index 5e5827cb8..e473c7ac3 100644 --- a/app/assets/javascripts/controllers/main_nav.coffee.erb +++ b/app/assets/javascripts/controllers/main_nav.coffee.erb @@ -73,7 +73,7 @@ Application.Controllers.controller "MainNavController", ["$scope", "$location", } { state: 'app.admin.events' - linkText: 'events_monitoring' + linkText: 'manage_the_events' linkIcon: 'tags' } { diff --git a/app/assets/javascripts/router.coffee.erb b/app/assets/javascripts/router.coffee.erb index 978705d54..a293b6985 100644 --- a/app/assets/javascripts/router.coffee.erb +++ b/app/assets/javascripts/router.coffee.erb @@ -534,6 +534,9 @@ angular.module('application.router', ['ui.router']). eventsPromise: ['Event', (Event)-> Event.query(page: 1).$promise ] + categoriesPromise: ['Category', (Category) -> + Category.query().$promise + ] translations: [ 'Translations', (Translations) -> Translations.query('app.admin.events').$promise ] diff --git a/app/assets/templates/admin/events/filters.html.erb b/app/assets/templates/admin/events/filters.html.erb new file mode 100644 index 000000000..e25108313 --- /dev/null +++ b/app/assets/templates/admin/events/filters.html.erb @@ -0,0 +1,41 @@ +
+

{{ 'categories' }}

+ + + + + + + + + + + + + + +
{{ 'name' }}
+ + {{ category.name }} + + + +
+ + +
+
+ + +
+
+ +
\ No newline at end of file diff --git a/app/assets/templates/admin/events/index.html.erb b/app/assets/templates/admin/events/index.html.erb index f7aa514d0..3d4ad5b5e 100644 --- a/app/assets/templates/admin/events/index.html.erb +++ b/app/assets/templates/admin/events/index.html.erb @@ -21,57 +21,66 @@
+ + -
- -
+
+ +
- - - - - - - - - - - - - - - -
{{ 'title' }}{{ 'dates' }}
- {{ event.title }} - - {{ 'from_DATE' | translate:{DATE:(event.start_date | amDateFormat:'LL')} }} {{ 'to_date' }} {{event.end_date | amDateFormat:'LL'}} -
- {{ 'all_day' }} - - {{ 'from_TIME' | translate:{TIME:(event.start_date | amDateFormat:'LT')} }} - {{ 'to_time' }} - {{event.end_date | amDateFormat:'LT'}} - -
-
- - + + + + + + + + + + + + + + + +
{{ 'title' }}{{ 'dates' }}
+ {{ event.title }} + + {{ 'from_DATE' | translate:{DATE:(event.start_date | amDateFormat:'LL')} }} {{ 'to_date' }} {{event.end_date | amDateFormat:'LL'}} +
+ {{ 'all_day' }} + + {{ 'from_TIME' | translate:{TIME:(event.start_date | amDateFormat:'LT')} }} + {{ 'to_time' }} + {{event.end_date | amDateFormat:'LT'}} + +
+
+ + +
+
+ +
-
-
+ + -
-
diff --git a/app/controllers/api/categories_controller.rb b/app/controllers/api/categories_controller.rb index 39419deb4..19941064a 100644 --- a/app/controllers/api/categories_controller.rb +++ b/app/controllers/api/categories_controller.rb @@ -1,5 +1,46 @@ class API::CategoriesController < API::ApiController + before_action :set_category, only: [:show, :update, :destroy] + def index + authorize Category @categories = Category.all end + + def show + end + + def create + authorize Category + @category = Category.new(category_params) + if @category.save + render :show, status: :created, location: @category + else + render json: @category.errors, status: :unprocessable_entity + end + end + + + def update + authorize Category + if @category.update(category_params) + render :show, status: :ok, location: @category + else + render json: @category.errors, status: :unprocessable_entity + end + end + + def destroy + authorize Category + @category.destroy + head :no_content + end + + private + def set_category + @category = Category.find(params[:id]) + end + + def category_params + params.require(:category).permit(:name) + end end diff --git a/app/policies/category_policy.rb b/app/policies/category_policy.rb new file mode 100644 index 000000000..cd29fbf7f --- /dev/null +++ b/app/policies/category_policy.rb @@ -0,0 +1,7 @@ +class CategoryPolicy < ApplicationPolicy + %w(index create update destroy show).each do |action| + define_method "#{action}?" do + user.is_admin? + end + end +end diff --git a/app/views/api/categories/show.json.jbuilder b/app/views/api/categories/show.json.jbuilder new file mode 100644 index 000000000..0501fe17e --- /dev/null +++ b/app/views/api/categories/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @category, :id, :name \ No newline at end of file diff --git a/config/locales/app.admin.en.yml b/config/locales/app.admin.en.yml index e6bed3057..3f58da90a 100644 --- a/config/locales/app.admin.en.yml +++ b/config/locales/app.admin.en.yml @@ -70,6 +70,8 @@ en: events: # events tracking and management + events_monitoring: "Events monitoring" + manage_filters: "Manage filters" fablab_events: "Fablab events" all_events: "All events" passed_events: "Passed events" @@ -77,6 +79,8 @@ en: from_DATE: "From {{DATE}}" # angular interpolation from_TIME: "From {{TIME}}" # angular interpolation view_reservations: "View reservations" + categories: "Categories" + add_a_category: "Add a category" events_new: # add a new event diff --git a/config/locales/app.admin.fr.yml b/config/locales/app.admin.fr.yml index 80ecdf162..a060fe0fc 100644 --- a/config/locales/app.admin.fr.yml +++ b/config/locales/app.admin.fr.yml @@ -70,6 +70,8 @@ fr: events: # gestion et suivi des stages et ateliers + events_monitoring: "Suivi des évènements" + manage_filters: "Gérer les filtres" fablab_events: "Les évènements du Fab Lab" all_events: "Tous les évènements" passed_events: "Les évènements déjà passés" @@ -77,6 +79,8 @@ fr: from_DATE: "Du {{DATE}}" # angular interpolation from_TIME: "De {{TIME}}" # angular interpolation view_reservations: "Consulter les réservations" + categories: "Catégories" + add_a_category: "Ajouter une catégorie" events_new: # ajouter un nouveau atelier/stage diff --git a/config/locales/app.public.en.yml b/config/locales/app.public.en.yml index 5f5e2f9c7..e1025026d 100644 --- a/config/locales/app.public.en.yml +++ b/config/locales/app.public.en.yml @@ -40,7 +40,7 @@ en: manage_the_users: "Manage the Users" manage_the_invoices: "Manage the invoices" subscriptions_and_prices: "Subscriptions and Prices" - events_monitoring: "Events monitoring" + manage_the_events: "Manage the events" manage_the_machines: "Manage the Machines" manage_the_projects_elements: "Manage the Projects Elements" statistics: "Statistics" diff --git a/config/locales/app.public.fr.yml b/config/locales/app.public.fr.yml index 4f57e4103..27256d0b0 100644 --- a/config/locales/app.public.fr.yml +++ b/config/locales/app.public.fr.yml @@ -40,7 +40,7 @@ fr: manage_the_users: "Gérer les utilisateurs" manage_the_invoices: "Gérer les factures" subscriptions_and_prices: "Abonnements & Tarifs" - events_monitoring: "Suivi des évènements" + manage_the_events: "Gérer les évènements" manage_the_machines: "Gérer les machines" manage_the_projects_elements: "Gérer les éléments projets" statistics: "Statistiques" diff --git a/config/routes.rb b/config/routes.rb index 1226d6dbb..a67dc9e38 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -87,7 +87,7 @@ Rails.application.routes.draw do # for admin resources :trainings resources :credits - resources :categories, only: [:index] + resources :categories resources :statistics, only: [:index] resources :custom_assets, only: [:show, :create, :update] resources :tags