public applyFilter()

in services/self-service/src/main/resources/webapp/src/app/administration/management/management-grid/management-grid.component.ts [177:240]


  public applyFilter(config) {
    if (config) {
      this.filterForm = JSON.parse(JSON.stringify(config));
      Object.setPrototypeOf(this.filterForm, Object.getPrototypeOf(config));
      this.cashedFilterForm = JSON.parse(JSON.stringify(config));
      Object.setPrototypeOf(this.cashedFilterForm, Object.getPrototypeOf(config));
    }

    let filteredData = this.getEnvironmentDataCopy();

    const containsStatus = (list, selectedItems) => {
      if (list) {
        return list.filter((item: any) => {
          if (selectedItems.indexOf(item.status) !== -1) return item;
        });
      }
    };

    if (filteredData.length) this.filtering = true;
    if (config) {
      filteredData = filteredData.filter(item => {
        const isUser = config.users.length > 0 ? (config.users.indexOf(item.user) !== -1) : true;
        const isTypeName = item.name
          ? item.name.toLowerCase().indexOf(config.type.toLowerCase()) !== -1
          : item.type.toLowerCase().indexOf(config.type.toLowerCase()) !== -1;
        const isStatus = config.statuses.length > 0
          ? (config.statuses.indexOf(item.status) !== -1)
          : (config.type !== 'active');
        const isShape = config.shapes.length > 0
          ? (config.shapes.indexOf(item.shape) !== -1 ||
            config.shapes.indexOf(item.gpu_type) !== -1 ||
            config.shapes.indexOf(`GPU count: ${item.gpu_count}`) !== -1)
          : true;
        const isProject = config.projects.length > 0
          ? (config.projects.indexOf(item.project) !== -1)
          : true;
        const isEndpoint = config.endpoints.length > 0
          ? (config.endpoints.indexOf(item.endpoint) !== -1)
          : true;

        const modifiedResources = containsStatus(item.resources, config.resources);
        let isResources = config.resources.length > 0
          ? (modifiedResources && modifiedResources.length > 0)
          : true;
        if (config.resources.length > 0 && modifiedResources && modifiedResources.length > 0) {
          item.resources = modifiedResources;
        }

        if (config.resources && config.resources.length === 0 && config.type === 'active' ||
          modifiedResources && modifiedResources.length >= 0 && config.resources.length > 0 && config.type === 'active') {
          item.resources = modifiedResources;
          isResources = true;
        }

        return isUser && isTypeName && isStatus && isShape && isProject && isResources && isEndpoint;
      });
    }
    this.allFilteredEnvironmentData = filteredData;
    this.allActiveNotebooks = this.allFilteredEnvironmentData
      .filter(v => v.name &&
        (v.status === 'running' || v.status === 'stopped') &&
        !this.clustersInProgress(v.resources || []));
    this.checkFilters();
  }