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

feat: local json #112

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d5be9e8
feat: local json
tanftw Nov 14, 2024
4de040b
refactor: move json data to JsonService
tanftw Nov 14, 2024
525eace
refactor: move js and js
tanftw Nov 14, 2024
9134de8
style: clearer UX
tanftw Dec 11, 2024
89c4d51
feat: bulk actions and notice
tanftw Dec 11, 2024
103e29d
feat: show sync status on all statuses
tanftw Dec 11, 2024
70948a0
refactor: add normalizer class
tanftw Dec 30, 2024
020c8c6
import with both old and new syntax
tanftw Dec 30, 2024
0fecc4d
refactor: normalize options
tanftw Dec 30, 2024
202e40b
add invert methods
tanftw Dec 31, 2024
f8a85ab
feat: invert conditional logic, array, datalist
tanftw Jan 2, 2025
5468171
more invert methods
tanftw Jan 3, 2025
d12d750
fix: invert conditional logic
tanftw Jan 6, 2025
970854a
refactor: move unparse to it own classes
tanftw Jan 7, 2025
4341fcb
feat: remove empty fields
tanftw Jan 8, 2025
bb4e5ac
more clean up
tanftw Jan 8, 2025
876af02
default data type and column name
tanftw Jan 15, 2025
63fd9f2
fix: version compare with unprocessed
tanftw Jan 15, 2025
117bb42
add schema to the exported file
tanftw Jan 15, 2025
3b9ae87
register meta box from both json and db
tanftw Jan 15, 2025
3ec8729
style: sync status
tanftw Jan 17, 2025
657069a
fix: fatal error when exporting inside trash
tanftw Jan 17, 2025
909b313
fix: warnings
tanftw Jan 20, 2025
cb48a07
fix: style and format
tanftw Jan 25, 2025
fed2302
fix: use mb id instead of file name
tanftw Jan 26, 2025
220030b
fix: missing schema in the local file
tanftw Feb 3, 2025
73f3608
feat: ajax syncing
tanftw Feb 4, 2025
18a3ed6
fix: translation and clean up
tanftw Feb 5, 2025
a5c3858
add check for files
tanftw Feb 5, 2025
ccc8842
refactor: improve code base
tanftw Feb 6, 2025
146c809
refactor: Use JsonService to register meta boxes
tanftw Feb 6, 2025
9754518
fix: ajax sync
tanftw Feb 11, 2025
775c4a9
fix: remove post_id from diff
tanftw Feb 11, 2025
0358c04
fix: created wrong post type
tanftw Feb 11, 2025
6e9350c
fix: wrong version and post type
tanftw Feb 12, 2025
2ba7fb3
refactor: fix version when sync db->file
tanftw Feb 12, 2025
4ee764e
fix: date format
tanftw Feb 13, 2025
23eda6f
refactor: show only minimized version
tanftw Feb 17, 2025
6f22b1e
fix: typing and scroll css
tanftw Feb 17, 2025
719f3ce
refactor: clean up false values
tanftw Feb 17, 2025
fce3914
refactor: make conditional logic even shorter
tanftw Feb 17, 2025
022a53f
refactor: set version directly on meta box
tanftw Feb 18, 2025
f2ac744
refactor: reuse get_meta_boxes function
tanftw Feb 18, 2025
81022d9
fix: bulk syncing
tanftw Feb 18, 2025
1c34b0a
style: no changes detected message
tanftw Feb 18, 2025
c62d3f3
fix: import multiple meta boxes
tanftw Feb 18, 2025
dd0b8d9
refactor: disable functionality if no json path found
tanftw Feb 18, 2025
aed3248
refactor: reload within 1s
tanftw Feb 18, 2025
95dcf64
fix: location column
tanftw Feb 18, 2025
6ecf194
fix: remove `closed` key
tanftw Feb 19, 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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ composer.lock export-ignore
package.json export-ignore
pnpm-lock.yaml export-ignore
webpack.config.js export-ignore
tests export-ignore
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
node_modules
*.zip
*.LICENSE.txt
composer.lock
.phpunit.cache
194 changes: 194 additions & 0 deletions assets/css/list.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
width: 16px;
height: 16px;
}

