How to use react render with AngularJs and ngReact - angularjs

I am trying to use StormReact library in angularJs app.
In below code i have created class inside the library which is bundled using webpack as single bundle.js
window.HelloStormReact = React.createClass({
render: function() {
var Engine = require("../src/Engine")();
var model = {links:[],nodes: []};
function generateSet(model,offsetX,offsetY){
var node1 = Engine.UID();
var node2 = Engine.UID();
var node3 = Engine.UID();
var node4 = Engine.UID();
var node5 = Engine.UID();
model.links = model.links.concat([
{
id: Engine.UID(),
source: node1,
sourcePort: 'out',
target: node2,
targetPort: 'in',
},
{
id: Engine.UID(),
source: node1,
sourcePort: 'out',
target: node3,
targetPort: 'in'
},
{
id: Engine.UID(),
source: node2,
sourcePort: 'out',
target: node4,
targetPort: 'in'
},
{
id: Engine.UID(),
source: node4,
sourcePort: 'out',
target: node5,
targetPort: 'in2'
},
{
id: Engine.UID(),
source: node2,
sourcePort: 'out',
target: node5,
targetPort: 'in'
}
]);
model.nodes = model.nodes.concat([
{
id:node1,
type: 'action',
data: {
name: "Create User",
outVariables: ['out']
},
x:50 + offsetX,
y:50 + offsetY
},
{
id:node2,
type: 'action',
data: {
name: "Add Card to User",
inVariables: ['in','in 2'],
outVariables: ['out']
},
x:250 +offsetX,
y:50 + offsetY
},
{
id:node3,
type: 'action',
data: {
color: 'rgb(0,192,255)',
name: "Remove User",
inVariables: ['in']
},
x:250 + offsetX,
y:150 + offsetY
},
{
id:node4,
type: 'action',
data: {
color: 'rgb(0,192,255)',
name: "Remove User",
inVariables: ['in'],
outVariables: ['out']
},
x:500 + offsetX,
y:150 + offsetY
},
{
id:node5,
type: 'action',
data: {
color: 'rgb(192,255,0)',
name: "Complex Action 2",
inVariables: ['in','in2','in3']
},
x:800 + offsetX,
y:100 + offsetY
},
]);
}
generateSet(model,0,0);
Engine.registerNodeFactory({
type:'action',
generateModel: function(model){
return React.createElement(BasicNodeWidget,{
removeAction: function(){
Engine.removeNode(model);
},
color: model.data.color,
node: model,
name: model.data.name,
inPorts: model.data.inVariables,
outPorts: model.data.outVariables
});
}
});
Engine.loadModel(model);
return ReactDOM.render(React.createElement(Canvas,{engine: Engine}), document.getElementById("howdy"));;
}
});
In index.html, I used that class created in Storm react library module.
<div class="content">
<react-component name="HelloStormReact" />
<div class="storm-flow-canvas" id="howdy">
</div>
</div>
I am getting the error
Constructor.render(): A valid React element (or null) must be returned.
You may have returned undefined, an array or some other invalid object.
Help me to write correct render object to return.

Since HelloStormReact is just a component, in its render function, you don't need to render it again, just return React.createElement(Canvas,{engine: Engine}) in the render function.

Related

Display highcharts graph with a lot of data in angularjs

I have an angularjs application and I use highcharts-ng to display some graphs. I got the data from an http request and I modify the data to display them in the graph.
If I receive just a just some data, it's ok, it works but when I receive a lot of data, the highcharts component take a long time to display the data. And in this time the browser in freezed.
In my controller, I have:
widgetCtrl.chartDataLine = {
chart: {
type: 'spline',
zoomType: 'xy'
},
title: {
text: 'Power Consumption'
},
xAxis: {
type: 'datetime',
title: {
text: 'Date time'
}
},
yAxis: {
title: {
text: 'Power (W)'
},
min: 0
},
options: {
exporting: {
enabled: true,
allowHTML: true,
buttons: {
contextButton: {
menuItems: null,
onclick: function () {
this.exportChart();
}
}
}
}
},
plotOptions:{
series:{
turboThreshold:60000 // larger threshold or set to 0 to disable
}
},
series: []
};
I call the data like that:
var getMetrics = function (searchText) {
var param = {
target: searchText
};
xcsDatasource.get('beo').callAction('getPowerMetrics', param.target, widgetCtrl.pickerFrom.date, widgetCtrl.pickerTo.date).then(
function (result) {
widgetCtrl.metrics = result;
widgetCtrl.metricsAsString = JSON.stringify(result);
var t = getChartData(result);
widgetCtrl.chartDataLine.series = angular.copy(t);
console.log(widgetCtrl.chartDataLine);
//widgetCtrl.chartDataArea.series = getChartData(result);
},
function () {
widgetCtrl.metrics = {};
widgetCtrl.metricsAsString = '';
}
);
};
And this is my html:
<div ng-if="config.linechart" class="graph-container col-sm-12">
<highchart id="chart1" config="pwrDashboardViewCtrl.chartDataLine"></highchart>
</div>
Do you have an idea how I can do to continue to load the grapph without freezing the browser ?

