<commit_before>/*jslint forin:true sub:true anon:true, sloppy:true, stupid:true nomen:true, node:true continue:true*/

/*
 * Copyright (c) 2012, Yahoo! Inc. All rights reserved.
 * Copyrights licensed under the New BSD License.
 * See the accompanying LICENSE file for terms.
 */
var log4js = require("log4js");
var SessionFactory = require("./sessionfactory");
var ReportManager = require("../util/reportmanager");
var FileUtil = require("../util/fileutil");
var WdSession = require("../session/wdsession");
var TestSession = require("../session/testsession");
var ProxyManager = require("../proxy/proxymanager");
var clone = require('clone');
var path = require("path");
var os = require("os");
var fs = require("fs");
var async = require("async");

var sf;
var testExecutor;
var curSessionCount;
var totalSessionCount;
var wdSessions;
var parallelCount;
var tests;
var testQueues;

function TestExecutor(sessionFactory) {

    sf = sessionFactory;

    this.logger = log4js.getLogger("TestExecutor");
    testExecutor = this;
    tests = [];
    wdSessions = [];
    testQueues = [];
    curSessionCount = 0;
    totalSessionCount = 0;
    parallelCount = 0;

}

TestExecutor.prototype.writeReportForDescriptor = function(testSession, callback) {

    var descriptor,
        testSessionsArr,
        currTime,
        reportObj,
        reportManager;

    for (descriptor in sf.descriptorMap) {

        if (descriptor === testSession.descriptorPath) {

            // Store testSessions array for each descriptor in testSessionMap
            if (sf.testSessionMap[descriptor]) {
                testSessionsArr = sf.testSessionMap[descriptor];
            } else {
                testSessionsArr = [];
            }
            testSessionsArr.push(testSession);

            sf.testSessionMap[descriptor] = testSessionsArr;

            sf.descriptorMap[descriptor] = sf.descriptorMap[descriptor] - 1;

            if (sf.descriptorMap[descriptor] === 0) {

                sf.timeReportObj[testSession.descriptorPath].endTime = Date.now(); // TODO Is endTime required ???
                sf.timeReportObj[testSession.descriptorPath].timeTaken =
                    ((sf.timeReportObj[testSession.descriptorPath].endTime - sf.timeReportObj[testSession.descriptorPath].startTime) / 1000).toFixed(2);

                testExecutor.logger.info('Time taken to run descriptor-' + testSession.descriptorPath + ' = ' + sf.timeReportObj[testSession.descriptorPath].timeTaken);

                testExecutor.logger.info('All tests over for descriptor:' + testSession.descriptorPath);
                reportObj = {
                    "reportFolder" : global.reportFolder,
                    "arrTestSessions" : sf.testSessionMap[descriptor],
                    "descriptor" : testSession.descriptorPath,
                    "reuseSession" : sf.reuseSession,
                    "testSuiteName" : sf.testSuiteName,
                    "driver" : sf.driver,
                    "browser" : sf.browser,
                    "group" : sf.args.group,
                    "testName" : sf.args.testName

                };
                reportManager = new ReportManager(reportObj);
                reportManager.totalTimeTaken = sf.timeReportObj[testSession.descriptorPath].timeTaken;
                reportManager.writeReports();

            }

        }
    }
    callback();
};

TestExecutor.prototype.startProxy = function(routerConfigPath, callback) {

    //TODO - move this to index.js
    if (os.type() === "Darwin") {
        global.hostname = "localhost";
    } else {
        global.hostname = os.hostname();
    }

    testExecutor.logger.info('Starting proxy server : ' + routerConfigPath);

    var proxyManager = new ProxyManager(path.resolve(global.workingDirectory, routerConfigPath));

    proxyManager.runRouterProxy(sf.config.minPort, sf.config.maxPort, global.hostname, function(proxyHost) {

        if (proxyHost) {
            if (proxyHost.indexOf("Error") === -1) {
                testExecutor.logger.info("Running Proxy Server at " + proxyHost + ' for :::' + routerConfigPath);
                global.routerMap[routerConfigPath] = proxyHost;
            } else {
                testExecutor.logger.info("Unable to Start Proxy, " + proxyHost);
                testExecutor.logger.info("Running Tests Without Proxy! ");
            }
        } else {
            testExecutor.logger.info("Some error while starting proxy");
            //TODO - What message to show here??
        }

    });

    setTimeout(callback, 500);

};

TestExecutor.prototype.runNextTest = function(testQueue) {

    var testSession,
        testSessionTimeArr = [];

    if (testQueue.curIndex === testQueue.sessions.length) {
        return; // all done with this queue
    }

    testSession = testQueue.sessions[testQueue.curIndex];
    testQueue.curIndex += 1;

    // If first test session is starting for the descriptor, note start time
    if (!sf.timeReportObj[testSession.descriptorPath]) {
        sf.timeReportObj[testSession.descriptorPath] = [];
        sf.timeReportObj[testSession.descriptorPath].startTime = Date.now();
    }

    testSession.runTest(function (error) {

        if (error) {
            var obj = {};
            obj.error = error;
            testSession.driver.reports.addReport(obj);
            testExecutor.logger.debug("Error : " + error);
        }

        testExecutor.logger.trace("Run Test :" + curSessionCount + "==" + totalSessionCount);
        testSession.endTime = Date.now();

        // Write report per descriptor ( if all testsessions for the descriptor ( to which the current test session belongs ) are run )

        if (sf.timeReportObj[testSession.descriptorPath].testSessionTimeArr) {
            testSessionTimeArr = sf.timeReportObj[testSession.descriptorPath].testSessionTimeArr;
        } else {
            testSessionTimeArr = {};
        }

        testSessionTimeArr[testSession.args.testName] = {};

        testSessionTimeArr[testSession.args.testName].timeTaken = ((testSession.endTime - testSession.startTime) / 1000).toFixed(2);
        sf.timeReportObj[testSession.descriptorPath].testSessionTimeArr = testSessionTimeArr;

        testExecutor.logger.info('Time taken to run - ' + testSession.args.testName + ' is::' +
            testSessionTimeArr[testSession.args.testName].timeTaken);

        testExecutor.writeReportForDescriptor(testSession, function() {

            curSessionCount += 1;
            if (curSessionCount === totalSessionCount) {
                testExecutor.logger.trace("Done with all the sessions");
                sf.tearDown(testQueue, wdSessions);
            } else {
                testExecutor.logger.trace("Calling Next Test : " + curSessionCount);
                testExecutor.runNextTest(testQueue);
            }
        });

    });
};

TestExecutor.prototype.runTests = function(testQueues, parallelCount) {

    var i, j;
    for (i = 0; i < testQueues.length; i += 1) {
        // start running as many sessions as we can in parallel as specified
        for (j = 0; j < parallelCount; j += 1) {
            testExecutor.runNextTest(testQueues[i]);
        }
    }

};

TestExecutor.prototype.setupTestQueues = function(callback) {

    var test,
        browsers,
        i,
        j;

    // there may be more than one independent queue that can always run in parallel
    if (wdSessions.length > 0) {
        parallelCount = 1; // when reusing sessions, items in a single queue cannot run in parallel

        // every wd session gets its own queue
        for (i = 0; i < wdSessions.length; i += 1) {
            testQueues[i] = {curIndex: 0, sessions: []};
            for (j = 0; j < tests.length; j += 1) {
                test = clone(tests[j]);

                // If proxy set to true , ignore reuseSession
                if (test.startProxyServer === true) {
                    testQueues[i].sessions.push(new TestSession(sf.config, test));
                } else {
                    testQueues[i].sessions.push(new TestSession(sf.config, test, wdSessions[i]));
                }

            }
            totalSessionCount += tests.length;
        }
    } else {
        // when not reusing sessions, a single queue contains all the items
        // parallelism is controlled by the "parallel" argument passed by the user
        testQueues[0] = {curIndex: 0, sessions: []};
        for (i = 0; i < tests.length; i += 1) {
            browsers = sf.getBrowsers(tests[i]);
            for (j = 0; j < browsers.length; j += 1) {
                test = clone(tests[i]);
                test.browser = browsers[j];
                testQueues[0].sessions.push(new TestSession(sf.config, test));
            }
            totalSessionCount += browsers.length;
        }
    }
    testExecutor.logger.info("Total test sessions: " + totalSessionCount);
    callback();

};

TestExecutor.prototype.getTests = function(callback) {

    var testParams,
        test,
        i;

    if (sf.arrDescriptor) {

        tests = sf.getFactoryTests();

        if (tests.length === 0) {
            sf.tearDown({}, null);
        }
    } else if (sf.tests) {
        for (i = 0; i < sf.tests.length; i += 1) {
            testParams = clone(sf.args);
            testParams.test = sf.tests[i];
            // convert the cmd line test to look like a descriptor test
            test = {
                config : {},
                params : testParams,
                testName : "Default",
                driver : sf.args.driver,
                controller : sf.args.controller,
                browser : sf.browser
            };
            tests.push(test);
        }
    } else {
        // convert the cmd line test to look like a descriptor test
        test = {
            config: {},
            params : sf.args,
            testName : "Default",
            driver : sf.args.driver,
            controller : sf.args.controller,
            browser : sf.browser
        };
        test.params.lib = sf.args.lib;
        tests.push(test);
    }

    callback();

};

TestExecutor.prototype.populateRouterProxyConfigList = function(callback) {

    var i,
        proxyConfig;

    // Get how many unique proxy servers we need to start
    for (i = 0; i < tests.length; i += 1) {

        if (tests[i].startProxyServer === false) {
            continue;
        }

        // If test has routerProxyConfig
        if (tests[i].routerProxyConfig) {

            proxyConfig = tests[i].routerProxyConfig;

            if (tests[i].relativePath) {
                proxyConfig = path.resolve(global.workingDirectory, tests[i].relativePath, proxyConfig);
            } else {
                proxyConfig = path.resolve(global.workingDirectory, proxyConfig);
            }

        } else if (sf.args.routerProxyConfig) { // If routerProxyConfig is passed as an argument
            proxyConfig = path.resolve(global.workingDirectory, sf.args.routerProxyConfig);
        }

        if (proxyConfig) {

            tests[i].resolvedRouterConfigPath = proxyConfig;
            // Add routerConfig to the list ,if not already added
            if (sf.routerConfigList.indexOf(proxyConfig) === -1) {
                sf.routerConfigList.push(proxyConfig);
            }
        }
    }
    callback();

};

TestExecutor.prototype.setupProxy = function(callback) {

    // If set from command line
    if (sf.args.startProxyServer === true || sf.args.startProxyServer === undefined) {

        testExecutor.populateRouterProxyConfigList(function () {

            if (sf.routerConfigList && sf.routerConfigList.length > 0) {

                testExecutor.logger.info('Number of Proxy servers needed to start:' + sf.routerConfigList.length);

                async.eachSeries(sf.routerConfigList, testExecutor.startProxy, function(err) {

                    if (err) {
                        testExecutor.logger.info('ERROR !! Failed to start proxy servers..');
                    } else {
                        testExecutor.logger.info('Started all proxy servers..Now running tests\n\n');
                    }
                    callback();

                });

            } else {
                callback();
            }
        });

    } else {
        callback();
    }

};

TestExecutor.prototype.startTest = function() {

    testExecutor.getTests(function() {
        parallelCount = parseInt(sf.parallel, 10);
        if (isNaN(parallelCount) || (parallelCount <= 0)) {
            parallelCount = 1;
        }
        testExecutor.cleanupReports(function() {
            testExecutor.setupProxy(function() {
                testExecutor.setupTestQueues(function() {
                    testExecutor.runTests(testQueues, parallelCount);
                });
            });

        });

    });

};

//TODO cleanup , move this to a proper class ???
TestExecutor.prototype.deleteReport = function(descriptorFile, callback) {

    var descFile = path.basename(descriptorFile, '.json'),
        xmlReport = path.resolve(global.reportFolder, 'arrow-report', descFile + "-report.xml"),
        jsonReport = path.resolve(global.reportFolder, 'arrow-report', descFile + "-report.json"),
        fileUtil = new FileUtil();

    try {

        fileUtil.deleteFile(xmlReport, function() {
            fileUtil.deleteFile(jsonReport, function() {
                callback();
            });
        });

    } catch (e) {
        console.log(e);
        callback();
    }
};

