<commit_before><template>
    <div class="mb-4">
        <div class="form-group">
            <label :for="field">{{ type === 'document' ? $t('Document') : $t('Image') }}</label>
            <input type="hidden" :name="field" :id="field" :rel="field" v-model="id" />
            <div>
                <div v-if="id !== null" class="filemanager-item-removable">
                    <button class="filemanager-item-removable-button" type="button" @click="unsetData">
                        <span class="fa fa-times"></span>
                    </button>
                    <div v-if="type === 'document'"><span class="fa fa-fw fa-2x fa-file-o"></span> {{ name }}</div>
                    <div class="filemanager-item-image-wrapper" v-if="type === 'image'">
                        <img class="filemanager-item-image" :src="src" :alt="alt" />
                    </div>
                </div>
            </div>
            <div>
                <button v-if="id === null" @click="openFilepicker" class="btn btn-sm btn-secondary" type="button">
                    <span class="fa fa-plus fa-fw text-white-50"></span> {{ $t('Add') }}
                </button>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    props: {
        field: {
            type: String,
            required: true,
        },
        type: {
            type: String,
            required: true,
            validator: function(value) {
                // The value must match one of these strings
                return ['image', 'document'].indexOf(value) !== -1;
            },
        },
        data: {
            type: String,
            required: true,
        },
    },
    data() {
        return {
            loading: false,
            choosingFile: false,
            id: null,
            name: null,
            src: null,
            alt: null,
        };
    },
    created() {
        if (this.data !== '') {
            this.setData(JSON.parse(this.data));
        }
    },
    mounted() {
        this.$root.$on('fileAdded', file => {
            if (this.choosingFile === true) {
                this.setData(file);
            }
            this.choosingFile = false;
        });
    },
    methods: {
        setData(file) {
            this.id = file.id;
            this.name = file.name;
            this.src = file.thumb_sm;
            this.alt = file.alt_attribute_translated;
        },
        unsetData() {
            this.id = null;
            this.name = null;
            this.src = null;
            this.alt = null;
        },
        openFilepicker() {
            this.choosingFile = true;
            let options = {
                open: true,
                multiple: false,
                overlay: true,
                single: true,
                modal: true,
            };
            this.$root.$emit('openFilepicker', options);
        },
    },
};
</script>
<commit_msg>label prop added to File field<commit_after><template>
    <div class="mb-4">
        <div class="form-group">
            <label :for="field">
                <span v-if="label"> {{ label }} </span>
                <span v-else> {{ type === 'document' ? $t('Document') : $t('Image') }} </span>
            </label>
            <input type="hidden" :name="field" :id="field" :rel="field" v-model="id" />
            <div>
                <div v-if="id !== null" class="filemanager-item-removable">
                    <button class="filemanager-item-removable-button" type="button" @click="unsetData">
                        <span class="fa fa-times"></span>
                    </button>
                    <div v-if="type === 'document'"><span class="fa fa-fw fa-2x fa-file-o"></span> {{ name }}</div>
                    <div class="filemanager-item-image-wrapper" v-if="type === 'image'">
                        <img class="filemanager-item-image" :src="src" :alt="alt" />
                    </div>
                </div>
            </div>
            <div>
                <button v-if="id === null" @click="openFilepicker" class="btn btn-sm btn-secondary" type="button">
                    <span class="fa fa-plus fa-fw text-white-50"></span> {{ $t('Add') }}
                </button>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    props: {
        field: {
            type: String,
            required: true,
        },
        label: {
            type: String,
        },
        type: {
            type: String,
            required: true,
            validator: function(value) {
                // The value must match one of these strings
                return ['image', 'document'].indexOf(value) !== -1;
            },
        },
        data: {
            type: String,
            required: true,
        },
    },
    data() {
        return {
            loading: false,
            choosingFile: false,
            id: null,
            name: null,
            src: null,
            alt: null,
        };
    },
    created() {
        if (this.data !== '') {
            this.setData(JSON.parse(this.data));
        }
    },
    mounted() {
        this.$root.$on('fileAdded', file => {
            if (this.choosingFile === true) {
                this.setData(file);
            }
            this.choosingFile = false;
        });
    },
    methods: {
        setData(file) {
            this.id = file.id;
            this.name = file.name;
            this.src = file.thumb_sm;
            this.alt = file.alt_attribute_translated;
        },
        unsetData() {
            this.id = null;
            this.name = null;
            this.src = null;
            this.alt = null;
        },
        openFilepicker() {
            this.choosingFile = true;
            let options = {
                open: true,
                multiple: false,
                overlay: true,
                single: true,
                modal: true,
            };
            this.$root.$emit('openFilepicker', options);
        },
    },
};
</script>

{'fraction_non_alphanumeric': 0.15365571876547285, 'fraction_numerical': 0.001650437365901964, 'mean_word_length': 1.2345132743362832, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 73, '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': '1874692', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1670, 'n_words': 351}