2017-08-07 19:34:34 +08:00
|
|
|
import axios from 'axios';
|
|
|
|
import variable from '../../constants/variable';
|
2017-07-18 10:56:03 +08:00
|
|
|
|
2017-08-07 19:34:34 +08:00
|
|
|
// Actions
|
|
|
|
const FETCH_PROJECT_LIST = 'yapi/project/FETCH_PROJECT_LIST';
|
|
|
|
const PROJECT_ADD = 'yapi/project/PROJECT_ADD';
|
|
|
|
const PROJECT_DEL = 'yapi/project/PROJECT_DEL';
|
|
|
|
const CHANGE_UPDATE_MODAL = 'yapi/project/CHANGE_UPDATE_MODAL';
|
|
|
|
const CHANGE_TABLE_LOADING = 'yapi/project/CHANGE_TABLE_LOADING';
|
|
|
|
const PROJECT_UPDATE = 'yapi/project/PROJECT_UPDATE';
|
2017-08-11 17:24:50 +08:00
|
|
|
const GET_CUR_PROJECT = 'yapi/project/GET_CUR_PROJECT'
|
2017-08-07 19:34:34 +08:00
|
|
|
|
|
|
|
// Reducer
|
2017-07-18 10:56:03 +08:00
|
|
|
const initialState = {
|
2017-07-19 20:59:59 +08:00
|
|
|
isUpdateModalShow: false,
|
|
|
|
handleUpdateIndex: -1,
|
2017-07-18 22:08:01 +08:00
|
|
|
projectList: [],
|
2017-07-20 17:08:29 +08:00
|
|
|
userInfo: {},
|
2017-07-19 21:21:40 +08:00
|
|
|
tableLoading: true,
|
2017-07-19 22:31:18 +08:00
|
|
|
total: 0,
|
2017-08-10 18:54:32 +08:00
|
|
|
currPage: 1,
|
|
|
|
curProject: {}
|
2017-07-18 10:56:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default (state = initialState, action) => {
|
|
|
|
switch (action.type) {
|
2017-08-11 17:24:50 +08:00
|
|
|
case GET_CUR_PROJECT: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
curProject: action.payload.data
|
|
|
|
}
|
|
|
|
}
|
2017-07-19 21:21:40 +08:00
|
|
|
case CHANGE_UPDATE_MODAL: {
|
2017-07-19 20:59:59 +08:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
isUpdateModalShow: action.payload.data,
|
|
|
|
handleUpdateIndex: action.payload.index
|
|
|
|
};
|
|
|
|
}
|
2017-07-19 21:21:40 +08:00
|
|
|
case CHANGE_TABLE_LOADING: {
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
tableLoading: action.payload
|
|
|
|
}
|
|
|
|
}
|
2017-07-18 17:46:09 +08:00
|
|
|
case FETCH_PROJECT_LIST: {
|
|
|
|
return {
|
|
|
|
...state,
|
2017-07-18 21:11:32 +08:00
|
|
|
projectList: action.payload.data.data.list,
|
2017-07-20 17:08:29 +08:00
|
|
|
total: action.payload.data.data.total,
|
|
|
|
userInfo: action.payload.data.data.userinfo
|
2017-07-18 17:46:09 +08:00
|
|
|
};
|
|
|
|
}
|
2017-07-18 10:56:03 +08:00
|
|
|
case PROJECT_ADD: {
|
|
|
|
return state;
|
|
|
|
}
|
2017-07-18 22:08:01 +08:00
|
|
|
case PROJECT_DEL: {
|
|
|
|
return state;
|
|
|
|
}
|
2017-07-18 10:56:03 +08:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
2017-08-07 19:34:34 +08:00
|
|
|
|
|
|
|
// Action Creators
|
|
|
|
export function fetchProjectList(id, pageNum) {
|
|
|
|
return {
|
|
|
|
type: FETCH_PROJECT_LIST,
|
2017-08-11 10:25:19 +08:00
|
|
|
payload: axios.get('/api/project/list', {
|
2017-08-07 19:34:34 +08:00
|
|
|
params: {
|
|
|
|
group_id: id,
|
|
|
|
page: pageNum || 1,
|
|
|
|
limit: variable.PAGE_LIMIT
|
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function changeUpdateModal(data, index) {
|
|
|
|
return {
|
|
|
|
type: CHANGE_UPDATE_MODAL,
|
|
|
|
payload: { data, index }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function changeTableLoading(data) {
|
|
|
|
return {
|
|
|
|
type: CHANGE_TABLE_LOADING,
|
|
|
|
payload: data
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function addProject(data) {
|
|
|
|
const { name, prd_host, basepath, desc, group_id, protocol } = data;
|
|
|
|
const param = {
|
|
|
|
name,
|
|
|
|
prd_host,
|
|
|
|
protocol,
|
|
|
|
basepath,
|
|
|
|
desc,
|
|
|
|
group_id
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
type: PROJECT_ADD,
|
2017-08-11 10:25:19 +08:00
|
|
|
payload: axios.post('/api/project/add', param)
|
2017-08-07 19:34:34 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function updateProject(data) {
|
|
|
|
const { name, prd_host, basepath, desc, _id, protocol, env } = data;
|
|
|
|
const param = {
|
|
|
|
name,
|
|
|
|
prd_host,
|
|
|
|
protocol,
|
|
|
|
basepath,
|
|
|
|
desc,
|
|
|
|
id: _id,
|
|
|
|
env
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
type: PROJECT_UPDATE,
|
2017-08-11 10:25:19 +08:00
|
|
|
payload: axios.post('/api/project/up', param)
|
2017-08-07 19:34:34 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function delProject(id) {
|
|
|
|
const param = { id };
|
|
|
|
return {
|
|
|
|
type: PROJECT_DEL,
|
2017-08-11 10:25:19 +08:00
|
|
|
payload: axios.post('/api/project/del', param)
|
2017-08-07 19:34:34 +08:00
|
|
|
};
|
|
|
|
}
|
2017-08-11 17:24:50 +08:00
|
|
|
|
|
|
|
export function getProject(id){
|
|
|
|
|
|
|
|
return async (dispatch) => {
|
|
|
|
let result = await axios.get('/api/project/get?id=' + id);
|
|
|
|
dispatch({
|
|
|
|
type: GET_CUR_PROJECT,
|
|
|
|
payload: result.data
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|