summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/registry/settings/store/mutations.js
blob: bb7071b020bd9cc7bc60c11f3e22c13e6dbd6619 (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
import { parseBoolean } from '~/lib/utils/common_utils';
import * as types from './mutation_types';

export default {
  [types.SET_INITIAL_STATE](state, initialState) {
    state.projectId = initialState.projectId;
    state.formOptions = {
      cadence: JSON.parse(initialState.cadenceOptions),
      keepN: JSON.parse(initialState.keepNOptions),
      olderThan: JSON.parse(initialState.olderThanOptions),
    };
    state.enableHistoricEntries = parseBoolean(initialState.enableHistoricEntries);
    state.isAdmin = parseBoolean(initialState.isAdmin);
    state.adminSettingsPath = initialState.adminSettingsPath;
  },
  [types.UPDATE_SETTINGS](state, data) {
    state.settings = { ...state.settings, ...data.settings };
  },
  [types.SET_SETTINGS](state, settings) {
    state.settings = settings ?? state.settings;
    state.original = Object.freeze(settings);
  },
  [types.RESET_SETTINGS](state) {
    state.settings = Object.assign({}, state.original);
  },
  [types.TOGGLE_LOADING](state) {
    state.isLoading = !state.isLoading;
  },
};