Commit fb880432 by Jun Matsushita

Rendering json schema from gitlab works

parent 5c73a057
......@@ -2,7 +2,13 @@ doctype html
html
head
meta(charset='utf-8')
link#theme(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css')
title Open Integrity
body
#app
.container-fluid
.page-header
h1 Open Integrity Claim Submission
.row
.col-sm-12
#app
script(type='text/javascript', src='/app.bundle.js')
......@@ -29,9 +29,11 @@
"dependencies": {
"babel-polyfill": "^6.8.0",
"babel-runtime": "^6.5.0",
"isomorphic-fetch": "^2.2.1",
"ramda": "^0.21.0",
"react": "^15.0.2",
"react-dom": "^15.0.2",
"react-jsonschema-form": "^0.34.1",
"react-redux": "^4.0.0",
"redux": "^3.3.1",
"redux-elm": "^2.0.10",
......
button(onClick=click) Say Hi
require('isomorphic-fetch');
export const fetchSchema = measurement =>
fetch(
`https://lab.openintegrity.org/api/v3/projects/12/repository/files?file_path=technology/${measurement}.json&ref=2016-06-27-leif`,
{
headers: {
'PRIVATE-TOKEN': 'R6xWVJM9LbeFGDJT9-27'
}
}
)
.then(response => {
if (response.status > 400) {
throw new Error('Error while fetching from the server');
} else {
return response.json();
}
})
.then(json => JSON.parse(new Buffer(json.content, 'base64').toString('binary')));
div Hello World!
/* @flow */
import { Updater } from 'redux-elm';
import { takeEvery } from 'redux-saga';
import { call, put, select } from 'redux-saga/effects';
import * as Effects from './effects';
const getMeasurement = model => model.measurement;
function* fetchSchema() {
const measurement = yield select(getMeasurement);
const schema = yield call(Effects.fetchSchema, measurement);
yield put({ type: 'NewSchema', schema });
}
function* saga() {
yield* fetchSchema();
yield* takeEvery('Request', fetchSchema);
}
export const request = () => ({ type: 'Request' });
type topicModel = {
measurement: string,
schema: string
};
export const init = measurement => ({
measurement,
schema: null
});
const updater : Updater<topicModel> = new Updater(init('pseudonymity'), saga)
.case('NewSchema', (model, { schema }) => ({ ...model, schema: schema }))
.case('Request', model => ({ ...model, schema: null }));
export default updater.toReducer();
import React from 'react';
import { view } from 'redux-elm';
import Form from "react-jsonschema-form";
import hello from './hello.jade'
import button from './button.jade'
const schema = {};
const formData = {
title: "First task",
done: true
};
const renderSchema = schema => {
if (schema) {
return <Form schema={schema}
formData={formData}
onChange={log("changed")}
onSubmit={log("submitted")}
onError={log("errors")} />
} else {
return <img src="/assets/waiting.gif" width="200" height="200" />;
}
}
const log = (type) => console.log.bind(console, type);
export default view(({ model, dispatch }) => (
<div id="parent">
<div style={{ width: '200px' }}>
<h2 style={{ width: '200px', textAlign: 'center' }}>{model.measurement}</h2>
{renderSchema(model.schema)}
<button onClick={() => dispatch({ type: 'Request' })}>Get Schema!</button>
</div>
</div>
));
......@@ -6,7 +6,7 @@ type appModel = {
greeted: boolean
};
const initialModel = {
export const initialModel = {
greeted: false
};
......
......@@ -5,8 +5,7 @@ import hello from './hello.jade'
import button from './button.jade'
export default view(({ model, dispatch }) => {
console.log(model)
if (model && model.greeted) {
if (model.greeted) {
return hello();
} else {
return button({
......
import { Updater } from 'redux-elm';
import helloUpdater, { initialModel as helloInitialModel } from './hello-world/updater';
import claimsUpdater, { init as claimsInitialModel } from './claims/updater';
console.log(helloInitialModel)
console.log(claimsInitialModel)
export const initialModel = {
hello: helloInitialModel
hello: helloInitialModel,
claims: claimsInitialModel('pseudonymity')
};
export default new Updater(initialModel)
.case('Hello', (model, ...rest) => ({ ...model, hello: helloUpdater(model.hello, ...rest) }))
.case('Claims', (model, ...rest) => ({ ...model, claims: claimsUpdater(model.claims, ...rest) }))
.toReducer();
......@@ -2,9 +2,12 @@ import React from 'react';
import { view, forwardTo } from 'redux-elm';
import Hello from './hello-world/view';
import Claims from './claims/view';
export default view(({ model, dispatch }) => (
<div>
Hello: <Hello model={model.hello} dispatch={forwardTo(dispatch, 'Hello')} />
<br/>
Claim <Claims model={model.claims} dispatch={forwardTo(dispatch, 'Claims')} />
</div>
));
......@@ -6,6 +6,7 @@ module.exports = {
target: 'web',
devtool: 'sourcemap',
plugins: [
new webpack.IgnorePlugin(/^(buffertools)$/), // unwanted "deeper" dependency
new webpack.NoErrorsPlugin()
],
entry: [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment