Skip to content
This repository has been archived by the owner on Feb 18, 2021. It is now read-only.

Commit

Permalink
adding server api
Browse files Browse the repository at this point in the history
  • Loading branch information
morsh committed Mar 23, 2017
1 parent c31db94 commit a585b28
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 19 deletions.
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "my-app",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:4000/",
"devDependencies": {
"@types/alt": "^0.16.32",
"@types/jest": "^19.2.2",
Expand All @@ -24,6 +25,7 @@
"lodash": "^4.17.4",
"material-colors": "^1.2.5",
"moment": "^2.18.0",
"morgan": "^1.8.1",
"react": "^15.4.2",
"react-addons-css-transition-group": "^15.4.2",
"react-addons-transition-group": "^15.4.2",
Expand All @@ -35,12 +37,12 @@
"xhr-request": "^1.0.1"
},
"scripts": {
"build-css": "node-sass src/ -o src/",
"watch-css": "yarn run build-css && node-sass src/ -o src/ --watch --recursive",
"start-js": "react-scripts-ts start",
"start": "npm-run-all -p watch-css start-js",
"build": "yarn run build-css && react-scripts-ts build",
"test": "react-scripts-ts test --env=jsdom",
"eject": "react-scripts-ts eject"
"css:build": "node-sass src/ -o src/",
"css:watch": "yarn run css:build && node-sass src/ -o src/ --watch --recursive",
"server:start": "node server",
"client:start": "react-scripts-ts start",
"start": "npm-run-all -p css:watch server:start client:start",
"build": "yarn run css:build && react-scripts-ts build",
"test": "react-scripts-ts test --env=jsdom"
}
}
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Roboto:300,400,500' />
<script type="text/javascript" src="/api/config.js"></script>
<!--
Notice the use of %PUBLIC_URL% in the tag above.
It will be replaced with the URL of the `public` folder during the build.
Expand Down
34 changes: 34 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// server/app.js
const express = require('express');
const morgan = require('morgan');
const path = require('path');
const fs = require('fs');

const app = express();

// Setup logger
app.use(morgan(':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] :response-time ms'));

// Serve static assets
app.use(express.static(path.resolve(__dirname, '..', 'build')));

app.get('/api/config.js', (req, res) => {
fs.readFile(path.join(__dirname, 'dashboards', 'bot-framework.js'), 'utf8', (err, data) => {
if (err) throw err;

// Ensuing this dashboard is loaded into the dashboards array on the page
data += `
window.dashboards = window.dashboards || [];
window.dashboards.push(dashboard);
`;

res.send(data);
});
});

// Always return the main index.html, so react-router render the route in the client
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, '..', 'build', 'index.html'));
});

module.exports = app;
13 changes: 4 additions & 9 deletions src/pages/temp.ts → server/dashboards/bot-framework.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import * as _ from 'lodash';
import colors from '../components/colors';

export default <IDashboardConfig>{
var dashboard = {
config: {
layout: {
isDraggable: true,
Expand Down Expand Up @@ -51,8 +48,8 @@ export default <IDashboardConfig>{
calculated: (state) => {
var { values } = state;

var total : any = _.find(values, { name: 'message.convert.start' });
var successful: any = _.find(values, { name: 'message.convert.end', successful: true }) || { event_count: 0 };
var total = _.find(values, { name: 'message.convert.start' });
var successful = _.find(values, { name: 'message.convert.end', successful: true }) || { event_count: 0 };

if (!total) {
return null;
Expand All @@ -71,7 +68,7 @@ export default <IDashboardConfig>{
type: 'ApplicationInsights/Query',
dependencies: { timespan: 'timespan', queryTimespan: 'timespan:queryTimespan', granularity: 'timespan:granularity' },
params: {
query: (dependencies: any) => {
query: (dependencies) => {
var { granularity } = dependencies;
return ` customEvents` +
` | where name == 'Activity'` +
Expand Down Expand Up @@ -191,7 +188,6 @@ export default <IDashboardConfig>{
title: 'Message Rate',
subtitle: 'How many messages were sent per timeframe',
size: { w: 5, h: 8},
theme: colors.ThemeColors2,
dependencies: { values: 'timeline:graphData', lines: 'timeline:channels', timeFormat: 'timeline:timeFormat' }
},
{
Expand Down Expand Up @@ -239,7 +235,6 @@ export default <IDashboardConfig>{
title: 'Conversion Rate',
subtitle: 'Total conversion rate',
size: { w: 4, h: 8},
theme: colors.ThemeColors2,
dependencies: { values: 'conversions:displayValues' },
props: {
pieProps: { nameKey: 'label', valueKey: 'count' }
Expand Down
10 changes: 10 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// server/index.js
'use strict';

const app = require('./app');

const PORT = process.env.PORT || 4000;

app.listen(PORT, () => {
console.log(`App listening on port ${PORT}!`);
});
5 changes: 3 additions & 2 deletions src/components/generic/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ export default class Table extends GenericComponent<ITableProps, ITableState> {
col.type === 'icon' ?
<FontIcon>{col.value || value[col.field]}</FontIcon> :
col.type === 'button' ?
<Button icon={true}
onClick={this.onButtonClick.bind(this, col, value)}>{col.value || value[col.field]}</Button> :
<Button
icon={true}
onClick={this.onButtonClick.bind(this, col, value)}>{col.value || value[col.field]}</Button> :
col.type === 'time' ?
moment(value[col.field]).format('MMM-DD HH:mm:ss') :
value[col.field]
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { DataSourceConnector, IDataSourceDictionary } from '../data-sources';
import ElementConnector from '../components/ElementConnector';
import { loadDialogsFromDashboard } from '../components/generic/Dialogs';

import dashboard from './temp';
var dashboards : IDashboardConfig = (window as any)["dashboards"];
var dashboard = dashboards[0];
const layout = dashboard.config.layout;

interface IDashboardState {
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ base64-js@^1.0.2:
version "1.2.0"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.0.tgz#a39992d723584811982be5e290bb6a53d86700f1"

basic-auth@~1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/basic-auth/-/basic-auth-1.1.0.tgz#45221ee429f7ee1e5035be3f51533f1cdfd29884"

[email protected]:
version "0.5.3"
resolved "https://registry.yarnpkg.com/batch/-/batch-0.5.3.tgz#3f3414f380321743bfc1042f9a83ff1d5824d464"
Expand Down Expand Up @@ -3053,6 +3057,16 @@ moment@^2.18.0:
version "2.18.0"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.18.0.tgz#6cfec6a495eca915d02600a67020ed994937252c"

morgan@^1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/morgan/-/morgan-1.8.1.tgz#f93023d3887bd27b78dfd6023cea7892ee27a4b1"
dependencies:
basic-auth "~1.1.0"
debug "2.6.1"
depd "~1.1.0"
on-finished "~2.3.0"
on-headers "~1.0.1"

[email protected]:
version "0.7.1"
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098"
Expand Down

0 comments on commit a585b28

Please sign in to comment.