actions.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import { returnType } from 'utils/redux'
  21. import { ActionTypes } from './constants'
  22. import {
  23. IDashboard,
  24. IDashboardItem,
  25. IQueryConditions,
  26. IDataRequestParams
  27. } from 'app/containers/Dashboard/types'
  28. import { IWidgetFormed } from 'app/containers/Widget/types'
  29. import {
  30. IShareFormedViews,
  31. IViewQueryResponse
  32. } from 'app/containers/View/types'
  33. import { RenderType } from 'app/containers/Widget/components/Widget'
  34. import { ControlPanelTypes } from 'app/components/Control/constants'
  35. import { IDistinctValueReqeustParams } from 'app/components/Control/types'
  36. export const DashboardActions = {
  37. getDashboard(token, reject) {
  38. return {
  39. type: ActionTypes.LOAD_SHARE_DASHBOARD,
  40. payload: {
  41. token,
  42. reject
  43. }
  44. }
  45. },
  46. dashboardGetted(
  47. dashboard: IDashboard,
  48. items: IDashboardItem[],
  49. widgets: IWidgetFormed[],
  50. formedViews: IShareFormedViews
  51. ) {
  52. return {
  53. type: ActionTypes.LOAD_SHARE_DASHBOARD_SUCCESS,
  54. payload: {
  55. dashboard,
  56. items,
  57. widgets,
  58. formedViews
  59. }
  60. }
  61. },
  62. loadDashboardFail() {
  63. return {
  64. type: ActionTypes.LOAD_SHARE_DASHBOARD_FAILURE
  65. }
  66. },
  67. getWidget(token, resolve, reject) {
  68. return {
  69. type: ActionTypes.LOAD_SHARE_WIDGET,
  70. payload: {
  71. token,
  72. resolve,
  73. reject
  74. }
  75. }
  76. },
  77. widgetGetted(widget: IWidgetFormed, formedViews: IShareFormedViews) {
  78. return {
  79. type: ActionTypes.LOAD_SHARE_WIDGET_SUCCESS,
  80. payload: {
  81. widget,
  82. formedViews
  83. }
  84. }
  85. },
  86. getResultset(
  87. renderType: RenderType,
  88. itemId: number,
  89. queryConditions: Partial<IQueryConditions>
  90. ) {
  91. return {
  92. type: ActionTypes.LOAD_SHARE_RESULTSET,
  93. payload: {
  94. renderType,
  95. itemId,
  96. queryConditions
  97. }
  98. }
  99. },
  100. resultsetGetted(
  101. renderType: RenderType,
  102. itemId: number,
  103. requestParams: IDataRequestParams,
  104. result: IViewQueryResponse
  105. ) {
  106. return {
  107. type: ActionTypes.LOAD_SHARE_RESULTSET_SUCCESS,
  108. payload: {
  109. renderType,
  110. itemId,
  111. requestParams,
  112. result
  113. }
  114. }
  115. },
  116. getResultsetFail(itemId, errorMessage) {
  117. return {
  118. type: ActionTypes.LOAD_SHARE_RESULTSET_FAILURE,
  119. payload: {
  120. itemId,
  121. errorMessage
  122. }
  123. }
  124. },
  125. getBatchDataWithControlValues(
  126. type: ControlPanelTypes,
  127. relatedItems: number[],
  128. formValues?: object,
  129. itemId?: number
  130. ) {
  131. return {
  132. type: ActionTypes.LOAD_BATCH_DATA_WITH_CONTROL_VALUES,
  133. payload: {
  134. type,
  135. relatedItems,
  136. formValues,
  137. itemId
  138. }
  139. }
  140. },
  141. setIndividualDashboard(
  142. widget: IWidgetFormed,
  143. formedViews: IShareFormedViews,
  144. token: string
  145. ) {
  146. return {
  147. type: ActionTypes.SET_INDIVIDUAL_DASHBOARD,
  148. payload: {
  149. widget,
  150. formedViews,
  151. token
  152. }
  153. }
  154. },
  155. loadWidgetCsv(itemId, requestParams, token) {
  156. return {
  157. type: ActionTypes.LOAD_WIDGET_CSV,
  158. payload: {
  159. itemId,
  160. requestParams,
  161. token
  162. }
  163. }
  164. },
  165. widgetCsvLoaded(itemId) {
  166. return {
  167. type: ActionTypes.LOAD_WIDGET_CSV_SUCCESS,
  168. payload: {
  169. itemId
  170. }
  171. }
  172. },
  173. loadWidgetCsvFail(itemId) {
  174. return {
  175. type: ActionTypes.LOAD_WIDGET_CSV_FAILURE,
  176. payload: {
  177. itemId
  178. }
  179. }
  180. },
  181. loadSelectOptions(
  182. controlKey: string,
  183. requestParams: { [viewId: string]: IDistinctValueReqeustParams },
  184. itemId: number
  185. ) {
  186. return {
  187. type: ActionTypes.LOAD_SELECT_OPTIONS,
  188. payload: {
  189. controlKey,
  190. requestParams,
  191. itemId
  192. }
  193. }
  194. },
  195. selectOptionsLoaded(controlKey, values, itemId) {
  196. return {
  197. type: ActionTypes.LOAD_SELECT_OPTIONS_SUCCESS,
  198. payload: {
  199. controlKey,
  200. values,
  201. itemId
  202. }
  203. }
  204. },
  205. loadSelectOptionsFail(error) {
  206. return {
  207. type: ActionTypes.LOAD_SELECT_OPTIONS_FAILURE,
  208. payload: {
  209. error
  210. }
  211. }
  212. },
  213. resizeDashboardItem(itemId) {
  214. return {
  215. type: ActionTypes.RESIZE_DASHBOARDITEM,
  216. payload: {
  217. itemId
  218. }
  219. }
  220. },
  221. resizeAllDashboardItem() {
  222. return {
  223. type: ActionTypes.RESIZE_ALL_DASHBOARDITEM
  224. }
  225. },
  226. renderChartError(itemId: number, error: Error) {
  227. return {
  228. type: ActionTypes.RENDER_CHART_ERROR,
  229. payload: {
  230. itemId,
  231. error
  232. }
  233. }
  234. },
  235. drillDashboardItem(itemId, drillHistory) {
  236. return {
  237. type: ActionTypes.DRILL_DASHBOARDITEM,
  238. payload: {
  239. itemId,
  240. drillHistory
  241. }
  242. }
  243. },
  244. deleteDrillHistory(itemId, index) {
  245. return {
  246. type: ActionTypes.DELETE_DRILL_HISTORY,
  247. payload: {
  248. itemId,
  249. index
  250. }
  251. }
  252. },
  253. selectDashboardItemChart(itemId, renderType, selectedItems) {
  254. return {
  255. type: ActionTypes.SELECT_DASHBOARD_ITEM_CHART,
  256. payload: {
  257. itemId,
  258. renderType,
  259. selectedItems
  260. }
  261. }
  262. },
  263. loadDownloadList(shareClinetId, token) {
  264. return {
  265. type: ActionTypes.LOAD_DOWNLOAD_LIST,
  266. payload: {
  267. shareClinetId,
  268. token
  269. }
  270. }
  271. },
  272. downloadListLoaded(list) {
  273. return {
  274. type: ActionTypes.LOAD_DOWNLOAD_LIST_SUCCESS,
  275. payload: {
  276. list
  277. }
  278. }
  279. },
  280. loadDownloadListFail(error) {
  281. return {
  282. type: ActionTypes.LOAD_DOWNLOAD_LIST_FAILURE,
  283. payload: {
  284. error
  285. }
  286. }
  287. },
  288. downloadFile(id, shareClinetId, token) {
  289. return {
  290. type: ActionTypes.DOWNLOAD_FILE,
  291. payload: {
  292. id,
  293. shareClinetId,
  294. token
  295. }
  296. }
  297. },
  298. fileDownloaded(id) {
  299. return {
  300. type: ActionTypes.DOWNLOAD_FILE_SUCCESS,
  301. payload: {
  302. id
  303. }
  304. }
  305. },
  306. downloadFileFail(error) {
  307. return {
  308. type: ActionTypes.DOWNLOAD_FILE_FAILURE,
  309. payload: {
  310. error
  311. }
  312. }
  313. },
  314. initiateDownloadTask(shareClientId: string, itemId: number) {
  315. return {
  316. type: ActionTypes.INITIATE_DOWNLOAD_TASK,
  317. payload: {
  318. shareClientId,
  319. itemId
  320. }
  321. }
  322. },
  323. DownloadTaskInitiated(itemId: number) {
  324. return {
  325. type: ActionTypes.INITIATE_DOWNLOAD_TASK_SUCCESS,
  326. payload: {
  327. itemId
  328. }
  329. }
  330. },
  331. initiateDownloadTaskFail(error, itemId: number) {
  332. return {
  333. type: ActionTypes.INITIATE_DOWNLOAD_TASK_FAILURE,
  334. payload: {
  335. error,
  336. itemId
  337. }
  338. }
  339. },
  340. sendShareParams(params) {
  341. return {
  342. type: ActionTypes.SEND_SHARE_PARAMS,
  343. payload: {
  344. params
  345. }
  346. }
  347. },
  348. setFullScreenPanelItemId(itemId) {
  349. return {
  350. type: ActionTypes.SET_FULL_SCREEN_PANEL_ITEM_ID,
  351. payload: {
  352. itemId
  353. }
  354. }
  355. }
  356. }
  357. const mockAction = returnType(DashboardActions)
  358. export type DashboardActionType = typeof mockAction
  359. export default DashboardActions