Skip to content

Commit

Permalink
fix conflicts, uncomment 'about collection' title
Browse files Browse the repository at this point in the history
  • Loading branch information
Inna-r committed May 15, 2017
2 parents 99b98a1 + 4cd7c2e commit bbe3101
Show file tree
Hide file tree
Showing 11 changed files with 1,286 additions and 61 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ docs/.tmp/**
.tmp
dist
/venv
.DS_Store
150 changes: 147 additions & 3 deletions js/modules/main/src/controllers/subHeaderController.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,162 @@
var SubHeaderController = function($state, header) {
var SubHeaderController = function($state, header, suggest, $timeout) {

this.$state = $state;
this.header = header;
this.suggest = suggest;
this.$timeout = $timeout;
this.suggested = {};

this.suggested_open = {
general: false
};

this.suggested_index = {
general: -1
};

Object.defineProperty(this, 'raw_suggested', {
get: function() {
return suggest.suggested;
}
});

Object.defineProperty(this, 'suggested_distribution', {
get: function() {
return {
general: [
suggest.suggested.general.People.length,
suggest.suggested.general.Articles.length,
suggest.suggested.general.Media.length
]
}
}
});

Object.defineProperty(this.suggested, 'general', {
get: function() {
return suggest.suggested.general.People.
concat(suggest.suggested.general.Articles.
concat(suggest.suggested.general.Media));
}
});
};

SubHeaderController.prototype = {

get_suggestions: function(type) {
var promise,
self = this;
this.suggested_index[type] = -1;

if (this.header.query) {
promise = this.suggest.suggest_general(this.header.query);

promise.
then(function() {
if (self.suggested[type].length > 0) {
self.open_suggested(type);
}
else {
self.close_suggested(type);
}
});
}
else {
this.close_suggested(type);
}
},


open_suggested: function(type) {
if (this.suggested[type].length > 0 && this.header.query) {
this.suggested_open[type] = true;
}
},

close_suggested: function(type) {
var self = this;

this.$timeout(function() {
self.suggested_open[type] = false;
}, 200);
},

isSelectedSuggested: function(type, value) {
return this.suggested[type].indexOf(value) === this.suggested_index[type];
},

get_active_title: function(type) {
if (this.suggested_index[type] >= this.suggested_distribution[type][0]) {
if (this.suggested_index[type] >= this.suggested_distribution[type][0] + this.suggested_distribution[type][1] + this.suggested_distribution[type][2]) {
return 3;
}
if (this.suggested_index[type] >= this.suggested_distribution[type] + this.suggested_distribution[type][1]) {
return 2;
}
else {
return 1;
}
}
else {
return 0;
}
},
select_suggested: function(type, collection, value) {
this.suggested_index[type] = this.suggested[type].indexOf(value);
},

adopt: function() {
this.header.query = this.suggested.general[this.suggested_index.general];
this.$state.go('general-search', {q: this.header.query});
},

handle_keyboard: function($event, type) {
var suggested_count = this.suggested[type].length;

if ( !this.suggested_open[type] ) {
return true;
}

if (suggested_count > 0) {
if($event.keyCode === 40) {
$event.preventDefault();

if (this.suggested_index[type] === suggested_count - 1) {
this.suggested_index[type] = 0;
}
else {
this.suggested_index[type] +=1 ;
}
}
else if ($event.keyCode === 38) {
$event.preventDefault();

if (this.suggested_index[type] === 0 || this.suggested_index[type] === -1) {
this.suggested_index[type] = suggested_count - 1;
}
else {
this.suggested_index[type] -=1 ;
}
}
else if ($event.keyCode === 13) {
if (this.suggested[type][ this.suggested_index[type] ]) {
$event.preventDefault();
this.adopt();
}

this.close_suggested(type);
}
}
},

search: function() {
this.$state.go('general-search', {q: this.header.query});
},

search_on_enter:function ($event) {
if ($event.keyCode === 13 && this.header.query.length > 1)
this.search();
}
};

angular.module('main').controller('SubHeaderController', ['$state', 'header', SubHeaderController]);
angular.module('main').controller('SubHeaderController', ['$state', 'header', 'suggest', '$timeout', SubHeaderController]);
90 changes: 66 additions & 24 deletions js/modules/main/src/services/suggestService.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ angular.module('main').

var collection_name_map = {
names: 'familyNames',
places: 'places'
places: 'places',
general: '*'
},

suggest = {
Expand All @@ -30,6 +31,11 @@ angular.module('main').
starts_with: [],
contains: [],
phonetic: []
},
general: {
Articles: [],
People: [],
Media: []
}
},

Expand All @@ -39,6 +45,9 @@ angular.module('main').

suggest_places: function(place) {
return get_suggestions('places', place);
},
suggest_general: function(query) {
return get_suggestions('general', query);
}
};

Expand All @@ -47,8 +56,8 @@ angular.module('main').
var count, exact, all_suggestions;
var value_lc = value.toLowerCase();

return $http.get(apiClient.urls.suggest + '/' + collection_name_map[what] + '/' + value).
success(function(response) {
return $http.get(apiClient.urls.suggest + '/' + collection_name_map[what] + '/' + value)
.success(function(response) {
suggest.suggested = {
names: {
exact: [],
Expand All @@ -61,33 +70,66 @@ angular.module('main').
starts_with: [],
contains: [],
phonetic: []
}
},
general: {}
};
exact = null;
all_suggestions = [];

['starts_with', 'contains', 'phonetic'].forEach(function(group) {
response[group].forEach(function(suggestion) {
if (suggestion.toLowerCase() === value_lc) {
exact = suggestion;
}
else {
all_suggestions = suggest.suggested[what].starts_with.
concat(suggest.suggested[what].contains.
concat(suggest.suggested[what].phonetic)
);
if (all_suggestions.indexOf(suggestion) === -1) {
suggest.suggested[what][group].push(suggestion);
if (what == 'general') {
var sections = {'Articles': [], 'People': [], 'Media': []};
for (var collection in response.starts_with) {
for(var i=0; i<response.starts_with[collection].length; i++) {
var suggestion = response.starts_with[collection][i];
// collection == "familyNames"
// suggestion == "Hoch"
if (["familyNames", "places"].indexOf(collection) > -1) {
if (sections["Articles"].indexOf(suggestion) == -1) {
sections["Articles"].push(suggestion);
}
} else if (["persons", "personalities"].indexOf(collection) > -1) {
if (sections["People"].indexOf(suggestion) == -1) {
sections["People"].push(suggestion);
}
} else if (["photoUnits", "movies"].indexOf(collection) > -1) {
if (sections["Media"].indexOf(suggestion) == -1) {
sections["Media"].push(suggestion);
}
}
}
});
});
}

if (exact) {
suggest.suggested[what].exact.push(exact);
Object.keys(sections).forEach(function(section) {
//sort and remove duplicates
sections[section] = sections[section].sort().slice(0, 6);
});
suggest.suggested[what] = sections;
}
}).
error(function() {
else {
exact = null;
all_suggestions = [];
['starts_with', 'contains', 'phonetic'].forEach(function(group) {
response[group].forEach(function(suggestion) {
if (suggestion.toLowerCase() === value_lc) {
exact = suggestion;
}
else {
all_suggestions = suggest.suggested[what].starts_with.
concat(suggest.suggested[what].contains.
concat(suggest.suggested[what].phonetic)
);

if (all_suggestions.indexOf(suggestion) === -1) {
suggest.suggested[what][group].push(suggestion);
}
}
})
});
if (exact) {
suggest.suggested[what].exact.push(exact);
}
};

})
.error(function() {
suggest.failed = true;
}).
finally(function() {
Expand Down
4 changes: 4 additions & 0 deletions scss/_placeholders.scss
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@
width: 15px;
height: 15px;
}
.search-icon {
width: 18px;
height: 18px;
}
}

%bhs-fieldset {
Expand Down
29 changes: 24 additions & 5 deletions scss/main/_item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -670,20 +670,39 @@
top: 1em;
}
p.vertical-middle {
max-width: 80%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
.he & {
margin-right: 2em;
}
.en & {
margin-left: 2em;
}
}
&:hover {
%item-type {
width: 28px;

&.search {
.en & {
padding-right: 10px;
}
.he & {
padding-left: 10px;
}
p.vertical-middle {
margin: 0;
}

.item-type {
.en & {
float: right;
}
.type-desc-container {
width: 0;
.he & {
float: left;
@include flip ();

}
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions templates/item/right_side.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@
<leaflet preview-data="itemController.item_data" id="mapid"></leaflet>
</div>

<div class="search-results">
<div class="search-results__header">
<en>All Search Results for:</en>
<he>לכל התוצאות עבור:</he>
</div>
<div class="search-results__field search"
ui-sref="general-search({q: itemController.item_data.Header.{{itemController.proper_lang}}})">
<p class="vertical-middle" ng-attr-title="{{itemController.item_data.Header[itemController.proper_lang]}}">
<en>{{itemController.item_data.Header.En}}</en>
<he>{{itemController.item_data.Header.He}}</he>
</p>
<div class="item-type">
<div class="search-icon">
<ng-include src="'templates/svgs/search_icon.svg'"></ng-include>
</div>
</div>
</div>
</div>
<div class="related" ng-show="itemController.related_data.length > 0">
<div class="related__header">
<en>Related Items:</en>
Expand Down
Loading

0 comments on commit bbe3101

Please sign in to comment.