SOLR-5456: Admin UI - Allow creating new Files

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1542967 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stefan Matheis 2013-11-18 10:30:54 +00:00
parent c13e4aaa38
commit bdbf771ef8
4 changed files with 219 additions and 87 deletions

View File

@ -89,6 +89,8 @@ New Features
* SOLR-5446: Admin UI - Allow changing Schema and Config (steffkes)
* SOLR-5456: Admin UI - Allow creating new Files (steffkes)
Bug Fixes
----------------------

View File

@ -17,15 +17,47 @@ limitations under the License.
*/
#content #files #tree
#content #files #tree-holder
{
float: left;
width: 20%;
}
#content #files .show #tree
#content #files #new-file-holder
{
overflow: hidden;
margin-top: 20px;
padding-bottom: 10px;
}
#content #files #new-file-holder button span
{
background-image: url( ../../img/ico/plus-button.png );
}
#content #files #new-file-holder form
{
box-shadow: 5px 5px 10px #c0c0c0;
-moz-box-shadow: 5px 5px 10px #c0c0c0;
-webkit-box-shadow: 5px 5px 10px #c0c0c0;
display: none;
padding: 10px;
}
#content #files #new-file-holder form input
{
margin-bottom: 3px;
width: 98%;
}
#content #files #new-file-holder .note
{
color: #c0c0c0;
margin-bottom: 5px;
}
#content #files form .buttons button
{
float: right;
}
#content #files #file-content
@ -42,31 +74,15 @@ limitations under the License.
display: block;
}
#content #files #file-content .close
{
background-image: url( ../../img/ico/cross-0.png );
background-position: 50% 50%;
display: block;
height: 20px;
position: absolute;
right: 0;
top: 0;
width: 20px;
}
#content #files #file-content .close:hover
{
background-image: url( ../../img/ico/cross-1.png );
}
#content #files #file-content .close span
#content #files #new-file-note
{
background-color: #ffa662;
background-image: url( ../../img/ico/exclamation-button.png );
background-position: 10px 50%;
display: none;
}
#content #files #file-content form .buttons button
{
float: right;
margin-bottom: 10px;
padding: 10px;
padding-left: 31px;
}
#content #files #file-content textarea

View File

@ -27,6 +27,7 @@ sammy.get
var content_element = $( '#content' );
var file_endpoint = core_basepath + '/admin/file';
var file_exists = null;
var path = context.path.split( '?' );
var selected_file = null;
@ -70,74 +71,118 @@ sammy.get
}
};
$( '#tree', frame_element )
.jstree
(
{
plugins : [ 'json_data', 'sort' ],
json_data : {
ajax: {
url : file_endpoint + '?wt=json',
data : function( n )
{
if( -1 === n )
return null;
return {
file : n.attr( 'data-file' )
};
},
success : function( response, status, xhr )
{
var files = [];
for( var file in response.files )
var load_tree = function()
{
$( '#tree', frame_element )
.empty()
.jstree
(
{
plugins : [ 'json_data', 'sort' ],
json_data : {
ajax: {
url : file_endpoint + '?wt=json',
data : function( n )
{
var is_directory = response.files[file].directory;
var prefix = xhr.data ? xhr.data.file + '/' : ''
if( -1 === n )
return null;
var item = {
data: {
title : file,
attr : {
href : '#/' + current_core + '/files?file=' + prefix + file
}
},
attr : {
'data-file' : prefix + file
}
return {
file : n.attr( 'data-file' )
};
},
success : function( response, status, xhr )
{
var files = [];
if( is_directory )
for( var file in response.files )
{
item.state = 'closed';
item.data.attr.href += '/';
var is_directory = response.files[file].directory;
var prefix = xhr.data ? xhr.data.file + '/' : ''
var item = {
data: {
title : file,
attr : {
href : '#/' + current_core + '/files?file=' + prefix + file
}
},
attr : {
'data-file' : prefix + file
}
};
if( is_directory )
{
item.state = 'closed';
item.data.attr.href += '/';
}
files.push( item );
}
files.push( item );
return files;
}
return files;
}
},
progressive_render : true
},
progressive_render : true
},
core : {
animation : 0
core : {
animation : 0
}
}
)
.on
(
'loaded.jstree',
tree_callback
)
.on
(
'open_node.jstree',
tree_callback
);
};
load_tree();
var new_file_form = $( '#new-file-holder form' );
$( '#new-file-holder > button' )
.on
(
'click',
function( event )
{
new_file_form.toggle();
return false;
}
)
.on
(
'loaded.jstree',
tree_callback
)
.on
(
'open_node.jstree',
tree_callback
);
new_file_form
.on
(
'submit',
function( event )
{
$( 'body' )
.animate( { scrollTop: 0 }, 500 );
window.location.href = '#/' + current_core + '/files?file=' + $( 'input', this ).val();
return false;
}
);
if( selected_file )
{
$( '#new-file-holder input' )
.val
(
'/' !== selected_file.substr( -1 )
? selected_file.replace( /[^\/]+$/, '' )
: selected_file
);
}
if( selected_file && '/' !== selected_file.substr( -1 ) )
{
frame_element
@ -173,6 +218,8 @@ sammy.get
button
.addClass( 'success' );
load_file( !file_exists );
window.setTimeout
(
function()
@ -186,10 +233,53 @@ sammy.get
}
);
var load_file = function()
var change_button_label = function( form, label )
{
$( 'form textarea', frame_element )
.load( endpoint );
$( 'span[data-' + label + ']', form )
.each
(
function( index, element )
{
var self = $( this );
self.text( self.data( label ) );
}
);
}
var load_file = function( load_tree )
{
if( load_tree )
{
load_tree();
}
$.ajax
(
{
url : endpoint,
context : $( 'form', frame_element ),
beforeSend : function( xhr, settings )
{
},
success : function( response, text_status, xhr )
{
change_button_label( this, 'existing-title' );
$( 'textarea', this )
.val( xhr.responseText );
},
error : function( xhr, text_status, error_thrown)
{
change_button_label( this, 'new-title' );
},
complete : function( xhr, text_status )
{
file_exists = 200 === xhr.status;
$( '#new-file-note' )
.toggle( !file_exists );
}
}
);
}
load_file();
@ -226,7 +316,7 @@ sammy.get
button
.addClass( 'success' );
load_file();
load_file( !file_exists );
$( 'body' )
.animate( { scrollTop: 0 }, 500 );

View File

@ -18,11 +18,35 @@ limitations under the License.
<div id="frame">
<div id="tree" class="tree">#tree</div>
<div id="tree-holder">
<div id="tree" class="tree">#tree</div>
<div id="new-file-holder">
<button><span>Create new file</span></button>
<form method="get">
<p class="note">Enter filename, on the next page you can input content or upload a file.</p>
<input type="text" name="file" placeholder="sample.xml">
<div class="buttons clearfix">
<button type="submit">Next </button>
</div>
</form>
</div>
</div>
<div id="file-content" class="clearfix">
<a id="url" class="address-bar" href="#"></a>
<p id="new-file-note">The requested file does (not yet) exist. <strong>Save file</strong> or <strong>Upload new file</strong> will create it.</p>
<form method="post" class="modify">
<textarea name="stream.body"></textarea>
@ -38,7 +62,7 @@ limitations under the License.
<input type="file" name="fileupload">
<div class="buttons clearfix">
<button><span>Replace current file</span></button>
<button><span data-new-title="Upload new file" data-existing-title="Replace current file">Replace current file</span></button>
</div>
</form>