<commit_before>const { BaseController } = require('./base_controller');
const { Job } = require('../../core/job');
const { JobParams } = require('../../core/job_params');
const Templates = require('../common/templates');
const { Workflow } = require('../../core/workflow');
const { WorkflowForm } = require('../forms/workflow_form');

const typeMap = {
    userCanDelete: 'boolean',  // part of Workflow
    limit: 'number',           // used in list params
    offset: 'number',          // used in list params
}

class WorkflowController extends BaseController {

    constructor(params) {
        super(params, 'Workflows');
        this.typeMap = typeMap;

        this.model = Workflow;
        this.formClass = WorkflowForm;
        this.formTemplate = Templates.workflowForm;
        this.listTemplate = Templates.workflowList;
        this.nameProperty = 'name';
        this.defaultOrderBy = 'name';
        this.defaultSortDirection = 'asc';
    }

    /**
     * This creates a new job based on a workflow, then redirects
     * the user to the JobController, where they can set up and run
     * the job.
     *
     *
     */
    createJob() {
        let workflow = Workflow.find(this.params.get('workflowId'));
        let jobParams = new JobParams({
            workflowName: workflow.name
        });
        let job = jobParams.toJob();
        if (job == null) {
            // Show errors
        }
        job.save();
        this.params.set('id', job.id);
        return this.redirect('JobFiles', 'show', this.params);
    }

    /**
     * The postRenderCallback attaches event handlers to elements
     * that this controller has just rendered.
     */
    postRenderCallback(fnName) {
        $("select[name=packageFormat]").change(this.onFormatChange());
    }

    /**
     * This presents a form to create a new {@link Workflow} from a<commit_msg>Display and log errors if job cannot be created from workflow<commit_after>const { BaseController } = require('./base_controller');
const { Context } = require('../../core/context');
const { Job } = require('../../core/job');
const { JobParams } = require('../../core/job_params');
const Templates = require('../common/templates');
const { Workflow } = require('../../core/workflow');
const { WorkflowForm } = require('../forms/workflow_form');

const typeMap = {
    userCanDelete: 'boolean',  // part of Workflow
    limit: 'number',           // used in list params
    offset: 'number',          // used in list params
}

class WorkflowController extends BaseController {

    constructor(params) {
        super(params, 'Workflows');
        this.typeMap = typeMap;

        this.model = Workflow;
        this.formClass = WorkflowForm;
        this.formTemplate = Templates.workflowForm;
        this.listTemplate = Templates.workflowList;
        this.nameProperty = 'name';
        this.defaultOrderBy = 'name';
        this.defaultSortDirection = 'asc';
    }

    /**
     * This creates a new job based on a workflow, then redirects
     * the user to the JobController, where they can set up and run
     * the job.
     *
     */
    createJob() {
        let workflow = Workflow.find(this.params.get('workflowId'));
        let jobParams = new JobParams({
            workflowName: workflow.name
        });
        let job = jobParams.toJob();
        if (job == null) {
            let errMsg = Context.y18n.__('Error creating job from workflow.');
            for (let [key, value] of Object.entries(jobParams.errors)) {
                errMsg += `\n\n${key}: ${value}`
            }
            Context.logger.error(errMsg);
            alert(errMsg);
            return this.noContent();
        }
        job.save();
        this.params.set('id', job.id);
        return this.redirect('JobFiles', 'show', this.params);
    }

    /**
     * The postRenderCallback attaches event handlers to elements
     * that this controller has just rendered.
     */
    postRenderCallback(fnName) {
        $("select[name=packageFormat]").change(this.onFormatChange());
    }

    /**
     * This presents a form to create a new {@link Workflow} from a
{'fraction_non_alphanumeric': 0.13515473887814314, 'fraction_numerical': 0.00048355899419729207, 'mean_word_length': 2.306954436450839, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '395149', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1132, 'n_words': 305}