123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483 |
- /*
- * <<
- * Davinci
- * ==
- * Copyright (C) 2016 - 2017 EDP
- * ==
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * >>
- */
- import axios from 'axios'
- import { ActionTypes } from './constants'
- import { returnType } from 'utils/redux'
- import { IDavinciResponse } from 'utils/request'
- import {
- IViewBase,
- IView,
- IExecuteSqlParams,
- IExecuteSqlResponse,
- IViewInfo,
- IDacChannel,
- IDacTenant,
- IDacBiz,
- IViewQueryResponse
- } from './types'
- import { IDataRequestBody } from '../Dashboard/types'
- import { RenderType } from 'containers/Widget/components/Widget'
- import { IDistinctValueReqeustParams } from 'app/components/Control/types'
- import { EExecuteType } from './Editor'
- const CancelToken = axios.CancelToken
- export const ViewActions = {
- viewsLoaded (views: IViewBase[]) {
- return {
- type: ActionTypes.LOAD_VIEWS_SUCCESS,
- payload: {
- views
- }
- }
- },
- loadViews (projectId: number, parentId?: number, resolve?: (views: IViewBase[]) => void) {
- return {
- type: ActionTypes.LOAD_VIEWS,
- payload: {
- projectId,
- parentId,
- resolve
- }
- }
- },
- loadViewsFail () {
- return {
- type: ActionTypes.LOAD_VIEWS_FAILURE,
- payload: {}
- }
- },
- viewsDetailLoaded (views: IView[], isEditing: boolean) {
- return {
- type: ActionTypes.LOAD_VIEWS_DETAIL_SUCCESS,
- payload: {
- views,
- isEditing
- }
- }
- },
- loadViewsDetail (
- viewIds: number[],
- resolve?: (views: IView[]) => void,
- isEditing: boolean = false
- ) {
- return {
- type: ActionTypes.LOAD_VIEWS_DETAIL,
- payload: {
- viewIds,
- isEditing,
- resolve
- }
- }
- },
- loadViewsDetailFail () {
- return {
- type: ActionTypes.LOAD_VIEWS_DETAIL_FAILURE,
- payload: {}
- }
- },
- addView (view: IView, resolve: () => void) {
- return {
- type: ActionTypes.ADD_VIEW,
- payload: {
- view,
- resolve
- }
- }
- },
- viewAdded (result: IView) {
- return {
- type: ActionTypes.ADD_VIEW_SUCCESS,
- payload: {
- result
- }
- }
- },
- addViewFail () {
- return {
- type: ActionTypes.ADD_VIEW_FAILURE,
- payload: {}
- }
- },
- editView (view: IView, resolve: () => void) {
- return {
- type: ActionTypes.EDIT_VIEW,
- payload: {
- view,
- resolve
- }
- }
- },
- viewEdited (result: IView) {
- return {
- type: ActionTypes.EDIT_VIEW_SUCCESS,
- payload: {
- result
- }
- }
- },
- editViewFail () {
- return {
- type: ActionTypes.EDIT_VIEW_FAILURE,
- payload: {}
- }
- },
- deleteView (id: number, resolve: (id: number) => void) {
- return {
- type: ActionTypes.DELETE_VIEW,
- payload: {
- id,
- resolve
- }
- }
- },
- viewDeleted (id: number) {
- return {
- type: ActionTypes.DELETE_VIEW_SUCCESS,
- payload: {
- id
- }
- }
- },
- deleteViewFail () {
- return {
- type: ActionTypes.DELETE_VIEW_FAILURE,
- payload: {}
- }
- },
- copyView (view: IViewBase, resolve: () => void) {
- return {
- type: ActionTypes.COPY_VIEW,
- payload: {
- view,
- resolve
- }
- }
- },
- viewCopied (fromViewId: number, result: IView) {
- return {
- type: ActionTypes.COPY_VIEW_SUCCESS,
- payload: {
- fromViewId,
- result
- }
- }
- },
- copyViewFail () {
- return {
- type: ActionTypes.COPY_VIEW_FAILURE,
- payload: {}
- }
- },
- setIsLastExecuteWholeSql (isLastExecuteWholeSql: boolean) {
- return {
- type: ActionTypes.IS_LAST_EXECUTE_WHOLE_SQL,
- payload: {
- isLastExecuteWholeSql
- }
- }
- },
- executeSql (params: IExecuteSqlParams, exeType: EExecuteType) {
- return {
- type: ActionTypes.EXECUTE_SQL,
- payload: {
- params,
- exeType
- }
- }
- },
- sqlExecuted (result: IDavinciResponse<IExecuteSqlResponse>) {
- return {
- type: ActionTypes.EXECUTE_SQL_SUCCESS,
- payload: {
- result
- }
- }
- },
- executeSqlFail (err: IDavinciResponse<any>['header']) {
- return {
- type: ActionTypes.EXECUTE_SQL_FAILURE,
- payload: {
- err
- }
- }
- },
- executeSqlCancel () {
- return {
- type: ActionTypes.EXECUTE_SQL_CANCEL,
- payload: {}
- }
- },
- updateEditingView (view: IView) {
- return {
- type: ActionTypes.UPDATE_EDITING_VIEW,
- payload: {
- view
- }
- }
- },
- updateEditingViewInfo (viewInfo: IViewInfo) {
- return {
- type: ActionTypes.UPDATE_EDITING_VIEW_INFO,
- payload: {
- viewInfo
- }
- }
- },
- setSqlLimit (limit: number) {
- return {
- type: ActionTypes.SET_SQL_LIMIT,
- payload: {
- limit
- }
- }
- },
- resetViewState () {
- return {
- type: ActionTypes.RESET_VIEW_STATE,
- payload: {}
- }
- },
- /** Actions for fetch external authorization variables values */
- loadDacChannels () {
- return {
- type: ActionTypes.LOAD_DAC_CHANNELS,
- payload: {}
- }
- },
- dacChannelsLoaded (channels: IDacChannel[]) {
- return {
- type: ActionTypes.LOAD_DAC_CHANNELS_SUCCESS,
- payload: {
- channels
- }
- }
- },
- loadDacChannelsFail () {
- return {
- type: ActionTypes.LOAD_DAC_CHANNELS_FAILURE,
- payload: {}
- }
- },
- loadDacTenants (channelName: string) {
- return {
- type: ActionTypes.LOAD_DAC_TENANTS,
- payload: {
- channelName
- }
- }
- },
- dacTenantsLoaded (tenants: IDacTenant[]) {
- return {
- type: ActionTypes.LOAD_DAC_TENANTS_SUCCESS,
- payload: {
- tenants
- }
- }
- },
- loadDacTenantsFail () {
- return {
- type: ActionTypes.LOAD_DAC_TENANTS_FAILURE,
- payload: {}
- }
- },
- loadDacBizs (channelName: string, tenantId: number) {
- return {
- type: ActionTypes.LOAD_DAC_BIZS,
- payload: {
- channelName,
- tenantId
- }
- }
- },
- dacBizsLoaded (bizs: IDacBiz[]) {
- return {
- type: ActionTypes.LOAD_DAC_BIZS_SUCCESS,
- payload: {
- bizs
- }
- }
- },
- loadDacBizsFail () {
- return {
- type: ActionTypes.LOAD_DAC_BIZS_FAILURE,
- payload: {}
- }
- },
- /** */
- /** Actions for external usages */
- loadSelectOptions (
- controlKey: string,
- requestParams: { [viewId: string]: IDistinctValueReqeustParams },
- itemId?: number
- ) {
- return {
- type: ActionTypes.LOAD_SELECT_OPTIONS,
- payload: {
- controlKey,
- requestParams,
- itemId,
- cancelTokenSource: CancelToken.source()
- }
- }
- },
- selectOptionsLoaded (
- controlKey: string,
- values: object[],
- itemId?: number
- ) {
- return {
- type: ActionTypes.LOAD_SELECT_OPTIONS_SUCCESS,
- payload: {
- controlKey,
- values,
- itemId
- }
- }
- },
- loadSelectOptionsFail (err) {
- return {
- type: ActionTypes.LOAD_SELECT_OPTIONS_FAILURE,
- payload: {
- err
- }
- }
- },
- loadViewData (
- id: number,
- requestParams: IDataRequestBody,
- resolve: (data: any[]) => void,
- reject: (error) => void
- ) {
- return {
- type: ActionTypes.LOAD_VIEW_DATA,
- payload: {
- id,
- requestParams,
- resolve,
- reject
- }
- }
- },
- viewDataLoaded () {
- return {
- type: ActionTypes.LOAD_VIEW_DATA_SUCCESS
- }
- },
- loadViewDataFail (err) {
- return {
- type: ActionTypes.LOAD_VIEW_DATA_FAILURE,
- payload: {
- err
- }
- }
- },
- loadColumnDistinctValue(
- paramsByViewId: {
- [viewId: string]: Omit<IDistinctValueReqeustParams, 'cache' | 'expired'>
- },
- callback: (options?: object[]) => void
- ) {
- return {
- type: ActionTypes.LOAD_COLUMN_DISTINCT_VALUE,
- payload: {
- paramsByViewId,
- callback
- }
- }
- },
- loadViewDataFromVizItem (
- renderType: RenderType,
- itemId: number | [number, number],
- viewId: number,
- requestParams: any,
- vizType: 'dashboard' | 'display',
- statistic
- ) {
- return {
- type: ActionTypes.LOAD_VIEW_DATA_FROM_VIZ_ITEM,
- payload: {
- renderType,
- itemId,
- viewId,
- requestParams,
- vizType,
- cancelTokenSource: CancelToken.source()
- },
- statistic
- }
- },
- viewDataFromVizItemLoaded (
- renderType: RenderType,
- itemId: number | [number, number],
- requestParams: any,
- result: IViewQueryResponse,
- vizType: 'dashboard' | 'display',
- statistic
- ) {
- return {
- type: ActionTypes.LOAD_VIEW_DATA_FROM_VIZ_ITEM_SUCCESS,
- payload: {
- renderType,
- itemId,
- requestParams,
- result,
- vizType
- },
- statistic
- }
- },
- loadViewDataFromVizItemFail (
- itemId: number | [number, number],
- vizType: 'dashboard' | 'display',
- errorMessage: string
- ) {
- return {
- type: ActionTypes.LOAD_VIEW_DATA_FROM_VIZ_ITEM_FAILURE,
- payload: {
- itemId,
- vizType,
- errorMessage
- }
- }
- }
- /** */
- }
- const mockAction = returnType(ViewActions)
- export type ViewActionType = typeof mockAction
- export default ViewActions
|