Skip to content

Commit 69a5c4c

Browse files
committed
feat: implement dynamic lifecycle enum and update lifecycle handling in components
1 parent 149d846 commit 69a5c4c

File tree

7 files changed

+138
-112
lines changed

7 files changed

+138
-112
lines changed

a faire.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cycle de vie enum dynamique,
2+
en dur ACTIVE devient OFFICIAL, INACTIF, MANUEL
3+
les autres sont par defaut
4+
5+
ficher default cycle de vie:
6+
En Attente = supannRessourceEtat : {COMPTE} A SupannAnticipe
7+
OFFI = supannRessourceEtat : {COMPTE} A SupannActif
8+
PROV = supannResourceEtat : {COMTE} A SupannSursis et supannRessourceEtatDate: Date de passage en PROV
9+
INACTIF = supannRessourceEtat : {COMPTE} I SupannInactif
10+
A Détruire = supannRessourceEtat : {COMPTE} I SupannSupprCompte
11+
Vérouillé = supannRessourceEtat : {COMPTE} S SupannVerrouille
12+
13+
trigger devient un nombre positif / dernier etat superieur a x jours
14+
ajouter une clé mutation
15+
16+
17+
voir le diff des modifs

src/components/identityForm/actions.vue

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,26 @@ div.flex
5252

5353
q-separator(v-if="props.identity?._id" size='3px' vertical)
5454

