Skip to content

Commit 614aa09

Browse files
wip
1 parent 0bf905f commit 614aa09

File tree

13 files changed

+1190
-618
lines changed

13 files changed

+1190
-618
lines changed

client/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"name": "@statamic-backup/client",
33
"type": "module",
44
"scripts": {
5-
"dev": "vite",
5+
"dev": "vite build --watch",
66
"build": "vite build"
77
},
88
"devDependencies": {
9-
"@vitejs/plugin-vue2": "^2.3.1",
10-
"laravel-vite-plugin": "^1.0.2",
11-
"vite": "^6.3.5"
9+
"@statamic/cms": "file:./../vendor/statamic/cms/resources/js/package",
10+
"laravel-vite-plugin": "^2.0.0",
11+
"vite": "npm:rolldown-vite@latest"
1212
},
1313
"dependencies": {
1414
"resumablejs": "^1.1.0"

client/src/components/Backup.vue

Lines changed: 62 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,65 @@
1-
<template>
2-
<div>
3-
<div class="flex">
4-
<div class="flex flex-col mb-4">
5-
<h1>{{ __("statamic-backup::backup.title") }}</h1>
6-
<p v-if="status !== 'idle'" class="text-sm text-gray-700 whitespace-nowrap">
7-
{{ __(`statamic-backup::backup.state.${status}`) }}
8-
</p>
9-
</div>
10-
<backup-actions @openBrowser="openBrowser" />
11-
</div>
12-
13-
<backup-listing />
14-
</div>
15-
</template>
1+
<script setup>
2+
import { Listing, DropdownItem, Header, Button } from "@statamic/cms/ui";
3+
import { requireElevatedSession } from "@statamic/cms"
4+
import { useBackupStore } from "../store";
5+
6+
const backupStore = useBackupStore();
7+
8+
backupStore.startPolling();
9+
10+
const restoreFrom = async (id) => {
1611
17-
<script>
18-
import Listing from "./Listing.vue";
19-
import Actions from "./Actions.vue";
20-
import { store } from "../store";
21-
22-
export default {
23-
components: {
24-
"backup-listing": Listing,
25-
"backup-actions": Actions,
26-
},
27-
props: {
28-
chunkSize: {
29-
type: Number,
30-
default: 2 * 1024 * 1024, // 2MB
31-
},
32-
},
33-
created() {
34-
// console.log(this.chunkSize)
35-
36-
window.backup = {
37-
chunkSize: this.chunkSize
38-
};
39-
40-
if (!this.$store.hasModule('backup-provider')) {
41-
this.$store.registerModule('backup-provider', store);
42-
this.$store.dispatch('backup-provider/pollEndpoint');
12+
try {
13+
await requireElevatedSession();
14+
15+
const { data } = await window.Statamic.$app.config.globalProperties.$axios.post(cp_url(`api/backups/restore/${id}`));
16+
17+
Statamic.$toast.info(__(data.message));
18+
} catch (e) {
19+
console.error(e);
20+
21+
if (error.response.data.message) {
22+
Statamic.$toast.error(message);
23+
} else {
24+
Statamic.$toast.error(__('statamic-backup::backup.restore.failed'));
25+
}
4326
}
44-
},
45-
computed: {
46-
status() {
47-
return this.$store.state['backup-provider'].status;
48-
},
49-
},
50-
destroy() {
51-
this.$store.dispatch('backup-provider/stopPolling');
52-
this.$store.unregisterModule('backup-provider');
53-
},
54-
};
27+
}
28+
29+
const queueBackup = async () => {
30+
try {
31+
backupStore.setStatus('backup_in_progress');
32+
33+
const { data } = await window.Statamic.$app.config.globalProperties.$axios.post(cp_url("api/backups"));
34+
35+
Statamic.$toast.info(__(data.message));
36+
} catch (e) {
37+
console.error(e);
38+
39+
if (error.response.data.message) {
40+
Statamic.$toast.error(message);
41+
} else {
42+
Statamic.$toast.error(__('statamic-backup::backup.restore.failed'));
43+
}
44+
}
45+
}
46+
5547
</script>
48+
<template>
49+
<Header :icon="database" :title="__('statamic-backup::backup.title')">
50+
<Button icon="save" variant="primary" v-on:click="queueBackup" :disabled="!backupStore.abilities.backup.isPossible">{{ __("statamic-backup::backup.create") }}</Button>
51+
</Header>
52+
53+
<Listing :allowSearch="false" :allowCustomizingColumns="false" :url="cp_url('api/backups')">
54+
<template #prepended-row-actions="{ row }">
55+
<DropdownItem v-if="backupStore.abilities.download.isPermitted"
56+
:text="__('statamic-backup::backup.download.label')"
57+
:href="`${cp_url('api/backups/download')}/${row.id}`" />
58+
<DropdownItem v-if="backupStore.abilities.restore.isPermitted"
59+
:disabled="!backupStore.abilities.restore.isPossible" @click="restoreFrom(row.id)"
60+
:text="__('statamic-backup::backup.restore.label')" />
61+
<DropdownItem v-if="backupStore.abilities.destroy.isPermitted" :dangerous="true"
62+
@click="() => console.log(row.id, row.name)" :text="__('statamic-backup::backup.destroy.label')" />
63+
</template>
64+
</Listing>
65+
</template>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<template>
2+
<div>
3+
<div class="flex">
4+
<div class="flex flex-col mb-4">
5+
<h1>{{ __("statamic-backup::backup.title") }}</h1>
6+
<p v-if="status !== 'idle'" class="text-sm text-gray-700 whitespace-nowrap">
7+
{{ __(`statamic-backup::backup.state.${status}`) }}
8+
</p>
9+
</div>
10+
<backup-actions @openBrowser="openBrowser" />
11+
</div>
12+
13+
<backup-listing />
14+
</div>
15+
</template>
16+
17+
<script>
18+
import Listing from "./Listing.vue";
19+
import Actions from "./Actions.vue";
20+
import { store } from "../../store";
21+
22+
export default {
23+
components: {
24+
"backup-listing": Listing,
25+
"backup-actions": Actions,
26+
},
27+
props: {
28+
chunkSize: {
29+
type: Number,
30+
default: 2 * 1024 * 1024, // 2MB
31+
},
32+
},
33+
created() {
34+
// console.log(this.chunkSize)
35+
36+
window.backup = {
37+
chunkSize: this.chunkSize
38+
};
39+
40+
if (!this.$store.hasModule('backup-provider')) {
41+
this.$store.registerModule('backup-provider', store);
42+
this.$store.dispatch('backup-provider/pollEndpoint');
43+
}
44+
},
45+
computed: {
46+
status() {
47+
return this.$store.state['backup-provider'].status;
48+
},
49+
},
50+
destroy() {
51+
this.$store.dispatch('backup-provider/stopPolling');
52+
this.$store.unregisterModule('backup-provider');
53+
},
54+
};
55+
</script>
File renamed without changes.

client/src/store.js

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ const calculatePollDelay = (state) => {
1313
return 5000;
1414
};
1515

16-
export const store = {
17-
namespaced: true,
16+
export const useBackupStore = Statamic.$pinia.defineStore("itiden::backup", {
1817
state: () => ({
1918
status: "initializing",
2019
timeout: null,
@@ -24,75 +23,51 @@ export const store = {
2423
return {
2524
backup: {
2625
isPossible: !INPROGRESS_STATES.includes(state.status),
27-
isPermitted:
28-
Statamic.$store.state.statamic.config.user.super ??
29-
Statamic.$store.state.statamic.config.user.permissions.includes(
30-
"download backups"
31-
),
26+
isPermitted: Statamic.$permissions.has("download backups"),
3227
},
3328
download: {
3429
isPossible: !INPROGRESS_STATES.includes(state.status),
35-
isPermitted:
36-
Statamic.$store.state.statamic.config.user.super ??
37-
Statamic.$store.state.statamic.config.user.permissions.includes(
38-
"restore backups"
39-
),
30+
isPermitted: Statamic.$permissions.has("restore backups"),
4031
},
4132
restore: {
4233
isPossible: !INPROGRESS_STATES.includes(state.status),
43-
isPermitted:
44-
Statamic.$store.state.statamic.config.user.super ??
45-
Statamic.$store.state.statamic.config.user.permissions.includes(
46-
"restore backups"
47-
),
34+
isPermitted: Statamic.$permissions.has("restore backups"),
4835
},
4936
destroy: {
5037
isPossible: !INPROGRESS_STATES.includes(state.status),
51-
isPermitted:
52-
Statamic.$store.state.statamic.config.user.super ??
53-
Statamic.$store.state.statamic.config.user.permissions.includes(
54-
"delete backups"
55-
),
38+
isPermitted: Statamic.$permissions.has("delete backups"),
5639
},
5740
};
5841
},
5942
},
60-
mutations: {
61-
setStatus(state, payload) {
62-
state.status = payload;
63-
// console.log("Server state:", state.status);
64-
},
65-
cancelPoll(state) {
66-
clearTimeout(state.timeout);
67-
state.commit("timeout", null);
68-
},
69-
},
7043
actions: {
71-
setStatus: ({ commit }, payload) => {
72-
commit("setStatus", payload);
44+
setStatus(payload) {
45+
this.status = payload;
7346
},
74-
stopPolling: ({ commit }) => {
75-
commit("cancelPoll");
47+
stopPolling() {
48+
clearTimeout(this.timeout);
49+
this.timeout = null;
7650
},
77-
pollEndpoint: ({ commit }) => {
51+
startPolling() {
7852
const pollServerState = async () => {
7953
let state;
8054
try {
81-
const response = await Statamic.$axios.get(
82-
cp_url("api/backups/state")
83-
);
55+
const response =
56+
await window.Statamic.$app.config.globalProperties.$axios.get(
57+
cp_url("api/backups/state")
58+
);
8459
state = response.data.state;
85-
commit("setStatus", response.data.state);
60+
this.setStatus(response.data.state);
8661
} catch (error) {
8762
console.error("Error fetching server state:", error);
8863
} finally {
8964
const pollDelay = calculatePollDelay(state);
90-
// console.log("Polling delay:", pollDelay);
91-
commit("timeout", setTimeout(pollServerState, pollDelay));
65+
66+
this.timeout = setTimeout(pollServerState, pollDelay);
9267
}
9368
};
9469

9570
pollServerState();
9671
},
9772
},
98-
};
73+
});

client/vite.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { defineConfig } from "vite";
22
import laravel from "laravel-vite-plugin";
3-
import vue from "@vitejs/plugin-vue2";
3+
import statamic from "@statamic/cms/vite-plugin";
44

55
export default defineConfig({
66
build: {
77
emptyOutDir: true,
88
},
99
plugins: [
10+
statamic(),
1011
laravel({
12+
refresh: true,
1113
input: ["src/main.js"],
1214
publicDirectory: "./../resources/dist",
1315
}),
14-
vue(),
1516
],
1617
});

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
],
1111
"require": {
1212
"ext-zip": "*",
13-
"statamic/cms": "^5.0.0",
13+
"statamic/cms": "6.0.0-alpha.1",
1414
"pixelfear/composer-dist-plugin": "^0.1.6"
1515
},
1616
"require-dev": {
1717
"orchestra/testbench": "^9.0",
1818
"pestphp/pest": "^3.0",
1919
"pestphp/pest-plugin-laravel": "^3.0",
20-
"carthage-software/mago": "1.0.0-alpha.2"
20+
"carthage-software/mago": "1.0.0-alpha.12"
2121
},
2222
"autoload": {
2323
"psr-4": {

0 commit comments

Comments
 (0)