public applyFilter_btnClick()

in services/self-service/src/main/resources/webapp/src/app/resources/resources-grid/resources-grid.component.ts [373:449]


  public applyFilter_btnClick(config: FilterConfigurationModel): void {
    const cached = this.loadUserPreferences(config);
    this.cashedFilterForm = JSON.parse(JSON.stringify(cached));
    Object.setPrototypeOf(this.cashedFilterForm, Object.getPrototypeOf(cached));
    let filteredData = this.getEnvironmentsListCopy();
    this.checkFilters();
    const containsStatus = (list, selectedItems) => {
      return list.filter((item: any) => { if (selectedItems.indexOf(item.status) !== -1) return item; });
    };

    if (filteredData.some((v) => v.exploratory.length)) {
      this.filtering = true;
    }

    if (config) {
      this.activeProject = config.project;
      filteredData = filteredData
        .filter(project => config.project ? project.project === config.project : project)
        .filter(project => {

          project.exploratory = project.exploratory.filter(item => {

            const isName = item.name.toLowerCase().indexOf(config.name.toLowerCase()) !== -1;
            const isStatus = config.statuses.length > 0 ? (config.statuses.indexOf(item.status) !== -1) : (config.type !== 'active');

            const isShapeCondition = (config.shapes.indexOf(item.shape) !== -1 ||
                                      config.shapes.indexOf(item.gpu_type) !== -1 ||
                                      config.shapes.indexOf(`GPU count: ${item.gpu_count}`) !== -1 );

            const isShape = config.shapes.length > 0 ? isShapeCondition : true;

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

            if (config.resources.length > 0 && modifiedResources.length > 0) { item.resources = modifiedResources; }

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

            return isName && isStatus && isShape && isResources;
          });
          return project.exploratory.length > 0;
        });

      this.updateUserPreferences(config);
    }

    let failedNotebooks = NotebookModel.notebook(this.getEnvironmentsListCopy());
    failedNotebooks = SortUtils.flatDeep(failedNotebooks, 1).filter(notebook => notebook.status === 'failed');
    if (this.filteredEnvironments.length && this.activeFiltering) {
      let creatingNotebook = NotebookModel.notebook(this.filteredEnvironments);
      creatingNotebook = SortUtils.flatDeep(creatingNotebook, 1).filter(resourse => resourse.status === 'creating');
      const fail = failedNotebooks
        .filter(v => creatingNotebook
          .some(create => create.project === v.project && create.exploratory === v.exploratory && create.resource === v.resource));
      if (fail.length) {
        this.toastr.error('Creating notebook failed!', 'Oops!');
      }
    }

    let failedResource = ComputationModel.computationRes(this.getEnvironmentsListCopy());
    failedResource = SortUtils.flatDeep(failedResource, 2).filter(resourse => resourse.status === 'failed');
    if (this.filteredEnvironments.length && this.activeFiltering) {
      let creatingResource = ComputationModel.computationRes(this.filteredEnvironments);
      creatingResource = SortUtils.flatDeep(creatingResource, 2).filter(resourse => resourse.status === 'creating');
      const fail = failedResource
        .filter(v => creatingResource
          .some(create => create.project === v.project && create.exploratory === v.exploratory && create.resource === v.resource));
      if (fail.length) {
        this.toastr.error('Creating computation resource failed!', 'Oops!');
      }
    }
    this.filteredEnvironments = filteredData;
  }