<commit_before>
frappe.provide('frappe.views');

frappe.views.ListGroupBy = class ListGroupBy {
	constructor(opts) {
		$.extend(this, opts);
		this.make_wrapper();

		this.user_settings = frappe.get_user_settings(this.doctype);
		this.group_by_fields = ['assigned_to', 'owner'];
		if(this.user_settings.group_by_fields) {
			this.group_by_fields = this.group_by_fields.concat(this.user_settings.group_by_fields);
		}
		this.render_group_by_items();
		this.make_group_by_fields_modal();
		this.setup_dropdown();
		this.setup_filter_by();
	}

	make_group_by_fields_modal() {
		let d = new frappe.ui.Dialog ({
			title: __("Select Filters"),
			fields: this.get_group_by_dropdown_fields()
		});
		d.set_primary_action("Save", ({ group_by_fields }) => {
			frappe.model.user_settings.save(this.doctype, 'group_by_fields', group_by_fields || null);
			this.group_by_fields = group_by_fields ? ['assigned_to', 'owner', ...group_by_fields] : ['assigned_to', 'owner'];
			this.render_group_by_items();
			d.hide();
		});

		this.page.sidebar.find(".add-list-group-by a ").on("click", () => {
			d.show();
		});
	}

	make_wrapper() {
		this.$wrapper = this.sidebar.sidebar.find('.list-group-by');
		let html = `
			<li class="list-sidebar-label">
				${__('Filter By')}
			</li>
			<div class="list-group-by-fields">
			</div>
			<li class="add-list-group-by list-link">
				<a class="add-group-by hidden-xs text-muted">
					${__("Add Fields")} <i class="octicon octicon-plus" style="margin-left: 2px;"></i>
				</a>
			</li>
		`;
		this.$wrapper.html(html);
	}

	render_group_by_items() {
		let get_item_html = (fieldname) => {
			let label;
			let fieldtype;
			if (fieldname === 'assigned_to') {
				label = __('Assigned To');
			} else if (fieldname === 'owner') {
				label = __('Created By');
			} else {
				label = frappe.meta.get_label(this.doctype, fieldname);
				fieldtype = frappe.meta.get_docfield(this.doctype, fieldname).fieldtype;<commit_msg>fix: remove field if no docfield exists<commit_after>
frappe.provide('frappe.views');

frappe.views.ListGroupBy = class ListGroupBy {
	constructor(opts) {
		$.extend(this, opts);
		this.make_wrapper();

		this.user_settings = frappe.get_user_settings(this.doctype);
		this.group_by_fields = ['assigned_to', 'owner'];
		if(this.user_settings.group_by_fields) {
			this.group_by_fields = this.group_by_fields.concat(this.user_settings.group_by_fields);
		}
		this.render_group_by_items();
		this.make_group_by_fields_modal();
		this.setup_dropdown();
		this.setup_filter_by();
	}

	make_group_by_fields_modal() {
		let d = new frappe.ui.Dialog ({
			title: __("Select Filters"),
			fields: this.get_group_by_dropdown_fields()
		});
		d.set_primary_action("Save", ({ group_by_fields }) => {
			frappe.model.user_settings.save(this.doctype, 'group_by_fields', group_by_fields || null);
			this.group_by_fields = group_by_fields ? ['assigned_to', 'owner', ...group_by_fields] : ['assigned_to', 'owner'];
			this.render_group_by_items();
			d.hide();
		});

		this.page.sidebar.find(".add-list-group-by a ").on("click", () => {
			d.show();
		});
	}

	make_wrapper() {
		this.$wrapper = this.sidebar.sidebar.find('.list-group-by');
		let html = `
			<li class="list-sidebar-label">
				${__('Filter By')}
			</li>
			<div class="list-group-by-fields">
			</div>
			<li class="add-list-group-by list-link">
				<a class="add-group-by hidden-xs text-muted">
					${__("Add Fields")} <i class="octicon octicon-plus" style="margin-left: 2px;"></i>
				</a>
			</li>
		`;
		this.$wrapper.html(html);
	}

	render_group_by_items() {
		let get_item_html = (fieldname) => {
			let label, fieldtype;
			if (fieldname === 'assigned_to') {
				label = __('Assigned To');
			} else if (fieldname === 'owner') {
				label = __('Created By');
			} else {
				label = frappe.meta.get_label(this.doctype, fieldname);
				let docfield = frappe.meta.get_docfield(this.doctype, fieldname);
				if (!docfield) {
					return;
				}
				fieldtype = docfield.fieldtype;
{'fraction_non_alphanumeric': 0.17568922305764412, 'fraction_numerical': 0.0005012531328320802, 'mean_word_length': 4.05830164765526, 'pattern_counts': {'":': 0, '<': 23, '<?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': '6715552', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1480, 'n_words': 226}