Updated: 9/23/2014
Iâm always tinkering around with different ideas and toward the beginning of 2013 decided to build a sample application using AngularJS that I call Customer Manager. The goal of the application is to highlight a lot of the different features offered by AngularJS and demonstrate how they can be used together. I also wanted to make sure that the application was approachable by people new to Angular since Iâve never found overly complex applications great for learning new concepts.
The application initially started out small and was used in my AngularJS in 60-ish Minutes video on YouTube but has gradually had more and more features added to it and will continue to be enhanced over time. Itâs used in a new âend-to-endâ instructor-led training course my company wrote for AngularJS as well as in some video courses that will be coming out. Hereâs a quick look at what the application home page looks like:
In this post Iâm going to provide an overview about how the application is organized, back-end options that are available, and some of the features it demonstrates. Iâve already written about some of the features so if youâre interested check out the following posts:
Two versions of the application are available on Github including a âstandardâ version that uses out-of-the-box AngularJS features and a custom version that provides custom routing and dynamic loading of controller scripts:
CustomerManagerStandard:Â https://github.com/DanWahlin/CustomerManagerStandard
CustomerManager with Custom Routing: https://github.com/DanWahlin/CustomerManager
Â
Key Features
The Customer Manager application certainly doesnât cover every feature provided by AngularJS but does provide insight into several key areas. Here are a few of the features it demonstrates with information about the files to look at if you want more details:
The structure of the application is shown to the right. The homepage is index.html and is located at the root of the application folder. It defines where application views will be loaded using the ng-view directive and includes script references to AngularJS, AngularJS routing and animation scripts, plus a few others located in the Scripts folder and to custom application scripts located in the app folder.
Â
The app folder contains all of the key scripts used in the application. There are several techniques that can be used for organizing script files but after experimenting with several of them I decided that I prefer content organized by module name (customersApp and wc.directives are examples of module folder names). Within each module folder I follow a convention such as controllers, views, services, etc. Individual features are identified within a convention folder by using additional subfolders such as customers and orders. Doing that helps me find things a lot faster due to mixing the convention/feature approach.
Iâm a huge believer in having some conventions in place especially when it comes to team development. Having managed several development teams over the years I learned that consistency across projects is good since people come and go on teams and taking that approach allows files to be categorized and located easily (such as controllers and services). If youâre new to an app (a new hire, production support, a contractor, etc.) and are given a pure feature-based folder structure to work with it can be challenging to find things if you donât know the app features well since whoever created the folder structure did it based on their way of thinking about the app. If some convention is mixed in with the features it becomes much easier to find things in my opinion and it makes it easier to understand multiple projects â not just one. On the other hand, going with a pure convention-based approach causes challenges with large applications since a controllers folder could have a ton of files in it which is why I like to segregate things by module/convention/feature.
There are MANY different opinions on this so my recommendation is to go with whatever works best for you. Iâm definitely not saying this is âthe wayââ¦this is my way. Anyone who says, âYouâre doing it wrong!â should be ignored because in my experience these are generally the type of close-minded people you run into who arenât willing to take time to consider alternatives to their approach. Contrary to what some people think, there is no âone right wayâ to organize scripts and files. As long as the scripts make it down to the client properly (youâll likely minify and concatenate them anyway to reduce bandwidth and minimize HTTP calls so the structure is irrelevant to the browser), the way you organize them is completely up to you. Hereâs what I ended up doing for this application:
Â
Back-End Technologies
The Customer Manager application (grab it from Github) provides two different options on the back-end including ASP.NET Web API and Node.js so you'll want to select one of them in order to run the application. The ASP.NET Web API back-end uses C# and Entity Framework for data access and stores data in SQL Server (LocalDb). The other option on the back-end is Node.js, Express, and MongoDB.
Â
Using the ASP.NET Web API Back-End OptionTo run the application using ASP.NET Web API/SQL Server back-end open the .sln file at the root of the project in Visual Studio 2012 or higher (the free Visual Studio 2013 Community Edition version is fine). Press F5 and a browser will automatically launch and display the application. Under the covers, Entity Framework code first is used to create the database dynamically.
Â
Using the Node.js Back-End OptionTo run the application using the Node.js/MongoDB back-end follow the steps listed in the readme on the Github site.
Â
Front-End Technologies
The Customer Manager application uses the following frameworks and libraries on the front-end:
The application uses native AngularJS $http by default to make calls back to the server. However, by going to app/customersApp/services/config.js you can switch from using $http to using BreezeJS (a very cool client-side data management library). When using BreezeJS youâll also want to include Breeze Angular Service  (the script is already loaded in index.html to keep things simple). For more details on what BreezeJS is all about check out my previous post.
Â
Application Views
The application has several views designed to cover different aspects of AngularJS from editing data to displaying, paging, and filtering data. Here are the main views:
Â
Customers ViewThis view provides multiple views of customer data (Card View and List View), supports paging, allows customers to be added or removed, and provides filtering functionality.
Card View (app/customersApp/views/customers/customers.html)This view displays customer information and allows customers to be edited (by clicking their name), deleted (by clicking the X), or their orders to be viewed.
Â
List View (app/customersApp/views/customers/customers.html)
This view displays customer information in a standard list type of view.
Â
Login View (app/customersApp/views/login.html)
This view allows the user to login. Security isnât officially checked on the server for this demo as it just returns a boolean true value but the client-side does have security functionality built-in to show how that could be integrated with AngularJS, how events can be broadcast and handled, and more. Keep in mind that in a ârealâ application every secured resource on the server would have to be checked for the proper security credentials regardless of what data or information the client has.
Â
This view adds some custom AngularJS validation including a custom directive (wcUnique.js) that ensures that the email address being added is unique.
This view shows the orders for a specific customer. Orders can be sorted by clicking on the column headings.
Â
Orders View (app/customersApp/views/orders/orders.html)This view shows orders for all customers and supports paging, filtering, and sorting of the orders.
Â
About View (app/customersApp/views/about.html)
There isnât much to this view but I listed it for the sake of completeness.
Â
Custom Directives
Three custom directives are currently included in the application:
The application includes two custom filters used to filter data in the customers and orders views:
Â
ConclusionIâll be enhancing the application even more over time and welcome contributions as well. Tony Quinn contributed the initial Node.js/MongoDB code (thanks Tony!) which is very cool to have as a back-end option and several other contributions have been made for testing and the initial version of the menuHighlighter directive. Access the standard application here and a version that has custom routing in it here. Additional information about the custom routing can be found in this post.
Onsite Developer Training: If your company is interested in onsite training on JavaScript, ES6, AngularJS, Node.js, C# or other technologies please email training@thewahlingroup.com for details about the classes that we offer.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4