TestExecutor.prototype.cleanupReports = function(callback) {

    if (sf.arrDescriptor) {

        async.eachSeries(sf.arrDescriptor, testExecutor.deleteReport, function(err) {
            if (err) {
                testExecutor.logger.info('ERROR !! Failed to cleanup reports..');
            } else {
                testExecutor.logger.info('Cleaned up all reports\n\n');
            }
            callback();

        });

    } else {
        callback();
    }

};

TestExecutor.prototype.executeTests = function () {
    var hub;

    // get all wd sessions if applicable (based on reuseSession flag)
    if (sf.reuseSession) {
        hub = new WdSession(sf.config);
        hub.getSessions(sf, function (error, sf, arrSessions) {
            if (error) {
                // logger.error('No sessions found..'); TODO  search for this msg
                process.exit(1);
            }
            wdSessions = arrSessions;
            testExecutor.startTest();
        });
    } else {
        testExecutor.startTest();
    }

};

module.exports = TestExecutor;<commit_msg>Adding blank proxy<commit_after>/*jslint forin:true sub:true anon:true, sloppy:true, stupid:true nomen:true, node:true continue:true*/

/*
 * Copyright (c) 2012, Yahoo! Inc. All rights reserved.
 * Copyrights licensed under the New BSD License.
 * See the accompanying LICENSE file for terms.
 */
var log4js = require("log4js");
var SessionFactory = require("./sessionfactory");
var ReportManager = require("../util/reportmanager");
var FileUtil = require("../util/fileutil");
var WdSession = require("../session/wdsession");
var TestSession = require("../session/testsession");
var ProxyManager = require("../proxy/proxymanager");
var clone = require('clone');
var path = require("path");
var os = require("os");
var fs = require("fs");
var async = require("async");

var sf;
var testExecutor;
var curSessionCount;
var totalSessionCount;
var wdSessions;
var parallelCount;
var tests;
var testQueues;

function TestExecutor(sessionFactory) {

    sf = sessionFactory;

    this.logger = log4js.getLogger("TestExecutor");
    testExecutor = this;
    tests = [];
    wdSessions = [];
    testQueues = [];
    curSessionCount = 0;
    totalSessionCount = 0;
    parallelCount = 0;

}

TestExecutor.prototype.writeReportForDescriptor = function(testSession, callback) {

    var descriptor,
        testSessionsArr,
        currTime,
        reportObj,
        reportManager;

    for (descriptor in sf.descriptorMap) {

        if (descriptor === testSession.descriptorPath) {

            // Store testSessions array for each descriptor in testSessionMap
            if (sf.testSessionMap[descriptor]) {
                testSessionsArr = sf.testSessionMap[descriptor];
            } else {
                testSessionsArr = [];
            }
            testSessionsArr.push(testSession);

            sf.testSessionMap[descriptor] = testSessionsArr;

            sf.descriptorMap[descriptor] = sf.descriptorMap[descriptor] - 1;

            if (sf.descriptorMap[descriptor] === 0) {

                sf.timeReportObj[testSession.descriptorPath].endTime = Date.now(); // TODO Is endTime required ???
                sf.timeReportObj[testSession.descriptorPath].timeTaken =
                    ((sf.timeReportObj[testSession.descriptorPath].endTime - sf.timeReportObj[testSession.descriptorPath].startTime) / 1000).toFixed(2);

                testExecutor.logger.info('Time taken to run descriptor-' + testSession.descriptorPath + ' = ' + sf.timeReportObj[testSession.descriptorPath].timeTaken);

                testExecutor.logger.info('All tests over for descriptor:' + testSession.descriptorPath);
                reportObj = {
                    "reportFolder" : global.reportFolder,
                    "arrTestSessions" : sf.testSessionMap[descriptor],
                    "descriptor" : testSession.descriptorPath,
                    "reuseSession" : sf.reuseSession,
                    "testSuiteName" : sf.testSuiteName,
                    "driver" : sf.driver,
                    "browser" : sf.browser,
                    "group" : sf.args.group,
                    "testName" : sf.args.testName

                };
                reportManager = new ReportManager(reportObj);
                reportManager.totalTimeTaken = sf.timeReportObj[testSession.descriptorPath].timeTaken;
                reportManager.writeReports();

            }

        }
    }
    callback();
};

TestExecutor.prototype.startProxy = function(routerConfigPath, callback) {

    //TODO - move this to index.js
    if (os.type() === "Darwin") {
        global.hostname = "localhost";
    } else {
        global.hostname = os.hostname();
    }

    testExecutor.logger.info('Starting proxy server : ' + routerConfigPath);

    var proxyManager = new ProxyManager(path.resolve(global.workingDirectory, routerConfigPath));

    proxyManager.runRouterProxy(sf.config.minPort, sf.config.maxPort, global.hostname, function(proxyHost) {

        if (proxyHost) {
            if (proxyHost.indexOf("Error") === -1) {
                testExecutor.logger.info("Running Proxy Server at " + proxyHost + ' for :::' + routerConfigPath);
                global.routerMap[routerConfigPath] = proxyHost;
            } else {
                testExecutor.logger.info("Unable to Start Proxy, " + proxyHost);
                testExecutor.logger.info("Running Tests Without Proxy! ");
            }
        } else {
            testExecutor.logger.info("Some error while starting proxy");
            //TODO - What message to show here??
        }

    });

    setTimeout(callback, 500);

};

TestExecutor.prototype.runNextTest = function(testQueue) {

    var testSession,
        testSessionTimeArr = [];

    if (testQueue.curIndex === testQueue.sessions.length) {
        return; // all done with this queue
    }

    testSession = testQueue.sessions[testQueue.curIndex];
    testQueue.curIndex += 1;

    // If first test session is starting for the descriptor, note start time
    if (!sf.timeReportObj[testSession.descriptorPath]) {
        sf.timeReportObj[testSession.descriptorPath] = [];
        sf.timeReportObj[testSession.descriptorPath].startTime = Date.now();
    }

    testSession.runTest(function (error) {

        if (error) {
            var obj = {};
            obj.error = error;
            testSession.driver.reports.addReport(obj);
            testExecutor.logger.debug("Error : " + error);
        }

        testExecutor.logger.trace("Run Test :" + curSessionCount + "==" + totalSessionCount);
        testSession.endTime = Date.now();

        // Write report per descriptor ( if all testsessions for the descriptor ( to which the current test session belongs ) are run )

        if (sf.timeReportObj[testSession.descriptorPath].testSessionTimeArr) {
            testSessionTimeArr = sf.timeReportObj[testSession.descriptorPath].testSessionTimeArr;
        } else {
            testSessionTimeArr = {};
        }

        testSessionTimeArr[testSession.args.testName] = {};

        testSessionTimeArr[testSession.args.testName].timeTaken = ((testSession.endTime - testSession.startTime) / 1000).toFixed(2);
        sf.timeReportObj[testSession.descriptorPath].testSessionTimeArr = testSessionTimeArr;

        testExecutor.logger.info('Time taken to run - ' + testSession.args.testName + ' is::' +
            testSessionTimeArr[testSession.args.testName].timeTaken);

        testExecutor.writeReportForDescriptor(testSession, function() {

            curSessionCount += 1;
            if (curSessionCount === totalSessionCount) {
                testExecutor.logger.trace("Done with all the sessions");
                sf.tearDown(testQueue, wdSessions);
            } else {
                testExecutor.logger.trace("Calling Next Test : " + curSessionCount);
                testExecutor.runNextTest(testQueue);
            }
        });

    });
};

TestExecutor.prototype.runTests = function(testQueues, parallelCount) {

    var i, j;
    for (i = 0; i < testQueues.length; i += 1) {
        // start running as many sessions as we can in parallel as specified
        for (j = 0; j < parallelCount; j += 1) {
            testExecutor.runNextTest(testQueues[i]);
        }
    }

};

TestExecutor.prototype.setupTestQueues = function(callback) {

    var test,
        browsers,
        i,
        j;

    // there may be more than one independent queue that can always run in parallel
    if (wdSessions.length > 0) {
        parallelCount = 1; // when reusing sessions, items in a single queue cannot run in parallel

        // every wd session gets its own queue
        for (i = 0; i < wdSessions.length; i += 1) {
            testQueues[i] = {curIndex: 0, sessions: []};
            for (j = 0; j < tests.length; j += 1) {
                test = clone(tests[j]);

                // If proxy set to true , ignore reuseSession
                if (test.startProxyServer === true) {
                    testQueues[i].sessions.push(new TestSession(sf.config, test));
                } else {
                    testQueues[i].sessions.push(new TestSession(sf.config, test, wdSessions[i]));
                }

            }
            totalSessionCount += tests.length;
        }
    } else {
        // when not reusing sessions, a single queue contains all the items
        // parallelism is controlled by the "parallel" argument passed by the user
        testQueues[0] = {curIndex: 0, sessions: []};
        for (i = 0; i < tests.length; i += 1) {
            browsers = sf.getBrowsers(tests[i]);
            for (j = 0; j < browsers.length; j += 1) {
                test = clone(tests[i]);
                test.browser = browsers[j];
                testQueues[0].sessions.push(new TestSession(sf.config, test));
            }
            totalSessionCount += browsers.length;
        }
    }
    testExecutor.logger.info("Total test sessions: " + totalSessionCount);
    callback();

};

TestExecutor.prototype.getTests = function(callback) {

    var testParams,
        test,
        i;

    if (sf.arrDescriptor) {

        tests = sf.getFactoryTests();

        if (tests.length === 0) {
            sf.tearDown({}, null);
        }
    } else if (sf.tests) {
        for (i = 0; i < sf.tests.length; i += 1) {
            testParams = clone(sf.args);
            testParams.test = sf.tests[i];
            // convert the cmd line test to look like a descriptor test
            test = {
                config : {},
                params : testParams,
                testName : "Default",
                driver : sf.args.driver,
                controller : sf.args.controller,
                browser : sf.browser
            };
            tests.push(test);
        }
    } else {
        // convert the cmd line test to look like a descriptor test
        test = {
            config: {},
            params : sf.args,
            testName : "Default",
            driver : sf.args.driver,
            controller : sf.args.controller,
            browser : sf.browser
        };
        test.params.lib = sf.args.lib;
        tests.push(test);
    }

    callback();

};

TestExecutor.prototype.populateRouterProxyConfigList = function(callback) {

    var i,
        proxyConfig;

    // Get how many unique proxy servers we need to start
    for (i = 0; i < tests.length; i += 1) {

        if (tests[i].startProxyServer === false) {
            continue;
        }

        // If test has routerProxyConfig
        if (tests[i].routerProxyConfig) {

            proxyConfig = tests[i].routerProxyConfig;

            if (tests[i].relativePath) {
                proxyConfig = path.resolve(global.workingDirectory, tests[i].relativePath, proxyConfig);
            } else {
                proxyConfig = path.resolve(global.workingDirectory, proxyConfig);
            }

        } else if (sf.args.routerProxyConfig) { // If routerProxyConfig is passed as an argument
            proxyConfig = path.resolve(global.workingDirectory, sf.args.routerProxyConfig);
        }

        if (proxyConfig) {

            tests[i].resolvedRouterConfigPath = proxyConfig;
            // Add routerConfig to the list ,if not already added
            if (sf.routerConfigList.indexOf(proxyConfig) === -1) {
                sf.routerConfigList.push(proxyConfig);
            }
        } else {
            tests[i].resolvedRouterConfigPath = {};
        }
    }
    callback();

};

TestExecutor.prototype.setupProxy = function(callback) {

    // If set from command line
    if (sf.args.startProxyServer === true || sf.args.startProxyServer === undefined) {

        testExecutor.populateRouterProxyConfigList(function () {

            if (sf.routerConfigList && sf.routerConfigList.length > 0) {

                testExecutor.logger.info('Number of Proxy servers needed to start:' + sf.routerConfigList.length);

                async.eachSeries(sf.routerConfigList, testExecutor.startProxy, function(err) {

                    if (err) {
                        testExecutor.logger.info('ERROR !! Failed to start proxy servers..');
                    } else {
                        testExecutor.logger.info('Started all proxy servers..Now running tests\n\n');
                    }
                    callback();

                });

            } else {
                callback();
            }
        });

    } else {
        callback();
    }

};

TestExecutor.prototype.startTest = function() {

    testExecutor.getTests(function() {
        parallelCount = parseInt(sf.parallel, 10);
        if (isNaN(parallelCount) || (parallelCount <= 0)) {
            parallelCount = 1;
        }
        testExecutor.cleanupReports(function() {
            testExecutor.setupProxy(function() {
                testExecutor.setupTestQueues(function() {
                    testExecutor.runTests(testQueues, parallelCount);
                });
            });

        });

    });

};

//TODO cleanup , move this to a proper class ???
TestExecutor.prototype.deleteReport = function(descriptorFile, callback) {

    var descFile = path.basename(descriptorFile, '.json'),
        xmlReport = path.resolve(global.reportFolder, 'arrow-report', descFile + "-report.xml"),
        jsonReport = path.resolve(global.reportFolder, 'arrow-report', descFile + "-report.json"),
        fileUtil = new FileUtil();

    try {

        fileUtil.deleteFile(xmlReport, function() {
            fileUtil.deleteFile(jsonReport, function() {
                callback();
            });
        });

    } catch (e) {
        console.log(e);
        callback();
    }
};

TestExecutor.prototype.cleanupReports = function(callback) {

    if (sf.arrDescriptor) {

        async.eachSeries(sf.arrDescriptor, testExecutor.deleteReport, function(err) {
            if (err) {
                testExecutor.logger.info('ERROR !! Failed to cleanup reports..');
            } else {
                testExecutor.logger.info('Cleaned up all reports\n\n');
            }
            callback();

        });

    } else {
        callback();
    }

};

TestExecutor.prototype.executeTests = function () {
    var hub;

    // get all wd sessions if applicable (based on reuseSession flag)
    if (sf.reuseSession) {
        hub = new WdSession(sf.config);
        hub.getSessions(sf, function (error, sf, arrSessions) {
            if (error) {
                // logger.error('No sessions found..'); TODO  search for this msg
                process.exit(1);
            }
            wdSessions = arrSessions;
            testExecutor.startTest();
        });
    } else {
        testExecutor.startTest();
    }

};

module.exports = TestExecutor;<|endoftext|>


<commit_before>/**
 * @fileOverview
 * Slides player.
 */
modules.define('shower.Player', [
    'event.Emitter',
    'util.extend'
], function (provide, EventEmitter, extend) {

    /**
     * @class
     * @name shower.Player
     * @param {Shower} shower
     */
    function Player (shower) {
        this.events = new EventEmitter();

        this._shower = shower;
        this._currentSlideNumber = -1;
        this._currentSlide = null;
        this._playerLoop = null;

        this._documentTitle = null;

        this._init();
    }

    extend(Player.prototype, /** @lends shower.Player.prototype */ {
        /**
         * Next slide.
         * @returns {shower.Player}
         */
        next: function () {
            this.events.emmit('next');
            return this;
        },

        /**
         * Prev slide.
         * @returns {shower.Player}
         */
        prev: function () {
            this.events.emmit('prev');
            return this;
        },

        /**
         * @returns {shower.Player}
         */
        first: function () {
            this.setActive(0);
            return this;
        },

        /**
         * @returns {shower.Player}
         */
        last: function () {
            this.setActive(this._shower.getSlidesCount() - 1);
            return this;
        },

        /**
         * Play slideshow.
         * @param {Object} [options] Play options.
         * @param {Number} [options.timeout = 2000]
         * @param {Number} [options.startIndex = 0]
         * @param {Number} [options.stopIndex]
         */
        play: function (options) {
            options = extend({
                timeout: 2000,
                startIndex: 0,
                stopIndex: this._shower.getSlidesCount()
            }, options || {});

            if (this._playerLoop) {
                this.stop();
            }
            this.setActive(options.startIndex);
            this._playerLoop = setInterval(function () {
                var currentSlideNumber = this._currentSlideNumber;
                if (
                    currentSlideNumber == options.stopIndex ||
                    currentSlideNumber < this._shower.getSlidesCount()
                ) {
                    this.stop();
                } else {
                    this.next();
                }
            }.bind(this), options.timeout);

            this.events.emmit('play');
        },

        /**
         * Stop slideshow.
         */
        stop: function () {
            if (this._playerLoop) {
                clearInterval(this._playerLoop);
                this._playerLoop = null;
            }
            this.events.emmit('stop');
        },

        /**
         * @param {Number} index Slide index to activate.
         * @returns {shower.Player}
         */
        setActive: function (index) {
            var slidesCount = this._shower.getSlidesCount(),
                currentSlide = this._currentSlide;

            if (index < slidesCount && index >= 0) {
                if (currentSlide) {
                    currentSlide.setInactive();
                }
                currentSlide = this._shower.get(index);
                currentSlide.setActive();

                this._currentSlide = currentSlide;
                this._currentSlideNumber = index;

                this.events.emmit('activate', {
                    index: index
                });
            }

            return this;
        },

        /**
         * @returns {Slide} Current slide.
         */
        getCurrentSlide: function () {
            return this._currentSlide;
        },

        /**
         * @returns {Number} Current slide index.
         */
        getCurrentSlideIndex: function () {
            return this._currentSlideNumber;
        },

        destroy: function () {
            this._showerContainerListeners.offAll();
            this._playerListeners.offAll();

            this._currentSlide = null;
            this._currentSlideNumber = null;
            this._playerLoop = null;
            this._documentTitle = null;
            this._shower = null;
        },

        /**
         * @ignore
         * Init player state.
         */
        _init: function () {
            this._showerContainerListeners = this._shower.container.events.group()
                .on('fullscreenenter', this._onFullscreenEnter, this)
                .on('fullscreenexit', this._onFullscreenExit, this);

            this._playerListeners = this.events.group()
                .on('prev', this._onPrev, this)
                .on('next', this._onNext, this);

            // get active slide
            // check init data
        },

        _onPrev: function () {
            this._changeSlide(this._currentSlideNumber - 1);
        },

        _onNext: function () {
            this._changeSlide(this._currentSlideNumber + 1);
        },

        /**
         * @ignore
         * @param {Number} index Slide index.
         */
        _changeSlide: function (index) {
            this.setActive(index);
            this.events.emmit('slidechange');
        },

        _onFullscreenEnter: function () {
            var slideTitle = this._currentSlide.getTitle();
            if (slideTitle) {
                this._documentTitle = document.title;
                document.title = slideTitle;
            }
        },

        _onFullscreenExit: function () {
            if (this._documentTitle) {
                document.title = this._documentTitle;
                this._documentTitle = null;
            }
        }
    });

    provide(Player);
});
<commit_msg>[player] + hotkeys, listen slides<commit_after>/**
 * @fileOverview
 * Slides player.
 */
modules.define('shower.Player', [
    'event.Emitter',
    'util.extend'
], function (provide, EventEmitter, extend) {

    /**
     * @class
     * @name shower.Player
     * @param {Shower} shower
     */
    function Player (shower) {
        this.events = new EventEmitter();

        this._shower = shower;
        this._currentSlideNumber = -1;
        this._currentSlide = null;

        this._documentTitle = null;

        this.init();
    }

    extend(Player.prototype, /** @lends shower.Player.prototype */ {

        /**
         * Init player.
         */
        init: function () {
            var shower = this._shower;

            this._showerListeners = shower.events.group()
                .on('slideadd', this._onSlideAdd, this)
                .on('slideremove', this._onSlideRemove, this);

            this._showerContainerListeners = shower.container.events.group()
                .on('slidemodeenter', this._onSlideModeEnter, this)
                .on('slidemodeenter', this._onSlideModeExit, this);

            this._playerListeners = this.events.group()
                .on('prev', this._onPrev, this)
                .on('next', this._onNext, this);

            document.addEventListener('keydown', this._onKeyDown.bind(this));

            // get active slide
            // check init data
        },

        destroy: function () {
            this._showerListeners.offAll();
            this._showerContainerListeners.offAll();
            this._playerListeners.offAll();

            document.addEventListener('keydown', this._onKeyDown.bind(this));

            this._currentSlide = null;
            this._currentSlideNumber = null;
            this._documentTitle = null;
            this._shower = null;
        },

        /**
         * Next slide.
         * @returns {shower.Player}
         */
        next: function () {
            this.events.emmit('next');
            return this;
        },

        /**
         * Prev slide.
         * @returns {shower.Player}
         */
        prev: function () {
            this.events.emmit('prev');
            return this;
        },

        /**
         * @returns {shower.Player}
         */
        first: function () {
            this.go(0);
            return this;
        },

        /**
         * @returns {shower.Player}
         */
        last: function () {
            this.go(this._shower.getSlidesCount() - 1);
            return this;
        },

        /**
         * @param {Number} index Slide index to activate.
         * @returns {shower.Player}
         */
        go: function (index) {
            var slidesCount = this._shower.getSlidesCount(),
                currentSlide = this._currentSlide;

            if (index != this._currentSlideNumber && index < slidesCount && index >= 0) {
                if (currentSlide && currentSlide.isActive()) {
                    currentSlide.deactivate();
                }

                currentSlide = this._shower.get(index);
                if (!currentSlide.isActive()) {
                    currentSlide.activate();
                }

                this._currentSlide = currentSlide;
                this._currentSlideNumber = index;

                this.events.emmit('activate', {
                    index: index
                });
            }

            return this;
        },

        /**
         * @returns {Slide} Current slide.
         */
        getCurrentSlide: function () {
            return this._currentSlide;
        },

        /**
         * @returns {Number} Current slide index.
         */
        getCurrentSlideIndex: function () {
            return this._currentSlideNumber;
        },

        _onPrev: function () {
            this._changeSlide(this._currentSlideNumber - 1);
        },

        _onNext: function () {
            this._changeSlide(this._currentSlideNumber + 1);
        },

        /**
         * @ignore
         * @param {Number} index Slide index.
         */
        _changeSlide: function (index) {
            this.go(index);
            this.events.emmit('slidechange');
        },

        _onSlideModeEnter: function () {
            var slideTitle = this._currentSlide.getTitle();
            if (slideTitle) {
                this._documentTitle = document.title;
                document.title = slideTitle;
            }
        },

        _onSlideModeExit: function () {
            if (this._documentTitle) {
                document.title = this._documentTitle;
                this._documentTitle = null;
            }
        },

        _onSlideAdd: function (e) {
            var slide = e.get('slide');

            slide.events
                .on('activate', this._onSlideActivate, this);
        },

        _onSlideRemove: function (e) {
            var slide = e.get('slide');

            slide.events
                .off('activate', this._onSlideActivate, this);
        },

        _onSlideActivate: function (e) {
            var slide = e.get('slide'),
                slideNumber = this._shower.getSlidesArray().indexOf(slide);

            this.go(slideNumber);
        },

        _onKeyDown: function (e) {
            switch (e.which) {
                case 33: // PgUp
                case 38: // Up
                case 37: // Left
                case 72: // H
                case 75: // K
                    if (e.altKey || e.ctrlKey || e.metaKey) { return; }
                    e.preventDefault();
                    this.prev();
                    break;

                case 34: // PgDown
                case 40: // Down
                case 39: // Right
                case 76: // L
                case 74: // J
                    if (e.altKey || e.ctrlKey || e.metaKey) { return; }
                    e.preventDefault();
                    this.next();
                    break;

                case 36: // Home
                    e.preventDefault();
                    this.first();
                    break;

                case 35: // End
                    e.preventDefault();
                    this.last();
                    break;
            }
        }
    });

    provide(Player);
});
<|endoftext|>


<commit_before>var crypto = require('crypto');

function maskFrame(source, mask, output, offset, length) {
  for (var i = 0; i < length; i++) {
    output[offset + i] = source[i] ^ mask[i & 3];
  }
}

function unmask(buffer, mask) {
  var length = buffer.length;
  for (var i = 0; i < length; i++) {
    buffer[i] ^= mask[i & 3];
  }
}

