load icons, nests and states

show the first nest on the map <3 <3 <3
This commit is contained in:
Torben Indorf
2020-02-11 21:55:54 +01:00
parent 3770a4111a
commit 6fe11728eb
11 changed files with 243 additions and 9 deletions
+40
View File
@@ -0,0 +1,40 @@
import { ActionTree, Module } from 'vuex';
import { RepositoryFactory } from '@/api/RepositoryFactory';
import NestRepository from '@/api/NestRepository';
import { Nest } from '@/models/Nest';
const nestRepository: NestRepository = RepositoryFactory.get('nest');
const store = {
nests: undefined,
};
const actions: ActionTree<any, any> = {
findAll: async ({ commit }, payload: { areaId: string }): Promise<Nest[]> => {
const response = await nestRepository.findAll(payload.areaId);
const nests: Nest[] = response.map((nestData: any) =>
new Nest(nestData));
commit('saveNests', nests);
return nests;
},
};
const mutations = {
saveNests: (state: any, nests: any) => {
state.nests = nests;
},
};
const getters = {
nests: (state: any) => state.nests,
};
const nestStore: Module<any, any> = {
state: store,
actions,
mutations,
getters
};
export default nestStore;
+58
View File
@@ -0,0 +1,58 @@
import { ActionTree, Module } from 'vuex';
import AuthRepository from '@/api/AuthRepository';
import { RepositoryFactory } from '@/api/RepositoryFactory';
import AreaRepository from '@/api/AreaRepository';
import { Area } from '@/models/Area';
import StatusRepository from '@/api/StatusRepository';
import { Status } from '@/models/Status';
const statusRepository: StatusRepository = RepositoryFactory.get('status');
const store = {
status: undefined,
icons: undefined
};
const actions: ActionTree<any, any> = {
findAll: async ({ commit }): Promise<Status[]> => {
const response = await statusRepository.findAll();
const status: Status[] = response.map((statusData: any) =>
new Status(statusData));
commit('saveStatus', status);
return status;
},
getIcons: async ({ commit }, lastUpdate?: Date):
Promise<any> => {
const response = await statusRepository.getIcons(lastUpdate);
console.log(response);
commit('saveIcons', response);
return response;
},
};
const mutations = {
saveStatus: (state: any, status: any) => {
state.status = status;
},
saveIcons: (state: any, iconData: any) => {
state.icons = iconData;
}
};
const getters = {
status: (state: any) => state.status,
icons: (state: any) => state.icons,
};
const statusStore: Module<any, any> = {
state: store,
actions,
mutations,
getters
};
export default statusStore;
+10
View File
@@ -4,6 +4,8 @@ import VuexPersistence from 'vuex-persist';
import authStore from '@/store/auth.store';
import globalStore from '@/store/global.store';
import areaStore from '@/store/area.store';
import statusStore from '@/store/status.store';
import nestStore from '@/store/nest.store';
Vue.use(Vuex);
// set up persistence storage plugin
@@ -29,6 +31,14 @@ export default new Vuex.Store({
area: {
namespaced: true,
...areaStore
},
status: {
namespaced: true,
...statusStore
},
nest: {
namespaced: true,
...nestStore
}
},
plugins: [vuexPersistence.plugin]