Removed debug code, Updated contribution guidelines, Updated autosave to remove polling, Fixed renaming projects issue, Added rescans to some file manager functions, Added setting that keeps track of projects side panel being open or closed.

This commit is contained in:
xevidos 2019-02-06 17:52:49 -05:00
parent 5ae4c4c0d9
commit a0105544c0
7 changed files with 100 additions and 30 deletions

View File

@ -14,13 +14,12 @@ Stick to the conventions defined in other components as closely as possible.
* Utilize the same commenting structure
* Use underscores in namespaces instead of interCaps
* Use intend with 4 spaces in your code
* Use single quotes for parameternames and double quotes for strings
* Use intend with a tab character in your code
* When working with the editor utilize the `active` object whenever possible instead of going direct to the `editor`
**Javascript Formatting**
In order to maintain a consistant code structure to the code across the application please follow the wordpress standard, or run any changes through JSBeautifier (http://jsbeautifier.org/) with the settings below.
In order to maintain a consistant code structure to the code across the application please follow the wordpress standard, or run any changes through [JSBeautifier] (http://jsbeautifier.org/) with the settings below.
{
"indent_size": "1",
@ -45,4 +44,4 @@ If you have questions, please ask. Submit an issue or [contact us directly](mail
**PHP Formatting**
In order to maintain a consistant code structure we follow PSR2 standards.
In order to maintain a consistant code structure we follow WordPress standards.

View File

@ -33,6 +33,8 @@
// Allows relative `this.path` linkage
auto_save_trigger: null,
content: null,
editor: null,
invalid_states: [ "", " ", null, undefined ],
path: curpath,
saving: false,
@ -44,7 +46,8 @@
init: async function() {
codiad.auto_save.settings.autosave = await codiad.settings.get_option( 'codiad.settings.autosave' );
let _this = codiad.auto_save;
_this.settings.autosave = await codiad.settings.get_option( 'codiad.settings.autosave' );
// Check if the auto save setting is true or false
// Also check to see if the editor is any of the invalid states
@ -83,7 +86,35 @@
console.log( 'Auto save Enabled' );
}
this.auto_save_trigger = setInterval( this.auto_save, 256 );
let content = codiad.editor.getContent();
if( ! codiad.active.getPath() == null && ! codiad.auto_save.invalid_states.includes( content ) ) {
this.content = content;
}
/* Subscribe to know when a file is being closed. */
amplify.subscribe( 'active.onClose', function( path ) {
let _this = codiad.auto_save;
_this.editor.removeEventListener( "change", _this.change );
});
/* Subscribe to know when a file become active. */
amplify.subscribe( 'active.onFocus', function( path ) {
let _this = codiad.auto_save;
if( ! _this.editor == null && path == _this.editor.getSession().path ) {
return;
}
_this.editor = codiad.editor.getActive();
_this.content = codiad.editor.getContent();
_this.editor.addEventListener( "change", _this.auto_save );
});
},
/**
@ -95,34 +126,61 @@
auto_save: function() {
if( this.settings.toggle == false || this.settings.autosave == false || codiad.auto_save.invalid_states.includes( codiad.editor.getContent() ) ) {
return;
}
this.saving = true;
if ( codiad.active.getPath() == null ) {
this.saving = false;
return;
}
let _this = codiad.auto_save;
_this.saving = true;
let tabs = document.getElementsByClassName( "tab-item" );
let path = codiad.active.getPath();
let content = codiad.editor.getContent();
if( _this.settings.toggle == false || _this.settings.autosave == false || codiad.auto_save.invalid_states.includes( content ) ) {
_this.saving = false;
return;
}
if( path == null ) {
_this.saving = false;
return;
}
if( _this.verbose ) {
console.log( content, _this.content );
}
if( content == _this.content ) {
var session = codiad.active.sessions[path];
if( typeof session != 'undefined' ) {
session.untainted = content;
session.serverMTime = session.serverMTime;
if ( session.listThumb ) {
session.listThumb.removeClass('changed');
}
if ( session.tabThumb ) {
session.tabThumb.removeClass('changed');
}
}
return;
}
/*
this code caused issues even though it is the proper way to save something.
_this code caused issues even though it is the proper way to save something.
Whenever in collaboration, the server constantly gave a wrong file version error.
let path = codiad.active.getPath();
codiad.active.save( path, false );
this.saving = false;
_this.saving = false;
*/
_this.content = content;
codiad.active.save;
codiad.filemanager.saveFile( path, content, localStorage.removeItem( path ), false );
var session = codiad.active.sessions[path];
@ -140,7 +198,7 @@
session.tabThumb.removeClass('changed');
}
}
this.saving = false;
_this.saving = false;
},
reload_interval: async function() {

View File

@ -562,6 +562,9 @@
if(type == 'file') {
codiad.filemanager.openFile(createPath, true);
}
codiad.filemanager.rescan( path );
/* Notify listeners. */
amplify.publish('filemanager.onCreate', {createPath: createPath, path: path, shortName: shortName, type: type});
}
@ -608,6 +611,8 @@
} else { // No conflicts; proceed...
_this.processPasteNode(path,false);
}
codiad.filemanager.rescan( path );
}
},
@ -672,7 +677,7 @@
// Change any active files
codiad.active.rename(path, newPath);
codiad.modal.unload();
codiad.filemanager.rescan( parentPath );
/* Notify listeners. */
amplify.publish('filemanager.onRename', {path: path, newPath: newPath, parentPath: parentPath });
}

