b3985db31f
* chore: remove commented out code and skipped tests * refact: triggeredBy requires filter expression not qp * refact: use filter expression dsl instead of named params * fix: add type * docs: add in-line reference to filter expression DSL * fix: update filter copy for non-matches * fix: correct conditional logic to render no match copy
103 lines
2.6 KiB
JavaScript
103 lines
2.6 KiB
JavaScript
import { inject as service } from '@ember/service';
|
|
import Route from '@ember/routing/route';
|
|
|
|
export default class EvaluationsIndexRoute extends Route {
|
|
@service store;
|
|
|
|
queryParams = {
|
|
pageSize: {
|
|
refreshModel: true,
|
|
},
|
|
nextToken: {
|
|
refreshModel: true,
|
|
},
|
|
status: {
|
|
refreshModel: true,
|
|
},
|
|
triggeredBy: {
|
|
refreshModel: true,
|
|
},
|
|
qpNamespace: {
|
|
refreshModel: true,
|
|
},
|
|
searchTerm: {
|
|
refreshModel: true,
|
|
},
|
|
type: {
|
|
refreshModel: true,
|
|
},
|
|
};
|
|
|
|
model({
|
|
nextToken,
|
|
pageSize,
|
|
searchTerm,
|
|
status,
|
|
triggeredBy,
|
|
type,
|
|
qpNamespace: namespace,
|
|
}) {
|
|
/*
|
|
We use our own DSL for filter expressions. This function takes our query parameters and builds a query that matches our DSL.
|
|
Documentation can be found here: https://www.nomadproject.io/api-docs#filtering
|
|
*/
|
|
const generateFilterExpression = () => {
|
|
const searchFilter = searchTerm
|
|
? `ID contains "${searchTerm}" or JobID contains "${searchTerm}" or NodeID contains "${searchTerm}" or TriggeredBy contains "${searchTerm}"`
|
|
: null;
|
|
const typeFilter =
|
|
type === 'client' ? `NodeID is not empty` : `NodeID is empty`;
|
|
const triggeredByFilter = `TriggeredBy contains "${triggeredBy}"`;
|
|
const statusFilter = `Status contains "${status}"`;
|
|
|
|
let filterExp;
|
|
if (searchTerm) {
|
|
if (!type && !status && !triggeredBy) {
|
|
return searchFilter;
|
|
}
|
|
filterExp = `(${searchFilter})`;
|
|
if (type) {
|
|
filterExp = `${filterExp} and ${typeFilter}`;
|
|
}
|
|
if (triggeredBy) {
|
|
filterExp = `${filterExp} and ${triggeredByFilter}`;
|
|
}
|
|
if (status) {
|
|
filterExp = `${filterExp} and ${statusFilter}`;
|
|
}
|
|
return filterExp;
|
|
}
|
|
|
|
if (type || status || triggeredBy) {
|
|
const lookup = {
|
|
[type]: typeFilter,
|
|
[status]: statusFilter,
|
|
[triggeredBy]: triggeredByFilter,
|
|
};
|
|
|
|
filterExp = [type, status, triggeredBy].reduce((result, filter) => {
|
|
const expression = lookup[filter];
|
|
if (!!filter && result !== '') {
|
|
result = result.concat(` and ${expression}`);
|
|
} else if (filter) {
|
|
result = expression;
|
|
}
|
|
return result;
|
|
}, '');
|
|
return filterExp;
|
|
}
|
|
|
|
return null;
|
|
};
|
|
|
|
this.store.findAll('namespace');
|
|
|
|
return this.store.query('evaluation', {
|
|
namespace,
|
|
per_page: pageSize,
|
|
next_token: nextToken,
|
|
filter: generateFilterExpression(),
|
|
});
|
|
}
|
|
}
|