Skip to content

Commit b064556

Browse files
authored
Merge pull request #6 from observatorycontrolsystem/feature/use_archive_thumbs
Feature/use archive thumbs
2 parents 9b071b2 + 95ac9fd commit b064556

1 file changed

Lines changed: 69 additions & 5 deletions

File tree

src/components/Thumbnail.vue

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,88 @@
66
<template #not-found>
77
<div>Could not load thumbnail</div>
88
</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>
1013
</ocs-data-loader>
1114
</template>
1215
<script>
13-
import { OCSMixin } from 'ocs-component-lib';
16+
import _ from 'lodash';
17+
import $ from 'jquery';
1418
1519
export default {
1620
name: 'Thumbnail',
17-
mixins: [OCSMixin.getDataMixin],
1821
props: {
1922
frameId: {
2023
type: [String, Number],
2124
required: true
2225
}
2326
},
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+
},
2442
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+
});
2791
}
2892
}
2993
};

0 commit comments

Comments
 (0)