-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin): add autonomous courses list filters
- Loading branch information
Showing
2 changed files
with
129 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,81 @@ | ||
import PixInput from '@1024pix/pix-ui/components/pix-input'; | ||
import { fn } from '@ember/helper'; | ||
import { action } from '@ember/object'; | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { t } from 'ember-intl'; | ||
|
||
import ListItem from './item'; | ||
|
||
<template> | ||
<div class="content-text content-text--small"> | ||
<div class="table-admin"> | ||
<table> | ||
<caption class="screen-reader-only">{{t "components.autonomous-courses.list.title"}}</caption> | ||
<thead> | ||
<tr> | ||
<th scope="col" class="table__column table__column--id">{{t | ||
"components.autonomous-courses.list.headers.id" | ||
}}</th> | ||
<th scope="col">{{t "components.autonomous-courses.list.headers.name"}}</th> | ||
<th scope="col" class="table__column table__medium">{{t | ||
"components.autonomous-courses.list.headers.createdAt" | ||
}}</th> | ||
<th scope="col" class="table__column table__medium">{{t | ||
"components.autonomous-courses.list.headers.status" | ||
}}</th> | ||
</tr> | ||
</thead> | ||
|
||
{{#if @items}} | ||
<tbody> | ||
{{#each @items as |autonomousCourseListItem|}} | ||
<ListItem @item={{autonomousCourseListItem}} /> | ||
{{/each}} | ||
</tbody> | ||
{{/if}} | ||
</table> | ||
|
||
{{#unless @items}} | ||
<div class="table__empty">{{t "components.autonomous-courses.list.no-result"}}</div> | ||
{{/unless}} | ||
export default class AutonomousCoursesList extends Component { | ||
@tracked items = this.args.items; | ||
|
||
@action | ||
triggerFiltering(key, event) { | ||
function normalizeText(text) { | ||
return text | ||
.toUpperCase() | ||
.normalize('NFD') | ||
.replace(/[\u0300-\u036f]/g, '') | ||
.trim(); | ||
} | ||
|
||
const valueToSearch = normalizeText(event.target.value); | ||
|
||
this.items = this.args.items.filter((item) => { | ||
if (!valueToSearch) return true; | ||
return normalizeText(item[key]).includes(valueToSearch); | ||
}); | ||
} | ||
|
||
<template> | ||
<div class="content-text content-text--small"> | ||
<div class="table-admin"> | ||
<table> | ||
<caption class="screen-reader-only">{{t "components.autonomous-courses.list.title"}}</caption> | ||
<thead> | ||
<tr> | ||
<th scope="col" class="table__column table__column--id">{{t | ||
"components.autonomous-courses.list.headers.id" | ||
}}</th> | ||
<th scope="col">{{t "components.autonomous-courses.list.headers.name"}}</th> | ||
<th scope="col" class="table__column table__medium">{{t | ||
"components.autonomous-courses.list.headers.createdAt" | ||
}}</th> | ||
<th scope="col" class="table__column table__medium">{{t | ||
"components.autonomous-courses.list.headers.status" | ||
}}</th> | ||
</tr> | ||
<tr> | ||
<td> | ||
<PixInput id="id" type="text" oninput={{fn this.triggerFiltering "id"}} placeholder="Filtrer par ID" /> | ||
</td> | ||
<td> | ||
<PixInput | ||
id="id" | ||
type="text" | ||
oninput={{fn this.triggerFiltering "name"}} | ||
placeholder="Filtrer par nom" | ||
/> | ||
</td> | ||
<td></td> | ||
<td></td> | ||
</tr> | ||
</thead> | ||
|
||
{{#if this.items}} | ||
<tbody> | ||
{{#each this.items as |autonomousCourseListItem|}} | ||
<ListItem @item={{autonomousCourseListItem}} /> | ||
{{/each}} | ||
</tbody> | ||
{{/if}} | ||
</table> | ||
|
||
{{#unless @items}} | ||
<div class="table__empty">{{t "components.autonomous-courses.list.no-result"}}</div> | ||
{{/unless}} | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
</template> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters