Skip to content

Commit

Permalink
Merge pull request #41 from Roxayl/develop
Browse files Browse the repository at this point in the history
Historique modifs page pays, ville et organisation
  • Loading branch information
Roxayl authored Jan 14, 2024
2 parents b57b7fc + a6babfa commit d967c65
Show file tree
Hide file tree
Showing 39 changed files with 641 additions and 185 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,6 @@ jobs:
find ./.env -type f -exec sed -i '' -e "/^APP_BUILD=/s/=.*/=\'$BUILD_NUMBER\'/" {} \;
php artisan optimize:clear
php artisan migrate --force
php artisan monde:generate-htaccess
php artisan monde:regenerate-influences
php artisan up
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Notes de mise à jour

## [master](https://github.com/Roxayl/mondegc/compare/release-2.20...master)
## [master](https://github.com/Roxayl/mondegc/compare/release-2.21...master)

## [v2.20](https://github.com/Roxayl/mondegc/compare/release-2.18...release-2.19) - 2024-01-13
## [v2.21](https://github.com/Roxayl/mondegc/compare/release-2.20...release-2.21) - 2024-01-14

## [v2.20](https://github.com/Roxayl/mondegc/compare/release-2.19...release-2.20) - 2024-01-13

## [v2.19](https://github.com/Roxayl/mondegc/compare/release-2.18...release-2.19) - 2023-12-24

Expand Down
10 changes: 0 additions & 10 deletions app/Console/Commands/GenerateHtaccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ class GenerateHtaccess extends Command
protected $description = "Génère un fichier .htaccess au répertoire racine, "
. "selon la configuration de l'application";

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
Expand Down
10 changes: 0 additions & 10 deletions app/Console/Commands/InitializeDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ class InitializeDatabase extends Initializer
*/
protected $description = "Initialise la base de données en créant le schéma de la base et les données";

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
Expand Down
10 changes: 0 additions & 10 deletions app/Console/Commands/InitializeEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ class InitializeEnvironment extends Initializer
*/
protected $description = "Initialise l'application et les variables d'environnement";

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
Expand Down
10 changes: 0 additions & 10 deletions app/Console/Commands/InitializeTesting.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ class InitializeTesting extends Initializer
*/
protected $description = "Initialise l'environnement de test";

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
Expand Down
10 changes: 0 additions & 10 deletions app/Console/Commands/OverrideVendorFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ class OverrideVendorFiles extends Command
'app/Overrides/Searchable/SearchResult.php' => 'vendor/spatie/laravel-searchable/src/SearchResult.php'
];

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
Expand Down
45 changes: 45 additions & 0 deletions app/Console/Commands/RegenerateInfluences.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Roxayl\MondeGC\Console\Commands;

use Illuminate\Console\Command;
use Roxayl\MondeGC\Services\RegenerateInfluenceService;

class RegenerateInfluences extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'monde:regenerate-influences';

/**
* The console command description.
*
* @var string
*/
protected $description = "Régénère les influences générées par les entités influençables.";

/**
* Execute the console command.
*
* @param RegenerateInfluenceService $regenerateInfluenceService
* @return int
*/
public function handle(RegenerateInfluenceService $regenerateInfluenceService): int
{
try {
$this->line('Régénération des influences ('
. $regenerateInfluenceService->influenceCount() . ' influence(s) actuellement dans la base de données)...');
$regenerateInfluenceService->regenerate();
$this->info('Influences regénérées avec succès ('
. $regenerateInfluenceService->influenceCount() . ' influence(s) actuellement dans la base de données).');
}
catch (\Throwable $ex) {
$this->error("Une erreur s'est produite : " . $ex->getMessage());
return 1;
}
return 0;
}
}
27 changes: 7 additions & 20 deletions app/Http/Controllers/BackOfficeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
use Roxayl\MondeGC\Models\Contracts\Influencable;
use Roxayl\MondeGC\Models\Factories\InfluencableFactory;
use Roxayl\MondeGC\Models\Influence;
use Roxayl\MondeGC\Services\HelperService;
use Roxayl\MondeGC\Services\RegenerateInfluenceService;
use YlsIdeas\FeatureFlags\Facades\Features;

