Connecting to the internet using Concept N - sony-future-lab-n

I can’t connect to the internet using Concept N. I am using jquery with a simple $.get, but it is just not working. Can someone help me with this?

You actually need to use the da.getXHr() function to access external web services. Here is an example of how to access rss data using jquery. First thing to do is download jquery and include it in your index.html file:
<script type="text/javascript" src="app/jquery.min.js"></script>
Now use this code snippet to access a rss url with jquery. Be sure to replace the line "** Enter-rss-2.0-url-here **" with your own rss url
/*
* Copyright 2016 Sony Corporation
*/
var title;
var description;
/**
* The callback to prepare a segment for play.
* #param {string} trigger The trigger type of a segment.
* #param {object} args The input arguments.
*/
da.segment.onpreprocess = function (trigger, args) {
console.log('onpreprocess', { trigger: trigger, args: args });
//da.startSegment(null, null);
$.ajax({
url:"** Enter-rss-2.0-url-here **",
type: "GET",
dataType: 'xml',
xhr: function () { return da.getXhr(); },
error: function (jqXHR, textStatus, errorThrown) {
console.log('ajax error jqXHR.status[' + jqXHR.status + ']');
def.reject("failed with error "+jqXHR.status);
return;
},
success: function (data, textStatus, jqXHR) {
$(data).find("item:first").each(function() {
title = $(this).find("title").text();
description = $(this).find("description").text()
})
da.startSegment(null, null)
}
})
};
/**
* The callback to start a segment.
* #param {string} trigger The trigger type of a segment.
* #param {object} args The input arguments.
*/
da.segment.onstart = function (trigger, args) {
console.log('onstart', { trigger: trigger, args: args });
var synthesis = da.SpeechSynthesis.getInstance();
synthesis.speak("Title "+title+", Content "+description, {
onstart: function () {
console.log('speak start');
},
onend: function () {
console.log('speak onend');
da.stopSegment();
},
onerror: function (error) {
console.log('speak cancel: ' + error.messsage);
da.stopSegment();
}
});
};

Related

Documenting Object with methods and their return values in JSDoc

