Skip to content

Commit 9ee6121

Browse files
authored
adjust frontend to new API schemas (focusing on search results) (#432)
* 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
1 parent f5804dc commit 9ee6121

File tree

6 files changed

+82
-64
lines changed

6 files changed

+82
-64
lines changed

js/modules/main/src/controllers/GeneralSearchController.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ GeneralSearchController.prototype = {
238238
this.$state.go('general-search', {params: par});
239239
self.$http.get(self.apiClient.urls.search, {params: par})
240240
.success(function (r) {
241-
self.results = r.hits;
241+
self.results = r;
242242
self.notification.loading(false);
243243
});
244244
},
@@ -248,7 +248,7 @@ GeneralSearchController.prototype = {
248248
self.notification.loading(true);
249249
self.$http.get(self.apiClient.urls.search, {params: self.api_params()})
250250
.success(function (r) {
251-
self.results = r.hits;
251+
self.results = r;
252252
self.notification.loading(false);
253253
});
254254

@@ -363,7 +363,7 @@ GeneralSearchController.prototype = {
363363

364364
this.$http.get(this.apiClient.urls.search, {params: this.api_params()})
365365
.success(function (r){
366-
results.hits = results.hits.concat(r.hits.hits);
366+
results.hits = results.hits.concat(r.hits);
367367
});
368368
},
369369

js/modules/main/src/controllers/itemPreviewCtrl.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ var ItemPreviewCtrl = function($state, $scope, $location, $rootScope, itemTypeMa
77
this.mjs = mjs;
88
this.$scope = $scope;
99
this.item = item;
10-
this.item_type = itemTypeMap.get_type($scope.previewData.UnitType);
10+
this.item_type = itemTypeMap.get_type($scope.previewData/*.UnitType*/);
11+
// TODO: what's in_branch?
1112
this.in_branch = $scope.previewData.in_branch;
13+
// TODO: what's url?
1214
this.url = $scope.previewData.url;
1315
this.collection_name = itemTypeMap.get_collection_name($scope.previewData);
1416
this.rmdialog_is_open = false;
@@ -23,21 +25,20 @@ ItemPreviewCtrl.prototype = {
2325
},
2426

2527
get_item_url: function(item_data) {
26-
// TODO: refactor to user item.get_url
2728
if (this.url !== undefined) {
2829
return this.url;
30+
} else {
31+
return this.item.get_url(item_data);
2932
}
30-
if (this.collection_name === 'genTreeIndividuals') {
31-
var state_name = this.proper_lang=='he'?'he.he_person-view':'person-view';
32-
return this.$state.href(state_name,
33-
{tree_number:item_data.tree_num,
34-
version:item_data.tree_version,
35-
node_id: (item_data.person_id||item_data.id)
36-
});
37-
}
38-
else {
39-
return this.item.get_url(item_data);
40-
}
33+
// TODO: re-enable once we have persons data from CM
34+
// if (this.collection_name === 'genTreeIndividuals') {
35+
// var state_name = this.proper_lang=='he'?'he.he_person-view':'person-view';
36+
// return this.$state.href(state_name,
37+
// {tree_number:item_data.tree_num,
38+
// version:item_data.tree_version,
39+
// node_id: (item_data.person_id||item_data.id)
40+
// });
41+
// }
4142
},
4243

4344
remove_from_mjs: function() {
@@ -69,6 +70,10 @@ ItemPreviewCtrl.prototype = {
6970
uc_first: function() {
7071
var lang = this.proper_lang;
7172
return lang.charAt(0).toUpperCase() + lang.slice(1);
73+
},
74+
75+
has_lang_content: function(doc) {
76+
if (doc["content_text_"+this.proper_lang.toLowerCase()]) return true; else return false;
7277
}
7378

7479
};

js/modules/main/src/services/itemService.js

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ angular.module('main').
6767
},
6868

6969
get_key: function(item_data) {
70-
if (item_data.Slug)
71-
return item_data.Slug.En || item_data.Slug.He;
72-
if (item_data.params)
73-
return JSON.stringify(item_data.params)
70+
if (item_data.slug_en) return item_data.slug_en;
71+
if (item_data.slug_he) return item_data.slug_he;
72+
// TODO: figure out what params attribute contains
73+
if (item_data.params) return JSON.stringify(item_data.params)
7474
},
7575

7676
get_marker_link: function(slug) {
@@ -102,26 +102,35 @@ angular.module('main').
102102
proper_lang = lang[0].toUpperCase() + lang.slice(1),
103103
params,
104104
state;
105-
//get url with another language if the item's description in current is missing
106-
if (item_data.UnitText1 && (item_data.UnitText1[proper_lang] == null || item_data.UnitText1[proper_lang] == '')) {
107-
proper_lang == 'En' ? proper_lang = 'He' : proper_lang = 'En';
108-
lang = proper_lang.toLowerCase();
105+
// get url with another language if the item's description in current is missing
106+
if (
107+
item_data["content_text_"+proper_lang.toLowerCase()] == null
108+
|| item_data["content_text_"+proper_lang.toLowerCase()] == ""
109+
) {
110+
// no content for current lang, use the other lang
111+
if (proper_lang.toLowerCase() == "en") {
112+
proper_lang = "He";
113+
} else {
114+
proper_lang = "En";
115+
}
116+
lang = proper_lang.toLowerCase();
109117
}
110-
111-
//TODO: try and remove the next 3 lines as url should be based
112-
// on current language
118+
//TODO: try and remove the next 3 lines as url should be based on current language
113119
if (item_data.slug) {
120+
// TODO: figure out what is this used for
114121
state = 'item-view';
115-
params = {collection: item_data.slug.collection,
116-
local_slug : item_data.slug.local_slug};
117-
}
118-
else if (item_data.Slug) {
122+
params = {
123+
collection: item_data.slug.collection,
124+
local_slug : item_data.slug.local_slug
125+
};
126+
} else if (item_data["slug_"+proper_lang.toLowerCase()]) {
119127
state = 'item-view';
120-
var parts = item_data.Slug[proper_lang].split('_'),
128+
// TODO: we should not make assumptions about how the slug looks like
129+
// also, we know which collection the item belongs to
130+
var parts = item_data["slug_"+proper_lang.toLowerCase()].split('_'),
121131
params = {collection: parts[0],
122132
local_slug : parts[1]};
123-
}
124-
else {
133+
} else {
125134
state = item_data.state;
126135
params = item_data.params;
127136
}

js/modules/main/src/services/itemTypeMapService.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ angular.module('main').service('itemTypeMap', function() {
1515
'Photographs' : 'photoUnits',
1616
'Photograph albums' : 'photoUnits',
1717
'Photographic portraits' : 'photoUnits',
18-
'Manuscripts': 'text',
18+
'Manuscripts': 'text'
1919
};
2020

21-
this.get_type = function(description_code) {
22-
var type;
23-
if (description_code) {
24-
type = map[description_code];
25-
}
26-
else {
27-
type = 'unknown';
28-
}
29-
30-
return type;
21+
this.get_type = function(item) {
22+
return item.collection;
23+
// TODO: how to determine type from CM item / what's the meaning of type
24+
// see https://github.com/Beit-Hatfutsot/mojp-dbs-pipelines/issues/20
25+
// var type;
26+
// if (description_code) {
27+
// type = map[description_code];
28+
// }
29+
// else {
30+
// type = 'unknown';
31+
// }
32+
//
33+
// return type;
3134
};
3235

3336
this.get_collection_name = function(item_data) {
@@ -38,7 +41,7 @@ angular.module('main').service('itemTypeMap', function() {
3841
return 'genTreeIndividuals';
3942
}
4043
else {
41-
return this.get_type(item_data.UnitType);
44+
return this.get_type(item_data);
4245
}
4346
};
4447

templates/main/item-preview.html

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<div class="{{itemPreviewController.collection_name==='genTreeIndividuals'? 'person-preview':'item-preview'}}">
22
<ng-switch on="itemPreviewController.collection_name==='genTreeIndividuals'">
33
<a ng-switch-when="true" ng-href="{{itemPreviewController.get_item_url(previewData)}}" ng-click="itemPreviewController.saveCurrentSearchUrl()">
4+
<!-- TODO: re-enable once we have persons data from clearmash
45
<div class="top">
56
<div class="tree-num">
67
<div class="tree-num__title">
@@ -56,41 +57,41 @@
5657
</ng-switch>
5758
<div class="family__members">{{children}}</div>
5859
</div>
59-
</div>
60+
</div>-->
6061
</a>
6162

6263
<a ng-switch-when="false" ng-href="{{itemPreviewController.get_item_url(previewData)}}"
6364
target="{{itemSource=='cjh'||itemSource=='europeana'?'_blank': '_self'}}">
64-
<div class="thumbnail" ng-if="previewData.thumbnail_url">
65-
<img ng-src="{{previewData.thumbnail_url}}"
65+
<div class="thumbnail" ng-if="previewData.main_thumbnail_image_url">
66+
<img ng-src="{{previewData.main_thumbnail_image_url}}"
6667
alt="Preview Image"/>
6768
</div>
6869
<div class="white-part1" ng-class="{'white-part1--nothumb':
69-
!(previewData.thumbnail_url), 'white-part1--thumbnail':
70-
previewData.thumbnail_url}">
70+
!(previewData.main_thumbnail_image_url), 'white-part1--thumbnail':
71+
previewData.main_thumbnail_image_url}">
7172

72-
<div class="header" ng-class="{'header--nothumb': !(previewData.thumbnail_url),
73+
<div class="header" ng-class="{'header--nothumb': !(previewData.main_thumbnail_image_url),
7374
'isExtResult': itemSource != 'bh'}">
7475
<item-type type="itemPreviewController.item_type"></item-type>
7576
<span class="header__text">
76-
<en>{{previewData.Header.En}}</en>
77-
<he>{{previewData.Header.He}}</he>
77+
<en>{{previewData.title_en}}</en>
78+
<he>{{previewData.title_he}}</he>
7879
</span>
7980
</div>
8081
<div ng-if="itemSource != 'bh'" class="text" ng-class="{'text--nothumb':
81-
!(previewData.thumbnail_url)}">
82-
<en><span marked="previewData.UnitText1.En"></span></en>
83-
<he><span marked="previewData.UnitText1.He"></span></he>
82+
!(previewData.main_thumbnail_image_url)}">
83+
<en><span marked="previewData.content_text_en"></span></en>
84+
<he><span marked="previewData.content_text_he"></span></he>
8485
</div>
8586
<div ng-if="itemSource == 'bh'">
86-
<ng-switch on="previewData.UnitText1.{{itemPreviewController.uc_first()}} != '' && previewData.UnitText1.{{itemPreviewController.uc_first()}} != null">
87+
<ng-switch on="itemPreviewController.has_lang_content(previewData)">
8788
<div ng-switch-when="true" class="text"
88-
ng-class="{'text--nothumb': !(previewData.thumbnail_url)}">
89-
<en><span marked="previewData.UnitText1.En"></span></en>
90-
<he><span marked="previewData.UnitText1.He"></span></he>
89+
ng-class="{'text--nothumb': !(previewData.main_thumbnail_image_url)}">
90+
<en><span marked="previewData.content_text_en"></span></en>
91+
<he><span marked="previewData.content_text_he"></span></he>
9192
</div>
9293
<div ng-switch-when="false" class="text"
93-
ng-class="{'text--nothumb': !(previewData.thumbnail_url)}">
94+
ng-class="{'text--nothumb': !(previewData.main_thumbnail_image_url)}">
9495
<en>This item only exists in Hebrew at the moment.<br>
9596
But not all is lost.<br>Click on the card to view it in Hebrew.
9697
</en>
@@ -99,7 +100,7 @@
99100
</ng-switch>
100101
</div>
101102

102-
<div class="diagonal-block" ng-if="previewData.thumbnail_url"
103+
<div class="diagonal-block" ng-if="previewData.main_thumbnail_image_url"
103104
ng-class="{'diagonal-block--ext-result': itemSource!='bh'}">
104105
<div class="diagonal-separator" style="right:-22px; opacity:1"></div>
105106
<div class="diagonal-separator" style="right:-10px; opacity:0.7"

templates/main/search-results.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
</div>
247247
<item-preview item-source="bh"
248248
ng-repeat="r_data in generalSearchCtrl.results.hits"
249-
preview-data="r_data._source">
249+
preview-data="r_data">
250250
</item-preview>
251251
<div class="loader" ng-click="generalSearchCtrl.fetch_more()" ng-if="generalSearchCtrl.results.total>generalSearchCtrl.results.hits.length">
252252
<icon class="eye-icon" alt-text="{en: 'See more', he: 'לראות עוד'}" position="[-447, -628]" hover-offset="[3, 61]"></icon>

0 commit comments

Comments
 (0)