From c4af2fe556229621ddf80fb04439e6ae0b1d7772 Mon Sep 17 00:00:00 2001 From: Mike Vickery Date: Sat, 26 Sep 2015 20:35:07 -0600 Subject: [PATCH 1/9] all complete for now - ready to tackle services --- angProject-app.css | 6 + angProject-app.js | 47 +++++ angProject-index.html | 39 ++++ angular-playground.sln | 37 ++++ app/components/bindings/BindingsController.js | 3 +- app/components/bindings/bindings.html | 6 +- .../controllers/ControllersController.js | 11 +- app/components/controllers/controllers.html | 21 ++- .../expressions/ExpressionsController.js | 2 +- app/components/expressions/expressions.html | 6 +- app/components/repeat/RepeatController.js | 133 ++++++++------ app/components/repeat/repeating.html | 167 +++++++++--------- assets/css/site.css | 7 + 13 files changed, 331 insertions(+), 154 deletions(-) create mode 100644 angProject-app.css create mode 100644 angProject-app.js create mode 100644 angProject-index.html create mode 100644 angular-playground.sln diff --git a/angProject-app.css b/angProject-app.css new file mode 100644 index 0000000..935d6b7 --- /dev/null +++ b/angProject-app.css @@ -0,0 +1,6 @@ +body { + background-color: lightblue; +} +.button-custom { + background-color:lightgreen; +} \ No newline at end of file diff --git a/angProject-app.js b/angProject-app.js new file mode 100644 index 0000000..6884156 --- /dev/null +++ b/angProject-app.js @@ -0,0 +1,47 @@ +var app = angular.module('racingFrogs', []); +app.controller('MainController', MainController); +//No need to change anything above this line. + +function MainController() { + var vm = this; //instead of using this when refering to the controller, let's use vm. It will make things easier. + vm.working = "Yes"; + vm.joe = new Guy("Joe", 100); + vm.bob = new Guy("Bob", 150); + vm.bank = 200; + + function Guy(name, startingCash) { + this.name = name; + this.cash = startingCash; + this.giveCash = function (amount) { + if (amount <= this.cash && amount > 0) { + this.cash = this.cash - amount; + return amount; + } else { + console.log("I don't have enough cash to give you " + amount + ". " + this.name + " says..."); + return 0; + } + }; + this.receiveCash = function (amount) { + if (amount > 0) { + this.cash = this.cash + amount; + return amount; + } else { + console.log(amount + " isn't an amount I'll take " + this.name + " says..."); + return 0; + } + } + } + + vm.giveMoneyToJoe = function () { + if (vm.bank >= 10) { + vm.bank -= vm.joe.receiveCash(10); + } else { + alert("The bank is out of money."); + } + } + + vm.receiveMoneyFromBob = function () { + vm.bank += vm.bob.giveCash(5); + } + +} \ No newline at end of file diff --git a/angProject-index.html b/angProject-index.html new file mode 100644 index 0000000..68b6fbc --- /dev/null +++ b/angProject-index.html @@ -0,0 +1,39 @@ + + + + + Racing Frogs + + + + + +
+
+
+
+ Fun with Joe and Bob
+ Angular Working? : {{vm.working}} +
+
+

+ Joe has {{ vm.joe.cash }} +

+

+ Bob has {{ vm.bob.cash }} +

+

+ The bank has {{ vm.bank }} +

+
+ +
+
+ + + + + diff --git a/angular-playground.sln b/angular-playground.sln new file mode 100644 index 0000000..f3c421b --- /dev/null +++ b/angular-playground.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "angular-playground", ".", "{1C264CEB-6514-436C-8705-3789D954C442}" + ProjectSection(WebsiteProperties) = preProject + TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.0" + Debug.AspNetCompiler.VirtualPath = "/localhost_52606" + Debug.AspNetCompiler.PhysicalPath = "..\..\..\..\..\..\source\angular-playground\" + Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_52606\" + Debug.AspNetCompiler.Updateable = "true" + Debug.AspNetCompiler.ForceOverwrite = "true" + Debug.AspNetCompiler.FixedNames = "false" + Debug.AspNetCompiler.Debug = "True" + Release.AspNetCompiler.VirtualPath = "/localhost_52606" + Release.AspNetCompiler.PhysicalPath = "..\..\..\..\..\..\source\angular-playground\" + Release.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_52606\" + Release.AspNetCompiler.Updateable = "true" + Release.AspNetCompiler.ForceOverwrite = "true" + Release.AspNetCompiler.FixedNames = "false" + Release.AspNetCompiler.Debug = "False" + VWDPort = "52606" + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1C264CEB-6514-436C-8705-3789D954C442}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1C264CEB-6514-436C-8705-3789D954C442}.Debug|Any CPU.Build.0 = Debug|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/app/components/bindings/BindingsController.js b/app/components/bindings/BindingsController.js index 281242d..87d65a6 100644 --- a/app/components/bindings/BindingsController.js +++ b/app/components/bindings/BindingsController.js @@ -5,5 +5,6 @@ app.controller('BindingsController', BindingsController); function BindingsController(){ this.bindingsStatus = 'Working'; - this.name= "Please enter your Name"; + this.name = "Please enter your Name"; + this.somethingOfYourChoice = "Something of your choice"; } \ No newline at end of file diff --git a/app/components/bindings/bindings.html b/app/components/bindings/bindings.html index c6bb99f..2887c17 100644 --- a/app/components/bindings/bindings.html +++ b/app/components/bindings/bindings.html @@ -36,10 +36,10 @@

