Polarion - Display message box to the user - javascript

I would like to display a warning message (with just an "OK" button) when transitioning from one status to another. I tried using a ScriptFunction in the workflow of the WI with the following code (display_message.js):
// Get work item
var workItem = workflowContext.getTarget();
// Get the first parameter - the message itself
var fieldMsg = arguments.getAsString("field.msg");
// Display message
Message(fieldMsg, 1);
But I get the error message that "Message" is unknown. I also tried with "setMessage(fieldMsg)". And I got the same. I found those two functions in RtLinkBuilder and IBuildEvent.
Any idea how to solve this?
Thx for your help.

There is no support for UI-features in Workflow functions and conditions.
In general Polarion Open API does not support UI features(except Formextensions, which should not write/modify content)
The only possibility is to throw an exception, but you cannot branch on this and you cannot transport any user-readable message (except the Exceptionname).

Related

Omegle JavaScript bot that send three messages

I am trying to adjust the Omegle bot code in JavaScript that I have seen on the internet.
I want to use this bot to give the children on Omegle more knowledge about what other things they can do in their life instead of wasting their time on chats like that.
the issue is that the message I want to print is very long, such that Omegle will not send it (it looks like it was sent but when I tried with a friend, he didn't see anything. only when I divided the long message into small three messages.
I need to send three messages (one after another) instead of one.
the following code is what I have found, it is very simple - I just copy and paste it into the browser console and it works. - but it worked for only one message and then skip to the next person.
here is the original code:
function executeOmegle()
{
let btn = document.querySelector('.disconnectbtn')
let messageBox = document.querySelector('.chatmsg')
let sendBtn = document.querySelector('.sendbtn')
btn.click()
messageBox.innerHTML=" Hello, i am a bot"
sendBtn.click()
}
setInterval(executeOmegle,4000)
I need to send three messages, so I have modified the code like this:
but this will not work - it sends only the first message and skips to the next person.
function executeOmegle()
{
let btn = document.querySelector('.disconnectbtn')
let messageBox = document.querySelector('.chatmsg')
let sendBtn = document.querySelector('.sendbtn')
btn.click()
messageBox.innerHTML=" first message "
sendBtn.click()
messageBox.innerHTML=" Second message "
sendBtn.click()
messageBox.innerHTML=" Third message "
sendBtn.click()
}
setInterval(executeOmegle,4000)
can someone please help me to understand what I am doing wrong?
I don't have any experience in JavaScript or another platform.
I wish the code can be fixed so I will be able to use it "easily" in my browser.
thank you for your help,
Dan
PS
This is my first time on stack overflow.
I don't have any experience with JavaScript.
before I posted this question for six hours I tried to fix the code and did my research with no success.
so why do people here give bad feedback to my question as someone that didn't do his research?
or that the subject is not useful?

WP REST API ERROR 401 While trying to fetch image from wp:featuredmedia

I'm trying to fetch featured image from my published post but it seems impossible! I get
an error :( that's the code:
function fetchSlideShow(){
let endpoint = "http://loreleiheckmann.com/wordpress/wordpress/wp-json/wp/v2/Vinyls?_embed";
fetch(endpoint)
.then(e => e.json())
.then(showSlideShow);
}
function showSlideShow(data){
console.log(data);
data.forEach(showSingleSlide);
showSlides();
}
function showSingleSlide(aSlide) {
let template = document.querySelector(".slide_template").content;
let clone = template.cloneNode(true);
console.log(aSlide);
clone.querySelector("img").setAttribute("src", aSlide._embedded["wp:featuredmedia"]
[0].media_details.source_url);
let SlideList = document.querySelector("#SlideList");
SlideList.appendChild(clone);
}
While going to the array I see error 401 :( and moreover: Cannot read property 'source_url' of undefined" I don't know what I'm doing wrong .. any insights?
HERE ARE THE ERRORS -> 401 ON CONSOLE + PROBLEM WITH URL.:
Please try changing your url in the endpoint variable:
let endpoint = "http://loreleiheckmann.com/wordpress/wordpress/wp-json/wp/v2/posts?per_page=20&_embed=wp:featuredmedia
If you need more data you can add them with a comma:
wp-json/wp/v2/posts?per_page=20&_embed=wp:term,wp:featuredmedia
Post per page is optional, but I would prefer having that set.
And you should write what image size you need. That way rest api will give you the right source url:
_embedded['wp:featuredmedia']['0'].media_details.sizes.medium_large.source_url
I think it would also be better practice if you use an ssl certificate, there are free by "Let's encrypt".
EDIT:
Your screenshot shows the rest api message:
wp:featuredmedia: Array(1)
0:
code: "rest_forbidden"
data: {status: 401}
message: "Sorry, you are not allowed to do that."
So the 401 status code means: unauthorised
Seems like you are not allowed to access the data via rest api.
There could be multiple reasons for that:
The image is attached to an unpublished post. The post may have the status "private" or "draft", and therefore is not public available.
Your post (and attached image) is not available for not logged in users. If there is a restriction to view your code, this also applies to rest api.
Maybe you are using some kind of membership plugin that restricts the wp rest-api. Try deactivating all plugins if one of them affects the behaviour.
You have added some custom code to restrict access rest api access.
If nothing works for you, you should look into your database and check the medias post_status.
I think it is working fine, but you do not have access to view the posts data. This is what the 401 error indicates.
To whom it may concern - In the end, I added image in WP by custom post type ( I gave up wp:featured media - I wasn't able to fetch it.) Afterward I added a code to JS -> b.querySelector(".img").setAttribute("src", a.acf.image.url); so it works:)

How to handle XMLhttpRequest.Response based alerts without time violation?

What I have:
A Form with file attachment that on submit gets send via XMLhttpRequest (in JSON) to an external server. I get a response, and the user gets an alert window if the data has been submitted - or what information is missing.
Problem:
However chrome is not too happy with it, because apparently the window.alert in the readystate == 4 is not a good idea?
The ms from the error message seem to be the time the user takes to click OK.
See error message below:
[Violation] 'readystatechange' handler took 3203ms
This is the code in question:
abc.onreadystatechange = function () {
if (abc.readyState == 4) {
var answer = abc.response;
if (answer.success) {
// alert("Data was sent. Number: " + answer.Number);
console.log("Data was sent. Number: " + answer.Number);
}
else {
//alert("Data is missing: " + answer.message);
console.log("Data is missing: " + answer.message);
}
}
};
What is the better way to use different window.alert based on the values of the .response ?
This seems to be a generic violation warning message thrown by chrome to report those functions which are taking too long
As per this thread
Summary
A new performance API to enable applications to detect presence of
“long tasks” that monopolize the UI thread for extended periods of
time and block other critical tasks from being executed - e.g.
reacting to user input.
Going by the message you have received, it looks like chrome has thrown a warning that you took 3 seconds to close the alert box.
Also,
This is just a warning, you can hide this warning by choosing log levels
in your developer tool's console.
Use console.log for debugging, instead of alert.

Firefox - displaying web notifications from extension/addon

I'm building Firefox addon (with addon-SDK) and I'd like to display desktop notification to a user.
There is Notification object but it doesn't seem to work from addon code (background page). There is no error etc, but no dialog for permissions is displayed, so no notifications can be displayed. I've tried of course adding permissions/desktop-notifications but no effect.
Edit: pasting sample code I've tried (the code is located inside callback function for socket.io event. Event is received properly, but no notification is displayed, or request for permission.
Notification.requestPermission( function(status) {
console.log(status); // notifications will only be displayed if "granted"
var n = new Notification("title", {body: "notification body"}); // this also shows the notification
});
I've also found alerts service this one works. However alerts disappear quite fast (too fast for me) - edit: that's the way it works - so guess no code sample needed, as I don't see any option to make them last longer.
Is there any way to display chrome like notifications on Firefox? (chrome.notifications.create) Or at least use web notifications object from within the addon?
If you're using the add-on SDK, you're looking at the wrong docs. Here are the notification docs.
You create a notification like so:
var notifications = require("sdk/notifications");
notifications.notify({
title: "Jabberwocky",
text: "'Twas brillig, and the slithy toves",
data: "did gyre and gimble in the wabe",
onClick: function (data) {
console.log(data);
}
});
All the docs you look at should be a subset of developer.mozilla.org/en-US/Add-ons/SDK.

Postgresql. One process insert, second try to select but not found

Strange situation.
I try to start chat application.
I use postgresql 9.3 and tomcat as web server.
What is happens when one browser sending message another:
1 - Broswer A send message to server (tomcat)
2 - Tomcat put msg into database and get his id
INSERT INTO messages VALUES('first message') returning into MSGID id
3 - Tomcat resend message to Browser B (websocket recipient)
4 - Browser B send system answer: MSGID_READED
5 - Tomcat update database message
UPDATE messages SET readtime = now() WHERE id = MSGID
All works, but sometimes at point 5 update can't find message by MSGID...
Very strange, coz at point 2 I getting message record ID, but at 5, not.
May postgresql write slowly and this record not allow (not visible) from parallel db connection?
UPDATE
I found solution for me, just put insert inside begin/exception/end block.
BEGIN
INSERT INTO messages (...)
VALUES (...)
RETURNING id INTO MSGID;
EXCEPTION
WHEN unique_violation THEN
-- nothing
END;
UPDATE 2
In detail tests above changes with BEGIN block has no effects.
Solution in Javascript! I sent websocket messages from other thread and problem solved!
// WebSocket send message function
// Part of code. so is a web socket
send = function(msg) {
if (msg != null && msg != '') {
var f = function() {
var mm = m;
// JCC.log('SENT: [' + mm + ']');
so.send(mm);
};
setTimeout(f, 1);
}
};
Ok, so the problem is that normally writers do not block readers. This means that your first insert happens, and the second insert fires before the first one commits. This introduces a race condition in your application which introduces the problem you see.
Your best issue here is either to switch to serializable snapshot isolation or to do what you have done and do exception handling on the insert. One way or another you end up with additional exception handling that must be handled (if serializable, then a serialization failure exception may sometimes happen and you may have to wait for it).
In your case, despite the performance penalty of exception handling in plpgsql, you are best off to do things the way you are currently doing them because that avoids the locking issues and waiting for the transaction to complete.

Categories