2015年08月

Meteor js cursor hasNext() and next()?

problem

I have a potentially big find query which has to stop once my server "javascript" conditions are met, for instance my server already have documents results to figure out a solution.



The idea here is to iterate a cursor from mongo, hitting mongo "on demand", kinda "streaming", so neither my server or mongo has to fetch all results at once.



expected behaviour


query and get cursor ( r = Collection.find() )
check for next ( r.hasNext() )
fetch next ( r.next() )
once my requirements are met, stop ( delete r )


example code

Collection.find().forEach(function(doc) {
doc = do_my_business( doc );
if (doc.found) {
// hey mister cursor, go home and die! don't touch my mongo anymore!
return false;
}
});


the real problem

I created another Question which is actually how i end up here:
Mongodb find near until $maxDistance or at least X records?



Answers

A meteor cursor isn't a mongo cursor. Meteor cursors don't have hasNext or next. So, this is really just a question about forEach, which is the same as the ES5 forEach. So here's what you can do:



1.Fetch all the docs into an array & run a for loop over it, break when criteria is met.



2.Turn a flag when the criteria is met & check at the beginning of the function:



if (isHappy) return;
doc = do_my_business( doc );
if (doc.found) isHappy = true;


3. Use a try catch loop:



foo = {};
try {
Collection.find().forEach(function(doc) {
doc = do_my_business( doc );
if (doc.found) {
throw foo;
}
});
} catch(e) {
if (e !== foo) {
throw e;
}
}


4.Forget the forEach garbage & use a $where with a findOne + (do a find().limit(1).explain() so you can see that it won't touch every document.)



5.Store something in your database so you don't have to use javascript on the cursor. Repeating a javascript loop over every doc on the server should be avoided like the plague. Storage is cheap. processing, not so much.





how to implement progress bar using angular js for processing multiple request?

I have created multiple orders and now I have to confirm all these
orders but until and unless all orders gets confirmed I have to show
progress bar and have to show the status of the ordered confirmed



i.e. suppose i have confirmed 10 orders then 1/10 then 2/10 then 3/10
...10/10 status of orders getting confirmed at background.



below i have one example but which doesn't meets to requirement ..





angular.module("app", []) .controller("main", ['$scope',
function($scope) {
$scope.value = 10
$scope.items = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100] }]) .directive('progressbar', [function() {
return {
restrict: 'A',
scope: {
'progress': '=progressbar'
},
controller: function($scope, $element, $attrs) {
$element.progressbar({
value: $scope.progress
})

$scope.$watch(function() {
$element.progressbar({value: $scope.progress})
})
}
} }])


Answers

I have once used below template:



You can use it:



http://victorbjelkholm.github.io/ngProgress/





SMTP error code : 551

com.sun.mail.smtp.SMTPSendFailedException: 551 This mail server requires authentication before sending mail from a locally hosted domain. Please reconfigure your mail client to authenticate before sending mail.



I am getting the error above when I integrate with the my Java Application running on a Tomcat server



Sending successfully if I use the same properties in separate class with main and run as java application



Why I am not getting this? Thank you in advance.



Answers

Finally got answer
Here we go: before it was like
`Properties props = new Properties();
props.put("mail.smtp.host", "webmail.technobbyte.com");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.starttls.enable", true);
props.put("mail.smtp.auth", true);`


now i changed to:
`Properties props = new Properties();
props.setProperty("mail.smtp.host", "webmail.technobbyte.com");
props.setProperty("mail.smtp.port", "25");
props.setProperty("mail.smtp.starttls.enable", "true");
props.setProperty("mail.smtp.auth", "true");`




How to make nodes in sankey diagram clickable using d3.js library

Code Snippet :
We are using d3.js for this.
Sankey diagrams is made up of nodes and links.
Here the data comes from json file.
So how to make all the nodes clickable.
Which methods can we use with the rectangles so that we can make the nodes clickable.



<script>

var margin = {top: 1, right: 1, bottom: 6, left: 1},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;

var formatNumber = d3.format(",.0f"), //decimal places
format = function(d) { return formatNumber(d) + " TWh"; },
color = d3.scale.category20();

var svg = d3.select("#chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");

var sankey = d3.sankey()
.nodeWidth(15)
.nodePadding(10)
.size([width, height]);

var path = sankey.link();

//d3.json("energy.json", function(energy) {


d3.json("numbers-subset.json", function(energy) {



sankey
.nodes(energy.nodes)
.links(energy.links)
.layout(32);

var link = svg.append("g").selectAll(".link")
.data(energy.links)
.enter().append("path")
.attr("class", "link")
.attr("d", path)
.style("stroke-width", function(d) { return Math.max(1, d.dy); })
.sort(function(a, b) { return b.dy - a.dy; });


link.append("title")
.text(function(d) { return d.source.name + " → " + d.target.name + "\n" + format(d.value); });


var node = svg.append("g").selectAll(".node")
.data(energy.nodes)
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })
.call(d3.behavior.drag()
.origin(function(d) { return d; })
.on("dragstart", function() { this.parentNode.appendChild(this); })
.on("drag", dragmove));

node.append("rect")
.attr("height", function(d) { return d.dy; })
.attr("width", sankey.nodeWidth())
.style("fill", function(d) { return d.color = color(d.name.split("|")[0]); })
.style("stroke", function(d) { return d3.rgb(d.color).darker(2); })
.append("title")
.text(function(d) { return d.name + "\n" + format(d.value); });