Data binding and promise in AngularJS

I have the following factory I use to return a http promise with the user data from the server
(function () {
angular.module('BlurAdmin.theme')
.factory('getData', function($http){
var service = {};
service.objData = null;
service.savePromise = function(objData) {
service.objData = objData;
}
service.getSavedPromise = function() {
return service.objData;
}
service.getDataFromServer = function() {
var promise = $http.get('/admin/data');
service.savePromise(promise);
}
return service;
});
})();
I launch this http request at the run method of the app.
In another controller I have done the following
getData.getSavedPromise().then(function (data) {
$scope.newVisits = data.data.data.newVisitors;
});
var pieColor = baUtil.hexToRGB(baConfig.colors.defaultText, 0.2);
$scope.charts = [{
color: pieColor,
description: 'New Visits',
stats: '$ ' + $scope.newVisits,
icon: 'person',
}, {
color: pieColor,
description: 'Purchases',
stats: '$ 89,745',
icon: 'money',
}, {
color: pieColor,
description: 'Active Users',
stats: '178,391',
icon: 'face',
}, {
color: pieColor,
description: 'Returned',
stats: '32,592',
icon: 'refresh',
}
];
The Data structure is a little messed up and I need to fix it but that is beside the point.
I use for example
<div class="description-stats">{{ ::chart.stats }}</div>
In the html.
The issue is that the data is not being bind and I see undefined in the page.
What am I doing wrong?

UI Bootstrap Typeahead is not displaying the values returned async

I am trying to do an autocomplete search using UI Bootstrap Typeahead to select a data from a database.
My service returns data in my response, but data are not listed in the component.
When I put a breakpoint in the component code , the list is there and when I continue to debug the list is displayed, but if it runs without breakpoints , the list is not displayed.
HTML
<input id="inputInstalation"
ng-model="profile.instalation"
typeahead-editable="false"
typeahead="installation as installation.name for installation in searchInstallation($viewValue)"
typeahead-input-formatter="formatLabel($model)"
ng-required="true">
Controller
$scope.searchInstallation = function(text){
return $http.get('/api/installations/name/' + text).then(function(response){
return response.data;
});
};
$scope.formatLabel = function(model){
return model ? model.name : "";
};
API NodeJS - DB Mongo
exports.findByName = function(req, res){
var connection = getConnection();
var Installation = getInstallationModel(connection);
Installation.find({name: new RegExp(req.params.name, "i")}, function (err, result) {
connection.close();
if(err) throw err;
res.json(result);
});
};
Response
[{ _id: 5525662b74100eb40f13ce00,
name: 'test 2',
description: 'Gdoc 02.02.00-00',
__v: 0,
services:
[ { name: 'Alfresco',
context: '/alfresco',
parameterURL: 'prmGdocServiceUrl',
_id: 5525662b74100eb40f13ce03 },
{ name: 'ri-rest',
context: '/iserver',
parameterURL: 'prmUrlIntegrationServer',
_id: 5525662b74100eb40f13ce02 },
{ name: 'ldap',
parameterURL: 'prmLdapUrl',
parameterUser: 'prmLdapPrincipal',
parameterPassword: 'prmLdapPassword',
_id: 5525662b74100eb40f13ce01 } ],
tables:
[ { _id: 5525662b74100eb40f13ce06, name: 'esegsistema' },
{ _id: 5525662b74100eb40f13ce05, name: 'esegusuario' },
{ _id: 5525662b74100eb40f13ce04, name: 'XPTO' } ],
parameters:
[ { name: 'prmUrlBaseServidorHTTP',
systemCode: '314',
_id: 5525662b74100eb40f13ce0e },
{ name: 'prmTamanhoMaximoArquivo',
systemCode: '314',
_id: 5525662b74100eb40f13ce0d },
{ name: 'prmGdocServiceUrl',
systemCode: '314',
_id: 5525662b74100eb40f13ce0c },
{ name: 'prmLdapUrl',
systemCode: '314',
_id: 5525662b74100eb40f13ce0b },
{ name: 'prmLdapPrincipal',
systemCode: '314',
_id: 5525662b74100eb40f13ce0a },
{ name: 'prmLdapPassword',
systemCode: '314',
_id: 5525662b74100eb40f13ce09 },
{ name: 'prmDomainSufix',
systemCode: '314',
_id: 5525662b74100eb40f13ce08 },
{ name: 'xxxxx',
systemCode: '314',
_id: 5525662b74100eb40f13ce07 } ] }]
I found the problem, I'm using the https://github.com/McNull/angular-block-ui and it conflicts with the component.
Solution : I created a requestFilter from angular blockui to don't block requests sent the component to API .

