<commit_before>import { Input, Output, EventEmitter, ViewChild, TemplateRef } from '@angular/core';
import { each, clone } from 'lodash';
import { GridHeaderComponent } from './GridHeaderComponent';
import {FormioPromiseService} from '../formio-promise.service';

export class GridBodyComponent {
  @Input() header: GridHeaderComponent;
  @Input() actionAllowed: any;
  @Output() rowSelect: EventEmitter<any>;
  @Output() rowAction: EventEmitter<any>;
  @ViewChild(TemplateRef, {static: true}) template: TemplateRef<any>;
  public rows: Array<any>;
  public loading: Boolean;
  public firstItem = 0;
  public lastItem = 0;
  public skip = 0;
  public limit = 0;
  public total = 0;
  constructor() {
    this.rowSelect = new EventEmitter();
    this.rowAction = new EventEmitter();
    this.loading = true;
  }

  load(formio: FormioPromiseService, query?: any): Promise<any> {
    return formio.loadForm(query);
  }

  onRowSelect(event, row) {
    event.preventDefault();
    this.rowSelect.emit(row);
  }

  onRowAction(event, row, action) {
    event.preventDefault();
    this.rowAction.emit({ row, action });
  }

  /**
   * Set the rows for this Grid body.
   *
   * @param query
   * @param items
   * @return any
   */
  setRows(query: any, items: any) {
    this.rows = [];
    this.firstItem = query.skip + 1;
    this.lastItem = this.firstItem + items.length - 1;
    this.total = items.serverCount;
    this.limit = query.limit;
    this.skip = Math.floor(items.skip / query.limit) + 1;
    this.loading = false;
    each(items, (item: any) => {
      this.rows.push(clone(item));
    });
    return this.rows;
  }
}<commit_msg>Fixes an issue when Clicking on “Forms” button at the header of the app when no project has been selected, 721 blank form rows show up in FormManager.<commit_after>import { Input, Output, EventEmitter, ViewChild, TemplateRef } from '@angular/core';
import { each, clone } from 'lodash';
import { GridHeaderComponent } from './GridHeaderComponent';
import {FormioPromiseService} from '../formio-promise.service';

export class GridBodyComponent {
  @Input() header: GridHeaderComponent;
  @Input() actionAllowed: any;
  @Output() rowSelect: EventEmitter<any>;
  @Output() rowAction: EventEmitter<any>;
  @ViewChild(TemplateRef, {static: true}) template: TemplateRef<any>;
  public rows: Array<any>;
  public loading: Boolean;
  public firstItem = 0;
  public lastItem = 0;
  public skip = 0;
  public limit = 0;
  public total = 0;
  constructor() {
    this.rowSelect = new EventEmitter();
    this.rowAction = new EventEmitter();
    this.loading = true;
  }

  load(formio: FormioPromiseService, query?: any): Promise<any> {
    return formio.loadForm(query);
  }

  onRowSelect(event, row) {
    event.preventDefault();
    this.rowSelect.emit(row);
  }

  onRowAction(event, row, action) {
    event.preventDefault();
    this.rowAction.emit({ row, action });
  }

  /**
   * Set the rows for this Grid body.
   *
   * @param query
   * @param items
   * @return any
   */
  setRows(query: any, items: any) {
    this.rows = [];

    if (typeof items !== 'object') {
      this.firstItem = 0;
      this.lastItem = 0;
      this.total = 0;
      this.skip = 0;
      this.loading = false;
      return this.rows;
    }

    this.firstItem = query.skip + 1;
    this.lastItem = this.firstItem + items.length - 1;
    this.total = items.serverCount;
    this.limit = query.limit;
    this.skip = Math.floor(items.skip / query.limit) + 1;
    this.loading = false;
    each(items, (item: any) => {
      this.rows.push(clone(item));
    });
    return this.rows;
  }
}
{'fraction_non_alphanumeric': 0.13739612188365652, 'fraction_numerical': 0.006371191135734072, 'mean_word_length': 3.303933253873659, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '641121', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1153, 'n_words': 303}