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