Initial template cleanup and submit config

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2020-04-28 09:04:53 +02:00
Родитель f99c04b56b
Коммит 81b2e9a537
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 60C25B8C072916CF
16 изменённых файлов: 9657 добавлений и 325 удалений

Разница между файлами не показана из-за своего большого размера Загрузить разницу

11
js/survey.jquery.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -56,6 +56,7 @@ use OCP\Util;
class PageController extends Controller {
protected $appName;
private $userId;
private $formMapper;
private $submissionMapper;
@ -71,24 +72,23 @@ class PageController extends Controller {
/** @var ILogger */
private $logger;
public function __construct(
IRequest $request,
IUserManager $userMgr,
IGroupManager $groupManager,
IURLGenerator $urlGenerator,
$userId,
FormMapper $formMapper,
QuestionMapper $questionMapper,
OptionMapper $optionMapper,
SubmissionMapper $SubmissionMapper,
AnswerMapper $AnswerMapper,
ILogger $logger
) {
public function __construct(string $appName,
IRequest $request,
IUserManager $userMgr,
IGroupManager $groupManager,
IURLGenerator $urlGenerator,
FormMapper $formMapper,
$userId,
QuestionMapper $questionMapper,
OptionMapper $optionMapper,
SubmissionMapper $SubmissionMapper,
AnswerMapper $AnswerMapper,
ILogger $logger) {
parent::__construct(Application::APP_ID, $request);
$this->userMgr = $userMgr;
$this->groupManager = $groupManager;
$this->urlGenerator = $urlGenerator;
$this->appName = $appName;
$this->userId = $userId;
$this->formMapper = $formMapper;
@ -167,31 +167,29 @@ class PageController extends Controller {
* @return TemplateResponse
*/
public function gotoForm($hash): ?TemplateResponse {
// Inject style on all templates
Util::addStyle($this->appName, 'forms');
try {
$form = $this->formMapper->findByHash($hash);
} catch (DoesNotExistException $e) {
return new TemplateResponse('forms', 'no.acc.tmpl', []);
}
// If form expired, return Expired-Template
if ( ($form->getExpires() !== 0) && (time() > $form->getExpires()) ) {
return new TemplateResponse('forms', 'expired.tmpl');
return new TemplateResponse('forms', 'notfound');
}
// Does the user have permissions to display
if ($this->hasUserAccess($form)) {
$renderAs = $this->userId !== null ? 'user' : 'public';
$res = new TemplateResponse('forms', 'submit.tmpl', [
'form' => $form,
'questions' => $this->getQuestions($form->getId()),
], $renderAs);
$csp = new ContentSecurityPolicy();
$csp->allowEvalScript(true);
$res->setContentSecurityPolicy($csp);
return $res;
return new TemplateResponse('forms', 'notfound');
}
User::checkLoggedIn();
return new TemplateResponse('forms', 'no.acc.tmpl', []);
// Has form expired
if ($form->getExpires() !== 0 && time() > $form->getExpires()) {
return new TemplateResponse('forms', 'expired');
}
$renderAs = is_null($this->userId) ? 'user' : 'public';
Util::addScript($this->appName, 'submit');
return new TemplateResponse($this->appName, 'main', [], $renderAs);
}
/**

Просмотреть файл

@ -57,8 +57,7 @@ __webpack_nonce__ = btoa(getRequestToken())
// eslint-disable-next-line
__webpack_public_path__ = generateFilePath('forms', '', 'js/')
/* eslint-disable-next-line no-new */
new Vue({
export default new Vue({
el: '#content',
// eslint-disable-next-line vue/match-component-file-name
name: 'FormsRoot',

36
src/submit.js Normal file
Просмотреть файл

@ -0,0 +1,36 @@
/**
* @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @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/>.
*
*/
import { translate, translatePlural } from '@nextcloud/l10n'
import Vue from 'vue'
import Fill from './views/Submit'
Vue.prototype.t = translate
Vue.prototype.n = translatePlural
export default new Vue({
el: '#content',
// eslint-disable-next-line vue/match-component-file-name
name: 'FormsSubmitRoot',
render: h => h(Fill),
})

Просмотреть файл

@ -26,6 +26,6 @@
<script>
export default {
name: 'Fill',
name: 'Submit',
}
</script>

Просмотреть файл

31
templates/expired.php Normal file
Просмотреть файл

@ -0,0 +1,31 @@
<?php
/**
* @copyright Copyright (c) 2019 Inigo Jiron <ijiron@terpmail.umd.edu>
*
* @author Inigo Jiron <ijiron@terpmail.umd.edu>
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @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/>.
*
*/
?>
<div id="emptycontent" class="">
<div class="icon-forms"></div>
<h2><?php p($l->t('Form Expired')); ?></h2>
<p><?php p($l->t('This Form has expired and is no longer taking answers')); ?></p>
</div>

Просмотреть файл

@ -1,35 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2019 Inigo Jiron <ijiron@terpmail.umd.edu>
*
* @author Inigo Jiron <ijiron@terpmail.umd.edu>
*
* @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/>.
*
*/
use OCP\Util;
Util::addStyle('forms', 'main');
?>
<div id="emptycontent" class="">
<div class="icon-forms"></div>
<h1>
<?php p($l->t('Form Expired')); ?>
</h1>
<h2>
<?php p($l->t('This Form has expired and is no longer taking answers.')); ?>
</h2>
</div>

Просмотреть файл

@ -1,28 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
* @author René Gieling <github@dartcafe.de>
*
* @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/>.
*
*/
?>
<?php \OCP\Util::addScript('forms', 'forms'); ?>
<div id="app-forms" value = 'forms'></div>

Просмотреть файл

@ -1,35 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @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/>.
*
*/
use OCP\Util;
Util::addStyle('forms', 'main');
?>
<div id="emptycontent" class="">
<div class="icon-forms"></div>
<h1>
<?php p($l->t('Access denied')); ?>
</h1>
<h2>
<?php p($l->t('You are not allowed to view this form or the form does not exist.')); ?>
</h2>
</div>

Просмотреть файл

@ -1,35 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @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/>.
*
*/
use OCP\Util;
Util::addStyle('forms', 'main');
?>
<div id="emptycontent" class="">
<div class="icon-forms"></div>
<h1>
<?php p($l->t('Access denied')); ?>
</h1>
<h2>
<?php p($l->t('You are not allowed to edit this form or the form does not exist.')); ?>
</h2>
</div>

Просмотреть файл

@ -1,35 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @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/>.
*
*/
use OCP\Util;
Util::addStyle('forms', 'main');
?>
<div id="emptycontent" class="">
<div class="icon-forms"></div>
<h1>
<?php p($l->t('Access denied')); ?>
</h1>
<h2>
<?php p($l->t('You are either not allowed to delete this form or it doesn\'t exist.')); ?>
</h2>
</div>

31
templates/notfound.php Normal file
Просмотреть файл

@ -0,0 +1,31 @@
<?php
/**
* @copyright Copyright (c) 2019 Inigo Jiron <ijiron@terpmail.umd.edu>
*
* @author Inigo Jiron <ijiron@terpmail.umd.edu>
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @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/>.
*
*/
?>
<div id="emptycontent" class="">
<div class="icon-forms"></div>
<h2><?php p($l->t('Form not found')); ?></h2>
<p><?php p($l->t('This form does not exists')); ?></p>
</div>

Просмотреть файл

@ -1,45 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @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/>.
*
*/
use OCP\Util;
Util::addStyle('forms', 'submit');
Util::addScript('forms', 'submit');
Util::addScript('forms', 'survey.jquery.min');
/** @var \OCA\Forms\Db\Form $form */
$form = $_['form'];
/** @var OCA\Forms\Db\Question[] $questions */
$questions = $_['questions'];
?>
<?php if ($form->getIsAnonymous()):?>
*NOTE: This form is anonymous
<?php endif?>
<div id="surveyContainer"
form="<?php echo htmlentities(json_encode($form->read()))?>"
questions="<?php echo htmlentities(json_encode($questions))?>"
></div>

Просмотреть файл

@ -1,14 +1,23 @@
const path = require('path')
const { VueLoaderPlugin } = require('vue-loader')
const webpack = require('webpack')
const StyleLintPlugin = require('stylelint-webpack-plugin')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const appName = process.env.npm_package_name
const appVersion = process.env.npm_package_version
console.info('Building', appName, appVersion, '\n')
module.exports = {
entry: path.join(__dirname, 'src', 'main.js'),
entry: {
forms: path.resolve(path.join('src', 'main.js')),
submit: path.resolve(path.join('src', 'submit.js')),
},
output: {
path: path.resolve(__dirname, './js'),
path: path.resolve('./js'),
publicPath: '/js/',
filename: 'forms.js',
chunkFilename: 'chunks/[name].js',
filename: `[name].js`,
chunkFilename: `${appName}.[name].js?v=[contenthash]`,
},
module: {
rules: [
@ -36,18 +45,14 @@ module.exports = {
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'url-loader',
options: {
limit: 8192,
},
},
],
},
plugins: [
new VueLoaderPlugin(),
new StyleLintPlugin(),
// Make appName & appVersion available as a constant
new webpack.DefinePlugin({ appName }),
new webpack.DefinePlugin({ appVersion }),
],
resolve: {
extensions: ['*', '.js', '.vue'],