call google app script htmlservice.createTemplateFromFile(file) with file located on sub folder - google-apps-script

On a side bar google app script htmlservice.createTemplateFromFile(file) is used to launch the side bar by user request.
When the html file (the client html file) is located on the root folder, all works smoothly.
I want to rearrange the project files into several subfolders.
I'm using visual studio code and clasp push to push changes to server.
Everything is ok, except with the file location.
When moving the file, I can not find the way to supply the right path.
for example:
before rearrange two files (and others) were on the google editor.
client.html
server.gs
after moving to subfolder and pushing to server, as the editor does not support sub folders it is reflected with the files names so:
./subFolder/client.html
./subFolder/sever.gs
I also moved the server js (gs in google editor) to the same folder
Code in server to launch side bar
function launchSideBar(){
//try obvious
let file = "client"; // #1
file = "./client"; // #2
//like it displays in editor
file = ".subFolder/client"; // #3
/*maybe server is launched from root,
although it also resides on sun folder, so supply
relative path from root, like for other files (css,ims etc)
*/
file = "./subFolder/client"; // #4
let output =
HtmlService.createHtmlOutputFromFile(file);
//launch
SpreadsheetApp.getUi()
.showSidebar(output);
}
you can see the 4 options I have tried (of course only one different option was not commented each time)
When trying to display the side bar from the sheet added menu item, there is an error message
Exception: No HTML file named subFolder/client was found.
each time file name is different of course.
server is recognized automatically although also moved.
Ideas?

Try using file = "subFolder/client" instead.

Related

Writing GPX-File to Google Drive and open with APP