class BackOfficeController extends Controller
Expand All @@ -26,17 +23,18 @@ public function __construct()
}

/**
* @param RegenerateInfluenceService $regenerateInfluenceService
* @return View
*/
public function advancedParameters(): View
public function advancedParameters(RegenerateInfluenceService $regenerateInfluenceService): View
{
$cacheSize = HelperService::formatBytes(HelperService::directorySize(
storage_path('framework/cache/data')
));

$cacheEnabled = Features::accessible('cache');

$influenceTableSize = Influence::count();
$influenceTableSize = $regenerateInfluenceService->influenceCount();

return view('back-office.advanced-parameters', compact(
'cacheSize', 'cacheEnabled', 'influenceTableSize'
Expand All @@ -55,23 +53,12 @@ public function purgeCache(): RedirectResponse
}

/**
* @param InfluencableFactory $influencableFactory
* @param RegenerateInfluenceService $regenerateInfluenceService
* @return RedirectResponse
*/
public function regenerateInfluences(InfluencableFactory $influencableFactory): RedirectResponse
public function regenerateInfluences(RegenerateInfluenceService $regenerateInfluenceService): RedirectResponse
{
/** @var Influencable[] $influencables */
$influencables = $influencableFactory->listEnabled();

DB::transaction(function() use ($influencables) {
DB::table('influence')->delete();

foreach($influencables as $influencable) {
$influencable->generateInfluence();
}
});

cache()->flush();
$regenerateInfluenceService->regenerate();

return redirect()->route('back-office.advanced-parameters')
->with('message', 'success|Les influences ont été regénérées avec succès.');
Expand Down
28 changes: 15 additions & 13 deletions app/Http/Controllers/ChapterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Roxayl\MondeGC\Models\Chapter;
use Roxayl\MondeGC\Models\Roleplay;
use Roxayl\MondeGC\Services\StringBladeService;
use Roxayl\MondeGC\View\Components\Blocks\TextDiff;
use Roxayl\MondeGC\Services\VersionDiffService;

class ChapterController extends Controller
{
Expand Down Expand Up @@ -196,39 +196,41 @@ public function history(Chapter $chapter): View
$this->authorize('display', Chapter::class);

$firstChapter = $chapter->roleplay->chapters->first();
$versions = $chapter->versions()->latest('version_id')->paginate(15);
$versions = $chapter->versions()->latest('version_id')->paginate();
$canRevert = Gate::allows('revert', $chapter);
$title = 'Historique du chapitre ' . $chapter->order . ' : ' . $chapter->name;
$diffRoute = 'chapter.diff';
$breadcrumb = view('chapter.components.history-breadcrumb', compact('firstChapter', 'chapter'));

return view('chapter.history',
compact('chapter', 'firstChapter', 'versions', 'canRevert'));
return view(
'version.history',
compact('title', 'breadcrumb', 'chapter', 'firstChapter', 'versions', 'canRevert', 'diffRoute')
);
}

/**
* Compare deux versions d'un chapitre.
*
* @param VersionDiffService $diffService
* @param Version $version1
* @param Version|null $version2
* @return View
*/
public function diff(Version $version1, ?Version $version2 = null): View
public function diff(VersionDiffService $diffService, Version $version1, ?Version $version2 = null): View
{
$this->authorize('display', Chapter::class);

/** @var Chapter $model1 */
/** @var Chapter $model2 */
$model1 = $version1->getModel();
if($version2 === null) {
$model2 = new ($model1::class);
} else {
$model2 = $version2->getModel();
}

$nameDiffComponent = new TextDiff((string)$model2->name, $model1->name);
$summaryDiffComponent = new TextDiff((string)$model2->summary, $model1->summary);
$contentDiffComponent = new TextDiff((string)$model2->content, $model1->content);

$nameDiff = $nameDiffComponent->render();
$summaryDiff = $summaryDiffComponent->render();
$contentDiff = $contentDiffComponent->render();
$diffs = $diffService->generate($model1, $model2);

return view('chapter.diff', compact('nameDiff', 'summaryDiff', 'contentDiff'));
return view('version.diff', compact('diffs'));
}
}
46 changes: 46 additions & 0 deletions app/Http/Controllers/OrganisationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Str;
use Mpociot\Versionable\Version;
use Roxayl\MondeGC\Events\Organisation\TypeMigrated;
use Roxayl\MondeGC\Http\Requests\Organisation\MigrateType;
use Roxayl\MondeGC\Models\Communique;
use Roxayl\MondeGC\Models\Organisation;
use Roxayl\MondeGC\Models\OrganisationMember;
use Roxayl\MondeGC\Services\VersionDiffService;

class OrganisationController extends Controller
{
Expand Down Expand Up @@ -215,4 +217,48 @@ public function runMigration(MigrateType $request, int $id): RedirectResponse
->with('message', 'success|Votre organisation est devenue une '
. __("organisation.types.$organisation->type"));
}

/**
* @param Organisation $organisation
* @return \Illuminate\View\View
*/
public function history(Organisation $organisation): View
{
$versions = $organisation->versions()->latest('version_id')->paginate();
$canRevert = Gate::allows('revert', $organisation);
$title = 'Historique de l\'organisation ' . $organisation->name;
$diffRoute = 'organisation.diff';
$breadcrumb = view('organisation.components.history-breadcrumb', compact('organisation'));

return view(
'version.history',
compact('title', 'breadcrumb', 'versions', 'canRevert', 'diffRoute')
);
}

/**
* Compare deux versions d'une organisation.
*
* @param VersionDiffService $diffService
* @param Version $version1
* @param Version|null $version2
* @return View
*/
public function diff(VersionDiffService $diffService, Version $version1, ?Version $version2 = null): View
{
$this->authorize('viewAny', Organisation::class);

/** @var Organisation $model1 */
/** @var Organisation $model2 */
$model1 = $version1->getModel();
if($version2 === null) {
$model2 = new ($model1::class);
} else {
$model2 = $version2->getModel();
}

$diffs = $diffService->generate($model1, $model2);

return view('version.diff', compact('diffs'));
}
}
56 changes: 56 additions & 0 deletions app/Http/Controllers/PaysController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Roxayl\MondeGC\Http\Controllers;

use Illuminate\Support\Facades\Gate;
use Illuminate\View\View;
use Mpociot\Versionable\Version;
use Roxayl\MondeGC\Models\Pays;
use Roxayl\MondeGC\Services\VersionDiffService;

class PaysController extends Controller
{
/**
* @param Pays $pays
* @return View
*/
public function history(Pays $pays): View
{
$versions = $pays->versions()->latest('version_id')->paginate();
$canRevert = Gate::allows('revert', $pays);
$title = 'Historique du pays ' . $pays->ch_pay_nom;
$diffRoute = 'pays.diff';
$breadcrumb = view('pays.components.history-breadcrumb', compact('pays'));

return view(
'version.history',
compact('title', 'breadcrumb', 'versions', 'canRevert', 'diffRoute')
);
}

/**
* Compare deux versions d'un pays.
*
* @param VersionDiffService $diffService
* @param Version $version1
* @param Version|null $version2
* @return View
*/
public function diff(VersionDiffService $diffService, Version $version1, ?Version $version2 = null): View
{
$this->authorize('viewAny', Pays::class);

/** @var Pays $model1 */
/** @var Pays $model2 */
$model1 = $version1->getModel();
if($version2 === null) {
$model2 = new ($model1::class);
} else {
$model2 = $version2->getModel();
}

$diffs = $diffService->generate($model1, $model2);

return view('version.diff', compact('diffs'));
}
}
Loading

0 comments on commit d967c65

Please sign in to comment.