Skip to content
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

Dis 92 add feedback when saving grapes page #2194

Open
wants to merge 18 commits into
base: 25.02.00
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
cf0eea5
feat: Add message for template and page save
AlexanderBlanchardAC Jan 2, 2025
e510c0f
chore: Update Change Log
AlexanderBlanchardAC Jan 3, 2025
c88a6cd
chore: Update Release Notes
AlexanderBlanchardAC Jan 14, 2025
e16e0a9
Merge pull request #153 from AlexanderBlanchardAC/DIS-92-Add_Feedback…
AlexanderBlanchardAC Jan 14, 2025
b800113
refactor: Update success and error save messages
AlexanderBlanchardAC Jan 15, 2025
475556c
Merge pull request #161 from AlexanderBlanchardAC/DIS-92-Add_Feedback…
AlexanderBlanchardAC Jan 15, 2025
7658ba5
refactor: Update success and error save messages
AlexanderBlanchardAC Jan 15, 2025
0f5da38
Merge pull request #162 from AlexanderBlanchardAC/DIS-92-Add_Feedback…
AlexanderBlanchardAC Jan 15, 2025
e6224f9
refactor: Add User Logged In Check to Grapes
AlexanderBlanchardAC Jan 17, 2025
f60b5ab
feat: Check user grapes permissions before saving
AlexanderBlanchardAC Jan 17, 2025
14bff62
chore: Update change log
AlexanderBlanchardAC Jan 17, 2025
b1f4322
Merge pull request #170 from AlexanderBlanchardAC/DIS-92-Add_Feedback…
AlexanderBlanchardAC Jan 17, 2025
22f7e9d
feat: Check user grapes permissions before saving
AlexanderBlanchardAC Jan 17, 2025
8f50bb1
chore: Update change log
AlexanderBlanchardAC Jan 17, 2025
300b2e8
Merge branch 'DIS-92_Add_Feedback_When_Saving_Grapes_Page' into DIS-9…
AlexanderBlanchardAC Jan 17, 2025
e8445e1
Merge pull request #171 from AlexanderBlanchardAC/DIS-92-Add_Feedback…
AlexanderBlanchardAC Jan 17, 2025
9bb9c60
refactor: Alter check to use active user
AlexanderBlanchardAC Jan 17, 2025
87e2a82
Merge pull request #172 from AlexanderBlanchardAC/DIS-92-Add_Feedback…
AlexanderBlanchardAC Jan 17, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,19 @@
}),
contentType: "application/json",
success: function (response) {
console.log('Saved as Template');
if (response.success) {
AlexanderBlanchardAC marked this conversation as resolved.
Show resolved Hide resolved
AspenDiscovery.showMessage('Success', response.message);
} else {
AspenDiscovery.showMessage('Error', response.message || 'Failed to save template.');
}
},
error: function (xhr, status, error) {
console.error('Error saving template: ', error);
let errorMessage = 'Failed to save template. Please try again.';
AlexanderBlanchardAC marked this conversation as resolved.
Show resolved Hide resolved
if (xhr.responseJSON && xhr.responseJSON.message) {
errorMessage = xhr.responseJSON.message;
}
AspenDiscovery.showMessage('Error', errorMessage);
}
});
}
Expand Down
11 changes: 10 additions & 1 deletion code/web/interface/themes/responsive/WebBuilder/grapesjs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,19 @@
}),
contentType: "application/json",
success: function (response) {
console.log('Saved as Grapes Page');
if (response.success) {
AspenDiscovery.showMessage('Success', response.message);
} else {
AspenDiscovery.showMessage('Error', response.message || 'Failed to save page.');
}
},
error: function (xhr, status, error) {
console.error('Error saving page: ', error);
let errorMessage = 'Failed to save page. Please try again.';
if (xhr.responseJSON && xhr.responseJSON.message){
errorMessage = xhr.responseJSON.message;
}
AspenDiscovery.showMessage('Error', errorMessage);
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions code/web/release_notes/25.02.00.MD
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
//james

//alexander
### Web Builder Updates
- Add a message when saving a Grapes JS Template or Page to confirm it has been updated successfully. (*AB*)

//chloe

Expand Down
116 changes: 80 additions & 36 deletions code/web/services/WebBuilder/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -972,43 +972,87 @@ function trackWebResourceUsage() {
}
function saveAsTemplate(){
require_once ROOT_DIR . '/sys/WebBuilder/GrapesTemplate.php';
$newGrapesPageContent = json_decode(file_get_contents("php://input"), true);
$templateId = $newGrapesPageContent['templateId'];
$html = $newGrapesPageContent['html'];
$css = $newGrapesPageContent['css'];
$projectData = json_encode($newGrapesPageContent['projectData']);

$template = new GrapesTemplate();
$template->id = $templateId;

if ($template->find(true)) {
$template->templateContent = $projectData;
$template->htmlData = $html;
$template->cssData = $css;
}
$template->update();
}

function saveAsPage() {
require_once ROOT_DIR . '/sys/WebBuilder/GrapesPage.php';
$newGrapesPageContent = json_decode(file_get_contents("php://input"), true);
$grapesPageId = $newGrapesPageContent['grapesPageId'];
$grapesGenId = $newGrapesPageContent['grapesGenId'];
$templateId = $newGrapesPageContent['templateId'];
$html = $newGrapesPageContent['html'];
$css = $newGrapesPageContent['css'];
$grapesPage = new GrapesPage();
$grapesPage->id = $grapesPageId;
$projectData = json_encode($newGrapesPageContent['projectData']);

try {
$newGrapesPageContent = json_decode(file_get_contents("php://input"), true);
$templateId = $newGrapesPageContent['templateId'];
$html = $newGrapesPageContent['html'];
$css = $newGrapesPageContent['css'];
$projectData = json_encode($newGrapesPageContent['projectData']);

$template = new GrapesTemplate();
$template->id = $templateId;

if (!$template->find(true)) {
return [
'success' => false,
'message' => "Template with ID $templateId not found. Unable to update."
AlexanderBlanchardAC marked this conversation as resolved.
Show resolved Hide resolved
AlexanderBlanchardAC marked this conversation as resolved.
Show resolved Hide resolved
];
}
$template->templateContent = $projectData;
$template->htmlData = $html;
$template->cssData = $css;

if(!$template->update()) {
return [
'success' => false,
'message' => 'Failed to update the template.'
];
}
return [
'success' => true,
'message' => 'Template saved successfully.'
];
} catch (Exception $e) {
return [
'success' => false,
'message' => 'an unexpected error occurred: ' . $e->getMessage()
];
}
}

if ($grapesPage->find(true)) {
$grapesPage->grapesGenId = $grapesGenId;
$grapesPage->templateContent = $projectData;
$grapesPage->htmlData = $html;
$grapesPage->cssData = $css;
}
$grapesPage->update();
}
function saveAsPage() {
require_once ROOT_DIR . '/sys/WebBuilder/GrapesPage.php';

try {
$newGrapesPageContent = json_decode(file_get_contents("php://input"), true);
$grapesPageId = $newGrapesPageContent['grapesPageId'];
$grapesGenId = $newGrapesPageContent['grapesGenId'];
$templateId = $newGrapesPageContent['templateId'];
$html = $newGrapesPageContent['html'];
$css = $newGrapesPageContent['css'];
$grapesPage = new GrapesPage();
$grapesPage->id = $grapesPageId;
$projectData = json_encode($newGrapesPageContent['projectData']);

if (!$grapesPage->find(true)) {
return [
'success' =>false,
'message' => "Page with ID $grapesPageId not found. Unable to update."
];
}
$grapesPage->grapesGenId = $grapesGenId;
$grapesPage->templateContent = $projectData;
$grapesPage->htmlData = $html;
$grapesPage->cssData = $css;

if (!$grapesPage->update()) {
return [
'success ' => false,
'message' => 'Failed to update the page.'
];
}
return [
'success' => true,
'message' => 'Page saved successfully.'
];
} catch (Exception $e) {
return [
'success' => false,
'message' => 'An unexpected error occurred: ' . $e->getMessage()
];
}
}

function loadGrapesPage() {
require_once ROOT_DIR . '/sys/WebBuilder/GrapesPage.php';
Expand Down
Loading