function frame(data, options) {
  var offset = options.mask ? 6 : 2;
  var payloadLength = data.length;

  if (data.length >= 65536) {
    offset += 8;
    payloadLength = 127;
  } else if (data.length > 125) {
    offset += 2;
    payloadLength = 126;
  }

  var target = new Buffer(data.length + offset);
  target[0] = options.fin ? options.opcode | 0x80 : options.opcode;
  if (options.rsv1) target[0] |= 0x40;

  if (payloadLength === 126) {
    target.writeUInt16BE(data.length, 2, true);
  } else if (payloadLength === 127) {
    target.writeUInt32BE(0, 2, true);
    target.writeUInt32BE(data.length, 6, true);
  }

  if (!options.mask) {
    target[1] = payloadLength;
    data.copy(target, offset);
    return target;
  }

  var mask = crypto.randomBytes(4);
  target[1] = payloadLength | 0x80;
  target[offset - 4] = mask[0];
  target[offset - 3] = mask[1];
  target[offset - 2] = mask[2];
  target[offset - 1] = mask[3];
  maskFrame(data, mask, target, offset, data.length);

  return target;
}

exports.encode = function(data, options) {
  if (!Buffer.isBuffer(data)) {
    data = new Buffer(data + '');
  }
  options = options || {};
  return frame(data, options);
};
<commit_msg>feat: Parse websocket<commit_after>var crypto = require('crypto');

function maskFrame(source, mask, output, offset, length) {
  for (var i = 0; i < length; i++) {
    output[offset + i] = source[i] ^ mask[i & 3];
  }
}

// function unmask(buffer, mask) {
//   var length = buffer.length;
//   for (var i = 0; i < length; i++) {
//     buffer[i] ^= mask[i & 3];
//   }
// }

function frame(data, options) {
  var offset = options.mask ? 6 : 2;
  var payloadLength = data.length;

  if (data.length >= 65536) {
    offset += 8;
    payloadLength = 127;
  } else if (data.length > 125) {
    offset += 2;
    payloadLength = 126;
  }

  var target = new Buffer(data.length + offset);
  target[0] = options.fin ? options.opcode | 0x80 : options.opcode;
  if (options.rsv1) target[0] |= 0x40;

  if (payloadLength === 126) {
    target.writeUInt16BE(data.length, 2, true);
  } else if (payloadLength === 127) {
    target.writeUInt32BE(0, 2, true);
    target.writeUInt32BE(data.length, 6, true);
  }

  if (!options.mask) {
    target[1] = payloadLength;
    data.copy(target, offset);
    return target;
  }

  var mask = crypto.randomBytes(4);
  target[1] = payloadLength | 0x80;
  target[offset - 4] = mask[0];
  target[offset - 3] = mask[1];
  target[offset - 2] = mask[2];
  target[offset - 1] = mask[3];
  maskFrame(data, mask, target, offset, data.length);

  return target;
}

exports.encode = function(data, options) {
  if (!Buffer.isBuffer(data)) {
    data = new Buffer(data + '');
  }
  options = options || {};
  return frame(data, options);
};
<|endoftext|>


<commit_before>import resolve from 'rollup-plugin-node-resolve';

import sourcemaps from 'rollup-plugin-sourcemaps';

const pkg = require('../package.json');

const name = pkg.name.replace(/-([a-z])/g, (g) => {
  return g[1].toUpperCase();
});

const globals = {
  '@angular/animations': 'ng.animations',
  '@angular/common': 'ng.common',
  '@angular/core': 'ng.core',
  '@angular/forms': 'ng.forms',
  '@angular/http': 'ng.http',
  '@angular/router': 'ng.router',

  '@angular/platform-browser': 'ng.platformBrowser',
  '@angular/platform-server': 'ng.platformServer',

  'rxjs/AsyncSubject': 'Rx',
  'rxjs/BehaviorSubject': 'Rx',
  'rxjs/Observable': 'Rx',
  'rxjs/Observer': 'Rx',
  'rxjs/ReplaySubject': 'Rx',
  'rxjs/Scheduler': 'Rx',
  'rxjs/Subject': 'Rx',
  'rxjs/Subscriber': 'Rx',
  'rxjs/Subscription': 'Rx',

  'rxjs/operators': 'Rx.Observable.prototype',

  'rxjs/observable/bindCallback': 'Rx.Observable',
  'rxjs/observable/combineLatest': 'Rx.Observable',
  'rxjs/observable/concat': 'Rx.Observable',
  'rxjs/observable/defer': 'Rx.Observable',
  'rxjs/observable/empty': 'Rx.Observable',
  'rxjs/observable/forkJoin': 'Rx.Observable',
  'rxjs/observable/from': 'Rx.Observable',
  'rxjs/observable/fromEvent': 'Rx.Observable',
  'rxjs/observable/fromEventPattern': 'Rx.Observable',
  'rxjs/observable/fromPromise': 'Rx.Observable',
  'rxjs/observable/generate': 'Rx.Observable',
  'rxjs/observable/if': 'Rx.Observable',
  'rxjs/observable/interval': 'Rx.Observable',
  'rxjs/observable/merge': 'Rx.Observable',
  'rxjs/observable/never': 'Rx.Observable',
  'rxjs/observable/of': 'Rx.Observable',
  'rxjs/observable/onErrorResumeNext': 'Rx.Observable',
  'rxjs/observable/pairs': 'Rx.Observable',
  'rxjs/observable/race': 'Rx.Observable',
  'rxjs/observable/range': 'Rx.Observable',
  'rxjs/observable/throw': 'Rx.Observable',
  'rxjs/observable/timer': 'Rx.Observable',
  'rxjs/observable/using': 'Rx.Observable',
  'rxjs/observable/zip': 'Rx.Observable',

  'rxjs/operator/audit': 'Rx.Observable.prototype',
  'rxjs/operator/auditTime': 'Rx.Observable.prototype',
  'rxjs/operator/buffer': 'Rx.Observable.prototype',
  'rxjs/operator/bufferCount': 'Rx.Observable.prototype',
  'rxjs/operator/bufferTime': 'Rx.Observable.prototype',
  'rxjs/operator/bufferToggle': 'Rx.Observable.prototype',
  'rxjs/operator/bufferWhen': 'Rx.Observable.prototype',
  'rxjs/operator/catch': 'Rx.Observable.prototype',
  'rxjs/operator/combineAll': 'Rx.Observable.prototype',
  'rxjs/operator/combineLatest': 'Rx.Observable.prototype',
  'rxjs/operator/concat': 'Rx.Observable.prototype',
  'rxjs/operator/concatAll': 'Rx.Observable.prototype',
  'rxjs/operator/concatMap': 'Rx.Observable.prototype',
  'rxjs/operator/concatMapTo': 'Rx.Observable.prototype',
  'rxjs/operator/count': 'Rx.Observable.prototype',
  'rxjs/operator/debounce': 'Rx.Observable.prototype',
  'rxjs/operator/debounceTime': 'Rx.Observable.prototype',
  'rxjs/operator/defaultIfEmpty': 'Rx.Observable.prototype',
  'rxjs/operator/delay': 'Rx.Observable.prototype',
  'rxjs/operator/delayWhen': 'Rx.Observable.prototype',
  'rxjs/operator/dematerialize': 'Rx.Observable.prototype',
  'rxjs/operator/distinct': 'Rx.Observable.prototype',
  'rxjs/operator/distinctUntilChanged': 'Rx.Observable.prototype',
  'rxjs/operator/distinctUntilKeyChanged': 'Rx.Observable.prototype',
  'rxjs/operator/do': 'Rx.Observable.prototype',
  'rxjs/operator/elementAt': 'Rx.Observable.prototype',
  'rxjs/operator/every': 'Rx.Observable.prototype',
  'rxjs/operator/exhaust': 'Rx.Observable.prototype',
  'rxjs/operator/exhaustMap': 'Rx.Observable.prototype',
  'rxjs/operator/expand': 'Rx.Observable.prototype',
  'rxjs/operator/filter': 'Rx.Observable.prototype',
  'rxjs/operator/finally': 'Rx.Observable.prototype',
  'rxjs/operator/find': 'Rx.Observable.prototype',
  'rxjs/operator/findIndex': 'Rx.Observable.prototype',
  'rxjs/operator/first': 'Rx.Observable.prototype',
  'rxjs/operator/groupBy': 'Rx.Observable.prototype',
  'rxjs/operator/ignoreElements': 'Rx.Observable.prototype',
  'rxjs/operator/isEmpty': 'Rx.Observable.prototype',
  'rxjs/operator/last': 'Rx.Observable.prototype',
  'rxjs/operator/let': 'Rx.Observable.prototype',
  'rxjs/operator/map': 'Rx.Observable.prototype',
  'rxjs/operator/mapTo': 'Rx.Observable.prototype',
  'rxjs/operator/materialize': 'Rx.Observable.prototype',
  'rxjs/operator/max': 'Rx.Observable.prototype',
  'rxjs/operator/merge': 'Rx.Observable.prototype',
  'rxjs/operator/mergeAll': 'Rx.Observable.prototype',
  'rxjs/operator/mergeMap': 'Rx.Observable.prototype',
  'rxjs/operator/mergeMapTo': 'Rx.Observable.prototype',
  'rxjs/operator/mergeScan': 'Rx.Observable.prototype',
  'rxjs/operator/min': 'Rx.Observable.prototype',
  'rxjs/operator/multicast': 'Rx.Observable.prototype',
  'rxjs/operator/observeOn': 'Rx.Observable.prototype',
  'rxjs/operator/onErrorResumeNext': 'Rx.Observable.prototype',
  'rxjs/operator/pairwise': 'Rx.Observable.prototype',
  'rxjs/operator/partition': 'Rx.Observable.prototype',
  'rxjs/operator/pluck': 'Rx.Observable.prototype',
  'rxjs/operator/publish': 'Rx.Observable.prototype',
  'rxjs/operator/publishBehavior': 'Rx.Observable.prototype',
  'rxjs/operator/publishLast': 'Rx.Observable.prototype',
  'rxjs/operator/publishReplay': 'Rx.Observable.prototype',
  'rxjs/operator/race': 'Rx.Observable.prototype',
  'rxjs/operator/reduce': 'Rx.Observable.prototype',
  'rxjs/operator/repeat': 'Rx.Observable.prototype',
  'rxjs/operator/repeatWhen': 'Rx.Observable.prototype',
  'rxjs/operator/retry': 'Rx.Observable.prototype',
  'rxjs/operator/retryWhen': 'Rx.Observable.prototype',
  'rxjs/operator/sample': 'Rx.Observable.prototype',
  'rxjs/operator/sampleTime': 'Rx.Observable.prototype',
  'rxjs/operator/scan': 'Rx.Observable.prototype',
  'rxjs/operator/sequenceEqual': 'Rx.Observable.prototype',
  'rxjs/operator/share': 'Rx.Observable.prototype',
  'rxjs/operator/shareReplay': 'Rx.Observable.prototype',
  'rxjs/operator/single': 'Rx.Observable.prototype',
  'rxjs/operator/skip': 'Rx.Observable.prototype',
  'rxjs/operator/skipLast': 'Rx.Observable.prototype',
  'rxjs/operator/skipUntil': 'Rx.Observable.prototype',
  'rxjs/operator/skipWhile': 'Rx.Observable.prototype',
  'rxjs/operator/startWith': 'Rx.Observable.prototype',
  'rxjs/operator/subscribeOn': 'Rx.Observable.prototype',
  'rxjs/operator/switch': 'Rx.Observable.prototype',
  'rxjs/operator/switchMap': 'Rx.Observable.prototype',
  'rxjs/operator/switchMapTo': 'Rx.Observable.prototype',
  'rxjs/operator/take': 'Rx.Observable.prototype',
  'rxjs/operator/takeLast': 'Rx.Observable.prototype',
  'rxjs/operator/takeUntil': 'Rx.Observable.prototype',
  'rxjs/operator/takeWhile': 'Rx.Observable.prototype',
  'rxjs/operator/throttle': 'Rx.Observable.prototype',
  'rxjs/operator/throttleTime': 'Rx.Observable.prototype',
  'rxjs/operator/timeInterval': 'Rx.Observable.prototype',
  'rxjs/operator/timeout': 'Rx.Observable.prototype',
  'rxjs/operator/timeoutWith': 'Rx.Observable.prototype',
  'rxjs/operator/timestamp': 'Rx.Observable.prototype',
  'rxjs/operator/toArray': 'Rx.Observable.prototype',
  'rxjs/operator/toPromise': 'Rx.Observable.prototype',
  'rxjs/operator/window': 'Rx.Observable.prototype',
  'rxjs/operator/windowCount': 'Rx.Observable.prototype',
  'rxjs/operator/windowTime': 'Rx.Observable.prototype',
  'rxjs/operator/windowToggle': 'Rx.Observable.prototype',
  'rxjs/operator/windowWhen': 'Rx.Observable.prototype',
  'rxjs/operator/withLatestFrom': 'Rx.Observable.prototype',
  'rxjs/operator/zip': 'Rx.Observable.prototype',
  'rxjs/operator/zipAll': 'Rx.Observable.prototype',

  'rxjs/operators/audit': 'Rx.Observable.prototype',
  'rxjs/operators/auditTime': 'Rx.Observable.prototype',
  'rxjs/operators/buffer': 'Rx.Observable.prototype',
  'rxjs/operators/bufferCount': 'Rx.Observable.prototype',
  'rxjs/operators/bufferTime': 'Rx.Observable.prototype',
  'rxjs/operators/bufferToggle': 'Rx.Observable.prototype',
  'rxjs/operators/bufferWhen': 'Rx.Observable.prototype',
  'rxjs/operators/catch': 'Rx.Observable.prototype',
  'rxjs/operators/combineAll': 'Rx.Observable.prototype',
  'rxjs/operators/combineLatest': 'Rx.Observable.prototype',
  'rxjs/operators/concat': 'Rx.Observable.prototype',
  'rxjs/operators/concatAll': 'Rx.Observable.prototype',
  'rxjs/operators/concatMap': 'Rx.Observable.prototype',
  'rxjs/operators/concatMapTo': 'Rx.Observable.prototype',
  'rxjs/operators/count': 'Rx.Observable.prototype',
  'rxjs/operators/debounce': 'Rx.Observable.prototype',
  'rxjs/operators/debounceTime': 'Rx.Observable.prototype',
  'rxjs/operators/defaultIfEmpty': 'Rx.Observable.prototype',
  'rxjs/operators/delay': 'Rx.Observable.prototype',
  'rxjs/operators/delayWhen': 'Rx.Observable.prototype',
  'rxjs/operators/dematerialize': 'Rx.Observable.prototype',
  'rxjs/operators/distinct': 'Rx.Observable.prototype',
  'rxjs/operators/distinctUntilChanged': 'Rx.Observable.prototype',
  'rxjs/operators/distinctUntilKeyChanged': 'Rx.Observable.prototype',
  'rxjs/operators/do': 'Rx.Observable.prototype',
  'rxjs/operators/elementAt': 'Rx.Observable.prototype',
  'rxjs/operators/every': 'Rx.Observable.prototype',
  'rxjs/operators/exhaust': 'Rx.Observable.prototype',
  'rxjs/operators/exhaustMap': 'Rx.Observable.prototype',
  'rxjs/operators/expand': 'Rx.Observable.prototype',
  'rxjs/operators/filter': 'Rx.Observable.prototype',
  'rxjs/operators/finally': 'Rx.Observable.prototype',
  'rxjs/operators/find': 'Rx.Observable.prototype',
  'rxjs/operators/findIndex': 'Rx.Observable.prototype',
  'rxjs/operators/first': 'Rx.Observable.prototype',
  'rxjs/operators/groupBy': 'Rx.Observable.prototype',
  'rxjs/operators/ignoreElements': 'Rx.Observable.prototype',
  'rxjs/operators/isEmpty': 'Rx.Observable.prototype',
  'rxjs/operators/last': 'Rx.Observable.prototype',
  'rxjs/operators/let': 'Rx.Observable.prototype',
  'rxjs/operators/map': 'Rx.Observable.prototype',
  'rxjs/operators/mapTo': 'Rx.Observable.prototype',
  'rxjs/operators/materialize': 'Rx.Observable.prototype',
  'rxjs/operators/max': 'Rx.Observable.prototype',
  'rxjs/operators/merge': 'Rx.Observable.prototype',
  'rxjs/operators/mergeAll': 'Rx.Observable.prototype',
  'rxjs/operators/mergeMap': 'Rx.Observable.prototype',
  'rxjs/operators/mergeMapTo': 'Rx.Observable.prototype',
  'rxjs/operators/mergeScan': 'Rx.Observable.prototype',
  'rxjs/operators/min': 'Rx.Observable.prototype',
  'rxjs/operators/multicast': 'Rx.Observable.prototype',
  'rxjs/operators/observeOn': 'Rx.Observable.prototype',
  'rxjs/operators/onErrorResumeNext': 'Rx.Observable.prototype',
  'rxjs/operators/pairwise': 'Rx.Observable.prototype',
  'rxjs/operators/partition': 'Rx.Observable.prototype',
  'rxjs/operators/pluck': 'Rx.Observable.prototype',
  'rxjs/operators/publish': 'Rx.Observable.prototype',
  'rxjs/operators/publishBehavior': 'Rx.Observable.prototype',
  'rxjs/operators/publishLast': 'Rx.Observable.prototype',
  'rxjs/operators/publishReplay': 'Rx.Observable.prototype',
  'rxjs/operators/race': 'Rx.Observable.prototype',
  'rxjs/operators/reduce': 'Rx.Observable.prototype',
  'rxjs/operators/repeat': 'Rx.Observable.prototype',
  'rxjs/operators/repeatWhen': 'Rx.Observable.prototype',
  'rxjs/operators/retry': 'Rx.Observable.prototype',
  'rxjs/operators/retryWhen': 'Rx.Observable.prototype',
  'rxjs/operators/sample': 'Rx.Observable.prototype',
  'rxjs/operators/sampleTime': 'Rx.Observable.prototype',
  'rxjs/operators/scan': 'Rx.Observable.prototype',
  'rxjs/operators/sequenceEqual': 'Rx.Observable.prototype',
  'rxjs/operators/share': 'Rx.Observable.prototype',
  'rxjs/operators/shareReplay': 'Rx.Observable.prototype',
  'rxjs/operators/single': 'Rx.Observable.prototype',
  'rxjs/operators/skip': 'Rx.Observable.prototype',
  'rxjs/operators/skipLast': 'Rx.Observable.prototype',
  'rxjs/operators/skipUntil': 'Rx.Observable.prototype',
  'rxjs/operators/skipWhile': 'Rx.Observable.prototype',
  'rxjs/operators/startWith': 'Rx.Observable.prototype',
  'rxjs/operators/subscribeOn': 'Rx.Observable.prototype',
  'rxjs/operators/switch': 'Rx.Observable.prototype',
  'rxjs/operators/switchMap': 'Rx.Observable.prototype',
  'rxjs/operators/switchMapTo': 'Rx.Observable.prototype',
  'rxjs/operators/take': 'Rx.Observable.prototype',
  'rxjs/operators/takeLast': 'Rx.Observable.prototype',
  'rxjs/operators/takeUntil': 'Rx.Observable.prototype',
  'rxjs/operators/takeWhile': 'Rx.Observable.prototype',
  'rxjs/operators/throttle': 'Rx.Observable.prototype',
  'rxjs/operators/throttleTime': 'Rx.Observable.prototype',
  'rxjs/operators/timeInterval': 'Rx.Observable.prototype',
  'rxjs/operators/timeout': 'Rx.Observable.prototype',
  'rxjs/operators/timeoutWith': 'Rx.Observable.prototype',
  'rxjs/operators/timestamp': 'Rx.Observable.prototype',
  'rxjs/operators/toArray': 'Rx.Observable.prototype',
  'rxjs/operators/toPromise': 'Rx.Observable.prototype',
  'rxjs/operators/window': 'Rx.Observable.prototype',
  'rxjs/operators/windowCount': 'Rx.Observable.prototype',
  'rxjs/operators/windowTime': 'Rx.Observable.prototype',
  'rxjs/operators/windowToggle': 'Rx.Observable.prototype',
  'rxjs/operators/windowWhen': 'Rx.Observable.prototype',
  'rxjs/operators/withLatestFrom': 'Rx.Observable.prototype',
  'rxjs/operators/zip': 'Rx.Observable.prototype',
  'rxjs/operators/zipAll': 'Rx.Observable.prototype',

  'webfontloader': 'WebFont'
};

