actions.tpl 3.93 KB
Newer Older
1
2
3
4
5
6
// WARNING
// THIS FILE HAS BEEN AUTOMATICALLY GENERATED
// WITH /frontend/generate/generate_frontend_files.js
// MODIFY THE FILE ABOVE IF YOUR NOT SATISFIED 
// THIS WARNING DOESN'T APPLY TO .tpl FILES...

Florent Chehab's avatar
Florent Chehab committed
7
8

import SmartActions from '../actions/SmartActions';
Florent Chehab's avatar
Florent Chehab committed
9

10
import {
11
{% for obj in data %}
12
    {{obj.NAME}}_FETCH_HAS_ERROR,
13
14
15
    {{obj.NAME}}_IS_LOADING,
    {{obj.NAME}}_FETCH_DATA_SUCCESS,
    {{obj.NAME}}_INVALIDATED,
Florent Chehab's avatar
Florent Chehab committed
16
17

    {{obj.NAME}}_EL_INVALIDATED,
18
    {{obj.NAME}}_EL_FETCH_HAS_ERROR,
Florent Chehab's avatar
Florent Chehab committed
19
20
21
    {{obj.NAME}}_EL_IS_LOADING,
    {{obj.NAME}}_EL_FETCH_DATA_SUCCESS,

Florent Chehab's avatar
Florent Chehab committed
22
    {% if not obj.read_only %}
Florent Chehab's avatar
Florent Chehab committed
23
    {{obj.NAME}}_EL_IS_SAVING,
24
    {{obj.NAME}}_EL_SAVING_HAS_ERROR,
25
    {{obj.NAME}}_EL_SHARE_SAVED_TIME,
Florent Chehab's avatar
Florent Chehab committed
26
    {% endif %}
Florent Chehab's avatar
Florent Chehab committed
27

28
{% endfor %}
29
30
} from "./action-types";

Florent Chehab's avatar
Florent Chehab committed
31
32
33
//////////////////////////////////
// generic function definitions

Florent Chehab's avatar
Florent Chehab committed
34
const smartActions = new SmartActions();
Florent Chehab's avatar
Florent Chehab committed
35
36
/////////////////////////////////

37
{% for obj in data %}
38
export function {{obj.name}}FetchHasError(bool, error=null) {
39
    return {
40
41
42
        type: {{obj.NAME}}_FETCH_HAS_ERROR,
        hasError: bool,
        error
43
44
45
    };
}

46
export function {{obj.name}}IsLoading(bool) {
47
    return {
48
        type: {{obj.NAME}}_IS_LOADING,
49
50
51
52
        isLoading: bool
    };
}

53
54
55
56
export function {{obj.name}}Invalidated(bool, resetObj=false) {
     if (resetObj){
        {{obj.name}}FetchDataSuccess({}, false);
    }
57
    return {
58
        type: {{obj.NAME}}_INVALIDATED,
59
60
61
62
        invalidated: bool
    };
}

63
64
65
66
67
68
69

export function {{obj.name}}FetchDataSuccess({{obj.name}},  setInvalidateFalse=true) {
     let time = null;
    if (setInvalidateFalse){
        {{obj.name}}Invalidated(false)
        time = Date.now();
    }
70
71

    return {
72
73
        type: {{obj.NAME}}_FETCH_DATA_SUCCESS,
        {{obj.name}},
74
        {{obj.name}}FetchedAt: time
75
76
77
78
    };
}


79
export function {{obj.name}}FetchData(pk="") {
Florent Chehab's avatar
Florent Chehab committed
80
    return smartActions._FetchData(
81
        pk, 
82
        "{{obj.api_end_point}}", 
Florent Chehab's avatar
Florent Chehab committed
83
84
85
        {{obj.name}}IsLoading, 
        {{obj.name}}FetchDataSuccess, 
        {{obj.name}}Invalidated, 
86
        {{obj.name}}FetchHasError
Florent Chehab's avatar
Florent Chehab committed
87
    )
88
}
Florent Chehab's avatar
Florent Chehab committed
89
90


91
export function {{obj.name}}ElFetchHasError(bool, error) {
Florent Chehab's avatar
Florent Chehab committed
92
    return {
93
94
95
        type: {{obj.NAME}}_EL_FETCH_HAS_ERROR,
        hasError: bool,
        error
Florent Chehab's avatar
Florent Chehab committed
96
97
98
    };
}

