Skip to content

Commit b02926d

Browse files
authored
Merge pull request #358 from armd-pro/master
#137 Unit tests.
2 parents ebd025e + a92076b commit b02926d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2666
-475
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"express": "^4.16.4",
7979
"extract-text-webpack-plugin": "^4.0.0-beta.0",
8080
"file-loader": "^1.1.11",
81+
"flush-promises": "^1.0.2",
8182
"friendly-errors-webpack-plugin": "^1.7.0",
8283
"html-webpack-plugin": "^3.2.0",
8384
"http-proxy-middleware": "^0.19.1",

src/components/AppHeader.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<b-col class="sign-block text-right" cols="4" md="2" order="5" order-md="5">
3232
<span class="sign-in-out" v-if="$store.getters.user.authenticated">
33-
<a href="javascript:void(0)" v-on:click="signOut" key="sign-out">
33+
<a href="#" v-on:click.prevent="signOut" key="sign-out" data-btn="sign-out">
3434
Выйти <i class="fa fa-times" />
3535
</a>
3636
</span>

src/components/CountersHeader.vue

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
:variant="showTrainingEvents ? 'event-training' : 'info'"
2323
:disabled="trainingEventsBtnDisabled"
2424
:pressed.sync="showTrainingEvents"
25+
id="showTraining"
2526
size="sm">{{ showTrainingEvents ? 'Скрыть' : 'Показать' }} учебные</b-btn>
2627

2728
<ModalMap v-if="showModalMap && count > 0" :filtersData="filtersData" />

