Skip to content

UI and usability improvements #119

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

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions assets/js/revisr-staging.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ jQuery(document).ready(function($) {

$.post(ajaxurl, data, function(response) {
document.getElementById('pending_files_result').innerHTML = response;
old_title = document.getElementById('title');
new_title = document.getElementById('title-tmp');
document.getElementById('titlewrap').replaceChild(new_title, old_title);
new_title.id = 'title';
});

}
Expand Down
25 changes: 19 additions & 6 deletions classes/class-revisr-admin-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public function menus() {
$this->page_hooks['menu'] = add_menu_page( __( 'Dashboard', 'revisr' ), __( 'Revisr', 'revisr' ), $cap, 'revisr', array( $this, 'include_page' ), $icon_svg );
$this->page_hooks['dashboard'] = add_submenu_page( 'revisr', __( 'Revisr - Dashboard', 'revisr' ), __( 'Dashboard', 'revisr' ), $cap, 'revisr', array( $this, 'include_page' ) );
$this->page_hooks['commits'] = add_submenu_page( 'revisr', __( 'Revisr - Commits', 'revisr' ), __( 'Commits', 'revisr' ), $cap, 'revisr_commits', array( $this, 'include_page' ) );
$this->page_hooks['new_commit'] = add_submenu_page( NULL, __( 'Revisr - New Commit', 'revisr' ), __( 'New Commit', 'revisr' ), $cap, 'revisr_new_commit', array( $this, 'include_page' ) );
$this->page_hooks['view_commit'] = add_submenu_page( NULL, __( 'Revisr - View Commit', 'revisr' ), __( 'View Commit', 'revisr' ), $cap, 'revisr_view_commit', array( $this, 'include_page' ) );
$this->page_hooks['new_commit'] = add_submenu_page( 'admin', __( 'Revisr - New Commit', 'revisr' ), __( 'New Commit', 'revisr' ), $cap, 'revisr_new_commit', array( $this, 'include_page' ) );
$this->page_hooks['view_commit'] = add_submenu_page( 'admin', __( 'Revisr - View Commit', 'revisr' ), __( 'View Commit', 'revisr' ), $cap, 'revisr_view_commit', array( $this, 'include_page' ) );
$this->page_hooks['branches'] = add_submenu_page( 'revisr', __( 'Revisr - Branches', 'revisr' ), __( 'Branches', 'revisr' ), $cap, 'revisr_branches', array( $this, 'include_page' ) );
$this->page_hooks['settings'] = add_submenu_page( 'revisr', __( 'Revisr - Settings', 'revisr' ), __( 'Settings', 'revisr' ), $cap, 'revisr_settings', array( $this, 'include_page' ) );
$this->page_hooks['setup'] = add_submenu_page( NULL, __( 'Revisr - Setup', 'revisr' ), 'Revisr', $cap, 'revisr_setup', array( $this, 'include_page' ) );
$this->page_hooks['setup'] = add_submenu_page( 'admin', __( 'Revisr - Setup', 'revisr' ), 'Revisr', $cap, 'revisr_setup', array( $this, 'include_page' ) );
} else {
$this->page_hooks['setup'] = add_menu_page( __( 'Revisr Setup', 'revisr' ), __( 'Revisr', 'revisr' ), $cap, 'revisr_setup', array( $this, 'include_page' ), $icon_svg );
$this->page_hooks['dashboard'] = add_submenu_page( null, __( 'Revisr - Dashboard', 'revisr' ), __( 'Dashboard', 'revisr' ), $cap, 'revisr', array( $this, 'include_page' ) );
$this->page_hooks['branches'] = add_submenu_page( NULL, __( 'Revisr - Branches', 'revisr' ), __( 'Branches', 'revisr' ), $cap, 'revisr_branches', array( $this, 'include_page' ) );
$this->page_hooks['settings'] = add_submenu_page( NULL, __( 'Revisr - Settings', 'revisr' ), __( 'Settings', 'revisr' ), $cap, 'revisr_settings', array( $this, 'include_page' ) );
$this->page_hooks['dashboard'] = add_submenu_page( 'admin', __( 'Revisr - Dashboard', 'revisr' ), __( 'Dashboard', 'revisr' ), $cap, 'revisr', array( $this, 'include_page' ) );
$this->page_hooks['branches'] = add_submenu_page( 'admin', __( 'Revisr - Branches', 'revisr' ), __( 'Branches', 'revisr' ), $cap, 'revisr_branches', array( $this, 'include_page' ) );
$this->page_hooks['settings'] = add_submenu_page( 'admin', __( 'Revisr - Settings', 'revisr' ), __( 'Settings', 'revisr' ), $cap, 'revisr_settings', array( $this, 'include_page' ) );
}

}
Expand Down Expand Up @@ -277,6 +277,19 @@ public function site5_notice() {
<?php _e( 'Sponsored by', 'revisr' ); ?>
<a href="http://www.site5.com/" target="_blank"><img id="site5_logo" src="<?php echo REVISR_URL . 'assets/img/site5.png'; ?>" width="80" /></a>
</div>

<style>
#TB_window {
width: 95% !important;
left: 0px !important;
margin-left: 52px !important;
}
#TB_ajaxContent {
width: 98% !important;
height: 95% !important;
font-family: monospace;
}
</style>
<?php
}

