<commit_before>// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt

frappe.ui.form.Dashboard = Class.extend({
	init: function(opts) {
		$.extend(this, opts);
		this.section = this.frm.fields_dict._form_dashboard.wrapper;
		this.parent = this.section.find('.section-body');
		this.wrapper = $(frappe.render_template('form_dashboard',
			{frm: this.frm})).appendTo(this.parent);

		this.progress_area = this.wrapper.find(".progress-area");
		this.heatmap_area = this.wrapper.find('.form-heatmap');
		this.chart_area = this.wrapper.find('.form-graph');
		this.stats_area = this.wrapper.find('.form-stats');
		this.stats_area_row = this.stats_area.find('.row');
		this.links_area = this.wrapper.find('.form-links');
		this.transactions_area = this.links_area.find('.transactions');

	},
	reset: function() {
		this.section.addClass('hidden');
		this.clear_headline();

		// clear progress
		this.progress_area.empty().addClass('hidden');

		// clear links
		this.links_area.addClass('hidden');
		this.links_area.find('.count, .open-notification').addClass('hidden');

		// clear stats
		this.stats_area.addClass('hidden')
		this.stats_area_row.empty();

		// clear custom
		this.wrapper.find('.custom').remove();
	},
	set_headline: function(html) {
		this.frm.layout.show_message(html);
	},
	clear_headline: function() {
		this.frm.layout.show_message();
	},

	add_comment: function(text, alert_class, permanent) {
		var me = this;
		this.set_headline_alert(text, alert_class);
		if(!permanent) {
			setTimeout(function() {
				me.clear_headline();
			}, 10000);
		}
	},

	clear_comment: function() {
		this.clear_headline();
	},

	set_headline_alert: function(text, indicator_color) {
		if (!indicator_color) {
			indicator_color = 'orange';
		}
		if(text) {
			this.set_headline(`<div><span class="indicator ${indicator_color}">${text}</span></div>`);
		} else {
			this.clear_headline();
		}
	},

	add_section: function(html) {
		return $('<div class="form-dashboard-section custom">'+html+'</div>').appendTo(this.wrapper);
	},

	add_progress: function(title, percent, message) {
		var progress_chart = this.make_progress_chart(title);

		if(!$.isArray(percent)) {
			percent = this.format_percent(title, percent);
		}

		var progress = $('<div class="progress"></div>').appendTo(progress_chart);
		$.each(percent, function(i, opts) {
			$(repl('<div class="progress-bar %(progress_class)s" style="width: %(width)s" \
				title="%(title)s"></div>', opts)).appendTo(progress);
		});

		if(message) {
			$('<p class="text-muted small">' + message + '</p>').appendTo(this.progress_area);
		}

		this.show();

		return progress_chart;
	},

	show_progress: function(title, percent, message) {
		this._progress_map = this._progress_map || {};

		if (!this._progress_map[title]) {
			const progress_chart = this.add_progress(title, percent, message);
			this._progress_map[title] = progress_chart;
		}

		let progress_chart = this._progress_map[title];

		if (!$.isArray(percent)) {
			percent = this.format_percent(title, percent);
		}

		progress_chart.find('.progress-bar').each((i, progress_bar) => {
			const width = percent[i].width;
			$(progress_bar).css('width', width);
		});
	},

	format_percent: function(title, percent) {
		var width = cint(percent) < 1 ? 1 : cint(percent);<commit_msg>fix: Update progress class on update<commit_after>// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
// MIT License. See license.txt

frappe.ui.form.Dashboard = Class.extend({
	init: function(opts) {
		$.extend(this, opts);
		this.section = this.frm.fields_dict._form_dashboard.wrapper;
		this.parent = this.section.find('.section-body');
		this.wrapper = $(frappe.render_template('form_dashboard',
			{frm: this.frm})).appendTo(this.parent);

		this.progress_area = this.wrapper.find(".progress-area");
		this.heatmap_area = this.wrapper.find('.form-heatmap');
		this.chart_area = this.wrapper.find('.form-graph');
		this.stats_area = this.wrapper.find('.form-stats');
		this.stats_area_row = this.stats_area.find('.row');
		this.links_area = this.wrapper.find('.form-links');
		this.transactions_area = this.links_area.find('.transactions');

	},
	reset: function() {
		this.section.addClass('hidden');
		this.clear_headline();

		// clear progress
		this.progress_area.empty().addClass('hidden');

		// clear links
		this.links_area.addClass('hidden');
		this.links_area.find('.count, .open-notification').addClass('hidden');

		// clear stats
		this.stats_area.addClass('hidden')
		this.stats_area_row.empty();

		// clear custom
		this.wrapper.find('.custom').remove();
	},
	set_headline: function(html) {
		this.frm.layout.show_message(html);
	},
	clear_headline: function() {
		this.frm.layout.show_message();
	},

	add_comment: function(text, alert_class, permanent) {
		var me = this;
		this.set_headline_alert(text, alert_class);
		if(!permanent) {
			setTimeout(function() {
				me.clear_headline();
			}, 10000);
		}
	},

	clear_comment: function() {
		this.clear_headline();
	},

	set_headline_alert: function(text, indicator_color) {
		if (!indicator_color) {
			indicator_color = 'orange';
		}
		if(text) {
			this.set_headline(`<div><span class="indicator ${indicator_color}">${text}</span></div>`);
		} else {
			this.clear_headline();
		}
	},

	add_section: function(html) {
		return $('<div class="form-dashboard-section custom">'+html+'</div>').appendTo(this.wrapper);
	},

	add_progress: function(title, percent, message) {
		var progress_chart = this.make_progress_chart(title);

		if(!$.isArray(percent)) {
			percent = this.format_percent(title, percent);
		}

		var progress = $('<div class="progress"></div>').appendTo(progress_chart);
		$.each(percent, function(i, opts) {
			$(repl('<div class="progress-bar %(progress_class)s" style="width: %(width)s" \
				title="%(title)s"></div>', opts)).appendTo(progress);
		});

		if(message) {
			$('<p class="text-muted small">' + message + '</p>').appendTo(this.progress_area);
		}

		this.show();

		return progress_chart;
	},

	show_progress: function(title, percent, message) {
		this._progress_map = this._progress_map || {};

		if (!this._progress_map[title]) {
			const progress_chart = this.add_progress(title, percent, message);
			this._progress_map[title] = progress_chart;
		}

		let progress_chart = this._progress_map[title];

		if (!$.isArray(percent)) {
			percent = this.format_percent(title, percent);
		}

		progress_chart.find('.progress-bar').each((i, progress_bar) => {
			const { progress_class, width } = percent[i];
			$(progress_bar).css('width', width)
				.removeClass('progress-bar-danger progress-bar-success')
				.addClass(progress_class);
		});
	},

	format_percent: function(title, percent) {
		var width = cint(percent) < 1 ? 1 : cint(percent);
{'fraction_non_alphanumeric': 0.17929515418502204, 'fraction_numerical': 0.0032305433186490457, 'mean_word_length': 4.596548890714873, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '4657066', 'n_tokens_mistral': 2535, 'n_tokens_neox': 2294, 'n_words': 358}