WebStorm JavaScript live template - deciding where the cursor will be - javascript

I've created a JavaScript live template which I use a lot in WebStorm:
console.log('$PARAM$ -> ', $PARAM$);
It helps me type this kind of lines faster:
console.log('nextProps -> ', nextProps);
However as it starts on the first $PARAM$ I don't get autocomplete. Is there a way to get the cursor to the second $PARAM$ while keeping the duplicated text adding?

Use 2 variables instead of 1
Reorder them -- 2nd one should be filled first
Tell IDE to auto-copy 2nd variable into 1st
Tell IDE to ignore 1st variable if it has value (which it will because of #3)
console.log('$PARAM1$ -> ', $PARAM2$);

Related

Loop through list in AppleScript and JavaScript

I’m currently using AppleScript to automate some tasks in Safari. I have below code, which is supposed to set the value of the text box ‘ownerValue’ to the item from the loop. Whenever I execute the code, nothing happens.
set countryList to {"BR", "CN"}
repeat with country in countryList
tell application "Safari"
activate
tell document 1
do JavaScript "document.getElementById('ownerValue').value = country"
end tell
end tell
end repeat
When I replace the country in the loop to the actual country value, e.g. “BR”, it then inserts the text into the text field.
tell application "Safari"
activate
tell document 1
do JavaScript "document.getElementById('ownerValue').value = ‘BR'"
end tell
end tell
It also seems that AppleScript doesn’t recognise country as an item from the loop, since country is not in green.
Any ideas on how I can fix this so I can let AppleScript loop through the values in countryList?
Thanks!
This will resolve the issue of the variable not being treated as a variable:
set countryList to {"BR", "CN"}
repeat with country in countryList
tell application "Safari"
activate
tell document 1
do JavaScript "document.getElementById('ownerValue').value = '" & country & "';"
end tell
end tell
end repeat
However, you may have another issue here, in that you are looping while inputing the value of a new variable into the same input field. In other words the JavaScript command as written is going to first input BR and immediately overwrite it with CN.
Note that the color of country in the code above is not showing as green, however, here is a clipped screenshot from Script Editor and you see it's green.
To address the comment:
Could you please explain why it was previously not treated as a variable but now is?
When mixing two languages, i.e. AppleScript and JavaScript in this use case, and passing an AppleScript variable to JavaScript, you need to build out the JavaScript command using concatenation so the value of the variable is expanded.
In your code it was being treated as a fixed value as JavaScript has no way of knowing it was an AppleScript variable, hence concatenation, i.e. & ... &. In AppleScript, & is the concatenation character.

How do I view the contents of a set in Javascript in Visual Studio Code?

I am using Visual Studio Code Insiders.
I am teaching myself this as well as Javascript at the same time using a textbook from SitePoint.
I noticed that when I tried to display the contents of my set as shown in the book, I could only display the number of elements in the set. However, I was supposed to see the contents of the set. When using the command line, the contents did indeed show.
Is it my text editor settings, or is this normal? What can I do to be able to see the contents of my sets on my text editor? Am I supposed to keep copying and pasting my sets into the command line to see if they work?
This is what I entered:
const letters = new Set ('hello');
console.log(letters);
This is what VS Code Insider printed:
>>Set(4) {}
This is what the command line printed:
const letters = new Set('hello');
>>undefined
console.log(letters);
>>Set { 'h', 'e', 'l', 'o' }
I find I have no problem printing the contents of an array, so I'm not sure what's wrong.
I noticed that when I tried to display the contents of my set as shown in the book, I could only display the number of elements in the set
Displaying the contents of a variable in JavaScript depends on the environment in which JavaScript runs.
As you pointed out, VS Code displays differently than the command line. Each of them are different interpreters.
is this normal?
Yes
What can I do to be able to see the contents of my sets on my text editor? [...] I find I have no problem printing the contents of an array
Since it works for an array (which indicates that both interpreters have very similar implementation for this type) you can convert the Set into an array when displaying:
const letters = new Set ('hello');
console.log(Array.from(letters));
console.log([...letters]) // or this way

Javascript indexOf not finding text in a variable

I am sure there is something simple that I am missing but I am stumped here.
The issue is that I am looping through an array of strings and using the string value to search for a part of that string using indexOf. The first time around the loop the index of is finding what I am looking for but the second time it is not.
Here is a fiddle - http://jsfiddle.net/jeremywrags/uSwjG/1/
the line that seems to be not working is this
var aliasIndex = fromclause.indexOf(" " + tableAlias + " " );
I am trying to build a SQL parser for a cloud app and the use case here is that when a table is aliased I need to get the original table name so that I can look up the table columns. The first time around the loop index of returns the index and then the table name. The second time around the index of is -1 and the table name is not retrieved.
If I need to provide more context please let me know.
thanks
It's not matching because on the second pass, tableAlias is the string " b" (note the space). So then you search for " b " (note two leading spaces), which isn't there.
Rather than using alert, use the debugger built into your browser. You can set breakpoints in the code, step through line by line, inspect variables, etc., etc. Doing that with this would have shown you, when looking at the variable tableAlias, that it had a leading space, hopefully helping you find the solution.
Here's what that looks like in Chrome's debugger, for instance:
(If you look at the jsFiddle source above the actual debugger's version, you'll see a debugger; statement in the code — normally you don't need that statement, you can just open your page, use the "Sources" tab to find your JavaScript file, navigate to the line, and click the margin to the left of it to set a breakpoint. But sometimes [for instance, when using jsFiddle], the debugger; statement is handy. What it does is, if the debugger is open, halts execution of the code at that point like a breakpoint does.)

Open SSRS URL in New Window

I have a report that passes an id that is used to access salesforce.com. I want to open SFDC as a new page from the URL hyperlink. However, nothing I do seems to be working!
="javascript:void(window.open('https://na5.salesforce.com/& Fields!id.Value,'_blank'))"
Fields!id!Value is the SFDC id that is being passed. I'm trying this in the expression to no avail!
I know it is something VERY simple but I'm just not finding it. Thanks in advance for the assistance!
UPDATE!!!
Figured it out!!! For the record, the syntax is:
="javascript:void(window.open('https://na5.salesforce.com/" & Fields!id.Value & "'))"
For the record, the problem with your original syntax was that you were trying to go from referencing an SSRS field to entering a string without separating the two properly. If you wanted your previous syntax to work (without removing the target window's name (i.e., '_blank'), you would do it like this:
="javascript:void(window.open('https://na5.salesforce.com/" & Fields!id.Value & "','_blank'))"
I struggled with this for a long time, but you can make these pretty complex as long as you're careful to put everything together correctly. You can also add multiple javascript commands (but no functions) in the same action expression. Below is one of my most complicated SSRS Go-to-URL Action commands:
="Javascript:"
& IIF(left(Fields!Name.Value,11)="RESTRICTED-",
"alert('Restricted!'); ","") & IIF(Fields!Name_Alert.Value = 1, "alert('Alternate Alert!'); ","")
& "void(window.open('"
& Globals!ReportServerUrl
& "/Pages/ReportViewer.aspx?%2fJPD%2fPO_Dashboard%2fJuvenile_Profile&rs:Command=Render"
& "&rc:Parameters=true"
& "&Emp_Number="
& Parameters!Param1.Value
& “&ID=" & Fields!ID.Value & "'));"
The key is to make sure that any and all necessary single quotes required by javascript show up inside a string (i.e., "'").
Nonono, don't use ="javascript:void(window.open(.
First, it breaks PDF & Excel reports,
and second, it doesn't work in IE11 and possible also < 11.
Tested it, worked only in Chrome for me.
And third, it's a mess to put it together.
There's a far easier & better solution:
Add &rc:LinkTarget=_blank to your report access URL, like:
https://your-domain.com/ReportServer/Pages/ReportViewer.aspx?%2fJPD%2fPO_Dashboard%2fJuvenile_Profile&rs:Command=Render&rc:LinkTarget=_blank
and it will open in a new window tab.
Edit:
If you want to make your own display page:
This is how you get all reports:
USE [ReportServer$MSSQL_2008_R2]
SELECT
[ItemID]
,[Path]
,[Name]
,[ParentID]
FROM [Catalog]
WHERE Type = 2
And this is how you can display all folders/reports at level x
;WITH CTE AS
(
SELECT
[ItemID]
,[Path]
,[Name]
,[ParentID]
,0 AS lvl
,CAST([Name] AS nvarchar(MAX)) AS RecursivePath
FROM [Catalog]
WHERE [ParentID] IS NULL
UNION ALL
SELECT
[Catalog].[ItemID]
,[Catalog].[Path]
,[Catalog].[Name]
,[Catalog].[ParentID]
,cte.lvl +1 AS lvl
,CAST(cte.RecursivePath + '/' + [Catalog].[Name] AS nvarchar(MAX)) AS RecursivePath
FROM CTE
INNER JOIN [Catalog]
ON [Catalog].ParentID = CTE.ItemID
)
SELECT * FROM CTE
WHERE lvl = 1
ORDER BY lvl, Path
If you only want the folders:
WHERE Type = 1
If you only want the data-sources:
WHERE Type = 5
If you are wanting to link to an external URL and want the links to work both within the report viewer and if you export to Excel for example, I use the following expression.
=IIF(
Globals!RenderFormat.Name = "RPL",
"javascript:void(window.open('http://www.domain.com/page/" & Fields!Page_ID.Value & "','_blank'))",
"http://www.domain.com/page/" & Fields!Page_ID.Value
)
It will use the JavaScript if viewing from within the report in the browser and standard linking otherwise.
Here is what I had used; it will open the ChildReport in a new tab, with a parameter voucher_id and its value passed from a dataset.
="javascript:void window.open(" &"'"& Globals!ReportServerUrl &"/Pages/ReportViewer.aspx?"&Globals!ReportFolder &"/JournalVoucher&voucher_id="&Fields!account_voucher_id.Value &" ','_blank')"

Lucene search to find either of 2 particular content model types within a folder

I am trying to write a lucene search in an Alfresco webscript (javascript) to find 1 of 2 custom types within a custom type cm:folder
So the folder might have the following contents
1. Some text (cm:content)
2. More text (custom:content)
3. Even more text (custom:content)
4. Another folder (cm:folder)
5. Crazy, more text (custom:content2)
6. Last text (custom:content2)
The expected result of the lucene search should return the following
2. More text (custom:content)
3. Even more text (custom:content)
5. Crazy, more text (custom:content2)
6. Last text (custom:content2)
Where am I going wrong with the lucene search? I have written something along the lines of
+PATH:"/app:company_home/PATH_TO_A_CUSTOM_TYPE_FOLDER/*" TYPE:"custom:content1" TYPE:"custom:content2"
The problem is it returns all content, I think the intention is to write something like
+PATH:"/app:company_home/PATH_TO_A_CUSTOM_TYPE_FOLDER/*" +TYPE:"custom:content1" OR +PATH:"/app:company_home/PATH_TO_A_CUSTOM_TYPE_FOLDER/*"+TYPE:"custom:content2"
Worse case scenario is I can run 2 lucene searches, but it would be good to know how the query is written :-)
Thanks
Can't you just do the following:
+PATH:"/app:company_home/PATH_TO_A_CUSTOM_TYPE_FOLDER/*" AND (TYPE:"custom:content1" TYPE:"custom:content2")
Because if you write +PATH TYPE: TYPE:, it actually says PATH:(Must have) OR TYPE: OR TYPE:, hence it looks that if the PATH: is matched it will return everything beneath.

Categories

Resources