const external = Object.keys(globals);

export default {
  external: external,
  input: `${pkg.module}`,
  output: {
    file: `${pkg.main}`,
    format: 'umd',
    name: `zef.${name}`,
    globals: globals,
    sourcemap: true,
    exports: 'named'
  },
  plugins: [
    resolve(),
    sourcemaps()
  ]
}
<commit_msg>Updated externals in rollup umd configuration<commit_after>import resolve from 'rollup-plugin-node-resolve';

import sourcemaps from 'rollup-plugin-sourcemaps';

const pkg = require('../package.json');

const name = pkg.name.replace(/-([a-z])/g, (g) => {
  return g[1].toUpperCase();
});

const globals = {
  '@angular/animations': 'ng.animations',
  '@angular/common': 'ng.common',
  '@angular/core': 'ng.core',
  '@angular/forms': 'ng.forms',
  '@angular/http': 'ng.http',
  '@angular/router': 'ng.router',

  '@angular/platform-browser': 'ng.platformBrowser',
  '@angular/platform-server': 'ng.platformServer',

  'rxjs/AsyncSubject': 'Rx',
  'rxjs/BehaviorSubject': 'Rx',
  'rxjs/Observable': 'Rx',
  'rxjs/Observer': 'Rx',
  'rxjs/ReplaySubject': 'Rx',
  'rxjs/Scheduler': 'Rx',
  'rxjs/Subject': 'Rx',
  'rxjs/Subscriber': 'Rx',
  'rxjs/Subscription': 'Rx',

  'rxjs/operators': 'Rx.Observable.prototype',

  'rxjs/observable/bindCallback': 'Rx.Observable',
  'rxjs/observable/combineLatest': 'Rx.Observable',
  'rxjs/observable/concat': 'Rx.Observable',
  'rxjs/observable/defer': 'Rx.Observable',
  'rxjs/observable/empty': 'Rx.Observable',
  'rxjs/observable/forkJoin': 'Rx.Observable',
  'rxjs/observable/from': 'Rx.Observable',
  'rxjs/observable/fromEvent': 'Rx.Observable',
  'rxjs/observable/fromEventPattern': 'Rx.Observable',
  'rxjs/observable/fromPromise': 'Rx.Observable',
  'rxjs/observable/generate': 'Rx.Observable',
  'rxjs/observable/if': 'Rx.Observable',
  'rxjs/observable/interval': 'Rx.Observable',
  'rxjs/observable/merge': 'Rx.Observable',
  'rxjs/observable/never': 'Rx.Observable',
  'rxjs/observable/of': 'Rx.Observable',
  'rxjs/observable/onErrorResumeNext': 'Rx.Observable',
  'rxjs/observable/pairs': 'Rx.Observable',
  'rxjs/observable/race': 'Rx.Observable',
  'rxjs/observable/range': 'Rx.Observable',
  'rxjs/observable/throw': 'Rx.Observable',
  'rxjs/observable/timer': 'Rx.Observable',
  'rxjs/observable/using': 'Rx.Observable',
  'rxjs/observable/zip': 'Rx.Observable',

  'rxjs/operator/audit': 'Rx.Observable.prototype',
  'rxjs/operator/auditTime': 'Rx.Observable.prototype',
  'rxjs/operator/buffer': 'Rx.Observable.prototype',
  'rxjs/operator/bufferCount': 'Rx.Observable.prototype',
  'rxjs/operator/bufferTime': 'Rx.Observable.prototype',
  'rxjs/operator/bufferToggle': 'Rx.Observable.prototype',
  'rxjs/operator/bufferWhen': 'Rx.Observable.prototype',
  'rxjs/operator/catchError': 'Rx.Observable.prototype',
  'rxjs/operator/combineAll': 'Rx.Observable.prototype',
  'rxjs/operator/combineLatest': 'Rx.Observable.prototype',
  'rxjs/operator/concat': 'Rx.Observable.prototype',
  'rxjs/operator/concatAll': 'Rx.Observable.prototype',
  'rxjs/operator/concatMap': 'Rx.Observable.prototype',
  'rxjs/operator/concatMapTo': 'Rx.Observable.prototype',
  'rxjs/operator/count': 'Rx.Observable.prototype',
  'rxjs/operator/debounce': 'Rx.Observable.prototype',
  'rxjs/operator/debounceTime': 'Rx.Observable.prototype',
  'rxjs/operator/defaultIfEmpty': 'Rx.Observable.prototype',
  'rxjs/operator/delay': 'Rx.Observable.prototype',
  'rxjs/operator/delayWhen': 'Rx.Observable.prototype',
  'rxjs/operator/dematerialize': 'Rx.Observable.prototype',
  'rxjs/operator/distinct': 'Rx.Observable.prototype',
  'rxjs/operator/distinctUntilChanged': 'Rx.Observable.prototype',
  'rxjs/operator/distinctUntilKeyChanged': 'Rx.Observable.prototype',
  'rxjs/operator/do': 'Rx.Observable.prototype',
  'rxjs/operator/elementAt': 'Rx.Observable.prototype',
  'rxjs/operator/every': 'Rx.Observable.prototype',
  'rxjs/operator/exhaust': 'Rx.Observable.prototype',
  'rxjs/operator/exhaustMap': 'Rx.Observable.prototype',
  'rxjs/operator/expand': 'Rx.Observable.prototype',
  'rxjs/operator/filter': 'Rx.Observable.prototype',
  'rxjs/operator/finally': 'Rx.Observable.prototype',
  'rxjs/operator/find': 'Rx.Observable.prototype',
  'rxjs/operator/findIndex': 'Rx.Observable.prototype',
  'rxjs/operator/first': 'Rx.Observable.prototype',
  'rxjs/operator/groupBy': 'Rx.Observable.prototype',
  'rxjs/operator/ignoreElements': 'Rx.Observable.prototype',
  'rxjs/operator/isEmpty': 'Rx.Observable.prototype',
  'rxjs/operator/last': 'Rx.Observable.prototype',
  'rxjs/operator/let': 'Rx.Observable.prototype',
  'rxjs/operator/map': 'Rx.Observable.prototype',
  'rxjs/operator/mapTo': 'Rx.Observable.prototype',
  'rxjs/operator/materialize': 'Rx.Observable.prototype',
  'rxjs/operator/max': 'Rx.Observable.prototype',
  'rxjs/operator/merge': 'Rx.Observable.prototype',
  'rxjs/operator/mergeAll': 'Rx.Observable.prototype',
  'rxjs/operator/mergeMap': 'Rx.Observable.prototype',
  'rxjs/operator/mergeMapTo': 'Rx.Observable.prototype',
  'rxjs/operator/mergeScan': 'Rx.Observable.prototype',
  'rxjs/operator/min': 'Rx.Observable.prototype',
  'rxjs/operator/multicast': 'Rx.Observable.prototype',
  'rxjs/operator/observeOn': 'Rx.Observable.prototype',
  'rxjs/operator/onErrorResumeNext': 'Rx.Observable.prototype',
  'rxjs/operator/pairwise': 'Rx.Observable.prototype',
  'rxjs/operator/partition': 'Rx.Observable.prototype',
  'rxjs/operator/pluck': 'Rx.Observable.prototype',
  'rxjs/operator/publish': 'Rx.Observable.prototype',
  'rxjs/operator/publishBehavior': 'Rx.Observable.prototype',
  'rxjs/operator/publishLast': 'Rx.Observable.prototype',
  'rxjs/operator/publishReplay': 'Rx.Observable.prototype',
  'rxjs/operator/race': 'Rx.Observable.prototype',
  'rxjs/operator/reduce': 'Rx.Observable.prototype',
  'rxjs/operator/repeat': 'Rx.Observable.prototype',
  'rxjs/operator/repeatWhen': 'Rx.Observable.prototype',
  'rxjs/operator/retry': 'Rx.Observable.prototype',
  'rxjs/operator/retryWhen': 'Rx.Observable.prototype',
  'rxjs/operator/sample': 'Rx.Observable.prototype',
  'rxjs/operator/sampleTime': 'Rx.Observable.prototype',
  'rxjs/operator/scan': 'Rx.Observable.prototype',
  'rxjs/operator/sequenceEqual': 'Rx.Observable.prototype',
  'rxjs/operator/share': 'Rx.Observable.prototype',
  'rxjs/operator/shareReplay': 'Rx.Observable.prototype',
  'rxjs/operator/single': 'Rx.Observable.prototype',
  'rxjs/operator/skip': 'Rx.Observable.prototype',
  'rxjs/operator/skipLast': 'Rx.Observable.prototype',
  'rxjs/operator/skipUntil': 'Rx.Observable.prototype',
  'rxjs/operator/skipWhile': 'Rx.Observable.prototype',
  'rxjs/operator/startWith': 'Rx.Observable.prototype',
  'rxjs/operator/subscribeOn': 'Rx.Observable.prototype',
  'rxjs/operator/switch': 'Rx.Observable.prototype',
  'rxjs/operator/switchMap': 'Rx.Observable.prototype',
  'rxjs/operator/switchMapTo': 'Rx.Observable.prototype',
  'rxjs/operator/take': 'Rx.Observable.prototype',
  'rxjs/operator/takeLast': 'Rx.Observable.prototype',
  'rxjs/operator/takeUntil': 'Rx.Observable.prototype',
  'rxjs/operator/takeWhile': 'Rx.Observable.prototype',
  'rxjs/operator/throttle': 'Rx.Observable.prototype',
  'rxjs/operator/throttleTime': 'Rx.Observable.prototype',
  'rxjs/operator/timeInterval': 'Rx.Observable.prototype',
  'rxjs/operator/timeout': 'Rx.Observable.prototype',
  'rxjs/operator/timeoutWith': 'Rx.Observable.prototype',
  'rxjs/operator/timestamp': 'Rx.Observable.prototype',
  'rxjs/operator/toArray': 'Rx.Observable.prototype',
  'rxjs/operator/toPromise': 'Rx.Observable.prototype',
  'rxjs/operator/window': 'Rx.Observable.prototype',
  'rxjs/operator/windowCount': 'Rx.Observable.prototype',
  'rxjs/operator/windowTime': 'Rx.Observable.prototype',
  'rxjs/operator/windowToggle': 'Rx.Observable.prototype',
  'rxjs/operator/windowWhen': 'Rx.Observable.prototype',
  'rxjs/operator/withLatestFrom': 'Rx.Observable.prototype',
  'rxjs/operator/zip': 'Rx.Observable.prototype',
  'rxjs/operator/zipAll': 'Rx.Observable.prototype',

  'rxjs/operators/audit': 'Rx.Observable.prototype',
  'rxjs/operators/auditTime': 'Rx.Observable.prototype',
  'rxjs/operators/buffer': 'Rx.Observable.prototype',
  'rxjs/operators/bufferCount': 'Rx.Observable.prototype',
  'rxjs/operators/bufferTime': 'Rx.Observable.prototype',
  'rxjs/operators/bufferToggle': 'Rx.Observable.prototype',
  'rxjs/operators/bufferWhen': 'Rx.Observable.prototype',
  'rxjs/operators/catchError': 'Rx.Observable.prototype',
  'rxjs/operators/combineAll': 'Rx.Observable.prototype',
  'rxjs/operators/combineLatest': 'Rx.Observable.prototype',
  'rxjs/operators/concat': 'Rx.Observable.prototype',
  'rxjs/operators/concatAll': 'Rx.Observable.prototype',
  'rxjs/operators/concatMap': 'Rx.Observable.prototype',
  'rxjs/operators/concatMapTo': 'Rx.Observable.prototype',
  'rxjs/operators/count': 'Rx.Observable.prototype',
  'rxjs/operators/debounce': 'Rx.Observable.prototype',
  'rxjs/operators/debounceTime': 'Rx.Observable.prototype',
  'rxjs/operators/defaultIfEmpty': 'Rx.Observable.prototype',
  'rxjs/operators/delay': 'Rx.Observable.prototype',
  'rxjs/operators/delayWhen': 'Rx.Observable.prototype',
  'rxjs/operators/dematerialize': 'Rx.Observable.prototype',
  'rxjs/operators/distinct': 'Rx.Observable.prototype',
  'rxjs/operators/distinctUntilChanged': 'Rx.Observable.prototype',
  'rxjs/operators/distinctUntilKeyChanged': 'Rx.Observable.prototype',
  'rxjs/operators/do': 'Rx.Observable.prototype',
  'rxjs/operators/elementAt': 'Rx.Observable.prototype',
  'rxjs/operators/every': 'Rx.Observable.prototype',
  'rxjs/operators/exhaust': 'Rx.Observable.prototype',
  'rxjs/operators/exhaustMap': 'Rx.Observable.prototype',
  'rxjs/operators/expand': 'Rx.Observable.prototype',
  'rxjs/operators/filter': 'Rx.Observable.prototype',
  'rxjs/operators/finally': 'Rx.Observable.prototype',
  'rxjs/operators/find': 'Rx.Observable.prototype',
  'rxjs/operators/findIndex': 'Rx.Observable.prototype',
  'rxjs/operators/first': 'Rx.Observable.prototype',
  'rxjs/operators/groupBy': 'Rx.Observable.prototype',
  'rxjs/operators/ignoreElements': 'Rx.Observable.prototype',
  'rxjs/operators/isEmpty': 'Rx.Observable.prototype',
  'rxjs/operators/last': 'Rx.Observable.prototype',
  'rxjs/operators/let': 'Rx.Observable.prototype',
  'rxjs/operators/map': 'Rx.Observable.prototype',
  'rxjs/operators/mapTo': 'Rx.Observable.prototype',
  'rxjs/operators/materialize': 'Rx.Observable.prototype',
  'rxjs/operators/max': 'Rx.Observable.prototype',
  'rxjs/operators/merge': 'Rx.Observable.prototype',
  'rxjs/operators/mergeAll': 'Rx.Observable.prototype',
  'rxjs/operators/mergeMap': 'Rx.Observable.prototype',
  'rxjs/operators/mergeMapTo': 'Rx.Observable.prototype',
  'rxjs/operators/mergeScan': 'Rx.Observable.prototype',
  'rxjs/operators/min': 'Rx.Observable.prototype',
  'rxjs/operators/multicast': 'Rx.Observable.prototype',
  'rxjs/operators/observeOn': 'Rx.Observable.prototype',
  'rxjs/operators/onErrorResumeNext': 'Rx.Observable.prototype',
  'rxjs/operators/pairwise': 'Rx.Observable.prototype',
  'rxjs/operators/partition': 'Rx.Observable.prototype',
  'rxjs/operators/pluck': 'Rx.Observable.prototype',
  'rxjs/operators/publish': 'Rx.Observable.prototype',
  'rxjs/operators/publishBehavior': 'Rx.Observable.prototype',
  'rxjs/operators/publishLast': 'Rx.Observable.prototype',
  'rxjs/operators/publishReplay': 'Rx.Observable.prototype',
  'rxjs/operators/race': 'Rx.Observable.prototype',
  'rxjs/operators/reduce': 'Rx.Observable.prototype',
  'rxjs/operators/repeat': 'Rx.Observable.prototype',
  'rxjs/operators/repeatWhen': 'Rx.Observable.prototype',
  'rxjs/operators/retry': 'Rx.Observable.prototype',
  'rxjs/operators/retryWhen': 'Rx.Observable.prototype',
  'rxjs/operators/sample': 'Rx.Observable.prototype',
  'rxjs/operators/sampleTime': 'Rx.Observable.prototype',
  'rxjs/operators/scan': 'Rx.Observable.prototype',
  'rxjs/operators/sequenceEqual': 'Rx.Observable.prototype',
  'rxjs/operators/share': 'Rx.Observable.prototype',
  'rxjs/operators/shareReplay': 'Rx.Observable.prototype',
  'rxjs/operators/single': 'Rx.Observable.prototype',
  'rxjs/operators/skip': 'Rx.Observable.prototype',
  'rxjs/operators/skipLast': 'Rx.Observable.prototype',
  'rxjs/operators/skipUntil': 'Rx.Observable.prototype',
  'rxjs/operators/skipWhile': 'Rx.Observable.prototype',
  'rxjs/operators/startWith': 'Rx.Observable.prototype',
  'rxjs/operators/subscribeOn': 'Rx.Observable.prototype',
  'rxjs/operators/switch': 'Rx.Observable.prototype',
  'rxjs/operators/switchMap': 'Rx.Observable.prototype',
  'rxjs/operators/switchMapTo': 'Rx.Observable.prototype',
  'rxjs/operators/take': 'Rx.Observable.prototype',
  'rxjs/operators/takeLast': 'Rx.Observable.prototype',
  'rxjs/operators/takeUntil': 'Rx.Observable.prototype',
  'rxjs/operators/takeWhile': 'Rx.Observable.prototype',
  'rxjs/operators/throttle': 'Rx.Observable.prototype',
  'rxjs/operators/throttleTime': 'Rx.Observable.prototype',
  'rxjs/operators/timeInterval': 'Rx.Observable.prototype',
  'rxjs/operators/timeout': 'Rx.Observable.prototype',
  'rxjs/operators/timeoutWith': 'Rx.Observable.prototype',
  'rxjs/operators/timestamp': 'Rx.Observable.prototype',
  'rxjs/operators/toArray': 'Rx.Observable.prototype',
  'rxjs/operators/toPromise': 'Rx.Observable.prototype',
  'rxjs/operators/window': 'Rx.Observable.prototype',
  'rxjs/operators/windowCount': 'Rx.Observable.prototype',
  'rxjs/operators/windowTime': 'Rx.Observable.prototype',
  'rxjs/operators/windowToggle': 'Rx.Observable.prototype',
  'rxjs/operators/windowWhen': 'Rx.Observable.prototype',
  'rxjs/operators/withLatestFrom': 'Rx.Observable.prototype',
  'rxjs/operators/zip': 'Rx.Observable.prototype',
  'rxjs/operators/zipAll': 'Rx.Observable.prototype',

  'webfontloader': 'WebFont'
};

