<commit_before>import { inject, NewInstance } from 'aurelia-framework';
import { WorkflowApi } from './api';
import { ValidationRules, ValidationController, validateTrigger } from 'aurelia-validation';
import { UiValidationRenderer } from '../components/semantic-ui/ui-validation-renderer';
import {Router} from 'aurelia-router';

@inject(WorkflowApi, NewInstance.of(ValidationController), Router)
export class StartTask {

    constructor(workflowApi, validationController, router) {
        this.api = workflowApi;
        this.router = router;
        this.isLoading = true;

        this.validator = validationController;
        this.validator.validateTrigger = validateTrigger.changeOrBlur;
        this.validator.addRenderer(new UiValidationRenderer());

        this.setup = true;
        this.complete = false;
        this.requirements = false;

        this.taskData = {}

        this.validationRuleset = {
            input_fields: ValidationRules
                                .ensure('amount').required()
                                .matches(/^-?[0-9.]+/)
                                .ensure('inventory_identifier').required()
                                .rules,
            output_fields: ValidationRules
                                .ensure('amount').required()
                                .matches(/^-?[0-9.]+/)
                                .rules,
            variable_fields: ValidationRules
                                .ensure('amount').required()
                                .matches(/^-?[0-9.]+/)
                                .rules,
            calculation_fields: ValidationRules
                                    .ensure('calculation').required()
                                    .rules,
        }

        ValidationRules
            .ensure('equipment_choice').required()
            .ensure('labware_identifier').required()
            .when(obj => !obj.labware_not_required)
            .on(this.taskData);
    }

    activate(params, routeMap) {
        this.api.runDetail(params.id).then(data => {
            this.run = data;
            routeMap.navModel.title = this.run.name;

            this.taskId = this.run.tasks[this.run.current_task].id;
            this.taskPosition = this.run.current_task + 1;
            this.api.taskDetail(this.taskId).then(data => {
                this.isLoading = false;
                this.task = data;
                this.generateTaskData();
            });
        });
    }

    generateTaskData() {
        // Defaults required for submission
        this.taskData.product_input = this.task.product_input;
        this.taskData.product_input_measure = this.task.product_input_measure;
        this.taskData.product_input_amount = this.task.product_input_amount;
        this.taskData.labware_amount = this.task.labware_amount;
        this.taskData.labware_not_required = this.task.labware_not_required;

        var rules = [];

        let field_types = ['input_fields', 'variable_fields', 'output_fields',
                           'calculation_fields', 'step_fields'];
        for (let ft of field_types) {
            for (let field of this.task[ft]) {
                if (!this.taskData[ft]) {
                    this.taskData[ft] = [];
                }
                let fieldObj = {};
                this.taskData[ft].push(fieldObj);
                // Validation rUUUUUULES!
                if (ft !== 'step_fields') {
                    this.validator.addObject(fieldObj, this.validationRuleset[ft]);
                }
            }
        }
    }

    toggleSection(section) {<commit_msg>Fix issue preventing tasks starting due to stricker API<commit_after>import { inject, NewInstance } from 'aurelia-framework';
import { WorkflowApi } from './api';
import { ValidationRules, ValidationController, validateTrigger } from 'aurelia-validation';
import { UiValidationRenderer } from '../components/semantic-ui/ui-validation-renderer';
import {Router} from 'aurelia-router';

@inject(WorkflowApi, NewInstance.of(ValidationController), Router)
export class StartTask {

    constructor(workflowApi, validationController, router) {
        this.api = workflowApi;
        this.router = router;
        this.isLoading = true;

        this.validator = validationController;
        this.validator.validateTrigger = validateTrigger.changeOrBlur;
        this.validator.addRenderer(new UiValidationRenderer());

        this.setup = true;
        this.complete = false;
        this.requirements = false;

        this.taskData = {}

        this.validationRuleset = {
            input_fields: ValidationRules
                                .ensure('amount').required()
                                .matches(/^-?[0-9.]+/)
                                .ensure('inventory_identifier').required()
                                .rules,
            output_fields: ValidationRules
                                .ensure('amount').required()
                                .matches(/^-?[0-9.]+/)
                                .rules,
            variable_fields: ValidationRules
                                .ensure('amount').required()
                                .matches(/^-?[0-9.]+/)
                                .rules,
            calculation_fields: ValidationRules
                                    .ensure('calculation').required()
                                    .rules,
        }

        ValidationRules
            .ensure('equipment_choice').required()
            .ensure('labware_identifier').required()
            .when(obj => !obj.labware_not_required)
            .on(this.taskData);
    }

    activate(params, routeMap) {
        this.api.runDetail(params.id).then(data => {
            this.run = data;
            routeMap.navModel.title = this.run.name;

            this.taskId = this.run.tasks[this.run.current_task].id;
            this.taskPosition = this.run.current_task + 1;
            this.api.taskDetail(this.taskId).then(data => {
                this.isLoading = false;
                this.task = data;
                this.generateTaskData();
            });
        });
    }

    generateTaskData() {
        // Defaults required for submission
        this.taskData.product_input = this.task.product_input;
        this.taskData.product_input_measure = this.task.product_input_measure;
        this.taskData.product_input_amount = this.task.product_input_amount;
        this.taskData.labware_amount = this.task.labware_amount;
        this.taskData.labware_not_required = this.task.labware_not_required;

        var rules = [];

        let field_types = ['input_fields', 'variable_fields', 'output_fields',
                           'calculation_fields', 'step_fields'];
        for (let ft of field_types) {
            if (!this.taskData[ft]) {
                this.taskData[ft] = [];
            }
            for (let field of this.task[ft]) {
                let fieldObj = {};
                this.taskData[ft].push(fieldObj);
                // Validation rUUUUUULES!
                if (ft !== 'step_fields') {
                    this.validator.addObject(fieldObj, this.validationRuleset[ft]);
                }
            }
        }
    }

    toggleSection(section) {
{'fraction_non_alphanumeric': 0.11105002748763057, 'fraction_numerical': 0.0019241341396371632, 'mean_word_length': 1.6280245576020225, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4597488', 'n_tokens_mistral': 1918, 'n_tokens_neox': 1830, 'n_words': 296}