actions.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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, DragTriggerTypes } from './constants'
  21. import { returnType } from 'utils/redux'
  22. import {
  23. IBaseline,
  24. ILayerFormed,
  25. DeltaSize,
  26. DeltaPosition,
  27. ILayerParams,
  28. ILayerOperationInfo
  29. } from './components/types'
  30. import { IWidgetFormed } from 'containers/Widget/types'
  31. import { IFormedViews } from 'containers/View/types'
  32. import { ISlideFormed, ISlideParams } from 'containers/Viz/types'
  33. import { LayerOperations, LayerAlignmentTypes } from './components/constants'
  34. import { IShareTokenParams } from 'app/components/SharePanel/types'
  35. export const DisplayActions = {
  36. loadSlideDetail (displayId: number, slideId: number) {
  37. return {
  38. type: ActionTypes.LOAD_SLIDE_DETAIL,
  39. payload: {
  40. displayId,
  41. slideId
  42. }
  43. }
  44. },
  45. slideDetailLoaded (
  46. slideId: number,
  47. layers: ILayerFormed[],
  48. widgets: IWidgetFormed[],
  49. formedViews: IFormedViews
  50. ) {
  51. return {
  52. type: ActionTypes.LOAD_SLIDE_DETAIL_SUCCESS,
  53. payload: {
  54. slideId,
  55. layers,
  56. widgets,
  57. formedViews
  58. }
  59. }
  60. },
  61. loadSlideDetailFail (err) {
  62. return {
  63. type: ActionTypes.LOAD_SLIDE_DETAIL_FAILURE,
  64. payload: {
  65. err
  66. }
  67. }
  68. },
  69. uploadCurrentSlideCover (cover: Blob, slide: ISlideFormed) {
  70. return {
  71. type: ActionTypes.UPLOAD_CURRENT_SLIDE_COVER,
  72. payload: {
  73. cover,
  74. slide
  75. }
  76. }
  77. },
  78. currentSlideCoverUploaded (result: string) {
  79. return {
  80. type: ActionTypes.UPLOAD_CURRENT_SLIDE_COVER_SUCCESS,
  81. payload: {
  82. result
  83. }
  84. }
  85. },
  86. uploadCurrentSlideCoverFail (error) {
  87. return {
  88. type: ActionTypes.UPLOAD_CURRENT_SLIDE_COVER_FAILURE,
  89. payload: {
  90. error
  91. }
  92. }
  93. },
  94. resizeLayer (
  95. slideSize: Pick<ISlideParams, 'width' | 'height'>,
  96. scale: number,
  97. layerId: number,
  98. deltaSize: DeltaSize,
  99. finish: boolean
  100. ) {
  101. return {
  102. type: ActionTypes.RESIZE_LAYER,
  103. payload: {
  104. slideSize,
  105. scale,
  106. layerId,
  107. deltaSize,
  108. finish
  109. }
  110. }
  111. },
  112. resizeLayerAdjusted (layerIds: number[], deltaSize: DeltaSize, finish: boolean) {
  113. return {
  114. type: ActionTypes.RESIZE_LAYER_ADJUSTED,
  115. payload: {
  116. layerIds,
  117. deltaSize,
  118. finish
  119. }
  120. }
  121. },
  122. dragLayer (
  123. slideSize: Pick<ISlideParams, 'width' | 'height'>,
  124. scale: number,
  125. deltaPosition: DeltaPosition,
  126. eventTrigger: DragTriggerTypes,
  127. finish: boolean,
  128. layerId?: number
  129. ) {
  130. return {
  131. type: ActionTypes.DRAG_LAYER,
  132. payload: {
  133. slideSize,
  134. scale,
  135. layerId,
  136. deltaPosition,
  137. eventTrigger,
  138. finish
  139. }
  140. }
  141. },
  142. dragLayerAdjusted (
  143. layerIds: number[],
  144. slideSize: Pick<ISlideParams, 'width' | 'height'>,
  145. deltaPosition: DeltaPosition,
  146. finish: boolean
  147. ) {
  148. return {
  149. type: ActionTypes.DRAG_LAYER_ADJUSTED,
  150. payload: {
  151. layerIds,
  152. slideSize,
  153. deltaPosition,
  154. finish
  155. }
  156. }
  157. },
  158. changeLayersStack (operation: LayerOperations) {
  159. return {
  160. type: ActionTypes.CHANGE_LAYERS_STACK,
  161. payload: {
  162. operation
  163. }
  164. }
  165. },
  166. setLayersAlignment (alignmentType: LayerAlignmentTypes) {
  167. return {
  168. type: ActionTypes.SET_LAYERS_ALIGNMENT,
  169. payload: {
  170. alignmentType
  171. }
  172. }
  173. },
  174. selectLayer (layerId: number, selected: boolean, exclusive: boolean) {
  175. return {
  176. type: ActionTypes.SELECT_LAYER,
  177. payload: {
  178. layerId,
  179. selected,
  180. exclusive
  181. }
  182. }
  183. },
  184. clearLayersOperationInfo (changedInfo: Pick< Partial<ILayerOperationInfo>, 'selected' | 'editing'>) {
  185. return {
  186. type: ActionTypes.CLEAR_LAYERS_OPERATION_INFO,
  187. payload: {
  188. changedInfo
  189. }
  190. }
  191. },
  192. clearEditorBaselines () {
  193. return {
  194. type: ActionTypes.CLEAR_EDITOR_BASELINES,
  195. payload: {}
  196. }
  197. },
  198. showEditorBaselines (baselines: IBaseline[]) {
  199. return {
  200. type: ActionTypes.SHOW_EDITOR_BASELINES,
  201. payload: {
  202. baselines
  203. }
  204. }
  205. },
  206. copySlideLayers () {
  207. return {
  208. type: ActionTypes.COPY_SLIDE_LAYERS,
  209. payload: {}
  210. }
  211. },
  212. slideLayersCopied (layers: ILayerFormed[]) {
  213. return {
  214. type: ActionTypes.COPY_SLIDE_LAYERS_SUCCESS,
  215. payload: {
  216. layers
  217. }
  218. }
  219. },
  220. pasteSlideLayers () {
  221. return {
  222. type: ActionTypes.PASTE_SLIDE_LAYERS,
  223. payload: {}
  224. }
  225. },
  226. undoOperation (currentState) {
  227. return {
  228. type: ActionTypes.UNDO_OPERATION,
  229. payload: {
  230. currentState
  231. }
  232. }
  233. },
  234. undoOperationDone () {
  235. return {
  236. type: ActionTypes.UNDO_OPERATION_SUCCESS,
  237. payload: {}
  238. }
  239. },
  240. undoOperationFail () {
  241. return {
  242. type: ActionTypes.UNDO_OPERATION_FAILURE,
  243. payload: {}
  244. }
  245. },
  246. redoOperation (nextState) {
  247. return {
  248. type: ActionTypes.REDO_OPERATION,
  249. payload: {
  250. nextState
  251. }
  252. }
  253. },
  254. redoOperationDone () {
  255. return {
  256. type: ActionTypes.REDO_OPERATION_SUCCESS,
  257. payload: {}
  258. }
  259. },
  260. redoOperationFail () {
  261. return {
  262. type: ActionTypes.REDO_OPERATION_FAILURE,
  263. payload: {}
  264. }
  265. },
  266. addSlideLayers (
  267. displayId: number,
  268. slideId: number,
  269. layers: Array<Omit<ILayerFormed, 'id'>>,
  270. widgets?: IWidgetFormed[]
  271. ) {
  272. return {
  273. type: ActionTypes.ADD_SLIDE_LAYERS,
  274. payload: {
  275. displayId,
  276. slideId,
  277. layers,
  278. widgets
  279. }
  280. }
  281. },
  282. slideLayersAdded (
  283. slideId: number,
  284. layers: ILayerFormed[],
  285. widgets: IWidgetFormed[]
  286. ) {
  287. return {
  288. type: ActionTypes.ADD_SLIDE_LAYERS_SUCCESS,
  289. payload: {
  290. slideId,
  291. layers,
  292. widgets
  293. }
  294. }
  295. },
  296. addSlideLayersFail () {
  297. return {
  298. type: ActionTypes.ADD_SLIDE_LAYERS_FAILURE,
  299. payload: {}
  300. }
  301. },
  302. editSlideLayers (displayId: number, slideId: number, layers: ILayerFormed[], layerParamsUnChanged?: boolean) {
  303. return {
  304. type: ActionTypes.EDIT_SLIDE_LAYERS,
  305. payload: {
  306. displayId,
  307. slideId,
  308. layers,
  309. layerParamsUnChanged
  310. }
  311. }
  312. },
  313. slideLayersEdited (slideId: number, layers: ILayerFormed[]) {
  314. return {
  315. type: ActionTypes.EDIT_SLIDE_LAYERS_SUCCESS,
  316. payload: {
  317. slideId,
  318. layers
  319. }
  320. }
  321. },
  322. editSlideLayersFail () {
  323. return {
  324. type: ActionTypes.EDIT_SLIDE_LAYERS_FAILURE,
  325. payload: {}
  326. }
  327. },
  328. editSlideLayerParams (layerId: number, changedParams: Partial<ILayerParams>) {
  329. return {
  330. type: ActionTypes.EDIT_SLIDE_LAYER_PARAMS,
  331. payload: {
  332. layerId,
  333. changedParams
  334. }
  335. }
  336. },
  337. deleteSlideLayers (displayId: number, slideId: number) {
  338. return {
  339. type: ActionTypes.DELETE_SLIDE_LAYERS,
  340. payload: {
  341. displayId,
  342. slideId
  343. }
  344. }
  345. },
  346. changeLayerOperationInfo (layerId: number, changedInfo: Partial<ILayerOperationInfo>) {
  347. return {
  348. type: ActionTypes.CHANGE_LAYER_OPERATION_INFO,
  349. payload: {
  350. layerId,
  351. changedInfo
  352. }
  353. }
  354. },
  355. slideLayersDeleted (slideId: number, layerIds: number[]) {
  356. return {
  357. type: ActionTypes.DELETE_SLIDE_LAYERS_SUCCESS,
  358. payload: {
  359. slideId,
  360. layerIds
  361. }
  362. }
  363. },
  364. deleteSlideLayersFail () {
  365. return {
  366. type: ActionTypes.DELETE_SLIDE_LAYERS_FAILURE,
  367. payload: {}
  368. }
  369. },
  370. loadDisplayShareLink (params: IShareTokenParams) {
  371. return {
  372. type: ActionTypes.LOAD_DISPLAY_SHARE_LINK,
  373. payload: {
  374. params
  375. }
  376. }
  377. },
  378. displayShareLinkLoaded (shareToken: string) {
  379. return {
  380. type: ActionTypes.LOAD_DISPLAY_SHARE_LINK_SUCCESS,
  381. payload: {
  382. shareToken
  383. }
  384. }
  385. },
  386. displayAuthorizedShareLinkLoaded (authorizedShareToken: string) {
  387. return {
  388. type: ActionTypes.LOAD_DISPLAY_AUTHORIZED_SHARE_LINK_SUCCESS,
  389. payload: {
  390. authorizedShareToken
  391. }
  392. }
  393. },
  394. displayPasswordShareLinkLoaded (passwordShareToken, password) {
  395. return {
  396. type: ActionTypes.LOAD_DISPLAY_PASSWORD_SHARE_LINK_SUCCESS,
  397. payload: {
  398. passwordShareToken,
  399. password
  400. }
  401. }
  402. },
  403. loadDisplayShareLinkFail () {
  404. return {
  405. type: ActionTypes.LOAD_DISPLAY_SHARE_LINK_FAILURE,
  406. payload: {}
  407. }
  408. },
  409. openSharePanel (id, title) {
  410. return {
  411. type: ActionTypes.OPEN_SHARE_PANEL,
  412. payload: {
  413. id,
  414. title
  415. }
  416. }
  417. },
  418. closeSharePanel () {
  419. return {
  420. type: ActionTypes.CLOSE_SHARE_PANEL
  421. }
  422. },
  423. resetDisplayState () {
  424. return {
  425. type: ActionTypes.RESET_DISPLAY_STATE,
  426. payload: {}
  427. }
  428. },
  429. monitoredSyncDataAction () {
  430. return {
  431. type: ActionTypes.MONITORED_SYNC_DATA_ACTION,
  432. payload: {}
  433. }
  434. },
  435. monitoredSearchDataAction () {
  436. return {
  437. type: ActionTypes.MONITORED_SEARCH_DATA_ACTION,
  438. payload: {}
  439. }
  440. },
  441. monitoredLinkageDataAction () {
  442. return {
  443. type: ActionTypes.MONITORED_LINKAGE_DATA_ACTION,
  444. payload: {}
  445. }
  446. }
  447. }
  448. const mockAction = returnType(DisplayActions)
  449. export type DisplayActionType = typeof mockAction
  450. export default DisplayActions