This commit is contained in:
Kamil Klecha
2021-06-01 22:56:36 +02:00
parent d39e9f15e6
commit 3320858efa
20 changed files with 13959 additions and 1 deletions

21
.gitignore vendored Normal file
View File

@@ -0,0 +1,21 @@
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@@ -1 +1,24 @@
fakesw
# fakesw
## Project setup
```
npm install
```
### Compiles and hot-reloads for development
```
npm run serve
```
### Compiles and minifies for production
```
npm run build
```
### Lints and fixes files
```
npm run lint
```
### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).

5
babel.config.js Normal file
View File

@@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

13176
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

51
package.json Normal file
View File

@@ -0,0 +1,51 @@
{
"name": "fakesw",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^0.19.2",
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vue-router": "^3.3.4",
"vuetify": "^2.3.7",
"vuex": "^3.5.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.4.6",
"@vue/cli-plugin-eslint": "~4.4.6",
"@vue/cli-plugin-router": "^4.4.6",
"@vue/cli-plugin-vuex": "^4.4.6",
"@vue/cli-service": "~4.4.6",
"babel-eslint": "^10.1.0",
"eslint": "^7.6.0",
"eslint-plugin-vue": "^6.2.2",
"sass": "^1.26.10",
"sass-loader": "^9.0.2",
"vue-cli-plugin-vuetify": "~2.0.7",
"vue-template-compiler": "^2.6.11",
"vuetify-loader": "^1.6.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 KiB

19
public/index.html Normal file
View File

@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

18
src/App.vue Normal file
View File

@@ -0,0 +1,18 @@
<template>
<v-app>
<Navbar />
<v-main>
<router-view />
</v-main>
<Footer />
</v-app>
</template>
<script>
import Navbar from "./components/Navbar";
import Footer from "./components/Footer";
export default {
name: "App",
components: { Navbar, Footer }
};
</script>

BIN
src/assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@@ -0,0 +1,8 @@
<template>
<v-footer dark color="primary" class="font-weight-medium">
<v-col class="text-center" cols="12">
&copy;
<strong>Kamil Klecha</strong> 2019
</v-col>
</v-footer>
</template>

79
src/components/Index.vue Normal file
View File

@@ -0,0 +1,79 @@
<template>
<v-container fluid fill-height>
<v-layout align-center justify-center>
<v-flex xs12 sm8 md6 lg4>
<v-card outlined>
<v-card-title>Zaloguj się</v-card-title>
<v-card-text>
<v-form>
<v-text-field
label="Login"
prepend-icon="mdi-account"
type="text"
v-model="login"
></v-text-field>
<v-text-field
label="Hasło"
prepend-icon="mdi-lock"
type="password"
v-model="password"
></v-text-field>
</v-form>
</v-card-text>
<v-alert
type="error"
dense
outlined
prominent
class="mx-2 my-0"
:value="isError"
transition="scale-transition"
>
<v-row align="center">
<v-col class="grow">Nieprawidłowy login lub hasło</v-col>
<v-col class="shrink">
<v-btn @click="dismisLoginError()">Ok</v-btn>
</v-col>
</v-row>
</v-alert>
<v-card-actions>
<v-hover v-slot:default="{ hover }">
<v-btn
large
block
:color="hover ? 'success' : 'primary'"
@click="loginUser()"
>Wyślij</v-btn
>
</v-hover>
</v-card-actions>
<v-alert type="info" class="mx-2 mt-0 mb-2" prominent>
Dane do logowania:<br/>Luke:123
</v-alert>
</v-card>
</v-flex>
</v-layout>
</v-container>
</template>
<script>
export default {
data: () => ({
login: null,
password: null,
}),
computed: {
isError() {
return this.$store.getters.isLoginError;
},
},
methods: {
loginUser() {
this.$store.dispatch("login", { login: this.login, pass: this.password });
},
dismisLoginError() {
this.$store.commit("resetLoginError");
},
},
};
</script>

268
src/components/List.vue Normal file
View File

@@ -0,0 +1,268 @@
<template>
<div>
<v-tabs v-model="tab" centered icons-and-text>
<v-tabs-slider></v-tabs-slider>
<v-tab href="#tab-1">
Filmy
<v-icon large>mdi-movie-open</v-icon>
</v-tab>
<v-tab href="#tab-2">
Planety
<v-icon large>mdi-earth</v-icon>
</v-tab>
<v-tab href="#tab-3">
Osoby
<v-icon large>mdi-account-group</v-icon>
</v-tab>
<v-tab href="#tab-4">
Gatunki
<v-icon large>mdi-paw</v-icon>
</v-tab>
<v-tab href="#tab-5">
Statki kosmiczne
<v-icon large>mdi-airplane-takeoff</v-icon>
</v-tab>
<v-tab href="#tab-6">
Pojazdy
<v-icon large>mdi-car-sports</v-icon>
</v-tab>
</v-tabs>
<v-tabs-items v-model="tab">
<v-tab-item value="tab-1">
<TabList :headers="headers.moviesHeaders" data-name="Films" />
</v-tab-item>
<v-tab-item value="tab-2">
<TabList :headers="headers.planetsHeaders" data-name="Planets" />
</v-tab-item>
<v-tab-item value="tab-3">
<TabList :headers="headers.peopleHeaders" data-name="People" />
</v-tab-item>
<v-tab-item value="tab-4">
<TabList :headers="headers.speciesHeaders" data-name="Species" />
</v-tab-item>
<v-tab-item value="tab-5">
<TabList :headers="headers.starshipsHeaders" data-name="Starships" />
</v-tab-item>
<v-tab-item value="tab-6">
<TabList :headers="headers.vehiclesHeaders" data-name="Vehicles" />
</v-tab-item>
</v-tabs-items>
</div>
</template>
<script>
import TabList from "./TabList";
export default {
components: { TabList },
data: () => ({
tab: null,
headers: {
moviesHeaders: [
{
text: "Część",
align: "start",
sortable: true,
value: "episode_id"
},
{
text: "Tytuł",
value: "title"
},
{
text: "Reżyser",
value: "director"
},
{
text: "Producent",
value: "producer"
},
{
text: "Data premiery",
value: "release_date"
}
],
planetsHeaders: [
{
text: "Nazwa",
align: "start",
sortable: true,
value: "name"
},
{
text: "Średnica",
value: "diameter"
},
{
text: "Czas obiegu wokół słońca",
value: "orbital_period"
},
{
text: "Czas obrotu wokół własnej osi",
value: "rotation_period"
},
{
text: "Populacja",
value: "population"
}
],
peopleHeaders: [
{
text: "Nazwa",
align: "start",
sortable: true,
value: "name"
},
{
text: "Wzrost",
value: "height"
},
{
text: "Waga",
value: "mass"
},
{
text: "Kolor włosów",
value: "hair_color"
},
{
text: "Kolor skóry",
value: "skin_color"
},
{
text: "Kolor oczu",
value: "eye_color"
}
],
speciesHeaders: [
{
text: "Nazwa",
align: "start",
sortable: true,
value: "name"
},
{
text: "Typ",
value: "classification"
},
{
text: "Średnia wysokość",
value: "average_height"
},
{
text: "Średnia długość życia",
value: "average_lifespan"
},
{
text: "Kolor oczu",
value: "eye_colors"
},
{
text: "Kolor włosów",
value: "hair_colors"
},
{
text: "Kolor skóry",
value: "skin_colors"
},
{
text: "Język",
value: "language"
}
],
starshipsHeaders: [
{
text: "Nazwa",
align: "start",
sortable: true,
value: "name"
},
{
text: "Typ",
value: "model"
},
{
text: "Klasa statku",
value: "starship_class"
},
{
text: "Producent",
value: "manufacturer"
},
{
text: "Koszt w kredytach",
value: "cost_in_credits"
},
{
text: "Długość",
value: "length"
},
{
text: "Załoga",
value: "crew"
},
{
text: "Pasażerowie",
value: "passengers"
},
{
text: "Prędkość w atmosferze",
value: "max_atmosphering_speed"
},
{
text: "Klasa napędu nadświetlnego",
value: "hyperdrive_rating"
},
{
text: "Pojemność ladunku",
value: "cargo_capacity"
}
],
vehiclesHeaders: [
{
text: "Nazwa",
align: "start",
sortable: true,
value: "name"
},
{
text: "Typ",
value: "model"
},
{
text: "Klasa pojazdu",
value: "vehicle_class"
},
{
text: "Producent",
value: "manufacturer"
},
{
text: "Koszt w kredytach",
value: "cost_in_credits"
},
{
text: "Długość",
value: "length"
},
{
text: "Załoga",
value: "crew"
},
{
text: "Pasażerowie",
value: "passengers"
},
{
text: "Prędkość w atmosferze",
value: "max_atmosphering_speed"
},
{
text: "Pojemność ladunku",
value: "cargo_capacity"
}
]
}
})
};
</script>

41
src/components/Navbar.vue Normal file
View File

@@ -0,0 +1,41 @@
<template>
<div>
<v-app-bar dark color="primary">
<v-toolbar-title class="display-1 font-weight-black">Fake SW</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn large text v-if="isAuth" @click="logout()">
<v-icon left>mdi-logout</v-icon>Wyloguj
</v-btn>
<v-hover v-slot:default="{ hover }">
<v-btn
:light="$vuetify.theme.dark ? false : true"
:dark="$vuetify.theme.dark ? true : false"
:outlined="hover ? false : true"
:color="$vuetify.theme.dark ? 'black' : 'white'"
icon
depressed
@click="$vuetify.theme.dark = !$vuetify.theme.dark"
>
<v-icon
:color="hover ? $vuetify.theme.dark ? 'white' : 'black' : $vuetify.theme.dark ? 'black' : 'white'"
>mdi-brightness-6</v-icon>
</v-btn>
</v-hover>
</v-app-bar>
</div>
</template>
<script>
export default {
computed: {
isAuth() {
return this.$store.getters.isUserAuthenticated;
}
},
methods: {
logout() {
this.$store.dispatch("logout");
}
}
};
</script>

View File

@@ -0,0 +1,55 @@
<template>
<div>
<Table :loading="loading" :headers="headers" :data="dataGetter" :items="5" />
</div>
</template>
<script>
import Table from "./TableView";
import axios from "axios";
export default {
components: { Table },
props: ["headers", "dataName"],
data: () => ({
loading: true
}),
created() {
this.getData();
},
computed: {
dataGetter() {
return this.$store.getters[this.dataName];
}
},
methods: {
async getData() {
let data = [];
let next = "https://swapi.dev/api/" + this.dataName.toLowerCase() + "/";
while (next) {
const res = await this.getNextData(next);
next = res.next;
for (let i = 0; i < res.data.length; i++) {
data.push(res.data[i]);
}
}
this.$store.commit("set" + this.dataName + "Data", data);
this.loading = false;
},
async getNextData(next) {
let data = [];
let newNext = null;
const res = await axios.get(next).catch(error => {
console.log(error);
});
data = res.data.results;
newNext = res.data.next;
if (newNext && !newNext.startsWith("https") && newNext.startsWith("http"))
newNext = [newNext.slice(0, 4), "s", newNext.slice(4)].join("");
return { data: data, next: newNext };
}
}
};
</script>

View File

@@ -0,0 +1,27 @@
<template>
<div>
<p class="display-1 text-center my-2" v-if="loading">Ładowanie danych...</p>
<v-card v-if="!loading" class="my-2">
<v-text-field
v-model="search"
append-icon="mdi-magnify"
label="Filtruj tabelę"
single-line
clearable
hide-details
class="mx-3 my-2 py-2"
></v-text-field>
</v-card>
<v-skeleton-loader :loading="loading" transition="scale-transition" type="table">
<v-data-table :headers="headers" :items="data" :items-per-page="items" :search="search"></v-data-table>
</v-skeleton-loader>
</div>
</template>
<script>
export default {
props: ["loading", "headers", "data", "items"],
data: () => ({
search: null
})
};
</script>

14
src/main.js Normal file
View File

@@ -0,0 +1,14 @@
import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import vuetify from './plugins/vuetify';
Vue.config.productionTip = false
new Vue({
router,
store,
vuetify,
render: h => h(App)
}).$mount('#app')

7
src/plugins/vuetify.js Normal file
View File

@@ -0,0 +1,7 @@
import Vue from 'vue';
import Vuetify from 'vuetify/lib';
Vue.use(Vuetify);
export default new Vuetify({
});

42
src/router/index.js Normal file
View File

@@ -0,0 +1,42 @@
import Vue from 'vue'
import VueRouter from 'vue-router'
import Index from '../components/Index.vue'
import store from '../store/index'
Vue.use(VueRouter)
const routes = [
{
path: '/login',
name: 'Index',
component: Index
},
{
path: '/list',
name: 'List',
component: () => import(/* webpackChunkName: "List" */ '../components/List.vue'),
beforeEnter: (to, from, next) => {
if(store.getters.isUserAuthenticated) {
next();
}
else {
next('/login');
}
}
},
{ path: '*', redirect: '/login' }
// {
// path: '/about',
// name: 'About',
// // route level code-splitting
// // this generates a separate chunk (about.[hash].js) for this route
// // which is lazy-loaded when the route is visited.
// component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
// }
]
const router = new VueRouter({
routes
})
export default router

99
src/store/index.js Normal file
View File

@@ -0,0 +1,99 @@
import Vue from 'vue'
import Vuex from 'vuex'
import router from '../router/index'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
loginError: false,
login: null,
token: null,
planets: [],
people: [],
movies: [],
species: [],
starships: [],
vehicles: []
},
mutations: {
authUser(state, userData) {
state.token = "Miracle fake token"
state.login = userData.login
},
clearAuthData(state) {
state.token = null
state.login = null
},
setLoginError(state) {
state.loginError = true;
},
resetLoginError(state) {
state.loginError = false;
},
setPlanetsData(state, payload) {
state.planets = payload;
},
setPeopleData(state, payload) {
state.people = payload;
},
setFilmsData(state, payload) {
state.movies = payload;
},
setSpeciesData(state, payload) {
state.species = payload;
},
setStarshipsData(state, payload) {
state.starships = payload;
},
setVehiclesData(state, payload) {
state.vehicles = payload;
}
},
actions: {
login ({commit}, authData) {
if(authData.login === "Luke" && authData.pass === "123") {
commit('authUser', { login: authData.login });
commit('resetLoginError');
router.replace('/list');
}
else {
commit('setLoginError');
}
},
logout({commit}) {
commit('clearAuthData');
router.replace('/login');
}
},
getters: {
user (state) {
return state.user
},
isUserAuthenticated (state) {
return state.token !== null;
},
isLoginError(state) {
return state.loginError !== false;
},
Planets(state) {
return state.planets;
},
People(state) {
return state.people;
},
Films(state) {
return state.movies;
},
Species(state) {
return state.species;
},
Starships(state) {
return state.starships;
},
Vehicles(state) {
return state.vehicles;
}
},
modules: {
}
})

5
vue.config.js Normal file
View File

@@ -0,0 +1,5 @@
module.exports = {
"transpileDependencies": [
"vuetify"
]
}