actions.tpl 3.75 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
export function {{obj.name}}Invalidated(bool) {
54
    return {
55
        type: {{obj.NAME}}_INVALIDATED,
56
57
58
59
        invalidated: bool
    };
}

60
61
62
63
64
65
66

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

    return {
69
70
        type: {{obj.NAME}}_FETCH_DATA_SUCCESS,
        {{obj.name}},
71
        {{obj.name}}FetchedAt: time
72
73
74
75
    };
}


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


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

96
export function {{obj.name}}ElInvalidated(bool) {
Florent Chehab's avatar
Florent Chehab committed
97
98
99
100
101
102
    return {
        type: {{obj.NAME}}_EL_INVALIDATED,
        invalidated: bool
    };
}

Florent Chehab's avatar
Florent Chehab committed
103
export function {{obj.name}}ElIsLoading(bool) {
Florent Chehab's avatar
Florent Chehab committed
104
    return {
Florent Chehab's avatar
Florent Chehab committed
105
106
        type: {{obj.NAME}}_EL_IS_LOADING,
        isLoading: bool
Florent Chehab's avatar
Florent Chehab committed
107
108
109
110
    };
}


111
112
113
114
115
116
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
117
118

    return {
Florent Chehab's avatar
Florent Chehab committed
119
        type: {{obj.NAME}}_EL_FETCH_DATA_SUCCESS,
Florent Chehab's avatar
Florent Chehab committed
120
        {{obj.name}}El,
121
        {{obj.name}}ElFetchedAt: time
Florent Chehab's avatar
Florent Chehab committed
122
123
124
125
    };
}


Florent Chehab's avatar
Florent Chehab committed
126
export function {{obj.name}}ElFetchData(pk) {
Florent Chehab's avatar
Florent Chehab committed
127
    return smartActions._FetchData(
Florent Chehab's avatar
Florent Chehab committed
128
        pk, 
129
        "{{obj.api_end_point}}", 
Florent Chehab's avatar
Florent Chehab committed
130
131
132
        {{obj.name}}ElIsLoading, 
        {{obj.name}}ElFetchDataSuccess, 
        {{obj.name}}ElInvalidated, 
133
        {{obj.name}}ElFetchHasError,
Florent Chehab's avatar
Florent Chehab committed
134
135
136
        true
    )
}
Florent Chehab's avatar
Florent Chehab committed
137
138


Florent Chehab's avatar
Florent Chehab committed
139
{% if not obj.read_only %}
Florent Chehab's avatar
Florent Chehab committed
140

Florent Chehab's avatar
Florent Chehab committed
141
142
143
144
export function {{obj.name}}ElIsSaving(bool) {
    return {
        type: {{obj.NAME}}_EL_IS_SAVING,
        isSaving: bool
Florent Chehab's avatar
Florent Chehab committed
145
146
147
    };
}

Florent Chehab's avatar
Florent Chehab committed
148
export function {{obj.name}}ElSavingHasError(b, error=null) {
Florent Chehab's avatar
Florent Chehab committed
149
    return {
150
        type: {{obj.NAME}}_EL_SAVING_HAS_ERROR,
Florent Chehab's avatar
Florent Chehab committed
151
        hasError: b,
152
        error
Florent Chehab's avatar
Florent Chehab committed
153
154
155
    };
}

156
157
158
159
160
161
export function {{obj.name}}ElShareSavedTime() {
    return {
        type: {{obj.NAME}}_EL_SHARE_SAVED_TIME,
        time: Date.now()
    };
}
162

Florent Chehab's avatar
Florent Chehab committed
163
export function {{obj.name}}ElSaveData(data) {
Florent Chehab's avatar
Florent Chehab committed
164
    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
165
166
167
}
{% endif %}

168
{% endfor %}