mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 04:46:02 +00:00
added loadingformview
This commit is contained in:
@@ -16,87 +16,20 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import FormView from './FormView.svelte';
|
||||
import { apiCall } from '../utility/api';
|
||||
import ChangeSetGrider from '../datagrid/ChangeSetGrider';
|
||||
import _ from 'lodash';
|
||||
import LoadingFormView from './LoadingFormView.svelte';
|
||||
|
||||
export let changeSetState;
|
||||
export let dispatchChangeSet;
|
||||
export let masterLoadedTime;
|
||||
export let conid;
|
||||
export let database;
|
||||
export let onReferenceSourceChanged;
|
||||
export let display;
|
||||
|
||||
let isLoadingData = false;
|
||||
let isLoadedData = false;
|
||||
let rowData = null;
|
||||
let isLoadingCount = false;
|
||||
let isLoadedCount = false;
|
||||
let loadedTime = new Date().getTime();
|
||||
let allRowCount = null;
|
||||
let errorMessage = null;
|
||||
async function handleLoadRow() {
|
||||
return await loadRow($$props, display.getPageQuery(display.config.formViewRecordNumber || 0, 1));
|
||||
}
|
||||
|
||||
const handleLoadCurrentRow = async () => {
|
||||
if (isLoadingData) return;
|
||||
let newLoadedRow = false;
|
||||
isLoadingData = true;
|
||||
const row = await loadRow($$props, display.getPageQuery(display.config.formViewRecordNumber || 0, 1));
|
||||
isLoadingData = false;
|
||||
isLoadedData = true;
|
||||
rowData = row;
|
||||
loadedTime = new Date().getTime();
|
||||
newLoadedRow = row;
|
||||
};
|
||||
|
||||
const handleLoadRowCount = async () => {
|
||||
isLoadingCount = true;
|
||||
async function handleLoadRowCount() {
|
||||
const countRow = await loadRow($$props, display.getCountQuery());
|
||||
// const countBeforeRow = await loadRow($$props, formDisplay.getBeforeCountQuery());
|
||||
|
||||
isLoadedCount = true;
|
||||
isLoadingCount = false;
|
||||
allRowCount = countRow ? parseInt(countRow.count) : null;
|
||||
};
|
||||
|
||||
const handleNavigate = async command => {
|
||||
display.formViewNavigate(command, allRowCount);
|
||||
};
|
||||
|
||||
export function reload() {
|
||||
isLoadingData = false;
|
||||
isLoadedData = false;
|
||||
isLoadingCount = false;
|
||||
isLoadedCount = false;
|
||||
rowData = null;
|
||||
loadedTime = new Date().getTime();
|
||||
allRowCount = null;
|
||||
errorMessage = null;
|
||||
return countRow ? parseInt(countRow.count) : null;
|
||||
}
|
||||
|
||||
$: {
|
||||
if (masterLoadedTime && masterLoadedTime > loadedTime) {
|
||||
display.reload();
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
if (display?.cache?.refreshTime > loadedTime) {
|
||||
reload();
|
||||
}
|
||||
}
|
||||
|
||||
$: {
|
||||
if (display?.isLoadedCorrectly) {
|
||||
if (!isLoadedData && !isLoadingData) handleLoadCurrentRow();
|
||||
if (isLoadedData && !isLoadingCount && !isLoadedCount) handleLoadRowCount();
|
||||
}
|
||||
}
|
||||
|
||||
$: grider = new ChangeSetGrider(rowData ? [rowData] : [], changeSetState, dispatchChangeSet, display);
|
||||
|
||||
$: if (onReferenceSourceChanged && rowData) onReferenceSourceChanged([rowData], loadedTime);
|
||||
</script>
|
||||
|
||||
<FormView {...$$props} {grider} isLoading={isLoadingData} {allRowCount} onNavigate={handleNavigate} />
|
||||
<LoadingFormView {...$$props} loadRowFunc={handleLoadRow} loadRowCountFunc={handleLoadRowCount} />
|
||||
|
||||
Reference in New Issue
Block a user