From c0042d1505d15b4644e781e16da17a52c28e5f3b Mon Sep 17 00:00:00 2001 From: mohiit1502 Date: Tue, 8 May 2018 23:33:13 +0530 Subject: [PATCH] Merged UI and backend --- ._.bowerrc | Bin 0 -> 4096 bytes ._.gitignore | Bin 0 -> 4096 bytes ._.jshintrc | Bin 0 -> 4096 bytes ._.travis.yml | Bin 0 -> 4096 bytes ._LICENSE | Bin 0 -> 4096 bytes ._README.md | Bin 0 -> 4096 bytes ._bower.json | Bin 0 -> 4096 bytes ._karma.conf.js | Bin 0 -> 4096 bytes ._package.json | Bin 0 -> 4096 bytes .bowerrc | 3 + .gitignore | 113 ++++++++++++- .jshintrc | 13 ++ .travis.yml | 14 ++ README.md | 297 +++++++++++++++++++++++++++++++++++ app/._app.css | Bin 0 -> 4096 bytes app/._app.js | Bin 0 -> 4096 bytes app/._index-async.html | Bin 0 -> 4096 bytes app/._index.html | Bin 0 -> 4096 bytes app/__init__.py | 8 + app/api.py | 131 +++++++++++++++ app/app.css | 70 +++++++++ app/app.js | 12 ++ app/facebook/._facebook.html | Bin 0 -> 4096 bytes app/facebook/._facebook.js | Bin 0 -> 4096 bytes app/facebook/facebook.html | 59 +++++++ app/facebook/facebook.js | 75 +++++++++ app/index-async.html | 58 +++++++ app/index.html | 49 ++++++ app/models/__init__.py | 0 app/models/product.py | 45 ++++++ app/models/user.py | 112 +++++++++++++ app/static/admin.html | 32 ++++ app/static/blocks.css | 84 ++++++++++ app/templates/cart.html | 23 +++ app/templates/index.html | 64 ++++++++ app/templates/profile.html | 11 ++ app/templates/results.html | 93 +++++++++++ app/templates/users.html | 38 +++++ app/view1/._view1.html | Bin 0 -> 4096 bytes app/view1/._view1.js | Bin 0 -> 4096 bytes app/view1/._view1_test.js | Bin 0 -> 4096 bytes app/view1/view1.html | 1 + app/view1/view1.js | 14 ++ app/view1/view1_test.js | 16 ++ app/view2/._view2.html | Bin 0 -> 4096 bytes app/view2/._view2.js | Bin 0 -> 4096 bytes app/view2/._view2_test.js | Bin 0 -> 4096 bytes app/view2/view2.html | 5 + app/view2/view2.js | 14 ++ app/view2/view2_test.js | 16 ++ app/views.py | 7 + bower.json | 15 ++ config.json | 7 + karma.conf.js | 33 ++++ package.json | 34 ++++ run.py | 6 + 56 files changed, 1571 insertions(+), 1 deletion(-) create mode 100644 ._.bowerrc create mode 100644 ._.gitignore create mode 100644 ._.jshintrc create mode 100644 ._.travis.yml create mode 100644 ._LICENSE create mode 100644 ._README.md create mode 100644 ._bower.json create mode 100644 ._karma.conf.js create mode 100644 ._package.json create mode 100644 .bowerrc create mode 100644 .jshintrc create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 app/._app.css create mode 100644 app/._app.js create mode 100644 app/._index-async.html create mode 100644 app/._index.html create mode 100644 app/__init__.py create mode 100644 app/api.py create mode 100644 app/app.css create mode 100644 app/app.js create mode 100644 app/facebook/._facebook.html create mode 100644 app/facebook/._facebook.js create mode 100644 app/facebook/facebook.html create mode 100644 app/facebook/facebook.js create mode 100644 app/index-async.html create mode 100644 app/index.html create mode 100644 app/models/__init__.py create mode 100644 app/models/product.py create mode 100644 app/models/user.py create mode 100644 app/static/admin.html create mode 100644 app/static/blocks.css create mode 100644 app/templates/cart.html create mode 100644 app/templates/index.html create mode 100644 app/templates/profile.html create mode 100644 app/templates/results.html create mode 100644 app/templates/users.html create mode 100644 app/view1/._view1.html create mode 100644 app/view1/._view1.js create mode 100644 app/view1/._view1_test.js create mode 100644 app/view1/view1.html create mode 100644 app/view1/view1.js create mode 100644 app/view1/view1_test.js create mode 100644 app/view2/._view2.html create mode 100644 app/view2/._view2.js create mode 100644 app/view2/._view2_test.js create mode 100644 app/view2/view2.html create mode 100644 app/view2/view2.js create mode 100644 app/view2/view2_test.js create mode 100644 app/views.py create mode 100644 bower.json create mode 100644 config.json create mode 100644 karma.conf.js create mode 100644 package.json create mode 100644 run.py diff --git a/._.bowerrc b/._.bowerrc new file mode 100644 index 0000000000000000000000000000000000000000..fafd92fe096b2da23f24ab391a9197a02fe26763 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;FvU8^ zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;FvU8^ zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;FvU8^ zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;FvU8^ zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB) /dev/null & + - npm run update-webdriver + - sleep 1 # give server time to start + +script: + - node_modules/.bin/karma start karma.conf.js --no-auto-watch --single-run --reporters=dots --browsers=Firefox + - node_modules/.bin/protractor e2e-tests/protractor.conf.js --browser=firefox diff --git a/README.md b/README.md new file mode 100644 index 0000000..e7aece1 --- /dev/null +++ b/README.md @@ -0,0 +1,297 @@ +# angular-seed — the seed for AngularJS apps + +This project is an application skeleton for a typical [AngularJS](http://angularjs.org/) web app. +You can use it to quickly bootstrap your angular webapp projects and dev environment for these +projects. + +The seed contains a sample AngularJS application and is preconfigured to install the Angular +framework and a bunch of development and testing tools for instant web development gratification. + +The seed app doesn't do much, just shows how to wire two controllers and views together. + + +## Getting Started + +To get you started you can simply clone the angular-seed repository and install the dependencies: + +### Prerequisites + +You need git to clone the angular-seed repository. You can get git from +[http://git-scm.com/](http://git-scm.com/). + +We also use a number of node.js tools to initialize and test angular-seed. You must have node.js and +its package manager (npm) installed. You can get them from [http://nodejs.org/](http://nodejs.org/). + +### Clone angular-seed + +Clone the angular-seed repository using [git][git]: + +``` +git clone https://github.com/angular/angular-seed.git +cd angular-seed +``` + +If you just want to start a new project without the angular-seed commit history then you can do: + +```bash +git clone --depth=1 https://github.com/angular/angular-seed.git +``` + +The `depth=1` tells git to only pull down one commit worth of historical data. + +### Install Dependencies + +We have two kinds of dependencies in this project: tools and angular framework code. The tools help +us manage and test the application. + +* We get the tools we depend upon via `npm`, the [node package manager][npm]. +* We get the angular code via `bower`, a [client-side code package manager][bower]. + +We have preconfigured `npm` to automatically run `bower` so we can simply do: + +``` +npm install +``` + +Behind the scenes this will also call `bower install`. You should find that you have two new +folders in your project. + +* `node_modules` - contains the npm packages for the tools we need +* `app/bower_components` - contains the angular framework files + +*Note that the `bower_components` folder would normally be installed in the root folder but +angular-seed changes this location through the `.bowerrc` file. Putting it in the app folder makes +it easier to serve the files by a webserver.* + +### Run the Application + +We have preconfigured the project with a simple development web server. The simplest way to start +this server is: + +``` +npm start +``` + +Now browse to the app at `http://localhost:8000/app/index.html`. + + + +## Directory Layout + +``` +app/ --> all of the source files for the application + app.css --> default stylesheet + components/ --> all app specific modules + version/ --> version related components + version.js --> version module declaration and basic "version" value service + version_test.js --> "version" value service tests + version-directive.js --> custom directive that returns the current app version + version-directive_test.js --> version directive tests + interpolate-filter.js --> custom interpolation filter + interpolate-filter_test.js --> interpolate filter tests + view1/ --> the view1 view template and logic + view1.html --> the partial template + view1.js --> the controller logic + view1_test.js --> tests of the controller + view2/ --> the view2 view template and logic + view2.html --> the partial template + view2.js --> the controller logic + view2_test.js --> tests of the controller + app.js --> main application module + index.html --> app layout file (the main html template file of the app) + index-async.html --> just like index.html, but loads js files asynchronously +karma.conf.js --> config file for running unit tests with Karma +e2e-tests/ --> end-to-end tests + protractor-conf.js --> Protractor config file + scenarios.js --> end-to-end scenarios to be run by Protractor +``` + +## Testing + +There are two kinds of tests in the angular-seed application: Unit tests and End to End tests. + +### Running Unit Tests + +The angular-seed app comes preconfigured with unit tests. These are written in +[Jasmine][jasmine], which we run with the [Karma Test Runner][karma]. We provide a Karma +configuration file to run them. + +* the configuration is found at `karma.conf.js` +* the unit tests are found next to the code they are testing and are named as `..._test.js`. + +The easiest way to run the unit tests is to use the supplied npm script: + +``` +npm test +``` + +This script will start the Karma test runner to execute the unit tests. Moreover, Karma will sit and +watch the source and test files for changes and then re-run the tests whenever any of them change. +This is the recommended strategy; if your unit tests are being run every time you save a file then +you receive instant feedback on any changes that break the expected code functionality. + +You can also ask Karma to do a single run of the tests and then exit. This is useful if you want to +check that a particular version of the code is operating as expected. The project contains a +predefined script to do this: + +``` +npm run test-single-run +``` + + +### End to end testing + +The angular-seed app comes with end-to-end tests, again written in [Jasmine][jasmine]. These tests +are run with the [Protractor][protractor] End-to-End test runner. It uses native events and has +special features for Angular applications. + +* the configuration is found at `e2e-tests/protractor-conf.js` +* the end-to-end tests are found in `e2e-tests/scenarios.js` + +Protractor simulates interaction with our web app and verifies that the application responds +correctly. Therefore, our web server needs to be serving up the application, so that Protractor +can interact with it. + +``` +npm start +``` + +In addition, since Protractor is built upon WebDriver we need to install this. The angular-seed +project comes with a predefined script to do this: + +``` +npm run update-webdriver +``` + +This will download and install the latest version of the stand-alone WebDriver tool. + +Once you have ensured that the development web server hosting our application is up and running +and WebDriver is updated, you can run the end-to-end tests using the supplied npm script: + +``` +npm run protractor +``` + +This script will execute the end-to-end tests against the application being hosted on the +development server. + + +## Updating Angular + +Previously we recommended that you merge in changes to angular-seed into your own fork of the project. +Now that the angular framework library code and tools are acquired through package managers (npm and +bower) you can use these tools instead to update the dependencies. + +You can update the tool dependencies by running: + +``` +npm update +``` + +This will find the latest versions that match the version ranges specified in the `package.json` file. + +You can update the Angular dependencies by running: + +``` +bower update +``` + +This will find the latest versions that match the version ranges specified in the `bower.json` file. + + +## Loading Angular Asynchronously + +The angular-seed project supports loading the framework and application scripts asynchronously. The +special `index-async.html` is designed to support this style of loading. For it to work you must +inject a piece of Angular JavaScript into the HTML page. The project has a predefined script to help +do this. + +``` +npm run update-index-async +``` + +This will copy the contents of the `angular-loader.js` library file into the `index-async.html` page. +You can run this every time you update the version of Angular that you are using. + + +## Serving the Application Files + +While angular is client-side-only technology and it's possible to create angular webapps that +don't require a backend server at all, we recommend serving the project files using a local +webserver during development to avoid issues with security restrictions (sandbox) in browsers. The +sandbox implementation varies between browsers, but quite often prevents things like cookies, xhr, +etc to function properly when an html page is opened via `file://` scheme instead of `http://`. + + +### Running the App during Development + +The angular-seed project comes preconfigured with a local development webserver. It is a node.js +tool called [http-server][http-server]. You can start this webserver with `npm start` but you may choose to +install the tool globally: + +``` +sudo npm install -g http-server +``` + +Then you can start your own development web server to serve static files from a folder by +running: + +``` +http-server -a localhost -p 8000 +``` + +Alternatively, you can choose to configure your own webserver, such as apache or nginx. Just +configure your server to serve the files under the `app/` directory. + + +### Running the App in Production + +This really depends on how complex your app is and the overall infrastructure of your system, but +the general rule is that all you need in production are all the files under the `app/` directory. +Everything else should be omitted. + +Angular apps are really just a bunch of static html, css and js files that just need to be hosted +somewhere they can be accessed by browsers. + +If your Angular app is talking to the backend server via xhr or other means, you need to figure +out what is the best way to host the static files to comply with the same origin policy if +applicable. Usually this is done by hosting the files by the backend server or through +reverse-proxying the backend server(s) and webserver(s). + + +## Continuous Integration + +### Travis CI + +[Travis CI][travis] is a continuous integration service, which can monitor GitHub for new commits +to your repository and execute scripts such as building the app or running tests. The angular-seed +project contains a Travis configuration file, `.travis.yml`, which will cause Travis to run your +tests when you push to GitHub. + +You will need to enable the integration between Travis and GitHub. See the Travis website for more +instruction on how to do this. + +### CloudBees + +CloudBees have provided a CI/deployment setup: + + + + +If you run this, you will get a cloned version of this repo to start working on in a private git repo, +along with a CI service (in Jenkins) hosted that will run unit and end to end tests in both Firefox and Chrome. + + +## Contact + +For more information on AngularJS please check out http://angularjs.org/ + +[git]: http://git-scm.com/ +[bower]: http://bower.io +[npm]: https://www.npmjs.org/ +[node]: http://nodejs.org +[protractor]: https://github.com/angular/protractor +[jasmine]: http://jasmine.github.io +[karma]: http://karma-runner.github.io +[travis]: https://travis-ci.org/ +[http-server]: https://github.com/nodeapps/http-server diff --git a/app/._app.css b/app/._app.css new file mode 100644 index 0000000000000000000000000000000000000000..fafd92fe096b2da23f24ab391a9197a02fe26763 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;FvU8^ zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;FvU8^ zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB)', methods=['GET', 'POST']) +def user_actions(action): + if action == 'login': + user = User(None, None, request.form.get('username'), request.form.get('password')) + is_valid = mongo_user.authenticate(user) + name = mongo_user.find_user_name_by_credentials(user) + if is_valid is not None and is_valid: + return render_template('profile.html', sign_up_msg="Welcome to Mini-Amazon", name = name if name is not None else "Anonymous", user_id=mongo_user.get_id_by_username(request.form.get('username'))) + else: + return render_template("index.html", message="Invalid Username/Password") + elif action == 'signup': + user = dict() + user['name'] = request.form.get('name') + user['email'] = request.form.get('email') + user['username'] = request.form.get('username') + user['password'] = request.form.get('password') + does_user_exist = mongo_user.check_if_user_exists(request.form.get('username')) + if does_user_exist: + return render_template("index.html", user_exists_msg="Username exists, please enter a different user name!") + else: + mongo_user.save(user) + return Response(str({'status' : 'User Added!'}), mimetype='application/json', status=200) + + else: + status = { + 'status' : 'Invalid Action' + } + return Response(str(status), mimetype='application/json', status=400) + + +@app.route('/listUsers', methods=['GET']) +def list_all_users(): + matching_users = mongo_user.list_all_users() + matches = [] + if matching_users is not None: + for user in matching_users: + matches.append(user) + return render_template('users.html', results=matches) + + +@app.route('/addUsers', methods=['GET']) +def add_users(): + mongo_user.add_stuff() + return Response(str({'status': 'success'}), mimetype='application/json', status=200) + +@app.route('/api/cart', methods=['GET','POST']) +def cart(): + if request.args.get('op_type') == 'getcart': + userId = request.args.get('user_id') + matched_ids = mongo_user.get_usercart_by_userid(userId) + matches = mongo_product.get_product_list_from_product_ids(matched_ids) + return render_template('cart.html', user_id=userId, results=matches) + elif request.args.get('op_type') == 'addToCart': + pass + else: + user_id = request.args.get('user_id',None) + product_id = request.args.get('product_id', None) + + user= mongo_user.get_by_id(user_id) + success = mongo_user.add_to_cart(user_id,product_id) + user_data = mongo_user.get_by_id(user_id) + + return render_template('profile.html',name=user_data['name'],user_id=user_id) + + +# @app.route('/admin.html') +# def admin_tasks(): +# return render_template('../../static/admin.html') diff --git a/app/app.css b/app/app.css new file mode 100644 index 0000000..94edafe --- /dev/null +++ b/app/app.css @@ -0,0 +1,70 @@ +/* app css stylesheet */ + +.menu { + list-style: none; + border-bottom: 0.1em solid black; + margin-bottom: 2em; + padding: 0 0 0.5em; +} + +.menu:before { + content: "["; +} + +.menu:after { + content: "]"; +} + +.menu > li { + display: inline; +} + +.menu > li:before { + content: "|"; + padding-right: 0.3em; +} + +.menu > li:nth-child(1):before { + content: ""; + padding: 0; +} + + + +.stbody +{ +min-height:70px; + +} +.stbody +{ +min-height:70px; +margin-bottom:10px; +border-bottom:dashed 1px #cc0000; +} +.stimg +{ +float:left; +height:50px; +width:50px; +border:solid 1px #dedede; +padding:5px; +} +.sttext +{ +margin-left:70px; + +min-height:50px; +word-wrap:break-word; +overflow:hidden; +padding:5px; +display:block; +font-family:'Georgia', Times New Roman, Times, serif +} +.sttime +{ +font-size:11px; +color:#999; +font-family:Arial, Helvetica, sans-serif; +margin-top:5px; +} \ No newline at end of file diff --git a/app/app.js b/app/app.js new file mode 100644 index 0000000..84692d1 --- /dev/null +++ b/app/app.js @@ -0,0 +1,12 @@ +'use strict'; + +// Declare app level module which depends on views, and components +angular.module('ngSocial', [ + 'ngRoute', + 'ngSocial.view1', + 'ngSocial.view2', + 'ngSocial.facebook' +]). +config(['$routeProvider', function($routeProvider) { + $routeProvider.otherwise({redirectTo: '/facebook'}); +}]); diff --git a/app/facebook/._facebook.html b/app/facebook/._facebook.html new file mode 100644 index 0000000000000000000000000000000000000000..6c8ce97dafef6bbe1c137c4d7314f130b6d1afe3 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB) +
+

