fixed errors, persist save of server (cordova)

This commit is contained in:
Tim Gröger 2021-01-29 14:06:25 +01:00
parent 797f7dd67a
commit feaeb3f4e4
5 changed files with 53 additions and 24 deletions

View File

@ -3,6 +3,9 @@ import { boot } from 'quasar/wrappers';
import config from '../config'; import config from '../config';
import { Store } from 'vuex'; import { Store } from 'vuex';
import { StateInterface } from 'src/store'; import { StateInterface } from 'src/store';
import { LocalStorage } from 'quasar';
import {Notify} from 'quasar';
import {Router} from 'src/router';
declare module 'vue/types/vue' { declare module 'vue/types/vue' {
interface Vue { interface Vue {
@ -11,14 +14,27 @@ declare module 'vue/types/vue' {
} }
export const setBaseUrl = (url: string) => { export const setBaseUrl = (url: string) => {
LocalStorage.set('baseURL', url);
axios.defaults.baseURL = url; axios.defaults.baseURL = url;
Notify.create({
message: "Serveraddresse gespeichert",
position: "bottom",
caption: `${url}`,
color: "positive"
})
setTimeout(() => {window.location.reload()}, 5000)
} }
export default boot<Store<StateInterface>>(({ Vue, store, router }) => { export default boot<Store<StateInterface>>(({ Vue, store, router }) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
Vue.prototype.$axios = axios; Vue.prototype.$axios = axios;
const baseURL = <string | undefined>LocalStorage.getItem('baseURL');
if (baseURL){
axios.defaults.baseURL = baseURL
} else {
axios.defaults.baseURL = config.baseURL; axios.defaults.baseURL = config.baseURL;
}
/*** /***
* Intercept requests and insert Token if available * Intercept requests and insert Token if available
*/ */

View File

@ -43,7 +43,7 @@ interface Props {
label?: string; label?: string;
readonly: boolean; readonly: boolean;
type: string; type: string;
rules: Array<any>; rules: Array<string>;
} }
export default defineComponent({ export default defineComponent({

View File

@ -35,17 +35,25 @@
<q-btn label="Login" type="submit" color="primary" tabindex="3" /> <q-btn label="Login" type="submit" color="primary" tabindex="3" />
</div> </div>
</q-form> </q-form>
</q-card-section> </q-card-section>
<q-card-section> <div class="row justify-end">
<q-separator class="q-mt-sm"/> <q-btn flat round icon="mdi-menu-down" class="cordova-only" @click="openServerSettings"/>
<div class="cordova-only q-my-sm">
<div class="text-h6">Serversettings</div>
<q-input filled label="Server" dense v-model="server" />
</div> </div>
<q-slide-transition class="cordova-only">
<div v-show="visible">
<q-separator />
<q-card-section>
<q-form ref="ServerSettingsForm" @submit="changeUrl" class="q-gutter-md">
<div class="text-h6">Servereinstellung</div>
<q-input filled label="Server" dense v-model="server" />
<q-btn size="xs" dense color="primary" label="Speichern" type="submit" />
</q-form>
</q-card-section> </q-card-section>
<q-card-actions align="right">
<q-btn dense color="primary" label="Speichern" @click="changeUrl" /> </div>
</q-card-actions> </q-slide-transition>
</q-card> </q-card>
</q-page> </q-page>
</template> </template>
@ -65,6 +73,11 @@ export default defineComponent({
const password = ref(''); const password = ref('');
const rules = [(val: string) => (val && val.length > 0) || 'Feld darf nicht leer sein!']; const rules = [(val: string) => (val && val.length > 0) || 'Feld darf nicht leer sein!'];
const server = ref<string|undefined>(root.$axios.defaults.baseURL) const server = ref<string|undefined>(root.$axios.defaults.baseURL)
const visible = ref(false);
function openServerSettings() {
visible.value = !visible.value
}
function changeUrl() { function changeUrl() {
if (server.value) { if (server.value) {
@ -134,7 +147,7 @@ export default defineComponent({
}); });
} }
return { userid, password, doLogin, doReset, rules, server, changeUrl }; return { userid, password, doLogin, doReset, rules, server, changeUrl, visible, openServerSettings };
} }
}); });
</script> </script>

View File

@ -45,12 +45,12 @@
<job <job
:job="job" :job="job"
:jobCanDelete="jobDeleteDisabled" :jobCanDelete="jobDeleteDisabled"
@setStart="setStart" @set-start="setStart"
@setRequired="setRequired" @set-required="setRequired"
@setEnd="setEnd" @set-end="setEnd"
@setComment="setComment" @set-comment="setComment"
@setJobType="setJobType" @set-job-type="setJobType"
@removeJob="removeJob(index)" @remove-job="removeJob(index)"
/> />
</q-card> </q-card>
</q-card-section> </q-card-section>
@ -149,7 +149,7 @@ export default defineComponent({
event.value.id = NaN; event.value.id = NaN;
event.value.start = new Date(); event.value.start = new Date();
event.value.description = ''; event.value.description = '';
delete event.value['type']; event.value.type = {id: -1, name: ''};
event.value.jobs = [Object.assign({}, newJob.value)]; event.value.jobs = [Object.assign({}, newJob.value)];
} }
function notEmpty(val: string) { function notEmpty(val: string) {

View File

@ -89,33 +89,33 @@ export default defineComponent({
function setStart(value: Date) { function setStart(value: Date) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call // eslint-disable-next-line @typescript-eslint/no-unsafe-call
emit('setStart', { job: props.job, value }); emit('set-start', { job: props.job, value });
} }
function setEnd(value: Date) { function setEnd(value: Date) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call // eslint-disable-next-line @typescript-eslint/no-unsafe-call
emit('setEnd', { job: props.job, value }); emit('set-end', { job: props.job, value });
} }
function setComment(value: string) { function setComment(value: string) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call // eslint-disable-next-line @typescript-eslint/no-unsafe-call
emit('setComment', { job: props.job, value }); emit('set-comment', { job: props.job, value });
} }
function setJobType(value: FG.JobType) { function setJobType(value: FG.JobType) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call // eslint-disable-next-line @typescript-eslint/no-unsafe-call
console.log('setJobType', value); console.log('setJobType', value);
emit('setJobType', { job: props.job, value }); emit('set-job-type', { job: props.job, value });
} }
function setRequired(value: number) { function setRequired(value: number) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call // eslint-disable-next-line @typescript-eslint/no-unsafe-call
emit('setRequired', { job: props.job, value }); emit('set-required', { job: props.job, value });
} }
function removeJob() { function removeJob() {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call // eslint-disable-next-line @typescript-eslint/no-unsafe-call
emit('removeJob'); emit('remove-job');
} }
function notEmpty(val: string) { function notEmpty(val: string) {