I am using a script to produce a file with GPS-Data...GPX-File. Now I am searching for the applicable MIME TYPE.
var alumnopath = DriveApp.getFoldersByName(foldername);
var folderalumno = alumnopath.hasNext() ?
alumnopath.next() : DriveApp.createFolder(foldername);
//This creates a file in the folder
var file = folderalumno.createFile(filename + '.gpx', TRK, MimeType.PLAIN_TEXT);
TRK is the content of the file (the GPS-Data).
Due to lack of other options I am using MimeType.PLAIN_TEXT.
The problem: If I open the produced GPX-File out of my Google-Drive-App on my Smartphone, the file opens as text-file instead of opening directly an appropriate APP (such as Outdooractive, OruxMaps, etc.) for navigation.
When I modify the file (doesn't matter what...just doing minor stuff) and safe it again, it works as expected (opening a navigation app).
My question: How can I tell Google Drive that the file has to be treated as a GPX-File that has to be opened by navigation apps?
Meanwhile I found the solution myself.
I just replaced MimeType.PLAIN_TEXT by application/gpx+xml
var file = folderalumno.createFile(filename + '.gpx', TRK, 'application/gpx+xml');

Keyboard short for uploading two files in PhpStorm

The problem
In PhpStorm I have a style.css- and a app.js-file that I have to upload to a server over and over again. I'm trying to automate it.
They're compiled by Webpack, so they are generated/compiled. Which means that I can't simply use the 'Tools' >> 'Deployment' >> 'Upload to...' (since that file isn't and won't every be open).
What I currently do
At the moment, every time I want to see the changed I've done, then I do this (for each file):
Navigate to the files in the file-tree (using the mouse)
Select it
The I've set up a shortcut for Main menu >> Tools >> Deployment >> Upload to..., where-after I select the server I want to upload to.
I do this approximately 100+ times per day.
The ideal solution
The ideal solution would be, that if I pressed a shortcut like CMD + Option + Shift + G
That it then uploaded a selection of files (a scope?) to a predefined remote server.
Solution attempts
Open and upload.
Changing to those files (using CMD + p) and then uploading them (once they're open). But the files are generated, which means that it takes PhpStorm a couple of seconds to render the content (which is necessary before I can do anything with the file) - so that's not faster.
Macro.
Recording a macro, uploading the two files, looking like this:
If I go to the menu and trigger the Macro, then it works. So far so good.
But if I assign a shortcut key and trigger that shortcut while in a file, then it shows me this:
And if I press '1' (for it to upload to number 1 on the list), then it uploads the file that I'm currently in(!?), and not the two files from my macro.
I've tried several different shortcuts (to rule out some kind of keyboard-shortcut-clash):
CMD + Option + CTRL + 0
CMD + Shift 0
CMD + ;
... Same result.
And the PhpStorm Macro's doesn't seem to give me that many options anyways.
Keyboard Maestro.
I've tried doing it using Keyboard Maestro.
But I can't get it setup right. Because if it can't find the folders (if they're off-screen or if I'm in a different project and forgot to adjust they shortcuts), then it blasts through the rest of the recorded actions, resulting in chaos. Ideally it should stop, if it can't find the file on the screen.
Update1 - External program
Even if it's not possible to do in PhpStorm, - are there then another program that I could achieve this with?
Update2 - Automatic Deployment in PhpStorm
I've previously used this, - but I've had happen a few times that I started sync'ing waaaay to many files, overwriting critical core files. It seems smart, but can possibly tear down walls if I've forgotten to define an ignore properly.
I wish there was an 'Automatic Deployment for theses files'-function.
Update3 - File Watchers
I looked into file-watchers ( recommendation from #LazyOne ). Based on this forum thread, then file watchers cannot be used to upload files.
It is possible to accomplish it using external program scp (Secure Copy Protocol):
Steps:
1. Create a Scope (for compiled files app.js and style.css)
2. Create a Custom File Watcher with scp over that Scope
Start with Scope:
Create a Local Scope with name scp files for your compiled files directory (I will assume that your webpack compiles into dist directory):
Then, to add dist directory into Scope, select that folder and click on Include Recursively. Apply and Move to File Watchers
Create a custom template for File Watcher:
Choose a Name
Choose File type as Any
Choose Scope as scp files(created earlier)
Choose Program as scp
Choose Arguments as $FileName$ REMOTE_USER#REMOTE_HOST:/REMOTE_DIR_PATH/$FileName$
Choose Working directory as $FileDir$
That's it, basically what we have done is every time when a file in that scope changes, that file is copied with scp to the remote server to the corresponding path.
Voila. Apply Everything and recompile your project and you will see that everything is uploaded to the server.
(I assumed that you have already set up your ssh client; Generated public/private keys; Added a public key in your remote server; And, know ssh credentials to connect to your remote server)
I figured this out myself. I posted the answer here.
The two questions are kind of similar but not identical.
This way I found is also not the best, since it stores the server password in clean text. So I'll leave the question open, in case someone can come up with a better way to achieve this.

Why does my file download link seem to work, but is unable to find the file?

I added this HTML to a page that I render via a REST call:
StringBuilder builder = new StringBuilder();
. . .
builder.Append("<p></p>");
builder.Append("<a href=\"/App_Data/MinimalSpreadsheetLight.xlsx\" download>");
builder.Append("<p></p>");
. . .
return builder.ToString();
My ASP.NET Web API project has a folder named "App_Data" which does contain a file named "MinimalSpreadsheetLight.xlsx"
The download link is indeed rendered on the page, and clicking it does appear, at first, to download the file (it has the Excel icon, and it bears the file name), but beneath that it says "Failed - No file":
Is the problem with my HTML, or the path I'm using, or file permissions, or what?
I've only tested this with Chrome, so far, BTW. IOW, it's not an IE issue.
UPDATE
I tried it with a leading squiggly, too:
builder.Append("<a href=\"~/App_Data/MinimalSpreadsheetLight.xlsx\" download=\"Spreadsheet file\">");
...yet, alas, to no avail.
UPDATE 2
I changed the pertinent line of HTML to this:
builder.Append("<a href=\"App_Data/MinimalSpreadsheetLight.xlsx\" download=\"Minimal Spreadsheet file\">");
...and it displays in the source like so (with some context):
<p>(Invoice Count excludes credits and re-delivery invoices)</p><p></p><p></p><a href="App_Data/MinimalSpreadsheetLight.xlsx" download="Minimal Spreadsheet file">
...but the link does not appear at all.
UPDATE 3
I was misled by this reference, which showed no text being added; I changed the code to this:
builder.Append("Spreadsheet file");
...(adding "Spreadsheet file" and closing out the anchor tag), and now the link appears; however, I still get the "Failed - No file" msg, and 2-clicking the "downloaded file" does nothing.
UPDATE 4
I tried two other permutations of what's seen in Update 3, namely with the forward whack reintroduced prior to "App_Data":
builder.Append("Spreadsheet file");
...and with both the squiggly prepended and the forward whack:
builder.Append("Spreadsheet file");
...but the results are the same in any of these permutations ("Failed - no file").
UPDATE 5
I also tried it without the "App_Data" at all, on the off change that is not needed:
builder.Append("Spreadsheet file");
...but the same "Failed - No file" is the result of that attempt, too.
UPDATE 6
Okay, so I tried this, too (single quotes):
builder.Append("<a href='/App_Data/MinimalSpreadsheetLight.xlsx' download='Minimal Spreadsheet file'>Spreadsheet file</a>");
...but no change. The file is there:
...so why is it not seen or accessible?
UPDATE 7
This:
string fullPath = HttpContext.Server.MapPath("~/App_Data/MinimalSpreadsheetLight.xlsx");
... (which I got from here) fails to compile with, "An object reference is required for the non-static field, method, or property 'System.Web.HttpContext.Server.get'
2-clicking the err msg highlights just "Server"
UPDATE 8
This (which I got from the same place as what I tried in Update 7):
string justDataDir = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();
string url2 = string.Format("Spreadsheet file</button>", justDataDir);
builder.Append(url2);
...does nothing; clicking the link doesn't even give me a fake/failed download now...
justDataDir is:
C:\Projects\ProActWebReports\ProActWebReports\App_Data
url2 is:
Spreadsheet file</button>
UPDATE 9
I noticed on further fine-tooth-combing that url2 had a forward whack in it; I changed it so that all the whacks were back, but it made no difference to Update 8's results: clicking the link does nothing whatsoever.
If somebody solves this, it will definitely get bountified after the fact.
UPDATE 10
Maybe what I really need to do is, instead of the simple html, add some jQuery that will download the file. But the question is, can jQuery access the App_Data folder any better than raw/simple html can?
The app_data folder is used by iis and asp.net as a private area in which to put database files which can only be accessed by code running on the server.
If you try to access the folder directly via your browser you will get a permissions error.
In order to make the files available for download, move them the a folder under 'Content' (if you have an mvc site) and ensure that your web.config allows the .xlsx exention to be downloaded.
It may depend on what version of iis you are using.
Downloading Docx from IE - Setting MIME Types in IIS

Script Task - Add existing file as link

I've been looking for an answer to this for a bit now but couldn't find anything. I was wondering if it is possible to add an existing file to the project created under the script task in an SSIS package. What I want to be able to do is to add one file called Helper or Utility to the solution and then add that file to all the script tasks for common functions. This is so if I change the class, it gets pushed through to all script tasks.
I know that I can add a reference to a DLL and add it to the GAC. I have tried this and it works. I've also tried adding the file to the projects and that works too.
This is just another solution that I'm trying, just in case I'm not able to deploy the DLL in prod. Any help will be appreciated. Thanks.
Firstly you need a master copy of your classes, you can copy them from an existing Script Task using the same process below but in reverse.
Open the Editor for the Script Task and on the Property Explorer click on the Project File (the st_[Guid] ), in the Properties window you’ll see the Project Folder location. (This location gets recreated every time you edit the script task)
In explorer, copy your classes to this folder
On the Project Explorer, click on the “Show All Files” icon
Right click on your files and add to Project
You can use regular VS functionality for linking files:
Right click your script project
Add > Existing item...
Select files to be included in your project
In the bottom right corner of the Open file dialog box you have a drop-down with 2 options: "Add" or "Add As Link" - select the latter one and you are done (see image below)
We can not use relative path after adding pages using Add link. Each user need to correct the path before running the project. The script task uses its own path.it doesn't run from package path which is the problem.

FlexPMD Violations Viewer - how to view results directly

So I started using FlexPMD for static code analysis, and I want to add it to my team's build process. I have it running nicely from a shell script, and can view the results by clicking a button and uploading the desired (pmd.xml) output file in the Violations Viewer that comes with it (note there is also one online here: http://opensource.adobe.com/svn/opensource/flexpmd/bin/flex-pmd-violations-viewer.html).
But I'd like to view the results directly without having to take the extra step of clicking the upload button. I imagine there is some black magic URL parameter that works, but (if so) what is it? This site:
http://blogs.adobe.com/xagnetti/2009/09/load_pmd_results_directly_in_t.html
mentions referencing pmd.xml with a "report" URL param, like so:
http://opensource.adobe.com/svn/opensource/flexpmd/bin/flex-pmd-violations-viewer.html?report=path/to/my/pmd.xml
but it's not working for me. Has anyone encountered this problem and triumphed, by chance?
EDIT: More info...
The latter (opensource.adobe.com...) webpage has the following JavaScript:
function getReport()
{
if ( window.location.href.indexOf('=') == -1 )
{
return "";
}
var hashes = window.location.href.slice(window.location.href.indexOf('=') + 1);
return hashes;
}
var report = getReport();
which it passes into flashvars. Perhaps the format with which I'm passing pmd.xml is incorrect?
Okay, figured it out. The version of the violations viewer that ships with the open source FlexPMD does not allow for automatic viewing of reports (the HTML wrapper doesn't pass in the report filepath, and the SWF doesn't take it in). The solution that worked for me was to download the files from the online violations viewer here:
http://opensource.adobe.com/svn/opensource/flexpmd/bin/flex-pmd-violations-viewer.html?report=path/to/my/pmd.xml
by using your browser to just save the webpage, and then curl to save the SWF file (directly trying to save from the browser will not work - appears to redirect to a null address) to like so:
curl -O http://opensource.adobe.com/svn/opensource/flexpmd/bin/flex-pmd-violations-viewer-1.1.swf
and place in the same directory as the violations viewer html file you downloaded. Then you can read your reports automatically! Here is an example (absolute filepath on Mac):
file:///path/to/your/violations-viewer/ViolationsViewer.html?report=/Users/joverton/some/project/path/bin-debug/pmd_reports/pmd.xml