2022-09-15 15:03:56 +00:00
|
|
|
import Controller from '@ember/controller';
|
|
|
|
|
import { tracked } from '@glimmer/tracking';
|
2022-09-16 10:12:57 +00:00
|
|
|
import { taskStatuses, taskTypes } from 'meiliadmin/models/task';
|
2022-09-16 12:32:08 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
|
import { resource, use } from 'ember-resources';
|
2022-09-15 15:03:56 +00:00
|
|
|
|
|
|
|
|
export default class AdminTasksIndexController extends Controller {
|
2022-09-16 12:32:08 +00:00
|
|
|
@service meilisearch;
|
|
|
|
|
|
2022-09-16 10:12:57 +00:00
|
|
|
taskStatuses = taskStatuses;
|
|
|
|
|
taskTypes = taskTypes;
|
|
|
|
|
|
2023-03-02 07:33:09 +00:00
|
|
|
queryParams = ['limit', 'statuses', 'types', 'indexUids'];
|
2022-09-16 12:32:08 +00:00
|
|
|
|
2022-09-15 15:03:56 +00:00
|
|
|
@tracked limit = 20;
|
|
|
|
|
@tracked from;
|
2023-03-02 07:33:09 +00:00
|
|
|
@tracked statuses;
|
|
|
|
|
@tracked types;
|
|
|
|
|
@tracked indexUids;
|
2022-09-15 15:03:56 +00:00
|
|
|
|
2022-09-16 12:32:08 +00:00
|
|
|
@use
|
2023-03-02 07:57:10 +00:00
|
|
|
tasks = resource(({ on }) => {
|
2022-09-16 12:32:08 +00:00
|
|
|
this.tasksHolder.isLoading = true;
|
|
|
|
|
|
2023-03-02 07:57:10 +00:00
|
|
|
const controller = new AbortController();
|
2022-09-16 12:32:08 +00:00
|
|
|
const params = {
|
|
|
|
|
limit: this.limit,
|
|
|
|
|
from: this.from,
|
2023-03-02 07:33:09 +00:00
|
|
|
statuses: this.statuses,
|
|
|
|
|
types: this.types,
|
|
|
|
|
indexUids: this.indexUids,
|
2022-09-16 12:32:08 +00:00
|
|
|
};
|
|
|
|
|
|
2023-03-02 07:57:10 +00:00
|
|
|
on.cleanup(() => controller.abort());
|
|
|
|
|
|
|
|
|
|
this.meilisearch
|
|
|
|
|
.getTasks(params, { signal: controller.signal })
|
|
|
|
|
.then((data) => {
|
|
|
|
|
this.tasksHolder.results = this.tasksHolder.results.concat(
|
|
|
|
|
data.results
|
|
|
|
|
);
|
|
|
|
|
this.tasksHolder.next = data.next;
|
|
|
|
|
this.tasksHolder.isLoading = false;
|
|
|
|
|
});
|
2022-09-16 12:32:08 +00:00
|
|
|
|
|
|
|
|
return this.tasksHolder;
|
|
|
|
|
});
|
2022-09-15 15:03:56 +00:00
|
|
|
}
|