2020-05-10 03:46:06 +00:00
|
|
|
import Modal from 'src/components/modal/modal.vue'
|
2020-05-26 20:58:55 +00:00
|
|
|
import PanelLoading from 'src/components/panel_loading/panel_loading.vue'
|
|
|
|
import AsyncComponentError from 'src/components/async_component_error/async_component_error.vue'
|
2020-05-25 13:11:05 +00:00
|
|
|
import getResettableAsyncComponent from 'src/services/resettable_async_component.js'
|
2021-03-08 17:53:30 +00:00
|
|
|
import Popover from '../popover/popover.vue'
|
|
|
|
import { library } from '@fortawesome/fontawesome-svg-core'
|
|
|
|
import { cloneDeep } from 'lodash'
|
|
|
|
import {
|
|
|
|
newImporter,
|
|
|
|
newExporter
|
|
|
|
} from 'src/services/export_import/export_import.js'
|
|
|
|
import {
|
|
|
|
faTimes,
|
|
|
|
faFileUpload,
|
|
|
|
faFileDownload,
|
|
|
|
faChevronDown
|
|
|
|
} from '@fortawesome/free-solid-svg-icons'
|
|
|
|
import {
|
|
|
|
faWindowMinimize
|
|
|
|
} from '@fortawesome/free-regular-svg-icons'
|
|
|
|
|
2021-03-08 19:00:43 +00:00
|
|
|
const PLEROMAFE_SETTINGS_MAJOR_VERSION = 1
|
|
|
|
const PLEROMAFE_SETTINGS_MINOR_VERSION = 0
|
|
|
|
|
2021-03-08 17:53:30 +00:00
|
|
|
library.add(
|
|
|
|
faTimes,
|
|
|
|
faWindowMinimize,
|
|
|
|
faFileUpload,
|
|
|
|
faFileDownload,
|
|
|
|
faChevronDown
|
|
|
|
)
|
2020-05-03 14:36:12 +00:00
|
|
|
|
|
|
|
const SettingsModal = {
|
2021-03-08 17:53:30 +00:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
dataImporter: newImporter({
|
|
|
|
validator: this.importValidator,
|
|
|
|
onImport: this.onImport,
|
|
|
|
onImportFailure: this.onImportFailure
|
|
|
|
}),
|
|
|
|
dataThemeExporter: newExporter({
|
|
|
|
filename: 'pleromafe_settings.full',
|
|
|
|
getExportedObject: () => this.generateExport(true)
|
|
|
|
}),
|
|
|
|
dataExporter: newExporter({
|
|
|
|
filename: 'pleromafe_settings',
|
|
|
|
getExportedObject: () => this.generateExport()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
2020-05-03 14:36:12 +00:00
|
|
|
components: {
|
|
|
|
Modal,
|
2021-03-08 17:53:30 +00:00
|
|
|
Popover,
|
2020-05-25 13:11:05 +00:00
|
|
|
SettingsModalContent: getResettableAsyncComponent(
|
|
|
|
() => import('./settings_modal_content.vue'),
|
|
|
|
{
|
2020-05-26 20:58:55 +00:00
|
|
|
loading: PanelLoading,
|
|
|
|
error: AsyncComponentError,
|
2020-05-25 13:32:32 +00:00
|
|
|
delay: 0
|
2020-05-25 13:11:05 +00:00
|
|
|
}
|
|
|
|
)
|
2020-05-03 14:36:12 +00:00
|
|
|
},
|
2020-05-26 20:58:55 +00:00
|
|
|
methods: {
|
|
|
|
closeModal () {
|
|
|
|
this.$store.dispatch('closeSettingsModal')
|
|
|
|
},
|
|
|
|
peekModal () {
|
|
|
|
this.$store.dispatch('togglePeekSettingsModal')
|
2021-03-08 17:53:30 +00:00
|
|
|
},
|
|
|
|
importValidator (data) {
|
2021-03-08 19:00:43 +00:00
|
|
|
if (!Array.isArray(data._pleroma_settings_version)) {
|
|
|
|
return {
|
|
|
|
messageKey: 'settings.file_import_export.invalid_file'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const [major, minor] = data._pleroma_settings_version
|
|
|
|
|
|
|
|
if (major > PLEROMAFE_SETTINGS_MAJOR_VERSION) {
|
|
|
|
return {
|
|
|
|
messageKey: 'settings.file_export_import.errors.file_too_new',
|
|
|
|
messageArgs: {
|
|
|
|
fileMajor: major,
|
|
|
|
feMajor: PLEROMAFE_SETTINGS_MAJOR_VERSION
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (major < PLEROMAFE_SETTINGS_MAJOR_VERSION) {
|
|
|
|
return {
|
|
|
|
messageKey: 'settings.file_export_import.errors.file_too_old',
|
|
|
|
messageArgs: {
|
|
|
|
fileMajor: major,
|
|
|
|
feMajor: PLEROMAFE_SETTINGS_MAJOR_VERSION
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (minor > PLEROMAFE_SETTINGS_MINOR_VERSION) {
|
|
|
|
this.$store.dispatch('pushGlobalNotice', {
|
|
|
|
level: 'warning',
|
2021-03-08 19:03:55 +00:00
|
|
|
messageKey: 'settings.file_export_import.errors.file_slightly_new'
|
2021-03-08 19:00:43 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
2021-03-08 17:53:30 +00:00
|
|
|
},
|
2021-03-08 19:00:43 +00:00
|
|
|
onImportFailure (result) {
|
|
|
|
if (result.error) {
|
|
|
|
this.$store.dispatch('pushGlobalNotice', { messageKey: 'settings.invalid_settings_imported', level: 'error' })
|
|
|
|
} else {
|
|
|
|
this.$store.dispatch('pushGlobalNotice', { ...result.validationResult, level: 'error' })
|
|
|
|
}
|
2021-03-08 17:53:30 +00:00
|
|
|
},
|
|
|
|
onImport (data) {
|
2021-03-08 19:03:55 +00:00
|
|
|
if (data) { this.$store.dispatch('loadSettings', data) }
|
2021-03-08 17:53:30 +00:00
|
|
|
},
|
|
|
|
restore () {
|
|
|
|
this.dataImporter.importData()
|
|
|
|
},
|
|
|
|
backup () {
|
|
|
|
this.dataExporter.exportData()
|
|
|
|
},
|
|
|
|
backupWithTheme () {
|
|
|
|
this.dataThemeExporter.exportData()
|
|
|
|
},
|
|
|
|
generateExport (theme = false) {
|
|
|
|
const { config } = this.$store.state
|
|
|
|
let sample = config
|
|
|
|
if (!theme) {
|
|
|
|
const ignoreList = new Set([
|
|
|
|
'customTheme',
|
|
|
|
'customThemeSource',
|
|
|
|
'colors'
|
|
|
|
])
|
|
|
|
sample = Object.fromEntries(
|
|
|
|
Object
|
|
|
|
.entries(sample)
|
|
|
|
.filter(([key]) => !ignoreList.has(key))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
const clone = cloneDeep(sample)
|
2021-03-08 19:00:43 +00:00
|
|
|
clone._pleroma_settings_version = [
|
|
|
|
PLEROMAFE_SETTINGS_MAJOR_VERSION,
|
|
|
|
PLEROMAFE_SETTINGS_MINOR_VERSION
|
|
|
|
]
|
2021-03-08 17:53:30 +00:00
|
|
|
return clone
|
2020-05-26 20:58:55 +00:00
|
|
|
}
|
|
|
|
},
|
2020-05-03 14:36:12 +00:00
|
|
|
computed: {
|
2020-05-27 00:32:57 +00:00
|
|
|
currentSaveStateNotice () {
|
|
|
|
return this.$store.state.interface.settings.currentSaveStateNotice
|
|
|
|
},
|
2020-05-03 14:36:12 +00:00
|
|
|
modalActivated () {
|
|
|
|
return this.$store.state.interface.settingsModalState !== 'hidden'
|
2020-05-10 03:46:06 +00:00
|
|
|
},
|
2020-06-01 22:10:52 +00:00
|
|
|
modalOpenedOnce () {
|
|
|
|
return this.$store.state.interface.settingsModalLoaded
|
|
|
|
},
|
2020-05-10 03:46:06 +00:00
|
|
|
modalPeeked () {
|
|
|
|
return this.$store.state.interface.settingsModalState === 'minimized'
|
2020-05-03 14:36:12 +00:00
|
|
|
}
|
2020-05-25 00:43:55 +00:00
|
|
|
}
|
2020-05-03 14:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default SettingsModal
|