2023-03-17 15:13:37 +00:00
|
|
|
import { defineStore } from 'pinia';
|
|
|
|
import axios from 'axios';
|
2023-03-24 10:41:52 +00:00
|
|
|
import { Dataset } from '@/Dataset';
|
2023-11-29 15:52:41 +00:00
|
|
|
import menu from '@/menu';
|
2023-03-17 15:13:37 +00:00
|
|
|
|
2023-03-24 10:41:52 +00:00
|
|
|
export interface Person {
|
2023-03-17 15:13:37 +00:00
|
|
|
id: number;
|
|
|
|
name: string;
|
|
|
|
email: string;
|
2023-03-24 10:41:52 +00:00
|
|
|
name_type: string;
|
|
|
|
identifier_orcid: string;
|
2023-03-17 15:13:37 +00:00
|
|
|
datasetCount: string;
|
|
|
|
created_at: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface TransactionItem {
|
|
|
|
amount: number;
|
|
|
|
account: string;
|
2023-03-24 10:41:52 +00:00
|
|
|
name: string;
|
2023-03-17 15:13:37 +00:00
|
|
|
date: string;
|
|
|
|
type: string;
|
|
|
|
business: string;
|
|
|
|
}
|
|
|
|
|
2024-01-19 14:33:46 +00:00
|
|
|
export enum State {
|
|
|
|
STATE_DISABLED = 0,
|
|
|
|
STATE_CREATED = 1,
|
|
|
|
STATE_ENABLED = 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
export const saveState = async (data) => {
|
|
|
|
const url = '/api/twofactor_totp/settings/enable';
|
|
|
|
|
|
|
|
const resp = await axios.post(url, data);
|
|
|
|
return resp.data;
|
|
|
|
};
|
|
|
|
|
2024-07-08 11:52:20 +00:00
|
|
|
export const generateCodes = async () => {
|
|
|
|
const url = '/api/twofactor_backupcodes/settings/create';
|
|
|
|
|
|
|
|
// return Axios.post(url, {}).then((resp) => resp.data);
|
|
|
|
const resp = await axios.post(url, {});
|
|
|
|
return resp.data;
|
|
|
|
};
|
|
|
|
|
2024-01-19 14:33:46 +00:00
|
|
|
// Anfrage staet : 1
|
|
|
|
|
|
|
|
// ANtwort json:
|
|
|
|
// state: 1
|
|
|
|
// secret:"OX7IQ4OI3GXGFPHY"
|
|
|
|
// qUrl:"https://odysseus.geologie.ac.at/apps/twofactor_totp/settings/enable"
|
|
|
|
|
2023-03-17 15:13:37 +00:00
|
|
|
export const MainService = defineStore('main', {
|
|
|
|
state: () => ({
|
|
|
|
/* User */
|
|
|
|
userName: '',
|
|
|
|
userEmail: null,
|
|
|
|
userAvatar: null,
|
|
|
|
|
|
|
|
/* Field focus with ctrl+k (to register only once) */
|
|
|
|
isFieldFocusRegistered: false,
|
|
|
|
|
|
|
|
/* Sample data for starting dashboard(commonly used) */
|
|
|
|
clients: [],
|
|
|
|
history: [] as Array<TransactionItem>,
|
2023-03-24 10:41:52 +00:00
|
|
|
|
|
|
|
// api based data
|
2023-03-17 15:13:37 +00:00
|
|
|
authors: [] as Array<Person>,
|
2023-03-24 10:41:52 +00:00
|
|
|
// persons: [] as Array<Person>,
|
2023-03-17 15:13:37 +00:00
|
|
|
datasets: [],
|
2024-01-19 14:33:46 +00:00
|
|
|
files: [],
|
2023-03-24 10:41:52 +00:00
|
|
|
|
|
|
|
dataset: {} as Dataset,
|
2023-11-29 15:52:41 +00:00
|
|
|
|
|
|
|
menu: menu,
|
2024-01-19 14:33:46 +00:00
|
|
|
|
|
|
|
totpState: 0,
|
2024-02-02 13:00:54 +00:00
|
|
|
|
2024-07-08 11:52:20 +00:00
|
|
|
backupcodesEnabled: false,
|
|
|
|
total: 0,
|
|
|
|
used: 0,
|
|
|
|
codes: [],
|
|
|
|
|
2024-02-02 13:00:54 +00:00
|
|
|
graphData: {},
|
2023-03-17 15:13:37 +00:00
|
|
|
}),
|
|
|
|
actions: {
|
|
|
|
// payload = authenticated user
|
2024-07-08 11:52:20 +00:00
|
|
|
setUser(payload: any) {
|
2023-03-17 15:13:37 +00:00
|
|
|
if (payload.name) {
|
|
|
|
this.userName = payload.name;
|
|
|
|
}
|
|
|
|
if (payload.email) {
|
|
|
|
this.userEmail = payload.email;
|
|
|
|
}
|
|
|
|
if (payload.avatar) {
|
|
|
|
this.userAvatar = payload.avatar;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2024-07-08 11:52:20 +00:00
|
|
|
setDataset(payload: any) {
|
2023-03-24 10:41:52 +00:00
|
|
|
this.dataset = payload;
|
2023-06-27 16:23:18 +00:00
|
|
|
|
2023-03-24 10:41:52 +00:00
|
|
|
// this.dataset = {
|
|
|
|
// language: language,
|
|
|
|
// licenses: payload.licenses,
|
|
|
|
// rights: payload.rights,
|
|
|
|
// type: payload.type,
|
|
|
|
// creating_corporation: payload.creating_corporation,
|
|
|
|
// titles: payload.titles,
|
|
|
|
// descriptions: payload.descriptions,
|
|
|
|
// authors: payload.authors,
|
|
|
|
// project_id: payload.project_id,
|
|
|
|
// embargo_date: payload.embargo_date,
|
|
|
|
// } as Dataset;
|
|
|
|
// for (let index in payload.titles) {
|
|
|
|
// let title = payload.titles[index];
|
|
|
|
// title.language = language;
|
|
|
|
// }
|
|
|
|
},
|
|
|
|
|
2023-06-01 12:29:56 +00:00
|
|
|
clearDataset() {
|
|
|
|
this.dataset = null;
|
|
|
|
},
|
|
|
|
|
2024-07-08 11:52:20 +00:00
|
|
|
fetch(sampleDataKey: any) {
|
2023-03-17 15:13:37 +00:00
|
|
|
// sampleDataKey= clients or history
|
|
|
|
axios
|
2023-12-01 09:44:19 +00:00
|
|
|
.get(`/data-sources/${sampleDataKey}.json`)
|
2023-03-17 15:13:37 +00:00
|
|
|
.then((r) => {
|
|
|
|
if (r.data && r.data.data) {
|
|
|
|
this[sampleDataKey] = r.data.data;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
alert(error.message);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
fetchApi(sampleDataKey) {
|
|
|
|
// sampleDataKey= authors or datasets
|
|
|
|
axios
|
2023-12-01 09:44:19 +00:00
|
|
|
.get(`/api/${sampleDataKey}`)
|
2023-03-17 15:13:37 +00:00
|
|
|
.then((r) => {
|
|
|
|
if (r.data) {
|
|
|
|
this[sampleDataKey] = r.data;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
alert(error.message);
|
|
|
|
});
|
|
|
|
},
|
2023-11-22 16:06:55 +00:00
|
|
|
|
2024-01-19 14:33:46 +00:00
|
|
|
setState(state) {
|
|
|
|
this.totpState = state;
|
|
|
|
},
|
|
|
|
|
|
|
|
async create(): Promise<{ url: any; secret: any; svg: any }> {
|
|
|
|
const { state, secret, url, svg } = await saveState({ state: State.STATE_CREATED });
|
|
|
|
this.totpState = state;
|
|
|
|
return { url, secret, svg };
|
|
|
|
// .then(({ state, secret, qrUrl }) => {
|
|
|
|
// this.totpState = state;
|
|
|
|
// return { qrUrl, secret };
|
|
|
|
// })
|
|
|
|
// .catch((error) => {
|
|
|
|
// alert(error.message);
|
|
|
|
// });
|
|
|
|
},
|
|
|
|
|
|
|
|
async disable() {
|
2024-07-08 11:52:20 +00:00
|
|
|
const { state, backupState } = await saveState({ state: State.STATE_DISABLED });
|
2024-01-19 14:33:46 +00:00
|
|
|
this.totpState = state;
|
2024-07-08 11:52:20 +00:00
|
|
|
|
|
|
|
this.backupcodesEnabled = backupState.enabled;
|
|
|
|
this.total = backupState.total;
|
|
|
|
this.used = backupState.used;
|
2024-01-19 14:33:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
async confirm(code: string) {
|
|
|
|
const { state } = await saveState({
|
|
|
|
state: State.STATE_ENABLED,
|
|
|
|
code,
|
|
|
|
});
|
|
|
|
this.totpState = state;
|
|
|
|
},
|
|
|
|
|
2024-04-23 17:36:45 +00:00
|
|
|
async fetchChartData(year: string) {
|
2024-02-02 13:00:54 +00:00
|
|
|
// sampleDataKey= authors or datasets
|
|
|
|
axios
|
|
|
|
.get(`/api/statistic/${year}`)
|
|
|
|
.then((r) => {
|
|
|
|
if (r.data) {
|
|
|
|
this.graphData = r.data;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
alert(error.message);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2024-07-08 11:52:20 +00:00
|
|
|
async generate(): Promise<void> {
|
|
|
|
const { codes, backupState } = await generateCodes();
|
|
|
|
// this.totpState = state;
|
|
|
|
this.codes = codes;
|
|
|
|
this.backupcodesEnabled = backupState.enabled;
|
|
|
|
this.total = backupState.total;
|
|
|
|
this.used = backupState.used;
|
|
|
|
},
|
|
|
|
|
2023-11-22 16:06:55 +00:00
|
|
|
// fetchfiles(id) {
|
|
|
|
// // sampleDataKey= authors or datasets
|
|
|
|
// axios
|
|
|
|
// .get(`api/files/${id}`)
|
|
|
|
// .then((r) => {
|
|
|
|
// if (r.data) {
|
|
|
|
// this[sampleDataKey] = r.data;
|
|
|
|
// }
|
|
|
|
// })
|
|
|
|
// .catch((error) => {
|
|
|
|
// alert(error.message);
|
|
|
|
// });
|
|
|
|
// },
|
2023-03-17 15:13:37 +00:00
|
|
|
},
|
|
|
|
});
|