{{welcomeMsg}}

+
+ +
+
+
+ +
+
+ +
+

+
+

User Info

+
    +
  • ID: {{userInfo.id}}
  • +
  • First Name: {{userInfo.first_name}}
  • +
  • Last Name: {{userInfo.last_name}}
  • +
  • Email: {{userInfo.email}}
  • +
  • Gender: {{userInfo.gender}}
  • +
  • Locale: {{userInfo.locale}}
  • +
+
+
+
+

Permissions

+
    +
  • {{permission.permission}} - {{permission.status}}
  • +
+
+
+
+

Welcome to Facebook!

+
+
+
+ + +
+ +
+

+
+
+ +
+
+ {{post.message}} +
{{post.updated_time}}
+
+
+
+
+

You need to login to post

+
+
+ \ No newline at end of file diff --git a/app/facebook/facebook.js b/app/facebook/facebook.js new file mode 100644 index 0000000..f9659e7 --- /dev/null +++ b/app/facebook/facebook.js @@ -0,0 +1,75 @@ +'use strict'; + +angular.module('ngSocial.facebook', ['ngRoute','ngFacebook']) + +.config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/facebook', { + templateUrl: 'facebook/facebook.html', + controller: 'FacebookCtrl' + }); +}]) + +.config( function( $facebookProvider ) { + $facebookProvider.setAppId('846149575421651'); + $facebookProvider.setPermissions("email,public_profile, user_posts, publish_actions, user_photos"); +}) + +.run(function($rootScope){ + (function(d, s, id){ + var js, fjs = d.getElementsByTagName(s)[0]; + if (d.getElementById(id)) {return;} + js = d.createElement(s); js.id = id; + js.src = "//connect.facebook.net/en_US/sdk.js"; + fjs.parentNode.insertBefore(js, fjs); + }(document, 'script', 'facebook-jssdk')); +}) + +.controller('FacebookCtrl', ['$scope', '$facebook', function($scope, $facebook) { + $scope.isLoggedIn = false; + + $scope.login = function(){ + $facebook.login().then(function(){ + $scope.isLoggedIn = true; + refresh(); + }); + } + + $scope.logout = function(){ + $facebook.logout().then(function(){ + $scope.isLoggedIn = false; + refresh(); + }); + } + + function refresh(){ + $facebook.api("/me").then(function(response){ + $scope.welcomeMsg = "Welcome "+ response.name; + $scope.isLoggedIn = true; + $scope.userInfo = response; + $facebook.api('/me/picture').then(function(response){ + $scope.picture = response.data.url; + $facebook.api('/me/permissions').then(function(response){ + $scope.permissions = response.data; + $facebook.api('/me/posts').then(function(response){ + console.log(response.data); + $scope.posts = response.data; + }); + }); + }); + + }, + function(err){ + $scope.welcomeMsg = "Please Log In"; + }); + } + + $scope.postStatus = function(){ + var body = this.body; + $facebook.api('/me/feed', 'post', {message: body}).then(function(response){ + $scope.msg = 'Thanks for Posting'; + refresh(); + }); + } + + refresh(); +}]); \ No newline at end of file diff --git a/app/index-async.html b/app/index-async.html new file mode 100644 index 0000000..a559b71 --- /dev/null +++ b/app/index-async.html @@ -0,0 +1,58 @@ + + + + + + + + + + My AngularJS App + + + + + +
+ +
Angular seed app: v
+ + + diff --git a/app/index.html b/app/index.html new file mode 100644 index 0000000..c4fd228 --- /dev/null +++ b/app/index.html @@ -0,0 +1,49 @@ + + + + + + + + + ngSocial App + + + + + + + + + +
+
+
+ + + + + + + + + + + + diff --git a/app/models/__init__.py b/app/models/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/models/product.py b/app/models/product.py new file mode 100644 index 0000000..1c93f6a --- /dev/null +++ b/app/models/product.py @@ -0,0 +1,45 @@ +from pymongo import MongoClient +import json +import re +from bson import ObjectId + +class Product: + def __init__(self, id, name, description, price): + self.id = id + self.name = name + self.description = description + self.price = price + + +class MongoProduct: + def __init__(self): + config = json.load(open('./config.json', 'r')) + client = MongoClient(config['mongo_host'], config['mongo_port']) + self.db = client[config['db_name']] + + def save(self, product): + self.db.products.insert_one(product) + + def search_by_name(self, name): + result_cursor = self.db.products.find({'name': re.compile(name, re.IGNORECASE)}) + matches = [] + for prod in result_cursor: + matches.append(prod) + return matches + + def delete_by_id(self, _id): + self.db.products.delete_one({'_id': ObjectId(_id)}) + + def update_by_id(self, _id, prod): + self.db.products.update_one({'_id': ObjectId(_id)}, {'$set': prod}) + + def list_all_products(self): + return self.db.products.find() + + def add_stuff(self): + for i in range(10): + product = dict() + product['name'] = "name" + str(i) + product['description'] = "description" + str(i) + product['price'] = "price" + str(i) + self.db.products.insert_one(product) diff --git a/app/models/user.py b/app/models/user.py new file mode 100644 index 0000000..1df9f4f --- /dev/null +++ b/app/models/user.py @@ -0,0 +1,112 @@ +from pymongo import MongoClient +import re +from bson import ObjectId +import json + + +class User: + def __init__(self, name, email, username, password): + self.name = name + self.email = email + self.username = username + self.password = password + + +class MongoUser: + def __init__(self): + config = json.load(open('./config.json', 'r')) + client = MongoClient(config['mongo_host'], config['mongo_port']) + self.db = client[config['db_name']] + + def save(self, user): + self.db.users.insert_one(user) + + def search_by_name(self, name): + result_cursor = self.db.users.find({'name': name}) + matches = [] + for user in result_cursor: + matches.append(user) + return matches + + def delete_by_id(self, _id): + self.db.users.delete_one({'_id': ObjectId(_id)}) + + def update_by_id(self, _id, user): + self.db.users.update_one({'_id': ObjectId(_id)}, {'$set': user}) + + def authenticate(self, user): + result_cursor = self.db.users.find({'username': user.username, 'password':user.password}) + if result_cursor.count() == 0: + return False + else: + return True + + def list_all_users(self): + return self.db.users.find() + + def add_stuff(self): + for i in range(10): + user = dict() + user['name'] = "name" + str(i) + user['email'] = "email" + str(i) + user['username'] = "username" + str(i) + user['password'] = "password" + str(i) + self.db.users.insert_one(user) + + def find_user_name_by_credentials(self, user): + a = 3 if True else 1 + result_cursor = self.db.users.find({'username': user.username}) + matches = [] + for user in result_cursor: + matches.append(user) + return matches[0]['name'] if len(matches) > 0 else None + + def check_if_user_exists(self, username): + result_cursor = self.db.users.find({'username': username}) + matches = [] + for user in result_cursor: + matches.append(user) + if len(matches) > 0: + return True + else: + return False + + def add_to_cart(self, user_id, product_id): + condition = {'_id': ObjectId(user_id)} + cursor = self.db.users.find(condition) + user_data = cursor[0] if cursor.count() > 0 else None + if user_data is None: + return False + + if 'cart' not in user_data: + user_data['cart'] = [] + + if ObjectId(product_id) not in user_data['cart']: + user_data['cart'].append(ObjectId(product_id)) + self.db.users.update_one(filter=condition, update={'$set':user_data}) + return True + + def get_by_id(self, _id): + query = { + '_id': ObjectId(_id) + } + cursor = self.db.users.find(query) + user = cursor[0] if cursor.count() > 0 else None + return user + + def get_id_by_username(self, username): + cursor = self.db.users.find({'username': username}) + user_data = cursor[0] if cursor.count() > 0 else None + if user_data is None: + return "Anonymous" + else: + matches = [] + for user in cursor: + matches.append(user) + return matches[0]['_id'] + + def get_usercart_by_userid(self, user_id): + user = self.get_by_id(user_id) + return user['cart'] + + diff --git a/app/static/admin.html b/app/static/admin.html new file mode 100644 index 0000000..05ca526 --- /dev/null +++ b/app/static/admin.html @@ -0,0 +1,32 @@ + + + + + + + + + + + +

