<commit_before>/*global $, app, me, client*/
"use strict";

var HumanView = require('human-view');
var templates = require('../templates');
var ContactListItem = require('../views/contactListItem');
var MUCListItem = require('../views/mucListItem');

module.exports = HumanView.extend({
    template: templates.body,
    initialize: function () {
        this.listenTo(app.state, 'change:title', this.handleTitle);
        this.handleTitle();
    },
    events: {
        'click a[href]': 'handleLinkClick',
        'click .reconnect': 'handleReconnect'
    },
    classBindings: {
        connected: '#connectionOverlay'
    },
    render: function () {
        $('head').append(templates.head());
        $('body').removeClass('aux');
        this.renderAndBind();
        this.renderCollection(me.contacts, ContactListItem, this.$('#roster nav'));
        this.renderCollection(me.mucs, MUCListItem, this.$('#bookmarks nav'));
        return this;
    },
    handleReconnect: function (e) {
        client.connect();
    },
    handleLinkClick: function (e) {
        var t = $(e.target);
        var aEl = t.is('a') ? t[0] : t.closest('a')[0];
        var local = window.location.host === aEl.host;
        var path = aEl.pathname.slice(1);

        if (local) {
            e.preventDefault();
            app.navigate(path);
            return false;
        }
    },
    handleTitle: function (e) {
        document.title = app.state.title;
        if (window.macgap) {
            window.macgap.dock.badge = app.state.badge;
        }
    }
});
<commit_msg>Try avoiding error with macgap<commit_after>/*global $, app, me, client*/
"use strict";

var HumanView = require('human-view');
var templates = require('../templates');
var ContactListItem = require('../views/contactListItem');
var MUCListItem = require('../views/mucListItem');

module.exports = HumanView.extend({
    template: templates.body,
    initialize: function () {
        this.listenTo(app.state, 'change:title', this.handleTitle);
        window.macgap.dock.badge = '';
    },
    events: {
        'click a[href]': 'handleLinkClick',
        'click .reconnect': 'handleReconnect'
    },
    classBindings: {
        connected: '#connectionOverlay'
    },
    render: function () {
        $('head').append(templates.head());
        $('body').removeClass('aux');
        this.renderAndBind();
        this.renderCollection(me.contacts, ContactListItem, this.$('#roster nav'));
        this.renderCollection(me.mucs, MUCListItem, this.$('#bookmarks nav'));
        return this;
    },
    handleReconnect: function (e) {
        client.connect();
    },
    handleLinkClick: function (e) {
        var t = $(e.target);
        var aEl = t.is('a') ? t[0] : t.closest('a')[0];
        var local = window.location.host === aEl.host;
        var path = aEl.pathname.slice(1);

        if (local) {
            e.preventDefault();
            app.navigate(path);
            return false;
        }
    },
    handleTitle: function (e) {
        document.title = app.state.title;
        if (window.macgap) {
            window.macgap.dock.badge = app.state.badge;
        }
    }
});
<|endoftext|>


