Skip to content

Commit

Permalink
Merge pull request GeekTrainer#2 from SkillUpTech/main
Browse files Browse the repository at this point in the history
merge from main
  • Loading branch information
ppardi authored Jan 14, 2021
2 parents 7c58f29 + c741759 commit ed65342
Show file tree
Hide file tree
Showing 33 changed files with 497 additions and 77 deletions.
33 changes: 33 additions & 0 deletions code/module-08/m08_end/components/FoodPrefsForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<template>
<div class="componentBox">
<h3 style="text-align:center;">Food Preferences</h3>
<p style="text-align:center;">
<strong>Room Service Fee</strong>{{ roomService }}</p>
<p>Please fill out this form to let us know your food preferences.</p>
</div>
</template>

<script>
export default {
//TODO: Add berth prop
props: {
berth: {
type: Boolean,
required: true,
},
},
//TODO: Add computed property
computed: {
roomService() {
if (this.berth) {
return `: No charge`;
}
return `: $24.99`;
}
}
};
</script>

<style>
/* styles can be included*/
</style>
97 changes: 97 additions & 0 deletions code/module-09/m09_end/components/FoodPrefsForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<template>
<!-- TODO: Add <form> element below last <p> tag -->
<div class="componentBox">
<h3 style="text-align:center;">Food Preferences</h3>
<p style="text-align:center;"><strong>Room Service Fee</strong>{{ roomService }}</p>
<p>Please fill out this form to let us know your food preferences.</p>

<form @submit.prevent="onSubmit">
<h4>Submit food preferences</h4>
<label for="passenger">Passenger name:</label>
<input id="passenger" v-model="passenger">

<br>
<label for="allergies">Do you have food allergies? </label>
<select id="allergies" v-model.number="allergies">
<option>Yes</option>
<option>No</option>
</select>

<br>
<label for="allergydesc">Describe allergies: (enter "None" if not applicable)</label>
<textarea id="allergydesc" v-model="allergydesc"></textarea>

<label for="glutenfree">Gluten-free? </label>
<select id="glutenfree" v-model.number="glutenfree">
<option>Yes</option>
<option>No</option>
</select>

<br><br>
<label for="vegan">Vegan? </label>
<select id="vegan" v-model="vegan">
<option>Yes</option>
<option>No</option>
</select>

<br>
<input class="button" type="submit" value="Submit">

</form>
</div>
</template>
<script>
export default {
props: {
berth: {
type: Boolean,
required: true,
}
}
}
</script>
/* TODO: Add form data properties and methods */
data() {
return {
passenger: '',
allergies: '',
allergydesc: '',
glutenfree: '',
vegan: '',
}
},
/* TODO: Add methods */
methods: {
onSubmit() {
if (this.passenger === '' || this.allergies === '' || this.allergydesc === '' || this.glutenfree === '' || this.vegan === '') {
alert('Form is incomplete. Please fill out every field.')
return
}

let foodprefanswers = {
passenger: this.passenger,
allergies: this.allergies,
allergydesc: this.allergydesc,
glutenfree: this.glutenfree,
vegan: this.vegan,
}

this.$emit('foodpref-submitted', foodprefanswers);

this.passenger = '';
this.allergies = '';
this.allergydesc = '';
this.glutenfree = '';
this.vegan = '';

},
},
computed: {
roomService() {
if (this.berth) {
return `: No charge`;
}
return `: $24.99`;
}
},
})
2 changes: 1 addition & 1 deletion code/module-09/m09_end/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h4>{{ featureDetails }}</h4>
<script src="./components/FoodPrefsList.js"></script>
<script src="./components/ReviewForm.js"></script>
<script src="./components/ReviewList.js"></script>

<script src="./components/test.vue"></script>
<!-- Mount Vue App to the DOM -->
<script>
const mountedApp = app.mount('#app')
Expand Down
1 change: 1 addition & 0 deletions m04-list-rendering/includes/2-list-rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ If you completed the prior exercises, your HTML file should look like the image
Before users decide to book a cruise, they will want to know how much it costs. So the next thing we need to do is add information about pricing.

