Skip to content

Commit

Permalink
New source improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
jlpereira committed Feb 19, 2020
1 parent 88c9297 commit 825f244
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/javascript/vue/tasks/sources/new_source/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
</template>
</div>
<div class="horizontal-right-content">
<span
v-if="unsave"
class="medium-icon margin-small-right"
title="You have unsaved changes."
data-icon="warning"/>
<button
v-shortkey="[getMacKey(), 's']"
@shortkey="saveSource"
Expand Down Expand Up @@ -156,6 +161,10 @@ export default {
set (value) {
this.$store.commit(MutationNames.SetSettings, value)
}
},
unsave() {
let settings = this.$store.getters[GetterNames.GetSettings]
return settings.lastSave < settings.lastEdit
}
},
data () {
Expand All @@ -165,6 +174,14 @@ export default {
showRecent: false
}
},
watch: {
source: {
handler () {
this.settings.lastEdit = Date.now()
},
deep: true
}
},
mounted () {
TW.workbench.keyboard.createLegend(`${this.getMacKey()}+s`, 'Save', 'New source')
TW.workbench.keyboard.createLegend(`${this.getMacKey()}+n`, 'New', 'New source')
Expand Down
15 changes: 15 additions & 0 deletions app/javascript/vue/tasks/sources/new_source/components/matches.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export default {
set (value) {
return this.$store.commit(MutationNames.SetSource, value)
}
},
saving () {
return this.$store.getters[GetterNames.GetSettings].saving
}
},
data () {
Expand Down Expand Up @@ -67,11 +70,23 @@ export default {
},
deep: true,
immediate: true
},
saving (newVal) {
if(!newVal) {
this.getRecent ()
}
}
},
methods: {
getRecent () {
this.searching = true
AjaxCall('get', `/sources?query_term=${this.source.title}&per=5`).then(response => {
if(this.source.id) {
let index = response.body.findIndex(item => { return item.id === this.source.id })
if(index > -1) {
response.body.splice(index, 1)
}
}
this.founded = response.body
this.searching = false
}, () => { this.searching = false })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default ({ state, commit }, id) => {
})

setParam('/tasks/sources/new_source', 'source_id', response.body.id)
console.log("se")
state.settings.lastSave = Date.now()
}, () => {
TW.workbench.alert.create('No source was found with that ID.', 'alert')
history.pushState(null, null, `/tasks/sources/new_source`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import newSource from '../../const/source'
export default ({ state, commit }) => {
let source = newSource()
let locked = state.settings.lock
state.settings.lastEdit = 0
state.settings.lastSave = 0

Object.keys(locked).forEach(key => {
source[key] = locked[key] ? state.source[key] : undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CreateSource, UpdateSource, LoadSoftValidation } from '../../request/re
import setParam from 'helpers/setParam'

export default ({ state, commit }) => {
state.settings.saving = true
if(state.source.id) {
UpdateSource(state.source).then(response => {
commit(MutationNames.SetSource, response.body)
Expand All @@ -16,7 +17,11 @@ export default ({ state, commit }) => {
LoadSoftValidation(response.body.global_id).then(response => {
commit(MutationNames.SetSoftValidation, response.body.validations.soft_validations)
})
state.settings.saving = false
state.settings.lastSave = Date.now() + 100
TW.workbench.alert.create('Source was successfully updated.', 'notice')
}, () => {
state.settings.saving = false
})
} else {
CreateSource(state.source).then(response => {
Expand All @@ -30,7 +35,11 @@ export default ({ state, commit }) => {
LoadSoftValidation(response.body.global_id).then(response => {
commit(MutationNames.SetSoftValidation, response.body.validations.soft_validations)
})
state.settings.saving = false
state.settings.lastSave = Date.now() + 100
TW.workbench.alert.create('Source was successfully created.', 'notice')
}, () => {
state.settings.saving = false
})
}
}
2 changes: 2 additions & 0 deletions app/javascript/vue/tasks/sources/new_source/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ function makeInitialState () {
settings: {
saving: false,
loading: false,
lastSave: 0,
lastEdit: 0,
lock: {
type: false,
language_id: false,
Expand Down

0 comments on commit 825f244

Please sign in to comment.