<commit_before>$(function() {
	'use strict';

	module('PowerTip Core');

	test('powerTip defined', function() {
		var element = $('');
		strictEqual(typeof element.powerTip, 'function', 'powerTip is defined');
	});

	test('expose default settings', function() {
		ok($.fn.powerTip.defaults, 'defaults is defined');
		ok($.fn.powerTip.defaults.hasOwnProperty('fadeInTime'), 'fadeInTime exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('fadeOutTime'), 'fadeOutTime exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('followMouse'), 'followMouse exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('popupId'), 'popupId exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('intentSensitivity'), 'intentSensitivity exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('intentPollInterval'), 'intentPollInterval exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('closeDelay'), 'closeDelay exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('placement'), 'placement exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('smartPlacement'), 'smartPlacement exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('offset'), 'offset exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('mouseOnToPopup'), 'mouseOnToPopup exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('manual'), 'manual exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('openEvents'), 'openEvents exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('closeEvents'), 'closeEvents exists');
	});

	test('expose smart placement lists', function() {
		ok($.fn.powerTip.smartPlacementLists, 'smartPlacementLists is defined');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('n'), 'n exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('e'), 'e exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('s'), 's exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('w'), 'w exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('ne'), 'ne exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('nw'), 'nw exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('se'), 'se exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('sw'), 'sw exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('ne-alt'), 'ne-alt exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('nw-alt'), 'nw-alt exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('se-alt'), 'se-alt exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('sw-alt'), 'sw-alt exists');
	});

	test('powerTip', function() {
		var div = $('
'),
			empty = $('#thisDoesntExist'),
			element = $('').powerTip();

		deepEqual(div.powerTip(), div, 'original jQuery object returned for matched selector');
		deepEqual(empty.powerTip(), empty, 'original jQuery object returned for empty selector');
		deepEqual(div.powerTip('show'), div, 'original jQuery object returned for show');
		deepEqual(div.powerTip('hide'), div, 'original jQuery object returned for hide');
		deepEqual(div.powerTip('toggle'), div, 'original jQuery object returned for toggle');
		deepEqual(div.powerTip('resetPosition'), div, 'original jQuery object returned for resetPosition');
		deepEqual(div.powerTip('destroy'), div, 'original jQuery object returned for destroy');
		ok(!element.attr('title'), 'title attribute was removed');
		ok(element.data(DATA_DISPLAYCONTROLLER), 'new DisplayController created and added to data');
	});

	test('powerTip hooks events', function() {
		var element = $('TEXT').powerTip(),
			showTriggered = false,
			hideTriggered = false;

		element.data(
			DATA_DISPLAYCONTROLLER,
			new MockDisplayController(
				function() {
					showTriggered = true;
				},
				function() {
					hideTriggered = true;
				}
			)
		);

		// jquery 1.9 will not trigger a focus event on an element that cannot
		// be focused, so we have to append the test element to the document
		// before the focus test will work
		$('body').prepend(element);

		element.trigger($.Event('mouseenter', { pageX: 10, pageY: 10 }));
		ok(showTriggered, 'mouseenter event calls DisplayController.show');
		showTriggered = false;

		element.trigger('mouseleave');
		ok(hideTriggered, 'mouseleave event calls DisplayController.hide');
		hideTriggered = false;

		element.trigger('focus');
		ok(showTriggered, 'focus event calls DisplayController.show');
		showTriggered = false;

		element.trigger('blur');
		ok(hideTriggered, 'blur event calls DisplayController.hide');
		hideTriggered = false;

		element.trigger($.Event('keydown', { keyCode: 27 }));
		ok(hideTriggered, 'keydown event for key code 27 calls DisplayController.hide');
		hideTriggered = false;

		// cleanup test element
		element.remove();
	});

	test('expose API', function() {
		strictEqual(typeof $.powerTip.show, 'function', 'show is defined');
		strictEqual(typeof $.powerTip.reposition, 'function', 'reposition is defined');
		strictEqual(typeof $.powerTip.hide, 'function', 'hide is defined');
		strictEqual(typeof $.powerTip.toggle, 'function', 'toggle is defined');
		strictEqual(typeof $.powerTip.destroy, 'function', 'destroy is defined');
		// deprecated
		strictEqual(typeof $.powerTip.showTip, 'function', 'showTip is defined');
		strictEqual(typeof $.powerTip.closeTip, 'function', 'closeTip is defined');
	});

	test('API show method should call DisplayController.show', function() {
		var showCalled = false,
			element = $('')
				.data(DATA_DISPLAYCONTROLLER, new MockDisplayController(
					function() {
						showCalled = true;
					}
				));

		$.powerTip.show(element);

		ok(showCalled, 'show method was called');
	});

	test('API reposition method should call DisplayController.resetPosition', function() {
		var resetCalled = false,
			element = $('')
				.data(DATA_DISPLAYCONTROLLER, new MockDisplayController(
					null,
					null,
					null,
					function() {
						resetCalled = true;
					}
				));

		$.powerTip.reposition(element);

		ok(resetCalled, 'reposition method was called');
	});

	test('API hide method should call DisplayController.hide', function() {
		var hideCalled = false,
			element = $('')
				.data(DATA_DISPLAYCONTROLLER, new MockDisplayController(
					null,
					function() {
						hideCalled = true;
					}
				));

		$.powerTip.hide(element);

		ok(hideCalled, 'hide method was called');
	});

	test('API toggle method should call DisplayController.show to open and DisplayController.hide to close', function() {
		var showCalled = false,
			hideCalled = false,
			element = $('')
				.data(DATA_DISPLAYCONTROLLER, new MockDisplayController(
					function() {
						showCalled = true;
						// toggle checks activeHover to determine action
						session.activeHover = element;
					},
					function() {
						hideCalled = true;
					}
				));

		$.powerTip.toggle(element); // simulate show
		$.powerTip.toggle(element); // simulate hide

		ok(showCalled, 'show method was called');
		ok(hideCalled, 'hide method was called');

		// reset activeHover
		session.activeHover = null;
	});

	test('API destroy method rolls back PowerTip changes', function() {
		var element = $('').powerTip(),
			elementDataAttr = $('').powerTip(),
			showTriggered = false,
			hideTriggered = false;

		element.data(
			DATA_DISPLAYCONTROLLER,
			new MockDisplayController(
				function() {
					showTriggered = true;
				},
				function() {
					hideTriggered = true;
				}
			)
		);

		element.powerTip('destroy');
		elementDataAttr.powerTip('destroy');

		// attributes
		strictEqual(element.attr('title'), 'This is the tooltip text', 'destory method rolled back the title attribute');
		ok(!element.data(DATA_POWERTIP), 'destroy method removed powertip data attribute');
		strictEqual(elementDataAttr.data(DATA_POWERTIP), 'This is the tooltip text', 'destroy method did not remove manually set powertip data attribute');

		// events
		element.trigger($.Event('mouseenter', { pageX: 10, pageY: 10 }));
		ok(!showTriggered, 'mouseenter event was unhooked after destroy');
		showTriggered = false;

		element.trigger('mouseleave');
		ok(!hideTriggered, 'mouseleave event was unhooked after destroy');
		hideTriggered = false;

		element.trigger('focus');
		ok(!showTriggered, 'focus event was unhooked after destroy');
		showTriggered = false;

		element.trigger('blur');
		ok(!hideTriggered, 'blur event was unhooked after destroy');
		hideTriggered = false;

		element.trigger($.Event('keydown', { keyCode: 27 }));
		ok(!hideTriggered, 'keydown event was unhooked after destroy');
		hideTriggered = false;
	});

	function MockDisplayController(show, hide, cancel, resetPosition) {
		this.show = show || $.noop;
		this.hide = hide || $.noop;
		this.cancel = cancel || $.noop;
		this.resetPosition = resetPosition || $.noop;
	}

});
<commit_msg>Added API destroy method no arguments test.<commit_after>$(function() {
	'use strict';

	module('PowerTip Core');

	test('powerTip defined', function() {
		var element = $('');
		strictEqual(typeof element.powerTip, 'function', 'powerTip is defined');
	});

	test('expose default settings', function() {
		ok($.fn.powerTip.defaults, 'defaults is defined');
		ok($.fn.powerTip.defaults.hasOwnProperty('fadeInTime'), 'fadeInTime exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('fadeOutTime'), 'fadeOutTime exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('followMouse'), 'followMouse exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('popupId'), 'popupId exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('intentSensitivity'), 'intentSensitivity exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('intentPollInterval'), 'intentPollInterval exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('closeDelay'), 'closeDelay exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('placement'), 'placement exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('smartPlacement'), 'smartPlacement exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('offset'), 'offset exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('mouseOnToPopup'), 'mouseOnToPopup exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('manual'), 'manual exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('openEvents'), 'openEvents exists');
		ok($.fn.powerTip.defaults.hasOwnProperty('closeEvents'), 'closeEvents exists');
	});

	test('expose smart placement lists', function() {
		ok($.fn.powerTip.smartPlacementLists, 'smartPlacementLists is defined');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('n'), 'n exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('e'), 'e exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('s'), 's exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('w'), 'w exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('ne'), 'ne exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('nw'), 'nw exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('se'), 'se exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('sw'), 'sw exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('ne-alt'), 'ne-alt exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('nw-alt'), 'nw-alt exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('se-alt'), 'se-alt exists');
		ok($.fn.powerTip.smartPlacementLists.hasOwnProperty('sw-alt'), 'sw-alt exists');
	});

	test('powerTip', function() {
		var div = $('
'),
			empty = $('#thisDoesntExist'),
			element = $('').powerTip();

		deepEqual(div.powerTip(), div, 'original jQuery object returned for matched selector');
		deepEqual(empty.powerTip(), empty, 'original jQuery object returned for empty selector');
		deepEqual(div.powerTip('show'), div, 'original jQuery object returned for show');
		deepEqual(div.powerTip('hide'), div, 'original jQuery object returned for hide');
		deepEqual(div.powerTip('toggle'), div, 'original jQuery object returned for toggle');
		deepEqual(div.powerTip('resetPosition'), div, 'original jQuery object returned for resetPosition');
		deepEqual(div.powerTip('destroy'), div, 'original jQuery object returned for destroy');
		ok(!element.attr('title'), 'title attribute was removed');
		ok(element.data(DATA_DISPLAYCONTROLLER), 'new DisplayController created and added to data');
	});

	test('powerTip hooks events', function() {
		var element = $('TEXT').powerTip(),
			showTriggered = false,
			hideTriggered = false;

		element.data(
			DATA_DISPLAYCONTROLLER,
			new MockDisplayController(
				function() {
					showTriggered = true;
				},
				function() {
					hideTriggered = true;
				}
			)
		);

		// jquery 1.9 will not trigger a focus event on an element that cannot
		// be focused, so we have to append the test element to the document
		// before the focus test will work
		$('body').prepend(element);

		element.trigger($.Event('mouseenter', { pageX: 10, pageY: 10 }));
		ok(showTriggered, 'mouseenter event calls DisplayController.show');
		showTriggered = false;

		element.trigger('mouseleave');
		ok(hideTriggered, 'mouseleave event calls DisplayController.hide');
		hideTriggered = false;

		element.trigger('focus');
		ok(showTriggered, 'focus event calls DisplayController.show');
		showTriggered = false;

		element.trigger('blur');
		ok(hideTriggered, 'blur event calls DisplayController.hide');
		hideTriggered = false;

		element.trigger($.Event('keydown', { keyCode: 27 }));
		ok(hideTriggered, 'keydown event for key code 27 calls DisplayController.hide');
		hideTriggered = false;

		// cleanup test element
		element.remove();
	});

	test('expose API', function() {
		strictEqual(typeof $.powerTip.show, 'function', 'show is defined');
		strictEqual(typeof $.powerTip.reposition, 'function', 'reposition is defined');
		strictEqual(typeof $.powerTip.hide, 'function', 'hide is defined');
		strictEqual(typeof $.powerTip.toggle, 'function', 'toggle is defined');
		strictEqual(typeof $.powerTip.destroy, 'function', 'destroy is defined');
		// deprecated
		strictEqual(typeof $.powerTip.showTip, 'function', 'showTip is defined');
		strictEqual(typeof $.powerTip.closeTip, 'function', 'closeTip is defined');
	});

	test('API show method should call DisplayController.show', function() {
		var showCalled = false,
			element = $('')
				.data(DATA_DISPLAYCONTROLLER, new MockDisplayController(
					function() {
						showCalled = true;
					}
				));

		$.powerTip.show(element);

		ok(showCalled, 'show method was called');
	});

	test('API reposition method should call DisplayController.resetPosition', function() {
		var resetCalled = false,
			element = $('')
				.data(DATA_DISPLAYCONTROLLER, new MockDisplayController(
					null,
					null,
					null,
					function() {
						resetCalled = true;
					}
				));

		$.powerTip.reposition(element);

		ok(resetCalled, 'reposition method was called');
	});

	test('API hide method should call DisplayController.hide', function() {
		var hideCalled = false,
			element = $('')
				.data(DATA_DISPLAYCONTROLLER, new MockDisplayController(
					null,
					function() {
						hideCalled = true;
					}
				));

		$.powerTip.hide(element);

		ok(hideCalled, 'hide method was called');
	});

	test('API toggle method should call DisplayController.show to open and DisplayController.hide to close', function() {
		var showCalled = false,
			hideCalled = false,
			element = $('')
				.data(DATA_DISPLAYCONTROLLER, new MockDisplayController(
					function() {
						showCalled = true;
						// toggle checks activeHover to determine action
						session.activeHover = element;
					},
					function() {
						hideCalled = true;
					}
				));

		$.powerTip.toggle(element); // simulate show
		$.powerTip.toggle(element); // simulate hide

		ok(showCalled, 'show method was called');
		ok(hideCalled, 'hide method was called');

		// reset activeHover
		session.activeHover = null;
	});

	test('API destroy method rolls back PowerTip changes', function() {
		var element = $('').powerTip(),
			elementDataAttr = $('').powerTip(),
			showTriggered = false,
			hideTriggered = false;

		element.data(
			DATA_DISPLAYCONTROLLER,
			new MockDisplayController(
				function() {
					showTriggered = true;
				},
				function() {
					hideTriggered = true;
				}
			)
		);

		element.powerTip('destroy');
		elementDataAttr.powerTip('destroy');

		// attributes
		strictEqual(element.attr('title'), 'This is the tooltip text', 'destory method rolled back the title attribute');
		ok(!element.data(DATA_POWERTIP), 'destroy method removed powertip data attribute');
		strictEqual(elementDataAttr.data(DATA_POWERTIP), 'This is the tooltip text', 'destroy method did not remove manually set powertip data attribute');

		// events
		element.trigger($.Event('mouseenter', { pageX: 10, pageY: 10 }));
		ok(!showTriggered, 'mouseenter event was unhooked after destroy');
		showTriggered = false;

		element.trigger('mouseleave');
		ok(!hideTriggered, 'mouseleave event was unhooked after destroy');
		hideTriggered = false;

		element.trigger('focus');
		ok(!showTriggered, 'focus event was unhooked after destroy');
		showTriggered = false;

		element.trigger('blur');
		ok(!hideTriggered, 'blur event was unhooked after destroy');
		hideTriggered = false;

		element.trigger($.Event('keydown', { keyCode: 27 }));
		ok(!hideTriggered, 'keydown event was unhooked after destroy');
		hideTriggered = false;
	});

	test('API destroy method with no arguments rolls back all PowerTip changes', function() {
		// run PowerTip
		$('').powerTip();

		// destroy everything
		$.powerTip.destroy();

		// tooltip element
		strictEqual($('#' + $.fn.powerTip.defaults.popupId).length, 0, 'tooltip element removed');

		// document event (mouse tracking)
		session.currentX = 1;
		$(document).trigger($.Event('mousemove', { pageX: 2, pageY: 3 }));
		strictEqual(session.currentX, 1, 'document event removed');
	});

	function MockDisplayController(show, hide, cancel, resetPosition) {
		this.show = show || $.noop;
		this.hide = hide || $.noop;
		this.cancel = cancel || $.noop;
		this.resetPosition = resetPosition || $.noop;
	}

});
<|endoftext|>


<commit_before>'use strict';

module.exports = function(config) {
    var browsers,
        reporters = ['dots'];

    if (process.env.KARMA_BROWSERS) {
        browsers = process.env.KARMA_BROWSERS.split(',');
    }

    config.set({
        frameworks: ['jasmine'],
        browsers: browsers,
        files: [
            'dist/loud.js',
            require.resolve('es5-shim'),
            require.resolve('html5shiv/dist/html5shiv'),
            'test/**/*.js'
        ]
    });

    if (process.env.CI && process.env.SAUCE_ACCESS_KEY) {
        var customLaunchers = {
            sauceLabsEdge: {
                base: 'SauceLabs',
                browserName: 'MicrosoftEdge',
                version: '16.16299'
            },
            sauceLabsSafari: {
                base: 'SauceLabs',
                browserName: 'safari',
                version: '11.0'
            },
            sauceLabsIOs: {
                base: 'SauceLabs',
                browserName: 'Safari',
                deviceName: 'iPhone X Simulator',
                platformVersion: '11.1',
                platformName: 'iOS'
            },
            sauceLabsAndroid: {
                base: 'SauceLabs',
                browserName: 'android',
                deviceName: 'Android Emulator',
                version: '6.0'
            },
            sauceLabsIE8: {
                base: 'SauceLabs',
                browserName: 'internet explorer',
                version: 8
            }
        };

        reporters.push('saucelabs');
        config.set({
            browsers: browsers.concat(Object.keys(customLaunchers)),
            captureTimeout: 120000,
            sauceLabs: {
                testName: 'Loud'
            },
            customLaunchers: customLaunchers
        });
    }

    if (process.env.KARMA_COVERAGE) {
        reporters.push('coverage');
        config.set({
            preprocessors: {
                'dist/loud.js': ['sourcemap'],
                'lib/*.js': ['coverage']
            },
            coverageReporter: {
                type: process.env.KARMA_COVERAGE,
                dir: 'coverage/'
            }
        });
    }

    config.set({
        reporters: reporters
    });
};
<commit_msg>Test in modern browsers<commit_after>'use strict';

module.exports = function(config) {
    var browsers,
        reporters = ['dots'];

    if (process.env.KARMA_BROWSERS) {
        browsers = process.env.KARMA_BROWSERS.split(',');
    }

    config.set({
        frameworks: ['jasmine'],
        browsers: browsers,
        files: [
            'dist/loud.js',
            require.resolve('es5-shim'),
            require.resolve('html5shiv/dist/html5shiv'),
            'test/**/*.js'
        ]
    });

    if (process.env.CI && process.env.SAUCE_ACCESS_KEY) {
        var customLaunchers = {
            sauceLabsEdge: {
                base: 'SauceLabs',
                browserName: 'MicrosoftEdge',
                version: '18.17763'
            },
            sauceLabsSafari: {
                base: 'SauceLabs',
                browserName: 'safari',
                version: '12.0'
            },
            sauceLabsIOs: {
                base: 'SauceLabs',
                browserName: 'Safari',
                deviceName: 'iPhone X Simulator',
                platformVersion: '12.0',
                platformName: 'iOS'
            },
            sauceLabsAndroid: {
                base: 'SauceLabs',
                browserName: 'android',
                deviceName: 'Android GoogleAPI Emulator',
                version: '7.1'
            },
            sauceLabsIE8: {
                base: 'SauceLabs',
                browserName: 'internet explorer',
                version: 8
            }
        };

        reporters.push('saucelabs');
        config.set({
            browsers: browsers.concat(Object.keys(customLaunchers)),
            captureTimeout: 120000,
            sauceLabs: {
                testName: 'Loud'
            },
            customLaunchers: customLaunchers
        });
    }

    if (process.env.KARMA_COVERAGE) {
        reporters.push('coverage');
        config.set({
            preprocessors: {
                'dist/loud.js': ['sourcemap'],
                'lib/*.js': ['coverage']
            },
            coverageReporter: {
                type: process.env.KARMA_COVERAGE,
                dir: 'coverage/'
            }
        });
    }

    config.set({
        reporters: reporters
    });
};
<|endoftext|>


<commit_before>'use strict';

/**
 */
angular.module('openolitor-admin')
  .controller('OpenOlitorRootController', ['$scope', '$rootScope',
    'ServerService', 'ProjektService', 'gettextCatalog', 'amMoment',
    '$location', 'msgBus', 'checkSize', '$window', '$timeout', 'BUILD_NR',
    'ENV', 'VERSION', 'cssInjector', 'API_URL',
    'ooAuthService', '$cookies',
    function($scope, $rootScope, ServerService, ProjektService,
      gettextCatalog, amMoment, $location, msgBus, checkSize, $window,
      $timeout, BUILD_NR, ENV, VERSION, cssInjector, API_URL,
      ooAuthService, $cookies) {
      angular.element($window).bind('resize', function() {
        checkSize();
      });

      $scope.currentPathContains = function(pathJunk) {
        return $location.url().indexOf(pathJunk) !== -1;
      };

      //initial launch
      checkSize();

      $scope.connected = false;
      $scope.showConnectionErrorMessage = false;

      var unwatchLoggedIn = $scope.$watch(function() {
        return ooAuthService.getUser();
      }, function(user) {
        $scope.loggedIn = ooAuthService.isUserLoggedIn(user);
        $scope.user = user;

        if($scope.loggedIn) {
          ProjektService.resolveProjekt().then(function(projekt) {
            $scope.projekt = projekt;
            $rootScope.projekt = projekt;
          });
        }
      });

      $timeout(function() {
        $scope.menushow[angular.element('.sidebar-nav .active').parent()
          .attr(
            'activate-id')] = true;
      }, 0);

      var unwatchStaticServerInfo = $scope.$watch(ServerService.getStaticServerInfo,
        function(info) {
          if (!angular.isUndefined(info)) {
            $scope.serverInfo = info;
            $scope.connected = true;
          }
        });

      $scope.buildNr = BUILD_NR;
      $scope.env = ENV;
      $scope.version = VERSION;

      msgBus.onMsg('WebSocketClosed', $rootScope, function(event, msg) {
        $scope.connected = false;
        $scope.messagingSocketClosedReason = msg.reason;
        if(angular.isUndefined($scope.messagingSocketClosedSetter)) {
          $scope.messagingSocketClosedSetter = $timeout(function() {
            $scope.showConnectionErrorMessage = true;
            $scope.messagingSocketClosedSetter = undefined;
          }, 30000);
        }
        $scope.$apply();
      });

      msgBus.onMsg('WebSocketOpen', $rootScope, function() {
        $scope.connected = true;
        $scope.showConnectionErrorMessage = false;
        if(angular.isUndefined($scope.messagingSocketClosedSetter)) {
          $scope.messagingSocketClosedSetter.close();
        }
        $scope.messagingSocketClosedReason = '';
        $scope.$apply();
      });

      $scope.changeLang = function(lang) {
        if (!angular.isUndefined(lang)) {

          msgBus.emitMsg({
            type: 'ChangeLang',
            reason: lang
          });
          $scope.storeActiveLang(lang);
          $scope.$emit('languageChanged');
        }
      };

      msgBus.onMsg('ChangeLang', $rootScope, function(event, msg) {
        gettextCatalog.setCurrentLanguage(msg.reason);
      });

      $scope.activeLang = function() {
        return gettextCatalog.getCurrentLanguage();
      };

      $scope.storedActiveLang = function() {
        return $cookies.get('activeLang');
      };

      $scope.storeActiveLang = function(lang) {
        $cookies.put('activeLang', lang);
      };

      if (angular.isUndefined($scope.storedActiveLang())) {
        var lang = $window.navigator.language || $window.navigator.userLanguage;
        if(lang.indexOf('de-') > 0) {
          $scope.changeLang('de');
        } else if(lang.indexOf('fr-') > 0) {
          $scope.changeLang('fr');
        } else if(lang.indexOf('en-') > 0) {
          $scope.changeLang('en');
        } else {
          $scope.changeLang('de');
        }
      } else {
        $scope.changeLang($scope.storedActiveLang());
      }

      $scope.$on('destroy', function() {
        unwatchLoggedIn();
        unwatchStaticServerInfo();
      });

      cssInjector.add(API_URL + 'ressource/style/admin');
    }
  ]);
<commit_msg>corrected small error<commit_after>'use strict';

/**
 */
angular.module('openolitor-admin')
  .controller('OpenOlitorRootController', ['$scope', '$rootScope',
    'ServerService', 'ProjektService', 'gettextCatalog', 'amMoment',
    '$location', 'msgBus', 'checkSize', '$window', '$timeout', 'BUILD_NR',
    'ENV', 'VERSION', 'cssInjector', 'API_URL',
    'ooAuthService', '$cookies',
    function($scope, $rootScope, ServerService, ProjektService,
      gettextCatalog, amMoment, $location, msgBus, checkSize, $window,
      $timeout, BUILD_NR, ENV, VERSION, cssInjector, API_URL,
      ooAuthService, $cookies) {
      angular.element($window).bind('resize', function() {
        checkSize();
      });

      $scope.currentPathContains = function(pathJunk) {
        return $location.url().indexOf(pathJunk) !== -1;
      };

      //initial launch
      checkSize();

      $scope.connected = false;
      $scope.showConnectionErrorMessage = false;

      var unwatchLoggedIn = $scope.$watch(function() {
        return ooAuthService.getUser();
      }, function(user) {
        $scope.loggedIn = ooAuthService.isUserLoggedIn(user);
        $scope.user = user;

        if($scope.loggedIn) {
          ProjektService.resolveProjekt().then(function(projekt) {
            $scope.projekt = projekt;
            $rootScope.projekt = projekt;
          });
        }
      });

      $timeout(function() {
        $scope.menushow[angular.element('.sidebar-nav .active').parent()
          .attr(
            'activate-id')] = true;
      }, 0);

      var unwatchStaticServerInfo = $scope.$watch(ServerService.getStaticServerInfo,
        function(info) {
          if (!angular.isUndefined(info)) {
            $scope.serverInfo = info;
            $scope.connected = true;
          }
        });

      $scope.buildNr = BUILD_NR;
      $scope.env = ENV;
      $scope.version = VERSION;

      msgBus.onMsg('WebSocketClosed', $rootScope, function(event, msg) {
        $scope.connected = false;
        $scope.messagingSocketClosedReason = msg.reason;
        if(angular.isUndefined($scope.messagingSocketClosedSetter)) {
          $scope.messagingSocketClosedSetter = $timeout(function() {
            $scope.showConnectionErrorMessage = true;
            $scope.messagingSocketClosedSetter = undefined;
          }, 30000);
        }
        $scope.$apply();
      });

      msgBus.onMsg('WebSocketOpen', $rootScope, function() {
        $scope.connected = true;
        $scope.showConnectionErrorMessage = false;
        if(!angular.isUndefined($scope.messagingSocketClosedSetter)) {
          $scope.messagingSocketClosedSetter.close();
        }
        $scope.messagingSocketClosedReason = '';
        $scope.$apply();
      });

      $scope.changeLang = function(lang) {
        if (!angular.isUndefined(lang)) {

          msgBus.emitMsg({
            type: 'ChangeLang',
            reason: lang
          });
          $scope.storeActiveLang(lang);
          $scope.$emit('languageChanged');
        }
      };

      msgBus.onMsg('ChangeLang', $rootScope, function(event, msg) {
        gettextCatalog.setCurrentLanguage(msg.reason);
      });

      $scope.activeLang = function() {
        return gettextCatalog.getCurrentLanguage();
      };

      $scope.storedActiveLang = function() {
        return $cookies.get('activeLang');
      };

      $scope.storeActiveLang = function(lang) {
        $cookies.put('activeLang', lang);
      };

      if (angular.isUndefined($scope.storedActiveLang())) {
        var lang = $window.navigator.language || $window.navigator.userLanguage;
        if(lang.indexOf('de-') > 0) {
          $scope.changeLang('de');
        } else if(lang.indexOf('fr-') > 0) {
          $scope.changeLang('fr');
        } else if(lang.indexOf('en-') > 0) {
          $scope.changeLang('en');
        } else {
          $scope.changeLang('de');
        }
      } else {
        $scope.changeLang($scope.storedActiveLang());
      }

      $scope.$on('destroy', function() {
        unwatchLoggedIn();
        unwatchStaticServerInfo();
      });

      cssInjector.add(API_URL + 'ressource/style/admin');
    }
  ]);
<|endoftext|>


<commit_before>'use strict';
var aplus = exports,
    _Promise;

aplus.Promise = global.Promise;

// Use the promise polyfill for old versions of node.
/* istanbul ignore next */
if (!aplus.Promise) {
    aplus.Promise = require('promise-polyfill');
}

_Promise = aplus.Promise;

aplus.setPromise = function setPromise(newPromise) {
    aplus.Promise = newPromise;
};

aplus.resetPromise = function resetPromise() {
    aplus.Promise = _Promise;
};

function _thenable(fn, args) {
    try {
        var value = fn.apply(null, args || []),
            thenable = value;
        if (!value || typeof value.then !== 'function') {
            thenable = aplus.Promise.resolve(value);
        }
        return thenable;
    } catch (err) {
        return aplus.Promise.reject(err);
    }
}

function _each(obj, keys, limit, fn) {
    var result = Array.isArray(obj) ? [] : {},
        finished = 0,
        active = 0,
        index = 0,
        done = false;

    function generator() {
        var key = keys[index];
        index += 1;
        return {
            key: key,
            value: obj[key]
        };
    }

    return new Promise(function (resolve, reject) {
        function apply(item) {
            active += 1;
            _thenable(fn, [item.value, item.key, obj]).then(function (value) {
                result[item.key] = value;
                active -= 1;
                finished += 1;
                if (!done && finished === keys.length) {
                    done = true;
                    return resolve(result);
                }
                process.nextTick(spawn);
            }, function (err) {
                reject(err);
            });
        }

        function spawn() {
            while (!done && index < keys.length && active < limit) {
                var item = generator();
                apply(item);
            }
        }
        spawn();
    });
}

aplus.mapLimit = aplus.forEachLimit = aplus.eachLimit = function eachLimit(arr, limit, iterator) {
    if (Number.isNaN(Math.floor(limit))) {
        limit = 1; // Fallback if non number provided
    }
    if (!arr || arr.length === 0) {
        return aplus.Promise.resolve([]);
    }
    var keys = Object.keys(arr);
    if (keys.length === 0) {
        return aplus.Promise.resolve({});
    }
    return _each(arr, keys, limit, iterator);
};

aplus.map = aplus.forEach = aplus.each = function each(arr, iterator) {
    return aplus.eachLimit(arr, Number.POSITIVE_INFINITY, iterator);
};

aplus.mapSeries = aplus.forEachSeries = aplus.eachSeries = function eachSeries(arr, iterator) {
    return aplus.eachLimit(arr, 1, iterator);
};

function _filter(arr) {
    return function (values) {
        return aplus.Promise.resolve(arr.filter(function (_, index) {
            return values[index];
        }));
    };
}
aplus.filter = aplus.select = function select(arr, iterator) {
    return aplus.each(arr, iterator).then(_filter(arr));
};
aplus.filterSeries = aplus.selectSeries = function selectSeries(arr, iterator) {
    return aplus.eachSeries(arr, iterator).then(_filter(arr));
};
aplus.filterLimit = aplus.selectLimit = function selectLimit(arr, limit, iterator) {
    return aplus.eachLimit(arr, limit, iterator).then(_filter(arr));
};

function _reject(arr) {
    return function (values) {
        return aplus.Promise.resolve(arr.filter(function (_, index) {
            return !values[index];
        }));
    };
}
aplus.reject = function reject(arr, iterator) {
    return aplus.each(arr, iterator).then(_reject(arr));
};
aplus.rejectSeries = function rejectSeries(arr, limit, iterator) {
    return aplus.eachSeries(arr, limit, iterator).then(_reject(arr));
};
aplus.rejectLimit = function rejectLimit(arr, limit, iterator) {
    return aplus.eachLimit(arr, limit, iterator).then(_reject(arr));
};

function _detect(each, arr, iterator) {
    var breakEarly = new Error('early break'),
        result;

    function stepper(item) {
        return iterator(item).then(function (value) {
            if (value) {
                result = item;
                return aplus.Promise.reject(breakEarly);
            }
            return aplus.Promise.resolve(value);
        });
    }
    return each(arr, stepper).then(function () {
        return aplus.Promise.resolve(undefined);
    }).catch(function (err) {
        if (err === breakEarly) {
            return aplus.Promise.resolve(result);
        }
        return aplus.Promise.reject(err);
    });
}
aplus.detect = function detect(arr, iterator) {
    return _detect(aplus.each, arr, iterator);
};
aplus.detectSeries = function detectSeries(arr, iterator) {
    return _detect(aplus.eachSeries, arr, iterator);
};
aplus.detectLimit = function detectLimit(arr, limit, iterator) {
    return _detect(function (a, i) {
        return aplus.eachLimit(a, limit, i);
    }, arr, iterator);
};

aplus.foldl = aplus.reduce = function reduce(arr, start, iterator) {
    function stepper(item) {
        return iterator(start, item).then(function (value) {
            start = value;
            return aplus.Promise.resolve(value);
        });
    }
    return aplus.eachSeries(arr, stepper).then(function () {
        return aplus.Promise.resolve(start);
    });
};

aplus.foldr = aplus.reduceRight = function reduceRight(arr, start, iterator) {
    arr = (arr || []).reverse();
    return aplus.foldl(arr, start, iterator);
};

function _every(each, arr, iterator) {
    var breakEarly = new Error('early break');

    function stepper(item) {
        return iterator(item).then(function (value) {
            if (!value) {
                return aplus.Promise.reject(breakEarly);
            }
            return aplus.Promise.resolve(value);
        });
    }
    return each(arr, stepper).then(function () {
        return aplus.Promise.resolve(true);
    }).catch(function (err) {
        if (err === breakEarly) {
            return aplus.Promise.resolve(false);
        }
        return aplus.Promise.reject(err);
    });
}

aplus.all = aplus.every = function every(arr, iterator) {
    return _every(aplus.each, arr, iterator);
};
aplus.allSeries = aplus.everySeries = function everySeries(arr, iterator) {
    return _every(aplus.eachSeries, arr, iterator);
};
aplus.allLimit = aplus.everyLimit = function everyLimit(arr, limit, iterator) {
    return _every(function (a, i) {
        return aplus.eachLimit(a, limit, i);
    }, arr, iterator);
};

function _any(each, arr, iterator) {
    var breakEarly = new Error('early break');

    function stepper(item) {
        return iterator(item).then(function (value) {
            if (value) {
                return aplus.Promise.reject(breakEarly);
            }
            return aplus.Promise.resolve(value);
        });
    }
    return each(arr, stepper).then(function () {
        return aplus.Promise.resolve(false);
    }).catch(function (err) {
        if (err === breakEarly) {
            return aplus.Promise.resolve(true);
        }
        return aplus.Promise.reject(err);
    });
}

aplus.any = aplus.some = function some(arr, iterator) {
    return _any(aplus.each, arr, iterator);
};
aplus.anySeries = aplus.someSeries = function someSeries(arr, iterator) {
    return _any(aplus.eachSeries, arr, iterator);
};
aplus.anyLimit = aplus.someLimit = function someLimit(arr, limit, iterator) {
    return _any(function (a, i) {
        return aplus.eachLimit(a, limit, i);
    }, arr, iterator);
};

function _sorter(each, arr, iterator) {
    var original = (arr || []).map(function (value) {
        return {
            original: value,
            key: null
        };
    });
    return each(original, function (value, index) {
        return iterator(arr[index], index, arr).then(function (key) {
            value.key = key;
            return aplus.Promise.resolve(key);
        });
    }).then(function () {
        var sorted = original.sort(function (a, b) {
            if (a.key < b.key) {
                return -1;
            }
            if (a.key > b.key) {
                return 1;
            }
            return 0;
        });
        return aplus.Promise.resolve(sorted.map(function (value) {
            return value.original;
        }));
    });
}
aplus.sort = aplus.sortBy = function sortBy(arr, iterator) {
    return _sorter(aplus.each, arr, iterator);
};
aplus.sortSeries = aplus.sortBySeries = function sortBySeries(arr, iterator) {
    return _sorter(aplus.eachSeries, arr, iterator);
};
aplus.sortLimit = aplus.sortByLimit = function sortByLimit(arr, limit, iterator) {
    return _sorter(function (a, i) {
        return aplus.eachLimit(a, limit, i);
    }, arr, iterator);
};

function _concat(each, arr, iterator) {
    return each(arr, iterator).then(function (values) {
        var result = [].concat.apply([],
            values.map(function (item) {
                if (Array.isArray(item)) {
                    return item;
                }
                return [item];
            }));
        return aplus.Promise.resolve(result);
    });
}

aplus.concat = function concat(arr, iterator) {
    return _concat(aplus.each, arr, iterator);
};
aplus.concatSeries = function concatSeries(arr, iterator) {
    return _concat(aplus.eachSeries, arr, iterator);
};
aplus.concatLimit = function concatLimit(arr, limit, iterator) {
    return _concat(function (a, i) {
        return aplus.eachLimit(a, limit, i);
    }, arr, iterator);
};

function _runner(each, tasks) {
    function runner(fn) {
        return fn();
    }
    return each(tasks, runner);
}
aplus.series = function series(tasks) {
    return _runner(aplus.eachSeries, tasks);
};
aplus.parallel = function parallel(tasks) {
    return _runner(aplus.each, tasks);
};
aplus.parallelLimit = function parallelLimit(tasks, limit) {
    return _runner(function (a, i) {
        return aplus.eachLimit(a, limit, i);
    }, tasks);
};

aplus.waterfall = function waterfall(tasks) {
    var arg = undefined;

    function runner(fn) {
        return _thenable(fn, [arg]).then(function (value) {
            arg = value;
            return aplus.Promise.resolve(value);
        });
    }
    return aplus.eachSeries(tasks, runner).then(function () {
        return aplus.Promise.resolve(arg);
    });
};

function _loop(test, fn, invert) {
    function truth(value) {
        return invert ? !value : value;
    }
    return new Promise(function (resolve, reject) {
        function apply() {
            _thenable(test).then(function (value) {
                if (truth(value)) {
                    _thenable(fn).then(function () {
                        process.nextTick(apply);
                    }, function (err) {
                        reject(err);
                    });
                } else {
                    resolve();
                }
            }, function (err) {
                reject(err);
            });
        }
        apply();
    });
}

aplus.forever = function forever(task) {
    return _loop(function () {
        return aplus.Promise.resolve(true);
    }, task);
};

aplus.during = aplus.whilst = function whilst(test, fn) {
    return _loop(test, fn);
};

aplus.until = function until(test, fn) {
    return _loop(test, fn, true);
};

aplus.doDuring = aplus.doWhilst = function doWhilst(fn, test) {
    var frist = true;
    return _loop(function () {
        return new Promise(function (resolve, reject) {
            if (frist) {
                frist = false;
                return resolve(true);
            }
            return _thenable(test).then(function (value) {
                resolve(value);
            }, reject);
        });
    }, fn);
};

aplus.doUntil = function doUntil(fn, test) {
    var frist = true;
    return _loop(function () {
        return new Promise(function (resolve, reject) {
            if (frist) {
                frist = false;
                return resolve(false);
            }
            _thenable(test).then(function (value) {
                resolve(value);
            }, reject);
        });
    }, fn, true);
};

function _times(each, times, fn) {
    if (typeof times !== 'number' || times < 0 || Number.isNaN(times)) {
        times = 0;
    }
    times = Math.floor(times);
    if (times === 0) {
        return aplus.Promise.resolve([]);
    }
    var arr = Array.apply(null, Array(times)).map(function (_, i) {
        return i;
    });
    return each(arr, fn);
}
aplus.times = function times(times, fn) {
    return _times(aplus.each, times, fn);
};
aplus.timesSeries = function timesSeries(times, fn) {
    return _times(aplus.eachSeries, times, fn);
};
aplus.timesLimit = function timesLimit(times, limit, fn) {
    return _times(function (a, i) {
        return aplus.eachLimit(a, limit, i);
    }, times, fn);
};<commit_msg>Bad Fox! putting lint errors into source!<commit_after>'use strict';
var aplus = exports,
    _Promise;

aplus.Promise = global.Promise;

// Use the promise polyfill for old versions of node.
/* istanbul ignore next */
if (!aplus.Promise) {
    aplus.Promise = require('promise-polyfill');
}

_Promise = aplus.Promise;

aplus.setPromise = function setPromise(newPromise) {
    aplus.Promise = newPromise;
};

aplus.resetPromise = function resetPromise() {
    aplus.Promise = _Promise;
};

function _thenable(fn, args) {
    try {
        var value = fn.apply(null, args || []),
            thenable = value;
        if (!value || typeof value.then !== 'function') {
            thenable = aplus.Promise.resolve(value);
        }
        return thenable;
    } catch (err) {
        return aplus.Promise.reject(err);
    }
}

function _each(obj, keys, limit, fn) {
    var result = Array.isArray(obj) ? [] : {},
        finished = 0,
        active = 0,
        index = 0,
        done = false;

    function generator() {
        var key = keys[index];
        index += 1;
        return {
            key: key,
            value: obj[key]
        };
    }

    return new Promise(function (resolve, reject) {
        function apply(item) {
            active += 1;
            _thenable(fn, [item.value, item.key, obj]).then(function (value) {
                result[item.key] = value;
                active -= 1;
                finished += 1;
                if (!done && finished === keys.length) {
                    done = true;
                    return resolve(result);
                }
                process.nextTick(spawn);
            }, function (err) {
                reject(err);
            });
        }

        function spawn() {
            while (!done && index < keys.length && active < limit) {
                var item = generator();
                apply(item);
            }
        }
        spawn();
    });
}

aplus.mapLimit = aplus.forEachLimit = aplus.eachLimit = function eachLimit(arr, limit, iterator) {
    if (Number.isNaN(Math.floor(limit))) {
        limit = 1; // Fallback if non number provided
    }
    if (!arr || arr.length === 0) {
        return aplus.Promise.resolve([]);
    }
    var keys = Object.keys(arr);
    if (keys.length === 0) {
        return aplus.Promise.resolve({});
    }
    return _each(arr, keys, limit, iterator);
};

aplus.map = aplus.forEach = aplus.each = function each(arr, iterator) {
    return aplus.eachLimit(arr, Number.POSITIVE_INFINITY, iterator);
};

aplus.mapSeries = aplus.forEachSeries = aplus.eachSeries = function eachSeries(arr, iterator) {
    return aplus.eachLimit(arr, 1, iterator);
};

function _filter(arr) {
    return function (values) {
        return aplus.Promise.resolve(arr.filter(function (_, index) {
            return values[index];
        }));
    };
}
aplus.filter = aplus.select = function select(arr, iterator) {
    return aplus.each(arr, iterator).then(_filter(arr));
};
aplus.filterSeries = aplus.selectSeries = function selectSeries(arr, iterator) {
    return aplus.eachSeries(arr, iterator).then(_filter(arr));
};
aplus.filterLimit = aplus.selectLimit = function selectLimit(arr, limit, iterator) {
    return aplus.eachLimit(arr, limit, iterator).then(_filter(arr));
};

function _reject(arr) {
    return function (values) {
        return aplus.Promise.resolve(arr.filter(function (_, index) {
            return !values[index];
        }));
    };
}
aplus.reject = function reject(arr, iterator) {
    return aplus.each(arr, iterator).then(_reject(arr));
};
aplus.rejectSeries = function rejectSeries(arr, limit, iterator) {
    return aplus.eachSeries(arr, limit, iterator).then(_reject(arr));
};
aplus.rejectLimit = function rejectLimit(arr, limit, iterator) {
    return aplus.eachLimit(arr, limit, iterator).then(_reject(arr));
};

function _detect(each, arr, iterator) {
    var breakEarly = new Error('early break'),
        result;

    function stepper(item) {
        return iterator(item).then(function (value) {
            if (value) {
                result = item;
                return aplus.Promise.reject(breakEarly);
            }
            return aplus.Promise.resolve(value);
        });
    }
    return each(arr, stepper).then(function () {
        return aplus.Promise.resolve(undefined);
    }).catch(function (err) {
        if (err === breakEarly) {
            return aplus.Promise.resolve(result);
        }
        return aplus.Promise.reject(err);
    });
}
aplus.detect = function detect(arr, iterator) {
    return _detect(aplus.each, arr, iterator);
};
aplus.detectSeries = function detectSeries(arr, iterator) {
    return _detect(aplus.eachSeries, arr, iterator);
};
aplus.detectLimit = function detectLimit(arr, limit, iterator) {
    return _detect(function (a, i) {
        return aplus.eachLimit(a, limit, i);
    }, arr, iterator);
};

aplus.foldl = aplus.reduce = function reduce(arr, start, iterator) {
    function stepper(item) {
        return iterator(start, item).then(function (value) {
            start = value;
            return aplus.Promise.resolve(value);
        });
    }
    return aplus.eachSeries(arr, stepper).then(function () {
        return aplus.Promise.resolve(start);
    });
};

aplus.foldr = aplus.reduceRight = function reduceRight(arr, start, iterator) {
    arr = (arr || []).reverse();
    return aplus.foldl(arr, start, iterator);
};

function _every(each, arr, iterator) {
    var breakEarly = new Error('early break');

    function stepper(item) {
        return iterator(item).then(function (value) {
            if (!value) {
                return aplus.Promise.reject(breakEarly);
            }
            return aplus.Promise.resolve(value);
        });
    }
    return each(arr, stepper).then(function () {
        return aplus.Promise.resolve(true);
    }).catch(function (err) {
        if (err === breakEarly) {
            return aplus.Promise.resolve(false);
        }
        return aplus.Promise.reject(err);
    });
}

aplus.all = aplus.every = function every(arr, iterator) {
    return _every(aplus.each, arr, iterator);
};
aplus.allSeries = aplus.everySeries = function everySeries(arr, iterator) {
    return _every(aplus.eachSeries, arr, iterator);
};
aplus.allLimit = aplus.everyLimit = function everyLimit(arr, limit, iterator) {
    return _every(function (a, i) {
        return aplus.eachLimit(a, limit, i);
    }, arr, iterator);
};

function _any(each, arr, iterator) {
    var breakEarly = new Error('early break');

    function stepper(item) {
        return iterator(item).then(function (value) {
            if (value) {
                return aplus.Promise.reject(breakEarly);
            }
            return aplus.Promise.resolve(value);
        });
    }
    return each(arr, stepper).then(function () {
        return aplus.Promise.resolve(false);
    }).catch(function (err) {
        if (err === breakEarly) {
            return aplus.Promise.resolve(true);
        }
        return aplus.Promise.reject(err);
    });
}

aplus.any = aplus.some = function some(arr, iterator) {
    return _any(aplus.each, arr, iterator);
};
aplus.anySeries = aplus.someSeries = function someSeries(arr, iterator) {
    return _any(aplus.eachSeries, arr, iterator);
};
aplus.anyLimit = aplus.someLimit = function someLimit(arr, limit, iterator) {
    return _any(function (a, i) {
        return aplus.eachLimit(a, limit, i);
    }, arr, iterator);
};

function _sorter(each, arr, iterator) {
    var original = (arr || []).map(function (value) {
        return {
            original: value,
            key: null
        };
    });
    return each(original, function (value, index) {
        return iterator(arr[index], index, arr).then(function (key) {
            value.key = key;
            return aplus.Promise.resolve(key);
        });
    }).then(function () {
        var sorted = original.sort(function (a, b) {
            if (a.key < b.key) {
                return -1;
            }
            if (a.key > b.key) {
                return 1;
            }
            return 0;
        });
        return aplus.Promise.resolve(sorted.map(function (value) {
            return value.original;
        }));
    });
}
aplus.sort = aplus.sortBy = function sortBy(arr, iterator) {
    return _sorter(aplus.each, arr, iterator);
};
aplus.sortSeries = aplus.sortBySeries = function sortBySeries(arr, iterator) {
    return _sorter(aplus.eachSeries, arr, iterator);
};
aplus.sortLimit = aplus.sortByLimit = function sortByLimit(arr, limit, iterator) {
    return _sorter(function (a, i) {
        return aplus.eachLimit(a, limit, i);
    }, arr, iterator);
};

function _concat(each, arr, iterator) {
    return each(arr, iterator).then(function (values) {
        var result = [].concat.apply([],
            values.map(function (item) {
                if (Array.isArray(item)) {
                    return item;
                }
                return [item];
            }));
        return aplus.Promise.resolve(result);
    });
}

aplus.concat = function concat(arr, iterator) {
    return _concat(aplus.each, arr, iterator);
};
aplus.concatSeries = function concatSeries(arr, iterator) {
    return _concat(aplus.eachSeries, arr, iterator);
};
aplus.concatLimit = function concatLimit(arr, limit, iterator) {
    return _concat(function (a, i) {
        return aplus.eachLimit(a, limit, i);
    }, arr, iterator);
};

function _runner(each, tasks) {
    function runner(fn) {
        return fn();
    }
    return each(tasks, runner);
}
aplus.series = function series(tasks) {
    return _runner(aplus.eachSeries, tasks);
};
aplus.parallel = function parallel(tasks) {
    return _runner(aplus.each, tasks);
};
aplus.parallelLimit = function parallelLimit(tasks, limit) {
    return _runner(function (a, i) {
        return aplus.eachLimit(a, limit, i);
    }, tasks);
};

aplus.waterfall = function waterfall(tasks) {
    var arg = undefined;

    function runner(fn) {
        return _thenable(fn, [arg]).then(function (value) {
            arg = value;
            return aplus.Promise.resolve(value);
        });
    }
    return aplus.eachSeries(tasks, runner).then(function () {
        return aplus.Promise.resolve(arg);
    });
};

function _loop(test, fn, invert) {
    function truth(value) {
        return invert ? !value : value;
    }
    return new Promise(function (resolve, reject) {
        function apply() {
            _thenable(test).then(function (value) {
                if (truth(value)) {
                    _thenable(fn).then(function () {
                        process.nextTick(apply);
                    }, function (err) {
                        reject(err);
                    });
                } else {
                    resolve();
                }
            }, function (err) {
                reject(err);
            });
        }
        apply();
    });
}

aplus.forever = function forever(task) {
    return _loop(function () {
        return aplus.Promise.resolve(true);
    }, task);
};

aplus.during = aplus.whilst = function whilst(test, fn) {
    return _loop(test, fn);
};

aplus.until = function until(test, fn) {
    return _loop(test, fn, true);
};

aplus.doDuring = aplus.doWhilst = function doWhilst(fn, test) {
    var frist = true;
    return _loop(function () {
        return new Promise(function (resolve, reject) {
            if (frist) {
                frist = false;
                return resolve(true);
            }
            return _thenable(test).then(function (value) {
                resolve(value);
            }, reject);
        });
    }, fn);
};

aplus.doUntil = function doUntil(fn, test) {
    var frist = true;
    return _loop(function () {
        return new Promise(function (resolve, reject) {
            if (frist) {
                frist = false;
                return resolve(false);
            }
            _thenable(test).then(function (value) {
                resolve(value);
            }, reject);
        });
    }, fn, true);
};

function _times(each, n, fn) {
    if (typeof n !== 'number' || n < 0 || Number.isNaN(n)) {
        n = 0;
    }
    n = Math.floor(n);
    if (n === 0) {
        return aplus.Promise.resolve([]);
    }
    var arr = Array.apply(null, Array(n)).map(function (_, i) {
        return i;
    });
    return each(arr, fn);
}
aplus.times = function times(n, fn) {
    return _times(aplus.each, n, fn);
};
aplus.timesSeries = function timesSeries(n, fn) {
    return _times(aplus.eachSeries, n, fn);
};
aplus.timesLimit = function timesLimit(n, limit, fn) {
    return _times(function (a, i) {
        return aplus.eachLimit(a, limit, i);
    }, n, fn);
};
<|endoftext|>


<commit_before>module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['mocha'],
    files: [
      { pattern: 'https://cdn.polyfill.io/v2/polyfill.js?features=default,WeakMap,WeakSet', watched: false, served: false, included: true },
      { pattern: 'node_modules/power-assert/build/power-assert.js', watched: true, served: true, included: true },
      { pattern: 'node_modules/lodash/lodash.js', watched: true, served: true, included: true },
      { pattern: 'node_modules/benchmark/benchmark.js', watched: true, served: true, included: true },
      { pattern: 'dist/*.js', watched: true, served: true, included: true }
    ],
    exclude: [
    ],
    espowerPreprocessor: {
      options: {
        emitActualCode: false,
        ignoreUpstreamSourceMap: true
      }
    },
    reporters: ['dots'],
    coverageReporter: {
      dir: 'coverage',
      subdir: function (browser, platform) {
        return browser.toLowerCase().split(' ')[0];
      },
      reporters: [
        { type: 'lcov' },
        { type: 'text-summary', subdir: '.', file: 'summary.txt' }
      ]
    },
    autoWatch: true,
    autoWatchBatchDelay: 500,
    browsers: ['Chrome'],
    browserNoActivityTimeout: 100 * 1e3
  });
};
<commit_msg>chore(config): modify the karma config<commit_after>module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['mocha'],
    files: [
      { pattern: 'https://cdn.polyfill.io/v2/polyfill.js?features=default,WeakMap,WeakSet', watched: false, served: false, included: true },
      { pattern: 'node_modules/power-assert/build/power-assert.js', watched: true, served: true, included: true },
      { pattern: 'node_modules/lodash/lodash.js', watched: true, served: true, included: true },
      { pattern: 'node_modules/benchmark/benchmark.js', watched: true, served: true, included: true },
      { pattern: 'dist/*.js', watched: true, served: true, included: true }
    ],
    exclude: [
    ],
    espowerPreprocessor: {
      options: {
        emitActualCode: false,
        ignoreUpstreamSourceMap: true
      }
    },
    reporters: ['dots'],
    coverageReporter: {
      dir: 'coverage',
      subdir: function (browser, platform) {
        return browser.toLowerCase().split(' ')[0];
      },
      reporters: [
        { type: 'lcov' },
        { type: 'text-summary', subdir: '.', file: 'summary.txt' }
      ]
    },
    autoWatch: true,
    autoWatchBatchDelay: 500,
    browsers: ['Chrome'],
    browserNoActivityTimeout: 100 * 1e3,
    client: {
      useIframe: false
    }
  });
};
<|endoftext|>


<commit_before>/* exported util */

var util = {
	baseUrl: function() {
		var prefix = 'https://platform.cod.uno';

		if (location.origin.indexOf('localhost') !== -1) {
			prefix = 'http://localhost:8080';
		}

		if (location.origin.indexOf('coduno-staging') !== -1) {
			prefix = 'https://platform-dot-coduno-staging.appspot.com';
		}

		return prefix;
	},
	build: function(suffix) {
		return util.baseUrl() + suffix;
	},
	getWSUrl: function(suffix) {
		var prefix = 'wss://ws.cod.uno:8080';

		if (location.origin.indexOf('localhost') !== -1) {
			prefix = 'ws://localhost:8080';
		}

		return prefix + suffix;
	},
	getSockWSUrl: function(suffix) {
		var prefix = 'https://platform.cod.uno';

		if (location.origin.indexOf('localhost') !== -1) {
			prefix = 'http://localhost:8080';
		}

		return prefix + suffix;
	},
	computeDuration: function(duration) {
		var minutes = Math.floor(duration / 60);
		var hours = Math.floor(minutes / 60);
		var days = Math.floor(hours / 24);
		var months = Math.floor(days / 30);
		if (months >= 1) {
			return months + ' months';
		}
		if (days >= 2) {
			return days + ' days';
		}
		if (hours >= 5) {
			return hours + ' hours';
		}
		return minutes + ' minutes';
	},
	error: function(error) {
		var app = document.querySelector('#app');
		if (error.detail.request.xhr.status === 401) {
			app.isLoggedIn = false;
			return page.redirect('/login');
		}
		app.error = error;
		page.redirect('/error');
	},
	getFormatedTime: function(d) {
		var w = Math.floor(d / 604800);
		var days = Math.floor(d / 86400) % 7;
		var h = Math.floor(d / 3600) % 24;
		var m = Math.floor(d / 60 % 60);
		var s = Math.floor(d % 60);
		var time = ('0' + h).slice(-2) + ':' + ('0' + m).slice(-2) + ':' + ('0' + s).slice(-2);
		if (days === 0 && w === 0){
			return time;
		}
		time = ' and ' + time;
		time = days > 0 ? days + ' days ' + time : time;
		time = w > 0 ? days > 0 ? w + ' weeks, ' + time : w + ' weeks ' + time : time;
		return time;
	},
	padTime: function(i) {
		var str = String(i);
		return '00'.substring(0, 2 - str.length) + str;
	},
	formatDate: function(date, omitTime) {
		if (!(date instanceof Date)) {
			date = new Date(date * 1000);
		}

		var result = date.toISOString();
		result = result.substring(0, result.indexOf('T'));

		if (omitTime) {
			return result + ' UTC';
		}

		return result + ' ' + util.padTime(date.getUTCHours()) + ':' + util.padTime(date.getUTCMinutes()) + ' UTC';
	},
	languages: [
		'java',
		'py',
		'c',
		'js'
	]
};
<commit_msg>Travis: change url in app<commit_after>/* exported util */

var util = {
	baseUrl: function() {
		var prefix = 'https://platform.cod.uno';

		if (location.origin.indexOf('localhost') !== -1) {
			prefix = 'http://localhost:8080';
		}

		if (location.origin.indexOf('coduno-lab') !== -1) {
			prefix = 'https://platform-dot-coduno-lab.appspot.com';
		}

		return prefix;
	},
	build: function(suffix) {
		return util.baseUrl() + suffix;
	},
	getWSUrl: function(suffix) {
		var prefix = 'wss://ws.cod.uno:8080';

		if (location.origin.indexOf('localhost') !== -1) {
			prefix = 'ws://localhost:8080';
		}

		return prefix + suffix;
	},
	getSockWSUrl: function(suffix) {
		var prefix = 'https://platform.cod.uno';

		if (location.origin.indexOf('localhost') !== -1) {
			prefix = 'http://localhost:8080';
		}

		return prefix + suffix;
	},
	computeDuration: function(duration) {
		var minutes = Math.floor(duration / 60);
		var hours = Math.floor(minutes / 60);
		var days = Math.floor(hours / 24);
		var months = Math.floor(days / 30);
		if (months >= 1) {
			return months + ' months';
		}
		if (days >= 2) {
			return days + ' days';
		}
		if (hours >= 5) {
			return hours + ' hours';
		}
		return minutes + ' minutes';
	},
	error: function(error) {
		var app = document.querySelector('#app');
		if (error.detail.request.xhr.status === 401) {
			app.isLoggedIn = false;
			return page.redirect('/login');
		}
		app.error = error;
		page.redirect('/error');
	},
	getFormatedTime: function(d) {
		var w = Math.floor(d / 604800);
		var days = Math.floor(d / 86400) % 7;
		var h = Math.floor(d / 3600) % 24;
		var m = Math.floor(d / 60 % 60);
		var s = Math.floor(d % 60);
		var time = ('0' + h).slice(-2) + ':' + ('0' + m).slice(-2) + ':' + ('0' + s).slice(-2);
		if (days === 0 && w === 0){
			return time;
		}
		time = ' and ' + time;
		time = days > 0 ? days + ' days ' + time : time;
		time = w > 0 ? days > 0 ? w + ' weeks, ' + time : w + ' weeks ' + time : time;
		return time;
	},
	padTime: function(i) {
		var str = String(i);
		return '00'.substring(0, 2 - str.length) + str;
	},
	formatDate: function(date, omitTime) {
		if (!(date instanceof Date)) {
			date = new Date(date * 1000);
		}

		var result = date.toISOString();
		result = result.substring(0, result.indexOf('T'));

		if (omitTime) {
			return result + ' UTC';
		}

		return result + ' ' + util.padTime(date.getUTCHours()) + ':' + util.padTime(date.getUTCMinutes()) + ' UTC';
	},
	languages: [
		'java',
		'py',
		'c',
		'js'
	]
};
<|endoftext|>


<commit_before>'use strict';

const utils = require( './utils' );

const BaseSchema = require( './base' );

class ArraySchema extends BaseSchema {

    constructor( parseSchema ) {

        super( 'array' );

        this.parseSchema = parseSchema;
    }

    updateSchema( state, key, value ) {

        if( key === 'items' || key === 'ordered' ) {

            if( !utils.isArray( value ) ) {

                // convert to array
                value = [ value ];
            }

            let schemas = [];

            let parseSchemaFunc = this.parseSchema;

            for( let item of value ) {

                let itemSchema = parseSchemaFunc.call( null, item, state.engine );

                schemas.push( itemSchema );
            }

            state.schema = state.schema[ key ]( schemas );
            return true;
        }

        return super.updateSchema( state, key, value );
    }
}

module.exports = ArraySchema;
<commit_msg>changed to use apply rather than passing the object array<commit_after>'use strict';

const utils = require( './utils' );

const BaseSchema = require( './base' );

class ArraySchema extends BaseSchema {

    constructor( parseSchema ) {

        super( 'array' );

        this.parseSchema = parseSchema;
    }

    updateSchema( state, key, value ) {

        if( key === 'items' || key === 'ordered' ) {

            if( !utils.isArray( value ) ) {

                // convert to array
                value = [ value ];
            }

            let schemas = [];

            let parseSchemaFunc = this.parseSchema;

            for( let item of value ) {

                let itemSchema = parseSchemaFunc.call( null, item, state.engine );

                schemas.push( itemSchema );
            }

            state.schema = state.schema[ key ].apply( state.schema, schemas );
            return true;
        }

        return super.updateSchema( state, key, value );
    }
}

