|
6 | 6 | <template #not-found> |
7 | 7 | <div>Could not load thumbnail</div> |
8 | 8 | </template> |
9 | | - <b-img :src="data.url" :alt="'Thumbnail for frame' + frameId" center thumbnail></b-img> |
| 9 | + <b-img :src="thumbnailSmallUrl" :alt="'Thumbnail for frame' + frameId" center thumbnail @click="showLargeThumb = true"></b-img> |
| 10 | + <b-modal v-if="thumbnailLargeUrl != ''" v-model="showLargeThumb" size="xl" centered hide-footer hide-header body-class="p-0" scrollable> |
| 11 | + <b-img :src="thumbnailLargeUrl" :alt="'Thumbnail for frame' + frameId" style="width: 100%; object-fit: contain;" /> |
| 12 | + </b-modal> |
10 | 13 | </ocs-data-loader> |
11 | 14 | </template> |
12 | 15 | <script> |
13 | | -import { OCSMixin } from 'ocs-component-lib'; |
| 16 | +import _ from 'lodash'; |
| 17 | +import $ from 'jquery'; |
14 | 18 |
|
15 | 19 | export default { |
16 | 20 | name: 'Thumbnail', |
17 | | - mixins: [OCSMixin.getDataMixin], |
18 | 21 | props: { |
19 | 22 | frameId: { |
20 | 23 | type: [String, Number], |
21 | 24 | required: true |
22 | 25 | } |
23 | 26 | }, |
| 27 | + data: function() { |
| 28 | + return { |
| 29 | + dataLoadError: false, |
| 30 | + dataLoaded: false, |
| 31 | + dataNotFound: false, |
| 32 | + thumbnailSmallUrl: '', |
| 33 | + thumbnailLargeUrl: '', |
| 34 | + showLargeThumb: false, |
| 35 | + archiveThumbnailEndpoint: `${this.$store.state.urls.archiveApiUrl}/frames/${this.frameId}/?include_thumbnails=true`, |
| 36 | + oldThumbnailEndpoint: `${this.$store.state.urls.thumbnailServiceUrl}/${this.frameId}/?width=300` |
| 37 | + }; |
| 38 | + }, |
| 39 | + created: function() { |
| 40 | + this.getThumbnailData(); |
| 41 | + }, |
24 | 42 | methods: { |
25 | | - initializeDataEndpoint: function() { |
26 | | - return `${this.$store.state.urls.thumbnailServiceUrl}/${this.frameId}/?width=300`; |
| 43 | + clearLoadStates: function() { |
| 44 | + this.dataLoaded = false; |
| 45 | + this.dataLoadError = false; |
| 46 | + this.dataNotFound = false; |
| 47 | + this.thumbnailSmallUrl = ''; |
| 48 | + this.thumbnailLargeUrl = ''; |
| 49 | + }, |
| 50 | + getThumbnailData: function() { |
| 51 | + this.clearLoadStates(); |
| 52 | + let that = this; |
| 53 | + $.ajax({ |
| 54 | + url: this.archiveThumbnailEndpoint |
| 55 | + }) |
| 56 | + .done(function(response) { |
| 57 | + let data = response; |
| 58 | + if (_.isArray(data.thumbnails) && data.thumbnails.length > 0) { |
| 59 | + // This sorting works to put 'small' before 'large', should also work for 'medium', |
| 60 | + // but falls back to at least using a thumbnail if one exists for the frame in the archive. |
| 61 | + let thumbnails = _.orderBy(data.thumbnails, ['size'], ['desc']); |
| 62 | + that.thumbnailSmallUrl = thumbnails[0].url || ''; |
| 63 | + that.thumbnailLargeUrl = thumbnails[1].url || ''; |
| 64 | + that.dataLoaded = true; |
| 65 | + } else { |
| 66 | + that.getOldThumbnailData(); |
| 67 | + } |
| 68 | + }) |
| 69 | + .fail(function() { |
| 70 | + that.getOldThumbnailData(); |
| 71 | + }); |
| 72 | + }, |
| 73 | + getOldThumbnailData: function() { |
| 74 | + let that = this; |
| 75 | + $.ajax({ |
| 76 | + url: this.oldThumbnailEndpoint |
| 77 | + }) |
| 78 | + .done(function(response) { |
| 79 | + that.thumbnailSmallUrl = response.url; |
| 80 | + }) |
| 81 | + .fail(function(response) { |
| 82 | + if (response.status === 404 || response.status === 403) { |
| 83 | + that.dataNotFound = true; |
| 84 | + } else { |
| 85 | + that.dataLoadError = true; |
| 86 | + } |
| 87 | + }) |
| 88 | + .always(function () { |
| 89 | + that.dataLoaded = true; |
| 90 | + }); |
27 | 91 | } |
28 | 92 | } |
29 | 93 | }; |
|
0 commit comments