Apache Lucene open-source search software
SOLR-5456: Admin UI - Allow creating new Files
Stefan Matheisbdbf771ef88e
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 473fffed42d..a13187ec850 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -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----------------------diff --git a/solr/webapp/web/css/styles/files.css b/solr/webapp/web/css/styles/files.cssindex 8e11588fd7d..dcd0d88f8ef 100644--- a/solr/webapp/web/css/styles/files.css+++ b/solr/webapp/web/css/styles/files.css@@ -17,56 +17,72 @@ 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 #file-content+#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;- float: right;- position: relative;- width: 78%;- min-height: 100px+ padding: 10px;}-#content #files .show #file-content+#content #files #new-file-holder form input{- display: block;+ margin-bottom: 3px;+ width: 98%;}-#content #files #file-content .close+#content #files #new-file-holder .note{- background-image: url( ../../img/ico/cross-0.png );- background-position: 50% 50%;- display: block;- height: 20px;- position: absolute;- right: 0;- top: 0;- width: 20px;+ color: #c0c0c0;+ margin-bottom: 5px;}-#content #files #file-content .close:hover+#content #files form .buttons button{- background-image: url( ../../img/ico/cross-1.png );+ float: right;}-#content #files #file-content .close span+#content #files #file-content{display: none;+ float: right;+ position: relative;+ width: 78%;+ min-height: 100px}-#content #files #file-content form .buttons button+#content #files .show #file-content{- float: right;+ display: block;+}++#content #files #new-file-note+{+ background-color: #ffa662;+ background-image: url( ../../img/ico/exclamation-button.png );+ background-position: 10px 50%;+ display: none;+ margin-bottom: 10px;+ padding: 10px;+ padding-left: 31px;}#content #files #file-content textareadiff --git a/solr/webapp/web/js/scripts/files.js b/solr/webapp/web/js/scripts/files.jsindex 02f2a945ffb..9f2ef63617d 100644--- a/solr/webapp/web/js/scripts/files.js+++ b/solr/webapp/web/js/scripts/files.js@@ -27,6 +27,7 @@ sammy.getvar 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 = [];+ var load_tree = function()+ {+ $( '#tree', frame_element )+ .empty()+ .jstree+ (+ {+ plugins : [ 'json_data', 'sort' ],+ json_data : {+ ajax: {+ url : file_endpoint + '?wt=json',+ data : function( n )+ {+ if( -1 === n )+ return null;- for( var file in response.files )+ return {+ file : n.attr( 'data-file' )+ };+ },+ success : function( response, status, xhr ){- var is_directory = response.files[file].directory;- var prefix = xhr.data ? xhr.data.file + '/' : ''+ var files = [];- var item = {- data: {- title : file,+ for( var file in response.files )+ {+ 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 : {- href : '#/' + current_core + '/files?file=' + prefix + file+ 'data-file' : prefix + file}- },- attr : {- 'data-file' : prefix + file+ };++ if( is_directory )+ {+ item.state = 'closed';+ item.data.attr.href += '/';}- };- 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(- 'loaded.jstree',- tree_callback- )+ 'click',+ function( event )+ {+ new_file_form.toggle();+ return false;+ }+ );++ new_file_form.on(- 'open_node.jstree',- tree_callback+ '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.getbutton.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 )+ {+ $( 'span[data-' + label + ']', form )+ .each+ (+ function( index, element )+ {+ var self = $( this );+ self.text( self.data( label ) );+ }+ );+ }++ var load_file = function( load_tree ){- $( 'form textarea', frame_element )- .load( endpoint );+ 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.getbutton.addClass( 'success' );- load_file();+ load_file( !file_exists );$( 'body' ).animate( { scrollTop: 0 }, 500 );diff --git a/solr/webapp/web/tpl/files.html b/solr/webapp/web/tpl/files.htmlindex 6d0f63bf50b..dba9bf0d0e8 100644--- a/solr/webapp/web/tpl/files.html+++ b/solr/webapp/web/tpl/files.html@@ -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>