|
@@ -42,111 +42,118 @@ let connectionNotificationId: string
|
|
|
// TODO: consider switching from notification to a modal dialog, and improving the message
|
|
|
const notifications = useNotifications()
|
|
|
|
|
|
-const useApplicationStore = defineStore('applicationLoaded', () => {
|
|
|
- const loaded = ref(false)
|
|
|
- const loading = computed(() => !loaded.value)
|
|
|
-
|
|
|
- const setLoaded = (): void => {
|
|
|
- const loadingAppElement: Maybe<HTMLElement> =
|
|
|
- document.getElementById('loading-app')
|
|
|
-
|
|
|
- if (useNotifications().hasErrors()) {
|
|
|
- loadingAppElement
|
|
|
- ?.getElementsByClassName('loading-failed')
|
|
|
- .item(0)
|
|
|
- ?.classList.add('active')
|
|
|
- return
|
|
|
+const useApplicationStore = defineStore(
|
|
|
+ 'application',
|
|
|
+ () => {
|
|
|
+ const loaded = ref(false)
|
|
|
+ const loading = computed(() => !loaded.value)
|
|
|
+
|
|
|
+ const setLoaded = (): void => {
|
|
|
+ const loadingAppElement: Maybe<HTMLElement> =
|
|
|
+ document.getElementById('loading-app')
|
|
|
+
|
|
|
+ if (useNotifications().hasErrors()) {
|
|
|
+ loadingAppElement
|
|
|
+ ?.getElementsByClassName('loading-failed')
|
|
|
+ .item(0)
|
|
|
+ ?.classList.add('active')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ loaded.value = true
|
|
|
+
|
|
|
+ if (loadingAppElement) {
|
|
|
+ loadingAppElement.remove()
|
|
|
+ }
|
|
|
+
|
|
|
+ testFlags.set('applicationLoaded.loaded')
|
|
|
}
|
|
|
|
|
|
- loaded.value = true
|
|
|
+ const connected = ref(false)
|
|
|
|
|
|
- if (loadingAppElement) {
|
|
|
- loadingAppElement.remove()
|
|
|
+ const bringConnectionUp = (): void => {
|
|
|
+ if (connected.value) return
|
|
|
+
|
|
|
+ log.debug('Application connection just came up.')
|
|
|
+
|
|
|
+ if (connectionNotificationId) {
|
|
|
+ notifications.removeNotification(connectionNotificationId)
|
|
|
+ }
|
|
|
+ connected.value = true
|
|
|
}
|
|
|
|
|
|
- testFlags.set('applicationLoaded.loaded')
|
|
|
- }
|
|
|
+ const takeConnectionDown = (): void => {
|
|
|
+ if (!connected.value) return
|
|
|
|
|
|
- const connected = ref(false)
|
|
|
+ log.debug('Application connection just went down.')
|
|
|
|
|
|
- const bringConnectionUp = (): void => {
|
|
|
- if (connected.value) return
|
|
|
+ connectionNotificationId = notifications.notify({
|
|
|
+ message: __('The connection to the server was lost.'),
|
|
|
+ type: NotificationTypes.Error,
|
|
|
+ persistent: true,
|
|
|
+ })
|
|
|
+ connected.value = false
|
|
|
+ }
|
|
|
|
|
|
- log.debug('Application connection just came up.')
|
|
|
+ const config = ref<ConfigList>({})
|
|
|
|
|
|
- if (connectionNotificationId) {
|
|
|
- notifications.removeNotification(connectionNotificationId)
|
|
|
+ const initializeConfigUpdateSubscription = (): void => {
|
|
|
+ const configUpdatesSubscription = new SubscriptionHandler(
|
|
|
+ useConfigUpdatesSubscription(),
|
|
|
+ )
|
|
|
+
|
|
|
+ configUpdatesSubscription.onResult((result) => {
|
|
|
+ const updatedSetting = result.data?.configUpdates.setting
|
|
|
+ if (updatedSetting) {
|
|
|
+ config.value[updatedSetting.key] = updatedSetting.value
|
|
|
+ } else {
|
|
|
+ testFlags.set('useConfigUpdatesSubscription.subscribed')
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ configUpdatesSubscriptionInitialized = true
|
|
|
}
|
|
|
- connected.value = true
|
|
|
- }
|
|
|
-
|
|
|
- const takeConnectionDown = (): void => {
|
|
|
- if (!connected.value) return
|
|
|
-
|
|
|
- log.debug('Application connection just went down.')
|
|
|
-
|
|
|
- connectionNotificationId = notifications.notify({
|
|
|
- message: __('The connection to the server was lost.'),
|
|
|
- type: NotificationTypes.Error,
|
|
|
- persistent: true,
|
|
|
- })
|
|
|
- connected.value = false
|
|
|
- }
|
|
|
-
|
|
|
- const config = ref<ConfigList>({})
|
|
|
-
|
|
|
- const initializeConfigUpdateSubscription = (): void => {
|
|
|
- const configUpdatesSubscription = new SubscriptionHandler(
|
|
|
- useConfigUpdatesSubscription(),
|
|
|
- )
|
|
|
-
|
|
|
- configUpdatesSubscription.onResult((result) => {
|
|
|
- const updatedSetting = result.data?.configUpdates.setting
|
|
|
- if (updatedSetting) {
|
|
|
- config.value[updatedSetting.key] = updatedSetting.value
|
|
|
- } else {
|
|
|
- testFlags.set('useConfigUpdatesSubscription.subscribed')
|
|
|
+
|
|
|
+ const getConfig = async (): Promise<void> => {
|
|
|
+ const configQuery = getApplicationConfigQuery()
|
|
|
+
|
|
|
+ const result = await configQuery.loadedResult(true)
|
|
|
+ if (result?.applicationConfig) {
|
|
|
+ result.applicationConfig.forEach((item) => {
|
|
|
+ config.value[item.key] = item.value
|
|
|
+ })
|
|
|
+
|
|
|
+ // app/assets/javascripts/app/config.coffee
|
|
|
+ config.value.api_path = '/api/v1'
|
|
|
}
|
|
|
- })
|
|
|
|
|
|
- configUpdatesSubscriptionInitialized = true
|
|
|
- }
|
|
|
+ if (!configUpdatesSubscriptionInitialized) {
|
|
|
+ initializeConfigUpdateSubscription()
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- const getConfig = async (): Promise<void> => {
|
|
|
- const configQuery = getApplicationConfigQuery()
|
|
|
+ const resetAndGetConfig = async (): Promise<void> => {
|
|
|
+ config.value = {}
|
|
|
|
|
|
- const result = await configQuery.loadedResult(true)
|
|
|
- if (result?.applicationConfig) {
|
|
|
- result.applicationConfig.forEach((item) => {
|
|
|
- config.value[item.key] = item.value
|
|
|
- })
|
|
|
- // app/assets/javascripts/app/config.coffee
|
|
|
- config.value.api_path = '/api/v1'
|
|
|
+ await getConfig()
|
|
|
}
|
|
|
|
|
|
- if (!configUpdatesSubscriptionInitialized) {
|
|
|
- initializeConfigUpdateSubscription()
|
|
|
+ return {
|
|
|
+ loaded,
|
|
|
+ loading,
|
|
|
+ setLoaded,
|
|
|
+ connected,
|
|
|
+ bringConnectionUp,
|
|
|
+ takeConnectionDown,
|
|
|
+ config,
|
|
|
+ initializeConfigUpdateSubscription,
|
|
|
+ getConfig,
|
|
|
+ resetAndGetConfig,
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- const resetAndGetConfig = async (): Promise<void> => {
|
|
|
- config.value = {}
|
|
|
-
|
|
|
- await getConfig()
|
|
|
- }
|
|
|
-
|
|
|
- return {
|
|
|
- loaded,
|
|
|
- loading,
|
|
|
- setLoaded,
|
|
|
- connected,
|
|
|
- bringConnectionUp,
|
|
|
- takeConnectionDown,
|
|
|
- config,
|
|
|
- initializeConfigUpdateSubscription,
|
|
|
- getConfig,
|
|
|
- resetAndGetConfig,
|
|
|
- }
|
|
|
-})
|
|
|
+ },
|
|
|
+ {
|
|
|
+ requiresAuth: false,
|
|
|
+ },
|
|
|
+)
|
|
|
|
|
|
export default useApplicationStore
|