-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix router, premove products, add AddProduct, EditProduct
- Loading branch information
Showing
6 changed files
with
265 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
ShoppingCart/Frondend/ecommerce-ui/src/views/Product/AddProduct.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<template> | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-12 text-center"> | ||
<h4 class="pt-3">Add new Product</h4> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-3"></div> | ||
<div class="col-md-6 px-5 px-md-0"> | ||
<form> | ||
<div class="form-group"> | ||
<label>Category</label> | ||
<select class="form-control" v-model="categoryId" required> | ||
<option | ||
v-for="category of categories" | ||
:key="category.id" | ||
:value="category.id" | ||
> | ||
{{ category.categoryName }} | ||
</option> | ||
</select> | ||
</div> | ||
<div class="form-group"> | ||
<label>Name</label> | ||
<input type="text" class="form-control" v-model="name" required /> | ||
</div> | ||
<div class="form-group"> | ||
<label>Description</label> | ||
<input | ||
type="text" | ||
class="form-control" | ||
v-model="description" | ||
required | ||
/> | ||
</div> | ||
<div class="form-group"> | ||
<label>ImageURL</label> | ||
<input | ||
type="url" | ||
class="form-control" | ||
v-model="imageURL" | ||
required | ||
/> | ||
</div> | ||
<div class="form-group"> | ||
<label>Price</label> | ||
<input | ||
type="number" | ||
class="form-control" | ||
v-model="price" | ||
required | ||
/> | ||
</div> | ||
<button type="button" class="btn btn-primary" @click="addProduct"> | ||
Submit | ||
</button> | ||
</form> | ||
</div> | ||
<div class="col-3"></div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import swal from "sweetalert"; | ||
import axios from "axios"; | ||
export default { | ||
data() { | ||
return { | ||
id: null, | ||
categoryId: null, | ||
name: null, | ||
description: null, | ||
imageURL: null, | ||
price: null, | ||
}; | ||
}, | ||
props: ["baseURL", "products", "categories"], | ||
methods: { | ||
async addProduct() { | ||
const newProduct = { | ||
id: this.id, | ||
categoryId: this.categoryId, | ||
name: this.name, | ||
description: this.description, | ||
imageURL: this.imageURL, | ||
price: this.price, | ||
}; | ||
await axios({ | ||
method: "post", | ||
url: "http://localhost:9999/" + "product/add", | ||
data: JSON.stringify(newProduct), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}) | ||
.then((res) => { | ||
//sending the event to parent to handle | ||
console.log(res) | ||
this.$emit("fetchData"); | ||
this.$router.push({ name: "AdminProduct" }); | ||
swal({ | ||
text: "Product Added Successfully!", | ||
icon: "success", | ||
closeOnClickOutside: false, | ||
}); | ||
}) | ||
.catch((err) => console.log(err)); | ||
}, | ||
}, | ||
mounted() { | ||
if (!localStorage.getItem("token")) { | ||
this.$router.push({ name: "Signin" }); | ||
} | ||
}, | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
h4 { | ||
font-family: "Roboto", sans-serif; | ||
color: #484848; | ||
font-weight: 700; | ||
} | ||
</style> |
118 changes: 118 additions & 0 deletions
118
ShoppingCart/Frondend/ecommerce-ui/src/views/Product/EditProduct.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<template> | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-12 text-center"> | ||
<h4 class="pt-3">Edit Product</h4> | ||
</div> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-3"></div> | ||
<div class="col-md-6 px-5 px-md-0"> | ||
<form v-if="product"> | ||
<div class="form-group"> | ||
<label>Category</label> | ||
<select class="form-control" v-model="product.categoryId" required> | ||
<option | ||
v-for="category of categories" | ||
:key="category.id" | ||
:value="category.id" | ||
> | ||
{{ category.categoryName }} | ||
</option> | ||
</select> | ||
</div> | ||
<div class="form-group"> | ||
<label>Name</label> | ||
<input | ||
type="text" | ||
class="form-control" | ||
v-model="product.name" | ||
required | ||
/> | ||
</div> | ||
<div class="form-group"> | ||
<label>Description</label> | ||
<input | ||
type="text" | ||
class="form-control" | ||
v-model="product.description" | ||
required | ||
/> | ||
</div> | ||
<div class="form-group"> | ||
<label>ImageURL</label> | ||
<input | ||
type="url" | ||
class="form-control" | ||
v-model="product.imageURL" | ||
required | ||
/> | ||
</div> | ||
<div class="form-group"> | ||
<label>Price</label> | ||
<input | ||
type="number" | ||
class="form-control" | ||
v-model="product.price" | ||
required | ||
/> | ||
</div> | ||
<button type="button" class="btn btn-primary" @click="editProduct"> | ||
Submit | ||
</button> | ||
</form> | ||
</div> | ||
<div class="col-3"></div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import swal from "sweetalert"; | ||
import axios from "axios"; | ||
export default { | ||
data() { | ||
return { | ||
product: null, | ||
}; | ||
}, | ||
props: ["baseURL", "products", "categories"], | ||
methods: { | ||
async editProduct() { | ||
axios | ||
//post(this.baseURL + "product/update/" + this.id, this.product) | ||
.post("localhost:9999" + "product/update/" + this.id, this.product) | ||
.then((res) => { | ||
console.log(res) | ||
//sending the event to parent to handle | ||
this.$emit("fetchData"); | ||
this.$router.push({ name: "AdminProduct" }); | ||
swal({ | ||
text: "Product Updated Successfully!", | ||
icon: "success", | ||
closeOnClickOutside: false, | ||
}); | ||
}) | ||
.catch((err) => console.log("err", err)); | ||
}, | ||
}, | ||
mounted() { | ||
// if (!localStorage.getItem("token")) { | ||
// this.$router.push({ name: "Signin" }); | ||
// return; | ||
// } | ||
this.id = this.$route.params.id; | ||
this.product = this.products.find((product) => product.id == this.id); | ||
}, | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
h4 { | ||
font-family: "Roboto", sans-serif; | ||
color: #484848; | ||
font-weight: 700; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
ShoppingCart/Frondend/ecommerce-ui/src/views/Product/Products.vue
This file was deleted.
Oops, something went wrong.