Skip to content

Commit 57492ba

Browse files
committed
fix(viewer): graceful pagination when backend returns @odata.count=0
The custom -data service endpoint returns @odata.count:0 rather than the real total. Fall back to page-size heuristic: Next is enabled when a full page was returned (data.length >= top), disabled on a short page. Record count shows 'X-Y rows' without total when count unavailable. Also add inline script SHA hash to CSP so theme-init IIFE is permitted.
1 parent f130576 commit 57492ba

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

cap/app/viewer/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ const app = Vue.createApp({
257257
if (this.skip > 0) this.skip = Math.max(0, this.skip - this.top)
258258
},
259259
nextPage() {
260-
if (this.skip + this.top < this.totalCount) this.skip += this.top
260+
if (this.skip + this.top < this.totalCount || (this.totalCount === 0 && this.data.length >= this.top)) this.skip += this.top
261261
},
262262

263263
// ── Column visibility ──────────────────────────────────

cap/app/viewer/index.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
77
<!-- 'unsafe-eval' required: Vue 3 CDN build compiles in-DOM templates via new Function() at runtime.
8-
Remove if switching to a pre-compiled (SFC + build step) approach. -->
8+
Remove if switching to a pre-compiled (SFC + build step) approach.
9+
sha256 hash permits the theme-init inline script without 'unsafe-inline'. -->
910
<meta http-equiv="Content-Security-Policy"
10-
content="default-src 'none'; script-src 'self' https://cdn.jsdelivr.net 'unsafe-eval'; style-src 'self' 'unsafe-inline'; connect-src 'self' https://cdn.jsdelivr.net">
11+
content="default-src 'none'; script-src 'self' https://cdn.jsdelivr.net 'unsafe-eval' 'sha256-N4WklxMrXQgruarjLCMlEllSgqwMIdw+mSI73XtOD+w='; style-src 'self' 'unsafe-inline'; connect-src 'self' https://cdn.jsdelivr.net">
1112
<title>Data Browser</title>
1213

1314
<!-- Theme init: runs before body renders to avoid flash of wrong theme -->
@@ -287,7 +288,8 @@ <h1>Data Browser<span v-if="entity"> &mdash; {{ entity.name }}</span></h1>
287288
<span class="record-count">
288289
<template v-if="loading">Loading&hellip;</template>
289290
<template v-else-if="!search && totalCount > 0">{{ skip + 1 }}&ndash;{{ Math.min(skip + top, totalCount) }} of {{ totalCount }} rows</template>
290-
<template v-else-if="search">{{ filteredData.length }} of {{ totalCount }} rows (filtered)</template>
291+
<template v-else-if="!search && data.length">{{ skip + 1 }}&ndash;{{ skip + data.length }} rows</template>
292+
<template v-else-if="search">{{ filteredData.length }} rows (filtered)</template>
291293
</span>
292294

293295
<!-- Column visibility -->
@@ -310,7 +312,7 @@ <h1>Data Browser<span v-if="entity"> &mdash; {{ entity.name }}</span></h1>
310312
<option :value="50">50</option>
311313
<option :value="100">100</option>
312314
</select>
313-
<button type="button" class="btn-page" @click="nextPage" :disabled="skip + top >= totalCount">Next &#8250;</button>
315+
<button type="button" class="btn-page" @click="nextPage" :disabled="totalCount > 0 ? skip + top >= totalCount : data.length < top">Next &#8250;</button>
314316
</div>
315317
</div>
316318

0 commit comments

Comments
 (0)