switch back to previous tab in browser by using protractor - protractor

I am trying to get the second tab in my window browser by using below code but it is not working for me. Can any one suggest me easy way.
browser.getAllWindowHandles().then(function (handles) {
//Code for switchTo one Tab to another Tab in Same Browser
browser.switchTo().window('http://localhost:4200/home-unauth');
});

Resolved promise of getAllWindowHandles returns an array of tabs uuid. You even don't need to decode the values; new tab is added as last parameter of that array.
Try that - switch to second tab:
return browser.getAllWindowHandles().then((allTabs) => {
return browser.switchTo().window(allTabs[1]);
});

Related

How to prevent closing of cell editing in ag-grid on "Other Cell Focus"

I am working on an editable table in Angular application with ag-grid library. I would like to keep editing cells (in full row edit mode) until I finish with it and then close the editors manually via API. The problem is that the editor is closing on other cell click/focus (on some other line) as described here:
The grid will stop editing when any of the following happen:
Other Cell Focus: If focus in the grid goes to another cell, the editing will stop.
I cannot figure out how to disable this, if it is possible. Installing the onCellMouseDown() hook does not help, because the cellFocused event is fired before cellMouseDown. Therefore, the editing stops before I have a chance to intercept the mousedown event.
Here is my stackblitz little extract with related pieces of code.
The need for such scenario is that I want to validate the entry and not to allow a used to quit the editing if the form is not valid. The only workaround I found so far is that on any click outside of editing cells when the editor closing I reopen it right away in onRowEditingStopped() hook unless the editor has been closed via 'OK' button.
After all, I have managed to provide a custom solution that fits exactly into this problem which I was facing also.
First thing is to disable pointer events to non edited rows when a specific row is currently being edited. On Ag-grid's 'cellEditingStarted' callback I have added the following code:
public cellEditingStarted(event: any): void {
//not all rows are on dom ag-grid takes care of it
const nonSelectedGridRows = document.querySelectorAll('.ag-grid-custom-row:not(.ag-row-selected):not(.ag-row-editing):not(.pointer-events-none)');
forEach(nonSelectedGridRows, row => {
row.classList.add("pointer-events-none");
});
}
Because not all rows exist on dom (Ag-grid creates and destroys while you are scrolling )when a specific cell is being edited, I have also added a rowClassRule which is applied when rows are being created:
this.rowClassRules = {
'pointer-events-none': params => {
if (params.api.getEditingCells().length > 0) {
return true;
}
return false;
}
};
scss:
.pointer-events-none {
pointer-events: none
}
By disabling pointer events, when you click on a non edited cell the cell won't get focus and thus the currently edited cell will stil remain on edit mode. You can provide your own custom validation solution and close the editor manually through API. When you are done, you have to enable pointer events to all grid rows back again:
private enablePointerEvents(): void {
//not all rows are on dom ag-grid takes care of it
const nonSelectedGridRows = document.querySelectorAll('.ag-grid-custom-row.pointer-events-none');
forEach(nonSelectedGridRows, row => {
row.classList.remove("pointer-events-none");
});
}
I implemented the same above approach in Ag-Grid React.
I used getRowStyle callback for adding the css pointerEvents: none on dynemic basis.
It seems to be working for me fine.
Please refer the below code
const getRowStyle = (params) => {
// this is not initialized in read mode
// condition for me ==> currentEditRowIndex.current !== null && params.node.rowIndex !== currentEditRowIndex.current
if (someCondition for Row other than inline edit row) {
return { pointerEvents: "none" };
}
return null;
};
After adding this whenver you start the editing..You will need to call redrawRows so that css changes can be applied.
Hope this will help. Thank You!!
Thought I would share another solution that has been working out okay for me so far.
Using 'pointer-events-none' as suggested in the other answer is flawed because the Enter key can also close the editor.
In my case, I want to prevent the editor from closing when client side validation has failed and the data is invalid. When my conditions are met, I call stopPropagation() on the events to prevent the editor close from happening in the first place. It still has potential problems:
It cancels mousedown, dblclick, keydown, focusout and click for all elements that have a class name starting with ag- so if you happen to use this class prefix for other controls on the page, it could interfere. It also means any controls within the grid (sorting, resizing, etc.) don't work while the condition is met.
Calling stopPropagation() could potentially interfere with your own custom controls. So far I've been okay if I dont use the ag- prefix within the markup from my own custom cell editors and renderers
I hope they can add a proper API function to cancel the row/cell stopEditing function in the future.
["mousedown", "dblclick", "keydown", "focusout", "click"].forEach(function (eventName) {
document.addEventListener(eventName, function (e) {
if ( conditionForCancelingIsMet() ) {
// this appears to cancel some events in agGrid, it works for
// preventing editor closing on clicking other cells for example.
// It would be ideal if this worked for all ag-grid specific events
// and had a proper public API to use!
e["__ag_Grid_Stop_Propagation"] = true;
}
// convert element classList to normal js array so we can use some()
var classArray = [].slice.apply(e.target.classList);
if ( conditionForCancelingIsMet() && classArray.some(c => c.startsWith("ag-")) ) {
// unfortunately some events like pressing the 'enter' key still
// require stopPropagation() and could potentially interfere with unrelated controls
e.stopPropagation();
}
}, true);
});

