Skip to content

Commit

Permalink
Fixes #139 #114
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mulholland committed Oct 25, 2017
1 parent b2d7f65 commit c8dfd2b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 31 deletions.
60 changes: 42 additions & 18 deletions src/renderer/components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,24 @@
</div>
<div id="main-bottom-panel" class="panel-footer">
<div id="message-panel" class="panel-default">
<div v-show="errorMessages && errorMessages.length > 0">
<!-- tidy up messages view with components -->
<div v-show="messages">
<ul class="nav navbar-right closebtn">
<li>
<a href="#" @click="closeErrorMessages()">
<a href="#" @click="closeMessages()">
<span style="color:#000" class="btn-default fa fa-times" />
</a>
</li>
</ul>
<h3>Validation errors</h3>
<div v-for="errorMessage in errorMessages">
<span>row no.{{errorMessage.rowNumber}}</span><span>: {{errorMessage.message}}</span>
</div>
<h3>{{messagesTitle}}</h3>
<template v-if="messagesType === 'error'">
<div v-for="errorMessage in messages">
<span>row no.{{errorMessage.rowNumber}}</span><span>: {{errorMessage.message}}</span>
</div>
</template>
<div v-else>
<span>{{messages}}</span>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -169,7 +175,9 @@ export default {
enableTransition: false,
enableSideNavLeftArrow: true,
enableSideNavRightArrow: true,
errorMessages: false,
messagesType: '',
messages: false,
messagesTitle: 'Feedback',
loadingDataMessage: false,
sideNavFormHeight: '300px',
toolbarMenus: [{
Expand Down Expand Up @@ -254,39 +262,57 @@ export default {
'destroyHotTab',
'destroyTabObject'
]),
closeErrorMessages: function() {
closeMessages: function() {
for (let el of ['main-bottom-panel', 'main-middle-panel']) {
document.getElementById(el).classList.remove('opened')
}
this.errorMessages = false
this.messages = false
this.messagesType = ''
this.messageTitle = ''
},
selectionListener: function() {
this.updateActiveColumn()
this.resetSideNavArrows()
},
async updateColumnProperties() {
try {
await guessColumnProperties()
let feedback = await guessColumnProperties()
this.messages = feedback
this.messagesType = 'feedback'
this.messagesTitle = 'Guess column properties'
this.reportFeedback()
} catch (err) {
console.log(err)
}
},
openValidationMessagesOnIds: function(ids) {
// TODO: tidy up error view handling
openMessagesOnIds: function(ids) {
for (let el of ids) {
document.getElementById(el).classList += ' opened'
}
},
closeValidationMessagesOnIds: function(ids) {
closeMessagesOnIds: function(ids) {
for (let el of ids) {
document.getElementById(el).classList.remove('opened')
}
},
reportValidationRowErrors: function(errorCollection) {
this.errorMessages = errorCollection
if (errorCollection.length > 0) {
this.messagesTitle = 'Validation Errors'
this.messages = errorCollection
this.messagesType = 'error'
} else {
this.messagesTitle = 'Validation Success'
this.messages = 'No validation errors reported.'
this.messagesType = 'feedback'
}
this.reportFeedback()
},
reportFeedback: function() {
let ids = ['main-bottom-panel', 'main-middle-panel']
let cssUpdateFunction = this.errorMessages.length > 0
? this.openValidationMessagesOnIds(ids)
: this.closeValidationMessagesOnIds(ids)
let cssUpdateFunction = this.messages
? this.openMessagesOnIds(ids)
: this.closeMessagesOnIds(ids)
},
async validateTable() {
try {
Expand Down Expand Up @@ -575,11 +601,9 @@ export default {
})
},
created: function() {
const vueForceUpdate = this.forceWrapper
const vueGuessProperties = this.updateColumnProperties
ipc.on('guessColumnProperties', function(event, arg) {
vueGuessProperties()
vueForceUpdate()
})
const vueValidateTable = this.validateTable
ipc.on('validateTable', function(event, arg) {
Expand Down
14 changes: 5 additions & 9 deletions src/renderer/frictionless.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,19 @@ async function initDataAgainstSchema(data, schema) {
return table
}

async function storeData(hotId, table) {
await store.mutations.pushTableSchema(store.state, {
function storeData(hotId, table) {
return store.mutations.pushTableSchema(store.state, {
hotId: hotId,
tableSchema: table
})
}

export async function guessColumnProperties() {
console.log('about to guess...')
let activeHot = HotRegister.getActiveHotIdData()
let table = await initDataAndInferSchema(activeHot.data)
await storeData(activeHot.id, table)
// let tableDescriptor = table.schema.descriptor
// return {
// 'hotId': activeHot.id,
// 'columnProperties': tableDescriptor.fields
// }
let isStored = storeData(activeHot.id, table)
let message = isStored ? 'Success: Guess column properties succeeded.' : 'Failed: Guess column properties failed.'
return message
}

// function checkRowCells(row, schema) {
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/store/modules/hots.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ const mutations = {
pushTableSchema(state, hotTable) {
console.log('pushing table schema')
let hotId = hotTable.hotId
_.set(state.hotTabs, `${hotId}.tableSchema`, hotTable.tableSchema)
mutations.mergeTableSchemaOverCurrentColumnProperties(state, hotId)
console.log(state.hotTabs)
let tableSchema = _.set(state.hotTabs, `${hotId}.tableSchema`, hotTable.tableSchema)
let columnProperties = mutations.mergeTableSchemaOverCurrentColumnProperties(state, hotId)
return tableSchema && columnProperties
},
mergeTableSchemaOverCurrentColumnProperties(state, hotId) {
let hotTab = state.hotTabs[hotId]
let tableSchemaProperties = hotTab.tableSchema.schema.descriptor.fields
if (!hotTab.columnProperties) {
hotTab.columnProperties = []
}
_.merge(hotTab.columnProperties, tableSchemaProperties)
return _.merge(hotTab.columnProperties, tableSchemaProperties)
},
mergeCurrentColumnPropertiesOverTableSchema(state, hotId) {
let hotTab = state.hotTabs[hotId]
Expand Down

0 comments on commit c8dfd2b

Please sign in to comment.