aboutsummaryrefslogtreecommitdiff
path: root/src/components/settings_modal/admin_tabs/frontends_tab.js
blob: f57310eec43492c5032b33cba48c5e892168053b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import BooleanSetting from '../helpers/boolean_setting.vue'
import ChoiceSetting from '../helpers/choice_setting.vue'
import IntegerSetting from '../helpers/integer_setting.vue'
import StringSetting from '../helpers/string_setting.vue'
import GroupSetting from '../helpers/group_setting.vue'
import Popover from 'src/components/popover/popover.vue'
import PanelLoading from 'src/components/panel_loading/panel_loading.vue'

import SharedComputedObject from '../helpers/shared_computed_object.js'
import { library } from '@fortawesome/fontawesome-svg-core'
import {
  faGlobe
} from '@fortawesome/free-solid-svg-icons'

library.add(
  faGlobe
)

const FrontendsTab = {
  provide () {
    return {
      defaultDraftMode: true,
      defaultSource: 'admin'
    }
  },
  data () {
    return {
      working: false
    }
  },
  components: {
    BooleanSetting,
    ChoiceSetting,
    IntegerSetting,
    StringSetting,
    GroupSetting,
    PanelLoading,
    Popover
  },
  created () {
    if (this.user.rights.admin) {
      this.$store.dispatch('loadFrontendsStuff')
    }
  },
  computed: {
    frontends () {
      return this.$store.state.adminSettings.frontends
    },
    ...SharedComputedObject()
  },
  methods: {
    canInstall (frontend) {
      const fe = this.frontends.find(f => f.name === frontend.name)
      if (!fe) return false
      return fe.refs.includes(frontend.ref)
    },
    getSuggestedRef (frontend) {
      if (this.adminDraft) {
        const defaultFe = this.adminDraft[':pleroma'][':frontends'][':primary']
        if (defaultFe?.name === frontend.name && this.canInstall(defaultFe)) {
          return defaultFe.ref
        } else {
          return frontend.refs[0]
        }
      } else {
        return frontend.refs[0]
      }
    },
    update (frontend, suggestRef) {
      const ref = suggestRef || this.getSuggestedRef(frontend)
      const { name } = frontend
      const payload = { name, ref }

      this.working = true
      this.$store.state.api.backendInteractor.installFrontend({ payload })
        .finally(() => {
          this.working = false
        })
        .then(async (response) => {
          this.$store.dispatch('loadFrontendsStuff')
          if (response.error) {
            const reason = await response.error.json()
            this.$store.dispatch('pushGlobalNotice', {
              level: 'error',
              messageKey: 'admin_dash.frontend.failure_installing_frontend',
              messageArgs: {
                version: name + '/' + ref,
                reason: reason.error
              },
              timeout: 5000
            })
          } else {
            this.$store.dispatch('pushGlobalNotice', {
              level: 'success',
              messageKey: 'admin_dash.frontend.success_installing_frontend',
              messageArgs: {
                version: name + '/' + ref
              },
              timeout: 2000
            })
          }
        })
    },
    setDefault (frontend, suggestRef) {
      const ref = suggestRef || this.getSuggestedRef(frontend)
      const { name } = frontend

      this.$store.commit('updateAdminDraft', { path: [':pleroma', ':frontends', ':primary'], value: { name, ref } })
    }
  }
}

export default FrontendsTab