<commit_before>class WorkflowService {
    /*@ngInject*/
    constructor(experimentsAPI, processesAPI, mcbus, templates, toast, $mdDialog) {
        this.experimentsAPI = experimentsAPI;
        this.processesAPI = processesAPI;
        this.mcbus = mcbus;
        this.templates = templates;
        this.toast = toast;
        this.$mdDialog = $mdDialog;
    }

    addProcessFromTemplate(templateId, projectId, experimentId, multiple = true) {
        this.experimentsAPI.createProcessFromTemplate(projectId, experimentId, `global_${templateId}`)
            .then(
                (process) => {
                    let p = this.templates.loadTemplateFromProcess(process.template_name, process);
                    this.$mdDialog.show({
                        templateUrl: 'app/project/experiments/experiment/components/workflow/new-process-dialog.html',
                        controllerAs: '$ctrl',
                        controller: NewProcessDialogController,
                        bindToController: true,
                        multiple: multiple,
                        locals: {
                            process: p
                        }
                    }).then(
                        () => this.sendProcessChangeEvent(projectId, experimentId)
                    );
                },
                () => this.toast.error('Unable to add samples')
            );
    }

    cloneProcess(projectId, experimentId, process) {
        let p = angular.copy(process);
        p.input_samples.forEach(s => s.selected = true);
        p.output_samples.forEach(s => s.selected = true);
        p.files.forEach(f => f.selected = true);
        return this.$mdDialog.show({
            templateUrl: 'app/project/experiments/experiment/components/workflow/services/clone-process-dialog.html',
            controllerAs: '$ctrl',
            controller: CloneProcessDialogController,
            bindToController: true,
            locals: {
                process: p
            }
        }).then(
            (cloneArgs) => {
                return this.experimentsAPI.cloneProcess(projectId, experimentId, p.id, cloneArgs).then(
                    () => this.sendProcessChangeEvent(projectId, experimentId),
                    () => this.toast.error('Error cloning process')
                )
            }
        );
    }

    sendProcessChangeEvent(projectId, experimentId) {
        this.experimentsAPI.getProcessesForExperiment(projectId, experimentId)
            .then(
                (processes) => this.mcbus.send('PROCESSES$CHANGE', processes),
                () => this.toast.error('Error retrieving processes for experiment')
            );
    }

    deleteNodeAndProcess(projectId, experimentId, processId) {
        this.processesAPI.getDeleteProcessPreConditions(projectId, processId)
            .then(
                process => {
                    let numberOfSamples = process.output_samples.length;
                    if (numberOfSamples == 0) {
                        this.deleteNodeAndProcess();
                    } else {
                        this.confirmAndDeleteProcess(projectId, experimentId, process);
                    }
                },
                error => this.toast.error(error.data.error)
            );
    }

    confirmAndDeleteProcess(projectId, experimentId, process) {
        let processName = process.name;
        let numberOfSamples = process.output_samples.length;
        let samples = " output sample" + ((numberOfSamples != 1) ? "s" : "");
        let processInfo = processName + " - has " + numberOfSamples + samples + ".";
        let confirm = this.$mdDialog.confirm()
            .title('This process has output samples: Delete node and Samples?')
            .textContent(processInfo)
            .ariaLabel('Please confirm - deleting node')
            .ok('Delete')
            .cancel('Cancel');

        this.$mdDialog.show(confirm).then(() => this.deleteNodeAndProcess(projectId, experimentId, process.id));
    }

    deleteNodeAndProcess(projectId, experimentId, processId) {
        //NOTE: currently the graph is redisplayed after the process is deleted;
        // so, currently we do not delete the node from the graph itself; the problem
        // with this approach is that redrawing the graph "blows away"
        // any local layout that the user has created. Hence, this needs to be
        // updated so that only the process is deleted, and the node is deleted
        // from the graph without disturbing the layout. <NAME> - Sept 29, 2016
        this.processesAPI.deleteProcess(projectId, processId)
            .then(
                () => {
                    this.experimentsAPI.getProcessesForExperiment(projectId, experimentId)
                        .then(
                            (processes) => {
                                this.mcbus.send('PROCESSES$CHANGE', processes);
                            },
                            () => this.toast.error('Error retrieving processes for experiment')
                        );
                },

                error => this.toast.error(error.data.error)
            );
    }
}

class NewProcessDialogController {
    /*@ngInject*/
    constructor($mdDialog, processesAPI, $stateParams) {
        this.$mdDialog = $mdDialog;
        this.processesAPI = processesAPI;
        this.projectId = $stateParams.project_id;
        this.processName = this.process.name;
    }

    done() {
        this.$mdDialog.hide();
    }

    cancel() {
        this.processesAPI.deleteProcess(this.projectId, this.process.id).then(
            () => this.$mdDialog.cancel(),
            () => this.$mdDialog.cancel()
        );
    }
}

class CloneProcessDialogController {
    /*@ngInject*/
    constructor($mdDialog) {
        this.$mdDialog = $mdDialog;
    }

    done() {
        let files = this.process.files.filter(f => f.selected);
        let inputSamples = this.process.input_samples.filter(s => s.selected);
        this.$mdDialog.hide({name: this.process.name, files: files, samples: inputSamples});
    }

    cancel() {
        this.$mdDialog.cancel();
    }
}

