actions.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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 axios from 'axios'
  21. import { ActionTypes } from './constants'
  22. import { returnType } from 'utils/redux'
  23. import {
  24. IDashboard,
  25. IDashboardItem,
  26. IQueryConditions,
  27. IDataRequestParams,
  28. IDataDownloadStatistic
  29. } from './types'
  30. import { IWidgetFormed } from '../Widget/types'
  31. import { IFormedViews, IViewQueryResponse } from '../View/types'
  32. import { RenderType } from '../Widget/components/Widget'
  33. import { ControlPanelTypes } from 'app/components/Control/constants'
  34. import { DownloadTypes } from '../App/constants'
  35. import { IShareTokenParams } from 'app/components/SharePanel/types'
  36. const CancelToken = axios.CancelToken
  37. export const DashboardActions = {
  38. addDashboardItems(
  39. portalId: number,
  40. items: Array<Omit<IDashboardItem, 'id' | 'config'>>,
  41. resolve: (items: IDashboardItem[]) => void
  42. ) {
  43. return {
  44. type: ActionTypes.ADD_DASHBOARD_ITEMS,
  45. payload: {
  46. portalId,
  47. items,
  48. resolve
  49. }
  50. }
  51. },
  52. deleteDashboardItem(id, resolve) {
  53. return {
  54. type: ActionTypes.DELETE_DASHBOARD_ITEM,
  55. payload: {
  56. id,
  57. resolve
  58. }
  59. }
  60. },
  61. clearCurrentDashboard() {
  62. return {
  63. type: ActionTypes.CLEAR_CURRENT_DASHBOARD
  64. }
  65. },
  66. loadDashboardItemData(
  67. renderType: RenderType,
  68. itemId: number,
  69. queryConditions?: Partial<IQueryConditions>
  70. ) {
  71. return {
  72. type: ActionTypes.LOAD_DASHBOARD_ITEM_DATA,
  73. payload: {
  74. renderType,
  75. itemId,
  76. queryConditions,
  77. cancelTokenSource: CancelToken.source()
  78. }
  79. }
  80. },
  81. dashboardItemDataLoaded(
  82. renderType: RenderType,
  83. itemId: number,
  84. requestParams: IDataRequestParams,
  85. result: IViewQueryResponse,
  86. statistic
  87. ) {
  88. return {
  89. type: ActionTypes.LOAD_DASHBOARD_ITEM_DATA_SUCCESS,
  90. payload: {
  91. renderType,
  92. itemId,
  93. requestParams,
  94. result
  95. },
  96. statistic
  97. }
  98. },
  99. loadDashboardItemDataFail(itemId: number, errorMessage: string) {
  100. return {
  101. type: ActionTypes.LOAD_DASHBOARD_ITEM_DATA_FAILURE,
  102. payload: {
  103. itemId,
  104. errorMessage
  105. }
  106. }
  107. },
  108. loadBatchDataWithControlValues(
  109. type: ControlPanelTypes,
  110. relatedItems: number[],
  111. formValues?: object,
  112. itemId?: number
  113. ) {
  114. return {
  115. type: ActionTypes.LOAD_BATCH_DATA_WITH_CONTROL_VALUES,
  116. payload: {
  117. type,
  118. relatedItems,
  119. formValues,
  120. itemId,
  121. cancelTokenSource: CancelToken.source()
  122. }
  123. }
  124. },
  125. initiateDownloadTask(type: DownloadTypes, id?: number, itemId?: number) {
  126. return {
  127. type: ActionTypes.INITIATE_DOWNLOAD_TASK,
  128. payload: {
  129. type,
  130. id,
  131. itemId
  132. }
  133. }
  134. },
  135. DownloadTaskInitiated(
  136. type: DownloadTypes,
  137. statistic: IDataDownloadStatistic[],
  138. itemId?: number
  139. ) {
  140. return {
  141. type: ActionTypes.INITIATE_DOWNLOAD_TASK_SUCCESS,
  142. payload: {
  143. type,
  144. itemId
  145. },
  146. statistic
  147. }
  148. },
  149. initiateDownloadTaskFail(error, type: DownloadTypes, itemId?: number) {
  150. return {
  151. type: ActionTypes.INITIATE_DOWNLOAD_TASK_FAILURE,
  152. payload: {
  153. error,
  154. type,
  155. itemId
  156. }
  157. }
  158. },
  159. loadDashboardDetail(portalId, dashboardId) {
  160. return {
  161. type: ActionTypes.LOAD_DASHBOARD_DETAIL,
  162. payload: {
  163. portalId,
  164. dashboardId
  165. }
  166. }
  167. },
  168. dashboardDetailLoaded(
  169. dashboard: IDashboard,
  170. items: IDashboardItem[],
  171. widgets: IWidgetFormed[],
  172. formedViews: IFormedViews
  173. ) {
  174. return {
  175. type: ActionTypes.LOAD_DASHBOARD_DETAIL_SUCCESS,
  176. payload: {
  177. dashboard,
  178. items,
  179. widgets,
  180. formedViews
  181. }
  182. }
  183. },
  184. loadDashboardDetailFail() {
  185. return {
  186. type: ActionTypes.LOAD_DASHBOARD_DETAIL_FAILURE
  187. }
  188. },
  189. dashboardItemsAdded(
  190. items: IDashboardItem[],
  191. widgets: IWidgetFormed[],
  192. formedViews: IFormedViews
  193. ) {
  194. return {
  195. type: ActionTypes.ADD_DASHBOARD_ITEMS_SUCCESS,
  196. payload: {
  197. items,
  198. widgets,
  199. formedViews
  200. }
  201. }
  202. },
  203. addDashboardItemsFail() {
  204. return {
  205. type: ActionTypes.ADD_DASHBOARD_ITEMS_FAILURE
  206. }
  207. },
  208. editDashboardItem(portalId, item, resolve) {
  209. return {
  210. type: ActionTypes.EDIT_DASHBOARD_ITEM,
  211. payload: {
  212. portalId,
  213. item,
  214. resolve
  215. }
  216. }
  217. },
  218. dashboardItemEdited(result) {
  219. return {
  220. type: ActionTypes.EDIT_DASHBOARD_ITEM_SUCCESS,
  221. payload: {
  222. result
  223. }
  224. }
  225. },
  226. editDashboardItemFail() {
  227. return {
  228. type: ActionTypes.EDIT_DASHBOARD_ITEM_FAILURE
  229. }
  230. },
  231. editDashboardItems(portalId, items) {
  232. return {
  233. type: ActionTypes.EDIT_DASHBOARD_ITEMS,
  234. payload: {
  235. portalId,
  236. items
  237. }
  238. }
  239. },
  240. dashboardItemsEdited(items) {
  241. return {
  242. type: ActionTypes.EDIT_DASHBOARD_ITEMS_SUCCESS,
  243. payload: {
  244. items
  245. }
  246. }
  247. },
  248. editDashboardItemsFail() {
  249. return {
  250. type: ActionTypes.EDIT_DASHBOARD_ITEMS_FAILURE
  251. }
  252. },
  253. dashboardItemDeleted(id) {
  254. return {
  255. type: ActionTypes.DELETE_DASHBOARD_ITEM_SUCCESS,
  256. payload: {
  257. id
  258. }
  259. }
  260. },
  261. deleteDashboardItemFail() {
  262. return {
  263. type: ActionTypes.DELETE_DASHBOARD_ITEM_FAILURE
  264. }
  265. },
  266. loadDashboardShareLink(params: IShareTokenParams) {
  267. return {
  268. type: ActionTypes.LOAD_DASHBOARD_SHARE_LINK,
  269. payload: {
  270. params
  271. }
  272. }
  273. },
  274. dashboardShareLinkLoaded(shareToken) {
  275. return {
  276. type: ActionTypes.LOAD_DASHBOARD_SHARE_LINK_SUCCESS,
  277. payload: {
  278. shareToken
  279. }
  280. }
  281. },
  282. dashboardAuthorizedShareLinkLoaded(authorizedShareToken) {
  283. return {
  284. type: ActionTypes.LOAD_DASHBOARD_AUTHORIZED_SHARE_LINK_SUCCESS,
  285. payload: {
  286. authorizedShareToken
  287. }
  288. }
  289. },
  290. dashboardPasswordShareLinkLoaded(passwordShareToken, password) {
  291. return {
  292. type: ActionTypes.LOAD_DASHBOARD_PASSWORD_SHARE_LINK_SUCCESS,
  293. payload: {
  294. passwordShareToken,
  295. password
  296. }
  297. }
  298. },
  299. loadDashboardShareLinkFail() {
  300. return {
  301. type: ActionTypes.LOAD_DASHBOARD_SHARE_LINK_FAILURE
  302. }
  303. },
  304. loadWidgetShareLink(params: IShareTokenParams) {
  305. return {
  306. type: ActionTypes.LOAD_WIDGET_SHARE_LINK,
  307. payload: {
  308. params
  309. }
  310. }
  311. },
  312. widgetShareLinkLoaded(shareToken, itemId) {
  313. return {
  314. type: ActionTypes.LOAD_WIDGET_SHARE_LINK_SUCCESS,
  315. payload: {
  316. shareToken,
  317. itemId
  318. }
  319. }
  320. },
  321. widgetAuthorizedShareLinkLoaded(authorizedShareToken, itemId) {
  322. return {
  323. type: ActionTypes.LOAD_WIDGET_AUTHORIZED_SHARE_LINK_SUCCESS,
  324. payload: {
  325. authorizedShareToken,
  326. itemId
  327. }
  328. }
  329. },
  330. widgetPasswordShareLinkLoaded(passwordShareToken, password, itemId) {
  331. return {
  332. type: ActionTypes.LOAD_WIDGET_PASSWORD_SHARE_LINK_SUCCESS,
  333. payload: {
  334. passwordShareToken,
  335. password,
  336. itemId
  337. }
  338. }
  339. },
  340. loadWidgetShareLinkFail(itemId) {
  341. return {
  342. type: ActionTypes.LOAD_WIDGET_SHARE_LINK_FAILURE,
  343. payload: {
  344. itemId
  345. }
  346. }
  347. },
  348. openSharePanel(id, type, title, itemId?) {
  349. return {
  350. type: ActionTypes.OPEN_SHARE_PANEL,
  351. payload: {
  352. id,
  353. type,
  354. title,
  355. itemId
  356. }
  357. }
  358. },
  359. closeSharePanel() {
  360. return {
  361. type: ActionTypes.CLOSE_SHARE_PANEL
  362. }
  363. },
  364. loadWidgetCsv(itemId, widgetId, requestParams) {
  365. return {
  366. type: ActionTypes.LOAD_WIDGET_CSV,
  367. payload: {
  368. itemId,
  369. widgetId,
  370. requestParams
  371. }
  372. }
  373. },
  374. widgetCsvLoaded(itemId) {
  375. return {
  376. type: ActionTypes.LOAD_WIDGET_CSV_SUCCESS,
  377. payload: {
  378. itemId
  379. }
  380. }
  381. },
  382. loadWidgetCsvFail(itemId) {
  383. return {
  384. type: ActionTypes.LOAD_WIDGET_CSV_FAILURE,
  385. payload: {
  386. itemId
  387. }
  388. }
  389. },
  390. renderDashboardItem(itemId) {
  391. return {
  392. type: ActionTypes.RENDER_DASHBOARDITEM,
  393. payload: {
  394. itemId
  395. }
  396. }
  397. },
  398. resizeDashboardItem(itemId) {
  399. return {
  400. type: ActionTypes.RESIZE_DASHBOARDITEM,
  401. payload: {
  402. itemId
  403. }
  404. }
  405. },
  406. resizeAllDashboardItem() {
  407. return {
  408. type: ActionTypes.RESIZE_ALL_DASHBOARDITEM
  409. }
  410. },
  411. renderChartError(itemId: number, error: Error) {
  412. return {
  413. type: ActionTypes.RENDER_CHART_ERROR,
  414. payload: {
  415. itemId,
  416. error
  417. }
  418. }
  419. },
  420. drillDashboardItem(itemId, drillHistory) {
  421. return {
  422. type: ActionTypes.DRILL_DASHBOARDITEM,
  423. payload: {
  424. itemId,
  425. drillHistory
  426. }
  427. }
  428. },
  429. deleteDrillHistory(itemId, index) {
  430. return {
  431. type: ActionTypes.DELETE_DRILL_HISTORY,
  432. payload: {
  433. itemId,
  434. index
  435. }
  436. }
  437. },
  438. drillPathsetting(itemId, history) {
  439. return {
  440. type: ActionTypes.DRILL_PATH_SETTING,
  441. payload: {
  442. itemId,
  443. history
  444. }
  445. }
  446. },
  447. selectDashboardItemChart(itemId, renderType, selectedItems) {
  448. return {
  449. type: ActionTypes.SELECT_DASHBOARD_ITEM_CHART,
  450. payload: {
  451. itemId,
  452. renderType,
  453. selectedItems
  454. }
  455. }
  456. },
  457. monitoredSyncDataAction() {
  458. return {
  459. type: ActionTypes.MONITORED_SYNC_DATA_ACTION
  460. }
  461. },
  462. monitoredSearchDataAction() {
  463. return {
  464. type: ActionTypes.MONITORED_SEARCH_DATA_ACTION
  465. }
  466. },
  467. monitoredLinkageDataAction() {
  468. return {
  469. type: ActionTypes.MONITORED_LINKAGE_DATA_ACTION
  470. }
  471. },
  472. setFullScreenPanelItemId(itemId) {
  473. return {
  474. type: ActionTypes.SET_FULL_SCREEN_PANEL_ITEM_ID,
  475. payload: {
  476. itemId
  477. }
  478. }
  479. }
  480. }
  481. const mockAction = returnType(DashboardActions)
  482. export type DashboardActionType = typeof mockAction
  483. export default DashboardActions