<commit_before>define("data_list/DataListView", [
    "use!backbone",
    "use!handlebars",
    "datum/Datum",
    "data_list/DataList",
    "text!data_list/data_list.handlebars",
    "datum_menu/DatumMenu",
    "datum_menu/DatumMenuView"
    "text!data_list/data_list_view.handlebars",
    "text!data_list_title/data_list_title.handlebars",
    "data_list_title/DataListTitle",
    "data_list_title/DataListTitleView",
    "datum_menu/DatumMenu",
    "datum_menu/DatumMenuView",

 //   "search/Search"
], function(Backbone, Handlebars, Datum, DataList, data_list_viewTemplate, data_list_titleTemplate, DataListTitle, DataListTitleView, DatumMenu,DatumMenuView) {
    var DataListView = Backbone.View.extend(
    /** @lends DatumView.prototype */
    {
        /**
         * @class A list of datum that are returned as a search result.  It will have check-boxes on the side and a datum menu on the bottom.
         *
         * @extends Backbone.View
         * @constructs
         */
        initialize : function() {
        //	var datumMenu = new DatumMenu();
//            this.menuview = new DatumMenuView({model: new DatumMenu()});
  //      	this.searchview = new Search({model: this.model.get("search")});
       //     this.listview = new DataList({model: this.model.get("dataList")});
    //        this.titleview = new DataListTitleView({model: this.model.get("dataListTitle")});
            this.menuview = new DatumMenuView({model: this.model.get("datumMenu")});

        },

        model : DataList,
        classname : "dataList",
        template: Handlebars.compile(data_listTemplate),

        menuview: DatumMenuView,

        render : function() {

        	Handlebars.registerPartial("datum_menu", this.menuview.template(this.menuview.model.toJSON()) );
        template: Handlebars.compile(data_list_viewTemplate),

      //  searchsview: null,
       //listview: null,
 //       titleview: null,
        menuview: null,

        render : function() {

//        	Handlebars.registerPartial("search", this.statusview.template(this.statusview.model.toJSON()) );
//        	Handlebars.registerPartial("list", this.tagview.template(this.tagview.model.toJSON()) );
   //     	Handlebars.registerPartial("data_list_title", this.titleview.template(this.titleview.model.toJSON()) );
        	Handlebars.registerPartial("datum_menu", this.menuview.template(this.menuview.model.toJSON()) );

        	$(this.el).html(this.template(this.model.toJSON()));
            return this;
        }

    });

    return DataListView;
});
<commit_msg>added a comma<commit_after>define("data_list/DataListView", [
    "use!backbone",
    "use!handlebars",
    "datum/Datum",
    "data_list/DataList",
    "text!data_list/data_list.handlebars",
    "datum_menu/DatumMenu",
    "datum_menu/DatumMenuView",
    "text!data_list/data_list_view.handlebars",
    "text!data_list_title/data_list_title.handlebars",
    "data_list_title/DataListTitle",
    "data_list_title/DataListTitleView",
    "datum_menu/DatumMenu",
    "datum_menu/DatumMenuView",

 //   "search/Search"
], function(Backbone, Handlebars, Datum, DataList, data_list_viewTemplate, data_list_titleTemplate, DataListTitle, DataListTitleView, DatumMenu,DatumMenuView) {
    var DataListView = Backbone.View.extend(
    /** @lends DatumView.prototype */
    {
        /**
         * @class A list of datum that are returned as a search result.  It will have check-boxes on the side and a datum menu on the bottom.
         *
         * @extends Backbone.View
         * @constructs
         */
        initialize : function() {
        //	var datumMenu = new DatumMenu();
//            this.menuview = new DatumMenuView({model: new DatumMenu()});
  //      	this.searchview = new Search({model: this.model.get("search")});
       //     this.listview = new DataList({model: this.model.get("dataList")});
    //        this.titleview = new DataListTitleView({model: this.model.get("dataListTitle")});
            this.menuview = new DatumMenuView({model: this.model.get("datumMenu")});

        },

        model : DataList,
        classname : "dataList",
        template: Handlebars.compile(data_listTemplate),

        menuview: DatumMenuView,

        render : function() {

        	Handlebars.registerPartial("datum_menu", this.menuview.template(this.menuview.model.toJSON()) );
        template: Handlebars.compile(data_list_viewTemplate),

      //  searchsview: null,
       //listview: null,
 //       titleview: null,
        menuview: null,

        render : function() {

//        	Handlebars.registerPartial("search", this.statusview.template(this.statusview.model.toJSON()) );
//        	Handlebars.registerPartial("list", this.tagview.template(this.tagview.model.toJSON()) );
   //     	Handlebars.registerPartial("data_list_title", this.titleview.template(this.titleview.model.toJSON()) );
        	Handlebars.registerPartial("datum_menu", this.menuview.template(this.menuview.model.toJSON()) );

        	$(this.el).html(this.template(this.model.toJSON()));
            return this;
        }

    });

    return DataListView;
});
<|endoftext|>


<commit_before>var pull = require('pull-stream')
var crypto = require('crypto')

var log = exports.log = function log (name) {
  if(process.env.DEBUG)
    return pull.through(function (e) {
      console.log(name, e)
    })
  else
    return pull.through()
}

function bindAll(obj, context) {
  var o = {}
  for(var k in obj)
    o[k] = obj[k].bind(context)
  return o
}

exports.peers = function (nameA, a, nameB, b, async) {
  var na = nameA[0].toUpperCase(), nb = nameB[0].toUpperCase()
  //this is just a hack to fake RPC. over rpc each method is called
  //with the remote id in the current this context.
  a._onConnect({id: nameB, blobs: bindAll(b, {id: nameA})}, nb+na)
  b._onConnect({id: nameA, blobs: bindAll(a, {id: nameB})}, na+nb)
}

exports.hash = function (buf) {
  buf = 'string' == typeof buf ? new Buffer(buf) : buf
  return '&'+crypto.createHash('sha256')
            .update(buf).digest('base64')+'.sha256'
}

exports.fake = function (string, length) {
  var b = new Buffer(length)
  var n = Buffer.byteLength(string)
  for(var i = 0; i < length; i += n)
    b.write(string, i)
  return b
}

exports.sync = function noAsync (test, done) {
  function async(fn) {
    return fn
  }
  async.through = function () { return pull.through() }
  async.done = done
  test(async)
}

exports.tests = function (tests) {
  tests(function (name, async) {
    return require('../inject')(
      require('./mock/blobs')(name, async),
      require('./mock/set')(async),
      name
    )
  }, exports.sync)
}
<commit_msg>handle multiblob@1.1<commit_after>var pull = require('pull-stream')
var crypto = require('crypto')

var log = exports.log = function log (name) {
  if(process.env.DEBUG)
    return pull.through(function (e) {
      console.log(name, e)
    })
  else
    return pull.through()
}

function bindAll(obj, context) {
  var o = {}
  for(var k in obj) {
    if(obj[k])
      o[k] = obj[k].bind(context)
  }
  return o
}

exports.peers = function (nameA, a, nameB, b, async) {
  var na = nameA[0].toUpperCase(), nb = nameB[0].toUpperCase()
  //this is just a hack to fake RPC. over rpc each method is called
  //with the remote id in the current this context.
  a._onConnect({id: nameB, blobs: bindAll(b, {id: nameA})}, nb+na)
  b._onConnect({id: nameA, blobs: bindAll(a, {id: nameB})}, na+nb)
}

exports.hash = function (buf) {
  buf = 'string' == typeof buf ? new Buffer(buf) : buf
  return '&'+crypto.createHash('sha256')
            .update(buf).digest('base64')+'.sha256'
}

exports.fake = function (string, length) {
  var b = new Buffer(length)
  var n = Buffer.byteLength(string)
  for(var i = 0; i < length; i += n)
    b.write(string, i)
  return b
}

exports.sync = function noAsync (test, done) {
  function async(fn) {
    return fn
  }
  async.through = function () { return pull.through() }
  async.done = done
  test(async)
}

exports.tests = function (tests) {
  tests(function (name, async) {
    return require('../inject')(
      require('./mock/blobs')(name, async),
      require('./mock/set')(async),
      name
    )
  }, exports.sync)
}

<|endoftext|>


<commit_before>/*
 * Before running, make sure to do:
 * - npm install
 * - npm install -g grunt-cli
 *
 * TASKS:
 * grunt - runs Mocha tests (default task)
 */

'use strict';

module.exports = function(grunt) {
    var tests = ['test/**/*.js'];

    require('load-grunt-tasks')(grunt); // load all grunt modules

    grunt.initConfig({
        watch: {
            files: tests,
            options: {
                spawn: false,
                event: ['added', 'changed']
            }
        },
        mochaTest: {
            test: {
                options: {
                    reporter: 'spec',
                    clearRequireCache: true
                },
                src: tests
            }
        }
    });

    grunt.registerTask('default', 'mochaTest');

};
<commit_msg>RUN-633: init check-in<commit_after>/*
 * Before running, make sure to do:
 * - npm install
 * - npm install -g grunt-cli
 *
 * TASKS:
 * grunt - runs Mocha tests (default task)
 */

'use strict';

module.exports = function(grunt) {
    var tests = ['test/**/*.js'];
    grunt.loadNpmTasks('grunt-mocha-test');
    grunt.initConfig({
        mochaTest: {
            test: {
                options: {
                    reporter: 'spec',
                    clearRequireCache: true
                },
                src: tests
            }
        }
    });
    grunt.registerTask('default', 'mochaTest');
};
<|endoftext|>


<commit_before>const path = require('path');
const { Router } = require('express');
const orgCtrl = require('./orgCtrl');

const orgRoutes = module.exports = new Router();

orgRoutes.get('/?', orgCtrl.validateIntake, (req, res) => {
  res.sendFile(path.join(__dirname, '../../../src/intake.html'));
});

orgRoutes.get('/addOrg?', orgCtrl.addOrg);<commit_msg>minor add org change<commit_after>const path = require('path');
const { Router } = require('express');
const orgCtrl = require('./orgCtrl');

const orgRoutes = module.exports = new Router();

orgRoutes.get('/?', orgCtrl.validateIntake, (req, res) => {
  res.sendFile(path.join(__dirname, '../../../src/intake.html'));
});

orgRoutes.get('/add?', orgCtrl.addOrg);<|endoftext|>


<commit_before>/*!
 * grunt-svg2png
 * https://github.com/dbushell/grunt-svg2png
 *
 * Copyright (c) 2013 David Bushell
 * Licensed under The MIT License (MIT)
 */

'use strict';

module.exports = function(grunt)
{
    var fs = require('fs'),
        path = require('path'),
        checksum = require('checksum'),
        stamp = JSON.parse(fs.readFileSync('stamp.json', 'utf8'));

    function onlyChanged(filepath) {
        var file = path.resolve(filepath);

        return stamp[file] !== checksum(file);
    }

    grunt.initConfig({

        jshint: {
            all: [
                'Gruntfile.js',
                'tasks/**/*.js',
                '<%= nodeunit.tests %>'
            ],
            options: {
                jshintrc: '.jshintrc'
            }
        },

        clean: {
            tests: ['test/**/*.png']
        },

        nodeunit: {
            tests: ['test/*_test.js']
        },

        svg2png: {
            all: {
                files: [
                    { src: ['test/**/*.svg'], dest: 'test/png/' }
                ]
            },
            filtered: {
                options: {
                    stamp: 'stamp.json'
                },
                files: [
                    { src: ['test/**/*.svg'], dest: 'test/png/', filter: onlyChanged }
                ],
            }
        }

    });

    grunt.loadTasks('tasks');

    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-nodeunit');

    grunt.registerTask('test', ['clean', 'svg2png', 'nodeunit']);
    grunt.registerTask('default', ['jshint', 'test']);

};
<commit_msg>Check for file exist<commit_after>/*!
 * grunt-svg2png
 * https://github.com/dbushell/grunt-svg2png
 *
 * Copyright (c) 2013 David Bushell
 * Licensed under The MIT License (MIT)
 */

'use strict';

module.exports = function(grunt)
{
    var fs = require('fs'),
        path = require('path'),
        checksum = require('checksum'),
        stamp = {};

    fs.exists('stamp.json', function(exists) {
        if (exists) {
            stamp = JSON.parse(fs.readFileSync('stamp.json', 'utf8'));
        }
    });

    function onlyChanged(filepath) {
        var file = path.resolve(filepath);

        return stamp[file] !== checksum(file);
    }

    grunt.initConfig({

        jshint: {
            all: [
                'Gruntfile.js',
                'tasks/**/*.js',
                '<%= nodeunit.tests %>'
            ],
            options: {
                jshintrc: '.jshintrc'
            }
        },

        clean: {
            tests: ['test/**/*.png']
        },

        nodeunit: {
            tests: ['test/*_test.js']
        },

        svg2png: {
            all: {
                files: [
                    { src: ['test/**/*.svg'], dest: 'test/png/' }
                ]
            },
            filtered: {
                options: {
                    stamp: 'stamp.json'
                },
                files: [
                    { src: ['test/**/*.svg'], dest: 'test/png/', filter: onlyChanged }
                ],
            }
        }

    });

    grunt.loadTasks('tasks');

    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-nodeunit');

    grunt.registerTask('test', ['clean', 'svg2png', 'nodeunit']);
    grunt.registerTask('default', ['jshint', 'test']);

};
<|endoftext|>


<commit_before>// ==UserScript==
// @name         TruyenCV downloader
// @namespace    http://devs.forumvi.com/
// @version      1.0.0
// @description  Tải truyện từ truyencv.com định dạng html. Sau đó, bạn có thể dùng Mobipocket Creator để tạo ebook prc
// @author       Zzbaivong
// @icon         http://truyencv.com/templates/truyencv/images/logo.png
// @match        http://truyencv.com/*/
// @require      http://code.jquery.com/jquery-2.2.1.min.js
// @require      http://openuserjs.org/src/libs/baivong/FileSaver.min.js
// @run-at       document-end
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function ($, window, document, undefined) {
    'use strict';

    window.URL = window.URL || window.webkitURL;

    function getChapter() {

        ++count;

        var path = location.pathname,
            url = path + 'chuong-' + count,
            fileName = path.slice(1, -1) + '.html',
            blob;

        if (count > max) {

            txt = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">' + txt + '

-- Hết --

Truyện được tải từ: TruyenCV - http://truyencv.com

Scipt được viết bởi: Zzbaivong - http://devs.forumvi.com
';

            blob = new Blob([txt], {
                type: 'text/html'
            });

            saveAs(blob, fileName);

            $download.attr({
                href: window.URL.createObjectURL(blob),
                download: fileName
            }).text('Download Finished!').off('click');

            $(window).off("beforeunload");

            console.log('%cDownload Finished!', 'color:blue;');

        } else {

            GM_xmlhttpRequest({
                method: 'GET',
                url: url,
                onload: function (response) {

                    var $data = $(response.response),
                        $chapter = $data.find('.chapter');

                    if ($chapter.length) {
                        console.log('%c' + url, 'color:green;');
                        $download.text(count + '/' + max);
                    } else {
                        console.log('%c' + url, 'color:red;');
                    }

                    $chapter.find('font, p:last').remove();
                    txt += '
' + $data.find('h2.text-muted').html() + '
' + $chapter.html();

                    getChapter();

                },
                onerror: function (err) {
                    console.log('%c' + url, 'color:red;');
                    console.error(err);
                }
            });

        }

    }

    var $download = $('[href="#dsc"]'),
        count = 0,
        max = parseInt($('.listchapter').eq($('.listchapter').length - 2).find('.latestchaper').eq(0).find('a').attr('href').match(/chuong-(\d+)/)[1], 10),
        txt = '';

    $download.text('Download').on('click', function (e) {
        e.preventDefault();

        $(window).on("beforeunload", function () {
            return "Truyện đang được tải xuống...";
        });

        getChapter();
    });

})(jQuery, window, document);
<commit_msg>Resume download<commit_after>// ==UserScript==
// @name         TruyenCV downloader
// @namespace    http://devs.forumvi.com/
// @version      1.1.0
// @description  Tải truyện từ truyencv.com định dạng html. Sau đó, bạn có thể dùng Mobipocket Creator để tạo ebook prc
// @author       Zzbaivong
// @icon         http://truyencv.com/templates/truyencv/images/logo.png
// @match        http://truyencv.com/*/
// @require      http://code.jquery.com/jquery-2.2.1.min.js
// @require      http://openuserjs.org/src/libs/baivong/FileSaver.min.js
// @run-at       document-end
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function ($, window, document, undefined) {

    'use strict';

    window.URL = window.URL || window.webkitURL;

    function downloadFail() {
        console.log('%c' + url, 'color:red;');
        $download.text('Resume...').css('background', 'red');
        disableClick = false;
    }

    function getChapter() {

        var path = location.pathname,
            url = path + 'chuong-' + count,
            fileName = path.slice(1, -1) + '_' + begin + '-' + end + '.html ',
            blob;

        if (count > max) {

            txt = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
' + $('h1').text() + '

' + $('#poster p:eq(3)').text() + '

' + $('#poster p:eq(4)').text() + '

Chương từ ' + begin + ' đến ' + end + '

' + txt + '

-- Hết --

Truyện được tải từ: TruyenCV - http://truyencv.com

Scipt được viết bởi: Zzbaivong - http://devs.forumvi.com
';

            blob = new Blob([txt], {
                type: 'text/html'
            });

            saveAs(blob, fileName);

            $download.attr({
                href: window.URL.createObjectURL(blob),
                download: fileName
            }).text('Download Finished!').css('background', 'green').off('click');

            $(window).off("beforeunload");

            console.log('%cDownload Finished!', 'color:blue;');

        } else {

            GM_xmlhttpRequest({
                method: 'GET',
                url: url,
                onload: function (response) {

                    var $data = $(response.response),
                        title = $data.find('h2.text-muted').html(),
                        $chapter = $data.find('.chapter');

                    if ($chapter.length) {
                        console.log('%c' + url, 'color:green;');
                        $download.text(count + '/' + max);
                        ++count;
                    } else {
                        downloadFail();
                    }

                    $chapter.find('font, p:last').remove();
                    txt += '
' + title + '
' + $chapter.html();

                    getChapter();

                },
                onerror: function (err) {
                    downloadFail();
                    console.error(err);
                }
            });

        }

    }

    var $download = $('[href="#dsc"]'),
        count = 1,
        max = parseInt($('.listchapter').eq($('.listchapter').length - 2).find('.latestchaper').eq(0).find('a').attr('href').match(/chuong-(\d+)/)[1], 10),
        begin,
        end,
        txt = '',
        enablePrompt = true,
        disableClick = false;

    $download.text('Download').css('background', 'orange').on('click', function (e) {
        e.preventDefault();

        if (disableClick) {
            return;
        }

        if (enablePrompt) {

            begin = prompt("Chọn Chương bắt đầu tải", count);
            end = prompt("Chọn Chương kết thúc tải", max);

            if (begin !== null && /^\d+$/.test(begin)) {
                begin = parseInt(begin, 10);
                if (begin < max) {
                    count = begin;
                }
            } else {
                begin = count;
            }

            if (end !== null && /^\d+$/.test(end)) {
                end = parseInt(end, 10);
                if (end > count) {
                    max = end;
                }
            } else {
                end = max;
            }

            $(window).on("beforeunload", function () {
                return "Truyện đang được tải xuống...";
            });

            enablePrompt = false;
        }

        getChapter();

        disableClick = true;
    });

})(jQuery, window, document);
<|endoftext|>