const external = Object.keys(globals);

export default {
  external: external,
  input: `${pkg.module}`,
  output: {
    file: `${pkg.main}`,
    format: 'umd',
    name: `zef.${name}`,
    globals: globals,
    sourcemap: true,
    exports: 'named'
  },
  plugins: [
    resolve(),
    sourcemaps()
  ]
}
<|endoftext|>


<commit_before>// @flow
import React from 'react';
import environment from '@ncigdc/modern_components/environment';
import { commitMutation, graphql } from 'react-relay';
import JSURL from 'jsurl';
import { compose } from 'recompose';

import withRouter from '@ncigdc/utils/withRouter';
import { makeFilter } from '@ncigdc/utils/filters';

import CreateSetButtonBase from './CreateSetButtonBase';

const exploreMutation = graphql`
  mutation CreateExploreCaseSetButtonMutation(
    $input: CreateSetInput
    $never_used: RelayIsDumb
  ) {
    sets(input: $never_used) {
      create {
        explore {
          case(input: $input) {
            set_id
          }
        }
      }
    }
  }
`;

const enhance = compose(withRouter);

const CreateExploreCaseSetButton = ({ filters, setSize, style, push }) => {
  const reRouteOnCompleted = setId => {
    push({
      pathname: '/repository',
      query: {
        filters: JSURL.stringify(
          makeFilter([
            {
              field: 'cases.case_id',
              value: `set_id:${setId}`,
            },
          ]),
        ),
      },
    });
  };

  return (
    <CreateSetButtonBase
      style={style}
      field="cases.case_id"
      filters={filters}
      disabled={!setSize}
      setIdExtractor={response => response.sets.create.explore.case.set_id}
      commitMutation={(variables, onCompleted, onError) => {
        commitMutation(environment, {
          mutation: exploreMutation,
          variables,
          onCompleted,
          onError,
        });
      }}
      reRouteOnCompleted={reRouteOnCompleted}
    >
      View in Repository
    </CreateSetButtonBase>
  );
};