I have a paging controller factory, that returns a paging controller Object with a bunch of methods (for the view to interact with, especially when an end-user does an action like navigate to a different page or enter some search text). It is defined something like:
/**
* Returns a paging controller object with data
* #param {Object[]} data
* #param {string} prop the property containing that data. If it's a function, it should be no-args.
* #param {filterFunc} filterer a callback that filters the data
*/
function pagingControllerFor(data, prop, filterer) {
let _currentPage = 0
let _filterFunc = filterer
let _stateChange = false
let _data;
const _ITEMS_PER_PAGE = 50
let _selectAllChecked = [];
/**
* Getter for all the data. Useful for debugging.
*/
function getAllData() {
if (prop) {
if (typeof data[prop] === 'function') {
return data[prop]()
}
return data[prop]
}
return data
}
/**
* Always returns fresh data for the controller
*/
function getData() {
let data = getAllData()
if (_filterFunc) {
if ((_stateChange) || (!_data)) {
_data = data.filter(_filterFunc)
_selectAllChecked = Array(Math.ceil(_data.length / _ITEMS_PER_PAGE)).fill(false)
_stateChange = false
}
return _data
}
return data
}
return {
/* a whole bunch of methods irrelevant to my use case on here */
getCurrentPageData : () => getData().slice(_currentPage * _ITEMS_PER_PAGE, (_currentPage + 1) * _ITEMS_PER_PAGE),
// get/set current "Select All" checkbox state
isCurrentSelectAllChecked : () => _selectAllChecked[_currentPage],
setCurrentSelectAllChecked : (checked) => _selectAllChecked[_currentPage] = checked
}
}
I am writing an event-binder for the "Select/Deselect All" checkboxes on the view being paginated. It is, as of the time I wrote this, defined to be:
/**
* Binds clicks on the current "Select/Deselect All" checkbox to the controller
* #param {string} modalType
* #param {{ getCurrentPageData : () => Array<{IsSelectedOnModal : boolean}>, setCurrentSelectAllChecked : () => boolean }} controller
* #param {Function} callback
*/
function bindToggleSelectAllEvent(modalType, controller, callback) {
callback = callback || bindToggleSelectAllEvent
const modalSelector = `#${modalType}-selector-modal`
$(`#toggle-all-${(modalType === ITEM) ? 'items' : 'categories'}-selected`)
.off('change')
.on('change', function() {
// get the state of this
let isChecked = $(this).prop('checked')
// change the selection state of all current items/categories in the controller to that state
controller.getCurrentPageData().forEach((data) => {
data.IsSelectedOnModal = isChecked
})
// tell the controller the new state of this "Select All" checkbox
controller.setCurrentSelectAllChecked(isChecked)
// Re-render modal?!
// TODO: implement this
})
}
VSCode knows what I'm doing, as it detects the relevant methods of controller, which I have specified.
However, JSDoc doesn't, for some reason:
ERROR: Unable to parse a tag's type expression for source file [my-project-path]\static\js\menu\edit\index.js in line 433 with tag title "param" and text "{{ getCurrentPageData : () => Array<{IsSelectedOnModal : boolean}>, setCurrentSelectAllChecked : () => boolean }} controller": Invalid type expression "{ getCurrentPageData : () => Array<{IsSelectedOnModal : boolean}>, setCurrentSelectAllChecked : () => boolean }": Expected "," or "}" but "=" found.
ERROR: Unable to parse a tag's type expression for source file [my-project-path]\static\js\menu\edit\index.js in line 439 with tag title "param" and text "{{ getCurrentPageData : () => Array<{IsSelectedOnModal : boolean}>, setCurrentSelectAllChecked : () => boolean }} controller": Invalid type expression "{ getCurrentPageData : () => Array<{IsSelectedOnModal : boolean}>, setCurrentSelectAllChecked : () => boolean }": Expected "," or "}" but "=" found.
What should I do about this?
VS Code support TypeScript types in JS Docs but the JS Doc tool only supports Closure types.
I believe that the arrow function type expressions that you are using are valid TypeScript types but cannot be understood by the JSDoc tool. Try using the function(): function type syntax instead
#param {{ getCurrentPageData : function(): Array<{IsSelectedOnModal : boolean}> }} controller

Magento 2 : Display Loader While Ajax call on Column row action?

Grid xml column:
<column name='actions' class='My\Test\Ui\Component\Listing\Columns\Feeds\AdvancedActions'>
<argument name='data' xsi:type='array'>
<item name='config' xsi:type='array'>
<item name='component' xsi:type='string'>My_Test/js/grid/columns/actions</item>
<item name='dataType' xsi:type='string'>text</item>
<item name='label' xsi:type='string' translate='true'>Actions</item>
<item name='sortOrder' xsi:type='number'>90</item>
</item>
</argument>
</column>
Actions.js
define(
[
'jquery',
'underscore',
'mageUtils',
'uiRegistry',
'Magento_Ui/js/grid/columns/actions',
'Magento_Ui/js/modal/confirm'
], function ($, _, utils, registry, Column, confirm) {
'use strict';
return Column.extend(
{
/**
* Applies specified action.
*
* #param {String} actionIndex - Actions' identifier.
* #param {Number} rowIndex - Index of a row.
* #returns {ActionsColumn} Chainable.
*/
applyAction: function (actionIndex, rowIndex) {
var action = this.getAction(rowIndex, actionIndex),
callback = this._getCallback(action);
if (action.confirm) {
this._confirm(action, callback);
} else if (action.popup) {
this._popup(action, callback);
} else {
callback();
}
return this;
},
_popup: function (action, callback) {
var popupData = action.popup;
var dataType = popupData.type;
//Start loader
var body = $('body').loader();
body.loader('show');
if (popupData.file !== undefined && popupData.file !== '') {
$.ajax(
{
url: popupData.file,
async: false,
dataType: "text",
type: 'GET',
showLoader: true, //use for display loader
success: function (data) {
popupData.message = data;
}
}
);
}
//Stop loader
body.loader('hide');
},
});
Used showLoader: true and var body = $('body').loader(); body.loader('show'); but unable to start loader while ajax request.
Need an alternative to start loader during ajax call.
I faced the same issue. In my case, I need to load the 'jquery/ui' dependency.
define(
[
'jquery',
...
'jquery/ui'
Please have a look at the below code which might help.
define([
'jquery',
'Magento_Checkout/js/model/full-screen-loader',
], function ($,fullScreenLoader
) {
//Start Loader
fullScreenLoader.startLoader();
//Your AJax COde here
//Stop Loader
fullScreenLoader.stopLoader();
});
Just add the loader dependency to the end:
define([
'jquery',
...
'loader'
]
showLoader: true and
var body = $('body'); body.loader('hide'); will start working.
Try $('body').trigger('processStart') & $('body').trigger('processStop')

How to write reusable methods in cucumber + Protractor

/* jshint -W117 */
'use strict';
var Support = require('./_support');
var $ = new Support();
var LoginPage = require('./login.page');
/**
* Collection of basic steps definitions reusable across features
*/
var basicSteps = function (page) {
//var page = new LoginPage();
this.Then(/^the title should equal "([^"]*)"$/, function (arg1, callback) {
$.expect(browser.getTitle()).to.eventually.equal(arg1).and.notify(callback);
});
this.Then(/^I should see validation message "([^"]*)"$/, function (arg1, callback) {
$.expect(LoginPage.hasErrors()).to.eventually.equal(arg1).and.notify(callback);
});
this.Then(/^the "([^"]*)" button should be disabled$/, function (arg1, callback) {
$.expect(LoginPage.buttonDisabled.isEnabled()).to.eventually.to.equal(false).and.notify(callback);;
});
};
module.exports = basicSteps;
I want to use this code to all page files to make reusable.
I have other login.page file so if I create any other page file as per the feature I should be able to reuse this code

