Suspend Time Based on Holidays Node Red - function

I'm trying to suspend the eztimer node by an input of the holiday (Feiertage) - Node.
The Holiday node sends every day at 00:01 a boolean value if today is a holiday or not.
It's possible to suspend the timer by putting a message.suspend true or false.
So I've already tried a function with transform the msg.payload to msg.payload.suspend but it was not working. Then I tried to use the change function to set msg.payload.suspend from msg.payload - but it's also not working. I always get from the time the input is not supported.
tested function node:
var test = msg.payload;
msg.payload.suspend = test;
return msg;

You need to use the "Move" verb in the change node not the "Set" (Festlegen) verb.
And the function node should be:
msg.payload = {
suspended: true
}
return msg
In the old version you are trying to set the suspend field on what is probably a number (assuming you are using an inject node to trigger it). You can't do this, so you need to replace it with an object.

Related

ngOnChanges only works when it's not the same value

So basically I have a modal component with an input field that tells it which modal should be opened (coz I didn't want to make a component for each modal):
#Input() type!:string
ngOnChanges(changes: SimpleChanges): void {
this.type = changes["type"].currentValue;
this.openModal();
}
that field is binded to one in the app component:
modalType = "auth";
HTML:
<app-modal [type] = modalType></app-modal>
In the beginning it's got the type "auth" (to login or register), but when I click on an icon I want to open a different modal, I do it like so:
<h1 id="options-route"
(click) ="modalType = 'settings'"
>⚙</h1>
but this only works the first time, when modalType already has the value "settings" the event doesn't trigger even though the value has technically changed
I think the problem is that it's the same value because i tried putting a button that does the exact same thing but with the value "auth" again and with that it was clear that the settings button only worked when tha last modal opened was auth and viceversa
any ideas? I want to be able to open the settings modal more than once consecutively possibly keeping onChange because ngDoCheck gets called a whole lot of times and it slows down the app
You need to include the changeDetectorRef, in order to continue in this way.
More about it https://angular.io/api/core/ChangeDetectorRef
Although, a better and a faster alternative is the use of a behavior Subject.
All you have to do is create a service that makes use of a behavior subject to cycle through each and every value exposed and then retrieve that value in as many components as you want. To do that just check for data changes in the ngOnInit of target component.
You may modify this for implementation,
private headerData = new BehaviorSubject(new HeaderData());
headerDataCurrent = this.headerData.asObservable();
changeHeaderData(headerDataNext : HeaderData) {
this.headerData.next(headerDataNext)
console.log("subscription - changeUserData - "+headerDataNext);
}
Explanation:
HeaderData is a class that includes the various values that can be shared with respective data types.
changeHeaderData({obj: value}), is used to update the subject with multiple values.
headerDataCurrent, an observable has to be subscribed to in the target component and data can be retrieved easily.
I mean i'm too l-a-z-y to use your slightly-not-so-much-tbh complicated answers so I just did this:
I added a counter that tops to 9 then gets resetted to 0 and I add it to the value
screwYouOnChangesImTheMasterAndYouShallDoMyBidding = 0;
//gets called onClick
openSettings(){
if(this.screwYouOnChangesImTheMasterAndYouShallDoMyBidding === 9){
this.screwYouOnChangesImTheMasterAndYouShallDoMyBidding = 0;
}
this.screwYouOnChangesImTheMasterAndYouShallDoMyBidding = this.screwYouOnChangesImTheMasterAndYouShallDoMyBidding + 1;
this.modalType = "settings"+this.screwYouOnChangesImTheMasterAndYouShallDoMyBidding;
}
then in the child component I just cut that last character out:
ngOnChanges(changes: SimpleChanges): void {
let change = changes["type"].currentValue as string;
change = change.substring(0, change.length - 1);
this.type = change;
this.openModal();
}
works like a charm 😂

Run replace script in Google App Maker

I would like to add a server script that replaces special characters when a textbox is filled. The info for the "onValueEdit" routine states:
This script will run on the client whenever the value of this widget is edited by the user. The widget can be referenced using parameter widget and the new value of the widget is stored in newValue. Unlike onValueChange(), this runs only when a user changes the value of the widget; it won't run in response to bindings or when the value is set programmatically.
Therefore I have built the following server script that should take the text from the textbox, overwrite the special characters and replace the text in the textbox. But when I add the script to "onValueEdit" event, Google App Maker returns "function is undefined".
function cleanup(input, output) {
if (input !== null) {
output = input.trim();
output = output.replace('ß','ss');
output = output.replace('ä','ae');
output = output.replace('ö','oe');
output = output.replace('ü','ue');
return output;
}
}
In case you want to make this changes only on client side the ritgh way to do it will be adding this code to the onValueEdit event handler:
// onValueEdit input's event handler
if (newValue !== null) {
output = newValue.trim();
output = output.replace('ß','ss');
...
widget.value = output;
}
If you need to securely enforce this override prior to persisting to database, then you need to go with Model Events:
// onBeforeCreate and onBeforeSave events
if (record.FieldToChange !== null) {
record.FieldToChange = record.FieldToChange.trim();
record.FieldToChange = record.FieldToChange.replace('ß','ss');
...
}
With this approach you don't need any client code since all changes made on server should automatically sync back to client.

chrome.idle: how can I query the current detection interval?

You can do this:
chrome.idle.setDetectionInterval(60*60);
chrome.idle.onStateChanged.addListener(my_code)
However, someone on the browser console can then type in:
chrome.idle.setDetectionInterval(15);
...and this will affect the way that my_code is called. This is useful for debugging, but it begs the question: how can I query the current detection interval?
There is no way (at least none that I or Google know of) to query the detection interval. However we know that the default is 60 seconds, and it's possible to override the function. (You just need to make sure that nobody calls setDetectionInveral in your app's environment before you overrode the function - and if you can't be sure, you would have to manually set the detection interval to a known value afterwards.)
Example:
var currentDetectionInterval = 60;
var originalSetDetectionInterval = chrome.idle.setDetectionInterval;
chrome.idle.setDetectionInterval = function(detectionIntervalInSeconds, callback) {
currentDetectionInterval = detectionIntervalInSeconds;
return originalSetDetectionInterval.apply(this, arguments);
};
// Optional, if you like this.
chrome.idle.getDetectionInterval = function() {
return currentDetectionInterval;
};
This would allow you to query the detection interval by checking the variable currentDetectionInterval, or if you like this better, by using the new function chrome.idle.getDetectionInterval we just added.

Checking whether a checkbox is checked

I have not found any inbuilt function for checking whether a checkbox is set true or false,
isChecked() is not available is apps-script (if i am right).
Any idea on how to find it or we shall have a value change handler to count the number of times the value changed and find if it is checked or not?
You should assign your checkbox a name so that you can retrieve its value in a handler function with e.parameter.checkboxname : this value is boolean.
var chkmode = app.createCheckBox("description").setName("chk1").setId("chk1")
with the ID you can modify its state from the handler function (or from any other) if necessary (getElementbyId())
note that the handler can be on the checkbox itself (a change handler) or on any other element in the UI, depending on your needs.
I might be wrong, however I believe there is a problem with the checkBox status, even though its status looks like boolean, it doesn't behave like boolean but like string
if you print in a spreadsheet e.parameter.myCheckBox you will get TRUE or FALSE
if you print in a spreadsheet e.parameter you will get the whole object and see myCheckBox=true or myCheckBox=false
however, if (e.parameter.myCheckBox) will always return True
the workaround I am using is: if (e.parameter.myCheckBox == "true") will return the actual myCheckBox status
Just in case, I am opening a new ticket in the issue tracker
I hope this would help you
ps. confirmed with Google, e.parameter.myCheckBox is a string, not a boolean
if you want to use it as boolean it would be like (e.parameter.myCheckBox == "true")
var handler = app.createServerClickHandler('tellStatus');
and then (as example showing it in a label)
function tellStatus(e){
var app = UiApp.getActiveApplication();
app.getElementById('yourStatusLabel').setText('Checkbox checked: ' + e.parameter.yourCheckbox)
return app;
}
You should use handler function look like below.
I found example from https://sites.google.com/site/scriptsexamples/learn-by-example/uiapp-examples-code-snippets/check-box
if(e.parameter['checkbox_isChecked_'] == 'true'){
itemsSelected+= e.parameter['checkbox_value_']+',';
}

Primefaces PickList update target list on transfer

I want to update the lists in the bean when the user transfers an item from one list to another. Is there a way to do that?
Thx.
In the xhtml:
<p:pickList value="#{myBean.myDepartment}" onTransfer="handleTransfer(e)"....>
In the bean:
List<Department> selectedDepartments = new ArrayList<Department>();
List<Department> availableDepartments = getAvailableDepartments();
private DualListModel<Department> myDepartment;
myDepartment = new DualListModel<Department>(availableDepartments, selectedDepartments);
On Commit, Departments selected by the user can be accessed using selectedDepartments
And the script ...
<script type="text/javascript">
function handleTransfer(e) {
item = e.item;
alert(item.text());
fromList = e.from;
toList = e.to;
type = e.type; //type of transfer; command, dblclick or dragdrop)
}
</script>
I don't exactly know what do you want. This is done automatically same as if you type something into p:inputText it is available in beans property representing the value of p:inputText without need of manual update.
Just access the updated values in your pickList with getTarget() or getSource() methods. You are probably trying to access lists which you provided to DualListModel directly like:
DualListModel<fooType> fooModel = new DualListModel<fooType>(fooList1,fooList2);
// transfer item
// check if fooList2 is updated - this is wrong, it is **not** updated
fooModel.getTarget(); // this way you can get the actual values of target list
target - right side, source - left side of a pickList.