<commit_before>import {Component, Input, Output, EventEmitter, OnDestroy} from '@angular/core';
import {Action} from '../../model/action.model';
import {SharedService} from '../shared.service';
import {RequirementEvent} from '../requirements/requirement.event.model';
import {Requirement} from '../../model/requirement.model';
import {ParameterEvent} from '../parameter/parameter.event.model';
import {Parameter} from '../../model/parameter.model';
import {Pipeline} from '../../model/pipeline.model';
import {ActionEvent} from './action.event.model';
import {ActionStore} from '../../service/action/action.store';
import {DragulaService} from 'ng2-dragula/components/dragula.provider';
import {Project} from '../../model/project.model';
import {StepEvent} from './step/step.event';
import {cloneDeep} from 'lodash';

@Component({
    selector: 'app-action',
    templateUrl: './action.html',
    styleUrls: ['./action.scss']
})
export class ActionComponent implements OnDestroy {
    editableAction: Action;
    steps: Array<Action> = new Array<Action>();
    publicActions: Array<Action>;

    @Input() project: Project;
    @Input() pipeline: Pipeline;
    @Input() edit = false;
    @Input() suggest: Array<string>;

    @Input('action')
    set action(data: Action) {
        this.editableAction = cloneDeep(data);
        this.editableAction.showAddStep = false;
        if (!this.editableAction.requirements) {
            this.editableAction.requirements = new Array<Requirement>();
        } else {
            this.prepareEditRequirements();
        }
        this.steps = new Array<Action>();
        if (this.editableAction.actions) {
            this.steps = cloneDeep(this.editableAction.actions);
        }
    }

    @Output() actionEvent = new EventEmitter<ActionEvent>();

    collapsed = true;
    configRequirements: {disableModel?: boolean, disableHostname?: boolean} = {};
    constructor(private sharedService: SharedService, private _actionStore: ActionStore, private dragulaService: DragulaService) {
        this._actionStore.getActions().subscribe(mapActions => {
            this.publicActions = mapActions.toArray();
        });

        dragulaService.setOptions('bag-nonfinal', {
            moves: function (el, source, handle) {
                return handle.classList.contains('move');
            },
        });
        dragulaService.setOptions('bag-final', {
            moves: function (el, source, handle) {
                return handle.classList.contains('move');
            },
            direction: 'vertical'
        });
        this.dragulaService.drop.subscribe( () => {
            this.editableAction.hasChanged = true;
        });
    }

    ngOnDestroy() {
        this.dragulaService.destroy('bag-nonfinal');
        this.dragulaService.destroy('bag-final');
    }

    getDescriptionHeight(): number {
        return this.sharedService.getTextAreaheight(this.editableAction.description);
    }

    /**
     * Manage Requirement Event
     * @param r event
     */
    requirementEvent(r: RequirementEvent): void {
        this.editableAction.hasChanged = true;
        switch (r.type) {
            case 'add':
                if (!this.editableAction.requirements) {
                    this.editableAction.requirements = new Array<Requirement>();
                }
                let indexAdd = this.editableAction.requirements.findIndex(req => r.requirement.value === req.value);
                if (indexAdd === -1) {
                    this.editableAction.requirements.push(r.requirement);
                }
                if (r.requirement.type === 'model') {
                    this.configRequirements.disableModel = true;
                }
                if (r.requirement.type === 'hostname') {
                    this.configRequirements.disableHostname = true;
                }
                break;
            case 'delete':
                let indexDelete = this.editableAction.requirements.indexOf(r.requirement);
                if (indexDelete >= 0) {
                    this.editableAction.requirements.splice(indexDelete, 1);
                }
                if (r.requirement.type === 'model') {
                    this.configRequirements.disableModel = false;
                }
                if (r.requirement.type === 'hostname') {
                    this.configRequirements.disableHostname = false;
                }
                break;
        }
    }

