Issue with JQuery window resize function calls - event-handling

I have a resize method in my js file :
$(window).resize(function(){
my_function();
});
In it i have loads of other functions which need to be called when the window is resized (for the responsive part of a website) ,i have not included all these functions as the problem i keep facing is the same in the one i am about to post.
It can't be simpler :
function my_function() {
console.log('1');
$('body').click(function(){
console.log('2');
});
}
my_function();
//when the function is called the console logs 1,when you click on the body ,it logs 2.
Now the problem, when I resize the window (for example : from full window to half in 2s),the resize() fires a couple of times (for example : 10 [every time it's different]).I know this because in the console the number 1 is called/logged 10 times as the window is being resized.Now,after i finished resizing the window, when i click on the body, the console logs the number 2 the same amount of times (10).
Why ? And how can i make it fire the click.function only once ?
Alex.
UPDATE 1 : in addition,every subsequent click on the body logs 2 another 10 times (so if i click 5 times,the console will log the number 2 50 times.

Related

Displaying calculated data on simulation main window

after running my simulation model, I have results that are printed on the console. instead of printing on the console, is there a way i can display results on simulation main. i mean once we run the model the simulation window pops up and we push the run button where the simulation main closes and the main window starts running, instead of that once the run button is pushed the simulation main window stays until the simulation is ended and the output is displayed later on simulation main window
Sure. First, untick this box in your sim experiment properties:
Next, drag in a button to your experiment and give it this code:
if ( getState() == IDLE ){
run();
getExperimentHost().setPresentable( this);
}
This starts the model but you stay at the experiment.
To display data, you use the code box below in the experiment using the root keyword to access Main:
NOTE: This only updates after the model run. If you want to see data updates during the run, you need to display it on Main directly (this is what it is for)

Filtering on ag-grid serverside not setting start row to 0 and end row to 100

Really need help on this, please.
Brief: I have implemented ag-grid serverside mode with partial store for lazy loading.
Problem Scenario : ServerSide mode, what happens is as you scroll more data is loaded, in terms of ag-grid more row blocks are loaded.
Lets say block size is 100 rows.
I scrolled 5-6 times, 5-6 request went to the server , loaded the data into the grid using success callback of getRows method in ServerSideDataSource Implementation.
You are currently viewing 500th-600th row in your viewport(the last request that went to server).
If you go and apply a fresh/change-existing filter on a column, the getRows method will get called but with request params having startRow 500 and endRow 600(rowBlock you are currently viewing).
This is the issue. I want that to be 0 and 100 respectively as you generally implement server-side filtering. It should be a fresh request to server right. ag-grid should recognise a new filter got applied so dump the existing rows on the grid send fresh request to server with 0 and 100 values.
This start and end row values are fine when you have already loaded data with filter applied till 500 and scrolling to load 500-600. But when the filter is first applied/ freshly applied(change from existing filter/ newly applied) you need the start and end rows to be 0 and 100 right. Help!!
Hi i came across this question while searching for this exact problem, looking around to the docs and couldn't find solution there. It's happening after they introduce serverSideStoreType: "partial | full".
my current workaround for this is to updating params.request.filterModel on your getRows datasource, if detect any changes on filterModel
getRows: function (params) {
//update startRow to 0 then detect changes
if(grid.filterModel != JSON.stringify(params.request.filterModel) ){
params.request.startRow = 0;
}
grid.filterModel = JSON.stringify(params.request.filterModel);
I got a method,after filter changed grid will be scrolled to the first row.
Angular :
filterChanged(params: FilterChangedEvent): void {
this.gridApi.ensureIndexVisible(0,null);
}
Javascript :
filterChanged(params) {
gridOptions.api.ensureIndexVisible(0,null);
}

wxPython window randomly freezes on RPi and acts weird afterwards

This Problem occurs on the RPi (3B+, Raspbian Buster) only. I run the program on my Mac without any problems.
Short description of my program:
After entering the mainloop, the program enters a second thread with another loop (call it requestloop) when the designated button is pressed. The requestloop can be left by pressing the button again. This requestloop requests a xml table via url every 10 seconds which is then parsed with ElementTree, sorted and displayed in a wx.grid.Grid. I use grid.ForceRefresh to make sure the grid is updated.
I hope the following snippet helps to understand the above:
def on_btnrun(self, event):
global run
if self.btnrun.Label == "Start":
run = True
thrupt = threading.Thread(target=self.thrupdate)
thrupt.start()
self.btnrun.SetLabel("Ende")
elif self.btnrun.Label == "Ende":
run = False
self.btnrun.SetLabel("Start")
def thrupdate(self):
while run is True:
reset()
self.grid.ClearGrid()
update(self.grid)
self.grid.ForceRefresh()
time.sleep(10)
Problem:
Now as mentioned in the title the whole wx Window freezes after passing the requestloop between roughly 5 and 20 times. This happens completely randomly, I could not find any regularities. The program keeps running though, for it still prints the output in the terminal every cycle (I added this function for testing).
When I now open another window (eg. menu dropwdown) which lays over the wx Window it will be copied onto the wx Window and stay there after I closed it.
Here are some Images to better understand what I mean (ignore all other widgets that I didn't mention, they are just nonfunctional placeholders).
Image of the wx Window before it freezes
Image of the wx Window after it freezes
Image of the wx Window after opening and closing the dropdown menu
Extra-Info: while building wxPython on the RPi I got some warnings and everytime I run the program I get the following one (it says the actual time instead of time):
(program.py:1666): Gtk-Critical **: time: gtk_distribute_natural_allocation: assertion ‚extra_space >= 0‘ failed
Question:
I have no idea why any of this happens. Is wxPython not stable on Raspbian? Or did the build partly fail? Or is the RPi not having enough rendering capacity?
Solved it by using wx.CallAfter in the details of the update() method.

How to use WebUI.getUrl().contains('atlassian') with timeout value

I have a piece of code that has a 5 sec delay and getUrl after. If I dont delay the execution, getUrl returns false since the site doesn't load yet.
WebUI.delay(5)
assert WebUI.getUrl().contains('atlassian')
In the website, there is a div which leads to another window when clicked. This code checks if the opened page is an Atlassian webpage. However, I don't want to use delay for 5 sec(it may take way longer or shorter). Is there a way to put a timeout, for instance wait for 1 min until page loads and if not loaded -> fail execution?
Try waiting for page load
WebUI.waitForPageLoad(5, FailureHandling.STOP)
assert WebUI.getUrl().contains('atlassian')
This will wait for 5 seconds for the page load and stop execution with test failed if the page isn't loaded in that time.
Alternatively, you could use WebUI.waitForElementPresent(to, timeout) where to is a test object you are certain is present when the page is loaded.

how to validate multiple toaster messages in Protractor

I am using Chrome browser(Version 54.0.2840.98 (64-bit)). There are two different operations happening in my application webpage. The success toaster for the result of first operation and second operation does not come simultaneously. There is a delay between the appearance of both toasters. I see that the second toaster appears after the first toaster has disappeared ( I have set timeout to 3 seconds). How would I validate using protractor that both toasters have appeared. The messages inside toasters are different. The ID of the toasters are same.
All the answers which I have seen here in stackoverflow site, doesn't work for this scenario.
First validate the appearance of first toaster, because the second appears when first disappears use waiting :
browser.wait(EC.invisibilityOf(element(by.id("toaster1"))), 30000).then(function () {
{here place the code for validation of second toaster}
})
var toast1 = element(by.css(".toast-message"));
expect(toast1).toEqual("validateText");
browser.wait(EC.invisibilityOf(element(by.id("toaster1"))), 30000).then(function () {
var toast2 = element(by.css(".toast-message2"));
expect(toast2).toEqual("validateText2");
})