How to leave from group chat using node-xmpp - node.js

This doesn't work. Here cl is xmpp-client object of who wants to leave from group.
cl.on('online', function (userData) {
var userJid = userData.jid.user + '#' + userData.jid.domain + "/" + userData.jid.resource,
roomJid = params.typeId + params.service + userData.jid.domain + '/' + params.userName;
pres = new xmpp.Element('presence', {
from : userJid,
to : roomJid, //54d213e000e9e50c4e8e5a2b#conference.domain/nickName
type : 'unavailable',
xmlns : 'jabber:client'
});
status = cl.send(pres);
});

Related

Authorize dataset to access another dataset

What I have right now is I am authorizing using views. Now, I want to access all the underlying data inside a dataset.
view_dataset: '***'
view_table: '***'
table_dataset: '***'
view_string = "view={'projectId': '" + view_project + "', 'datasetId': '" + view_dataset + "', 'tableId': '" + view_table + "'}"
view_source = bigquery.Table(view_project + '.' + view_dataset + '.' + view_name)
dataset = client.get_dataset(table_project + '.' + table_dataset)
access_entries = dataset.access_entries
table_source = bigquery.Dataset(table_project + '.' + table_dataset)
access_entries.append(bigquery.AccessEntry(None, "view", view_source.reference.to_api_repr()))
table_source.access_entries = access_entries
table_source = client.update_dataset(table_source, ["access_entries"])
How will I be able to authorize view_dataset to access table_dataset programmatically?
To anyone who wants to authorize programatically, here is how I did it:
Create an entity ID for the dataset:
entity_id = {
'dataset': {
'projectId': table_project,
'datasetId': view_dataset,
},
'target_types': 'VIEWS'
}
Then, instead of view, use dataset:
access_entries.append(bigquery.AccessEntry(None, "dataset", entity_id))
I've managed to do this by reading the AccessEntry class on dataset.py of BigQuery.
If the ``entity_type`` is 'dataset', the ``entity_id`` is a ``dict``
that includes a 'dataset' field with a ``dict`` representing the dataset
and a 'target_types' field with a ``str`` value of the dataset's resource type:
{
'dataset': {
'projectId': string,
'datasetId': string,
},
'target_types: 'VIEWS'
}

I'm sending a generated pdf from my server to the client as a base64 pdf string. I'm trying to print it on the client side using printJS

