Why is onsegmentchange event only happening after timeout code is completed - asynchronous

There is an issue where ionSegmentChange is processing the change only after the timeout is completed and not before even though this.section has been changed before the timeout is called.
Result
HTML File
<ion-segment *ngIf="this.os == 'ios'" class="forms-examples-segment-ios" [(ngModel)]="section" (ionChange)="onSegmentChanged($event)">
</ion-segment>
TS FILE
let ticketToScrollTo = null;
let notification_item_segment_type = null;
//User was already on another page that is not TicketListPage when notification was clicked (Ticket list page was pushed into nav controller)
if(!userOnCurrentPageWhenNotificationTriggered){
ticketToScrollTo = this.navParams.get('item_id');
notification_item_segment_type = this.navParams.get('ticket_segment_type');
}
//User was already on TicketListPage when notification was clicked (Page is refreshed rather than push to nav controller)
else{
ticketToScrollTo = this.notification_item_id;
notification_item_segment_type = this.notification_ticket_segment_type;
}
// Check if this page was accessed through clicking on mobile notification
if(ticketToScrollTo){
console.log("Page entered through notification");
let targetSection = null;
console.log("Classification that is received = "+notification_item_segment_type);
targetSection = notification_item_segment_type;
console.log("Target Section = "+targetSection);
console.log("THIS OS = "+ this.os);
this.section= targetSection;
console.log("Target section value has been changed, waiting for segment event handler to process it");
setTimeout(()=> {
console.log("Scrolling item to notification item");
console.log(notification_item_segment_type+"_"+ticketToScrollTo);
let notification_ticket_item = <HTMLElement>document.getElementById(notification_item_segment_type+"_"+ticketToScrollTo);
console.log(notification_ticket_item);
if(notification_ticket_item){
console.log("Item found and scrolling item into view");
notification_ticket_item.style.border ="5px solid #FFDCCD";
notification_ticket_item.style.boxShadow ="5px 8px rgb(0 0 0 / 30%)";
notification_ticket_item.style.marginBottom = '16px';
notification_ticket_item.scrollIntoView({
behavior: 'smooth',
block: "center"
});
console.log("DONE GETTING INITIAL DATA");
loader.dismiss();
}
else{
console.log("DONE GETTING INITIAL DATA");
loader.dismiss();
}
},10000);
}

Related

send notification from background worker

