Skip to content

Commit

Permalink
Update service and app to new api model
Browse files Browse the repository at this point in the history
  • Loading branch information
fawind committed Oct 15, 2017
1 parent f6fa67b commit ce8e914
Show file tree
Hide file tree
Showing 10 changed files with 715 additions and 23 deletions.
6 changes: 3 additions & 3 deletions chrome/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class NewTab {
_setBackground(image) {
this.bgElement.style['background-image'] = `url(${image.dataUri})`;
this.titleElement.textContent = image.title;
this.titleElement.setAttribute('href', image.details || image.image);
this.titleElement.setAttribute('href', image.detailsUrl || image.imageUrl);
this.descriptionElement.textContent = this._getDescription(image);
}

Expand All @@ -105,10 +105,10 @@ class NewTab {
}

_getDescription(image) {
if (!image.completitionYear || image.completitionYear === '-1') {
if (!image.completionYear || image.completionYear === '-1') {
return image.artistName;
}
return `${image.artistName}, ${image.completitionYear}`;
return `${image.artistName}, ${image.completionYear}`;
}

_printError(error) {
Expand Down
6 changes: 3 additions & 3 deletions chrome/src/js/imageProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class ImageProvider {

constructor(imageStore) {
this.imageStore = imageStore;
this._API_ENPOINT = 'http://picasso-tab.appspot.com/api/v1/image/batch/';
this._API_ENPOINT = 'http://picasso-tab.appspot.com/api/v2/image/batch/';
}

async skipCurrentImage() {
Expand Down Expand Up @@ -47,13 +47,13 @@ export default class ImageProvider {
}

async _downloadImage(image, retry = false) {
const dataUri = await this._convertToDataUri(image.image);
const dataUri = await this._convertToDataUri(image.imageUrl);
const annotatedImage = Object.assign({}, image, { dataUri });
if (!this.imageStore.canUpdateCachedImage(annotatedImage)) {
if (retry) {
throw new Error('Cannot set image');
}
annotatedImage.image += '!Large.jpg';
annotatedImage.imageUrl += '!Large.jpg';
return this._downloadImage(annotatedImage, true);
}
return annotatedImage;
Expand Down
6 changes: 4 additions & 2 deletions chrome/src/js/imageStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class ImageStore {
this._MIN_QUEUE_SIZE = 4;
this._IMAGES_TO_DOWNLOAD = 4;

this._BREAKING_VERSIONS = new Set(['0.1.0']);
this._BREAKING_VERSIONS = new Set(['0.1.0', '0.2.0']);
this._clearStoreOnUpdate(this._getManifestVersion());
}

Expand Down Expand Up @@ -93,15 +93,17 @@ export default class ImageStore {
this.store.set(this._keys.VERSION, version);
}

// TODO(fawind): Remove after users have updated
_clearStoreOnUpdate(currentVersion) {
const oldVersion = this.getVersion();
if (currentVersion !== oldVersion &&
this._BREAKING_VERSIONS.has(currentVersion)) {
const newIndex = 0; // TODO - HACK: Reset index since images have a new order
/*
const oldIndex = this.store.get('index') || 0;
const oldImages = this.store.get('images') || [];
// Retrieve index of current image.
const newIndex = Math.max(0, oldIndex - oldImages.length - 1);
*/
this.store.clear();
this.setBatchIndex(newIndex);
this.setVersion(currentVersion);
Expand Down
2 changes: 1 addition & 1 deletion chrome/src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "Picasso - New Tab Page",
"description": "Art masterpieces in your browser tabs.",
"version": "0.1.2",
"version": "0.2.0",
"incognito": "split",
"permissions": [
"http://picasso-tab.appspot.com/*",
Expand Down
18 changes: 17 additions & 1 deletion chrome/test/js/imageStore.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ describe('ImageStore', () => {
expect(setIndexSpy).toNotHaveBeenCalled();
});

it('should recover the index if clearing the store', () => {
// TODO: HACK - New index is set to 0, test is excluded
xit('should recover the index if clearing the store', () => {
const newVersion = '0.0.2';
const index = 20;
const images = ['imageA', 'imageB', 'imageC'];
Expand All @@ -246,5 +247,20 @@ describe('ImageStore', () => {
expect(setVersionSpy).toHaveBeenCalledWith(newVersion);
expect(setIndexSpy).toHaveBeenCalledWith(index - imagesCount - 1);
});

// TODO: HACK - New index is set to 0, test is excluded
it('should set index to 0 if clearing the store', () => {
const newVersion = '0.0.2';
const index = 20;
const images = ['imageA', 'imageB', 'imageC'];
imageStore.store.set('index', index);
imageStore.store.set('images', images);
imageStore._BREAKING_VERSIONS = new Set([newVersion]);

imageStore._clearStoreOnUpdate(newVersion);
expect(clearStoreSpy).toHaveBeenCalled();
expect(setVersionSpy).toHaveBeenCalledWith(newVersion);
expect(setIndexSpy).toHaveBeenCalledWith(0);
});
});
});
6 changes: 3 additions & 3 deletions server/artworks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

class Artworks:

def __init__(self):
self._artworks = self._load_artworks()
def __init__(self, file_path='data/images.csv'):
self._artworks = self._load_artworks(file_path)

def _load_artworks(self, file_path='data/images.csv'):
def _load_artworks(self, file_path):
with open(file_path, 'r') as csv_file:
reader = csv.DictReader(csv_file)
return [r for r in reader]
Expand Down
2 changes: 0 additions & 2 deletions server/data/.gitignore

This file was deleted.

Loading

0 comments on commit ce8e914

Please sign in to comment.