.mbb-tooltip .dashicons {
font-size: 14px;
width: 16px;
height: 16px;
margin-top: 2px;
}

.tippy-tooltip {
text-align: left;
}

.column-shortcode input {
max-width: 100%;
}
Expand All @@ -25,6 +28,7 @@
display: none;
padding: 50px 0;
}

.mbb-import-form p {
color: #555d66;
font-size: 18px;
Expand All @@ -33,10 +37,200 @@
padding: 0;
text-align: center;
}

.mbb-import-form form {
background: #fafafa;
border: 1px solid #e5e5e5;
padding: 30px;
margin: 30px auto;
max-width: 380px;
}

#mbb-diff-dialog {
width: 80%;
max-width: 800px;
border: 1px solid #ccd0d4;
border-radius: 4px;
box-shadow: 0 3px 5px rgba(0, 0, 0, 0.2);
padding: 20px;
background: #fff;
}

#mbb-diff-dialog header {
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 10px;
margin-bottom: 20px;
}

#mbb-diff-dialog header h2 {
margin: 0;
font-size: 1.5em;
}

#mbb-diff-dialog .mbb-diff-dialog-button-group {
width: 100%;
display: flex;
gap: 10px;
margin: 40px 0;
}

#mbb-diff-dialog .mbb-diff-dialog-button-group>div {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
}

#mbb-diff-dialog header button {
background: none;
border: none;
color: #0073aa;
cursor: pointer;
}

#mbb-diff-dialog header button:hover {
color: #005177;
}

.mbb-diff-dialog-content {
display: flex;
justify-content: space-between;
background: #fafafa;
border-radius: 10px;
}

.button-sync {
background: none;
color: #0073aa;
border: 1px solid #0073aa;
border-radius: 4px;
padding: 10px 20px;
cursor: pointer;
transition: background-color 0.3s ease, color 0.3s ease;
}

.button-sync:hover {
background: #0073aa;
color: #fff;
}

.button-sync:disabled {
background: none;
color: #0073aa;
opacity: 0.5;
cursor: not-allowed;
}

.sync-success-content {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
background: #D6F1DF;
color: #218358;
animation: fadeIn 0.5s ease-in-out;
}

.sync-error-content {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
background: #FFF7F8;
color: #CA244D;
animation: fadeIn 0.5s ease-in-out;
}

.no-changes-content {
display: flex;
align-items: center;
justify-content: center;
flex: 1;
animation: fadeIn 0.5s ease-in-out;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}

#mbb-diff-dialog {
max-height: 80vh;
overflow: hidden;
}

.mbb-diff-dialog-content {
max-height: 300px;
overflow: auto;
}

.mbb-diff-dialog-content>div {
width: 48%;
}

.mbb-diff-dialog-content h3 {
margin-top: 0;
font-size: 1.2em;
}

.mbb-diff-dialog-content pre {
background: #f6f7f7;
border: 1px solid #ccd0d4;
border-radius: 4px;
padding: 10px;
overflow-x: auto;
max-height: 300px;
}

#mbb-diff-dialog footer {
display: flex;
justify-content: flex-end;
padding-top: 10px;
margin-top: 20px;
}

#mbb-diff-dialog footer button {
margin-left: 10px;
}

#mbb-diff-dialog-close {
font-size: 2em;
text-decoration: none;
}

.mbb-label {
padding: 4px 8px;
border-radius: 5px;
display: inline-block;
}

.mbb-sub-path {
color: #999;
}

.mbb-label[data-status="synced"] {
background: #D6F1DF;
color: #218358;
}

.mbb-label[data-status="changes_detected"] {
background: #FFDFB5;
color: #CC4E00;
}

.mbb-label[data-status="error"] {
background: #FFF7F8;
color: #CA244D;
}

.mbb-label[data-status="not_imported"] {
background: #F0F0F0;
color: #646464;
}
86 changes: 82 additions & 4 deletions assets/js/list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
jQuery( function ( $ ) {
jQuery( $ => {
// Add "Export" option to the Bulk Actions dropdowns.
$( '<option value="mbb-export">' )
.text( MBB.export )
Expand All @@ -10,16 +10,94 @@ jQuery( function ( $ ) {
.text( MBB.import )
.insertAfter( '.page-title-action' );

$toggle.on( 'click', function( e ) {
$toggle.on( 'click', e => {
e.preventDefault();
$form.toggle();
} );

// Enable submit button when selecting a file.
var $input = $form.find( 'input[type="file"]' ),
const $input = $form.find( 'input[type="file"]' ),
$submit = $form.find( 'input[type="submit"]' );

$input.on( 'change', function() {
$input.on( 'change', () => {
$submit.prop( 'disabled', ! $input.val() );
} );

// Dialog for diff
document.getElementById( 'mbb-diff-dialog-close' ).addEventListener( 'click', () => {
document.getElementById( 'mbb-diff-dialog' ).close();
} );
document.getElementById( 'mbb-diff-dialog-close-btn' ).addEventListener( 'click', () => {
document.getElementById( 'mbb-diff-dialog' ).close();
} );

// Escape key to close dialog
document.addEventListener( 'keydown', ( e ) => {
if ( e.key === 'Escape' ) {
document.getElementById( 'mbb-diff-dialog' ).close();
}
} );

// Click outside to close dialog
document.getElementById( 'mbb-diff-dialog' ).addEventListener( 'click', ( e ) => {
if ( e.target === document.getElementById( 'mbb-diff-dialog' ) ) {
document.getElementById( 'mbb-diff-dialog' ).close();
}
} );

// AJAX action to run sync
document.querySelectorAll( '.button-sync' ).forEach( buttonSync => {
buttonSync.addEventListener( 'click', async (e) => {
e.preventDefault();
const previousText = buttonSync.textContent;

// Set the button to loading state
buttonSync.classList.add( 'loading' );
buttonSync.disabled = true;
buttonSync.textContent = MBB.syncing;

const data = await wp.apiFetch( {
path: '/mbb/set-json-data',
method: 'PUT',
data: {
id: buttonSync.dataset.id,
use: buttonSync.dataset.use,
}
} );

if ( data.success ) {
const templateSyncSuccess = document.querySelector('#sync-success').content.cloneNode(true);

// Update the diff section
document.querySelector('.mbb-diff-dialog-content').innerHTML = templateSyncSuccess.querySelector('div').innerHTML;

// Update status of current row sync to synced
const label = document.querySelector(`.mbb-label[data-for-id="${buttonSync.dataset.id}"]`);
label.textContent = MBB.synced;
label.dataset.status = 'synced';
} else {
const templateSyncError = document.querySelector('#sync-error').content.cloneNode(true);

// Update the diff section
document.querySelector('.mbb-diff-dialog-content').innerHTML = templateSyncError.querySelector('div').innerHTML;
// Update status of current row sync to error
const label = document.querySelector(`.mbb-label[data-for-id="${buttonSync.dataset.id}"]`);
label.textContent = MBB.error;
label.dataset.status = 'error';
}

// Run the sync

// Reset the button
buttonSync.classList.remove( 'loading' );
buttonSync.disabled = false;
buttonSync.textContent = previousText;

// Refresh in 1 seconds
setTimeout(() => {
location.reload();
}, 1000);
} );
} );

} );
1 change: 1 addition & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
new About();
new Import();
new Export();
new LocalJson();
new Edit( 'meta-box', __( 'Field Group ID', 'meta-box-builder' ) );
new AdminColumns();
}
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"meta-box/mbb-parser": "dev-master",
"elightup/twig": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "^11.3"
},
"scripts": {
"post-update-cmd": [
"echo Deleting .git dirs...",
Expand Down Expand Up @@ -90,4 +93,4 @@
]
}
}
}
}
Loading