mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-29 10:24:20 +01:00
(feat) display special style if a training override general settings
This commit is contained in:
parent
73a7f3bcbd
commit
2b42858229
@ -8,6 +8,7 @@ class API::TrainingsController < API::ApiController
|
|||||||
before_action :set_training, only: %i[update destroy]
|
before_action :set_training, only: %i[update destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@requested_attributes = params[:requested_attributes]
|
||||||
@trainings = TrainingService.list(params)
|
@trainings = TrainingService.list(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ import Select from 'react-select';
|
|||||||
import { SelectOption } from '../../models/select';
|
import { SelectOption } from '../../models/select';
|
||||||
import { CalendarBlank } from 'phosphor-react';
|
import { CalendarBlank } from 'phosphor-react';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import type { Training } from '../../models/training';
|
import type { Training, TrainingIndexFilter } from '../../models/training';
|
||||||
import type { Machine } from '../../models/machine';
|
import type { Machine } from '../../models/machine';
|
||||||
import TrainingAPI from '../../api/training';
|
import TrainingAPI from '../../api/training';
|
||||||
import MachineAPI from '../../api/machine';
|
import MachineAPI from '../../api/machine';
|
||||||
@ -63,7 +63,11 @@ export const Trainings: React.FC<TrainingsProps> = ({ onError, onSuccess }) => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
TrainingAPI.index(typeof filter === 'boolean' ? { disabled: filter } : {})
|
const trainingsFilters = Object.assign(
|
||||||
|
{ requested_attributes: ['override_settings'] },
|
||||||
|
(typeof filter === 'boolean') ? { disabled: filter } : {}
|
||||||
|
) as TrainingIndexFilter;
|
||||||
|
TrainingAPI.index(trainingsFilters)
|
||||||
.then(setTrainings)
|
.then(setTrainings)
|
||||||
.catch(onError);
|
.catch(onError);
|
||||||
}, [filter]);
|
}, [filter]);
|
||||||
@ -143,11 +147,8 @@ export const Trainings: React.FC<TrainingsProps> = ({ onError, onSuccess }) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='trainings-list'>
|
<div className='trainings-list'>
|
||||||
{/* map
|
|
||||||
ajouter la classe .is-override si l'item a au moins un réglage spécifique (différent des paramètres généraux)
|
|
||||||
*/}
|
|
||||||
{trainings.map(training => (
|
{trainings.map(training => (
|
||||||
<div className='trainings-list-item' key={training.id}>
|
<div className={`trainings-list-item ${training.override_settings ? 'is-override' : ''}`} key={training.id}>
|
||||||
<div className='name'>
|
<div className='name'>
|
||||||
<span>{t('app.admin.trainings.name')}</span>
|
<span>{t('app.admin.trainings.name')}</span>
|
||||||
<p>{training.name}</p>
|
<p>{training.name}</p>
|
||||||
|
@ -31,11 +31,12 @@ export interface Training {
|
|||||||
is_valid: boolean
|
is_valid: boolean
|
||||||
}>
|
}>
|
||||||
}>,
|
}>,
|
||||||
advanced_accounting_attributes?: AdvancedAccounting
|
advanced_accounting_attributes?: AdvancedAccounting,
|
||||||
|
override_settings?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TrainingIndexFilter extends ApiFilter {
|
export interface TrainingIndexFilter extends ApiFilter {
|
||||||
disabled?: boolean,
|
disabled?: boolean,
|
||||||
public_page?: boolean,
|
public_page?: boolean,
|
||||||
requested_attributes?: ['availabilities'],
|
requested_attributes?: ['availabilities' | 'override_settings'],
|
||||||
}
|
}
|
||||||
|
@ -30,49 +30,6 @@
|
|||||||
</uib-tab>
|
</uib-tab>
|
||||||
<uib-tab heading="{{ 'app.admin.trainings.all_trainings' | translate }}" index="0" class="manage-trainings">
|
<uib-tab heading="{{ 'app.admin.trainings.all_trainings' | translate }}" index="0" class="manage-trainings">
|
||||||
<trainings on-error="onError" on-success="onSuccess"></trainings>
|
<trainings on-error="onError" on-success="onSuccess"></trainings>
|
||||||
|
|
||||||
<div class="m-t m-b">
|
|
||||||
<button type="button" class="btn btn-warning" ui-sref="app.admin.trainings_new" ng-show="isAuthorized('admin')">
|
|
||||||
<i class="fa fa-plus m-r"></i>
|
|
||||||
<span translate>{{ 'app.admin.trainings.add_a_new_training' }}</span>
|
|
||||||
</button>
|
|
||||||
<div class="form-group pull-right filter-trainings">
|
|
||||||
<div class="input-group">
|
|
||||||
<span class="input-group-addon"><i class="fa fa-filter"></i></span>
|
|
||||||
<select ng-model="trainingFiltering" class="form-control">
|
|
||||||
<option ng-repeat="status in filterDisabled" value="{{status}}" translate>{{ 'app.admin.trainings.status_'+status }}</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<table class="table trainings-list">
|
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th style="width:20%" translate>{{ 'app.admin.trainings.name' }}</th>
|
|
||||||
<th ng-if="enableMachinesModule" style="width:40%" translate>{{ 'app.admin.trainings.associated_machines' }}</th>
|
|
||||||
<th style="width:20%" translate>{{ 'app.admin.trainings.capacity' }}</th>
|
|
||||||
<th style="width:20%"></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<tr ng-repeat="training in trainings | filterDisabled:trainingFiltering" ng-class="{'disabled-line' : training.disabled && trainingFiltering === 'all'}">
|
|
||||||
<td>{{ training.name }}</td>
|
|
||||||
<td ng-if="enableMachinesModule">{{ showMachines(training) }}</td>
|
|
||||||
<td>{{ training.nb_total_places }}</td>
|
|
||||||
<td>
|
|
||||||
<div class="buttons" ng-show="isAuthorized('admin')">
|
|
||||||
<button class="btn btn-default" ui-sref="app.admin.trainings_edit({id:training.id})">
|
|
||||||
<i class="fa fa-edit"></i> {{ 'app.shared.buttons.edit' | translate }}
|
|
||||||
</button>
|
|
||||||
<button class="btn btn-danger" ng-click="removeTraining($index, training)">
|
|
||||||
<i class="fa fa-trash-o"></i>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</uib-tab>
|
</uib-tab>
|
||||||
|
|
||||||
<uib-tab heading="{{ 'app.admin.trainings.trainings_monitoring' | translate }}" class="post-tracking" index="2">
|
<uib-tab heading="{{ 'app.admin.trainings.trainings_monitoring' | translate }}" class="post-tracking" index="2">
|
||||||
|
@ -64,6 +64,12 @@ class Training < ApplicationRecord
|
|||||||
reservations.empty?
|
reservations.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def override_settings?
|
||||||
|
Trainings::AutoCancelService.override_settings?(self) ||
|
||||||
|
Trainings::InvalidationService.override_settings?(self) ||
|
||||||
|
Trainings::AuthorizationService.override_settings?(self)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def create_trainings_pricings
|
def create_trainings_pricings
|
||||||
|
@ -42,5 +42,12 @@ class Trainings::AuthorizationService
|
|||||||
params[:authorization_period] = duration.value unless duration.nil?
|
params[:authorization_period] = duration.value unless duration.nil?
|
||||||
training.update(params)
|
training.update(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @param training [Training]
|
||||||
|
# @return [Boolean]
|
||||||
|
def override_settings?(training)
|
||||||
|
training.authorization.to_s != Setting.find_by(name: 'trainings_authorization_validity').value.to_s ||
|
||||||
|
training.authorization_period.to_s != Setting.find_by(name: 'trainings_authorization_validity_duration').value.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -59,6 +59,14 @@ class Trainings::AutoCancelService
|
|||||||
training.update(params)
|
training.update(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @param training [Training]
|
||||||
|
# @return [Boolean]
|
||||||
|
def override_settings?(training)
|
||||||
|
training.auto_cancel.to_s != Setting.find_by(name: 'trainings_auto_cancel').value.to_s ||
|
||||||
|
training.auto_cancel_threshold.to_s != Setting.find_by(name: 'trainings_auto_cancel_threshold').value.to_s ||
|
||||||
|
training.auto_cancel_deadline.to_s != Setting.find_by(name: 'trainings_auto_cancel_deadline').value.to_s
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# @param reservation [Reservation]
|
# @param reservation [Reservation]
|
||||||
|
@ -47,5 +47,12 @@ class Trainings::InvalidationService
|
|||||||
params[:invalidation_period] = duration.value unless duration.nil?
|
params[:invalidation_period] = duration.value unless duration.nil?
|
||||||
training.update(params)
|
training.update(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# @param training [Training]
|
||||||
|
# @return [Boolean]
|
||||||
|
def override_settings?(training)
|
||||||
|
training.invalidation.to_s != Setting.find_by(name: 'trainings_invalidation_rule').value.to_s ||
|
||||||
|
training.invalidation_period.to_s != Setting.find_by(name: 'trainings_invalidation_rule_period').value.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,4 +3,5 @@
|
|||||||
json.array!(@trainings) do |training|
|
json.array!(@trainings) do |training|
|
||||||
json.partial! 'api/trainings/training', training: training
|
json.partial! 'api/trainings/training', training: training
|
||||||
json.plan_ids training.plan_ids if current_user&.admin?
|
json.plan_ids training.plan_ids if current_user&.admin?
|
||||||
|
json.override_settings training.override_settings? if attribute_requested?(@requested_attributes, 'override_settings')
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user