logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://hacktivis.me/git/pleroma-fe.git

settings_modal.js (5831B)


  1. import Modal from 'src/components/modal/modal.vue'
  2. import PanelLoading from 'src/components/panel_loading/panel_loading.vue'
  3. import AsyncComponentError from 'src/components/async_component_error/async_component_error.vue'
  4. import getResettableAsyncComponent from 'src/services/resettable_async_component.js'
  5. import Popover from '../popover/popover.vue'
  6. import Checkbox from 'src/components/checkbox/checkbox.vue'
  7. import ConfirmModal from 'src/components/confirm_modal/confirm_modal.vue'
  8. import { library } from '@fortawesome/fontawesome-svg-core'
  9. import { cloneDeep, isEqual } from 'lodash'
  10. import {
  11. newImporter,
  12. newExporter
  13. } from 'src/services/export_import/export_import.js'
  14. import {
  15. faTimes,
  16. faFileUpload,
  17. faFileDownload,
  18. faChevronDown
  19. } from '@fortawesome/free-solid-svg-icons'
  20. import {
  21. faWindowMinimize
  22. } from '@fortawesome/free-regular-svg-icons'
  23. const PLEROMAFE_SETTINGS_MAJOR_VERSION = 1
  24. const PLEROMAFE_SETTINGS_MINOR_VERSION = 0
  25. library.add(
  26. faTimes,
  27. faWindowMinimize,
  28. faFileUpload,
  29. faFileDownload,
  30. faChevronDown
  31. )
  32. const SettingsModal = {
  33. data () {
  34. return {
  35. dataImporter: newImporter({
  36. validator: this.importValidator,
  37. onImport: this.onImport,
  38. onImportFailure: this.onImportFailure
  39. }),
  40. dataThemeExporter: newExporter({
  41. filename: 'pleromafe_settings.full',
  42. getExportedObject: () => this.generateExport(true)
  43. }),
  44. dataExporter: newExporter({
  45. filename: 'pleromafe_settings',
  46. getExportedObject: () => this.generateExport()
  47. })
  48. }
  49. },
  50. components: {
  51. Modal,
  52. Popover,
  53. Checkbox,
  54. ConfirmModal,
  55. SettingsModalUserContent: getResettableAsyncComponent(
  56. () => import('./settings_modal_user_content.vue'),
  57. {
  58. loadingComponent: PanelLoading,
  59. errorComponent: AsyncComponentError,
  60. delay: 0
  61. }
  62. ),
  63. SettingsModalAdminContent: getResettableAsyncComponent(
  64. () => import('./settings_modal_admin_content.vue'),
  65. {
  66. loadingComponent: PanelLoading,
  67. errorComponent: AsyncComponentError,
  68. delay: 0
  69. }
  70. )
  71. },
  72. methods: {
  73. closeModal () {
  74. this.$store.dispatch('closeSettingsModal')
  75. },
  76. peekModal () {
  77. this.$store.dispatch('togglePeekSettingsModal')
  78. },
  79. importValidator (data) {
  80. if (!Array.isArray(data._pleroma_settings_version)) {
  81. return {
  82. messageKey: 'settings.file_import_export.invalid_file'
  83. }
  84. }
  85. const [major, minor] = data._pleroma_settings_version
  86. if (major > PLEROMAFE_SETTINGS_MAJOR_VERSION) {
  87. return {
  88. messageKey: 'settings.file_export_import.errors.file_too_new',
  89. messageArgs: {
  90. fileMajor: major,
  91. feMajor: PLEROMAFE_SETTINGS_MAJOR_VERSION
  92. }
  93. }
  94. }
  95. if (major < PLEROMAFE_SETTINGS_MAJOR_VERSION) {
  96. return {
  97. messageKey: 'settings.file_export_import.errors.file_too_old',
  98. messageArgs: {
  99. fileMajor: major,
  100. feMajor: PLEROMAFE_SETTINGS_MAJOR_VERSION
  101. }
  102. }
  103. }
  104. if (minor > PLEROMAFE_SETTINGS_MINOR_VERSION) {
  105. this.$store.dispatch('pushGlobalNotice', {
  106. level: 'warning',
  107. messageKey: 'settings.file_export_import.errors.file_slightly_new'
  108. })
  109. }
  110. return true
  111. },
  112. onImportFailure (result) {
  113. if (result.error) {
  114. this.$store.dispatch('pushGlobalNotice', { messageKey: 'settings.invalid_settings_imported', level: 'error' })
  115. } else {
  116. this.$store.dispatch('pushGlobalNotice', { ...result.validationResult, level: 'error' })
  117. }
  118. },
  119. onImport (data) {
  120. if (data) { this.$store.dispatch('loadSettings', data) }
  121. },
  122. restore () {
  123. this.dataImporter.importData()
  124. },
  125. backup () {
  126. this.dataExporter.exportData()
  127. },
  128. backupWithTheme () {
  129. this.dataThemeExporter.exportData()
  130. },
  131. generateExport (theme = false) {
  132. const { config } = this.$store.state
  133. let sample = config
  134. if (!theme) {
  135. const ignoreList = new Set([
  136. 'customTheme',
  137. 'customThemeSource',
  138. 'colors'
  139. ])
  140. sample = Object.fromEntries(
  141. Object
  142. .entries(sample)
  143. .filter(([key]) => !ignoreList.has(key))
  144. )
  145. }
  146. const clone = cloneDeep(sample)
  147. clone._pleroma_settings_version = [
  148. PLEROMAFE_SETTINGS_MAJOR_VERSION,
  149. PLEROMAFE_SETTINGS_MINOR_VERSION
  150. ]
  151. return clone
  152. },
  153. resetAdminDraft () {
  154. this.$store.commit('resetAdminDraft')
  155. },
  156. pushAdminDraft () {
  157. this.$store.dispatch('pushAdminDraft')
  158. }
  159. },
  160. computed: {
  161. currentSaveStateNotice () {
  162. console.log(this.$store.state.interface.settings.currentSaveStateNotice)
  163. return this.$store.state.interface.settings.currentSaveStateNotice
  164. },
  165. modalActivated () {
  166. return this.$store.state.interface.settingsModalState !== 'hidden'
  167. },
  168. modalMode () {
  169. return this.$store.state.interface.settingsModalMode
  170. },
  171. modalOpenedOnceUser () {
  172. return this.$store.state.interface.settingsModalLoadedUser
  173. },
  174. modalOpenedOnceAdmin () {
  175. return this.$store.state.interface.settingsModalLoadedAdmin
  176. },
  177. modalPeeked () {
  178. return this.$store.state.interface.settingsModalState === 'minimized'
  179. },
  180. expertLevel: {
  181. get () {
  182. return this.$store.state.config.expertLevel > 0
  183. },
  184. set (value) {
  185. this.$store.dispatch('setOption', { name: 'expertLevel', value: value ? 1 : 0 })
  186. }
  187. },
  188. adminDraftAny () {
  189. return !isEqual(
  190. this.$store.state.adminSettings.config,
  191. this.$store.state.adminSettings.draft
  192. )
  193. }
  194. }
  195. }
  196. export default SettingsModal