Exercises

diff --git a/app/components/controllers/ControllersController.js b/app/components/controllers/ControllersController.js index 6a3d65f..aecba63 100644 --- a/app/components/controllers/ControllersController.js +++ b/app/components/controllers/ControllersController.js @@ -4,5 +4,12 @@ app.controller('ControllersController', ControllersController); function ControllersController(){ - this.controllersStatus = 'Working'; -} \ No newline at end of file + this.controllersStatus = 'Working'; + this.friends = ['Joey', 'Chandler', 'Monica', 'Phebes', 'Ross & Rachel']; + this.addFriend = function () { + if (this.newFriend) { + this.friends.push(this.newFriend); + this.newFriend = null; + } + } +} diff --git a/app/components/controllers/controllers.html b/app/components/controllers/controllers.html index 4c6da3a..f04e7c6 100644 --- a/app/components/controllers/controllers.html +++ b/app/components/controllers/controllers.html @@ -32,12 +32,18 @@

Exercises

create a property in the constructor called friends which will be an array of strings ['Joey', 'Chandler', 'Monica', 'Phebes', 'Ross & Rachel']; -
-
    -
  • {{friend}}
  • -
-
- +

+
    +

    Friends

    +
    +
      +
        +
      • {{friend}}
      • +
      +
    +
    +

