/* * @Description: jupyter tpi 相关内容 * @Author: tangjiang * @Github: * @Date: 2019-12-12 09:01:30 * @LastEditors: tangjiang * @LastEditTime: 2019-12-13 23:03:27 */ import types from "./actionTypes"; import { message } from 'antd'; import { fetchJupyterTpiDataSet, fetchJupyterTpiUrl, fetchJupyterInfo, fetchSyncJupyterCode, fetchSaveJupyterTpi } from "../../services/jupyterServer"; // 获取 jupyter 相关信息 export const getJupyterInfo = (id) => { return (dispatch, getState) => { const { jupyter_pagination } = getState().jupyterReducer; console.log(jupyter_pagination); fetchJupyterInfo(id).then(res => { if (res.data.status === 401) return; if (res.status === 200) { const { data } = res; // if (data.status === 0) { dispatch({ type: types.SAVE_JUPYTER_INFO, payload: data }); const { identifier, myshixun_identifier } = data; dispatch(saveJupyterIdentifier(identifier)); // 调用获取数据集接口 dispatch(getJupyterTpiDataSet(identifier, jupyter_pagination)); // 调用获取url接口 dispatch(getJupyterTpiUrl({identifier: myshixun_identifier})); // } } }) } } // 获取 jupyter tpi 数据集 export const getJupyterTpiDataSet = (identifier, params) => { return (dispatch, getState) => { if (!params) { params = getState().jupyterReducer.jupyter_pagination; } fetchJupyterTpiDataSet(identifier, params).then(res => { if (res.data.status === 401) return; // 用户未登录 if (res.status === 200) { const {data_sets, data_sets_count} = res.data; dispatch({ type: types.GET_JUPYTER_DATA_SETS, payload: { data_sets, data_sets_count } }); } }); } } // 获取 jupyter tpi 地址 export const getJupyterTpiUrl = (obj) => { return (dispatch, getState) => { const {jupyter_info} = getState().jupyterReducer; if (!obj.identifier && !jupyter_info.myshixun_identifier) return; const id = obj.identifier || jupyter_info.myshixun_identifier; fetchJupyterTpiUrl({identifier: id}).then(res => { if (res.data.status === 401) return; // 用户未登录 console.log('获取url', res); if (res.status === 200) { const { status, url = '', port } = res.data; dispatch({ type: types.GET_JUPYTER_TPI_URL, payload: { status, url, port } }) } }) } } // 保存 jupyter identifer export const saveJupyterIdentifier = (identifier) => { return { type: types.SAVE_JUPYTER_IDENTIFIER, payload: identifier } } // 重置代码 export const syncJupyterCode = (identifier, msg) => { return (dispatch) => { fetchSyncJupyterCode(identifier).then(res => { // console.log('同步代码成功: ', res); if (res.data.status === 401) return; if (res.status === 200) { const {status} = res.data if (status === 0) { message.success(msg); setTimeout(() => { window.location.reload(); }, 300); } } }) } } // 改变状态值 export const changeGetJupyterUrlState = (status) => { return { type: types.CHANGE_JUPYTER_URL_STATE, payload: status } } // 保存 jupyter tpi export const saveJupyterTpi = () => { return (dispatch, getState) => { const { jupyter_tpi_code, jupyter_info }= getState().jupyterReducer; // console.log(jupyter_info.myshixun_identifier, jupyter_tpi_code); if (!jupyter_info.myshixun_identifier) return; const params = { identifier: jupyter_info.myshixun_identifier, jupyter_port: jupyter_tpi_code }; console.log(params); fetchSaveJupyterTpi(params).then(res => { dispatch({ type: types.LOADING_STATUS, payload: false }); if (res.status === 200) { const { data } = res; if (data.status === 0) { message.success('保存成功!') } } }).catch(() => { dispatch({ type: types.LOADING_STATUS, payload: false }); }); } } // 改变当前页数 export const changeCurrentPage = (current) => { return { type: types.CHANGE_JUPYTER_CURRENT_PAGE, payload: current } }