QScript Functions for Moving Variables

From Q
Jump to navigation Jump to search
This page is currently under construction, or it refers to features which are under development and not yet available for use.
This page is under construction. Its contents are only visible to developers!
var __webpack_modules__ = ({});
// The module cache
var __webpack_module_cache__ = {};

// The require function
function __webpack_require__(moduleId) {

// Check if module is in cache
var cachedModule = __webpack_module_cache__[moduleId];
if (cachedModule !== undefined) {
return cachedModule.exports;
}
// Create a new module (and put it into the cache)
var module = (__webpack_module_cache__[moduleId] = {
exports: {}
});
// Execute the module function
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);

// Return the exports of the module
return module.exports;

}

// webpack/runtime/rspack_version
(() => {
__webpack_require__.rv = () => ("1.7.2")
})();
// webpack/runtime/rspack_unique_id
(() => {
__webpack_require__.ruid = "bundler=rspack@1.7.2";
})();
includeWeb('QScript Selection Functions'); // for requestOneDataFileFromProject
includeWeb('QScript Utility Functions'); // for inDisplayr

// tag_type: string for the variable type to move, one of either filter, hidden or weight
// position: string, either top or bottom
moveTaggedVariablesToTopOrBottom = function (tag_type = 'Filter', position = 'top') {
    let data_file = requestOneDataFileFromProject(last_as_default = false);
    const allowed_tag_types = ['Filter', 'Hidden', 'Weight'];
    let all_questions = data_file.questions;
    if (!allowed_tag_types.includes(tag_type))
        throw new UserError('Possible tag types are "' + allowed_tag_types.join('", "') + '" ');
    let all_relevant_questions = all_questions.filter(vs => vs['is' + tag_type]);
    let data_file_name = data_file.name;
    if (all_relevant_questions.length === 0)
        log(correctTerminology('No ' + tag_type + ' questions found in the ' + data_file_name + ' Data Set'));
    else {
        let relevant_array = getVariablesFromQuestions(all_relevant_questions);
        if (!['top', 'bottom'].includes(position))
            throw new UserError('Possible position arguments are top or bottom');
        let final_position = position === 'top' ? null : data_file.variables[data_file.variables.length - 1];
        data_file.moveAfter(relevant_array, final_position);
        if (!inDisplayr()) {
            let variable_tag = tag_type === 'filter' ? tag_type : (tag_type + ' variable');
            variable_tag = variable_tag.toLowerCase();
            variable_tag += relevant_array.length === 1 ? '' : 's';
            log('Moved ' + relevant_array.length + ' ' + variable_tag + ' to the ' + position +
                ' in the Variables and Questions tab for ' + data_file_name + '.');
        }
    }
};