Resource Filters

From 3B Knowledge
Revision as of 04:34, 6 February 2025 by Admin (talk | contribs) (Created page with "In addition to the Scheduling Filters article, with the release of version 2.3 of WFM, we are introducing Resource Filtering. To create a resource filter, ensure that the filter has: - type set to "resource" - you access the two new global variables: resources and screenResources. The first variable returns all resources loaded, the second one returns only the resources currently visible - the matchItems function should use resources and filterItems arguments inst...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In addition to the Scheduling Filters article, with the release of version 2.3 of WFM, we are introducing Resource Filtering. To create a resource filter, ensure that the filter has:

- type set to "resource"

- you access the two new global variables: resources and screenResources. The first variable returns all resources loaded, the second one returns only the resources currently visible

- the matchItems function should use resources and filterItems arguments instead of events and filterItems

{
    name: "resource",
    label: "Resource",
    type: 'resource',
    items: function () {
        const workerOptions = [...new Map(resources.map(item => {
            return [item.id, item];
        })).values()].filter(resource => {
            return !!resource.extendedProps?.record?.Id
        })
        .map(resource => {
            return {
                name: resource.extendedProps?.record?.Id, 
                label: resource.extendedProps?.record?.Name
            }
        }).sort(function (a, b) {
              if (a.label < b.label) {
                return -1;
              } else if (a.label > b.label) {
                return 1;
              }
              // a must be equal to b
              return 0;
        });
        return [
            { label:'Open', name: '*' },
            ...workerOptions
        ]    
    },
    matchesItems: function (resource, filterItems = []) {
        return filterItems.some(filterItem => {
            return (resource.extendedProps?.record?.Id ?? '*') === filterItem;
        });
    }
}