    prepareEditRequirements(): void {
        this.editableAction.requirements.forEach(req => {
            if (req.type === 'model' || req.type === 'service') {
                let spaceIdx = req.value.indexOf(' ');
                if (spaceIdx > 1) {
                    let newValue = req.value.substring(0, spaceIdx);
                    let newOpts = req.value.substring(spaceIdx + 1, req.value.length);
                    req.value = newValue.trim();
                    req.opts = newOpts.replace(/\s/g, '\n');
                }
            }
            if (req.type === 'model') {
                this.configRequirements.disableModel = true;
            }
            if (req.type === 'hostname') {
                this.configRequirements.disableHostname = true;<commit_msg>fix(ui): fix refresh configRequirements on modal requirements (#2279)<commit_after>import {Component, Input, Output, EventEmitter, OnDestroy} from '@angular/core';
import {Action} from '../../model/action.model';
import {SharedService} from '../shared.service';
import {RequirementEvent} from '../requirements/requirement.event.model';
import {Requirement} from '../../model/requirement.model';
import {ParameterEvent} from '../parameter/parameter.event.model';
import {Parameter} from '../../model/parameter.model';
import {Pipeline} from '../../model/pipeline.model';
import {ActionEvent} from './action.event.model';
import {ActionStore} from '../../service/action/action.store';
import {DragulaService} from 'ng2-dragula/components/dragula.provider';
import {Project} from '../../model/project.model';
import {StepEvent} from './step/step.event';
import {cloneDeep} from 'lodash';

@Component({
    selector: 'app-action',
    templateUrl: './action.html',
    styleUrls: ['./action.scss']
})
export class ActionComponent implements OnDestroy {
    editableAction: Action;
    steps: Array<Action> = new Array<Action>();
    publicActions: Array<Action>;

    @Input() project: Project;
    @Input() pipeline: Pipeline;
    @Input() edit = false;
    @Input() suggest: Array<string>;

    @Input('action')
    set action(data: Action) {
        this.editableAction = cloneDeep(data);
        this.editableAction.showAddStep = false;
        if (!this.editableAction.requirements) {
            this.editableAction.requirements = new Array<Requirement>();
        } else {
            this.prepareEditRequirements();
        }
        this.steps = new Array<Action>();
        if (this.editableAction.actions) {
            this.steps = cloneDeep(this.editableAction.actions);
        }
    }

    @Output() actionEvent = new EventEmitter<ActionEvent>();

    collapsed = true;
    configRequirements: {disableModel?: boolean, disableHostname?: boolean} = {};
    constructor(private sharedService: SharedService, private _actionStore: ActionStore, private dragulaService: DragulaService) {
        this._actionStore.getActions().subscribe(mapActions => {
            this.publicActions = mapActions.toArray();
        });

        dragulaService.setOptions('bag-nonfinal', {
            moves: function (el, source, handle) {
                return handle.classList.contains('move');
            },
        });
        dragulaService.setOptions('bag-final', {
            moves: function (el, source, handle) {
                return handle.classList.contains('move');
            },
            direction: 'vertical'
        });
        this.dragulaService.drop.subscribe( () => {
            this.editableAction.hasChanged = true;
        });
    }

    ngOnDestroy() {
        this.dragulaService.destroy('bag-nonfinal');
        this.dragulaService.destroy('bag-final');
    }

    getDescriptionHeight(): number {
        return this.sharedService.getTextAreaheight(this.editableAction.description);
    }

    /**
     * Manage Requirement Event
     * @param r event
     */
    requirementEvent(r: RequirementEvent): void {
        this.editableAction.hasChanged = true;
        switch (r.type) {
            case 'add':
                if (!this.editableAction.requirements) {
                    this.editableAction.requirements = new Array<Requirement>();
                }
                let indexAdd = this.editableAction.requirements.findIndex(req => r.requirement.value === req.value);
                if (indexAdd === -1) {
                    this.editableAction.requirements.push(r.requirement);
                }
                if (r.requirement.type === 'model') {
                    this.configRequirements.disableModel = true;
                }
                if (r.requirement.type === 'hostname') {
                    this.configRequirements.disableHostname = true;
                }
                break;
            case 'delete':
                let indexDelete = this.editableAction.requirements.indexOf(r.requirement);
                if (indexDelete >= 0) {
                    this.editableAction.requirements.splice(indexDelete, 1);
                }
                if (r.requirement.type === 'model') {
                    this.configRequirements.disableModel = false;
                }
                if (r.requirement.type === 'hostname') {
                    this.configRequirements.disableHostname = false;
                }
                break;
        }
    }

    prepareEditRequirements(): void {
        this.configRequirements = {};
        this.editableAction.requirements.forEach(req => {
            if (req.type === 'model' || req.type === 'service') {
                let spaceIdx = req.value.indexOf(' ');
                if (spaceIdx > 1) {
                    let newValue = req.value.substring(0, spaceIdx);
                    let newOpts = req.value.substring(spaceIdx + 1, req.value.length);
                    req.value = newValue.trim();
                    req.opts = newOpts.replace(/\s/g, '\n');
                }
            }
            if (req.type === 'model') {
                this.configRequirements.disableModel = true;
            }
            if (req.type === 'hostname') {
                this.configRequirements.disableHostname = true;
{'fraction_non_alphanumeric': 0.1321523304281925, 'fraction_numerical': 0.0017051913603637742, 'mean_word_length': 2.0796382730455076, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 31, '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': '815423', 'n_tokens_mistral': 2802, 'n_tokens_neox': 2736, 'n_words': 535}