Expand Down
15 changes: 13 additions & 2 deletions classes/class-revisr-git.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,13 @@ public function run( $command, $args, $callback = '', $info = '' ) {
$git_dir = Revisr_Admin::escapeshellarg( "--git-dir=$this->git_dir" );
$work_tree = Revisr_Admin::escapeshellarg( "--work-tree=$this->work_tree" );

// Check for the special SSH key
exec( "stat ~/.ssh/id_github", $stat_output, $stat_return_code );
$ssh_key = $stat_return_code === 0 ? "GIT_SSH_COMMAND='ssh -i ~/.ssh/id_github' " : "";

// Run the command.
chdir( $this->work_tree );
exec( "$safe_path $git_dir $work_tree $safe_cmd $safe_args 2>&1", $output, $return_code );
exec( "$ssh_key$safe_path $git_dir $work_tree $safe_cmd $safe_args 2>&1", $output, $return_code );
chdir( $this->current_dir );

// Process the response.
Expand Down Expand Up @@ -355,6 +359,13 @@ public function count_unpushed( $ajax_btn = true ) {
*/
public function count_untracked() {
$untracked = $this->run( 'status', array( '--short', '--untracked-files=all' ) );

foreach ( $untracked as $k => $v ) {
if ( stripos( $v, 'warning: ' ) === 0 ) {
unset( $untracked[$k] );
}
}

return count( $untracked );
}

Expand Down Expand Up @@ -622,7 +633,7 @@ public function merge( $branch ) {
* @param array $commits The commits we're pulling (used in callback).
*/
public function pull( $commits = array() ) {
$this->reset();
//$this->reset();
$pull = $this->run( 'pull', array( '-Xtheirs', '--quiet', $this->remote, $this->branch ), __FUNCTION__, $commits );
return $pull;
}
Expand Down
90 changes: 81 additions & 9 deletions classes/class-revisr-meta-boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ class Revisr_Meta_Boxes {
*/
public function add_meta_box_actions() {

do_action( 'add_meta_boxes_admin_page_revisr_new_commit', null );
do_action( 'add_meta_boxes', 'admin_page_revisr_new_commit', null );
do_action( 'add_meta_boxes_admin_page_revisr_view_commit', null );
do_action( 'add_meta_boxes', 'admin_page_revisr_view_commit', null );
$no_post = new stdClass();
$no_post->ID = 0;

do_action( 'add_meta_boxes_admin_page_revisr_new_commit', $no_post );
do_action( 'add_meta_boxes', 'admin_page_revisr_new_commit', $no_post );
do_action( 'add_meta_boxes_admin_page_revisr_view_commit', $no_post );
do_action( 'add_meta_boxes', 'admin_page_revisr_view_commit', $no_post );

wp_enqueue_script( 'postbox' );

Expand Down Expand Up @@ -61,23 +64,54 @@ public function pending_files() {
check_ajax_referer( 'staging_nonce', 'security' );
$output = revisr()->git->status();
$total_pending = count( $output );
$text = sprintf( __( 'There are <strong>%s</strong> untracked files that can be added to this commit.', 'revisr' ), $total_pending, revisr()->git->branch );
$commit_items = array(); // Categorize the changed files into categories for automated commit message creation
$unstaged = array(); // Store changes that do not match wp-content/plugins/plugin-name/ or wp-content/plugins/plugin-name.php
$warnings = array();
$text = sprintf( __( 'There are <strong>%s</strong> untracked files that can be added to this commit.', 'revisr' ), $total_pending, revisr()->git->branch );
echo "<br>" . $text . "<br><br>";
_e( 'Use the boxes below to select the files to include in this commit. Only files in the "Staged Files" section will be included.<br>Double-click files marked as "Modified" to view the changes to the file.<br><br>', 'revisr' );
if ( is_array( $output ) ) {
?>
<!-- Staging -->
<div class="stage-container">
<p><strong><?php _e( 'Staged Files', 'revisr' ); ?></strong></p>
<select id='staged' multiple="multiple" name="staged_files[]" size="6">
<select id='staged' multiple="multiple" name="staged_files[]" size="15" style="resize: vertical;">
<?php
// Clean up output from git status and echo the results.
foreach ( $output as $result ) {

if ( stripos( $result, 'warning: ' ) !== false ) {
$warnings[] = $result;
continue;
}

$result = str_replace( '"', '', $result );
$short_status = substr( $result, 0, 3 );
$file = substr( $result, 3 );
$status = Revisr_Git::get_status( $short_status );
echo "<option class='pending' value='{$result}'>{$file} [{$status}]</option>";
$status = Revisr_Git::get_status( $short_status );
$item = "<option class='pending' value='{$result}'>{$file} [{$status}]</option>";

if ( preg_match('/wp-content\/plugins\/((.*?)\/|(.*?)\.php)/', $file, $match) ) { // Match plugin name, example : wp-content/plugins/plugin-name/ or wp-content/plugins/plugin-name.php
$plugin_matched = !empty($match[2]) ? $match[2] : $match[3];

if( $status == 'Untracked' && isset($commit_items['Modified']) ) { // New file or folder created in existing plugin is not added to commit_items if plugin name is in modified
if(in_array($plugin_matched, $commit_items['Modified'])) {
echo $item;
continue;
}
}

if( !isset($commit_items[$status]) ) { // No status yet
$commit_items[$status][] = $plugin_matched;
} else if( !in_array($plugin_matched, $commit_items[$status]) ) { // Prevent duplicates
$commit_items[$status][] = $plugin_matched;
}

echo $item;
} else { // No plugin matched, move to unstaged
$unstaged[] = $item;
}

}
?>
</select>
Expand All @@ -92,7 +126,15 @@ public function pending_files() {
<!-- Unstaging -->
<div class="stage-container">
<p><strong><?php _e( 'Unstaged Files', 'revisr' ); ?></strong></p>
<select id="unstaged" multiple="multiple" name="unstaged_files[]" size="6">
<select id="unstaged" multiple="multiple" name="unstaged_files[]" size="15" style="resize: vertical;">
<?php
// Echo all files that are in unstaged array
if( !empty($unstaged) ) {
foreach( $unstaged as $option ) {
echo $option;
}
}
?>
</select>
<div class="stage-nav">
<input id="stage-file" type="button" class="button button-primary stage-nav-button" value="<?php _e( 'Stage Selected', 'revisr' ); ?>" onclick="stage_file()" />
Expand All @@ -101,6 +143,36 @@ public function pending_files() {
</div>
</div><!-- /Unstaging -->

<?php
// Improve commit message
$commit_msg = "";
foreach( $commit_items as $status => $plugins ) {
switch($status) {
case 'Modified':
$commit_msg .=" Plugin updates";
break;
case 'Untracked':
$commit_msg .=" New plugins";
break;
case 'Deleted':
$commit_msg .=" Deleted plugins";
break;
default:
$commit_msg .=" " . $status;
}
$commit_msg .= " - " . implode(", ", $plugins); // Build commit message from plugin names and statuses
}
$commit_msg = trim($commit_msg);
?>

<!-- New input for commit msg -->
<input type="text" name="post_title" size="30" value="<?php echo $commit_msg; ?>" id="title-tmp" spellcheck="true" autocomplete="off" placeholder="Enter a message for your commit">

<?php if ( ! empty( $warnings ) ) : ?>
<p><strong><?php _e( 'Warnings:', 'revisr' ); ?></strong></p>
<?php echo implode( '<br />', $warnings ); ?>
<?php endif; ?>

<?php
}
exit();
Expand Down
18 changes: 9 additions & 9 deletions classes/class-revisr-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,18 @@ public function pull() {
Revisr_Admin::verify_nonce( $_REQUEST['revisr_dashboard_nonce'], 'revisr_dashboard_nonce' );

// Fetch the changes so we can compare them.
revisr()->git->reset();
//revisr()->git->reset();
revisr()->git->fetch();

// Build an array of the commits we don't have locally.
$commits_since = revisr()->git->run( 'log', array( revisr()->git->branch . '..' . revisr()->git->remote . '/' . revisr()->git->branch, '--pretty=oneline' ) );

// Maybe backup database.
if ( revisr()->git->get_config( 'revisr', 'import-pulls' ) === 'true' ) {
revisr()->db->backup();
$undo_hash = revisr()->git->current_commit();
revisr()->git->set_config( 'revisr', 'last-db-backup', $undo_hash );
}
// if ( revisr()->git->get_config( 'revisr', 'import-pulls' ) === 'true' ) {
// revisr()->db->backup();
// $undo_hash = revisr()->git->current_commit();
// revisr()->git->set_config( 'revisr', 'last-db-backup', $undo_hash );
// }

// Fires before the changes are pulled.
do_action( 'revisr_pre_pull', $commits_since );
Expand Down Expand Up @@ -352,9 +352,9 @@ public function view_diff() {
Revisr_Admin::verify_nonce( $_GET['security'], 'staging_nonce' );

if ( isset( $_REQUEST['commit'] ) ) {
$diff = revisr()->git->run( 'show', array( $_REQUEST['commit'], $_REQUEST['file'] ) );
$diff = revisr()->git->run( 'show', array( $_REQUEST['commit'], '--ignore-all-space', $_REQUEST['file'] ) );
} else {
$diff = revisr()->git->run( 'diff', array( $_REQUEST['file'] ) );
$diff = revisr()->git->run( 'diff', array( '--ignore-all-space', $_REQUEST['file'] ) );
}

if ( is_array( $diff ) ) {
Expand Down
9 changes: 9 additions & 0 deletions classes/class-revisr-settings-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ public function remote_url_callback() {
$remote,
__( 'Useful if you need to authenticate over "https://" instead of SSH, or if the remote has not already been set through Git.', 'revisr' )
);

if( stripos($remote,'git@') === 0 ) {
exec( "stat ~/.ssh/id_github", $stat_output, $stat_return_code );
if( $stat_return_code === 0 ) {
echo 'Found the SSH key in ~/.ssh/id_github';
} else {
echo '<div class="error">Error: SSH key for Github in ~/.ssh/id_github not found!</a>';
}
}
}

/**
Expand Down
8 changes: 4 additions & 4 deletions revisr.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*
* Plugin Name: Revisr
* Plugin URI: https://revisr.io/
* Description: A plugin that allows users to manage WordPress websites with Git repositories.
* Version: 2.0.2
* Description: A plugin that allows users to manage WordPress websites with Git repositories. FV: Removing the db backup from pull function and improving the admin UI a bit
* Version: 100.2.0.2.fv
* Author: Expanded Fronts, LLC
* Author URI: http://expandedfronts.com/
* License: GPL-3.0+
Expand Down Expand Up @@ -110,7 +110,7 @@ private function __clone() {
* Prevent direct unserialization by making the method private.
* @access private
*/
private function __wakeup() {
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'revisr' ), '1.8' );
}

Expand Down Expand Up @@ -228,7 +228,7 @@ private function define_constants() {
define( 'REVISR_URL', plugin_dir_url( REVISR_FILE ) );

// The current version of the plugin.
define( 'REVISR_VERSION', '2.0.2' );
define( 'REVISR_VERSION', '2.0.3' );
}

/**
Expand Down