Skip to content

Commit 52d5543

Browse files
authored
Merge pull request #3139 from idodeclare/bugfix/user_intent
Fix #3078 : record user intent for projects
2 parents 14bbb99 + 72b8f04 commit 52d5543

File tree

6 files changed

+38
-23
lines changed

6 files changed

+38
-23
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/web/PageConfig.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -925,10 +925,6 @@ protected SortedSet<String> getRequestedProjects(
925925
TreeSet<String> projectNames = new TreeSet<>();
926926
List<Project> projects = getEnv().getProjectList();
927927

928-
if (projects == null) {
929-
return projectNames;
930-
}
931-
932928
if (Boolean.parseBoolean(req.getParameter(searchAllParamName))) {
933929
return getProjectHelper()
934930
.getAllProjects()
@@ -975,7 +971,7 @@ protected SortedSet<String> getRequestedProjects(
975971
}
976972

977973
// Add projects based on cookie.
978-
if (projectNames.isEmpty()) {
974+
if (projectNames.isEmpty() && getIntParam(QueryParameters.NUM_SELECTED_PARAM, -1) != 0) {
979975
List<String> cookies = getCookieVals(cookieName);
980976
for (String s : cookies) {
981977
Project x = Project.getByName(s);

opengrok-indexer/src/main/java/org/opengrok/indexer/web/QueryParameters.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ public class QueryParameters {
124124
*/
125125
public static final String NO_REDIRECT_PARAM = "xrd";
126126

127+
/**
128+
* Parameter name to specify a count of projects selected by the user
129+
* through browser interaction.
130+
*/
131+
public static final String NUM_SELECTED_PARAM = "nn";
132+
127133
/**
128134
* Parameter name to specify an OpenGrok search of paths.
129135
*/

opengrok-indexer/src/main/java/org/opengrok/indexer/web/Scripts.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ public String toHtml() {
110110
putjs("jquery-ui", "js/jquery-ui-1.12.1-custom", 11);
111111
putjs("jquery-tablesorter", "js/jquery-tablesorter-2.26.6", 12);
112112
putjs("tablesorter-parsers", "js/tablesorter-parsers-0.0.2", 13, true);
113-
putjs("searchable-option-list", "js/searchable-option-list-2.0.12", 14);
114-
putjs("utils", "js/utils-0.0.34", 15, true);
113+
putjs("searchable-option-list", "js/searchable-option-list-2.0.13", 14);
114+
putjs("utils", "js/utils-0.0.35", 15, true);
115115
putjs("repos", "js/repos-0.0.2", 20, true);
116116
putjs("diff", "js/diff-0.0.4", 20, true);
117117
putjs("jquery-caret", "js/jquery.caret-1.5.2", 25);

opengrok-web/src/main/webapp/js/searchable-option-list-2.0.12.js renamed to opengrok-web/src/main/webapp/js/searchable-option-list-2.0.13.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,9 @@
10451045

10461046
_addSelectionDisplayItem: function ($changedItem) {
10471047
this.numSelected = 1 + this.numSelected;
1048+
if (this.config.numSelectedItem) {
1049+
this.config.numSelectedItem.val(this.numSelected);
1050+
}
10481051

10491052
if (this.config.maxShow !== 0 && this.numSelected > this.config.maxShow) {
10501053
if (this.valMap == null) {
@@ -1057,6 +1060,7 @@
10571060

10581061
_buildSelectionDisplayItem: function ($changedItem) {
10591062
var solOptionItem = $changedItem.data('sol-item'),
1063+
self = this,
10601064
$existingDisplayItem,
10611065
$displayItemText;
10621066

@@ -1093,9 +1097,14 @@
10931097
/*
10941098
* Modified for OpenGrok in 2017.
10951099
*/
1096-
if (isOnSearchPage()) {
1097-
$('#xrd').val("1"); // no redirect
1098-
$('#sbox').submit();
1100+
if (self.config.quickDeleteForm) {
1101+
if (self.config.quickDeletePermit) {
1102+
if (self.config.quickDeletePermit()) {
1103+
self.config.quickDeleteForm.submit();
1104+
}
1105+
} else {
1106+
self.config.quickDeleteForm.submit();
1107+
}
10991108
}
11001109
})
11011110
.prependTo($existingDisplayItem);
@@ -1110,6 +1119,9 @@
11101119

11111120
var wasExceeding = this.config.maxShow !== 0 && this.numSelected > this.config.maxShow;
11121121
this.numSelected = this.numSelected - 1;
1122+
if (this.config.numSelectedItem) {
1123+
this.config.numSelectedItem.val(this.numSelected);
1124+
}
11131125

11141126
if ($myDisplayItem) {
11151127
$myDisplayItem.remove();
@@ -1294,7 +1306,7 @@
12941306
.prop('checked', false)
12951307
.trigger('change', true);
12961308

1297-
this.options.closeOnClick && this.close();
1309+
this.config.closeOnClick && this.close();
12981310

12991311
if ($.isFunction(this.config.events.onChange)) {
13001312
this.config.events.onChange.call(this, this, $changedInputs);

opengrok-web/src/main/webapp/js/utils-0.0.34.js renamed to opengrok-web/src/main/webapp/js/utils-0.0.35.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,9 @@ function init_searchable_option_list() {
13661366
showSelectAll: false,
13671367
maxShow: 30,
13681368
resultsContainer: $("#ltbl"),
1369+
numSelectedItem: $("#nn"),
1370+
quickDeleteForm: $("#sbox"),
1371+
quickDeletePermit: checkIsOnSearchPage,
13691372
texts: {
13701373
searchplaceholder: 'Click here to select project(s)'
13711374
},
@@ -2237,6 +2240,14 @@ function isOnSearchPage() {
22372240
return $(document.documentElement).hasClass('search');
22382241
}
22392242

2243+
function checkIsOnSearchPage() {
2244+
if (isOnSearchPage()) {
2245+
$('#xrd').val("1"); // no redirect
2246+
return true;
2247+
}
2248+
return false;
2249+
}
2250+
22402251
/**
22412252
* Preprocess the searched projects in the form with:
22422253
*

opengrok-web/src/main/webapp/menu.jspf

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
2525
java.util.Map,
2626
java.util.Set,
2727
java.util.SortedSet,
28-
java.util.TreeMap,
2928
java.util.TreeSet,
3029

3130
org.opengrok.indexer.configuration.Group,
@@ -45,25 +44,14 @@ org.opengrok.indexer.web.messages.MessagesUtils"
4544
ProjectHelper ph = ProjectHelper.getInstance(cfg);
4645
String messages;
4746
Set<Project> projects = ph.getAllProjects();
48-
if (projects == null) {
49-
projects = new TreeSet<>();
50-
}
5147
int projectsSize = ph.getAllUngrouped().size();
5248
if (ph.getGroups().size() > 0 && ph.getAllUngrouped().size() > 0)
5349
projectsSize++;
5450
for (Group group : ph.getGroups()) {
5551
projectsSize++;
5652
projectsSize += ph.getAllGrouped(group).size();
5753
}
58-
TreeMap<String, String> pMap = new TreeMap<>();
5954
QueryBuilder queryParams = cfg.getQueryBuilder();
60-
if (projects.size() != 0) {
61-
for (Project p : projects) {
62-
String name = p.getName();
63-
String esc = Util.formQuoteEscape(p.getName());
64-
pMap.put(name, esc);
65-
}
66-
}
6755
%>
6856
<script type="text/javascript">/* <![CDATA[ */
6957
document.domReady.push(function() { domReadyMenu(); });
@@ -241,6 +229,8 @@ document.domReady.push(function() { domReadyMenu(); });
241229
</div>
242230
<input type="hidden" id="<%= QueryParameters.NO_REDIRECT_PARAM %>"
243231
name="<%= QueryParameters.NO_REDIRECT_PARAM %>" value=""/>
232+
<input type="hidden" id="<%= QueryParameters.NUM_SELECTED_PARAM %>"
233+
name="<%= QueryParameters.NUM_SELECTED_PARAM %>" value=""/>
244234
</form>
245235
<div class="clearfix"></div>
246236
<%

0 commit comments

Comments
 (0)