tethys.backend/resources/js/Stores/main.ts
Arno Kaimbacher b540547e4c
All checks were successful
CI / container-job (push) Successful in 49s
feat: update API controllers, validations, and Vue components
- Modified Api/Authors.Controller.ts to use only personal types and sort by dataset_count.
- Completely rewritten AvatarController.ts.
- Added new Api/CollectionsController.ts for querying collections and collection_roles.
- Modified Api/DatasetController.ts to preload titles, identifier and order by server_date_published.
- Modified FileController.ts to serve files from /storage/app/data/ instead of /storage/app/public.
- Added new Api/UserController for requesting submitters (getSubmitters).
- Improved OaiController.ts with performant DB queries for better ResumptionToken handling.
- Modified Submitter/DatasetController.ts by adding a categorize method for library classification.
- Rewritten ResumptionToken.ts.
- Improved TokenWorkerService.ts to utilize browser fingerprint.
- Edited dataset.ts by adding the doiIdentifier property.
- Enhanced person.ts to improve the fullName property.
- Completely rewritten AsideMenuItem.vue component.
- Updated CarBoxClient.vue to use TypeScript.
- Added new CardBoxDataset.vue for displaying recent datasets on the dashboard.
- Completely rewritten TableSampleClients.vue for the dashboard.
- Completely rewritten UserAvatar.vue.
- Made small layout changes in Dashboard.vue.
- Added new Category.vue for browsing scientific collections.
- Adapted the pinia store in main.ts.
- Added additional routes in start/routes.ts and start/api/routes.ts.
- Improved referenceValidation.ts for better ISBN existence checking.
- NPM dependency updates.
2025-03-14 17:39:58 +01:00

276 lines
7.5 KiB
TypeScript

import { defineStore } from 'pinia';
import axios from 'axios';
import { Dataset } from '@/Dataset';
import menu from '@/menu';
// import type Person from '#models/person';
export interface User {
id: number;
login: string;
firstName: string;
lastName: string;
email: string;
password: string;
created_at: DateTime;
updatedAt: DateTime;
lastLoginAt: DateTime;
isActive: boolean;
isVerified: boolean;
roles: string[];
permissions: string[];
settings: Record<string, any>;
profile: {
avatar: string;
bio: string;
location: string;
website: string;
social: {
twitter: string;
facebook: string;
linkedin: string;
github: string;
}
};
metadata: Record<string, any>;
verifyPassword: (plainPassword: string) => Promise<boolean>;
}
interface DateTime {
get: (unit: keyof DateTime) => number;
getPossibleOffsets: () => DateTime[];
toRelativeCalendar: (options?: ToRelativeCalendarOptions) => string | null;
toFormat: (format: string) => string;
toISO: () => string;
toJSON: () => string;
toString: () => string;
toLocaleString: (options?: Intl.DateTimeFormatOptions) => string;
toUTC: () => DateTime;
toLocal: () => DateTime;
valueOf: () => number;
toMillis: () => number;
toSeconds: () => number;
toUnixInteger: () => number;
}
export interface Person {
id: number;
name: string;
email: string;
name_type: string;
identifier_orcid: string;
dataset_count: number;
created_at: string;
}
interface TransactionItem {
amount: number;
account: string;
name: string;
date: string;
type: string;
business: string;
}
export enum State {
STATE_DISABLED = 0,
STATE_CREATED = 1,
STATE_ENABLED = 2,
}
export const saveState = async (data: any) => {
const url = '/api/twofactor_totp/settings/enable';
const resp = await axios.post(url, data);
return resp.data;
};
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;
};
// Anfrage staet : 1
// ANtwort json:
// state: 1
// secret:"OX7IQ4OI3GXGFPHY"
// qUrl:"https://odysseus.geologie.ac.at/apps/twofactor_totp/settings/enable"
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: [] as Array<User>,
history: [] as Array<TransactionItem>,
// api based data
authors: [] as Array<Person>,
// persons: [] as Array<Person>,
datasets: [],
files: [],
dataset: {} as Dataset,
menu: menu,
totpState: 0,
backupcodesEnabled: false,
total: 0,
used: 0,
codes: [],
graphData: {},
}),
actions: {
// payload = authenticated user
setUser(payload: any) {
if (payload.name) {
this.userName = payload.name;
}
if (payload.email) {
this.userEmail = payload.email;
}
if (payload.avatar) {
this.userAvatar = payload.avatar;
}
},
setDataset(payload: any) {
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;
// }
},
clearDataset() {
this.dataset = null;
},
fetch(sampleDataKey: string) {
// 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: string) {
// sampleDataKey= authors or datasets
axios
.get(`/api/${sampleDataKey}`)
.then((r) => {
if (r.data) {
this[sampleDataKey] = r.data;
}
})
.catch((error) => {
alert(error.message);
});
},
setState(state: any) {
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() {
const { state, backupState } = await saveState({ state: State.STATE_DISABLED });
this.totpState = state;
this.backupcodesEnabled = backupState.enabled;
this.total = backupState.total;
this.used = backupState.used;
},
async confirm(code: string) {
const { state } = await saveState({
state: State.STATE_ENABLED,
code,
});
this.totpState = state;
},
fetchChartData(year: string) {
// sampleDataKey= authors or datasets
axios
.get(`/api/statistic/${year}`)
.then((r) => {
if (r.data) {
this.graphData = r.data;
}
})
.catch((error) => {
alert(error.message);
});
},
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;
},
// 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);
// });
// },
},
});