<commit_before><template>
    <div class="custom-fields" id="custom-fields">
        <custom-field-form :field="field"
                           :taken-names="getTakenNames"
                           @deleted="deleteField"
                           @updated="updateField"
                           v-for="(field, index) in getFields"
                           :key="index"
                           :is-blank="field === undefined">
            <hr v-if="index !== getFields.length-1">
        </custom-field-form>
    </div>
</template>

<script>
    import Utility from '@js/Classes/Utility';
    import CustomFieldForm from '@vue/Dialog/CreatePassword/CustomFieldForm';

    export default {
        components: {CustomFieldForm},
        props     : {
            fields: {
                type: Object
            }
        },
        data() {
            return {
                customFields: this.fields
            };
        },
        computed  : {
            getFields() {
                let fields = [];

                for(let name in this.customFields) {
                    if(!this.customFields.hasOwnProperty(name)) continue;
                    fields.push(
                        {
                            name,
                            type : this.customFields[name].type,
                            value: this.customFields[name].value
                        }
                    );
                }

                if(fields.length < 20) fields.push(undefined);
                return fields;
            },
            getTakenNames() {
                return Object.keys(this.customFields);
            }
        },
        methods   : {
            updateField($event) {
                let fields = Utility.cloneObject(this.customFields);
                if($event.originalName !== '' && $event.originalName !== $event.name) {
                    delete fields[$event.originalName];
                }
                fields[$event.name] = {
                    type : $event.type,
                    value: $event.value
                };
                this.customFields = fields;
            },
            deleteField($event) {
                let fields = Utility.cloneObject(this.customFields);
                delete fields[$event];
                this.customFields = fields;
            }
        },
        watch     : {
            customFields() {
                let fields = {};
                for(let name in this.customFields) {
                    if(!this.customFields.hasOwnProperty(name) || !name.length) continue;
                    let field = this.customFields[name];
                    fields[name] = {type: field.type, value: field.value};
                }

                this.$emit('updated', fields);
            }<commit_msg>fix custom fields in edit form<commit_after><template>
    <div class="custom-fields" id="custom-fields">
        <custom-field-form :field="field"
                           :taken-names="getTakenNames"
                           @deleted="deleteField"
                           @updated="updateField"
                           v-for="(field, index) in getFields"
                           :key="index"
                           :is-blank="field === undefined">
            <hr v-if="index !== getFields.length-1">
        </custom-field-form>
    </div>
</template>

<script>
    import Utility from '@js/Classes/Utility';
    import CustomFieldForm from '@vue/Dialog/CreatePassword/CustomFieldForm';

    export default {
        components: {CustomFieldForm},
        props     : {
            fields: {
                type: Object
            }
        },
        data() {
            return {
                customFields: this.fields
            };
        },
        computed  : {
            getFields() {
                let fields = [];

                for(let name in this.customFields) {
                    if(!this.customFields.hasOwnProperty(name)) continue;
                    fields.push(
                        {
                            name,
                            type : this.customFields[name].type,
                            value: this.customFields[name].value
                        }
                    );
                }

                if(fields.length < 20) fields.push(undefined);
                return fields;
            },
            getTakenNames() {
                return Object.keys(this.customFields);
            }
        },
        methods   : {
            updateField($event) {
                let fields = Utility.cloneObject(this.customFields);
                if($event.originalName !== '' && $event.originalName !== $event.name) {
                    delete fields[$event.originalName];
                }
                fields[$event.name] = {
                    type : $event.type,
                    value: $event.value
                };
                this.customFields = fields;
            },
            deleteField($event) {
                let fields = Utility.cloneObject(this.customFields);
                delete fields[$event];
                this.customFields = fields;
            }
        },
        watch     : {
            fields() {
                if(JSON.stringify(this.fields) !== JSON.stringify(this.customFields)) {
                    this.customFields = this.fields;
                }
            },
            customFields() {
                let fields = {};
                for(let name in this.customFields) {
                    if(!this.customFields.hasOwnProperty(name) || !name.length) continue;
                    let field = this.customFields[name];
                    fields[name] = {type: field.type, value: field.value};
                }

                this.$emit('updated', fields);
            }
{'fraction_non_alphanumeric': 0.10874785591766724, 'fraction_numerical': 0.0010291595197255575, 'mean_word_length': 1.0862254025044722, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, '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': '2227504', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1331, 'n_words': 236}