mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Refactor ExportGeneration to improve serialization and usage
Streamlined the `ExportGeneration` entity by adding a `getStatus` accessor and updating the serialization group. Refactored frontend logic to use computed properties for `status` and `storedObject`. Simplified API methods to work with the updated `ExportGeneration` interface for consistent handling.
This commit is contained in:
parent
b2d8d21f04
commit
0c2508d26d
@ -59,7 +59,7 @@ final readonly class ExportGenerationController
|
|||||||
|
|
||||||
return new JsonResponse(
|
return new JsonResponse(
|
||||||
$this->serializer->serialize(
|
$this->serializer->serialize(
|
||||||
['status' => $exportGeneration->getStoredObject()->getStatus(), 'stored_object' => $exportGeneration->getStoredObject()],
|
$exportGeneration,
|
||||||
'json',
|
'json',
|
||||||
[AbstractNormalizer::GROUPS => ['read']],
|
[AbstractNormalizer::GROUPS => ['read']],
|
||||||
),
|
),
|
||||||
|
@ -99,6 +99,13 @@ class ExportGeneration implements TrackCreationInterface
|
|||||||
return $this->savedExport;
|
return $this->savedExport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[Serializer\Groups(['read'])]
|
||||||
|
#[Serializer\SerializedName('status')]
|
||||||
|
public function getStatus(): string
|
||||||
|
{
|
||||||
|
return $this->getStoredObject()->getStatus();
|
||||||
|
}
|
||||||
|
|
||||||
public function setSavedExport(SavedExport $savedExport): self
|
public function setSavedExport(SavedExport $savedExport): self
|
||||||
{
|
{
|
||||||
$this->savedExport = $savedExport;
|
$this->savedExport = $savedExport;
|
||||||
|
@ -1,14 +1,19 @@
|
|||||||
import { StoredObject, StoredObjectStatus } from "ChillDocStoreAssets/types";
|
import { StoredObject, StoredObjectStatus } from "ChillDocStoreAssets/types";
|
||||||
import { makeFetch } from "ChillMainAssets/lib/api/apiMethods";
|
import { makeFetch } from "ChillMainAssets/lib/api/apiMethods";
|
||||||
|
import {ExportGeneration} from "ChillMainAssets/types";
|
||||||
|
|
||||||
export const fetchExportGenerationStatus = async (
|
export const fetchExportGenerationStatus = async (
|
||||||
exportGenerationId: string,
|
exportGenerationId: string,
|
||||||
): Promise<
|
): Promise<ExportGeneration> =>
|
||||||
| { status: "pending" }
|
makeFetch(
|
||||||
| { status: StoredObjectStatus; stored_object: StoredObject }
|
|
||||||
> => {
|
|
||||||
return makeFetch(
|
|
||||||
"GET",
|
"GET",
|
||||||
`/api/1.0/main/export-generation/${exportGenerationId}/object`,
|
`/api/1.0/main/export-generation/${exportGenerationId}/object`,
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
export const generateFromSavedExport = async (
|
||||||
|
savedExportUuid: string,
|
||||||
|
): Promise<ExportGeneration> =>
|
||||||
|
makeFetch(
|
||||||
|
"POST",
|
||||||
|
`/api/1.0/main/export/export-generation/${savedExportUuid}`
|
||||||
|
);
|
@ -1,4 +1,5 @@
|
|||||||
import { GenericDoc } from "ChillDocStoreAssets/types/generic_doc";
|
import { GenericDoc } from "ChillDocStoreAssets/types/generic_doc";
|
||||||
|
import {StoredObject, StoredObjectStatus} from "ChillDocStoreAssets/types";
|
||||||
|
|
||||||
export interface DateTime {
|
export interface DateTime {
|
||||||
datetime: string;
|
datetime: string;
|
||||||
@ -203,3 +204,13 @@ export interface WorkflowAttachment {
|
|||||||
updatedBy: User | null;
|
updatedBy: User | null;
|
||||||
genericDoc: null | GenericDoc;
|
genericDoc: null | GenericDoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ExportGeneration {
|
||||||
|
id: string;
|
||||||
|
type: "export_generation";
|
||||||
|
exportAlias: string;
|
||||||
|
createdBy: User | null;
|
||||||
|
createdAt: DateTime | null;
|
||||||
|
status: StoredObjectStatus;
|
||||||
|
storedObject: StoredObject;
|
||||||
|
}
|
||||||
|
@ -8,8 +8,9 @@ import {
|
|||||||
} from "translator";
|
} from "translator";
|
||||||
import { computed, onMounted, ref } from "vue";
|
import { computed, onMounted, ref } from "vue";
|
||||||
import { StoredObject, StoredObjectStatus } from "ChillDocStoreAssets/types";
|
import { StoredObject, StoredObjectStatus } from "ChillDocStoreAssets/types";
|
||||||
import { fetchExportGenerationStatus } from "ChillMainAssets/vuejs/DownloadExport/api";
|
import { fetchExportGenerationStatus } from "ChillMainAssets/lib/api/export";
|
||||||
import DocumentActionButtonsGroup from "ChillDocStoreAssets/vuejs/DocumentActionButtonsGroup.vue";
|
import DocumentActionButtonsGroup from "ChillDocStoreAssets/vuejs/DocumentActionButtonsGroup.vue";
|
||||||
|
import {ExportGeneration} from "ChillMainAssets/types";
|
||||||
|
|
||||||
interface AppProps {
|
interface AppProps {
|
||||||
exportGenerationId: string;
|
exportGenerationId: string;
|
||||||
@ -19,8 +20,16 @@ interface AppProps {
|
|||||||
|
|
||||||
const props = defineProps<AppProps>();
|
const props = defineProps<AppProps>();
|
||||||
|
|
||||||
const status = ref<StoredObjectStatus>("pending");
|
const exportGeneration = ref<ExportGeneration|null>(null);
|
||||||
const storedObject = ref<null | StoredObject>(null);
|
|
||||||
|
const status = computed<StoredObjectStatus>(() => exportGeneration.value?.status ?? 'pending');
|
||||||
|
const storedObject = computed<null | StoredObject>(() => {
|
||||||
|
if (exportGeneration.value === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return exportGeneration.value?.storedObject;
|
||||||
|
}) ;
|
||||||
|
|
||||||
const isPending = computed<boolean>(() => status.value === "pending");
|
const isPending = computed<boolean>(() => status.value === "pending");
|
||||||
const isFetching = computed<boolean>(
|
const isFetching = computed<boolean>(
|
||||||
@ -56,18 +65,15 @@ const checkForReady = function (): void {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onObjectNewStatusCallback = async function (): Promise<void> {
|
const onObjectNewStatusCallback = async function (): Promise<void> {
|
||||||
let status_response = await fetchExportGenerationStatus(
|
exportGeneration.value = await fetchExportGenerationStatus(
|
||||||
props.exportGenerationId,
|
props.exportGenerationId,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (status_response.status === "pending") {
|
if (isPending) {
|
||||||
checkForReady();
|
checkForReady();
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
status.value = status_response.status;
|
|
||||||
storedObject.value = status_response.stored_object;
|
|
||||||
|
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user