Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--appinfo/routes.php3
-rw-r--r--lib/Controller/PreferencesController.php45
-rw-r--r--lib/Db/PreferencesMapper.php14
-rw-r--r--lib/Service/CalendarService.php25
-rw-r--r--lib/Service/PreferencesService.php88
-rw-r--r--src/js/components/Settings/ExpertimantalSettings.vue22
-rw-r--r--src/js/components/Settings/FeatureSettings.vue65
-rw-r--r--src/js/components/Settings/SettingsDlg.vue12
-rw-r--r--src/js/store/modules/settings.js18
9 files changed, 236 insertions, 56 deletions
diff --git a/appinfo/routes.php b/appinfo/routes.php
index e69b3c50..5537eb4a 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -77,8 +77,7 @@ return [
['name' => 'preferences#write', 'url' => '/preferences/write', 'verb' => 'POST'],
['name' => 'preferences#get', 'url' => '/preferences/get', 'verb' => 'GET'],
-
- ['name' => 'integrations#get_circle_display_name', 'url' => '/circle/{circleId}/name', 'verb' => 'GET'],
+ ['name' => 'preferences#get_calendars', 'url' => '/calendars', 'verb' => 'GET'],
// REST-API calls
['name' => 'poll_api#list', 'url' => '/api/v1.0/polls', 'verb' => 'GET'],
diff --git a/lib/Controller/PreferencesController.php b/lib/Controller/PreferencesController.php
index 763ee342..293eedd6 100644
--- a/lib/Controller/PreferencesController.php
+++ b/lib/Controller/PreferencesController.php
@@ -30,28 +30,29 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCA\Polls\Db\Preferences;
-use OCA\Polls\Db\PreferencesMapper;
+use OCA\Polls\Service\PreferencesService;
+use OCA\Polls\Service\CalendarService;
class PreferencesController extends Controller {
- private $userId;
- private $preferencesMapper;
+ private $preferencesService;
+ private $calendarService;
/**
* PreferencesController constructor.
* @param string $appName
- * @param $UserId
- * @param PreferencesMapper $preferencesMapper
+ * @param PreferencesService $preferencesService
+ * @param CalendarService $calendarService
*/
public function __construct(
string $appName,
- $userId,
IRequest $request,
- PreferencesMapper $preferencesMapper
+ PreferencesService $preferencesService,
+ CalendarService $calendarService
) {
parent::__construct($appName, $request);
- $this->userId = $userId;
- $this->preferencesMapper = $preferencesMapper;
+ $this->preferencesService = $preferencesService;
+ $this->calendarService = $calendarService;
}
/**
@@ -63,7 +64,7 @@ class PreferencesController extends Controller {
*/
public function get() {
try {
- return new DataResponse($this->preferencesMapper->find($this->userId), Http::STATUS_OK);
+ return new DataResponse($this->preferencesService->get(), Http::STATUS_OK);
} catch (DoesNotExistException $e) {
return new DataResponse($e, Http::STATUS_NOT_FOUND);
}
@@ -82,18 +83,20 @@ class PreferencesController extends Controller {
}
try {
- $preferences = $this->preferencesMapper->find($this->userId);
- $preferences->setPreferences(json_encode($settings));
- $preferences->setTimestamp(time());
- $preferences = $this->preferencesMapper->update($preferences);
- } catch (\Exception $e) {
- $preferences = new Preferences();
- $preferences->setUserId($this->userId);
- $preferences->setPreferences(json_encode($settings));
- $preferences->setTimestamp(time());
- $preferences = $this->preferencesMapper->insert($preferences);
+ return new DataResponse($this->preferencesService->write($settings), Http::STATUS_OK);
+ } catch (DoesNotExistException $e) {
+ return new DataResponse($e, Http::STATUS_NOT_FOUND);
}
+ }
- return new DataResponse($preferences, Http::STATUS_OK);
+ /**
+ * get
+ * Read all preferences
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @return DataResponse
+ */
+ public function getCalendars() {
+ return new DataResponse(['calendars' => $this->calendarService->getCalendars()], Http::STATUS_OK);
}
}
diff --git a/lib/Db/PreferencesMapper.php b/lib/Db/PreferencesMapper.php
index 651e46d4..99af453c 100644
--- a/lib/Db/PreferencesMapper.php
+++ b/lib/Db/PreferencesMapper.php
@@ -56,18 +56,4 @@ class PreferencesMapper extends QBMapper {
return $this->findEntity($qb);
}
-
- // /**
- // * @param int $userId
- // */
- // public function delete($userId) {
- // $qb = $this->db->getQueryBuilder();
- //
- // $qb->delete($this->getTableName())
- // ->where(
- // $qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_INT))
- // );
- //
- // $qb->execute();
- // }
}
diff --git a/lib/Service/CalendarService.php b/lib/Service/CalendarService.php
index cb9bd29e..fe53e54f 100644
--- a/lib/Service/CalendarService.php
+++ b/lib/Service/CalendarService.php
@@ -30,11 +30,16 @@ use OCP\Calendar\IManager as CalendarManager;
class CalendarService {
private $calendarManager;
private $calendars;
+ private $preferencesService;
+ private $preferences;
public function __construct(
- CalendarManager $calendarManager
+ CalendarManager $calendarManager,
+ PreferencesService $preferencesService
) {
$this->calendarManager = $calendarManager;
+ $this->preferencesService = $preferencesService;
+ $this->preferences = $this->preferencesService->get();
$this->calendars = $this->calendarManager->getCalendars();
}
@@ -47,8 +52,13 @@ class CalendarService {
*/
public function getEvents($from, $to) {
$events = [];
-
foreach ($this->calendars as $calendar) {
+
+ // Skip not configured calendars
+ if (!in_array($calendar->getKey(), json_decode($this->preferences->getPreferences())->checkCalendars)) {
+ continue;
+ }
+
$foundEvents = $calendar->search('', ['SUMMARY'], ['timerange' => ['start' => $from, 'end' => $to]]);
foreach ($foundEvents as $event) {
array_push($events, [
@@ -78,6 +88,15 @@ class CalendarService {
* @return Array
*/
public function getCalendars() {
- return $this->calendars;
+ $calendars = [];
+ foreach ($this->calendars as $calendar) {
+ $calendars[] = [
+ 'name' => $calendar->getDisplayName(),
+ 'key' => $calendar->getKey(),
+ 'displayColor' => $calendar->getDisplayColor(),
+ 'permissions' => $calendar->getPermissions(),
+ ];
+ }
+ return $calendars;
}
}
diff --git a/lib/Service/PreferencesService.php b/lib/Service/PreferencesService.php
new file mode 100644
index 00000000..f03fd11e
--- /dev/null
+++ b/lib/Service/PreferencesService.php
@@ -0,0 +1,88 @@
+<?php
+/**
+ * @copyright Copyright (c) 2017 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\Polls\Service;
+
+use OCA\Polls\Exceptions\NotAuthorizedException;
+
+use OCA\Polls\Db\Preferences;
+use OCA\Polls\Db\PreferencesMapper;
+
+class PreferencesService {
+
+ /** @var PreferencesMapper */
+ private $preferencesMapper;
+
+ /** @var PreferencesMapper */
+ private $preferences;
+
+ /** @var String */
+ private $userId;
+
+ /**
+ * SystemService constructor.
+ * @param PreferencesMapper $preferencesMapper
+ */
+ public function __construct(
+ $UserId,
+ PreferencesMapper $preferencesMapper
+ ) {
+ $this->userId = $UserId;
+ $this->preferencesMapper = $preferencesMapper;
+ try {
+ $this->preferences = $this->preferencesMapper->find($this->userId);
+ } catch (\Exception $e) {
+ $this->preferences = new Preferences();
+ $preferences->setUserId($this->userId);
+ $preferences = $this->preferencesMapper->insert($preferences);
+ }
+ }
+ /**
+ * get
+ * Read all preferences
+ * @NoAdminRequired
+ * @NoCSRFRequired
+ * @return Preferences
+ */
+ public function get() {
+ return $this->preferences;
+ }
+
+ /**
+ * write
+ * Write references
+ * @NoAdminRequired
+ * @param array $settings
+ * @return Preferences
+ * @throws NotAuthorizedException
+ */
+ public function write($settings) {
+ if (!$this->userId) {
+ throw new NotAuthorizedException;
+ }
+
+ $this->preferences->setPreferences(json_encode($settings));
+ $this->preferences->setTimestamp(time());
+ return $this->preferencesMapper->update($this->preferences);
+ }
+}
diff --git a/src/js/components/Settings/ExpertimantalSettings.vue b/src/js/components/Settings/ExpertimantalSettings.vue
index 0d444b7d..a3782278 100644
--- a/src/js/components/Settings/ExpertimantalSettings.vue
+++ b/src/js/components/Settings/ExpertimantalSettings.vue
@@ -26,7 +26,7 @@
<input id="experimental" v-model="experimental"
type="checkbox" class="checkbox">
<label for="experimental">{{ t('polls', 'Try experimental styles') }}</label>
- <div class="settings_description">
+ <div class="settings_details">
{{ t('polls', 'Some experimental UI variants. Changes the background color of the main area.') }}
</div>
</div>
@@ -36,15 +36,12 @@
<input id="useImage" v-model="useImage"
type="checkbox" class="checkbox">
<label for="useImage">{{ t('polls', 'Use background image') }}</label>
- <div class="settings_description">
+ <div class="settings_details">
{{ t('polls', 'Add a background image to the main area.') }}
- </div>
- </div>
-
- <div class="user_settings">
- <input v-if="useImage" v-model="imageUrl" type="text">
- <div class="settings_description">
- {{ t('polls', 'Enter the URL of your favorite background image.') }}
+ <input v-if="useImage" v-model="imageUrl" type="text">
+ <div v-if="useImage">
+ {{ t('polls', 'Enter the URL of your favorite background image.') }}
+ </div>
</div>
</div>
@@ -52,7 +49,7 @@
<input id="glassyNavigation" v-model="glassyNavigation"
type="checkbox" class="checkbox">
<label for="glassyNavigation">{{ t('polls', 'Glassy navigation') }}</label>
- <div class="settings_description">
+ <div class="settings_details">
{{ t('polls', 'Blurrs the background of the navigation (Does not work with all browsers).') }}
</div>
</div>
@@ -61,7 +58,7 @@
<input id="glassySidebar" v-model="glassySidebar"
type="checkbox" class="checkbox">
<label for="glassySidebar">{{ t('polls', 'Glassy sidebar') }}</label>
- <div class="settings_description">
+ <div class="settings_details">
{{ t('polls', 'Blurrs the background of the sidebar (Does not work with all browsers).') }}
</div>
</div>
@@ -144,7 +141,8 @@ export default {
padding-top: 16px;
}
- .settings_description {
+ .settings_details {
padding-top: 8px;
+ margin-left: 26px;
}
</style>
diff --git a/src/js/components/Settings/FeatureSettings.vue b/src/js/components/Settings/FeatureSettings.vue
index e7e4e381..1d3a44f8 100644
--- a/src/js/components/Settings/FeatureSettings.vue
+++ b/src/js/components/Settings/FeatureSettings.vue
@@ -26,8 +26,21 @@
<input id="calendarPeek" v-model="calendarPeek"
type="checkbox" class="checkbox">
<label for="calendarPeek">{{ t('polls', 'Use calendar lookup') }}</label>
- <div class="settings_description">
+ <div class="settings_details">
{{ t('polls', 'Check, if an option in a date poll is conflicting with or near an entry in your calendar.') }}
+ {{ t('polls', 'Opt in to the calendars, which should be checked.') }}
+
+ <div v-for="(calendar) in calendarChoices" :key="calendar.key" class="calendar-item">
+ <input :id="'calendar_' + calendar.key"
+ v-model="calendar.selected"
+ type="checkbox"
+ class="checkbox"
+ @click="clickedCalendar(calendar)">
+ <label :for="'calendar_' + calendar.key" class="calendar-checkbox">
+ <span class="bully" :style="{ backgroundColor: calendar.displayColor }" />
+ <span>{{ calendar.name }}</span>
+ </label>
+ </div>
</div>
</div>
@@ -35,7 +48,7 @@
<input id="defaultViewTextPoll" v-model="defaultViewTextPoll"
type="checkbox" class="checkbox">
<label for="defaultViewTextPoll">{{ t('polls', 'Text polls default to list view') }}</label>
- <div class="settings_description">
+ <div class="settings_details">
{{ t('polls', 'Check this, if you prefer to display text poll in a vertical aligned list rather than in the grid view. The initial default is list view.') }}
</div>
</div>
@@ -44,7 +57,7 @@
<input id="defaultViewDatePoll" v-model="defaultViewDatePoll"
type="checkbox" class="checkbox">
<label for="defaultViewDatePoll">{{ t('polls', 'Date polls default to list view') }}</label>
- <div class="settings_description">
+ <div class="settings_details">
{{ t('polls', 'Check this, if you prefer to display date poll in a vertical view rather than in the grid view. The initial default is grid view.') }}
</div>
</div>
@@ -68,6 +81,7 @@ export default {
computed: {
...mapState({
settings: state => state.settings.user,
+ calendars: state => state.settings.availableCalendars,
}),
// Add bindings
calendarPeek: {
@@ -78,6 +92,25 @@ export default {
this.writeValue({ calendarPeek: value })
},
},
+
+ calendarChoices() {
+ var list = []
+ this.calendars.forEach((calendar) => {
+ // console.log(calendar.key.toString())
+ // console.log(this.settings.checkCalendars)
+ // console.log(this.settings.checkCalendars.includes(calendar.key.toString()))
+
+ list.push({
+ key: calendar.key.toString(),
+ name: calendar.name,
+ displayColor: calendar.displayColor,
+ selected: this.settings.checkCalendars.includes(calendar.key.toString()),
+ })
+ })
+
+ return list
+ },
+
defaultViewTextPoll: {
get() {
return (this.settings.defaultViewTextPoll === 'mobile')
@@ -109,6 +142,21 @@ export default {
this.$store.commit('settings/setPreference', value)
this.$store.dispatch('settings/write')
},
+
+ clickedCalendar(calendar) {
+ // console.log(calendar.key)
+ // console.log(checkCalendars)
+ if (this.settings.checkCalendars.includes(calendar.key)) {
+ // console.log(this.settings.checkCalendars)
+ // console.log('removed', this.settings.checkCalendars.filter(item => item !== calendar.key.toString()))
+ this.writeValue({ checkCalendars: this.settings.checkCalendars.filter(item => item !== calendar.key.toString()) })
+ } else {
+ this.$store.commit('settings/addCheckCalendar', { calendar: calendar })
+ // this.writeValue({ checkCalendars: checkCalendars })
+ }
+ // console.log(this.settings.checkCalendars)
+ this.$store.dispatch('settings/write')
+ },
},
}
</script>
@@ -118,7 +166,16 @@ export default {
padding-top: 16px;
}
- .settings_description {
+ .settings_details {
padding-top: 8px;
+ margin-left: 26px;
+ }
+
+ .bully {
+ display: inline-block;
+ width: 11px;
+ height: 11px;
+ border-radius: 50%;
+ margin: 0 4px 0 0;
}
</style>
diff --git a/src/js/components/Settings/SettingsDlg.vue b/src/js/components/Settings/SettingsDlg.vue
index aeafb472..fdce6178 100644
--- a/src/js/components/Settings/SettingsDlg.vue
+++ b/src/js/components/Settings/SettingsDlg.vue
@@ -52,9 +52,21 @@ export default {
data() {
return {
show: false,
+ calendars: [],
}
},
+ watch: {
+ show() {
+ if (this.show === true) {
+ this.$store.dispatch('settings/getCalendars')
+ .then((response) => {
+ this.calendars = response.data.calendars
+ })
+ }
+ },
+ },
+
created() {
subscribe('show-settings', () => {
this.show = true
diff --git a/src/js/store/modules/settings.js b/src/js/store/modules/settings.js
index 4fd933d3..29ab512b 100644
--- a/src/js/store/modules/settings.js
+++ b/src/js/store/modules/settings.js
@@ -28,6 +28,7 @@ const defaultSettings = () => {
user: {
experimental: false,
calendarPeek: false,
+ checkCalendars: [],
useImage: false,
imageUrl: '',
glassyNavigation: false,
@@ -35,6 +36,7 @@ const defaultSettings = () => {
defaultViewTextPoll: 'mobile',
defaultViewDatePoll: 'desktop',
},
+ availableCalendars: [],
viewModes: [
'mobile',
'desktop',
@@ -55,6 +57,12 @@ const mutations = {
state.user[key] = payload[key]
})
},
+ setCalendars(state, payload) {
+ state.availableCalendars = payload.calendars
+ },
+ addCheckCalendar(state, payload) {
+ state.user.checkCalendars.push(payload.calendar.key)
+ },
}
const actions = {
@@ -81,6 +89,16 @@ const actions = {
throw error
})
},
+
+ getCalendars(context) {
+ const endPoint = 'apps/polls/calendars'
+
+ return axios.get(generateUrl(endPoint))
+ .then((response) => {
+ context.commit('setCalendars', { calendars: response.data.calendars })
+ return response
+ })
+ },
}
export default { namespaced, state, mutations, actions }