![Screenshot showing the HTML page with a selected product image on the left; product name and description are shown on the right, followed by two paragraphs that read "Sold out! Please check back for our next available shuttle." and "Bookings for our next cruise shuttle will be available in February, 2051.](../media/m4-html-start.png)

- If the `data()` property for `numSeatsAvailable` is set to `0`, the text in the product detail section will inform users that this cruise is "Sold out!"
- An additional paragraph will be displayed that asks users to check back in February, 2051 to book seats on the next cruise shuttle.

Expand Down
10 changes: 1 addition & 9 deletions m05-event-handling/includes/3-event-handling-using-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Open **index.html** either from the [starter code](link), or your existing proje
- Increment the value of cart by 1

```javascript
...
//TODO: Add a comma
},
//TODO: Increment value of cart
Expand All @@ -33,10 +32,8 @@ Now change the button in your HTML file to use the `addToCart` method instead of
- Add `v-on:click` directive to Book a Cruise button below the comment that reads `TODO: Add item to cart`

```html
...
<!-- TODO: Add item to cart -->
<button class="button" v-on:click="addItemToCart">Book a Cruise</button>
...
```

If you render the HTML file now, the cart should behave the same way it did when using the data expression. Clicking the "Book a Cruise" button should increment the number in the cart by 1 every time you click it because the `v-on` directive is still listening for that click event.
Expand All @@ -46,9 +43,7 @@ If you render the HTML file now, the cart should behave the same way it did when
You should also be aware that Vue allows a shorthand notation when using the `v-on` directive. You can use the "at" symbol (@) in place of `v-on:`, as shown below.

```html
...
<button class="button" @click="addItemToCart">Book a Cruise</button>
...
```

## Change selected product image when thumbnail is clicked
Expand All @@ -64,7 +59,6 @@ Then use the `v-on:click` directive in your **index.html** file to execute the a
- Apply `v-on:click` directive in **index.html** below the comment `TODO: Change selected image`

```javascript
...
//TODO: Change selected image
featureBookCruise() {
this.selectedProdImg = './assets/images/space-4888643_1284x856.jpg';
Expand All @@ -78,25 +72,23 @@ featureBulletTrain() {
featureAlienShip() {
this.selectedProdImg = './assets/images/spaceship-5730066_1284x856.jpg';
},
...
```

```html
...
<!-- TODO: Change selected image -->
<div style="text-align:left; padding-top:0; height:200px;">
<img src="./assets/images/space-4888643_1284x856.jpg" @click="featureBookCruise" style="width:12%; margin-right:0px;">
<img src="./assets/images/asteroid-5737398_1284x856.jpg" @click="featureAsteroid" style="width:12%; margin-left:12px; margin-right:0px;">
<img src="./assets/images/fantasy-5732286_1284x856.jpg" @click="featureBulletTrain" style="width:12%; margin-left:12px; margin-right:0px;">
<img src="./assets/images/spaceship-5730066_1284x856.jpg" @click="featureAlienShip" style="width:12%; margin-left:12px; margin-right:0px;">
</div>
...
```

> [!TIP]
> If you want to have this method execute whenever a user hovers the mouse over a thumbnail image you could use the Vue @mouseover directive instead of @click.
![Screenshot showing the HTML page with a selected produce image on the left and 4 thumbnail images below it. Product name and description are displayed on the right, with two paragraphs of text. Below this are unordered lists for Passenger Rates and Group Discounts](../media/thumbnails_cart_button.png)

- Change the selected product image when a thumbnail image is clicked
- Increment the value of cart when "Book a Cruise" button is clicked

Expand Down
18 changes: 1 addition & 17 deletions m06-class-and-style-binding/includes/2-styles-and-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ We can use the `v-bind` directive for this purpose. Vue provides special enhance
- Set the background color to light yellow

```css
...
li {
font-size: 18px;
}

/* TODO: Add a highlight class */
.highlight {
background-color: rgb(250, 250, 133);
}
...
```

In our **main.js** file we will set a boolean data property that lets us tell Vue when to apply our highlight style. We need to establish separate properties for each thumbnail object, because at any given time we want only one property to evaluate to `true` while the other three properties evaluate to `false`. That way only one thumbnail will have a yellow background highlight at any given time. We set the first image property to `true` in the data declaration section so that the default thumbnail image will be highlighted as soon as the HTML page loads.
Expand All @@ -36,14 +30,6 @@ Next we need a way to trigger a change in the status of all 4 properties based o
- Set the data property to `false` for all other features in that method

```Javascript
...
//TODO: create boolean data property for each thumbnail
isSelectedCruise: true,
isSelectedAsteroid: false,
isSelectedBullet: false,
isSelectedAlien: false,
...

//TODO: set boolean values for all thumbnails
featureBookCruise() {
this.selectedProdImg = './assets/images/space-4888643_1284x856.jpg';
Expand Down Expand Up @@ -73,7 +59,6 @@ featureAlienShip() {
this.isSelectedBullet = false;
this.isSelectedAlien = true;
},
...
```

## Add style bindings to thumbnail images
Expand All @@ -84,19 +69,18 @@ The last step of this process is to add the appropriate directives to each `<img
- Bind the `.highlight` class to the data property that will be set to `true` after execution of the `method` called by `v-on:click`

```html
...
<div style="text-align:left; padding-top:0; height:200px;">
<!-- TODO: Bind a class to each image -->
<img src="./assets/images/space-4888643_1284x856.jpg" @click="featureBookCruise" :class="{ highlight: isSelectedCruise }" style="width:12%; margin-right:0px;">
<img src="./assets/images/asteroid-5737398_1284x856.jpg" @click="featureAsteroid" :class="{ highlight: isSelectedAsteroid }" style="width:12%; margin-left:12px; margin-right:0px;">
<img src="./assets/images/fantasy-5732286_1284x856.jpg" @click="featureBulletTrain" :class="{ highlight: isSelectedBullet }" style="width:12%; margin-left:12px; margin-right:0px;">
<img src="./assets/images/spaceship-5730066_1284x856.jpg" @click="featureAlienShip" :class="{ highlight: isSelectedAlien }" style="width:12%; margin-left:12px; margin-right:0px;">
</div>
...
```

Notice that we are able to use several types of Vue directives on each `<img>` tag. We have applied a `v-on:click` directive to call a method that executes multiple actions on different element tags in our HTML page. We are also using the `v-bind:class` directive to dynamically change the background style of each image based on a condition. In addition, we are able to simultaneously apply several inline style settings to each `<img>` tag.

![Screenshot showing the HTML page with a selected product image on the left and 4 thumbnail images below it. The thumbnail on the far left is highlighted with a yellow background. Product name and description are displayed on the right, with two paragraphs of text. Below this are unordered lists for Passenger Rates and Group Discounts. At the bottom are two buttons labeled "Book a Cruise" and "Remove Item".](../media/m06-thumbnail-highlight.png)

- The selected product image is indicated by the highlight on the matching thumbnail image
- Clicking a thumbnail will change the large image to match the thumbnail image, and the highlight background will be moved to the clicked thumbnail image
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ We already have a `disabledButton` class in our **styles.css** file that sets th
- Use the `v-bind:class` directive to apply the `disabledButton` class style when the value of cart is 0

```html
...
<button class="button" @click="addItemToCart">Book a Cruise</button>
<!-- TODO: Disable Remove Item button -->
<button class="button" :disabled="cart==0" :class="{ disabledButton:cart==0 }" @click="removeItemFromCart">Remove Item</button>
...
```

When viewed in a live browser your HTML page should look like the image below.
Expand All @@ -23,4 +21,4 @@ When viewed in a live browser your HTML page should look like the image below.
- Clicking the "Book a Cruise" button will increment the value of cart by 1
- Clicking the "Remove Item" button will decrement the value of cart by 1 (unless the value is 0)
- "Remove Item" button will be active if the value of cart is 1 or higher
- "Remove Item" button will be inactive (and appear disabled) if the value of cart is 0
- "Remove Item" button will be inactive (and appear disabled) if the value of cart is 0
Loading

0 comments on commit ed65342

Please sign in to comment.