angular.module('materialscommons').service('workflowService', WorkflowService);<commit_msg>Add default list of all samples to to cloneProcess. Fix double declared deleteNodeAndProcess method.<commit_after>class WorkflowService {
    /*@ngInject*/
    constructor(experimentsAPI, processesAPI, mcbus, templates, toast, $mdDialog) {
        this.experimentsAPI = experimentsAPI;
        this.processesAPI = processesAPI;
        this.mcbus = mcbus;
        this.templates = templates;
        this.toast = toast;
        this.$mdDialog = $mdDialog;
    }

    addProcessFromTemplate(templateId, projectId, experimentId, multiple = true) {
        this.experimentsAPI.createProcessFromTemplate(projectId, experimentId, `global_${templateId}`)
            .then(
                (process) => {
                    let p = this.templates.loadTemplateFromProcess(process.template_name, process);
                    this.$mdDialog.show({
                        templateUrl: 'app/project/experiments/experiment/components/workflow/new-process-dialog.html',
                        controllerAs: '$ctrl',
                        controller: NewProcessDialogController,
                        bindToController: true,
                        multiple: multiple,
                        locals: {
                            process: p
                        }
                    }).then(
                        () => this.sendProcessChangeEvent(projectId, experimentId)
                    );
                },
                () => this.toast.error('Unable to add samples')
            );
    }

    cloneProcess(projectId, experimentId, process, allSamples = []) {
        let p = angular.copy(process);
        p.input_samples.forEach(s => s.selected = true);
        p.output_samples.forEach(s => s.selected = true);
        p.files.forEach(f => f.selected = true);
        return this.$mdDialog.show({
            templateUrl: 'app/project/experiments/experiment/components/workflow/services/clone-process-dialog.html',
            controllerAs: '$ctrl',
            controller: CloneProcessDialogController,
            bindToController: true,
            locals: {
                process: p
            }
        }).then(
            (cloneArgs) => {
                return this.experimentsAPI.cloneProcess(projectId, experimentId, p.id, cloneArgs).then(
                    () => this.sendProcessChangeEvent(projectId, experimentId),
                    () => this.toast.error('Error cloning process')
                )
            }
        );
    }

    sendProcessChangeEvent(projectId, experimentId) {
        this.experimentsAPI.getProcessesForExperiment(projectId, experimentId)
            .then(
                (processes) => this.mcbus.send('PROCESSES$CHANGE', processes),
                () => this.toast.error('Error retrieving processes for experiment')
            );
    }

    deleteNodeAndProcess(projectId, experimentId, processId) {
        this.processesAPI.getDeleteProcessPreConditions(projectId, processId)
            .then(
                process => {
                    let numberOfSamples = process.output_samples.length;
                    if (numberOfSamples == 0) {
                        this.deleteNodeAndProcess2(projectId, experimentId, processId);
                    } else {
                        this.confirmAndDeleteProcess(projectId, experimentId, process);
                    }
                },
                error => this.toast.error(error.data.error)
            );
    }

    confirmAndDeleteProcess(projectId, experimentId, process) {
        let processName = process.name;
        let numberOfSamples = process.output_samples.length;
        let samples = " output sample" + ((numberOfSamples != 1) ? "s" : "");
        let processInfo = processName + " - has " + numberOfSamples + samples + ".";
        let confirm = this.$mdDialog.confirm()
            .title('This process has output samples: Delete node and Samples?')
            .textContent(processInfo)
            .ariaLabel('Please confirm - deleting node')
            .ok('Delete')
            .cancel('Cancel');

        this.$mdDialog.show(confirm).then(() => this.deleteNodeAndProcess2(projectId, experimentId, process.id));
    }

    deleteNodeAndProcess2(projectId, experimentId, processId) {
        //NOTE: currently the graph is redisplayed after the process is deleted;
        // so, currently we do not delete the node from the graph itself; the problem
        // with this approach is that redrawing the graph "blows away"
        // any local layout that the user has created. Hence, this needs to be
        // updated so that only the process is deleted, and the node is deleted
        // from the graph without disturbing the layout. <NAME> - Sept 29, 2016
        this.processesAPI.deleteProcess(projectId, processId)
            .then(
                () => {
                    this.experimentsAPI.getProcessesForExperiment(projectId, experimentId)
                        .then(
                            (processes) => {
                                this.mcbus.send('PROCESSES$CHANGE', processes);
                            },
                            () => this.toast.error('Error retrieving processes for experiment')
                        );
                },

                error => this.toast.error(error.data.error)
            );
    }
}

class NewProcessDialogController {
    /*@ngInject*/
    constructor($mdDialog, processesAPI, $stateParams) {
        this.$mdDialog = $mdDialog;
        this.processesAPI = processesAPI;
        this.projectId = $stateParams.project_id;
        this.processName = this.process.name;
    }

    done() {
        this.$mdDialog.hide();
    }

    cancel() {
        this.processesAPI.deleteProcess(this.projectId, this.process.id).then(
            () => this.$mdDialog.cancel(),
            () => this.$mdDialog.cancel()
        );
    }
}

class CloneProcessDialogController {
    /*@ngInject*/
    constructor($mdDialog) {
        this.$mdDialog = $mdDialog;
    }

    done() {
        let files = this.process.files.filter(f => f.selected);
        let inputSamples = this.process.input_samples.filter(s => s.selected);
        this.$mdDialog.hide({name: this.process.name, files: files, samples: inputSamples});
    }

    cancel() {
        this.$mdDialog.cancel();
    }
}

angular.module('materialscommons').service('workflowService', WorkflowService);
{'fraction_non_alphanumeric': 0.10759844703272324, 'fraction_numerical': 0.0015054274621662308, 'mean_word_length': 1.826875699888018, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, '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': '2568186', 'n_tokens_mistral': 3265, 'n_tokens_neox': 3129, 'n_words': 637}