Commit 0a024877 authored by Florent Chehab's avatar Florent Chehab
Browse files

Frontend generation enhanced : access to saving time added ; and possibility...

Frontend generation enhanced : access to saving time added ; and possibility to completly invalidate an obj
parent 4a9ed6bb
...@@ -22,6 +22,7 @@ export const {{obj.NAME}}_EL_FETCH_DATA_SUCCESS = '{{obj.NAME}}_EL_FETCH_DATA_SU ...@@ -22,6 +22,7 @@ export const {{obj.NAME}}_EL_FETCH_DATA_SUCCESS = '{{obj.NAME}}_EL_FETCH_DATA_SU
{% if not obj.read_only %} {% if not obj.read_only %}
export const {{obj.NAME}}_EL_IS_SAVING = '{{obj.NAME}}_EL_IS_SAVING'; export const {{obj.NAME}}_EL_IS_SAVING = '{{obj.NAME}}_EL_IS_SAVING';
export const {{obj.NAME}}_EL_SHARE_SAVED_TIME = '{{obj.NAME}}_EL_SHARE_SAVED_TIME';
export const {{obj.NAME}}_EL_SAVING_HAS_ERROR = '{{obj.NAME}}_EL_SAVING_HAS_ERROR'; export const {{obj.NAME}}_EL_SAVING_HAS_ERROR = '{{obj.NAME}}_EL_SAVING_HAS_ERROR';
{% endif %} {% endif %}
......
...@@ -21,6 +21,7 @@ import { ...@@ -21,6 +21,7 @@ import {
{% if not obj.read_only %} {% if not obj.read_only %}
{{obj.NAME}}_EL_IS_SAVING, {{obj.NAME}}_EL_IS_SAVING,
{{obj.NAME}}_EL_SAVING_HAS_ERROR, {{obj.NAME}}_EL_SAVING_HAS_ERROR,
{{obj.NAME}}_EL_SHARE_SAVED_TIME,
{{obj.NAME}}_EL_SAVING_DATA_SUCCESS, {{obj.NAME}}_EL_SAVING_DATA_SUCCESS,
{% endif %} {% endif %}
...@@ -62,7 +63,7 @@ function _FetchData(pk, api_end_point, _IsLoading, _FetchDataSuccess, _Invalidat ...@@ -62,7 +63,7 @@ function _FetchData(pk, api_end_point, _IsLoading, _FetchDataSuccess, _Invalidat
function _ElSaveData(data, api_end_point, _ElIsSaving, _ElFetchDataSuccess, _ElInvalidated, _ElHasError) { function _ElSaveData(data, api_end_point, _ElIsSaving, _ElFetchDataSuccess, _ElShareSavedTime, _ElInvalidated, _ElHasError) {
return (dispatch) => { return (dispatch) => {
let method = "POST"; let method = "POST";
let pk = ""; let pk = "";
...@@ -94,6 +95,7 @@ function _ElSaveData(data, api_end_point, _ElIsSaving, _ElFetchDataSuccess, _ElI ...@@ -94,6 +95,7 @@ function _ElSaveData(data, api_end_point, _ElIsSaving, _ElFetchDataSuccess, _ElI
.then((_El) => { .then((_El) => {
dispatch(_ElInvalidated(false)); dispatch(_ElInvalidated(false));
dispatch(_ElFetchDataSuccess(_El)); // we use the same here dispatch(_ElFetchDataSuccess(_El)); // we use the same here
dispatch(_ElShareSavedTime());
dispatch(_ElIsSaving(false)); dispatch(_ElIsSaving(false));
}) })
.catch((e) => { .catch((e) => {
...@@ -168,7 +170,11 @@ export function {{obj.name}}ElFetchHasError(bool, error) { ...@@ -168,7 +170,11 @@ export function {{obj.name}}ElFetchHasError(bool, error) {
}; };
} }
export function {{obj.name}}ElInvalidated(bool) { export function {{obj.name}}ElInvalidated(bool, resetObj=false) {
if (resetObj){
{{obj.name}}ElFetchDataSuccess({}, false);
}
return { return {
type: {{obj.NAME}}_EL_INVALIDATED, type: {{obj.NAME}}_EL_INVALIDATED,
invalidated: bool invalidated: bool
...@@ -183,13 +189,17 @@ export function {{obj.name}}ElIsLoading(bool) { ...@@ -183,13 +189,17 @@ export function {{obj.name}}ElIsLoading(bool) {
} }
export function {{obj.name}}ElFetchDataSuccess({{obj.name}}El) { export function {{obj.name}}ElFetchDataSuccess({{obj.name}}El, setInvalidateFalse=true) {
{{obj.name}}ElInvalidated(false) let time = null;
if (setInvalidateFalse){
{{obj.name}}ElInvalidated(false);
time = Date.now();
}
return { return {
type: {{obj.NAME}}_EL_FETCH_DATA_SUCCESS, type: {{obj.NAME}}_EL_FETCH_DATA_SUCCESS,
{{obj.name}}El, {{obj.name}}El,
{{obj.name}}ElFetchedAt: Date.now() {{obj.name}}ElFetchedAt: time
}; };
} }
...@@ -224,9 +234,15 @@ export function {{obj.name}}ElSavingHasError(b, error=null) { ...@@ -224,9 +234,15 @@ export function {{obj.name}}ElSavingHasError(b, error=null) {
}; };
} }
export function {{obj.name}}ElShareSavedTime() {
return {
type: {{obj.NAME}}_EL_SHARE_SAVED_TIME,
time: Date.now()
};
}
export function {{obj.name}}ElSaveData(data) { export function {{obj.name}}ElSaveData(data) {
return _ElSaveData(data, "{{obj.api_end_point}}", {{obj.name}}ElIsSaving, {{obj.name}}ElFetchDataSuccess, {{obj.name}}ElInvalidated, {{obj.name}}ElSavingHasError) return _ElSaveData(data, "{{obj.api_end_point}}", {{obj.name}}ElIsSaving, {{obj.name}}ElFetchDataSuccess, {{obj.name}}ElShareSavedTime, {{obj.name}}ElInvalidated, {{obj.name}}ElSavingHasError)
} }
{% endif %} {% endif %}
......
...@@ -20,6 +20,7 @@ import { ...@@ -20,6 +20,7 @@ import {
{% if not obj.read_only %} {% if not obj.read_only %}
{{obj.name}}ElIsSaving, {{obj.name}}ElIsSaving,
{{obj.name}}ElShareSavedTime,
{{obj.name}}ElSavingHasError, {{obj.name}}ElSavingHasError,
{% endif %} {% endif %}
...@@ -42,7 +43,8 @@ export const {{obj.name}}ElReducers = combineReducers({ ...@@ -42,7 +43,8 @@ export const {{obj.name}}ElReducers = combineReducers({
{% if not obj.read_only %} {% if not obj.read_only %}
isSaving: {{obj.name}}ElIsSaving, isSaving: {{obj.name}}ElIsSaving,
savingHasError: {{obj.name}}ElSavingHasError savedAt: {{obj.name}}ElShareSavedTime,
savingHasError: {{obj.name}}ElSavingHasError,
{% endif %} {% endif %}
}) })
......
...@@ -19,6 +19,7 @@ import { ...@@ -19,6 +19,7 @@ import {
{% if not obj.read_only %} {% if not obj.read_only %}
{{obj.NAME}}_EL_IS_SAVING, {{obj.NAME}}_EL_IS_SAVING,
{{obj.NAME}}_EL_SAVING_HAS_ERROR, {{obj.NAME}}_EL_SAVING_HAS_ERROR,
{{obj.NAME}}_EL_SHARE_SAVED_TIME,
{{obj.NAME}}_EL_SAVING_DATA_SUCCESS, {{obj.NAME}}_EL_SAVING_DATA_SUCCESS,
{% endif %} {% endif %}
...@@ -135,6 +136,16 @@ export function {{obj.name}}ElIsSaving(state = false, action) { ...@@ -135,6 +136,16 @@ export function {{obj.name}}ElIsSaving(state = false, action) {
} }
export function {{obj.name}}ElShareSavedTime(state = null, action) {
switch (action.type) {
case {{obj.NAME}}_EL_SHARE_SAVED_TIME:
return action.time;
default:
return state;
}
}
export function {{obj.name}}ElSavingHasError(state = {status: false, error: null}, action) { export function {{obj.name}}ElSavingHasError(state = {status: false, error: null}, action) {
switch (action.type) { switch (action.type) {
case {{obj.NAME}}_EL_SAVING_HAS_ERROR: case {{obj.NAME}}_EL_SAVING_HAS_ERROR:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment