<commit_before>var gulp = require('gulp'),
    wrap = require('gulp-wrap'),
    connect = require('gulp-connect'),
    watch = require('gulp-watch'),
    minifyCss = require('gulp-minify-css'),
    minifyJs = require('gulp-uglify'),
    concat = require('gulp-concat'),
    less = require('gulp-less'),
    rename = require('gulp-rename'),
    minifyHtml = require('gulp-minify-html'),
    Server = require('karma').Server,
    runSequence = require('run-sequence'),
    del = require('del'),
    html2Js = require('gulp-ng-html2js'),
    argv = require('yargs').argv,
    fs = require('fs'),
    replace = require('gulp-replace-task'),
    protractor = require("gulp-protractor").protractor;

var paths = {
    app_scripts: [
        'src/app/constants.js',
        'src/app/**/*module.js',
        'src/app/components/**/*.js',
        '!src/app/**/*.spec.js'
    ],
    build_app_scripts: [
        'build/app/app.min.js',
        'build/app/templates.min.js'
    ],
    app_less: 'src/assets/less/**/*.*',
    app_images: 'src/assets/img/**/*.*',
    app_html: 'src/app/**/*.html',

    libs_css: [
        'bower_components/bootstrap/dist/css/bootstrap.min.css',
        'bower_components/font-awesome/css/font-awesome.min.css',
        'bower_components/animate.css/animate.min.css',
        'bower_components/angular-ui-notification/dist/angular-ui-notification.min.css'

    ],
    libs_scripts: [
        'bower_components/jquery/dist/jquery.js',
        'bower_components/bootstrap/dist/js/bootstrap.js',
        'bower_components/angular/angular.js',
        'bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
        'bower_components/angular-cookies/angular-cookies.js',
        'bower_components/angular-ui-router/release/angular-ui-router.js',
        'bower_components/angular-animate/angular-animate.js',
        'bower_components/jsrasign/jsrasign-latest-all-min.js',
        'bower_components/ngstorage/ngStorage.js',
        'bower_components/oauth-ng/dist/oauth-ng.js',
        'bower_components/lodash/lodash.js',
        'bower_components/restangular/dist/restangular.js',
        'bower_components/angular-clipboard/angular-clipboard.js',
        'bower_components/angular-ui-notification/dist/angular-ui-notification.js'
    ],

    index: 'src/index.html',

    bower_fonts: 'bower_components/**/*.{ttf,woff,woff2,eof,svg}'
};

gulp.task('build', function(callback) {
  runSequence('clean',
            [
                'build-css',
                'build-templates',
                'build-app',
                'build-index',
                'build-libs-css',
                'build-libs-js',
                'build-images',
                'build-libs-font'
            ],
            'minify',
            callback);
});

gulp.task('buildDev', function(callback) {
  runSequence('clean',
            [
                'build-css',
                'build-templates-dev',
                'build-app',
                'build-index',
                'build-libs-css',
                'build-libs-js',
                'build-images',
                'build-libs-font',
                'replace-constants'
            ],
            callback);
});

gulp.task('clean', function(callback) {
    return del(['build'], callback);
});

gulp.task('build-css', function() {
    return gulp.src(paths.app_less)
        .pipe(less())
        .pipe(concat("app.min.css"))
        .pipe(gulp.dest('build/assets/css'));
});

gulp.task('build-templates', function() {
    return gulp.src(paths.app_html)
        .pipe(minifyHtml({
          empty: true,
          spare: true,
          quotes: true
        }))
        .pipe(html2Js({
          moduleName: "app.templates",
          prefix: "/"
        }))
        .pipe(concat("templates.min.js"))
        .pipe(gulp.dest('build/app'));
});

gulp.task('build-templates-dev', function() {
    return gulp.src(paths.app_html)
        .pipe(html2Js({
          moduleName: "app.templates",
          prefix: "/"
        }))
        .pipe(concat("templates.min.js"))
        .pipe(gulp.dest('build/app'));
});

gulp.task('build-app', function() {
    return gulp.src(paths.app_scripts)
        .pipe(concat("app.min.js"))
        .pipe(gulp.dest('build/app'));
});

gulp.task('build-libs-js', function() {
    return gulp.src(paths.libs_scripts)
        .pipe(concat("vendor.min.js"))
        .pipe(gulp.dest('build/assets/libs/js'));
});

gulp.task('build-images', function() {
    return gulp.src(paths.app_images)
        .pipe(gulp.dest('build/assets/img'));
});

gulp.task('build-libs-font', function() {
    return gulp.src(paths.bower_fonts)
        .pipe(rename({
            dirname: '/'
        }))
        .pipe(gulp.dest('build/assets/libs/fonts'));
});

gulp.task('build-libs-css', function() {
    return gulp.src(paths.libs_css)
        .pipe(concat('vendor.min.css'))
        .pipe(gulp.dest('build/assets/libs/css'));
});

gulp.task('build-index', function() {
    return gulp.src(paths.index)
        .pipe(gulp.dest('build'));
});

gulp.task('minify', ['minify-html', 'minify-css', 'minify-js'])

gulp.task('minify-html', function() {
    return gulp.src('build/index.html')
        .pipe(minifyHtml())
        .pipe(gulp.dest('build'));
});

gulp.task('minify-css', function() {
    return gulp.src('build/**/*.css')
        .pipe(minifyCss())
        .pipe(gulp.dest('build'));
});

gulp.task('minify-js', function() {
    return gulp.src('build/**/*.js')
        .pipe(minifyJs())
        .pipe(gulp.dest('build'));
});

gulp.task('watchResources', function() {
    gulp.watch(paths.app_less, ['build-css']);
    gulp.watch(paths.app_images, ['build-images']);
    gulp.watch(paths.app_html, ['build-templates']);
    gulp.watch(paths.app_scripts, ['build-app']);
    gulp.watch(paths.index, ['build-index']);
});

gulp.task('webserver', function() {
    connect.server({
        root: 'build',
        livereload: true,
        port: 8888,
        fallback: 'build/index.html'
    });
});

gulp.task('livereload', function() {
    gulp.src(['build/**/*.*'])
        .pipe(connect.reload());
});

gulp.task('default', function(callback) {
  runSequence('buildDev',
              'webserver',
              'livereload',
              'watchResources',
              callback);
});

gulp.task('start', function(callback) {
  runSequence('webserver',
              'livereload',
              'watchResources',
              callback);
});

gulp.task('replace-constants', function () {
    // Get the environment from the command line
    var envFile = argv.env || './config/localdev.json';
    // Read the settings from the right file
    var settings = JSON.parse(fs.readFileSync(envFile, 'utf8'));

    //Replace each placeholder with the correct value for the variable.
    gulp.src(paths.build_app_scripts)
        .pipe(replace({
            patterns: [
                {
                    match: 'apiUrl',
                    replacement: settings.apiUrl
                },
                {
                    match: 'oauthUrl',
                    replacement: settings.oauthUrl
                }]
            }))
        .pipe(gulp.dest('build/app'));
});

gulp.task('unit', function (done) {
  new Server({
        configFile: __dirname + '/tests/karma.conf.js',
        singleRun: true
    },
    function() {
        done();
    }).start();
});

gulp.task('e2e', function (done) {
  var args = ['--baseUrl', 'http://127.0.0.1:8888'];
  gulp.src(["./tests/**/*.js"])
    .pipe(protractor({
      configFile: "tests/protractor.conf.js",
      args: args
    }))
    .on('error', function(e) { throw e; });
});
<commit_msg>#19: Add support for build task<commit_after>var gulp = require('gulp'),
    wrap = require('gulp-wrap'),
    connect = require('gulp-connect'),
    watch = require('gulp-watch'),
    minifyCss = require('gulp-minify-css'),
    minifyJs = require('gulp-uglify'),
    concat = require('gulp-concat'),
    less = require('gulp-less'),
    rename = require('gulp-rename'),
    minifyHtml = require('gulp-minify-html'),
    Server = require('karma').Server,
    runSequence = require('run-sequence'),
    del = require('del'),
    html2Js = require('gulp-ng-html2js'),
    argv = require('yargs').argv,
    fs = require('fs'),
    replace = require('gulp-replace-task'),
    protractor = require("gulp-protractor").protractor;

var paths = {
    app_scripts: [
        'src/app/constants.js',
        'src/app/**/*module.js',
        'src/app/components/**/*.js',
        '!src/app/**/*.spec.js'
    ],
    build_app_scripts: [
        'build/app/app.min.js',
        'build/app/templates.min.js'
    ],
    app_less: 'src/assets/less/**/*.*',
    app_images: 'src/assets/img/**/*.*',
    app_html: 'src/app/**/*.html',

    libs_css: [
        'bower_components/bootstrap/dist/css/bootstrap.min.css',
        'bower_components/font-awesome/css/font-awesome.min.css',
        'bower_components/animate.css/animate.min.css',
        'bower_components/angular-ui-notification/dist/angular-ui-notification.min.css'

    ],
    libs_scripts: [
        'bower_components/jquery/dist/jquery.js',
        'bower_components/bootstrap/dist/js/bootstrap.js',
        'bower_components/angular/angular.js',
        'bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
        'bower_components/angular-cookies/angular-cookies.js',
        'bower_components/angular-ui-router/release/angular-ui-router.js',
        'bower_components/angular-animate/angular-animate.js',
        'bower_components/jsrasign/jsrasign-latest-all-min.js',
        'bower_components/ngstorage/ngStorage.js',
        'bower_components/oauth-ng/dist/oauth-ng.js',
        'bower_components/lodash/lodash.js',
        'bower_components/restangular/dist/restangular.js',
        'bower_components/angular-clipboard/angular-clipboard.js',
        'bower_components/angular-ui-notification/dist/angular-ui-notification.js'
    ],

    index: 'src/index.html',

    bower_fonts: 'bower_components/**/*.{ttf,woff,woff2,eof,svg}'
};

gulp.task('build', function(callback) {
  runSequence('clean',
            [
                'build-css',
                'build-templates',
                'build-app',
                'build-index',
                'build-libs-css',
                'build-libs-js',
                'build-images',
                'build-libs-font',
                'replace-constants'
            ],
            'minify',
            callback);
});

gulp.task('buildDev', function(callback) {
  runSequence('clean',
            [
                'build-css',
                'build-templates-dev',
                'build-app',
                'build-index',
                'build-libs-css',
                'build-libs-js',
                'build-images',
                'build-libs-font',
                'replace-constants'
            ],
            callback);
});

gulp.task('clean', function(callback) {
    return del(['build'], callback);
});

gulp.task('build-css', function() {
    return gulp.src(paths.app_less)
        .pipe(less())
        .pipe(concat("app.min.css"))
        .pipe(gulp.dest('build/assets/css'));
});

gulp.task('build-templates', function() {
    return gulp.src(paths.app_html)
        .pipe(minifyHtml({
          empty: true,
          spare: true,
          quotes: true
        }))
        .pipe(html2Js({
          moduleName: "app.templates",
          prefix: "/"
        }))
        .pipe(concat("templates.min.js"))
        .pipe(gulp.dest('build/app'));
});

gulp.task('build-templates-dev', function() {
    return gulp.src(paths.app_html)
        .pipe(html2Js({
          moduleName: "app.templates",
          prefix: "/"
        }))
        .pipe(concat("templates.min.js"))
        .pipe(gulp.dest('build/app'));
});

gulp.task('build-app', function() {
    return gulp.src(paths.app_scripts)
        .pipe(concat("app.min.js"))
        .pipe(gulp.dest('build/app'));
});

gulp.task('build-libs-js', function() {
    return gulp.src(paths.libs_scripts)
        .pipe(concat("vendor.min.js"))
        .pipe(gulp.dest('build/assets/libs/js'));
});

gulp.task('build-images', function() {
    return gulp.src(paths.app_images)
        .pipe(gulp.dest('build/assets/img'));
});

gulp.task('build-libs-font', function() {
    return gulp.src(paths.bower_fonts)
        .pipe(rename({
            dirname: '/'
        }))
        .pipe(gulp.dest('build/assets/libs/fonts'));
});

gulp.task('build-libs-css', function() {
    return gulp.src(paths.libs_css)
        .pipe(concat('vendor.min.css'))
        .pipe(gulp.dest('build/assets/libs/css'));
});

gulp.task('build-index', function() {
    return gulp.src(paths.index)
        .pipe(gulp.dest('build'));
});

gulp.task('minify', ['minify-html', 'minify-css', 'minify-js'])

gulp.task('minify-html', function() {
    return gulp.src('build/index.html')
        .pipe(minifyHtml())
        .pipe(gulp.dest('build'));
});

gulp.task('minify-css', function() {
    return gulp.src('build/**/*.css')
        .pipe(minifyCss())
        .pipe(gulp.dest('build'));
});

gulp.task('minify-js', function() {
    return gulp.src('build/**/*.js')
        .pipe(minifyJs())
        .pipe(gulp.dest('build'));
});

gulp.task('watchResources', function() {
    gulp.watch(paths.app_less, ['build-css']);
    gulp.watch(paths.app_images, ['build-images']);
    gulp.watch(paths.app_html, ['build-templates']);
    gulp.watch(paths.app_scripts, ['build-app']);
    gulp.watch(paths.index, ['build-index']);
});

gulp.task('webserver', function() {
    connect.server({
        root: 'build',
        livereload: true,
        port: 8888,
        fallback: 'build/index.html'
    });
});

gulp.task('livereload', function() {
    gulp.src(['build/**/*.*'])
        .pipe(connect.reload());
});

gulp.task('default', function(callback) {
  runSequence('buildDev',
              'webserver',
              'livereload',
              'watchResources',
              callback);
});

gulp.task('start', function(callback) {
  runSequence('webserver',
              'livereload',
              'watchResources',
              callback);
});

gulp.task('replace-constants', function () {
    // Get the environment from the command line
    var envFile = argv.env || './config/localdev.json';
    // Read the settings from the right file
    var settings = JSON.parse(fs.readFileSync(envFile, 'utf8'));

    //Replace each placeholder with the correct value for the variable.
    gulp.src(paths.build_app_scripts)
        .pipe(replace({
            patterns: [
                {
                    match: 'apiUrl',
                    replacement: settings.apiUrl
                },
                {
                    match: 'oauthUrl',
                    replacement: settings.oauthUrl
                }]
            }))
        .pipe(gulp.dest('build/app'));
});

gulp.task('unit', function (done) {
  new Server({
        configFile: __dirname + '/tests/karma.conf.js',
        singleRun: true
    },
    function() {
        done();
    }).start();
});

gulp.task('e2e', function (done) {
  var args = ['--baseUrl', 'http://127.0.0.1:8888'];
  gulp.src(["./tests/**/*.js"])
    .pipe(protractor({
      configFile: "tests/protractor.conf.js",
      args: args
    }))
    .on('error', function(e) { throw e; });
});
<|endoftext|>


<commit_before>var gulp = require('gulp'),
   uglify = require('gulp-uglify'),
   jshint = require('gulp-jshint'),
   concat = require('gulp-concat');

gulp.task('minify', function () {
   gulp.src('js/app.js')
      .pipe(uglify())
      .pipe(gulp.dest('build'))
});

gulp.task('js', function () {
   return gulp.src('js/*.js')
      .pipe(jshint())
      .pipe(jshint.reporter('default'))
      .pipe(uglify())
      .pipe(concat('app.js'))
      .pipe(gulp.dest('build'));
});
<commit_msg>add sample task logging to console<commit_after>var gulp = require('gulp'),
   uglify = require('gulp-uglify'),
   jshint = require('gulp-jshint'),
   concat = require('gulp-concat');

gulp.task('minify', function () {
   gulp.src('js/app.js')
      .pipe(uglify())
      .pipe(gulp.dest('build'))
});

gulp.task('js', function () {
   return gulp.src('js/*.js')
      .pipe(jshint())
      .pipe(jshint.reporter('default'))
      .pipe(uglify())
      .pipe(concat('app.js'))
      .pipe(gulp.dest('build'));
});

gulp.task('greet', function () {
   console.log('Hello world!');
});
<|endoftext|>


<commit_before>const gulp = require('gulp');
const runSequence = require('run-sequence');

require('./gulp/spark-core/spark-core.gulpfile.js');
require('./gulp/spark-extras/spark-card.gulpfile.js');
require('./gulp/spark-extras/spark-dictionary.gulpfile.js');
require('./gulp/spark-extras/spark-highlight-board.gulpfile.js');
require('./gulp/drizzle/drizzle.gulpfile.js');
require('./gulp/angular/dev-app/angulardevapp.gulpfile.js');
require('./gulp/angular/spark-core-angular/spark-core-angular.gulpfile.js');
require('./gulp/angular/spark-extras-angular-award/spark-extras-angular-award.gulpfile.js');
require('./gulp/angular/spark-extras-angular-card/spark-extras-angular-card.gulpfile.js');
require('./gulp/angular/spark-extras-angular-dictionary/spark-extras-angular-dictionary.gulpfile.js');
require('./gulp/angular/spark-extras-angular-highlight-board/spark-extras-angular-highlight-board.gulpfile.js');
require('./gulp/react/dev-app/reactdevapp.gulpfile.js');
require('./gulp/react/spark-core-react/spark-core-react.gulpfile.js');

gulp.task('pre-publish', (cb) => {
  runSequence(
    'setup-spark-packages',
    'build-drizzle',
    'install-angular-dev-app',
    'install-react-dev-app',
    'link-spark-to-react-dir',
    'setup-spark-angular-projects',
    'setup-spark-core-react',
    cb,
  );
});

gulp.task('setup-spark-packages', (cb) => {
  runSequence(
    'setup-spark-core',
    'setup-spark-card',
    'setup-spark-dictionary',
    'setup-spark-highlight-board',
    cb,
  );
});

// assumes that setup-spark-packages has been run
gulp.task('setup-spark-angular-projects', (cb) => {
  runSequence(
    'setup-spark-core-angular',
    [
      'setup-spark-extras-angular-award',
      'setup-spark-extras-angular-card',
      'setup-spark-extras-angular-dictionary',
      'setup-spark-extras-angular-highlight-board',
    ],
    cb,
  );
});

gulp.task('clean-all', (cb) => {
  runSequence(
    [
      'clean',
      'clean-spark-core',
      'clean-spark-highlight-board',
      'clean-angular-dev-app',
      'clean-react-dev-app',
      'clean-spark-core-react',
      'clean-spark-core-angular',
      'clean-spark-extras-angular-award',
      'clean-spark-extras-angular-card',
      'clean-spark-extras-angular-dictionary',
      'clean-spark-extras-angular-highlight-board',
    ],
    cb,
  );
});

gulp.task('dev-spark-packages', (cb) => {
  runSequence('setup-spark-packages', 'build-drizzle', ['watch', 'serve'], cb);
});

gulp.task('dev-spark-angular', (cb) => {
  runSequence(
    'install-angular-dev-app',
    'setup-spark-packages',
    'setup-spark-angular-projects',
    ['serve-angular-dev-app', 'watch'],
    cb,
  );
});

gulp.task('dev-spark-react', (cb) => {
  runSequence(
    'setup-spark-packages',
    'install-react-dev-app',
    'link-spark-to-react-dir',
    'setup-spark-core-react',
    ['serve-react-dev-app', 'watch'],
    cb,
  );
});

gulp.task('dev-all', (cb) => {
  runSequence(
    'setup-spark-packages',
    'install-angular-dev-app',
    'install-react-dev-app',
    'setup-spark-angular-projects',
    'link-spark-to-react-dir',
    'setup-spark-core-react',
    'build-drizzle',
    ['serve-angular-dev-app', 'serve-react-dev-app', 'serve', 'watch'],
    cb,
  );
});

gulp.task('test-angular', (cb) => {
  runSequence(
    'test-spark-core-angular',
    'test-spark-extras-angular-award',
    'test-spark-extras-angular-card',
    'test-spark-extras-angular-dictionary',
    'test-spark-extras-angular-highlight-board',
    cb,
  );
});

gulp.task('test-react', (cb) => {
  runSequence(
    'test-spark-core-react',
    cb,
  );
});

// netlify
gulp.task('build', (cb) => {
  runSequence(
    'pre-publish',
    cb,
  );
});

// netlify angular
gulp.task('build-angular', (cb) => {
  runSequence(
    'install-angular-dev-app',
    'setup-spark-packages',
    'setup-spark-angular-projects',
    'build-angular-dev-app-netlify',
    cb,
  );
});

// netlify react
gulp.task('build-react', (cb) => {
  runSequence(
    'setup-spark-packages',
    'install-react-dev-app',
    'link-spark-to-react-dir',
    'setup-spark-core-react',
    'build-react-dev-app-netlify',
    cb,
  );
});
<commit_msg>updated comment again<commit_after>const gulp = require('gulp');
const runSequence = require('run-sequence');

require('./gulp/spark-core/spark-core.gulpfile.js');
require('./gulp/spark-extras/spark-card.gulpfile.js');
require('./gulp/spark-extras/spark-dictionary.gulpfile.js');
require('./gulp/spark-extras/spark-highlight-board.gulpfile.js');
require('./gulp/drizzle/drizzle.gulpfile.js');
require('./gulp/angular/dev-app/angulardevapp.gulpfile.js');
require('./gulp/angular/spark-core-angular/spark-core-angular.gulpfile.js');
require('./gulp/angular/spark-extras-angular-award/spark-extras-angular-award.gulpfile.js');
require('./gulp/angular/spark-extras-angular-card/spark-extras-angular-card.gulpfile.js');
require('./gulp/angular/spark-extras-angular-dictionary/spark-extras-angular-dictionary.gulpfile.js');
require('./gulp/angular/spark-extras-angular-highlight-board/spark-extras-angular-highlight-board.gulpfile.js');
require('./gulp/react/dev-app/reactdevapp.gulpfile.js');
require('./gulp/react/spark-core-react/spark-core-react.gulpfile.js');

gulp.task('pre-publish', (cb) => {
  runSequence(
    'setup-spark-packages',
    'build-drizzle',
    'install-angular-dev-app',
    'install-react-dev-app',
    'link-spark-to-react-dir',
    'setup-spark-angular-projects',
    'setup-spark-core-react',
    cb,
  );
});

gulp.task('setup-spark-packages', (cb) => {
  runSequence(
    'setup-spark-core',
    'setup-spark-card',
    'setup-spark-dictionary',
    'setup-spark-highlight-board',
    cb,
  );
});

// assumes that setup-spark-packages has been run
gulp.task('setup-spark-angular-projects', (cb) => {
  runSequence(
    'setup-spark-core-angular',
    [
      'setup-spark-extras-angular-award',
      'setup-spark-extras-angular-card',
      'setup-spark-extras-angular-dictionary',
      'setup-spark-extras-angular-highlight-board',
    ],
    cb,
  );
});

gulp.task('clean-all', (cb) => {
  runSequence(
    [
      'clean',
      'clean-spark-core',
      'clean-spark-highlight-board',
      'clean-angular-dev-app',
      'clean-react-dev-app',
      'clean-spark-core-react',
      'clean-spark-core-angular',
      'clean-spark-extras-angular-award',
      'clean-spark-extras-angular-card',
      'clean-spark-extras-angular-dictionary',
      'clean-spark-extras-angular-highlight-board',
    ],
    cb,
  );
});

gulp.task('dev-spark-packages', (cb) => {
  runSequence('setup-spark-packages', 'build-drizzle', ['watch', 'serve'], cb);
});

gulp.task('dev-spark-angular', (cb) => {
  runSequence(
    'install-angular-dev-app',
    'setup-spark-packages',
    'setup-spark-angular-projects',
    ['serve-angular-dev-app', 'watch'],
    cb,
  );
});

gulp.task('dev-spark-react', (cb) => {
  runSequence(
    'setup-spark-packages',
    'install-react-dev-app',
    'link-spark-to-react-dir',
    'setup-spark-core-react',
    ['serve-react-dev-app', 'watch'],
    cb,
  );
});

gulp.task('dev-all', (cb) => {
  runSequence(
    'setup-spark-packages',
    'install-angular-dev-app',
    'install-react-dev-app',
    'setup-spark-angular-projects',
    'link-spark-to-react-dir',
    'setup-spark-core-react',
    'build-drizzle',
    ['serve-angular-dev-app', 'serve-react-dev-app', 'serve', 'watch'],
    cb,
  );
});

gulp.task('test-angular', (cb) => {
  runSequence(
    'test-spark-core-angular',
    'test-spark-extras-angular-award',
    'test-spark-extras-angular-card',
    'test-spark-extras-angular-dictionary',
    'test-spark-extras-angular-highlight-board',
    cb,
  );
});

gulp.task('test-react', (cb) => {
  runSequence(
    'test-spark-core-react',
    cb,
  );
});

// netlify
gulp.task('build', (cb) => {
  runSequence(
    'pre-publish',
    cb,
  );
});

// netlify
gulp.task('build-angular', (cb) => {
  runSequence(
    'install-angular-dev-app',
    'setup-spark-packages',
    'setup-spark-angular-projects',
    'build-angular-dev-app-netlify',
    cb,
  );
});

// netlify react
gulp.task('build-react', (cb) => {
  runSequence(
    'setup-spark-packages',
    'install-react-dev-app',
    'link-spark-to-react-dir',
    'setup-spark-core-react',
    'build-react-dev-app-netlify',
    cb,
  );
});
<|endoftext|>


<commit_before>var gulp = require('gulp'),
    uglify = require('gulp-uglify'),
    imagemin = require('gulp-imagemin');

var services = ['medical-diagnosis', 'patient-med-profile', 'research-platform', 'surgery-printing'];

// Javascript minification task
// Minify javascript files and put the minified version in the dist folder
gulp.task('js-minify', function(){
    gulp.src('src/js/**')
        .pipe(uglify())
        .pipe(gulp.dest('dist/js'));
    // Dive also into services
    for (var i=0; i<services.length; i++) {
        gulp.src('src/services/'+services[i]+'/js/**')
            .pipe(uglify())
            .pipe(gulp.dest('dist/services/'+services[i]+'/js'));
    }
});

// Image task
// Compress images files
gulp.task('img-minify', function(){
    gulp.src('src/media/img/**')
        .pipe(imagemin())
        .pipe(gulp.dest('dist/media/img'));
    // Dive also into services
    for (var i=0; i<services.length; i++) {
        gulp.src('src/services/'+services[i]+'/media/img/**')
            .pipe(imagemin())
            .pipe(gulp.dest('dist/services/'+services[i]+'/media/img'));
    }
});

// Copying task
// Simple copy content to dist
gulp.task('simply-copy', function(){
    gulp.src('src/css/**')
        .pipe(gulp.dest('dist/css'));
    gulp.src('src/includes/**')
        .pipe(gulp.dest('dist/includes'));
    gulp.src('src/services/**')
        .pipe(gulp.dest('dist/services'));
    gulp.src('src/*.php')
        .pipe(gulp.dest('dist'));
    gulp.src('src/*.txt')
        .pipe(gulp.dest('dist'));
    gulp.src('src/*.ico')
        .pipe(gulp.dest('dist'));
});

// Default task to run all of the above tasks
gulp.task('default', ['js-minify', 'simply-copy', 'img-minify']);
<commit_msg>Added to gulp process build instruction for core folder<commit_after>var gulp = require('gulp'),
    uglify = require('gulp-uglify'),
    imagemin = require('gulp-imagemin');

var services = ['medical-diagnosis', 'patient-med-profile', 'research-platform', 'surgery-printing'];

// Javascript minification task
// Minify javascript files and put the minified version in the dist folder
gulp.task('js-minify', function(){
    gulp.src('src/js/**')
        .pipe(uglify())
        .pipe(gulp.dest('dist/js'));
    // Dive also into services
    for (var i=0; i<services.length; i++) {
        gulp.src('src/services/'+services[i]+'/js/**')
            .pipe(uglify())
            .pipe(gulp.dest('dist/services/'+services[i]+'/js'));
    }
});

// Image task
// Compress images files
gulp.task('img-minify', function(){
    gulp.src('src/media/img/**')
        .pipe(imagemin())
        .pipe(gulp.dest('dist/media/img'));
    // Dive also into services
    for (var i=0; i<services.length; i++) {
        gulp.src('src/services/'+services[i]+'/media/img/**')
            .pipe(imagemin())
            .pipe(gulp.dest('dist/services/'+services[i]+'/media/img'));
    }
});

// Copying task
// Simple copy content to dist
gulp.task('simply-copy', function(){
    gulp.src('src/core/**')
        .pipe(gulp.dest('dist/core'));
    gulp.src('src/css/**')
        .pipe(gulp.dest('dist/css'));
    gulp.src('src/includes/**')
        .pipe(gulp.dest('dist/includes'));
    gulp.src('src/services/**')
        .pipe(gulp.dest('dist/services'));
    gulp.src('src/*.php')
        .pipe(gulp.dest('dist'));
    gulp.src('src/*.txt')
        .pipe(gulp.dest('dist'));
    gulp.src('src/*.ico')
        .pipe(gulp.dest('dist'));
});

// Default task to run all of the above tasks
gulp.task('default', ['js-minify', 'simply-copy', 'img-minify']);
<|endoftext|>


<commit_before>// check for Geolocation support
if (navigator.geolocation)
{

    console.log('Geolocation is supported!');
}
else
{
    alert('Geolocation is not supported for this Browser/OS version yet.');
}

// our current position
var worldAdjustRotation = null;
var positionHng;
var defaultOrientation;
var positionCurrent = {
    lat: null,
    lng: null,
    hng: null
};

function getBrowserOrientation() {
    var orientation;
    if (screen.orientation && screen.orientation.type) {
        orientation = screen.orientation.type;
    } else {
        orientation = screen.orientation ||
            screen.mozOrientation ||
            screen.msOrientation;
    }

    /*
     'portait-primary':      for (screen width < screen height, e.g. phone, phablet, small tablet)
     device is in 'normal' orientation
     for (screen width > screen height, e.g. large tablet, laptop)
     device has been turned 90deg clockwise from normal

     'portait-secondary':    for (screen width < screen height)
     device has been turned 180deg from normal
     for (screen width > screen height)
     device has been turned 90deg anti-clockwise (or 270deg clockwise) from normal

     'landscape-primary':    for (screen width < screen height)
     device has been turned 90deg clockwise from normal
     for (screen width > screen height)
     device is in 'normal' orientation

     'landscape-secondary':  for (screen width < screen height)
     device has been turned 90deg anti-clockwise (or 270deg clockwise) from normal
     for (screen width > screen height)
     device has been turned 180deg from normal
     */

    return orientation;
}

