├── client
├── typings
│ ├── tsd.d.ts
│ └── socket.io-client
│ │ └── socket.io-client.d.ts
├── tsd.json
├── tsconfig.json
├── build
│ ├── app
│ │ ├── components
│ │ │ ├── rate
│ │ │ │ ├── rate.html
│ │ │ │ └── rateComponent.js
│ │ │ ├── socket
│ │ │ │ ├── socket.html
│ │ │ │ ├── socketComponent.js
│ │ │ │ └── socketService.js
│ │ │ ├── home
│ │ │ │ ├── home.html
│ │ │ │ └── homeComponent.js
│ │ │ ├── category
│ │ │ │ ├── category.html
│ │ │ │ └── categoryComponent.js
│ │ │ ├── selling
│ │ │ │ ├── selling.html
│ │ │ │ └── sellingComponent.js
│ │ │ ├── form
│ │ │ │ ├── customValidator.js
│ │ │ │ ├── form.html
│ │ │ │ └── formComponent.js
│ │ │ ├── product
│ │ │ │ ├── product.html
│ │ │ │ └── productComponent.js
│ │ │ ├── inventry
│ │ │ │ ├── inventry.html
│ │ │ │ └── inventryComponent.js
│ │ │ ├── testApi
│ │ │ │ └── apiComponent.js
│ │ │ └── app
│ │ │ │ ├── app.html
│ │ │ │ └── appComponent.js
│ │ └── boot.js
│ └── index.html
└── src
│ ├── app
│ ├── components
│ │ ├── rate
│ │ │ ├── rate.html
│ │ │ └── rateComponent.ts
│ │ ├── socket
│ │ │ ├── socketComponent.ts
│ │ │ ├── socket.html
│ │ │ └── socketService.ts
│ │ ├── home
│ │ │ ├── home.html
│ │ │ └── homeComponent.ts
│ │ ├── category
│ │ │ ├── category.html
│ │ │ └── categoryComponent.ts
│ │ ├── testApi
│ │ │ └── apiComponent.ts
│ │ ├── form
│ │ │ ├── customValidator.ts
│ │ │ ├── formComponent.ts
│ │ │ └── form.html
│ │ ├── selling
│ │ │ ├── selling.html
│ │ │ └── sellingComponent.ts
│ │ ├── product
│ │ │ ├── product.html
│ │ │ └── productComponent.ts
│ │ ├── app
│ │ │ ├── appComponent.ts
│ │ │ └── app.html
│ │ └── inventry
│ │ │ ├── inventry.html
│ │ │ └── inventryComponent.ts
│ └── boot.ts
│ └── index.html
├── server
├── tsconfig.json
├── typings
│ ├── tsd.d.ts
│ ├── mime
│ │ └── mime.d.ts
│ ├── serve-static
│ │ └── serve-static.d.ts
│ ├── body-parser
│ │ └── body-parser.d.ts
│ └── q
│ │ └── Q.d.ts
├── build
│ ├── rate
│ │ ├── rateRouter.js
│ │ ├── rateController.js
│ │ └── rateModel.js
│ ├── user
│ │ ├── userRouter.js
│ │ ├── userController.js
│ │ └── userModel.js
│ ├── selling
│ │ ├── sellingRouter.js
│ │ ├── sellingController.js
│ │ └── sellingModel.js
│ ├── category
│ │ ├── categoryRouter.js
│ │ ├── categoryController.js
│ │ └── categoryModel.js
│ ├── inventry
│ │ ├── inventryRouter.js
│ │ ├── inventryController.js
│ │ └── inventryModel.js
│ ├── product
│ │ ├── productRouter.js
│ │ ├── productController.js
│ │ └── productModel.js
│ ├── helpers
│ │ └── helper.js
│ └── app.js
├── src
│ ├── rate
│ │ ├── rateRouter.ts
│ │ ├── rateController.ts
│ │ └── rateModel.ts
│ ├── user
│ │ ├── userRouter.ts
│ │ ├── userController.ts
│ │ └── userModel.ts
│ ├── selling
│ │ ├── sellingRouter.ts
│ │ ├── sellingController.ts
│ │ └── sellingModel.ts
│ ├── category
│ │ ├── categoryRouter.ts
│ │ ├── categoryController.ts
│ │ └── categoryModel.ts
│ ├── inventry
│ │ ├── inventryRouter.ts
│ │ ├── inventryController.ts
│ │ └── inventryModel.ts
│ ├── product
│ │ ├── productRouter.ts
│ │ ├── productController.ts
│ │ └── productModel.ts
│ ├── helpers
│ │ └── helper.ts
│ └── app.ts
└── tsd.json
├── README.md
├── package.json
└── gulpfile.js
/client/typings/tsd.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/server/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES5",
4 | "module": "commonjs"
5 | },
6 | "exclude": [
7 | "node_modules"
8 | ]
9 | }
--------------------------------------------------------------------------------
/client/tsd.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "v4",
3 | "repo": "borisyankov/DefinitelyTyped",
4 | "ref": "master",
5 | "path": "typings",
6 | "bundle": "typings/tsd.d.ts",
7 | "installed": {
8 | "socket.io-client/socket.io-client.d.ts": {
9 | "commit": "0d622d857f97d44ea7dcad2b3edec1f23c48fe9e"
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ng2seed
2 | Typed Nodejs/Express & Angular2
3 |
4 | Sample Code using: NodeJS, ExpressJS, Angular2 (routing, form validation, http), Socket
5 |
6 | for run this application...
7 |
8 | 1. open terminal / command prompt
9 | 2. type: npm install
10 | 3. type: npm start
11 | 4. open your browser and type: http://localhost:4000
12 |
--------------------------------------------------------------------------------
/client/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES5",
4 | "module": "system",
5 | "moduleResolution": "node",
6 | "sourceMap": true,
7 | "emitDecoratorMetadata": true,
8 | "experimentalDecorators": true,
9 | "removeComments": false,
10 | "noImplicitAny": false
11 | },
12 | "exclude": [
13 | "node_modules"
14 | ]
15 | }
--------------------------------------------------------------------------------
/client/build/app/components/rate/rate.html:
--------------------------------------------------------------------------------
1 |
Rate List
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | -
11 | Name: {{get.rates}}
12 | Dec: {{get.rateDec}}
13 |
14 |
15 |
--------------------------------------------------------------------------------
/client/src/app/components/rate/rate.html:
--------------------------------------------------------------------------------
1 | Rate List
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | -
11 | Name: {{get.rates}}
12 | Dec: {{get.rateDec}}
13 |
14 |
15 |
--------------------------------------------------------------------------------
/server/typings/tsd.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 | ///
6 | ///
7 | ///
8 | ///
9 |
--------------------------------------------------------------------------------
/server/build/rate/rateRouter.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | ///
3 | var express = require("express");
4 | var router = express.Router();
5 | //import controller
6 | var controller = require("./rateController");
7 | //Get
8 | // router.get('/', controller.Index_get)
9 | ;
10 | //router.post('/', controller.UserSave_post);
11 | router.get('/getRate', controller.getRate);
12 | router.post('/Rate', controller.RateSave_post);
13 | module.exports = router;
14 |
--------------------------------------------------------------------------------
/server/build/user/userRouter.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | ///
3 | var express = require("express");
4 | var router = express.Router();
5 | //import controller
6 | var controller = require("./userController");
7 | //Get
8 | // router.get('/', controller.Index_get)
9 | ;
10 | //router.post('/', controller.UserSave_post);
11 | router.get('/getUser', controller.getAllUsers);
12 | router.post('/User', controller.UserSave_post);
13 | module.exports = router;
14 |
--------------------------------------------------------------------------------
/server/build/selling/sellingRouter.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | ///
3 | var express = require("express");
4 | var router = express.Router();
5 | //import controller
6 | var controller = require("./sellingController");
7 | //Get
8 | // router.get('/', controller.Index_get)
9 | ;
10 | //router.post('/', controller.UserSave_post);
11 | router.get('/getSellers', controller.getSeller);
12 | router.post('/Selling', controller.sellingSave_post);
13 | module.exports = router;
14 |
--------------------------------------------------------------------------------
/server/build/category/categoryRouter.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | ///
3 | var express = require("express");
4 | var router = express.Router();
5 | //import controller
6 | var controller = require("./categoryController");
7 | //Get
8 | // router.get('/', controller.Index_get)
9 | ;
10 | //router.post('/', controller.UserSave_post);
11 | router.get('/getCategory', controller.getAllUsers);
12 | router.post('/Category', controller.CategorySave_post);
13 | module.exports = router;
14 |
--------------------------------------------------------------------------------
/server/build/inventry/inventryRouter.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | ///
3 | var express = require("express");
4 | var router = express.Router();
5 | //import controller
6 | var controller = require("./inventryController");
7 | //Get
8 | // router.get('/', controller.Index_get)
9 | ;
10 | //router.post('/', controller.UserSave_post);
11 | router.get('/getInventry', controller.getInventry);
12 | router.post('/Inventry', controller.InventrySave_post);
13 | module.exports = router;
14 |
--------------------------------------------------------------------------------
/server/build/product/productRouter.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | ///
3 | var express = require("express");
4 | var router = express.Router();
5 | //import controller
6 | var controller = require("./productController");
7 | //Get
8 | // router.get('/', controller.Index_get)
9 | ;
10 | //router.post('/', controller.UserSave_post);
11 | router.get('/getProducts', controller.getAllgetProducts);
12 | router.post('/Category', controller.ProductSave_post);
13 | module.exports = router;
14 |
--------------------------------------------------------------------------------
/server/src/rate/rateRouter.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import express = require("express");
3 | var router : express.Router = express.Router();
4 |
5 | //import controller
6 | import * as controller from "./rateController";
7 |
8 | //Get
9 | // router.get('/', controller.Index_get)
10 | ;
11 | //router.post('/', controller.UserSave_post);
12 | router.get('/getRate', controller.getRate);
13 | router.post('/Rate', controller.RateSave_post);
14 | // router.post('/signin', controller.UserSigin_post);
15 | // router.put('/updateUserStatus',controller.updateUserStatus);
16 |
17 |
18 | export = router;
--------------------------------------------------------------------------------
/server/src/user/userRouter.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import express = require("express");
3 | var router : express.Router = express.Router();
4 |
5 | //import controller
6 | import * as controller from "./userController";
7 |
8 | //Get
9 | // router.get('/', controller.Index_get)
10 | ;
11 | //router.post('/', controller.UserSave_post);
12 | router.get('/getUser', controller.getAllUsers);
13 | router.post('/User', controller.UserSave_post);
14 | // router.post('/signin', controller.UserSigin_post);
15 | // router.put('/updateUserStatus',controller.updateUserStatus);
16 |
17 |
18 | export = router;
--------------------------------------------------------------------------------
/server/src/selling/sellingRouter.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import express = require("express");
3 | var router : express.Router = express.Router();
4 |
5 | //import controller
6 | import * as controller from "./sellingController";
7 |
8 | //Get
9 | // router.get('/', controller.Index_get)
10 | ;
11 | //router.post('/', controller.UserSave_post);
12 | router.get('/getSellers', controller.getSeller);
13 | router.post('/Selling', controller.sellingSave_post);
14 | // router.post('/signin', controller.UserSigin_post);
15 | // router.put('/updateUserStatus',controller.updateUserStatus);
16 |
17 |
18 | export = router;
--------------------------------------------------------------------------------
/server/src/category/categoryRouter.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import express = require("express");
3 | var router : express.Router = express.Router();
4 |
5 | //import controller
6 | import * as controller from "./categoryController";
7 |
8 | //Get
9 | // router.get('/', controller.Index_get)
10 | ;
11 | //router.post('/', controller.UserSave_post);
12 | router.get('/getCategory', controller.getAllUsers);
13 | router.post('/Category', controller.CategorySave_post);
14 | // router.post('/signin', controller.UserSigin_post);
15 | // router.put('/updateUserStatus',controller.updateUserStatus);
16 |
17 |
18 | export = router;
--------------------------------------------------------------------------------
/server/src/inventry/inventryRouter.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import express = require("express");
3 | var router : express.Router = express.Router();
4 |
5 | //import controller
6 | import * as controller from "./inventryController";
7 |
8 | //Get
9 | // router.get('/', controller.Index_get)
10 | ;
11 | //router.post('/', controller.UserSave_post);
12 | router.get('/getInventry', controller.getInventry);
13 | router.post('/Inventry', controller.InventrySave_post);
14 | // router.post('/signin', controller.UserSigin_post);
15 | // router.put('/updateUserStatus',controller.updateUserStatus);
16 |
17 |
18 | export = router;
--------------------------------------------------------------------------------
/server/src/product/productRouter.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import express = require("express");
3 | var router : express.Router = express.Router();
4 |
5 | //import controller
6 | import * as controller from "./productController";
7 |
8 | //Get
9 | // router.get('/', controller.Index_get)
10 | ;
11 | //router.post('/', controller.UserSave_post);
12 | router.get('/getProducts', controller.getAllgetProducts);
13 | router.post('/Category', controller.ProductSave_post);
14 | // router.post('/signin', controller.UserSigin_post);
15 | // router.put('/updateUserStatus',controller.updateUserStatus);
16 |
17 |
18 | export = router;
--------------------------------------------------------------------------------
/client/src/app/components/socket/socketComponent.ts:
--------------------------------------------------------------------------------
1 | import { Component } from "angular2/core";
2 | import { SocketService } from "./socketService";
3 |
4 |
5 | @Component({
6 | selector: "socket",
7 | templateUrl: "./app/components/socket/socket.html"
8 | //providers: [SocketService]
9 | })
10 | export class SocketComponent {
11 | socket: any;
12 | fruitz: Array;
13 |
14 | // constructor
15 | constructor(private io: SocketService) {
16 | this.fruitz = this.io.getAllFruits();
17 | }
18 |
19 | add(name) {
20 | if(name.trim().length > 2){
21 | this.io.add(name);
22 | }
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/client/build/app/components/socket/socket.html:
--------------------------------------------------------------------------------
1 | Scoket Sample
2 |
3 | Add Fruits
4 |
5 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | | {{i}} - {{f}} |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/client/src/app/components/home/home.html:
--------------------------------------------------------------------------------
1 | Home Page
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | -
19 | Name: {{get.fName}}
20 | Dec: {{get.lName}}
21 | Type: {{get.type}}
22 |
23 |
24 |
--------------------------------------------------------------------------------
/client/src/app/components/socket/socket.html:
--------------------------------------------------------------------------------
1 | Scoket Sample
2 |
3 | Add Fruits
4 |
5 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | | {{i}} - {{f}} |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/client/build/app/components/home/home.html:
--------------------------------------------------------------------------------
1 | Home Page
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | -
19 | Name: {{get.fName}}
20 | Dec: {{get.lName}}
21 | Type: {{get.type}}
22 |
23 |
24 |
--------------------------------------------------------------------------------
/server/typings/mime/mime.d.ts:
--------------------------------------------------------------------------------
1 | // Type definitions for mime
2 | // Project: https://github.com/broofa/node-mime
3 | // Definitions by: Jeff Goddard
4 | // Definitions: https://github.com/borisyankov/DefinitelyTyped
5 |
6 | // Imported from: https://github.com/soywiz/typescript-node-definitions/mime.d.ts
7 |
8 | declare module "mime" {
9 | export function lookup(path: string): string;
10 | export function extension(mime: string): string;
11 | export function load(filepath: string): void;
12 | export function define(mimes: Object): void;
13 |
14 | interface Charsets {
15 | lookup(mime: string): string;
16 | }
17 |
18 | export var charsets: Charsets;
19 | export var default_type: string;
20 | }
21 |
--------------------------------------------------------------------------------
/client/build/app/components/category/category.html:
--------------------------------------------------------------------------------
1 | Category
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
16 |
17 |
18 |
19 | | Name: {{get.categoryName}} |
20 | Dec: {{get.categoryDec}} |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/client/src/app/components/category/category.html:
--------------------------------------------------------------------------------
1 | Category
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
16 |
17 |
18 |
19 | | Name: {{get.categoryName}} |
20 | Dec: {{get.categoryDec}} |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/client/src/app/components/testApi/apiComponent.ts:
--------------------------------------------------------------------------------
1 | import { Component } from "angular2/core";
2 | import { Http, Response, RequestOptions, Headers } from 'angular2/http'; //for http request (rest API)
3 |
4 | @Component({
5 | selector: 'test-api',
6 | template: ' Api
{{receivedFromServer | json}} ',
7 | })
8 | export class ApiComponent {
9 | receivedFromServer: any
10 |
11 | constructor(private http: Http) {
12 | //constructor
13 |
14 | //calling test api (testing)
15 | this.testApi();
16 | }
17 |
18 | testApi(): void {
19 | this.http.request('http://localhost:4000/api/test')
20 | .subscribe((res: Response) => {
21 | this.receivedFromServer = res.json();
22 | }); //http.request
23 | }
24 |
25 |
26 | }
--------------------------------------------------------------------------------
/client/src/app/boot.ts:
--------------------------------------------------------------------------------
1 |
2 | //Builtin Methods
3 | import { provide } from "angular2/core" ;
4 | import { bootstrap } from "angular2/platform/browser" ;
5 | import { HTTP_PROVIDERS } from "angular2/http"; // getting http compnent
6 | import { ROUTER_PROVIDERS, LocationStrategy, HashLocationStrategy} from "angular2/router"; // with hash on url
7 | import {FORM_PROVIDERS} from "angular2/common"; // getting form_providers for form validation (not required its work without importing also)
8 | import { SocketService } from "./components/socket/socketService";
9 |
10 | // Import Components
11 | import {AppComponent} from "./components/app/appComponent";
12 |
13 | // Bootstraping
14 | bootstrap(AppComponent, [
15 | ROUTER_PROVIDERS,
16 | HTTP_PROVIDERS,
17 | FORM_PROVIDERS,
18 | SocketService,
19 | provide(LocationStrategy, { useClass: HashLocationStrategy }) // angular hashing urls
20 | // form builder for form validations
21 | ]);
--------------------------------------------------------------------------------
/server/tsd.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "v4",
3 | "repo": "borisyankov/DefinitelyTyped",
4 | "ref": "master",
5 | "path": "typings",
6 | "bundle": "typings/tsd.d.ts",
7 | "installed": {
8 | "body-parser/body-parser.d.ts": {
9 | "commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4"
10 | },
11 | "express/express.d.ts": {
12 | "commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4"
13 | },
14 | "node/node.d.ts": {
15 | "commit": "552fe5d3e45ef9c8ecd3eda2b6a24d2546c438f4"
16 | },
17 | "serve-static/serve-static.d.ts": {
18 | "commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4"
19 | },
20 | "mime/mime.d.ts": {
21 | "commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4"
22 | },
23 | "q/Q.d.ts": {
24 | "commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4"
25 | },
26 | "mongoose/mongoose.d.ts": {
27 | "commit": "1a5b2a729d35b1d41e2d15818db013a3644c6ba4"
28 | },
29 | "socket.io/socket.io.d.ts": {
30 | "commit": "552fe5d3e45ef9c8ecd3eda2b6a24d2546c438f4"
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/server/build/helpers/helper.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var _User = require('./../category/categoryModel');
3 | function CreateCategory(cb) {
4 | var u1 = { categoryName: 'MuZz', categoryDec: "Something" };
5 | var userObj = new _User.User(u1);
6 | //checking user exists or not
7 | _User.User.isUserExists(userObj.categoryName, function (error, result) {
8 | console.log('user -- exists?', error);
9 | if (!error) {
10 | userObj.create(userObj, function (err, data) {
11 | if (err) {
12 | console.log('User Create Err');
13 | console.log(err);
14 | cb(false);
15 | }
16 | else {
17 | console.log('User Created');
18 | console.log(data);
19 | }
20 | }); //userObj.create
21 | }
22 | else {
23 | console.log('User/Member not created...Err!');
24 | console.log(error);
25 | cb(false);
26 | }
27 | }); //User.isUserExists
28 | } //CreateUserAndMember
29 |
--------------------------------------------------------------------------------
/server/build/rate/rateController.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var RateModel_1 = require("./RateModel"); //import Member Class
3 | var user = new RateModel_1.User();
4 | //Object
5 | var Controller = {
6 | RateSave_post: function (req, res) {
7 | console.log(req.body, "rrrrrrrrrrrrrrrrrrrrrrrrrrrrr");
8 | var Obj = req.body;
9 | user.create(Obj, function (err, data) {
10 | if (err) {
11 | res.json({ 'success': false, 'data': null, 'error': err });
12 | }
13 | else {
14 | res.json({ 'success': true, 'data': data, 'error': null });
15 | }
16 | });
17 | },
18 | getRate: function (req, res) {
19 | RateModel_1.RateModel.find({}, function (err, data) {
20 | console.log('controller err', err);
21 | console.log('controller data', data);
22 | if (err) {
23 | res.send({ 'success': false, 'data': null, 'error': err });
24 | }
25 | else {
26 | res.send({ 'success': true, 'data': data, 'error': err });
27 | }
28 | });
29 | },
30 | };
31 | module.exports = Controller;
32 |
--------------------------------------------------------------------------------
/server/build/user/userController.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var userModel_1 = require("./userModel"); //import Member Class
3 | var user = new userModel_1.User();
4 | //Object
5 | var Controller = {
6 | UserSave_post: function (req, res) {
7 | console.log(req.body, "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu");
8 | var userObj = req.body;
9 | user.create(userObj, function (err, data) {
10 | if (err) {
11 | res.json({ 'success': false, 'data': null, 'error': err });
12 | }
13 | else {
14 | res.json({ 'success': true, 'data': data, 'error': null });
15 | }
16 | });
17 | },
18 | getAllUsers: function (req, res) {
19 | userModel_1.userModel.find({}, function (err, data) {
20 | console.log('controller err', err);
21 | console.log('controller data', data);
22 | if (err) {
23 | res.send({ 'success': false, 'data': null, 'error': err });
24 | }
25 | else {
26 | res.send({ 'success': true, 'data': data, 'error': err });
27 | }
28 | });
29 | },
30 | };
31 | module.exports = Controller;
32 |
--------------------------------------------------------------------------------
/client/src/app/components/form/customValidator.ts:
--------------------------------------------------------------------------------
1 | import {Control} from "angular2/common";
2 |
3 | // Custom form validation
4 | // Of course we can also write our own custom validators.
5 | // Here is an example of a validator that checks if the first character is not a number:
6 |
7 | interface ValidationResult {
8 | [key: string]: boolean;
9 | }
10 |
11 | export class UsernameValidator {
12 |
13 | static startsWithNumber (control: Control): ValidationResult {
14 | if ( control.value !== "" && !isNaN(control.value.charAt(0)) ) {
15 | return { "startsWithNumber" : true };
16 | }
17 | return null;
18 | }
19 |
20 | static emailValidation(control: Control): ValidationResult {
21 | let pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
22 | if ( control.value !== "" && !control.value.match(pattern) ) {
23 | return { "emailValidation": true };
24 | }
25 | return null;
26 | }
27 | }
28 |
29 |
30 | // One weird thing you might notice is that returning null actually means the validation is valid.
31 | // If we find a number at the first position of the string we return the validation error { “startsWithNumber”: true }
--------------------------------------------------------------------------------
/server/build/selling/sellingController.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var sellingModel_1 = require("./sellingModel"); //import Member Class
3 | var user = new sellingModel_1.User();
4 | //Object
5 | var Controller = {
6 | sellingSave_post: function (req, res) {
7 | console.log(req.body, "ssssssssssssssssssssssss");
8 | var Obj = req.body;
9 | user.create(Obj, function (err, data) {
10 | if (err) {
11 | res.json({ 'success': false, 'data': null, 'error': err });
12 | }
13 | else {
14 | res.json({ 'success': true, 'data': data, 'error': null });
15 | }
16 | });
17 | },
18 | getSeller: function (req, res) {
19 | sellingModel_1.sellingModel.find({}, function (err, data) {
20 | console.log('controller err', err);
21 | console.log('controller data', data);
22 | if (err) {
23 | res.send({ 'success': false, 'data': null, 'error': err });
24 | }
25 | else {
26 | res.send({ 'success': true, 'data': data, 'error': err });
27 | }
28 | });
29 | },
30 | };
31 | module.exports = Controller;
32 |
--------------------------------------------------------------------------------
/server/build/inventry/inventryController.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var InventryModel_1 = require("./InventryModel"); //import Member Class
3 | var user = new InventryModel_1.User();
4 | //Object
5 | var Controller = {
6 | InventrySave_post: function (req, res) {
7 | console.log(req.body, "iiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
8 | var Obj = req.body;
9 | user.create(Obj, function (err, data) {
10 | if (err) {
11 | res.json({ 'success': false, 'data': null, 'error': err });
12 | }
13 | else {
14 | res.json({ 'success': true, 'data': data, 'error': null });
15 | }
16 | });
17 | },
18 | getInventry: function (req, res) {
19 | InventryModel_1.InventryModel.find({}, function (err, data) {
20 | console.log('controller err', err);
21 | console.log('controller data', data);
22 | if (err) {
23 | res.send({ 'success': false, 'data': null, 'error': err });
24 | }
25 | else {
26 | res.send({ 'success': true, 'data': data, 'error': err });
27 | }
28 | });
29 | },
30 | };
31 | module.exports = Controller;
32 |
--------------------------------------------------------------------------------
/server/build/product/productController.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var ProductModel_1 = require("./ProductModel"); //import Member Class
3 | var user = new ProductModel_1.User();
4 | //Object
5 | var Controller = {
6 | ProductSave_post: function (req, res) {
7 | console.log(req.body, "pppppppppppppppppppppppppppp");
8 | var Obj = req.body;
9 | user.create(Obj, function (err, data) {
10 | if (err) {
11 | res.json({ 'success': false, 'data': null, 'error': err });
12 | }
13 | else {
14 | res.json({ 'success': true, 'data': data, 'error': null });
15 | }
16 | });
17 | },
18 | getAllgetProducts: function (req, res) {
19 | ProductModel_1.ProductModel.find({}, function (err, data) {
20 | console.log('controller err', err);
21 | console.log('controller data', data);
22 | if (err) {
23 | res.send({ 'success': false, 'data': null, 'error': err });
24 | }
25 | else {
26 | res.send({ 'success': true, 'data': data, 'error': err });
27 | }
28 | });
29 | },
30 | };
31 | module.exports = Controller;
32 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "angularstarter",
3 | "version": "0.1.0",
4 | "description": "Angular2 Starter",
5 | "main": "app.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1",
8 | "start2": "node ./server/build/app",
9 | "start": "gulp start"
10 | },
11 | "keywords": [
12 | "Angular2 Starter App",
13 | "Angular2 Starter Seed with Server",
14 | "Typed Angular2 Starter Seed with Server",
15 | "Typed Angular2 Stater App with Server"
16 | ],
17 | "author": "Yousuf Qutubuddin",
18 | "license": "ISC",
19 | "dependencies": {
20 | "angular2": "2.0.0-beta.3",
21 | "body-parser": "^1.14.2",
22 | "del": "^2.2.0",
23 | "es6-promise": "^3.0.2",
24 | "es6-shim": "^0.33.3",
25 | "express": "^4.13.4",
26 | "gulp": "^3.9.1",
27 | "gulp-nodemon": "^2.0.6",
28 | "gulp-open": "^1.0.0",
29 | "gulp-sequence": "^0.4.4",
30 | "gulp-typescript": "^2.10.0",
31 | "gulp-webserver": "^0.9.1",
32 | "mongoose": "^4.4.2",
33 | "reflect-metadata": "0.1.2",
34 | "rxjs": "5.0.0-beta.0",
35 | "socket.io": "^1.4.5",
36 | "socket.io-client": "^1.4.5",
37 | "systemjs": "0.19.6",
38 | "zone.js": "0.5.11"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/server/build/category/categoryController.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var categoryModel_1 = require("./categoryModel"); //import Member Class
3 | var user = new categoryModel_1.User();
4 | //Object
5 | var Controller = {
6 | CategorySave_post: function (req, res) {
7 | console.log(req.body, "ccccccccccccccccccccccccccc");
8 | var categoryObj = req.body;
9 | user.create(categoryObj, function (err, data) {
10 | if (err) {
11 | res.json({ 'success': false, 'data': null, 'error': err });
12 | }
13 | else {
14 | res.json({ 'success': true, 'data': data, 'error': null });
15 | }
16 | });
17 | },
18 | getAllUsers: function (req, res) {
19 | categoryModel_1.categoryModel.find({}, function (err, data) {
20 | console.log('controller err', err);
21 | console.log('controller data', data);
22 | if (err) {
23 | res.send({ 'success': false, 'data': null, 'error': err });
24 | }
25 | else {
26 | res.send({ 'success': true, 'data': data, 'error': err });
27 | }
28 | });
29 | },
30 | };
31 | module.exports = Controller;
32 |
--------------------------------------------------------------------------------
/client/src/app/components/rate/rateComponent.ts:
--------------------------------------------------------------------------------
1 | import { Component } from "angular2/core" ;
2 | import { Http, Response, RequestOptions, Headers } from 'angular2/http'; //for http request (rest API)
3 |
4 | @Component({
5 | selector : 'home',
6 | templateUrl : "./app/components/rate/rate.html"
7 | })
8 | export class RateComponent{
9 | rate : {}
10 | getData;
11 | constructor(public http: Http) {
12 | this.rate = {
13 | rates : "",
14 | rateDec: ""
15 | }
16 | this.http.get('/api/rate/getRate')
17 | .subscribe((res: Response) => {
18 | this.getData = res.json().data
19 | console.log(res.json().data)
20 | })
21 | }
22 |
23 |
24 | send(rate): void {
25 | let headers: Headers = new Headers();
26 | headers.append('Content-Type', 'application/json');
27 | let options: RequestOptions = new RequestOptions();
28 | options.headers = headers;
29 |
30 | this.http.post('/api/rate/Rate' ,JSON.stringify(rate), options)
31 |
32 | .subscribe((res: Response) => {
33 | console.log(res)
34 |
35 | });
36 |
37 | ; //http.post
38 |
39 | }
40 | // }
41 |
42 | }
--------------------------------------------------------------------------------
/server/build/selling/sellingModel.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var mongoose = require('mongoose'); //import mongodb
3 | //////////////////// Mongoose ////////////////////////
4 | //Creating Schema for User in MongoDB
5 | var userSchema = new mongoose.Schema({
6 | productName: String,
7 | unit: String
8 | });
9 | exports.sellingModel = mongoose.model("Selling", userSchema); //Create Collection with the name of Users (in db it shows Todos)
10 | //user class
11 | var User = (function () {
12 | function User() {
13 | }
14 | //constructor
15 | // constructor(user?: IUser) {
16 | // if (user) {
17 | // this.categoryName = user.categoryName
18 | // this.productName = user.productName
19 | // this.rate = user.rate
20 | // this.userName = user.userName
21 | // this.unit = user.unit
22 | // }
23 | // }
24 | //create user
25 | User.prototype.create = function (user, cb) {
26 | var Obj = new exports.sellingModel(user);
27 | Obj.save(function (error, data) {
28 | if (error) {
29 | cb(error, null);
30 | }
31 | cb(null, data);
32 | });
33 | };
34 | ;
35 | return User;
36 | }());
37 | exports.User = User;
38 |
--------------------------------------------------------------------------------
/server/src/rate/rateController.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import express = require("express");
3 | import {User, IUser,RateModel} from "./RateModel"; //import Member Class
4 |
5 |
6 | let user = new User();
7 |
8 | //Object
9 | let Controller = {
10 |
11 | RateSave_post: (req: express.Request, res: express.Response) => {
12 | console.log(req.body,"rrrrrrrrrrrrrrrrrrrrrrrrrrrrr")
13 | var Obj: IUser = req.body;
14 | user.create(Obj, (err, data) => {
15 | if (err) {
16 | res.json({ 'success': false, 'data': null, 'error': err });
17 | } else {
18 | res.json({ 'success': true, 'data': data, 'error': null });
19 | }
20 | });
21 | },
22 |
23 | getRate(req:express.Request, res:express.Response){
24 | RateModel.find({},(err,data) => {
25 | console.log('controller err',err)
26 | console.log('controller data',data)
27 | if(err){
28 | res.send({'success': false , 'data': null, 'error': err})
29 | }
30 | else{
31 | res.send({'success': true,'data': data, 'error': err })
32 | }
33 | })
34 |
35 | },
36 |
37 | };
38 |
39 | //export controller object
40 | export = Controller;
41 |
--------------------------------------------------------------------------------
/client/src/app/components/home/homeComponent.ts:
--------------------------------------------------------------------------------
1 | import { Component } from "angular2/core" ;
2 | import { Http, Response, RequestOptions, Headers } from 'angular2/http'; //for http request (rest API)
3 |
4 | @Component({
5 | selector : 'home',
6 | templateUrl : "./app/components/home/home.html"
7 | })
8 | export class HomeComponent{
9 | user : {}
10 | getData;
11 | constructor(public http: Http) {
12 | this.user = {
13 | fName : "",
14 | lName: "",
15 | type : ""
16 | }
17 | this.http.get('/api/user/getUser')
18 | .subscribe((res: Response) => {
19 | this.getData = res.json().data
20 | console.log(res.json().data)
21 | })
22 | }
23 |
24 |
25 | send(user): void {
26 | let headers: Headers = new Headers();
27 | headers.append('Content-Type', 'application/json');
28 | let options: RequestOptions = new RequestOptions();
29 | options.headers = headers;
30 |
31 | this.http.post('/api/user/User' ,JSON.stringify(user), options)
32 |
33 | .subscribe((res: Response) => {
34 | console.log("Create User :",res)
35 |
36 | });
37 |
38 | ; //http.post
39 |
40 | }
41 | // }
42 |
43 | }
--------------------------------------------------------------------------------
/server/src/user/userController.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import express = require("express");
3 | import {User, IUser,userModel} from "./userModel"; //import Member Class
4 |
5 |
6 | let user = new User();
7 |
8 | //Object
9 | let Controller = {
10 |
11 | UserSave_post: (req: express.Request, res: express.Response) => {
12 | console.log(req.body,"uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu")
13 | var userObj: IUser = req.body;
14 | user.create(userObj, (err, data) => {
15 | if (err) {
16 | res.json({ 'success': false, 'data': null, 'error': err });
17 | } else {
18 | res.json({ 'success': true, 'data': data, 'error': null });
19 | }
20 | });
21 | },
22 |
23 | getAllUsers(req:express.Request, res:express.Response){
24 | userModel.find({},(err,data) => {
25 | console.log('controller err',err)
26 | console.log('controller data',data)
27 | if(err){
28 | res.send({'success': false , 'data': null, 'error': err})
29 | }
30 | else{
31 | res.send({'success': true,'data': data, 'error': err })
32 | }
33 | })
34 |
35 | },
36 |
37 | };
38 |
39 | //export controller object
40 | export = Controller;
41 |
--------------------------------------------------------------------------------
/client/src/app/components/category/categoryComponent.ts:
--------------------------------------------------------------------------------
1 | import { Component } from "angular2/core" ;
2 | import { Http, Response, RequestOptions, Headers } from 'angular2/http'; //for http request (rest API)
3 |
4 | @Component({
5 | selector : 'home',
6 | templateUrl : "./app/components/category/category.html"
7 | })
8 | export class CategoryComponent{
9 | user : {}
10 | getData;
11 | constructor(public http: Http) {
12 | this.user = {
13 | categoryName : "",
14 | categoryDec: ""
15 | }
16 | this.http.get('/api/getCategory')
17 | .subscribe((res: Response) => {
18 | this.getData = res.json().data
19 | console.log(res.json().data)
20 | })
21 | }
22 |
23 |
24 | send(user): void {
25 | let headers: Headers = new Headers();
26 | headers.append('Content-Type', 'application/json');
27 | let options: RequestOptions = new RequestOptions();
28 | options.headers = headers;
29 |
30 | this.http.post('/api/Category' ,JSON.stringify(user), options)
31 |
32 | .subscribe((res: Response) => {
33 | console.log("Create Category : ",res)
34 |
35 | });
36 |
37 | ; //http.post
38 |
39 | }
40 | // }
41 |
42 | }
--------------------------------------------------------------------------------
/server/src/product/productController.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import express = require("express");
3 | import {User, IUser,ProductModel} from "./ProductModel"; //import Member Class
4 |
5 |
6 | let user = new User();
7 |
8 | //Object
9 | let Controller = {
10 |
11 | ProductSave_post: (req: express.Request, res: express.Response) => {
12 | console.log(req.body,"pppppppppppppppppppppppppppp")
13 | var Obj: IUser = req.body;
14 | user.create(Obj, (err, data) => {
15 | if (err) {
16 | res.json({ 'success': false, 'data': null, 'error': err });
17 | } else {
18 | res.json({ 'success': true, 'data': data, 'error': null });
19 | }
20 | });
21 | },
22 |
23 | getAllgetProducts(req:express.Request, res:express.Response){
24 | ProductModel.find({},(err,data) => {
25 | console.log('controller err',err)
26 | console.log('controller data',data)
27 | if(err){
28 | res.send({'success': false , 'data': null, 'error': err})
29 | }
30 | else{
31 | res.send({'success': true,'data': data, 'error': err })
32 | }
33 | })
34 |
35 | },
36 |
37 | };
38 |
39 | //export controller object
40 | export = Controller;
41 |
--------------------------------------------------------------------------------
/server/src/selling/sellingController.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import express = require("express");
3 | import {User, IUser,sellingModel} from "./sellingModel"; //import Member Class
4 |
5 |
6 | let user = new User();
7 |
8 | //Object
9 | let Controller = {
10 |
11 | sellingSave_post: (req: express.Request, res: express.Response) => {
12 | console.log(req.body,"ssssssssssssssssssssssss")
13 | var Obj: IUser = req.body;
14 |
15 | user.create(Obj, (err, data) => {
16 | if (err) {
17 | res.json({ 'success': false, 'data': null, 'error': err });
18 | } else {
19 | res.json({ 'success': true, 'data': data, 'error': null });
20 | }
21 | });
22 | },
23 |
24 | getSeller(req:express.Request, res:express.Response){
25 | sellingModel.find({},(err,data) => {
26 | console.log('controller err',err)
27 | console.log('controller data',data)
28 | if(err){
29 | res.send({'success': false , 'data': null, 'error': err})
30 | }
31 | else{
32 | res.send({'success': true,'data': data, 'error': err })
33 | }
34 | })
35 |
36 | },
37 |
38 | };
39 |
40 | //export controller object
41 | export = Controller;
42 |
--------------------------------------------------------------------------------
/server/build/inventry/inventryModel.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var mongoose = require('mongoose'); //import mongodb
3 | //////////////////// Mongoose ////////////////////////
4 | //Creating Schema for User in MongoDB
5 | var userSchema = new mongoose.Schema({
6 | categoryName: String,
7 | productName: String,
8 | rate: String,
9 | userName: String,
10 | unit: String
11 | });
12 | exports.InventryModel = mongoose.model("Inventry", userSchema); //Create Collection with the name of Users (in db it shows Todos)
13 | //user class
14 | var User = (function () {
15 | //constructor
16 | function User(user) {
17 | if (user) {
18 | this.categoryName = user.categoryName;
19 | this.productName = user.productName;
20 | this.rate = user.rate;
21 | this.userName = user.userName;
22 | this.unit = user.unit;
23 | }
24 | }
25 | //create user
26 | User.prototype.create = function (user, cb) {
27 | var Obj = new exports.InventryModel(user);
28 | console.log("Checking DATA", Obj);
29 | Obj.save(function (error, data) {
30 | if (error) {
31 | cb(error, null);
32 | }
33 | cb(null, data);
34 | });
35 | };
36 | ;
37 | return User;
38 | }());
39 | exports.User = User;
40 |
--------------------------------------------------------------------------------
/server/src/category/categoryController.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import express = require("express");
3 | import {User, IUser,categoryModel} from "./categoryModel"; //import Member Class
4 |
5 |
6 | let user = new User();
7 |
8 | //Object
9 | let Controller = {
10 |
11 | CategorySave_post: (req: express.Request, res: express.Response) => {
12 | console.log(req.body,"ccccccccccccccccccccccccccc")
13 | var categoryObj: IUser = req.body;
14 | user.create(categoryObj, (err, data) => {
15 | if (err) {
16 | res.json({ 'success': false, 'data': null, 'error': err });
17 | } else {
18 | res.json({ 'success': true, 'data': data, 'error': null });
19 | }
20 | });
21 | },
22 |
23 | getAllUsers(req:express.Request, res:express.Response){
24 | categoryModel.find({},(err,data) => {
25 | console.log('controller err',err)
26 | console.log('controller data',data)
27 | if(err){
28 | res.send({'success': false , 'data': null, 'error': err})
29 | }
30 | else{
31 | res.send({'success': true,'data': data, 'error': err })
32 | }
33 | })
34 |
35 | },
36 |
37 | };
38 |
39 | //export controller object
40 | export = Controller;
41 |
--------------------------------------------------------------------------------
/server/src/inventry/inventryController.ts:
--------------------------------------------------------------------------------
1 | ///
2 | import express = require("express");
3 | import {User, IUser,InventryModel} from "./InventryModel"; //import Member Class
4 |
5 |
6 | let user = new User();
7 |
8 | //Object
9 | let Controller = {
10 |
11 | InventrySave_post: (req: express.Request, res: express.Response) => {
12 | console.log(req.body,"iiiiiiiiiiiiiiiiiiiiiiiiiiiiii")
13 | var Obj: IUser = req.body;
14 |
15 | user.create(Obj, (err, data) => {
16 | if (err) {
17 | res.json({ 'success': false, 'data': null, 'error': err });
18 | } else {
19 | res.json({ 'success': true, 'data': data, 'error': null });
20 | }
21 | });
22 | },
23 |
24 | getInventry(req:express.Request, res:express.Response){
25 | InventryModel.find({},(err,data) => {
26 | console.log('controller err',err)
27 | console.log('controller data',data)
28 | if(err){
29 | res.send({'success': false , 'data': null, 'error': err})
30 | }
31 | else{
32 | res.send({'success': true,'data': data, 'error': err })
33 | }
34 | })
35 |
36 | },
37 |
38 | };
39 |
40 | //export controller object
41 | export = Controller;
42 |
--------------------------------------------------------------------------------
/server/src/helpers/helper.ts:
--------------------------------------------------------------------------------
1 | import * as _User from './../category/categoryModel';
2 |
3 |
4 | //create type for callback function
5 | export type CallBackFunction = (error, data) => void;
6 |
7 | //for response of api
8 | export type customServerResponseObject = { 'success': boolean, 'data': any, 'error': any };
9 |
10 |
11 |
12 |
13 |
14 |
15 | function CreateCategory(cb) {
16 | var u1: _User.IUser = {categoryName: 'MuZz', categoryDec : "Something"};
17 | var userObj = new _User.User(u1);
18 |
19 | //checking user exists or not
20 | _User.User.isUserExists(userObj.categoryName, (error, result) => {
21 | console.log('user -- exists?', error);
22 | if (!error) {
23 | userObj.create(userObj, (err, data: _User.IUser) => {
24 | if (err) {
25 | console.log('User Create Err');
26 | console.log(err)
27 | cb(false);
28 | } else {
29 | console.log('User Created');
30 | console.log(data);
31 |
32 | }
33 | }); //userObj.create
34 | } else {
35 | console.log('User/Member not created...Err!');
36 | console.log(error);
37 | cb(false);
38 | }
39 | }); //User.isUserExists
40 | } //CreateUserAndMember
--------------------------------------------------------------------------------
/client/src/app/components/form/formComponent.ts:
--------------------------------------------------------------------------------
1 | import {Component} from "angular2/core";
2 | import {FormBuilder, Validators, ControlGroup, Control} from "angular2/common";
3 | import {UsernameValidator} from "./customValidator";
4 |
5 |
6 |
7 |
8 |
9 | @Component({
10 | selector: "form-page",
11 | templateUrl: "./app/components/form/form.html"
12 | })
13 | export class FormComponent {
14 |
15 | name: Control;
16 | email: Control;
17 | email2: Control;
18 | password: Control;
19 |
20 | loginForm: ControlGroup;
21 |
22 | constructor(private fb: FormBuilder) {
23 | this.email = new Control("", Validators.required);
24 | this.email2 = new Control("", UsernameValidator.emailValidation);
25 | this.name = new Control( "", Validators.compose([Validators.required, UsernameValidator.startsWithNumber]) );
26 | this.password = new Control( "", Validators.compose([Validators.required, Validators.minLength(4)]) );
27 |
28 | this.loginForm = this.fb.group({
29 | "email": this.email,
30 | "email2": this.email2,
31 | "name": this.name,
32 | "password": this.password
33 | });
34 | }
35 |
36 | doLogin(event) {
37 | if (this.loginForm.dirty && this.loginForm.valid) {
38 | console.log(this.loginForm.value);
39 | event.preventDefault();
40 | }
41 | }
42 |
43 | }
--------------------------------------------------------------------------------
/client/src/app/components/selling/selling.html:
--------------------------------------------------------------------------------
1 | Selling
2 |
3 |
30 |
31 |
32 |
33 |
34 |
35 |
Storing Data
36 |
37 |
38 |
39 | | Products |
40 | Unit |
41 |
42 |
43 |
44 |
45 | | {{get.productName}} |
46 | {{get.unit}} |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/client/build/app/components/selling/selling.html:
--------------------------------------------------------------------------------
1 | Selling
2 |
3 |
30 |
31 |
32 |
33 |
34 |
35 |
Storing Data
36 |
37 |
38 |
39 | | Products |
40 | Unit |
41 |
42 |
43 |
44 |
45 | | {{get.productName}} |
46 | {{get.unit}} |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/client/build/app/components/form/customValidator.js:
--------------------------------------------------------------------------------
1 | System.register([], function(exports_1, context_1) {
2 | "use strict";
3 | var __moduleName = context_1 && context_1.id;
4 | var UsernameValidator;
5 | return {
6 | setters:[],
7 | execute: function() {
8 | UsernameValidator = (function () {
9 | function UsernameValidator() {
10 | }
11 | UsernameValidator.startsWithNumber = function (control) {
12 | if (control.value !== "" && !isNaN(control.value.charAt(0))) {
13 | return { "startsWithNumber": true };
14 | }
15 | return null;
16 | };
17 | UsernameValidator.emailValidation = function (control) {
18 | var pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/;
19 | if (control.value !== "" && !control.value.match(pattern)) {
20 | return { "emailValidation": true };
21 | }
22 | return null;
23 | };
24 | return UsernameValidator;
25 | }());
26 | exports_1("UsernameValidator", UsernameValidator);
27 | }
28 | }
29 | });
30 | // One weird thing you might notice is that returning null actually means the validation is valid.
31 | // If we find a number at the first position of the string we return the validation error { “startsWithNumber”: true }
32 |
--------------------------------------------------------------------------------
/client/build/app/components/product/product.html:
--------------------------------------------------------------------------------
1 | Product
2 |
3 |
4 |
5 |
6 |
7 |
17 |
18 |
22 |
23 |
24 |
25 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | | Category: {{get.categoryName}} |
39 | Name: {{get.productName}} |
40 | Dec: {{get.productDec}} |
41 | Unit : {{get.unit}} |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/client/src/app/components/product/product.html:
--------------------------------------------------------------------------------
1 | Product
2 |
3 |
4 |
5 |
6 |
7 |
17 |
18 |
22 |
23 |
24 |
25 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 | | Category: {{get.categoryName}} |
39 | Name: {{get.productName}} |
40 | Dec: {{get.productDec}} |
41 | Unit : {{get.unit}} |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/client/src/app/components/socket/socketService.ts:
--------------------------------------------------------------------------------
1 | import {Injectable} from 'angular2/core';
2 |
3 | declare var io: any;
4 |
5 | @Injectable()
6 | export class SocketService {
7 |
8 | socket: any;
9 | host: string;
10 | fruits: [string] = ['Pineapple'];
11 |
12 | constructor () {
13 |
14 | this.host = window.location.origin;
15 | console.log("WEBSOCKET connecting to", this.host);
16 |
17 | this.socket = io();
18 |
19 | //getting all last record from server if restored or default array
20 | this.get();
21 |
22 | //listing if add fruit on server then server emits the fruit name
23 | this.socket.on("addedFruit", (data) => {
24 | this.fruits.push(data);
25 | console.log('addedFruit this.fruits', this.fruits);
26 | });
27 | }
28 |
29 |
30 | add(fruitName): void {
31 | this.socket.emit('addFruit', fruitName);
32 | }
33 |
34 | getAllFruits() {
35 | return this.fruits;
36 | }
37 |
38 | get(): void {
39 |
40 | //catching from sever when it emits (all fruits)..
41 | this.socket.on('getAllFruits', (data)=>{
42 | ///this.fruits = data;
43 | console.log('getAllFruits: ', data);
44 | });
45 |
46 | //sending request to fire all fruits from server and catching from server events (getAllFruits)
47 | this.socket.emit('getFruits', null);
48 | }
49 |
50 |
51 | }
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 | // let host = window.location.origin;
60 | // console.log("WEBSOCKET connecting to", host);
--------------------------------------------------------------------------------
/client/build/app/boot.js:
--------------------------------------------------------------------------------
1 | System.register(["angular2/core", "angular2/platform/browser", "angular2/http", "angular2/router", "angular2/common", "./components/socket/socketService", "./components/app/appComponent"], function(exports_1, context_1) {
2 | "use strict";
3 | var __moduleName = context_1 && context_1.id;
4 | var core_1, browser_1, http_1, router_1, common_1, socketService_1, appComponent_1;
5 | return {
6 | setters:[
7 | function (core_1_1) {
8 | core_1 = core_1_1;
9 | },
10 | function (browser_1_1) {
11 | browser_1 = browser_1_1;
12 | },
13 | function (http_1_1) {
14 | http_1 = http_1_1;
15 | },
16 | function (router_1_1) {
17 | router_1 = router_1_1;
18 | },
19 | function (common_1_1) {
20 | common_1 = common_1_1;
21 | },
22 | function (socketService_1_1) {
23 | socketService_1 = socketService_1_1;
24 | },
25 | function (appComponent_1_1) {
26 | appComponent_1 = appComponent_1_1;
27 | }],
28 | execute: function() {
29 | // Bootstraping
30 | browser_1.bootstrap(appComponent_1.AppComponent, [
31 | router_1.ROUTER_PROVIDERS,
32 | http_1.HTTP_PROVIDERS,
33 | common_1.FORM_PROVIDERS,
34 | socketService_1.SocketService,
35 | core_1.provide(router_1.LocationStrategy, { useClass: router_1.HashLocationStrategy }) // angular hashing urls
36 | ]);
37 | }
38 | }
39 | });
40 |
--------------------------------------------------------------------------------
/client/src/app/components/app/appComponent.ts:
--------------------------------------------------------------------------------
1 | import { Component } from "angular2/core";
2 | import { ROUTER_DIRECTIVES, RouteConfig} from "angular2/router";
3 |
4 | // import { Menu } from "./../menu/menu";
5 | import { HomeComponent } from "./../home/homeComponent";
6 | import { ProductComponent } from "./../product/productComponent";
7 | import { RateComponent } from "./../rate/rateComponent";
8 | import { inventryComponent } from "./../inventry/inventryComponent";
9 | import { CategoryComponent } from "./../category/categoryComponent";
10 | import { ApiComponent } from "./../testApi/apiComponent";
11 | import { SocketComponent } from "./../socket/socketComponent";
12 | import { FormComponent } from "./../form/formComponent";
13 | import {SellingComponent} from "./../selling/sellingComponent"
14 |
15 | @Component({
16 | selector: "start-app",
17 | templateUrl: "./app/components/app/app.html",
18 | directives: [ROUTER_DIRECTIVES]
19 | })
20 | @RouteConfig([
21 | // { path : "/", redirectTo : ["Home"] },
22 | { path: "/home", name: "Home", component: HomeComponent, useAsDefault: true },
23 | { path: "/category", name: "Category", component: CategoryComponent },
24 | { path: "/product", name: "Product", component: ProductComponent },
25 | { path: "/rate", name: "Rate", component: RateComponent },
26 | { path: "/inventry", name: "Inventry", component: inventryComponent },
27 | {path : "/seller" , name : "Seller", component: SellingComponent},
28 | { path: "/form", name: "Form", component: FormComponent },
29 | { path: "/testApi", name: "TestApi", component: ApiComponent },
30 | { path: "/scoket", name: "Socket", component: SocketComponent }
31 | ])
32 | export class AppComponent {
33 |
34 | constructor() {
35 |
36 | }
37 |
38 | }
--------------------------------------------------------------------------------
/client/src/app/components/product/productComponent.ts:
--------------------------------------------------------------------------------
1 | import { Component } from "angular2/core" ;
2 | import { Http, Response, RequestOptions, Headers } from 'angular2/http'; //for http request (rest API)
3 |
4 |
5 | @Component({
6 | selector : 'about',
7 | templateUrl : "./app/components/product/product.html"
8 | })
9 | export class ProductComponent{
10 | product : {}
11 | getProduct;
12 | getCategory;
13 | constructor(public http: Http) {
14 | this.product = {
15 | productName : "",
16 | priductDec: "",
17 | categoryName : "",
18 | unit : ""
19 | }
20 |
21 | this.http.get('/api/getProducts') /// get Products...
22 | .subscribe((res: Response) => {
23 | this.getProduct = res.json().data
24 | console.log(res.json().data)
25 | })
26 |
27 |
28 |
29 | this.http.get('/api/getCategory') /// GEt Category..
30 | .subscribe((res: Response) => {
31 | this.getCategory = res.json().data
32 | console.log(res.json().data)
33 | })
34 | }
35 |
36 |
37 | send(product): void {
38 | console.log(product)
39 | let headers: Headers = new Headers();
40 | headers.append('Content-Type', 'application/json');
41 | let options: RequestOptions = new RequestOptions();
42 | options.headers = headers;
43 |
44 | this.http.post('/api/Category' ,JSON.stringify(this.product), options)
45 |
46 | .subscribe((res: Response) => {
47 | console.log("Craete Products: ",res)
48 |
49 | });
50 |
51 | ; //http.post
52 |
53 | }
54 | // }
55 | }
--------------------------------------------------------------------------------
/server/src/selling/sellingModel.ts:
--------------------------------------------------------------------------------
1 | import mongoose = require('mongoose'); //import mongodb
2 | import * as helper from './../helpers/helper';
3 | //import q = require('q');
4 | //if using promise pattren
5 |
6 | //interface of user
7 | export interface IUser {
8 | productName: string;
9 | unit: string
10 | }
11 |
12 |
13 |
14 |
15 | //////////////////// Mongoose ////////////////////////
16 | //Creating Schema for User in MongoDB
17 | let userSchema = new mongoose.Schema({ //Create Schema for User Collection
18 | productName: String,
19 | unit: String
20 | });
21 |
22 | export const sellingModel = mongoose.model("Selling", userSchema); //Create Collection with the name of Users (in db it shows Todos)
23 |
24 |
25 |
26 | //user class
27 | export class User implements IUser {
28 | productName: string;
29 | unit: string
30 |
31 | //constructor
32 | // constructor(user?: IUser) {
33 | // if (user) {
34 | // this.categoryName = user.categoryName
35 | // this.productName = user.productName
36 | // this.rate = user.rate
37 | // this.userName = user.userName
38 | // this.unit = user.unit
39 | // }
40 | // }
41 |
42 |
43 |
44 | //create user
45 | create(user: IUser, cb: helper.CallBackFunction): void {
46 | let Obj = new sellingModel(user);
47 |
48 | Obj.save((error, data: IUser) => {
49 | if (error) {
50 | cb(error, null);
51 | }
52 | cb(null, data);
53 | });
54 |
55 |
56 | }; // create user
57 |
58 |
59 |
60 |
61 | // getInventry(req,res){
62 | // InventryModel.find({}, (err,data) => {
63 | // if (err) {
64 | // //if error on finding user
65 | // res.send("Error")
66 | // } else {
67 | // res.send(data)
68 | // }
69 |
70 | // });
71 | // };
72 | }
--------------------------------------------------------------------------------
/client/build/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Angular2 - Task Management
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
35 |
36 |
37 |
38 |
39 | Loading.......
40 |
41 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |