actions.ts 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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 { ActionTypes } from './constants'
  21. import { returnType } from 'utils/redux'
  22. import {
  23. IPortal,
  24. IDashboardNode,
  25. IDisplayRaw,
  26. IDisplayFormed,
  27. ISlideFormed,
  28. ISlideParams,
  29. IDashboard
  30. } from './types'
  31. export const VizActions = {
  32. loadPortals(projectId: number) {
  33. return {
  34. type: ActionTypes.LOAD_PORTALS,
  35. payload: {
  36. projectId
  37. }
  38. }
  39. },
  40. portalsLoaded(result: IPortal[]) {
  41. return {
  42. type: ActionTypes.LOAD_PORTALS_SUCCESS,
  43. payload: {
  44. result
  45. }
  46. }
  47. },
  48. loadPortalsFail() {
  49. return {
  50. type: ActionTypes.LOAD_PORTALS_FAILURE,
  51. payload: {}
  52. }
  53. },
  54. addPortal(portal: IPortal, resolve) {
  55. return {
  56. type: ActionTypes.ADD_PORTAL,
  57. payload: {
  58. portal,
  59. resolve
  60. }
  61. }
  62. },
  63. portalAdded(result) {
  64. return {
  65. type: ActionTypes.ADD_PORTAL_SUCCESS,
  66. payload: {
  67. result
  68. }
  69. }
  70. },
  71. addPortalFail() {
  72. return {
  73. type: ActionTypes.ADD_PORTAL_FAILURE,
  74. payload: {}
  75. }
  76. },
  77. editPortal(values, resolve) {
  78. return {
  79. type: ActionTypes.EDIT_PORTAL,
  80. payload: {
  81. values,
  82. resolve
  83. }
  84. }
  85. },
  86. portalEdited(result) {
  87. return {
  88. type: ActionTypes.EDIT_PORTAL_SUCCESS,
  89. payload: {
  90. result
  91. }
  92. }
  93. },
  94. editPortalFail() {
  95. return {
  96. type: ActionTypes.EDIT_PORTAL_FAILURE,
  97. payload: {}
  98. }
  99. },
  100. deletePortal(id) {
  101. return {
  102. type: ActionTypes.DELETE_PORTAL,
  103. payload: {
  104. id
  105. }
  106. }
  107. },
  108. portalDeleted(id) {
  109. return {
  110. type: ActionTypes.DELETE_PORTAL_SUCCESS,
  111. payload: {
  112. id
  113. }
  114. }
  115. },
  116. deletePortalFail() {
  117. return {
  118. type: ActionTypes.DELETE_PORTAL_FAILURE,
  119. payload: {}
  120. }
  121. },
  122. loadPortalDashboards(portalId: number, resolve?: (result) => void, convertTree: boolean = true) {
  123. return {
  124. type: ActionTypes.LOAD_PORTAL_DASHBOARDS,
  125. payload: {
  126. portalId,
  127. resolve,
  128. convertTree
  129. }
  130. }
  131. },
  132. portalDashboardsLoaded(portalId: number, dashboards: IDashboardNode[]) {
  133. return {
  134. type: ActionTypes.LOAD_PORTAL_DASHBOARDS_SUCCESS,
  135. payload: {
  136. portalId,
  137. dashboards
  138. }
  139. }
  140. },
  141. loadPortalDashboardsFail(portalId: number) {
  142. return {
  143. type: ActionTypes.LOAD_PORTAL_DASHBOARDS_FAILURE,
  144. payload: {
  145. portalId
  146. }
  147. }
  148. },
  149. loadDisplays(projectId: number) {
  150. return {
  151. type: ActionTypes.LOAD_DISPLAYS,
  152. payload: {
  153. projectId
  154. }
  155. }
  156. },
  157. displaysLoaded(displays: IDisplayRaw[]) {
  158. return {
  159. type: ActionTypes.LOAD_DISPLAYS_SUCCESS,
  160. payload: {
  161. displays
  162. }
  163. }
  164. },
  165. loadDisplaysFail(error) {
  166. return {
  167. type: ActionTypes.LOAD_DISPLAYS_FAILURE,
  168. payload: {
  169. error
  170. }
  171. }
  172. },
  173. updateCurrentDisplay(display: IDisplayFormed) {
  174. return {
  175. type: ActionTypes.UPDATE_CURRENT_DISPLAY,
  176. payload: {
  177. display
  178. }
  179. }
  180. },
  181. loadDisplaySlides(displayId: number) {
  182. return {
  183. type: ActionTypes.LOAD_DISPLAY_SLIDES,
  184. payload: {
  185. displayId
  186. }
  187. }
  188. },
  189. displaySlidesLoaded(display: IDisplayFormed, slides: ISlideFormed[]) {
  190. return {
  191. type: ActionTypes.LOAD_DISPLAY_SLIDES_SUCCESS,
  192. payload: {
  193. display,
  194. slides
  195. }
  196. }
  197. },
  198. loadDisplaySlidesFail(displayId: number) {
  199. return {
  200. type: ActionTypes.LOAD_DISPLAY_SLIDES_FAILURE,
  201. payload: {
  202. displayId
  203. }
  204. }
  205. },
  206. addDisplay(display, resolve) {
  207. return {
  208. type: ActionTypes.ADD_DISPLAY,
  209. payload: {
  210. display,
  211. resolve
  212. }
  213. }
  214. },
  215. displayAdded(result) {
  216. return {
  217. type: ActionTypes.ADD_DISPLAY_SUCCESS,
  218. payload: {
  219. result
  220. }
  221. }
  222. },
  223. addDisplayFail() {
  224. return {
  225. type: ActionTypes.ADD_DISPLAY_FAILURE,
  226. payload: {}
  227. }
  228. },
  229. editDisplay(display: IDisplayFormed, resolve?) {
  230. return {
  231. type: ActionTypes.EDIT_DISPLAY,
  232. payload: {
  233. display,
  234. resolve
  235. }
  236. }
  237. },
  238. displayEdited(result: IDisplayFormed) {
  239. return {
  240. type: ActionTypes.EDIT_DISPLAY_SUCCESS,
  241. payload: {
  242. result
  243. }
  244. }
  245. },
  246. editDisplayFail(error) {
  247. return {
  248. type: ActionTypes.EDIT_DISPLAY_FAILURE,
  249. payload: {
  250. error
  251. }
  252. }
  253. },
  254. deleteDisplay(id) {
  255. return {
  256. type: ActionTypes.DELETE_DISPLAY,
  257. payload: {
  258. id
  259. }
  260. }
  261. },
  262. displayDeleted(id) {
  263. return {
  264. type: ActionTypes.DELETE_DISPLAY_SUCCESS,
  265. payload: {
  266. id
  267. }
  268. }
  269. },
  270. deleteDisplayFail() {
  271. return {
  272. type: ActionTypes.DELETE_DISPLAY_FAILURE,
  273. payload: {}
  274. }
  275. },
  276. copyDisplay(display: IDisplayFormed, resolve) {
  277. return {
  278. type: ActionTypes.COPY_DISPLAY,
  279. payload: {
  280. display,
  281. resolve
  282. }
  283. }
  284. },
  285. displayCopied(display: IDisplayFormed) {
  286. return {
  287. type: ActionTypes.COPY_DISPLAY_SUCCESS,
  288. payload: {
  289. display
  290. }
  291. }
  292. },
  293. copyDisplayFail() {
  294. return {
  295. type: ActionTypes.COPY_DISPLAY_FAILURE,
  296. payload: {}
  297. }
  298. },
  299. addDashboard(dashboard, resolve) {
  300. return {
  301. type: ActionTypes.ADD_DASHBOARD,
  302. payload: {
  303. dashboard,
  304. resolve
  305. }
  306. }
  307. },
  308. dashboardAdded(result) {
  309. return {
  310. type: ActionTypes.ADD_DASHBOARD_SUCCESS,
  311. payload: {
  312. result
  313. }
  314. }
  315. },
  316. addDashboardFail() {
  317. return {
  318. type: ActionTypes.ADD_DASHBOARD_FAILURE
  319. }
  320. },
  321. editDashboard(formType, dashboard, resolve) {
  322. return {
  323. type: ActionTypes.EDIT_DASHBOARD,
  324. payload: {
  325. formType,
  326. dashboard,
  327. resolve
  328. }
  329. }
  330. },
  331. dashboardEdited(result, formType) {
  332. return {
  333. type: ActionTypes.EDIT_DASHBOARD_SUCCESS,
  334. payload: {
  335. result,
  336. formType
  337. }
  338. }
  339. },
  340. editDashboardFail() {
  341. return {
  342. type: ActionTypes.EDIT_DASHBOARD_FAILURE
  343. }
  344. },
  345. editCurrentDashboard (
  346. dashboard: IDashboard,
  347. type: 'linkage' | 'control',
  348. resolve: () => void) {
  349. return {
  350. type: ActionTypes.EDIT_CURRENT_DASHBOARD,
  351. payload: {
  352. dashboard,
  353. type,
  354. resolve
  355. }
  356. }
  357. },
  358. currentDashboardEdited (result: IDashboard, type: 'linkage' | 'control') {
  359. return {
  360. type: ActionTypes.EDIT_CURRENT_DASHBOARD_SUCCESS,
  361. payload: {
  362. result,
  363. type
  364. }
  365. }
  366. },
  367. editCurrentDashboardFail () {
  368. return {
  369. type: ActionTypes.EDIT_CURRENT_DASHBOARD_FAILURE
  370. }
  371. },
  372. deleteDashboard(id, portalId, resolve) {
  373. return {
  374. type: ActionTypes.DELETE_DASHBOARD,
  375. payload: {
  376. resolve,
  377. id,
  378. portalId
  379. }
  380. }
  381. },
  382. dashboardDeleted(id, portalId) {
  383. return {
  384. type: ActionTypes.DELETE_DASHBOARD_SUCCESS,
  385. payload: {
  386. id,
  387. portalId
  388. }
  389. }
  390. },
  391. deleteDashboardFail() {
  392. return {
  393. type: ActionTypes.DELETE_DASHBOARD_FAILURE
  394. }
  395. },
  396. addSlide() {
  397. return {
  398. type: ActionTypes.ADD_SLIDE,
  399. payload: {
  400. }
  401. }
  402. },
  403. slideAdded(slide: ISlideFormed, insertIdx: number, afterSlides: ISlideFormed[]) {
  404. return {
  405. type: ActionTypes.ADD_SLIDE_SUCCESS,
  406. payload: {
  407. slide,
  408. insertIdx,
  409. afterSlides
  410. }
  411. }
  412. },
  413. addSlideFail() {
  414. return {
  415. type: ActionTypes.ADD_SLIDE_FAILURE,
  416. payload: {}
  417. }
  418. },
  419. editSlides(slides: ISlideFormed[]) {
  420. return {
  421. type: ActionTypes.EDIT_SLIDES,
  422. payload: {
  423. slides
  424. }
  425. }
  426. },
  427. slidesEdited(displayId: number, slides: ISlideFormed[]) {
  428. return {
  429. type: ActionTypes.EDIT_SLIDES_SUCCESS,
  430. payload: {
  431. displayId,
  432. slides
  433. }
  434. }
  435. },
  436. editSlidesFail() {
  437. return {
  438. type: ActionTypes.EDIT_SLIDES_FAILURE,
  439. payload: {}
  440. }
  441. },
  442. editCurrentSlideParams(changedParams: Partial<ISlideParams>) {
  443. return {
  444. type: ActionTypes.EDIT_CURRENT_SLIDE_PARAMS,
  445. payload: {
  446. changedParams
  447. }
  448. }
  449. },
  450. deleteSlides(displayId: number, slideIds: number[]) {
  451. return {
  452. type: ActionTypes.DELETE_SLIDES,
  453. payload: {
  454. displayId,
  455. slideIds
  456. }
  457. }
  458. },
  459. slidesDeleted(displayId: number, slideIds: number[]) {
  460. return {
  461. type: ActionTypes.DELETE_SLIDES_SUCCESS,
  462. payload: {
  463. displayId,
  464. slideIds
  465. }
  466. }
  467. },
  468. deleteSlidesFail() {
  469. return {
  470. type: ActionTypes.DELETE_SLIDES_FAILURE,
  471. payload: {}
  472. }
  473. }
  474. }
  475. const mockAction = returnType(VizActions)
  476. export type VizActionType = typeof mockAction
  477. export default VizActions