EN · DE · RU · FR · ES

#2478 : index.js

projectforge-webapp/src/actions/list/index.js Module JavaScript, projectforge-webapp/src/actions/list/index.js 208 lignes · 174 code · 9 commentaires · 25 vides
Objectif : Application web React : index.js. index.js fait partie de l'application open-source de gestion de projet ProjectForge.

Source (100 premières lignes)

import history from '../../utilities/history';
import { fetchJsonPost, getObjectFromQuery, getServiceURL, handleHTTPErrors } from '../../utilities/rest';

export const LIST_DISMISS_ERROR = 'LIST_DISMISS_ERROR';
export const LIST_SWITCH_CATEGORY = 'LIST_SWITCH_CATEGORY';
export const LIST_FETCH_FAILURE = 'LIST_FETCH_FAILURE';
export const LIST_INITIAL_CALL_BEGIN = 'LIST_INITIAL_CALL_BEGIN';
export const LIST_FETCH_DATA_BEGIN = 'LIST_FETCH_DATA_BEGIN';
export const LIST_CALL_SUCCESS = 'LIST_CALL_SUCCESS';
export const LIST_CATEGORY_RESET = 'LIST_CATEGORY_RESET';

const dismissError = (category) => ({
    type: LIST_DISMISS_ERROR,
    payload: { category },
});

const switchCategory = (category) => ({
    type: LIST_SWITCH_CATEGORY,
    payload: { category },
});

const resetCategory = (category) => ({
    type: LIST_CATEGORY_RESET,
    payload: { category },
});

export const fetchFailure = (category, error) => ({
    type: LIST_FETCH_FAILURE,
    payload: {
        category,
        error,
    },
});

const initialCallBegin = (category, search) => ({
    type: LIST_INITIAL_CALL_BEGIN,
    payload: {
        category,
        search,
    },
});

const fetchDataBegin = (category, variables) => ({
    type: LIST_FETCH_DATA_BEGIN,
    payload: {
        category,
        variables,
    },
});

const callSuccess = (category, response) => ({
    type: LIST_CALL_SUCCESS,
    payload: {
        category,
        response,
    },
});

const initialCall = (category, dispatch) => {
    dispatch(initialCallBegin(category, history.location.search));

    return fetch(
        getServiceURL(
            `${category}/initialList`,
            getObjectFromQuery(history.location.search),
        ),
        {
            method: 'GET',
            credentials: 'include',
        },
    )
        .then(handleHTTPErrors)
        .then((response) => response.json())
        .then((json) => {
            const { targetType, url: redirectUrl } = json;
            if (targetType === 'REDIRECT' && redirectUrl) {
                // Réinitialiser complètement l'état de la catégorie avant la redirection
                // Cela garantit un chargement de données fraîches lors du retour à la page
                dispatch(resetCategory(category));
                history.push(redirectUrl);
                return;
            }
            dispatch(callSuccess(category, json));
        })
        .catch((error) => dispatch(fetchFailure(category, error.message)));
};

