From 9ee61211ff83285d2352ffdedbd0eca89d7d68fc Mon Sep 17 00:00:00 2001 From: Ori Hoch Date: Wed, 21 Jun 2017 15:19:01 +0300 Subject: [PATCH] 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 --- .../controllers/GeneralSearchController.js | 6 +-- .../main/src/controllers/itemPreviewCtrl.js | 31 +++++++------ js/modules/main/src/services/itemService.js | 45 +++++++++++-------- .../main/src/services/itemTypeMapService.js | 27 ++++++----- templates/main/item-preview.html | 35 ++++++++------- templates/main/search-results.html | 2 +- 6 files changed, 82 insertions(+), 64 deletions(-) diff --git a/js/modules/main/src/controllers/GeneralSearchController.js b/js/modules/main/src/controllers/GeneralSearchController.js index 4860af4d..57ce125e 100644 --- a/js/modules/main/src/controllers/GeneralSearchController.js +++ b/js/modules/main/src/controllers/GeneralSearchController.js @@ -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); }); }, @@ -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); }); @@ -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); }); }, diff --git a/js/modules/main/src/controllers/itemPreviewCtrl.js b/js/modules/main/src/controllers/itemPreviewCtrl.js index 590762ad..9afe6745 100644 --- a/js/modules/main/src/controllers/itemPreviewCtrl.js +++ b/js/modules/main/src/controllers/itemPreviewCtrl.js @@ -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; @@ -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() { @@ -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; } }; diff --git a/js/modules/main/src/services/itemService.js b/js/modules/main/src/services/itemService.js index c6a6e21a..31c8cbdd 100644 --- a/js/modules/main/src/services/itemService.js +++ b/js/modules/main/src/services/itemService.js @@ -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) { @@ -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; } diff --git a/js/modules/main/src/services/itemTypeMapService.js b/js/modules/main/src/services/itemTypeMapService.js index 30bcca8b..a0b2bf04 100644 --- a/js/modules/main/src/services/itemTypeMapService.js +++ b/js/modules/main/src/services/itemTypeMapService.js @@ -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) { @@ -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); } }; diff --git a/templates/main/item-preview.html b/templates/main/item-preview.html index 3f0f6144..5fb14b27 100644 --- a/templates/main/item-preview.html +++ b/templates/main/item-preview.html @@ -1,6 +1,7 @@
+ -
- + Preview Image
+ !(previewData.main_thumbnail_image_url), 'white-part1--thumbnail': + previewData.main_thumbnail_image_url}"> -
- {{previewData.Header.En}} - {{previewData.Header.He}} + {{previewData.title_en}} + {{previewData.title_he}}
- - + !(previewData.main_thumbnail_image_url)}"> + +
- +
- - + ng-class="{'text--nothumb': !(previewData.main_thumbnail_image_url)}"> + +
+ ng-class="{'text--nothumb': !(previewData.main_thumbnail_image_url)}"> This item only exists in Hebrew at the moment.
But not all is lost.
Click on the card to view it in Hebrew.
@@ -99,7 +100,7 @@
-
+ preview-data="r_data">