Skip to content

Commit

Permalink
Added frontend side
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetkucukoglu committed May 14, 2021
1 parent 23d874e commit 0bd20b8
Show file tree
Hide file tree
Showing 25 changed files with 26,985 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Blockchain Uygulama Geliştirme

1.Bölüm Kontrat Oluşturma :
[ahmetkucukoglu.com/blockchain-uygulama-gelistirme-1-kontrat-olusturma](https://www.ahmetkucukoglu.com/blockchain-uygulama-gelistirme-1-kontrat-olusturma)
[ahmetkucukoglu.com/blockchain-uygulama-gelistirme-1-kontrat-olusturma](https://www.ahmetkucukoglu.com/blockchain-uygulama-gelistirme-1-kontrat-olusturma)

2.Bölüm UI İle Etkileşim :
[ahmetkucukoglu.com/blockchain-uygulama-gelistirme-2-ui-ile-etkilesim](https://www.ahmetkucukoglu.com/blockchain-uygulama-gelistirme-2-ui-ile-etkilesim)
931 changes: 931 additions & 0 deletions backend/build/contracts/Migrations.json

Large diffs are not rendered by default.

844 changes: 844 additions & 0 deletions backend/build/contracts/MockedOrders.json

Large diffs are not rendered by default.

10,881 changes: 10,881 additions & 0 deletions backend/build/contracts/Orders.json

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.DS_Store
node_modules
/dist


# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
24 changes: 24 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frontend

## Project setup
```
npm install
```

### Compiles and hot-reloads for development
```
npm run serve
```

### Compiles and minifies for production
```
npm run build
```

### Lints and fixes files
```
npm run lint
```

### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).
5 changes: 5 additions & 0 deletions frontend/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}
13,431 changes: 13,431 additions & 0 deletions frontend/package-lock.json

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"@metamask/detect-provider": "^1.2.0",
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vuex": "^3.6.2",
"web3": "^1.3.6"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
Binary file added frontend/public/favicon.ico
Binary file not shown.
31 changes: 31 additions & 0 deletions frontend/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="">

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>
<%= htmlWebpackPlugin.options.title %>
</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
</head>

<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled.
Please enable it to continue.</strong>
</noscript>
<div class="container">
<div id="app"></div>
</div>
<!-- built files will be auto injected -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-JEW9xMcG8R+pH31jmWH6WWP0WintQrMb4s7ZOdauHnUtxwoG2vI5DkLtS3qm9Ekf"
crossorigin="anonymous"></script>
</body>

</html>
29 changes: 29 additions & 0 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<template>
<div id="app">
<StatusBar />
<Products />
<Cart />
<Orders />
</div>
</template>

<script>
import StatusBar from "./components/StatusBar.vue";
import Products from "./components/Products.vue";
import Cart from "./components/Cart.vue";
import Orders from "./components/Orders.vue";
export default {
name: "App",
components: {
StatusBar,
Products,
Cart,
Orders,
},
methods: {},
};
</script>

<style>
</style>
Binary file added frontend/src/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 98 additions & 0 deletions frontend/src/components/Cart.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<template>
<div id="cart" class="card shadow-sm mt-3" v-if="this.cart.items.length > 0">
<div class="card-body">
<h5 class="card-title">Cart</h5>
<hr />
<div class="row fw-bold">
<div class="col">Name</div>
<div class="col">Quantity</div>
<div class="col">Total Price</div>
<div class="col"></div>
</div>
<CartItem
:key="cartItem.productId"
:cartItem="cartItem"
v-for="cartItem in this.cart.items"
@removeProductFromCart="removeProductFromCart"
/>

<button
type="button"
class="btn btn-sm btn-outline-primary"
@click="createOrder"
>
<i class="bi bi-box-seam"></i> Create order
</button>
</div>
</div>
</template>

<script>
import CartItem from "./CartItem.vue";
import { eventHub } from "../main";
export default {
name: "Cart",
components: {
CartItem,
},
props: {},
data() {
return {
cart: {
items: [],
},
};
},
methods: {
addProductToCart(productId, productName, productPrice, deliveryDate) {
var cartItems = this.cart.items.filter((x) => x.productId == productId);
if (cartItems.length == 0) {
this.cart.items.push({
productId: productId,
productName: productName,
productPrice: productPrice,
deliveryDate: deliveryDate,
quantity: 1,
});
} else {
cartItems[0].quantity++;
}
},
removeProductFromCart(productId) {
let items = this.cart.items.filter((x) => x.productId != productId);
this.cart.items = items;
},
async createOrder() {
let totalPrice = this.cart.items
.map((x) => x.productPrice * x.quantity)
.reduce((p, c) => p + c);
let deliveryDate = new Date(
Math.max.apply(
null,
this.cart.items.map((x) => new Date(x.deliveryDate))
)
);
eventHub.$emit("createOrder", { totalPrice, deliveryDate });
this.cart.items = [];
},
},
created() {
eventHub.$on("addProductToCart", (product) => {
this.addProductToCart(
product.id,
product.name,
product.price,
product.deliveryDate
);
});
},
};
</script>

<style scoped>
</style>
49 changes: 49 additions & 0 deletions frontend/src/components/CartItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div class="row mt-3">
<div class="col">{{ cartItem.productName }}</div>
<div class="col">
<input
type="text"
class="form-control count"
v-model="cartItem.quantity"
/>
</div>
<div class="col">{{ getTotalPrice }} ETH</div>
<div class="col">
<button
type="button"
class="btn btn-sm btn-outline-secondary"
@click="removeProductFromCart"
>
<i class="bi bi-cart-dash"></i> Remove from cart
</button>
</div>
</div>
</template>

<script>
export default {
name: "CartItem",
props: {
cartItem: Object,
},
methods: {
removeProductFromCart() {
this.$emit("removeProductFromCart", this.cartItem.productId);
},
},
computed: {
getTotalPrice() {
var totalPrice = this.cartItem.quantity * this.cartItem.productPrice;
return totalPrice;
},
},
};
</script>

<style scoped>
.count {
width: 45px;
}
</style>
Loading

0 comments on commit 0bd20b8

Please sign in to comment.