module.exports = ArraySchema;
<|endoftext|>


<commit_before>// Copyright (c) 2011, Centrum Cyfrowe
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistributions of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//   * Redistributions in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//   * Neither the name of the Centrum Cyfrowe nor the names of its contributors
//     may be used to endorse or promote products derived from this software
//     without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

var _store = (function () {

//  P U B L I C   I N T E R F A C E
    var that = {};

    // meta_data setter/getter
    that.meta_data = function ( value ) {
        // set it just once
//        _assert.is_equal( meta_data.length, 0,
//                          "meta_data already assigned" );

        meta_data = value;
    };

    // get metadata about available datasets
    that.meta_datasets = function () {
        return meta_data;
    };

    // get metadata about perspectives available in a cerain dataset
    that.meta_perspectives = function ( dataset_id ) {
        return meta_data[ dataset_id ]['perspectives'];
    };

    // check if group exists
    that.group_exists = function (data) {
        if( find_group( data ) !== -1) {
            return false;
        }
        return true;
    };

    // creates a new group and sets an activ group index
    that.create_group = function (data) {
        // create a group for new data collection
        groups.push( group( data ));
        that.active_group( groups.length - 1 );
    };

    // creates a new group or sets an active group index to apropriate group
    that.create_new_group = function ( data ) {
        var found = find_group( data );

        if( found !== -1 ) {
            that.active_group( found );
            return false;
        }

        // create a group for new data collection
        groups.push( group( data ));
        that.active_group( groups.length - 1 );

        return true;
    };

    that.dataset = function () {
        return that.active_group()['dataset'];
    };

    that.perspective = function () {
        return that.active_group()['perspective'];
    };

    that.issue = function () {
        return that.active_group()['issue'];
    };

    that.init_basic_sheet = function ( data ) {
        var active_grp = that.active_group();

        // store original version of collection
        active_grp['name'] = data['name'];
        active_grp['basic_rows'] = sheet( data, true );
        // add data to mutable list of sheets
        active_grp['sheets'].push( sheet( data ) );
    };

    that.set_active_columnes = function ( columns ) {
        that.active_sheet()['columns'] = columns;
    };

    that.get_column_from_group = function( id ) {
        var columns = that.active_group()['columns'];
        return columns.filter( function ( col ) {
            return col['key'] === id;
        })[0];
    };

    that.active_columns = function () {
        return that.active_sheet()['columns'];
    };

    that.group_columns = function () {
        return that.active_group()['columns'];
    };

    //TODO not needed
    that.basic_schema = function () {
        var full_schema = that.active_columns();

        return full_schema.filter( function ( element ) {
            return element['basic'] === true;
        });
    };

    that.set_selected = function ( id, state ) {
        var node, rows = that.active_rows();
        var i, len = rows.length;

        for( i = 0; i < len; i += 1 ) {
            node = rows[i];
            if( node['data']['idef'] === id ) {
                node['state']['selected'] = state;
                return;
            }
        }
//        that.active_rows().forEach( function ( node ) {
//            if( node['data']['idef'] === id ) {
//                node['state']['selected'] = true;
//            }
//            else {
//                node['state']['selected'] = false;
//            }
//        });
    };

    that.set_open = function ( id, state ) {
        var node, rows = that.active_rows();
        var i, len = rows.length;

        for( i = 0; i < len; i += 1 ) {
            node = rows[i];
            if( node['data']['idef'] === id ) {
                node['state']['open'] = state;
                return;
            }
        }
    };

    that.set_visible = function ( id, state ) {
        var node, rows = that.active_rows();
        var i, len = rows.length;
        for ( i = 0; i < len; i += 1 ) {
            node = rows[i];
            if ( node['data']['idef'] === id ) {
                node['state']['visible'] = state;
                return;
            }

        }

    };

    that.active_sheet_index = function ( new_active_sheet_num ) {
        if( arguments.length === 0 ) {
            return that.active_group()['active_sheet_number'];
        }
        that.active_group()['active_sheet_number'] = new_active_sheet_num;
    };

    that.active_group_index = function () {
        return active_group_number;
    };

    that.next_sheet_number = function () {
        return that.active_group()['sheets'].length;
    };

    that.max_group_number = function () {
        return groups.length;
    };

    that.active_rows = function () {
        return that.active_sheet()['rows'];
    };

//    that.active_pending_nodes = function () {
//        return that.active_sheet()['pending_nodes'];
//    };

    that.active_basic_changed = function ( value ) {
        that.active_group()['basic_changed'] = value;
    };

    that.active_filtered = function () {
        return that.active_sheet()['filtered'];
    };

    // active sheet getter / setter
    that.active_sheet = function ( value ) {
        var active_grp = that.active_group();

        if( arguments.length === 0 ) {
            return active_grp['sheets'][active_grp['active_sheet_number']];
        }

        active_grp['active_sheet_number'] = value;
    };

    // active group getter / setter
    that.active_group = function ( value ) {
        if( arguments.length === 0 ) {
            return groups[ active_group_number ];
        }

        active_group_number = value;
    };

    that.active_group_name = function () {
        return that.active_group()['name'];
    };

    that.add_data = function ( new_data ) {
        var rows = that.active_rows();

        new_data
            .map( function ( row ) {
                return {
                    data: row,
                    state: { open: false, selected: false, visible: true }
                };
            })
            .forEach( function ( e ) {
                rows.push( e );
            });
    };

    that.add_new_sheet = function ( sheet ) {
        var active_grp = that.active_group();
        var next_sheet_number = that.next_sheet_number() ;

        active_grp['sheets'].push( sheet );
        that.active_sheet_index( next_sheet_number );
    };

    that.get_all_groups = function () {
        return groups;
    };

    // check if column exists in active_sheet
    that.is_column_in_active_sheet = function( key ){
        var i;
        var cols = that.active_columns();

        for( i = 0; i < cols.length; i += 1 ) {
            if( cols[i]['key'] === key ){
                    return true;
            }
        }
        return false;
    };

    that.get_group = function ( group ) {
        return groups[group];
    };

    that.get_sheet = function ( group, sheet ) {
        return groups[group]['sheets'][sheet];
    };

    that.remove_active_group = function() {
        if (groups.length === 1){
            return false;
        }
        groups.splice ( that.active_group_index(), 1 );
        if (that.active_group_index() !== 0){
            active_group_number = that.active_group_index()-1;
        }
        return true;
    }

    that.remove_active_sheet = function () {
        var active_grp = that.active_group();
        var active_group_sheets = active_grp['sheets'];
        var active_sheet_num = that.active_sheet_index();
        if (groups.length === 1 && active_group_sheets.length === 1 ){
            return false;
        }
        active_group_sheets.splice(active_sheet_num, 1 );
        if (active_group_sheets.length === 0 ){
            that.remove_active_group();
        }else if (active_sheet_num !== 0 ) {
                active_grp['active_sheet_number'] = active_sheet_num - 1  ;
            }
        return true;
    };

    that.active_sheet_name = function (sheet_name) {
        if( arguments.length === 0 ) {
            return that.active_sheet()['name'];
        }
        that.active_sheet()['name'] = sheet_name;
    };

    that.reset_sheet = function () {
        var active_sheet = that.active_sheet();
        var basic_rows = $.extend( true, [], that.active_group()['basic_rows'] );
        var total = active_sheet['rows']['total'];

        active_sheet['rows'] = basic_rows;
        active_sheet['rows']['total'] = total;
    };

    that.next_sheet_name = function () {
        var next_num=1;
        var sheet_name;
        that.active_group()['sheets'].forEach( function (sheet, sheet_num){
            if ( sheet['name'].indexOf('Arkusz') !== -1 ) {
                sheet_name = sheet['name'].split(' ');
                if ( sheet_name[1] >= next_num ){
                    next_num = sheet_name[1];
                    next_num++;
                   };
            }
        });

        return 'Arkusz ' + next_num;
    };

    that.get_info = function ( id ) {
        var node = that.active_rows().filter( function ( e ) {
                return e['idef'] === id;
                })
                .pop();

        return node['data']['info'];
    };

    that.get_all_sheets_num = function () {
        var groups = that.get_all_groups();
        var num = 0;
        groups.forEach( function ( group ){
            num += group['sheets'].length;
        });
        return num;
    };

// P R I V A T E   I N T E R F A C E
    // data about available datasets and their perspectives
    var meta_data = [];

    // a store for a sheets tab in the GUI
    var groups = [];
    var active_group_number = null;

    // returns group id if it exists or -1 if there is no such a group
    function find_group( data ) {
        var i;

        for( i = 0; i < groups.length; i += 1 ) {
            if( data['dataset'] === groups[i]['dataset'] &&
                data['view'] === groups[i]['view'] &&
                data['issue'] === groups[i]['issue'] ) {

                return i;
            }
        }

        return -1;
    }

// O B J E C T   F A C T O R I E S
    // a single sheet
    function sheet( data, basic ) {
        var cols = that.active_group()['columns'].filter( function ( e ) {
                    return e['basic'] === true;
                });
        var rows = data['rows'].map( function ( row ) {
                                    return {
                                        data: row,
                                        state: {
                                            open: false,
                                            selected: false,
                                            visible: true
                                        }
                                    };
                                });

        // if total present in collection move it to special position
        if( rows[ rows.length - 1 ]['data']['idef'].indexOf( '9999' ) !== -1 ) {
            rows['total'] = rows.pop();
        }

        if( !!basic ) {
            return rows;
        }

        return {
            'columns': cols,
            'rows': rows,
            'name': data['name'],
            'filtered': false
        };
    }

    // list of all sheets of the same dataset/perspective/issue
    function group( data ) {
        return {
            'name': null,
            'dataset': data['dataset'],
            'perspective': data['view'],
            'issue': data['issue'],
            'columns': data['columns'],
            'active_sheet_number': 0,
            'sheets': [],
            'basic_rows': null,
            'basic_changed': false
        };
    }

    return that;

}) ();
<commit_msg>Bug fixed<commit_after>// Copyright (c) 2011, Centrum Cyfrowe
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistributions of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//   * Redistributions in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//   * Neither the name of the Centrum Cyfrowe nor the names of its contributors
//     may be used to endorse or promote products derived from this software
//     without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