I'm generating a report using fluentreports on my server and sending the base64 pdf string to the client on the callback. On the client once he/she receives the base64 string, I am required to print out this pdf string as a pdf which I am trying to accomplish using printJS. I also tried pdfMake but neither one wanted to work. If I console.log the base64 string and click on it, the pdf opens beautifully in the next tab but once I try to print it using printJS or pdfMake it opens a new tab and automatically closes it without doing anything. Is there any other way I could accomplish this? I've tried a lot of things already from reading up on other peoples' issues online and haven't gotten anywhere. Is there any library out there that can create a PDF document using a base64 pdf string so that I can use printJS to print out the document?
Function on the client that sends info to the server and receives back the pdf string:
submit: function () {
this.$Socket.emit('addrepair', {
CustomerID: this.$route.params.Customer.CustomerID,
Problem: this.problem,
BrandID: this.brand,
TypeID: this.type,
Model: this.model,
ColorID: this.color,
Warranty: this.convertbool(this.warranty),
Purchased: this.convertbool(this.purchase),
RushService: this.convertbool(this.rush),
DateReceived: this.datereceived,
UserID: this.UserID
}, (data) => {
if(data.authenticated==true)
{
//window.open(data.pdf)
//pdfMake.createPdf(this.convertDataURIToBinary(data.pdf)).print()
console.log(data.pdf)
printJS({printable: data.pdf, type: 'pdf'})
this.jobdialog=true
}
})
Function on the server that serves the pdf base64 string:
socket.on('addrepair', (data, callbackfn) => {
let query="INSERT INTO repair(CustomerID, Problem, BrandID, Model, ColorID, Warranty, Purchased, RushService, DateReceived, TypeID, UserID) VALUES (" + data.CustomerID + ", \'" + data.Problem + "\', " + data.BrandID + ", \'" + data.Model + "\', " + data.ColorID + ", " + data.Warranty + ", " + data.Purchased + ", " + data.RushService + ", \'" + data.DateReceived + "\', " + data.TypeID + ", " + data.UserID + ");"
con.query(query, function(err) {
if(err) {
throw err
}
else
{
query="SELECT RepairID, FirstName, LastName, Address, PhoneNumber, RushService, Purchased, DateReceived, Problem, Model, (SELECT Type from types WHERE repair.TypeID=types.TypeID) as Type, (SELECT Color from colors WHERE repair.ColorID=colors.ColorID) as Color, (SELECT Brand from brands WHERE repair.BrandID=brands.BrandID) as Brand, Warranty from repair INNER JOIN customer ON repair.CustomerID=customer.CustomerID WHERE repair.RepairID=(SELECT LAST_INSERT_ID())"
con.query(query, function(err, rows) {
if(err) {
throw err
}
else
{
var options = {
data: rows
}
//var myreport = new Report("buffer", options)
var myreport=new Report.Report("buffer", options)
.data(rows)
.pageHeader(repairheaderFunction)
.detail(repairdetailFunction)
.pageFooter(repairfooterFunction)
myreport.render(function (err, data) {
callbackfn({authenticated: true, pdf: 'data:application/pdf;base64,' + data.toString('base64')})
})
//callbackfn({authenticated: true, data: rows})
}
})
}
})
})
var repairheaderFunction = function(Report, data) {
};
var repairdetailFunction = function(Report, data) {
Report.print("#" + data.RepairID, {fontSize: 22, bold: true, underline:true, align: "center"});
Report.newLine(2);
Report.print('First Name: ' + data.FirstName + "\n")
Report.print('Last Name: ' + data.LastName + "\n")
Report.print('Address: ' + data.Address + "\n")
Report.print('Phone Number: ' + data.PhoneNumber + "\n")
Report.print('Brand: ' + data.Brand + "\n")
Report.print('Model: ' + data.Model + "\n")
Report.print('Color: ' + data.Color + "\n")
Report.print('Problem: ' + data.Problem + "\n")
Report.print('Date Received: ' + data.DateReceived.slice(15) + "\n")
/*.text('Last Name: [LastName]\n')
.text('Address: [Address]\n')
.text('Phone Number: [PhoneNumber]\n')
.text('Brand: [Brand]\n')
.text('Model: [Model]\n')
.text('Color: [Color]\n')
.text('Problem: [Problem]\n')
.text('Date Received: [DateReceived]', 1.75, 0, 1, 0.25, {
pattern: 'M/D/YY'
})*/
};
var repairfooterFunction = function(Report) {
Report.line(Report.currentX(), Report.maxY()-18, Report.maxX(), Report.maxY()-18);
Report.pageNumber({text: "Page {0} of {1}", footer: true, align: "right"});
Report.print("Printed: "+(new Date().toLocaleDateString()), {y: Report.maxY()-14, align: "left"});
};
Print.js is now supporting base64 PDF print.
Try this:
printJS({
printable: your_base64_data_string,
type: 'pdf'
base64: true
})
The documentation has been updated with an example printing a base64 PDF document.
http://printjs.crabbly.com#pdf
Was able to get this to work after a lot of playing around with the code and thinking of possible solutions. Generates the iframe, pulls up the print dialog using the autoprint property of the report and then deletes the iframe once the focus is on the document again using the 'mousemove' event
The code is below:
printIframe: function(url) {
var proxyIframe = document.createElement('iframe');
var body = document.getElementsByTagName('body')[0];
body.appendChild(proxyIframe);
proxyIframe.style.width = '100%';
proxyIframe.style.height = '100%';
proxyIframe.id='iframe'
proxyIframe.style.display = 'none';
var contentWindow = proxyIframe.contentWindow;
contentWindow.document.open();
// Set dimensions according to your needs.
// You may need to calculate the dynamically after the content has loaded
contentWindow.document.write('<iframe src="' + url + '" width="1000" height="1800" frameborder="0" marginheight="0" marginwidth="0">');
contentWindow.document.close();
var x=0
var func=function (event) {
if(x===0)
{
body.removeChild(proxyIframe)
++x
}
else
{
document.removeEventListener('mousemove', func)
}
}
contentWindow.document.body.onload=() => {
contentWindow.document.body.focus()
setTimeout(()=>{
document.addEventListener('mousemove', func)
}, 5000)
}
},

getting name of steam user from id

I'm using npm package steam-user
I'm stuck on getting steam name from steam id, I tried this:
var name;
client.getPersonas([sid], function(personas) {
var persona = personas[sid];
name = persona ? persona.player_name : ("[" + sid + "]");
});
console.log(config.console_userMessageReceived + "(" + name + " | " + sid + "): " + message);
However when the variable name is printed in console, its printed as undefined. Any help how to solve this, and print the actual steam name?
Seems like you have asynchronous call. Try this:
var name;
client.getPersonas([sid], function(personas) {
var persona = personas[sid];
name = persona ? persona.player_name : ("[" + sid + "]");
console.log(config.console_userMessageReceived + "(" + name + " | " + sid + "): " + message);
});

SharePoint List UserCustomAction, In whole sitecollection

I'm getting this to work if I choose a specific list to add the action to. Is there an easy way to enable this custom action on all document libraries in the whole sitecollection?
Code sample:
function createUserCustomActionList() {
var cmd = "<CommandUIExtension><CommandUIDefinitions><CommandUIDefinition Location=\"Ribbon.Documents.Manage.Controls._children\">" +
"<Button Id=\"DiaryAction.Button\" TemplateAlias=\"o1\" Command=\"DiaryCommand\" CommandType=\"General\" LabelText=\"Dela flera\" Image32by32=\"https://eolusvind.sharepoint.com/sites/intranet/_layouts/15/1033/Images/formatmap32x32.png?rev=23\"" +
" Image32by32Top=\"-271\" Image32by32Left=\"-109\" />" +
"</CommandUIDefinition></CommandUIDefinitions><CommandUIHandlers>" +
"<CommandUIHandler Command =\"DiaryCommand\" CommandAction=\"javascript:alert('Hej');\" EnabledScript=\"javascript:SP.ListOperation.Selection.getSelectedItems().length > 1;\" />" +
"</CommandUIHandlers></CommandUIExtension>";
var ctx = new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle('Dokument');
var uca = list.get_userCustomActions();
var oUserCustomAction = uca.add();
oUserCustomAction.set_location('CommandUI.Ribbon.ListView');
oUserCustomAction.set_commandUIExtension(cmd);
oUserCustomAction.set_sequence(100);
oUserCustomAction.set_title('Dela flera');
oUserCustomAction.update();
ctx.load(list, 'Title' ,'UserCustomActions');
ctx.executeQueryAsync(function () {
alert('Custom action created for ' + list.get_title())
}, function (sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
});
}
I would suggest the following approach for registering custom button in Documents libraries across site collection:
use RegistrationType set to 2(ContentType) and RegistrationId set to 0x0101 (for Document content type) to register custom action via content type
use site scope user custom action to apply changes across all site
collection
Example
var cmd = "<CommandUIExtension>" +
"<CommandUIDefinitions>" +
"<CommandUIDefinition Location=\"Ribbon.Documents.Manage.Controls._children\">" +
"<Button Id=\"ClickAction.Button\" TemplateAlias=\"o1\" Command=\"ViewCustomPropertiesCommand\" CommandType=\"General\" LabelText=\"View Custom Properties\" Image32by32=\"/_layouts/15/1033/Images/formatmap32x32.png?rev=23\" Image32by32Top=\"-1\" Image32by32Left=\"-171\" />" +
"</CommandUIDefinition></CommandUIDefinitions><CommandUIHandlers>" +
"<CommandUIHandler Command =\"ViewCustomPropertiesCommand\" CommandAction=\"javascript:console.log('View Custom Properties');\" EnabledScript=\"javascript:SP.ListOperation.Selection.getSelectedItems().length > 0;\" />" +
"</CommandUIHandlers>" +
"</CommandUIExtension>";
var ctx = new SP.ClientContext.get_current();
var customAction = ctx.get_site().get_userCustomActions().add(); //1. apply via site scope user custom action
customAction.set_location('CommandUI.Ribbon.ListView');
customAction.set_commandUIExtension(cmd);
customAction.set_sequence(112);
customAction.set_registrationType(2); //2.set to ContentType
customAction.set_registrationId("0x0101"); //2.set Document content type
//customAction.set_title('Document custom button');
customAction.update();
ctx.executeQueryAsync(function () {
console.log('Button has been registered');
}, function (sender, args) {
console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
});

Setting SOAP Version with node-soap.

I'm using this npm-module: https://github.com/vpulim/node-soap
The webservice I want to consume is only using SOAP 1.2 and returns a server error on using any other SOAP version.
Has someone experienced the same problem and knows how to set the SOAP version?
With latest version of https://github.com/vpulim/node-soap, there is option to set SOAP 1.2 header
var options = {
forceSoap12Headers: true
};
soap.createClient(url,options, function (err, client) {
//Your soap call here
});
IMO, I dont think we should modify the lib, not good for upgrade
I have solved the issue changing as NicolasZ said, my current soap/lib/client.js is:
line 187:
xml = "<soap:Envelope " +
//"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
"xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
encoding +
this.wsdl.xmlnsInEnvelope + '>' +
((self.soapHeaders || self.security) ?
(
"<soap:Header>" +
(self.soapHeaders ? self.soapHeaders.join("\n") : "") +
(self.security ? self.security.toXML() : "") +
"</soap:Header>"
)
:
''
) +
"<soap:Body" +
(self.bodyAttributes ? self.bodyAttributes.join(' ') : '') +
">" +
message +
"</soap:Body>" +
"</soap:Envelope>";
You could go into soap\lib\client.js to the line 186 and modify the envelope syntaxis so it is compliant with soap 1.2:
//modify this with the envelope used by soap1.2:
xml = "<soap:Envelope " +
"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
'xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
'xmlns:ns2="http://xml.apache.org/xml-soap"' +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
encoding +
this.wsdl.xmlnsInEnvelope + '>' +
//until here
((self.soapHeaders || self.security) ?
(
"<soap:Header>" +
(self.soapHeaders ? self.soapHeaders.join("\n") : "") +
(self.security ? self.security.toXML() : "") +
"</soap:Header>"
)
:
''
) +
"<soap:Body" +
(self.bodyAttributes ? self.bodyAttributes.join(' ') : '') +
">" +
message +
"</soap:Body>" +
"</soap:Envelope>";

Resources