/**
 * Created by Zhong on 2017/8/11.
 * 标准工料机库页面控制器
 */

import BaseController from "../../common/base/base_controller";
import mongoose from 'mongoose';
const compilationModel = mongoose.model('compilation');
const stdGljLibModel = mongoose.model('std_glj_lib_map');
let config = require("../../../config/config.js");
class ViewsController extends BaseController{
    redirectMain(req, res){
        res.render('maintain/std_glj_lib/html/main.html',
        {
            userAccount: req.session.managerData.username
        });
    }
    async redirectGlj(req, res){
        let overWriteUrl = null;
        let stdGljLib = await stdGljLibModel.findOne({ID: req.query.gljLibId, deleted: false});
        if(stdGljLib){
           let compilation = await compilationModel.findOne({_id: mongoose.Types.ObjectId(stdGljLib.compilationId)});
           overWriteUrl = stdGljLib.compilationId === '5b4d581023a924000b760f2d' ? null : compilation.overWriteUrl;
           console.log(overWriteUrl);
        }
        res.render('maintain/std_glj_lib/html/gongliao.html',
        {
            userAccount: req.session.managerData.username,
            LicenseKey:config.getLicenseKey(process.env.NODE_ENV),
            overWriteUrl: overWriteUrl
        });
    }
}

export default ViewsController;
