-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Nextcloud Calendar widget #2287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nxdjib
wants to merge
1
commit into
lissy93:master
Choose a base branch
from
nxdjib:nextcloud-widget
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+569
−7
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,9 +45,36 @@ | |
| :options="boolRadioOptions" | ||
| :initialOption="form.ignoreErrors" | ||
| /> | ||
| <h4 class="options-heading"> | ||
| {{ $t('interactive-editor.edit-widget.options-heading') }} | ||
| </h4> | ||
|
|
||
| <div v-if="currentOptionDefinitions.length"> | ||
| <h4 class="options-heading">Calendar options</h4> | ||
| <div | ||
| class="row option-row" | ||
| v-for="option in currentOptionDefinitions" | ||
| :key="option.name" | ||
| > | ||
| <Input | ||
| v-if="option.type === 'text' || option.type === 'number' || option.type === 'password' | ||
| || option.type === 'text' | ||
| " | ||
| :type="option.type" | ||
| v-model="form.options[option.name]" | ||
| :label="option.label" | ||
| :description="option.description" | ||
| layout="horizontal" | ||
| /> | ||
| <Radio | ||
| v-else-if="option.type === 'boolean'" | ||
| v-model="form.options[option.name]" | ||
| :label="option.label" | ||
| :description="option.description" | ||
| :options="boolRadioOptions" | ||
| :initialOption="boolToStr(form.options[option.name])" | ||
| /> | ||
| </div> | ||
| </div> | ||
|
|
||
| <h4 class="options-heading">Additional options</h4> | ||
| <div class="row option-row" v-for="(opt, i) in optionRows" :key="i"> | ||
| <Input | ||
| v-model="opt.key" | ||
|
|
@@ -89,6 +116,7 @@ const emptyForm = () => ({ | |
| timeout: '', | ||
| useProxy: '', | ||
| ignoreErrors: '', | ||
| options: {}, | ||
| }); | ||
|
|
||
| /* Coerce a string from a free-form options input back to its likely native type. */ | ||
|
|
@@ -103,6 +131,55 @@ const coerceValue = (raw) => { | |
| return raw; | ||
| }; | ||
|
|
||
| const widgetOptionDefinitions = { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 'nextcloud-calendar': [ | ||
| { | ||
| name: 'icsUrl', | ||
| label: 'Calendar URL', | ||
| description: 'Public ICS export URL or shared calendar export URL.', | ||
| type: 'text', | ||
| }, | ||
| { | ||
| name: 'calendarId', | ||
| label: 'Calendar ID', | ||
| description: 'Nextcloud calendar ID for authenticated calendars.', | ||
| type: 'text', | ||
| }, | ||
| { | ||
| name: 'username', | ||
| label: 'Username', | ||
| description: 'Optional. Only required for private Nextcloud calendars that need authentication.', | ||
| type: 'text', | ||
| }, | ||
| { | ||
| name: 'password', | ||
| label: 'Password', | ||
| description: 'Optional. Use only with authenticated Nextcloud calendar access (app password or account password).', | ||
| type: 'password', | ||
| }, | ||
| { | ||
| name: 'pastDays', | ||
| label: 'Include recent past days', | ||
| description: 'Number of past days to show. Set 0 to show only future events.', | ||
| type: 'number', | ||
| }, | ||
| { | ||
| name: 'limit', | ||
| label: 'Event count', | ||
| description: 'Maximum upcoming events to display.', | ||
| type: 'number', | ||
| }, | ||
| { | ||
| name: 'taskLimit', | ||
| label: 'Task count', | ||
| description: 'Maximum tasks to display.', | ||
| type: 'number', | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const getWidgetOptionDefinitions = (widgetType) => widgetOptionDefinitions[(widgetType || '').toLowerCase()] || []; | ||
|
|
||
| export default { | ||
| name: 'EditWidget', | ||
| components: { | ||
|
|
@@ -127,6 +204,9 @@ export default { | |
| }, | ||
| computed: { | ||
| allowViewConfig() { return this.$store.getters.permissions.allowViewConfig; }, | ||
| currentOptionDefinitions() { | ||
| return getWidgetOptionDefinitions(this.form.type); | ||
| }, | ||
| }, | ||
| /* Populate form before children render so Radio's `initialOption` is set on its first creation. */ | ||
| created() { | ||
|
|
@@ -140,11 +220,20 @@ export default { | |
| timeout: widget.timeout ?? '', | ||
| useProxy: widget.useProxy === undefined ? '' : String(widget.useProxy), | ||
| ignoreErrors: widget.ignoreErrors === undefined ? '' : String(widget.ignoreErrors), | ||
| options: Object.fromEntries( | ||
| Object.entries(widget.options || {}).map(([key, value]) => [ | ||
| key, | ||
| typeof value === 'object' ? JSON.stringify(value) : String(value), | ||
| ]), | ||
| ), | ||
| }; | ||
| this.optionRows = Object.entries(widget.options || {}).map(([key, value]) => ({ | ||
| key, | ||
| value: typeof value === 'object' ? JSON.stringify(value) : String(value), | ||
| })); | ||
| const reservedKeys = getWidgetOptionDefinitions(widget.type || this.form.type).map((field) => field.name); | ||
| this.optionRows = Object.entries(widget.options || {}) | ||
| .filter(([key]) => !reservedKeys.includes(key)) | ||
| .map(([key, value]) => ({ | ||
| key, | ||
| value: typeof value === 'object' ? JSON.stringify(value) : String(value), | ||
| })); | ||
| }, | ||
| mounted() { | ||
| this.$modal.show(this.modalName); | ||
|
|
@@ -171,6 +260,11 @@ export default { | |
| if (this.form.ignoreErrors === 'true') widget.ignoreErrors = true; | ||
| else if (this.form.ignoreErrors === 'false') widget.ignoreErrors = false; | ||
| const options = {}; | ||
| Object.entries(this.form.options || {}).forEach(([key, value]) => { | ||
| if (value !== '' && value !== null && value !== undefined) { | ||
| options[key] = coerceValue(value); | ||
| } | ||
| }); | ||
| this.optionRows.forEach(({ key, value }) => { | ||
| const k = (key || '').trim(); | ||
| if (k) options[k] = coerceValue(value); | ||
|
|
@@ -202,6 +296,11 @@ export default { | |
| this.$toast.error('Error saving widget. See Logs.'); | ||
| } | ||
| }, | ||
| boolToStr(value) { | ||
| if (value === true || value === 'true') return 'true'; | ||
| if (value === false || value === 'false') return 'false'; | ||
| return ''; | ||
| }, | ||
| closeModal() { | ||
| this.$modal.hide(this.modalName); | ||
| }, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's happening here?
A widget code should never be in the generic form like this, it needs to be fully standalone. Otherwise everyone not using calendar widget is going to be loading unused code