INIT commit

This commit is contained in:
Michal Kváček
2023-05-31 20:44:10 +02:00
commit a3e8917db5
73 changed files with 5405 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
import {defineStore} from 'pinia'
import {apolloWrapper} from "src/graphql/apollo";
import {AIRCRAFT_DETAIL, AIRCRAFTS_LIST} from "src/graphql/queries/aircrafts";
import {CREATE_AIRCRAFT, DELETE_AIRCRAFT, EDIT_AIRCRAFT} from "src/graphql/mutations/aircrafts";
import {reactive} from "vue";
export const useAircraftsStore = defineStore('Aircrafts', {
state: () => ({
items: []
}),
getters: {
getDetail: (state) => (aircraftId) => state.items.find(a => a.id === aircraftId) || {}
},
actions: {
fetchDetail(id) {
return apolloWrapper
.query(AIRCRAFT_DETAIL, {id})
.then((result) => {
return result.data.aircraft;
});
},
create(formData) {
delete formData['id'];
return apolloWrapper.mutate(CREATE_AIRCRAFT, {input: formData}).then(({data}) => {
// this.items.push(data.createAircraft);
return data.createAircraft;
})
},
delete(id) {
return apolloWrapper.mutate(DELETE_AIRCRAFT, {id}).then(({data}) => {
// const idx = this.items.findIndex(a => a.id === id);
// console.log(idx);
// this.items.splice(idx, 1);
this.items = this.items.filter(a => {
console.log(a.id, id);
return a.id !== id
});
console.log(this.items);
return data;
});
},
update(id, formData) {
console.log(id, formData);
return apolloWrapper.mutate(EDIT_AIRCRAFT, {id: id, input: formData}).then(({data}) => {
return data.editAircraft;
});
},
fetch() {
/***
* {id: id, name: "OK-ABC" + id, private: true, limits: {wind: {frontKt: 22, sideKt: 16}, speed: {vmax: 220}}};
*/
return apolloWrapper
.query(AIRCRAFTS_LIST)
.then((result) => {
this.items = result.data.aircrafts;
return result.data.aircrafts;
});
}
}
})
+14
View File
@@ -0,0 +1,14 @@
import {defineStore} from 'pinia'
export const useAppStore = defineStore('App', {
state: () => ({
pageTitle: null,
fabButton: {icon: null, label: null, action: {}}
}),
getters: {
},
actions: {
}
})
+51
View File
@@ -0,0 +1,51 @@
import {defineStore} from 'pinia'
import {apolloClient} from "src/graphql/apollo"
import {FLIGHTS_LIST} from "src/graphql/queries/flights";
export const useFlightsStore = defineStore('Flights', {
state: () => ({
items: []
}),
getters: {
getDetail: (state) => (flightId) => {
console.log(state.items);
return state.items.find(f => f.id === flightId);
},
},
actions: {
create(formData) {
this.items.push(formData);
},
fetchDetail(id) {
this.items.push({id: id, takeOffLocation: "LKLT", landingLocation: "LKLT", date: "2023-02-01", aircraft: {id: 1, name: "OK-AUR28"}, flightDurationMinutes: 76})
},
fetch() {
apolloClient
.query({
query: FLIGHTS_LIST,
})
.then((result) => console.log(result));
// if (this.items.length > 0) return;
//
// this.$patch({
// items: [
// {id: 1, takeOffLocation: "LKLT", titlePhotoUrl: null, landingLocation: "LKLC", date: "2023-03-03", aircraft: {id: 1, name: "OK-AUR28"}, flightDurationMinutes: 63},
// {id: 2, takeOffLocation: "LKLT", titlePhotoUrl: "https://cdn.quasar.dev/img/mountains.jpg", landingLocation: "LKLT", date: "2023-02-01", aircraft: {id: 1, name: "OK-AUR28"}, flightDurationMinutes: 76},
// {id: 3, takeOffLocation: "LKLT", titlePhotoUrl: null, landingLocation: "LKLC", date: "2023-04-03", aircraft: {id: 1, name: "OK-AUR28"}, flightDurationMinutes: 53},
// {id: 4, takeOffLocation: "LKLT", titlePhotoUrl: null, landingLocation: "LKMB", date: "2023-03-04", aircraft: {id: 1, name: "OK-AUR28"}, flightDurationMinutes: 75},
// {id: 5, takeOffLocation: "LKLT", titlePhotoUrl: null, landingLocation: "LKMH", date: "2023-01-46", aircraft: {id: 1, name: "OK-AUR28"}, flightDurationMinutes: 23},
// ]
// });
},
deleteItem(id) {
const idx = this.items.indexOf(this.items.find(f => f.id === id));
this.items.splice(idx, 1);
console.log("maxu let ID " + id + " na indexu " + idx);
}
}
})
+52
View File
@@ -0,0 +1,52 @@
import {defineStore} from 'pinia'
export const usePointsOfInterestStore = defineStore('PointsOfInterest', {
state: () => ({
items: []
}),
getters: {
getDetail: (state) => (poiId) => {
console.log(poiId, state.items, state.items.length);
const item = state.items.find(p => {
console.log(p, poiId);
return p.id === poiId
}
);
console.log('item', item);
return item;
},
pointTypeName() {
return (typeName) => {
const typeToNameMap = {
poi: "General POI",
airport: "Airport",
}
return typeToNameMap[typeName] || "Unknown";
}
},
groupByTypes() {
const groupedByType = {};
for (const item of this.items) {
if (!groupedByType[item.type]) groupedByType[item.type] = [];
groupedByType[item.type].push(item);
}
return groupedByType;
}
},
actions: {
fetchDetail(poiId) {
console.log("fetch poi detail");
this.items.push({id: poiId, "name": "Zamek " + poiId, "type": "poi", "location": {"lat": 50, "lng": 10}});
},
fetch() {
console.log("fetch poi");
this.items = [
{id: 1, "name": "LKLT", private: false, "type": "airport", "location": {"lat": 50, "lng": 10}},
{id: 2, "name": "Hrad", "type": "poi", "location": {"lat": 50, "lng": 10}},
{id: 3, "name": "Zamek", "type": "poi", "location": {"lat": 50, "lng": 10}},
]
}
}
})
+26
View File
@@ -0,0 +1,26 @@
import {defineStore} from 'pinia'
export const useSecondPilotsStore = defineStore('SecondPilots', {
state: () => ({
items: []
}),
getters: {},
actions: {
create(formData) {
this.items.push(formData);
},
fetch() {
if (this.items.length > 0) return;
this.$patch({
items: [
{id: 1, name: "Karel Franta", isInstructor: false},
{id: 2, name: "Franta Pepa", isInstructor: false},
{id: 3, name: "Instruktor Letajici", isInstructor: true},
]
});
}
}
})
+63
View File
@@ -0,0 +1,63 @@
import {defineStore} from 'pinia'
import {api} from "boot/axios";
export const useUserStore = defineStore('LoggedUser', {
state: () => ({
user: {},
accessToken: null
}),
actions: {
setAccessToken(token) {
console.log(token);
if (token) {
localStorage.setItem("accessToken", token);
}
this.accessToken = localStorage.getItem("accessToken");
},
getAccessToken() {
if (!this.accessToken) {
this.setAccessToken();
}
return this.accessToken;
},
async setupCredentials() {
await api.get("/me").then(({data}) => {
this.user = data;
}).catch(e => {
console.log(e);
});
},
async register(formData) {
return api.post('/registration', formData).then(response => {
const registeredUser = response.data;
const isSuccess = response.status === 201
})
},
async login(formData) {
return api.post("/login", formData).then(response => {
const data = response.data;
console.log("data", data);
this.setAccessToken(data.access_token);
this.user = data.user;
})
// console.log("login", username, password);
// Object.assign(this.user, {
// id: 1,
// email: "michal@kvacek.cz",
// name: "Michal K.",
// accessToken: "abcdef",
// avatarImageUrl: "https://via.placeholder.com/50x50"
// });
},
logout() {
Object.assign(this.user, {});
}
}
})
+21
View File
@@ -0,0 +1,21 @@
import { store } from 'quasar/wrappers'
import { createPinia } from 'pinia'
/*
* If not building with SSR mode, you can
* directly export the Store instantiation;
*
* The function below can be async too; either use
* async/await or return a Promise which resolves
* with the Store instance.
*/
export default store((/* { ssrContext } */) => {
const pinia = createPinia()
console.log("Pinia index");
// You can add Pinia plugins here
// pinia.use(SomePiniaPlugin)
return pinia
})
+10
View File
@@ -0,0 +1,10 @@
/* eslint-disable */
// THIS FEATURE-FLAG FILE IS AUTOGENERATED,
// REMOVAL OR CHANGES WILL CAUSE RELATED TYPES TO STOP WORKING
import "quasar/dist/types/feature-flag";
declare module "quasar/dist/types/feature-flag" {
interface QuasarFeatureFlags {
store: true;
}
}