function onHeadingChange(event) {
    var heading = event.alpha;

    if (typeof event.webkitCompassHeading !== "undefined") {
        heading = event.webkitCompassHeading; //iOS non-standard
    }

    var orientation = getBrowserOrientation();

    if (typeof heading !== "undefined" && heading !== null)
    {
        // && typeof orientation !== "undefined") {
        // we have a browser that reports device heading and orientation

        // what adjustment we have to add to rotation to allow for current device orientation
        var adjustment = 0;
        if (defaultOrientation === "landscape") {
            adjustment -= 90;
        }

        if (typeof orientation !== "undefined") {
            var currentOrientation = orientation.split("-");

            if (defaultOrientation !== currentOrientation[0])
            {
                if (defaultOrientation === "landscape")
                {
                    adjustment -= 270;
                }
                else
                {
                    adjustment -= 90;
                }
            }

            if (currentOrientation[1] === "secondary")
            {
                adjustment -= 180;
            }
        }

        positionCurrent.hng = heading + adjustment;

        var phase = positionCurrent.hng < 0 ? 360 + positionCurrent.hng : positionCurrent.hng;
        //positionHng.textContent = (360 - phase | 0) + "°";

        console.log('positionCurrent.hng ',positionCurrent.hng,positionCurrent);
        console.log( (360 - phase | 0) + "°");

        var ajusteRot = null;
        if(ajusteRot == null)
        {
            ajusteRot = 90 - positionCurrent.hng;
            alert('Ajuste: '+ajusteRot);
            //$('.orientation').html('
AJUSTE ROT: '+ajusteRot+'
')
        }

        //$('#pointers').attr('rotation','0 '+ajusteRot+' 0');

        $('.brujula').html(parseFloat(positionCurrent.hng).toFixed(2)+ "°")

        /*
        // apply rotation to compass rose
        if (typeof rose.style.transform !== "undefined") {
            rose.style.transform = "rotateZ(" + positionCurrent.hng + "deg)";
        } else if (typeof rose.style.webkitTransform !== "undefined") {
            rose.style.webkitTransform = "rotateZ(" + positionCurrent.hng + "deg)";
        }
        */
    }
    else
    {
        // device can't show heading

        positionHng  = "n/a";
        console.log('brujula no disponible');
    }
}

if (window.DeviceOrientationEvent) {

    if (screen.width > screen.height)
    {
        defaultOrientation = "landscape";
    }
    else
    {
        defaultOrientation = "portrait";
    }

    window.addEventListener("deviceorientation", onHeadingChange);
    /*
    window.addEventListener("deviceorientation", function(event)
    {

        var xValue      = Math.round(event.gamma);
        var yValue      = Math.round(event.beta);
        var rotation    = Math.round(event.alpha);

        //$('#cameraControl').attr('rotation' , '0 '+yValue+' 0');

        $('.orientation').html('xValue :'+xValue + '
yValue :'+yValue+ '
rotation :'+rotation)

    }, true)
    */

} else {
    alert("Sorry, your browser doesn't support Device Orientation");
}

MAP_WIDTH           = 100000;
MAP_HEIGHT          = 100000;
var store_current   = null;

function convert(lat, lon){
    var y = ((-1 * lat) + 90) * (MAP_HEIGHT / 180);
    var x = (lon + 180) * (MAP_WIDTH / 360);
    return {x:x,y:y};
}

