build(dump): migrate admin UI to TypeScript and commit built bundle

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
haylanandQwen-Coder committed 2026-09-14 23:01:16 +02:00
1 parent b89a878b92
commit 59e48c8f21
10 files changed
+198 -87

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
// Shopware injects its Administration API as untyped globals at runtime; there's
// no official @shopware-ag type package for plugin authors to install against
// (per docs/research/admin-dump-manager-ui.md §4), so these are declared loosely
// as `any` — good enough for editor support, and the build (swc, type-stripping
// only, no tsc typecheck) doesn't need them at all.
declare const Shopware: any;
interface Window {
Shopware: typeof Shopware;
}
declare module '*.html.twig' {
const template: string;
export default template;
}
declare module '*.json' {
const value: Record<string, unknown>;
export default value;
}
@@ -1,7 +1,7 @@
import DumpApiService from './service/dump-api.service';
import './module/aeon-dump-manager';
Shopware.Application.addServiceProvider('aeonDumpManagerApiService', (container) => {
Shopware.Application.addServiceProvider('aeonDumpManagerApiService', (container: { loginService: unknown }) => {
const initContainer = Shopware.Application.getContainer('init');
return new DumpApiService(initContainer.httpClient, container.loginService);
@@ -1,39 +0,0 @@
import './acl';
import './page/aeon-dump-manager-list';
import deDE from './snippet/de-DE.json';
import enGB from './snippet/en-GB.json';
Shopware.Module.register('aeon-dump-manager', {
type: 'plugin',
name: 'DumpManager',
title: 'aeon-dump-manager.general.mainMenuItemGeneral',
description: 'aeon-dump-manager.general.descriptionTextModule',
color: '#ff3d58',
icon: 'default-object-storage',
snippets: {
'de-DE': deDE,
'en-GB': enGB,
},
routes: {
list: {
component: 'aeon-dump-manager-list',
path: 'list',
meta: {
parentPath: 'sw.settings.index.system',
privilege: 'aeon_dump_manager.viewer',
},
},
},
// Shown as a card on the Settings page's "System" group, next to
// Plugins/Cache — matches the locked ACL/menu-naming decision. Plugins
// cannot register a first-level main-menu entry.
settingsItem: {
group: 'system',
to: 'aeon.dump.manager.list',
icon: 'default-object-storage',
privilege: 'aeon_dump_manager.viewer',
},
});
@@ -0,0 +1,53 @@
import './acl';
import './page/aeon-dump-manager-list';
import deDE from './snippet/de-DE.json';
import enGB from './snippet/en-GB.json';
Shopware.Module.register('aeon-dump-manager', {
type: 'plugin',
name: 'DumpManager',
title: 'aeon-dump-manager.general.mainMenuItemGeneral',
description: 'aeon-dump-manager.general.descriptionTextModule',
color: '#ff3d58',
icon: 'regular-database',
snippets: {
'de-DE': deDE,
'en-GB': enGB,
},
routes: {
list: {
component: 'aeon-dump-manager-list',
path: 'list',
meta: {
parentPath: 'sw.settings.index.system',
privilege: 'aeon_dump_manager.viewer',
},
},
},
// Per https://developer.shopware.com/docs/v6.6/guides/plugins/plugins/administration/routing-navigation/add-menu-entry.html —
// plugins can't register a first-level main-menu entry, so this nests
// under the core 'sw-settings' navigation node. Clicking Settings in the
// main sidebar shows this as a sub-item, landing at #/sw/settings/.
navigation: [{
id: 'aeon-dump-manager-list',
label: 'aeon-dump-manager.general.mainMenuItemGeneral',
color: '#ff3d58',
path: 'aeon.dump.manager.list',
icon: 'regular-database',
parent: 'sw-settings',
position: 100,
privilege: 'aeon_dump_manager.viewer',
}],
// Also shown as a card on the Settings overview page's "System" group,
// next to Plugins/Cache — complements the navigation entry above.
settingsItem: {
group: 'system',
to: 'aeon.dump.manager.list',
icon: 'regular-database',
privilege: 'aeon_dump_manager.viewer',
},
});
@@ -1,13 +1,38 @@
import template from './aeon-dump-manager-list.html.twig';
import type DumpApiService, { DumpFile, DumpJob } from '../../../../service/dump-api.service';
const { Component } = Shopware;
interface PendingJob {
status: string;
percent: number | null;
errorMessage?: string | null;
}
interface ComponentData {
dumps: DumpFile[];
isLoading: boolean;
pendingJob: PendingJob | null;
deleteFilename: string | null;
pollTimer: number | null;
}
interface ComponentInstance extends ComponentData {
aeonDumpManagerApiService: DumpApiService;
$tc: (key: string, count?: number, values?: Record<string, unknown>) => string;
createNotificationError: (options: { message: string }) => void;
createNotificationSuccess: (options: { message: string }) => void;
loadList: () => Promise<void>;
stopPolling: () => void;
pollJobStatus: (jobId: string) => void;
}
Component.register('aeon-dump-manager-list', {
template,
inject: ['aeonDumpManagerApiService', 'acl'],
data() {
data(): ComponentData {
return {
dumps: [],
isLoading: false,
@@ -40,16 +65,16 @@ Component.register('aeon-dump-manager-list', {
},
},
created() {
created(this: ComponentInstance) {
this.loadList();
},
beforeDestroy() {
beforeDestroy(this: ComponentInstance) {
this.stopPolling();
},
methods: {
loadList() {
loadList(this: ComponentInstance): Promise<void> {
this.isLoading = true;
return this.aeonDumpManagerApiService.getList()
@@ -61,22 +86,22 @@ Component.register('aeon-dump-manager-list', {
});
},
formatDatetime(value) {
formatDatetime(value: string): string {
return new Date(value).toLocaleString();
},
formatSize(bytes) {
formatSize(bytes: number): string {
return Shopware.Utils.format.fileSize(bytes);
},
onCreate() {
onCreate(this: ComponentInstance) {
this.pendingJob = { percent: 0, status: 'pending' };
this.aeonDumpManagerApiService.create()
.then((response) => {
this.pollJobStatus(response.jobId);
})
.catch((error) => {
.catch((error: Error) => {
this.pendingJob = null;
this.createNotificationError({
message: this.$tc('aeon-dump-manager.list.createFailed', 0, { error: error.message }),
@@ -84,11 +109,11 @@ Component.register('aeon-dump-manager-list', {
});
},
pollJobStatus(jobId) {
pollJobStatus(this: ComponentInstance, jobId: string) {
this.stopPolling();
this.pollTimer = window.setInterval(() => {
this.aeonDumpManagerApiService.getJobStatus(jobId).then((job) => {
this.aeonDumpManagerApiService.getJobStatus(jobId).then((job: DumpJob) => {
if (job.status === 'done') {
this.stopPolling();
this.pendingJob = null;
@@ -101,7 +126,7 @@ Component.register('aeon-dump-manager-list', {
this.stopPolling();
this.pendingJob = null;
this.createNotificationError({
message: this.$tc('aeon-dump-manager.list.createFailed', 0, { error: job.errorMessage }),
message: this.$tc('aeon-dump-manager.list.createFailed', 0, { error: job.errorMessage ?? '' }),
});
return;
}
@@ -111,23 +136,23 @@ Component.register('aeon-dump-manager-list', {
}, 2000);
},
stopPolling() {
stopPolling(this: ComponentInstance) {
if (this.pollTimer !== null) {
window.clearInterval(this.pollTimer);
this.pollTimer = null;
}
},
onRequestDelete(filename) {
onRequestDelete(this: ComponentInstance, filename: string) {
this.deleteFilename = filename;
},
onCancelDelete() {
onCancelDelete(this: ComponentInstance) {
this.deleteFilename = null;
},
onConfirmDelete() {
const filename = this.deleteFilename;
onConfirmDelete(this: ComponentInstance): Promise<void> {
const filename = this.deleteFilename as string;
this.deleteFilename = null;
return this.aeonDumpManagerApiService.remove(filename)
@@ -1,31 +0,0 @@
const { ApiService } = Shopware.Classes;
export default class DumpApiService extends ApiService {
constructor(httpClient, loginService, apiEndpoint = 'aeon-dump-manager') {
super(httpClient, loginService, apiEndpoint);
}
getList() {
return this.httpClient
.get('/_action/aeon-dump-manager/dumps', { headers: this.getBasicHeaders() })
.then((response) => ApiService.handleResponse(response));
}
create() {
return this.httpClient
.post('/_action/aeon-dump-manager/dumps', {}, { headers: this.getBasicHeaders() })
.then((response) => ApiService.handleResponse(response));
}
remove(filename) {
return this.httpClient
.delete(`/_action/aeon-dump-manager/dumps/${encodeURIComponent(filename)}`, { headers: this.getBasicHeaders() })
.then((response) => ApiService.handleResponse(response));
}
getJobStatus(jobId) {
return this.httpClient
.get(`/_action/aeon-dump-manager/dumps/jobs/${encodeURIComponent(jobId)}`, { headers: this.getBasicHeaders() })
.then((response) => ApiService.handleResponse(response));
}
}
@@ -0,0 +1,69 @@
export interface DumpFile {
filename: string;
datetime: string;
sizeBytes: number;
}
export interface DumpList {
dumps: DumpFile[];
}
export interface CreateDumpResponse {
jobId: string;
}
export type DumpJobStatus = 'pending' | 'running' | 'done' | 'failed';
export interface DumpJob {
id: string;
status: DumpJobStatus;
percent: number | null;
filename: string | null;
errorMessage: string | null;
}
// Shopware.Classes.ApiService has no official type package for plugin authors
// (per docs/research/admin-dump-manager-ui.md §4) — redeclaring the inherited
// member this class actually uses keeps everything below typed without one.
// `declare` is required here: a normal field declaration compiles to a real
// `this.httpClient = void 0` in the constructor, which runs *after* `super()`
// and silently clobbers the value the base class just set.
const { ApiService } = Shopware.Classes;
export default class DumpApiService extends ApiService {
protected declare httpClient: {
get: (url: string, config?: unknown) => Promise<unknown>;
post: (url: string, data: unknown, config?: unknown) => Promise<unknown>;
delete: (url: string, config?: unknown) => Promise<unknown>;
};
protected declare getBasicHeaders: (additionalHeaders?: Record<string, string>) => Record<string, string>;
constructor(httpClient: unknown, loginService: unknown, apiEndpoint = 'aeon-dump-manager') {
super(httpClient, loginService, apiEndpoint);
}
getList(): Promise<DumpList> {
return this.httpClient
.get('/_action/aeon-dump-manager/dumps', { headers: this.getBasicHeaders() })
.then((response: unknown) => ApiService.handleResponse(response));
}
create(): Promise<CreateDumpResponse> {
return this.httpClient
.post('/_action/aeon-dump-manager/dumps', {}, { headers: this.getBasicHeaders() })
.then((response: unknown) => ApiService.handleResponse(response));
}
remove(filename: string): Promise<void> {
return this.httpClient
.delete(`/_action/aeon-dump-manager/dumps/${encodeURIComponent(filename)}`, { headers: this.getBasicHeaders() })
.then((response: unknown) => ApiService.handleResponse(response));
}
getJobStatus(jobId: string): Promise<DumpJob> {
return this.httpClient
.get(`/_action/aeon-dump-manager/dumps/jobs/${encodeURIComponent(jobId)}`, { headers: this.getBasicHeaders() })
.then((response: unknown) => ApiService.handleResponse(response));
}
}
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "es2022",
"module": "esnext",
"moduleResolution": "bundler",
"strict": false,
"noEmit": true,
"skipLibCheck": true,
"allowJs": true,
"esModuleInterop": true
},
"include": ["**/*.ts", "global.d.ts"]
}
@@ -0,0 +1 @@
!function(){var e={74:function(){Shopware.Service("privileges").addPrivilegeMappingEntry({category:"permissions",parent:null,key:"aeon_dump_manager",roles:{viewer:{privileges:["aeon_dump_manager.viewer"],dependencies:[]},creator:{privileges:["aeon_dump_manager.creator"],dependencies:["aeon_dump_manager.viewer"]},deleter:{privileges:["aeon_dump_manager.deleter"],dependencies:["aeon_dump_manager.viewer"]}}})}},n={};function t(a){var i=n[a];if(void 0!==i)return i.exports;var r=n[a]={exports:{}};return e[a](r,r.exports,t),r.exports}t.p="bundles/aeondumpmanager/",window?.__sw__?.assetPath&&(t.p=window.__sw__.assetPath+"/bundles/aeondumpmanager/"),function(){"use strict";let{ApiService:e}=Shopware.Classes;class n extends e{constructor(e,n,t="aeon-dump-manager"){super(e,n,t)}getList(){return this.httpClient.get("/_action/aeon-dump-manager/dumps",{headers:this.getBasicHeaders()}).then(n=>e.handleResponse(n))}create(){return this.httpClient.post("/_action/aeon-dump-manager/dumps",{},{headers:this.getBasicHeaders()}).then(n=>e.handleResponse(n))}remove(n){return this.httpClient.delete(`/_action/aeon-dump-manager/dumps/${encodeURIComponent(n)}`,{headers:this.getBasicHeaders()}).then(n=>e.handleResponse(n))}getJobStatus(n){return this.httpClient.get(`/_action/aeon-dump-manager/dumps/jobs/${encodeURIComponent(n)}`,{headers:this.getBasicHeaders()}).then(n=>e.handleResponse(n))}}t(74);let{Component:a}=Shopware;a.register("aeon-dump-manager-list",{template:'{% block aeon_dump_manager_list %}\n<sw-page class="aeon-dump-manager-list">\n <template #smart-bar-actions>\n <sw-button\n v-if="acl.can(\'aeon_dump_manager.creator\')"\n variant="primary"\n :disabled="pendingJob !== null"\n @click="onCreate"\n >\n {{ $tc(\'aeon-dump-manager.list.buttonCreate\') }}\n </sw-button>\n </template>\n\n <template #content>\n <sw-card-view>\n <sw-card>\n <sw-data-grid\n :data-source="dumps"\n :columns="columns"\n :is-loading="isLoading"\n :show-selection="false"\n identifier="filename"\n >\n <template #before-item-list>\n <tr v-if="pendingJob !== null" class="aeon-dump-manager-list__pending-row">\n <td colspan="3">\n <span>{{ $tc(\'aeon-dump-manager.list.creating\') }}</span>\n <sw-progress-bar :max-value="100" :value="pendingJob.percent || 0" />\n </td>\n </tr>\n </template>\n\n <template #column-datetime="{ item }">\n {{ formatDatetime(item.datetime) }}\n </template>\n\n <template #column-sizeBytes="{ item }">\n {{ formatSize(item.sizeBytes) }}\n </template>\n\n <template #actions="{ item }">\n <sw-context-menu-item\n v-if="acl.can(\'aeon_dump_manager.deleter\')"\n variant="danger"\n @click="onRequestDelete(item.filename)"\n >\n {{ $tc(\'aeon-dump-manager.list.buttonDelete\') }}\n </sw-context-menu-item>\n </template>\n\n <template #empty-state>\n {{ $tc(\'aeon-dump-manager.list.empty\') }}\n </template>\n </sw-data-grid>\n </sw-card>\n </sw-card-view>\n </template>\n\n <sw-confirm-modal\n v-if="deleteFilename !== null"\n :title="$tc(\'aeon-dump-manager.list.confirmDeleteTitle\')"\n :text="$tc(\'aeon-dump-manager.list.confirmDeleteText\', 0, { filename: deleteFilename })"\n @confirm="onConfirmDelete"\n @cancel="onCancelDelete"\n @close="onCancelDelete"\n />\n</sw-page>\n{% endblock %}\n',inject:["aeonDumpManagerApiService","acl"],data(){return{dumps:[],isLoading:!1,pendingJob:null,deleteFilename:null,pollTimer:null}},computed:{columns(){return[{property:"datetime",label:this.$tc("aeon-dump-manager.list.columnDatetime"),allowResize:!0},{property:"filename",label:this.$tc("aeon-dump-manager.list.columnFilename"),allowResize:!0},{property:"sizeBytes",label:this.$tc("aeon-dump-manager.list.columnSize"),align:"right",allowResize:!0}]}},created(){this.loadList()},beforeDestroy(){this.stopPolling()},methods:{loadList(){return this.isLoading=!0,this.aeonDumpManagerApiService.getList().then(e=>{this.dumps=e.dumps}).finally(()=>{this.isLoading=!1})},formatDatetime(e){return new Date(e).toLocaleString()},formatSize(e){return Shopware.Utils.format.fileSize(e)},onCreate(){this.pendingJob={percent:0,status:"pending"},this.aeonDumpManagerApiService.create().thenLine truncated