ui: add tags to ResourceGrid and GlobalSearchField

also allows to search for tags in the GlobalSearchField where each tag is
treated like a seperate field, so it weighs more if the user searches for
the exact string of a single tag

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>

ui: ResourceGrid: render tags

with the 'full' styling

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2022-11-16 16:48:14 +01:00 committed by Thomas Lamprecht
parent 366558a79d
commit ad4a19f652
3 changed files with 17 additions and 5 deletions

View File

@ -295,6 +295,7 @@ Ext.define('PVE.data.ResourceStore', {
},
tags: {
header: gettext('Tags'),
renderer: (value) => PVE.Utils.renderTags(value, PVE.Utils.tagOverrides),
type: 'string',
hidden: true,
sortable: true,

View File

@ -15,6 +15,7 @@ Ext.define('PVE.form.GlobalSearchField', {
grid: {
xtype: 'gridpanel',
userCls: 'proxmox-tags-full',
focusOnToFront: false,
floating: true,
emptyText: Proxmox.Utils.noneText,
@ -23,7 +24,7 @@ Ext.define('PVE.form.GlobalSearchField', {
scrollable: {
xtype: 'scroller',
y: true,
x: false,
x: true,
},
store: {
model: 'PVEResources',
@ -78,6 +79,11 @@ Ext.define('PVE.form.GlobalSearchField', {
text: gettext('Description'),
flex: 1,
dataIndex: 'text',
renderer: function(value, mD, rec) {
let overrides = PVE.Utils.tagOverrides;
let tags = PVE.Utils.renderTags(rec.data.tags, overrides);
return `${value}${tags}`;
},
},
{
text: gettext('Node'),
@ -104,16 +110,20 @@ Ext.define('PVE.form.GlobalSearchField', {
'storage': ['type', 'pool', 'node', 'storage'],
'default': ['name', 'type', 'node', 'pool', 'vmid'],
};
let fieldArr = fieldMap[item.data.type] || fieldMap.default;
let fields = fieldMap[item.data.type] || fieldMap.default;
let fieldArr = fields.map(field => item.data[field]?.toString().toLowerCase());
if (item.data.tags) {
let tags = item.data.tags.split(/[;, ]/);
fieldArr.push(...tags);
}
let filterWords = me.filterVal.split(/\s+/);
// all text is case insensitive and each split-out word is searched for separately.
// a row gets 1 point for every partial match, and and additional point for every exact match
let match = 0;
for (let field of fieldArr) {
let fieldValue = item.data[field]?.toString().toLowerCase();
if (fieldValue === undefined) {
for (let fieldValue of fieldArr) {
if (fieldValue === undefined || fieldValue === "") {
continue;
}
for (let filterWord of filterWords) {

View File

@ -7,6 +7,7 @@ Ext.define('PVE.grid.ResourceGrid', {
property: 'type',
direction: 'ASC',
},
userCls: 'proxmox-tags-full',
initComponent: function() {
let me = this;