var _store = (function () {

//  P U B L I C   I N T E R F A C E
    var that = {};

    // meta_data setter/getter
    that.meta_data = function ( value ) {
        // set it just once
//        _assert.is_equal( meta_data.length, 0,
//                          "meta_data already assigned" );

        meta_data = value;
    };

    // get metadata about available datasets
    that.meta_datasets = function () {
        return meta_data;
    };

    // get metadata about perspectives available in a cerain dataset
    that.meta_perspectives = function ( dataset_id ) {
        return meta_data[ dataset_id ]['perspectives'];
    };

    // check if group exists
    that.group_exists = function (data) {
        if( find_group( data ) !== -1) {
            return false;
        }
        return true;
    };

    // creates a new group and sets an activ group index
    that.create_group = function (data) {
        // create a group for new data collection
        groups.push( group( data ));
        that.active_group( groups.length - 1 );
    };

    // creates a new group or sets an active group index to apropriate group
    that.create_new_group = function ( data ) {
        var found = find_group( data );

        if( found !== -1 ) {
            that.active_group( found );
            return false;
        }

        // create a group for new data collection
        groups.push( group( data ));
        that.active_group( groups.length - 1 );

        return true;
    };

    that.dataset = function () {
        return that.active_group()['dataset'];
    };

    that.perspective = function () {
        return that.active_group()['perspective'];
    };

    that.issue = function () {
        return that.active_group()['issue'];
    };

    that.init_basic_sheet = function ( data ) {
        var active_grp = that.active_group();

        // store original version of collection
        active_grp['name'] = data['name'];
        active_grp['basic_rows'] = sheet( data, true );
        // add data to mutable list of sheets
        active_grp['sheets'].push( sheet( data ) );
    };

    that.set_active_columnes = function ( columns ) {
        that.active_sheet()['columns'] = columns;
    };

    that.get_column_from_group = function( id ) {
        var columns = that.active_group()['columns'];
        return columns.filter( function ( col ) {
            return col['key'] === id;
        })[0];
    };

    that.active_columns = function () {
        return that.active_sheet()['columns'];
    };

    that.group_columns = function () {
        return that.active_group()['columns'];
    };

    //TODO not needed
    that.basic_schema = function () {
        var full_schema = that.active_columns();

        return full_schema.filter( function ( element ) {
            return element['basic'] === true;
        });
    };

    that.set_selected = function ( id, state ) {
        var node, rows = that.active_rows();
        var i, len = rows.length;

        for( i = 0; i < len; i += 1 ) {
            node = rows[i];
            if( node['data']['idef'] === id ) {
                node['state']['selected'] = state;
                return;
            }
        }
//        that.active_rows().forEach( function ( node ) {
//            if( node['data']['idef'] === id ) {
//                node['state']['selected'] = true;
//            }
//            else {
//                node['state']['selected'] = false;
//            }
//        });
    };

    that.set_open = function ( id, state ) {
        var node, rows = that.active_rows();
        var i, len = rows.length;

        for( i = 0; i < len; i += 1 ) {
            node = rows[i];
            if( node['data']['idef'] === id ) {
                node['state']['open'] = state;
                return;
            }
        }
    };

    that.set_visible = function ( id, state ) {
        var node, rows = that.active_rows();
        var i, len = rows.length;
        for ( i = 0; i < len; i += 1 ) {
            node = rows[i];
            if ( node['data']['idef'] === id ) {
                node['state']['visible'] = state;
                return;
            }

        }

    };

    that.active_sheet_index = function ( new_active_sheet_num ) {
        if( arguments.length === 0 ) {
            return that.active_group()['active_sheet_number'];
        }
        that.active_group()['active_sheet_number'] = new_active_sheet_num;
    };

    that.active_group_index = function () {
        return active_group_number;
    };

    that.next_sheet_number = function () {
        return that.active_group()['sheets'].length;
    };

    that.max_group_number = function () {
        return groups.length;
    };

    that.active_rows = function () {
        return that.active_sheet()['rows'];
    };

//    that.active_pending_nodes = function () {
//        return that.active_sheet()['pending_nodes'];
//    };

    that.active_basic_changed = function ( value ) {
        that.active_group()['basic_changed'] = value;
    };

    that.active_filtered = function () {
        return that.active_sheet()['filtered'];
    };

    // active sheet getter / setter
    that.active_sheet = function ( value ) {
        var active_grp = that.active_group();

        if( arguments.length === 0 ) {
            return active_grp['sheets'][active_grp['active_sheet_number']];
        }

        active_grp['active_sheet_number'] = value;
    };

    // active group getter / setter
    that.active_group = function ( value ) {
        if( arguments.length === 0 ) {
            return groups[ active_group_number ];
        }

        active_group_number = value;
    };

    that.active_group_name = function () {
        return that.active_group()['name'];
    };

    that.add_data = function ( new_data ) {
        var rows = that.active_rows();

        new_data
            .map( function ( row ) {
                return {
                    data: row,
                    state: { open: false, selected: false, visible: true }
                };
            })
            .forEach( function ( e ) {
                rows.push( e );
            });
    };

    that.add_new_sheet = function ( sheet ) {
        var active_grp = that.active_group();
        var next_sheet_number = that.next_sheet_number() ;

        active_grp['sheets'].push( sheet );
        that.active_sheet_index( next_sheet_number );
    };

    that.get_all_groups = function () {
        return groups;
    };

    // check if column exists in active_sheet
    that.is_column_in_active_sheet = function( key ){
        var i;
        var cols = that.active_columns();

        for( i = 0; i < cols.length; i += 1 ) {
            if( cols[i]['key'] === key ){
                    return true;
            }
        }
        return false;
    };

    that.get_group = function ( group ) {
        return groups[group];
    };

    that.get_sheet = function ( group, sheet ) {
        return groups[group]['sheets'][sheet];
    };

    that.remove_active_group = function() {
        if (groups.length === 1){
            return false;
        }
        groups.splice ( that.active_group_index(), 1 );
        if (that.active_group_index() !== 0){
            active_group_number = that.active_group_index()-1;
        }
        return true;
    }

    that.remove_active_sheet = function () {
        var active_grp = that.active_group();
        var active_group_sheets = active_grp['sheets'];
        var active_sheet_num = that.active_sheet_index();
        if (groups.length === 1 && active_group_sheets.length === 1 ){
            return false;
        }
        active_group_sheets.splice(active_sheet_num, 1 );
        if (active_group_sheets.length === 0 ){
            that.remove_active_group();
        }else if (active_sheet_num !== 0 ) {
                active_grp['active_sheet_number'] = active_sheet_num - 1  ;
            }
        return true;
    };

    that.active_sheet_name = function (sheet_name) {
        if( arguments.length === 0 ) {
            return that.active_sheet()['name'];
        }
        that.active_sheet()['name'] = sheet_name;
    };

    that.reset_sheet = function () {
        var active_sheet = that.active_sheet();
        var basic_rows = $.extend( true, [], that.active_group()['basic_rows'] );
        var total = active_sheet['rows']['total'];

        active_sheet['rows'] = basic_rows;
        active_sheet['rows']['total'] = total;
    };

    that.next_sheet_name = function () {
        var next_num=1;
        var sheet_name;
        that.active_group()['sheets'].forEach( function (sheet, sheet_num){
            if ( sheet['name'].indexOf('Arkusz') !== -1 ) {
                sheet_name = sheet['name'].split(' ');
                if ( sheet_name[1] >= next_num ){
                    next_num = sheet_name[1];
                    next_num++;
                   };
            }
        });

        return 'Arkusz ' + next_num;
    };

    that.get_info = function ( id ) {
        var node = that.active_rows().filter( function ( e ) {
                return e['idef'] === id;
                })
                .pop();

        return node['data']['info'];
    };

    that.get_all_sheets_num = function () {
        var groups = that.get_all_groups();
        var num = 0;
        groups.forEach( function ( group ){
            num += group['sheets'].length;
        });
        return num;
    };

// P R I V A T E   I N T E R F A C E
    // data about available datasets and their perspectives
    var meta_data = [];

    // a store for a sheets tab in the GUI
    var groups = [];
    var active_group_number = null;

    // returns group id if it exists or -1 if there is no such a group
    function find_group( data ) {
        var i;

        for( i = 0; i < groups.length; i += 1 ) {
            if( data['dataset'] === groups[i]['dataset'] &&
                data['view'] === groups[i]['view'] &&
                data['issue'] === groups[i]['issue'] ) {

                return i;
            }
        }

        return -1;
    }

// O B J E C T   F A C T O R I E S
    // a single sheet
    function sheet( data, basic ) {
        var cols = that.active_group()['columns'].filter( function ( e ) {
                    return e['basic'] === true;
                });
        var rows = data['rows'].map( function ( row ) {
                                    return {
                                        data: row,
                                        state: {
                                            open: false,
                                            selected: false,
                                            visible: true
                                        }
                                    };
                                });

        // if total present in collection move it to special position
        if( rows[ rows.length - 1 ]['data']['idef'].indexOf( '9999' ) !== -1 ) {
            rows['total'] = rows.pop();
        }

        if( !!basic ) {
            return rows;
        }

        return {
            'columns': cols,
            'rows': rows,
            'name': data['name'],
            'filtered': false
        };
    }

    // list of all sheets of the same dataset/perspective/issue
    function group( data ) {
        return {
            'name': null,
            'dataset': data['dataset'],
            'perspective': data['view'] || data['perspective'],
            'issue': data['issue'],
            'columns': data['columns'],
            'active_sheet_number': 0,
            'sheets': [],
            'basic_rows': null,
            'basic_changed': false
        };
    }

    return that;

}) ();
<|endoftext|>


