How do I fix indentation/alignment in my pull request in Bitbucket? - javascript

I have written a small piece of JavaScript code (not allowed to share code). The code is aligned perfectly in text editor (Sublime) but in the pull request it is distorted. I tried to solve this but failed.
I tried to save each line but the result in pull request in still same. In SourceTree the indentation is correct before I push the code to the repository but after the push is successful the alignment dies.
Please forgive if this is a stupid question to ask to the developer community.
Sample code
$(document).ready(function()
{
var validate = $("#formId").validate(
{
debug : true,
rules : {
Name : {
required : true
}
},
messages : {
Name: {
required : "Name is required"
}
},
onfocusout : false,
invalildHandler : function (form, validator)
{
var errors = validator.numberofInvalids();
if(errors)
{
validator.errorList[0].element.focus();
}
}
});
})
So this is how it is actually supposed to be (above code) but in the pull request it comes something like this
$(document).ready(function()
{
var validate = $("#formId").validate(
{
debug : true,
rules : {
Name : {
required : true
}
},
messages : {
Name : {
required : "Name is required"
}
},
onfocusout : false,
invalildHandler : function (form, validator)
{
var errors = validator.numberofInvalids();
if(errors)
{
validator.errorList[0].element.focus();
}
}
});
})

I wonder if it'd figure out the problem, but hope you'd make a try anyway.
Download the conflicted target .js file from Bitbucket. (It doesn't matter whether it's a js file or not.) It's easy to make a file download if you open it as a raw status.
Replace your local original file with that one. It means you're going to get rid of confliction from your local side.
Make a commit to remote Bitbucket repo by git push -u origin [your_branch]. If your branch is not the master one, make a PR(pull request) and update your local branches syncing with remote ones.
Now you can recover your own indentation/alignment style on your favorite editor as you wish! (local edit)
Finally, make a commit to Bitbucket again.
To make a long story short, you can apply your own indentation after Git conflicts would get fixed.
Thanks.

Related

Managing browser permissions with Laravel Dusk

Total Laravel Dusk noob here (started using it today). I wanted to test a "copy link" on the Web app I'm working on and I ran into browser permissions issues when trying to access the clipboard content while testing. Of course, that default behavior makes sense, because Google Chrome prompts the user and ask for permission to access the clipboard. However, I haven't found a way to tell Dusk to enable specific permissions. I found the following Cypress example that is probably the appropriate way of doing it, but I don't know if there's a Dusk equivalent.
cy.wrap(Cypress.automation('remote:debugger:protocol', {
command: 'Browser.grantPermissions',
params: {
permissions: ['clipboardReadWrite', 'clipboardSanitizedWrite'],
origin: window.location.origin,
},
}))
Thanks in advance!
You can add this function to your DuskTestCase class.
use Facebook\WebDriver\Chrome\ChromeDevToolsDriver;
//
protected function grantPermission(Browser $browser, $permissions)
{
try {
$driver = $browser->driver;
$devtools = new ChromeDevToolsDriver($driver);
$result = $devtools->execute('Browser.grantPermissions', [
"permissions" => $permissions,
]);
return $result;
} catch (\Exception) {
return null;
}
}
And use it globally in a real test case like this
public function testClipboard()
{
$this->browse(function (Browser $browser) {
$this->grantPermission($browser, ["clipboardReadWrite", "clipboardSanitizedWrite"]);
// Your test flow and assertion
});
}
Hope my answer can help.

How to filter a displayed JSON file

