Skip to content

Commit

Permalink
implment inferTypeFromDataset into our playground
Browse files Browse the repository at this point in the history
  • Loading branch information
Dalanir authored and adimascio committed Jul 11, 2019
1 parent e77b469 commit 7c89c33
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
51 changes: 26 additions & 25 deletions playground/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const {
Vqb,
filterOutDomain,
inferTypeFromDataset,
getTranslator,
mongoResultsToDataset,
servicePluginFactory,
Expand All @@ -21,12 +22,11 @@ class MongoService {
}

async executePipeline(pipeline) {
const {
domain,
pipeline: subpipeline
} = filterOutDomain(pipeline);
const { domain, pipeline: subpipeline } = filterOutDomain(pipeline);
const rset = await this.executeQuery(this.translator.translate(subpipeline), domain);
return mongoResultsToDataset(rset);
const dataset = mongoResultsToDataset(rset);
const datasetWithInferedType = inferTypeFromDataset(dataset);
return datasetWithInferedType;
}

async executeQuery(query, collection) {
Expand Down Expand Up @@ -57,10 +57,12 @@ class MongoService {

const mongoservice = new MongoService();
const mongoBackendPlugin = servicePluginFactory(mongoservice);
const initialPipeline = [{
name: 'domain',
domain: 'test-collection',
}];
const initialPipeline = [
{
name: 'domain',
domain: 'test-collection',
},
];

async function setupInitialData(store, domain = null) {
const collections = await mongoservice.listCollections();
Expand All @@ -80,11 +82,12 @@ async function setupInitialData(store, domain = null) {

async function buildVueApp() {
Vue.use(Vuex);
const store = setupStore({
pipeline: initialPipeline,
currentDomain: 'test-collection',
},
[mongoBackendPlugin],
const store = setupStore(
{
pipeline: initialPipeline,
currentDomain: 'test-collection',
},
[mongoBackendPlugin],
);

new Vue({
Expand All @@ -93,7 +96,7 @@ async function buildVueApp() {
Vqb,
},
store,
data: function () {
data: function() {
return {
isCodeOpened: false,
draggedOverFirst: false,
Expand All @@ -102,15 +105,15 @@ async function buildVueApp() {
};
},
computed: {
code: function () {
code: function() {
const query = mongo36translator.translate(this.$store.getters.activePipeline);
return JSON.stringify(query, null, 2);
},
},
methods: {
// both methods below help to detect correctly dragover child element and
// out on parent element
dragEnter: function (event) {
dragEnter: function(event) {
event.preventDefault();
if (this.draggedOverFirst) {
this.draggedOverSecond = true;
Expand All @@ -119,7 +122,7 @@ async function buildVueApp() {
}
this.draggedover = true;
},
dragLeave: function () {
dragLeave: function() {
if (this.draggedOverSecond) {
this.draggedOverSecond = false;
} else if (this.draggedOverFirst) {
Expand All @@ -129,24 +132,22 @@ async function buildVueApp() {
this.draggedover = false;
}
},
dragOver: function (event) {
dragOver: function(event) {
// Prevent to open file when drop the file
event.preventDefault();
},
drop: async function (event) {
drop: async function(event) {
this.draggedover = false;
event.preventDefault();
// For the moment, only take one file and we should also test event.target
const {
collection: domain
} = await mongoservice.loadCSV(event.dataTransfer.files[0]);
const { collection: domain } = await mongoservice.loadCSV(event.dataTransfer.files[0]);
await setupInitialData(store, domain);
event.target.value = null;
},
hideCode: function () {
hideCode: function() {
this.isCodeOpened = false;
},
openCode: function () {
openCode: function() {
this.isCodeOpened = true;
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// export lib entrypoints
export { filterOutDomain, mongoToPipe } from './lib/pipeline';
export { getTranslator } from './lib/translators';
export { mongoResultsToDataset } from './lib/dataset/mongo';
export { mongoResultsToDataset, inferTypeFromDataset } from './lib/dataset/mongo';

// export store entrypoints
export { servicePluginFactory } from '@/store/backend-plugin';
Expand Down

0 comments on commit 7c89c33

Please sign in to comment.