Skip to content

Commit

Permalink
Get thumbnail using thumbnailHash when avaialable
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Feb 1, 2024
1 parent d243d9d commit 0d16867
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions scilog/src/app/core/model/logbooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface Logbooks extends Basesnippets {
name?: string;
description?: string;
thumbnail?: string;
thumbnailHash?: string;
location?: string;
readACL?: string[];
updateACL?: string[];
Expand Down
4 changes: 2 additions & 2 deletions scilog/src/app/core/remote-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ export class LogbookItemDataService extends RemoteDataService {
return this.getSnippets<Blob>(imageSnippetUrl, { responseType: 'blob' }).toPromise();
}

async getImage(id: string) {
getImage(id: string) {
// first retrieve image snippet, then filesnippet and then file
// let fileSnippet = await this.getFilesnippet(id);
// console.log(fileSnippet)
// let headers = new HttpHeaders();
// headers = headers.set('Accept', 'application/json');
return this.getSnippets<Blob>("filesnippet/" + id + "/files", { responseType: 'blob' }).toPromise();
return this.getSnippets<Blob>("images/" + id, { responseType: 'blob' }).toPromise();
}

getFilesnippet(id: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('LogbookWidgetComponent', () => {
logbookSpy = jasmine.createSpyObj("LogbookInfoService", ["logbookInfo"]);
logbookSpy.logbookInfo.and.returnValue([]);

logbookItemDataSpy = jasmine.createSpyObj("LogbookItemDataService", ["getFile"]);
logbookItemDataSpy = jasmine.createSpyObj("LogbookItemDataService", ["getFile", "getImage"]);
logbookItemDataSpy.getFile.and.returnValue(of({}));

beforeEach(waitForAsync(() => {
Expand Down Expand Up @@ -72,11 +72,21 @@ describe('LogbookWidgetComponent', () => {
expect(component).toBeTruthy();
});


it('should test enableActions', () => {
const isAnyEditAllowedSpy = spyOn(component['isActionAllowed'], 'isAnyEditAllowed');
component['enableActions']();
expect(isAnyEditAllowedSpy).toHaveBeenCalledTimes(1);
});

[undefined, 'hash'].forEach((t, i) => {
it(`should getImageFromService ${i}`, async () => {
logbookItemDataSpy.getImage.calls.reset();
component.logbook.thumbnail = 'abc'
component.logbook.thumbnailHash = t
spyOn(component, 'createImageFromBlob');
await component.getImageFromService();
expect(logbookItemDataSpy.getImage).toHaveBeenCalledOnceWith(t ?? 'abc');
});
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export class LogbookWidgetComponent implements OnInit {

async getImageFromService() {
this.isImageLoading = true;
let data = await this.logbookItemDataService.getImage(this.logbook.thumbnail);
let data = await this.logbookItemDataService.getImage(
this.logbook.thumbnailHash ??
this.logbook.thumbnail
);
this.createImageFromBlob(data);
this.isImageLoading = false;
}
Expand Down

0 comments on commit 0d16867

Please sign in to comment.