118 lines
7.2 KiB
PHP
118 lines
7.2 KiB
PHP
@extends('layouts.app')
|
|
@section('title', 'Campagnes — Signatures')
|
|
@section('content')
|
|
@php
|
|
$isAdmin = auth()->user()->hasRole('admin');
|
|
$tz = config('signature.timezone');
|
|
$badge = ['running' => 'ok', 'scheduled' => '', 'inactive' => 'warn', 'ended' => 'off'];
|
|
$variable = '{'.'{'.'{banniere}'.'}'.'}';
|
|
$period = fn ($d) => $d->timezone($tz)->format('d/m/Y H:i');
|
|
@endphp
|
|
<header class="page-head">
|
|
<div>
|
|
<h1>Campagnes</h1>
|
|
<p class="lead">
|
|
Une campagne ajoute une bannière sous la signature pendant une période, pour tous les agents ou pour certains groupes AD.
|
|
<strong>Une seule bannière par signature</strong> : si plusieurs campagnes en cours concernent un agent, celle dont la priorité
|
|
est la plus haute l'emporte (à égalité : la plus ancienne). La bannière n'apparaît que dans la signature complète,
|
|
pas dans la signature courte des réponses.
|
|
@unless ($isAdmin) Vous préparez les campagnes ; un administrateur les active. @endunless
|
|
</p>
|
|
</div>
|
|
<div class="page-actions">
|
|
<a class="btn" href="{{ route('admin.campaigns.create') }}"><x-icon name="plus" />Nouvelle campagne</a>
|
|
</div>
|
|
</header>
|
|
|
|
@if ($withoutBanner->isNotEmpty())
|
|
<div class="alert notice" role="note">
|
|
<x-icon name="triangle-alert" />
|
|
<div>Ces templates publiés ne contiennent pas <code>{{ $variable }}</code> : leurs agents ne verront aucune bannière.
|
|
<strong>{{ $withoutBanner->join(', ') }}</strong></div>
|
|
</div>
|
|
@endif
|
|
|
|
<div class="card card--flush">
|
|
<div class="table-wrap">
|
|
<table class="list">
|
|
<thead><tr><th>Bannière</th><th>Campagne</th><th>Période</th><th>Destinataires</th><th>Priorité</th><th>État</th><th class="right">{{ $isAdmin ? 'Active' : '' }}</th></tr></thead>
|
|
<tbody>
|
|
@forelse ($campaigns as $c)
|
|
@php
|
|
$status = $c->status();
|
|
$locked = $c->active && ! $isAdmin;
|
|
@endphp
|
|
<tr>
|
|
<td>
|
|
@if (in_array($c->id, $missing, true))
|
|
<span class="badge warn">image manquante</span>
|
|
<div class="muted">{{ $c->image_path }}</div>
|
|
@else
|
|
<img class="thumb" src="{{ asset('img/'.$c->image_path) }}" alt="{{ $c->alt_text }}" loading="lazy">
|
|
@endif
|
|
</td>
|
|
<td>
|
|
<a class="cell-title" href="{{ route('admin.campaigns.edit', $c) }}">{{ $c->name }}</a>
|
|
<div class="muted">
|
|
@if ($c->link_url)
|
|
<a href="{{ $c->link_url }}" target="_blank" rel="noopener" title="{{ $c->link_url }}">{{ \Illuminate\Support\Str::limit(preg_replace('#^https?://(www\.)?#', '', $c->link_url), 38) }}</a>
|
|
@else
|
|
Sans lien
|
|
@endif
|
|
</div>
|
|
</td>
|
|
<td class="nowrap">{{ $period($c->starts_at) }}<br><span class="muted">au</span> {{ $period($c->ends_at) }}</td>
|
|
<td style="min-width:130px;overflow-wrap:anywhere">{{ $c->groups->isEmpty() ? 'Tous les agents' : $c->groups->pluck('display_name')->join(', ') }}</td>
|
|
<td class="num">{{ $c->priority }}</td>
|
|
<td>
|
|
<span class="badge {{ $badge[$status] }}">{{ \App\Models\Campaign::STATUSES[$status] }}</span>
|
|
@if ($status === 'running')
|
|
<div class="muted">
|
|
@if (($reach[$c->id] ?? 0) > 0)
|
|
vue par {{ $reach[$c->id] }} agent{{ $reach[$c->id] > 1 ? 's' : '' }}
|
|
@else
|
|
aucun agent : masquée par une campagne plus prioritaire, ou groupes vides
|
|
@endif
|
|
</div>
|
|
@elseif ($status === 'inactive')
|
|
<div class="muted">{{ $isAdmin ? 'à activer' : 'en attente d\'un administrateur' }}</div>
|
|
@endif
|
|
</td>
|
|
<td class="cell-actions">
|
|
<a class="btn secondary small icon-only" href="{{ route('admin.campaigns.edit', $c) }}"
|
|
title="{{ $locked ? 'Voir' : 'Modifier' }}" aria-label="{{ $locked ? 'Voir' : 'Modifier' }} {{ $c->name }}">
|
|
<x-icon :name="$locked ? 'eye' : 'pencil'" :size="15" />
|
|
</a>
|
|
@if ($isAdmin)
|
|
@if ($status !== 'ended')
|
|
<form class="inline" method="post" action="{{ route('admin.campaigns.toggle', $c) }}">
|
|
@csrf
|
|
<button class="switch-btn" type="submit" role="switch" aria-checked="{{ $c->active ? 'true' : 'false' }}"
|
|
title="{{ $c->active ? 'Désactiver' : 'Activer' }}" aria-label="Campagne {{ $c->name }} active"></button>
|
|
</form>
|
|
@endif
|
|
<form class="inline" method="post" action="{{ route('admin.campaigns.destroy', $c) }}"
|
|
data-confirm="Supprimer la campagne « {{ $c->name }} » ? Les messages déjà envoyés conservent la bannière."
|
|
data-confirm-label="Supprimer" data-confirm-danger>
|
|
@csrf @method('DELETE')
|
|
<button class="btn danger small icon-only" type="submit" title="Supprimer" aria-label="Supprimer {{ $c->name }}"><x-icon name="trash-2" :size="15" /></button>
|
|
</form>
|
|
@endif
|
|
</td>
|
|
</tr>
|
|
@empty
|
|
<tr><td colspan="7">
|
|
<div class="empty">
|
|
<x-icon name="megaphone" :size="32" />
|
|
<p><strong>Aucune campagne</strong>Les signatures partent sans bannière. Créez une campagne pour en afficher une pendant une période donnée.</p>
|
|
<p><a class="btn" href="{{ route('admin.campaigns.create') }}"><x-icon name="plus" />Nouvelle campagne</a></p>
|
|
</div>
|
|
</td></tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div class="card-foot muted">Vérifiez la bannière reçue par un agent précis dans l'écran <a href="{{ route('admin.agents.index') }}">Agents</a>.</div>
|
|
</div>
|
|
@endsection
|