Problems getting Iron Router to work on my project - meteor

I'm trying to create a quiz app on Meteor and have had trouble setting up Iron Router forever. I'll try to give a visual:
This is the front page:
Image 1
When a user clicks on the button shown above, I want the first question to show up, whose contents are filled from MongoDB.
Image 2
This is what my router looks like ("question" is the name of the question template, as seen in image 2):
Router.route("/quiz/:_id", {
name: "question",
data: function(){
return Quiz.findOne(this.params._id);}
});
Now, in order for me to get from image 1 to image 2, I have to use a mongo object _id in the html file.
<template name="main">
<div class="jumbotron">
<h2>
Welcome to Simple Meteor Quiz app!
</h2>
<p>
To try it out, simply click "start" below!
</p>
<p>
<a class="btn btn-primary btn-large" href="/quiz/cieLkdzvGZPwrnZYE">Start</a>
</p>
</div>
</template>
When I click "Next Question" on image 2 to go onto the 2nd question, it doesn't work. I don't know how to make this process dynamic.
The way it looks to me right now is that I physically have to create a new route for every single question, which would look really ugly really quickly.
Any way to help implement Iron Router in this scenario? I read Discover Meteor and thought I fully understood how Iron Router works, but the more I try to fix this, the more I get confused.
Edit:
To solve my dilemma, I simple created a helper function which I could place behind the /quiz/ in the main template to lead me to the quiz question, based on a suggestion by Michel Floyd.
So the helper ends up looking like this:
Template.main.helpers({
nextQuestion: function(){
queue = Quiz.find().fetch();
return queue[0]._id;
}
});
Then attached to the URL like this:
<a class="btn btn-primary btn-large" href="/quiz/{{nextQuestion}}">Start</a>
Basically just spit out the first _id of first item in the array by making the collection an array via find().fetch(). Will probably randomize the _id at a later time.

You need a way for each template to know what the next question is. For example you can add a nextQuestionId key to your Quiz object. Then your template can be:
<template name="main">
<div class="jumbotron">
<h2>
Welcome to Simple Meteor Quiz app!
</h2>
<p>
To try it out, simply click "start" below!
</p>
<p>
<a class="btn btn-primary btn-large" href="/quiz/{{nextQuestionId}}">
Start
</a>
</p>
</div>
</template>

Related

add button is missing for Content:Toolbar

The add button that appears over the 2sxc items is missing all of a sudden. It was there a couple days agao but now when I log into any portal in my DNN instance the "+" or add button is missing
here is a screen shot:
As you can see, the change layout and edit buttons are there. Not sure why the add button disappeared.
This is true for apps that I import from the 2sxc.org website as well. So I know its not just my template becasue it also happens on all the apps I have created which use different templates.
But to be thorough, here is my template code, its token based:
<div class="kr-gallery animation">
<p>Hover or touch image and click brush icon for more details</p>
<div class="isotope_grid isotope_grid2">
<div class="isotope_main animation" data-min-width="230">
<repeat repeat="Content in Data:Default">
<div class="isotope_item kr-gallery-item sc-element">[Content:Toolbar]
<div class="photo"><a href="[Tab:FullUrl]/details/[Content:EntityId]"> <img alt="" src="[Content:Image]?h=500" />
<span class="fa fa-paint-brush"></span></a>
</div>
</div>
</repeat>
</div>
</div>
</div>
Any idea why this is?
UPDATE:
Here is my visual query:
SOLUTION:
Based on answer, I switched to razor because I am using a custom query. Here is my simple template code now:
#* this will show an "add" button if the current user is an editor *#
#Edit.Toolbar(actions: "new", contentType: "Image")
#{
// get all images as delived from the standard query
var images = AsDynamic(Data["Default"]);
}
<div class="kr-gallery animation">
<p>Hover or touch image and click brush icon for more details</p>
<div class="isotope_grid isotope_grid2">
<div class="isotope_main animation" data-min-width="230">
#foreach(var img in images)
{
<div class="isotope_item kr-gallery-item sc-element">#img.Toolbar
<div class="photo"><a href="#Link.To(parameters: "details=" + img.EntityId)"> <img alt="#img.Title" src="#img.Image?h=500" />
<span class="fa fa-paint-brush"></span></a>
</div>
</div>
}
</div>
</div>
</div>
The missing + is by design, because editors are used to the + adding an item right after the previous one. This behavior cannot be guaranteed with a query, as the order of things is determined by the query. It is even possible, that adding an item will not show up, if a query-parameter hides that item.
So the design pattern is to provide a separate + button. The easiest way is in razor, I believe the code is something like
#Edit.Toolbar(actions: "new", contentType: "your-content-type-name")
In Tokens it's a bit more messy, and you cannot conditionally check if a user has edit-permissions.
So I recommend you go the edit.toolbar way
You can also find an example of this in the blog app: http://2sxc.org/en/apps/app/dnn-blog-app-for-dnn-dotnetnuke
I could be wrong but did you recently experiment with the visual query designer? Because this could be the cause.
The most common reason is when you use a pipeline (visual query) to deliver data to a template, which is not assigned to this instance. Reason is that "add" in a instance-list of items add it to a specific position (like right after the first one). This isn't the same when you use data like a data base - as there is no sorting in that scenario. So if this is the cause, I'll help you more.

