diff --git a/.gitignore b/.gitignore index 6674d05..0426581 100755 --- a/.gitignore +++ b/.gitignore @@ -7,12 +7,9 @@ .env *service-account-key\.json -src/config.js /yarn-error.log *.pem .travis.yml.old tags tags.lock tags.temp - -src/sheets_config.js diff --git a/Dockerfile b/Dockerfile index 794700d..3297bc6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ RUN cd /www; yarn COPY . /www WORKDIR /www RUN yarn build -RUN mkdir -p temp +RUN mkdir -p data # set your port ENV PORT 8080 diff --git a/README.md b/README.md index 79bb4a8..81269cb 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ Other configuration options, such as the port at which the server will expose resources, are also modifiable from the .env file. #### [Sources](#sources) -Sources are specified in [src/sheets_config.js](https://github.com/forensic-architecture/datasheet-server/blob/develop/src/sheets_config.js). Datasheet server currently only supports Google Sheets as a source. +Sources are specified in [src/config.js](https://github.com/forensic-architecture/datasheet-server/blob/develop/src/config.js). Datasheet server currently only supports Google Sheets as a source. ###### [Google Sheets](#source-google-sheets) | sheets | A list of objects, one for each sheet that is being used as a source. Each sheet object has a `name` (String), an `id` (String), and a `tabs` (object) field, which are explained below. | object | diff --git a/data/.gitignore b/data/.gitignore new file mode 100644 index 0000000..8a7b0fd --- /dev/null +++ b/data/.gitignore @@ -0,0 +1,3 @@ +* +!.gitignore +!timemap_data.xlsx diff --git a/data/timemap_data.xlsx b/data/timemap_data.xlsx new file mode 100644 index 0000000..0f6bce5 Binary files /dev/null and b/data/timemap_data.xlsx differ diff --git a/docs/architecture.md b/docs/architecture.md index 96b39f0..4bde5bf 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -8,10 +8,10 @@ management of the sheets it represents. It exposes an API with four endpoints: * `/:sheet/:tab/:resource` - the primary means of accessing data in the server. The name of a sheet is specified in - [sheets_config.js](https://github.com/forensic-architecture/datasheet-server/blob/develop/src/sheets_config.js#L7). + [_config.js](https://github.com/forensic-architecture/datasheet-server/blob/develop/src/config.js#L7). Each tab on the sheet is in lower case, with spaces replaced by underscores. The resource name is the same as the name of the blueprinter - specified for the tab is sheets_config.js. + specified for the tab is config.js. * `/:sheet/:tab/:resource/:id` - when the resource is a list, items in the list can be accessed individually as well. * `/update` - when this route is queried with a GET request, each of the diff --git a/src/config.js b/src/config.js new file mode 100644 index 0000000..bb33ef8 --- /dev/null +++ b/src/config.js @@ -0,0 +1,12 @@ +import { tabs, prefixedTabs } from './lib' + +export default { + gsheets: [], + xlsx: [ + { + name: 'timemap_data', + path: 'data/timemap_data.xlsx', + tabs + } + ] +} diff --git a/src/index.js b/src/index.js index 3352614..ab969e9 100755 --- a/src/index.js +++ b/src/index.js @@ -3,7 +3,6 @@ import express from 'express' import initialize from './initialize' import middleware from './middleware' import api from './api' -// import config from './sheets_config' import dotenv from 'dotenv' const hbs = require('express-handlebars') @@ -41,6 +40,8 @@ initialize(controller => { }) ) + app.use(express.static(__dirname + '/public')) + app.server.listen(process.env.PORT || 4040, () => { console.log('===========================================') console.log(`Server running on port ${app.server.address().port}`) diff --git a/src/initialize.js b/src/initialize.js index f3c3d43..44e59bf 100755 --- a/src/initialize.js +++ b/src/initialize.js @@ -1,7 +1,7 @@ import StoreJson from './models/StoreJson' import fetchers from './lib/Fetcher' import Controller from './lib/Controller' -import config from './sheets_config' +import config from './config' import R from 'ramda' const isntNull = n => n !== null diff --git a/src/lib.js b/src/lib.js new file mode 100644 index 0000000..7a488ae --- /dev/null +++ b/src/lib.js @@ -0,0 +1,21 @@ +import BP from './lib/blueprinters' + +export function prefixedTabs (prefix) { + return { + [`${prefix}_export_events`]: BP.deeprows, + [`${prefix}_export_categories`]: [BP.groups, BP.rows], + [`${prefix}_export_filters`]: BP.tree, + [`${prefix}_export_narratives`]: BP.rows, + [`${prefix}_export_sources`]: BP.deepids, + [`${prefix}_export_sites`]: BP.rows + } +} + +export const tabs = { + export_events: BP.deeprows, + export_categories: [BP.groups, BP.rows], + export_filters: BP.tree, + export_narratives: BP.rows, + export_sources: BP.deepids, + export_sites: BP.rows +} diff --git a/src/models/StoreJson.js b/src/models/StoreJson.js index 72ca593..07390c8 100644 --- a/src/models/StoreJson.js +++ b/src/models/StoreJson.js @@ -1,7 +1,7 @@ import fs from 'mz/fs' import errors from '../lib/errors' -const STORAGE_DIRNAME = 'temp' +const STORAGE_DIRNAME = 'data' function partsFromFilename (fname) { const body = fname.slice(0, -5) diff --git a/src/sheets_config.js b/src/sheets_config.js deleted file mode 100644 index c27cef0..0000000 --- a/src/sheets_config.js +++ /dev/null @@ -1,46 +0,0 @@ -import BP from './lib/blueprinters' - -const timemapStructure = { - export_events: BP.deeprows, - export_categories: [BP.groups, BP.rows], - export_narratives: BP.rows, - export_sources: BP.deepids, - export_sites: BP.rows, - export_tags: BP.tree -} - -const treatyStructure = { - treaty_export_events: BP.deeprows, - treaty_export_categories: [BP.groups, BP.rows], - export_narratives: BP.rows, - treaty_export_sources: BP.deepids, - export_sites: BP.rows, - export_tags: BP.tree -} - -const moraldriftStructure = { - moraldrift_export_events: BP.deeprows, - moraldrift_export_categories: [BP.groups, BP.rows], - moraldrift_export_narratives: BP.rows, - moraldrift_export_sources: BP.deepids, - moraldrift_export_sites: BP.rows, - moraldrift_export_tags: BP.tree - -} - -export default { - gsheets: [{ - name: 'example', - id: '1UC7DkCFeUXHfpUxUGruExwFbP4pqVBdJLOKfo6wDDGk', - tabs: timemapStructure, - }], - - - xlsx: [ - /** { - name: 'my_local_sheet', - tabs: timemapStructure, - path: 'temp/my_local_sheet.xlsx' - } **/ - ] -} diff --git a/temp/.gitignore b/temp/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/temp/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore