Use variables on MongoDB query

My basic MongoDB query

test.find({$or : [{"timeIn":"2018-1-31 11:57"},{"timeIn":"2018-1-31 11:58"},{"timeIn":"2018-1-31 11:59"},{"timeIn":"2018-1-31 12:00"},{"timeIn":"2018-1-31 12:01"},{"timeIn":"2018-1-31 12:02"},]})

I want use variables for replace expression and I tried

    //console.log(expression);
    test.find({"$or" : [expression]  }, {"email": 1, "_id": 0}).toArray(function (err,data){
      if (err) throw err;
      console.log(data);
});

But got a error

MongoError: $or/$and/$nor entries need to be full objects

With variables expression are {"timeIn":"2018-1-31 11:57"},{"timeIn":"2018-1-31 11:58"},{"timeIn":"2018-1-31 11:59"},{"timeIn":"2018-1-31 12:00"},{"timeIn":"2018-1-31 12:01"},{"timeIn":"2018-1-31 12:02"},

How I can use variables on MongoDB query?

AJAX PUT request to Phillips Hue Hub Local

I have created a file with the following:

<form id="myForm" name="myForm">
<div>
<button type="submit">Turn Light on</button>
</div>
</form>
<script> $('#myForm').submit(function(e){
e.preventDefault();
$.ajax({
    url:'http://192.168.1.102/api/user/lights/1/state',
    type:'PUT',
    data: JSON.stringify({"on":true}),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(data){alert(data);},
    failure: function(errMsg) {
    alert(errMsg);
    }
});
});
</script>

Currently, no error or success message is displayed and the light does not turn on. I can only put it down to there being an error in my code, or am I misunderstanding Jquery & AJAX and they are not client side, hence why this doesn’t work?

EDIT: Typo on the form ID was the issue.

Opencontrail logutils not found

i have a probleme with opencontrail-webui server is not running i was able to track the error to file config.utils.js when i tried to decrale a variable with the same name. server started but i got a blanc page this is some text from log file
thank you

