<commit_before>import * as types from '../mutation-types';
import {HTTP} from './../../../utils/http-common';
import configCheck from './exportConfigCheck';
import equal from 'deep-equal';

const state = {
    config: {networkingPlatforms: [], organization: {}},
    configActual: {networkingPlatforms: [], organization: {}},
    eventsImportConfigurationIsValid: true,
    eventsImportConfiguration: '',
    eventsImportConfigurationActual: '',
    successfullyUpdated: false,
    isLoaded: false
};

const getters = {
    hasChanged: state => {
        return !equal(state.config.organization.administrators,
            state.configActual.organization.administrators) ||
            !equal(state.config.networkingPlatforms, state.configActual.networkingPlatforms) ||
            state.eventsImportConfiguration !==
            state.eventsImportConfigurationActual;
    },
    networkingPlatformsChanged: state => {
        return !equal(state.config.networkingPlatforms, state.configActual.networkingPlatforms);
    },
    administratorsChanged: state => {
        return !equal(state.config.organization.administrators, state.configActual.organization.administrators);
    },
    getOrgName: state => state.config.organization.name,
    getNetworkingPlatforms: state => state.config.networkingPlatforms,
    getOrgAdministrators: state => state.config.organization.administrators,
    getEventsImportConfiguration: state => state.config.organization.eventsImportConfiguration,
    isLoaded: state => state.isLoaded,
    isValidConfig: state => configCheck(state.config.networkingPlatforms) && state.eventsImportConfigurationIsValid,
    successfullyUpdated: state => state.successfullyUpdated
};

const actions = {
    getConfiguration({commit}, organizationId) {

        HTTP.get(`/admin/api/organization/config`,
            {params: {organizationId: organizationId, language: 'DE'}}).then((resp) => {
            commit(types.SET_ORG_CONFIG, {config: resp.data});
        }).catch(e => {

        });
    }
};

const mutations = {
    [types.SET_ORG_CONFIG](state, {config}) {
        state.config = JSON.parse(JSON.stringify(config));
        state.eventsImportConfiguration = state.config.organization.eventsImportConfiguration || '';
        state.eventsImportConfigurationActual = state.eventsImportConfiguration;
        state.configActual = JSON.parse(JSON.stringify(state.config));<commit_msg>Check of changed networking platforms is now correct.<commit_after>import * as types from '../mutation-types';
import {HTTP} from './../../../utils/http-common';
import configCheck from './exportConfigCheck';
import equal from 'deep-equal';

const state = {
    config: {networkingPlatforms: [], organization: {}},
    configActual: {networkingPlatforms: [], organization: {}},
    eventsImportConfigurationIsValid: true,
    eventsImportConfiguration: '',
    eventsImportConfigurationActual: '',
    successfullyUpdated: false,
    isLoaded: false
};

let networkingPlatformHasChanged = function (networkingPlatforms, actualNetworkingPlatforms) {
    let hasChanged = false;
    for (let i = 0; i < networkingPlatforms.length; i++) {
        if (networkingPlatforms[i].isExported) {
            if (!equal(networkingPlatforms[i], actualNetworkingPlatforms[i])) {
                hasChanged = true;
            }
        } else {
            if (networkingPlatforms[i].isExported !== actualNetworkingPlatforms[i].isExported) {
                hasChanged = true;
            }
        }
    }
    return hasChanged;
};

const getters = {
    hasChanged: state => {
        return !equal(state.config.organization.administrators,
            state.configActual.organization.administrators) ||
            networkingPlatformHasChanged(state.config.networkingPlatforms, state.configActual.networkingPlatforms) ||
            state.eventsImportConfiguration !==
            state.eventsImportConfigurationActual;
    },
    networkingPlatformsChanged: state => {
        return networkingPlatformHasChanged(state.config.networkingPlatforms, state.configActual.networkingPlatforms);
    },
    administratorsChanged: state => {
        return !equal(state.config.organization.administrators, state.configActual.organization.administrators);
    },
    getOrgName: state => state.config.organization.name,
    getNetworkingPlatforms: state => state.config.networkingPlatforms,
    getOrgAdministrators: state => state.config.organization.administrators,
    getEventsImportConfiguration: state => state.config.organization.eventsImportConfiguration,
    isLoaded: state => state.isLoaded,
    isValidConfig: state => configCheck(state.config.networkingPlatforms) && state.eventsImportConfigurationIsValid,
    successfullyUpdated: state => state.successfullyUpdated
};

const actions = {
    getConfiguration({commit}, organizationId) {

        HTTP.get(`/admin/api/organization/config`,
            {params: {organizationId: organizationId, language: 'DE'}}).then((resp) => {
            commit(types.SET_ORG_CONFIG, {config: resp.data});
        }).catch(e => {

        });
    }
};

const mutations = {
    [types.SET_ORG_CONFIG](state, {config}) {
        state.config = JSON.parse(JSON.stringify(config));
        state.eventsImportConfiguration = state.config.organization.eventsImportConfiguration || '';
        state.eventsImportConfigurationActual = state.eventsImportConfiguration;
        state.configActual = JSON.parse(JSON.stringify(state.config));
{'fraction_non_alphanumeric': 0.1185076810534016, 'fraction_numerical': 0.000182882223847842, 'mean_word_length': 3.751520417028671, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6272286', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1403, 'n_words': 240}