Skip to content

Commit

Permalink
add category view, component, update router, negelect multi-word-comp…
Browse files Browse the repository at this point in the history
…onent-names checks
  • Loading branch information
yennanliu committed Nov 27, 2023
1 parent bddb979 commit 824defa
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ShoppingCart/Frondend/ecommerce-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"parserOptions": {
"parser": "@babel/eslint-parser"
},
"rules": {}
"rules": {"vue/multi-word-component-names": "off"}
},
"browserslist": [
"> 1%",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<template>
<div class="card h-100 w-100">
<div class="embed-responsive embed-responsive-16by9">
<img class="card-img-top embed-responsive-item" :src="category.imageUrl" alt="Category Image">
</div>

<div class="card-body">
<h5 class="card-title">{{category.categoryName}}</h5>
<p class="card-text font-italic">{{category.description.substring(0,65)}}...</p>
<router-link id="edit-category" :to="{ name: 'EditCategory', params: { id : category.id } }" >
Edit
</router-link>
</div>
</div>
</template>

<script>
export default {
name : "CategoryBox",
props : ["category"],
methods : {
}
}
</script>

<style scoped>
.card{
width : 20rem;
height : 24rem;
}
.embed-responsive .card-img-top {
object-fit: cover;
}
a {
text-decoration: none;
}
.card-title {
color: #484848;
font-size: 1.1rem;
font-weight: 400;
}
.card-title:hover {
font-weight: bold;
}
.card-text {
font-size: 0.9rem;
}
#edit-category {
float: right;
}
</style>
8 changes: 8 additions & 0 deletions ShoppingCart/Frondend/ecommerce-ui/src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";

import AddCategory from "../views/Category/AddCategory";
import Category from "../views/Category/Category";


Vue.use(VueRouter);
Expand All @@ -27,6 +28,13 @@ const routes = [
name: "AddCategory",
component: AddCategory,
},

{
path: "/admin/category",
name: "AdminCategory",
component: Category,
}

];

const router = new VueRouter({
Expand Down
57 changes: 57 additions & 0 deletions ShoppingCart/Frondend/ecommerce-ui/src/views/Category/Category.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<template>
<div class="container">
<div class="row">
<div class="col-12 text-center">
<h4 class="pt-3">Our Categories</h4>
<router-link id="add-category" :to="{name : 'AddCategory'}" v-show="$route.name=='AdminCategory'">
<button class="btn">Add a new Category</button>
</router-link>
</div>
</div>
<div class="row">
<div v-for="category of categories" :key="category.id" class="col-md-6 col-xl-4 col-12 pt-3 justify-content-around d-flex">
<CategoryBox :category="category">
</CategoryBox>
</div>
</div>
</div>
</template>

<script>
import CategoryBox from '../../components/Category/CategoryBox';
var axios = require('axios');
export default {
name: 'Category',
components : {CategoryBox},
data() {
return {
baseURL : "https://limitless-lake-55070.herokuapp.com/",
categories : null,
}
},
methods: {
async getCategories() {
//fetch categories
await axios.get(this.baseURL + "category/")
.then(res => this.categories = res.data)
.catch(err => console.log(err))
}
},
mounted(){
this.getCategories();
}
}
</script>

<style scoped>
h4 {
font-family: 'Roboto', sans-serif;
color: #484848;
font-weight: 700;
}
#add-category {
float: right;
font-weight: 500;
}
</style>

0 comments on commit 824defa

Please sign in to comment.