Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add admin vue db #19

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
9 changes: 9 additions & 0 deletions assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
padding:2px;
}

#db .fiche{
display: inline-block;
background: #d1d1d1;
text-align: center;
border-radius: .4rem;
margin-bottom: 2.5rem;
margin: 0 10px 10px 10px;
}

#conflict .fiche, #conflict .column {
background: #d1d1d1;
text-align: center;
Expand Down
8 changes: 5 additions & 3 deletions assets/js/pages.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
define(["jquery","vue","app/pages/memo","app/pages/configuration","app/pages/team","app/pages/export","app/pages/conflict","app/pages/stat"], function($,Vue,memo,configuration,team,exp,conflict,stat) { //Load all page JS scripts
define(["jquery","vue","app/pages/memo","app/pages/configuration","app/pages/team","app/pages/export","app/pages/db","app/pages/conflict","app/pages/stat"], function($,Vue,memo,configuration,team,exp,db,conflict,stat) { //Load all page JS scripts
var pages = {
menu: {
"configuration" : "Configuration",
"memo" : "Memo",
"team" : "Teams",
"export" : "Export",
"db": "Database",
"conflict" : "Conflict",
"stat": "Stats"
},
Expand All @@ -13,6 +14,7 @@ define(["jquery","vue","app/pages/memo","app/pages/configuration","app/pages/tea
memo : memo,
team : team,
export : exp,
db : db,
conflict : conflict,
stat : stat,
},
Expand All @@ -33,11 +35,11 @@ define(["jquery","vue","app/pages/memo","app/pages/configuration","app/pages/tea
}
});

//Pages components
//Pages components
for (var id in pages.tabs) {
//console.log(pages.tabs[id].template);
pages.tabs[id].template = '<div class="page" id="'+id+'">' + pages.tabs[id].template + '</div>'; //Force wrap around page element
pages.components[id] = Vue.extend(pages.tabs[id]);
pages.components[id] = Vue.extend(pages.tabs[id]);
}

return pages;
Expand Down
132 changes: 132 additions & 0 deletions assets/js/pages/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/* global define, emit */
define(["jquery"], function($) {
return {
props: ['db'],
data: function() {
return {
fiches: {},
tests: {
viewExistence: {
description: "Les indexes sont présent ?",
validator: function(db) {
var test = this;

//db.query('index', { include_docs: false }).then({
db.fiches.get('_design/fiche').then(function() {
//TODO test every veiw
test.result = true;
}).catch(function(err) {
test.result = false;
console.log(err);
});
},
result: false
}
}
};
},
template: '<h2>Database</h2>' +
'<div id="actions" class="float-right">' +
'<button class="button-primary" @click="applyView">(Re-)Generate View/Index</button>'+
'</div>' +
'<div id="fiches">' +
'<div v-for="(id, fiche) in fiches" class="fiche" id="fiche-{{id}}" style="width : 33%" >' +
'{{id}}' +
'</div>' +
'</div>' +
'<div id="tests">' +
'<div v-for="(id, test) in tests" class="tes" id="test-{{id}}">' +
'{{test.description}} : {{test.result}}' +
'</div>' +
'</div>',
methods: {
applyView: function() {
var vue = this;

// create a design doc
var index = {
_id: '_design/fiche',
views: {
all: {
map: function(doc) {
if (doc.uid) { //if fiche (uid of fiche)
emit(doc._id);
}
}.toString()
},
by_owner: {
map: function(doc) {
if (doc.owner_id) {
emit(doc.owner_id);
}
}.toString()
},
by_uid: {
map: function(doc) {
if (doc.uid) {
emit(doc.uid);
}
}.toString()
},
search: {
map: function(doc) {
if (doc.uid) { //if fiche (uid of fiche)
emit([doc._id, doc.uid, doc.owner_id, doc.patient.firstname, doc.patient.lastname, doc.patient.birthdate, doc.patient.gender, doc.origin, doc.pathologys]);
}
}.toString()
}
}
};

vue.db.fiches.get(index._id).then(function(doc) { //Tryiing to get doc and corresponding _rev
if(doc._rev){
index._rev = doc._rev;
}
}).then(function(doc) {
// save the design doc
return vue.db.fiches.put(index).catch(function(err) {
//Error are to be logged
console.log(err);
alert(err.message);

});
});
},
testViews: function() {
var vue = this;
$.each(vue.tests, function(index, test) {
test.validator.call(test, vue.db); //Call in context of test
});
},
getFiches: function() {
var vue = this;
var fiches = {};
return this.db.fiches.allDocs({
include_docs: true,
conflicts: true,
attachments: false
}).then(function(result) {
console.log(result);
$.each(result.rows, function(index, obj) {
//console.log(obj.doc)
if (obj.doc._id.startsWith("_")) {
return; //Skipping config file like "_design/sofia-config"
}
fiches[obj.doc._id] = obj.doc;
});
vue.fiches = fiches;
}).catch(function(err) {
console.log(err);
});
}
},
events: {
onload: function() {
this.getFiches().then(this.testViews);
},
onchange: function() {
this.getFiches().then(this.testViews);
}
}
};
});