Welcome to Mini Amazon

+
+

Select operation type

+ + + ID:
+
+ Name:
+
+ Description:
+
+ Price:
+
+ +
+ + \ No newline at end of file diff --git a/app/static/blocks.css b/app/static/blocks.css new file mode 100644 index 0000000..8f0f1f2 --- /dev/null +++ b/app/static/blocks.css @@ -0,0 +1,84 @@ +.pricing-table { + max-width: 368px; + margin: 0 auto; + transition: all .3s ease; + -o-transition: all .3s ease; + -moz-transition: all .3s ease; + -webkit-transition: all .3s ease; + border-radius: 0px; +} +.pricing-table:hover { + box-shadow: 0px 0px 30px rgba(0,0,0, .2); +} +.pricing-table:hover>.panel-footer-landing { + box-shadow: 0px 0px 30px rgba(0,0,0, .05) inset; + -webkit-transition: all .3s ease; +} +.pricing-table:hover>.panel>.panel-body-landing { + background: #5CB85C; + -webkit-transition: all .3s ease; +} +.pricing-table:hover>.panel>.panel-heading-landing-box { + background: #f0f0f0 !important; + color: #333 !important; + -webkit-transition: all .3s ease; +} +.pricing-table:hover>.panel>.controle-header { + background: #5CB85C !important; + /* border: solid 2px #5CB85C !important;*/ + -webkit-transition: all .3s ease; +} +.pricing-table:hover>.panel>.panel-footer { + background: #5CB85C !important; + /* border: solid 2px #5CB85C !important;*/ + -webkit-transition: all .3s ease; +} +.pricing-table:hover>.panel>.panel-footer>.btn { + border: solid 1px #fff !important; + -webkit-transition: all .3s ease; +} +.btn-price:hover { + background: #fff !important; + color: #5CB85C !important; + -webkit-transition: all .3s ease; +} +.pricing-table:hover>.panel>.controle-header>.panel-title-landing { + color: #fff !important; + -webkit-transition: all .3s ease; +} +.pricing-table:hover>.panel>.panel-body-landing>.table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th { + color: #fff !important; + -webkit-transition: all .3s ease; +} +.panel-heading-landing { + background: #f7f7f7 !important; + padding: 20px !important; + border-top-left-radius: 10px !important; + border-top-right-radius: 10px !important; + border: solid 2px #5CB85C !important; + border-bottom: none !important; +} +.panel-heading-landing-box { + background: #5CB85C !important; + color: #fff !important; + font-size: 16px !important; + padding: 3px !important; + border: solid 2px #5CB85C !important; + border-top: none !important; +} +.panel-title-landing { + color: #626367 !important; + font-size: 25px; + font-weight: bold; +} +.panel-body-landing { + border: solid 2px #ccc !important; + border-top: none !important; + border-bottom: none !important; +} +.panel-footer-landing { + border: solid 2px #ccc !important; + border-bottom-left-radius: 10px !important; + border-bottom-right-radius: 10px !important; + border-top: none !important; +} \ No newline at end of file diff --git a/app/templates/cart.html b/app/templates/cart.html new file mode 100644 index 0000000..620bff3 --- /dev/null +++ b/app/templates/cart.html @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + Cart + + +
+ {% for result in results %} + {{result.name}} + {% endfor %} +
+ + \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..6ff1e45 --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,64 @@ + + + + + + + + + + +
+

Welcome to Mini Amazon

+ + + + + + + + + + + + + + + + + + + + + + + + + +

{{ message }}

+
+

Login

+
+
+ Username:
+ Password:

+ +
+
+
+

{{ user_exists_msg }}

+
+

Sign Up

+
+
+ Name:
+ Email:
+ Username:
+ Password:

+ +
+
+
+
+ + \ No newline at end of file diff --git a/app/templates/profile.html b/app/templates/profile.html new file mode 100644 index 0000000..22da9f1 --- /dev/null +++ b/app/templates/profile.html @@ -0,0 +1,11 @@ +

{{ sign_up_msg }}, {{ name }}

+ +
You may perform a product search below:

+
+
+


+ + + +
+
\ No newline at end of file diff --git a/app/templates/results.html b/app/templates/results.html new file mode 100644 index 0000000..ca06e72 --- /dev/null +++ b/app/templates/results.html @@ -0,0 +1,93 @@ + + + + + + + + + + + Search results + + + +
+ +
+ +
+ +

Found {{ results | length }} results for {{ query }}:

+
+ + {% for result in results %} + +
+
+
+
+

+ {{result.name}} +

+
+
+ +
+
+ + + + + + + + + + + + + +
{{result.name}}
{{result.description}}
{{result.price}}
+
+ +
+
+ + + + + + + + + + + + + + + + +
+
+
+
+
+ {% endfor %} +
+ + \ No newline at end of file diff --git a/app/templates/users.html b/app/templates/users.html new file mode 100644 index 0000000..e1ee92a --- /dev/null +++ b/app/templates/users.html @@ -0,0 +1,38 @@ + + + + + + + + + + Users Manager + + + +

Users {{ results | length }} displayed:

+
+ + {% for result in results %} +
+
{{result.name}}
+
+

+ Name: +
+ Username: +
+ Email: +
+ Password: +
+ + + +
+
+ {% endfor %} + + + \ No newline at end of file diff --git a/app/view1/._view1.html b/app/view1/._view1.html new file mode 100644 index 0000000000000000000000000000000000000000..6c8ce97dafef6bbe1c137c4d7314f130b6d1afe3 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB)This is the partial for view 1.

