HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/shop.komma.nl/resources/js/components/vue/properties/resources/key.js
import BaseResource from "./baseResource";
import KeyValueTranslation from "./translation";

export default class Key extends BaseResource {
    /**
     * @return {number}
     */
    get id() {
        return this._id;
    }

    /**
     * @param {number} value
     */
    set id(value) {
        this._id = typeof value === 'number' ? value : BaseResource.newId();
    }

    /**
     * @return {KeyValueTranslation[]}
     */
    get translations() {
        if(!Array.isArray(this._translations)) this._translations = [];
        return this._translations;
    }

    /**
     * @param {KeyValueTranslation[]|[{}]} values
     */
    set translations(values) {
        if(!Array.isArray(values)) {
            this._translations = [];
            return;
        }

        this._translations = values.map((value) => {
            if(value instanceof KeyValueTranslation) return value;
            return new KeyValueTranslation(value);
        })
    }

    /**
     * @return {string}
     */
    get names() {
        return this.translations.map(
            /** @param {KeyValueTranslation} translation */
            (translation) => translation.name
        ).filter((value, index, self) => {
            return self.indexOf(value) === index;
        }).join(' / ')
    }
}