From 7092d9a0220d54ece6217d4f65a8063f7f93c520 Mon Sep 17 00:00:00 2001 From: Erick Erickson Date: Sat, 4 Apr 2015 17:14:59 +0000 Subject: [PATCH] SOLR-7263: Add files tab support to AngularJS Admin UI git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1671281 13f79535-47bb-0310-9956-ffa450edef68 --- partials/files.html | 47 +++++++++++ solr/webapp/web/css/angular/files.css | 53 ++++++++++++ solr/webapp/web/index.html | 3 +- solr/webapp/web/js/angular/app.js | 16 +++- .../web/js/angular/controllers/files.js | 82 +++++++++++++++++++ solr/webapp/web/js/angular/services.js | 7 +- 6 files changed, 202 insertions(+), 6 deletions(-) create mode 100644 partials/files.html create mode 100644 solr/webapp/web/css/angular/files.css create mode 100644 solr/webapp/web/js/angular/controllers/files.js diff --git a/partials/files.html b/partials/files.html new file mode 100644 index 00000000000..1278fbeccb3 --- /dev/null +++ b/partials/files.html @@ -0,0 +1,47 @@ + +
+ +
+ +
+ + + +
+
+ +
+ + {{url}} + +
+ +
+ +
+
+
+ + +
+ +
+ +
+ +
\ No newline at end of file diff --git a/solr/webapp/web/css/angular/files.css b/solr/webapp/web/css/angular/files.css new file mode 100644 index 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.html index 508e9e19342..b5e0a9e59e6 100644 --- a/solr/webapp/web/index.html +++ b/solr/webapp/web/index.html @@ -29,7 +29,7 @@ limitations under the License. - + @@ -64,6 +64,7 @@ limitations under the License. + diff --git a/solr/webapp/web/js/angular/app.js b/solr/webapp/web/js/angular/app.js index 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.js new file mode 100644 index 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.js index 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) {