Skip to content

Commit

Permalink
adjust frontend to new API schemas (focusing on search results) (#432)
Browse files Browse the repository at this point in the history
* starting to adjust frontend to new API schemas (focusing on search results)
* use content_text instead of content_html, use collection instead of item_type
  • Loading branch information
OriHoch authored Jun 21, 2017
1 parent f5804dc commit 9ee6121
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 64 deletions.
6 changes: 3 additions & 3 deletions js/modules/main/src/controllers/GeneralSearchController.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ GeneralSearchController.prototype = {
this.$state.go('general-search', {params: par});
self.$http.get(self.apiClient.urls.search, {params: par})
.success(function (r) {
self.results = r.hits;
self.results = r;
self.notification.loading(false);
});
},
Expand All @@ -248,7 +248,7 @@ GeneralSearchController.prototype = {
self.notification.loading(true);
self.$http.get(self.apiClient.urls.search, {params: self.api_params()})
.success(function (r) {
self.results = r.hits;
self.results = r;
self.notification.loading(false);
});

Expand Down Expand Up @@ -363,7 +363,7 @@ GeneralSearchController.prototype = {

this.$http.get(this.apiClient.urls.search, {params: this.api_params()})
.success(function (r){
results.hits = results.hits.concat(r.hits.hits);
results.hits = results.hits.concat(r.hits);
});
},

Expand Down
31 changes: 18 additions & 13 deletions js/modules/main/src/controllers/itemPreviewCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ var ItemPreviewCtrl = function($state, $scope, $location, $rootScope, itemTypeMa
this.mjs = mjs;
this.$scope = $scope;
this.item = item;
this.item_type = itemTypeMap.get_type($scope.previewData.UnitType);
this.item_type = itemTypeMap.get_type($scope.previewData/*.UnitType*/);
// TODO: what's in_branch?
this.in_branch = $scope.previewData.in_branch;
// TODO: what's url?
this.url = $scope.previewData.url;
this.collection_name = itemTypeMap.get_collection_name($scope.previewData);
this.rmdialog_is_open = false;
Expand All @@ -23,21 +25,20 @@ ItemPreviewCtrl.prototype = {
},

get_item_url: function(item_data) {
// TODO: refactor to user item.get_url
if (this.url !== undefined) {
return this.url;
} else {
return this.item.get_url(item_data);
}
if (this.collection_name === 'genTreeIndividuals') {
var state_name = this.proper_lang=='he'?'he.he_person-view':'person-view';
return this.$state.href(state_name,
{tree_number:item_data.tree_num,
version:item_data.tree_version,
node_id: (item_data.person_id||item_data.id)
});
}
else {
return this.item.get_url(item_data);
}
// TODO: re-enable once we have persons data from CM
// if (this.collection_name === 'genTreeIndividuals') {
// var state_name = this.proper_lang=='he'?'he.he_person-view':'person-view';
// return this.$state.href(state_name,
// {tree_number:item_data.tree_num,
// version:item_data.tree_version,
// node_id: (item_data.person_id||item_data.id)
// });
// }
},

remove_from_mjs: function() {
Expand Down Expand Up @@ -69,6 +70,10 @@ ItemPreviewCtrl.prototype = {
uc_first: function() {
var lang = this.proper_lang;
return lang.charAt(0).toUpperCase() + lang.slice(1);
},

has_lang_content: function(doc) {
if (doc["content_text_"+this.proper_lang.toLowerCase()]) return true; else return false;
}

};
Expand Down
45 changes: 27 additions & 18 deletions js/modules/main/src/services/itemService.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ angular.module('main').
},

get_key: function(item_data) {
if (item_data.Slug)
return item_data.Slug.En || item_data.Slug.He;
if (item_data.params)
return JSON.stringify(item_data.params)
if (item_data.slug_en) return item_data.slug_en;
if (item_data.slug_he) return item_data.slug_he;
// TODO: figure out what params attribute contains
if (item_data.params) return JSON.stringify(item_data.params)
},

get_marker_link: function(slug) {
Expand Down Expand Up @@ -102,26 +102,35 @@ angular.module('main').
proper_lang = lang[0].toUpperCase() + lang.slice(1),
params,
state;
//get url with another language if the item's description in current is missing
if (item_data.UnitText1 && (item_data.UnitText1[proper_lang] == null || item_data.UnitText1[proper_lang] == '')) {
proper_lang == 'En' ? proper_lang = 'He' : proper_lang = 'En';
lang = proper_lang.toLowerCase();
// get url with another language if the item's description in current is missing
if (
item_data["content_text_"+proper_lang.toLowerCase()] == null
|| item_data["content_text_"+proper_lang.toLowerCase()] == ""
) {
// no content for current lang, use the other lang
if (proper_lang.toLowerCase() == "en") {
proper_lang = "He";
} else {
proper_lang = "En";
}
lang = proper_lang.toLowerCase();
}

//TODO: try and remove the next 3 lines as url should be based
// on current language
//TODO: try and remove the next 3 lines as url should be based on current language
if (item_data.slug) {
// TODO: figure out what is this used for
state = 'item-view';
params = {collection: item_data.slug.collection,
local_slug : item_data.slug.local_slug};
}
else if (item_data.Slug) {
params = {
collection: item_data.slug.collection,
local_slug : item_data.slug.local_slug
};
} else if (item_data["slug_"+proper_lang.toLowerCase()]) {
state = 'item-view';
var parts = item_data.Slug[proper_lang].split('_'),
// TODO: we should not make assumptions about how the slug looks like
// also, we know which collection the item belongs to
var parts = item_data["slug_"+proper_lang.toLowerCase()].split('_'),
params = {collection: parts[0],
local_slug : parts[1]};
}
else {
} else {
state = item_data.state;
params = item_data.params;
}
Expand Down
27 changes: 15 additions & 12 deletions js/modules/main/src/services/itemTypeMapService.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,22 @@ angular.module('main').service('itemTypeMap', function() {
'Photographs' : 'photoUnits',
'Photograph albums' : 'photoUnits',
'Photographic portraits' : 'photoUnits',
'Manuscripts': 'text',
'Manuscripts': 'text'
};

this.get_type = function(description_code) {
var type;
if (description_code) {
type = map[description_code];
}
else {
type = 'unknown';
}

return type;
this.get_type = function(item) {
return item.collection;
// TODO: how to determine type from CM item / what's the meaning of type
// see https://github.com/Beit-Hatfutsot/mojp-dbs-pipelines/issues/20
// var type;
// if (description_code) {
// type = map[description_code];
// }
// else {
// type = 'unknown';
// }
//
// return type;
};

this.get_collection_name = function(item_data) {
Expand All @@ -38,7 +41,7 @@ angular.module('main').service('itemTypeMap', function() {
return 'genTreeIndividuals';
}
else {
return this.get_type(item_data.UnitType);
return this.get_type(item_data);
}
};

Expand Down
35 changes: 18 additions & 17 deletions templates/main/item-preview.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div class="{{itemPreviewController.collection_name==='genTreeIndividuals'? 'person-preview':'item-preview'}}">
<ng-switch on="itemPreviewController.collection_name==='genTreeIndividuals'">
<a ng-switch-when="true" ng-href="{{itemPreviewController.get_item_url(previewData)}}" ng-click="itemPreviewController.saveCurrentSearchUrl()">
<!-- TODO: re-enable once we have persons data from clearmash
<div class="top">
<div class="tree-num">
<div class="tree-num__title">
Expand Down Expand Up @@ -56,41 +57,41 @@
</ng-switch>
<div class="family__members">{{children}}</div>
</div>
</div>
</div>-->
</a>

<a ng-switch-when="false" ng-href="{{itemPreviewController.get_item_url(previewData)}}"
target="{{itemSource=='cjh'||itemSource=='europeana'?'_blank': '_self'}}">
<div class="thumbnail" ng-if="previewData.thumbnail_url">
<img ng-src="{{previewData.thumbnail_url}}"
<div class="thumbnail" ng-if="previewData.main_thumbnail_image_url">
<img ng-src="{{previewData.main_thumbnail_image_url}}"
alt="Preview Image"/>
</div>
<div class="white-part1" ng-class="{'white-part1--nothumb':
!(previewData.thumbnail_url), 'white-part1--thumbnail':
previewData.thumbnail_url}">
!(previewData.main_thumbnail_image_url), 'white-part1--thumbnail':
previewData.main_thumbnail_image_url}">

<div class="header" ng-class="{'header--nothumb': !(previewData.thumbnail_url),
<div class="header" ng-class="{'header--nothumb': !(previewData.main_thumbnail_image_url),
'isExtResult': itemSource != 'bh'}">
<item-type type="itemPreviewController.item_type"></item-type>
<span class="header__text">
<en>{{previewData.Header.En}}</en>
<he>{{previewData.Header.He}}</he>
<en>{{previewData.title_en}}</en>
<he>{{previewData.title_he}}</he>
</span>
</div>
<div ng-if="itemSource != 'bh'" class="text" ng-class="{'text--nothumb':
!(previewData.thumbnail_url)}">
<en><span marked="previewData.UnitText1.En"></span></en>
<he><span marked="previewData.UnitText1.He"></span></he>
!(previewData.main_thumbnail_image_url)}">
<en><span marked="previewData.content_text_en"></span></en>
<he><span marked="previewData.content_text_he"></span></he>
</div>
<div ng-if="itemSource == 'bh'">
<ng-switch on="previewData.UnitText1.{{itemPreviewController.uc_first()}} != '' && previewData.UnitText1.{{itemPreviewController.uc_first()}} != null">
<ng-switch on="itemPreviewController.has_lang_content(previewData)">
<div ng-switch-when="true" class="text"
ng-class="{'text--nothumb': !(previewData.thumbnail_url)}">
<en><span marked="previewData.UnitText1.En"></span></en>
<he><span marked="previewData.UnitText1.He"></span></he>
ng-class="{'text--nothumb': !(previewData.main_thumbnail_image_url)}">
<en><span marked="previewData.content_text_en"></span></en>
<he><span marked="previewData.content_text_he"></span></he>
</div>
<div ng-switch-when="false" class="text"
ng-class="{'text--nothumb': !(previewData.thumbnail_url)}">
ng-class="{'text--nothumb': !(previewData.main_thumbnail_image_url)}">
<en>This item only exists in Hebrew at the moment.<br>
But not all is lost.<br>Click on the card to view it in Hebrew.
</en>
Expand All @@ -99,7 +100,7 @@
</ng-switch>
</div>

<div class="diagonal-block" ng-if="previewData.thumbnail_url"
<div class="diagonal-block" ng-if="previewData.main_thumbnail_image_url"
ng-class="{'diagonal-block--ext-result': itemSource!='bh'}">
<div class="diagonal-separator" style="right:-22px; opacity:1"></div>
<div class="diagonal-separator" style="right:-10px; opacity:0.7"
Expand Down
2 changes: 1 addition & 1 deletion templates/main/search-results.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
</div>
<item-preview item-source="bh"
ng-repeat="r_data in generalSearchCtrl.results.hits"
preview-data="r_data._source">
preview-data="r_data">
</item-preview>
<div class="loader" ng-click="generalSearchCtrl.fetch_more()" ng-if="generalSearchCtrl.results.total>generalSearchCtrl.results.hits.length">
<icon class="eye-icon" alt-text="{en: 'See more', he: 'לראות עוד'}" position="[-447, -628]" hover-offset="[3, 61]"></icon>
Expand Down

0 comments on commit 9ee6121

Please sign in to comment.