I'm trying to make a web application using Outlook API's that allows me to search for a specific Outlook contact by his name.
I've got a little knowledge of javaScript but i never used any API or manipulated JSON files beforehand, so i looked through tutorials to help me, and
I ran into this one : https://dev.outlook.com/restapi/tutorial/javascript which i followed and succeeded to implement without much trouble.
Briefly, the tutorial allows me to build an app that can display the last 10 emails from the user, or the contact list of this user, which gives something like that :
Contacts displayed
Now what i'm trying to do is to filter this display and be able to search something like " give the contacts which name contains the syllable "AG" ".
I tried to understand the code as much as i can and i'm almost sure that i have to modify the function displaying all the contacts.
So what i did is that i pasted it, renamed it but now i'm struggling with the query parameters.
function getUserContacts(emailAddress, callback) {
getAccessToken(function(accessToken) {
if (accessToken) {
// Call the Outlook API
var callOptions = {
// Get contacts
url: apiEndpoint + '/Me/contacts',
token: accessToken,
method: 'GET',
email: emailAddress,
query: {
// Limit to the first 100 contacts
'$top': 100,
// Only return fields we will use
'$select': 'GivenName,Surname,EmailAddresses',
// Sort by given name alphabetically
'$orderby': 'GivenName ASC'
}
};
makeApiCall(callOptions, function(result, error) {
if (error) {
callback(null, error);
} else {
callback(result.value);
}
});
} else {
var error = { responseText: 'Could not retrieve access token' };
callback(null, error);
}
});
}
And that's the moment i get totally lost, i tried adding '$where':GivenName='AG' in the query{} section, as well as '$filter':GivenName='AG', but neither of them worked. I searched online for an answer but in every one i founded, the JSON file was "available" ( meaning for me that they have,somewhere this kind of code :
[
{"name":"Lenovo Thinkpad 41A4298","website":"google222"},
{"name":"Lenovo Thinkpad 41A2222","website":"google"}
]
But i don't have this type of code anywhere, so i'm wondering if it is possible to do it like i tried to, or if i have to find a way to retrieve the JSON file in order to obtain something like just above ?
I hope i've been clear enough despite my lack of experience in this field, i'd be glad to give some more details/codes if you ask too !
Thanks in advance and have a great day :)
Thanks to Useless Code and his link i managed to send the right request (error was coming from the fact that filter properties must be listed first in the orderby) from the outlook sandbox and get the expected answer with this URL:
https://outlook.office.com/api/v2.0/me/contacts?$filter=GivenName eq 'AG-Carto'&$orderby=GivenName ASC&$select=GivenName,Surname,EmailAddresses
Now what i'm trying to do is to get my javascript code to send it right.
So i know i have to modify the query{} part of the function, i tried this :
query: {
'$filter': 'GivenName eq AG-carto',
'$orderby': 'GivenName ASC',
'$select': 'GivenName,Surname,EmailAddresses'
}
But when i run it, i got a bad request error, and i see that the url sent by the js code is this one :
https://outlook.office.com/api/v2.0/Me/contacts?%24filter=GivenName+eq+AG-carto&%24orderby=GivenName+ASC&%24select=GivenName%2CSurname%2CEmailAddresses
So i'm obviously seeing that they aren't the same, and i have no idea on how to modify the query{} section so that the URL sent by js is the same as my working URL. If anyone could help me on that i'd be grateful !

chrome.storage.managed doesn't seem to work in my kiosk app

I've written a fairly simple kiosk app for a enterprise-enrolled/managed chromebox. I want to provide a default URL through a policy with chrome.storage.managed.
According to the documentation available a schema could look something like this:
{
"type": "object",
"properties": {
"DefaultUrl": {
"title": "Default URL",
"description": "The Default URL that will be loaded",
"type": "string"
}
}
}
And then the configuration text file you upload on the admin.google page would look like this (but this is kind of a guess):
{
"DefaultUrl": {
"Value": "http://example.com"
}
}
Next I try to use this URL using the following code:
chrome.storage.managed.get('DefaultUrl', function (data) {
var url = data.DefaultUrl;
/*if(url == undefined)
url = "undefined url";*/
//further code to proces the url
});
As far as I understand from the documentation a dict object with key/value pairs is returned containing the specified keys (1 in my case). When I uncomment the ifstatement in the above code the variable url always ends up being "undefined url", and otherwise it doesn't show any text (since it seems to be undefined)..
Debugging this isn't easy, because as far as I know you can't use console.log in kiosk mode, the policies can't be set through the admin panel when running it locally and since it's a managed device I can't run it from dev mode..
Can anyone tell me what's wrong here? If this is insufficient info I'd be glad to supply more, but my guess is the error is somewhere in the code above.
Update
I got this working locally when adding policies for chrome in my windows register, as described by the 'windows' part on: this site..
Allthough I am now using more than 1 policy, so maybe the error was that the schema expects atleast 2 policies? I have yet to test this on the kiosk app.

