<commit_before>import Backbone from 'backbone'
import relion from 'modules/types/em/relion/parameters-store'

const module = {
    'namespaced': true,
    'state': {
        'processingDialog': false,
        'processingDisallowedReason': '',
    },
    'getters': {
        'processingDialogVisible': function(state) {
            return state.processingDialog
        },
        'processingAllowed': function(state) {
            return state.processingDisallowedReason == ''
        },
        'processingDisallowedReason': function(state) {
            return state.processingDisallowedReason == '' ?
                '' :
                "Relion processing can't be run because " +
                    state.processingDisallowedReason
        }
    },
    'mutations': {
        'processingAllowedCheck': function(state, payload) {
            if (payload.dataCollection.ARCHIVED == '1') {
                state.processingDisallowedReason =
                    'this data collection is archived'
                return
            }

            const blockingStatus = payload.processingJobs.reduce(
                function(result, job) {
                    const status = job.PROCESSINGSTATUSDESCRIPTION
                    return ['submitted', 'queued', 'running'].includes(status) ?
                        status : result
                },
                ''
            )
            if (blockingStatus) {
                state.processingDisallowedReason = 'there is already a job ' +
                    blockingStatus + ' on this data collection'
                return
            }

            state.processingDisallowedReason = ''
        },
        'cancelProcessingDialog': function(state) {
            state.processingDialog = false
        },
        'showProcessingDialog': function(state) {
            state.processingDialog = true
        },
    },
    'actions': {
        'fetch': function(context, {url, humanName, middleware}) {
            const handleResult = function (response) {
                const result = typeof middleware == 'function' ?
                    middleware(response) : response;
                console.log(humanName, result)
                context.commit('loading', false, {'root': true })
                return result
            }

            const handleError = function(response) {
                const message = 'Could not retrieve ' + humanName
                context.commit('notifications/addNotification', {
                    'title': 'Error',
                    'message': message,
                    'level': 'error'
                }, {'root': true })
                console.log(response || message)
                context.commit('loading', false, {'root': true })
            }

            context.commit('loading', true, {'root': true })
            return new Promise((resolve, reject) => {
                // Backbone.ajax is overridden in src/js/app/marionette-application.js
                // to provide additional SynchWeb specific functionality
                Backbone.ajax({
                    'type': 'GET',
                    'url': context.rootGetters.apiUrl + url,
                    'success': function (
                        response,
                        status, // eslint-disable-line no-unused-vars
                        xhr // eslint-disable-line no-unused-vars
                    ) {
                        resolve(handleResult(response))
                    },
                    'error': function(
                        model,
                        response, // eslint-disable-line no-unused-vars
                        options // eslint-disable-line no-unused-vars
                    ) {
                        handleError(JSON.parse(model.responseText).message)
                        reject()
                    }
                })
            })
        },
    },
}

export default {
    'register': function(store) {
        if (!store.hasModule('em')) {
            store.registerModule('em', module)
            console.log('registered storage module em')
        }
        if (!store.hasModule(['em', 'relion'])) {
            store.registerModule(['em', 'relion'], relion)
            console.log('registered storage module em/relion')
        }
    },
    'unregister': function(store) {
        if (store.hasModule(['em', 'relion'])) {
            store.unregisterModule(['em', 'relion'])
            console.log('unregistered storage module em/relion')
        }
        if (store.hasModule('em')) {
            store.unregisterModule('em')
            console.log('unregistered storage module em')
        }
    },<commit_msg>forgot the VueX stuff in 8fe82dec749340794d8df48a5cd266457e59a51a<commit_after>import Backbone from 'backbone'

const module = {
    'namespaced': true,
    'state': {
        'processingDialog': false,
        'processingDisallowedReason': '',
    },
    'getters': {
        'processingDialogVisible': function(state) {
            return state.processingDialog
        },
        'processingAllowed': function(state) {
            return state.processingDisallowedReason == ''
        },
        'processingDisallowedReason': function(state) {
            return state.processingDisallowedReason == '' ?
                '' :
                "Relion processing can't be run because " +
                    state.processingDisallowedReason
        }
    },
    'mutations': {
        'processingAllowedCheck': function(state, payload) {
            if (payload.dataCollection.ARCHIVED == '1') {
                state.processingDisallowedReason =
                    'this data collection is archived'
                return
            }

            const blockingStatus = payload.processingJobs.reduce(
                function(result, job) {
                    const status = job.PROCESSINGSTATUSDESCRIPTION
                    return ['submitted', 'queued', 'running'].includes(status) ?
                        status : result
                },
                ''
            )
            if (blockingStatus) {
                state.processingDisallowedReason = 'there is already a job ' +
                    blockingStatus + ' on this data collection'
                return
            }

            state.processingDisallowedReason = ''
        },
        'cancelProcessingDialog': function(state) {
            state.processingDialog = false
        },
        'showProcessingDialog': function(state) {
            state.processingDialog = true
        },
    },
    'actions': {
        'fetch': function(context, {url, humanName, middleware}) {
            const handleResult = function (response) {
                const result = typeof middleware == 'function' ?
                    middleware(response) : response;
                console.log(humanName, result)
                context.commit('loading', false, {'root': true })
                return result
            }

            const handleError = function(response) {
                const message = 'Could not retrieve ' + humanName
                context.commit('notifications/addNotification', {
                    'title': 'Error',
                    'message': message,
                    'level': 'error'
                }, {'root': true })
                console.log(response || message)
                context.commit('loading', false, {'root': true })
            }

            context.commit('loading', true, {'root': true })
            return new Promise((resolve, reject) => {
                // Backbone.ajax is overridden in src/js/app/marionette-application.js
                // to provide additional SynchWeb specific functionality
                Backbone.ajax({
                    'type': 'GET',
                    'url': context.rootGetters.apiUrl + url,
                    'success': function (
                        response,
                        status, // eslint-disable-line no-unused-vars
                        xhr // eslint-disable-line no-unused-vars
                    ) {
                        resolve(handleResult(response))
                    },
                    'error': function(
                        model,
                        response, // eslint-disable-line no-unused-vars
                        options // eslint-disable-line no-unused-vars
                    ) {
                        handleError(JSON.parse(model.responseText).message)
                        reject()
                    }
                })
            })
        },
    },
}

export default {
    'register': function(store) {
        if (!store.hasModule('em')) {
            store.registerModule('em', module)
            console.log('registered storage module em')
        }
    },
    'unregister': function(store) {
        if (store.hasModule('em')) {
            store.unregisterModule('em')
            console.log('unregistered storage module em')
        }
    },
{'fraction_non_alphanumeric': 0.1059033590001116, 'fraction_numerical': 0.0031246512665997097, 'mean_word_length': 1.4091397849462366, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7472717', 'n_tokens_mistral': 2134, 'n_tokens_neox': 2024, 'n_words': 426}