diff --git a/app/view1/view1.js b/app/view1/view1.js new file mode 100644 index 0000000..dbf15ef --- /dev/null +++ b/app/view1/view1.js @@ -0,0 +1,14 @@ +'use strict'; + +angular.module('ngSocial.view1', ['ngRoute']) + +.config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/view1', { + templateUrl: 'view1/view1.html', + controller: 'View1Ctrl' + }); +}]) + +.controller('View1Ctrl', [function() { + +}]); \ No newline at end of file diff --git a/app/view1/view1_test.js b/app/view1/view1_test.js new file mode 100644 index 0000000..14ba79b --- /dev/null +++ b/app/view1/view1_test.js @@ -0,0 +1,16 @@ +'use strict'; + +describe('myApp.view1 module', function() { + + beforeEach(module('myApp.view1')); + + describe('view1 controller', function(){ + + it('should ....', inject(function($controller) { + //spec body + var view1Ctrl = $controller('View1Ctrl'); + expect(view1Ctrl).toBeDefined(); + })); + + }); +}); \ No newline at end of file diff --git a/app/view2/._view2.html b/app/view2/._view2.html new file mode 100644 index 0000000000000000000000000000000000000000..6c8ce97dafef6bbe1c137c4d7314f130b6d1afe3 GIT binary patch literal 4096 zcmZQz6=P>$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB)$Vqox1Ojhs@R)|o50+1L3ClDJkFz{^v(m+1nBL)UWIUt(=a103vvYvJF zKST$^44`s#G%bukK2%&ZIX_n~v7jI)Rj;r#u_!UGBr`9S!N9=4$lBD@!Z^*;Fx5K9 zF({_O$iTItq$n}DB)This is the partial for view 2.

