Skip to content

FOUR-13443 Implement Clipboard usage between pages or separate screens #7423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ProcessMaker/Models/Clipboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ class Clipboard extends ProcessMakerModel
'updated_at',
];

/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'config' => 'array',
];

public function user()
{
return $this->belongsTo(User::class);
Expand Down
9 changes: 0 additions & 9 deletions resources/js/processes/screen-builder/screen.vue
Original file line number Diff line number Diff line change
Expand Up @@ -716,15 +716,6 @@ export default {
ProcessMaker.EventBus.$on("show-create-template-modal", () => {
this.$refs["create-template-modal"].show();
});
ProcessMaker.EventBus.$on(
"save-clipboard",
(items) => {
console.log('save-clipboard',items);
ProcessMaker.apiClient.post('/api/1.1/clipboard/create_or_update', {
config: JSON.stringify(items),
});
},
);
},
methods: {
...mapMutations("globalErrorsModule", { setStoreMode: "setMode" }),
Expand Down
41 changes: 14 additions & 27 deletions resources/views/processes/screen-builder/screen.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,43 +100,29 @@ class="border-0 bg-white p-0"
}
});
window.ProcessMaker.EventBus.$on("screen-renderer-init", (screen) => {
const savedClipboard = localStorage.getItem("savedClipboard");
// Register saveToServerFn
screen.$store.dispatch("clipboardModule/setupSaveToServerFn", (items) => {
return ProcessMaker.apiClient.post('/api/1.1/clipboard/create_or_update', {
config: items, // JSON.stringify(items),
});
});

if (savedClipboard) {
addClipboardToStore(savedClipboard);
return;
}

ProcessMaker.apiClient.get('/api/1.1/clipboard/get_by_user')
// Register loadFromServerFn
screen.$store.dispatch("clipboardModule/setupLoadFromServerFn", () => {
return ProcessMaker.apiClient.get('/api/1.1/clipboard/get_by_user')
.then(handleClipboardResponse)
.catch(handleClipboardError);

/**
* Helper function to add clipboard data to the store
* @param {string|object} clipboardData
*/
function addClipboardToStore(clipboardData) {
try {
const parsedData = typeof clipboardData === 'string' ? JSON.parse(clipboardData) : clipboardData;
if (parsedData && typeof parsedData === 'object') {
screen.$store.dispatch("clipboardModule/addToClipboard", parsedData);
} else {
console.error("Clipboard data is not in the expected format.");
}
} catch (error) {
console.error("Failed to parse clipboard data: ", error);
}
}

/**
* Handle clipboard API response
* @param {object} response
*/
function handleClipboardResponse(response) {
if (response && response.data && response.data.config) {
addClipboardToStore(response.data.config);
if (response && response.data && response.data.config && Array.isArray(response.data.config)) {
// addClipboardToStore(response.data.config);
return response.data.config;
} else {
console.error("No valid clipboard config data in response.");
throw new Error("No valid clipboard config data in response.");
}
}

Expand All @@ -147,6 +133,7 @@ function handleClipboardResponse(response) {
function handleClipboardError(error) {
console.error("Error fetching clipboard data: ", error);
}
});
});

window.Processmaker.user = @json($currentUser);
Expand Down
Loading