2020-10-19 11:59:56 +00:00
|
|
|
<template>
|
|
|
|
<q-card class="col-12" height="">
|
|
|
|
<q-card-section v-if="isThisSession(session.token)" class="text-caption">
|
|
|
|
Diese Session.
|
|
|
|
</q-card-section>
|
|
|
|
<q-card-section>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-xs-12 col-sm-6">
|
|
|
|
Browser:
|
|
|
|
<q-icon :name="getBrowserIcon(session.browser)" size="24px" />
|
|
|
|
{{ session.browser }}
|
|
|
|
</div>
|
|
|
|
<div class="col-xs-12 col-sm-6">
|
|
|
|
Plattform:
|
|
|
|
<q-icon :name="getPlatformIcon(session.platform)" size="24px" />
|
|
|
|
{{ session.platform }}
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-02-01 23:48:33 +00:00
|
|
|
<div v-if="!isEdit" class="row">
|
2020-10-19 11:59:56 +00:00
|
|
|
<div class="col-xs-12 col-sm-6">
|
|
|
|
Lebenszeit:
|
|
|
|
{{ session.lifetime }}
|
|
|
|
</div>
|
2021-01-30 07:38:44 +00:00
|
|
|
<div class="col-xs-12 col-sm-6">Läuft aus: {{ dateTime(session.expires) }}</div>
|
2020-10-19 11:59:56 +00:00
|
|
|
</div>
|
2021-02-01 23:48:33 +00:00
|
|
|
<div v-else class="row q-my-sm">
|
2021-01-27 13:04:09 +00:00
|
|
|
<q-input
|
|
|
|
v-model="computedLifetime"
|
2021-02-01 23:48:33 +00:00
|
|
|
class="col-xs-12 col-sm-6 q-px-sm"
|
2021-01-27 13:04:09 +00:00
|
|
|
type="number"
|
|
|
|
label="Zeit"
|
|
|
|
filled
|
|
|
|
/>
|
2021-02-01 23:48:33 +00:00
|
|
|
<q-select v-model="option" class="col-xs-12 col-sm-6 q-px-sm" :options="options" filled />
|
2021-01-27 13:04:09 +00:00
|
|
|
</div>
|
2020-10-19 11:59:56 +00:00
|
|
|
</q-card-section>
|
2021-02-01 23:48:33 +00:00
|
|
|
<q-card-actions v-if="!isEdit" align="right">
|
2021-01-27 13:04:09 +00:00
|
|
|
<q-btn flat round dense icon="mdi-pencil" @click="edit(true)" />
|
2021-01-27 07:16:44 +00:00
|
|
|
<q-btn flat round dense icon="mdi-delete" @click="deleteSession(session.token)" />
|
2020-10-19 11:59:56 +00:00
|
|
|
</q-card-actions>
|
2021-02-01 23:48:33 +00:00
|
|
|
<q-card-actions v-else align="right">
|
2021-01-27 13:04:09 +00:00
|
|
|
<q-btn flat dense label="Abbrechen" @click="edit(false)" />
|
|
|
|
<q-btn flat dense label="Speichern" @click="save" />
|
|
|
|
</q-card-actions>
|
2020-10-19 11:59:56 +00:00
|
|
|
</q-card>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-01-30 07:38:44 +00:00
|
|
|
import { useStore } from 'vuex';
|
2021-01-30 03:16:17 +00:00
|
|
|
import { defineComponent, ref, computed } from 'vue';
|
2021-01-30 07:38:44 +00:00
|
|
|
import { UserSessionState } from '../../store';
|
|
|
|
import { formatDateTime } from 'src/utils/datetime';
|
2020-10-29 00:39:06 +00:00
|
|
|
|
2020-10-19 11:59:56 +00:00
|
|
|
export default defineComponent({
|
|
|
|
name: 'Sessions',
|
|
|
|
props: {
|
|
|
|
session: {
|
2021-03-18 16:23:57 +00:00
|
|
|
required: true,
|
2021-01-30 07:38:44 +00:00
|
|
|
type: Object,
|
2021-03-18 16:23:57 +00:00
|
|
|
},
|
2020-10-19 11:59:56 +00:00
|
|
|
},
|
2021-01-30 07:38:44 +00:00
|
|
|
setup(props) {
|
|
|
|
const store = useStore<UserSessionState>();
|
|
|
|
|
|
|
|
const dateTime = (date: Date) => formatDateTime(date, true);
|
|
|
|
|
2021-01-27 13:04:09 +00:00
|
|
|
const options = ref(['Minuten', 'Stunden', 'Tage']);
|
|
|
|
const option = ref<string>(options.value[0]);
|
|
|
|
const lifetime = ref(0);
|
2020-10-19 11:59:56 +00:00
|
|
|
function getBrowserIcon(browser: string) {
|
|
|
|
return browser == 'firefox'
|
|
|
|
? 'mdi-firefox'
|
|
|
|
: browser == 'chrome'
|
|
|
|
? 'mdi-google-chrome'
|
|
|
|
: browser == 'safari'
|
|
|
|
? 'mdi-apple-safari'
|
|
|
|
: 'mdi-help';
|
|
|
|
}
|
2020-10-29 00:39:06 +00:00
|
|
|
|
2020-10-19 11:59:56 +00:00
|
|
|
function getPlatformIcon(platform: string) {
|
|
|
|
return platform == 'linux'
|
|
|
|
? 'mdi-linux'
|
|
|
|
: platform == 'windows'
|
|
|
|
? 'mdi-microsoft-windows'
|
2020-10-31 18:33:05 +00:00
|
|
|
: platform == 'macos'
|
2020-10-19 11:59:56 +00:00
|
|
|
? 'mdi-apple'
|
2020-10-31 21:37:28 +00:00
|
|
|
: platform == 'iphone'
|
|
|
|
? 'mdi-cellphone-iphone'
|
|
|
|
: platform == 'android'
|
|
|
|
? 'mdi-cellphone-android'
|
2020-10-19 11:59:56 +00:00
|
|
|
: 'mdi-help';
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteSession(token: string) {
|
2021-01-30 07:38:44 +00:00
|
|
|
store.dispatch('sessions/deleteSession', token).catch((error) => {
|
2020-10-28 23:10:45 +00:00
|
|
|
console.warn(error);
|
|
|
|
});
|
2020-10-19 11:59:56 +00:00
|
|
|
}
|
|
|
|
function isThisSession(token: string) {
|
2021-01-30 07:38:44 +00:00
|
|
|
return store.state.sessions.currentSession?.token === token;
|
2020-10-19 11:59:56 +00:00
|
|
|
}
|
|
|
|
|
2021-01-27 13:04:09 +00:00
|
|
|
const isEdit = ref(false);
|
|
|
|
|
|
|
|
const computedLifetime = computed({
|
|
|
|
get: () => {
|
|
|
|
switch (option.value) {
|
|
|
|
case options.value[0]:
|
|
|
|
return (lifetime.value / 60).toFixed(2);
|
|
|
|
case options.value[1]:
|
|
|
|
return (lifetime.value / (60 * 60)).toFixed(2);
|
|
|
|
case options.value[2]:
|
|
|
|
return (lifetime.value / (60 * 60 * 24)).toFixed(2);
|
|
|
|
}
|
2021-01-30 07:38:44 +00:00
|
|
|
throw 'Invalid option';
|
2021-01-27 13:04:09 +00:00
|
|
|
},
|
2021-03-18 16:23:57 +00:00
|
|
|
set: (val) => {
|
2021-01-27 13:04:09 +00:00
|
|
|
if (val) {
|
|
|
|
switch (option.value) {
|
|
|
|
case options.value[0]:
|
|
|
|
lifetime.value = parseFloat(val) * 60;
|
|
|
|
break;
|
|
|
|
case options.value[1]:
|
|
|
|
lifetime.value = parseFloat(val) * 60 * 60;
|
|
|
|
break;
|
|
|
|
case options.value[2]:
|
|
|
|
lifetime.value = parseFloat(val) * 60 * 60 * 24;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-03-18 16:23:57 +00:00
|
|
|
},
|
2021-01-27 13:04:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function edit(value: boolean) {
|
2021-01-30 07:38:44 +00:00
|
|
|
lifetime.value = (<FG.Session>props.session).lifetime;
|
2021-01-27 13:04:09 +00:00
|
|
|
isEdit.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function save() {
|
|
|
|
console.log(lifetime.value);
|
|
|
|
isEdit.value = false;
|
|
|
|
void store
|
2021-01-30 07:38:44 +00:00
|
|
|
.dispatch('sessions/updateSession', {
|
|
|
|
lifetime: lifetime.value,
|
|
|
|
token: (<FG.Session>props.session).token,
|
|
|
|
})
|
2021-03-18 16:23:57 +00:00
|
|
|
.catch((error) => {
|
2021-01-27 13:04:09 +00:00
|
|
|
console.log(error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-10-19 11:59:56 +00:00
|
|
|
return {
|
|
|
|
getBrowserIcon,
|
|
|
|
getPlatformIcon,
|
|
|
|
isThisSession,
|
2021-01-27 13:04:09 +00:00
|
|
|
deleteSession,
|
|
|
|
isEdit,
|
2021-01-30 07:38:44 +00:00
|
|
|
dateTime,
|
2021-01-27 13:04:09 +00:00
|
|
|
edit,
|
|
|
|
options,
|
|
|
|
option,
|
|
|
|
lifetime,
|
|
|
|
computedLifetime,
|
2021-03-18 16:23:57 +00:00
|
|
|
save,
|
2020-10-19 11:59:56 +00:00
|
|
|
};
|
2021-03-18 16:23:57 +00:00
|
|
|
},
|
2020-10-19 11:59:56 +00:00
|
|
|
});
|
|
|
|
</script>
|