Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add persistent query and paging #70

Merged
merged 5 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const router = createRouter({
name: "search",
component: () => import("../views/search/SearchView.vue"),
},
{
path: "/search/:query",
name: "search-query",
component: () => import("../views/search/SearchView.vue"),
props: true,
},
{
path: "/imprint",
name: "imprint",
Expand Down
36 changes: 36 additions & 0 deletions src/views/search/SearchView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,29 @@ import {
import ExportProgress from "./ExportProgress.vue";
import { downloadFullTsv, type ProgressEvent } from "./ExportTsv";
import ResultTable from "./ResultTable.vue";
import { useRoute } from "vue-router";
import router from "@/router";
crsct marked this conversation as resolved.
Show resolved Hide resolved
const pageState = usePageState();
const searchState = usePageState();
const entries: Ref<BakrepSearchResultEntry[]> = ref([]);

const api = useApi();
const route = useRoute();

const pagination: Ref<PaginationData> = ref(empty());
const query: Ref<CompoundQuery> = ref({ op: "and", value: [] });
const ordering: Ref<SortOption[]> = ref([{ field: "id", ord: "asc" }]);
const searchinfo: Ref<SearchInfo> = ref({ fields: [] });
let startingOffset: number = 0;

if (route.params.query) {
const importedData = importQuery(route.params.query as string);
pagination.value.limit = importedData.pagination;
query.value = importedData.query;
ordering.value = importedData.ordering;
startingOffset = importedData.offset;
}
crsct marked this conversation as resolved.
Show resolved Hide resolved

function init() {
pageState.value.setState(State.Loading);
api
Expand All @@ -52,6 +66,11 @@ function init() {
searchinfo.value = r;
pageState.value.setState(State.Main);
})
.then(() => {
if (route.params.query) {
search(startingOffset);
}
})
.catch((err) => pageState.value.setError(err));
}

Expand Down Expand Up @@ -158,6 +177,8 @@ const fieldNames: Record<string, FieldConfiguration> = {
function search(offset = 0) {
searchState.value.setState(State.Loading);
resetTsvExport();
const b64 = exportQuery(offset);
crsct marked this conversation as resolved.
Show resolved Hide resolved
router.push({ name: "search-query", params: { query: b64 } });
api
.search({
query: unref(query),
Expand All @@ -174,6 +195,21 @@ function search(offset = 0) {
.catch((err) => pageState.value.setError(err));
}

function exportQuery(offset: number): string {
crsct marked this conversation as resolved.
Show resolved Hide resolved
const data = {
query: query.value,
ordering: ordering.value,
pagination: pagination.value.limit,
offset: offset,
};

return btoa(JSON.stringify(data));
}

function importQuery(base64: string) {
crsct marked this conversation as resolved.
Show resolved Hide resolved
return JSON.parse(atob(base64));
}

const positionInResults: Ref<PositionInResult> = computed(() =>
toPosition(pagination.value),
);
Expand Down