Skip to content

Commit

Permalink
HUE-2234 [core] Select first document or shared document tag by default
Browse files Browse the repository at this point in the history
Added logic to return the first available tag/project that has more than one document. If not available, it returns the history
  • Loading branch information
enricoberti committed Jul 23, 2014
1 parent adf679f commit ca921d5
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions desktop/core/src/desktop/templates/home.mako
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
<script type="text/javascript" charset="utf-8">
var viewModel, JSON_USERS_GROUPS;
var JSON_TAGS = ${ json_tags | n,unicode };
var JSON_DOCS = ${ json_documents | n,unicode };
function prettifyUsername(userId) {
var _user = null;
for (var i = 0; i < JSON_USERS_GROUPS.users.length; i++) {
Expand All @@ -408,7 +411,7 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
}
$(document).ready(function () {
viewModel = new HomeViewModel(${ json_tags | n,unicode }, ${ json_documents | n,unicode });
viewModel = new HomeViewModel(JSON_TAGS, JSON_DOCS);
ko.applyBindings(viewModel);
var selectedUserOrGroup, map, dropdown = null;
Expand Down Expand Up @@ -474,14 +477,34 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
$.totalStorage("hueHomeSelectedTag", value.id());
});
function getFirstAvailableDoc() {
var _found = null;
JSON_TAGS.mine.forEach(function(tag){
if (_found == null && tag.docs.length > 0){
_found = tag.id;
}
});
JSON_TAGS.notmine.forEach(function(tag){
tag.projects.forEach(function(project){
if (_found == null && project.docs.length > 0){
_found = project.id;
}
});
});
if (_found != null){
return viewModel.getTagById(_found);
}
return viewModel.history();
}
if ($.totalStorage("hueHomeSelectedTag") != null) {
var _preselectedTag = viewModel.getTagById($.totalStorage("hueHomeSelectedTag"));
if (_preselectedTag != null) {
viewModel.filterDocs(_preselectedTag);
}
}
else {
viewModel.filterDocs(viewModel.history());
viewModel.filterDocs(getFirstAvailableDoc());
}
$("#searchInput").jHueDelayedInput(function () {
Expand Down

0 comments on commit ca921d5

Please sign in to comment.