initial commit
This commit is contained in:
commit
873f5edfd2
21
appinfo/info.xml
Normal file
21
appinfo/info.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0"?>
|
||||
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
|
||||
<id>pride_flags</id>
|
||||
<name>Pride Flags</name>
|
||||
<summary>Add pride flags to your nextcloud</summary>
|
||||
<description><![CDATA[Diversity and inclusion are what makes the world worth living in! Let's show some pride!]]></description>
|
||||
<version>0.1.2</version>
|
||||
<licence>cnvpl</licence>
|
||||
<author mail="" homepage="https://github.com/finallycoffee/nextcloud-pride"></author>
|
||||
<namespace>PrideFlags</namespace>
|
||||
<category>customization</category>
|
||||
<bugs>https://github.com/finallycoffee/nextcloud-pride/issues</bugs>
|
||||
<dependencies>
|
||||
<nextcloud min-version="26" max-version="28"/>
|
||||
</dependencies>
|
||||
<settings>
|
||||
<personal-section>OCA\PrideFlags\Settings\PersonalSection</personal-section>
|
||||
<personal>OCA\PrideFlags\Settings\PersonalSettings</personal>
|
||||
</settings>
|
||||
</info>
|
8
appinfo/routes.php
Normal file
8
appinfo/routes.php
Normal file
@ -0,0 +1,8 @@
|
||||
<?
|
||||
|
||||
return [
|
||||
'routes' => [
|
||||
['name' => 'settings#get', 'url' => '/settings', 'verb' => 'GET'],
|
||||
['name' => 'settings#set', 'url' => '/settings', 'verb' => 'POST'],
|
||||
]
|
||||
];
|
3
css/pride.css
Normal file
3
css/pride.css
Normal file
@ -0,0 +1,3 @@
|
||||
.files-list__row-icon .folder-icon svg {
|
||||
fill: url("#gradient-pride");
|
||||
}
|
29
js/pride-settings.js
Normal file
29
js/pride-settings.js
Normal file
@ -0,0 +1,29 @@
|
||||
const folder_selector = document.querySelectorAll('.pride_flags_user_settings .user-settings.folder-flavour select');
|
||||
const button_selector = document.querySelectorAll('.pride_flags_user_settings .user-settings.button-flavour select');
|
||||
const submit_button = document.querySelectorAll('.pride_flags_user_settings .settings-pride-submit');
|
||||
|
||||
fetch('/index.php/apps/pride_flags/settings')
|
||||
.then(res => JSON.parse(res))
|
||||
.then(({folderPrideVariant, buttonPrideVariant}) => {
|
||||
folder_selector.value = folderPrideVariant;
|
||||
button_selector.value = buttonPrideVariant;
|
||||
});
|
||||
|
||||
function save() {
|
||||
const payload = {
|
||||
folderVariant: folder_selector.value,
|
||||
buttonVariant: button_selector.value,
|
||||
}
|
||||
fetch('index.php/apps/pride_flags/settings', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(payload),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
}).then(response => {
|
||||
if (response.ok) {
|
||||
window.location.reload();
|
||||
}
|
||||
})
|
||||
}
|
||||
submit_button.on('click', e => save());
|
66
js/pride.js
Normal file
66
js/pride.js
Normal file
@ -0,0 +1,66 @@
|
||||
const flags = [
|
||||
{
|
||||
id: 'pride',
|
||||
colors: ['#E04641', '#DE7E41', '#E4D56F', '#55B85F', '#2473B5', '#6F5DA5'],
|
||||
transform: 'rotate(90)'
|
||||
}, {
|
||||
id: 'trans',
|
||||
colors: ['#55CDFC', '#F7A8B8', '#FFFFFF', '#F7A8B8', '#55CDFC'],
|
||||
transform: 'rotate(90)'
|
||||
}
|
||||
];
|
||||
|
||||
const generateGradient = colors => {
|
||||
const steps = colors.length;
|
||||
return colors.map((color, index) => { return [
|
||||
[color, (index / steps)],
|
||||
[color, (index + 1) / steps]
|
||||
]}).flat();
|
||||
};
|
||||
|
||||
const generateStops = (colors, opacity) => {
|
||||
return generateGradient(colors).map(([color, offset]) => {
|
||||
return `<stop stop-color="${color}" stop-opacity="${opacity}" offset="${offset * 100}%"></stop>`;
|
||||
});
|
||||
};
|
||||
|
||||
const makeLinearGradientSvg = (id, colors, opacity, transform) => {
|
||||
return `<svg xmlns="http://www.w3.org/2000/svg" id="svg-${id}" preserveAspectRatio="none" width="100%" height="100%">
|
||||
<defs>
|
||||
<linearGradient id="gradient-${id}" gradientTransform="${transform}">
|
||||
${generateStops(colors, opacity).join('\n')}
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<style>
|
||||
rect { height: 100%; width: 100%; }
|
||||
</style>
|
||||
<rect fill="url(#gradient-${id})" width="100%" height="100%" />
|
||||
</svg>`;
|
||||
};
|
||||
|
||||
flags.forEach(flag => {
|
||||
const svg_html = makeLinearGradientSvg(flag.id, flag.colors, flag.opacity ?? '0.8', flag.transform ?? 'rotate(0)');
|
||||
const container = document.createElement('div');
|
||||
container.classList.add('hidden-visually');
|
||||
container.ariaHidden = true;
|
||||
container.innerHTML = svg_html;
|
||||
const style_c = document.createElement('style');
|
||||
style_c.textContent = `
|
||||
body {
|
||||
--image-background-pride-${flag.id}: url('data:image/svg+xml;base64,${btoa(svg_html)}');
|
||||
}
|
||||
#app-navigation ul > li.active,
|
||||
.button-vue--vue-primary,
|
||||
.preview-card__header,
|
||||
.profile__primary-action-button,
|
||||
.app-navigation-entry.active {
|
||||
background-image: var(--image-background-pride-trans) !important;
|
||||
}
|
||||
.material-design-icon__svg,
|
||||
.checkbox-radio-switch svg {
|
||||
fill: url(#gradient-trans);
|
||||
}
|
||||
`;
|
||||
document.body.prepend(container);
|
||||
document.head.prepend(style_c);
|
||||
});
|
9
lib/AppConstants.php
Normal file
9
lib/AppConstants.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\PrideFlags;
|
||||
|
||||
abstract class AppConstants {
|
||||
public const APP_ID = 'pride_flags';
|
||||
}
|
28
lib/AppInfo/Application.php
Normal file
28
lib/AppInfo/Application.php
Normal 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');
|
||||
}
|
||||
}
|
23
lib/Controller/PageController.php
Normal file
23
lib/Controller/PageController.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\PrideFlags\Controller;
|
||||
|
||||
use OCA\PrideFlags\Settings\AppSettings;
|
||||
use OCP\IRequest;
|
||||
use OCP\IConfig;
|
||||
//use OCP\Framework\Controller;
|
||||
use OCP\Framework\Http\Response;
|
||||
|
||||
class SettingsController {
|
||||
public function __construct($appName, IRequest $request, AppSettings $settings) {
|
||||
parent::__construct($appName, $request);
|
||||
}
|
||||
public function get(): JSONResponse {
|
||||
return $this->settings->getAll();
|
||||
}
|
||||
public function set(string $folderVariant, string $buttonVariant): JSONResponse {
|
||||
return $this->settings->set($folderVariant, $buttonVariant);
|
||||
}
|
||||
}
|
39
lib/Settings/AppSettings.php
Normal file
39
lib/Settings/AppSettings.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?
|
||||
|
||||
namespace OCA\PrideFlags\Settings;
|
||||
|
||||
use OCA\PrideFlags\AppConstants;
|
||||
use OCP\IConfig;
|
||||
|
||||
class AppSettings implements JsonSerializable {
|
||||
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): string {
|
||||
return $this->config->getAppValue(AppConstants::APP_ID, $key, $value);
|
||||
}
|
||||
|
||||
public function getAll(): JsonSerializable {
|
||||
return [
|
||||
AppSettings::FOLDER_VARIANT => $this->getStringSetting(AppSettings::FOLDER_VARIANT, 'pride'),
|
||||
AppSettings::BUTTON_VARIANT => $this->getStringSetting(AppSettings::BUTTON_VARIANT, 'trans'),
|
||||
]
|
||||
}
|
||||
|
||||
public function set($folder, $button): JsonSerializable {
|
||||
$this->setStringSetting(AppSettings::FOLDER_VARIANT, $folder);
|
||||
$this->setStringSetting(AppSettings::BUTTON_VARIANT, $button);
|
||||
return $this->getAll();
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array {
|
||||
return $this->getAll();
|
||||
}
|
||||
}
|
30
lib/Settings/PersonalSection.php
Normal file
30
lib/Settings/PersonalSection.php
Normal 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');
|
||||
}
|
||||
}
|
25
lib/Settings/PersonalSettings.php
Normal file
25
lib/Settings/PersonalSettings.php
Normal 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;
|
||||
}
|
||||
}
|
24
templates/settings.php
Normal file
24
templates/settings.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
?>
|
||||
<div class="pride_flags_user_settings">
|
||||
<div class="settings-section section">
|
||||
<h2 class="settings_section__name">Personal preferences</h2>
|
||||
<p class="settings_section__desc"><em>Configure which pride flags you want where</em></p>
|
||||
<div class="user-settings folder-flavour" style="margin-left: 40px; display: flex;">
|
||||
<label for="user-settings-folder-flavour-select" style="display: flex; width: 250px;">Folders</label>
|
||||
<select id="user-settings-folder-flavour-select" style="display: flex; width: 300px;">
|
||||
<option value='pride'>Pride</option>
|
||||
<option value='trans'>Trans Pride</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="user-settings button-flavour" style="margin-left: 40px; display: flex;">
|
||||
<label for="user-settings-button-flavour-select" style="display: flex; width: 250px;">Buttons</label>
|
||||
<select id="user-settings-button-flavour-select" style="display: flex; width: 300px;">
|
||||
<option value='pride'>Pride</option>
|
||||
<option value='trans'>Trans Pride</option>
|
||||
</select>
|
||||
</div>
|
||||
<button class="settings-pride-submit button" style="margin-left: 40px; display: flex; width: 100px;">Save</button>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user