<commit_before>import {Component, Input} from '@angular/core';
import {DecimalPipe} from '@angular/common';
import {Resource, Dimension} from 'idai-components-2';
import {UtilTranslations} from '../../../../core/util/util-translations';
import {FieldDefinition} from '../../../../core/configuration/model/field-definition';
import {ValuelistUtil} from '../../../../core/util/valuelist-util';


@Component({
    selector: 'dai-dimension',
    templateUrl: './dimension.html'
})

/**
 * @author <NAME>.
 * @author <NAME>
 */
export class DimensionComponent {

    @Input() resource: Resource;
    @Input() field: FieldDefinition;

    public newDimension: Dimension|undefined = undefined;
    public dimensionsInEditing: Array<Dimension> = [];


    constructor(private decimalPipe: DecimalPipe,
                private utilTranslations: UtilTranslations) {}


    public createNewDimension() {

    	this.newDimension = {
    		value: 0,
            inputValue: 0,
			measurementPosition: '',
			measurementComment: '',
			inputUnit: 'cm',
			isImprecise: false
    	};

        (this.newDimension as any)['isRange'] = false;
    }


    public getLabel(dimension: Dimension): string {

        return dimension.label
            ? dimension.label
            : Dimension.generateLabel(
                dimension,
                (value: any) => this.decimalPipe.transform(value),
                (key: string) => this.utilTranslations.getTranslation(key),
                dimension.measurementPosition
                    ? this.getPositionValueLabel(dimension.measurementPosition)
                    : undefined
                );
    }


    public getPositionValues(): string[] {

        return Object.keys(this.field['positionValues'].values);
    }


    public getPositionValueLabel(valueId: string): string {

        return ValuelistUtil.getValueLabel(this.field['positionValues'], valueId);
    }


    public cancelNewDimension() {

        this.newDimension = undefined;
    }


    public startEditing(dimension: Dimension) {

        if (dimension.inputRangeEndValue !== undefined) (dimension as any)['isRange'] = true;
        else (dimension as any)['isRange'] = false;

        this.dimensionsInEditing.push(dimension);
    }


    private stopEditing(dimension: Dimension) {

        const index: number = this.dimensionsInEditing.indexOf(dimension);
        if (index > -1) this.dimensionsInEditing.splice(index, 1);
    }


    public isInEditing(dimension: Dimension) {

        return this.dimensionsInEditing.includes(dimension);
    }


    public removeDimensionAtIndex(dimensionIndex: number) {

        this.resource[this.field.name].splice(dimensionIndex, 1);
        if (this.resource[this.field.name].length === 0) delete this.resource[this.field.name];
    }

<commit_msg>Do not open dimension editor in range mode if inputRangeEndValue is 0<commit_after>import {Component, Input} from '@angular/core';
import {DecimalPipe} from '@angular/common';
import {Resource, Dimension} from 'idai-components-2';
import {UtilTranslations} from '../../../../core/util/util-translations';
import {FieldDefinition} from '../../../../core/configuration/model/field-definition';
import {ValuelistUtil} from '../../../../core/util/valuelist-util';


@Component({
    selector: 'dai-dimension',
    templateUrl: './dimension.html'
})

/**
 * @author <NAME>.
 * @author <NAME>
 */
export class DimensionComponent {

    @Input() resource: Resource;
    @Input() field: FieldDefinition;

    public newDimension: Dimension|undefined = undefined;
    public dimensionsInEditing: Array<Dimension> = [];


    constructor(private decimalPipe: DecimalPipe,
                private utilTranslations: UtilTranslations) {}


    public createNewDimension() {

    	this.newDimension = {
    		value: 0,
            inputValue: 0,
			measurementPosition: '',
			measurementComment: '',
			inputUnit: 'cm',
			isImprecise: false
    	};

        (this.newDimension as any)['isRange'] = false;
    }


    public getLabel(dimension: Dimension): string {

        return dimension.label
            ? dimension.label
            : Dimension.generateLabel(
                dimension,
                (value: any) => this.decimalPipe.transform(value),
                (key: string) => this.utilTranslations.getTranslation(key),
                dimension.measurementPosition
                    ? this.getPositionValueLabel(dimension.measurementPosition)
                    : undefined
                );
    }


    public getPositionValues(): string[] {

        return Object.keys(this.field['positionValues'].values);
    }


    public getPositionValueLabel(valueId: string): string {

        return ValuelistUtil.getValueLabel(this.field['positionValues'], valueId);
    }


    public cancelNewDimension() {

        this.newDimension = undefined;
    }


    public startEditing(dimension: Dimension) {

        dimension.isRange = dimension.inputRangeEndValue ? true : false;

        this.dimensionsInEditing.push(dimension);
    }


    private stopEditing(dimension: Dimension) {

        const index: number = this.dimensionsInEditing.indexOf(dimension);
        if (index > -1) this.dimensionsInEditing.splice(index, 1);
    }


    public isInEditing(dimension: Dimension) {

        return this.dimensionsInEditing.includes(dimension);
    }


    public removeDimensionAtIndex(dimensionIndex: number) {

        this.resource[this.field.name].splice(dimensionIndex, 1);
        if (this.resource[this.field.name].length === 0) delete this.resource[this.field.name];
    }


{'fraction_non_alphanumeric': 0.12555893400107315, 'fraction_numerical': 0.0026828832051511357, 'mean_word_length': 2.7911864406779663, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '5561827', 'n_tokens_mistral': 1629, 'n_tokens_neox': 1511, 'n_words': 305}