+
  • Write a function called addFriend that will take the input from ng-model="controller.newFriend" If done correctly you should see your new friend pop up on the list above once you click submit
    @@ -50,4 +56,5 @@

    Exercises

  • - \ No newline at end of file + + diff --git a/app/components/expressions/ExpressionsController.js b/app/components/expressions/ExpressionsController.js index f90acbf..e2ee29d 100644 --- a/app/components/expressions/ExpressionsController.js +++ b/app/components/expressions/ExpressionsController.js @@ -5,5 +5,5 @@ app.controller('ExpressionsController', ExpressionsController); function ExpressionsController(){ this.expressionsStatus = 'Working'; - this.test = 'Angular is really neat! Look how easy it was for you to connect this string to your view'; + this.test = 'Angular is really neat! Look how easy it was for you to connect this string to your view'; } \ No newline at end of file diff --git a/app/components/expressions/expressions.html b/app/components/expressions/expressions.html index ca65403..f53d197 100644 --- a/app/components/expressions/expressions.html +++ b/app/components/expressions/expressions.html @@ -69,19 +69,19 @@

    Exercises

  • Write a math equation that Angular can evaluate
    - {{}} + {{8 + 8}}
  • Using string concatination get the customary Hello, World! to display on the screen. Don't forget your quotes
    - {{}} + {{'Hello, ' + 'World!'}}
  • We have a controller driving this view. The controller is nothing more than an object with properties. One of the properties on the controller object is called test. Render the test property to the screen
    - {{}} + {{controller.test}}
  • diff --git a/app/components/repeat/RepeatController.js b/app/components/repeat/RepeatController.js index cf9c4e7..bc33593 100644 --- a/app/components/repeat/RepeatController.js +++ b/app/components/repeat/RepeatController.js @@ -1,60 +1,87 @@ -var app = angular.module('angularPlayground'); +var app = angular.module('angularPlayground'); app.controller('RepeatController', RepeatController); -function RepeatController(){ - this.repeatStatus = 'Working'; - //The cart is an array of items that we are adding from our view - this.cart = []; - //The store is what we are using to populate our page with - this.store = { - items: StoreData - }; - //*** No Need to edit anything above this line **** - - this.name = "My BɼokƏn Cart!"; - - this.getCartCount = function(){ - //return the length of our cart - }; - - /* - * Write a calculateCartTotal function - * make it assesible to our view - * this function should return the total cost - * of each item that is in our cart - */ - - - this.removeItemFromCart = function(item){ - //Item gets passed in from our view when the user clicks the x button +function RepeatController() { + this.repeatStatus = 'Working'; + //The cart is an array of items that we are adding from our view + this.cart = []; + //The store is what we are using to populate our page with + this.store = { + items: StoreData + }; + //*** No Need to edit anything above this line **** + + this.name = "My BɼokƏn Cart!"; + + this.getCount = function () { + //return the length of our cart + return this.cart.length; + }; + /* - * This function should be able to remove the passed in item - * from our cart. You will have to first identify where the passed - * in item is in the array. Then you will need to use the correct - * Array.method to remove 1 item hint method(i, 1); + * Write a calculateCartTotal function + * make it assesible to our view + * this function should return the total cost + * of each item that is in our cart */ - }; - - this.addItemToCart = function(item){ - //item gets passed in to this function from the view - - /* - Our cart demands that items being added to it must have the following properties - var newItem = { - name:'', - color:'', - size: '', - quantity: 1, - price:'', - } - console.log the item being passed in from the view - to figure out which properties from item need to be - remaped to the newItem object. - After building the newItem add it to the cart - */ - - } - + + this.calculateCartTotal = function () { + var total = 0; + for (var i = 0; i < this.cart.length; i++) { + total += this.cart[i].price * this.cart[i].quantity; + //console.log(i + " Item:"+this.cart[i].name+" Price:"+this.cart[i].price+" Quantity:"+this.cart[i].quantity + " RunningTotal:"+ total); + } + return total; + }; + + this.removeItemFromCart = function (item) { + //Item gets passed in from our view when the user clicks the x button + for (var i = 0; i < this.cart.length; i++) { + if (item.name === this.cart[i].name && + item.color === this.cart[i].color && + item.size === this.cart[i].size && + item.quantity === this.cart[i].quantity && + item.price === this.cart[i].price) { + //console.log("Delete " + i + " which is " + item.name + ":" + item.size + ":" + item.color); + this.cart.splice(i, 1); + break; + } + } + /* + * This function should be able to remove the passed in item + * from our cart. You will have to first identify where the passed + * in item is in the array. Then you will need to use the correct + * Array.method to remove 1 item hint method(i, 1); + */ + }; + + this.addItemToCart = function (item) { + //item gets passed in to this function from the view + //console.log(item); + var newItem = { + name: item.name, + color: item.selectedColor, + size: item.selectedSize, + quantity: 1, + price: item.price, + } + //console.log(newItem); + this.cart.push(newItem); + /* + Our cart demands that items being added to it must have the following properties + var newItem = { + name:'', + color:'', + size: '', + quantity: 1, + price:'', + } + console.log the item being passed in from the view + to figure out which properties from item need to be + remaped to the newItem object. + After building the newItem add it to the cart + */ + } } \ No newline at end of file diff --git a/app/components/repeat/repeating.html b/app/components/repeat/repeating.html index 3717987..448a9c2 100644 --- a/app/components/repeat/repeating.html +++ b/app/components/repeat/repeating.html @@ -1,90 +1,89 @@ -RepeatController Status: {{controller.repeatStatus}} +RepeatController Status: {{controller.repeatStatus}}
    -

    Help Fix this Cart

    -

    What we have here is a broken website. There are a few challenges we need to solve to get it working

    -

    using the comments in the html and in the controller file as guides you should be able to get this cart back in top notch condition.

    - -

    First things first lets start with the HTML.

    - +

    Help Fix this Cart

    +

    What we have here is a broken website. There are a few challenges we need to solve to get it working

    +

    using the comments in the html and in the controller file as guides you should be able to get this cart back in top notch condition.

    + +

    First things first lets start with the HTML.

    +

    -

    {{controller.name}}

    -

    Items added to your Cart ({{controller.getCount() || 0}})

    -
    -

    - You have no items in your cart... Buy something! -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    ItemColorSizeQuantityPrice
    {{item.name}}{{item.color}}{{item.size}} - - {{item.price * item.quantity}} - -
    Total:{{controller.calculateCartTotal()}}
    -
    -
    -
    - -
    -
    - -

    {{item.price}}

    -

    - {{item.name}}

    - -

    - - -

    - +

    {{controller.name}}

    +

    Items added to your Cart ({{controller.getCount() | number:0}})

    +
    +

    + You have no items in your cart... Buy something! +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ItemColorSizeQuantityPrice
    {{item.name}}{{item.color}}{{item.size}} + + {{item.price * item.quantity | currency}} + +
    Total:{{controller.calculateCartTotal() | currency}}
    +
    +
    +
    + +
    +
    + +

    {{item.price | currency}}

    +

    {{item.name}}

    + +

    + + +

    + +
    +
    -
    -
    -
    \ No newline at end of file +
    diff --git a/assets/css/site.css b/assets/css/site.css index 483c07b..d3840f1 100644 --- a/assets/css/site.css +++ b/assets/css/site.css @@ -45,4 +45,11 @@ color:yellow; font-size:16px; font-weight:bold; +} + +.box1-custom { + width:300px; + background-color:lightgrey; + border-color:black; + border-width:2px; } \ No newline at end of file From b51e38f414885121db4f4c5e607fa65d7706e0e1 Mon Sep 17 00:00:00 2001 From: Mike Vickery Date: Sat, 26 Sep 2015 20:48:15 -0600 Subject: [PATCH 2/9] currency added on 'Fun with Joe and Bob' --- angProject-index.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/angProject-index.html b/angProject-index.html index 68b6fbc..046bf5b 100644 --- a/angProject-index.html +++ b/angProject-index.html @@ -17,13 +17,13 @@

    - Joe has {{ vm.joe.cash }} + Joe has {{ vm.joe.cash | currency }}

    - Bob has {{ vm.bob.cash }} + Bob has {{ vm.bob.cash | currency }}

    - The bank has {{ vm.bank }} + The bank has {{ vm.bank | currency }}