const fetchData = (category, dispatch, listState, variables) => {
    dispatch(fetchDataBegin(category, variables));

    return fetch(
        getServiceURL(`${category}/list`),
        {
            method: 'POST',
            credentials: 'include',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(listState.categories[category].filter),
        },

Historique Git

a5be6fdda Correction du spinner infini après la redirection 2FA sur les pages de liste
7a2807af1 WIP : Valeurs de campagne d'adresse
c527aa3a9 wip : Pages d'édition de dépendance
c3331c88e WIP : Plugin bancaire (et nouveau module d'import). DynamicDropArea : bug de copier-coller corrigé (fonction renommée)
3eac1c792 Version REST de ProjectPagesRest (vue liste) incluant la sélection multiple (pas encore terminée).

a5be6fdda

Correction du spinner infini après la redirection 2FA sur les pages de liste
a5be6fdda4dd21f1b91eedc251245dc950dc29c2
diff --git a/projectforge-webapp/src/actions/list/index.js b/projectforge-webapp/src/actions/list/index.js
index 9f42abdbe..6b0c5c37b 100644
--- a/projectforge-webapp/src/actions/list/index.js
+++ b/projectforge-webapp/src/actions/list/index.js
@@ -7,6 +7,7 @@ export const LIST_FETCH_FAILURE = 'LIST_FETCH_FAILURE';
 export const LIST_INITIAL_CALL_BEGIN = 'LIST_INITIAL_CALL_BEGIN';
 export const LIST_FETCH_DATA_BEGIN = 'LIST_FETCH_DATA_BEGIN';
 export const LIST_CALL_SUCCESS = 'LIST_CALL_SUCCESS';
+export const LIST_CATEGORY_RESET = 'LIST_CATEGORY_RESET';
 
 const dismissError = (category) => ({
     type: LIST_DISMISS_ERROR,
@@ -18,6 +19,11 @@ const switchCategory = (category) => ({
     payload: { category },
 });
 
+const resetCategory = (category) => ({
+    type: LIST_CATEGORY_RESET,
+    payload: { category },
+});
+
 export const fetchFailure = (category, error) => ({
     type: LIST_FETCH_FAILURE,
     payload: {
@@ -68,6 +74,9 @@ const initialCall = (category, dispatch) => {
         .then((json) => {
             const { targetType, url: redirectUrl } = json;
             if (targetType === 'REDIRECT' && redirectUrl) {
+                // Réinitialiser complètement l'état de la catégorie avant la redirection
+                // Cela garantit un chargement de données fraîches lors du retour à la page
+                dispatch(resetCategory(category));
                 history.push(redirectUrl);
                 return;
             }

7a2807af1

WIP : Valeurs de campagne d'adresse
7a2807af1dde56bee7339dee02fb793546a76fcf
diff --git a/projectforge-webapp/src/actions/list/index.js b/projectforge-webapp/src/actions/list/index.js
index bffca1e35..9f42abdbe 100644
--- a/projectforge-webapp/src/actions/list/index.js
+++ b/projectforge-webapp/src/actions/list/index.js
@@ -92,7 +92,14 @@ const fetchData = (category, dispatch, listState, variables) => {
     )
         .then(handleHTTPErrors)
         .then((response) => response.json())
-        .then((data) => dispatch(callSuccess(category, { data })))
+        .then((data) => {
+            if (data.reloadUI) {
+                // Les définitions de campagne ou d'interface utilisateur ont changé - recharger la liste initiale
+                // pour obtenir les définitions de filtre mises à jour
+                return initialCall(category, dispatch);
+            }
+            return dispatch(callSuccess(category, { data }));
+        })
         .catch((error) => dispatch(fetchFailure(category, error.message)));
 };
 

c527aa3a9

wip : Pages d'édition de dépendance
c527aa3a95b05e84e642e5181a314cf1a034b093
diff --git a/projectforge-webapp/src/actions/list/index.js b/projectforge-webapp/src/actions/list/index.js
index a2329133c..bffca1e35 100644
--- a/projectforge-webapp/src/actions/list/index.js
+++ b/projectforge-webapp/src/actions/list/index.js
@@ -190,8 +190,3 @@ export const startMultiSelection = () => (dispatch, getState) => {
         },
     );
 };
-
-export const openEditPage = (id) => (_, getState) => {
-    const state = getState().list;
-    history.push(`/${state.categories[state.currentCategory].standardEditPage.replace(':id', id)}`);
-};

c3331c88e

WIP : Plugin bancaire (et nouveau module d'import). DynamicDropArea : bug de copier-coller corrigé (fonction renommée)
c3331c88e9049edefa60c0ee3535d208a33fe07f
diff --git a/projectforge-webapp/src/actions/list/index.js b/projectforge-webapp/src/actions/list/index.js
index a8fb0ef67..a2329133c 100644
--- a/projectforge-webapp/src/actions/list/index.js
+++ b/projectforge-webapp/src/actions/list/index.js
@@ -1,4 +1,3 @@
-import fileDownload from 'js-file-download';
 import history from '../../utilities/history';
 import { fetchJsonPost, getObjectFromQuery, getServiceURL, handleHTTPErrors } from '../../utilities/rest';
 

3eac1c792

Version REST de ProjectPagesRest (vue liste) incluant la sélection multiple (pas encore terminée).
3eac1c79281040e1206da9fa4c94c700edefec0d
diff --git a/projectforge-webapp/src/actions/list/index.js b/projectforge-webapp/src/actions/list/index.js
index 43130e055..a8fb0ef67 100644
--- a/projectforge-webapp/src/actions/list/index.js
+++ b/projectforge-webapp/src/actions/list/index.js
@@ -1,6 +1,6 @@
 import fileDownload from 'js-file-download';
 import history from '../../utilities/history';
-import { getObjectFromQuery, getServiceURL, handleHTTPErrors } from '../../utilities/rest';
+import { fetchJsonPost, getObjectFromQuery, getServiceURL, handleHTTPErrors } from '../../utilities/rest';
 
 export const LIST_DISMISS_ERROR = 'LIST_DISMISS_ERROR';
 export const LIST_SWITCH_CATEGORY = 'LIST_SWITCH_CATEGORY';
@@ -179,6 +179,19 @@ export const exportCurrentList = () => (dispatch, getState) => {
         .catch((error) => dispatch(fetchFailure(category, error.message)));
 };
 
+export const startMultiSelection = () => (dispatch, getState) => {
+    const { list } = getState();
+    const category = list.currentCategory;
+    return fetchJsonPost(
+        `${category}/startMultiSelection`,
+        list.categories[category].filter,
+        (json) => {
+            const { url } = json;
+            history.push(url);
+        },
+    );
+};
+
 export const openEditPage = (id) => (_, getState) => {
     const state = getState().list;
     history.push(`/${state.categories[state.currentCategory].standardEditPage.replace(':id', id)}`);