55+
div(ref='targetEl' style='display: height: 36px;')
56+
q-tooltip.text-body2(:target="targetEl" anchor="top middle" self="bottom middle") État du cycle de vie : {{ stateName }}
57+
q-btn-dropdown.q-pl-sm.full-height(icon='mdi-clock' color='purple-8' square unelevated dense)
58+
q-list
59+
q-item(
60+
v-for='stateItem in stateList' :key='stateItem.key'
61+
@click="switchLifecycle(stateItem.key)"
62+
:active='stateItem.key === props.identity.lifecycle'
63+
active-class="bg-purple-8 text-white"
64+
clickable v-close-popup
65+
)
66+
q-item-section(avatar)
67+
q-icon(:name="stateItem.icon || 'mdi-help-rhombus-outline'" :color="stateItem.color")
68+
q-item-section
69+
q-item-label
70+
span(v-text='stateItem.label')
71+
|  
72+
small(v-text='("(" + stateItem.key + ")")')
73+
q-separator(size='3px' vertical)
74+
5575
q-btn-dropdown.text-white(v-if="props.identity?._id" dropdown-icon="mdi-dots-vertical" style='background-color: rgba(0, 0, 0, .6)' padding='5px 10px' dense no-caps)
5676
q-list
5777
a(:href="'/jobs?filters[:concernedTo.id]=' + props.identity?._id" target="_blank" style='text-decoration: none; color: inherit' @click.prevent="dialogLog = true")
@@ -128,6 +148,7 @@ import InputNewPassword from '~/components/inputNewPassword.vue'
128148
const resetPasswordModal = ref(false)
129149
const forcePasswordModal = ref(false)
130150
151+
const targetEl = ref()
131152
const newpassword = ref('')
132153
type IdentityResponse = operations['IdentitiesController_search']['responses']['200']['content']['application/json']
133154
type Identity = components['schemas']['IdentitiesDto']
@@ -157,6 +178,7 @@ const props = defineProps({
157178
const $q = useQuasar()
158179
const router = useRouter()
159180
const { getStateColor, getStateName } = useIdentityStates()
181+
const { getLifecycleColor, getLifecycleName, getLifecycleIcon, stateList } = await useIdentityLifecycles()
160182
const { handleError } = useErrorHandling()
161183
162184
const emits = defineEmits(['submit', 'sync', 'logs', 'create', 'delete'])
@@ -166,6 +188,27 @@ const validationsModal = ref(false)
166188
const dialogLog = ref(false)
167189
const dialogLifecycle = ref(false)
168190
191+
async function switchLifecycle(lifecycle: string) {
192+
const requestOptions = { method: 'POST', body: JSON.stringify({ lifecycle }) }
193+
try {
194+
const data = await $http.patch(`/management/identities/${props.identity._id}/lifecycle`, requestOptions)
195+
$q.notify({
196+
message: 'Le cycle de vie a été mis à jour : ' + data._data?.data?.lifecycle,
197+
color: 'positive',
198+
position: 'top-right',
199+
icon: 'mdi-check-circle-outline',
200+
})
201+
props?.refreshTarget(props.identity)
202+
} catch (error) {
203+
$q.notify({
204+
message: 'Impossible de modifier le cycle de vie : ' + error.response._data.message,
205+
color: 'negative',
206+
position: 'top-right',
207+
icon: 'mdi-alert-circle-outline',
208+
})
209+
}
210+
}
211+
169212
async function doChangePassword() {
170213
const requestOptions = { method: 'POST', body: JSON.stringify({ id: props.identity._id, newPassword: newpassword.value }) }
171214
try {
@@ -346,11 +389,26 @@ const stateName = computed(() => {
346389
return getStateName(state)
347390
})
348391
392+
const lifecycleName = computed(() => {
393+
const lifecycle = props.identity?.lifecycle
394+
return getLifecycleName(lifecycle)
395+
})
396+
349397
const stateColor = computed(() => {
350398
const state = props.identity?.state
351399
return getStateColor(state)
352400
})
353401
402+
const lifecycleColor = computed(() => {
403+
const lifecycle = props.identity?.lifecycle
404+
return getLifecycleColor(lifecycle)
405+
})
406+
407+
const lifecycleIcon = computed(() => {
408+
const lifecycle = props.identity?.lifecycle
409+
return getLifecycleIcon(lifecycle)
410+
})
411+
354412
async function sync() {
355413
emits('sync')
356414
}

src/components/table/state-col.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<template lang="pug">
22
q-td
33
q-icon(:name="stateInfo.icon" :color="stateInfo.color" :style='{color: stateInfo.color.startsWith("#") ? stateInfo.color : "inherit"}' :class="`q-mr-md`")
4-
q-tooltip.text-body2(slot="trigger") Etat : {{ stateInfo.name }}
5-
q-icon(:name="initStateInfo.icon" :color="initStateInfo.color" :style='{color: initStateInfo.color.startsWith("#") ? initStateInfo.color : "inherit"}' :class="`q-mr-md`")
6-
q-tooltip.text-body2(slot="trigger") Initialisation du compte : {{ initStateInfo.name }}
7-
q-icon(:name="lifecycleInfo.icon" :color="lifecycleInfo.color" :style='{color: lifecycleInfo.color.startsWith("#") ? lifecycleInfo.color : "inherit"}' :class="`q-mr-md`")
8-
q-tooltip.text-body2(slot="trigger") Cycle de vie : {{ lifecycleInfo.name }}
4+
q-tooltip.text-body2(slot="trigger") Etat : {{ stateInfo.name }} ({{ stateInfo.value || '?' }})
5+
q-icon(:name="initStateInfo.icon" :color="initStateInfo.color" :style='{color: initStateInfo.color?.startsWith("#") ? initStateInfo.color : "inherit"}' :class="`q-mr-md`")
6+
q-tooltip.text-body2(slot="trigger") Initialisation du compte : {{ initStateInfo.name }} ({{ initStateInfo.value || '?' }})
7+
q-icon(:name="lifecycleInfo.icon" :color="lifecycleInfo.color" :style='{color: lifecycleInfo.color?.startsWith("#") ? lifecycleInfo.color : "inherit"}' :class="`q-mr-md`")
8+
q-tooltip.text-body2(slot="trigger") Cycle de vie : {{ lifecycleInfo.name }} ({{ lifecycleInfo.value || '?' }})
99
</template>
1010

1111
<script lang="ts" setup>
@@ -16,7 +16,7 @@ import type { PropType } from 'vue'
1616
import { useIdentityStates, useIdentityLifecycles, useIdentityInitStates } from '~/composables'
1717
const { getStateColor, getStateName, getStateInfos } = useIdentityStates()
1818
const { getInitStateColor, getInitStateName, getInitStateInfos } = useIdentityInitStates()
19-
const { getLifecycleColor, getLifecycleName, getLifecycleInfos } = useIdentityLifecycles()
19+
const { getLifecycleColor, getLifecycleName, getLifecycleInfos } = await useIdentityLifecycles()
2020
2121
const props = defineProps({
2222
identity: {

src/composables/useIdentityLifecycle.ts

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,44 @@ type useIdentityLifecycleReturnType = {
44
getLifecycleName: (state: string) => string;
55
getLifecycleIcon: (state: string) => string;
66
getLifecycleInfos: (state: string) => { color: string, name: string, value: string, icon: string };
7+
stateList: Ref<any[]>;
78
};
89

10+
export async function useIdentityLifecycles(): Promise<useIdentityLifecycleReturnType> {
11+
const stateList = ref<any[]>([])
912

10-
export enum IdentityLifecycle {
11-
WAIT = "W",
12-
OFFICIAL = "O",
13-
ACTIVE = "A",
14-
PROVISIONAL = "P",
15-
INACTIVE = "I",
16-
DELETED = "D",
17-
18-
// IMPORTED = 3,
19-
// OFFICIAL = 2,
20-
// ACTIVE = 1,
21-
// PROVISIONAL = 0,
22-
// INACTIVE = -1,
23-
// DELETED = -2,
24-
}
25-
26-
27-
export const IdentityLifecycleList = [
28-
// { value: IdentityLifecycle.IMPORTED, text: 'Importé', color: '#F0E68C', icon: 'mdi-clock', display: true }, // Khaki
29-
{ value: IdentityLifecycle.OFFICIAL, text: 'Officiel', color: '#228B22', icon: 'mdi-clock', display: true }, // Forest Green
30-
{
31-
value: IdentityLifecycle.ACTIVE, text: 'Actif', color: '#00FF00', icon: 'mdi-clock-check', display: true
32-
}, // Lime
33-
{ value: IdentityLifecycle.PROVISIONAL, text: 'Provisoir', color: '#FFD700', icon: 'mdi-progress-clock', display: true }, // Gold
34-
{ value: IdentityLifecycle.INACTIVE, text: 'Inactif', color: '#808080', icon: 'mdi-clock-alert', display: true }, // Gray
35-
{
36-
value: IdentityLifecycle.DELETED, text: 'Supprimé', color: '#FF0000', icon: 'mdi-archive-clock', display: true
37-
}, // Red
38-
];
13+
try {
14+
const { data: states } = await useHttp<{ data: any }>('/management/lifecycle/states')
15+
if (states.value && Array.isArray(states.value.data)) {
16+
stateList.value = states.value.data
17+
}
18+
} catch (error) {
19+
console.error('Error fetching lifecycle states:', error)
20+
}
3921

40-
export function useIdentityLifecycles(): useIdentityLifecycleReturnType {
4122
function getLifecycleName(state: string): string {
42-
const found = IdentityLifecycleList.find(item => item.value === state);
43-
if (found && found?.display) return found.text;
23+
const found = stateList.value.find(item => item.key === state);
24+
if (found && found?.label) return found.label;
4425
return 'Inconnu';
4526
}
4627

4728
function getLifecycleColor(state: string): string {
48-
const found = IdentityLifecycleList.find(item => item.value === state);
49-
if (found && found?.display) return found.color;
29+
const found = stateList.value.find(item => item.key === state);
30+
if (found && found?.color) return found.color;
5031
return 'grey';
5132
}
5233

5334
function getLifecycleIcon(state: string): string {
54-
const found = IdentityLifecycleList.find(item => item.value === state);
55-
if (found && found?.display) return found.icon;
56-
return 'mdi-circle';
35+
const found = stateList.value.find(item => item.key === state);
36+
if (found && found?.icon) return found.icon;
37+
return 'mdi-help-rhombus-outline';
5738
}
5839

5940
function getLifecycleInfos(state: string): { color: string, name: string, icon: string, value: string } {
60-
const found = IdentityLifecycleList.find(item => item.value === state);
61-
if (found && found?.display) return {
41+
const found = stateList.value.find(item => item.key === state);
42+
if (found && found?.key) return {
6243
color: found.color,
63-
name: found.text,
44+
name: found.label,
6445
icon: found.icon,
6546
value: state,
6647
};
@@ -72,6 +53,5 @@ export function useIdentityLifecycles(): useIdentityLifecycleReturnType {
7253
};
7354
}
7455

75-
76-
return { getLifecycleName, getLifecycleColor, getLifecycleIcon, getLifecycleInfos };
56+
return { getLifecycleName, getLifecycleColor, getLifecycleIcon, getLifecycleInfos, stateList };
7757
}

src/composables/useIdentityStates.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type useIdentityStateReturnType = {
55
getStateName: (state: number) => string;
66
getStateInfos: (state: number) => { color: string, name: string, value: number };
77
getStateBadge: (state: number) => { color: string, name: string };
8+
getStateIcon: (state: number) => string;
89
};
910

1011
export enum IdentityState {
@@ -24,7 +25,7 @@ export const IdentityStateList = [
2425
{ value: IdentityState.TO_SYNC, text: 'A Synchroniser', color: 'orange-8', icon: 'mdi-circle', display: true },
2526
{ value: IdentityState.TO_VALIDATE, text: 'A valider', color: 'info', icon: 'mdi-circle', display: true },
2627
{ value: IdentityState.UNKNOWN, text: 'Inconnu', color: 'grey', icon: 'mdi-circle', display: true },
27-
{ value: IdentityState.TO_CREATE, text: 'A créer', color: 'grey', icon: 'mdi-circle', display: false },
28+
{ value: IdentityState.TO_CREATE, text: 'A créer', color: 'grey', icon: 'mdi-circle', display: true },
2829
{ value: IdentityState.TO_COMPLETE, text: 'A compléter', color: 'warning', icon: 'mdi-circle', display: true },
2930
{ value: IdentityState.ON_ERROR, text: 'En erreur', color: 'negative', icon: 'mdi-circle', display: true },
3031
{ value: IdentityState.PROCESSING, text: 'En cours de synchronisation', color: 'warning', icon: 'mdi-loading', display: true },
@@ -64,6 +65,6 @@ export function useIdentityStates(): useIdentityStateReturnType {
6465
return omit(getStateInfos(state), ['value']);
6566
}
6667

67-
return { getStateColor, getStateName, getStateInfos, getStateBadge };
68+
return { getStateColor, getStateName, getStateInfos, getStateBadge, getStateIcon };
6869
}
6970

src/pages/identities/index.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ q-page.container
2323
)
2424
template(#right-panel-title-before="props")
2525
q-icon(name="mdi-circle" :color="getStateColor(props?.target?.state)" :style='{color: getStateColor(props?.target?.state).startsWith("#") ? getStateColor(props?.target?.state) : "inherit"}' class="q-mr-xs")
26-
q-tooltip.text-body2(slot="trigger") Initialisation du compte : {{ getStateName(props.target.state) }}
26+
q-tooltip.text-body2(slot="trigger") Initialisation du compte : {{ getStateName(props.target.state) }} ({{ props?.target?.state || '?' }})
2727
q-icon(:name="getInitStateIcon(props?.target?.initState)" :color="getInitStateColor(props?.target?.initState)" :style='{color: getInitStateColor(props?.target?.initState).startsWith("#") ? getInitStateColor(props?.target?.initState) : "inherit"}' class="q-mr-xs")
28-
q-tooltip.text-body2(slot="trigger") Initialisation du compte : {{ getInitStateName(props.target.initState) }}
28+
q-tooltip.text-body2(slot="trigger") Initialisation du compte : {{ getInitStateName(props.target.initState) }} ({{ props?.target?.initState || '?' }})
2929
q-icon(:name="getLifecycleIcon(props?.target?.lifecycle)" :color="getLifecycleColor(props?.target?.lifecycle)" :style='{color: getLifecycleColor(props?.target?.lifecycle).startsWith("#") ? getLifecycleColor(props?.target?.lifecycle) : "inherit"}' class="q-mr-xs")
30-
q-tooltip.text-body2(slot="trigger") Cycle de vie : {{ getLifecycleName(props.target.lifecycle) }}
30+
q-tooltip.text-body2(slot="trigger") Cycle de vie : {{ getLifecycleName(props.target.lifecycle) }} ({{ props?.target?.lifecycle || '?' }})
3131
template(#top-left-btn-grp="{selectedValues}")
3232
sesame-table-top-left( :selected="selectedValues" @refresh="refresh" @clear="clearSelected" :total="identities?.total")
3333
template(#body-cell-states="props")
@@ -86,7 +86,7 @@ const { handleError } = useErrorHandling()
8686
const form = ref<any>(null)
8787
const { getStateColor, getStateName } = useIdentityStates()
8888
const { getInitStateColor, getInitStateName, getInitStateIcon } = useIdentityInitStates()
89-
const { getLifecycleColor, getLifecycleIcon, getLifecycleName } = useIdentityLifecycles()
89+
const { getLifecycleColor, getLifecycleIcon, getLifecycleName } = await useIdentityLifecycles()
9090
9191
onMounted(() => {
9292
initializePagination(identities.value?.total)

0 commit comments

Comments
 (0)