Rewrite the Component PickWorkflow.vue into typescript

This commit is contained in:
Julien Fastré 2024-09-23 12:51:22 +02:00
parent 4b65ec9b54
commit 20e8b03588
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
6 changed files with 42 additions and 52 deletions

View File

@ -1,12 +1,8 @@
const buildLinkCreate = function(workflowName, relatedEntityClass, relatedEntityId) { export const buildLinkCreate = (workflowName: string, relatedEntityClass: string, relatedEntityId: number): string => {
let params = new URLSearchParams(); let params = new URLSearchParams();
params.set('entityClass', relatedEntityClass); params.set('entityClass', relatedEntityClass);
params.set('entityId', relatedEntityId); params.set('entityId', relatedEntityId.toString(10));
params.set('workflow', workflowName); params.set('workflow', workflowName);
return `/fr/main/workflow/create?`+params.toString(); return `/fr/main/workflow/create?`+params.toString();
}; };
export {
buildLinkCreate,
};

View File

@ -168,3 +168,8 @@ export interface NewsItemType {
startDate: DateTime; startDate: DateTime;
endDate: DateTime | null; endDate: DateTime | null;
} }
export interface WorkflowAvailable {
name: string;
text: string;
}

View File

@ -1,63 +1,52 @@
<template> <template>
<template v-if="workflowsAvailables.length >= 1"> <template v-if="props.workflowsAvailables.length >= 1">
<div class="dropdown d-grid gap-2"> <div class="dropdown d-grid gap-2">
<button class="btn btn-primary dropdown-toggle" type="button" id="createWorkflowButton" data-bs-toggle="dropdown" aria-expanded="false"> <button class="btn btn-primary dropdown-toggle" type="button" id="createWorkflowButton" data-bs-toggle="dropdown" aria-expanded="false">
Créer un workflow Créer un workflow
</button> </button>
<ul class="dropdown-menu" aria-labelledby="createWorkflowButton"> <ul class="dropdown-menu" aria-labelledby="createWorkflowButton">
<li v-for="w in workflowsAvailables" :key="w.name"> <li v-for="w in props.workflowsAvailables" :key="w.name">
<a class="dropdown-item" :href="makeLink(w.name)" @click.prevent="goToGenerateWorkflow($event, w.name)">{{ w.text }}</a> <button class="dropdown-item" type="button" @click.prevent="goToGenerateWorkflow($event, w.name)">{{ w.text }}</button>
</li> </li>
</ul> </ul>
</div> </div>
</template> </template>
</template> </template>
<script> <script setup lang="ts">
import {buildLinkCreate} from 'ChillMainAssets/lib/entity-workflow/api.js'; import {buildLinkCreate} from '../../../lib/entity-workflow/api';
import {WorkflowAvailable} from "../../../types";
export default { interface PickWorkflowConfig {
name: "PickWorkflow", relatedEntityClass: string;
props: { relatedEntityId: number;
relatedEntityClass: { workflowsAvailables: WorkflowAvailable[];
type: String, preventDefaultMoveToGenerate: boolean;
required: true, goToGenerateWorkflowPayload: object;
}, }
relatedEntityId: {
type: Number,
required: false,
},
workflowsAvailables: {
type: Array,
required: true,
},
preventDefaultMoveToGenerate: {
type: Boolean,
required: false,
default: false,
},
goToGenerateWorkflowPayload: {
required: false,
default: {}
},
},
emits: ['goToGenerateWorkflow'],
methods: {
makeLink(workflowName) {
return buildLinkCreate(workflowName, this.relatedEntityClass, this.relatedEntityId);
},
goToGenerateWorkflow(event, workflowName) {
console.log('goToGenerateWorkflow', event, workflowName);
if (!this.$props.preventDefaultMoveToGenerate) { const props = withDefaults(defineProps<PickWorkflowConfig>(), {preventDefaultMoveToGenerate: false, goToGenerateWorkflowPayload: {}});
console.log('to go generate');
window.location.assign(this.makeLink(workflowName));
}
this.$emit('goToGenerateWorkflow', {event, workflowName, link: this.makeLink(workflowName), payload: this.goToGenerateWorkflowPayload}); const emit = defineEmits<{
} (e: 'goToGenerateWorkflow', {event: MouseEvent, workflowName: string, link: string, payload: object}): void;
}>();
const makeLink = (workflowName: string): string => buildLinkCreate(workflowName, props.relatedEntityClass, props.relatedEntityId);
const goToGenerateWorkflow = (event: MouseEvent, workflowName: string): void => {
console.log('goToGenerateWorkflow', event, workflowName);
if (!props.preventDefaultMoveToGenerate) {
console.log('to go generate');
window.location.assign(makeLink(workflowName));
} }
emit('goToGenerateWorkflow', {event, workflowName, link: makeLink(workflowName), payload: props.goToGenerateWorkflowPayload});
}
const goToDuplicateRelatedEntity = (event: MouseEvent, workflowName: string): void => {
} }
</script> </script>