<commit_before>// Karma configuration

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['mocha'],

    // list of files / patterns to load in the browser
    files: [
      'node_modules/should/should.min.js',
      'node_modules/babel-polyfill/dist/polyfill.min.js',
      'dist/modelico.min.js',
      'dist/modelico-spec.js',
      'test/browser/index.js'
    ],

    // list of files to exclude
    exclude: [],

    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },

    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['dots', 'saucelabs'],

    // web server port
    port: 9876,

    // enable / disable colors in the output (reporters and logs)
    colors: true,

    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,

    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: false,

    sauceLabs: {
      username: process.env.SAUCE_USERNAME,
      accessKey: process.env.SAUCE_ACCESS_KEY,
      build: process.env.TRAVIS_BUILD_NUMBER,
      tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER,
      startConnect: true,
      testName: 'modelico: browser tests'
    },

    customLaunchers: customLaunchers(),

    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    //browsers: ['Chrome', 'Firefox'],
    browsers: Object.keys(customLaunchers()),

    // timeout for capturing a browser (in ms)
    captureTimeout: 0,

    // how long will Karma wait for a message from a browser before disconnecting from it (in ms).
    browserNoActivityTimeout: 0,

    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false
  });
};

function customLaunchers() {
  return {
    'SL_Chrome': {
      base: 'SauceLabs',
      browserName: 'chrome'
    },
    'SL_Firefox': {
      base: 'SauceLabs',
      browserName: 'firefox'
    },
    'SL_Edge': {
      base: 'SauceLabs',
      browserName: 'microsoftedge',
      platform: 'Windows 10'
    },
    'SL_Safari': {
      base: 'SauceLabs',
      browserName: 'safari',
      platform: 'OS X 10.10'
    },
    'SL_IE_11': {
      base: 'SauceLabs',
      browserName: 'internet explorer',
      platform: 'Windows 8.1',
      version: '11'
    },
    'SL_Opera': {
      base: 'SauceLabs',
      browserName: 'opera',
      platform: 'Windows 7',
      version: '12.12'
    },
    'SL_Android': {
      base: 'SauceLabs',
      browserName: 'android',
      deviceName: 'Samsung Galaxy S4 Emulator',
      deviceOrientation: 'portrait',
      platform: 'Linux',
      version: '4.4'
    },
    'SL_iOS': {
      base: 'SauceLabs',
      browserName: 'iphone',
      deviceName: 'iPhone Simulator',
      deviceOrientation: 'portrait',
      platform: 'OS X 10.10',
      version: '8.2'
    }
  };
}
<commit_msg>chore: test on latest Android, iOS and OS X<commit_after>// Karma configuration

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['mocha'],

    // list of files / patterns to load in the browser
    files: [
      'node_modules/should/should.min.js',
      'node_modules/babel-polyfill/dist/polyfill.min.js',
      'dist/modelico.min.js',
      'dist/modelico-spec.js',
      'test/browser/index.js'
    ],

    // list of files to exclude
    exclude: [],

    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },

    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['dots', 'saucelabs'],

    // web server port
    port: 9876,

    // enable / disable colors in the output (reporters and logs)
    colors: true,

    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_INFO,

    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: false,

    sauceLabs: {
      username: process.env.SAUCE_USERNAME,
      accessKey: process.env.SAUCE_ACCESS_KEY,
      build: process.env.TRAVIS_BUILD_NUMBER,
      tunnelIdentifier: process.env.TRAVIS_JOB_NUMBER,
      startConnect: true,
      testName: 'modelico: browser tests'
    },

    customLaunchers: customLaunchers(),

    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    //browsers: ['Chrome', 'Firefox'],
    browsers: Object.keys(customLaunchers()),

    // timeout for capturing a browser (in ms)
    captureTimeout: 0,

    // how long will Karma wait for a message from a browser before disconnecting from it (in ms).
    browserNoActivityTimeout: 0,

    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false
  });
};

function customLaunchers() {
  return {
    'SL_Chrome': {
      base: 'SauceLabs',
      browserName: 'chrome'
    },
    'SL_Firefox': {
      base: 'SauceLabs',
      browserName: 'firefox'
    },
    'SL_Edge': {
      base: 'SauceLabs',
      browserName: 'microsoftedge',
      platform: 'Windows 10'
    },
    'SL_Safari': {
      base: 'SauceLabs',
      browserName: 'safari',
      platform: 'OS X 10.11'
    },
    'SL_IE_11': {
      base: 'SauceLabs',
      browserName: 'internet explorer',
      platform: 'Windows 8.1',
      version: '11'
    },
    'SL_Opera': {
      base: 'SauceLabs',
      browserName: 'opera',
      platform: 'Windows 7',
      version: '12.12'
    },
    'SL_Android': {
      base: 'SauceLabs',
      browserName: 'android',
      deviceOrientation: 'portrait',
      platform: 'Linux',
      version: '5.1'
    },
    'SL_iOS': {
      base: 'SauceLabs',
      browserName: 'iphone',
      deviceName: 'iPhone Simulator',
      deviceOrientation: 'portrait',
      platform: 'OS X 10.10',
      version: '9.2'
    }
  };
}
<|endoftext|>