From a56df46fecfba7e5c07ff7b8dedbcfb9ea2ce045 Mon Sep 17 00:00:00 2001 From: Hermann <blumh@student.ethz.ch> Date: Thu, 3 May 2018 22:38:56 +0200 Subject: [PATCH] attempt for dynamical config based on the environment we want to build for --- src/auth.js | 13 ++--- src/events/newEvent.js | 2 +- src/events/table.js | 2 +- src/events/viewEvent.js | 3 +- src/groups/groupModal.js | 16 +++++++ src/networkConfig.json | 5 ++ src/networkConfig.prod.json | 5 ++ src/resourceConfig.json | 94 +++++++++++++++++++++++++++++++++++++ src/users/userTool.js | 2 +- src/users/viewUser.js | 2 +- src/views/editView.js | 2 +- webpack.config.js | 6 +++ webpack.config.prod.js | 4 ++ 13 files changed, 144 insertions(+), 12 deletions(-) create mode 100644 src/groups/groupModal.js create mode 100644 src/networkConfig.json create mode 100644 src/networkConfig.prod.json create mode 100644 src/resourceConfig.json diff --git a/src/auth.js b/src/auth.js index 1650702..9e782b7 100644 --- a/src/auth.js +++ b/src/auth.js @@ -1,8 +1,9 @@ import m from 'mithril'; import axios from 'axios'; import ClientOAuth2 from 'client-oauth2'; +import { apiUrl, ownUrl, oAuthID } from 'networkConfig'; import * as localStorage from './localStorage'; -import config from './config.json'; +import config from './resourceConfig.json'; // Object which stores the current login-state const APISession = { @@ -12,9 +13,9 @@ const APISession = { // OAuth Handler const oauth = new ClientOAuth2({ - clientId: 'Local Tool', - authorizationUri: `${config.apiUrl}/oauth`, - redirectUri: 'http://localhost:9000/oauthcallback', + clientId: oAuthID, + authorizationUri: `${apiUrl}/oauth`, + redirectUri: `${ownUrl}/oauthcallback`, }); export function resetSession() { @@ -25,7 +26,7 @@ export function resetSession() { } const amivapi = axios.create({ - baseURL: config.apiUrl, + baseURL: apiUrl, timeout: 10000, headers: { 'Content-Type': 'application/json' }, }); @@ -73,7 +74,7 @@ export function getSession() { return new Promise((resolve) => { checkAuthenticated().then(() => { const authenticatedSession = axios.create({ - baseURL: config.apiUrl, + baseURL: apiUrl, timeout: 10000, headers: { 'Content-Type': 'application/json', diff --git a/src/events/newEvent.js b/src/events/newEvent.js index c071f5e..0dec08e 100644 --- a/src/events/newEvent.js +++ b/src/events/newEvent.js @@ -1,9 +1,9 @@ import m from 'mithril'; import { RaisedButton, RadioGroup, Slider } from 'polythene-mithril'; import { styler } from 'polythene-core-css'; +import { apiUrl } from 'networkConfig'; import EditView from '../views/editView'; import { fileInput } from '../views/elements'; -import { apiUrl } from '../config.json'; const style = [ { diff --git a/src/events/table.js b/src/events/table.js index c913134..8e49de9 100644 --- a/src/events/table.js +++ b/src/events/table.js @@ -1,5 +1,5 @@ import m from 'mithril'; -import { events as config } from '../config.json'; +import { events as config } from '../resourceConfig.json'; import TableView from '../views/tableView'; import DatalistController from '../listcontroller'; import { dateFormatter } from '../utils'; diff --git a/src/events/viewEvent.js b/src/events/viewEvent.js index a551dff..0be005a 100644 --- a/src/events/viewEvent.js +++ b/src/events/viewEvent.js @@ -7,8 +7,9 @@ import { Icon, } from 'polythene-mithril'; import { styler } from 'polythene-core-css'; +import { apiUrl } from 'networkConfig'; import ItemView from '../views/itemView'; -import { apiUrl, eventsignups as signupConfig } from '../config.json'; +import { eventsignups as signupConfig } from '../resourceConfig.json'; import TableView from '../views/tableView'; import DatalistController from '../listcontroller'; import { dateFormatter } from '../utils'; diff --git a/src/groups/groupModal.js b/src/groups/groupModal.js new file mode 100644 index 0000000..c63b205 --- /dev/null +++ b/src/groups/groupModal.js @@ -0,0 +1,16 @@ +import m from 'mithril'; +import viewGroup from './viewGroup'; +import newGroup from './newGroup'; + +export default class EventModal { + constructor() { + this.edit = false; + } + + view() { + if (this.edit) { + return m(newGroup); + } + return m(viewGroup, { onEdit: () => { this.edit = true; } }); + } +} diff --git a/src/networkConfig.json b/src/networkConfig.json new file mode 100644 index 0000000..5b8bbd1 --- /dev/null +++ b/src/networkConfig.json @@ -0,0 +1,5 @@ +{ + "apiUrl": "https://api-dev.amiv.ethz.ch", + "ownUrl": "http://localhost:9000", + "oAuthID": "Local Tool" +} diff --git a/src/networkConfig.prod.json b/src/networkConfig.prod.json new file mode 100644 index 0000000..04d8931 --- /dev/null +++ b/src/networkConfig.prod.json @@ -0,0 +1,5 @@ +{ + "apiUrl": "https://api-dev.amiv.ethz.ch", + "ownUrl": "https://amiv-admin.amiv.ethz.ch", + "oAuthID": "Admintools Beta" +} diff --git a/src/resourceConfig.json b/src/resourceConfig.json new file mode 100644 index 0000000..5a8bdf3 --- /dev/null +++ b/src/resourceConfig.json @@ -0,0 +1,94 @@ +{ + "apiUrl": "https://api-dev.amiv.ethz.ch/", + "events": { + "keyDescriptors": { + "title_de": "German Title", + "title_en": "English Title", + "location": "Location", + "show_website": "Event is shown on the website", + "priority": "Priority", + "time_end": "Ending time", + "time_register_end": "Deadline for registration", + "time_start": "Starting time", + "spots": "Spots available", + "allow_email_signup": "Event open for non-AMIV members", + "price": "Price", + "signup_count": "Signed-up participants", + "catchphrase_en": "Catchphrase in English. Announce and Website.", + "catchphrase_de": "Schlagwort auf Deutsch", + "description_de": "Beschreibung auf Deutsch", + "description_en": "Description in English", + "img_banner": "Banner as png", + "img_poster": "Poster as png", + "img_thumbnail": "Thumbnail as png", + "show_infoscreen": "Does the event show on the infoscreen?", + "img_infoscreen": "Infoscreen as png", + "time_advertising_end": "Advertisment ends on", + "time_advertising_start": "Advertisement starts on", + "selection_strategy": "TODO what is this?", + "show_announce": "Does it belong to announce?", + "_id": "TODO Event ID how is this generated?" + }, + "tableKeys": [ + "title_de", + "time_start", + "time_end", + "time_register_end", + "show_website", + "priority" + ], + "notPatchableKeys": [ + "signup_count" + ] + }, + "users": { + "keyDescriptors": { + "legi": "Legi Number", + "firstname": "First Name", + "lastname": "Last Name", + "rfid": "RFID", + "phone": "Phone", + "nethz": "nethz Account", + "gender": "Gender", + "department": "Department", + "email": "Email" + }, + "tableKeys": [ + "firstname", + "lastname", + "nethz", + "legi", + "membership" + ], + "searchKeys": [ + "firstname", + "lastname", + "nethz", + "legi", + "department" + ], + "notPatchableKeys": [ + "password_set" + ] + }, + "groups": { + "keyDescriptors": { + "name": "Name" + }, + "searchKeys": ["name"], + "patchableKeys": ["name"] + }, + "groupmemberships": { + "patchableKeys": ["user", "group"] + }, + "eventsignups": { + "patchableKeys": ["event"], + "tableKeys": [ + "_created", + "user.lastname", + "user.firstname", + "email" + ], + "searchKeys": [] + } +} diff --git a/src/users/userTool.js b/src/users/userTool.js index 5d8010f..da312a3 100644 --- a/src/users/userTool.js +++ b/src/users/userTool.js @@ -2,7 +2,7 @@ import m from 'mithril'; import UserEdit from './editUser'; import UserView from './viewUser'; import TableView from '../views/tableView'; -import { users as config } from '../config.json'; +import { users as config } from '../resourceConfig.json'; import DatalistController from '../listcontroller'; export class NewUser extends UserEdit { diff --git a/src/users/viewUser.js b/src/users/viewUser.js index 46754e3..f8ca87e 100644 --- a/src/users/viewUser.js +++ b/src/users/viewUser.js @@ -2,7 +2,7 @@ import m from 'mithril'; import ItemView from '../views/itemView'; import TableView from '../views/tableView'; import SelectList from '../views/selectList'; -import { users as config } from '../config.json'; +import { users as config } from '../resourceConfig.json'; import DatalistController from '../listcontroller'; export default class UserView extends ItemView { diff --git a/src/views/editView.js b/src/views/editView.js index 04fbcc8..ec72d74 100644 --- a/src/views/editView.js +++ b/src/views/editView.js @@ -1,7 +1,7 @@ import Ajv from 'ajv'; import { Checkbox } from 'polythene-mithril'; +import { apiUrl } from 'networkConfig'; import ItemView from './itemView'; -import { apiUrl } from '../config.json'; import { textInput, datetimeInput, numInput } from './elements'; const m = require('mithril'); diff --git a/webpack.config.js b/webpack.config.js index 5853b51..b46e4fb 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -78,7 +78,13 @@ const config = { ], }, ], + }, + // Dynamically include config + resolve: { + alias: { + networkConfig: `${__dirname}/src/networkConfig.json`, + }, }, devtool: 'eval-source-map', // Default development sourcemap diff --git a/webpack.config.prod.js b/webpack.config.prod.js index 3017e2f..2f2029f 100644 --- a/webpack.config.prod.js +++ b/webpack.config.prod.js @@ -21,4 +21,8 @@ config.plugins = [ }), ]; +// Replace development with production config +config.resolve.alias.config = `${__dirname}/config.${process.env.BUILD_CONFIG_POSTFIX}.js`; + + module.exports = config; -- GitLab