import dva from 'dva'
import undoable, { includeAction } from 'redux-undo'
import indexRouter from './routes/router'
import mainModel from './models/main'
import chartDesigner from './models/chartDesigner'
import dataSource from './models/dataSource'
import dataConnect from './models/dataConnect'
import dashboard from './models/dashboard'
import chart from './models/chart'
import dashboardDesigner from './models/dashboardDesigner';
import userGroup from './models/userGroup'
import user from './models/user'
import chartPolicy from './models/chartPolicy'
import dataSourcePolicy from './models/dataSourcePolicy'
import dashboardPolicy from './models/dashboardPolicy'
import './utils/baseUtils'
import './index.less'
import createLoading from 'dva-loading';

// 1. Initialize
const app = dva({
    onReducer: reducer => (state, action) => {
        const newState = undoable(reducer, {
            limit: 10,
            filter: includeAction(['chartDesigner/setField', 'chartDesigner/setFields']), // 只对图表编辑界面的部分action生效
        })(state, action);
        return { ...newState };
    },
});

// 2. Plugins
app.use(createLoading());

// 3. Model
app.model(mainModel); // 通用action
app.model(dataConnect); // 数据连接
app.model(dataSource); // 数据源
app.model(chart);  // 图表
app.model(chartDesigner); // 图表设计
app.model(dashboard);  //报告与看板
app.model(dashboardDesigner); // 看板设计
app.model(userGroup); // 用户组
app.model(user); // 用户
app.model(chartPolicy); // 图表策略
app.model(dataSourcePolicy); // 数据源策略
app.model(dashboardPolicy); // 看板策略

// 4. Router
app.router(indexRouter);

// 5. Start
app.start('#root');
