Commit e478e5c3 authored by Thomas Citharel's avatar Thomas Citharel 🏃🏻
Browse files

Merge branch 'version-2.0' into 'master'

Release 0.2.0

Closes #1

See merge request !1
parents e8a144a0 4b6a0687
Pipeline #291880 passed with stage
in 1 minute and 23 seconds
......@@ -66,4 +66,6 @@ js
# php deps
vendor
.php_cs.cache
translationfiles/
stages:
- lint
phplint:
stage: lint
image: php:latest
cache:
paths:
- vendor/
before_script:
- apt-get update -yqq
- apt-get install -yqq git zlib1g-dev libzip-dev
- docker-php-ext-install zip
- curl -sS https://getcomposer.org/installer | php
- php composer.phar install
script:
- php composer.phar run cs:check || ( echo 'Please run `composer run cs:fix` to format your code' && exit 1 )
eslint:
stage: lint
image: node:latest
cache:
paths:
- node_modules/
before_script:
- make npm-init
script:
- make lint
<?php
declare(strict_types=1);
require_once './vendor/autoload.php';
use Nextcloud\CodingStandard\Config;
$config = new Config();
$config
->getFinder()
->ignoreVCSIgnored(true)
->notPath('build')
->notPath('vendor')
->in(__DIR__);
return $config;
......@@ -23,22 +23,29 @@
namespace OCA\LoginNotes\AppInfo;
use OCP\IInitialStateService;
if ((@include_once __DIR__ . '/../vendor/autoload.php') === false) {
throw new \Exception('Cannot include autoload. Did you run install dependencies using composer?');
}
const APP_NAME = 'login_notes';
$request = \OC::$server->getRequest();
if (isset($request->server['REQUEST_URI'])) {
$url = $request->server['REQUEST_URI'];
if (preg_match('%/login(\?.+)?$%m', $url)) {
$url = $request->server['REQUEST_URI'];
if (preg_match('%/login(\?.+)?$%m', $url)) {
$notes = \OC::$server->query('OCA\LoginNotes\Manager')->getNotes();
\OC::$server->query('OCP\IInitialStateService')->provideInitialState(
$isCentered = \OC::$server->query('OCP\IConfig')->getAppValue(APP_NAME, 'centered', false);
/** @var IInitialStateService $initialStateService */
$initialStateService = \OC::$server->query('OCP\IInitialStateService');
$initialStateService->provideInitialState(APP_NAME, 'centered', $isCentered);
$initialStateService->provideInitialState(
'login_notes',
'notes',
$notes
);
\OCP\Util::addScript('login_notes', 'login_notes');
}
\OCP\Util::addScript(APP_NAME, 'login_notes');
}
}
......@@ -5,7 +5,7 @@
<name>Login notes</name>
<summary>Display notes on log-in page</summary>
<description>This app will show admin defined notes the log-in page</description>
<version>0.1.0</version>
<version>0.2.0</version>
<licence>agpl</licence>
<author mail="nextcloud@tcit.fr">Thomas Citharel</author>
<namespace>LoginNotes</namespace>
......
<?php
/**
* @copyright Copyright (c) 2020 Thomas Citharel <nextcloud@tcit.fr>
*
* @author Thomas Citharel <nextcloud@tcit.fr>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
return ['routes' => [
['name' => 'note#create', 'url' => '/notes', 'verb' => 'POST'],
['name' => 'note#destroy', 'url' => '/notes/{id}', 'verb' => 'DELETE'],
['name' => 'note#update', 'url' => '/notes/{id}', 'verb' => 'PATCH']
['name' => 'note#update', 'url' => '/notes/{id}', 'verb' => 'PATCH'],
['name' => 'setting#set', 'url' => '/settings', 'verb' => 'POST']
]];
{
"require": {
"league/commonmark": "^1.3"
}
"require": {
"league/commonmark": "^1.3",
"nextcloud/coding-standard": "^0.3.0"
},
"scripts": {
"cs:fix": "php-cs-fixer fix",
"cs:check": "php-cs-fixer fix --dry-run --diff"
}
}
This diff is collapsed.
......@@ -20,4 +20,8 @@
align-items: center;
}
}
form.alignment {
margin-bottom: 1rem;
}
}
......@@ -7,7 +7,13 @@ OC.L10N.register(
"Edit" : "Éditer",
"Delete" : "Supprimer",
"Notes on login screen" : "Notes sur la page de connexion",
"These messages will be shown on the login screen." : "Ces messages seront affichés sur la page de connexion.",
"Text alignment" : "Alignement du texte",
"Aligned" : "Aligné",
"Note content will be aligned to left (or right with RTL languages)." : "Le contenu des notes sera aligné à gauche (ou à droite dans le cas de systèmes d'écriture sinistroverses).",
"Centered" : "Centré",
"Note content will be centered." : "Le contenu des notes sera centré.",
"Notes list" : "Liste de notes",
"These notes will be shown on the login screen." : "Ces notes seront affichés sur la page de connexion.",
"No notes yet" : "Pas encore de notes",
"New login note" : "Nouvelle note",
"Enter the text for your new login note here. Markdown supported." : "Entrez le texte pour votre nouvelle note sur la page de connexion. Markdown supporté.",
......
......@@ -5,7 +5,13 @@
"Edit" : "Éditer",
"Delete" : "Supprimer",
"Notes on login screen" : "Notes sur la page de connexion",
"These messages will be shown on the login screen." : "Ces messages seront affichés sur la page de connexion.",
"Text alignment" : "Alignement du texte",
"Aligned" : "Aligné",
"Note content will be aligned to left (or right with RTL languages)." : "Le contenu des notes sera aligné à gauche (ou à droite dans le cas de systèmes d'écriture sinistroverses).",
"Centered" : "Centré",
"Note content will be centered." : "Le contenu des notes sera centré.",
"Notes list" : "Liste de notes",
"These notes will be shown on the login screen." : "Ces notes seront affichés sur la page de connexion.",
"No notes yet" : "Pas encore de notes",
"New login note" : "Nouvelle note",
"Enter the text for your new login note here. Markdown supported." : "Entrez le texte pour votre nouvelle note sur la page de connexion. Markdown supporté.",
......
......@@ -72,7 +72,7 @@ class NoteController extends Controller {
public function destroy(int $id) {
try {
$note = $this->manager->getById($id);
} catch(\Exception $e) {
} catch (\Exception $e) {
return new DataResponse([], Http::STATUS_NOT_FOUND);
}
$this->manager->delete($note);
......
<?php
/**
* @copyright Copyright (c) 2020 Thomas Citharel <nextcloud@tcit.fr>
*
* @author Thomas Citharel <nextcloud@tcit.fr>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\LoginNotes\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;
use OCP\IRequest;
use OCP\AppFramework\Controller;
class SettingController extends Controller {
/** @var IConfig */
private $config;
public function __construct(string $AppName, IRequest $request, IConfig $config) {
parent::__construct($AppName, $request);
$this->config = $config;
}
/**
* @param bool $centered
* @return DataResponse
*/
public function set(bool $centered) {
$this->config->setAppValue('login_notes', 'centered', $centered);
return new DataResponse([], Http::STATUS_OK);
}
}
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Thomas Citharel <nextcloud@tcit.fr>
......
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Thomas Citharel <nextcloud@tcit.fr>
......
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2020 Thomas Citharel <nextcloud@tcit.fr>
......@@ -31,8 +32,7 @@ use OCP\AppFramework\Db\QBMapper;
use OCP\IDBConnection;
class NoteMapper extends QBMapper {
const DB_NAME = 'login_notes';
public const DB_NAME = 'login_notes';
public function __construct(IDBConnection $db) {
parent::__construct($db, self::DB_NAME, Note::class);
......
......@@ -25,6 +25,7 @@ namespace OCA\LoginNotes\Settings;
use OCA\LoginNotes\Manager;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\Settings\ISettings;
......@@ -36,21 +37,27 @@ class AdminSettings implements ISettings {
/** @var IInitialStateService */
private $initialStateService;
/** @var IConfig */
private $config;
/**
* AdminSettings constructor.
*
* @param Manager $manager
* @param IInitialStateService $initialStateService
* @param IConfig $config
*/
public function __construct(Manager $manager, IInitialStateService $initialStateService) {
public function __construct(Manager $manager, IInitialStateService $initialStateService, IConfig $config) {
$this->manager = $manager;
$this->initialStateService = $initialStateService;
$this->config = $config;
}
/**
* @return TemplateResponse
*/
public function getForm() {
$this->initialStateService->provideInitialState('login_notes', 'centered', $this->config->getAppValue('login_notes', 'centered', false));
$this->initialStateService->provideInitialState('login_notes', 'notes', $this->manager->getNotes());
return new TemplateResponse('login_notes', 'admin');
......
......@@ -21,9 +21,15 @@
*/
import { loadState } from '@nextcloud/initial-state'
const notes = loadState('login_notes', 'notes')
const centered = loadState('login_notes', 'centered') || false
// insert warning
const submit = document.querySelector('.wrapper main')
notes.forEach(note => {
const warning = `<div class="warning">${note.text}</div>`
const warning = `<div class="login-notes warning" dir="auto">${note.text}</div>`
submit.insertAdjacentHTML('afterend', warning)
const loginNotes = document.querySelector('.wrapper .login-notes.warning')
loginNotes.style.textAlign = 'start'
if (centered) {
loginNotes.style.textAlign = 'center'
}
})
......@@ -23,8 +23,38 @@
<template>
<div id="login_notes_settings" class="section">
<h2>{{ t('login_notes', 'Notes on login screen') }}</h2>
<form class="alignment">
<h3>{{ t('login_notes', 'Text alignment') }}</h3>
<fieldset>
<p>
<input id="login_notes_aligned"
v-model="alignment"
type="radio"
name="alignment"
class="radio"
value="aligned">
<label for="login_notes_aligned">
{{ t('login_notes', 'Aligned') }}<br>
<em>{{ t('login_notes', 'Note content will be aligned to left (or right with RTL languages).') }}</em>
</label>
</p>
<p>
<input id="login_notes_centered"
v-model="alignment"
type="radio"
name="alignment"
class="radio"
value="centered">
<label for="login_notes_centered">
{{ t('login_notes', 'Centered') }}<br>
<em>{{ t('login_notes', 'Note content will be centered.') }}</em>
</label>
</p>
</fieldset>
</form>
<h3>{{ t('login_notes', 'Notes list') }}</h3>
<p class="settings-hint">
{{ t('login_notes', 'These messages will be shown on the login screen.') }}
{{ t('login_notes', 'These notes will be shown on the login screen.') }}
</p>
<div v-if="notes.length > 0" class="notes">
<Note v-for="note in notes"
......@@ -40,7 +70,8 @@
<h3>{{ t('login_notes', 'New login note') }}</h3>
<div>
<label>
<textarea v-model="newNoteData.text" :placeholder="t('login_notes', 'Enter the text for your new login note here. Markdown supported.')" />
<textarea v-model="newNoteData.text"
:placeholder="t('login_notes', 'Enter the text for your new login note here. Markdown supported.')" />
</label>
<button type="submit">
{{ t('login_notes', 'Add new note') }}
......@@ -62,9 +93,17 @@ export default {
data() {
return {
notes: loadState('login_notes', 'notes'),
alignment: loadState('login_notes', 'centered') === true ? 'centered' : 'aligned',
newNoteData: { text: '', created_at: 0 },
}
},
watch: {
async alignment(alignment) {
await axios.post(generateUrl('/apps/login_notes/settings'), {
centered: alignment === 'centered',
})
},
},
methods: {
async newNote() {
const note = await axios.post(generateUrl('/apps/login_notes/notes'), {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment