This commit is contained in:
deploy-bot committed 2026-12-06 12:23:34 +00:00
commit d94473aff6
305 files changed
+22017

No files matched your search

+189
View File
@@ -0,0 +1,189 @@
<?php
namespace IriksIT\Manager\Modules\IriksIT;
use IriksIT\Manager\Modules\BaseModule;
use IriksIT\Manager\Modules\Costs\CostsModule;
use IriksIT\Manager\Modules\Numbers\NumbersModule;
use IriksIT\Manager\Modules\Support\SupportModule;
use IriksIT\Manager\Modules\Updates\UpdatesModule;
use IriksIT\Manager\Support\IriksStorage\Client;
use IriksIT\Manager\Support\ModuleRegistry;
/**
* Iriks-IT (ADR-0017): what a customer of a project that Iriks-IT builds and hosts gets to see, for clarity and transparency. One module with
* four parts (what it cost, the numbers in plain words, the updates per version, and help), and one option: storage at Iriks-IT.
*
* It has one switch. When it is off, the heading "Iriks-IT" is gone from the menu, and so are its routes, rights and screens; its tables stay
* (ADR-0004). The parts are the modules that were separate before v0.10.0 (`CostsModule`, `NumbersModule`, `UpdatesModule`, `SupportModule`); they
* are not modules of their own any more, and a site that still lists them gets this module instead (see `ModuleRegistry`).
*
* Which parts are on: a part is on when `manager.iriksit.parts.<part>` says so, else when the old switch `manager.modules.<part>` says so. When
* nothing says anything about any part, every part is on (help shows only where an API account is filled in), so switching the module on shows the lot.
*/
class IriksItModule extends BaseModule
{
/** The parts, by name: the class that knows its screens. */
public const PARTS = [
'costs' => CostsModule::class,
'numbers' => NumbersModule::class,
'updates' => UpdatesModule::class,
'support' => SupportModule::class,
];
/** @var array<string, BaseModule>|null */
private ?array $built = null;
public function key(): string
{
return 'iriksit';
}
public function label(): string
{
return 'Iriks-IT';
}
/** On by default for a site that already used one of the parts, or that has an API account (it can then ask for help). */
public function enabledByDefault(): bool
{
foreach (array_keys(self::PARTS) as $part) {
if (self::said($part) === true) {
return true;
}
}
return self::accountFilledIn();
}
/** Whether the IriksIT API account of this site is filled in. */
public static function accountFilledIn(): bool
{
return (new Client((array) config('manager.media.iriksit', [])))->isConfigured();
}
/** What the site says about one part: true, false, or null when it says nothing. */
public static function said(string $part): ?bool
{
$value = config('manager.iriksit.parts.'.$part) ?? config('manager.modules.'.$part);
return $value === null ? null : filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
/** Whether a part is on, when the module itself is. */
public static function partOn(string $part): bool
{
if (! isset(self::PARTS[$part])) {
return false;
}
$said = self::said($part);
if ($said !== null) {
return $said;
}
// Help was on unless a site said no; it shows only where an account is filled in.
if ($part === 'support') {
return true;
}
// Nothing is said about any part: all of them are on. Something is said about another one: this one is left out, as it always was.
return array_filter(array_keys(self::PARTS), fn (string $other) => self::said($other) !== null) === [];
}
/**
* The parts that are on. The numbers need the statistics (they are its plain-words view), so without them that part is left out.
*
* @return array<string, BaseModule>
*/
public function parts(): array
{
if ($this->built === null) {
$this->built = [];
foreach (self::PARTS as $name => $class) {
$on = self::partOn($name) && ($name !== 'numbers' || app(ModuleRegistry::class)->enabled('statistics'));
$on && $this->built[$name] = new $class;
}
}
return $this->built;
}
public function tables(): array
{
return $this->merge('tables');
}
public function permissions(): array
{
return $this->merge('permissions');
}
public function navigation(): array
{
return $this->merge('navigation');
}
public function commands(): array
{
return $this->merge('commands');
}
public function tutorial(): array
{
return $this->merge('tutorial');
}
public function actions(): array
{
return $this->mergeKeyed('actions');
}
public function views(): array
{
return $this->mergeKeyed('views');
}
public function boot(): void
{
foreach ($this->parts() as $part) {
$part->boot();
}
}
/**
* What a site may set about this module on the settings screen: which parts are on, and the account at the IriksIT API that serves the help
* and the storage. Only there while the module is on.
*
* @return array<string, array<string, mixed>>
*/
public function settings(): array
{
$parts = [];
foreach (['costs' => 'What it cost', 'numbers' => 'The numbers in plain words', 'updates' => 'Updates per version', 'support' => 'Help'] as $part => $label) {
$parts['manager.iriksit.parts.'.$part] = ['label' => $label, 'type' => 'toggle', 'group' => 'Iriks-IT', 'env' => 'MANAGER_'.strtoupper($part)];
}
return [
...$parts,
'manager.media.iriksit.url' => ['label' => 'IriksIT API: address', 'type' => 'url', 'group' => 'IriksIT API', 'sensitive' => true, 'help' => 'With its version, for example https://api.iriks-it.nl/v1', 'env' => 'MANAGER_IRIKSIT_URL'],
'manager.media.iriksit.email' => ['label' => 'IriksIT API: account', 'type' => 'text', 'group' => 'IriksIT API', 'sensitive' => true, 'env' => 'MANAGER_IRIKSIT_EMAIL'],
'manager.media.iriksit.password' => ['label' => 'IriksIT API: password', 'type' => 'secret', 'group' => 'IriksIT API', 'env' => 'MANAGER_IRIKSIT_PASSWORD'],
];
}
/** @return list<mixed> */
private function merge(string $method): array
{
return array_values(array_merge(...array_map(fn (BaseModule $part) => $part->{$method}(), array_values($this->parts())) ?: [[]]));
}
/** @return array<string, mixed> */
private function mergeKeyed(string $method): array
{
return array_merge(...array_map(fn (BaseModule $part) => $part->{$method}(), array_values($this->parts())) ?: [[]]);
}
}
@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use IriksIT\Manager\Support\Names;
use IriksIT\Manager\Support\Tables;
return new class extends Migration
{
public function up(): void
{
Tables::create(Names::table('work_costs'), function (Blueprint $table) {
$table->id();
// What makes a row the row it is: the day, the model and the tokens (see Support\Costs\Ledger).
$table->string('fingerprint', 64)->unique();
$table->string('date', 10);
$table->string('name');
$table->string('version', 40)->nullable();
$table->string('model', 80);
$table->decimal('usd', 12, 4);
$table->decimal('eur', 12, 2);
$table->decimal('usd_per_eur', 10, 4);
$table->dateTime('priced_at');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists(Names::table('work_costs'));
}
};
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use IriksIT\Manager\Support\Names;
use IriksIT\Manager\Support\Tables;
return new class extends Migration
{
public function up(): void
{
Tables::create(Names::table('support_tickets'), function (Blueprint $table) {
$table->id();
// The number the API gave, like IT-2026-00042.
$table->string('number', 40)->unique();
// The account that sent it: it sees its own tickets.
$table->unsignedBigInteger('user_id')->nullable()->index();
$table->string('subject', 150);
$table->string('kind', 20)->default('question');
$table->string('status', 20)->default('open');
$table->string('last_message_from', 10)->nullable();
$table->unsignedInteger('message_count')->default(1);
$table->dateTime('last_message_at')->nullable();
// What the API said the last time (its own clock), and when the sender last opened the ticket.
$table->dateTime('remote_updated_at')->nullable();
$table->dateTime('seen_at')->nullable();
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists(Names::table('support_tickets'));
}
};
+10
View File
@@ -0,0 +1,10 @@
<?php
use IriksIT\Manager\Support\ModuleRegistry;
/** The screens of the Iriks-IT module: those of the parts that are on (see IriksItModule). */
foreach (app(ModuleRegistry::class)->all()['iriksit']->parts() as $part) {
if ($part->routes() !== null) {
require $part->routes();
}
}