Skip to content

Commit

Permalink
close #138
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidZhang73 committed Mar 6, 2022
1 parent e3e9819 commit 25b4f0e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ if (showPopup) {
preferenceStore.showPopup = false
}
}
window.addEventListener('beforeunload', event => {
if (annotationStore.hasVideo && !mainStore.isSaved) {
event.returnValue = 'The annotations are not saved!'
}
})
</script>
<style lang="sass">
Expand Down
17 changes: 14 additions & 3 deletions src/store/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import deepClone from 'lodash.clonedeep'
import { defineStore } from 'pinia'
import { computed, reactive, toRefs, watch } from 'vue'
import utils from '~/libs/utils.js'
import { useMainStore } from '~/store/index.js'
import { usePreferenceStore } from '~/store/preference.js'
import { ActionAnnotation, ObjectAnnotation, RegionAnnotation, SkeletonAnnotation } from '../libs/annotationlib.js'

Expand Down Expand Up @@ -35,13 +36,12 @@ const DEFAULT_ANNOTATION = {
copyMode: false,
addPointMode: false,
delPointMode: false,
indicatingMode: false,

isSaved: true
indicatingMode: false
}

export const useAnnotationStore = defineStore('annotation', () => {
const preferenceStore = usePreferenceStore()
const mainStore = useMainStore()
let defaultAnnotation = deepClone(DEFAULT_ANNOTATION)
const state = reactive(DEFAULT_ANNOTATION)
watch(
Expand Down Expand Up @@ -77,6 +77,15 @@ export const useAnnotationStore = defineStore('annotation', () => {
state.leftCurrentFrame = 0
}
})
watch(() => [
state.objectAnnotationListMap,
state.regionAnnotationListMap,
state.skeletonAnnotationListMap,
state.actionAnnotationList,
state.keyframeList
], () => {
mainStore.isSaved = false
}, { deep: true })
return {
...toRefs(state),
hasVideo: computed(() => {
Expand Down Expand Up @@ -108,6 +117,7 @@ export const useAnnotationStore = defineStore('annotation', () => {
}
})
}
mainStore.isSaved = true
return {
video: state.video,
keyframeList: state.keyframeList,
Expand Down Expand Up @@ -200,6 +210,7 @@ export const useAnnotationStore = defineStore('annotation', () => {
)
}
state.actionAnnotationList = actionAnnotationList
mainStore.isSaved = true
}
}
})
2 changes: 1 addition & 1 deletion src/store/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export const useConfigurationStore = defineStore('configuration', () => {
return {
objectLabelData: state.objectLabelData,
actionLabelData: state.actionLabelData,
skeletonTypeData: state.skeletonTypeData,
skeletonTypeData: state.skeletonTypeData
}
},
importObjectLabelData,
Expand Down
3 changes: 2 additions & 1 deletion src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const useMainStore = defineStore('main', {
state: () => ({
drawer: false,
zoom: false,
submitURL: null
submitURL: null,
isSaved: true
})
})

0 comments on commit 25b4f0e

Please sign in to comment.