initial commit

This commit is contained in:
2024-07-28 17:57:30 +02:00
commit f21cb97a1b
25 changed files with 1286 additions and 0 deletions

9
lib/AppConstants.php Normal file
View File

@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
namespace OCA\PrideFlags;
abstract class AppConstants {
public const APP_ID = 'pride_flags';
}

View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace OCA\PrideFlags\AppInfo;
use OCA\PrideFlags\AppConstants;
use OCP\Util;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\IConfig;
class Application extends App implements IBootstrap {
const APP_ID = AppConstants::APP_ID;
public function __construct(array $urlParams = []) {
parent::__construct(AppConstants::APP_ID, $urlParams);
}
public function register(IRegistrationContext $ctx): void {
$config = \OC::$server->get(IConfig::class);
}
public function boot(IBootContext $ctx): void {
Util::addStyle(AppConstants::APP_ID, 'pride');
Util::addScript(AppConstants::APP_ID, 'pride');
}
}

View File

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace OCA\PrideFlags\Controller;
use OCA\PrideFlags\Settings\AppSettings;
use Closure;
use OCP\IRequest;
use OCP\IConfig;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
class SettingsController extends Controller {
public function __construct($appName, IRequest $request, private AppSettings $appSettings) {
parent::__construct($appName, $request);
}
#[NoAdminRequired]
#[NoCSRFRequired]
public function get(): JSONResponse {
return $this->makeJSONResponse(fn () => $this->appSettings->getAll());
}
#[NoAdminRequired]
public function set(string $folderVariant, string $buttonVariant): JSONResponse {
$this->appSettings->set($folderVariant, $buttonVariant);
return $this->makeJSONResponse(fn () => $this->appSettings->getAll());
}
protected function makeJSONResponse(Closure $closure): JSONResponse {
try {
return new JSONResponse($closure(), HTTP::STATUS_OK);
} catch (Exception $e) {
return new JSONResponse(['message' => $e->getMessage()], HTTP::INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -0,0 +1,34 @@
<?
namespace OCA\PrideFlags\Settings;
use OCA\PrideFlags\AppConstants;
use OCP\IConfig;
class AppSettings {
public const FOLDER_VARIANT = 'folderVariant';
public const BUTTON_VARIANT = 'buttonVariant';
public function __construct(private IConfig $config) {
}
public function getStringSetting(string $key, string $default = ''): string {
return $this->config->getAppValue(AppConstants::APP_ID, $key) ?: $default;
}
public function setStringSetting(string $key, string $value): void {
$this->config->setAppValue(AppConstants::APP_ID, $key, $value);
}
public function getAll(): array {
return [
AppSettings::FOLDER_VARIANT => $this->getStringSetting(AppSettings::FOLDER_VARIANT, 'pride'),
AppSettings::BUTTON_VARIANT => $this->getStringSetting(AppSettings::BUTTON_VARIANT, 'trans'),
];
}
public function set($folder, $button): void {
$this->setStringSetting(AppSettings::FOLDER_VARIANT, $folder);
$this->setStringSetting(AppSettings::BUTTON_VARIANT, $button);
}
}

View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace OCA\PrideFlags\Settings;
use OCA\PrideFlags\AppConstants;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Settings\IIConSection;
class PersonalSection implements IIconSection {
public function __construct(private IL10N $l10n, private IURLGenerator $urlGenerator) {}
public function getID(): string {
return AppConstants::APP_ID;
}
public function getName(): string {
return 'Pride';
}
public function getPriority(): int {
return 100;
}
public function getIcon(): string {
return $this->urlGenerator->imagePath('core', 'actions/settings-dark.svg');
}
}

View File

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace OCA\PrideFlags\Settings;
use OCA\PrideFlags\AppConstants;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Settings\ISettings;
use OCP\Util;
class PersonalSettings implements ISettings {
public function getForm(): TemplateResponse {
Util::addScript(AppConstants::APP_ID, 'pride-settings');
return new TemplateResponse(AppConstants::APP_ID, 'settings', []);
}
public function getSection(): string {
return AppConstants::APP_ID;
}
public function getPriority(): int {
return 50;
}
}