mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-29 10:24:20 +01:00
[feature] manage events categories
This commit is contained in:
parent
cbbd697d38
commit
9adc219edb
@ -136,7 +136,8 @@ class EventsController
|
|||||||
##
|
##
|
||||||
# Controller used in the events listing page (admin view)
|
# 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
|
## Current virtual page
|
||||||
$scope.page = 2
|
$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
|
# 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
|
$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 ###
|
### PRIVATE SCOPE ###
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ Application.Controllers.controller "MainNavController", ["$scope", "$location",
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
state: 'app.admin.events'
|
state: 'app.admin.events'
|
||||||
linkText: 'events_monitoring'
|
linkText: 'manage_the_events'
|
||||||
linkIcon: 'tags'
|
linkIcon: 'tags'
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
@ -534,6 +534,9 @@ angular.module('application.router', ['ui.router']).
|
|||||||
eventsPromise: ['Event', (Event)->
|
eventsPromise: ['Event', (Event)->
|
||||||
Event.query(page: 1).$promise
|
Event.query(page: 1).$promise
|
||||||
]
|
]
|
||||||
|
categoriesPromise: ['Category', (Category) ->
|
||||||
|
Category.query().$promise
|
||||||
|
]
|
||||||
translations: [ 'Translations', (Translations) ->
|
translations: [ 'Translations', (Translations) ->
|
||||||
Translations.query('app.admin.events').$promise
|
Translations.query('app.admin.events').$promise
|
||||||
]
|
]
|
||||||
|
41
app/assets/templates/admin/events/filters.html.erb
Normal file
41
app/assets/templates/admin/events/filters.html.erb
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<div class="m-t">
|
||||||
|
<h3 translate>{{ 'categories' }}</h3>
|
||||||
|
<button type="button" class="btn btn-warning m-b m-t" ng-click="addCategory()" translate>{{ 'add_a_category' }}</button>
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th style="width:80%" translate>{{ 'name' }}</th>
|
||||||
|
<th style="width:20%"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr ng-repeat="category in categories">
|
||||||
|
<td>
|
||||||
|
<span editable-text="category.name" e-cols="100" e-name="name" e-form="rowform" e-required>
|
||||||
|
{{ category.name }}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<!-- form -->
|
||||||
|
<form editable-form name="rowform" onbeforesave="saveCategory($data, category.id)" ng-show="rowform.$visible" class="form-buttons form-inline" shown="inserted == category">
|
||||||
|
<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="cancelCategory(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="removeCategory($index)">
|
||||||
|
<i class="fa fa-trash-o"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
</div>
|
@ -21,8 +21,10 @@
|
|||||||
<section class="m-lg">
|
<section class="m-lg">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
|
<uib-tabset justified="true">
|
||||||
|
<uib-tab heading="{{ 'events_monitoring' | translate }}">
|
||||||
|
|
||||||
<div class="col-md-6 m-b">
|
<div class="col-md-6 m-b m-t">
|
||||||
<select ng-model="selectedTimezone" class="form-control">
|
<select ng-model="selectedTimezone" class="form-control">
|
||||||
<option value="" translate>{{ 'all_events' }}</option>
|
<option value="" translate>{{ 'all_events' }}</option>
|
||||||
<option value="passed" translate>{{ 'passed_events' }}</option>
|
<option value="passed" translate>{{ 'passed_events' }}</option>
|
||||||
@ -66,14 +68,21 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-lg-12 text-center">
|
<div class="col-lg-12 text-center">
|
||||||
<a class="btn btn-warning" ng-click="loadMoreEvents()" ng-if="paginateActive" translate>{{ 'load_the_next_events' }}</a>
|
<a class="btn btn-warning" ng-click="loadMoreEvents()" ng-if="paginateActive" translate>{{ 'load_the_next_events' }}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</uib-tab>
|
||||||
|
|
||||||
|
|
||||||
|
<uib-tab heading="{{ 'manage_filters' | translate }}">
|
||||||
|
<ng-include src="'<%= asset_path 'admin/events/filters.html' %>'"></ng-include>
|
||||||
|
</uib-tab>
|
||||||
|
</uib-tabset>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
@ -1,5 +1,46 @@
|
|||||||
class API::CategoriesController < API::ApiController
|
class API::CategoriesController < API::ApiController
|
||||||
|
before_action :set_category, only: [:show, :update, :destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
authorize Category
|
||||||
@categories = Category.all
|
@categories = Category.all
|
||||||
end
|
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
|
end
|
||||||
|
7
app/policies/category_policy.rb
Normal file
7
app/policies/category_policy.rb
Normal file
@ -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
|
1
app/views/api/categories/show.json.jbuilder
Normal file
1
app/views/api/categories/show.json.jbuilder
Normal file
@ -0,0 +1 @@
|
|||||||
|
json.extract! @category, :id, :name
|
@ -70,6 +70,8 @@ en:
|
|||||||
|
|
||||||
events:
|
events:
|
||||||
# events tracking and management
|
# events tracking and management
|
||||||
|
events_monitoring: "Events monitoring"
|
||||||
|
manage_filters: "Manage filters"
|
||||||
fablab_events: "Fablab events"
|
fablab_events: "Fablab events"
|
||||||
all_events: "All events"
|
all_events: "All events"
|
||||||
passed_events: "Passed events"
|
passed_events: "Passed events"
|
||||||
@ -77,6 +79,8 @@ en:
|
|||||||
from_DATE: "From {{DATE}}" # angular interpolation
|
from_DATE: "From {{DATE}}" # angular interpolation
|
||||||
from_TIME: "From {{TIME}}" # angular interpolation
|
from_TIME: "From {{TIME}}" # angular interpolation
|
||||||
view_reservations: "View reservations"
|
view_reservations: "View reservations"
|
||||||
|
categories: "Categories"
|
||||||
|
add_a_category: "Add a category"
|
||||||
|
|
||||||
events_new:
|
events_new:
|
||||||
# add a new event
|
# add a new event
|
||||||
|
@ -70,6 +70,8 @@ fr:
|
|||||||
|
|
||||||
events:
|
events:
|
||||||
# gestion et suivi des stages et ateliers
|
# 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"
|
fablab_events: "Les évènements du Fab Lab"
|
||||||
all_events: "Tous les évènements"
|
all_events: "Tous les évènements"
|
||||||
passed_events: "Les évènements déjà passés"
|
passed_events: "Les évènements déjà passés"
|
||||||
@ -77,6 +79,8 @@ fr:
|
|||||||
from_DATE: "Du {{DATE}}" # angular interpolation
|
from_DATE: "Du {{DATE}}" # angular interpolation
|
||||||
from_TIME: "De {{TIME}}" # angular interpolation
|
from_TIME: "De {{TIME}}" # angular interpolation
|
||||||
view_reservations: "Consulter les réservations"
|
view_reservations: "Consulter les réservations"
|
||||||
|
categories: "Catégories"
|
||||||
|
add_a_category: "Ajouter une catégorie"
|
||||||
|
|
||||||
events_new:
|
events_new:
|
||||||
# ajouter un nouveau atelier/stage
|
# ajouter un nouveau atelier/stage
|
||||||
|
@ -40,7 +40,7 @@ en:
|
|||||||
manage_the_users: "Manage the Users"
|
manage_the_users: "Manage the Users"
|
||||||
manage_the_invoices: "Manage the invoices"
|
manage_the_invoices: "Manage the invoices"
|
||||||
subscriptions_and_prices: "Subscriptions and Prices"
|
subscriptions_and_prices: "Subscriptions and Prices"
|
||||||
events_monitoring: "Events monitoring"
|
manage_the_events: "Manage the events"
|
||||||
manage_the_machines: "Manage the Machines"
|
manage_the_machines: "Manage the Machines"
|
||||||
manage_the_projects_elements: "Manage the Projects Elements"
|
manage_the_projects_elements: "Manage the Projects Elements"
|
||||||
statistics: "Statistics"
|
statistics: "Statistics"
|
||||||
|
@ -40,7 +40,7 @@ fr:
|
|||||||
manage_the_users: "Gérer les utilisateurs"
|
manage_the_users: "Gérer les utilisateurs"
|
||||||
manage_the_invoices: "Gérer les factures"
|
manage_the_invoices: "Gérer les factures"
|
||||||
subscriptions_and_prices: "Abonnements & Tarifs"
|
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_machines: "Gérer les machines"
|
||||||
manage_the_projects_elements: "Gérer les éléments projets"
|
manage_the_projects_elements: "Gérer les éléments projets"
|
||||||
statistics: "Statistiques"
|
statistics: "Statistiques"
|
||||||
|
@ -87,7 +87,7 @@ Rails.application.routes.draw do
|
|||||||
# for admin
|
# for admin
|
||||||
resources :trainings
|
resources :trainings
|
||||||
resources :credits
|
resources :credits
|
||||||
resources :categories, only: [:index]
|
resources :categories
|
||||||
resources :statistics, only: [:index]
|
resources :statistics, only: [:index]
|
||||||
resources :custom_assets, only: [:show, :create, :update]
|
resources :custom_assets, only: [:show, :create, :update]
|
||||||
resources :tags
|
resources :tags
|
||||||
|
Loading…
Reference in New Issue
Block a user