Haris Razis
4 years ago
19 changed files with 317 additions and 195 deletions
After Width: | Height: | Size: 90 KiB |
@ -1,15 +1,82 @@ |
|||
import {Module, Mutation, VuexModule} from 'vuex-module-decorators' |
|||
import {Action, Module, Mutation, VuexModule} from 'vuex-module-decorators' |
|||
import axios, {AxiosResponse} from "axios"; |
|||
|
|||
export interface AthleteData { |
|||
measurement: Date, |
|||
pointName: string, |
|||
} |
|||
|
|||
@Module |
|||
export default class Backend extends VuexModule { |
|||
private serverStatus = false |
|||
private serverStatus = false; |
|||
private liveAthData: AthleteData[] = []; |
|||
|
|||
get server_status() { |
|||
return this.serverStatus; |
|||
} |
|||
|
|||
get server_liveData() { |
|||
return this.liveAthData; |
|||
} |
|||
|
|||
@Mutation |
|||
private socket_connection(status: boolean) { |
|||
this.serverStatus = status; |
|||
} |
|||
|
|||
@Mutation |
|||
private server_queueData(data: AthleteData) { |
|||
this.liveAthData.push(data); |
|||
} |
|||
|
|||
get currentServerStatus() { |
|||
return this.serverStatus |
|||
@Mutation |
|||
private server_dequeueData() { |
|||
this.liveAthData.shift(); |
|||
} |
|||
|
|||
@Mutation |
|||
private serverConnected(status: boolean) { |
|||
this.serverStatus = status |
|||
private server_logout() { |
|||
this.liveAthData = [] |
|||
} |
|||
|
|||
@Action |
|||
private server_saveLiveData(data: AthleteData) { |
|||
console.log(this.liveAthData); |
|||
this.context.commit('server_queueData', data); |
|||
if (this.liveAthData.length > 15) |
|||
this.context.commit('server_dequeueData'); |
|||
} //Too "expensive" of an action? To be refactored.
|
|||
|
|||
@Action |
|||
private server_getAll() { |
|||
return new Promise((resolve, reject) => { |
|||
axios({ |
|||
method: 'GET', |
|||
url: `/api/data/` |
|||
}) |
|||
.then((resp: AxiosResponse) => { |
|||
resolve(resp) |
|||
}) |
|||
.catch((err: Error) => { |
|||
reject(err) |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
@Action |
|||
private server_getOne(id: string) { |
|||
return new Promise((resolve, reject) => { |
|||
axios({ |
|||
method: 'GET', |
|||
url: `/api/data/${id}` |
|||
}) |
|||
.then((resp: AxiosResponse) => { |
|||
resolve(resp) |
|||
}) |
|||
.catch((err: Error) => { |
|||
reject(err) |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue