Get custom menu item to appear with every instance of application - google-apps-script

Is there a way to create a custom menu item so that it is present every time you open the application? For example, every time I open a new google doc the menu item appears so that I can run my script in any and every document rather than only in the original "container" document.

Related

Bootstrap Tabs - trigger tabs by href link (how to trigger tab view in addition to hitting the tab itself)

For my projects section on my website I have them laid out in tabs. I have an overview tab that shows small cards with images of each of the projects. I would like to enable a feature where clicking on a project card will make "active" the respective tab.
I copied the format of the tabs by setting the following on my project card divs:
<a href="#Tab_Content_ID" data-toggle="tab" role="tab">
<div id="Project_Image"></div>
</a>
I am able to trigger the opening of that project's tab. However, the tab itself (in the tab navbar) is not selected. The overview tab is still selected (active) and thus the user can not return to the overview without first clicking on another project tab then back to the overview tab.
How can I fix this?
Project link
This is the current live version of the page. It does not reflect the changes I have made because they are still in testing. Just linking here so you can get a visual idea of what I'm talking about.
Relevant Projects Section HTML link
I can't post it in a codepen because none of the images will show.
Alright I doubt anyone will ever read this but I solved it myself. Now to be fair this is somewhat specific to my ID system but here goes
Each tab is a list item in the unordered list of the nav-tab bar. This is important because the "active" class is placed on the LIST item not the TAB itself.
Each tab content has an ID which I have titled "Project-Tab" where Project is the name of that particular project.
Each tab then links (href) to the content of that tab with an ID I have titled "Project" where project is the name of that particular project.
Now in my overview section on each of the "project cards" that I have linked to the tab content I added a class "Overview_Tab"
With that explanation here is the solution
$('.Overview_Tab').click(function(){
/* Gets the href of the clicked "project card" which is a link to the tab
content for that project. I then concatenate '-Tab' onto the end to get the
id of the associated tab (as explained above) */
var target = $(this).attr('href')+'-Tab';
// Get the parent (the list item containing that tab div) this is where
"active" needs to be placed
var target_parent = $(target).parent();
// Remove the active class on the overview tab
$('#Overview-Tab').parent().removeClass('active');
// Add active class to the target parent
target_parent.addClass('active');
});
So to generalize this you want your tab ID and tabContent ID to be the same just add '-Tab' to the end of your tab ID.
Pick any class name you want to add to the element that is replicating a tab (I picked "Overview_Tab" but you can put anything there as long as it matches between the HTML and the JS function)

Fragment Loads data every time i switch between tabs

In my application I am using fragment tab-host with view pager and I am opening child fragment inside each tab.
Every time I switch tab data get reloaded every time and one of the tab contains Google map, in Google map added markers programmatically but every time I switch tab it doubles the markers on map e.g. if I have added 10 markers for first time after switching once it get 20 and so on.
I have used this code to open child fragment
Used fragment page adapter with view pager
So please tellme how to stop reloading fragment.
This happens because each fragment has a lifecycle (http://developer.android.com/guide/components/fragments.html), and when you switch tab data the fragment is destroyed and another is created.
You are using fragments with view pager and this is controlled by a Parent Activity, so you can move the code to load the map to the Activity, and just use the fragment to display the data stored inside the activity.
You can get the parent activity with this code inside your fragment:
(YourActivity) this.getActivity();

Adding script to a button which can display Time now

Hi I am trying to make a spreadsheet with Button formed through shapes (using Drawing tool) and then assign script to it, to track Start time and End time. Basically the two button side by side would say Start and Stop, when you start working, you click the button and the start time would get recorded and when you click the Stop button it would record the time then as Stop time. I was reading the script tutorial and it said that now() argument is not allowed, is there any other way to do this on Google Sheets, because in Excel it is pretty simple.
Google Apps Script is based on JavaScript : new Date() is the equivalent of now()
Your idea is not bad but these button are not fixed, they move with the page whenever you scroll down...
I'd suggest using the sidebar available in new (standard) version of spreadsheets to place your 2 buttons and the corresponding results.
You can use HTMLService or UiApp to build a pretty user interface in the sidebar.

incompatible type passed in as a parameter created by loading a GUI component.

I am having a problem with a UI that I am building in a Google Spreadsheet. I will First explain a little about how it works and than I will get to the problem. The UI is fairly simple program that connects to a SQL database, it allows users to create new records, Query, search, and render reports. I have created all the panels (eg the intro page, the create record) in the GUI builder. As the user navigates through the UI I swap out a Grid with the new panel that i want the user to see. For example on the intro page there is a create button when the user clicks the button the gird where there intro panel was is replaced by the create record panel. I have created two ways for the user query/search for data. The first way is to select a number range on the intro panel and click the Query button. This will than query the last 10 or so records into a GUI built Panel that I will call MainForm. The second way is to "search" for a job. On the intro page there is a search button when the user clicks with button it goes to a new page; the grid is switched to the search panel. On the new page/panel the user can put in some parameters to search for. After the user clicks the search button the program should load the search results into the MainForm in the same way as when you Query from the intro page. I have taken the whole function apart line by line, so i am sure that the issue has to do with loading the panel/Component. What i mean by that is these few lines of code.
var Component = app.loadComponent("MainForm");
var panel = app.createVerticalPanel().setSize("770px", "900px").add(Component);
app.getElementById("contentGrid").setWidget(0,0, panel);
But why would it load in one case, but not in another? Also it is not the method of loading the Component, rather it is the returning the panel/ Component.
To Summarize, When I load the Component with the query function it works, but when i load the Component in the search function I get and error: Incompatible type passed in as a parameter. Also I load the MainForm Component in two other functions as and it works most of the time, but some times I get the same error.
I think your approach is not ideal, load component is not supposed to be called multiple times. It would be far more efficient to get all your panels in the same compnent and play with visibility of each panel to show / hide them on demand. Each panel should be inserted in a vertical panel so that the "new panel" slips to its place when the "old one" hides.
An example of this approach is shown in this post to simulate tabs and could easily be adapted to your needs.
btw, this method is also very fast and responsive since the full UI is ready from the very beginning ;-)

UiApp cache vertical panel

Developing small app to record a set of 6 readings for monitoring purposes in 31 rooms. App will have two main views, one view to show list of buttons for each room where readings will be taken, a second view where the values will be entered for a particular room and then posted to a spreadsheet.
The process in mind here is click on button for a particular room, enter the data, return to button view to choose another room to enter the data for that room and then back to button view screen.
Since the button view will seldom change do I have any options for caching this view so that I do not have to run a function to rebuild it each time. I have this function
function createTGSRoomListButtons(sh, aData){}
That takes the list of rooms and builds a panel of buttons for selecting the different rooms.
The question that I have can the above function be run once to cobble together the UI, cached and the later simply be 'recalled'?
TO that some end the view where the data will be entered can this be partially cached so that with each rendering a reference to a specific room can be made.
New to Google Apps Script so not really sure how to properly determine my answer.
You can have multiple panels in an UI and play with visibility to show one or another... no need to cache any content since they remain unchanged in the process.
If I understood your use case well, the panel with specific room info would be modified according to spreadsheet data so in this case you won't need to cache values since they would be "reconstructed" each time. The trick to show/hide panel has been shown in this post with clientHandlersand multiple panels in a unique vertical panel to ensure that the visible panel is always at the right place.
A very simple way would be build the UI for the first time and then hide/unhide the buttons' panel each time using the setVisible() method of the panel