[couchdb] synchronizacja kart po dodaniu nowych dziala

This commit is contained in:
pawlaczyk 2019-01-08 17:17:21 +01:00
parent 3497fb022c
commit 7399b45cfb
4 changed files with 178 additions and 41 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}

View File

@ -0,0 +1,4 @@
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
#powinno wyświetlic:
success

View File

@ -0,0 +1,113 @@
; CouchDB Configuration Settings
; Custom settings should be made in this file. They will override settings
; in default.ini, but unlike changes made to default.ini, this file won't be
; overwritten on server upgrade.
[couchdb]
;max_document_size = 4294967296 ; bytes
;os_process_timeout = 5000
uuid = aae385165fb06f68a709f782ee764194
[couch_peruser]
; If enabled, couch_peruser ensures that a private per-user database
; exists for each document in _users. These databases are writable only
; by the corresponding user. Databases are in the following form:
; userdb-{hex encoded username}
;enable = true
; If set to true and a user is deleted, the respective database gets
; deleted as well.
;delete_dbs = true
; Set a default q value for peruser-created databases that is different from
; cluster / q
;q = 1
[chttpd]
;port = 5984
;bind_address = 127.0.0.1
; Options for the MochiWeb HTTP server.
;server_options = [{backlog, 128}, {acceptor_pool_size, 16}]
; For more socket options, consult Erlang's module 'inet' man page.
;socket_options = [{sndbuf, 262144}, {nodelay, true}]
[httpd]
enable_cors = true
; NOTE that this only configures the "backend" node-local port, not the
; "frontend" clustered port. You probably don't want to change anything in
; this section.
; Uncomment next line to trigger basic-auth popup on unauthorized requests.
;WWW-Authenticate = Basic realm="administrator"
[cors]
origins = *
credentials = true
methods = GET, PUT, POST, HEAD, DELETE
headers = accept, authorization, content-type, origin, referer, x-csrf-token
[x-csrf-token]
accept, authorization, content-type, origin, referer, x-csrf-token
; Uncomment next line to set the configuration modification whitelist. Only
; whitelisted values may be changed via the /_config URLs. To allow the admin
; to change this value over HTTP, remember to include {httpd,config_whitelist}
; itself. Excluding it from the list would require editing this file to update
; the whitelist.
;config_whitelist = [{httpd,config_whitelist}, {log,level}, {etc,etc}]
[query_servers]
;nodejs = /usr/local/bin/couchjs-node /path/to/couchdb/share/server/main.js
[couch_httpd_auth]
; If you set this to true, you should also uncomment the WWW-Authenticate line
; above. If you don't configure a WWW-Authenticate header, CouchDB will send
; Basic realm="server" in order to prevent you getting logged out.
; require_valid_user = false
secret = 067e98c83b3132b81ff0d83bdb97cf10
[ssl]
;enable = true
;cert_file = /full/path/to/server_cert.pem
;key_file = /full/path/to/server_key.pem
;password = somepassword
; set to true to validate peer certificates
;verify_ssl_certificates = false
; Set to true to fail if the client does not send a certificate. Only used if verify_ssl_certificates is true.
;fail_if_no_peer_cert = false
; Path to file containing PEM encoded CA certificates (trusted
; certificates used for verifying a peer certificate). May be omitted if
; you do not want to verify the peer.
;cacert_file = /full/path/to/cacertf
; The verification fun (optional) if not specified, the default
; verification fun will be used.
;verify_fun = {Module, VerifyFun}
; maximum peer certificate depth
;ssl_certificate_max_depth = 1
;
; Reject renegotiations that do not live up to RFC 5746.
;secure_renegotiate = true
; The cipher suites that should be supported.
; Can be specified in erlang format "{ecdhe_ecdsa,aes_128_cbc,sha256}"
; or in OpenSSL format "ECDHE-ECDSA-AES128-SHA256".
;ciphers = ["ECDHE-ECDSA-AES128-SHA256", "ECDHE-ECDSA-AES128-SHA"]
; The SSL/TLS versions to support
;tls_versions = [tlsv1, 'tlsv1.1', 'tlsv1.2']
; To enable Virtual Hosts in CouchDB, add a vhost = path directive. All requests to
; the Virual Host will be redirected to the path. In the example below all requests
; to http://example.com/ are redirected to /database.
; If you run CouchDB on a specific port, include the port number in the vhost:
; example.com:5984 = /database
[vhosts]
;example.com = /database/
; To create an admin account uncomment the '[admins]' section below and add a
; line in the format 'username = password'. When you next start CouchDB, it
; will change the password to a hash (so that your passwords don't linger
; around in plain-text files). You can add more admin accounts with more
; 'username = password' lines. Don't forget to restart CouchDB after
; changing this.
[admins]
;admin = mysecretpassword
root = -pbkdf2-09d40af7168b7f20872a8a169b2ec3f4b3d3bb16,43ff5af3359e8ff310934e7c5effbf3d,10
root2 = -pbkdf2-cd4319b0a8943f9a8e9f7c86b3093d3b64ecef0f,63e56d6df3cba494997de6dd4bd83027,10
superuser = -pbkdf2-310f06740d41aa7f7281737805c9dc6f12aa4301,e0a1e64831746ae5d2b4238197dc119d,10

