Add VersionHistory page
This commit is contained in:
106
frontend/src/stores/useAppStore.ts
Normal file
106
frontend/src/stores/useAppStore.ts
Normal file
@@ -0,0 +1,106 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { api } from 'boot/axios';
|
||||
import { IAppDisplay, IAppVersion, IAppVersionDisplay, IManagedApp } from 'src/types/AppTypes';
|
||||
import { IUser } from 'src/types/UserTypes';
|
||||
import { date, Notify } from 'quasar'
|
||||
|
||||
|
||||
export const useAppStore = defineStore('app', {
|
||||
state: () => ({
|
||||
apps: [] as IAppDisplay[],
|
||||
rowIds: new Set<string>(),
|
||||
}),
|
||||
actions: {
|
||||
async loadApps() {
|
||||
this.reset();
|
||||
try {
|
||||
const { data } = await api.get('api/apps');
|
||||
this.apps = data.data.map((item: IManagedApp) => {
|
||||
this.rowIds.add(item.appid);
|
||||
return appToAppDisplay(item)
|
||||
}).sort((a: IAppDisplay, b: IAppDisplay) => a.sortId - b.sortId); // set default order
|
||||
} catch (error) {
|
||||
Notify.create({
|
||||
icon: 'error',
|
||||
color: 'negative',
|
||||
message: 'アプリ一覧の読み込みに失敗しました'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
getAppById(id: string) {
|
||||
if (!this.rowIds.has(id)) {
|
||||
return null;
|
||||
}
|
||||
return this.apps.find((item: IAppDisplay) => item.id === id);
|
||||
},
|
||||
|
||||
async getVersionsByAppId(app: IAppDisplay) {
|
||||
const { data } = await api.get(`api/appversions/${app.id}`);
|
||||
return data.data.map((item: IAppVersion) => versionToVersionDisplay(item));
|
||||
},
|
||||
|
||||
async changeVersion(app: IAppDisplay, version: IAppVersionDisplay) {
|
||||
await api.put(`api/appversions/${app.id}/${version.id}`);
|
||||
},
|
||||
|
||||
async deleteApp(app: IAppDisplay) {
|
||||
try {
|
||||
await api.delete(`api/apps/${app.id}`);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
Notify.create({
|
||||
icon: 'error',
|
||||
color: 'negative',
|
||||
message: 'アプリの削除に失敗しました'
|
||||
});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
||||
reset() {
|
||||
this.apps = [];
|
||||
this.rowIds.clear();
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
function versionToVersionDisplay(item: IAppVersion) {
|
||||
return {
|
||||
id: item.version,
|
||||
version: item.version,
|
||||
appid: item.appid,
|
||||
name: item.versionname,
|
||||
comment: item.comment,
|
||||
// updater: toUserDisplay(item.updateuser),
|
||||
// updateTime: formatDate(item.updatetime),
|
||||
// creator: toUserDisplay(item.createuser),
|
||||
// createTime: formatDate(item.createtime),
|
||||
} as IAppVersionDisplay;
|
||||
}
|
||||
|
||||
function appToAppDisplay(app: IManagedApp) {
|
||||
return {
|
||||
id: app.appid,
|
||||
sortId: parseInt(app.appid, 10),
|
||||
name: app.appname,
|
||||
url: `${app.domainurl}/k/${app.appid}`,
|
||||
version: app.version,
|
||||
updateTime: date.formatDate(app.update_time, 'YYYY/MM/DD HH:mm'),
|
||||
updateUser: userToUserDisplay(app.updateuser)
|
||||
} as IAppDisplay
|
||||
}
|
||||
|
||||
function userToUserDisplay(user: IUser) {
|
||||
return {
|
||||
id: user.id,
|
||||
firstName: user.first_name,
|
||||
lastName: user.last_name,
|
||||
fullNameSearch: (user.last_name + user.first_name).toLowerCase(),
|
||||
fullName: user.last_name + ' ' + user.first_name,
|
||||
email: user.email,
|
||||
isActive: user.is_active,
|
||||
isSuperuser: user.is_superuser,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user