Skip to content

Commit

Permalink
feat(doc): fix remarks doc
Browse files Browse the repository at this point in the history
  • Loading branch information
lailabjil committed May 23, 2024
1 parent ba853f5 commit 5b2fe5e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 23 deletions.
47 changes: 37 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,9 @@ It contains all the survey "fields" components and an associated storybook docum

### Initial survey state

A surveyed, when loggin in the first time, will be able to see REACT_APP_NUM_ACTIVITY_SURVEYS (total amount of activity surveys, accessible in env file) activity surveys and
REACT_APP_NUM_WORKTIME_SURVEYS work time surveys.
A surveyed, when loggin in the first time, will be able to see le total of the surveys retrieved by the query _REACT_APP_EDT_ORGANISATION_API_BASE_URL + "api/survey-assigment/interviewer/my-surveys"_.

In demo version, the surveys able to see are `REACT_APP_NUM_ACTIVITY_SURVEYS` (total amount of activity surveys, accessible in env file) activity surveys and `REACT_APP_NUM_WORKTIME_SURVEYS` work time surveys.

When a survey has never been started, no data are visible in the indexedDB.

Expand All @@ -321,12 +322,14 @@ Currently corresponding to the ISENVOYED boolean variable. This state is to know

## Locked survey state

ISLOCKED boolean variable is set to true when a surveyer change any of the surveyed data from the surveyer interface or if he locks the survey by using the lock button.
`ISLOCKED` boolean variable is set to true when a surveyer change any of the surveyed data from the surveyer interface or if he locks the survey by using the lock button.
This state is impacting the surveyed rights in the app. Any locked survey is not editable by the surveyed anymore (no more writting rights). The surveyer only can manage this state.

## Validated survey state

This state is visible on the ISVALIDATED boolean variable. This state can be set only by the surveyer. When this state is set to true, the ISLOCKED boolean also take true as value. The surveyer can still edit the data, but the surveyed doesn't have writting rights anymore.
This state is visible on the `ISVALIDATED` boolean variable. This state can be set only by the surveyer. When this state is set to true, the ISLOCKED boolean also take true as value. The surveyer can still edit the data, but the surveyed doesn't have writting rights anymore.

Also, the `ISVALIDATED` variable is updated by the value state on state-data when loading data.

## Household surveys state

Expand Down Expand Up @@ -386,7 +389,19 @@ The user bearer token is used to call the secured APIs.

The accounts are created and managed by INSEE. It is not possible to sign up by yourself.

SSO is available using INSEE LDAP only with users with reviewer role. The reviewer is already authenticated when we enter with SSO, if he enter the url https://{URL_ENVIRO}/?kc_idp_hint=insee-ssp already authenticated, he is redirect to the main page of the app taking the current token and the information corresponding, without having to go through the authentication page again.
SSO is available using INSEE LDAP only with users with reviewer role. The reviewer is already authenticated when we enter with SSO, if he enter the url https://{URL_ENVIRO}/?kc_idp_hint={IDP_ID} (or {IDP_ID} can be no value, defaults "insee-ssp") already authenticated, he is redirect to the main page of the app taking the current token and the information corresponding, without having to go through the authentication page again.

#### Rights

The different roles of the application are defined on the EdtUserRightsEnum enum.

![EdtUserRightsEnum](./src/documentation/images/rights_1.png)

The values of its variables are replaced by the environment variables `REACT_APP_REVIEWER_ROLE` and `REACT_APP_SURVEYED_ROLE` respectively.

The rights check is done on the _getUserRights()_ method so that we always retrieve a value from the _EdtUserRightsEnum_ enum.

![user rights](./src/documentation/images/rights_2.png)

### APIs usage