View File

@ -24,7 +24,7 @@
<!-- pa-3 jest już nie potrzebne w <v-card> lepiej to wyglada jak sa koloery na samym brzegu-->
<v-card flat v-for="card in cards" :key="card.text">
<v-card flat v-for="card in cards" :key="card.due">
<!-- dynamiczne budowanie stringa bedącego wartością klasy - składnia z $ i ciapki ukosne -->
<v-layout row wrap :class="`pa-3 cardType ${card.type}`">
@ -53,49 +53,33 @@
</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{
cards: [
{due: 'data jakas', text: 'jakis tekst karta pytanie1', type:'question'},
{due: 'data jakas', text: 'jakis tekst karta pytanie2', type:'question'},
{due: 'data jakas', text: 'jakis tekst karta pytanie3', type:'question'},
{due: 'data jakas', text: 'jakis tekst karta pytanie4', type:'question'},
{due: 'data jakas', text: 'jakis tekst karta pytanie5', type:'question'},
{due: 'data jakas', text: 'jakis tekst karta pytanie6', type:'question'},
{due: 'data jakas', text: 'jakis tekst karta pytanie7', type:'question'},
{due: 'data jakas', text: 'jakis tekst karta pytanie8', type:'question'},
{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'}
]
cards: [],
totalRows: null
}
},
methods:{
sortBy(prop){
//sortowanie po typie karty
console.log("prop:", prop)
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
// 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 mojeVue = this;
var db = new PouchDB('http://localhost:5984/golang_cards');
console.log("DB: ", db)
var cards = []
var cardsTmp = []
db.allDocs({include_docs : true}).then(function (res) {
console.log("res: ", res.rows[0].doc)
mojeVue.totalRows = res.total_rows; //aktualizacja zmiennej majacej liczbe wierszy
res.rows.forEach(function (entry){
var tmp = {}
@ -107,29 +91,62 @@ export default {
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)
cardsTmp.push(tmp)
})
})
this.cards = cards
}
this.cards = cardsTmp
},
created() {
console.log("Pobranie wszsytkich kard z bazy")
this.daneZbazy()
checkDiference(){
var mojeVue = this;
//Sprawdza róznice w bazie danych - czy nie zostały dodane nowe dane
var db = new PouchDB('http://localhost:5984/golang_cards');
//tylko sprawdza liczbe wierszy, bez pobierania dokuemnto - ktore sa prototype tye
var promiseRows = new Promise(function(resolve, reject) {
//tu sie dzieje magia promisow
var rowsCount = db.allDocs({include_docs : true}).then(function (res){
return res.total_rows;
})
if (rowsCount){
resolve(rowsCount)
}
else{
reject("No nie chcial mi dac wynikow")
}
//koniec magii
})
//wywolanie magii
var proszeDzialaj = promiseRows.then(function(fromResolve){
return fromResolve
}).catch(function(fromReject){
return "Proszę nie :<"
})
proszeDzialaj.then(function(fromResolve){
if (fromResolve !== mojeVue.totalRows){ //javascriptowe fantastyczne porownania
//aktualizuj dane wyswietlane
mojeVue.daneZbazy()
console.log("Nowe dane")
}
})
}
},
mounted() {
// console.log("Pobranie wszsytkich kard z bazy")
this.daneZbazy() //wczytuje na poczatku dane
//cyklicznie ywkonujaca sie funkcja - do sprawdzania zmian w bazie co 10 s - żeby plynnie wyswietlac nowo dodane karty jesli zmiana zostanie zauwaona
this.timer = setInterval(this.checkDiference, 10000) //na biezaco aktualizuje dane
}
}
</script>
<style>