mirror of
https://github.com/bellingcat/datasheet-server.git
synced 2026-06-10 12:28:34 +03:00
rename 'routes' in blueprints to 'resources'
routes was a confusing semantics that was not in order with the rest of the architecture
This commit is contained in:
@@ -9,7 +9,7 @@ import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
|
||||
* @return {type} Blueprint
|
||||
* generated.
|
||||
*/
|
||||
export default function byColumn (tabName, sheetName, sheetId, data) {
|
||||
function byColumn (tabName, sheetName, sheetId, data) {
|
||||
// Define Blueprint props
|
||||
const bp = R.clone(defaultBlueprint)
|
||||
bp.sheet = {
|
||||
@@ -18,18 +18,22 @@ export default function byColumn (tabName, sheetName, sheetId, data) {
|
||||
}
|
||||
bp.name = tabName
|
||||
|
||||
// column names define routes
|
||||
// column names define resources
|
||||
const labels = data[0]
|
||||
labels.forEach(label => {
|
||||
bp.routes[label] = R.clone(defaultRoute)
|
||||
bp.resources[label] = R.clone(defaultRoute)
|
||||
})
|
||||
|
||||
// remaining rows as data
|
||||
data.forEach((row, idx) => {
|
||||
if (idx === 0) return
|
||||
labels.forEach((label, idx) => {
|
||||
bp.routes[label].data.push(row[idx])
|
||||
bp.resources[label].data.push(row[idx])
|
||||
})
|
||||
})
|
||||
return bp
|
||||
}
|
||||
|
||||
byColumn.resourceName = 'columns'
|
||||
|
||||
export default byColumn
|
||||
|
||||
@@ -28,11 +28,11 @@ export default function byGroup (
|
||||
}
|
||||
bp.name = tabName
|
||||
|
||||
// Column names define routes
|
||||
// Column names define resources
|
||||
const itemLabels = data[0]
|
||||
const fmt = fmtObj(itemLabels)
|
||||
bp.routes[label] = R.clone(defaultRoute)
|
||||
bp.routes[label].data = []
|
||||
bp.resources[label] = R.clone(defaultRoute)
|
||||
bp.resources[label].data = []
|
||||
|
||||
const dataGroups = {}
|
||||
|
||||
@@ -46,7 +46,7 @@ export default function byGroup (
|
||||
}
|
||||
})
|
||||
Object.keys(dataGroups).forEach(groupKey => {
|
||||
bp.routes[label].data.push({
|
||||
bp.resources[label].data.push({
|
||||
group: groupKey,
|
||||
group_label: dataGroups[groupKey][0].group_label,
|
||||
data: dataGroups[groupKey]
|
||||
|
||||
@@ -28,15 +28,15 @@ export default function byId (
|
||||
}
|
||||
bp.name = tabName
|
||||
|
||||
// Column names define routes
|
||||
// Column names define resources
|
||||
const itemLabels = data[0]
|
||||
const fmt = fmtObj(itemLabels)
|
||||
bp.routes[label] = R.clone(defaultRoute)
|
||||
bp.routes[label].data = []
|
||||
bp.resources[label] = R.clone(defaultRoute)
|
||||
bp.resources[label].data = []
|
||||
|
||||
data.forEach((row, idx) => {
|
||||
if (idx === 0) return
|
||||
bp.routes[label].data[fmt(row).id] = fmt(row)
|
||||
bp.resources[label].data[fmt(row).id] = fmt(row)
|
||||
})
|
||||
return bp
|
||||
}
|
||||
|
||||
@@ -27,15 +27,15 @@ export default function byRow (
|
||||
}
|
||||
bp.name = tabName
|
||||
|
||||
// Column names define routes
|
||||
// Column names define resources
|
||||
const itemLabels = data[0]
|
||||
const fmt = fmtObj(itemLabels)
|
||||
bp.routes[label] = R.clone(defaultRoute)
|
||||
bp.routes[label].data = []
|
||||
bp.resources[label] = R.clone(defaultRoute)
|
||||
bp.resources[label].data = []
|
||||
|
||||
data.forEach((row, idx) => {
|
||||
if (idx === 0) return
|
||||
bp.routes[label].data.push(fmt(row))
|
||||
bp.resources[label].data.push(fmt(row))
|
||||
})
|
||||
return bp
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ export default function byTree (
|
||||
}
|
||||
bp.name = tabName
|
||||
|
||||
// Column names define routes
|
||||
bp.routes[label] = R.clone(defaultRoute)
|
||||
bp.routes[label].data = {}
|
||||
// Column names define resources
|
||||
bp.resources[label] = R.clone(defaultRoute)
|
||||
bp.resources[label].data = {}
|
||||
|
||||
const tree = {
|
||||
key: 'tags',
|
||||
@@ -62,6 +62,6 @@ export default function byTree (
|
||||
}
|
||||
})
|
||||
|
||||
bp.routes[label].data = tree
|
||||
bp.resources[label].data = tree
|
||||
return bp
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ class Controller {
|
||||
return this.fetchers[sheet].update()
|
||||
})
|
||||
).then(results => {
|
||||
console.log(results)
|
||||
if (results.every(r => r)) {
|
||||
return copy.success.update
|
||||
} else {
|
||||
|
||||
@@ -47,7 +47,10 @@ class Fetcher {
|
||||
* performance of indexing the blueprints.
|
||||
*/
|
||||
this.blueprints = this._indexDbForBlueprints()
|
||||
.then(res => res)
|
||||
.then(allUrls => {
|
||||
const supportedUrls = allUrls.filter(url => url.startsWith(this.id))
|
||||
return {}
|
||||
})
|
||||
|
||||
/*
|
||||
* Google API setup
|
||||
@@ -71,8 +74,8 @@ class Fetcher {
|
||||
)
|
||||
|
||||
return Promise.all(
|
||||
Object.keys(saturatedBp.routes).map(route =>
|
||||
this.db.save(`${this.id}/${tab}/${route}`, saturatedBp.routes[route].data)
|
||||
Object.keys(saturatedBp.resources).map(route =>
|
||||
this.db.save(`${this.id}/${tab}/${route}`, saturatedBp.resources[route].data)
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -106,7 +109,7 @@ class Fetcher {
|
||||
|
||||
update () {
|
||||
let tabTitles
|
||||
/* Retrieve all available routes on a given sheet, and store formatted copies of it where a formatter is available */
|
||||
/* Retrieve all available resources on a given sheet, and store formatted copies of it where a formatter is available */
|
||||
return this.API.spreadsheets
|
||||
.get({
|
||||
auth: this.auth,
|
||||
|
||||
@@ -5,7 +5,7 @@ export const defaultBlueprint = {
|
||||
name: null,
|
||||
id: null,
|
||||
dialects: ['rest'], // supported dialects, can (eventually) be multiple
|
||||
routes: {}
|
||||
resources: {}
|
||||
}
|
||||
|
||||
export const defaultRoute = {
|
||||
|
||||
@@ -77,11 +77,11 @@ export function desaturate (full) {
|
||||
name: R.clone(full.name),
|
||||
sheet: R.clone(full.sheet),
|
||||
dialects: R.clone(full.dialects),
|
||||
routes: {}
|
||||
resources: {}
|
||||
}
|
||||
Object.keys(full.routes).forEach(route => {
|
||||
blueprint.routes[route] = {
|
||||
options: R.clone(full.routes[route].options)
|
||||
Object.keys(full.resources).forEach(route => {
|
||||
blueprint.resources[route] = {
|
||||
options: R.clone(full.resources[route].options)
|
||||
}
|
||||
})
|
||||
return blueprint
|
||||
|
||||
@@ -18,7 +18,7 @@ test('defaultBlueprint exports', t => {
|
||||
name: null,
|
||||
id: null,
|
||||
dialects: ['rest'],
|
||||
routes: {}
|
||||
resources: {}
|
||||
}
|
||||
t.deepEqual(expected, defaultBlueprint)
|
||||
})
|
||||
@@ -31,12 +31,12 @@ test('byColumn blueprinter generates expected output', t => {
|
||||
id: 'egSheetId',
|
||||
name: 'egSheetName'
|
||||
}
|
||||
expected.routes['h1'] = R.clone(defaultRoute)
|
||||
expected.routes['h1'].data = [1, 4]
|
||||
expected.routes['h2'] = R.clone(defaultRoute)
|
||||
expected.routes['h2'].data = [2, 5]
|
||||
expected.routes['h3'] = R.clone(defaultRoute)
|
||||
expected.routes['h3'].data = [3, 6]
|
||||
expected.resources['h1'] = R.clone(defaultRoute)
|
||||
expected.resources['h1'].data = [1, 4]
|
||||
expected.resources['h2'] = R.clone(defaultRoute)
|
||||
expected.resources['h2'].data = [2, 5]
|
||||
expected.resources['h3'] = R.clone(defaultRoute)
|
||||
expected.resources['h3'].data = [3, 6]
|
||||
t.deepEqual(expected, actual)
|
||||
})
|
||||
|
||||
@@ -48,8 +48,8 @@ test('byRow blueprinter generates expected output', t => {
|
||||
id: 'egSheetId',
|
||||
name: 'egSheetName'
|
||||
}
|
||||
expected.routes['items'] = R.clone(defaultRoute)
|
||||
expected.routes['items'].data = [{
|
||||
expected.resources['items'] = R.clone(defaultRoute)
|
||||
expected.resources['items'].data = [{
|
||||
h1: 1,
|
||||
h2: 2,
|
||||
h3: 3
|
||||
|
||||
Reference in New Issue
Block a user