Merge pull request #39 from kaermorchen/fix/task-api

Fix task api
This commit is contained in:
Stanislav Romanov 2023-03-02 11:06:52 +03:00 committed by GitHub
commit 00aea43519
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 49 deletions

View file

@ -10,31 +10,38 @@ export default class AdminTasksIndexController extends Controller {
taskStatuses = taskStatuses;
taskTypes = taskTypes;
queryParams = ['limit', 'status', 'type', 'indexUid'];
queryParams = ['limit', 'statuses', 'types', 'indexUids'];
@tracked limit = 20;
@tracked from;
@tracked status;
@tracked type;
@tracked indexUid;
@tracked statuses;
@tracked types;
@tracked indexUids;
@use
tasks = resource(() => {
tasks = resource(({ on }) => {
this.tasksHolder.isLoading = true;
const controller = new AbortController();
const params = {
limit: this.limit,
from: this.from,
status: this.status,
type: this.type,
indexUid: this.indexUid,
statuses: this.statuses,
types: this.types,
indexUids: this.indexUids,
};
this.meilisearch.getTasks(params).then((data) => {
this.tasksHolder.results = this.tasksHolder.results.concat(data.results);
this.tasksHolder.next = data.next;
this.tasksHolder.isLoading = false;
});
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;
});
return this.tasksHolder;
});

View file

@ -8,9 +8,9 @@ export default class AdminTasksIndexRoute extends Route {
queryParams = {
limit: { refreshModel: true },
status: { refreshModel: true },
type: { refreshModel: true },
indexUid: { refreshModel: true },
statuses: { refreshModel: true },
types: { refreshModel: true },
indexUids: { refreshModel: true },
};
model() {

View file

@ -68,7 +68,7 @@ export default class MeilisearchService extends Service {
}
getDumps() {
return this.getTasks({ type: 'dumpCreation' });
return this.getTasks({ types: 'dumpCreation' });
}
createDump() {

View file

@ -1,31 +1,31 @@
<Headers::H1 @title='Tasks' />
<div class='sm:flex sm:flex-nowrap'>
{{! indexUid }}
{{! indexUids }}
<Form::Listbox
@prefixValue={{'Index: '}}
@value={{nu-co this.indexUid 'none'}}
@value={{nu-co this.indexUids 'none'}}
@values={{map-by 'uid' @model.indexes.results}}
@onChange={{set this 'indexUid'}}
@onChange={{set this 'indexUids'}}
@allowClear={{true}}
/>
{{! status }}
{{! statuses }}
<Form::Listbox
@prefixValue={{'Status: '}}
@value={{nu-co this.status 'none'}}
@value={{nu-co this.statuses 'none'}}
@values={{this.taskStatuses}}
@onChange={{set this 'status'}}
@onChange={{set this 'statuses'}}
@allowClear={{true}}
class='sm:ml-4 sm:flex-none'
/>
{{! status }}
{{! types }}
<Form::Listbox
@prefixValue={{'Type: '}}
@value={{nu-co this.type 'none'}}
@value={{nu-co this.types 'none'}}
@values={{this.taskTypes}}
@onChange={{set this 'type'}}
@onChange={{set this 'types'}}
@allowClear={{true}}
class='sm:ml-4 sm:flex-none'
/>
@ -49,10 +49,7 @@
>{{data.uid}}</LinkTo>
</Column>
<Column @prop='indexUid'>
<LinkTo
@route='admin.indexes.item'
@model={{data.indexUid}}
>{{data.indexUid}}</LinkTo>
{{data.indexUid}}
</Column>
<Column @prop='status'>
<Badge @label={{data.status}} @style={{data.style}} />

View file

@ -16,29 +16,19 @@ export default function query(path, options = {}) {
Object.assign(options, { headers })
);
return fetch(req)
.then((response) => {
if (response.status === 204) {
return;
} else if (response.ok) {
return response.json();
} else {
return response.json().then((reason) => {
toaster.dangerToast({
header: reason.type,
text: reason.message,
});
// throw new Error('Network response was not OK');
});
}
})
.catch((response) => {
return fetch(req).then((response) => {
if (response.status === 204) {
return;
} else if (response.ok) {
return response.json();
} else {
return response.json().then((reason) => {
toaster.dangerToast({
header: reason.type,
text: reason.message,
});
// throw new Error('Network response was not OK');
});
});
}
});
}