mirror of
https://github.com/bellingcat/datasheet-server.git
synced 2026-06-11 12:58:32 +03:00
defaultRoute -> defaultResource
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import R from 'ramda'
|
import R from 'ramda'
|
||||||
import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
|
import { defaultBlueprint, defaultResource } from '../lib/blueprinters'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* byColumn - generate a Blueprint from a data sheet by column. Each column
|
* byColumn - generate a Blueprint from a data sheet by column. Each column
|
||||||
@@ -9,7 +9,7 @@ import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
|
|||||||
* @return {type} Blueprint
|
* @return {type} Blueprint
|
||||||
* generated.
|
* generated.
|
||||||
*/
|
*/
|
||||||
function byColumn (tabName, sheetName, sheetId, data) {
|
function columns (tabName, sheetName, sheetId, data) {
|
||||||
// Define Blueprint props
|
// Define Blueprint props
|
||||||
const bp = R.clone(defaultBlueprint)
|
const bp = R.clone(defaultBlueprint)
|
||||||
bp.sheet = {
|
bp.sheet = {
|
||||||
@@ -21,7 +21,7 @@ function byColumn (tabName, sheetName, sheetId, data) {
|
|||||||
// column names define resources
|
// column names define resources
|
||||||
const labels = data[0]
|
const labels = data[0]
|
||||||
labels.forEach(label => {
|
labels.forEach(label => {
|
||||||
bp.resources[label] = R.clone(defaultRoute)
|
bp.resources[label] = R.clone(defaultResource)
|
||||||
})
|
})
|
||||||
|
|
||||||
// remaining rows as data
|
// remaining rows as data
|
||||||
@@ -34,6 +34,4 @@ function byColumn (tabName, sheetName, sheetId, data) {
|
|||||||
return bp
|
return bp
|
||||||
}
|
}
|
||||||
|
|
||||||
byColumn.resourceName = 'columns'
|
export default columns
|
||||||
|
|
||||||
export default byColumn
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import R from 'ramda'
|
import R from 'ramda'
|
||||||
import { fmtObj } from '../lib/util'
|
import { fmtObj } from '../lib/util'
|
||||||
import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
|
import { defaultBlueprint, defaultResource } from '../lib/blueprinters'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* byGroup - generate a Blueprint from a data sheet grouped by a column called 'group'
|
* groups - generate a Blueprint from a data sheet grouped by a column called 'group'
|
||||||
* The resource name defaults to 'groups', or a custom resource name can be passed.
|
* The resource name defaults to 'groups', or a custom resource name can be passed.
|
||||||
* Each resource item is an object with values labelled according to column
|
* Each resource item is an object with values labelled according to column
|
||||||
* names. Items are inserted in the data list at idx = id.
|
* names. Items are inserted in the data list at idx = id.
|
||||||
@@ -13,7 +13,7 @@ import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
|
|||||||
* @param {type} name="" name of blueprint.
|
* @param {type} name="" name of blueprint.
|
||||||
* @return {type} Blueprint
|
* @return {type} Blueprint
|
||||||
*/
|
*/
|
||||||
export default function byGroup (
|
export default function groups (
|
||||||
tabName,
|
tabName,
|
||||||
sheetName,
|
sheetName,
|
||||||
sheetId,
|
sheetId,
|
||||||
@@ -31,7 +31,7 @@ export default function byGroup (
|
|||||||
// Column names define resources
|
// Column names define resources
|
||||||
const itemLabels = data[0]
|
const itemLabels = data[0]
|
||||||
const fmt = fmtObj(itemLabels)
|
const fmt = fmtObj(itemLabels)
|
||||||
bp.resources[label] = R.clone(defaultRoute)
|
bp.resources[label] = R.clone(defaultResource)
|
||||||
bp.resources[label].data = []
|
bp.resources[label].data = []
|
||||||
|
|
||||||
const dataGroups = {}
|
const dataGroups = {}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import R from 'ramda'
|
import R from 'ramda'
|
||||||
import { fmtObj } from '../lib/util'
|
import { fmtObj } from '../lib/util'
|
||||||
import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
|
import { defaultBlueprint, defaultResource } from '../lib/blueprinters'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* byId - generate a Blueprint from a data sheet by id, which is an integer.
|
* ids - generate a Blueprint from a data sheet by id, which is an integer.
|
||||||
* The resource name defaults to 'ids', or a custom resource name can be passed.
|
* The resource name defaults to 'ids', or a custom resource name can be passed.
|
||||||
* Each resource item is an object with values labelled according to column
|
* Each resource item is an object with values labelled according to column
|
||||||
* names. Items are inserted in the data list at idx = id.
|
* names. Items are inserted in the data list at idx = id.
|
||||||
@@ -13,7 +13,7 @@ import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
|
|||||||
* @param {type} name="" name of blueprint.
|
* @param {type} name="" name of blueprint.
|
||||||
* @return {type} Blueprint
|
* @return {type} Blueprint
|
||||||
*/
|
*/
|
||||||
export default function byId (
|
export default function ids (
|
||||||
tabName,
|
tabName,
|
||||||
sheetName,
|
sheetName,
|
||||||
sheetId,
|
sheetId,
|
||||||
@@ -31,7 +31,7 @@ export default function byId (
|
|||||||
// Column names define resources
|
// Column names define resources
|
||||||
const itemLabels = data[0]
|
const itemLabels = data[0]
|
||||||
const fmt = fmtObj(itemLabels)
|
const fmt = fmtObj(itemLabels)
|
||||||
bp.resources[label] = R.clone(defaultRoute)
|
bp.resources[label] = R.clone(defaultResource)
|
||||||
bp.resources[label].data = []
|
bp.resources[label].data = []
|
||||||
|
|
||||||
data.forEach((row, idx) => {
|
data.forEach((row, idx) => {
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import R from 'ramda'
|
import R from 'ramda'
|
||||||
import { fmtObj } from '../lib/util'
|
import { fmtObj } from '../lib/util'
|
||||||
import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
|
import { defaultBlueprint, defaultResource } from '../lib/blueprinters'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* byRow - generate a Blueprint from a data sheet by row. The resource name
|
* rows - generate a Blueprint from a data sheet by row. The resource name
|
||||||
* defaults to 'rows', or a custom resource name can be passed. Each resource
|
* defaults to 'rows', or a custom resource name can be passed. Each resource
|
||||||
* item is an object with values labelled according to column names.
|
* item is an object with values labelled according to column names.
|
||||||
*
|
*
|
||||||
@@ -12,7 +12,7 @@ import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
|
|||||||
* @param {type} name="" name of blueprint.
|
* @param {type} name="" name of blueprint.
|
||||||
* @return {type} Blueprint
|
* @return {type} Blueprint
|
||||||
*/
|
*/
|
||||||
export default function byRow (
|
export default function rows (
|
||||||
tabName,
|
tabName,
|
||||||
sheetName,
|
sheetName,
|
||||||
sheetId,
|
sheetId,
|
||||||
@@ -30,7 +30,7 @@ export default function byRow (
|
|||||||
// Column names define resources
|
// Column names define resources
|
||||||
const itemLabels = data[0]
|
const itemLabels = data[0]
|
||||||
const fmt = fmtObj(itemLabels)
|
const fmt = fmtObj(itemLabels)
|
||||||
bp.resources[label] = R.clone(defaultRoute)
|
bp.resources[label] = R.clone(defaultResource)
|
||||||
bp.resources[label].data = []
|
bp.resources[label].data = []
|
||||||
|
|
||||||
data.forEach((row, idx) => {
|
data.forEach((row, idx) => {
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
import R from 'ramda'
|
import R from 'ramda'
|
||||||
import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
|
import { defaultBlueprint, defaultResource } from '../lib/blueprinters'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* byTree - generate a Blueprint from a data sheet grouped by a column called 'group'
|
* tree - generate a Blueprint from a data sheet grouped by a column called 'group'
|
||||||
* The resource name defaults to 'groups', or a custom resource name can be passed.
|
* The resource name defaults to 'groups', or a custom resource name can be passed.
|
||||||
* Each resource item is an object with values labelled according to column
|
* Each resource item is an object with values labelled according to column
|
||||||
* names. Items are inserted in the data list at idx = id.
|
* names. Items are inserted in the data list at idx = id.
|
||||||
@@ -12,7 +12,7 @@ import { defaultBlueprint, defaultRoute } from '../lib/blueprinters'
|
|||||||
* @param {type} name="" name of blueprint.
|
* @param {type} name="" name of blueprint.
|
||||||
* @return {type} Blueprint
|
* @return {type} Blueprint
|
||||||
*/
|
*/
|
||||||
export default function byTree (
|
export default function tree (
|
||||||
tabName,
|
tabName,
|
||||||
sheetName,
|
sheetName,
|
||||||
sheetId,
|
sheetId,
|
||||||
@@ -28,7 +28,7 @@ export default function byTree (
|
|||||||
bp.name = tabName
|
bp.name = tabName
|
||||||
|
|
||||||
// Column names define resources
|
// Column names define resources
|
||||||
bp.resources[label] = R.clone(defaultRoute)
|
bp.resources[label] = R.clone(defaultResource)
|
||||||
bp.resources[label].data = {}
|
bp.resources[label].data = {}
|
||||||
|
|
||||||
const tree = {
|
const tree = {
|
||||||
@@ -48,7 +48,14 @@ class Fetcher {
|
|||||||
*/
|
*/
|
||||||
this.blueprints = this._indexDbForBlueprints()
|
this.blueprints = this._indexDbForBlueprints()
|
||||||
.then(allUrls => {
|
.then(allUrls => {
|
||||||
const supportedUrls = allUrls.filter(url => url.startsWith(this.id))
|
const allParts = allUrls.reduce((acc, url) => {
|
||||||
|
if (url.startsWith(this.id)) {
|
||||||
|
const parts = url.split('/')
|
||||||
|
acc.push([ parts[1], parts[2] ])
|
||||||
|
return acc
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
console.log(allParts)
|
||||||
return {}
|
return {}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
|
import R from 'ramda'
|
||||||
|
|
||||||
export const defaultBlueprint = {
|
export const defaultBlueprint = {
|
||||||
name: null,
|
name: null,
|
||||||
@@ -8,13 +9,17 @@ export const defaultBlueprint = {
|
|||||||
resources: {}
|
resources: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultRoute = {
|
export const defaultResource = {
|
||||||
options: {
|
options: {
|
||||||
fragment: true
|
fragment: true
|
||||||
},
|
},
|
||||||
data: []
|
data: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function buildDesaturated (tab, resource) {
|
||||||
|
const bp = R.clone(defaultBlueprint)
|
||||||
|
}
|
||||||
|
|
||||||
// import all default exports from 'blueprinters' folder
|
// import all default exports from 'blueprinters' folder
|
||||||
const allBps = {}
|
const allBps = {}
|
||||||
const REL_PATH_TO_BPS = '../blueprinters'
|
const REL_PATH_TO_BPS = '../blueprinters'
|
||||||
@@ -28,5 +33,5 @@ fs.readdirSync(normalizedPath).forEach(file => {
|
|||||||
// each file in blueprinters folder available for granular import from here.
|
// each file in blueprinters folder available for granular import from here.
|
||||||
module.exports = Object.assign({
|
module.exports = Object.assign({
|
||||||
defaultBlueprint,
|
defaultBlueprint,
|
||||||
defaultRoute
|
defaultResource
|
||||||
}, allBps)
|
}, allBps)
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import test from 'ava'
|
|||||||
import R from 'ramda'
|
import R from 'ramda'
|
||||||
import {
|
import {
|
||||||
defaultBlueprint,
|
defaultBlueprint,
|
||||||
defaultRoute,
|
defaultResource,
|
||||||
byColumn,
|
columns,
|
||||||
byRow
|
rows
|
||||||
} from '../src/lib/blueprinters'
|
} from '../src/lib/blueprinters'
|
||||||
|
|
||||||
const egInput1 = [
|
const egInput1 = [
|
||||||
@@ -23,32 +23,32 @@ test('defaultBlueprint exports', t => {
|
|||||||
t.deepEqual(expected, defaultBlueprint)
|
t.deepEqual(expected, defaultBlueprint)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('byColumn blueprinter generates expected output', t => {
|
test('columns blueprinter generates expected output', t => {
|
||||||
const actual = byColumn('eg ColumnBlueprint', 'egSheetName', 'egSheetId', egInput1)
|
const actual = columns('eg ColumnBlueprint', 'egSheetName', 'egSheetId', egInput1)
|
||||||
const expected = R.clone(defaultBlueprint)
|
const expected = R.clone(defaultBlueprint)
|
||||||
expected.name = 'eg ColumnBlueprint'
|
expected.name = 'eg ColumnBlueprint'
|
||||||
expected.sheet = {
|
expected.sheet = {
|
||||||
id: 'egSheetId',
|
id: 'egSheetId',
|
||||||
name: 'egSheetName'
|
name: 'egSheetName'
|
||||||
}
|
}
|
||||||
expected.resources['h1'] = R.clone(defaultRoute)
|
expected.resources['h1'] = R.clone(defaultResource)
|
||||||
expected.resources['h1'].data = [1, 4]
|
expected.resources['h1'].data = [1, 4]
|
||||||
expected.resources['h2'] = R.clone(defaultRoute)
|
expected.resources['h2'] = R.clone(defaultResource)
|
||||||
expected.resources['h2'].data = [2, 5]
|
expected.resources['h2'].data = [2, 5]
|
||||||
expected.resources['h3'] = R.clone(defaultRoute)
|
expected.resources['h3'] = R.clone(defaultResource)
|
||||||
expected.resources['h3'].data = [3, 6]
|
expected.resources['h3'].data = [3, 6]
|
||||||
t.deepEqual(expected, actual)
|
t.deepEqual(expected, actual)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('byRow blueprinter generates expected output', t => {
|
test('rows blueprinter generates expected output', t => {
|
||||||
const actual = byRow('egRowBlueprint', 'egSheetName', 'egSheetId', egInput1, 'items')
|
const actual = rows('egRowBlueprint', 'egSheetName', 'egSheetId', egInput1, 'items')
|
||||||
const expected = R.clone(defaultBlueprint)
|
const expected = R.clone(defaultBlueprint)
|
||||||
expected.name = 'egRowBlueprint'
|
expected.name = 'egRowBlueprint'
|
||||||
expected.sheet = {
|
expected.sheet = {
|
||||||
id: 'egSheetId',
|
id: 'egSheetId',
|
||||||
name: 'egSheetName'
|
name: 'egSheetName'
|
||||||
}
|
}
|
||||||
expected.resources['items'] = R.clone(defaultRoute)
|
expected.resources['items'] = R.clone(defaultResource)
|
||||||
expected.resources['items'].data = [{
|
expected.resources['items'].data = [{
|
||||||
h1: 1,
|
h1: 1,
|
||||||
h2: 2,
|
h2: 2,
|
||||||
|
|||||||
Reference in New Issue
Block a user