Unable to use variable in angularjs ng-include

i build a list using .factory and in every elemt have a arrtibute which store page which needed to be include when clicked on any list item
.
i am unable to use this attribute dynamiclly ..plzz help,,,,
i am using ionic framework
////////////// service.js ////////////////
angular.module('starter.services', [])
.factory('Ctopic', function() {
// Might use a resource here that returns a JSON array
// Some fake testing data
var chats = [ { title: 'Arrays', id:11 ,desc: "'ctopic/Union.html'"},
{ title: 'Bit Field Declaration', id:12 },
{ title: 'C Pointers', id: 13 },
{ title: 'Conditional Statements', id: 14 },
{ title: 'File IO', id: 15 },
{ title: 'Function', id: 16 },
{ title: 'Input & Output', id: 17 },
{ title: 'Loops', id: 18 },
{ title: 'Preprocessor Operators', id: 19 },
{ title: 'Preprocessor', id: 20 },
{ title: 'String', id: 21 },
{ title: 'Structures', id: 22 },
{ title: 'Typedef', id: 23 },
{ title: 'Union', id: 24 }];
return {
all: function() {
return chats;
},
remove: function(chat) {
chats.splice(chats.indexOf(chat), 1);
},
get: function(chatId) {
for (var i = 0; i < chats.length; i++) {
if (chats[i].id === parseInt(chatId)) {
return chats[i];
}
}
return null;
}
};
});
/////// html page /////////
<ion-view view-title="{{chat.title}}">
<ion-content class="padding">
{{chat.id}}
{{chat.desc}}
<div ng-include="{{chat.desc}}"></div>
</ion-content>
</ion-view>
Don't use the brackets for ng-include:
<div ng-include="chat.desc"></div>

Extjs localstore method set

I am not able to update record in localStorage by id. I get the exception :
Uncaught TypeError: Cannot read property 'type' of undefined WebStorage.js:391Ext.define.getIds WebStorage.js:391Ext.define.update WebStorage.js:190Ext.define.runOperation Batch.js?_dc=1423751003307:251Ext.define.start Batch.js?_dc=1423751003307:178Ext.define.batch Proxy.js?_dc=1423751002203:456Ext.define.sync AbstractStore.js?_dc=1423751002173:810Ext.define.afterEdit AbstractStore.js?_dc=1423751002173:906Ext.define.callStore Model.js?_dc=1423751003310:1814Ext.define.afterEdit Model.js?_dc=1423751003310:1773Ext.define.set Model.js?_dc=1423751003310:1175(anonymous function) Main.js?_dc=1423751002786:26(anonymous function) VM3763:6wrap
My model is simple:
Ext.define('AM.model.Points', {
extend: 'Ext.data.Model',
idProperty: {
name: 'UUID',
type: String,
isUnique: true
},
fields: [
{
name: 'NO',
type: "string"
},
{
name: 'Y',
type: "int"
},
{
name: 'ROW',
type: 'int'
},
{
name: 'SEAT',
type: 'string'
},
{
name: 'PROCEEDED',
type: 'int'
},
{
name: 'X',
type: "int"
},
{
name: "CurrentPlace",
type: "int",
defaultValue: 0
}
],
});
My controller class init function:
init: function(){
// метод getStore контроллера возвращает экземпляр хранилища,
// если он уже создан - или создаёт его
console.log('Main controller init function()');
var changingImage = Ext.create('Ext.Img', {
src: '/is-bin/intershop.static/WFS/EnterpriseOrg-MainChannel-Site/ProductStore/ru_RU/kzch.jpg',
renderTo: Ext.get('canv1')
});
Ext.get('canv1').on('click', function(eventObj, elRef) {
var index = Ext.StoreMgr.lookup("LocalStore").findExact('UUID',AM.util.Utilities.CurrentPlace);
var rec = Ext.StoreMgr.lookup("LocalStore").getAt(index);
console.log('Ext.StoreMgr.lookup("LocalStore") ' + Ext.StoreMgr.lookup("LocalStore"));
console.log('index' + index);
console.log('rec' + rec);
var uuid = rec.get('UUID');
console.log('uuid is: '+uuid);
**rec.set('X', window.event.offsetX);**
});
The logic is that I click on canvas and pass X coordinate of the click to method on click. I retrieve model from store by previously saved id to update it. But I cant update record. What should be done? Version 4.2.1 Thanx in advance.

Resources