export default enhance(CreateExploreCaseSetButton);
<commit_msg>✏ PRTL-1476 view files in repo<commit_after>// @flow
import React from 'react';
import environment from '@ncigdc/modern_components/environment';
import { commitMutation, graphql } from 'react-relay';
import JSURL from 'jsurl';
import { compose } from 'recompose';

import withRouter from '@ncigdc/utils/withRouter';
import { makeFilter } from '@ncigdc/utils/filters';

import CreateSetButtonBase from './CreateSetButtonBase';

const exploreMutation = graphql`
  mutation CreateExploreCaseSetButtonMutation(
    $input: CreateSetInput
    $never_used: RelayIsDumb
  ) {
    sets(input: $never_used) {
      create {
        explore {
          case(input: $input) {
            set_id
          }
        }
      }
    }
  }
`;

const enhance = compose(withRouter);

const CreateExploreCaseSetButton = ({ filters, setSize, style, push }) => {
  const reRouteOnCompleted = setId => {
    push({
      pathname: '/repository',
      query: {
        searchTableTab: 'files',
        filters: JSURL.stringify(
          makeFilter([
            {
              field: 'cases.case_id',
              value: `set_id:${setId}`,
            },
          ]),
        ),
      },
    });
  };

  return (
    <CreateSetButtonBase
      style={style}
      field="cases.case_id"
      filters={filters}
      disabled={!setSize}
      setIdExtractor={response => response.sets.create.explore.case.set_id}
      commitMutation={(variables, onCompleted, onError) => {
        commitMutation(environment, {
          mutation: exploreMutation,
          variables,
          onCompleted,
          onError,
        });
      }}
      reRouteOnCompleted={reRouteOnCompleted}
    >
      View Files in Repository
    </CreateSetButtonBase>
  );
};

export default enhance(CreateExploreCaseSetButton);
<|endoftext|>


<commit_before>(function () {

'use strict';

angular.module('OpenSlidesApp.mediafiles.projector', [
    'OpenSlidesApp.mediafiles.resources',
    //TODO: Add deps for slidesProvider
])

.config([
    'slidesProvider',
    function (slidesProvider) {
        slidesProvider.registerSlide('mediafiles/mediafile', {
            template: 'static/templates/mediafiles/slide_mediafile.html'
        });
    }
])

.controller('SlideMediafileCtrl', [
    '$scope',
    'Mediafile',
    function ($scope, Mediafile) {
        // load mediafile object
        var mediafile = Mediafile.get($scope.element.id);
        $scope.mediafile = mediafile;

        // Allow the elements to render properly
        setTimeout(function() {
            if ($scope.mediafile) {
                if ($scope.mediafile.is_pdf) {
                    $scope.pdfName = mediafile.title;
                    $scope.pdfUrl = mediafile.mediafileUrl;
                } else if ($scope.mediafile.is_video) {
                    var player = angular.element.find('#video-player')[0];
                    if ($scope.element.playing) {
                        player.play();
                    } else {
                        player.pause();
                    }
                }
            }
        }, 0);
    }
]);

}());
<commit_msg>Bind mediafile to projector scope (fixes #2706)<commit_after>(function () {

'use strict';

angular.module('OpenSlidesApp.mediafiles.projector', [
    'OpenSlidesApp.mediafiles.resources',
    //TODO: Add deps for slidesProvider
])

.config([
    'slidesProvider',
    function (slidesProvider) {
        slidesProvider.registerSlide('mediafiles/mediafile', {
            template: 'static/templates/mediafiles/slide_mediafile.html'
        });
    }
])

.controller('SlideMediafileCtrl', [
    '$scope',
    'Mediafile',
    function ($scope, Mediafile) {
        // load mediafile object
        Mediafile.bindOne($scope.element.id, $scope, 'mediafile');

        // Allow the elements to render properly
        setTimeout(function() {
            if ($scope.mediafile) {
                if ($scope.mediafile.is_pdf) {
                    $scope.pdfName = $scope.mediafile.title;
                    $scope.pdfUrl = $scope.mediafile.mediafileUrl;
                } else if ($scope.mediafile.is_video) {
                    var player = angular.element.find('#video-player')[0];
                    if ($scope.element.playing) {
                        player.play();
                    } else {
                        player.pause();
                    }
                }
            }
        }, 0);
    }
]);

}());
<|endoftext|>


<commit_before>/* eslint-disable complexity */

import React, {Fragment} from 'react'
import PropTypes from 'prop-types'
import Poppable from 'part:@sanity/components/utilities/poppable'
import Checkbox from 'part:@sanity/components/toggles/checkbox'
import Button from 'part:@sanity/components/buttons/default'
import styles from './styles/SelectLanguage.css'
import ChevronDown from 'part:@sanity/base/angle-down-icon'

const LanguagePropType = PropTypes.shape({id: PropTypes.string, title: PropTypes.string})
export default class SelectLanguage extends React.Component {
  static propTypes = {
    languages: PropTypes.arrayOf(LanguagePropType),
    selected: PropTypes.arrayOf(LanguagePropType),
    onChange: PropTypes.func,
  }

  state = {isOpen: false}
  refElement = React.createRef()

  handleToggle = () => this.setState((prevState) => ({isOpen: !prevState.isOpen}))
  handleOpen = () => this.setState({isOpen: true})
  handleClose = () => {
    this.setState({isOpen: false})
  }

  selectLang = (langId) => {
    const {selected, onChange} = this.props
    onChange(selected.concat(langId))
  }

  unselectLang = (langId) => {
    const {selected, onChange} = this.props
    onChange(selected.filter((id) => id !== langId))
  }

  handleSelectAll = (event) => {
    const {languages, onChange} = this.props
    onChange(languages.map((l) => l.id))
  }
  handleSelectNone = (event) => {
    const {onChange} = this.props
    onChange([])
  }
  handleLangCheckboxChange = (event) => {
    const id = event.target.getAttribute('data-lang-id')
    const checked = event.target.checked
    this[checked ? 'selectLang' : 'unselectLang'](id)
  }

