niedziela, 1 grudnia 2013

Angularjs example MotoAds more advanced directive

Another thing we will add to MotoAds demo application is a feature which allows us to comment each advert. A good idea would be to realize this as AngularJS directive. It will look like in the picture below. We can see all added comment to advert, click on Comment link activate the comment form with Preview, Send and Cancel buttons.

The comment form we will realize as AngularJS directive. Before we start let's look at changed adverts.json, there is the additional comments field (array of comments):
Step 1
We create commenForm.html template which we use in directive:
Step 2
We in directives.js we create AngularJS directive:
Step 3
We add simple CommentController into controllers.js:
Step 4
We add simple newlines filter into filters.js:
Step 5
We comment-form directive into adverts.html and some additional code to list comments and activate the comment form: If you want to run this example on your computer, you can download sources from GitHub.

Any comment would be highly appreciated.

sobota, 30 listopada 2013

Java ESL program for connecting to the FreeSWITCH

Next simple Java program using Event Socket interface to control FreeSWITCH. First you should read: Next you should not forget to change event_socket.conf.xml (to allow connections from any host on the network): Now we can write simple java ESL program for connecting to the FreeSWITCH. When we run this program we can see on the console much more than below: Good start to do something cool :)

czwartek, 28 listopada 2013

Java program for connecting to the FreeSWITCH XML-RPC

I would like to show simple Java program which use XML-RPC interface to do some freeswitch commands. We should on freeswitch console load mod_xml_rpc: Worth checking out if it works, in web browser type: If you see "FreeSWITCH help" it works.

Next we download Apache XML-RPC library.

Now we create Java program (using Apache XML-RPC):
After running this simple Java program we can see on Java console: A lot of fun :)

sobota, 23 listopada 2013

AngularJS example MotoAds with NodeJS and MongoDB

I built MotoAds demo application in AngularJS but it did not have any server layer. Data was read directly from the json files. So I was decided to build the server side services. I know pretty well JEE and relational database, so I could use it. But I want to know something new so I chose NodeJS nad MongoDB. Thanks to this decision I got a full stack JavaScript application. It's incredible to use JavaScript to build the complete application.

Now MotoAds demo application consists of:
  • User interface in AngularJS and Bootstrap with full CRUD operations: add, read, edit and remove adverts.
  • Server service layer was built in NodeJS with RESTful serrvices. To simplify the use of a NodeJS I used ExpressJS.
  • Database: all data except the pictures are stored in MongoDB.
So let's see how to add the CRUD operations in AngularJS with services in NodeJS with MongoDB.

Step 1
We write in services.js access to our RESTful services:
Step 2
Inject services in app.js:
We use the angularjs services in controllers.js:
Step 3
In server.js we create the HTTP server with the RESTful service in NodeJS and ExpressJS. It is also used to host angularjs app:
Step 4
In adverts.js we write some code in NodeJS which allows us to use MongoDB:
We run MongoDB and start our HTTP server (node server.js). Now we are typing in web browser URL http://localhost:3000/#/. In web browser we should see the MotoAds application and we can use CRUD operations.

If you want to run this example on your computer, you can download sources from GitHub.

Any comment would be highly appreciated.