{"size": 1118, "ext": "js", "max_stars_repo_path": "app/controllers/table/index.js", "max_stars_repo_name": "256dpi/thermo", "max_stars_repo_stars_event_min_datetime": "2020-11-03T22:32:04.000Z", "max_stars_repo_stars_event_max_datetime": "2020-11-03T22:32:04.000Z", "max_issues_repo_path": "app/controllers/table/index.js", "max_issues_repo_name": "256dpi/thermo", "max_issues_repo_issues_event_min_datetime": "2022-03-11T10:26:12.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-11T10:26:13.000Z", "max_forks_repo_path": "app/controllers/table/index.js", "max_forks_repo_name": "256dpi/thermo", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 20.7037037037, "max_line_length": 61, "alphanum_fraction": 0.5670840787}
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';

export default class extends Controller {
  queryParams = [
    {
      sort: 's',
      filter: 'f',
      pageSize: 'ps',
      pageNumber: 'pn',
      pageBefore: 'pb',
      pageAfter: 'pa',
    },
  ];

  @tracked sort = '';
  @tracked filter = '{}';
  @tracked pageSize = 25;
  @tracked pageNumber = 0;
  @tracked pageBefore = '';
  @tracked pageAfter = '';

  get decodeFilter() {
    try {
      return JSON.parse(decodeURIComponent(this.filter));
    } catch (e) {
      return {};
    }
  }

  @action encodeFilter(filter) {
    this.filter = encodeURIComponent(JSON.stringify(filter));
  }

  @action setPageNumber(num) {
    this.pageNumber = num > 1 ? num : 0;
  }

  @action setPageCursor(kind, cursor) {
    if (kind === 'before') {
      this.pageBefore = cursor;
      this.pageAfter = '';
    } else if (kind === 'after') {
      this.pageBefore = '';
      this.pageAfter = cursor === '*' ? '' : cursor;
    }
  }

  @action refresh() {
    this.route.refresh();
  }
}