Simple search functionality in Meteor using form input

So I'm trying to implement a very simple search functionality in my Meteor app. It's a very simple medical dictionary app, so I have only one collection which contains all the terms along with their respective definitions, pronunciations, etc. My goal is for a user to input their search query using a form input, and display the relevant search results (after hitting submit, after keyup or keydown events, doesn't really matter for now; this is just a prototype). Here's what I have so far.
Search Bar (part of a template called header.html)
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<input type="text" id="search" name="search" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
Event Handler (called header.js)
Template.header.events({
'submit form': function(e) {
e.preventDefault();
var query = $(e.target).find('[name=search]').val();
// Log the query for testing
console.log(query);
//Log the object that is returned for testing
console.log(Dictionary.find({english: query}).fetch());
var result = Dictionary.find({english: query}).fetch();
}
});
List of Results (This is the part that doesn't work, in a template called itemsList.html)
<template name="itemsList">
<div class="items">
{{#each dictionary}}
<ul>
<!-- itemPage just refers to the page individual items -->
<li>{{english}}</li>
</ul>
{{/each}}
</div>
</template>
In this case {{english}} refers to the piece of data in the collection I would like to search for (the english word in the collection Dictionary).
So, now that I've got all that out of the way, my question is: what do I do from here? In header.js, the result from console.log(Dictionary.find({english: query}).fetch()); is/are the object(s) I'm looking for, so basically, what must I do to send that object/those objects to my itemsList.html template so I can iterate over it with a cursor?
I think I've been working at this too long, because I'm sure the solution is something really simple. Any help is appreciated, and if my approach is all wrong (I've seen a lot of people using sessions when searching for things), please let me know what I should do better. Also, I'm using iron-router and have autopublish turned off, so if changes need to made to either of those things please let me know that as well. Thanks!
Just save your search string in a session and subscribe using the session as an argument if it exists, that way you can dynamically subscribe to the data that you need to populate your template

Handlebars block helper "if" doesn't work

I'm making a movie search based on data I'm getting from rotten tomatoes api. I'm using handlebars.js. So far I've got this template and it works just fine.
<div class="info">
<h3>{{title}}</h3>
<span> Year: {{year}} </span>
<span> Studio:{{studio}} </span>
<span> Synopsis:{{synopsis}} <span>
</div>
However, some of of movies don't have a studio provided so I'd like to make that in this case no "Studio:" would be printed. This is my code to do so:
{{#if studio}}
<span> Studio:{{studio}} </span>
{{/if}}
I've copied it from example provided on handebars.js page. Still it doesn't work. Could anyone explain me what I'm missing? I suppose there is no need to use Handlebars.registerHelper since I'm using this simple if statement. Or is it?
see this jsFiddle. You should not have any issue with that.
From documentation.
You can use the if helper to conditionally render a block. If its
argument returns false, undefined, null, "" or [] (a "falsy" value),
Handlebars will not render the block.
So check your 'studio' value.
Code that i have fiddled.
HTML:
<p>{{name1}}</p>
{{#if name2}}
<p>{{name2}}</p>
{{/if}}
<p>End</p>
js:
this.$el.html(temp({name1: 'stack'}));

Understanding Two-Way Data-Binding in AngularJS

I'm new to AngularJS. A long time I tried to abuse it the way I've always used Javascript-Frameworks like JQuery or Mootools. Now I understood that it's not gonna work like that anymore... But I've come across some big problems since I always generate my HTML-output with a CMS.
So it's pretty static, when it first comes out... Small example:
<ul>
<li>foo <span>delete</span></li>
<li>bar <span>delete</span></li>
<li>blub <span>delete</span></li>
</ul>
Now I thought, that Two-Way Databinding means I can generate the View with help of the Angular Scope and Controller, but also can generate Models by the View.
I may got something confused there... So here's my question. Is there any way to initiate Models from static HTML-output from a CMS?
I tried something like this...
<ul ng-controller="Ctrl">
<li ng-init="item[0].name=foo">{{item[0].name}} <span ng-click="remove(0)">delete</span></li>
<li ng-init="item[1].name=bar">{{item[1].name}} <span ng-click="remove(1)">delete</span></li>
<li ng-init="item[2].name=blub">{{item[2].name}} <span ng-click="remove(2)">delete</span></li>
</ul>
And in my controller I wrote a delete function. But when it did delete, it did only delete the name... the span-button was still there
It did work though when I defined my data as an javascript-array and did the whole output via Angular with ng-repeat... like this:
<ul ng-repeat="it in item">
<li>{{it.name}} <span ng-click="remove($index)">delete</span></li>
</ul>
I hope I made a point here and everyone get's my dificulty and problems? Can anyone tell me if what I was trying there is possible at all?
This is a common issue people have adjusting to Angular and other frameworks like it.
You don't need your server to render the HTML for you anymore. All you need to do is set up the template, and load the proper data into the scope.
<ul ng-controller="Ctrl" ng-init="getMyItems()">
<li ng-repeat="item in items">{{item.name}} <a ng-click="remove($index)">delete</a></li>
</ul>
And in your controller you'd do something like this
app.controller('Ctrl', function($scope, $http) {
$scope.items = [];
$scope.getMyItems = function(){
$http.get('/my/json/stuff/url').success(function(data) {
$scope.items = data;
$scope.$apply();
});
};
});
Now I know you're probably thinking "but I don't want to make a seperate request to get my JSON. And that's fine (probably irrelevant, but fine)... All you need to do is stick it into a global variable and retrieve it with $window instead.
Let's talk code. Here is real time app which shows profile pictures which is bind to data from MySQL. When anything changes in MySQL ( model ) view (HTML) will be updated.
app.controller('two_way_control',function($scope,$http,$interval){
load_pictures();
$interval(function(){
load_pictures();
},300);
function load_pictures(){
$http.get('http://localhost:3000/load').success(function(data){
$scope.profile_pictures=data;
});
};
Here is HTML
<div id="container" ng-app='two_way' ng-controller='two_way_control'>
<div class="row" ng-repeat="data in profile_pictures">
<div class=".col-sm-6 .col-md-5 .col-lg-6">
<h4>User Say's</h4><hr>
<p>
This is a Demo feed. It is developed to demonstrate Two way data binding.
</p>
<img src="{{data.profile_picture}}">
</div>
</div>
</div>
Learn more :
http://codeforgeek.com/2014/09/two-way-data-binding-angularjs/
Hope it helps !

How to use Excel VBA to click a web CSS button?

I am creating a macro with Excel VBA that will submit an entry into an online database using information from an Excel spreadsheet. During this entry process, the macro needs to click on a CSS button. It isn't a form button, does not have an input type, no name, no id, and no source image except for a background image. I think my only hopes are either to click on the button based on the div class. Can anyone help?
The button is here :
<div class="v-captiontext">
By Ankit
</div>
<td class="v-tabsheet-tabitemcell v-tabsheet-tabitemcell-selected" style="">
<div class="v- tabsheet-tabitem v-tabsheet-tabitem-selected">
<div class="v-caption" style="width: 39px;">
<div class="v-captiontext">
By LOT</div>
<div class="v-caption-clearelem">
</div>
</div>
</div>
</td>
Thanks to Remou's answer on this thread: Use VBA code to click on a button on webpage
Here is a first stab in your issue, you could try this:
Set tags = wb.Document.GetElementsByTagname("div")
For Each tagx In tags
If tagx.class = "v-caption-clearelem" Then
tagx.Click
End If
Next
Yet, I've never tried to use the Click method on a div.

Resources