-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
22842d1
commit f716cad
Showing
12 changed files
with
203 additions
and
123 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 was deleted.
Oops, something went wrong.
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,56 @@ | ||
<template> | ||
<div class="main-view"> | ||
<div class="form-container"> | ||
<h3>Add Item</h3> | ||
<hr> | ||
<form v-on:submit.prevent="addItem" class="form-horizontal"> | ||
<label for="name">Product Name </label> | ||
<input type="text" v-model.trim="name" name="name" class="form-control" placeholder="Name" required="required" title=""> | ||
<br> | ||
<label for="name">Product Price </label> | ||
<input type="number" v-model.trim.number="price" class="form-control" placeholder="Price" required="required" title=""> | ||
<br> | ||
<label for="name">Product quantity </label> | ||
<input type="number" v-model.trim.number="quantity" class="form-control" placeholder="Quantity" required="required" title=""> | ||
<br> | ||
<button type="submit" class="btn btn-success">Save Changes</button> | ||
</form> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'AddItem', | ||
methods: { | ||
addItem: function () { | ||
var itemData = {name: this.name, price: this.price, quantity: this.quantity} | ||
this.$emit('addItem', itemData) | ||
console.log(itemData) | ||
} | ||
}, | ||
data () { | ||
return { | ||
name: '', | ||
price: '', | ||
quantity: '' | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<!-- Add "scoped" attribute to limit CSS to this component only --> | ||
<style scoped> | ||
.main-view { | ||
flex:1 1 auto; | ||
flex-wrap: wrap; | ||
padding:10px; | ||
display: flex; | ||
justify-content: center; | ||
|
||
} | ||
.form-container{ | ||
width:300px; | ||
text-align: center; | ||
} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
<template> | ||
<div class="container"> | ||
<Nav /> | ||
<Navbar /> | ||
|
||
<div class="main-content"> | ||
<Sidebar /> | ||
<router-view :drugs="drugs" v-on:removeItem="removeDrug"></router-view> | ||
<router-view :drugs="drugs" v-on:removeItem="removeDrug" | ||
v-on:editItem="editDrug" :itemToEdit="itemToEdit" v-on:addItem="addItem" | ||
v-on:updateItem="upudateItem"> | ||
</router-view> | ||
</div> | ||
</div> | ||
|
||
</template> | ||
|
||
<script> | ||
import Nav from './Nav' | ||
import Navbar from './Navbar' | ||
import Sidebar from './Sidebar' | ||
import Firebase from 'firebase' | ||
|
@@ -27,36 +31,52 @@ var firedb = FirebaseApp.database() | |
export default { | ||
name: 'AdminContainer', | ||
mounted () { | ||
// var wholeSaleRef = firedb.ref('wholesalers').push() | ||
var drugsRef = firedb.ref('drugs') | ||
// drugsRef.set({name: 'paracetamol', quantity: 77, price: 455}) | ||
// wholeSaleRef.set({name: 'Paul', email: '[email protected]', company: 'A labs'}) | ||
drugsRef.on('value', function (snap) { | ||
this.drugs = snap.val() | ||
}) | ||
console.log(snap.val()) | ||
}.bind(this)) | ||
}, | ||
methods: { | ||
removeDrug: function () { | ||
console.log('removeItem') | ||
this.drugs = [{name: 'paracetamol', price: '4, 873', qty: 45}] | ||
removeDrug: function (itemkey) { | ||
console.log('final removeItem', itemkey) | ||
var drugItemRef = firedb.ref('drugs').child(itemkey) | ||
drugItemRef.remove() | ||
}, | ||
addDrug: function (itemkey) { | ||
var drugsRef = firedb.ref('drugs').push() | ||
drugsRef.set(itemkey) | ||
}, | ||
editDrug: function (itemkey) { | ||
console.log('final edit', itemkey) | ||
this.itemToEdit = this.drugs[itemkey] | ||
console.log(this.itemToEdit.name) | ||
this.$router.push(`wholesaler/edit/${itemkey}`) | ||
}, | ||
upudateItem: function (itemObject) { | ||
console.log('updateing') | ||
var drugItemRef = firedb.ref('drugs').child(itemObject.key) | ||
drugItemRef.update({name: itemObject.name, price: itemObject.price, quantity: itemObject.quantity}, function () { | ||
console.log('updated') | ||
this.$router.push('/wholesaler') | ||
}.bind(this)) | ||
}, | ||
addDrug: function () { | ||
console.log('add drug') | ||
addItem: function (item) { | ||
var drugsRef = firedb.ref('drugs').push() | ||
drugsRef.set(item, () => { | ||
console.log('item added') | ||
}) | ||
} | ||
}, | ||
data () { | ||
return { | ||
msg: 'Welcome to Your Vue.js App', | ||
drugs: [{name: 'paracetamol', price: '4, 873', quantity: 45}, | ||
{name: 'paracetamol', price: '4, 873', quantity: 45}, | ||
{name: 'paracetamol', price: '4, 873', quantity: 45}, | ||
{name: 'paracetamol', price: '4, 873', quantity: 45}, | ||
{name: 'paracetamol', price: '4, 873', quantity: 45} | ||
] | ||
itemToEdit: {}, | ||
drugs: [] | ||
} | ||
}, | ||
components: { | ||
Nav, | ||
Navbar, | ||
Sidebar | ||
} | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<template> | ||
<div class="main-view"> | ||
<div class="form-container"> | ||
<h3>Edit Item</h3> | ||
<hr> | ||
<form v-on:submit.prevent="saveEdit" class="form-horizontal"> | ||
<label for="name">Product Name </label> | ||
<input type="text" v-model.trim="name" name="name" class="form-control" placeholder="Name" required="required" title=""> | ||
<br> | ||
<label for="name">Product Price </label> | ||
<input type="text" v-model.trim="price" class="form-control" placeholder="Price" required="required" title=""> | ||
<br> | ||
<label for="name">Product quantity </label> | ||
<input type="text" v-model.trim="quantity" class="form-control" placeholder="Quantity" required="required" title=""> | ||
<br> | ||
<button type="submit" class="btn btn-success">Save Changes</button> | ||
</form> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'EditItem', | ||
props: ['itemToEdit'], | ||
methods: { | ||
saveEdit: function () { | ||
var itemData = { | ||
key: this.$route.params.id, | ||
name: this.name, | ||
price: this.price, | ||
quantity: this.quantity | ||
} | ||
console.log(itemData) | ||
this.$emit('updateItem', itemData) | ||
} | ||
}, | ||
mounted: function () { | ||
}, | ||
data () { | ||
return { | ||
name: this.itemToEdit.name, | ||
price: this.itemToEdit.price, | ||
quantity: this.itemToEdit.quantity | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<!-- Add "scoped" attribute to limit CSS to this component only --> | ||
<style scoped> | ||
.main-view { | ||
flex:1 1 auto; | ||
flex-wrap: wrap; | ||
padding:10px; | ||
display: flex; | ||
justify-content: center; | ||
|
||
} | ||
.form-container{ | ||
width:300px; | ||
text-align: center; | ||
} | ||
</style> |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.