Posted on

Getting in to the Programming of our Meteor Project

 

Click here to subscribe for more videos like this!

What we’re going to do next is get into the programming of this. So, I want to close this, because I no longer need them. And in server, I’m going to create a new directory called Collections. And in here, I’m going to create a new file and I’m going to call this collection, posts. And so, posts=new Mongo Collection posts. And then, I’m going to write Posts.allow insert: function return true: update: function return true: and remove: function. Function, return true. And this is going to allow us to insert update, remove from that collection. So the posts are going to let’s create a way to put the posts in first. So in the Home page, let’s actually I’m going to create a new component here called a InsertPost.jsx Insert Post is going to be the name. It’s going to be put to React.createClass And I’m going to basically render some html to put a post in to the database. So I’m going to form actually I don’t need that. Let’s just use a text area placeholder is going to be Type a post, name is going to be actually let’s just give it a className. And we’re going to put form-control and id of a post-body. The male tag has empty body, alright, and then a button. So, button className is going to be button, btn.info and it’s going to say, Save Post. Let’s save that in the home component, let’s render that. So let’s just InsertPost, there. Alright, I have to wrap it here. There, alright. Let’s indent this so it doesn’t look too bad. And if we refresh this, we’re going to see that our new component has been rendered. But if we type stuff, it doesn’t do anything right now. So let’s have an insert to that collection over here. And how we do that is we’re going to create a new function here called insertTo Collection it’s going to take event. So once you start getting more functions in React components, you need to separate them with comma. And what we’re going to do is we need to, say, onClick and in curly braces type this and then the function name. So this is going to be insert to collection. And we’re not passing anything to it so you could leave out the brackets here at the end. And the first thing we’re going to do is event.preventDefault And then we’re going to get the post body. So, content… Actually I need to var content= or we can just use straight up
Jquery here to get post body. I’m going to console.log content make sure we’re getting it. Didn’t mean to copy that, there. So let’s save that. Come back here, refresh this. There we go. And so we are getting that content into that function. So from this point, it’s a basically regular Meteor stuff, we’re going to type Post insert and then content just content. So, save that and refresh and actually to be able to I’m going to wrap this in a form element just because it’s so, that we can hit Enter, in the text area. And it will also submit it. So, onSubmit we’re going to call this .insertToCollection So, we can just actually change this to type =Submit and remove this part here and this button will also function as a means to insert it to the collection. So, to come back here and refresh let’s make sure that it gets into the collection,so This is a post to insert to the collection. I’m gonna hit Enter. Alright, this is a text area, nevermind. I’m gonna save that. And it logs it out, and If I want to make sure that it inserts it successfully, I’m going to in the console log here, I’m going to find and let’s just do that fetch, and it did put it into the database with content there as the key. So, let’s actually extend that a bit further by adding, date, added, it’s going to be new date. And if you want to be able to read it easier, you can do this, that’s what I usually do, and it’s going to make it easier if you get like huge objects that you are putting in to the collection. So, I’m going to delete that console log now. We do not need that. So, now, we’ve got this working, it’s a component to insert post. But how can we get them out of the database? So, over in our home component, I’m going to do a couple of things, First, it’s going to be, I’m going to add a property called mixins Put a colon and then, this. I’m going to type MeteorReact ReactMeteorData So, now we can create a new function and it’s going to connect MeteorData to the component and the function name is going to be getMeteorData We open it up, we do this. So, right now, I’m going to just get all the posts. And so, I’m going to variable posts, = posts, find fetch. And then in here, we’re going to return certain things to the render function. So, I’m going to just type return and then open up curly brackets here. I’m going to return posts as posts. We’re gonna save this. And now, what we can do is we can access that from the render function by for instance create a variable here called allPosts and is = to this.data.posts I’m going to console log all posts I’m going to save that I’m going to refresh this page, and it’s going to log all the posts, which right now, this is the only one we have. So, that’s awesome. How do we get it into here? Ah, well, let’s actually go back to insert posts here. I’m going to create an input field class name is going to be form-control The idea is going to be, user and the placeholder is just going to say, username. And that let’s put a line break there. I’m also going to put a line break down here. I’m going to also handle this: var user = just straight up JQuery from here, the idea of user .val I’m going to insert that to the collection as well. So, user = user and then a comma. So, we now have three fields that will get entered into the collection. I’m going to remove the current one we’ve got. Because, it doesn’t have this necessary information in it to render it. So, I’m just going to type posts find fetch, I’m going to get that ID, I’m going to say, posts.remove id that connector. Now, if I run post find fetch, it finds nothing because we’ve just removed them.

Posted on

Continuing with our Meteor/React Project

Click here to subscribe for more videos like this!

