'use strict'

const fetch = require('isomorphic-fetch')
const groupBy = require('lodash.groupBy')



const endpoint = 'http://199.217.112.113:8080/picture/picture'
const filters = ['decade', 'collection', 'color', 'location', 'motif', 'view']



const err = (e) => {throw e}

const data = fetch(endpoint)
.then((res) => res.json(), err)
.then((photos) => {
	const data = {}

	data.photos = photos.map((p) => ({
		  id:         p.id
		, url:        p.Bildname
		, thumb: {
			  url:    p.BildSmall
			, width:  p.width
			, height: p.height
		}
		, year:       p.Decade
		, decade:     ((p.Decade - p.Decade % 10) || '?').toString()
		, collection: p.Collection
		, color:      p.Color.toLowerCase()
		, location:   p.Location
		, motif:      p.Subject
		, view:       p.View
	}))

	for (let filter of filters)
		data[filter] = groupBy(data.photos, (p) => p[filter])

	data.filters = filters
	return data
}, err)

module.exports = data

@@ -192,53 +192,55 @@
 'col
-lection', 'color', 'location', 'motif', 'view
+or', 'subject', 'view', 'collection', 'location
 '%5D%0A%0A
@@ -543,33 +543,8 @@
 %09%09%7D%0A
-%09%09, year:       p.Decade%0A
 %09%09, 
@@ -704,18 +704,18 @@
 %09%09, 
-motif:    
+subject: %09
   p.

reorder and rename filters