Expand Down Expand Up @@ -989,7 +1004,10 @@ REACT_APP_NUM_WORKTIME_SURVEYS=2
```
</details>

`REACT_APP_NUM_ACTIVITY_SURVEYS` and `REACT_APP_NUM_WORKTIME_SURVEYS` allows to change the amount of each survey kind for user.
`REACT_APP_NUM_ACTIVITY_SURVEYS` and `REACT_APP_NUM_WORKTIME_SURVEYS` allows to change the surveys affichées pour le mode demo.

Otherwise, the number of surveys displayed are retrieved by the request *"REACT_APP_EDT_ORGANISATION_API_BASE_URL + api/survey-assigment/interviewer/my-surveys"* or the distinction on each model is made from the variable *questionnaireModelId*.


## Orchestrator

Expand Down Expand Up @@ -1198,7 +1216,7 @@ In this step, the values of variables FIRSTNAME, SURVEYDATE are set in COLLECTED

3.2 - ROUTE

![ROUTE PAGE](create_survey_one_interviewer_first_route_route_page.png)
![ROUTE PAGE](./src/documentation/images/create_survey_one_interviewer_first_route_route_page.png)

Select "route home - work"

Expand Down Expand Up @@ -1379,18 +1397,27 @@ Once in offline mode, authentication is not performed or the token is reviewed u
The information displayed will always be the most recent information found.
The cached last modification date will always be compared (on object data -> lastLocalSaveDate), with the date of last modification in remote (on stateData -> date) and if the value in Remote is the most recent, the data will be updated by that of the remote.

### Offline update data
![GET DATA](./src/documentation/images/offline_get_data.png)

#### Interviewer mode

As there is no requirement with the API, the local data will not be sent until we go online and made a modification to the survey.
### Offline update data

#### Reviewer mode

As there is no requirement with the API, the local data will not be sent until we go online and : either click on the "update the list" button, or modify the corresponding survey.

If we click the "update list" button after having been in offline mode and having made modifications, we will send all the households that have been modified in offline.

![UPDATE DATA](./src/documentation/images/offline_save_offline_reviewer.png)

#### Interviewer mode

As there is no requirement with the API, the local data will not be sent until we go online and made a modification to the survey.

> **REMAINS TO BE DONE**
> Same behavior as reviewer, it will be necessary to call on the interviewer home page the *saveDatas()* method already used in reviewer mode (`saveAllAndUpdate` on *SurveysOverview*) when you go from offline to online.
## Maintenance and evolution

### Install local development environment
Expand Down
Binary file added src/documentation/images/offline_get_data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/documentation/images/rights_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/documentation/images/rights_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 11 additions & 13 deletions src/service/survey-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ const getRemoteSavedSurveysDatas = (
const surveyData = initializeData(remoteSurveyData, surveyId);

return lunaticDatabase.get(surveyId).then(localSurveyData => {
const lastRemoteSaveDate = remoteSurveyData.data.lastRemoteSaveDate ?? 1;
const lastRemoteSaveDate = remoteSurveyData.data.lastRemoteSaveDate ?? 1; //a supprimer
const lastLocalSaveDate =
remoteSurveyData.data.lastLocalSaveDate ??
localSurveyData?.lastLocalSaveDate ??
Expand All @@ -525,13 +525,13 @@ const getRemoteSavedSurveysDatas = (
remoteSurveyData?.stateData?.date != null &&
(localSurveyData == null ||
((localSurveyData.lastLocalSaveDate ?? 0) <= lastRemoteSaveDate &&
(remoteSurveyData.data.lastRemoteSaveDate != null ||
(remoteSurveyData.data.lastRemoteSaveDate != null || //quand existe des données en remote -> a suprrimer
(remoteSurveyData.data.lastLocalSaveDate == null &&
remoteSurveyData.data.lastRemoteSaveDate == null)) &&
lastLocalSaveDate <= remoteStateData))
//quand local est vide and jamais saved des données, remoteSurveyData.data.lastRemoteSaveDate change par stateData
lastLocalSaveDate <= remoteStateData)) // local date moins recent que remote date
) {
const stateData = getSurveyStateData(surveyData, surveyId);
console.log("set remote data", stateData);
setLocalOrRemoteData(surveyId, remoteSurveyData, surveyData, stateData);
return lunaticDatabase.save(surveyId, surveyData);
}
Expand Down Expand Up @@ -952,22 +952,18 @@ const updateLocked = (idSurvey: string, data: LunaticData) => {

const getDataUpdatedOffline = () => {
let surveysToUpdated = new Map<string, LunaticData>();
let surveysToUpdated2 = new Map<string, LunaticData>();
surveysIds[SurveysIdsEnum.ALL_SURVEYS_IDS].forEach(idSurvey => {
let data = getDataCache(idSurvey);
if (data.lastLocalSaveDate > (data.stateData?.date ?? data.lastRemoteSaveDate)) {
surveysToUpdated.set(idSurvey, data);
}

//state data -> last data recuperée from stateData
//lastRemoteSaveDate -> a pouvoir supprimer (change lastRemoteSaveDate to stateData.date)
if (
data.lastLocalSaveDate > data.lastRemoteSaveDate ||
data.lastLocalSaveDate > data.stateData?.date
) {
surveysToUpdated2.set(idSurvey, data);
surveysToUpdated.set(idSurvey, data);
}
});
console.log(surveysToUpdated, surveysToUpdated2);
return surveysToUpdated2;
return surveysToUpdated;
};

const saveDatas = () => {
Expand Down Expand Up @@ -996,7 +992,7 @@ const saveData = (
const isReviewerMode = getUserRights() == EdtUserRightsEnum.REVIEWER;
fixConditionals(data);
let oldDataSurvey = datas.get(idSurvey) ?? {};
const dataIsChanged = dataIsChange(idSurvey, data, oldDataSurvey); //dataIsChange(idSurvey, data, oldDatas.get(idSurvey) ?? {});
const dataIsChanged = dataIsChange(idSurvey, data, oldDataSurvey);
const isChange = forceUpdate || dataIsChanged;
datas.set(idSurvey, data);

Expand Down Expand Up @@ -1033,11 +1029,13 @@ const saveData = (
return setLocalOrRemoteData(idSurvey, remoteData, data, stateData);
});
} else if (isDemoMode || localSaveOnly || !navigator.onLine) {
//offline, always prio local, pour ça stateData 0
stateData = getSurveyStateData(data, idSurvey);
stateData.date = 0;
data.stateData = stateData;
return setLocalOrRemoteData(idSurvey, { data: data }, data, stateData);
} else {
//jamais
data.stateData = stateData;
return setLocalOrRemoteData(idSurvey, { data: data }, data, stateData);
}
Expand Down

0 comments on commit 5b2fe5e

Please sign in to comment.