Esempio n. 1
0
exports.part_create = function(doc, req) {
    var form = req.form;

    if (!form.name || form.name == "") {
        return [null, utils.redirect(req, '/part/new')];
    }

    var doc = {
        type: 'part',
        name: form.name,
        description: form.description,
        locations: {
            penn: (form.penn != "" ? parseInt(form.penn) : 0),
            surface: (form.surface != "" ? parseInt(form.surface) : 0),
            underground: (form.underground != "" ? parseInt(form.underground) : 0)
        }
    };

    db.newUUID(100, function(err, uuid) {
        doc._id = uuid;
    });

    console.log(doc);
    return [doc, utils.redirect(req, '/parts')];
};
Esempio n. 2
0
exports.part = function(doc, req) {
    var form = req.form;

    for (k in form) {
        doc.locations[k] = form[k];
    }

    return [doc, utils.redirect(req, '/parts')];
};
Esempio n. 3
0
exports.fec = function(doc, req) {
    var form = req.form;

    // unless the user is overriding them explicitly, perform some checks
    if (!form.override) {
        var ok = true;
        var reason = ''
        for (var i=0; i<32; i++) {
            var vthr = parseInt(form['vthr_' + i]);

            // vthr must be 3 counts above vthr zero
            var vthr_zero = doc.hw.vthr_zero[i];
            if (!(vthr > vthr_zero + 2)) {
                ok = false;
                reason = 'vthr for channel ' + i + ' not 3 counts above vthr_zero';
            }

            if (vthr < 0 || vthr > 255) {
                ok = false;
                reason = 'vthr for channel ' + i + ' must be between 0 and 255';
            }
        }
        if (!ok) {
            var title = 'Error setting hardware parameters';
            var content = templates.render('fec_edit_error.html', req, {
                id: doc._id,
                reason: reason
            });

            if (!(req.client)) {
                content = templates.render('base.html', req, {
                    content: content,
                    title: title
                });
                return [null, content];
            }

            return [null, {content: content, title: title}];
        }
    }

    for (var i=0; i<32; i++) {
        var vthr = parseInt(form['vthr_' + i]);
        doc.hw.vthr[i] = vthr;
    }

    doc.edited_date = new Date();
    if (form.comment != '') {
        doc.comment.push(form.comment + ' (' + doc.edited_date + ')');
    }

    return [doc, utils.redirect(req, '/fecdoc/'+ doc._id)];
};
Esempio n. 4
0
exports.board_create = function (doc, req) {
    var form = req.form;

    doc = {
        _id: form._id,
        type: 'board',
        board_type: {
            f: 'Front-End Card',
            d: 'Daughterboard',
            e: 'PMTIC',
            t: 'MTC/A+',
            c: 'CTC',
            x: 'XL3'
        }[form._id.substr(0,1)],
        comments: '',
        location: 'unknown',
        location_detail: '',
        status: 'none'
    };

    if (!doc._id || doc._id.length < 2 || !doc.board_type) {
        var title = 'Error creating board';
        var content = templates.render('board_create_error.html', req, {
            type: doc.board_type,
            id: doc._id
        });

        if (!(req.client)) {
            content = templates.render('base.html', req, {
                content: content,
                title: title
            });
            return [null, content];
        }

        return [null, {content: content, title: title}];
    }

    if (doc.board_type == 'Daughterboard') {
        doc.channels = [];
        for (var i=0; i<8; i++) {
            doc.channels.push({
                id: i,
                good: true
            });
        }
    }

    return [doc, utils.redirect(req, '/board/' + doc._id)];
};
Esempio n. 5
0
exports.board = function (doc, req) {
    var form = req.form;

    doc.status = form.status;
    doc.location = form.location;
    doc.location_detail = form.location_detail;
    doc.comments = form.comments;
    if (doc.channels) {
        for (var i=0; i<8; i++) {
            doc.channels[i].good = (('channel' + String(i)) in form);
        }
    }

    return [doc, utils.redirect(req, '/board/'+ doc._id)];
};
Esempio n. 6
0
exports.reconfigure = function(doc, req) {
    var form = req.form;

    var dest = form.dest.split('/').map(function(s) { return parseInt(s); });
    var old_board = form.old_board
    var board = form.new_board;
    var board_type = board.substr(0, 1);

    function InvalidLocation(msg) {
        var e = new Error(msg);
        e.name = 'InvalidLocation';
        return e;
    }

    // loop through the detector, removing references to board
    // assumes that the board can only appear once and that
    // the first letter is a valid indicator of board location
    function removeFromConfiguration(board, d) {
        var board_type = board.substr(0, 1);
        if (board_type == 'c') {
            for (idx in d.crates) {
                if (d.crates[idx].ctc == board) {
                    d.crates[idx].ctc = null;
                    return d; // String(idx);
                }
            }
        }
        else if (board_type == 'x') {
            for (idx in d.crates) {
                if (d.crates[idx].xl3 == board) {
                    d.crates[idx].xl3 = null;
                    return d; //String(idx);
                }
            }
        }
        else if (board_type == 'f') {
            for (idx in d.crates) {
                for (jdx in d.crates[idx].fecs) {
                    if (d.crates[idx].fecs[jdx].id == board) {
                        d.crates[idx].fecs[jdx].id = null;
                        return d; //[idx, jdx].join('/');
                    }
                }
            }
        }
        else if (board_type == 'e') {
            for (idx in d.crates) {
                for (jdx in d.crates[idx].pmtics) {
                    if (d.crates[idx].pmtics[jdx] == board) {
                        d.crates[idx].pmtics[jdx] = null;
                        return d; //[idx, jdx].join('/');
                    }
                }
            }
        }
        else if (board_type == 'd') {
            for (idx in d.crates) {
                for (jdx in d.crates[idx].fecs) {
                    for (kdx in d.crates[idx].fecs[jdx].dbs) {
                        if (d.crates[idx].fecs[jdx].dbs[kdx] == board) {
                            d.crates[idx].fecs[jdx].dbs[kdx] = null;
                            return d; //[idx, jdx, kdx].join('/');
                        }
                    }
                }
            }
        }
        return d;
    };

    var content;
    try {
        doc = removeFromConfiguration(old_board, doc);
        doc = removeFromConfiguration(board, doc);
        if (dest.length == 1) {
            if (board_type == 'c') {
                doc.crates[dest[0]].ctc = board;
            }
            else if (board_type == 'x') {
                doc.crates[dest[0]].xl3 = board;
            }
            else {
                throw InvalidLocation('Invalid board ' + board + ' for location ' + form.dest);
            }
        }
        else if (dest.length == 2) {
            if (board_type == 'f') {
                doc.crates[dest[0]].fecs[dest[1]].id = board;
            }
            else if (board_type == 'e') {
                doc.crates[dest[0]].pmtics[dest[1]] = board;
            }
            else {
                throw InvalidLocation('Invalid board ' + board + ' for location ' + form.dest);
            }
        }
        else if (dest.length == 3) {
            if (board_type == 'd') {
                doc.crates[dest[0]].fecs[dest[1]].dbs[dest[2]] = board;
            }
            else {
                throw InvalidLocation('Invalid board ' + board + ' for location ' + form.dest);
            }
        }
        else {
            throw InvalidLocation('Invalid location ' + form.dest);
        }

        return [doc, utils.redirect(req, '/crate/' + String(dest[0]))];
    }
    catch (e) {
        if (e.name == 'InvalidLocation') {
            var title = 'Error in reconfiguration';
            var content = templates.render('reconfigure_error.html', req, {
                crate_id: dest[0],
                error: e.message
            });

            if (!(req.client)) {
                content = templates.render('base.html', req, {
                    content: content,
                    title: title
                });
                return [null, content];
            }

            return [null, {content: content, title: title}];
        }
        else {
            throw e;
        }
    }
};