<commit_before>// Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
import { get_version_timeline_content } from "./version_timeline_content_builder";

frappe.ui.form.NewTimeline = class {
	constructor(opts) {
		Object.assign(this, opts);
		this.make();
	}

	make() {
		this.timeline_wrapper = $(`<div class="new-timeline">`);
		this.timeline_items_wrapper = $(`<div class="timeline-items">`);
		this.timeline_actions_wrapper = $(`
			<div class="timeline-actions">
				<div class="timeline-dot"></div>
			</div>
		`);

		this.timeline_wrapper.append(this.timeline_actions_wrapper);
		this.timeline_wrapper.append(this.timeline_items_wrapper);

		this.parent.replaceWith(this.timeline_wrapper);
		this.timeline_items = [];
		this.render_timeline_items();
		this.setup_timeline_actions();
		this.setup_document_email_link();
	}

	refresh() {
		this.render_timeline_items();
	}

	setup_timeline_actions() {
		this.add_action_button(__('New Email'), () => this.compose_mail());
		if (frappe.boot.developer_mode) {
			this.timeline_actions_wrapper.append(`
				<div class="custom-control custom-switch communication-switch">
					<input type="checkbox" class="custom-control-input" id="only-communication-switch">
					<label class="custom-control-label" for="only-communication-switch">${__('Show Only Communications')}</label>
				</div>`)
				.find('.custom-control-input')
				.change(e => {
					this.only_communication = e.target.checked;
					this.render_timeline_items();
				});
		}
	}

	setup_document_email_link() {
		let doc_info = this.doc_info || this.frm.get_docinfo();

		if (doc_info.document_email) {
			const link = `<a class="document-email-link">${doc_info.document_email}</a>`;
			const message = __("Send an email to {0} to link it here", [link.bold()]);

			this.document_email_link_wrapper = $(`
				<div class="document-email-link-container">
					<div class="timeline-dot"></div>
					<span>${message}</span>
				</div>
			`);
			this.timeline_wrapper.prepend(this.document_email_link_wrapper);

			this.document_email_link_wrapper
				.find('.document-email-link')
				.on("click", e => {
					let text = $(e.target).text();<commit_msg>fix: Show "Only Communication" switch if timeline has communications<commit_after>// Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt
import { get_version_timeline_content } from "./version_timeline_content_builder";

frappe.ui.form.NewTimeline = class {
	constructor(opts) {
		Object.assign(this, opts);
		this.make();
	}

	make() {
		this.timeline_wrapper = $(`<div class="new-timeline">`);
		this.timeline_items_wrapper = $(`<div class="timeline-items">`);
		this.timeline_actions_wrapper = $(`
			<div class="timeline-actions">
				<div class="timeline-dot"></div>
			</div>
		`);

		this.timeline_wrapper.append(this.timeline_actions_wrapper);
		this.timeline_wrapper.append(this.timeline_items_wrapper);

		this.parent.replaceWith(this.timeline_wrapper);
		this.timeline_items = [];
		this.render_timeline_items();
		this.setup_timeline_actions();
		this.setup_document_email_link();
	}

	refresh() {
		this.render_timeline_items();
	}

	setup_timeline_actions() {
		let doc_info = this.doc_info || this.frm.get_docinfo();
		this.add_action_button(__('New Email'), () => this.compose_mail());

		let has_communications = () => {
			let communications = doc_info.communications;
			let comments = doc_info.comments;
			return (communications || []).length || (comments || []).length;
		};

		if (has_communications()) {
			this.timeline_actions_wrapper.append(`
				<div class="custom-control custom-switch communication-switch">
					<input type="checkbox" class="custom-control-input" id="only-communication-switch">
					<label class="custom-control-label" for="only-communication-switch">
						${__('Show Only Communications')}
					</label>
				</div>`)
				.find('.custom-control-input')
				.change(e => {
					this.only_communication = e.target.checked;
					this.render_timeline_items();
				});
		}
	}

	setup_document_email_link() {
		let doc_info = this.doc_info || this.frm.get_docinfo();

		if (doc_info.document_email) {
			const link = `<a class="document-email-link">${doc_info.document_email}</a>`;
			const message = __("Send an email to {0} to link it here", [link.bold()]);

			this.document_email_link_wrapper = $(`
				<div class="document-email-link-container">
					<div class="timeline-dot"></div>
					<span>${message}</span>
				</div>
			`);
			this.timeline_wrapper.prepend(this.document_email_link_wrapper);

			this.document_email_link_wrapper
				.find('.document-email-link')
				.on("click", e => {
					let text = $(e.target).text();
{'fraction_non_alphanumeric': 0.16159695817490494, 'fraction_numerical': 0.0021123785382340513, 'mean_word_length': 4.39908779931585, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 48, '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': '929862', 'n_tokens_mistral': 1800, 'n_tokens_neox': 1558, 'n_words': 246}