am using ABP to build my project
I have a module to generate big size files using background worker, and after each successful file generated I need to send notification, but is not working !
I've put the background job in the core project and the queue in the engine project,
the DB notification tables are updated successfully (new record inserted so the pull notification will work fine !), but the browser doesn't receive the notification (so I can inform him that his file is ready), but there is no errors and no any notification send to the browser.
here is the worker class:
public class GeneratedFileWorker : BackgroundWorkerBase, ISingletonDependency
{
.
.
.
[UnitOfWork]
[AutomaticRetry(Attempts = 0)]
public override async System.Threading.Tasks.Task ExecuteAsync()
{
var notificationData = new NotificationData();
notificationData["URL"] = "app/main/data/generatedfiles";
using (AbpSession.Use(TenantConsts.DefaultTenantId, TenantConsts.UserServiceId))
{
GetDownloadArticleInput getDownloadArticleInput = new GetDownloadArticleInput();
if (pendingRequest is not null)
{
var entityType = _lookupItemManager.Get(pendingRequest.EntityTypeId).Code;
dynamic Args = JsonConvert.DeserializeObject<GetDownloadArticleInput>(String.Empty);
switch (entityType)
{
case "Article":
Args = JsonConvert.DeserializeObject<GetDownloadArticleInput>(pendingRequest.ExtensionData);
break;
case "ArticlesList":
Args = JsonConvert.DeserializeObject<GetDownloadArticlesInput>(pendingRequest.ExtensionData);
break;
};
GeneratedFile generatedFileDto = new GeneratedFile();
try
{
generatedFileDto = await _generateFile.Generate(Args);
await _appNotifier.SendMessageAsync(new UserIdentifier(1, pendingRequest.CreatorUserId.Value),string.Format(_LocalizationSource.GetString("GeneratedFile.fileIsNotready"), _lookupItemManager.GetTitle(pendingRequest.EntityTypeId)), notificationData, NotificationSeverity.Error);
else
await _appNotifier.SendMessageAsync(new UserIdentifier(1, pendingRequest.CreatorUserId.Value), string.Format(_LocalizationSource.GetString("GeneratedFile.fileIsready"), _lookupItemManager.GetTitle(pendingRequest.EntityTypeId)), notificationData, NotificationSeverity.Success);
}
catch (Exception ex)
{
pendingRequest.CurrentStateId = _lookupItemManager.GetByCode(LookupCategories.GeneratedFileStatus, "Failed").Id;
pendingRequest.OperationResult = ex.ToString();
await _generatedFileRepository.UpdateAsync(pendingRequest);
await _appNotifier.SendMessageAsync(new UserIdentifier(1, pendingRequest.CreatorUserId.Value), string.Format(_LocalizationSource.GetString("GeneratedFile.fileIsNotready"), _lookupItemManager.GetTitle(pendingRequest.EntityTypeId)), notificationData, NotificationSeverity.Error);
}
}
}
}
I have 2 cases here:
first one working when I define the queue in the host project, and
second one not working when I define the queue in the engine project

How to use trigger variables in the message of the raised alert in Kibana ElasticSearch open distro

I am using elastic search open distro.This is my trigger condition :
for (int i = 0; i < ctx.results[0].hits.hits.length; i++) {
if(2 < ctx.results[0].hits.hits[i]._source.responseTime) {
score = true;
} else {
score = false;
}
}
return score;
I am trying to send the message with the specific details of my source with the API url and response time, something like below just for all raised alerts(how do we ensure that):
Monitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue.
- **API Url : {{ctx.results.0.hits.hits.0._source.msg}} and response time {{ctx.results.0.hits.hits.0._source.responseTime}}** -- **need details only for raised alerts**
- Trigger: {{ctx.trigger.name}}
- Severity: {{ctx.trigger.severity}}
//painless trigger script
def errorCodes = new ArrayList();
for (def item : ctx.results[0].aggregations.mystats.bysats.buckets) {
if(item.val1 > 5) {
resMessate.add(item.key);
}
}
// at the end..
ctx.results[0].hits["customerror"] = errorCodes; `
//Now the custom error can be accessed from trigger Action template message format
//i.e
{
{{#ctx.results.0.hits.customerror}}
"erroIn": {{.}}
{{/ctx.results.0.hits.customerror}}
}

google maps api geolocation doesn't update on timeout

I know this is probably not the most performant code possible, but if anyone can help I'd really appreciate that.
I'm working on a web-application that's supposed to locate the user's position with the google maps api. For this I created an UI control that starts the tracking of the user's current position and starts a timeout function that should update the position of the user. Everything works fine, but I testet the app when moving around and the geolocation doesn't change with the timeout, it always just shows the position of the first loop. I have to click on the UI control again to update the position.
These are the functions I adapted from the Google developer sites:
The function to detect the position:
//locate the user via GPS by checking geopositioning
function locateUser(geoLoc) {
var geoSuccess = function(position, map) {
startPos = position;
userLat = startPos.coords.latitude;
userLon = startPos.coords.longitude;
geoLoc = {lat : userLat ,lng : userLon};
};
var geoError = function(error, map) {
geoLoc = null;
//console.log('Error occurred. Error code: ' + error.code);
// error.code can be:
// 0: unknown error
// 1: permission denied
// 2: position unavailable (error response from location provider)
// 3: timed out
};
navigator.geolocation.getCurrentPosition(geoSuccess, geoError);
};
locateUser(geoLoc);
I'm using the variable "geoLoc" to get latitude and longitude within the map api.
This is the function that is called by a click on the UI-control and that starts the timeout:
//set the marker for the current position to the geolocation, when geolocation is possible
function setUserPosition(map, geoLoc, controlUI) {
//get the geolocation
locateUser(geoLoc);
//check if the position marker for the user position is already attached
if (positionSet == false) {
//if the position marker is not attached (first time user hits the UI control), generate and attach it nad notify the user that it's position is tracked
positionSet = true;
var userpos = {
url: "https://myhost.com/mygraphic.png", // url
scaledSize: new google.maps.Size(45,45), // scaled size
origin: new google.maps.Point(0,0), // origin
anchor: new google.maps.Point(23,23) // anchor
};
positionMarker = new google.maps.Marker({
position: geoLoc,
map: map,
zIndex: 100,
icon: userpos
});
}
//Check if geolocation is possible.
//If geolocation is not possible, hide the location marker and change the UI control's state back to default, but try again in three seconds.
if(geoLoc == null) {
controlUI.style.backgroundColor = '#4485F8';
controlUI.style.backgroundImage = "url('https://myhost.com/oldbackgroundimage.png')";
moveControl = false;
} else {
//If geolocation is possible, make the position marker visible, set it to the located position and cahnge the UI's state to "active".
posMark = positionMarker;
posMark.setPosition(geoLoc);
controlUI.style.backgroundColor = '#eeeef4';
controlUI.style.backgroundImage = "url('https://myhost.com/newbackgroundimage.png')";
moveControl = true;
}
map.panTo(geoLoc);
//check if the user hit the button to start the positiontracking and loop the function if so
if(moveControl == true) {
timeoutControl = setTimeout(function(){setUserPosition(map, geoLoc, controlUI)}, 3000);
} else if(moveControl == false) {
clearTimeout(timeoutControl);
}
}
And this is the function for the UI-control within the init-map function:
controlUI.addEventListener('click', function() {
//check if the user tapped the UI to locate the current position
if(moveControl == false) {
moveControl = true;
locateUser();
//if geolocation is not possible, open an alert to notify the user
if(geoLoc == null) {
alert("No geolocation :(");
} else {
//if geolocation is possible, set the UI control to the "active" state and start the interval to locate the user permanently (every three seconds)
controlUI.style.backgroundColor = '#eeeef4';
controlUI.style.backgroundImage = "url('https://myhost.com/newbackgroundimage.png')";
setUserPosition(map, geoLoc, controlUI);
//Show the Position marker
posMark.setMap(map);
}
//if the user has tapped the UI control and is in "location-mode" this tap stops the location mode and sets everything back into default state
} else if(moveControl == true) {
clearTimeout(timeoutControl);
moveControl = false;
controlUI.style.backgroundColor = '#4485F8';
controlUI.style.backgroundImage = "url('https://myhost.com/oldbackgroundimage.png')";
//Hide the Position marker
posMark.setMap(null);
}
});
I ran the script with an alert to display geoLoc within the geoSucess function of the locateUser function and it gets executed every time the timeout runs over the code and always fires geoLoc with data, but always only the position the user had when he first clicked the UI control.
Can anybody help and does know why the position is not updated within the timeout or maybe know how it would be updated?
Thanks a lot & kind regards,
Philipp

How to have a pop-up screen to warn that the time out of the session is over in shiro?

I have my project with shiro and I need when closing inactivity timeout, pops out pop up warning the user that the session will close. At the moment I have shiro with Servlet Container
try using javascript to show a popup once timer expires here timeout stores timeout period and now run a timer and show a popup once timer expires. Demo code below but you have to customize it and it is not full code.
var timeout=<%= currentUser.getSession().getTimeout() %>;
var starttimer=timeout-60000; //+100000000;
var timerstep=1;//In minutes
var alertbefore=5;//In minutes
var logoutUrl="logout";//Url to logout
var militimerstep=timerstep*60*1000;
var sessionNoExpireMessage="Session will never expire!!!";
var sess_timer=window.setInterval(updateTimer,militimerstep);
$("#timeout_timer").html(moment.duration(parseInt(starttimer,10)).humanize(true) + " remaining ");
if(timeout<0)
{
clearInterval(sess_timer);
$("#timeout").html(sessionNoExpireMessage+ " remaining ");
}else{
$("#timeout").html( moment.duration(parseInt(starttimer,10)).humanize() + " remaining");
}
function updateTimer(){
console.log("In timer");
// alert(timeout);
if(timeout<0)
{
clearInterval(sess_timer);
$("#timeout").html(sessionNoExpireMessage);
return false;
}
starttimer = starttimer-militimerstep;
$("#timeout").html(moment.duration(parseInt(starttimer,10)).humanize() + " remaining");
$("#timeout_timer").html(moment.duration(parseInt(starttimer,10)).humanize(true));
if(starttimer<=0){
window.location.replace("${pageContext.request.contextPath}/"+logoutUrl);
window.location("${pageContext.request.contextPath}/"+logoutUrl);
}
if(starttimer<alertbefore*60*1000){
$("#session_alert").modal();
}
}
function updateSessionInfo(){
if(timeout<0)
{
return false;
}
ajaxCount--;
resetajaxView();
starttimer=timeout-60000;
$("#timeout").html(moment.duration(parseInt(starttimer,10)).humanize() + " remaining");
$("#timeout_timer").html(moment.duration(parseInt(starttimer,10)).humanize(true));
}

LinkBar button / label click event transition

I have created a linkbar with two labels. Now, I need to keep a track of the label clicks.
10
100
i.e. If in the beginning "First" is clicked, the details will be displayed. After that, if without submitting the details, "Second" is clicked then an alert message should come to inform the user that "First is still in progress, do you want to cancel and begin Second operation". Vice-versa for Second to First transition. I need to know how to write events to keep track of which button clicked.
maybe....
var inProgress:Boolean = false;
var clickedButton:Button;
private function clickButtonHandler(event:MouseEvent):void{
if(clickedButton != null){
if(clickedButton != event.currentTarget && inProgress){
//handle alert
}
}
else{
clickedButton = event.currentTarget;
}
inProgress = true;
}
private function sumbitDetailsHandler(event:Event):void{
inProgress = false;
clickedButton = null;
}

Resources