window.onload = function()
{
    var startPos;
    var stores =
    [
        {
            lat: 19.4375921,
            lng: -99.2099433,
            info:{
                title: 'Superama Los Morales',
                horario: 'horario',
                promo: 'promo',
                info: 'info',
                desc: 'desc',
                dist: 'dist',
                type: 'superama'
            }
        },
        {
            lat: 19.4477107,
            lng: -99.2171927,
            info:{
                title: 'Sam\'s Club Toreo',
                horario: 'horario',
                promo: 'promo',
                info: 'info',
                desc: 'desc',
                dist: 'dist',
                type: 'sams'
            }
        },
        {
            lat: 19.4373714,
            lng: -99.2056145,
            info:{
                title: 'Superama Polanco',
                horario: 'horario',
                promo: 'promo',
                info: 'info',
                desc: 'desc',
                dist: 'dist',
                type: 'superama'
            }
        },
        {
            lat: 19.2973321,
            lng: -99.1065446,
            info:{
                title: 'Walmart Pabellón Cuemanco',
                horario: 'horario',
                promo: 'promo',
                info: 'info',
                desc: 'desc',
                dist: 'dist',
                type: 'supercenter'
            }
        },
        {
            lat: 19.2989663,
            lng: -99.1059896,
            info:{
                title: 'Bodega Aurrera Hueso',
                horario: 'horario',
                promo: 'promo',
                info: 'info',
                desc: 'desc',
                dist: 'dist',
                type: 'ba'
            }
        },
        {
            lat: 19.2982219,
            lng: -99.1143161,
            info:{
                title: 'Audi Coapa',
                horario: 'horario',
                promo: 'promo',
                info: 'info',
                desc: 'desc',
                dist: 'dist',
                type: 'ba'
            }
        },
        {
            lat:19.2969037,
            lng: -99.1119386,
            info:{
                title: 'IIM',
                horario: 'horario',
                promo: 'promo',
                info: 'info',
                desc: 'desc',
                dist: 'dist',
                type: 'ba'
            }
        },

    ];

    $('.cerrar').click(function()
    {
        $('.info').hide();
    });

    $('.debug').click(function()
    {
        if($('#tripmeter').is(':visible'))
        {
            $('#tripmeter').hide();
        }
        else
        {
            $('#tripmeter').show();
        }
    });

    //ajuste inical mundo, mandar el norte arriba
    $('#pointers').attr('rotation','0 -90 0');

    //ajuste por la posicion inicial del teléfono con respecto al norte
    $('#pointers').attr('rotation','0 146 0');

    navigator.geolocation.getCurrentPosition(
        function(position)
        {
            startPos = position;
            document.getElementById('startLat').innerHTML = startPos.coords.latitude;
            document.getElementById('startLon').innerHTML = startPos.coords.longitude;

            //console.log('startPos ', startPos);
            //console.log('camera '  , $('#camera').attr('position'));

            var convStart   = convert(startPos.coords.latitude,startPos.coords.longitude);
            var conv        = convert(stores[0].lat,stores[0].lng);
            var dif         =
            {
                x: convStart.x - conv.x,
                y: convStart.y - conv.y
            }

            $('#superama').attr('position',dif.x+' 0.5 '+dif.y);

            var convSams    = convert(stores[1].lat,stores[1].lng);
            var difSams     =
            {
                x: convStart.x - convSams.x,
                y: convStart.y - convSams.y
            }

            $('#sams').attr('position',difSams.x+' 0.5 '+difSams.y);
            $('#sams').attr('show-info', JSON.stringify(stores[1].info));

            var convSup    = convert(stores[2].lat,stores[2].lng);
            var difSup     =
            {
                x: convStart.x - convSup.x,
                y: convStart.y - convSup.y
            }
            $('#supPol').attr('position',difSup.x+' 0.5 '+difSup.y);

            var offset = 10000;
            var difCoordenads = {
                x: (startPos.coords.latitude     - stores[0].lat)*offset,
                y: (startPos.coords.longitude    - stores[0].lng)*offset
            }

            $('#sams').attr('position',difCoordenads.x+' 0.5 '+difCoordenads.y);
            //console.log(dif,difCoordenads)

            generatePin(startPos)

        },
        function(error)
        {
            alert('Error occurred. Error code: ' + error.code);
            // error.code can be:
            //   0: unknown error
            //   1: permission denied
            //   2: position unavailable (error response from locaton provider)
            //   3: timed out
        });

    navigator.geolocation.watchPosition(
        function(position)
        {
            console.log('store_current ',store_current);
            document.getElementById('currentLat').innerHTML = position.coords.latitude;
            document.getElementById('currentLon').innerHTML = position.coords.longitude;

            $('.stores').html('');
            for(var s in stores)
            {
                $('.stores').append('
Distance to '+stores[s].info.title+':
 '+calculateDistance(stores[s].lat, stores[s].lng,position.coords.latitude, position.coords.longitude)+' m
')
            }

            if(store_current!=null)
            {
                $('.txt.dist').show();
                $('.txt.dist').html(this.calculateDistance(store_current.lat, store_current.lng,position.coords.latitude, position.coords.longitude)+'m');
            }

        });

    function generatePin(startPos)
    {
        var offset  = 5000;
        var scene   = document.getElementById('pointers');

        for(var s in stores)
        {

            var convStart   = convert(startPos.coords.latitude,startPos.coords.longitude);
            var conv        = convert(stores[s].lat,stores[s].lng);
            var difCoordenads =
            {
                x: convStart.x - conv.x,
                y: convStart.y - conv.y
            }

            difCoordenads =
            {
                x: (startPos.coords.latitude     - stores[s].lat)*offset,
                y: (startPos.coords.longitude    - stores[s].lng)*offset
            }
            //console.log(difCoordenads)

            var color = '#123123';
            if(stores[s].info.title == 'IIM')
            {
                color = '#ff0000';
            }

            if(stores[s].info.title == 'Audi Coapa')
            {
                color = '#00ff00';
            }

            console.log('X:', startPos.coords.latitude, stores[s].lat , difCoordenads.x , stores[s].info.title);
            console.log(' ');

            var box	= document.createElement('a-box');
            box.setAttribute("position"	, difCoordenads.x+' 0.5 '+difCoordenads.y);
            //box.setAttribute("position"	, difCoordenads.x+' 0.5 0');
            box.setAttribute("rotation"	, "0 45 0");
            box.setAttribute("show-info", JSON.stringify(stores[s]));
            box.setAttribute("color"    , color);
            //box.setAttribute("look-at"	, "[camera]");

            console.log('position' , difCoordenads.x+' 0.5 '+difCoordenads.y)

            scene.appendChild(box);
        }

        var norte	= document.createElement('a-entity');
        norte.setAttribute("position"   , '-10 0 0');
        norte.setAttribute("text"       , 'width:10; color:black; value:Norte; align:center;');
        norte.setAttribute("look-at"	, "[camera]");
        scene.appendChild(norte);

        var sur	= document.createElement('a-entity');
        sur.setAttribute("position"     , '10 0 0');
        sur.setAttribute("text"         , 'width:10; color:black; value:Sur; align:center;');
        sur.setAttribute("look-at"	    , "[camera]");
        scene.appendChild(sur);

        var este	= document.createElement('a-entity');
        este.setAttribute("position"     , '0 0 -10');
        este.setAttribute("text"         , 'width:10; color:black; value:Este; align:center;');
        este.setAttribute("look-at"	    , "[camera]");
        scene.appendChild(este);

        var oeste	= document.createElement('a-entity');
        oeste.setAttribute("position"     , '0 0 10');
        oeste.setAttribute("text"         , 'width:10; color:black; value:Oeste; align:center;');
        oeste.setAttribute("look-at"	  , "[camera]");
        scene.appendChild(oeste);

    }
};

function calculateDistance(lat1, lon1, lat2, lon2)
{
    var R = 6371 * 1000; // m
    var dLat = (lat2 - lat1).toRad();
    var dLon = (lon2 - lon1).toRad();
    var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
            Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
            Math.sin(dLon / 2) * Math.sin(dLon / 2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    var d = R * c;
    return d;
}

Number.prototype.toRad = function()
{
    return this * Math.PI / 180;
}
<commit_msg>alert ajuste<commit_after>// check for Geolocation support
if (navigator.geolocation)
{

    console.log('Geolocation is supported!');
}
else
{
    alert('Geolocation is not supported for this Browser/OS version yet.');
}

// our current position
var worldAdjustRotation = null;
var ajusteRot = null;
var positionHng;
var defaultOrientation;
var positionCurrent = {
    lat: null,
    lng: null,
    hng: null
};

function getBrowserOrientation() {
    var orientation;
    if (screen.orientation && screen.orientation.type) {
        orientation = screen.orientation.type;
    } else {
        orientation = screen.orientation ||
            screen.mozOrientation ||
            screen.msOrientation;
    }

    /*
     'portait-primary':      for (screen width < screen height, e.g. phone, phablet, small tablet)
     device is in 'normal' orientation
     for (screen width > screen height, e.g. large tablet, laptop)
     device has been turned 90deg clockwise from normal

     'portait-secondary':    for (screen width < screen height)
     device has been turned 180deg from normal
     for (screen width > screen height)
     device has been turned 90deg anti-clockwise (or 270deg clockwise) from normal

     'landscape-primary':    for (screen width < screen height)
     device has been turned 90deg clockwise from normal
     for (screen width > screen height)
     device is in 'normal' orientation

     'landscape-secondary':  for (screen width < screen height)
     device has been turned 90deg anti-clockwise (or 270deg clockwise) from normal
     for (screen width > screen height)
     device has been turned 180deg from normal
     */

    return orientation;
}

function onHeadingChange(event) {
    var heading = event.alpha;

    if (typeof event.webkitCompassHeading !== "undefined") {
        heading = event.webkitCompassHeading; //iOS non-standard
    }

    var orientation = getBrowserOrientation();

    if (typeof heading !== "undefined" && heading !== null)
    {
        // && typeof orientation !== "undefined") {
        // we have a browser that reports device heading and orientation

        // what adjustment we have to add to rotation to allow for current device orientation
        var adjustment = 0;
        if (defaultOrientation === "landscape") {
            adjustment -= 90;
        }

        if (typeof orientation !== "undefined") {
            var currentOrientation = orientation.split("-");

            if (defaultOrientation !== currentOrientation[0])
            {
                if (defaultOrientation === "landscape")
                {
                    adjustment -= 270;
                }
                else
                {
                    adjustment -= 90;
                }
            }

            if (currentOrientation[1] === "secondary")
            {
                adjustment -= 180;
            }
        }

        positionCurrent.hng = heading + adjustment;

        var phase = positionCurrent.hng < 0 ? 360 + positionCurrent.hng : positionCurrent.hng;
        //positionHng.textContent = (360 - phase | 0) + "°";

        console.log('positionCurrent.hng ',positionCurrent.hng,positionCurrent);
        console.log( (360 - phase | 0) + "°");

        if(ajusteRot == null && positionCurrent.hng!=0)
        {
            ajusteRot = 90 - positionCurrent.hng;
            alert('Ajuste: '+ajusteRot);
            //$('.orientation').html('
AJUSTE ROT: '+ajusteRot+'
')
        }

        //$('#pointers').attr('rotation','0 '+ajusteRot+' 0');

        $('.brujula').html(parseFloat(positionCurrent.hng).toFixed(2)+ "°")

        /*
        // apply rotation to compass rose
        if (typeof rose.style.transform !== "undefined") {
            rose.style.transform = "rotateZ(" + positionCurrent.hng + "deg)";
        } else if (typeof rose.style.webkitTransform !== "undefined") {
            rose.style.webkitTransform = "rotateZ(" + positionCurrent.hng + "deg)";
        }
        */
    }
    else
    {
        // device can't show heading

        positionHng  = "n/a";
        console.log('brujula no disponible');
    }
}

if (window.DeviceOrientationEvent) {

    if (screen.width > screen.height)
    {
        defaultOrientation = "landscape";
    }
    else
    {
        defaultOrientation = "portrait";
    }

    window.addEventListener("deviceorientation", onHeadingChange);
    /*
    window.addEventListener("deviceorientation", function(event)
    {

        var xValue      = Math.round(event.gamma);
        var yValue      = Math.round(event.beta);
        var rotation    = Math.round(event.alpha);

        //$('#cameraControl').attr('rotation' , '0 '+yValue+' 0');

        $('.orientation').html('xValue :'+xValue + '
yValue :'+yValue+ '
rotation :'+rotation)

    }, true)
    */

} else {
    alert("Sorry, your browser doesn't support Device Orientation");
}

MAP_WIDTH           = 100000;
MAP_HEIGHT          = 100000;
var store_current   = null;

function convert(lat, lon){
    var y = ((-1 * lat) + 90) * (MAP_HEIGHT / 180);
    var x = (lon + 180) * (MAP_WIDTH / 360);
    return {x:x,y:y};
}

window.onload = function()
{
    var startPos;
    var stores =
    [
        {
            lat: 19.4375921,
            lng: -99.2099433,
            info:{
                title: 'Superama Los Morales',
                horario: 'horario',
                promo: 'promo',
                info: 'info',
                desc: 'desc',
                dist: 'dist',
                type: 'superama'
            }
        },
        {
            lat: 19.4477107,
            lng: -99.2171927,
            info:{
                title: 'Sam\'s Club Toreo',
                horario: 'horario',
                promo: 'promo',
                info: 'info',
                desc: 'desc',
                dist: 'dist',
                type: 'sams'
            }
        },
        {
            lat: 19.4373714,
            lng: -99.2056145,
            info:{
                title: 'Superama Polanco',
                horario: 'horario',
                promo: 'promo',
                info: 'info',
                desc: 'desc',
                dist: 'dist',
                type: 'superama'
            }
        },
        {
            lat: 19.2973321,
            lng: -99.1065446,
            info:{
                title: 'Walmart Pabellón Cuemanco',
                horario: 'horario',
                promo: 'promo',
                info: 'info',
                desc: 'desc',
                dist: 'dist',
                type: 'supercenter'
            }
        },
        {
            lat: 19.2989663,
            lng: -99.1059896,
            info:{
                title: 'Bodega Aurrera Hueso',
                horario: 'horario',
                promo: 'promo',
                info: 'info',
                desc: 'desc',
                dist: 'dist',
                type: 'ba'
            }
        },
        {
            lat: 19.2982219,
            lng: -99.1143161,
            info:{
                title: 'Audi Coapa',
                horario: 'horario',
                promo: 'promo',
                info: 'info',
                desc: 'desc',
                dist: 'dist',
                type: 'ba'
            }
        },
        {
            lat:19.2969037,
            lng: -99.1119386,
            info:{
                title: 'IIM',
                horario: 'horario',
                promo: 'promo',
                info: 'info',
                desc: 'desc',
                dist: 'dist',
                type: 'ba'
            }
        },

    ];

    $('.cerrar').click(function()
    {
        $('.info').hide();
    });

    $('.debug').click(function()
    {
        if($('#tripmeter').is(':visible'))
        {
            $('#tripmeter').hide();
        }
        else
        {
            $('#tripmeter').show();
        }
    });

    //ajuste inical mundo, mandar el norte arriba
    $('#pointers').attr('rotation','0 -90 0');

    //ajuste por la posicion inicial del teléfono con respecto al norte
    $('#pointers').attr('rotation','0 146 0');

    navigator.geolocation.getCurrentPosition(
        function(position)
        {
            startPos = position;
            document.getElementById('startLat').innerHTML = startPos.coords.latitude;
            document.getElementById('startLon').innerHTML = startPos.coords.longitude;

            //console.log('startPos ', startPos);
            //console.log('camera '  , $('#camera').attr('position'));

            var convStart   = convert(startPos.coords.latitude,startPos.coords.longitude);
            var conv        = convert(stores[0].lat,stores[0].lng);
            var dif         =
            {
                x: convStart.x - conv.x,
                y: convStart.y - conv.y
            }

            $('#superama').attr('position',dif.x+' 0.5 '+dif.y);

            var convSams    = convert(stores[1].lat,stores[1].lng);
            var difSams     =
            {
                x: convStart.x - convSams.x,
                y: convStart.y - convSams.y
            }

            $('#sams').attr('position',difSams.x+' 0.5 '+difSams.y);
            $('#sams').attr('show-info', JSON.stringify(stores[1].info));

            var convSup    = convert(stores[2].lat,stores[2].lng);
            var difSup     =
            {
                x: convStart.x - convSup.x,
                y: convStart.y - convSup.y
            }
            $('#supPol').attr('position',difSup.x+' 0.5 '+difSup.y);

            var offset = 10000;
            var difCoordenads = {
                x: (startPos.coords.latitude     - stores[0].lat)*offset,
                y: (startPos.coords.longitude    - stores[0].lng)*offset
            }

            $('#sams').attr('position',difCoordenads.x+' 0.5 '+difCoordenads.y);
            //console.log(dif,difCoordenads)

            generatePin(startPos)

        },
        function(error)
        {
            alert('Error occurred. Error code: ' + error.code);
            // error.code can be:
            //   0: unknown error
            //   1: permission denied
            //   2: position unavailable (error response from locaton provider)
            //   3: timed out
        });

    navigator.geolocation.watchPosition(
        function(position)
        {
            console.log('store_current ',store_current);
            document.getElementById('currentLat').innerHTML = position.coords.latitude;
            document.getElementById('currentLon').innerHTML = position.coords.longitude;

            $('.stores').html('');
            for(var s in stores)
            {
                $('.stores').append('
Distance to '+stores[s].info.title+':
 '+calculateDistance(stores[s].lat, stores[s].lng,position.coords.latitude, position.coords.longitude)+' m
')
            }

            if(store_current!=null)
            {
                $('.txt.dist').show();
                $('.txt.dist').html(this.calculateDistance(store_current.lat, store_current.lng,position.coords.latitude, position.coords.longitude)+'m');
            }

        });

    function generatePin(startPos)
    {
        var offset  = 5000;
        var scene   = document.getElementById('pointers');

        for(var s in stores)
        {

            var convStart   = convert(startPos.coords.latitude,startPos.coords.longitude);
            var conv        = convert(stores[s].lat,stores[s].lng);
            var difCoordenads =
            {
                x: convStart.x - conv.x,
                y: convStart.y - conv.y
            }

            difCoordenads =
            {
                x: (startPos.coords.latitude     - stores[s].lat)*offset,
                y: (startPos.coords.longitude    - stores[s].lng)*offset
            }
            //console.log(difCoordenads)

            var color = '#123123';
            if(stores[s].info.title == 'IIM')
            {
                color = '#ff0000';
            }

            if(stores[s].info.title == 'Audi Coapa')
            {
                color = '#00ff00';
            }

            console.log('X:', startPos.coords.latitude, stores[s].lat , difCoordenads.x , stores[s].info.title);
            console.log(' ');

            var box	= document.createElement('a-box');
            box.setAttribute("position"	, difCoordenads.x+' 0.5 '+difCoordenads.y);
            //box.setAttribute("position"	, difCoordenads.x+' 0.5 0');
            box.setAttribute("rotation"	, "0 45 0");
            box.setAttribute("show-info", JSON.stringify(stores[s]));
            box.setAttribute("color"    , color);
            //box.setAttribute("look-at"	, "[camera]");

            console.log('position' , difCoordenads.x+' 0.5 '+difCoordenads.y)

            scene.appendChild(box);
        }

        var norte	= document.createElement('a-entity');
        norte.setAttribute("position"   , '-10 0 0');
        norte.setAttribute("text"       , 'width:10; color:black; value:Norte; align:center;');
        norte.setAttribute("look-at"	, "[camera]");
        scene.appendChild(norte);

        var sur	= document.createElement('a-entity');
        sur.setAttribute("position"     , '10 0 0');
        sur.setAttribute("text"         , 'width:10; color:black; value:Sur; align:center;');
        sur.setAttribute("look-at"	    , "[camera]");
        scene.appendChild(sur);

        var este	= document.createElement('a-entity');
        este.setAttribute("position"     , '0 0 -10');
        este.setAttribute("text"         , 'width:10; color:black; value:Este; align:center;');
        este.setAttribute("look-at"	    , "[camera]");
        scene.appendChild(este);

        var oeste	= document.createElement('a-entity');
        oeste.setAttribute("position"     , '0 0 10');
        oeste.setAttribute("text"         , 'width:10; color:black; value:Oeste; align:center;');
        oeste.setAttribute("look-at"	  , "[camera]");
        scene.appendChild(oeste);

    }
};

function calculateDistance(lat1, lon1, lat2, lon2)
{
    var R = 6371 * 1000; // m
    var dLat = (lat2 - lat1).toRad();
    var dLon = (lon2 - lon1).toRad();
    var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
            Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
            Math.sin(dLon / 2) * Math.sin(dLon / 2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    var d = R * c;
    return d;
}

Number.prototype.toRad = function()
{
    return this * Math.PI / 180;
}
<|endoftext|>


<commit_before>/* jshint maxdepth:7*/
steal("can/view", function(can){

	function makeMap(str){
		var obj = {}, items = str.split(",");
		for ( var i = 0; i < items.length; i++ ) {
			obj[ items[i] ] = true;
		}

		return obj;
	}

	var alphaNumericHU = "-A-Za-z0-9_",
		attributeNames = "[a-zA-Z_:]["+alphaNumericHU+":.]+",
		spaceEQspace = "\\s*=\\s*",
		dblQuote2dblQuote = "\"((?:\\\\.|[^\"])*)\"",
		quote2quote = "'((?:\\\\.|[^'])*)'",
		attributeEqAndValue = "(?:"+spaceEQspace+"(?:"+
		  "(?:\"[^\"]*\")|(?:'[^']*')|[^>\\s]+))?",
		matchStash = "\\{\\{[^\\}]*\\}\\}\\}?",
		stash = "\\{\\{([^\\}]*)\\}\\}\\}?",
		startTag = new RegExp("^<(["+alphaNumericHU+"]+)"+
				"(" +
					"(?:\\s*"+
						"(?:(?:"+
							"(?:"+attributeNames+")?"+
							attributeEqAndValue+")|"+
	                   "(?:"+matchStash+")+)"+
	                ")*"+
	            ")\\s*(\\/?)>"),
		endTag = new RegExp("^<\\/(["+alphaNumericHU+"]+)[^>]*>"),
		attr = new RegExp("(?:"+
					"(?:("+attributeNames+")|"+stash+")"+
								"(?:"+spaceEQspace+
									"(?:"+
										"(?:"+dblQuote2dblQuote+")|(?:"+quote2quote+")|([^>\\s]+)"+
									")"+
								")?)","g"),
		mustache = new RegExp(stash,"g"),
		txtBreak = /<|\{\{/;

	// Empty Elements - HTML 5
	var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed");

	// Block Elements - HTML 5
	var block = makeMap("address,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video");

	// Inline Elements - HTML 5
	var inline = makeMap("a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var");

	// Elements that you can, intentionally, leave open
	// (and which close themselves)
	var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");

	// Attributes that have their values filled in disabled="disabled"
	var fillAttrs = makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");

	// Special Elements (can contain anything)
	var special = makeMap("script,style");

	var HTMLParser = function (html, handler) {

		function parseStartTag(tag, tagName, rest, unary) {
			tagName = tagName.toLowerCase();

			if (block[tagName]) {
				while (stack.last() && inline[stack.last()]) {
					parseEndTag("", stack.last());
				}
			}

			if (closeSelf[tagName] && stack.last() === tagName) {
				parseEndTag("", tagName);
			}

			unary = empty[tagName] || !!unary;

			handler.start(tagName, unary);

			if (!unary) {
				stack.push(tagName);
			}
			// find attribute or special
			HTMLParser.parseAttrs(rest, handler);

			handler.end(tagName,unary);

		}

		function parseEndTag(tag, tagName) {
			// If no tag name is provided, clean shop
			var pos;
			if (!tagName) {
				pos = 0;
			}

				// Find the closest opened tag of the same type
			else {
				for (pos = stack.length - 1; pos >= 0; pos--) {
					if (stack[pos] === tagName) {
						break;
					}
				}

			}

			if (pos >= 0) {
				// Close all the open elements, up the stack
				for (var i = stack.length - 1; i >= pos; i--) {
					if (handler.close) {
						handler.close(stack[i]);
					}
				}

				// Remove the open elements from the stack
				stack.length = pos;
			}
		}

		function parseMustache(mustache, inside){
			if(handler.special){
				handler.special(inside);
			}
		}

		var index, chars, match, stack = [], last = html;
		stack.last = function () {
			return this[this.length - 1];
		};

		while (html) {
			chars = true;

			// Make sure we're not in a script or style element
			if (!stack.last() || !special[stack.last()]) {

				// Comment
				if (html.indexOf("<!--") === 0) {
					index = html.indexOf("-->");

					if (index >= 0) {
						if (handler.comment) {
							handler.comment(html.substring(4, index));
						}
						html = html.substring(index + 3);
						chars = false;
					}

					// end tag
				} else if (html.indexOf("</") === 0) {
					match = html.match(endTag);

					if (match) {
						html = html.substring(match[0].length);
						match[0].replace(endTag, parseEndTag);
						chars = false;
					}

					// start tag
				} else if (html.indexOf("<") === 0) {
					match = html.match(startTag);

					if (match) {
						html = html.substring(match[0].length);
						match[0].replace(startTag, parseStartTag);
						chars = false;
					}
				} else if (html.indexOf("{{") === 0 ) {
					match = html.match(mustache);

					if (match) {
						html = html.substring(match[0].length);
						match[0].replace(mustache, parseMustache);
					}
				}

				if (chars) {
					index = html.search(txtBreak);

					var text = index < 0 ? html : html.substring(0, index);
					html = index < 0 ? "" : html.substring(index);

					if (handler.chars && text) {
						handler.chars(text);
					}
				}

			} else {
				html = html.replace(new RegExp("([\\s\\S]*?)<\/" + stack.last() + "[^>]*>"), function (all, text) {
					text = text.replace(/<!--([\s\S]*?)-->|<!\[CDATA\[([\s\S]*?)]]>/g, "$1$2");
					if (handler.chars) {
						handler.chars(text);
					}
					return "";
				});

				parseEndTag("", stack.last());
			}

			if (html === last) {
				throw "Parse Error: " + html;
			}

			last = html;
		}

		// Clean up any remaining tags
		parseEndTag();

		handler.done();
	};
	HTMLParser.parseAttrs = function(rest, handler){

		(rest != null ? rest : "").replace(attr, function (text, name, special, dblQuote, singleQuote, val) {
			if(special) {
				handler.special(special);

			}
			if(name || dblQuote || singleQuote || val) {
				var value = arguments[3] ? arguments[3] :
					arguments[4] ? arguments[4] :
					arguments[5] ? arguments[5] :
					fillAttrs[name.toLowerCase()] ? name : "";
				handler.attrStart(name || "");

				var last = mustache.lastIndex = 0,
					res = mustache.exec(value),
					chars;
				while(res) {
					chars = value.substring(
						last,
						mustache.lastIndex - res[0].length );
					if( chars.length ) {
						handler.attrValue(chars);
					}
					handler.special(res[1]);
					last = mustache.lastIndex;
					res = mustache.exec(value);
				}
				chars = value.substr(
						last,
						value.length );
				if(chars) {
					handler.attrValue(chars);
				}
				handler.attrEnd(name || "");
			}

		});

	};

	can.view.parser = HTMLParser;

	return HTMLParser;

});
<commit_msg>Fixed #1132, parser should support single-char attributes because it's needed for SVG elements, for example.<commit_after>/* jshint maxdepth:7*/
steal("can/view", function(can){

	function makeMap(str){
		var obj = {}, items = str.split(",");
		for ( var i = 0; i < items.length; i++ ) {
			obj[ items[i] ] = true;
		}

		return obj;
	}

	var alphaNumericHU = "-A-Za-z0-9_",
		attributeNames = "[a-zA-Z_:]["+alphaNumericHU+":.]*",
		spaceEQspace = "\\s*=\\s*",
		dblQuote2dblQuote = "\"((?:\\\\.|[^\"])*)\"",
		quote2quote = "'((?:\\\\.|[^'])*)'",
		attributeEqAndValue = "(?:"+spaceEQspace+"(?:"+
		  "(?:\"[^\"]*\")|(?:'[^']*')|[^>\\s]+))?",
		matchStash = "\\{\\{[^\\}]*\\}\\}\\}?",
		stash = "\\{\\{([^\\}]*)\\}\\}\\}?",
		startTag = new RegExp("^<(["+alphaNumericHU+"]+)"+
				"(" +
					"(?:\\s*"+
						"(?:(?:"+
							"(?:"+attributeNames+")?"+
							attributeEqAndValue+")|"+
	                   "(?:"+matchStash+")+)"+
	                ")*"+
	            ")\\s*(\\/?)>"),
		endTag = new RegExp("^<\\/(["+alphaNumericHU+"]+)[^>]*>"),
		attr = new RegExp("(?:"+
					"(?:("+attributeNames+")|"+stash+")"+
								"(?:"+spaceEQspace+
									"(?:"+
										"(?:"+dblQuote2dblQuote+")|(?:"+quote2quote+")|([^>\\s]+)"+
									")"+
								")?)","g"),
		mustache = new RegExp(stash,"g"),
		txtBreak = /<|\{\{/;

	// Empty Elements - HTML 5
	var empty = makeMap("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed");

	// Block Elements - HTML 5
	var block = makeMap("address,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video");

	// Inline Elements - HTML 5
	var inline = makeMap("a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var");

	// Elements that you can, intentionally, leave open
	// (and which close themselves)
	var closeSelf = makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");

	// Attributes that have their values filled in disabled="disabled"
	var fillAttrs = makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");

	// Special Elements (can contain anything)
	var special = makeMap("script,style");

	var HTMLParser = function (html, handler) {

		function parseStartTag(tag, tagName, rest, unary) {
			tagName = tagName.toLowerCase();

			if (block[tagName]) {
				while (stack.last() && inline[stack.last()]) {
					parseEndTag("", stack.last());
				}
			}

			if (closeSelf[tagName] && stack.last() === tagName) {
				parseEndTag("", tagName);
			}

			unary = empty[tagName] || !!unary;

			handler.start(tagName, unary);

			if (!unary) {
				stack.push(tagName);
			}
			// find attribute or special
			HTMLParser.parseAttrs(rest, handler);

			handler.end(tagName,unary);

		}

		function parseEndTag(tag, tagName) {
			// If no tag name is provided, clean shop
			var pos;
			if (!tagName) {
				pos = 0;
			}

				// Find the closest opened tag of the same type
			else {
				for (pos = stack.length - 1; pos >= 0; pos--) {
					if (stack[pos] === tagName) {
						break;
					}
				}

			}

			if (pos >= 0) {
				// Close all the open elements, up the stack
				for (var i = stack.length - 1; i >= pos; i--) {
					if (handler.close) {
						handler.close(stack[i]);
					}
				}

				// Remove the open elements from the stack
				stack.length = pos;
			}
		}

		function parseMustache(mustache, inside){
			if(handler.special){
				handler.special(inside);
			}
		}

		var index, chars, match, stack = [], last = html;
		stack.last = function () {
			return this[this.length - 1];
		};

		while (html) {
			chars = true;

			// Make sure we're not in a script or style element
			if (!stack.last() || !special[stack.last()]) {

				// Comment
				if (html.indexOf("<!--") === 0) {
					index = html.indexOf("-->");

					if (index >= 0) {
						if (handler.comment) {
							handler.comment(html.substring(4, index));
						}
						html = html.substring(index + 3);
						chars = false;
					}

					// end tag
				} else if (html.indexOf("</") === 0) {
					match = html.match(endTag);

					if (match) {
						html = html.substring(match[0].length);
						match[0].replace(endTag, parseEndTag);
						chars = false;
					}

					// start tag
				} else if (html.indexOf("<") === 0) {
					match = html.match(startTag);

					if (match) {
						html = html.substring(match[0].length);
						match[0].replace(startTag, parseStartTag);
						chars = false;
					}
				} else if (html.indexOf("{{") === 0 ) {
					match = html.match(mustache);

					if (match) {
						html = html.substring(match[0].length);
						match[0].replace(mustache, parseMustache);
					}
				}

				if (chars) {
					index = html.search(txtBreak);

					var text = index < 0 ? html : html.substring(0, index);
					html = index < 0 ? "" : html.substring(index);

					if (handler.chars && text) {
						handler.chars(text);
					}
				}

			} else {
				html = html.replace(new RegExp("([\\s\\S]*?)<\/" + stack.last() + "[^>]*>"), function (all, text) {
					text = text.replace(/<!--([\s\S]*?)-->|<!\[CDATA\[([\s\S]*?)]]>/g, "$1$2");
					if (handler.chars) {
						handler.chars(text);
					}
					return "";
				});

				parseEndTag("", stack.last());
			}

			if (html === last) {
				throw "Parse Error: " + html;
			}

			last = html;
		}

		// Clean up any remaining tags
		parseEndTag();

		handler.done();
	};
	HTMLParser.parseAttrs = function(rest, handler){

		(rest != null ? rest : "").replace(attr, function (text, name, special, dblQuote, singleQuote, val) {
			if(special) {
				handler.special(special);

			}
			if(name || dblQuote || singleQuote || val) {
				var value = arguments[3] ? arguments[3] :
					arguments[4] ? arguments[4] :
					arguments[5] ? arguments[5] :
					fillAttrs[name.toLowerCase()] ? name : "";
				handler.attrStart(name || "");

				var last = mustache.lastIndex = 0,
					res = mustache.exec(value),
					chars;
				while(res) {
					chars = value.substring(
						last,
						mustache.lastIndex - res[0].length );
					if( chars.length ) {
						handler.attrValue(chars);
					}
					handler.special(res[1]);
					last = mustache.lastIndex;
					res = mustache.exec(value);
				}
				chars = value.substr(
						last,
						value.length );
				if(chars) {
					handler.attrValue(chars);
				}
				handler.attrEnd(name || "");
			}

		});

	};

	can.view.parser = HTMLParser;

	return HTMLParser;

});
<|endoftext|>


<commit_before>/**
 * Created by andreas on 02.05.14.
 */
avnav.provide('avnav.gui.Aispage');

/**
 *
 * @constructor
 */
avnav.gui.Aispage=function(){
    avnav.gui.Page.call(this,'aispage');
    /**
     * @private
     * @type {avnav.nav.AisData}
     */
    this.aishandler=null;
    var self=this;
    $(document).on(avnav.nav.NavEvent.EVENT_TYPE, function(ev,evdata){
        self.navEvent(evdata);
    });
};
avnav.inherits(avnav.gui.Aispage,avnav.gui.Page);

avnav.gui.Aispage.prototype.localInit=function(){
    this.aishandler=this.navobject.getAisData();
};
avnav.gui.Aispage.prototype.showPage=function(options) {
    if (!this.gui) return;
    this.fillData(true);
};

avnav.gui.Aispage.prototype.fillData=function(initial){
    var domid="#avi_ais_page_inner";
    var formatter=this.aishandler.getAisFormatter();
    var aisList=this.aishandler.getAisData();
    var html='
';
    html+='
';
    for (var p in formatter){
        html+='
'+formatter[p].headline+'
';
    }
    html+='
';
    var hasTracking=this.aishandler.getTrackedTarget();
    for( var aisidx in aisList){
        var ais=aisList[aisidx];
        var addClass='';
        if (ais.warning) addClass='avn_ais_warning';
        else {
            if ((ais.tracking)|| (ais.nearest && ! hasTracking)) addClass='avn_ais_selected';
        }
        html+='
';
        for (var p in formatter){
            html+='
'+formatter[p].format(ais)+'
';
        }
        html+='
';
    }
    html+='
';
    $(domid).html(html);
    $(domid+' .avn_ais_selector').click({self:this},function(ev){
        var mmsi=$(this).attr('mmsi');
        ev.data.self.aishandler.setTrackedTarget(mmsi);
        var pos=ev.data.self.aishandler.getAisPositionByMmsi(mmsi);
        if (pos)ev.data.self.gui.map.setCenter(pos);
        ev.data.self.gui.showPageOrReturn(ev.data.self.returnpage,'navpage');
    });
    if (initial){
        var topElement=$(domid+' .avn_ais_selected').position();
        if (! topElement)topElement=$(domid+' .avn_ais_warning').position();
        if (topElement){
            $(domid).scrollTop(topElement.top);
        }
    }

};

avnav.gui.Aispage.prototype.localInit=function(){

};

avnav.gui.Aispage.prototype.hidePage=function(){

};
/**
 *
 * @param {avnav.nav.NavEvent} ev
 */
avnav.gui.Aispage.prototype.navEvent=function(ev){
    if (! this.visible) return;
    if (ev.type==avnav.nav.NavEventType.AIS){
        this.fillData(false);
    }
};
avnav.gui.Aispage.prototype.goBack=function(){
    this.btnAisCancel();
};
//-------------------------- Buttons ----------------------------------------

avnav.gui.Aispage.prototype.btnAisNearest=function (button,ev){
    this.aishandler.setTrackedTarget(0);
    this.gui.showPageOrReturn(this.returnpage,'navpage');
    log("Nearest clicked");
};

avnav.gui.Aispage.prototype.btnAisCancel=function (button,ev){
    log("Cancel clicked");
    this.gui.showPageOrReturn(this.returnpage,'navpage');
};
/**
 * create the page instance
 */
(function(){
    //create an instance of the status page handler
    var page=new avnav.gui.Aispage();
}());

<commit_msg>remove duplicate localInit<commit_after>/**
 * Created by andreas on 02.05.14.
 */
avnav.provide('avnav.gui.Aispage');

/**
 *
 * @constructor
 */
avnav.gui.Aispage=function(){
    avnav.gui.Page.call(this,'aispage');
    /**
     * @private
     * @type {avnav.nav.AisData}
     */
    this.aishandler=null;
    var self=this;
    $(document).on(avnav.nav.NavEvent.EVENT_TYPE, function(ev,evdata){
        self.navEvent(evdata);
    });
};
avnav.inherits(avnav.gui.Aispage,avnav.gui.Page);

avnav.gui.Aispage.prototype.localInit=function(){
    this.aishandler=this.navobject.getAisData();
};
avnav.gui.Aispage.prototype.showPage=function(options) {
    if (!this.gui) return;
    this.fillData(true);
};

avnav.gui.Aispage.prototype.fillData=function(initial){
    var domid="#avi_ais_page_inner";
    var formatter=this.aishandler.getAisFormatter();
    var aisList=this.aishandler.getAisData();
    var html='
';
    html+='
';
    for (var p in formatter){
        html+='
'+formatter[p].headline+'
';
    }
    html+='
';
    var hasTracking=this.aishandler.getTrackedTarget();
    for( var aisidx in aisList){
        var ais=aisList[aisidx];
        var addClass='';
        if (ais.warning) addClass='avn_ais_warning';
        else {
            if ((ais.tracking)|| (ais.nearest && ! hasTracking)) addClass='avn_ais_selected';
        }
        html+='
';
        for (var p in formatter){
            html+='
'+formatter[p].format(ais)+'
';
        }
        html+='
';
    }
    html+='
';
    $(domid).html(html);
    $(domid+' .avn_ais_selector').click({self:this},function(ev){
        var mmsi=$(this).attr('mmsi');
        ev.data.self.aishandler.setTrackedTarget(mmsi);
        var pos=ev.data.self.aishandler.getAisPositionByMmsi(mmsi);
        if (pos)ev.data.self.gui.map.setCenter(pos);
        ev.data.self.gui.showPageOrReturn(ev.data.self.returnpage,'navpage');
    });
    if (initial){
        var topElement=$(domid+' .avn_ais_selected').position();
        if (! topElement)topElement=$(domid+' .avn_ais_warning').position();
        if (topElement){
            $(domid).scrollTop(topElement.top);
        }
    }

};

avnav.gui.Aispage.prototype.hidePage=function(){

};
/**
 *
 * @param {avnav.nav.NavEvent} ev
 */
avnav.gui.Aispage.prototype.navEvent=function(ev){
    if (! this.visible) return;
    if (ev.type==avnav.nav.NavEventType.AIS){
        this.fillData(false);
    }
};
avnav.gui.Aispage.prototype.goBack=function(){
    this.btnAisCancel();
};
//-------------------------- Buttons ----------------------------------------

avnav.gui.Aispage.prototype.btnAisNearest=function (button,ev){
    this.aishandler.setTrackedTarget(0);
    this.gui.showPageOrReturn(this.returnpage,'navpage');
    log("Nearest clicked");
};

avnav.gui.Aispage.prototype.btnAisCancel=function (button,ev){
    log("Cancel clicked");
    this.gui.showPageOrReturn(this.returnpage,'navpage');
};
/**
 * create the page instance
 */
(function(){
    //create an instance of the status page handler
    var page=new avnav.gui.Aispage();
}());

<|endoftext|>


<commit_before>/*
 * This program is part of the OpenLMIS logistics management information system platform software.
 * Copyright © 2017 VillageReach
 *
 * This program is free software: you can redistribute it and/or modify it under the terms
 * of the GNU Affero General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details. You should have received a copy of
 * the GNU Affero General Public License along with this program. If not, see
 * http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org.
 */

describe('UserListController', function () {

    var vm, $state, $controller, $q, confirmSpy, usersList, stateParams;

    beforeEach(function() {
        module('admin-user-list', function($provide) {

            confirmSpy = jasmine.createSpyObj('confirmService', ['confirm']);

            $provide.service('confirmService', function() {
                return confirmSpy;
            });
        });

        inject(function (_$controller_, _$state_, _$q_) {

            $controller = _$controller_;
            $state = _$state_;
            $q = _$q_;
            usersList = [
                {
                    id: 1,
                    username: 'administrator'
                },
                {
                    id: 2,
                    username: 'user'
                }
            ];
            stateParams = {
                page: 0,
                size: 10
            };

            vm = $controller('UserListController', {
                users: usersList
            });
        });
    });

    describe('init', function() {

        beforeEach(function() {
            $controllerMock = jasmine.createSpy('$controller').andCallFake(function() {
                vm.stateParams = {};
            });

            vm = $controller('UserListController', {
                users: usersList,
                $controller: $controllerMock
            });

        });

        it('should expose openUserFormModal method', function() {
            expect(angular.isFunction(vm.openUserFormModal)).toBe(true);
        });
    });

    describe('goToCreateNewUserPage', function() {

        it('should expose goToCreateNewUser method', function() {
            expect(angular.isFunction(vm.goToCreateNewUser)).toBe(true);
        });
    });

    describe('editUser', function() {

        it('should expose editUser method', function() {
            expect(angular.isFunction(vm.editUser)).toBe(true);
        });
    });

    describe('resetUserPassword', function() {

        beforeEach(function() {
            confirmSpy.confirm.andReturn($q.when(true));
        });

        it('should expose resetUserPassword method', function() {
            expect(angular.isFunction(vm.resetUserPassword)).toBe(true);
        });

        it('should call confirmService', function() {
            vm.resetUserPassword(1);
            expect(confirmSpy.confirm).toHaveBeenCalledWith('msg.question.confirmation.resetPassword');
        });
    });

    describe('search', function() {

        beforeEach(function() {
            spyOn($state, 'go').andReturn();
        });

        it('should set lastName param', function() {
            vm.lastName = 'lastName';

            vm.search();

            expect($state.go).toHaveBeenCalledWith('administration.users', {
                lastName: vm.lastName,
                firstName: undefined,
                email: undefined
            }, {reload: true});
        });

        it('should set firstName param', function() {
            vm.firstName = 'firstName';

            vm.search();

            expect($state.go).toHaveBeenCalledWith('administration.users', {
                lastName: undefined,
                firstName: vm.firstName,
                email: undefined
            }, {reload: true});
        });

        it('should set email param', function() {
            vm.email = 'email';

            vm.search();

            expect($state.go).toHaveBeenCalledWith('administration.users', {
                lastName: undefined,
                firstName: undefined,
                email: vm.email,
            }, {reload: true});
        });

        it('should call state go method', function() {
            vm.search();
            expect($state.go).toHaveBeenCalled();
        });
    });
});
<commit_msg>OLMIS-2105: Removed leftover test<commit_after>/*
 * This program is part of the OpenLMIS logistics management information system platform software.
 * Copyright © 2017 VillageReach
 *
 * This program is free software: you can redistribute it and/or modify it under the terms
 * of the GNU Affero General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Affero General Public License for more details. You should have received a copy of
 * the GNU Affero General Public License along with this program. If not, see
 * http://www.gnu.org/licenses.  For additional information contact info@OpenLMIS.org.
 */

describe('UserListController', function () {

    var vm, $state, $controller, $q, confirmSpy, usersList, stateParams;

    beforeEach(function() {
        module('admin-user-list', function($provide) {

            confirmSpy = jasmine.createSpyObj('confirmService', ['confirm']);

            $provide.service('confirmService', function() {
                return confirmSpy;
            });
        });

        inject(function (_$controller_, _$state_, _$q_) {

            $controller = _$controller_;
            $state = _$state_;
            $q = _$q_;
            usersList = [
                {
                    id: 1,
                    username: 'administrator'
                },
                {
                    id: 2,
                    username: 'user'
                }
            ];
            stateParams = {
                page: 0,
                size: 10
            };

            vm = $controller('UserListController', {
                users: usersList
            });
        });
    });

    describe('init', function() {

        beforeEach(function() {
            $controllerMock = jasmine.createSpy('$controller').andCallFake(function() {
                vm.stateParams = {};
            });

            vm = $controller('UserListController', {
                users: usersList,
                $controller: $controllerMock
            });

        });
    });

    describe('goToCreateNewUserPage', function() {

        it('should expose goToCreateNewUser method', function() {
            expect(angular.isFunction(vm.goToCreateNewUser)).toBe(true);
        });
    });

    describe('editUser', function() {

        it('should expose editUser method', function() {
            expect(angular.isFunction(vm.editUser)).toBe(true);
        });
    });

    describe('resetUserPassword', function() {

        beforeEach(function() {
            confirmSpy.confirm.andReturn($q.when(true));
        });

        it('should expose resetUserPassword method', function() {
            expect(angular.isFunction(vm.resetUserPassword)).toBe(true);
        });

        it('should call confirmService', function() {
            vm.resetUserPassword(1);
            expect(confirmSpy.confirm).toHaveBeenCalledWith('msg.question.confirmation.resetPassword');
        });
    });

    describe('search', function() {

        beforeEach(function() {
            spyOn($state, 'go').andReturn();
        });

        it('should set lastName param', function() {
            vm.lastName = 'lastName';

            vm.search();

            expect($state.go).toHaveBeenCalledWith('administration.users', {
                lastName: vm.lastName,
                firstName: undefined,
                email: undefined
            }, {reload: true});
        });

        it('should set firstName param', function() {
            vm.firstName = 'firstName';

            vm.search();

            expect($state.go).toHaveBeenCalledWith('administration.users', {
                lastName: undefined,
                firstName: vm.firstName,
                email: undefined
            }, {reload: true});
        });

        it('should set email param', function() {
            vm.email = 'email';

            vm.search();

            expect($state.go).toHaveBeenCalledWith('administration.users', {
                lastName: undefined,
                firstName: undefined,
                email: vm.email,
            }, {reload: true});
        });

        it('should call state go method', function() {
            vm.search();
            expect($state.go).toHaveBeenCalled();
        });
    });
});
<|endoftext|>