Add luma pagination (#187)
This commit is contained in:
1 parent
f701ae05b1
commit
f837700d02
9 files changed
+105
-29
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "patch",
|
||||||
|
"comment": "add luma pagination",
|
||||||
|
"packageName": "@acedatacloud/nexior",
|
||||||
|
"email": "1348977728@qq.com",
|
||||||
|
"dependentChangeType": "patch"
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="panel recent">
|
<div ref="panel" class="panel recent" @scroll="onHandleScroll">
|
||||||
<div v-if="tasks?.items === undefined" class="tasks">
|
<div v-if="tasks?.items === undefined" class="tasks">
|
||||||
<div v-for="_ in 3" :key="_" class="task placeholder">
|
<div v-for="_ in 3" :key="_" class="task placeholder">
|
||||||
<div class="left">
|
<div class="left">
|
||||||
@@ -40,6 +40,7 @@ export default defineComponent({
|
|||||||
ElSkeleton,
|
ElSkeleton,
|
||||||
ElSkeletonItem
|
ElSkeletonItem
|
||||||
},
|
},
|
||||||
|
emits: ['reach-top'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
job: 0
|
job: 0
|
||||||
@@ -50,9 +51,18 @@ export default defineComponent({
|
|||||||
// reverse the order of the tasks.items
|
// reverse the order of the tasks.items
|
||||||
return {
|
return {
|
||||||
...this.$store.state.luma?.tasks,
|
...this.$store.state.luma?.tasks,
|
||||||
items: this.$store.state.luma?.tasks?.items?.slice().reverse()
|
items: this.$store.state.luma?.tasks?.items?.slice()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onHandleScroll() {
|
||||||
|
const el = this.$refs.panel as HTMLElement;
|
||||||
|
console.log('reach-top reach-top reach-top');
|
||||||
|
if (el.scrollTop === 0) {
|
||||||
|
this.$emit('reach-top');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
type="textarea"
|
type="textarea"
|
||||||
class="prompt"
|
class="prompt"
|
||||||
:placeholder="$t('luma.placeholder.prompt')"
|
:placeholder="$t('luma.placeholder.prompt')"
|
||||||
:maxlength="300"
|
:maxlength="2000"
|
||||||
show-word-limit
|
show-word-limit
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -14,13 +14,7 @@
|
|||||||
<p v-if="modelValue?.request?.prompt" class="prompt mt-2">
|
<p v-if="modelValue?.request?.prompt" class="prompt mt-2">
|
||||||
{{ modelValue?.request?.prompt }}
|
{{ modelValue?.request?.prompt }}
|
||||||
<span v-if="!modelValue?.response"> - ({{ $t('luma.status.pending') }}) </span>
|
<span v-if="!modelValue?.response"> - ({{ $t('luma.status.pending') }}) </span>
|
||||||
<span
|
<span v-if="modelValue?.response?.state === 'processing' || modelValue?.response?.state === 'pending'">
|
||||||
v-if="
|
|
||||||
modelValue?.response?.data?.state === 'processing' ||
|
|
||||||
modelValue?.response?.data?.state === 'pending' ||
|
|
||||||
modelValue?.response?.data?.state === 'completed'
|
|
||||||
"
|
|
||||||
>
|
|
||||||
- ({{ $t('luma.status.processing') }})
|
- ({{ $t('luma.status.processing') }})
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
@@ -57,7 +51,10 @@
|
|||||||
</el-alert>
|
</el-alert>
|
||||||
</div>
|
</div>
|
||||||
<!-- Display error message -->
|
<!-- Display error message -->
|
||||||
<div v-if="modelValue?.response?.success === false" :class="{ content: true }">
|
<div
|
||||||
|
v-if="modelValue?.response?.state === 'failed' || modelValue?.response?.success === false"
|
||||||
|
:class="{ content: true }"
|
||||||
|
>
|
||||||
<el-alert :closable="false" class="failure">
|
<el-alert :closable="false" class="failure">
|
||||||
<template #template>
|
<template #template>
|
||||||
<font-awesome-icon icon="fa-solid fa-exclamation-triangle" class="mr-1" />
|
<font-awesome-icon icon="fa-solid fa-exclamation-triangle" class="mr-1" />
|
||||||
@@ -78,7 +75,7 @@
|
|||||||
<p class="description">
|
<p class="description">
|
||||||
<font-awesome-icon icon="fa-solid fa-hashtag" class="mr-1" />
|
<font-awesome-icon icon="fa-solid fa-hashtag" class="mr-1" />
|
||||||
{{ $t('luma.name.traceId') }}:
|
{{ $t('luma.name.traceId') }}:
|
||||||
{{ modelValue?.response?.trace_id }}
|
{{ modelValue?.trace_id }}
|
||||||
<copy-to-clipboard :content="modelValue?.response?.trace_id" class="btn-copy" />
|
<copy-to-clipboard :content="modelValue?.response?.trace_id" class="btn-copy" />
|
||||||
</p>
|
</p>
|
||||||
</el-alert>
|
</el-alert>
|
||||||
|
|||||||
+2
-1
@@ -48,7 +48,8 @@ export interface ILumaGenerateResponse {
|
|||||||
|
|
||||||
export interface ILumaTask {
|
export interface ILumaTask {
|
||||||
id: string;
|
id: string;
|
||||||
created_at?: string;
|
created_at?: number;
|
||||||
|
trace_id?: string;
|
||||||
request?: ILumaGenerateRequest;
|
request?: ILumaGenerateRequest;
|
||||||
response?: ILumaGenerateResponse;
|
response?: ILumaGenerateResponse;
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-1
@@ -23,7 +23,15 @@ class LumaOperator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async tasks(
|
async tasks(
|
||||||
filter: { ids?: string[]; applicationId?: string; userId?: string; limit?: number; offset?: number },
|
filter: {
|
||||||
|
ids?: string[];
|
||||||
|
applicationId?: string;
|
||||||
|
userId?: string;
|
||||||
|
limit?: number;
|
||||||
|
offset?: number;
|
||||||
|
createdAtMax?: number;
|
||||||
|
createdAtMin?: number;
|
||||||
|
},
|
||||||
options: { token: string }
|
options: { token: string }
|
||||||
): Promise<AxiosResponse<ILumaTasksResponse>> {
|
): Promise<AxiosResponse<ILumaTasksResponse>> {
|
||||||
return await axios.post(
|
return await axios.post(
|
||||||
@@ -54,6 +62,16 @@ class LumaOperator {
|
|||||||
? {
|
? {
|
||||||
offset: filter.offset
|
offset: filter.offset
|
||||||
}
|
}
|
||||||
|
: {}),
|
||||||
|
...(filter.createdAtMax !== undefined
|
||||||
|
? {
|
||||||
|
created_at_max: filter.createdAtMax
|
||||||
|
}
|
||||||
|
: {}),
|
||||||
|
...(filter.createdAtMin !== undefined
|
||||||
|
? {
|
||||||
|
created_at_min: filter.createdAtMin
|
||||||
|
}
|
||||||
: {})
|
: {})
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
+38
-10
@@ -14,7 +14,7 @@
|
|||||||
@refresh="onGetApplication"
|
@refresh="onGetApplication"
|
||||||
@select="$store.dispatch('luma/setApplication', $event)"
|
@select="$store.dispatch('luma/setApplication', $event)"
|
||||||
/>
|
/>
|
||||||
<recent-panel class="panel recent" />
|
<recent-panel class="panel recent" @reach-top="onReachTop" />
|
||||||
<!-- <operation-panel class="panel operation" @generate="onGenerate" /> -->
|
<!-- <operation-panel class="panel operation" @generate="onGenerate" /> -->
|
||||||
</template>
|
</template>
|
||||||
</layout>
|
</layout>
|
||||||
@@ -37,6 +37,7 @@ const CALLBACK_URL = 'https://webhook.acedata.cloud/luma';
|
|||||||
interface IData {
|
interface IData {
|
||||||
task: ILumaTask | undefined;
|
task: ILumaTask | undefined;
|
||||||
job: number;
|
job: number;
|
||||||
|
timer: NodeJS.Timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@@ -50,7 +51,9 @@ export default defineComponent({
|
|||||||
data(): IData {
|
data(): IData {
|
||||||
return {
|
return {
|
||||||
task: undefined,
|
task: undefined,
|
||||||
job: 0
|
job: 0,
|
||||||
|
// @ts-ignore
|
||||||
|
timer: undefined
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -75,8 +78,20 @@ export default defineComponent({
|
|||||||
application() {
|
application() {
|
||||||
return this.$store.state.luma.application;
|
return this.$store.state.luma.application;
|
||||||
},
|
},
|
||||||
applications() {
|
tasks() {
|
||||||
return this.$store.state.luma.applications;
|
return this.$store.state.luma.tasks;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
tasks: {
|
||||||
|
handler(value, oldValue) {
|
||||||
|
// scroll down if new tasks are added
|
||||||
|
if (value?.items?.length > oldValue?.items?.length) {
|
||||||
|
console.debug('new tasks detected');
|
||||||
|
// this.onScrollDown();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
deep: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
async mounted() {
|
||||||
@@ -84,7 +99,7 @@ export default defineComponent({
|
|||||||
await this.onGetApplication();
|
await this.onGetApplication();
|
||||||
await this.onScrollDown();
|
await this.onScrollDown();
|
||||||
await this.onGetTasks();
|
await this.onGetTasks();
|
||||||
await this.onScrollDown();
|
// await this.onScrollDown();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.job = setInterval(() => {
|
this.job = setInterval(() => {
|
||||||
this.onGetTasks();
|
this.onGetTasks();
|
||||||
@@ -92,8 +107,15 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
async unmounted() {
|
async unmounted() {
|
||||||
clearInterval(this.job);
|
clearInterval(this.job);
|
||||||
|
clearInterval(this.timer);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async onReachTop() {
|
||||||
|
console.debug('reached top');
|
||||||
|
await this.onGetTasks({
|
||||||
|
createdAtMax: this.tasks?.items?.[0]?.created_at
|
||||||
|
});
|
||||||
|
},
|
||||||
async onGetService() {
|
async onGetService() {
|
||||||
console.debug('start onGetService');
|
console.debug('start onGetService');
|
||||||
await this.$store.dispatch('luma/getService');
|
await this.$store.dispatch('luma/getService');
|
||||||
@@ -130,14 +152,18 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
},
|
},
|
||||||
async onGetTasks() {
|
async onGetTasks(payload?: { limit?: number; createdAtMin?: number; createdAtMax?: number }) {
|
||||||
if (this.loading) {
|
if (this.loading) {
|
||||||
console.debug('loading');
|
console.debug('loading');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.debug('start onGetTasks', payload);
|
||||||
|
const { limit = 5, createdAtMin, createdAtMax } = payload || {};
|
||||||
|
console.debug('limit', limit, 'createdAtMin', createdAtMin, 'createdAtMax', createdAtMax);
|
||||||
await this.$store.dispatch('luma/getTasks', {
|
await this.$store.dispatch('luma/getTasks', {
|
||||||
limit: 30,
|
limit,
|
||||||
offset: 0
|
createdAtMin,
|
||||||
|
createdAtMax
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async onGenerateVideo() {
|
async onGenerateVideo() {
|
||||||
@@ -170,8 +196,10 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.finally(async () => {
|
.finally(async () => {
|
||||||
await this.onGetTasks();
|
setTimeout(async () => {
|
||||||
await this.onScrollDown();
|
await this.onGetTasks();
|
||||||
|
await this.onScrollDown();
|
||||||
|
}, 1000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { IRootState } from '../common/models';
|
|||||||
import { IApplication, ICredential, ILumaConfig, ILumaTask, IService, IApplicationType } from '@/models';
|
import { IApplication, ICredential, ILumaConfig, ILumaTask, IService, IApplicationType } from '@/models';
|
||||||
import { Status } from '@/models/common';
|
import { Status } from '@/models/common';
|
||||||
import { LUMA_SERVICE_ID } from '@/constants';
|
import { LUMA_SERVICE_ID } from '@/constants';
|
||||||
|
import { mergeAndSortLists } from '@/utils/merge';
|
||||||
|
|
||||||
export const resetAll = ({ commit }: ActionContext<ILumaState, IRootState>): void => {
|
export const resetAll = ({ commit }: ActionContext<ILumaState, IRootState>): void => {
|
||||||
commit('resetAll');
|
commit('resetAll');
|
||||||
@@ -120,7 +121,12 @@ export const getService = async ({ commit, state }: ActionContext<ILumaState, IR
|
|||||||
|
|
||||||
export const getTasks = async (
|
export const getTasks = async (
|
||||||
{ commit, state, rootState }: ActionContext<ILumaState, IRootState>,
|
{ commit, state, rootState }: ActionContext<ILumaState, IRootState>,
|
||||||
{ offset, limit }: { offset?: number; limit?: number }
|
{
|
||||||
|
offset,
|
||||||
|
limit,
|
||||||
|
createdAtMin,
|
||||||
|
createdAtMax
|
||||||
|
}: { offset?: number; limit?: number; createdAtMin?: number; createdAtMax?: number }
|
||||||
): Promise<ILumaTask[]> => {
|
): Promise<ILumaTask[]> => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
console.debug('start to get tasks', offset, limit);
|
console.debug('start to get tasks', offset, limit);
|
||||||
@@ -132,15 +138,24 @@ export const getTasks = async (
|
|||||||
lumaOperator
|
lumaOperator
|
||||||
.tasks(
|
.tasks(
|
||||||
{
|
{
|
||||||
userId: rootState?.user?.id
|
userId: rootState?.user?.id,
|
||||||
|
createdAtMin,
|
||||||
|
createdAtMax
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
token
|
token
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.debug('get imagine tasks success', response.data.items);
|
console.debug('get luma tasks success', response.data.items);
|
||||||
commit('setTasksItems', response.data.items);
|
// merge with existing tasks
|
||||||
|
const existingItems = state?.tasks?.items || [];
|
||||||
|
console.debug('existing items', existingItems);
|
||||||
|
const newItems = response.data.items || [];
|
||||||
|
console.debug('new items', newItems);
|
||||||
|
// sort and de-duplicate using created_at
|
||||||
|
const mergedItems = mergeAndSortLists(existingItems, newItems);
|
||||||
|
commit('setTasksItems', mergedItems);
|
||||||
commit('setTasksTotal', response.data.count);
|
commit('setTasksTotal', response.data.count);
|
||||||
resolve(response.data.items);
|
resolve(response.data.items);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export default ['luma.credential', 'luma.application', 'luma.tasks'];
|
export default ['luma.credential', 'luma.application'];
|
||||||
Reference in new issue
Block a user