So in Components, let’s create a new file. Let’s call this Header.jsx and I’m going to open it up by typing Header=React.createClass open up that up as usual. And in the render function here, I’m just going to return a bit of bootstrap and so, div class, actually, I’m just going to wrap up that in the div first. So in this render function you can’t just type div class= you know whatever, because class is use to java script so we actually need to type class name. And then we can get the class so I’m just going to call it Navbar Navbar-default and close that. And I’m just going to div class name=container put up a bootstrap container in there and then div className=navbar-brand. Actually this shouldn’t be an A element. And it’s just going to say My Site Name, like that. So if we save that, the header is now created. So now, I’m going to create the Footer. And the same thing would go for the Footer. But I’m not going to put anything in here. I’m just going to have a return a div, so, Footer=React.createClass I’m going to open that up. Going to open the render function and return div. Like that. So now we need to create the Home component. And the reason why is we’ve referenced Home, header and footer we’ve got footer and header created we still need this component which we’re passing in as Home. So we need to create the Home component. So I’m going to create a new directory here to keep things organized, I’m going to call it Home. And in that directory I’m going to create a file called Home.jsx snd I’m going to do the same thing I’m going to name the component Home=React.createClass Right now, I’m just going to render return div, actually h1 I’m just going to say Hello World and hit Save. So to come back here and refresh this page we’re going to start to see it take shape. Because we’ve created all the components that we’re referencing. And so, the first thing I’d like to draw your attention to is that it…we open this up. So in the, where was it, the main layout, I console.log(this.props.LogThis) which I passed into this class as a property. So that’s basically what’s happening we’re passing in components to the main layout components. So, I would reference header, content and footer in the very same way. Except, what we could do is if you want to render the content of a property, you put it in single curly brackets. So it’s like blaze except you’re not using two curly brackets, you’re just using one and you just type it. So let’s type this.props.header this.props. home or content rather we’re referencing that here, we’re setting it, the property is content, so we’re going to reference it like that. And then the footer is so, this,props.footer We’re going to save thisand this is our main layout. So the header, if I for instance made a route called FlowRouter.route/page and open up curly brackets here, let’s name it a Page and the action is going to be renderView and let’s say I had a component named ThisPage I would do that and it would render that component into the main layout with the header that component and then the footer enrolls in passing this just as a proof content. We’re not going to do that. So now, we’ve got this. But bootstrap does not appear to be working and I think maybe, I’ve forgotten to add bootstrap here. I don’t think I got added. Maybe in the last video I know I added it. Maybe I canceled that a bit for some reason, so. Let’s go ahead and get that added, so, control C here, meteor add twbs:bootstrap and hit Enter. Alright. I’m going to run Meteor again. And the page refreshes automatically because it’s Meteor.

Posted on

How to use FlowRouter in your next Meteor Project

Click here to subscribe for more videos like this!

So the first thing we need to do is set up the router to be able to actually route to a certain files and routes. So to do this, we’re going to create a first route, which we’re going to type FlowRouter.route. This is the path that we are creating a route for in a new pass as a second parameter an object. And that with semi-colon. And you can name the route, since it’s going to be named Home. Then put a comma and the action function. Take params as its argument and we open that up. And I’m going to reference here a function that we haven’t yet actually created but we’re about to. So, the function name is going to be renderView. And then in here, I’m going to create the objects. So this is going to be Home and this is the React component that we are going to create. So, basically we have a function here that we need to create called renderView and we pass that as a component. So, here we are going to create function_renderView and we are going to reference that object here as component. And then we open it up. Basically, all you have to do is type React, sorry ReactLayout.render MainLayout and we are going to pass it a few parameters, so. Header is going to be header component that we need to create. Content is going to be the component were passing into it. And then footer is going to be a footer component that we need to create. And then hit Save. And this is all we need to do. This betacode is going to render a header, a component and a footer. So let’s get started with the the main layout. So we’re telling it here to render this React component. And pass these as parameters so we can actually reference these components inside the main layout component by typing this .props. header, content, and footer. And we’ll see these in action here in just a moment. So in Client, I’m going to in components, I’m going to create a new React class called MainLayout.jsx And here, basically we are going to get started with how to create React components. So, the first thing you need to do is name the component. Mine is going to be called MainLayout and we see that’s equal to React.createClass and we open that up with brackets and curly brackets. So, all we really need here is to render function and that’s all we are going to do at this point, so. Type in render and then in the render function, you’re going to put return. And you’re going to open up just regular brackets. And this is a bit odd, I know, but this is how it’s done, so. Here we can actually print html and it’s going to, it’s going to render what we tell it to. So we always need wrap all elements under a parent container. So I wouldn’t be able to say return two divs like this, two siblings, it wouldn’t work. So we do need to wrap it. So here, we are going to to reference the props that came in, land so as an example, I’m going to add another prop here called LogThis and it’s just going to be a string. This is a property and I’m going to save that. So in the render function, you can access that by typing console.log and then this.props.logThis and save that. And I’m going to go the app here and I’m going to refresh it. And you are going to see two things happening. The First, is that Home is not defined. And that’s because we haven’t created a component yet. So we still need to do a little bit of work. In order for this to work.

Posted on

The Complete Python 3 Course: Beginner to Advanced Coupon!

School is now back in full gear and learning season is upon us. Whether you are a student enrolled in a university program, or a professional looking to expand their skill-set, I am happy to announce the release of my newest course Learn Python 3 from Beginner to Advanced. Python is a great language for novice programmers because of it’s simplicity and easy to read syntax. You can learn how to think like a programmer while avoiding the very steep learning curves of other coding languages such as C++. This course will teach you Python through coding examples, and give you the tools you need to write programs with real-life applications. Enroll now for only $10!

https://www.udemy.com/python-complete

If you want to get started programming in Python you are going to LOVE this course! This course is designed to fully immerse you in the Python language, so it is great for both beginners and veteran programmers! Learn Python as Nick takes you through building a calculator, creating an RPG script, doing web scraping, coding web apps, and much more! We will cover the following topics in this course:

  • Python installation and PyCharm (IDE) setup
  • Programming basics
  • Numbers, strings, Boolean operators, lists, dictionaries, variables, built-in functions, arguments, logic statements, importing modules
  • PEP guidelines, loops, classes & objects, class & instance variables, comments
  • Reading/writing files, JSON, virtual environments, PyPl
  • Requests
  • Web scraping using Beautiful Soup
  • PyMongo (MongoDB)
  • WebPy for web app development
  • Django server setup and management

This course is fully subtitled in English!

Thank you for taking the time to read this and we hope to see you in the course!

python

Click here to enroll in the course on Udemy!