View File

@ -269,6 +269,7 @@ class Project extends Common {
$query = "SELECT * FROM projects WHERE name=? AND path=? AND ( owner=? OR owner='nobody' );";
$bind_variables = array( $old_name, $path, $_SESSION["user"] );
$return = $sql->query( $query, $bind_variables, array() );
$pass = false;
if( ! empty( $return ) ) {
@ -279,14 +280,17 @@ class Project extends Common {
if( $return > 0 ) {
echo( formatJSEND( "success", "Renamed " . htmlentities( $old_name ) . " to " . htmlentities( $new_name ) ) );
$pass = true;
} else {
echo( formatJSEND( "error", "Error renaming project." ) );
exit( formatJSEND( "error", "Error renaming project." ) );
}
} else {
echo( formatJSEND( "error", "Error renaming project, could not find specified project." ) );
}
return $pass;
}
//////////////////////////////////////////////////////////////////
@ -469,13 +473,11 @@ class Project extends Common {
$revised_array[] = array( "name" => $data['name'], "path" => $data['path'] );
} else {
$this->rename_project( $data['name'], $_GET['project_name'], $data['path'] );
$rename = $this->rename_project( $data['name'], $_GET['project_name'], $data['path'] );
}
}
$revised_array[] = $this->projects[] = array( "name" => $_GET['project_name'], "path" => $this->path );
// Response
echo formatJSEND("success", null);
}
//////////////////////////////////////////////////////////////////

View File

@ -275,8 +275,13 @@
//////////////////////////////////////////////////////////////////
loadSide: async function() {
this._sideExpanded = ( await codiad.settings.get_option( "codiad.projects.SideExpaned" ) == "true" );
$( '.sb-projects-content' ).load( this.dialog + '?action=sidelist&trigger='+ await codiad.settings.get_option( 'codiad.editor.fileManagerTrigger' ) );
this._sideExpanded = true;
if ( ! this._sideExpanded ) {
this.projectsCollapse();
}
},
//////////////////////////////////////////////////////////////////
@ -318,6 +323,7 @@
projectsExpand: function() {
this._sideExpanded = true;
codiad.settings.update_option( 'codiad.projects.SideExpaned', this._sideExpanded );
$( '#side-projects' ).css( 'height', 276 + 'px' );
$( '.project-list-title' ).css( 'right', 0 );
$( '.sb-left-content' ).css( 'bottom', 276 + 'px' );
@ -329,6 +335,7 @@
projectsCollapse: function() {
this._sideExpanded = false;
codiad.settings.update_option( 'codiad.projects.SideExpaned', this._sideExpanded );
$( '#side-projects' ).css( 'height', 33 + 'px' );
$( '.project-list-title' ).css( 'right', 0 );
$( '.sb-left-content' ).css( 'bottom', 33 + 'px' );

View File

@ -63,7 +63,7 @@
</div>
</div>
</div>
<button class="btn-right" onclick="save(); return false;"><?php i18n("Save"); ?></button>
<button class="btn-left" onclick="save(); return false;"><?php i18n("Save"); ?></button>
<button class="btn-right" onclick="codiad.modal.unload(); return false;"><?php i18n("Close"); ?></button>
<div class="loading"></div>
<script>

View File

@ -23,7 +23,6 @@
var sbWidth = await codiad.settings.get_option( 'codiad.sidebars.sb-left-width' );
var lock_left = await codiad.settings.get_option( 'codiad.sidebars.lock-left-sidebar' );
var lock_right = await codiad.settings.get_option( 'codiad.sidebars.lock-right-sidebar' );
console.log( "Sidebar width", sbWidth );
if (sbWidth !== null) {
$('#sb-left').width(sbWidth);
$(window).resize();