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-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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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: [],
|
2023-03-24 10:41:52 +00:00
|
|
|
|
|
|
|
dataset: {} as Dataset,
|
2023-03-17 15:13:37 +00:00
|
|
|
}),
|
|
|
|
actions: {
|
|
|
|
// payload = authenticated user
|
|
|
|
setUser(payload) {
|
|
|
|
if (payload.name) {
|
|
|
|
this.userName = payload.name;
|
|
|
|
}
|
|
|
|
if (payload.email) {
|
|
|
|
this.userEmail = payload.email;
|
|
|
|
}
|
|
|
|
if (payload.avatar) {
|
|
|
|
this.userAvatar = payload.avatar;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2023-03-24 10:41:52 +00:00
|
|
|
setDataset(payload) {
|
|
|
|
this.dataset = payload;
|
|
|
|
|
|
|
|
// 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-03-17 15:13:37 +00:00
|
|
|
fetch(sampleDataKey) {
|
|
|
|
// sampleDataKey= clients or history
|
|
|
|
axios
|
|
|
|
.get(`data-sources/${sampleDataKey}.json`)
|
|
|
|
.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
|
|
|
|
.get(`api/${sampleDataKey}`)
|
|
|
|
.then((r) => {
|
|
|
|
if (r.data) {
|
|
|
|
this[sampleDataKey] = r.data;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
alert(error.message);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|