+

+ Showing of 'interpolate' filter: + {{ 'Current version is v%VERSION%.' | interpolate }} +

diff --git a/app/view2/view2.js b/app/view2/view2.js new file mode 100644 index 0000000..5e5d25f --- /dev/null +++ b/app/view2/view2.js @@ -0,0 +1,14 @@ +'use strict'; + +angular.module('ngSocial.view2', ['ngRoute']) + +.config(['$routeProvider', function($routeProvider) { + $routeProvider.when('/view2', { + templateUrl: 'view2/view2.html', + controller: 'View2Ctrl' + }); +}]) + +.controller('View2Ctrl', [function() { + +}]); \ No newline at end of file diff --git a/app/view2/view2_test.js b/app/view2/view2_test.js new file mode 100644 index 0000000..07b34d6 --- /dev/null +++ b/app/view2/view2_test.js @@ -0,0 +1,16 @@ +'use strict'; + +describe('myApp.view2 module', function() { + + beforeEach(module('myApp.view2')); + + describe('view2 controller', function(){ + + it('should ....', inject(function($controller) { + //spec body + var view2Ctrl = $controller('View2Ctrl'); + expect(view2Ctrl).toBeDefined(); + })); + + }); +}); \ No newline at end of file diff --git a/app/views.py b/app/views.py new file mode 100644 index 0000000..1237680 --- /dev/null +++ b/app/views.py @@ -0,0 +1,7 @@ +from mini_amazon import app +from flask import render_template + + +@app.route('/', methods=['GET']) +def index(): + return render_template('index.html') diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..19e683e --- /dev/null +++ b/bower.json @@ -0,0 +1,15 @@ +{ + "name": "angular-seed", + "description": "A starter project for AngularJS", + "version": "0.0.0", + "homepage": "https://github.com/angular/angular-seed", + "license": "MIT", + "private": true, + "dependencies": { + "angular": "1.2.x", + "angular-route": "1.2.x", + "angular-loader": "1.2.x", + "angular-mocks": "~1.2.x", + "html5-boilerplate": "~4.3.0" + } +} diff --git a/config.json b/config.json new file mode 100644 index 0000000..8e470cb --- /dev/null +++ b/config.json @@ -0,0 +1,7 @@ +{ + "host":"0.0.0.0", + "port":5003, + "mongo_host":"localhost", + "mongo_port":27017, + "db_name":"mohit_amazon" +} \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..44bb29f --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,33 @@ +module.exports = function(config){ + config.set({ + + basePath : './', + + files : [ + 'app/bower_components/angular/angular.js', + 'app/bower_components/angular-route/angular-route.js', + 'app/bower_components/angular-mocks/angular-mocks.js', + 'app/components/**/*.js', + 'app/view*/**/*.js' + ], + + autoWatch : true, + + frameworks: ['jasmine'], + + browsers : ['Chrome'], + + plugins : [ + 'karma-chrome-launcher', + 'karma-firefox-launcher', + 'karma-jasmine', + 'karma-junit-reporter' + ], + + junitReporter : { + outputFile: 'test_out/unit.xml', + suite: 'unit' + } + + }); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..e17664c --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "angular-seed", + "private": true, + "version": "0.0.0", + "description": "A starter project for AngularJS", + "repository": "https://github.com/angular/angular-seed", + "license": "MIT", + "devDependencies": { + "karma": "~0.10", + "protractor": "^1.1.1", + "http-server": "^0.6.1", + "bower": "^1.3.1", + "shelljs": "^0.2.6", + "karma-junit-reporter": "^0.2.2" + }, + "scripts": { + "postinstall": "bower install", + + "prestart": "npm install", + "start": "http-server -a localhost -p 8000 -c-1", + + "pretest": "npm install", + "test": "karma start karma.conf.js", + "test-single-run": "karma start karma.conf.js --single-run", + + "preupdate-webdriver": "npm install", + "update-webdriver": "webdriver-manager update", + + "preprotractor": "npm run update-webdriver", + "protractor": "protractor e2e-tests/protractor.conf.js", + + "update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/@@NG_LOADER_START@@[\\s\\S]*\\/\\/@@NG_LOADER_END@@/, '//@@NG_LOADER_START@@\\n' + sed(/sourceMappingURL=angular-loader.min.js.map/,'sourceMappingURL=bower_components/angular-loader/angular-loader.min.js.map','app/bower_components/angular-loader/angular-loader.min.js') + '\\n//@@NG_LOADER_END@@', 'app/index-async.html');\"" + } +} diff --git a/run.py b/run.py new file mode 100644 index 0000000..060808b --- /dev/null +++ b/run.py @@ -0,0 +1,6 @@ +from mini_amazon import app +import json + +if __name__ == '__main__': + config = json.load(open('./config.json', 'r')) + app.run(config['host'], config['port'], debug=True, threaded=True)