<commit_before>﻿import * as Ro from '@nakedobjects/restful-objects';
import { ContextService, ErrorService, ErrorWrapper, Pane } from '@nakedobjects/services';
import * as Msg from './user-messages';

export class AttachmentViewModel {

    constructor(
        public readonly link: Ro.Link,
        private readonly parent: Ro.DomainObjectRepresentation,
        private readonly context: ContextService,
        private readonly error: ErrorService,
        public readonly onPaneId: Pane
    ) {
        this.href = link.href();
        this.mimeType = link.type().asString;
        this.title = link.title() || Msg.unknownFileTitle;
    }

    private readonly href: string;
    private readonly mimeType: string;
    empty = false;
    title: string;
    readonly downloadFile = () => this.context.getFile(this.parent, this.href, this.mimeType);
    readonly clearCachedFile = () => this.context.clearCachedFile(this.href);

    readonly displayInline = () =>
        this.mimeType === 'image/jpeg' ||
        this.mimeType === 'image/gif' ||
        this.mimeType === 'application/octet-stream'

    setImage(setImageOn: { image: string, title: string }) {
        this.downloadFile().then(blob => {
            if (blob.size > 0) {
                const reader = new FileReader();
                reader.onloadend = () => {
                    if (reader.result) {
                        setImageOn.image = reader.result as string;
                    }
                };
                reader.readAsDataURL(blob);
            } else {
                this.empty = true;
                this.title = this.emptyMessage;
            }
            setImageOn.title = this.title;
        }).catch((reject: ErrorWrapper) => this.error.handleError(reject));
    }

    setTitle(setTitleOn: { title: string }) {
        setTitleOn.title = this.title;
    }
<commit_msg>#443 fix compile error<commit_after>﻿import * as Ro from '@nakedobjects/restful-objects';
import { ContextService, ErrorService, ErrorWrapper, Pane } from '@nakedobjects/services';
import * as Msg from './user-messages';

export class AttachmentViewModel {

    constructor(
        public readonly link: Ro.Link,
        private readonly parent: Ro.DomainObjectRepresentation,
        private readonly context: ContextService,
        private readonly error: ErrorService,
        public readonly onPaneId: Pane
    ) {
        this.href = link.href();
        this.mimeType = link.type().asString;
        this.title = link.title() || Msg.unknownFileTitle;
    }

    private readonly href: string;
    private readonly mimeType: string;
    empty = false;
    title: string;
    readonly downloadFile = () => this.context.getFile(this.parent, this.href, this.mimeType);
    readonly clearCachedFile = () => this.context.clearCachedFile(this.href);

    readonly displayInline = () =>
        this.mimeType === 'image/jpeg' ||
        this.mimeType === 'image/gif' ||
        this.mimeType === 'application/octet-stream'

    setImage(setImageOn: { image?: string, title: string }) {
        this.downloadFile().then(blob => {
            if (blob.size > 0) {
                const reader = new FileReader();
                reader.onloadend = () => {
                    if (reader.result) {
                        setImageOn.image = reader.result as string;
                    }
                };
                reader.readAsDataURL(blob);
            } else {
                this.empty = true;
                this.title = this.emptyMessage;
            }
            setImageOn.title = this.title;
        }).catch((reject: ErrorWrapper) => this.error.handleError(reject));
    }

    setTitle(setTitleOn: { title: string }) {
        setTitleOn.title = this.title;
    }

{'fraction_non_alphanumeric': 0.1182108626198083, 'fraction_numerical': 0.0013312034078807242, 'mean_word_length': 2.1256239600665556, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7590185', 'n_tokens_mistral': 1043, 'n_tokens_neox': 998, 'n_words': 227}