Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85951523
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
68 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/components/settings_modal/helpers/attachment_setting.js b/src/components/settings_modal/helpers/attachment_setting.js
index cbcd4abf8d..56cc1b0d27 100644
--- a/src/components/settings_modal/helpers/attachment_setting.js
+++ b/src/components/settings_modal/helpers/attachment_setting.js
@@ -1,47 +1,43 @@
import Attachment from 'src/components/attachment/attachment.vue'
import MediaUpload from 'src/components/media_upload/media_upload.vue'
import Setting from './setting.js'
import { useInstanceStore } from 'src/stores/instance.js'
import { fileTypeExt } from 'src/services/file_type/file_type.service.js'
export default {
...Setting,
props: {
...Setting.props,
compact: Boolean,
acceptTypes: {
type: String,
required: false,
default: 'image/*',
},
},
components: {
...Setting.components,
MediaUpload,
Attachment,
},
computed: {
...Setting.computed,
attachment() {
- const path = this.realDraftMode ? this.draft : this.state
+ const path = this.visibleState
// The "server" part is primarily for local dev, but could be useful for alt-domain or multiuser usage.
const url = path.includes('://') ? path : useInstanceStore().server + path
return {
type: fileTypeExt(url),
url,
}
},
},
methods: {
...Setting.methods,
setMediaFile(fileInfo) {
- if (this.realDraftMode) {
- this.draft = fileInfo.url
- } else {
- this.configSink(this.path, fileInfo.url)
- }
+ this.visibleState = fileInfo.url
},
},
}
diff --git a/src/components/settings_modal/helpers/boolean_setting.vue b/src/components/settings_modal/helpers/boolean_setting.vue
index 6864aa4a59..e53c0ab845 100644
--- a/src/components/settings_modal/helpers/boolean_setting.vue
+++ b/src/components/settings_modal/helpers/boolean_setting.vue
@@ -1,46 +1,46 @@
<template>
<div
v-if="matchesExpertLevel"
class="BooleanSetting setting-item"
>
<span
class="setting-label"
:class="{ 'faint': shouldBeDisabled }"
>
<ModifiedIndicator
:changed="isChanged"
:onclick="reset"
/>
<LocalSettingIndicator :is-local="isLocalSetting" />
{{ ' ' }}
<label :for="idPrefix + 'checkbox'">
<template v-if="realLabel">
{{ realLabel }}
</template>
<template v-else-if="source === 'admin'">
MISSING LABEL FOR {{ path }}
</template>
<slot v-else />
</label>
</span>
<Checkbox
:id="idPrefix + 'checkbox'"
- class="setting-control"
v-model="visibleState"
+ class="setting-control"
:indeterminate="isIndeterminate"
:disabled="shouldBeDisabled"
/>
<p
v-if="realDescription"
class="setting-description"
:class="{ 'faint': shouldBeDisabled }"
>
<slot name="description">
{{ realDescription + ' ' }}
</slot>
</p>
<DraftButtons />
</div>
</template>
<script src="./boolean_setting.js"></script>
diff --git a/src/components/settings_modal/helpers/choice_setting.js b/src/components/settings_modal/helpers/choice_setting.js
index aad1e63caa..891d4d54ad 100644
--- a/src/components/settings_modal/helpers/choice_setting.js
+++ b/src/components/settings_modal/helpers/choice_setting.js
@@ -1,54 +1,48 @@
import Select from 'src/components/select/select.vue'
import Setting from './setting.js'
export default {
...Setting,
components: {
...Setting.components,
Select,
},
props: {
...Setting.props,
overrideOptions: {
type: Boolean,
required: false,
},
options: {
type: Array,
required: false,
},
optionLabelMap: {
type: Object,
required: false,
default: {},
},
},
computed: {
...Setting.computed,
realOptions() {
if (this.overrideOptions) {
return this.options
}
if (this.realSource === 'admin') {
if (
!this.realSuggestions?.length ||
this.realSuggestions?.length === 0
) {
return this.options
}
return this.realSuggestions.map((x) => ({
key: x,
value: x,
label: this.optionLabelMap[x] || x,
}))
}
return this.options
},
},
- methods: {
- ...Setting.methods,
- getValue(e) {
- return e
- },
- },
}
diff --git a/src/components/settings_modal/helpers/color_setting.vue b/src/components/settings_modal/helpers/color_setting.vue
index 6e0f137653..72c774beb0 100644
--- a/src/components/settings_modal/helpers/color_setting.vue
+++ b/src/components/settings_modal/helpers/color_setting.vue
@@ -1,72 +1,71 @@
<template>
<label
v-if="matchesExpertLevel"
class="ColorSetting setting-item"
>
<label
v-if="!hideLabel"
- :for="path"
+ :for="idPrefix + 'color'"
class="setting-label"
:class="{ 'faint': shouldBeDisabled }"
>
<template v-if="realLabel">
{{ realLabel + ' ' }}
</template>
<template v-else-if="source === 'admin'">
MISSING LABEL FOR {{ path }}
</template>
<slot v-else />
</label>
{{ ' ' }}
<ColorInput
- :id="path"
+ v-model="visibleState"
+ :id="idPrefix + 'color'"
:name="path"
class="setting-control color-setting-input"
:class="{ disabled: shouldBeDisabled }"
:disabled="shouldBeDisabled"
:placeholder="realSuggestions"
- :model-value="realDraftMode ? draft : state"
- @update:model-value="update"
/>
{{ ' ' }}
<ModifiedIndicator
:changed="isChanged"
:onclick="reset"
/>
<LocalSettingIndicator :is-local="isLocalSetting" />
<DraftButtons v-if="!hideDraftButtons" />
<p
v-if="realDescription"
class="setting-description"
:class="{ 'faint': shouldBeDisabled }"
>
{{ realDescription + ' ' }}
</p>
</label>
</template>
<script src="./color_setting.js"></script>
<style lang="scss">
.ColorSetting {
&.setting-item {
display: grid;
grid-template-areas:
"label control"
". desc"
". draft";
.setting-label {
text-align: right;
align-self: center;
}
.setting-control {
align-self: end;
}
}
.color-setting-input {
align-self: baseline;
}
}
</style>
diff --git a/src/components/settings_modal/helpers/list_setting.js b/src/components/settings_modal/helpers/list_setting.js
index 8e2ea0e512..15e2dfb1b9 100644
--- a/src/components/settings_modal/helpers/list_setting.js
+++ b/src/components/settings_modal/helpers/list_setting.js
@@ -1,135 +1,143 @@
import Checkbox from 'src/components/checkbox/checkbox.vue'
import Setting from './setting.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
export default {
...Setting,
data() {
return {
+ extraEntries: [],
newValue: '',
}
},
components: {
...Setting.components,
Checkbox,
},
props: {
...Setting.props,
ignoreSuggestions: {
required: false,
type: Boolean,
},
overrideAvailableOptions: {
required: false,
type: Boolean,
},
options: {
required: false,
type: Set,
},
allowNew: {
required: false,
type: Boolean,
default: true,
},
forceNew: {
required: false,
type: Boolean,
default: false,
},
},
computed: {
...Setting.computed,
showNew() {
if (this.forceNew) return true
if (!this.allowNew) return false
const isExpert = useMergedConfigStore().mergedConfig.expertLevel > 0
const hasBuiltins = this.builtinEntries.length > 0
if (hasBuiltins) {
return isExpert
} else {
return true
}
},
valueSet() {
return new Set(this.visibleState)
},
suggestionsSet() {
const suggestions = this.realSuggestions
if (suggestions) {
return new Set(suggestions)
} else {
return new Set()
}
},
- extraEntries() {
- if (this.ignoreSuggestions) return [...this.valueSet.values()]
- if (!this.suggestionsSet) return []
- return [...this.valueSet.values()].filter((x) => {
- return !this.builtinEntriesValueSet.has(x)
- })
- },
builtinEntries() {
if (this.ignoreSuggestions) return []
if (this.overrideAvailableOptions) {
return [...this.options]
}
if (!this.suggestionsSet) return []
const builtins = [...this.suggestionsSet.values()]
return builtins.map((option) => ({
label: option,
value: option,
}))
},
builtinEntriesValueSet() {
return new Set(this.builtinEntries.map((x) => x.value))
},
+ builtinEntriesSelected() {
+ return new Set(
+ this.builtinEntriesValueSet.values().filter((x) => {
+ return this.valueSet.has(x)
+ }),
+ )
+ },
+ newValid() {
+ return Boolean(this.newValue)
+ },
},
methods: {
...Setting.methods,
optionPresent(option) {
return this.valueSet.has(option)
},
- getValue({ event, value, index, eventType }) {
- switch (eventType) {
- case 'toggle': {
- this.newValue = ''
- const newSet = new Set(this.valueSet.values())
- if (event) {
- newSet.add(value)
- } else {
- newSet.delete(value)
- }
- return [...newSet.values()]
- }
-
- case 'add': {
- if (!this.newValue) return this.valueSet.values()
- const res = [...this.valueSet.values(), this.newValue]
- this.newValue = ''
- return res
- }
-
- case 'remove': {
- const pre = [...this.valueSet.values()].slice(0, index)
- const post = [...this.valueSet.values()].slice(index + 1)
-
- return [...pre, ...post]
- }
-
- case 'edit': {
- const pre = [...this.valueSet.values()].slice(0, index)
- const post = [...this.valueSet.values()].slice(index + 1)
- const string = event.target.value
- if (!string) return [...this.valueSet.values()]
-
- return [...pre, string, ...post]
- }
+ resetNew() {
+ this.newValue = ''
+ },
+ getValue(e) {
+ return e
+ },
+ update() {
+ this.visibleState = [
+ ...this.builtinEntriesSelected.values(),
+ ...this.extraEntries,
+ ]
+ },
+ toggle(event, value) {
+ const newSet = new Set(this.builtinEntriesSelected)
+ if (event) {
+ newSet.add(value)
+ } else {
+ newSet.delete(value)
}
+ this.visibleState = [...newSet.values(), ...this.extraEntries]
+ },
+ add() {
+ if (!this.newValid) return
+ this.extraEntries = [...this.extraEntries, this.newValue]
+ this.update()
+ this.resetNew()
+ },
+ remove(index) {
+ const pre = [...this.extraEntries].slice(0, index)
+ const post = [...this.extraEntries].slice(index + 1)
+ this.extraEntries = [...pre, ...post]
+ this.update()
+ },
+ edit(event, index) {
+ const string = event.target.value
+ if (!string) return
+ const pre = [...this.extraEntries].slice(0, index)
+ const post = [...this.extraEntries].slice(index + 1)
+ this.extraEntries = [...pre, string, ...post]
+ this.update()
},
},
}
diff --git a/src/components/settings_modal/helpers/list_setting.vue b/src/components/settings_modal/helpers/list_setting.vue
index 96fb880023..eb0c7b5528 100644
--- a/src/components/settings_modal/helpers/list_setting.vue
+++ b/src/components/settings_modal/helpers/list_setting.vue
@@ -1,100 +1,100 @@
<template>
<fieldset
v-if="matchesExpertLevel"
class="ListSetting setting-item"
>
<legend
class="setting-label"
:class="{ 'faint': shouldBeDisabled }"
>
<template v-if="realLabel">
{{ realLabel + ' ' }}
</template>
<template v-else-if="source === 'admin'">
MISSING LABEL FOR {{ path }}
</template>
<slot v-else />
</legend>
<p
v-if="realDescription"
class="setting-description"
:class="{ 'faint': shouldBeDisabled }"
>
{{ realDescription + ' ' }}
</p>
<ul class="setting-list">
<li
v-for="(item, i) in builtinEntries"
:key="i"
>
<Checkbox
:disabled="shouldBeDisabled"
:model-value="optionPresent(item.value)"
- @update:model-value="event => update({ event, value: item.value, eventType: 'toggle' })"
+ @update:model-value="event => toggle(event, item.value)"
>
{{ item.label }}
</Checkbox>
</li>
<li
v-for="(item, index) in extraEntries"
:key="index"
>
<div class="btn-group">
<input
class="input string-input"
:class="{ disabled: shouldBeDisabled }"
:value="item"
- @change="e => update({ event: e, index, eventType: 'edit' })"
+ @change="event => edit(event, index)"
>
<button
class="button-default"
- @click="e => update({ index, eventType: 'remove' })"
+ @click="e => remove(index)"
>
<FAIcon icon="times" />
</button>
</div>
</li>
<li v-if="showNew">
<div class="btn-group">
<input
v-model="newValue"
class="input string-input"
:class="{ disabled: shouldBeDisabled }"
:disabled="shouldBeDisabled"
>
<button
class="button-default"
- @click="e => update({ eventType: 'add' })"
+ @click="e => add()"
>
<FAIcon icon="plus" />
</button>
</div>
</li>
</ul>
<ModifiedIndicator
:changed="isChanged"
:onclick="reset"
/>
<LocalSettingIndicator :is-local="isLocalSetting" />
<DraftButtons />
</fieldset>
</template>
<script src="./list_setting.js"></script>
<style lang="scss">
.ListSetting {
border: none;
margin: 0;
legend {
float: left;
}
.setting-list {
align-self: center;
display: flex;
flex-direction: column;
gap: 0.5em;
}
}
</style>
diff --git a/src/components/settings_modal/helpers/list_tuple_setting.js b/src/components/settings_modal/helpers/list_tuple_setting.js
index 33cc725b12..05f98c44b5 100644
--- a/src/components/settings_modal/helpers/list_tuple_setting.js
+++ b/src/components/settings_modal/helpers/list_tuple_setting.js
@@ -1,44 +1,37 @@
import ListSetting from './list_setting.js'
export default {
...ListSetting,
data() {
return {
newValue: ['', ''],
}
},
+ computed: {
+ ...ListSetting.computed,
+ newValid() {
+ return Boolean(this.newValue[0]) && Boolean(this.newValue[1])
+ },
+ },
methods: {
...ListSetting.methods,
- getValue({ event, index, eventType, tuple }) {
- switch (eventType) {
- case 'add': {
- if (!this.newValue[0] || !this.newValue[1]) return this.visibleState
- const res = [...this.visibleState, this.newValue]
- this.newValue = ['', '']
- return res
- }
-
- case 'remove': {
- const pre = this.visibleState.slice(0, index)
- const post = this.visibleState.slice(index + 1)
-
- return [...pre, ...post]
- }
+ resetNew() {
+ this.newValue = ['', '']
+ },
+ edit(event, index, tuple) {
+ const string = event.target.value
+ if (!string) return
- case 'edit': {
- const pre = this.visibleState.slice(0, index)
- const post = this.visibleState.slice(index + 1)
- const item = this.visibleState[index]
- const string = event.target.value
- if (!string) return this.visibleState
+ const pre = this.extraEntries.slice(0, index)
+ const post = this.extraEntries.slice(index + 1)
+ const item = this.extraEntries[index]
- if (tuple === 0) {
- return [...pre, [string, item[1]], ...post]
- } else {
- return [...pre, [item[0], string], ...post]
- }
- }
+ if (tuple === 0) {
+ this.extraEntries = [...pre, [string, item[1]], ...post]
+ } else {
+ this.extraEntries = [...pre, [item[0], string], ...post]
}
+ this.update()
},
},
}
diff --git a/src/components/settings_modal/helpers/list_tuple_setting.vue b/src/components/settings_modal/helpers/list_tuple_setting.vue
index 41403997b5..96d4541c76 100644
--- a/src/components/settings_modal/helpers/list_tuple_setting.vue
+++ b/src/components/settings_modal/helpers/list_tuple_setting.vue
@@ -1,116 +1,116 @@
<template>
<fieldset
v-if="matchesExpertLevel"
class="ListTupleSetting"
>
<legend
class="setting-label"
:class="{ 'faint': shouldBeDisabled }"
>
<template v-if="realLabel">
{{ realLabel + ' ' }}
</template>
<template v-else-if="source === 'admin'">
MISSING LABEL FOR {{ path }}
</template>
<slot v-else />
</legend>
<p
v-if="realDescription"
class="setting-description"
:class="{ 'faint': shouldBeDisabled }"
>
{{ realDescription + ' ' }}
</p>
<ul class="setting-list">
<li
v-for="(item, index) in visibleState"
:key="index"
>
<div class="btn-group">
<input
class="input string-input"
:class="{ disabled: shouldBeDisabled }"
:value="item.tuple[0]"
:title="realSuggestions[0][0]"
- @change="e => update({ event: e, index, eventType: 'edit', tuple: 0 })"
+ @change="event => edit(event, index, 0)"
>
<input
class="input string-input"
:class="{ disabled: shouldBeDisabled }"
:value="item.tuple[1]"
:title="realSuggestions[0][1]"
- @change="e => update({ event: e, index, eventType: 'edit', tuple: 1 })"
+ @change="event => edit(event, index, 1)"
>
<button
class="button-default"
- @click="e => update({ index, eventType: 'remove' })"
+ @click="e => remove(index)"
>
<FAIcon icon="times" />
</button>
</div>
</li>
<li>
<div class="btn-group">
<input
v-model="newValue[0]"
class="input string-input"
:class="{ disabled: shouldBeDisabled }"
:disabled="shouldBeDisabled"
:placeholder="realSuggestions[0][0]"
:title="realSuggestions[0][0]"
>
<input
v-model="newValue[1]"
class="input string-input"
:class="{ disabled: shouldBeDisabled }"
:disabled="shouldBeDisabled"
:placeholder="realSuggestions[0][1]"
:title="realSuggestions[0][1]"
>
<button
class="button-default"
- @click="e => update({ eventType: 'add' })"
+ @click="e => add()"
>
<FAIcon icon="plus" />
</button>
</div>
</li>
</ul>
<ModifiedIndicator
:changed="isChanged"
:onclick="reset"
/>
<DraftButtons />
</fieldset>
</template>
<script src="./list_tuple_setting.js"></script>
<style lang="scss">
.ListTupleSetting {
.btn-group {
display: flex
}
dl {
display: inline-grid;
grid-template-columns: auto auto;
gap: 0.5em;
align-items: baseline;
dt {
display: inline;
font-weight: 800;
&::after {
content: ':'
}
}
dd {
display: inline;
margin: 0
}
}
}
</style>
diff --git a/src/components/settings_modal/helpers/map_setting.js b/src/components/settings_modal/helpers/map_setting.js
index 8615c90ca9..86c89e80b3 100644
--- a/src/components/settings_modal/helpers/map_setting.js
+++ b/src/components/settings_modal/helpers/map_setting.js
@@ -1,73 +1,71 @@
import Setting from './setting.js'
export default {
...Setting,
props: {
...Setting.props,
allowNew: {
required: false,
type: Boolean,
default: true,
},
},
data() {
return {
newValue: ['', ''], // avoiding extra complexity by just using an array instead of an object
}
},
computed: {
...Setting.computed,
// state that we'll show in the UI, i.e. transforming map into list
displayState() {
return Object.entries(this.visibleState)
},
},
methods: {
...Setting.methods,
- getValue({ event, key, eventType, isKey }) {
- switch (eventType) {
- case 'add': {
- if (key === '') return this.visibleState
- const res = {
- ...this.visibleState,
- ...Object.fromEntries([this.newValue]),
- }
- this.newValue = ['', '']
- return res
- }
-
- case 'remove': {
- // initial state for this type is empty array
- if (Array.isArray(this.visibleState)) return this.visibleState
- const newEntries = Object.entries(this.visibleState).filter(
- ([k]) => k !== key,
- )
+ getValue(e) {
+ return e
+ },
+ add() {
+ this.visibleSate = {
+ ...this.visibleState,
+ ...Object.fromEntries([this.newValue]),
+ }
+ this.newValue = ['', '']
+ },
+ remove(key) {
+ // initial state for this type is empty array
+ if (Array.isArray(this.visibleState)) return
+ const newEntries = Object.entries(this.visibleState).filter(
+ ([k]) => k !== key,
+ )
- if (newEntries.length === 0) return []
- return Object.fromEntries(newEntries)
+ if (newEntries.length === 0) {
+ this.visibleState = []
+ } else {
+ this.visibleState = Object.fromEntries(newEntries)
+ }
+ },
+ edit({ event, key, isKey }) {
+ const string = event.target.value
+ const newEntries = Object.entries(this.visibleState).map(([k, v]) => {
+ if (isKey) {
+ if (k === key) {
+ return [string, v]
+ } else {
+ return [k, v]
+ }
+ } else {
+ if (k === key) {
+ return [k, string]
+ } else {
+ return [k, v]
+ }
}
+ })
- case 'edit': {
- const string = event.target.value
- const newEntries = Object.entries(this.visibleState).map(([k, v]) => {
- if (isKey) {
- if (k === key) {
- return [string, v]
- } else {
- return [k, v]
- }
- } else {
- if (k === key) {
- return [k, string]
- } else {
- return [k, v]
- }
- }
- })
-
- return Object.fromEntries(newEntries)
- }
- }
+ this.visibleState = Object.fromEntries(newEntries)
},
},
}
diff --git a/src/components/settings_modal/helpers/map_setting.vue b/src/components/settings_modal/helpers/map_setting.vue
index 092e588575..867c8b0540 100644
--- a/src/components/settings_modal/helpers/map_setting.vue
+++ b/src/components/settings_modal/helpers/map_setting.vue
@@ -1,116 +1,116 @@
<template>
<fieldset
v-if="matchesExpertLevel"
class="MapSetting setting-item"
>
<legend
class="setting-label"
:class="{ 'faint': shouldBeDisabled }"
>
<template v-if="realLabel">
{{ realLabel + ' ' }}
</template>
<template v-else-if="source === 'admin'">
MISSING LABEL FOR {{ path }}
</template>
<slot v-else />
</legend>
<p
v-if="realDescription"
class="setting-description"
:class="{ 'faint': shouldBeDisabled }"
>
{{ realDescription + ' ' }}
</p>
<ul class="setting-list">
<li
v-for="(item, i) in displayState"
:key="i"
>
<div class="btn-group">
<input
class="input string-input"
:class="{ disabled: shouldBeDisabled }"
:value="item[0]"
:title="realSuggestions[0][0]"
- @change="e => update({ event: e, key: item[0], eventType: 'edit', isKey: true })"
+ @change="event => edit({ event, key: item[0], isKey: true })"
>
<input
class="input string-input"
:class="{ disabled: shouldBeDisabled }"
:value="item[1]"
:title="realSuggestions[0][1]"
- @change="e => update({ event: e, key: item[0], eventType: 'edit', isKey: false })"
+ @change="event => edit({ event, key: item[0], isKey: false })"
>
<button
class="button-default"
- @click="e => update({ key: item[0], eventType: 'remove' })"
+ @click="e => remove(item[0])"
>
<FAIcon icon="times" />
</button>
</div>
</li>
<li v-if="allowNew">
<div class="btn-group">
<input
v-model="newValue[0]"
class="input string-input"
:class="{ disabled: shouldBeDisabled }"
:disabled="shouldBeDisabled"
:placeholder="realSuggestions[0][0]"
:title="realSuggestions[0][0]"
>
<input
v-model="newValue[1]"
class="input string-input"
:class="{ disabled: shouldBeDisabled }"
:disabled="shouldBeDisabled"
:placeholder="realSuggestions[0][1]"
:title="realSuggestions[0][1]"
>
<button
class="button-default"
- @click="e => update({ eventType: 'add' })"
+ @click="add"
>
<FAIcon icon="plus" />
</button>
</div>
</li>
</ul>
<ModifiedIndicator
:changed="isChanged"
:onclick="reset"
/>
<LocalSettingIndicator :is-local="isLocalSetting" />
<DraftButtons />
</fieldset>
</template>
<script src="./map_setting.js"></script>
<style lang="scss">
.MapSetting {
.btn-group {
display: flex
}
dl {
display: inline-grid;
grid-template-columns: auto auto;
gap: 0.5em;
dt {
display: inline;
font-weight: 800;
&::after {
content: ':'
}
}
dd {
display: inline;
margin: 0
}
}
}
</style>
diff --git a/src/components/settings_modal/helpers/proxy_setting.js b/src/components/settings_modal/helpers/proxy_setting.js
index 4195b8430f..459781506a 100644
--- a/src/components/settings_modal/helpers/proxy_setting.js
+++ b/src/components/settings_modal/helpers/proxy_setting.js
@@ -1,54 +1,44 @@
import Checkbox from 'src/components/checkbox/checkbox.vue'
import Setting from './setting.js'
-const getUrl = (state) =>
- state?.tuple ? state.tuple[1] + ':' + state.tuple[2] : state
-const getSocks = (state) => state?.tuple
-
export default {
...Setting,
- data() {
- return {
- urlField: '',
- socksField: false,
- }
- },
- created() {
- Setting.created()
- this.urlField = getUrl(this.realDraftMode ? this.draft : this.state)
- this.socksField = getSocks(this.realDraftMode ? this.draft : this.state)
- },
computed: {
...Setting.computed,
- // state that we'll show in the UI, i.e. transforming map into list
- displayState() {
- if (this.visibleState?.tuple) {
- return this.visibleState.tuple[1] + ':' + this.visibleState.tuple[2]
- }
- return this.visibleState
+ urlField: {
+ get() {
+ if (this.visibleState?.tuple) {
+ return this.visibleState.tuple[1] + ':' + this.visibleState.tuple[2]
+ } else {
+ return this.visibleState
+ }
+ },
+ set(e) {
+ const string = e.target.value
+ if (this.socksField) {
+ this.visibleState = { tuple: [':socks5', ...string.split(':')] }
+ } else {
+ this.visibleState = string
+ }
+ },
},
- socksState() {
- return getSocks(this.visibleState)
+ socksField: {
+ get() {
+ return this.visibleState?.tuple
+ },
+ set(e) {
+ if (e) {
+ this.visibleState = {
+ tuple: [':socks5', ...this.urlField.split(':')],
+ }
+ } else {
+ this.visibleState = this.urlField
+ }
+ },
},
},
components: {
...Setting.components,
Checkbox,
},
- methods: {
- ...Setting.methods,
- getValue({ event, isProxy }) {
- if (isProxy) {
- this.socksField = event
- } else {
- this.urlField = event.target.value
- }
-
- if (this.socksField) {
- return { tuple: [':socks5', ...this.urlField.split(':')] }
- } else {
- return this.urlField
- }
- },
- },
}
diff --git a/src/components/settings_modal/helpers/proxy_setting.vue b/src/components/settings_modal/helpers/proxy_setting.vue
index 8ba23d68de..d2852fed17 100644
--- a/src/components/settings_modal/helpers/proxy_setting.vue
+++ b/src/components/settings_modal/helpers/proxy_setting.vue
@@ -1,60 +1,59 @@
<template>
<label
v-if="matchesExpertLevel"
class="ProxySetting setting-item"
>
<label
v-if="!hideLabel"
:for="idPrefix + 'input'"
:id="idPrefix + 'label'"
class="setting-label"
:class="{ 'faint': shouldBeDisabled }"
>
<template v-if="realLabel">
{{ realLabel + ' ' }}
</template>
<template v-else-if="source === 'admin'">
MISSING LABEL FOR {{ path }}
</template>
<slot v-else />
</label>
{{ ' ' }}
<div class="setting-control">
<input
:id="idPrefix + 'input'"
+ v-model="urlField"
class="input string-input"
:class="{ disabled: shouldBeDisabled }"
:disabled="shouldBeDisabled"
:placeholder="realSuggestions[0]"
:value="displayState"
- @change="event => update({ event })"
>
{{ ' ' }}
<Checkbox
- :model-value="socksState"
+ v-model="socksField"
:disabled="shouldBeDisabled"
:indeterminate="isIndeterminate"
style="margin-left: 1em"
- @update:model-value="event => update({ event, isProxy: true})"
>
SOCKS5
{{ ' ' }}
</Checkbox>
</div>
{{ ' ' }}
<ModifiedIndicator
:changed="isChanged"
:onclick="reset"
/>
<DraftButtons v-if="!hideDraftButtons" />
<p
v-if="realDescription"
class="setting-description"
:class="{ 'faint': shouldBeDisabled }"
>
{{ realDescription + ' ' }}
</p>
</label>
</template>
<script src="./proxy_setting.js"></script>
diff --git a/src/components/settings_modal/helpers/pwa_manifest_icons_setting.js b/src/components/settings_modal/helpers/pwa_manifest_icons_setting.js
index 892a61c25b..76ecd45ec5 100644
--- a/src/components/settings_modal/helpers/pwa_manifest_icons_setting.js
+++ b/src/components/settings_modal/helpers/pwa_manifest_icons_setting.js
@@ -1,102 +1,92 @@
import { clone } from 'lodash-es'
import Attachment from 'src/components/attachment/attachment.vue'
import MediaUpload from 'src/components/media_upload/media_upload.vue'
import Select from 'src/components/select/select.vue'
import Setting from './setting.js'
import { useInstanceStore } from 'src/stores/instance.js'
import { fileTypeExt } from 'src/services/file_type/file_type.service.js'
export default {
...Setting,
components: {
...Setting.components,
Select,
Attachment,
MediaUpload,
},
computed: {
...Setting.computed,
purposeOptions() {
return ['any', 'monochrome', 'maskable'].map((value) => ({
value,
key: value,
label: this.$t('admin_dash.instance.pwa.icon.' + value),
}))
},
},
methods: {
...Setting.methods,
attachment(e) {
const path = e[':src']
if (!path) {
return {
type: '',
url: '',
}
}
const url = path.includes('://') ? path : useInstanceStore().server + path
return {
type: fileTypeExt(url),
url,
}
},
setMediaFile({ event, index }) {
- this.update({
- event: {
+ this.update(
+ {
target: {
value: event.url,
},
},
- index,
- eventType: 'edit',
- field: ':src',
- })
+ ':src',
+ )
},
setPurpose({ event, index }) {
- this.update({
- event: {
+ this.edit(
+ {
target: {
value: event,
},
},
index,
- eventType: 'edit',
- field: ':purpose',
- })
+ ':purpose',
+ )
},
- getValue({ event, field, index, eventType }) {
- switch (eventType) {
- case 'add': {
- const res = [...this.visibleState, {}]
- return res
- }
-
- case 'remove': {
- const pre = this.visibleState.slice(0, index)
- const post = this.visibleState.slice(index + 1)
-
- return [...pre, ...post]
- }
-
- case 'edit': {
- const pre = this.visibleState.slice(0, index)
- const post = this.visibleState.slice(index + 1)
- const item = clone(this.visibleState[index])
- const string = event.target.value
+ add() {
+ this.visibleState = [...this.visibleState, {}]
+ },
+ remove(index) {
+ const pre = this.visibleState.slice(0, index)
+ const post = this.visibleState.slice(index + 1)
- if (!string) {
- delete item[field]
- } else {
- item[field] = string
- }
+ this.visibleState = [...pre, ...post]
+ },
+ edit(event, field, index) {
+ const string = event.target.value
+ const pre = this.visibleState.slice(0, index)
+ const post = this.visibleState.slice(index + 1)
+ const item = clone(this.visibleState[index])
- return [...pre, item, ...post]
- }
+ if (!string) {
+ delete item[field]
+ } else {
+ item[field] = string
}
+
+ this.visibleState = [...pre, item, ...post]
},
},
}
diff --git a/src/components/settings_modal/helpers/pwa_manifest_icons_setting.vue b/src/components/settings_modal/helpers/pwa_manifest_icons_setting.vue
index 1b80b7ec81..e105525ed1 100644
--- a/src/components/settings_modal/helpers/pwa_manifest_icons_setting.vue
+++ b/src/components/settings_modal/helpers/pwa_manifest_icons_setting.vue
@@ -1,236 +1,236 @@
<template>
<fieldset
v-if="matchesExpertLevel"
class="PWAManifestIconsSetting setting-item"
>
<legend
class="pwa-label setting-label"
:class="{ 'faint': shouldBeDisabled }"
>
<ModifiedIndicator
:changed="isChanged"
:onclick="reset"
/>
{{ ' ' }}
<template v-if="realLabel">
{{ realLabel + ' ' }}
</template>
<template v-else-if="source === 'admin'">
MISSING LABEL FOR {{ path }}
</template>
<slot v-else />
</legend>
<p
v-if="realDescription"
class="setting-description"
:class="{ 'faint': shouldBeDisabled }"
>
{{ realDescription + ' ' }}
</p>
<div class="setting-control">
<ul class="item-list">
<li
v-if="visibleState.length === 0"
class="no_items"
>
{{ $t('admin_dash.instance.pwa.no_icons') }}
<button
v-if="visibleState.length === 0"
class="button-default add-button"
- @click="e => update({ eventType: 'add' })"
+ @click="e => add()"
>
<FAIcon icon="plus" />
</button>
</li>
<li
v-for="(item, index) in visibleState"
:key="index"
>
<div class="icon-element">
<div class="src-field">
<Attachment
class="src-attachment"
:compact="true"
:attachment="attachment(item)"
size="small"
hide-description
/>
<div class="src-url">
<label :for="idPrefix + 'url' + index">{{ $t('settings.url') }}</label>
<input
:id="idPrefix + 'url' + index"
class="input string-input"
:disabled="shouldBeDisabled"
:value="item[':src']"
- @change="event => update({ event, index, eventType: 'edit', field: ':src' })"
+ @change="event => edit(event, index, ':src')"
>
</div>
<MediaUpload
ref="mediaUpload"
class="src-upload media-upload-icon"
:class="{ disabled: shouldBeDisabled }"
normal-button
accept-types="image"
@uploaded="event => setMediaFile({ event, index })"
/>
</div>
<dl>
<dt>{{ $t('admin_dash.instance.pwa.icon.purpose') }}</dt>
<dd>
<Select
:id="idPrefix + 'purpose' + index"
:class="{ disabled: shouldBeDisabled }"
:disabled="shouldBeDisabled"
:model-value="item[':purpose']"
@update:model-value="event => setPurpose({ event, index })"
>
<option
v-for="(purpose, index2) in purposeOptions"
:key="index2"
:value="purpose.value"
>
{{ purpose.label }}
</option>
</Select>
</dd>
<dt>
<label :for="idPrefix + 'sizes' + index">
<code>sizes</code>{{ $t('admin_dash.instance.pwa.optional') }}
</label>
</dt>
<dd>
<input
:id="idPrefix + 'sizes' + index"
class="input string-input"
:class="{ disabled: shouldBeDisabled }"
:value="item[':sizes']"
- @change="e => update({ event: e, index, eventType: 'edit', field: ':sizes' })"
+ @change="e => edit(event, index, ':sizes')"
>
</dd>
<dt>
<label :for="idPrefix + 'type' + index">
<code>type</code>{{ $t('admin_dash.instance.pwa.optional') }}
</label>
</dt>
<dd>
<input
:id="idPrefix + 'type' + index"
class="input string-input"
:class="{ disabled: shouldBeDisabled }"
:value="item[':type']"
- @change="e => update({ event: e, index, eventType: 'edit', field: ':type' })"
+ @change="e => edit(event, index, ':type')"
>
</dd>
</dl>
<div class="buttons">
<button
v-if="index === visibleState.length - 1"
class="button-default add-button"
- @click="e => update({ eventType: 'add' })"
+ @click="e => add()"
>
<FAIcon icon="plus" />
</button>
<button
class="button-default delete-button"
- @click="e => update({ index, eventType: 'remove' })"
+ @click="e => remove(index)"
>
<FAIcon icon="times" />
</button>
</div>
</div>
</li>
</ul>
</div>
</fieldset>
</template>
<script src="./pwa_manifest_icons_setting.js"></script>
<style lang="scss">
fieldset.PWAManifestIconsSetting {
margin-left: 3em;
&.setting-item {
display: grid;
grid-template-areas:
"label"
"desc"
"control"
"draft";
grid-template-rows: 2em auto 1fr;
grid-template-columns: 1fr;
}
.pwa-label.setting-label {
align-self: end;
text-align: left;
}
.buttons {
display: flex;
gap: 0.5em;
justify-content: right;
margin-top: 0.5em;
button {
line-height: 2;
}
}
ul {
list-style: none;
display: grid;
grid-template-columns: repeat(auto-fit, 12em);
gap: 2em;
}
dl {
display: grid;
grid-template-columns: 1fr;
margin-top: 0.5em;
gap: 0.25em;
align-items: baseline;
dt {
font-weight: 800;
&::after {
content: ':'
}
}
dd {
margin: 0
}
}
.src-field {
display: grid;
grid-template-columns: auto;
justify-items: center;
gap: 0.5em;
.src-attachment {
width: 10em;
height: 10em;
display: block;
margin-bottom: 0.5em;
}
.src-upload {
display: block;
width: 100%;
}
.src-url {
display: flex;
flex-direction: column;
gap: 0.25em;
width: 100%;
label {
display: block;
}
}
}
}
</style>
diff --git a/src/components/settings_modal/helpers/rate_setting.js b/src/components/settings_modal/helpers/rate_setting.js
index 50a804f1ae..39233afd22 100644
--- a/src/components/settings_modal/helpers/rate_setting.js
+++ b/src/components/settings_modal/helpers/rate_setting.js
@@ -1,53 +1,50 @@
import Checkbox from 'src/components/checkbox/checkbox.vue'
import Setting from './setting.js'
export default {
...Setting,
data() {
return {
newValue: '',
}
},
components: {
...Setting.components,
Checkbox,
},
props: {
...Setting.props,
},
computed: {
...Setting.computed,
isSeparate() {
// [[a1, b1], [a2, b2]] vs [a, b]
return Array.isArray(this.visibleState[0])
},
normalizedState() {
if (this.isSeparate) {
return this.visibleState.map((y) => y.map((x) => Number(x) || 0))
} else {
return [this.visibleState.map((x) => Number(x) || 0)]
}
},
},
methods: {
...Setting.methods,
- getValue({ event, side, index, eventType }) {
- if (eventType === 'edit') {
- const value = Number(event.target.value)
- if (Number.isNaN(value)) return this.visibleState
+ edit({ event, side, index }) {
+ const value = Number(event.target.value)
+ if (Number.isNaN(value)) return this.visibleState
- const newVal = [...this.normalizedState.map((x) => [...x])]
- newVal[side][index] = value
- return newVal
- }
-
- if (eventType === 'toggleMode') {
- if (event === 'split') {
- return [this.normalizedState[0], this.normalizedState[0]]
- } else if (event === 'join') {
- return this.normalizedState[0]
- }
+ const newVal = [...this.normalizedState.map((x) => [...x])]
+ newVal[side][index] = value
+ this.visibleState = newVal
+ },
+ toggleMode(event) {
+ if (event === 'split') {
+ this.visibleState = [this.normalizedState[0], this.normalizedState[0]]
+ } else if (event === 'join') {
+ this.visibleState = this.normalizedState[0]
}
},
},
}
diff --git a/src/components/settings_modal/helpers/rate_setting.vue b/src/components/settings_modal/helpers/rate_setting.vue
index 76dbb8ec73..980b7959dd 100644
--- a/src/components/settings_modal/helpers/rate_setting.vue
+++ b/src/components/settings_modal/helpers/rate_setting.vue
@@ -1,154 +1,154 @@
<template>
<fieldset
v-if="matchesExpertLevel"
class="RateSetting setting-item"
>
<legend
class="setting-label"
:class="{ 'faint': shouldBeDisabled }"
>
<ModifiedIndicator
:changed="isChanged"
:onclick="reset"
/>
<LocalSettingIndicator :is-local="isLocalSetting" />
{{ ' ' }}
<template v-if="realLabel">
{{ realLabel + ' ' }}
</template>
<template v-else-if="source === 'admin'">
MISSING LABEL FOR {{ path }}
</template>
<slot v-else />
</legend>
<p
v-if="realDescription"
class="setting-description"
:class="{ 'faint': shouldBeDisabled }"
>
{{ realDescription + ' ' }}
</p>
<div class="setting-control">
<table>
<thead>
<tr>
<td> </td>
<th :id="idPrefix + 'header-period'">
{{ $t('admin_dash.rate_limit.period') }}
</th>
<th :id="idPrefix + 'header-amount'">
{{ $t('admin_dash.rate_limit.amount') }}
</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">
{{ isSeparate ? $t('admin_dash.rate_limit.unauthenticated') : $t('admin_dash.rate_limit.all') }}
</th>
<td>
<input
:id="idPrefix + 'period'"
:aria-labelledby="idPrefix + 'header-period'"
class="input string-input"
type="number"
:value="normalizedState[0][0]"
- @change="e => update({ event: e, index: 0, side: 0, eventType: 'edit' })"
+ @change="event => edit({ event, index: 0, side: 0 })"
>
</td>
<td>
<input
:id="idPrefix + 'amount'"
:aria-labelledby="idPrefix + 'header-amount'"
class="input string-input"
type="number"
:value="normalizedState[0][1]"
- @change="e => update({ event: e, index: 1, side: 0, eventType: 'edit' })"
+ @change="event => edit({ event, index: 1, side: 0 })"
>
</td>
</tr>
<tr v-if="isSeparate">
<th scope="row">
{{ $t('admin_dash.rate_limit.authenticated') }}
</th>
<td>
<input
:id="idPrefix + 'period2'"
:aria-labelledby="idPrefix + 'header-period'"
class="input string-input"
type="number"
:value="normalizedState[1][0]"
- @change="e => update({ event: e, index: 0, side: 1, eventType: 'edit' })"
+ @change="event => edit({ event, index: 0, side: 1 })"
>
</td>
<td>
<input
:id="idPrefix + 'amount2'"
:aria-labelledby="idPrefix + 'header-amount'"
class="input string-input"
type="number"
:value="normalizedState[1][1]"
- @change="e => update({ event: e, index: 1, side: 1, eventType: 'edit' })"
+ @change="event => edit({ event, index: 1, side: 1 })"
>
</td>
</tr>
</tbody>
</table>
<Checkbox
:model-value="isSeparate"
- @update:model-value="event => update({ event: event ? 'split' : 'join', eventType: 'toggleMode' })"
+ @update:model-value="event => toggleMode(event ? 'split' : 'join')"
>
{{ $t('admin_dash.rate_limit.separate') }}
</Checkbox>
</div>
<DraftButtons />
</fieldset>
</template>
<script src="./rate_setting.js"></script>
<style lang="scss">
.RateSetting {
&.setting-item {
display: grid;
grid-template-areas:
"label control"
"desc control"
". draft";
.setting-label {
text-align: right;
align-self: center;
}
.setting-description {
text-align: right;
}
.setting-control {
align-self: end;
flex-direction: column;
align-items: start;
}
}
table {
margin-top: 0.5em;
}
th {
font-weight: normal;
}
tbody th {
text-align: right;
}
td {
input {
width: 15ch;
}
}
margin-bottom: 2em;
}
</style>
diff --git a/src/components/settings_modal/helpers/setting.js b/src/components/settings_modal/helpers/setting.js
index 88c7c1ad51..0b40bcb4d0 100644
--- a/src/components/settings_modal/helpers/setting.js
+++ b/src/components/settings_modal/helpers/setting.js
@@ -1,463 +1,466 @@
import { cloneDeep, get, isEqual, set } from 'lodash-es'
import { useId } from 'vue'
import DraftButtons from './draft_buttons.vue'
import LocalSettingIndicator from './local_setting_indicator.vue'
import ModifiedIndicator from './modified_indicator.vue'
import { useAdminSettingsStore } from 'src/stores/admin_settings.js'
import { useInterfaceStore } from 'src/stores/interface.js'
import { useLocalConfigStore } from 'src/stores/local_config.js'
import { useMergedConfigStore } from 'src/stores/merged_config.js'
import { useProfileConfigStore } from 'src/stores/profile_config.js'
import { useSyncConfigStore } from 'src/stores/sync_config.js'
export default {
components: {
ModifiedIndicator,
DraftButtons,
LocalSettingIndicator,
},
props: {
// # Main props.
// Path to a setting
path: {
type: [String, Array],
required: false,
},
// What store setting resides in
source: {
type: String,
default: undefined,
},
// Whether setting is meant to be an "expert" one
expert: {
type: [Number, String],
default: 0,
},
// Backend admin thing
subgroup: {
type: String,
required: false,
},
// Local-only setting
localOnly: {
type: Boolean,
default: false,
},
// Whether to use draft mode, i.e. writing to a draft first instead of real storage
draftMode: {
type: Boolean,
default: undefined,
},
// When changing setting, apply it temporarily and let user confirm the change
// or revert after a timeout. Only supported in sync/local sources
timedApplyMode: {
type: Boolean,
default: false,
},
// ## Option dependency
// Path of a "parent" setting
parentPath: {
type: [String, Array],
},
// Whether to disable setting when parent is true instead of false
parentInvert: {
type: Boolean,
default: false,
},
// # Direct mode
// using local state instead of storage when path=null
modelValue: {
type: String,
default: null,
},
disabled: {
type: Boolean,
default: false,
},
// # Admin settings labels/descriptions
suggestions: {
type: [String, Array],
required: false,
},
description: {
type: String,
default: null,
},
label: {
type: String,
default: null,
},
descriptionPathOverride: {
type: [String, Array],
required: false,
},
swapDescriptionAndLabel: {
type: Boolean,
},
// Override labels, for cases where they are incorrect or confusing
overrideBackendDescription: {
type: Boolean,
},
overrideBackendDescriptionLabel: {
type: [Boolean, String],
},
// # Text and supporting components
hideDraftButtons: {
// this is for the weird backend hybrid (Boolean|String or Boolean|Number) settings
required: false,
type: Boolean,
},
hideLabel: {
type: Boolean,
},
hideDescription: {
type: Boolean,
},
},
inject: {
defaultSource: {
default: 'sync',
},
defaultDraftMode: {
default: false,
},
},
setup() {
const uniqueId = useId()
return { uniqueId }
},
data() {
return {
localDraft: null,
}
},
emits: ['update:modelValue'],
created() {
if (!this.realDraftMode) return
if (this.realSource !== 'admin' || this.path == null) {
this.draft = cloneDeep(this.state)
}
},
computed: {
// Normalized props
canonPath() {
if (this.path == null) return null
return Array.isArray(this.path) ? this.path : this.path.split('.')
},
descriptionPath() {
if (this.path == null) return null
const data = this.descriptionPathOverride ?? this.path
const path = Array.isArray(data) ? data : data.split('.')
if (this.subgroup) {
return [
...path.slice(0, path.length - 1),
':subgroup,' + this.subgroup,
...path.slice(path.length - 1),
]
}
return path
},
realSource() {
return this.source || this.defaultSource
},
realDraftMode() {
return this.draftMode ?? this.defaultDraftMode
},
// Main state
draft: {
get() {
if (this.realSource === 'admin') {
return get(useAdminSettingsStore().draft, this.canonPath)
} else {
return this.localDraft
}
},
set(value) {
if (this.realSource === 'admin') {
useAdminSettingsStore().updateAdminDraft({
path: this.canonPath,
value,
})
} else {
this.localDraft = value
}
},
},
state: {
get() {
if (this.path == null) return this.modelValue
const value = get(this.configSource, this.canonPath)
if (value === undefined) {
return this.defaultState
} else {
return value
}
},
set(value) {
- this.$emit('update:modelValue', )
+ this.$emit('update:modelValue')
this.configSink(this.path, value)
- }
+ },
},
visibleState: {
get() {
if (this.realDraftMode) {
return this.draft
} else {
return this.state
}
},
set(value) {
if (this.realDraftMode) {
this.draft = this.getValue(value)
} else {
this.state = this.getValue(value)
}
- }
+ },
},
// Data access
configSource() {
switch (this.realSource) {
case 'profile':
return useProfileConfigStore().config
case 'admin':
return useAdminSettingsStore().config
case 'fe-admin':
throw Error('Not implemented')
default:
if (this.realSource === 'local' || this.localOnly) {
return useLocalConfigStore().prefsStorage
} else {
return useMergedConfigStore().mergedConfig
}
}
},
configSink() {
if (this.path == null) {
return () => {
/* no-op */
}
}
switch (this.realSource) {
case 'profile':
return (path, value) =>
useProfileConfigStore().setProfileOption({ name, value })
case 'admin':
return (path, value) =>
useAdminSettingsStore().pushAdminSetting({ path, value })
default:
return (path, value) => {
if (!this.timedApplyMode) {
if (this.realSource === 'local' || this.localOnly) {
useLocalConfigStore().set({
path,
value,
})
} else {
useSyncConfigStore().setSimplePrefAndSave({
path,
value,
})
}
} else {
if (useInterfaceStore().temporaryChangesTimeoutId !== null) {
console.error("Can't track more than one temporary change")
return
}
useLocalConfigStore().setTemporarily({ path, value })
const confirm = () => {
if (this.realSource === 'local' || this.localOnly) {
useLocalConfigStore().set({ path, value })
} else {
useSyncConfigStore().setSimplePrefAndSave({
path,
value,
})
}
useLocalConfigStore().unsetTemporarily({ path })
useInterfaceStore().clearTemporaryChanges()
}
const revert = () => {
useLocalConfigStore().unsetTemporarily({ path })
useInterfaceStore().clearTemporaryChanges()
}
useInterfaceStore().setTemporaryChanges({ confirm, revert })
}
}
}
},
defaultState() {
switch (this.realSource) {
case 'profile':
return {}
case 'admin':
return {}
case 'local':
return {}
case 'fe-admin':
return {}
default: {
return get(useMergedConfigStore().mergedConfigDefault, this.canonPath)
}
}
},
// Labels & Descriptions
backendDescription() {
return get(useAdminSettingsStore().descriptions, this.descriptionPath)
},
realLabel() {
+ if (this.hideLabel) return ''
if (this.label) return this.label
if (this.realSource !== 'admin') return ''
if (!this.backendDescription || this.overrideBackendDescriptionLabel) {
return this.$t(
[
'admin_dash',
'temp_overrides',
...this.canonPath.map((p) => p.replaceAll('.', '_DOT_')),
'label',
].join('.'),
)
} else {
return this.swapDescriptionAndLabel
? this.backendDescription?.description
: this.backendDescription?.label
}
},
realDescription() {
+ if (this.hideDescription) return ''
if (this.description) return this.description
if (this.realSource !== 'admin') return ''
- if (this.hideDescription) return null
if (!this.backendDescription || this.overrideBackendDescription) {
return this.$t(
[
'admin_dash',
'temp_overrides',
...this.canonPath.map((p) => p.replaceAll('.', '_DOT_')),
'description',
].join('.'),
)
} else {
return this.swapDescriptionAndLabel
? this.backendDescription?.label
: this.backendDescription?.description
}
},
realSuggestions() {
return this.suggestions || this.backendDescription?.suggestions
},
// Supporting misc states
shouldBeDisabled() {
if (this.path == null) return this.disabled
const parentValue = (() => {
if (this.parentPath === undefined) return undefined
if (this.realSource === 'admin') {
return get(useAdminSettingsStore().draft, this.parentPath)
} else {
return get(this.configSource, this.parentPath)
}
})()
if (parentValue === undefined) return this.disabled
return this.parentInvert ? parentValue : !parentValue
},
isProfileSetting() {
return this.realSource === 'profile'
},
isLocalSetting() {
return this.localOnly
},
isChanged() {
if (this.path == null) return false
switch (this.realSource) {
case 'profile':
case 'admin':
return false
default:
return this.state !== this.defaultState
}
},
isDirty() {
if (!this.realDraftMode) return false
if (this.realSource === 'admin' && this.canonPath.length > 3) {
return false // should not show draft buttons for "grouped" values
}
return !isEqual(this.draft, this.state)
},
canHardReset() {
switch (this.realSource) {
case 'admin':
- return useAdminSettingsStore().modifiedPaths?.has(this.canonPath.join(' -> '))
+ return useAdminSettingsStore().modifiedPaths?.has(
+ this.canonPath.join(' -> '),
+ )
case 'local':
case 'fe-admin':
return this.state !== undefined
default:
return false
}
},
matchesExpertLevel() {
const settingExpertLevel = this.expert || 0
const userToggleExpert =
useMergedConfigStore().mergedConfig.expertLevel || 0
return settingExpertLevel <= userToggleExpert
},
idPrefix() {
return `setting-${this.uniqueId}-`
},
},
methods: {
// Function that meant to be overriden by consumers to output
// correct value given the model-value update event
getValue(e) {
- return e.target.value
+ return e
},
commitDraft() {
if (this.realDraftMode) {
this.$emit('update:modelValue', this.draft)
this.configSink(this.path, this.draft)
}
},
reset() {
if (this.realDraftMode) {
this.draft = cloneDeep(this.state)
} else {
set(
useMergedConfigStore().mergedConfig,
this.path,
cloneDeep(this.defaultState),
)
}
},
hardReset() {
switch (this.realSource) {
case 'admin':
return useAdminSettingsStore()
.resetAdminSetting({ path: this.path })
.then(() => {
this.draft = this.state
})
default:
console.warn('Hard reset not implemented yet!')
}
},
},
}
diff --git a/src/components/settings_modal/helpers/string_setting.js b/src/components/settings_modal/helpers/string_setting.js
index 327654ff1d..19d2c1fd0f 100644
--- a/src/components/settings_modal/helpers/string_setting.js
+++ b/src/components/settings_modal/helpers/string_setting.js
@@ -1,5 +1,8 @@
import Setting from './setting.js'
export default {
...Setting,
+ getValue(e) {
+ return e.target.value
+ },
}
diff --git a/src/components/settings_modal/helpers/string_setting.vue b/src/components/settings_modal/helpers/string_setting.vue
index 261fdfbe1d..db4afc3a54 100644
--- a/src/components/settings_modal/helpers/string_setting.vue
+++ b/src/components/settings_modal/helpers/string_setting.vue
@@ -1,47 +1,47 @@
<template>
<span
v-if="matchesExpertLevel"
class="StringSetting setting-item"
>
<label
v-if="!hideLabel"
- :for="idPrefix + 'label'"
+ :for="idPrefix + 'text'"
class="setting-label"
:class="{ 'faint': shouldBeDisabled }"
>
<ModifiedIndicator
:changed="isChanged"
:onclick="reset"
/>
<LocalSettingIndicator :is-local="isLocalSetting" />
{{ ' ' }}
<template v-if="realLabel">
{{ realLabel + ' ' }}
</template>
<template v-else-if="source === 'admin'">
MISSING LABEL FOR {{ path }}
</template>
<slot v-else />
</label>
<input
- :id="idPrefix + 'label'"
+ :id="idPrefix + 'text'"
+ v-model="visibleState"
class="setting-control input string-input"
:class="{ disabled: shouldBeDisabled }"
:disabled="shouldBeDisabled"
:placeholder="realSuggestions"
:value="realDraftMode ? draft : state"
- @change="update"
>
{{ ' ' }}
<DraftButtons v-if="!hideDraftButtons" />
<p
v-if="realDescription"
class="setting-description"
:class="{ 'faint': shouldBeDisabled }"
>
{{ realDescription + ' ' }}
</p>
</span>
</template>
<script src="./string_setting.js"></script>
diff --git a/src/components/settings_modal/helpers/tuple_setting.js b/src/components/settings_modal/helpers/tuple_setting.js
index 88019c9013..b6a0be00c1 100644
--- a/src/components/settings_modal/helpers/tuple_setting.js
+++ b/src/components/settings_modal/helpers/tuple_setting.js
@@ -1,16 +1,29 @@
import Setting from './setting.js'
export default {
...Setting,
- methods: {
- ...Setting.methods,
- getValue({ e, side }) {
- const [a, b] = this.visibleState || []
- if (side === 0) {
- return { tuple: [e.target.value, b] }
- } else {
- return { tuple: [a, e.target.value] }
- }
+ computed: {
+ ...Setting.computed,
+ guardedState() {
+ return this.visibleState?.tuple ?? []
+ },
+ a: {
+ get() {
+ return this.guardedState[0]
+ },
+ set(e) {
+ const string = e.target.value
+ this.visibleState = { tuple: [string, this.guradredState[1]] }
+ },
+ },
+ b: {
+ get() {
+ return this.guardedState[1]
+ },
+ set(e) {
+ const string = e.target.value
+ this.visibleState = { tuple: [this.guradredState[0], string] }
+ },
},
},
}
diff --git a/src/components/settings_modal/helpers/tuple_setting.vue b/src/components/settings_modal/helpers/tuple_setting.vue
index 661ca09b34..cd4d49cdeb 100644
--- a/src/components/settings_modal/helpers/tuple_setting.vue
+++ b/src/components/settings_modal/helpers/tuple_setting.vue
@@ -1,56 +1,54 @@
<template>
<fieldset
v-if="matchesExpertLevel"
class="setting-item"
>
<legend
v-if="!hideLabel"
class="setting-label"
:class="{ 'faint': shouldBeDisabled }"
>
<ModifiedIndicator
:changed="isChanged"
:onclick="reset"
/>
<LocalSettingIndicator :is-local="isLocalSetting" />
{{ ' ' }}
<template v-if="realLabel">
{{ realLabel + ' ' }}
</template>
<template v-else-if="source === 'admin'">
MISSING LABEL FOR {{ path }}
</template>
<slot v-else />
</legend>
<span class="setting-control">
<input
+ v-model="a"
class="input string-input" :class="{ disabled: shouldBeDisabled }"
:disabled="shouldBeDisabled"
:placeholder="realSuggestions?.[0]?.[0]"
:title="realSuggestions?.[0]?.[0]"
- :value="visibleState?.tuple?.[0]"
- @change="e => update({ e, side: 0 })"
>
{{ ' ' }}
<input
+ v-model="b"
class="input string-input"
:class="{ disabled: shouldBeDisabled }"
:disabled="shouldBeDisabled"
:placeholder="realSuggestions?.[0]?.[1]"
:title="realSuggestions?.[0]?.[1]"
- :value="visibleState?.tuple?.[1]"
- @change="e => update({ e, side: 1 })"
>
</span>
<DraftButtons v-if="!hideDraftButtons" />
<p
v-if="realDescription"
class="setting-description"
:class="{ 'faint': shouldBeDisabled }"
>
{{ realDescription + ' ' }}
</p>
</fieldset>
</template>
<script src="./tuple_setting.js"></script>
diff --git a/src/components/settings_modal/helpers/unit_setting.js b/src/components/settings_modal/helpers/unit_setting.js
index 3be6b7a104..3d28b81791 100644
--- a/src/components/settings_modal/helpers/unit_setting.js
+++ b/src/components/settings_modal/helpers/unit_setting.js
@@ -1,87 +1,84 @@
import Select from 'src/components/select/select.vue'
import Setting from './setting.js'
export const allCssUnits = [
'cm',
'mm',
'in',
'px',
'pt',
'pc',
'em',
'ex',
'ch',
'rem',
'vw',
'vh',
'vmin',
'vmax',
'%',
]
export const defaultHorizontalUnits = ['px', 'rem', 'vw']
export const defaultVerticalUnits = ['px', 'rem', 'vh']
export default {
...Setting,
components: {
...Setting.components,
Select,
},
props: {
...Setting.props,
min: Number,
units: {
type: Array,
default: () => allCssUnits,
},
unitSet: {
type: String,
default: 'none',
},
step: {
type: Number,
default: 1,
},
resetDefault: {
type: Object,
default: null,
},
},
computed: {
...Setting.computed,
stateUnit() {
return typeof this.state === 'string'
? this.state.replace(/[0-9,.]+/, '')
: ''
},
stateValue() {
return typeof this.state === 'string'
? this.state.replace(/[^0-9,.]+/, '')
: ''
},
},
methods: {
...Setting.methods,
getUnitString(value) {
if (this.unitSet === 'none') return value
return this.$t(['settings', 'units', this.unitSet, value].join('.'))
},
updateValue(e) {
- this.configSink(
- this.path,
- Number.parseFloat(e.target.value) + this.stateUnit,
- )
+ this.visibleState = Number.parseFloat(e.target.value) + this.stateUnit
},
updateUnit(e) {
let value = this.stateValue
const newUnit = e.target.value
if (this.resetDefault) {
const replaceValue = this.resetDefault[newUnit]
if (replaceValue != null) {
value = replaceValue
}
}
- this.configSink(this.path, value + newUnit)
+ this.visibleState = value + newUnit
},
},
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Nov 19, 3:27 PM (1 d, 23 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1841299
Default Alt Text
(68 KB)
Attached To
Mode
rPUFE pleroma-fe-upstream
Attached
Detach File
Event Timeline