99
100
101
102
103
export function {{obj.name}}ElInvalidated(bool, resetObj=false) {
    if (resetObj){
        {{obj.name}}ElFetchDataSuccess({}, false);
    }

Florent Chehab's avatar
Florent Chehab committed
104
105
106
107
108
109
    return {
        type: {{obj.NAME}}_EL_INVALIDATED,
        invalidated: bool
    };
}

Florent Chehab's avatar
Florent Chehab committed
110
export function {{obj.name}}ElIsLoading(bool) {
Florent Chehab's avatar
Florent Chehab committed
111
    return {
Florent Chehab's avatar
Florent Chehab committed
112
113
        type: {{obj.NAME}}_EL_IS_LOADING,
        isLoading: bool
Florent Chehab's avatar
Florent Chehab committed
114
115
116
117
    };
}


118
119
120
121
122
123
export function {{obj.name}}ElFetchDataSuccess({{obj.name}}El, setInvalidateFalse=true) {
    let time = null;
    if (setInvalidateFalse){
        {{obj.name}}ElInvalidated(false);
        time = Date.now();
    }
Florent Chehab's avatar
Florent Chehab committed
124
125

    return {
Florent Chehab's avatar
Florent Chehab committed
126
        type: {{obj.NAME}}_EL_FETCH_DATA_SUCCESS,
Florent Chehab's avatar
Florent Chehab committed
127
        {{obj.name}}El,
128
        {{obj.name}}ElFetchedAt: time
Florent Chehab's avatar
Florent Chehab committed
129
130
131
132
    };
}


Florent Chehab's avatar
Florent Chehab committed
133
export function {{obj.name}}ElFetchData(pk) {
Florent Chehab's avatar
Florent Chehab committed
134
    return smartActions._FetchData(
Florent Chehab's avatar
Florent Chehab committed
135
        pk, 
136
        "{{obj.api_end_point}}", 
Florent Chehab's avatar
Florent Chehab committed
137
138
139
        {{obj.name}}ElIsLoading, 
        {{obj.name}}ElFetchDataSuccess, 
        {{obj.name}}ElInvalidated, 
140
        {{obj.name}}ElFetchHasError,
Florent Chehab's avatar
Florent Chehab committed
141
142
143
        true
    )
}
Florent Chehab's avatar
Florent Chehab committed
144
145


Florent Chehab's avatar
Florent Chehab committed
146
{% if not obj.read_only %}
Florent Chehab's avatar
Florent Chehab committed
147

Florent Chehab's avatar
Florent Chehab committed
148
149
150
151
export function {{obj.name}}ElIsSaving(bool) {
    return {
        type: {{obj.NAME}}_EL_IS_SAVING,
        isSaving: bool
Florent Chehab's avatar
Florent Chehab committed
152
153
154
    };
}

Florent Chehab's avatar
Florent Chehab committed
155
export function {{obj.name}}ElSavingHasError(b, error=null) {
Florent Chehab's avatar
Florent Chehab committed
156
    return {
157
        type: {{obj.NAME}}_EL_SAVING_HAS_ERROR,
Florent Chehab's avatar
Florent Chehab committed
158
        hasError: b,
159
        error
Florent Chehab's avatar
Florent Chehab committed
160
161
162
    };
}

163
164
165
166
167
168
export function {{obj.name}}ElShareSavedTime() {
    return {
        type: {{obj.NAME}}_EL_SHARE_SAVED_TIME,
        time: Date.now()
    };
}
169

Florent Chehab's avatar
Florent Chehab committed
170
export function {{obj.name}}ElSaveData(data) {
Florent Chehab's avatar
Florent Chehab committed
171
    return  smartActions._ElSaveData(data, "{{obj.api_end_point}}", {{obj.name}}ElIsSaving, {{obj.name}}ElFetchDataSuccess, {{obj.name}}ElShareSavedTime, {{obj.name}}ElInvalidated, {{obj.name}}ElSavingHasError) 
Florent Chehab's avatar
Florent Chehab committed
172
173
174
}
{% endif %}

175
{% endfor %}