mirror of
https://github.com/frappe/books.git
synced 2025-01-09 09:50:27 +00:00
Merge pull request #1022 from mildred/mildred/turn-off-filtering
feat: allow to turn off filtering
This commit is contained in:
commit
633aa1b76c
@ -64,6 +64,14 @@
|
|||||||
"readOnly": true,
|
"readOnly": true,
|
||||||
"section": "Default"
|
"section": "Default"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "allowFilterBypass",
|
||||||
|
"label": "Allow to bypass filters",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"default": false,
|
||||||
|
"description": "When linking documents, if no match is found and filtering is in effect, allow to disable filters.",
|
||||||
|
"section": "Default"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "locale",
|
"fieldname": "locale",
|
||||||
"label": "Locale",
|
"label": "Locale",
|
||||||
|
@ -11,7 +11,7 @@ export default {
|
|||||||
name: 'Link',
|
name: 'Link',
|
||||||
extends: AutoComplete,
|
extends: AutoComplete,
|
||||||
data() {
|
data() {
|
||||||
return { results: [] };
|
return { results: [], filtersDisabled: false };
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
value: {
|
value: {
|
||||||
@ -53,7 +53,7 @@ export default {
|
|||||||
getTargetSchemaName() {
|
getTargetSchemaName() {
|
||||||
return this.df.target;
|
return this.df.target;
|
||||||
},
|
},
|
||||||
async getOptions() {
|
async getOptions(filters) {
|
||||||
const schemaName = this.getTargetSchemaName();
|
const schemaName = this.getTargetSchemaName();
|
||||||
if (!schemaName) {
|
if (!schemaName) {
|
||||||
return [];
|
return [];
|
||||||
@ -64,7 +64,6 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const schema = fyo.schemaMap[schemaName];
|
const schema = fyo.schemaMap[schemaName];
|
||||||
const filters = await this.getFilters();
|
|
||||||
|
|
||||||
const fields = [
|
const fields = [
|
||||||
...new Set(['name', schema.titleField, this.df.groupBy]),
|
...new Set(['name', schema.titleField, this.df.groupBy]),
|
||||||
@ -86,7 +85,8 @@ export default {
|
|||||||
.filter(Boolean));
|
.filter(Boolean));
|
||||||
},
|
},
|
||||||
async getSuggestions(keyword = '') {
|
async getSuggestions(keyword = '') {
|
||||||
let options = await this.getOptions();
|
let filters = this.filtersDisabled ? null : await this.getFilters();
|
||||||
|
let options = await this.getOptions(filters || {});
|
||||||
|
|
||||||
if (keyword) {
|
if (keyword) {
|
||||||
options = options
|
options = options
|
||||||
@ -96,12 +96,20 @@ export default {
|
|||||||
.map(({ item }) => item);
|
.map(({ item }) => item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.doc && this.df.create) {
|
|
||||||
options = options.concat(this.getCreateNewOption());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.length === 0 && !this.df.emptyMessage) {
|
if (options.length === 0 && !this.df.emptyMessage) {
|
||||||
return [
|
if (filters && !!fyo.singles.SystemSettings?.allowFilterBypass) {
|
||||||
|
options = [
|
||||||
|
{
|
||||||
|
component: markRaw({
|
||||||
|
template:
|
||||||
|
'<span class="text-gray-600 dark:text-gray-400">{{ t`No results found, disable filters` }}</span>',
|
||||||
|
}),
|
||||||
|
action: () => this.disableFiltering(),
|
||||||
|
actionOnly: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
} else if (!this.doc || !this.df.create) {
|
||||||
|
options = [
|
||||||
{
|
{
|
||||||
component: markRaw({
|
component: markRaw({
|
||||||
template:
|
template:
|
||||||
@ -112,6 +120,11 @@ export default {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.doc && this.df.create) {
|
||||||
|
options = options.concat(this.getCreateNewOption());
|
||||||
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
},
|
},
|
||||||
@ -137,6 +150,14 @@ export default {
|
|||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
disableFiltering(keyword) {
|
||||||
|
this.filtersDisabled = true;
|
||||||
|
this.results = [];
|
||||||
|
setTimeout(() => {
|
||||||
|
this.toggleDropdown(true);
|
||||||
|
this.updateSuggestions(keyword);
|
||||||
|
}, 1);
|
||||||
|
},
|
||||||
async openNewDoc() {
|
async openNewDoc() {
|
||||||
const schemaName = this.df.target;
|
const schemaName = this.df.target;
|
||||||
const name =
|
const name =
|
||||||
@ -163,7 +184,7 @@ export default {
|
|||||||
return createFilters;
|
return createFilters;
|
||||||
}
|
}
|
||||||
|
|
||||||
const filters = await this.getFilters();
|
const filters = (await this.getFilters()) ?? {};
|
||||||
return getCreateFiltersFromListViewFilters(filters);
|
return getCreateFiltersFromListViewFilters(filters);
|
||||||
},
|
},
|
||||||
async getFilters() {
|
async getFilters() {
|
||||||
@ -171,17 +192,17 @@ export default {
|
|||||||
const getFilters = fyo.models[schemaName]?.filters?.[fieldname];
|
const getFilters = fyo.models[schemaName]?.filters?.[fieldname];
|
||||||
|
|
||||||
if (getFilters === undefined) {
|
if (getFilters === undefined) {
|
||||||
return {};
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.doc) {
|
if (this.doc) {
|
||||||
return (await getFilters(this.doc)) ?? {};
|
return await getFilters(this.doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return (await getFilters()) ?? {};
|
return await getFilters();
|
||||||
} catch {
|
} catch {
|
||||||
return {};
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -572,6 +572,7 @@ No,Non,
|
|||||||
"No filters selected","Aucun filtre sélectionné",
|
"No filters selected","Aucun filtre sélectionné",
|
||||||
"No linked entries found",,
|
"No linked entries found",,
|
||||||
"No results found","Aucun résultat trouvé",
|
"No results found","Aucun résultat trouvé",
|
||||||
|
"No results found, disable filters","Aucun résultat trouvé, désactiver les filtres",
|
||||||
"No rows added. Select a file or add rows.",,
|
"No rows added. Select a file or add rows.",,
|
||||||
"No transactions yet","Aucune transaction pour le moment",
|
"No transactions yet","Aucune transaction pour le moment",
|
||||||
"Non Active Serial Number ${0} cannot be used as Manufacture raw material",,
|
"Non Active Serial Number ${0} cannot be used as Manufacture raw material",,
|
||||||
@ -1056,3 +1057,5 @@ Yes,Oui,
|
|||||||
"in Batch ${0}",,
|
"in Batch ${0}",,
|
||||||
john@doe.com,,
|
john@doe.com,,
|
||||||
"to apply changes","pour appliquer les changements",
|
"to apply changes","pour appliquer les changements",
|
||||||
|
"Allow to bypass filters","Autoriser la désactivation des filtres"
|
||||||
|
"When linking documents, if no match is found and filtering is in effect, allow to disable filters.","Lors de la sélection d'un document lié, autoriser à désactiver les filtres si aucun résultat n'est trouvé"
|
||||||
|
Can't render this file because it has a wrong number of fields in line 1060.
|
Loading…
Reference in New Issue
Block a user