node.append("text")
.attr("x", -6)
.attr("y", function(d) { return d.dy / 2; })
.attr("dy", ".35em")
.attr("text-anchor", "end")
.attr("transform", null)
.text(function(d) { return d.name; })
.filter(function(d) { return d.x < width / 2; })
.attr("x", 6 + sankey.nodeWidth())
.attr("text-anchor", "start");

function dragmove(d) {
d3.select(this).attr("transform", "translate(" + d.x + "," + (d.y = Math.max(0, Math.min(height - d.dy, d3.event.y))) + ")");
sankey.relayout();
link.attr("d", path);
}



});

</script>




Creating a new YII Default page and redirect to it

I am new to YII framework and I am trying to make an application that works like following, when I visit my index it redirects me to this a page called management, I have to create a new page with some list options and I have to redirect to that, but I am not quite sure how to do it with YII.



here is my original action Index:



public function actionIndex()
{
$this->layout = '//layouts/main';
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
if (Yii::app()->user->isGuest)
{
$this->redirect(Yii::app()->createUrl('site/login'));
}
else
{
$this->redirect(array('management/list'));
//$this->redirect(array('site/HomePage'));
//$this->render('index');
}
}


it redirects me to management/list, what I have to do is to redirect to a new page instead of management called home page and in the new page there is an option for management which by clicking on that it takes you to the correct page.



this is my management folder:





this is my view:





what I did is:
inside site I created a page called homepage.php with the following body:



<div class="static_page">
<?php
/* @var $this SiteController */

$this->pageTitle=Yii::app()->name;
?>

<h2>Welcome to <?php echo CHtml::encode(Yii::app()->name); ?></h2>

<p>Congratulations! You have successfully created your Yii application.</p>

<p>You may change the content of this page by modifying the following two files:</p>
<ul>
<li>View file: <code><?php echo __FILE__; ?></code></li>
<li>Layout file: <code><?php echo $this->getLayoutFile('main'); ?></code></li>
</ul>

<p>For more details on how to further develop this application, please read
the <a href="http://www.yiiframework.com/doc/">documentation</a>.
Feel free to ask in the <a href="http://www.yiiframework.com/forum/">forum</a>,
should you have any questions.</p>

</div>


then I changed my actionIndex(), and added the following to the else part:



$this->redirect(array('site/HomePage'));


but when I run that I saw this errors:



The system is unable to find the requested action "HomePage".

/vagrant/vendor/yiisoft/yii/framework/web/CController.php(483)

471 return $this->createActionFromMap($map,$actionID,$requestActionID,$config);
472 }
473
474 /**
475 * Handles the request whose action is not recognized.
476 * This method is invoked when the controller cannot find the requested action.
477 * The default implementation simply throws an exception.
478 * @param string $actionID the missing action name
479 * @throws CHttpException whenever this method is invoked
480 */
481 public function missingAction($actionID)
482 {
483 throw new CHttpException(404,Yii::t('yii','The system is unable to find the requested action "{action}".',
484 array('{action}'=>$actionID==''?$this->defaultAction:$actionID)));
485 }
486
487 /**
488 * @return CAction the action currently being executed, null if no active action.
489 */
490 public function getAction()
491 {
492 return $this->_action;
493 }
494
495 /**


// specify how many levels of call stack should be shown in each log message
15 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
16
17 require_once($yii);
18
19 Yii::createWebApplication($config)->run();
20
21 echo 'temporary add records to the rbac tables';
22
23 //TODO create temporarily the RBAC settings
24 $auth=Yii::app()->authManager;


how can I add the new homepage.php instead of management page??



EDITED NEW VERSION:
So this is how I made it:
I created a new page called homepage.php withing my views\site. then I open the homepage and added the following:



<div class="static_page">
<?php
/* @var $this SiteController */

$this->pageTitle=Yii::app()->name;
?>

<h2>Welcome to <?php echo CHtml::encode(Yii::app()->name); ?></h2>

<p>You may change the page by clicking on the following pages.</p>
<ul>
<li>For Dossier Management click on: <code><a href="dossiermanagement/list"> dossiers </a></code></li>
<li>For Management Information click on: <code> Management Info</code></li>
<li>For System Management click on: <code> systemBeheer</code></li>
</ul>

<!-- <p>For more details on how to further develop this application, please read
the <a href="http://www.yiiframework.com/doc/">documentation</a>.
Feel free to ask in the <a href="http://www.yiiframework.com/forum/">forum</a>,
should you have any questions.</p> -->

</div>


and also changed my actionIndex to $this->render('HomePage');



it works but now my redirection doesnt work:



for example this part is totally incorrect



<li>For Dossier Management click on: <code><a href="dossiermanagement/list"> dossiers </a></code></li>
<li>For Management Information click on: <code> Management Info</code></li>


how can I solve this one?



Answers

Instead of redirecting to anywhere else please load a view





$this->render('yourview/index',array(
'dataProvider'=>$dataProvider,
'list_arr'=>$this->list
));





Make a folder named yourview inside the view folder. Even if you want to redirect it to management controller, please make sure that you have the controller in name.



Answers

Please write this code in place of " $this->redirect(array('management/list'));"


$list=array('David','Tristup');
$selected_value='';
$this->render('yourview/index',
array('list_arr'=>$list,'selected_value'=>$selected_value
));





Now you write this code in yourview/index.php. Here make_id is field name change it accordingly.





 <?php       
//echo $selected_value;
echo CHtml::dropDownList('make_id',$selected_value,$list_arr,array('empty' => 'Select a Make','class'=>'drop_class'));
?>





Now you can see a dropdown with our name. Please let me know if you have any questions.





↑このページのトップヘ