Version 1.0.3

This commit is contained in:
affan98 2019-05-14 03:03:59 -04:00
parent da21b60ef0
commit 1fce2a39fb
30 changed files with 175 additions and 1007 deletions

View file

@ -1,2 +1 @@
# compiled vue templates
js/create-form.js
js/survey.jquery.min.js

View file

@ -9,7 +9,7 @@
# * npm
# * curl: used if phpunit and composer are not installed to fetch them from the web
# * tar: for building the archive
yarn_install=$(shell which yarn)
app_name=forms
project_dir=$(CURDIR)
@ -27,7 +27,11 @@ all: dev-setup appstore
dev-setup: clean-dev npm-init composer
npm-init:
ifeq (,$(yarn_install))
npm install
else
yarn
endif
# a copy is fetched from the web
.PHONY: composer

View file

@ -32,7 +32,6 @@ return [
['name' => 'page#delete_form', 'url' => '/delete', 'verb' => 'POST'],
['name' => 'page#insert_vote', 'url' => '/insert/vote', 'verb' => 'POST'],
['name' => 'page#insert_comment', 'url' => '/insert/comment', 'verb' => 'POST'],
['name' => 'page#search', 'url' => '/search', 'verb' => 'POST'],
['name' => 'page#get_display_name', 'url' => '/get/displayname', 'verb' => 'POST'],
@ -40,7 +39,6 @@ return [
['name' => 'api#get_form', 'url' => '/get/form/{formIdOrHash}', 'verb' => 'GET'],
['name' => 'api#get_options', 'url' => '/get/options/{formId}', 'verb' => 'GET'],
['name' => 'api#get_votes', 'url' => '/get/votes/{formId}', 'verb' => 'GET'],
['name' => 'api#get_comments', 'url' => '/get/comments/{formId}', 'verb' => 'GET'],
['name' => 'api#get_shares', 'url' => '/get/shares/{formId}', 'verb' => 'GET'],
['name' => 'api#get_event', 'url' => '/get/event/{formId}', 'verb' => 'GET'],
['name' => 'api#remove_form', 'url' => '/remove/form', 'verb' => 'POST'],

View file

@ -4,17 +4,29 @@
margin-top: 20px;
}
.sv-q-description{
font-size: 420px;
}
.sv_container{
h3 {
width: 400px;
font-size: 30px;
}
}
.sv_qstn .sq-root {
border: 1px solid gray;
border-left: 4px solid #18a689;
border-radius: 5px;
padding: 20px;
width: 400px;
margin-bottom: 30px;
font-size: 18px;
}
.sq-title {
font-size: 22px;
font-size: 20px;
margin-left: 20px;
}

View file

@ -17,11 +17,13 @@ function sendDataToServer(survey) {
}
function cssUpdate(survey, options){
console.log(options.cssClasses)
var classes = options.cssClasses
classes.root = 'sq-root'
classes.title = 'sq-title'
classes.item = 'sq-item'
classes.label = 'sq-label'
classes.description = 'sv-q-description'
if (options.question.isRequired) {
classes.title = 'sq-title sq-title-required'

View file

@ -25,7 +25,6 @@ namespace OCA\Forms\AppInfo;
use OCA\Forms\Controller\PageController;
use OCA\Forms\Controller\ApiController;
use OCA\Forms\Db\CommentMapper;
use OCA\Forms\Db\OptionMapper;
use OCA\Forms\Db\EventMapper;
use OCA\Forms\Db\NotificationMapper;

View file

@ -41,12 +41,8 @@ use OCP\Security\ISecureRandom;
use OCA\Forms\Db\Event;
use OCA\Forms\Db\EventMapper;
use OCA\Forms\Db\Option;
use OCA\Forms\Db\OptionMapper;
use OCA\Forms\Db\Vote;
use OCA\Forms\Db\VoteMapper;
use OCA\Forms\Db\Comment;
use OCA\Forms\Db\CommentMapper;
use OCA\Forms\Db\Notification;
use OCA\Forms\Db\NotificationMapper;
@ -62,9 +58,7 @@ class ApiController extends Controller {
private $groupManager;
private $userManager;
private $eventMapper;
private $optionMapper;
private $voteMapper;
private $commentMapper;
private $questionMapper;
private $answerMapper;
@ -76,9 +70,7 @@ class ApiController extends Controller {
* @param IUserManager $userManager
* @param string $userId
* @param EventMapper $eventMapper
* @param OptionMapper $optionMapper
* @param VoteMapper $voteMapper
* @param CommentMapper $commentMapper
* @param QuestionMapper $questionMapper
* @param AnswerMapper $answerMapper
*/
@ -89,9 +81,7 @@ class ApiController extends Controller {
IUserManager $userManager,
$userId,
EventMapper $eventMapper,
OptionMapper $optionMapper,
VoteMapper $voteMapper,
CommentMapper $commentMapper,
QuestionMapper $questionMapper,
AnswerMapper $answerMapper
) {
@ -100,9 +90,7 @@ class ApiController extends Controller {
$this->groupManager = $groupManager;
$this->userManager = $userManager;
$this->eventMapper = $eventMapper;
$this->optionMapper = $optionMapper;
$this->voteMapper = $voteMapper;
$this->commentMapper = $commentMapper;
$this->questionMapper = $questionMapper;
$this->answerMapper = $answerMapper;
}
@ -209,23 +197,6 @@ class ApiController extends Controller {
return $grantAccessAs;
}
/**
* Read all options of a form based on the form id
* @NoAdminRequired
* @NoCSRFRequired
* @param Integer $formId
* @return Array
*/
public function getOptions($formId) {
$optionList = array();
$options = $this->optionMapper->findByForm($formId);
foreach ($options as $optionElement) {
$optionList[] = $optionElement->read();
}
return $optionList;
}
/**
* Read all votes of a form based on the form id
* @NoAdminRequired
@ -234,6 +205,17 @@ class ApiController extends Controller {
* @return Array
*/
public function getVotes($formId) {
if (!\OC::$server->getUserSession()->getUser() instanceof IUser) {
$currentUser = '';
} else {
$currentUser = \OC::$server->getUserSession()->getUser()->getUID();
}
$event = $this->getEvent($formId);
$accessList = $this->convertAccessList($event['access']);
if ($event['owner'] == $currentUser) {
$votesList = array();
$votes = $this->voteMapper->findByForm($formId);
@ -243,24 +225,9 @@ class ApiController extends Controller {
return $votesList;
}
return NULL;
}
/**
* Read all comments of a form based on the form id
* @NoAdminRequired
* @NoCSRFRequired
* @param Integer $formId
* @return Array
*/
public function getComments($formId) {
$commentsList = array();
$comments = $this->commentMapper->findByForm($formId);
foreach ($comments as $commentElement) {
$commentsList[] = $commentElement->read();
}
return $commentsList;
}
/**
* Read an entire form based on form id
@ -382,7 +349,6 @@ class ApiController extends Controller {
'grantedAs' => $this->grantAccessAs($event, $shares),
'mode' => $mode,
'event' => $event,
'comments' => $this->getComments($event['id']),
'votes' => $this->getVotes($event['id']),
'shares' => $shares,
'options' => [
@ -436,7 +402,6 @@ class ApiController extends Controller {
if ($this->userId !== $formToDelete->getOwner() && !$this->groupManager->isAdmin($this->userId)) {
return new DataResponse(null, Http::STATUS_UNAUTHORIZED);
}
$this->commentMapper->deleteByForm($id);
$this->voteMapper->deleteByForm($id);
// $this->notificationMapper->deleteByForm($id);
$this->questionMapper->deleteByForm($id);
@ -473,8 +438,6 @@ class ApiController extends Controller {
$newEvent->setDescription($event['description']);
$newEvent->setIsAnonymous($event['isAnonymous']);
$newEvent->setFullAnonymous($event['fullAnonymous']);
$newEvent->setAllowMaybe($event['allowMaybe']);
if ($event['access'] === 'select') {
$shareAccess = '';

View file

@ -27,14 +27,10 @@
namespace OCA\Forms\Controller;
use OCA\Forms\Db\Comment;
use OCA\Forms\Db\CommentMapper;
use OCA\Forms\Db\Event;
use OCA\Forms\Db\EventMapper;
use OCA\Forms\Db\Notification;
use OCA\Forms\Db\NotificationMapper;
// use OCA\Forms\Db\Option;
// use OCA\Forms\Db\OptionMapper;
use OCA\Forms\Db\Vote;
use OCA\Forms\Db\VoteMapper;
@ -68,10 +64,8 @@ class PageController extends Controller {
private $userId;
private $config;
private $commentMapper;
private $eventMapper;
private $notificationMapper;
// private $optionMapper;
private $voteMapper;
private $questionMapper;
@ -99,8 +93,6 @@ class PageController extends Controller {
* @param IFactory $transFactory
* @param IURLGenerator $urlGenerator
* @param string $userId
* @param CommentMapper $commentMapper
* @param OptionMapper $optionMapper
* @param EventMapper $eventMapper
*
* @param QuestionMapper $questionMapper
@ -122,8 +114,6 @@ class PageController extends Controller {
IFactory $transFactory,
IURLGenerator $urlGenerator,
$userId,
CommentMapper $commentMapper,
// OptionMapper $optionMapper,
EventMapper $eventMapper,
QuestionMapper $questionMapper,
@ -144,8 +134,6 @@ class PageController extends Controller {
$this->transFactory = $transFactory;
$this->urlGenerator = $urlGenerator;
$this->userId = $userId;
$this->commentMapper = $commentMapper;
// $this->optionMapper = $optionMapper;
$this->eventMapper = $eventMapper;
$this->questionMapper = $questionMapper;
@ -358,9 +346,7 @@ class PageController extends Controller {
}
$form = new Event();
$form->setId($formId);
$this->commentMapper->deleteByForm($formId);
$this->voteMapper->deleteByForm($formId);
// $this->optionMapper->deleteByForm($formId);
$this->eventMapper->delete($form);
$url = $this->urlGenerator->linkToRoute('forms.page.index');
return new RedirectResponse($url);
@ -379,71 +365,50 @@ class PageController extends Controller {
* @return RedirectResponse
*/
public function insertVote($id, $userId, $answers, $questions) {
$form = $this->eventMapper->find($id);
$count_answers = count($answers);
$count = 1;
$anonID = "anon-user-". hash('md5', (time() + rand()));
for ($i = 0; $i < $count_answers; $i++) {
if($questions[$i]['type'] == "checkbox"){
foreach (($answers[$questions[$i]['text']]) as $value) {
$vote = new Vote();
$vote->setFormId($id);
$vote->setUserId($userId);
if($form->getIsAnonymous()){
$vote->setUserId($anonID);
}else{
$vote->setUserId($userId);
}
$vote->setVoteOptionText(htmlspecialchars($questions[$i]['text']));
$vote->setVoteAnswer($value);
$vote->setVoteOptionId($count);
$vote->setVoteOptionType($questions[$i]['type']);
$this->voteMapper->insert($vote);
}
$count++;
} else {
$vote = new Vote();
$vote->setFormId($id);
$vote->setUserId($userId);
if($form->getIsAnonymous()){
$vote->setUserId($anonID);
}else{
$vote->setUserId($userId);
}
$vote->setVoteOptionText(htmlspecialchars($questions[$i]['text']));
$vote->setVoteAnswer($answers[$questions[$i]['text']]);
$vote->setVoteOptionId($count++);
$vote->setVoteOptionType($questions[$i]['type']);
$this->voteMapper->insert($vote);
}
}
$hash = $form->getHash();
$url = $this->urlGenerator->linkToRoute('forms.page.goto_form', ['hash' => $hash]);
return new RedirectResponse($url);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
* @PublicPage
* @param int $formId
* @param string $userId
* @param string $commentBox
* @return JSONResponse
*/
public function insertComment($formId, $userId, $commentBox) {
$comment = new Comment();
$comment->setFormId($formId);
$comment->setUserId($userId);
$comment->setComment($commentBox);
$comment->setDt(date('Y-m-d H:i:s'));
$this->commentMapper->insert($comment);
$this->sendNotifications($formId, $userId);
$timeStamp = time();
$displayName = $userId;
$user = $this->userMgr->get($userId);
if ($user !== null) {
$displayName = $user->getDisplayName();
}
return new JSONResponse(array(
'userId' => $userId,
'displayName' => $displayName,
'timeStamp' => $timeStamp * 100,
'date' => date('Y-m-d H:i:s', $timeStamp),
'relativeNow' => $this->trans->t('just now'),
'comment' => $commentBox
));
}
/**
* @NoAdminRequired
* @NoCSRFRequired

View file

@ -1,62 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
* @author Kai Schröer <git@schroeer.co>
* @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/>.
*
*/
namespace OCA\Forms\Db;
use OCP\AppFramework\Db\Entity;
/**
* @method string getUserId()
* @method void setUserId(string $value)
* @method string getDt()
* @method void setDt(string $value)
* @method string getComment()
* @method void setComment(string $value)
* @method integer getFormId()
* @method void setFormId(integer $value)
*/
class Comment extends Model {
protected $userId;
protected $dt;
protected $comment;
protected $formId;
/**
* Comment constructor.
*/
public function __construct() {
$this->addType('formId', 'integer');
}
public function read() {
return [
'id' => $this->getId(),
'userId' => $this->getUserId(),
'date' => $this->getDt() . ' UTC',
'comment' => $this->getComment()
];
}
}

View file

@ -1,72 +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/>.
*
*/
namespace OCA\Forms\Db;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper;
class CommentMapper extends QBMapper {
/**
* CommentMapper constructor.
* @param IDBConnection $db
*/
public function __construct(IDBConnection $db) {
parent::__construct($db, 'forms_comments', '\OCA\Forms\Db\Comment');
}
/**
* @param int $formId
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @return Comment[]
*/
public function findByForm($formId) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where(
$qb->expr()->eq('form_id', $qb->createNamedParameter($formId, IQueryBuilder::PARAM_INT))
);
return $this->findEntities($qb);
}
/**
* @param int $formId
*/
public function deleteByForm($formId) {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->getTableName())
->where(
$qb->expr()->eq('form_id', $qb->createNamedParameter($formId, IQueryBuilder::PARAM_INT))
);
$qb->execute();
}
}

View file

@ -44,10 +44,6 @@ use OCP\AppFramework\Db\Entity;
* @method void setHash(string $value)
* @method integer getIsAnonymous()
* @method void setIsAnonymous(integer $value)
* @method integer getFullAnonymous()
* @method void setFullAnonymous(integer $value)
* @method integer getAllowMaybe()
* @method void setAllowMaybe(integer $value)
*/
class Event extends Model {
protected $title;
@ -66,8 +62,6 @@ class Event extends Model {
*/
public function __construct() {
$this->addType('isAnonymous', 'integer');
$this->addType('fullAnonymous', 'integer');
$this->addType('allowMaybe', 'integer');
}
public function read() {
@ -96,8 +90,6 @@ class Event extends Model {
'expired' => $expired,
'expirationDate' => $this->getExpire(),
'isAnonymous' => $this->getIsAnonymous(),
'fullAnonymous' => $this->getFullAnonymous(),
'allowMaybe' => $this->getAllowMaybe()
];
}
}

View file

@ -1,58 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
*
* @author Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
* @author Kai Schröer <git@schroeer.co>
* @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/>.
*
*/
namespace OCA\Forms\Db;
use OCP\AppFramework\Db\Entity;
/**
* @method integer getFormId()
* @method void setFormId(integer $value)
* @method string getFormOptionText()
* @method void setFormOptionText(string $value)
* @method integer getTimestamp()
* @method void setTimestamp(integer $value)
*/
class Option extends Model {
protected $formId;
protected $formOptionText;
protected $timestamp;
/**
* Option constructor.
*/
public function __construct() {
$this->addType('formId', 'integer');
$this->addType('timestamp', 'integer');
}
public function read() {
return [
'id' => $this->getId(),
'text' => htmlspecialchars_decode($this->getFormOptionText()),
'timestamp' => $this->getTimestamp()
];
}
}

View file

@ -1,72 +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/>.
*
*/
namespace OCA\Forms\Db;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper;
class OptionMapper extends QBMapper {
/**
* TextMapper constructor.
* @param IDBConnection $db
*/
public function __construct(IDBConnection $db) {
parent::__construct($db, 'forms_options', '\OCA\Forms\Db\Option');
}
/**
* @param int $formId
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @return Option[]
*/
public function findByForm($formId) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->getTableName())
->where(
$qb->expr()->eq('form_id', $qb->createNamedParameter($formId, IQueryBuilder::PARAM_INT))
);
return $this->findEntities($qb);
}
/**
* @param int $formId
*/
public function deleteByForm($formId) {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->getTableName())
->where(
$qb->expr()->eq('form_id', $qb->createNamedParameter($formId, IQueryBuilder::PARAM_INT))
);
$qb->execute();
}
}

View file

@ -38,6 +38,8 @@ use OCP\AppFramework\Db\Entity;
* @method void setVoteOptionText(string $value)
* @method string getVoteAnswer()
* @method void setVoteAnswer(string $value)
* @method string getVoteOptionType()
* @method void setVoteOptionType(string $value)
*/
class Vote extends Model {
protected $formId;
@ -45,6 +47,7 @@ class Vote extends Model {
protected $voteOptionId;
protected $voteOptionText;
protected $voteAnswer;
protected $voteOptionType;
/**
* Options constructor.
@ -60,7 +63,8 @@ class Vote extends Model {
'userId' => $this->getUserId(),
'voteOptionId' => $this->getVoteOptionId(),
'voteOptionText' => htmlspecialchars_decode($this->getVoteOptionText()),
'voteAnswer' => $this->getVoteAnswer()
'voteAnswer' => $this->getVoteAnswer(),
'voteOptionType' => $this->getVoteOptionType()
];
}

View file

@ -37,7 +37,7 @@ use OCP\Migration\IOutput;
* Installation class for the forms app.
* Initial db creation
*/
class Version0009Date20190000000005 extends SimpleMigrationStep {
class Version0009Date20190000000006 extends SimpleMigrationStep {
/** @var IDBConnection */
protected $connection;
@ -182,6 +182,10 @@ class Version0009Date20190000000005 extends SimpleMigrationStep {
'notnull' => false,
'length' => 4096,
]);
$table->addColumn('vote_option_type', Type::STRING, [
'notnull' => false,
'length' => 256,
]);
$table->setPrimaryKey(['id']);
}

View file

@ -70,7 +70,7 @@
"dependencies": {
"acorn": "^6.1.1",
"bootstrap": "^3.3.7",
"json2csv" : "4.5.1",
"json2csv": "4.5.1",
"moment": "^2.23.0",
"nextcloud-axios": "^0.1.3",
"nextcloud-vue": "^0.9.0",
@ -80,9 +80,7 @@
"vue": "^2.6.8",
"vue-click-outside": "^1.0.7",
"vue-clipboard2": "^0.3.0",
"vue-router": "^3.0.2",
"survey-vue": "^1.0.56",
"surveyjs-widgets": "^1.0.56"
"vue-router": "^3.0.2"
},
"browserslist": [
"> 1%",
@ -121,7 +119,7 @@
"vue-loader": "^15.7.0",
"vue-style-loader": "^4.1.1",
"vue-template-compiler": "^2.6.8",
"webpack": "^4.29.6",
"webpack": "^4.31.0",
"webpack-cli": "^3.2.3",
"webpack-merge": "^4.1.5"
}

View file

@ -23,6 +23,9 @@
<template>
<div class="controls">
<div class="breadcrumb">
<button class="button btn primary" @click="helpPage">
{{ "Help" }}
</button>
<div class="crumb svg crumbhome">
<router-link :to="{ name: 'list'}" class="icon-home">
Home
@ -52,6 +55,11 @@ export default {
return {
imagePath: OC.imagePath('core', 'places/home.svg')
}
},
methods: {
helpPage() {
window.open('https://github.com/affan98/forms/blob/master/Forms_Support.md')
}
}
}
</script>

View file

@ -71,7 +71,7 @@
<div>
<img class="icontwo">
</div>
<div v-if="votedBycurrentUser" class="symbol icon-voted" />
<div class="symbol icon-voted" />
<a :href="voteUrl" class="wrapper group-1-1">
<div class="name">
{{ form.event.title }}
@ -173,19 +173,11 @@ export default {
return t('forms', 'never')
}
},
participants() {
return this.form.votes.map(item => item.userId)
.filter((value, index, self) => self.indexOf(value) === index)
},
countvotes() {
return this.participants.length
},
countShares() {
return this.form.shares.length
},
votedBycurrentUser() {
return this.participants.indexOf(OC.getCurrentUser().uid) > -1
},
voteUrl() {
return OC.generateUrl('apps/forms/form/') + this.form.event.hash
}

View file

@ -23,7 +23,7 @@
<li>
<div>{{ question.text }}</div>
<div>
<input v-show="question.type != 'text'" style="height:30px;" v-model="newQuizAnswer"
<input v-show="(question.type != 'text') && (question.type != 'comment')" style="height:30px;" v-model="newQuizAnswer"
:placeholder=" t('forms', 'Add Answer')"
@keyup.enter="emitNewAnswer(question)"
>

View file

@ -28,7 +28,6 @@ import Router from 'vue-router'
// Dynamic loading
const Create = () => import('./views/Create')
const List = () => import('./views/List')
const Vote = () => import('./views/Vote')
const Results = () => import('./views/Results')
Vue.use(Router)
@ -76,14 +75,6 @@ export default new Router({
},
props: false,
name: 'create'
},
{
path: '/:index(index.php/)?apps/forms/form/:hash',
components: {
default: Vote
},
props: false,
name: 'create'
}
]
})

View file

@ -129,10 +129,6 @@
<input v-show="form.event.isAnonymous" id="trueAnonymous" v-model="form.event.fullAnonymous"
:disabled="protect" type="checkbox" class="checkbox"
>
<label v-show="form.event.isAnonymous" class="title" for="trueAnonymous">
{{ t('forms', 'Hide user names for admin') }}
</label>
<input id="expiration" v-model="form.event.expiration" :disabled="protect"
type="checkbox" class="checkbox"
>
@ -255,7 +251,8 @@ export default {
options: [
{ text: 'Radio Buttons', value: 'radiogroup' },
{ text: 'Checkboxes', value: 'checkbox' },
{ text: 'Write In', value: 'text' },
{ text: 'Short Response', value: 'text' },
{ text: 'Long Response', value: 'comment' },
{ text: 'Drop Down', value: 'dropdown' }
]
}
@ -285,7 +282,7 @@ export default {
} else if (this.form.mode === 'edit') {
return t('forms', 'Update form')
} else {
return t('forms', 'Create new form')
return t('forms', 'Done')
}
},
@ -412,7 +409,7 @@ export default {
} else if (!this.uniqueName) {
OC.Notification.showTemporary(t('forms', 'Cannot have the same question!'))
} else {
if (this.newQuizQuestion !== null & this.newQuizQuestion !== '') {
if (this.newQuizQuestion !== null & this.newQuizQuestion !== '' & (/\S/.test(this.newQuizQuestion))) {
this.form.options.formQuizQuestions.push({
id: this.nextQuizQuestionId++,
text: this.newQuizQuestion,
@ -443,7 +440,7 @@ export default {
if (!this.uniqueAnsName) {
OC.Notification.showTemporary(t('forms', 'Two answers cannot be the same!'))
} else {
if (item.newQuizAnswer !== null & item.newQuizAnswer !== '') {
if (item.newQuizAnswer !== null & item.newQuizAnswer !== '' & (/\S/.test(item.newQuizAnswer))) {
item.formQuizAnswers.push({
id: item.nextQuizAnswerId,
text: item.newQuizAnswer
@ -461,7 +458,7 @@ export default {
allHaveAns() {
this.haveAns = true
this.form.options.formQuizQuestions.forEach(q => {
if (q.type !== 'text' && q.answers.length === 0) {
if (q.type !== 'text' && q.type !== 'comment' && q.answers.length === 0) {
this.haveAns = false
}
})
@ -472,13 +469,15 @@ export default {
if (mode !== '') {
this.form.mode = mode
}
if (this.form.event.title.length === 0) {
if (this.form.event.title.length === 0 | !(/\S/.test(this.form.event.title))) {
this.titleEmpty = true
OC.Notification.showTemporary(t('forms', 'Title must not be empty!'))
} else if (this.form.options.formQuizQuestions.length === 0) {
OC.Notification.showTemporary(t('forms', 'Must have at least one question!'))
} else if (!this.haveAns) {
OC.Notification.showTemporary(t('forms', 'All questions need answers!'))
} else if (this.form.event.expiration & this.form.event.expirationDate === '') {
OC.Notification.showTemporary(t('forms', 'Need to pick an expiration date!'))
} else {
this.writingForm = true
this.titleEmpty = false

View file

@ -31,7 +31,6 @@
</span>
</router-link>
</controls>
<div v-if="noForms" class="">
<div class="icon-forms" />
<h2> {{ t('No existing forms.') }} </h2>
@ -39,7 +38,6 @@
<span>{{ t('forms', 'Click here to add a form') }}</span>
</router-link>
</div>
<transition-group
v-if="!noForms"
name="list"
@ -102,7 +100,9 @@ export default {
this.loading = false
})
},
helpPage() {
window.open('https://github.com/affan98/forms/blob/master/Forms_Support.md')
},
viewFormResults(index, event, name) {
this.$router.push({
name: name,

View file

@ -23,31 +23,39 @@
-->
<template>
<div id="app-content">
<div>
<div>
<button class="button btn primary" @click="download">
<span>{{ "Export to CSV" }}</span>
</button>
</div>
<transition-group
name="list"
tag="div"
class="table"
>
<resultItem
key="0"
:header="true"
/>
<li
is="resultItem"
v-for="(vote, index) in votes"
:key="vote.id"
:vote="vote"
@viewResults="viewFormResults(index, form.event, 'results')"
/>
</transition-group>
<loading-overlay v-if="loading" />
<modal-dialog />
<h1>
{{ "Statistics" }}
</h1>
<div v-for="sum in stats" :key="sum">
{{ sum }}
</div>
<div id="app-content">
<transition-group
name="list"
tag="div"
class="table"
>
<resultItem
key="0"
:header="true"
/>
<li
is="resultItem"
v-for="(vote, index) in votes"
:key="vote.id"
:vote="vote"
@viewResults="viewFormResults(index, form.event, 'results')"
/>
</transition-group>
<loading-overlay v-if="loading" />
<modal-dialog />
</div>
</div>
</template>
@ -68,6 +76,7 @@ export default {
return {
loading: true,
votes: []
}
},
@ -81,7 +90,12 @@ export default {
this.loading = true
this.$http.get(OC.generateUrl('apps/forms/get/votes/' + this.$route.params.hash))
.then((response) => {
this.votes = response.data
if (response.data == null) {
this.votes = null
OC.Notification.showTemporary('Access Denied')
} else {
this.votes = response.data
}
this.loading = false
}, (error) => {
/* eslint-disable-next-line no-console */
@ -98,16 +112,57 @@ export default {
})
},
download() {
this.json2csvParser = ['userId', 'voteOptionId', 'voteOptionText', 'voteAnswer']
var element = document.createElement('a')
element.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(json2csvParser.parse(this.votes)))
element.setAttribute('download', 'NextCloud Forms CSV' + '.csv')
element.style.display = 'none'
document.body.appendChild(element)
this.loading = true
this.$http.get(OC.generateUrl('apps/forms/get/event/' + this.$route.params.hash))
.then((response) => {
this.json2csvParser = ['userId', 'voteOptionId', 'voteOptionText', 'voteAnswer']
var element = document.createElement('a')
element.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(json2csvParser.parse(this.votes)))
element.setAttribute('download', response.data.title + '.csv')
element.click()
document.body.removeChild(element)
element.style.display = 'none'
document.body.appendChild(element)
element.click()
document.body.removeChild(element)
this.loading = false
}, (error) => {
/* eslint-disable-next-line no-console */
console.log(error.response)
this.loading = false
})
}
},
computed: {
stats() {
if (this.votes != null) {
var uniqueAns = []
var uniqueQs = []
var ansToQ = new Map()
for (let i = 0; i < this.votes.length; i++) {
if (this.votes[i].voteOptionType === 'radiogroup' || this.votes[i].voteOptionType === 'dropdown') {
if (uniqueAns.includes(this.votes[i].voteAnswer) === false) {
uniqueAns.push(this.votes[i].voteAnswer)
ansToQ.set(this.votes[i].voteAnswer, this.votes[i].voteOptionId)
}
if (uniqueQs.includes(this.votes[i].voteOptionId) === false) {
uniqueQs.push(this.votes[i].voteOptionId)
}
}
}
var sums = []
for (let i = 0; i < uniqueAns.length; i++) {
sums[i] = 0
}
for (let i = 0; i < this.votes.length; i++) {
sums[uniqueAns.indexOf(this.votes[i].voteAnswer)]++
}
for (let i = 0; i < sums.length; i++) {
sums[i] = 'Question ' + ansToQ.get(uniqueAns[i]) + ': ' + (sums[i] / ((this.votes.length / uniqueQs.length)) * 100).toFixed(2) + '%' + ' of respondents voted for answer choice: ' + uniqueAns[i]
}
}
return sums.sort()
}
}
}

View file

@ -1,176 +0,0 @@
<!--
- @copyright Copyright (c) 2018 René Gieling <github@dartcafe.de>
-
- @author Natalie Gilbert
- @author Nick Gallo
- @author Affan Hussain
-
- @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/>.
-
-->
<template>
<div id="app-votes">
<survey :survey="survey"></survey>
</div>
</template>
<script>
import * as SurveyVue from 'survey-vue'
import * as widgets from 'surveyjs-widgets'
// import 'bootstrap/dist/css/bootstrap.css'
var Survey = SurveyVue.Survey
Survey.cssType = 'bootstrap'
// import "inputmask/dist/inputmask/phone-codes/phone.js"
widgets.icheck(SurveyVue)
widgets.select2(SurveyVue)
widgets.inputmask(SurveyVue)
widgets.jquerybarrating(SurveyVue)
widgets.jqueryuidatepicker(SurveyVue)
widgets.nouislider(SurveyVue)
widgets.select2tagbox(SurveyVue)
widgets.signaturepad(SurveyVue)
widgets.sortablejs(SurveyVue)
widgets.ckeditor(SurveyVue)
widgets.autocomplete(SurveyVue)
widgets.bootstrapslider(SurveyVue)
export default {
name: 'AppVote',
components: {
Survey
},
data() {
var json = {
title: '',
questions: []
}
var model = new SurveyVue.Model(json)
return {
loadingForm: false,
writingForm: false,
form: [],
myTitle: '',
quests: [],
survey: model,
ans: []
}
},
created() {
this.indexPage = OC.generateUrl('apps/forms/')
this.loadForm(this.$route.params.hash)
},
methods: {
loadForm(hash) {
this.loadingForm = true
this.$http.get(OC.generateUrl('apps/forms/get/form/' + hash))
.then((response) => {
this.form = response.data
this.myTitle = response.data.event.title
this.quests = response.data.options.formQuizQuestions
this.loadingForm = false
this.setSurvey()
}, (error) => {
/* eslint-disable-next-line no-console */
console.log(error.response)
this.form.event.hash = ''
this.loadingForm = false
})
},
setSurvey() {
this.quests.forEach(q => {
q.answers.forEach(a => {
this.ans.push(a.text)
})
this.survey.pages[0].addNewQuestion(q.type, q.text).choices = this.ans
this.ans = []
this.survey.pages[0].questions.forEach(i => {
i.isRequired = true
})
})
this.survey
.onUpdateQuestionCssClasses
.add(function(survey, options) {
var classes = options.cssClasses
classes.root = 'sq-root'
classes.title = 'sq-title'
classes.item = 'sq-item'
classes.label = 'sq-label'
if (options.question.isRequired) {
classes.title = 'sq-title sq-title-required'
classes.root = 'sq-root sq-root-required'
}
})
this.survey
.onComplete
.add(function(result) {
this.writingForm = true
this.form.answers = result.data
this.form.userId = OC.getCurrentUser().uid
this.form.questions = this.quests
this.$http.post(OC.generateUrl('apps/forms/insert/vote'), this.form)
.then((response) => {
this.writingForm = false
}, (error) => {
/* eslint-disable-next-line no-console */
console.log(error.response)
this.writingForm = false
})
}.bind(this))
}
}
}
</script>
<style lang="scss">
.app-forms {
margin: auto;
width: 50%;
margin-top: 20px;
}
.sv_qstn .sq-root {
border: 1px solid gray;
border-left: 4px solid #18a689;
border-radius: 5px;
padding: 20px;
margin-bottom: 30px;
font-size: 18px;
}
.sq-title {
font-size: 22px;
margin-left: 20px;
}
.sq-title-required {
color: black;
}
.sq-label {
margin-left: 30px;
}
.sq-item:nth-child(1) {
margin-bottom: 5px;
}
</style>

View file

@ -41,6 +41,10 @@
$access = $form->getAccess();
?>
<?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))?>"

View file

@ -1,120 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co>
*
* @author Kai Schröer <git@schroeer.co>
*
* @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\Forms\Tests\Unit\Controller;
use OCA\Forms\Controller\PageController;
use OCA\Forms\Tests\Unit\UnitTestCase;
use OCP\AppFramework\Http\TemplateResponse;
class PageControllerTest extends UnitTestCase {
/** @var PageController */
private $controller;
private $userId = 'john';
/**
* {@inheritDoc}
*/
public function setUp() {
$avatarManager = $this->getMockBuilder('OCP\IAvatarManager')
->disableOriginalConstructor()
->getMock();
$config = $this->getMockBuilder('OCP\IConfig')
->disableOriginalConstructor()
->getMock();
$groupManager = $this->getMockBuilder('OCP\IGroupManager')
->disableOriginalConstructor()
->getMock();
$l10n = $this->getMockBuilder('OCP\IL10N')
->disableOriginalConstructor()
->getMock();
$logger = $this->getMockBuilder('OCP\ILogger')
->disableOriginalConstructor()
->getMock();
$request = $this->getMockBuilder('OCP\IRequest')
->disableOriginalConstructor()
->getMock();
$urlGenerator = $this->getMockBuilder('OCP\IURLGenerator')
->disableOriginalConstructor()
->getMock();
$user = $this->getMockBuilder('OCP\IUser')
->disableOriginalConstructor()
->getMock();
$userManager = $this->getMockBuilder('OCP\IUserManager')
->disableOriginalConstructor()
->getMock();
$transFactory = $this->getMockBuilder('OCP\L10N\IFactory')
->disableOriginalConstructor()
->getMock();
$mailer = $this->getMockBuilder('OCP\Mail\IMailer')
->disableOriginalConstructor()
->getMock();
$commentMapper = $this->getMockBuilder('OCA\Forms\Db\CommentMapper')
->disableOriginalConstructor()
->getMock();
$optionMapper = $this->getMockBuilder('OCA\Forms\Db\OptionMapper')
->disableOriginalConstructor()
->getMock();
$eventMapper = $this->getMockBuilder('OCA\Forms\Db\EventMapper')
->disableOriginalConstructor()
->getMock();
$notificationMapper = $this->getMockBuilder('OCA\Forms\Db\NotificationMapper')
->disableOriginalConstructor()
->getMock();
$voteMapper = $this->getMockBuilder('OCA\Forms\Db\VoteMapper')
->disableOriginalConstructor()
->getMock();
$this->controller = new PageController(
'forms',
$request,
$config,
$userManager,
$groupManager,
$avatarManager,
$logger,
$l10n,
$transFactory,
$urlGenerator,
$this->userId,
$commentMapper,
$optionMapper,
$eventMapper,
$notificationMapper,
$voteMapper,
$mailer
);
}
/**
* Basic controller index route test.
*/
public function testIndex() {
$result = $this->controller->index();
$this->assertEquals('forms.tmpl', $result->getTemplateName());
$this->assertInstanceOf(TemplateResponse::class, $result);
}
}

View file

@ -1,97 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co>
*
* @author Kai Schröer <git@schroeer.co>
*
* @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\Forms\Tests\Unit\Db;
use OCA\Forms\Db\Comment;
use OCA\Forms\Db\CommentMapper;
use OCA\Forms\Db\Event;
use OCA\Forms\Db\EventMapper;
use OCA\Forms\Tests\Unit\UnitTestCase;
use OCP\IDBConnection;
use League\FactoryMuffin\Faker\Facade as Faker;
class CommentMapperTest extends UnitTestCase {
/** @var IDBConnection */
private $con;
/** @var CommentMapper */
private $commentMapper;
/** @var EventMapper */
private $eventMapper;
/**
* {@inheritDoc}
*/
public function setUp() {
parent::setUp();
$this->con = \OC::$server->getDatabaseConnection();
$this->commentMapper = new CommentMapper($this->con);
$this->eventMapper = new EventMapper($this->con);
}
/**
* Create some fake data and persist them to the database.
*
* @return Comment
*/
public function testCreate() {
/** @var Event $event */
$event = $this->fm->instance('OCA\Forms\Db\Event');
$this->assertInstanceOf(Event::class, $this->eventMapper->insert($event));
/** @var Comment $comment */
$comment = $this->fm->instance('OCA\Forms\Db\Comment');
$comment->setFormId($event->getId());
$this->assertInstanceOf(Comment::class, $this->commentMapper->insert($comment));
return $comment;
}
/**
* Update the previously created entry and persist the changes.
*
* @depends testCreate
* @param Comment $comment
* @return Comment
*/
public function testUpdate(Comment $comment) {
$newComment = Faker::paragraph();
$comment->setComment($newComment());
$this->commentMapper->update($comment);
return $comment;
}
/**
* Delete the previously created entries from the database.
*
* @depends testUpdate
* @param Comment $comment
*/
public function testDelete(Comment $comment) {
$event = $this->eventMapper->find($comment->getFormId());
$this->commentMapper->delete($comment);
$this->eventMapper->delete($event);
}
}

View file

@ -1,97 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co>
*
* @author Kai Schröer <git@schroeer.co>
*
* @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\Forms\Tests\Unit\Db;
use OCA\Forms\Db\Event;
use OCA\Forms\Db\EventMapper;
use OCA\Forms\Db\Option;
use OCA\Forms\Db\OptionMapper;
use OCA\Forms\Tests\Unit\UnitTestCase;
use OCP\IDBConnection;
use League\FactoryMuffin\Faker\Facade as Faker;
class OptionMapperTest extends UnitTestCase {
/** @var IDBConnection */
private $con;
/** @var OptionMapper */
private $optionMapper;
/** @var EventMapper */
private $eventMapper;
/**
* {@inheritDoc}
*/
public function setUp() {
parent::setUp();
$this->con = \OC::$server->getDatabaseConnection();
$this->optionMapper = new OptionMapper($this->con);
$this->eventMapper = new EventMapper($this->con);
}
/**
* Create some fake data and persist them to the database.
*
* @return Option
*/
public function testCreate() {
/** @var Event $event */
$event = $this->fm->instance('OCA\Forms\Db\Event');
$this->assertInstanceOf(Event::class, $this->eventMapper->insert($event));
/** @var Option $option */
$option = $this->fm->instance('OCA\Forms\Db\Option');
$option->setFormId($event->getId());
$this->assertInstanceOf(Option::class, $this->optionMapper->insert($option));
return $option;
}
/**
* Update the previously created entry and persist the changes.
*
* @depends testCreate
* @param Option $option
* @return Option
*/
public function testUpdate(Option $option) {
$newFormOptionText = Faker::text(255);
$option->setFormOptionText($newFormOptionText());
$this->optionMapper->update($option);
return $option;
}
/**
* Delete the previously created entries from the database.
*
* @depends testUpdate
* @param Option $option
*/
public function testDelete(Option $option) {
$event = $this->eventMapper->find($option->getFormId());
$this->optionMapper->delete($option);
$this->eventMapper->delete($event);
}
}

View file

@ -1,36 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co>
*
* @author Kai Schröer <git@schroeer.co>
*
* @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 League\FactoryMuffin\Faker\Facade as Faker;
/**
* General factory for the comment model.
*/
$fm->define('OCA\Forms\Db\Comment')->setDefinitions([
'userId' => Faker::firstNameMale(),
'dt' => function() {
$date = new DateTime('today');
return $date->format('Y-m-d H:i:s');
},
'comment' => Faker::text(255)
]);

View file

@ -1,31 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2017 Kai Schröer <git@schroeer.co>
*
* @author Kai Schröer <git@schroeer.co>
*
* @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 League\FactoryMuffin\Faker\Facade as Faker;
/**
* General factory for the text model.
*/
$fm->define('OCA\Forms\Db\Option')->setDefinitions([
'formOptionText' => Faker::text(255)
]);