Pbranie danych zcouchdb

This commit is contained in:
pawlaczyk 2019-01-08 03:30:47 +01:00
parent 39fa0946e7
commit 4e5cb685e6
7 changed files with 1283 additions and 177 deletions

0
frontend/app/git Normal file
View File

File diff suppressed because it is too large Load Diff

View File

@ -8,8 +8,16 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"couch-db": "^1.1.3",
"date-fns": "^1.30.1",
"ejs": "^2.6.1",
"node-couchdb": "^1.3.0",
"node-couchdb-plugin-memcached": "0.0.2",
"pouchdb": "^7.0.0",
"vue": "^2.5.21",
"vue-resource": "^1.5.1",
"vue-router": "^3.0.1",
"vuetify": "^1.3.0",
"vuex": "^3.0.1"

33
frontend/app/src/cb.js Normal file
View File

@ -0,0 +1,33 @@
//connector couchdb
//Inaczej pobieranie kard, które są dostępne publicznie będzie nieodświeżało widoku wszystkich kart po dodaniu przez backend danych
// gorsze rozwiazanie to zasluchiwanie ciagle na zmiany w bazie i wtedy wykonanie w widoku pobrania jeszcze raz danych, ale komunikacja źre za dużo, więc nie
// const NodeCouchDb = require('node-couchdb');
// // node-couchdb instance with default options
// const couch = new NodeCouchDb();
// // node-couchdb instance with Memcached
// const MemcacheNode = require('node-couchdb-plugin-memcached');
// const couchWithMemcache = new NodeCouchDb({
// cache: new MemcacheNode
// });
// // node-couchdb instance talking to external service
// const couchExternal = new NodeCouchDb({
// host: 'couchdb.external.service',
// protocol: 'https',
// port: 6984
// });
// // not admin party
// const couchAuth = new NodeCouchDb({
// auth: {
// user: 'root',
// pass: 'password'
// }
// });
// export default couch;

View File

@ -48,7 +48,9 @@
</v-menu>
<v-btn flat color="grey" @click="userAction">
<span v-if="isLogged">Wyjdź</span>
<span v-if="isLogged">Wyjdź
</span>
<span v-if="!isLogged">Zaloguj</span>
<v-icon right>exit_to_app</v-icon>
</v-btn>
@ -95,7 +97,7 @@ export default {
snackbar: false,
snackbarLogout: false,
isLogged: true,
snackbarLogint: false
snackbarLogin: false
}
},
computed:{

View File

@ -2,8 +2,11 @@ import Vue from 'vue'
import './plugins/vuetify'
import App from './App.vue'
import router from './router'
import VueResource from 'vue-resource'
import {store} from './store/store'
Vue.use(VueResource)
Vue.config.productionTip = false
new Vue({

View File

@ -53,8 +53,12 @@
</div>
</template>
<script src="http://localhost:5984/golang_cards/_all_docs?include_docs=true"></script>
<script>
import axios from 'axios';
import PouchDB from 'pouchdb'
export default {
data(){
return{
@ -70,10 +74,6 @@ export default {
{due: 'data jakas', text: 'jakis tekst karta pytanie9', type:'question'},
{due: 'data jakas', text: 'jakis tekst karta pytanie10', type:'question'},
{due: 'data jakas', text: 'jakis tekst karta pytanie0', type:'question'},
{due: 'data jakas', text: 'karta odpowiedz jakis tekst', type:'answer'}
]
}
@ -85,11 +85,50 @@ export default {
this.cards.filter( obj => {
return obj.type === prop
})
}
},
daneZbazy(){
// w linii komend jako admin na Windzie w folderze app
// C:\Users\dp\Desktop\PracowaniaProgramowania\frontend\app>add-cors-to-couchdb http://127.0.0.1:5984 -u root -p password success
var db = new PouchDB('http://localhost:5984/golang_cards');
console.log("DB: ", db)
var cards = []
db.allDocs({include_docs : true}).then(function (res) {
console.log("res: ", res.rows[0].doc)
res.rows.forEach(function (entry){
var tmp = {}
tmp.due = entry.doc.Timestamp
tmp.text = entry.doc.Text
if (entry.doc.isquestion){
tmp.type = 'question'
}
else{
tmp.type='answer'
}
cards.push(tmp)
console.log("tmp", tmp)
console.log(entry.doc.Text)
console.log(entry.doc.Timestamp)
console.log(entry.doc.blank)
console.log(entry.doc.isquestion)
})
})
this.cards = cards
}
},
created() {
console.log("Pobranie wszsytkich kard z bazy")
console.log("Pobranie wszsytkich kard z bazy")
this.daneZbazy()
}
}
</script>