How to categorize jQuery UI-autocomplete with YouTube's categories

I am using jQuery UI-autocomplete to get wordlist from YouTube, I used the code proposed here: How to get the wordlist from youtube search for Jquery UI autocomplete?
I wanted to know if it is possible to autocomplete from YouTube by categories, for example, category music of YouTube.
$("#q").autocomplete({
source: function(request, response){
/* Need a api key for this, so we add it: */
var apiKey = 'MYAPIKEY';
/* command */
var query = request.term;
/* youtube ajax request */
$.ajax({
url: "http://suggestqueries.google.com/complete/search?hl=en&ds=yt&client=youtube&hjson=t&cp=1&q="+query+"&key="+apiKey+"&format=5&alt=json&callback=?",
dataType: 'jsonp',
success: function(data, textStatus, request) {
response( $.map( data[1], function(item) {
return {
label: item[0],
value: item[0]
}
}));
}
});
},
/* seçilene işlem yapmak için burayı kullanabilirsin */
select: function( event, ui ) {
}
});

Sailsjs: How do I transform a POST request's body/fields for the REST API

It is awesome how sails will automatically generate a REST API for me. But, how can I add extra processing to a REST route? For example, I might have a POST /users route to create new users and it accepts a password as one of the attributes for the users model. But, I wouldn't want to store passwords as-is; rather I would want to hash passwords and salt them for better security. Is there a way to write code before the REST API handles the request so that way I can transform the input or do some kind of processing in general if need be?
You can implement beforeValidate or beforeCreate method under your user model
Check out the doc here http://www.sailsjs.org/#!/documentation/concepts/ORM/Lifecyclecallbacks.html
I use this for hash password :
/**
* User.js
*
* #description :: TODO: You might write a short summary of how this model works and what it represents here.
* #docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
attributes : {
name : 'string',
password : {
type : 'string',
required : true,
minLength : 6
},
email : {
type : 'email',
unique : true,
required : true
},
toJSON : function ()
{
var obj = this.toObject();
delete obj.password;
return obj;
}
},
beforeCreate : function (attrs, next)
{
var bcrypt = require('bcrypt');
bcrypt.genSalt(10, function (err, salt)
{
if (err)
{
return next(err);
}
bcrypt.hash(attrs.password, salt, function (err, hash)
{
if (err)
{
return next(err);
}
attrs.password = hash;
next();
});
});
}
};