From c65a208e34e7afd269d491c948da6cc82f56ddc3 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 12 Dec 2024 02:33:10 +0100 Subject: [PATCH] Add frontend for sorting --- resources/js/components/ui/Th.vue | 34 +++++++++++++++++++ resources/js/views/form/Participants.vue | 16 ++++++++- .../Form/ParticipantIndexActionTest.php | 2 ++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 resources/js/components/ui/Th.vue diff --git a/resources/js/components/ui/Th.vue b/resources/js/components/ui/Th.vue new file mode 100644 index 00000000..866ff5e5 --- /dev/null +++ b/resources/js/components/ui/Th.vue @@ -0,0 +1,34 @@ + + + diff --git a/resources/js/views/form/Participants.vue b/resources/js/views/form/Participants.vue index a46c8666..e418131e 100644 --- a/resources/js/views/form/Participants.vue +++ b/resources/js/views/form/Participants.vue @@ -69,7 +69,15 @@ - + @@ -174,6 +182,12 @@ var { meta, data, reload, reloadPage, axios, remove, toFilterString, url, update const activeColumns = computed(() => meta.value.columns.filter((c) => meta.value.form_meta.active_columns.includes(c.id))); +const getSort = computed(() => innerFilter.value.sort); + +async function setSort(column) { + innerFilter.value.sort = getSort.value.by === column ? {by: column, direction: !getSort.value.direction} : {by: column, direction: false}; +} + const activeColumnsConfig = computed({ get: () => meta.value.form_meta.active_columns, set: async (v) => { diff --git a/tests/EndToEnd/Form/ParticipantIndexActionTest.php b/tests/EndToEnd/Form/ParticipantIndexActionTest.php index cf0d363e..fafd01b2 100644 --- a/tests/EndToEnd/Form/ParticipantIndexActionTest.php +++ b/tests/EndToEnd/Form/ParticipantIndexActionTest.php @@ -255,6 +255,8 @@ it('test it orders participants by value', function (array $values, array $sorti sleep(2); $response = $this->callFilter('form.participant.index', ['sort' => ['by' => $key, 'direction' => $direction]], ['form' => $form]); + $response->assertJsonPath('meta.filter.sort.by', $key); + $response->assertJsonPath('meta.filter.sort.direction', $direction); foreach ($expected as $index => $value) { $response->assertJsonPath("data.{$index}.{$key}", $value);