  render() {
    const {isOpen} = this.state
    const {languages, selected} = this.props
    const allIsSelected = languages.length === selected.length
    const refElement =
      this.refElement && this.refElement.current && this.refElement.current._element

    return (
      <Fragment>

            Filter languages{allIsSelected ? '' : ` (${selected.length}/${languages.length})`}

            <ChevronDown />

        <Poppable
          onEscape={this.handleClose}
          onClickOutside={this.handleClose}
          placement="bottom"
          referenceElement={refElement}
        >
          {isOpen && (

                <Button
                  inverted
                  onClick={allIsSelected ? this.handleSelectNone : this.handleSelectAll}
                >
                  Select {allIsSelected ? 'none' : 'all'}
                </Button>

                {languages.map((lang) => (

                    <Checkbox
                      onChange={this.handleLangCheckboxChange}
                      data-lang-id={lang.id}
                      checked={selected.includes(lang.id)}
                    >
                      {lang.title}
                    </Checkbox>

                ))}

          )}
        </Poppable>
      </Fragment>
    )
  }
}
<commit_msg>[language-filter] Add missing labels for languages (#2187)<commit_after>/* eslint-disable complexity */

import React, {Fragment} from 'react'
import PropTypes from 'prop-types'
import Poppable from 'part:@sanity/components/utilities/poppable'
import Checkbox from 'part:@sanity/components/toggles/checkbox'
import Button from 'part:@sanity/components/buttons/default'
import styles from './styles/SelectLanguage.css'
import ChevronDown from 'part:@sanity/base/angle-down-icon'

const LanguagePropType = PropTypes.shape({id: PropTypes.string, title: PropTypes.string})
export default class SelectLanguage extends React.Component {
  static propTypes = {
    languages: PropTypes.arrayOf(LanguagePropType),
    selected: PropTypes.arrayOf(LanguagePropType),
    onChange: PropTypes.func,
  }

  state = {isOpen: false}
  refElement = React.createRef()

  handleToggle = () => this.setState((prevState) => ({isOpen: !prevState.isOpen}))
  handleOpen = () => this.setState({isOpen: true})
  handleClose = () => {
    this.setState({isOpen: false})
  }

  selectLang = (langId) => {
    const {selected, onChange} = this.props
    onChange(selected.concat(langId))
  }

  unselectLang = (langId) => {
    const {selected, onChange} = this.props
    onChange(selected.filter((id) => id !== langId))
  }

  handleSelectAll = (event) => {
    const {languages, onChange} = this.props
    onChange(languages.map((l) => l.id))
  }
  handleSelectNone = (event) => {
    const {onChange} = this.props
    onChange([])
  }
  handleLangCheckboxChange = (event) => {
    const id = event.target.getAttribute('data-lang-id')
    const checked = event.target.checked
    this[checked ? 'selectLang' : 'unselectLang'](id)
  }

  render() {
    const {isOpen} = this.state
    const {languages, selected} = this.props
    const allIsSelected = languages.length === selected.length
    const refElement =
      this.refElement && this.refElement.current && this.refElement.current._element

    return (
      <Fragment>

            Filter languages{allIsSelected ? '' : ` (${selected.length}/${languages.length})`}

            <ChevronDown />

        <Poppable
          onEscape={this.handleClose}
          onClickOutside={this.handleClose}
          placement="bottom"
          referenceElement={refElement}
        >
          {isOpen && (

                <Button
                  inverted
                  onClick={allIsSelected ? this.handleSelectNone : this.handleSelectAll}
                >
                  Select {allIsSelected ? 'none' : 'all'}
                </Button>

                {languages.map((lang) => (

                    <Checkbox
                      onChange={this.handleLangCheckboxChange}
                      data-lang-id={lang.id}
                      checked={selected.includes(lang.id)}
                      label={lang.title}
                    />

                ))}

          )}
        </Poppable>
      </Fragment>
    )
  }
}
<|endoftext|>


<commit_before>import path from 'path'
import tsconfig from 'tsconfig'

const MONOREPO_PATH = path.resolve(__dirname, '../../../../..')

function resolve(...segments) {
  return path.resolve(MONOREPO_PATH, ...segments)
}

export function getMonorepoAliases() {
  try {
    // eslint-disable-next-line no-sync
    const result = tsconfig.loadSync(MONOREPO_PATH)
    const {compilerOptions} = result.config

    if (!compilerOptions.baseUrl || !compilerOptions.paths) {
      return {}
    }

    const pathEntries = Object.entries(compilerOptions.paths)
    const aliases = pathEntries.map(([key, value]) => [key, value[0]])

    return aliases.reduce((acc, [key, relativePath]) => {
      acc[key] = resolve(compilerOptions.baseUrl, relativePath)
      return acc
    }, {})
  } catch (err) {
    // eslint-disable-next-line no-console
    console.warn('WARNING: failed to load paths from tsconfig.json in monorepo', err.message)
  }

  return {}
}
<commit_msg>[chore] Lazy require tsconfig when resolving monorepo aliases<commit_after>import path from 'path'

const MONOREPO_PATH = path.resolve(__dirname, '../../../../..')

function resolve(...segments) {
  return path.resolve(MONOREPO_PATH, ...segments)
}
export function getMonorepoAliases() {
  try {
    const tsconfig = require('tsconfig')
    // eslint-disable-next-line no-sync
    const result = tsconfig.loadSync(MONOREPO_PATH)
    const {compilerOptions} = result.config

    if (!compilerOptions.baseUrl || !compilerOptions.paths) {
      return {}
    }

    const pathEntries = Object.entries(compilerOptions.paths)
    const aliases = pathEntries.map(([key, value]) => [key, value[0]])

    return aliases.reduce((acc, [key, relativePath]) => {
      acc[key] = resolve(compilerOptions.baseUrl, relativePath)
      return acc
    }, {})
  } catch (err) {
    // eslint-disable-next-line no-console
    console.warn('WARNING: failed to load paths from tsconfig.json in monorepo', err.message)
  }

  return {}
}
<|endoftext|>


<commit_before>import React, { useState } from 'react';
import { c } from 'ttag';
import { Link } from 'react-router-dom';
import {
    useUser,
    useOrganization,
    useAuthentication,
    useModals,
    usePopperAnchor,
    useApi,
    Icon,
    Dropdown,
    AuthenticatedBugModal,
    DonateModal,
    generateUID,
    PrimaryButton,
    useConfig,
    useSubscription
} from 'react-components';
import { revoke } from 'proton-shared/lib/api/auth';
import { APPS, CLIENT_TYPES, PLANS } from 'proton-shared/lib/constants';
import { getPlanName } from 'proton-shared/lib/helpers/subscription';

import UserDropdownButton from './UserDropdownButton';

const { PROTONMAIL_SETTINGS } = APPS;
const { VPN } = CLIENT_TYPES;
const { PROFESSIONAL, VISIONARY } = PLANS;

const UserDropdown = ({ ...rest }) => {
    const { APP_NAME, CLIENT_TYPE } = useConfig();
    const api = useApi();
    const [user] = useUser();
    const { DisplayName, Email, Name } = user;
    const [{ Name: organizationName } = {}] = useOrganization();
    const [subscription] = useSubscription();
    const { logout } = useAuthentication();
    const { createModal } = useModals();
    const [uid] = useState(generateUID('dropdown'));
    const { anchorRef, isOpen, toggle, close } = usePopperAnchor();
    const planName = getPlanName(subscription);

    const handleBugReportClick = () => {
        createModal(<AuthenticatedBugModal />);
    };

    const handleSupportUsClick = () => {
        createModal(<DonateModal />);
    };

    const handleLogout = () => {
        api(revoke()); // Kick off the revoke request, but don't care for the result.
        logout();
    };

    return (

            <UserDropdownButton {...rest} user={user} buttonRef={anchorRef} isOpen={isOpen} onClick={toggle} />
            <Dropdown id={uid} isOpen={isOpen} anchorRef={anchorRef} onClose={close} originalPlacement="bottom-right">

                            {DisplayName || Name}

                        {Email ? (

                                {Email}

                        ) : null}
                        {[PROFESSIONAL, VISIONARY].includes(planName) && organizationName ? (

                                {organizationName}

                        ) : null}

                    {CLIENT_TYPE === VPN ? null : (

                            {APP_NAME === PROTONMAIL_SETTINGS ? (
                                <Link
                                    to="/settings"
                                    className="w100 flex flex-nowrap color-global-grey nodecoration pt0-5 pb0-5"
                                >
                                    <Icon className="mt0-25 mr0-5 fill-currentColor" name="settings" />
                                    {c('Action').t`Settings`}
                                </Link>
                            ) : (

                                    <Icon className="mt0-25 mr0-5 fill-currentColor" name="settings" />
                                    {c('Action').t`Settings`}

                            )}

                    )}

                        <a
                            className="w100 flex flex-nowrap color-global-grey nodecoration pt0-5 pb0-5"
                            href={
                                CLIENT_TYPE === VPN
                                    ? 'https://protonvpn.com/support/'
                                    : 'https://protonmail.com/support/'
                            }
                            // eslint-disable-next-line react/jsx-no-target-blank
                            target="_blank"
                        >
                            <Icon className="mt0-25 mr0-5 fill-currentColor" name="what-is-this" />
                            {c('Action').t`I have a question`}

                        <button
                            type="button"
                            className="w100 flex underline-hover pt0-5 pb0-5 alignleft"
                            onClick={handleBugReportClick}
                        >
                            <Icon className="mt0-25 mr0-5 fill-currentColor" name="report-bug" />
                            {c('Action').t`Report bug`}
                        </button>

                            <Icon className="mt0-25 mr0-5 fill-currentColor" name="shop" />
                            {c('Action').t`Proton shop`}

                        <button
                            type="button"
                            className="w100 flex underline-hover pt0-5 pb0-5 alignleft"
                            onClick={handleSupportUsClick}
                        >
                            <Icon className="mt0-25 mr0-5 fill-currentColor" name="donate" />
                            {c('Action').t`Support us`}
                        </button>

                        <PrimaryButton
                            className="w100 aligncenter navigationUser-logout"
                            onClick={handleLogout}
                            data-cy-header-user-dropdown="logout"
                        >
                            {c('Action').t`Logout`}
                        </PrimaryButton>

            </Dropdown>

    );
};

export default UserDropdown;
<commit_msg>Fix - user Drop Down link classes (#452)<commit_after>import React, { useState } from 'react';
import { c } from 'ttag';
import { Link } from 'react-router-dom';
import {
    useUser,
    useOrganization,
    useAuthentication,
    useModals,
    usePopperAnchor,
    useApi,
    Icon,
    Dropdown,
    AuthenticatedBugModal,
    DonateModal,
    generateUID,
    PrimaryButton,
    useConfig,
    useSubscription
} from 'react-components';
import { revoke } from 'proton-shared/lib/api/auth';
import { APPS, CLIENT_TYPES, PLANS } from 'proton-shared/lib/constants';
import { getPlanName } from 'proton-shared/lib/helpers/subscription';

import UserDropdownButton from './UserDropdownButton';

const { PROTONMAIL_SETTINGS } = APPS;
const { VPN } = CLIENT_TYPES;
const { PROFESSIONAL, VISIONARY } = PLANS;

const UserDropdown = ({ ...rest }) => {
    const { APP_NAME, CLIENT_TYPE } = useConfig();
    const api = useApi();
    const [user] = useUser();
    const { DisplayName, Email, Name } = user;
    const [{ Name: organizationName } = {}] = useOrganization();
    const [subscription] = useSubscription();
    const { logout } = useAuthentication();
    const { createModal } = useModals();
    const [uid] = useState(generateUID('dropdown'));
    const { anchorRef, isOpen, toggle, close } = usePopperAnchor();
    const planName = getPlanName(subscription);

    const handleBugReportClick = () => {
        createModal(<AuthenticatedBugModal />);
    };

    const handleSupportUsClick = () => {
        createModal(<DonateModal />);
    };

    const handleLogout = () => {
        api(revoke()); // Kick off the revoke request, but don't care for the result.
        logout();
    };

    return (

            <UserDropdownButton {...rest} user={user} buttonRef={anchorRef} isOpen={isOpen} onClick={toggle} />
            <Dropdown id={uid} isOpen={isOpen} anchorRef={anchorRef} onClose={close} originalPlacement="bottom-right">

                            {DisplayName || Name}

                        {Email ? (

                                {Email}

                        ) : null}
                        {[PROFESSIONAL, VISIONARY].includes(planName) && organizationName ? (

                                {organizationName}

                        ) : null}

                    {CLIENT_TYPE === VPN ? null : (

                            {APP_NAME === PROTONMAIL_SETTINGS ? (
                                <Link
                                    to="/settings"
                                    className="w100 flex flex-nowrap dropDown-link nodecoration pt0-5 pb0-5"
                                >
                                    <Icon className="mt0-25 mr0-5 fill-currentColor" name="settings" />
                                    {c('Action').t`Settings`}
                                </Link>
                            ) : (

                                    <Icon className="mt0-25 mr0-5 fill-currentColor" name="settings" />
                                    {c('Action').t`Settings`}

                            )}

                    )}

                            <Icon className="mt0-25 mr0-5 fill-currentColor" name="what-is-this" />
                            {c('Action').t`I have a question`}

                        <button
                            type="button"
                            className="w100 flex underline-hover dropDown-link pt0-5 pb0-5 alignleft"
                            onClick={handleBugReportClick}
                        >
                            <Icon className="mt0-25 mr0-5 fill-currentColor" name="report-bug" />
                            {c('Action').t`Report bug`}
                        </button>

                            <Icon className="mt0-25 mr0-5 fill-currentColor" name="shop" />
                            {c('Action').t`Proton shop`}

                        <button
                            type="button"
                            className="w100 flex underline-hover dropDown-link pt0-5 pb0-5 alignleft"
                            onClick={handleSupportUsClick}
                        >
                            <Icon className="mt0-25 mr0-5 fill-currentColor" name="donate" />
                            {c('Action').t`Support us`}
                        </button>

                        <PrimaryButton
                            className="w100 aligncenter navigationUser-logout"
                            onClick={handleLogout}
                            data-cy-header-user-dropdown="logout"
                        >
                            {c('Action').t`Logout`}
                        </PrimaryButton>

            </Dropdown>

    );
};

export default UserDropdown;
<|endoftext|>