logo

pleroma-fe

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

frontends_tab.js (3253B)


  1. import BooleanSetting from '../helpers/boolean_setting.vue'
  2. import ChoiceSetting from '../helpers/choice_setting.vue'
  3. import IntegerSetting from '../helpers/integer_setting.vue'
  4. import StringSetting from '../helpers/string_setting.vue'
  5. import GroupSetting from '../helpers/group_setting.vue'
  6. import Popover from 'src/components/popover/popover.vue'
  7. import PanelLoading from 'src/components/panel_loading/panel_loading.vue'
  8. import SharedComputedObject from '../helpers/shared_computed_object.js'
  9. import { library } from '@fortawesome/fontawesome-svg-core'
  10. import {
  11. faGlobe
  12. } from '@fortawesome/free-solid-svg-icons'
  13. library.add(
  14. faGlobe
  15. )
  16. const FrontendsTab = {
  17. provide () {
  18. return {
  19. defaultDraftMode: true,
  20. defaultSource: 'admin'
  21. }
  22. },
  23. data () {
  24. return {
  25. working: false
  26. }
  27. },
  28. components: {
  29. BooleanSetting,
  30. ChoiceSetting,
  31. IntegerSetting,
  32. StringSetting,
  33. GroupSetting,
  34. PanelLoading,
  35. Popover
  36. },
  37. created () {
  38. if (this.user.rights.admin) {
  39. this.$store.dispatch('loadFrontendsStuff')
  40. }
  41. },
  42. computed: {
  43. frontends () {
  44. return this.$store.state.adminSettings.frontends
  45. },
  46. ...SharedComputedObject()
  47. },
  48. methods: {
  49. canInstall (frontend) {
  50. const fe = this.frontends.find(f => f.name === frontend.name)
  51. if (!fe) return false
  52. return fe.refs.includes(frontend.ref)
  53. },
  54. getSuggestedRef (frontend) {
  55. if (this.adminDraft) {
  56. const defaultFe = this.adminDraft[':pleroma'][':frontends'][':primary']
  57. if (defaultFe?.name === frontend.name && this.canInstall(defaultFe)) {
  58. return defaultFe.ref
  59. } else {
  60. return frontend.refs[0]
  61. }
  62. } else {
  63. return frontend.refs[0]
  64. }
  65. },
  66. update (frontend, suggestRef) {
  67. const ref = suggestRef || this.getSuggestedRef(frontend)
  68. const { name } = frontend
  69. const payload = { name, ref }
  70. this.working = true
  71. this.$store.state.api.backendInteractor.installFrontend({ payload })
  72. .finally(() => {
  73. this.working = false
  74. })
  75. .then(async (response) => {
  76. this.$store.dispatch('loadFrontendsStuff')
  77. if (response.error) {
  78. const reason = await response.error.json()
  79. this.$store.dispatch('pushGlobalNotice', {
  80. level: 'error',
  81. messageKey: 'admin_dash.frontend.failure_installing_frontend',
  82. messageArgs: {
  83. version: name + '/' + ref,
  84. reason: reason.error
  85. },
  86. timeout: 5000
  87. })
  88. } else {
  89. this.$store.dispatch('pushGlobalNotice', {
  90. level: 'success',
  91. messageKey: 'admin_dash.frontend.success_installing_frontend',
  92. messageArgs: {
  93. version: name + '/' + ref
  94. },
  95. timeout: 2000
  96. })
  97. }
  98. })
  99. },
  100. setDefault (frontend, suggestRef) {
  101. const ref = suggestRef || this.getSuggestedRef(frontend)
  102. const { name } = frontend
  103. this.$store.commit('updateAdminDraft', { path: [':pleroma', ':frontends', ':primary'], value: { name, ref } })
  104. }
  105. }
  106. }
  107. export default FrontendsTab