Apache Lucene open-source search software
SOLR-7263: Add files tab support to AngularJS Admin UI
Erick Erickson7092d9a0220d
diff --git a/partials/files.html b/partials/files.htmlnew file mode 100644index 00000000000..1278fbeccb3--- /dev/null+++ b/partials/files.html@@ -0,0 +1,47 @@+<!--+Licensed to the Apache Software Foundation (ASF) under one or more+contributor license agreements. See the NOTICE file distributed with+this work for additional information regarding copyright ownership.+The ASF licenses this file to You under the Apache License, Version 2.0+(the "License"); you may not use this file except in compliance with+the License. You may obtain a copy of the License at++http://www.apache.org/licenses/LICENSE-2.0++Unless required by applicable law or agreed to in writing, software+distributed under the License is distributed on an "AS IS" BASIS,+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+See the License for the specific language governing permissions and+limitations under the License.+-->+<div id="files" class="clearfix">++ <div id="frame">++ <div id="tree-holder">++ <jstree class="tree" on-select="showTreeLink(data)" data="tree" id="tree"></jstree>++ </div>+ <div id="file-content" class="clearfix">++ <div class="top clearfix">++ <a id="url" class="address-bar" href="{{url}}" ng-show="url">{{url}}</a>++ </div>++ <div class="view-file">++ <div class="response" ng-show="content">+ <pre class="syntax language-{{lang}}"><code ng-bind-html="content | highlight:lang | unsafe"></code></pre>+ </div>+++ </div>++ </div>++ </div>++</div>\ No newline at end of filediff --git a/solr/webapp/web/css/angular/files.css b/solr/webapp/web/css/angular/files.cssnew file mode 100644index 00000000000..46b3e8c3012--- /dev/null+++ b/solr/webapp/web/css/angular/files.css@@ -0,0 +1,53 @@+/*++Licensed to the Apache Software Foundation (ASF) under one or more+contributor license agreements. See the NOTICE file distributed with+this work for additional information regarding copyright ownership.+The ASF licenses this file to You under the Apache License, Version 2.0+(the "License"); you may not use this file except in compliance with+the License. You may obtain a copy of the License at++http://www.apache.org/licenses/LICENSE-2.0++Unless required by applicable law or agreed to in writing, software+distributed under the License is distributed on an "AS IS" BASIS,+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+See the License for the specific language governing permissions and+limitations under the License.++*/++#content #files #tree-holder+{+ float: left;+ width: 20%;+}++#content #files #tree-holder li+{+ overflow: hidden;+}++#content #files form .buttons button+{+ float: right;+}++#content #files #file-content+{+ float: right;+ position: relative;+ width: 78%;+ min-height: 100px+}++#content #files .show #file-content+{+ display: block;+}++#content #files #file-content .response+{+ border: 1px solid transparent;+ padding: 2px;+}diff --git a/solr/webapp/web/index.html b/solr/webapp/web/index.htmlindex 508e9e19342..b5e0a9e59e6 100644--- a/solr/webapp/web/index.html+++ b/solr/webapp/web/index.html@@ -29,7 +29,7 @@ limitations under the License.<link rel="stylesheet" type="text/css" href="css/angular/cores.css?_=${version}"><link rel="stylesheet" type="text/css" href="css/styles/dashboard.css?_=${version}"><link rel="stylesheet" type="text/css" href="css/styles/dataimport.css?_=${version}">- <link rel="stylesheet" type="text/css" href="css/styles/files.css?_=${version}">+ <link rel="stylesheet" type="text/css" href="css/angular/files.css?_=${version}"><link rel="stylesheet" type="text/css" href="css/angular/index.css?_=${version}"><link rel="stylesheet" type="text/css" href="css/styles/java-properties.css?_=${version}"><link rel="stylesheet" type="text/css" href="css/angular/logging.css?_=${version}">@@ -64,6 +64,7 @@ limitations under the License.<script src="js/angular/controllers/core-overview.js"></script><script src="js/angular/controllers/analysis.js"></script><script src="js/angular/controllers/documents.js"></script>+ <script src="js/angular/controllers/files.js"></script><script src="js/angular/controllers/query.js"></script></head>diff --git a/solr/webapp/web/js/angular/app.js b/solr/webapp/web/js/angular/app.jsindex 4f7ce926ab9..e76febcc83d 100644--- a/solr/webapp/web/js/angular/app.js+++ b/solr/webapp/web/js/angular/app.js@@ -71,6 +71,10 @@ solrAdminApp.config([templateUrl: 'partials/documents.html',controller: 'DocumentsController'}).+ when('/:core/files', {+ templateUrl: 'partials/files.html',+ controller: 'FilesController'+ }).when('/:core/query', {templateUrl: 'partials/query.html',controller: 'QueryController'@@ -81,7 +85,7 @@ solrAdminApp.config([}]).filter('highlight', function($sce) {return function(input, lang) {- if (lang && input) return hljs.highlight(lang, input).value;+ if (lang && input && lang!="text") return hljs.highlight(lang, input).value;return input;}})@@ -129,10 +133,14 @@ solrAdminApp.config(["animation" : 0}};- var tree = $(element).jstree(treeConfig).jstree('open_node','li:first');++ var tree = $(element).jstree(treeConfig);+ tree.jstree('open_node','li:first');if (tree) {- tree.bind("select_node.jstree", function (event, data) {- scope.onSelect({url: data.args[0].href});+ element.bind("select_node.jstree", function (event, data) {+ scope.$apply(function() {+ scope.onSelect({url: data.args[0].href, data: data});+ });});}}diff --git a/solr/webapp/web/js/angular/controllers/files.js b/solr/webapp/web/js/angular/controllers/files.jsnew file mode 100644index 00000000000..2fa4020b038--- /dev/null+++ b/solr/webapp/web/js/angular/controllers/files.js@@ -0,0 +1,82 @@+/*+ Licensed to the Apache Software Foundation (ASF) under one or more+ contributor license agreements. See the NOTICE file distributed with+ this work for additional information regarding copyright ownership.+ The ASF licenses this file to You under the Apache License, Version 2.0+ (the "License"); you may not use this file except in compliance with+ the License. You may obtain a copy of the License at++ http://www.apache.org/licenses/LICENSE-2.0++ Unless required by applicable law or agreed to in writing, software+ distributed under the License is distributed on an "AS IS" BASIS,+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ See the License for the specific language governing permissions and+ limitations under the License.+*/++var contentTypeMap = { xml : 'text/xml', html : 'text/html', js : 'text/javascript', json : 'application/json', 'css' : 'text/css' };+var languages = {js: "javascript", xml:"xml", xsl:"xml", html: "xml", json: "text", css: "css"};++solrAdminApp.controller('FilesController',+ function($scope, $rootScope, $routeParams, $location, Files) {+ $scope.resetMenu("files");++ $scope.file = $location.search().file;+ $scope.content = null;++ $scope.baseurl = $location.protocol()+ "://" + $location.host() + ":" + $location.port();++ $scope.refresh = function () {++ var process = function (path, tree) {++ Files.list({core: $routeParams.core, file: path}, function (data) {+ for (var file in data.files) {+ var filedata = data.files[file];+ var state = undefined;+ var children = undefined;++ if (filedata.directory) {+ file = file + "/";+ if ($scope.file && $scope.file.indexOf(path + file) == 0) {+ state = "open";+ } else {+ state = "closed";+ }+ children = [];+ process(path + file, children);+ }+ tree.push({+ data: {+ title: file,+ attr: { id: path + file}+ },+ children: children,+ state: state+ });+ }+ });+ }+ $scope.tree = [];+ process("", $scope.tree);++ if ($scope.file && $scope.file != '' && $scope.file.split('').pop()!='/') {+ var extension = $scope.file.match( /\.(\w+)$/)[1] || '';+ var contentType = (contentTypeMap[extension] || 'text/plain' ) + ';charset=utf-8';++ Files.get({core: $routeParams.core, file: $scope.file, contentType: contentType}, function(data) {+ $scope.content = data.data;+ $scope.url = $scope.baseurl + data.config.url + "?" + $.param(data.config.params);+ $scope.lang = languages[extension] || "text";+ });+ }+ };++ $scope.showTreeLink = function(data) {+ var file = data.args[0].id;+ $location.search({file:file});+ };++ $scope.refresh();+ });diff --git a/solr/webapp/web/js/angular/services.js b/solr/webapp/web/js/angular/services.jsindex f1a94231605..3d833c16ff2 100644--- a/solr/webapp/web/js/angular/services.js+++ b/solr/webapp/web/js/angular/services.js@@ -129,7 +129,12 @@ solrAdminServices.factory('System',}]).factory('Files',['$resource', function($resource) {- return $resource('/solr/:core/admin/file', {'wt':'json', '_':Date.now()}); // @core+ return $resource('/solr/:core/admin/file', {'wt':'json', core: '@core', '_':Date.now()}, {+ "list": {},+ "get": {method: "GET", interceptor: {+ response: function(config) {return config;}+ }}+ });}]).factory('Query', // use $http for Query, as we need complete control over the URL['$http', '$location', function($http, $location) {