mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-28 09:24:24 +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)
|
||||
##
|
||||
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 ###
|
||||
|
||||
|
@ -73,7 +73,7 @@ Application.Controllers.controller "MainNavController", ["$scope", "$location",
|
||||
}
|
||||
{
|
||||
state: 'app.admin.events'
|
||||
linkText: 'events_monitoring'
|
||||
linkText: 'manage_the_events'
|
||||
linkIcon: 'tags'
|
||||
}
|
||||
{
|
||||
|
@ -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
|
||||
]
|
||||
|
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,57 +21,66 @@
|
||||
<section class="m-lg">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<uib-tabset justified="true">
|
||||
<uib-tab heading="{{ 'events_monitoring' | translate }}">
|
||||
|
||||
<div class="col-md-6 m-b">
|
||||
<select ng-model="selectedTimezone" class="form-control">
|
||||
<option value="" translate>{{ 'all_events' }}</option>
|
||||
<option value="passed" translate>{{ 'passed_events' }}</option>
|
||||
<option value="future" translate>{{ 'events_to_come' }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-6 m-b m-t">
|
||||
<select ng-model="selectedTimezone" class="form-control">
|
||||
<option value="" translate>{{ 'all_events' }}</option>
|
||||
<option value="passed" translate>{{ 'passed_events' }}</option>
|
||||
<option value="future" translate>{{ 'events_to_come' }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:30%" translate>{{ 'title' }}</th>
|
||||
<th style="width:30%" translate>{{ 'dates' }}</th>
|
||||
<th style="width:40%"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="event in filtered = (events | eventsReservationsFilter:selectedTimezone)">
|
||||
<td>
|
||||
<a ui-sref="app.public.events_show({id: event.id})">{{ event.title }} </a>
|
||||
</td>
|
||||
<td>
|
||||
<span> {{ 'from_DATE' | translate:{DATE:(event.start_date | amDateFormat:'LL')} }} <span class="text-sm font-thin" translate>{{ 'to_date' }}</span> {{event.end_date | amDateFormat:'LL'}}</span>
|
||||
<br/>
|
||||
<span ng-if="event.all_day == 'true'" translate>{{ 'all_day' }}</span>
|
||||
<span ng-if="event.all_day == 'false'">
|
||||
{{ 'from_TIME' | translate:{TIME:(event.start_date | amDateFormat:'LT')} }}
|
||||
<span class="text-sm font-thin" translate>{{ 'to_time' }}</span>
|
||||
{{event.end_date | amDateFormat:'LT'}}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="buttons">
|
||||
<button class="btn btn-default" ui-sref="app.admin.event_reservations({id: event.id})">
|
||||
<i class="fa fa-bookmark"></i> {{ 'view_reservations' | translate }}
|
||||
</button>
|
||||
<button class="btn btn-default" ui-sref="app.admin.events_edit({id: event.id})">
|
||||
<i class="fa fa-edit"></i> {{ 'edit' | translate }}
|
||||
</button>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width:30%" translate>{{ 'title' }}</th>
|
||||
<th style="width:30%" translate>{{ 'dates' }}</th>
|
||||
<th style="width:40%"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="event in filtered = (events | eventsReservationsFilter:selectedTimezone)">
|
||||
<td>
|
||||
<a ui-sref="app.public.events_show({id: event.id})">{{ event.title }} </a>
|
||||
</td>
|
||||
<td>
|
||||
<span> {{ 'from_DATE' | translate:{DATE:(event.start_date | amDateFormat:'LL')} }} <span class="text-sm font-thin" translate>{{ 'to_date' }}</span> {{event.end_date | amDateFormat:'LL'}}</span>
|
||||
<br/>
|
||||
<span ng-if="event.all_day == 'true'" translate>{{ 'all_day' }}</span>
|
||||
<span ng-if="event.all_day == 'false'">
|
||||
{{ 'from_TIME' | translate:{TIME:(event.start_date | amDateFormat:'LT')} }}
|
||||
<span class="text-sm font-thin" translate>{{ 'to_time' }}</span>
|
||||
{{event.end_date | amDateFormat:'LT'}}
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="buttons">
|
||||
<button class="btn btn-default" ui-sref="app.admin.event_reservations({id: event.id})">
|
||||
<i class="fa fa-bookmark"></i> {{ 'view_reservations' | translate }}
|
||||
</button>
|
||||
<button class="btn btn-default" ui-sref="app.admin.events_edit({id: event.id})">
|
||||
<i class="fa fa-edit"></i> {{ 'edit' | translate }}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12 text-center">
|
||||
<a class="btn btn-warning" ng-click="loadMoreEvents()" ng-if="paginateActive" translate>{{ 'load_the_next_events' }}</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</uib-tab>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12 text-center">
|
||||
<a class="btn btn-warning" ng-click="loadMoreEvents()" ng-if="paginateActive" translate>{{ 'load_the_next_events' }}</a>
|
||||
|
||||
<uib-tab heading="{{ 'manage_filters' | translate }}">
|
||||
<ng-include src="'<%= asset_path 'admin/events/filters.html' %>'"></ng-include>
|
||||
</uib-tab>
|
||||
</uib-tabset>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
@ -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
|
||||
|
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 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
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user