src/components/Events.vue

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
22
<div class="events">
33
<CountersHeader v-if="!error"
4+
:trainingEventsBtnShow="$store.getters.user.authenticated"
45
:trainingEventsBtnDisabled="spinners.loadMoreEvents"
56
@toggleTrainingEvents="toggleTrainingEvents"
6-
:trainingEventsBtnShow="true"
77
:filtersData="filtersData"
88
:showModalMap="true"
99
:count="events.length"
@@ -69,7 +69,7 @@
6969
<b-row class="load-more-events" no-gutters>
7070
<b-col class="text-center">
7171
<Spinner v-if="spinners.loadMoreEvents" />
72-
<a href="#" v-if="apiParams.cursor && !spinners.loadMoreEvents"
72+
<a href="#" v-if="apiParams.cursor && !spinners.loadMoreEvents" id="loadMoreEventsBtn"
7373
@click.prevent="loadMoreEvents">Показать больше событий</a>
7474
<span v-if="!apiParams.cursor">Загружены все события</span>
7575
</b-col>
@@ -104,7 +104,7 @@ export default {
104104
disabledFilters: false,
105105
highlightEventTreshold: eventsSettings.highlightTreshold,
106106
spinners: {
107-
loadMoreEvents: false
107+
loadMoreEvroundents: false
108108
},
109109
startDate: '',
110110
endDate: ''
@@ -114,12 +114,13 @@ export default {
114114
round: function() {
115115
return round
116116
},
117-
datetimeFormat: function() {
117+
datetimeFormat: function()
118+
{
118119
if (this.$root.onMobile) {
119120
return 'L в HH:mm:ss'
120-
} else {
121-
return 'LL в HH:mm:ss UTC'
122121
}
122+
123+
return 'LL в HH:mm:ss UTC'
123124
},
124125
backUrlQuery: function()
125126
{
@@ -211,9 +212,6 @@ export default {
211212
loadMoreEvents: function() {
212213
this.getEvents()
213214
},
214-
openEvent: function(item, index, event) {
215-
this.$router.push({ name: 'Event', params: { id: item.id } })
216-
},
217215
toggleTrainingEvents: function(checked) {
218216
this.$refs.filters.filters.has_training = checked ? 1 : null
219217
this.$refs.filters.send()

src/components/ExportDropDown.vue

+10-8
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,22 @@
2727
this.$emit('export2xls', (url, params) => {
2828
2929
this.$http.get(url, {
30+
3031
params: Object.assign(Object.assign({}, params), {
3132
include: 'nearestCity',
3233
export_to: 'xlsx'
3334
})
35+
36+
}).then(response => {
37+
38+
window.location.href = response.data.data.url
39+
this.$refs.dropdown.visible = false
40+
this.xlsSpinnerShow = false
41+
3442
})
35-
.then(response => {
36-
window.location.href = response.data.data.url
37-
this.$refs.dropdown.visible = false
38-
this.xlsSpinnerShow = false
39-
})
40-
.catch(error => {
41-
console.log(error)
42-
})
43+
4344
})
45+
4446
},
4547
onHide: function(e) {
4648
!this.xlsSpinnerShow || e.preventDefault()

src/components/StaticPage.vue

+3-8
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,9 @@ export default {
2323
}
2424
},
2525
methods: {
26-
getContent: async function() {
27-
return await this.$http.get(`/static/markdown/${this.page}.md`)
28-
.then(response => {
29-
this.content = response.data
30-
})
31-
.catch(error => {
32-
console.log(error)
33-
})
26+
getContent: function() {
27+
this.$http.get(`/static/markdown/${this.page}.md`)
28+
.then(response => { this.content = response.data })
3429
}
3530
},
3631
created() {

src/components/charts/ChartByDatetime.vue

+8-6
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,19 @@ export default Line.extend({
6868
drawChart: function(params = {}) {
6969
this.$http.get(apiSettings.endpointAnalyticsEarthquakeCounts, { params: params })
7070
.then(response => {
71-
const dates = this.prepareDates(response.data.data.dates)
71+
72+
const respData = response.data.data
73+
74+
const dates = this.prepareDates(respData.dates)
7275
this.chartData.datasets[0].label = 'Количество землетрясений'
73-
this.chartData.datasets[0].data = response.data.data.counts
76+
this.chartData.datasets[0].data = respData.counts
7477
this.chartData.labels = dates
7578
7679
// Pass data to the Analytics.vue component.
7780
this.$emit('update', {
78-
eventsCount: response.data.data.total_count,
79-
startDate: this.$moment(response.data.data.range.start).format('L'),
80-
endDate: this.$moment(response.data.data.range.end).format('L')
81+
eventsCount: respData.total_count,
82+
startDate: this.$moment(respData.range.start).format('L'),
83+
endDate: this.$moment(respData.range.end).format('L')
8184
})
8285
8386
// Ugly hack to prevent showing old data on hovering.
@@ -88,7 +91,6 @@ export default Line.extend({
8891
8992
this.renderChart(this.chartData, this.options)
9093
})
91-
.catch(error => { console.log(error) })
9294
},
9395
prepareDates: function(dates) {
9496
return dates.map(date => {

src/components/charts/ChartByDensityCounts.vue

+5-3
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,12 @@ export default Line.extend({
7474
drawChart: function(params = {}) {
7575
this.$http.get(apiSettings.endpointAnalyticsDensityCounts, { params: params })
7676
.then(response => {
77+
78+
const respData = response.data.data
79+
7780
this.chartData.datasets[0].label = 'Плотностное распределение повторяемости (ML)'
78-
this.chartData.datasets[0].data = response.data.data.counts
79-
this.chartData.labels = response.data.data.magnitudes
81+
this.chartData.datasets[0].data = respData.counts
82+
this.chartData.labels = respData.magnitudes
8083
8184
// Ugly hack to prevent showing old data on hovering.
8285
// No idea why it doesn't covered by https://github.com/apertureless/vue-chartjs/blob/master/src/BaseCharts.js#L71
@@ -86,7 +89,6 @@ export default Line.extend({
8689
8790
this.renderChart(this.chartData, this.options)
8891
})
89-
.catch(error => { console.log(error) })
9092
}
9193
},
9294
watch: {

src/components/charts/ChartByMagnitudeCumulative.vue

-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export default Line.extend({
9191
9292
this.renderChart(this.chartData, this.options)
9393
})
94-
.catch(error => { console.log(error) })
9594
}
9695
},
9796
watch: {

src/components/event/Buildings.vue

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
this.$root.$emit('onMapBuildingsDataFetched', response.data.data)
105105
this.setData(response.data.data)
106106
})
107-
.catch(error => { console.log(error) })
108107
},
109108
setData: function(buildings) {
110109
let itemsLen = this.items.length

src/components/event/LDOs.vue

+1-4
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ export default {
7272
this.$root.$emit('onMapLDOsDataFetched', response.data.data)
7373
this.setData(response.data.data)
7474
})
75-
.catch(error => { console.log(error) })
7675
},
7776
setData: function(data) {
7877
const damagedParts = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0 }
@@ -85,8 +84,6 @@ export default {
8584
})
8685
})
8786
88-
const msk64ConfigVersion = this.$store.getters.msk64ConfigVersion
89-
9087
Object.keys(damagedParts).forEach((k, i) => {
9188
this.items[i].value = damagedParts[k]
9289
})
@@ -99,7 +96,7 @@ export default {
9996
10097
this.items[6].value = this.$store.getters.srssDBVersion
10198
this.items[7].value = data.length
102-
this.items[8].value = `${msk64ConfigVersion}`
99+
this.items[8].value = this.$store.getters.msk64ConfigVersion
103100
104101
this.spinner = false
105102
}

src/components/event/LastEvents.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
.then(response => {
7373
7474
response.data.data.forEach(event => {
75+
7576
if (event.nearestCity) {
7677
const distance = round(event.nearestCity.data.ep_dis, 2)
7778
const title = event.nearestCity.data.settlement.data.translation.data.title
@@ -81,10 +82,9 @@
8182
}
8283
8384
this.events.push(event)
85+
8486
})
85-
})
86-
.catch(error => {
87-
console.log(error.response)
87+
8888
})
8989
},
9090
highlightEvent: function(id) {

src/components/event/MomentTensor.vue

-3
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,6 @@
142142
.then(response => {
143143
this.setData(response.data.data[0])
144144
})
145-
.catch(error => {
146-
console.log(error)
147-
})
148145
},
149146
setData: function(data) {
150147
this.setImage(data)

src/components/event/Settlements.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@
9595
cursor: this.cursor,
9696
limit: 10
9797
}
98+
}).then(response => {
99+
this.setData(response.data.data)
98100
})
99-
.then(response => { this.setData(response.data.data) })
100-
.catch(error => { console.log(error) })
101101
},
102102
setData(data) {
103103
data.forEach(settlement => {

src/components/event/Tabs.vue

+4-5
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@
5757
},
5858
currentTabName: function() {
5959
const currentTab = Object.keys(this.tabs).find(key => {
60-
return this.tabs[key].href === this.activeTab
60+
return this.isTabActive(this.tabs[key])
6161
})
6262
63-
if (currentTab) return this.tabs[currentTab].label
64-
65-
return 'Информация о событии'
63+
return currentTab
64+
? this.tabs[currentTab].label
65+
: 'Информация о событии'
6666
},
6767
isTabActive: function(tab) {
6868
return this.activeTab === tab.href
@@ -135,7 +135,6 @@
135135
},
136136
created() {
137137
this.setData()
138-
this.currentTabName()
139138
},
140139
watch: {
141140
event: function() {

src/components/maps/GeneralInformation.vue

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
methods: {
2424
addData: function(data) {
25+
2526
let legendData = `
2627
<table>
2728
<thead>
@@ -34,6 +35,7 @@
3435
<tbody>`
3536
3637
Object.keys(data).forEach((key) => {
38+
3739
const lineColor = this.pgaLineColor(key)
3840
const pga = window.L.polygon(data[key].data, { color: lineColor, weigh: 2 })
3941

src/components/maps/Mainpage.vue

-3
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@
133133
disableBtns(false)
134134
setReloadTimer()
135135
})
136-
.catch(error => {
137-
console.log(error.response || error)
138-
})
139136
}
140137
141138
eventsRangeRequests[eventsRangeName] = request

src/components/maps/ModalMap.vue

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class="modal-map">
3-
<b-btn size="sm" v-b-modal.map-dialog>Показать на карте</b-btn>
3+
<b-btn size="sm" id="map-dialog-btn" v-b-modal.map-dialog>Показать на карте</b-btn>
44
<b-modal
55
id="map-dialog"
66
size="lg"
@@ -73,6 +73,7 @@
7373
}
7474
7575
this.map.object.remove()
76+
this.map.object = null
7677
this.title = ''
7778
},
7879
@@ -88,26 +89,30 @@
8889
let _getEvents = function(url)
8990
{
9091
this.$http.get(url, {
92+
9193
params: params,
92-
before: (request) => {
94+
95+
before: (request) =>
96+
{
9397
if (this.previousRequest) {
9498
this.previousRequest.abort()
9599
}
96100
97101
this.previousRequest = request
98102
}
103+
104+
}).then(response => {
105+
106+
events = events.concat(response.data.data)
107+
108+
let pagination = response.data.meta.pagination
109+
let nextPageUrl = pagination.links.next
110+
111+
this.title = `Загружено ${events.length} из ${pagination.total} событий`
112+
113+
nextPageUrl ? _getEvents(nextPageUrl) : callBack(events)
114+
99115
})
100-
.then(response => {
101-
events = events.concat(response.data.data)
102-
let pagination = response.data.meta.pagination
103-
let nextPageUrl = pagination.links.next
104-
this.title = `Загружено ${events.length} из ${pagination.total} событий`
105-
nextPageUrl ? _getEvents(nextPageUrl) : callBack(events)
106-
})
107-
.catch(error => {
108-
this.map.object.spin(false)
109-
console.log(error)
110-
})
111116
112117
}.bind(this)
113118

src/components/maps/Settlements.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
fetchData: function() {
5858
this.$http.get(apiSettings.endpointEventMsk64(this.event.id))
5959
.then(response => { this.addData(response.data.data) })
60-
.catch(error => { console.log(error) })
6160
},
6261
initialize: function() {
6362
this.map.id = id(this.event.id, this.tab)
@@ -68,7 +67,8 @@
6867
},
6968
removeData: function() {
7069
// Remove map legend and MSK64 circles.
71-
this.$el.querySelector('.map-legend').remove()
70+
const legend = this.$el.querySelector('.map-legend')
71+
if (legend) legend.remove()
7272
this.map.circles.forEach(circle => { this.map.object.removeLayer(circle) })
7373
},
7474
resetMap: function() {

0 commit comments

Comments
 (0)