Ionic Back Button Go to Previous Page with Query String

I'm developing an ionic app, I faced a problem where I'm on Page A going to Page B with query string ex:
Page A: #/app/channels-inside?id=30
Page B: #/app/nowplaying
This is where the problem lies. When I click the back button it goes back to the correct page but without the query string (URL becomes #/app/channels-inside. How do I handle this where I want to redirect to previous page with the id in it?
I think you should use it.
AngularJS: $ stateParams
.controller('yourCtrl', function ($scope, $stateParams){
$stateParams.id
})
This cant be achieved with default pop() method as its action is limited to popping the component from navigation array. What you can do is use insert and remove functions of NavController. Insert channel-inside in the navigation stack with the params you want. Then remove now-playing and already existingchannel-inside.
insert(insertIndex, page, params, opts)
Inserts a component into the nav stack at the specified index. This is
useful if you need to add a component at any point in your navigation
stack.
remove(startIndex, removeCount, opts)
Removes a page from the nav stack at the specified index.
Check out the docs.
Edit
Or you could use Events to pass the params
constructor(public events: Events) {}
// in now-playing
function createUser(user) {
console.log('User created!')
events.publish('user:created', user, Date.now());
}
// in channel inside
events.subscribe('user:created', (user, time) => {
// user and time are the same arguments passed in `events.publish(user, time)`
console.log('Welcome', user, 'at', time);
});

tabcontrol page not updated

In my winfom program I have a function that change the tabpage when I hit a key.
On tabcontrol indexchanged I check for some parametre and if they are not correct I change the tabpage to the first tab.
If I click on the page with the mouse the tabpage changed to the first tab with the correct content.
If I click a key and run this code "tcOrdre.SelectedTab = tpOrdre;" it changes the tab back to the first but still showing the content of the selected one.
In SelectedIndexChanged is use this code:
MessageBox.Show("Der skal vælges en ordre først"); // Show a messagebox
tcOrdre.SelectedTab = tpOrdreListe; // change tap to first
If I use the mouse then SelectIndexChanged get called when I run:
tcOrdre.SelectedTab = tpOrdreListe; // change tap to first
the SelectedIndexChanged function is called again and the content is okay.
But if I use the key to change index the SelectedIndexChanged does not get called Again and the content never change. Only the tab in the top change to the first one.
I hope someone can help me.
I found the solution.
All I have to do is call this line.
this.BeginInvoke(new Action(() => tcOrdre.SelectTab(0)));
and not tcOrdre.SelectedTab = tpOrdreListe;
And everything Works fine.

jQuery accordion section index

How can I make this accordion generic? That is, instead of active:2 I want it to point to the next section(may be some function like next() or such...). Similarly, for previous section.
$('#accordion').accordion({collapsible: true, active:2});
Also once if it opens a section , is there a way to focus on the first or last input field of the section?
Any help is appreciated.
$("#selector").accordion({
change : function(event, ui) {
// Your code to expand the next section and/or select the first element
}
// There is also a changestart event you could use instead of change
});

Problem with tab index after closing one of the tabs in gwt

I am developing a application in GWT using the decorated tab panel. I have implemented a close option for the tabs. Now my problem is that when I close one tab and try to add some data in the other tab it is taking the wrong index.
For example: I have 4 tabs and close the third one. I open 4th tab and try to add something there, but its index is showing as 3 instead of 4 as there are only 3.
How can I reset the tab index in the program, or else any solution where I can read the correct index of tab as it was before removing it?
This is where i am adding the new tab and the close event.
HorizontalPanel horizontalPanel = new HorizontalPanel();
Image image = new Image();
Label label = new Label("New Report: " + k);
label.setWordWrap(false);
horizontalPanel.add(label);
horizontalPanel.add(image);
image.setUrl("images/1305803163_close.png");
tabpanel.add(newTab[k], horizontalPanel);
tabindexx[k] = k;
image.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
tabpanel.remove(tabpanel.getTabBar().getSelectedTab());
}
});
and in some part of the code I am accessing the tab index like this
int selectedtab = tabpanel.getTabBar().getSelectedTab();
Of course this will return an index based on the number of tabs present at that particular moment, so I need to store them somewhere or else I have to reset the tab index after I close.
That will happen because the index number is the index for the current set of tabs. (if one closes, it obviously impacts the others).
I am a little rusty with GWT now, but i believe the only way to remove or select tabs is using index.
One solution could be to manage a List of tab representatives (some tab identifier) in your code, and do a mirror remove in that list when a delete occurs in your code. Then you can lookup the new index of the tab that you want to update after the delete and get the right index. (Tab identifier can be as simple as the original index of the tab when you started before any deletes)