<commit_before>define( [
    'tests/mockup/mockup',
    'osg/Light',
    'osg/LightSource',
    'osg/Material',
    'osgShader/Compiler',
    'osgShadow/ShadowAttribute',
    'osgShadow/ShadowTexture'
], function ( mockup, Light, LightSource, Material, Compiler, ShadowAttribute, ShadowTexture ) {

    return function () {

        module( 'osgShader' );

        test( 'Compiler', function () {

            ( function () {

                var light = new Light( 1 );
                var lightSource = new LightSource();
                lightSource.setLight( light );
                var shadowAttribute = new ShadowAttribute();
                var shadowTexture = new ShadowTexture();
                shadowAttribute.setLight( light );
                shadowTexture.setLightUnit( light.getLightNumber() );

                var material = new Material();
                var compiler = new Compiler( [ light, material, shadowAttribute ], [
                    [ shadowTexture ]
                ] );

                var root = compiler.createFragmentShaderGraph();

                var extensions = compiler.evaluateAndGatherField( root, 'extensions' );
                ok( extensions.length === 0, 'Compiler Evaluate And Gather Field: defines rightly so' );
                var defines = compiler.evaluateAndGatherField( root, 'defines' );
                ok( defines.length === 1, 'Compiler Evaluate And Gather Field: defines rightly so' );

                var globalDecl = compiler.evaluateGlobalVariableDeclaration( root );
                ok( globalDecl.length > 1, 'Compiler Evaluate Global Variables output smth' );

                globalDecl = globalDecl.split( '\n' );
                var hasDoublons = false;
                globalDecl.sort().filter( function ( item, pos ) {
                    if ( !hasDoublons && item === globalDecl[ pos - 1 ] ) hasDoublons = true;
                    return !pos || item !== globalDecl[ pos - 1 ];
                } );
                ok( !hasDoublons, 'Compiler Evaluate Global Variables Declaration output no doublons' );

                globalDecl = compiler.evaluateGlobalFunctionDeclaration( root );
                ok( globalDecl.length > 1, 'Compiler Evaluate Global Functions Declaration output smth' );

                /*
                 // sadly doesn't work as is for functions decl.
                 // needs glsl parsing...
                 var hasDoublons = false;
                 globalDecl.sort().filter( function ( item, pos ) {
                    if ( !hasDoublons && item === globalDecl[ pos - 1 ] ) hasDoublons = true;
                    return !pos || item !== globalDecl[ pos - 1 ];
                } );

                var globalDecl = compiler.evaluateGlobalFunctionDeclaration( root );
                ok( !hasDoublons, 'Compiler Evaluate Global Functions Declaration output no doublons' );
                 */

            } )();

        } );
    };
} );
<commit_msg>Adds Compiler tests: Shader Node type checks (fail if new node not abstract added without type, fail if type string isn't uniq)<commit_after>define( [
    'tests/mockup/mockup',
    'osg/Light',
    'osg/LightSource',
    'osg/Material',
    'osgShader/Compiler',
    'osgShader/nodeFactory',
    'osgShadow/ShadowAttribute',
    'osgShadow/ShadowTexture'
], function ( mockup, Light, LightSource, Material, Compiler, nodeFactory, ShadowAttribute, ShadowTexture ) {

    return function () {

        module( 'osgShader' );

        test( 'Compiler', function () {

            ( function () {

                var light = new Light( 1 );
                var lightSource = new LightSource();
                lightSource.setLight( light );
                var shadowAttribute = new ShadowAttribute();
                var shadowTexture = new ShadowTexture();
                shadowAttribute.setLight( light );
                shadowTexture.setLightUnit( light.getLightNumber() );

                var material = new Material();
                var compiler = new Compiler( [ light, material, shadowAttribute ], [
                    [ shadowTexture ]
                ] );

                var root = compiler.createFragmentShaderGraph();

                var extensions = compiler.evaluateAndGatherField( root, 'extensions' );
                ok( extensions.length === 0, 'Compiler Evaluate And Gather Field: defines rightly so' );
                var defines = compiler.evaluateAndGatherField( root, 'defines' );
                ok( defines.length === 1, 'Compiler Evaluate And Gather Field: defines rightly so' );

                var globalDecl = compiler.evaluateGlobalVariableDeclaration( root );
                ok( globalDecl.length > 1, 'Compiler Evaluate Global Variables output smth' );

                globalDecl = globalDecl.split( '\n' );
                var hasDoublons = false;
                globalDecl.sort().filter( function ( item, pos ) {
                    if ( !hasDoublons && item === globalDecl[ pos - 1 ] ) hasDoublons = true;
                    return !pos || item !== globalDecl[ pos - 1 ];
                } );
                ok( !hasDoublons, 'Compiler Evaluate Global Variables Declaration output no doublons' );

                globalDecl = compiler.evaluateGlobalFunctionDeclaration( root );
                ok( globalDecl.length > 1, 'Compiler Evaluate Global Functions Declaration output smth' );

                /*
                 // sadly doesn't work as is for functions decl.
                 // needs glsl parsing...
                 var hasDoublons = false;
                 globalDecl.sort().filter( function ( item, pos ) {
                    if ( !hasDoublons && item === globalDecl[ pos - 1 ] ) hasDoublons = true;
                    return !pos || item !== globalDecl[ pos - 1 ];
                } );

                var globalDecl = compiler.evaluateGlobalFunctionDeclaration( root );
                ok( !hasDoublons, 'Compiler Evaluate Global Functions Declaration output no doublons' );
                 */

                var nodes = nodeFactory._nodes;
                var abstractNodeList = [];
                var variableNodeList = [];
                var realNodeList = [];
                nodes.forEach( function ( value, key, map ) {
                    var instance = Object.create( value.prototype );
                    value.apply( instance );
                    var t = instance.getType();

                    if ( t && t !== '' ) {
                        realNodeList.push( t );
                    } else if ( instance._name === 'Variable' ) {
                        variableNodeList.push( instance );
                    } else {
                        abstractNodeList.push( instance );
                    }
                } );

                ok( abstractNodeList.length === 2, 'Abstract Shader Node count OK. (error here means if you added an abstract node that you need to change the number here, or if you added a new node, you forgot to add a unique type for its class MANDATORY)' );

                //
                var realNodeListUniq = realNodeList.sort().filter( function ( item, pos ) {
                    return !pos || item !== realNodeList[ pos - 1 ];
                } );
                ok( realNodeListUniq.length === realNodeList.length, 'Shader Node Type string duplicate check (type must be unique, MANDATORY for compilation)' );

            } )();

        } );
    };
} );
<|endoftext|>


