Skip to content

Commit

Permalink
editor: add link to editor in brief results
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Martin Montull <javier.martin.montull@cern.ch>
  • Loading branch information
jmartinm committed Nov 10, 2016
1 parent 6ce7078 commit b0e53dc
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 5 deletions.
3 changes: 2 additions & 1 deletion inspirehep/modules/search/static/js/search/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ require([
'angular-loading-bar',
'invenio-search',
'inspirehep-search',
'inspirehep'
'inspirehep',
'inspire_results'
], function() {
// Requirements are needed in order to create the search bundle JS
});
61 changes: 61 additions & 0 deletions inspirehep/modules/search/static/js/search/inspire_results.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* This file is part of INSPIRE.
* Copyright (C) 2016 CERN.
*
* INSPIRE is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* INSPIRE is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with INSPIRE; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
* In applying this license, CERN does not
* waive the privileges and immunities granted to it by virtue of its status
* as an Intergovernmental Organization or submit itself to any jurisdiction.
*/

define(['inspire_results'], function() {
var app = angular.module('inspire_results', []);

app.controller('InspireResultsController', ['$scope', '$element', '$attrs',
function($scope, $element, $attrs) {

$scope.is_authenticated = $attrs.isAuthenticated
$scope.user_roles = $attrs.userRoles
$scope.can_view_editor = can_view_editor()
$scope.show_tools = show_tools

function show_tools() {
return [$scope.can_view_editor].some(function(value) {
return value === true;
});
}

function can_view_editor() {
if ($scope.is_authenticated) {
if
(
(-1 !== $scope.user_roles.indexOf('cataloger')) ||
(-1 !== $scope.user_roles.indexOf('superuser'))
) {
return true;
}
}
return false;
}
}]);

app.directive('inspireResultsInit', function() {
return {
restrict: 'A',
scope: true,
controller: 'InspireResultsController'
};
});
});
8 changes: 5 additions & 3 deletions inspirehep/modules/search/templates/search/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,25 @@
'angular-loading-bar',
'invenio-search',
'inspirehep-search',
'inspirehep'
'inspirehep',
'inspire_results'
], function() {
// When the DOM is ready bootstrap the AngularJS modules
angular.element(document).ready(function() {
angular.bootstrap(
document.getElementById("invenio-search"), ['angular-loading-bar',
'inspirehepSearch',
'inspirehep',
'invenioSearchAutocomplete']
'invenioSearchAutocomplete',
'inspire_results']
);
});
});
</script>
{%- endblock additional_javascript -%}

{%- block body_inner %}
<div id="invenio-search">
<div inspire-results-init is_authenticated={{current_user.is_authenticated|tojson}} user_roles={{current_user.roles|clean_roles}} id="invenio-search">
<invenio-search search-endpoint="{{ search_api }}" search-headers='{"Accept": "application/vnd+inspire.brief+json"}' search-extra-params='{"size": 25}'>
{{super()}}
</invenio-search>
Expand Down
6 changes: 6 additions & 0 deletions inspirehep/modules/theme/jinja2filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,9 @@ def back_to_search_link(referer, collection):
text = "Back to search results for \"{}\"".format(url_map['q'])
url_html = '<a href="{}">{}</a>'.format(url, text)
return url_html


@blueprint.app_template_filter()
def clean_roles(roles):
"""Extract names from user roles."""
return json.dumps([role.name for role in roles])
1 change: 1 addition & 0 deletions inspirehep/modules/theme/static/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ require.config({
'holding-pen-module': 'js/inspire_workflows_ui/holdingpen/holdingpen.module',
'holding-pen-services': 'js/inspire_workflows_ui/holdingpen/holdingpen.services',
'impact-graphs': 'node_modules/impact-graphs/impact-graph',
'inspire_results': 'js/search/inspire_results',
'inspirehep': 'node_modules/inspirehep-js/dist/inspirehep',
'inspirehep-clipboard': 'js/inspire_clipboard',
'inspirehep-search': 'node_modules/inspirehep-search-js/dist/inspirehep-search',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ article.search-result {
}

.panel-body {
position: relative;
padding: 0px 10px 0px 30px; // No padding to show separator
}

Expand Down

0 comments on commit b0e53dc

Please sign in to comment.