diff options
author | dartcafe <github@dartcafe.de> | 2020-09-03 19:07:37 +0300 |
---|---|---|
committer | dartcafe <github@dartcafe.de> | 2020-09-03 19:07:37 +0300 |
commit | 7cfa3ac5f2aa3559cd3856546da359cef8d6680d (patch) | |
tree | 384b2379495bd41f164dda12d78f1874604e382c | |
parent | c72e917f10ca25c691813e191ebec90b7da88d92 (diff) |
Adding option for important polls
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | lib/Db/Poll.php | 9 | ||||
-rw-r--r-- | lib/Migration/Version0105Date20200903172733.php | 77 | ||||
-rw-r--r-- | lib/Service/PollService.php | 2 | ||||
-rw-r--r-- | src/js/components/SideBar/SideBarTabConfiguration.vue | 15 | ||||
-rw-r--r-- | src/js/store/modules/poll.js | 1 | ||||
-rw-r--r-- | src/js/store/modules/polls.js | 3 |
7 files changed, 106 insertions, 2 deletions
@@ -1,5 +1,6 @@ .DS_Store .sass-cache/ +.php_cs.cache .project/ .idea/ build/ diff --git a/lib/Db/Poll.php b/lib/Db/Poll.php index 7a6b064d..dddbb17e 100644 --- a/lib/Db/Poll.php +++ b/lib/Db/Poll.php @@ -63,6 +63,8 @@ use OCP\AppFramework\Db\Entity; * @method void setShowResults(string $value) * @method int getAdminAccess() * @method void setAdminAccess(integer $value) + * @method int getImportant() + * @method void setImportant(integer $value) */ class Poll extends Entity implements JsonSerializable { @@ -114,6 +116,9 @@ class Poll extends Entity implements JsonSerializable { /** @var int $adminAccess*/ protected $adminAccess; + /** @var int $important*/ + protected $important; + public function jsonSerialize() { return [ 'id' => intval($this->id), @@ -131,7 +136,8 @@ class Poll extends Entity implements JsonSerializable { 'voteLimit' => intval($this->voteLimit), 'showResults' => $this->showResults, 'adminAccess' => intVal($this->adminAccess), - 'ownerDisplayName' => $this->getDisplayName() + 'ownerDisplayName' => $this->getDisplayName(), + 'important' => intVal($this->important) ]; } @@ -146,6 +152,7 @@ class Poll extends Entity implements JsonSerializable { $this->setShowResults(isset($array['showResults']) ? $array['showResults'] : $this->getShowResults()); $this->setDeleted(isset($array['deleted']) ? $array['deleted'] : $this->getDeleted()); $this->setAdminAccess(isset($array['adminAccess']) ? $array['adminAccess'] : $this->getAdminAccess()); + $this->setImportant(isset($array['important']) ? $array['important'] : $this->getImportant()); return $this; } diff --git a/lib/Migration/Version0105Date20200903172733.php b/lib/Migration/Version0105Date20200903172733.php new file mode 100644 index 00000000..5573f139 --- /dev/null +++ b/lib/Migration/Version0105Date20200903172733.php @@ -0,0 +1,77 @@ +<?php +/** + * @copyright Copyright (c) 2017 René Gieling <github@dartcafe.de> + * + * @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\Polls\Migration; + +use Doctrine\DBAL\Types\Type; +use OCP\DB\ISchemaWrapper; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Migration\SimpleMigrationStep; +use OCP\Migration\IOutput; + +/** + * Installation class for the polls app. + * Initial db creation + */ +class Version0105Date20200903172733 extends SimpleMigrationStep { + + /** @var IDBConnection */ + protected $connection; + + /** @var IConfig */ + protected $config; + + /** + * @param IDBConnection $connection + * @param IConfig $config + */ + public function __construct(IDBConnection $connection, IConfig $config) { + $this->connection = $connection; + $this->config = $config; + } + + /** + * @param IOutput $output + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + * @since 13.0.0 + */ + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + if ($schema->hasTable('polls_polls')) { + $table = $schema->getTable('polls_polls'); + if (!$table->hasColumn('important')) { + $table->addColumn('important', Type::INTEGER, [ + 'length' => 11, + 'notnull' => true, + 'default' => 0 + ]); + } + } + + return $schema; + } +} diff --git a/lib/Service/PollService.php b/lib/Service/PollService.php index 02e50d97..c75163db 100644 --- a/lib/Service/PollService.php +++ b/lib/Service/PollService.php @@ -175,6 +175,7 @@ class PollService { $this->poll->setShowResults('always'); $this->poll->setDeleted(0); $this->poll->setAdminAccess(0); + $this->poll->setImportant(0); $this->poll = $this->pollMapper->insert($this->poll); $this->logService->setLog($this->poll->getId(), 'addPoll'); @@ -298,6 +299,7 @@ class PollService { $this->poll->setOptions($origin->getOptions()); $this->poll->setShowResults($origin->getShowResults()); $this->poll->setAdminAccess($origin->getAdminAccess()); + $this->poll->setImportant($origin->getImportant()); return $this->pollMapper->insert($this->poll); } diff --git a/src/js/components/SideBar/SideBarTabConfiguration.vue b/src/js/components/SideBar/SideBarTabConfiguration.vue index aca08205..7cd7d766 100644 --- a/src/js/components/SideBar/SideBarTabConfiguration.vue +++ b/src/js/components/SideBar/SideBarTabConfiguration.vue @@ -72,6 +72,12 @@ type="radio" class="radio"> <label for="public">{{ t('polls', 'Visible to other users') }}</label> + + <input id="important" + v-model="pollImportant" + type="checkbox" + class="checkbox"> + <label for="important"> {{ t('polls', 'Relevant for all users') }}</label> </ConfigBox> <ConfigBox :title="t('polls', 'Result display')" icon-class="icon-screen"> @@ -210,6 +216,15 @@ export default { }, }, + pollImportant: { + get() { + return (this.poll.important > 0) + }, + set(value) { + this.writeValue({ important: value }) + }, + }, + pollAdminAccess: { get() { return (this.poll.adminAccess > 0) diff --git a/src/js/store/modules/poll.js b/src/js/store/modules/poll.js index 3a8b0f31..7ee4eec3 100644 --- a/src/js/store/modules/poll.js +++ b/src/js/store/modules/poll.js @@ -47,6 +47,7 @@ const defaultPoll = () => { voteLimit: 0, showResults: 'always', adminAccess: 0, + important: 0, } } diff --git a/src/js/store/modules/polls.js b/src/js/store/modules/polls.js index 719b6f26..232d7bf1 100644 --- a/src/js/store/modules/polls.js +++ b/src/js/store/modules/polls.js @@ -46,7 +46,8 @@ const getters = { return state.list.filter(poll => (poll.owner === getCurrentUser().uid && !poll.deleted)) } else if (filterId === 'relevant') { return state.list.filter(poll => (( - poll.userHasVoted + poll.important + || poll.userHasVoted || poll.isOwner || (poll.allowView && poll.access !== 'public') ) |