diff options
author | Phil Hughes <me@iamphill.com> | 2017-04-11 16:36:13 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-04-11 16:36:13 +0300 |
commit | cede16f5a2d9d774aef911177a1c23c129dbb7f1 (patch) | |
tree | 218fa9bcf275dcb65b9ec406b0be45a1ea2c3b12 /app | |
parent | 7173ab8e1fc72c93ec6f6915ec7f5ecb8893d1b9 (diff) |
Code improvements
More specs
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/blob/xlsx/components/table.vue | 15 | ||||
-rw-r--r-- | app/assets/javascripts/blob/xlsx/components/tabs.vue | 11 | ||||
-rw-r--r-- | app/assets/javascripts/blob/xlsx/index.vue | 10 |
3 files changed, 21 insertions, 15 deletions
diff --git a/app/assets/javascripts/blob/xlsx/components/table.vue b/app/assets/javascripts/blob/xlsx/components/table.vue index 6f9389132d8..256d3fa9f26 100644 --- a/app/assets/javascripts/blob/xlsx/components/table.vue +++ b/app/assets/javascripts/blob/xlsx/components/table.vue @@ -33,8 +33,6 @@ </template> <script> -import 'vendor/jquery.scrollTo'; - export default { name: 'XLSXTable', props: { @@ -50,8 +48,9 @@ export default { }, methods: { linePath(index) { - let hash = location.hash.replace('#', ''); - hash = hash.replace(/-?L(\d+)$/g, ''); + const hash = location.hash + .replace('#', '') + .replace(/-?L(\d+)$/g, ''); if (hash !== '') { return `#${hash}-L${index + 1}`; @@ -63,10 +62,12 @@ export default { this.currentLineNumber = index + 1; }, getCurrentLineNumberFromUrl() { - const hash = location.hash.replace('#', '').split('-'); - const lineHash = hash[hash.length - 1]; + const hash = location.hash + .replace('#', '') + .split('-') + .pop(); - this.currentLineNumber = parseInt(lineHash.replace('L', ''), 10); + this.currentLineNumber = parseInt(hash.replace('L', ''), 10); }, }, watch: { diff --git a/app/assets/javascripts/blob/xlsx/components/tabs.vue b/app/assets/javascripts/blob/xlsx/components/tabs.vue index 40bdcf6a45f..88375615e17 100644 --- a/app/assets/javascripts/blob/xlsx/components/tabs.vue +++ b/app/assets/javascripts/blob/xlsx/components/tabs.vue @@ -3,10 +3,10 @@ <li class="prepend-left-10" v-for="name in sheetNames" - :class="{ 'active': name === currentSheetName }"> + :class="{ active: name === currentSheetName }"> <a - href="#" - @click.prevent="changeSheet(name)"> + :href="getTabPath(name)" + @click="changeSheet(name)"> {{ name }} </a> </li> @@ -30,10 +30,11 @@ export default { }, methods: { changeSheet(name) { - location.hash = encodeURIComponent(name); - eventHub.$emit('update-sheet', name); }, + getTabPath(name) { + return `#${encodeURIComponent(name)}`; + }, }, }; </script> diff --git a/app/assets/javascripts/blob/xlsx/index.vue b/app/assets/javascripts/blob/xlsx/index.vue index 6cd6741fcfc..d841066cc87 100644 --- a/app/assets/javascripts/blob/xlsx/index.vue +++ b/app/assets/javascripts/blob/xlsx/index.vue @@ -55,13 +55,14 @@ export default { return this.sheetNames.find(sheet => sheet === hash) || this.sheetNames[0]; }, + updateSheetName(name) { + this.currentSheetName = name; + }, }, created() { this.service = new Service(this.endpoint); - eventHub.$on('update-sheet', (name) => { - this.currentSheetName = name; - }); + eventHub.$on('update-sheet', this.updateSheetName); }, mounted() { this.service.getData() @@ -71,6 +72,9 @@ export default { this.loading = false; }); }, + beforeDestroy() { + eventHub.$off('update-sheet', this.updateSheetName); + }, components: { xlsxTabs, xlsxTable, |