<commit_before>define('app/views/machine_add_dialog', [
    'text!app/templates/machine_add_dialog.html',
    'ember'],
    /**
     *
     * Machine Add Dialog
     *
     * @returns Class
     */
    function(machine_add_dialog_html) {
        return Ember.View.extend({

            template: Ember.Handlebars.compile(machine_add_dialog_html),

            imagesBinding: 'Mist.machineAddController.newMachineBackend.images',

            openMachineAddDialog: function(){
                var that = this;

                $('.select-listmenu').listview('refresh');
                $('.dialog-add').panel('open');
                if (Mist.keysController.content.length > 0) {
                    $('div.create-key').hide();
                    $('#create-key').hide();
                    $('#machines .select-key-collapsible').css('width', '100%');
                }
                // resize dismiss div TODO: reset on window resize
                $('.ui-panel-dismiss-position-right').css('left',(0-$('.ui-panel-position-right.ui-panel-open').width()));
            },

            selectProvider: function(backend){
                $('.select-provider-collapsible').collapsible('option','collapsedIcon','check');
                $('.select-provider-collapsible span.ui-btn-text').text(backend.title);
                Mist.machineAddController.set('newMachineBackend', backend);

                Mist.machineAddController.set('newMachineImage', null);
                $('.select-image-collapsible span.ui-btn-text').text('Select Image');
                Mist.machineAddController.set('newMachineSize', null);
                Mist.machineAddController.set('newMachineCost', 0);
                $('.cost').css('display', 'none');
                $('.select-size-collapsible span.ui-btn-text').text('Select Size');
                Mist.machineAddController.set('newMachineLocation', null);
                $('.select-location-collapsible span.ui-btn-text').text('Select Location');

                $('.select-provider-collapsible').trigger('collapse');
                return false;
            },

            selectImage: function(image){
                $('.select-image-collapsible').collapsible('option','collapsedIcon','check');
                $('.select-image-collapsible span.ui-btn-text').text(image.name);
                Mist.machineAddController.set('newMachineImage', image);

                Mist.machineAddController.set('newMachineSize', null);
                Mist.machineAddController.set('newMachineCost', 0);
                $('.cost').css('display', 'none');
                $('.select-size-collapsible span.ui-btn-text').text('Select Size');

                $('.select-image-collapsible').trigger('collapse');
                return false;
            },

            getPrice: function(size, image){
            //return price, for size/image combination for EC2/Rackspace, otherwise just size
            //eg on provider Linode
                if (Mist.machineAddController.newMachineBackend.provider.indexOf('ec2') != -1){
                    if(image.name.indexOf('Red Hat') != -1){
                        return size.price.rhel;
                    } else if(image.name.indexOf('SUSE Linux Enterprise') !=-1 ){
                        return size.price.sles;
                    } else if(image.name.indexOf('SQL Server Web') !=-1 ){
                        return size.price.mswinSQLWeb;
                    } else if(image.name.indexOf('SQL Server') !=-1 ){
                        return size.price.mswinSQL;
                    } else if(image.name.indexOf('Windows') !=-1 ){
                        return size.price.mswin;
                    } else {
                        return size.price.linux;
                    }
                } else if (Mist.machineAddController.newMachineBackend.provider.indexOf('rackspace') != -1){
                    if(image.name.indexOf('Red Hat') != -1){
                        return size.price.rhel;
                    } else if(image.name.indexOf('SQL Server Web') !=-1 ){
                        return size.price.mswinSQLWeb;
                    } else if(image.name.indexOf('SQL Server') !=-1 ){
                        return size.price.mswinSQL;
                    } else if(image.name.indexOf('Windows') !=-1 ){
                        return size.price.mswin;
                    } else if(image.name.indexOf('Vyatta') !=-1 ){
                        return size.price.vyatta;
                    } else {
                        return size.price.linux;
                    }
                } else {return size.price;
                }
            },

            selectSize: function(size){
                $('.select-size-collapsible').collapsible('option','collapsedIcon','check');
                $('.select-size-collapsible span.ui-btn-text').text(size.name);
                Mist.machineAddController.set('newMachineSize', size);
                Mist.machineAddController.set('newMachineCost', this.getPrice(size, Mist.machineAddController.newMachineImage));
                $('.cost').css('display', 'block');
                Mist.machineAddController.set('newMachineLocation', null);
                $('.select-location-collapsible span.ui-btn-text').text('Select Location');
                $('.select-size-collapsible').trigger('collapse');

                if (Mist.machineAddController.newMachineBackend.locations.content.length == 1){
                    $('.select-location-collapsible').collapsible('option','collapsedIcon','check');
                    $('.select-location-collapsible span.ui-btn-text').text(Mist.machineAddController.newMachineBackend.locations.content[0].name);
                    Mist.machineAddController.set('newMachineLocation', Mist.machineAddController.newMachineBackend.locations.content[0]);
                }
                return false;
            },

            selectLocation: function(location){
                $('.select-location-collapsible').collapsible('option','collapsedIcon','check');
                $('.select-location-collapsible span.ui-btn-text').text(location.name);
                Mist.machineAddController.set('newMachineLocation', location);
                $('.select-location-collapsible').trigger('collapse');

                if (Mist.keysController.content.length == 1){
                    $('.select-key-collapsible').collapsible('option','collapsedIcon','check');
                    $('.select-key-collapsible span.ui-btn-text').text(Mist.keysController.content[0].name);
                    Mist.machineAddController.set('newMachineKey', Mist.keysController.content[0]);
                }
                return false;
            },

            selectKey: function(key){
                $('.select-key-collapsible').collapsible('option','collapsedIcon','check');
                $('.select-key-collapsible span.ui-btn-text').text(key.name);
                Mist.machineAddController.set('newMachineKey', key);
                $('.select-key-collapsible').trigger('collapse');
                return false;
            },

            clear: function(){
                Mist.machineAddController.newMachineClear();
                $('.select-provider-collapsible span.ui-btn-text').text('Select Provider');
                $('.select-image-collapsible span.ui-btn-text').text('Select Image');
                $('.select-size-collapsible span.ui-btn-text').text('Select Size');
                $('.select-location-collapsible span.ui-btn-text').text('Select Location');
                $('.select-key-collapsible span.ui-btn-text').text('Select Key');

                $('#create-machine-name').val('');

            },

            didInsertElement: function() {
                var that = this;
                this.$().bind('popupbeforeposition', function(e, data){
                    that.clear();
                });
            },

            newMachineClicked: function() {
                //FIXME there should be a way to bind the action directly to the controller
                var providerName = $('.select-provider-collapsible span.ui-btn-text').text();
                var machineName = $('#create-machine-name').val();
                if ((providerName == 'NephoScale') && ((machineName.length > 64)||(machineName.indexOf(' ') >= 0))) {
                    Mist.notificationController.timeNotify("Server name in NephoScale must start with a letter, can contain mixed alpha-numeric characters, hyphen ('-') and underscore ('_') characters, cannot exceed 64 characters, and can end with a letter or a number.", 7000);
                } else {
                    Mist.machineAddController.newMachine();
                    $('.dialog-add').panel('close');
                    Mist.Router.router.transitionTo('machines');
                    this.clear();
                }
            },

            generateKey: function() {
                $('.generate-key-collapsible .ui-icon').hide();
                $('.dialog-add .ajax-loader').show();
                var payload = {
                    'action': 'generate'
                }
                $.ajax({
                    url: '/keys',
                    type: "POST",
                    data: JSON.stringify(payload),
                    contentType: "application/json",
                    headers: { "cache-control": "no-cache" },
                    dataType: "json",
                    success: function(result) {
                        var keyName = 'auto-generated-key-' + Math.round(+new Date/1000);
                        Mist.keysController.newKey(keyName,
                                            result.public,
                                            result.private, true);
                        $('.dialog-add .ajax-loader').css('display','none');
                    }
                });
                return false;
            },

            backClicked: function() {
                this.clear();
                $('div.cost').hide();
                $('.dialog-add').panel('close');
            },

            init: function() {
                this._super();
                this.set('template', Ember.Handlebars.compile(machine_add_dialog_html));

                var that = this;

                Ember.run.next(function(){
                    $('.generate-key-collapsible h2').on('click', that.generateKey);

                    Mist.machineAddController.addObserver('newMachineBackend', function() {
                        Ember.run.next(function() {
                            $('.dialog-add .ui-collapsible ul').listview('refresh');
                        });
                    });

                    Mist.machineAddController.addObserver('newMachineReady', function() {
                        Ember.run.next(function() {
                            $('#create-ok').button();
                            if (Mist.machineAddController.newMachineReady) {
                                $('#create-machine-ok').button('enable');
                            } else {
                                $('#create-machine-ok').button('disable');
                            }
                        });
                    });

                    Mist.machineAddController.addObserver('newMachineNameReady', function() {
                        Ember.run.next(function(){
                            if (Mist.machineAddController.newMachineNameReady) {
                                $('.select-provider-collapsible').removeClass('ui-disabled');
                                if (Mist.backendsController.content.length == 1){
                                    $('.select-provider-collapsible').collapsible('option','collapsedIcon','check');
                                    $('.select-provider-collapsible span.ui-btn-text').text(Mist.backendsController.content[0].title);
                                    Mist.machineAddController.set('newMachineBackend', Mist.backendsController.content[0]);
                                }

                                $('.select-image-collapsible').addClass('ui-disabled');
                                $('.select-size-collapsible').addClass('ui-disabled');
                                $('.select-location-collapsible').addClass('ui-disabled');
                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            } else {
                                $('.select-provider-collapsible').addClass('ui-disabled');
                                $('.select-image-collapsible').addClass('ui-disabled');
                                $('.select-size-collapsible').addClass('ui-disabled');
                                $('.select-location-collapsible').addClass('ui-disabled');
                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            }
                            $('.dialog-add .ui-collapsible ul').listview('refresh');
                        });
                    });

                    Mist.machineAddController.addObserver('newMachineBackendReady', function() {
                        Ember.run.next(function(){
                            if (Mist.machineAddController.newMachineBackendReady) {
                                $('.select-image-collapsible').removeClass('ui-disabled');

                                $('.select-size-collapsible').addClass('ui-disabled');
                                $('.select-location-collapsible').addClass('ui-disabled');
                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            } else {
                                $('.select-image-collapsible').addClass('ui-disabled');
                                $('.select-size-collapsible').addClass('ui-disabled');
                                $('.select-location-collapsible').addClass('ui-disabled');
                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            }
                            $('.dialog-add .ui-collapsible ul').listview('refresh');
                        });
                    });

                    Mist.machineAddController.addObserver('newMachineImageReady', function() {
                        Ember.run.next(function(){
                            if (Mist.machineAddController.newMachineImageReady) {
                                $('.select-size-collapsible').removeClass('ui-disabled');

                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('.select-location-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            } else {
                                $('.select-size-collapsible').addClass('ui-disabled');
                                $('.select-location-collapsible').addClass('ui-disabled');
                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            }
                            $('.dialog-add .ui-collapsible ul').listview('refresh');
                        });
                    });

                    Mist.machineAddController.addObserver('newMachineSizeReady', function() {
                        Ember.run.next(function(){
                            if (Mist.machineAddController.newMachineSizeReady) {
                                $('.select-location-collapsible').removeClass('ui-disabled');

                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            } else {
                                $('.select-location-collapsible').addClass('ui-disabled');
                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            }
                            $('.dialog-add .ui-collapsible ul').listview('refresh');
                        });
                    });

                    Mist.machineAddController.addObserver('newMachineLocationReady', function() {
                        Ember.run.next(function(){
                            if (Mist.machineAddController.newMachineLocationReady) {
                                $('.select-key-collapsible').removeClass('ui-disabled');
                                $('.generate-key-collapsible').removeClass('ui-disabled');
                                $('#create-machine-script').textinput('enable');
                                $('#create-key').button('enable');
                            } else {
                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('.generate-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('enable');
                                $('#create-key').button('disable');
                            }
                        });
                    });

                    Mist.machineAddController.addObserver('newMachineKeyReady', function() {
                        Ember.run.next(function(){
                            if (Mist.machineAddController.newMachineKeyReady) {
                                $('#create-machine-ok').button('enable');
                            } else {
                                $('#create-machine-ok').button('disable');
                            }
                        });
                    });
                });
            },
        });
    }
);
<commit_msg>on create machine wizzard, set warnings for nephoscale driver if wrong input<commit_after>define('app/views/machine_add_dialog', [
    'text!app/templates/machine_add_dialog.html',
    'ember'],
    /**
     *
     * Machine Add Dialog
     *
     * @returns Class
     */
    function(machine_add_dialog_html) {
        return Ember.View.extend({

            template: Ember.Handlebars.compile(machine_add_dialog_html),

            imagesBinding: 'Mist.machineAddController.newMachineBackend.images',

            openMachineAddDialog: function(){
                var that = this;

                $('.select-listmenu').listview('refresh');
                $('.dialog-add').panel('open');
                if (Mist.keysController.content.length > 0) {
                    $('div.create-key').hide();
                    $('#create-key').hide();
                    $('#machines .select-key-collapsible').css('width', '100%');
                }
                // resize dismiss div TODO: reset on window resize
                $('.ui-panel-dismiss-position-right').css('left',(0-$('.ui-panel-position-right.ui-panel-open').width()));
            },

            selectProvider: function(backend){
                $('.select-provider-collapsible').collapsible('option','collapsedIcon','check');
                $('.select-provider-collapsible span.ui-btn-text').text(backend.title);
                Mist.machineAddController.set('newMachineBackend', backend);

                Mist.machineAddController.set('newMachineImage', null);
                $('.select-image-collapsible span.ui-btn-text').text('Select Image');
                Mist.machineAddController.set('newMachineSize', null);
                Mist.machineAddController.set('newMachineCost', 0);
                $('.cost').css('display', 'none');
                $('.select-size-collapsible span.ui-btn-text').text('Select Size');
                Mist.machineAddController.set('newMachineLocation', null);
                $('.select-location-collapsible span.ui-btn-text').text('Select Location');

                $('.select-provider-collapsible').trigger('collapse');
                return false;
            },

            selectImage: function(image){
                $('.select-image-collapsible').collapsible('option','collapsedIcon','check');
                $('.select-image-collapsible span.ui-btn-text').text(image.name);
                Mist.machineAddController.set('newMachineImage', image);

                Mist.machineAddController.set('newMachineSize', null);
                Mist.machineAddController.set('newMachineCost', 0);
                $('.cost').css('display', 'none');
                $('.select-size-collapsible span.ui-btn-text').text('Select Size');

                $('.select-image-collapsible').trigger('collapse');
                return false;
            },

            getPrice: function(size, image){
            //return price, for size/image combination for EC2/Rackspace, otherwise just size
            //eg on provider Linode
                if (Mist.machineAddController.newMachineBackend.provider.indexOf('ec2') != -1){
                    if(image.name.indexOf('Red Hat') != -1){
                        return size.price.rhel;
                    } else if(image.name.indexOf('SUSE Linux Enterprise') !=-1 ){
                        return size.price.sles;
                    } else if(image.name.indexOf('SQL Server Web') !=-1 ){
                        return size.price.mswinSQLWeb;
                    } else if(image.name.indexOf('SQL Server') !=-1 ){
                        return size.price.mswinSQL;
                    } else if(image.name.indexOf('Windows') !=-1 ){
                        return size.price.mswin;
                    } else {
                        return size.price.linux;
                    }
                } else if (Mist.machineAddController.newMachineBackend.provider.indexOf('rackspace') != -1){
                    if(image.name.indexOf('Red Hat') != -1){
                        return size.price.rhel;
                    } else if(image.name.indexOf('SQL Server Web') !=-1 ){
                        return size.price.mswinSQLWeb;
                    } else if(image.name.indexOf('SQL Server') !=-1 ){
                        return size.price.mswinSQL;
                    } else if(image.name.indexOf('Windows') !=-1 ){
                        return size.price.mswin;
                    } else if(image.name.indexOf('Vyatta') !=-1 ){
                        return size.price.vyatta;
                    } else {
                        return size.price.linux;
                    }
                } else {return size.price;
                }
            },

            selectSize: function(size){
                $('.select-size-collapsible').collapsible('option','collapsedIcon','check');
                $('.select-size-collapsible span.ui-btn-text').text(size.name);
                Mist.machineAddController.set('newMachineSize', size);
                Mist.machineAddController.set('newMachineCost', this.getPrice(size, Mist.machineAddController.newMachineImage));
                $('.cost').css('display', 'block');
                Mist.machineAddController.set('newMachineLocation', null);
                $('.select-location-collapsible span.ui-btn-text').text('Select Location');
                $('.select-size-collapsible').trigger('collapse');

                if (Mist.machineAddController.newMachineBackend.locations.content.length == 1){
                    $('.select-location-collapsible').collapsible('option','collapsedIcon','check');
                    $('.select-location-collapsible span.ui-btn-text').text(Mist.machineAddController.newMachineBackend.locations.content[0].name);
                    Mist.machineAddController.set('newMachineLocation', Mist.machineAddController.newMachineBackend.locations.content[0]);
                }
                return false;
            },

            selectLocation: function(location){
                $('.select-location-collapsible').collapsible('option','collapsedIcon','check');
                $('.select-location-collapsible span.ui-btn-text').text(location.name);
                Mist.machineAddController.set('newMachineLocation', location);
                $('.select-location-collapsible').trigger('collapse');

                if (Mist.keysController.content.length == 1){
                    $('.select-key-collapsible').collapsible('option','collapsedIcon','check');
                    $('.select-key-collapsible span.ui-btn-text').text(Mist.keysController.content[0].name);
                    Mist.machineAddController.set('newMachineKey', Mist.keysController.content[0]);
                }
                return false;
            },

            selectKey: function(key){
                $('.select-key-collapsible').collapsible('option','collapsedIcon','check');
                $('.select-key-collapsible span.ui-btn-text').text(key.name);
                Mist.machineAddController.set('newMachineKey', key);
                $('.select-key-collapsible').trigger('collapse');
                return false;
            },

            clear: function(){
                Mist.machineAddController.newMachineClear();
                $('.select-provider-collapsible span.ui-btn-text').text('Select Provider');
                $('.select-image-collapsible span.ui-btn-text').text('Select Image');
                $('.select-size-collapsible span.ui-btn-text').text('Select Size');
                $('.select-location-collapsible span.ui-btn-text').text('Select Location');
                $('.select-key-collapsible span.ui-btn-text').text('Select Key');

                $('#create-machine-name').val('');

            },

            didInsertElement: function() {
                var that = this;
                this.$().bind('popupbeforeposition', function(e, data){
                    that.clear();
                });
            },

            newMachineClicked: function() {
                //FIXME there should be a way to bind the action directly to the controller
                var providerName = $('.select-provider-collapsible span.ui-btn-text').text();
                var machineSize = $('.select-size-collapsible span.ui-btn-text').text();
                var machineImage = $('.select-image-collapsible span.ui-btn-text').text();
                var machineName = $('#create-machine-name').val();
                if (providerName == 'NephoScale') {
                    if ((machineName.length > 64)||(machineName.indexOf(' ') >= 0)) {
                        Mist.notificationController.timeNotify("Server name in NephoScale must start with a letter, can contain mixed alpha-numeric characters, hyphen ('-') and underscore ('_') characters, cannot exceed 64 characters, and can end with a letter or a number.", 7000);
                        return false;
                    } else if (machineSize.indexOf('CS025') != -1) {
                          if (!((machineImage == 'Linux Ubuntu Server 10.04 LTS 64-bit') || (machineImage =='Linux CentOS 6.2 64-bit'))) {
                              Mist.notificationController.timeNotify("On CS025 size you can only create one of the two images: Linux Ubuntu Server 10.04 LTS 64-bit or Linux CentOS 6.2 64-bit", 10000);
                              return false;
                          }
                    }
                }
                Mist.machineAddController.newMachine();
                $('.dialog-add').panel('close');
                Mist.Router.router.transitionTo('machines');
                this.clear();
            },

            generateKey: function() {
                $('.generate-key-collapsible .ui-icon').hide();
                $('.dialog-add .ajax-loader').show();
                var payload = {
                    'action': 'generate'
                }
                $.ajax({
                    url: '/keys',
                    type: "POST",
                    data: JSON.stringify(payload),
                    contentType: "application/json",
                    headers: { "cache-control": "no-cache" },
                    dataType: "json",
                    success: function(result) {
                        var keyName = 'auto-generated-key-' + Math.round(+new Date/1000);
                        Mist.keysController.newKey(keyName,
                                            result.public,
                                            result.private, true);
                        $('.dialog-add .ajax-loader').css('display','none');
                    }
                });
                return false;
            },

            backClicked: function() {
                this.clear();
                $('div.cost').hide();
                $('.dialog-add').panel('close');
            },

            init: function() {
                this._super();
                this.set('template', Ember.Handlebars.compile(machine_add_dialog_html));

                var that = this;

                Ember.run.next(function(){
                    $('.generate-key-collapsible h2').on('click', that.generateKey);

                    Mist.machineAddController.addObserver('newMachineBackend', function() {
                        Ember.run.next(function() {
                            $('.dialog-add .ui-collapsible ul').listview('refresh');
                        });
                    });

                    Mist.machineAddController.addObserver('newMachineReady', function() {
                        Ember.run.next(function() {
                            $('#create-ok').button();
                            if (Mist.machineAddController.newMachineReady) {
                                $('#create-machine-ok').button('enable');
                            } else {
                                $('#create-machine-ok').button('disable');
                            }
                        });
                    });

                    Mist.machineAddController.addObserver('newMachineNameReady', function() {
                        Ember.run.next(function(){
                            if (Mist.machineAddController.newMachineNameReady) {
                                $('.select-provider-collapsible').removeClass('ui-disabled');
                                if (Mist.backendsController.content.length == 1){
                                    $('.select-provider-collapsible').collapsible('option','collapsedIcon','check');
                                    $('.select-provider-collapsible span.ui-btn-text').text(Mist.backendsController.content[0].title);
                                    Mist.machineAddController.set('newMachineBackend', Mist.backendsController.content[0]);
                                }

                                $('.select-image-collapsible').addClass('ui-disabled');
                                $('.select-size-collapsible').addClass('ui-disabled');
                                $('.select-location-collapsible').addClass('ui-disabled');
                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            } else {
                                $('.select-provider-collapsible').addClass('ui-disabled');
                                $('.select-image-collapsible').addClass('ui-disabled');
                                $('.select-size-collapsible').addClass('ui-disabled');
                                $('.select-location-collapsible').addClass('ui-disabled');
                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            }
                            $('.dialog-add .ui-collapsible ul').listview('refresh');
                        });
                    });

                    Mist.machineAddController.addObserver('newMachineBackendReady', function() {
                        Ember.run.next(function(){
                            if (Mist.machineAddController.newMachineBackendReady) {
                                $('.select-image-collapsible').removeClass('ui-disabled');

                                $('.select-size-collapsible').addClass('ui-disabled');
                                $('.select-location-collapsible').addClass('ui-disabled');
                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            } else {
                                $('.select-image-collapsible').addClass('ui-disabled');
                                $('.select-size-collapsible').addClass('ui-disabled');
                                $('.select-location-collapsible').addClass('ui-disabled');
                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            }
                            $('.dialog-add .ui-collapsible ul').listview('refresh');
                        });
                    });

                    Mist.machineAddController.addObserver('newMachineImageReady', function() {
                        Ember.run.next(function(){
                            if (Mist.machineAddController.newMachineImageReady) {
                                $('.select-size-collapsible').removeClass('ui-disabled');

                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('.select-location-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            } else {
                                $('.select-size-collapsible').addClass('ui-disabled');
                                $('.select-location-collapsible').addClass('ui-disabled');
                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            }
                            $('.dialog-add .ui-collapsible ul').listview('refresh');
                        });
                    });

                    Mist.machineAddController.addObserver('newMachineSizeReady', function() {
                        Ember.run.next(function(){
                            if (Mist.machineAddController.newMachineSizeReady) {
                                $('.select-location-collapsible').removeClass('ui-disabled');

                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            } else {
                                $('.select-location-collapsible').addClass('ui-disabled');
                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('disable');
                            }
                            $('.dialog-add .ui-collapsible ul').listview('refresh');
                        });
                    });

                    Mist.machineAddController.addObserver('newMachineLocationReady', function() {
                        Ember.run.next(function(){
                            if (Mist.machineAddController.newMachineLocationReady) {
                                $('.select-key-collapsible').removeClass('ui-disabled');
                                $('.generate-key-collapsible').removeClass('ui-disabled');
                                $('#create-machine-script').textinput('enable');
                                $('#create-key').button('enable');
                            } else {
                                $('.select-key-collapsible').addClass('ui-disabled');
                                $('.generate-key-collapsible').addClass('ui-disabled');
                                $('#create-machine-script').textinput('enable');
                                $('#create-key').button('disable');
                            }
                        });
                    });

                    Mist.machineAddController.addObserver('newMachineKeyReady', function() {
                        Ember.run.next(function(){
                            if (Mist.machineAddController.newMachineKeyReady) {
                                $('#create-machine-ok').button('enable');
                            } else {
                                $('#create-machine-ok').button('disable');
                            }
                        });
                    });
                });
            },
        });
    }
);
<|endoftext|>


<commit_before>/* Check LICENSE for details. Developed by Oratio.io */

//Node.js Standard Modules
var vm = require('vm');

//Global Variables
var _handlers = {};

global.process.handle = function(message, callback){
  _handlers[message] = callback;
}

process.on('message', function(message){
  if(message.type === 'init'){
    if(message.isSafe)
      global.require = require;

    vm.runInThisContext(message.code, {timeout: message.timeout, displayErrors: true});
    return;
  }

  if(message.type === 'contact'){
    function callbackHandler(returned){
      process.send({listener: message.listener, id: message.id, message: returned});
    }

    return _handlers[message.handler](message.value, callbackHandler);
  }

  throw new Error('This kind of message isn\'t currently accepted.')
})
<commit_msg>Update child.js<commit_after>/* Check LICENSE for details. Developed by Oratio.io */

//Node.js Standard Modules
var vm = require('vm');

//Global Variables
var isReady = false;
var _handlers = {};

global.process.handle = function(message, callback){
  _handlers[message] = callback;
}

global.process.handle('__isReady', function(value, done){
  done(isReady);
});

process.on('message', function(message){
  if(message.type === 'init'){
    if(message.isSafe)
      global.require = require;

    vm.runInThisContext(message.code, {timeout: message.timeout, displayErrors: true});
    isReady = true;
    return;
  }

  if(message.type === 'contact'){
    function callbackHandler(returned){
      process.send({listener: message.listener, id: message.id, message: returned});
    }

    return _handlers[message.handler](message.value, callbackHandler);
  }

  throw new Error('This kind of message isn\'t currently accepted.')
})
<|endoftext|>


<commit_before>"use strict";

var chai = require("chai");
var os = require("os");
var path = require("path");
var sh = require("shelljs");

var copyBabelrc = require("../util/copy-babelrc");
var copyTitorrc = require("../util/copy-titorrc");
var detectBuild = require("../util/detect-build");
var loadConfig = require("../util/load-config");

var expect = chai.expect;

var resource = path.join(__dirname, "resource");
var tmpRoot = path.join(os.tmpdir(), "titor-test-root");

describe("util", function () {
  beforeEach(function () {
    if (sh.test("-e", tmpRoot)) sh.rm("-rf", tmpRoot);
    sh.mkdir(tmpRoot);
    sh.cd(tmpRoot);
  });

  afterEach(function () {
    sh.cd(__dirname);
    sh.rm("-rf", tmpRoot);
  });

  describe("copyBabelrc", function () {
    var tmpBabelrc = path.join(tmpRoot, ".babelrc");

    it("should copy .babelrc to project root and return true", function () {
      expect(copyBabelrc()).to.be.true;
      expect(sh.test("-e", tmpBabelrc)).to.be.true;
    });

    it("should, if .babelrc already exists, return false", function () {
      copyBabelrc();

      expect(copyBabelrc()).to.be.false;
    });
  });

  describe("copyTitorrc", function () {
    var tmpTitorrc = path.join(tmpRoot, ".titorrc");
    var tmpPackageJson = path.join(tmpRoot, "package.json");
    var goodPackageJson = path.join(resource, "good.package.json");
    var badFormatPackageJson = path.join(resource, "bad-format.package.json");
    var badNamePackageJson = path.join(resource, "bad-name.package.json");

    beforeEach(function () {
      sh.cp(goodPackageJson, tmpPackageJson);
    });

    it("should copy .titorrc to project root, replace PLACEHOLDER with project"
     + " name converted to CamelCase, and return true", function () {
      expect(copyTitorrc()).to.be.true;
      expect(sh.test("-e", tmpTitorrc)).to.be.true;
      expect(sh.grep("testProject", tmpTitorrc)).to.match(/testProject/);
    });

    it("should, if .titorrc already exists, return false", function () {
      copyTitorrc();

      expect(copyTitorrc()).to.be.false;
    });

    it("should, if no package.json, throw", function () {
      sh.rm(tmpPackageJson);

      expect(copyTitorrc).to.throw(/no such file/);
    });

    it("should, if invalid package.json, throw", function () {
      sh.cp(badFormatPackageJson, tmpPackageJson);

      expect(copyTitorrc).to.throw(/Unexpected token/);
    });

    it("should, if missing name in package.json, throw", function () {
      sh.cp(badNamePackageJson, tmpPackageJson);

      expect(copyTitorrc).to.throw("Missing name in package.json");
    });
  });

  describe("detectBuild", function () {
    it("should, if node version is equal to minNodeVer, return 'current'",
    function () {
      expect(detectBuild(process.version)).to.equal("current");
    });

    it("should, if node version is greater than minNodeVer, return 'current'",
    function () {
      expect(detectBuild("v0.0.1")).to.equal("current");
    });

    it("should, if node version is less than minNodeVer, return 'legacy'",
    function () {
      expect(detectBuild("v999.99.99")).to.equal("legacy");
    });

    it("should, if minNodeVer is invalid, throw", function () {
      expect(function () { detectBuild("nacho cheese") })
        .to.throw("Invalid Version: nacho cheese");
    });
  });

  describe("loadConfig", function () {
    var tmpTitorrc = path.join(tmpRoot, ".titorrc");
    var goodTitorrc = path.join(resource, "good.titorrc");
    var badFormatTitorrc = path.join(resource, "bad-format.titorrc");
    var badExportTitorrc = path.join(resource, "bad-export.titorrc");

    beforeEach(function () {
      sh.cp(goodTitorrc, tmpTitorrc);
    });

    it("should return a config object", function () {
      expect(loadConfig()).to.be.an("object").with.property("export");
    });

    it("should, if no .titorrc, throw", function () {
      sh.rm(tmpTitorrc);

      expect(loadConfig).to.throw(/no such file/);
    });

    it("should, if invalid .titorrc, throw", function () {
      sh.cp(badFormatTitorrc, tmpTitorrc);

      expect(loadConfig).to.throw("Invalid .titorrc");
    });

    it("should, if invalid export, throw", function () {
      sh.cp(badExportTitorrc, tmpTitorrc);

      expect(loadConfig).to.throw(/Invalid or missing export/);
    });
  });
});
<commit_msg>Use shelljs instead of os tempdir for consistency<commit_after>"use strict";

var chai = require("chai");
var path = require("path");
var sh = require("shelljs");

var copyBabelrc = require("../util/copy-babelrc");
var copyTitorrc = require("../util/copy-titorrc");
var detectBuild = require("../util/detect-build");
var loadConfig = require("../util/load-config");

var expect = chai.expect;

var resource = path.join(__dirname, "resource");
var tmpRoot = path.join(sh.tempdir(), "titor-test-root");

describe("util", function () {
  beforeEach(function () {
    if (sh.test("-e", tmpRoot)) sh.rm("-rf", tmpRoot);
    sh.mkdir(tmpRoot);
    sh.cd(tmpRoot);
  });

  afterEach(function () {
    sh.cd(__dirname);
    sh.rm("-rf", tmpRoot);
  });

  describe("copyBabelrc", function () {
    var tmpBabelrc = path.join(tmpRoot, ".babelrc");

    it("should copy .babelrc to project root and return true", function () {
      expect(copyBabelrc()).to.be.true;
      expect(sh.test("-e", tmpBabelrc)).to.be.true;
    });

    it("should, if .babelrc already exists, return false", function () {
      copyBabelrc();

      expect(copyBabelrc()).to.be.false;
    });
  });

  describe("copyTitorrc", function () {
    var tmpTitorrc = path.join(tmpRoot, ".titorrc");
    var tmpPackageJson = path.join(tmpRoot, "package.json");
    var goodPackageJson = path.join(resource, "good.package.json");
    var badFormatPackageJson = path.join(resource, "bad-format.package.json");
    var badNamePackageJson = path.join(resource, "bad-name.package.json");

    beforeEach(function () {
      sh.cp(goodPackageJson, tmpPackageJson);
    });

    it("should copy .titorrc to project root, replace PLACEHOLDER with project"
     + " name converted to CamelCase, and return true", function () {
      expect(copyTitorrc()).to.be.true;
      expect(sh.test("-e", tmpTitorrc)).to.be.true;
      expect(sh.grep("testProject", tmpTitorrc)).to.match(/testProject/);
    });

    it("should, if .titorrc already exists, return false", function () {
      copyTitorrc();

      expect(copyTitorrc()).to.be.false;
    });

    it("should, if no package.json, throw", function () {
      sh.rm(tmpPackageJson);

      expect(copyTitorrc).to.throw(/no such file/);
    });

    it("should, if invalid package.json, throw", function () {
      sh.cp(badFormatPackageJson, tmpPackageJson);

      expect(copyTitorrc).to.throw(/Unexpected token/);
    });

    it("should, if missing name in package.json, throw", function () {
      sh.cp(badNamePackageJson, tmpPackageJson);

      expect(copyTitorrc).to.throw("Missing name in package.json");
    });
  });

  describe("detectBuild", function () {
    it("should, if node version is equal to minNodeVer, return 'current'",
    function () {
      expect(detectBuild(process.version)).to.equal("current");
    });

    it("should, if node version is greater than minNodeVer, return 'current'",
    function () {
      expect(detectBuild("v0.0.1")).to.equal("current");
    });

    it("should, if node version is less than minNodeVer, return 'legacy'",
    function () {
      expect(detectBuild("v999.99.99")).to.equal("legacy");
    });

    it("should, if minNodeVer is invalid, throw", function () {
      expect(function () { detectBuild("nacho cheese") })
        .to.throw("Invalid Version: nacho cheese");
    });
  });

  describe("loadConfig", function () {
    var tmpTitorrc = path.join(tmpRoot, ".titorrc");
    var goodTitorrc = path.join(resource, "good.titorrc");
    var badFormatTitorrc = path.join(resource, "bad-format.titorrc");
    var badExportTitorrc = path.join(resource, "bad-export.titorrc");

    beforeEach(function () {
      sh.cp(goodTitorrc, tmpTitorrc);
    });

    it("should return a config object", function () {
      expect(loadConfig()).to.be.an("object").with.property("export");
    });

    it("should, if no .titorrc, throw", function () {
      sh.rm(tmpTitorrc);

      expect(loadConfig).to.throw(/no such file/);
    });

    it("should, if invalid .titorrc, throw", function () {
      sh.cp(badFormatTitorrc, tmpTitorrc);

      expect(loadConfig).to.throw("Invalid .titorrc");
    });

    it("should, if invalid export, throw", function () {
      sh.cp(badExportTitorrc, tmpTitorrc);

      expect(loadConfig).to.throw(/Invalid or missing export/);
    });
  });
});
<|endoftext|>


<commit_before>'use strict';

module.exports = function(grunt) {
  // Show elapsed time at the end
  require('time-grunt')(grunt);
  // Load all grunt tasks
  require('load-grunt-tasks')(grunt);

  // Project configuration.
  grunt.initConfig({
    jshint: {
      options: {
        jshintrc: '.jshintrc',
        reporter: require('jshint-stylish')
      },
      gruntfile: {
        src: 'Gruntfile.js'
      },
      lib: {
        src: ['lib/**/*.js']
      },
      test: {
        src: ['test/**/*.js']
      }
    },
    watch: {
      gruntfile: {
        files: '<%= jshint.gruntfile.src %>',
        tasks: ['jshint:gruntfile']
      },
      lib: {
        files: '<%= jshint.lib.src %>',
        tasks: ['jshint:lib']
      },
      test: {
        files: '<%= jshint.test.src %>',
        tasks: ['jshint:test']
      }
    },
    karma: {
      options: {
        configFile: 'karma.conf.js'
      },
      dev: {
        autoWatch: true,
        browsers: ['Firefox', 'Chrome', 'PhantomJS']
      },
      build: {
        singleRun: true,
        browsers: ['PhantomJS']
      }
    },
    concurrent: {
      dev: {
        tasks: ['watch', 'karma:dev'],
        options: {
          logConcurrentOutput: true
        }
      }
    },
    bump: {
      options: {
        commitFiles: ['package.json', 'CHANGELOG.md'],
        pushTo: 'origin'
      }
    },
    changelog: {
      options: {

      }
    }
  });

  grunt.registerTask('dev', ['concurrent:dev']);

  // Default task.
  grunt.registerTask('default', ['jshint', 'karma:build']);

  grunt.registerTask('release', 'Alias for "bump-only", "changelog", and "bump-commit" tasks.', function (versionType) {
    grunt.task.run('bump-only' + (versionType ? ':' + versionType : ''));
    grunt.task.run('default');
    grunt.task.run('changelog');
    grunt.task.run('bump-commit');
  });

};
<commit_msg>chore(Gruntfile.js): update conventionalChangelog config<commit_after>'use strict';

module.exports = function(grunt) {
  // Show elapsed time at the end
  require('time-grunt')(grunt);
  // Load all grunt tasks
  require('load-grunt-tasks')(grunt);

  // Project configuration.
  grunt.initConfig({
    jshint: {
      options: {
        jshintrc: '.jshintrc',
        reporter: require('jshint-stylish')
      },
      gruntfile: {
        src: 'Gruntfile.js'
      },
      lib: {
        src: ['lib/**/*.js']
      },
      test: {
        src: ['test/**/*.js']
      }
    },
    watch: {
      gruntfile: {
        files: '<%= jshint.gruntfile.src %>',
        tasks: ['jshint:gruntfile']
      },
      lib: {
        files: '<%= jshint.lib.src %>',
        tasks: ['jshint:lib']
      },
      test: {
        files: '<%= jshint.test.src %>',
        tasks: ['jshint:test']
      }
    },
    karma: {
      options: {
        configFile: 'karma.conf.js'
      },
      dev: {
        autoWatch: true,
        browsers: ['Firefox', 'Chrome', 'PhantomJS']
      },
      build: {
        singleRun: true,
        browsers: ['PhantomJS']
      }
    },
    concurrent: {
      dev: {
        tasks: ['watch', 'karma:dev'],
        options: {
          logConcurrentOutput: true
        }
      }
    },
    bump: {
      options: {
        commitFiles: ['package.json', 'CHANGELOG.md'],
        pushTo: 'origin'
      }
    },
    conventionalChangelog: {
      options: {
        changelogOpts: {
          preset: 'angular'
        }
      },
      release: {
        src: 'CHANGELOG.md'
      }
    }
  });

  grunt.registerTask('dev', ['concurrent:dev']);

  // Default task.
  grunt.registerTask('default', ['jshint', 'karma:build']);

  grunt.registerTask('release', 'Alias for "bump-only", "conventionalChangelog", and "bump-commit" tasks.', function (versionType) {
    grunt.task.run('bump-only' + (versionType ? ':' + versionType : ''));
    grunt.task.run('default');
    grunt.task.run('changelog');
    grunt.task.run('bump-commit');
  });

};
<|endoftext|>


<commit_before>'use strict';

module.exports = function (grunt) {

    require('load-grunt-tasks')(grunt);
    require('time-grunt')(grunt);

    var serveStatic = require('serve-static'),
        path = require('path'),
        tmp = '.tmp'

    var config = {
        hosts: {
            runtime: 'localhost',
            fqdn: 'localhost',
            seleniumAddress: 'http://localhost:4444/wd/hub'
        },
        paths: {
            tmp: tmp,
            src: 'src',
            test: 'test',
            results: tmp + '/results',
            instrumented: tmp + '/instrumented',
            config: 'config',
            build: 'dist'
        }
    };

    grunt.initConfig({
        config: config,
        clean: {
            files: [
                '<%=config.paths.tmp%>'
            ]
        },
        instrument: {
            files: '<%=config.paths.src%>/**/*.js',
            options: {
                basePath: '<%=config.paths.instrumented%>',
                lazy: false
            }
        },
        portPick: {
            options: {
                port: 9900,
                limit: 9,
            },
            connectSource: {
                targets: [
                    'connect.source.options.port'
                ]
            },
            connectTest: {
                targets: [
                    'connect.test.options.port'
                ]
            },
            watch: {
                targets: [
                    'watch.options.livereload',
                    'connect.source.options.livereload',
                ]
            },
            protractorJasmine: {
                targets: [
                    'protractor_coverage.jasmine2.options.collectorPort'
                ]
            },
            protractorCucumber: {
                targets: [
                    'protractor_coverage.cucumber.options.collectorPort',
                    'protractor_coverage.cucumber.options.args.params.collectorPort'
                ]
            }
        },
        connect: {
            options: {
                hostname: '*',
                useAvailablePort: true
            },
            runtime: {
                options: {
                    port: 0,
                    open: true,
                    livereload: 0,
                    middleware: function (connect) {
                        grunt.log.ok('Mocking has been enabled and can located at /mocking');
                        return [
                            connect().use('/node_modules', serveStatic(__dirname + '/node_modules')),
                            connect().use('/mocking', serveStatic(config.paths.tmp + '/mocking')),
                            connect().use('/', serveStatic(config.paths.test + '/protractor')),
                            connect().use('/', serveStatic(config.paths.src)),
                            connect().use('/', serveStatic(config.paths.tmp))
                        ];
                    }
                }
            },
            test: {
                options: {
                    port: 0,
                    open: false,
                    middleware: function (connect) {
                        return [
                            connect().use('/node_modules', serveStatic(__dirname + '/node_modules')),
                            connect().use('/js', serveStatic(config.paths.instrumented + '/src/js')),
                            connect().use('/', serveStatic(config.paths.src)),
                            connect().use('/', serveStatic(config.paths.test + '/protractor')),
                        ];
                    }
                }
            },
            distribution: {
                options: {
                    port: 0,
                    open: true,
                    middleware: function (connect) {
                        return [
                            connect().use('/', serveStatic(config.paths.dist))
                        ];
                    }
                }
            }
        },
        ngApimock : {
            options: {
                defaultOutputDir: '<%= config.paths.tmp %>/mocking',
                defaultPassThrough: []
            },
            mock: {
                src: '<%=config.paths.test %>/mocks',
                moduleName: 'todo',
                dependencies: {
                    angular: '/node_modules/angular/angular.js'
                }
            }
        },
        jshint: {
            report: {
                options: {
                    jshintrc: '.jshintrc',
                    reporter: require('jshint-stylish')
                },
                files: {
                    src: ['<%= config.paths.src %>/**/*.js']
                }
            }

        },
        protractor_coverage: {
            options: {
                keepAlive: true,
                noColor: false,
            },
            jasmine2: {
                options: {
                    collectorPort: 0,
                    coverageDir: '<%=config.paths.results%>/protractor-coverage/jasmine2',
                    args: {
                        seleniumAddress: '<%=config.hosts.seleniumAddress%>',
                        params: {
                            resultsDir: '<%=config.paths.results%>/protractor/jasmine2',
                            testDir: '<%=config.paths.test%>/protractor'
                        },
                        baseUrl: 'http://<%=config.hosts.fqdn%>:<%= connect.test.options.port %>',
                        specs: [
                            '<%=config.paths.test%>/protractor/specs/**/*.spec.js'
                        ]
                    }
                },
                configFile: '<%=config.paths.test%>/protractor/config/protractor-jasmine2.conf.js'
            },
            cucumber: {
                options: {
                    collectorPort: 0,
                    noInject: true,
                    coverageDir: '<%=config.paths.results%>/protractor-coverage/cucumber',
                    args: {
                        seleniumAddress: '<%=config.hosts.seleniumAddress%>',
                        params: {
                            resultsDir: '<%=config.paths.results%>/protractor/cucumber',
                            testDir: '<%=config.paths.test%>/protractor',
                            collectorPort: 0
                        },
                        baseUrl: 'http://<%=config.hosts.fqdn%>:<%= connect.test.options.port %>',
                        specs: [
                            '<%=config.paths.test%>/protractor/specs/**/*.feature'
                        ]
                    }
                },
                configFile: '<%=config.paths.test%>/protractor/config/protractor-cucumber.conf.js'
            }
        },
        makeReport: {
            src: '<%=config.paths.results%>/protractor-coverage/**/*.json',
            options: {
                type: 'lcov',
                dir: '<%=config.paths.results%>/protractor-coverage',
                print: 'detail'
            }
        },
        watch: {
            js: {
                files: ['<%=config.paths.src%>/{,*/}*.js']
            },
            html: {
                files: ['<%=config.paths.src%>/index.html']
            }
        }
    });

    grunt.registerTask('serve', 'Serve the app using the distribution .', [
        'prepare',
        'connect:runtime',
        'watch'
    ]);

    grunt.registerTask('prepare', 'Prepare the build with all the necessary stuff.', [
        'clean',
        'portPick',
        'ngApimock'
    ]);

    grunt.registerTask('test', 'Execute tests.', [
        'force:on',
        'jshint',
        'instrument',
        'connect:test',
        'protractor_coverage',
        'makeReport',
        'force:reset'
    ]);

    grunt.registerTask('default', 'Default task', function (suite) {
        grunt.task.run([
            'prepare',
            'test'
        ]);
    });
};<commit_msg>syntax fixes<commit_after>'use strict';

module.exports = function (grunt) {

    require('load-grunt-tasks')(grunt);
    require('time-grunt')(grunt);

    var serveStatic = require('serve-static'),
        path = require('path'),
        tmp = '.tmp';

    var config = {
        hosts: {
            runtime: 'localhost',
            fqdn: 'localhost',
            seleniumAddress: 'http://localhost:4444/wd/hub'
        },
        paths: {
            tmp: tmp,
            src: 'src',
            test: 'test',
            results: tmp + '/results',
            instrumented: tmp + '/instrumented',
            config: 'config',
            build: 'dist'
        }
    };

    grunt.initConfig({
        config: config,
        clean: {
            files: [
                '<%=config.paths.tmp%>'
            ]
        },
        instrument: {
            files: '<%=config.paths.src%>/**/*.js',
            options: {
                basePath: '<%=config.paths.instrumented%>',
                lazy: false
            }
        },
        portPick: {
            options: {
                port: 9900,
                limit: 9
            },
            connectSource: {
                targets: [
                    'connect.source.options.port'
                ]
            },
            connectTest: {
                targets: [
                    'connect.test.options.port'
                ]
            },
            watch: {
                targets: [
                    'watch.options.livereload',
                    'connect.source.options.livereload',
                ]
            },
            protractorJasmine: {
                targets: [
                    'protractor_coverage.jasmine2.options.collectorPort'
                ]
            },
            protractorCucumber: {
                targets: [
                    'protractor_coverage.cucumber.options.collectorPort',
                    'protractor_coverage.cucumber.options.args.params.collectorPort'
                ]
            }
        },
        connect: {
            options: {
                hostname: '*',
                useAvailablePort: true
            },
            runtime: {
                options: {
                    port: 0,
                    open: true,
                    livereload: 0,
                    middleware: function (connect) {
                        grunt.log.ok('Mocking has been enabled and can located at /mocking');
                        return [
                            connect().use('/node_modules', serveStatic(__dirname + '/node_modules')),
                            connect().use('/mocking', serveStatic(config.paths.tmp + '/mocking')),
                            connect().use('/', serveStatic(config.paths.test + '/protractor')),
                            connect().use('/', serveStatic(config.paths.src)),
                            connect().use('/', serveStatic(config.paths.tmp))
                        ];
                    }
                }
            },
            test: {
                options: {
                    port: 0,
                    open: false,
                    middleware: function (connect) {
                        return [
                            connect().use('/node_modules', serveStatic(__dirname + '/node_modules')),
                            connect().use('/mocking', serveStatic(config.paths.tmp + '/mocking')),
                            connect().use('/js', serveStatic(config.paths.instrumented + '/src/js')),
                            connect().use('/', serveStatic(config.paths.src)),
                            connect().use('/', serveStatic(config.paths.test + '/protractor')),
                        ];
                    }
                }
            },
            distribution: {
                options: {
                    port: 0,
                    open: true,
                    middleware: function (connect) {
                        return [
                            connect().use('/', serveStatic(config.paths.dist))
                        ];
                    }
                }
            }
        },
        ngApimock : {
            options: {
                defaultOutputDir: '<%= config.paths.tmp %>/mocking',
                defaultPassThrough: []
            },
            mock: {
                src: '<%=config.paths.test %>/mocks',
                moduleName: 'todo',
                dependencies: {
                    angular: '/node_modules/angular/angular.js'
                }
            }
        },
        jshint: {
            report: {
                options: {
                    jshintrc: '.jshintrc',
                    reporter: require('jshint-stylish')
                },
                files: {
                    src: ['<%= config.paths.src %>/**/*.js']
                }
            }

        },
        protractor_coverage: {
            options: {
                keepAlive: true,
                noColor: false
            },
            jasmine2: {
                options: {
                    collectorPort: 0,
                    coverageDir: '<%=config.paths.results%>/protractor-coverage/jasmine2',
                    args: {
                        seleniumAddress: '<%=config.hosts.seleniumAddress%>',
                        params: {
                            resultsDir: '<%=config.paths.results%>/protractor/jasmine2',
                            testDir: '<%=config.paths.test%>/protractor'
                        },
                        baseUrl: 'http://<%=config.hosts.fqdn%>:<%= connect.test.options.port %>',
                        specs: [
                            '<%=config.paths.test%>/protractor/specs/**/*.spec.js'
                        ]
                    }
                },
                configFile: '<%=config.paths.test%>/protractor/config/protractor-jasmine2.conf.js'
            },
            cucumber: {
                options: {
                    collectorPort: 0,
                    noInject: true,
                    coverageDir: '<%=config.paths.results%>/protractor-coverage/cucumber',
                    args: {
                        seleniumAddress: '<%=config.hosts.seleniumAddress%>',
                        params: {
                            resultsDir: '<%=config.paths.results%>/protractor/cucumber',
                            testDir: '<%=config.paths.test%>/protractor',
                            collectorPort: 0
                        },
                        baseUrl: 'http://<%=config.hosts.fqdn%>:<%= connect.test.options.port %>',
                        specs: [
                            '<%=config.paths.test%>/protractor/specs/**/*.feature'
                        ]
                    }
                },
                configFile: '<%=config.paths.test%>/protractor/config/protractor-cucumber.conf.js'
            }
        },
        makeReport: {
            src: '<%=config.paths.results%>/protractor-coverage/**/*.json',
            options: {
                type: 'lcov',
                dir: '<%=config.paths.results%>/protractor-coverage',
                print: 'detail'
            }
        },
        watch: {
            js: {
                files: ['<%=config.paths.src%>/{,*/}*.js']
            },
            html: {
                files: ['<%=config.paths.src%>/index.html']
            }
        }
    });

    grunt.registerTask('serve', 'Serve the app using the distribution .', [
        'prepare',
        'connect:runtime',
        'watch'
    ]);

    grunt.registerTask('prepare', 'Prepare the build with all the necessary stuff.', [
        'clean',
        'portPick',
        'ngApimock'
    ]);

    grunt.registerTask('test', 'Execute tests.', [
        'force:on',
        'jshint',
        'instrument',
        'connect:test',
        'protractor_coverage',
        'makeReport',
        'force:reset'
    ]);

    grunt.registerTask('default', 'Default task', function (suite) {
        grunt.task.run([
            'prepare',
            'test'
        ]);
    });
};<|endoftext|>