/var/lib/contrail-webui/contrail-web-core/src/serverroot/common/config.utils.js:117
                logutils.logger.error("Configured/Default MOTD file " +
                ^

ReferenceError: logutils is not defined
at ReadFileContext.callback (/var/lib/contrail-webui/contrail-web-core/src/serverroot/common/config.utils.js:117:17)
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:367:13)
02/16/2018 05:01:38 PM – ^[[34mdebug^[[39m: The worker #5 has disconnected.
02/16/2018 05:01:38 PM – ^[[31merror^[[39m: The worker #5 has exited with exit code 1

……

replace second occurrence of comma with line break in string

Trying to figure out what’s the best way to insert a line break after the second comma in a string. Here’s what I’m currently using and it works, but I would like to know if a regex would be better for this.

var data = $('#test1').html();
var position = data.indexOf(",", data.indexOf(",") + 1);

String.prototype.replaceAt = function(index, replacement) {
  return this.substr(0, index) + replacement + this.substr(index + replacement.length);
}

var newstr = (data.replaceAt(position, "<br />"));

$('#result').html(newstr);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="test1">3131, abc street, ZZ, ZZ  128 376</span>
<br /><br />
<span id="result">###</span>

How to define a route and then create a simple crosslink to that route?

This API is clear enough…

<Button
      title="Go to Details"
      onPress={() => this.props.navigation.navigate('Details')}
    />

But how do I register this “Details” route for a component? In the React Navigation docs, it is often suggested to do something like…

export default StackNavigator({
  Home: {
    screen: HomeScreen,
  },
});

However, the above code does not just register a route, it also affects how the UI is presented. I don’t want these coupled. I don’t want the way in which I register/define routes to have any immediate effect on the GUI.

There must be a way to simply register a route so that when I call navigation.navigate(‘SomeRoute’), the relevant screen will load.

Even the documentation for building a custom router seems to assume that I want to render something, rather than just define routes. But I just want to register a route so I can call navigation.navigate(‘Someroute’).

Cannot find module ‘…/models/user’ nodejs

I’ve got a problem with require.
I’ve got a users.js inside folder ‘router’. In users.js everything works great with

let User = require('../models/user');

But when users.js file getting bigger I wanted to part this file into a few files like login.js regiseter.js and so on. I created a folder ‘users’ inside ‘router’ and put there those files (login.js, register.js)

I changed my require to

let User = require('.../models/user');

Now I got an error:

Cannot find module ‘…/models/user’
enter image description here

Concat + wrap + compile all JavaScript files

I have a webpack project what looks something like this:

[src]
   ?
   ??[components]
   ?   ?
   ?   ?? component1.js
   ?   ?
   ?   ?? component2.js
   ?   ?
   ?   ?? component3.js
   ?
   ?? main.js

I would like to have as output, two files:

main.js

(function(modules) { // webpackBootstrap
    // ...
})
(function(module, exports, __webpack_require__) {
    // my compiled JS code
    // ...
})

components.js

(function(modules) { // webpackBootstrap
    // ...
})
(function(module, exports, __webpack_require__) {
    const aSharedVariable = ...
    // compiled component1.js ...
    // compiled component2.js ...
    // compiled component3.js ...
})

I would like to share some common utilities (shown here as aSharedVariable) to all components, but keep the utilities scoped and out of the global scope.

Using webpack-concat-plugin I have been able to concatenate and, by using head and tail JavsScript files, wrap the code, however the code is not compiled so my require statements don’t become webpack require statements.

Using a input file:

components.js

const files = require.context("./components/", true, /.js$/);
files.keys().forEach(files);

I have been able to compile all files into a single compiled file but I’m not able to wrap the file so that I can provide scoped variables to all components.

I could also add a require statement to each component but this would result in a lot of duplicate code. There could be hundreds of components and each one may only be a couple of lines long, so I would rather have the file look like this:

component1.js

doSomething("that is what my component does", () => {
    // ...
    doSomethingElse(whatever());
});

Rather than:

const utilities = require("my-common-utilities");
utilities.doSomething("that is what my component does", () => {
    // ...
    utilities.doSomethingElse(utilities.whatever());
});

Is there a way that I can concatenate my JavaScript files first, then compile the code using webpack?

kevinchappell / form Builder

I am new Comer in JavaScript
I used kevinchappell / form Builder but i am stuck because i am unable to customize it.
I need to add dynamically values in autocomplete text field can you help me

Form Builder Link

My Code is this

var fields = [
        {
            type: 'autocomplete',
            label: 'Custom Autocomplete',
            required: true,
            fields : function (fieldData) {
                return {
                    values: '{label: "SQL"}'

                };
            },
            values:
                [
// here i want to add dynamic values
                {label: 'SQL'},
                {label: 'C#'},
                {label: 'JavaScript'},
                {label: 'Java'},
                {label: 'Python'},
                {label: 'C++'},
                {label: 'PHP'},
                {label: 'Swift'},
                {label: 'Ruby'}
            ]

this is form-builder.js by kevinchappell / form Builder

How to pass a dynamic variable to a ‘component’ and then display it – VueJS

I can not display a variable (which is the link of an image) in my component I am lost …

(To help you, I’m in a table and click on the icon that opens a pdf)

Thanks you !

Vue.component('modal', {
    template: '#modal-template-pdf',
    props: {
        lien: String
    }
});

let appCompta = new Vue({
        data: {
            showModalActive: false,
            currentModalPdfLink: '',
        }
}).$mount('#'+id+' #app-compta')
    
    
    
<img slot="apercu" slot-scope="props" class="iconeged main" src="images/ico_pdf.png"
             v-bind:currentModalPdfLink='props.row.imglien'
             @click="showModalActive = true"
        >

<modal v-if="showModalActive" @close="showModalActive = false" v-bind:lien="currentModalPdfLink">
        <h3 slot="header">Aperçu PDF</h3>
    </modal>

    <script type="text/x-template" id="modal-template-pdf">
        <transition name="modal">
            <div class="modal-mask">
                <div class="modal-wrapper">
                    <div class="modal-container">

                        <div class="modal-header">
                            <slot name="header">
                                default header
                            </slot>
                        </div>

                        <div class="modal-body">
                            <slot name="body">
                                {{currentModalPdfLink}}
                                <iframe height='100%' width='100%' frameborder='0' :src="currentModalPdfLink"/>
                            </slot>
                        </div>

                        <div class="modal-footer">
                            <slot name="footer">
                                <button class="modal-default-button" @click="$emit('close')">
                                    FERMER
                                </button>
                            </slot>
                        </div>
                    </div>
                </div>
            </div>
        </transition>
    </script>

popover is off by top: 300px

For whatever reason I cannot work out my popover is off by about 300px, I cannot work out why and as a solution I want to change the element.style that gets set on it to be +300px of whatever it gets set to.

I am using openlayers, and setting the position using the coordinates on click.

popup.setPosition(evt.coordinate);

Setting the position on my tooltip is working fine using this exact method, so I need to work out what the problem is or change the css once it has been set by the onclick function;

var element = document.getElementById('popup');
map.on('click', function (evt) {
    var element = popup.getElement();
    var coordinate = evt.coordinate;
    var hdms = ol.coordinate.toStringHDMS(ol.proj.transform(
        coordinate, 'EPSG:3857', 'EPSG:4326'));
    $(element).popover('destroy');
    popup.setPosition(coordinate);
    // the keys are quoted to prevent renaming in ADVANCED mode.
    $(element).popover({
        'placement': 'top',
        'animation': false,
        'html': true,
        'content': '<p>The location you clicked was:</p><code>' + hdms + '</code>'
    });
    $(element).popover('show');
});

Here is the code for toolltip:

function displayTooltip(evt) {
var feature = map.forEachFeatureAtPixel(pixel, function (feature) {
    return feature;
});
tooltip.style.display = feature ? '' : 'none';
if (feature) {
    overlay.setPosition(evt.coordinate);
    tooltip.innerHTML = feature.get('name');
}
};
map.on('pointermove', function (evt) {
if (evt.dragging) {
    return;
}
pixel = map.getEventPixel(evt.originalEvent);
displayTooltip(evt)

});