Using elasticsearch.js

I've run elasticsearch.bat and queried this in browser with localhost:9200. JSON object returned as follows, so all ok so far.
{
"status" : 200,
"name" : "hwils_01_dev",
"cluster_name" : "elasticsearch_hwils_dev",
"version" : {
"number" : "1.7.2",
"build_hash" : "e43676b1385b8125d647f593f7202acbd816e8ec",
"build_timestamp" : "2015-09-14T09:49:53Z",
"build_snapshot" : false,
"lucene_version" : "4.10.4"
},
"tagline" : "You Know, for Search"
}
I've downloaded and linked via tag to my index.html the elasticsearch.js
<script src="elasticsearch-js/elasticsearch.js"></script>
(incidentally there's more than 1 .js in the download - do I need to link them all?)
I've then run added to another tag the code
var client = new elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
and output this to console - JSON object returned so again, presumably all ok up to this point.
If I then run
client.ping({
requestTimeout: 30000,
// undocumented params are appended to the query string
hello: 'elasticsearch'
}, function (error) {
if (error) {
console.error('elasticsearch cluster is down!');
} else {
console.log('All is well');
}
});
I get the error message returned. And I don't know why.
Incidentally
var elasticsearch = require('elasticsearch');
returns "Uncaught reference error: require is not defined" which would suggest I'm missing at least one other .js file with that function?
Since you're in a browser, you need to use a browser build (at the moment Angular or jQuery are available).
So let's say you're going the jQuery way, your <script> should look like this:
<script src="elasticsearch-js/elasticsearch.jquery.min.js"></script>
And then you can create your client like this:
var client = new $.es.Client({
hosts: 'localhost:9200',
log: 'trace'
});
The require statement is a NodeJS only function. You need to download and reference the browser build of ES in your HTMl file as Val mentioned.

how to update a Mongo.db collection in meteor.js?

I have a collection that I need to update when the user presses a button.
I just need to change one variable to another.
In the console, this line of code works:
db.users.update({username : "Jack"},{age : 13, username : "Jack"});
But when I put in this code:
Template.body.events({
'click #updateAge' = function() {
{
alert();
db.users.update({username : "Jack"},{age : 13, username : "Jack"});
}
}
})
into my JavaScript file for Meteor.js, it doesn't do anything at all (I don't get an error message, and I see the alert, but the update just doesn't work).
I've read through the Meteor Documentation on updating, but I just can't seem to get it to work.
Does anybody know what I'm doing wrong here?
Found the problem.
Since I defined my database in my lib.js file
users = new Meteor.collection("users");
I don't need to put a db in front of the db.users.update({_id : "Jack"},{...}). I also need to find the document using the given mongo _id, not the identifier "username".
so the appropriate code would be
users.update({_id : "Jack"},{$set:{age : 13, username : "Jack"}});
In mongodb, you will have to use an update operator(for ex: $set). Otherwise, your document will overwritten by the update object you are passing(I am not sure that's what you want). I think, its works same in meteor. So, you will have to do something like this:
Meteor.users.update({username : "Jack"},{$set: {age : 13}});
This might not be the problem as you've stated you do not get a error message but to be sure: have you already allowed the user to update documents in the user collection?
Something like:
(in collections/permissions.js)
user.allow({
update: function (userId) {
// the user must be logged in to allow updates
return (userId != null);
}
})

Categories