View File

@ -342,7 +342,7 @@ import OnTheFly from 'ChillMainAssets/vuejs/OnTheFly/components/OnTheFly.vue';
import ListWorkflowModal from 'ChillMainAssets/vuejs/_components/EntityWorkflow/ListWorkflowModal.vue'; import ListWorkflowModal from 'ChillMainAssets/vuejs/_components/EntityWorkflow/ListWorkflowModal.vue';
import PickWorkflow from 'ChillMainAssets/vuejs/_components/EntityWorkflow/PickWorkflow.vue'; import PickWorkflow from 'ChillMainAssets/vuejs/_components/EntityWorkflow/PickWorkflow.vue';
import PersonText from 'ChillPersonAssets/vuejs/_components/Entity/PersonText.vue'; import PersonText from 'ChillPersonAssets/vuejs/_components/Entity/PersonText.vue';
import {buildLinkCreate} from 'ChillMainAssets/lib/entity-workflow/api.js'; import {buildLinkCreate} from 'ChillMainAssets/lib/entity-workflow/api';
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods'; import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
const i18n = { const i18n = {

View File

@ -54,7 +54,7 @@
import FormEvaluation from './FormEvaluation.vue'; import FormEvaluation from './FormEvaluation.vue';
import Modal from 'ChillMainAssets/vuejs/_components/Modal'; import Modal from 'ChillMainAssets/vuejs/_components/Modal';
import ListWorkflowModal from 'ChillMainAssets/vuejs/_components/EntityWorkflow/ListWorkflowModal.vue'; import ListWorkflowModal from 'ChillMainAssets/vuejs/_components/EntityWorkflow/ListWorkflowModal.vue';
import {buildLinkCreate} from 'ChillMainAssets/lib/entity-workflow/api.js'; import {buildLinkCreate} from 'ChillMainAssets/lib/entity-workflow/api';
const i18n = { const i18n = {
messages: { messages: {

View File

@ -189,7 +189,7 @@ import { mapGetters, mapState } from 'vuex';
import PickTemplate from 'ChillDocGeneratorAssets/vuejs/_components/PickTemplate.vue'; import PickTemplate from 'ChillDocGeneratorAssets/vuejs/_components/PickTemplate.vue';
import {buildLink} from 'ChillDocGeneratorAssets/lib/document-generator'; import {buildLink} from 'ChillDocGeneratorAssets/lib/document-generator';
import ListWorkflowModal from 'ChillMainAssets/vuejs/_components/EntityWorkflow/ListWorkflowModal.vue'; import ListWorkflowModal from 'ChillMainAssets/vuejs/_components/EntityWorkflow/ListWorkflowModal.vue';
import {buildLinkCreate} from 'ChillMainAssets/lib/entity-workflow/api.js'; import {buildLinkCreate} from 'ChillMainAssets/lib/entity-workflow/api';
import {buildLinkCreate as buildLinkCreateNotification} from 'ChillMainAssets/lib/entity-notification/api'; import {buildLinkCreate as buildLinkCreateNotification} from 'ChillMainAssets/lib/entity-notification/api';
import DocumentActionButtonsGroup from "ChillDocStoreAssets/vuejs/DocumentActionButtonsGroup.vue"; import DocumentActionButtonsGroup from "ChillDocStoreAssets/vuejs/DocumentActionButtonsGroup.vue";
import DropFileModal from "ChillDocStoreAssets/vuejs/DropFileWidget/DropFileModal.vue"; import DropFileModal from "ChillDocStoreAssets/vuejs/DropFileWidget/DropFileModal.vue";