aboutsummaryrefslogtreecommitdiff
path: root/src/components/settings_modal/settings_modal_admin_content.js
blob: ce835bf24f271d1ddfc901d1f7eed4f130776c63 (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
import TabSwitcher from 'src/components/tab_switcher/tab_switcher.jsx'

import InstanceTab from './admin_tabs/instance_tab.vue'
import LimitsTab from './admin_tabs/limits_tab.vue'
import FrontendsTab from './admin_tabs/frontends_tab.vue'
import EmojiTab from './admin_tabs/emoji_tab.vue'

import { library } from '@fortawesome/fontawesome-svg-core'
import {
  faWrench,
  faHand,
  faLaptopCode,
  faPaintBrush,
  faBell,
  faDownload,
  faEyeSlash,
  faInfo
} from '@fortawesome/free-solid-svg-icons'

library.add(
  faWrench,
  faHand,
  faLaptopCode,
  faPaintBrush,
  faBell,
  faDownload,
  faEyeSlash,
  faInfo
)

const SettingsModalAdminContent = {
  components: {
    TabSwitcher,

    InstanceTab,
    LimitsTab,
    FrontendsTab,
    EmojiTab
  },
  computed: {
    user () {
      return this.$store.state.users.currentUser
    },
    isLoggedIn () {
      return !!this.$store.state.users.currentUser
    },
    open () {
      return this.$store.state.interface.settingsModalState !== 'hidden'
    },
    bodyLock () {
      return this.$store.state.interface.settingsModalState === 'visible'
    },
    adminDbLoaded () {
      return this.$store.state.adminSettings.loaded
    },
    adminDescriptionsLoaded () {
      return this.$store.state.adminSettings.descriptions !== null
    },
    noDb () {
      return this.$store.state.adminSettings.dbConfigEnabled === false
    }
  },
  created () {
    if (this.user.rights.admin) {
      this.$store.dispatch('loadAdminStuff')
    }
  },
  methods: {
    onOpen () {
      const targetTab = this.$store.state.interface.settingsModalTargetTab
      // We're being told to open in specific tab
      if (targetTab) {
        const tabIndex = this.$refs.tabSwitcher.$slots.default().findIndex(elm => {
          return elm.props && elm.props['data-tab-name'] === targetTab
        })
        if (tabIndex >= 0) {
          this.$refs.tabSwitcher.setTab(tabIndex)
        }
      }
      // Clear the state of target tab, so that next time settings is opened
      // it doesn't force it.
      this.$store.dispatch('clearSettingsModalTargetTab')
    }
  },
  mounted () {
    this.onOpen()
  },
  watch: {
    open: function (value) {
      if (value) this.onOpen()
    }
  }
}

export default SettingsModalAdminContent