Skip to content

Commit

Permalink
chore: support view setting
Browse files Browse the repository at this point in the history
  • Loading branch information
xudafeng committed Jan 19, 2019
1 parent c43dff6 commit e61a704
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 16 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ coverage
view
app/controller/app.js
docs_dist
public/
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
logs/
npm-debug.log
yarn-error.log
node_modules/
package-lock.json
yarn.lock
coverage/
.nyc_output
docs_dist/
.idea/
.vscode/
app/public/**/*.js
app/public/**/*.css
view/public/
run/
.DS_Store
*.sw*
Expand Down
3 changes: 2 additions & 1 deletion app/controller/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class HomeController extends Controller {
const ctx = this.ctx;
const user = ctx.session.user;
const { appid, callbackUrl } = ctx.app.config.authorize.dingtalkAuth;
const { data: configRes } = await this.ctx.model.Config.findOne({ raw: true });
ctx.body = await this.app.render({
dingtalkAuth: {
appid,
Expand All @@ -19,7 +20,7 @@ class HomeController extends Controller {
title: 'Reliable Suites for Macaca',
pageId: 'home',
SERVER_ADDRESS: this.config.reliableView.serverUrl,
assetsUrl: this.config.reliableView.assetsUrl,
assetsUrl: configRes.site.assetsUrl || this.config.reliableView.assetsUrl,
version: this.app.config.pkg.version,
});
}
Expand Down
6 changes: 4 additions & 2 deletions test/fixtures/config-data.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"type": "webhooks",
"webhooks": [
{
"tag": "build",
"url": "https://localhost"
}
]
],
"site": {
"assetsUrl": ""
}
}
3 changes: 1 addition & 2 deletions view/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
**/.*
**/node_modules
**/dist
**/public
**/assets
**/coverage
**/reports

11 changes: 5 additions & 6 deletions view/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
{
"name": "reliable-view",
"version": "",
"version": "1.0.1",
"description": "view layer for Reliable",
"files": [
"dist/*.js",
"dist/*.css",
"lib/*.js",
"index.html"
"public/*.js",
"public/*.css"
],
"links": {
"issues": "https://github.com/macacajs/reliable/issues?utf8=%E2%9C%93&q=",
Expand All @@ -19,8 +17,9 @@
"test": "macaca run -d ./test",
"lint": "eslint --fix . --ext jsx,js && stylelint --fix assets/**/*.less -s less",
"build": "NODE_ENV=production webpack -p --mode production",
"build:local": "DIST_DIR=./public npm run build",
"build:report": "npm run build --report",
"prepublishOnly": "npm run build",
"prepublishOnly": "npm run build:local",
"ci": "npm run lint && npm run build && npm run serve && npm test"
},
"precommit": [
Expand Down
1 change: 0 additions & 1 deletion view/src/components/DingdingSetting.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class DingdingSetting extends React.Component {

postWebhooks = async (webhooks) => {
const res = await request('postWebhooks', 'POST', {
type: 'webhooks',
webhooks,
});
if (res.success) {
Expand Down
114 changes: 114 additions & 0 deletions view/src/components/SiteSetting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
'use strict';

import React from 'react';
import safeGet from 'lodash.get';
import { FormattedMessage } from 'react-intl';
import {
Form,
Icon,
Spin,
Input,
Button,
Select,
message,
} from 'antd';

import request from '../util/request';

const FormItem = Form.Item;
const Option = Select.Option;

const siteConfigFormItemLayout = {
wrapperCol: {
xs: { span: 24 },
sm: { offset: 4, span: 16 },
},
};
const buttonFormItemLayout = {
wrapperCol: {
xs: { span: 24 },
sm: { offset: 10, span: 4 },
},
};

class SiteSetting extends React.Component {
state = {
}

componentDidMount () {
this.fetchSite();
}

fetchSite = async () => {
this.setState({ loading: true });
const res = await request('getSite', 'GET');
this.setState({ loading: false });
if (!res.success) return;

const siteConfig = safeGet(res, 'data.site');
this.setState({
siteConfig,
});
}

postSite = async (siteConfig) => {
const res = await request('postSite', 'POST', {
site: siteConfig,
});
if (res.success) {
await this.fetchSite();
message.success('Update siteConfig successfully!');
} else {
message.error('Update siteConfig failed.');
console.error('postSite', res);
}
}

updateSite = () => {
this.props.form.validateFields((err, values) => {
if (err) return;
this.postSite(values);
});
}

renderSiteConfig = () => {
const { getFieldDecorator } = this.props.form;
const assetsUrl = safeGet(this.state, 'siteConfig.assetsUrl');
return (
<div>
<Form.Item
{...siteConfigFormItemLayout}
>
{getFieldDecorator('assetsUrl', {
initialValue: assetsUrl,
})(
<Input />
)}
</Form.Item>
<Form.Item {...buttonFormItemLayout}>
<Button
style={{ width: '100%' }}
type="primary"
htmlType="submit"
onClick={this.updateSite}
>
<FormattedMessage id='setting.submit' />
</Button>
</Form.Item>
</div>
);
}

render () {
return (
<Form>
<Spin spinning={this.state.loading}>
{this.renderSiteConfig()}
</Spin>
</Form>
);
}
}

export default Form.create()(SiteSetting);

1 change: 1 addition & 0 deletions view/src/i18n/en_US.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {
'setting.submit': 'Update',
'setting.versioning': 'Version Info',
'setting.notification.build': 'Build',
'setting.site': 'Site Config',

'builds.buildNumber': 'Build Number',
'builds.buildLog': 'Build Log',
Expand Down
1 change: 1 addition & 0 deletions view/src/i18n/zh_CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default {
'setting.submit': '更新设置',
'setting.versioning': '版本信息',
'setting.notification.build': '构建',
'setting.site': '站点设置',

'builds.buildNumber': '构建号',
'builds.buildLog': '构建日志',
Expand Down
8 changes: 8 additions & 0 deletions view/src/page/Setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
} from 'antd';

import ReliableLayout from '../components/ReliableLayout';
import SiteSetting from '../components/SiteSetting';
import DingdingSetting from '../components/DingdingSetting';

import pkg from '../../package.json';
Expand Down Expand Up @@ -38,6 +39,13 @@ export default class Setting extends React.Component {
</Col>
</Row>
</Card>
<Card style={{ marginTop: 10 }} title={<FormattedMessage id='setting.site' />}>
<Row>
<Col>
<SiteSetting />
</Col>
</Row>
</Card>
<Card style={{ marginTop: 10 }} title={<FormattedMessage id='setting.versioning' />}>
<Row>
<Col>
Expand Down
4 changes: 4 additions & 0 deletions view/src/util/getServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,9 @@ export const getServer = (url, param) => {
return `${SERVER_ADDRESS}/api/config`;
}

if (url === 'getSite' || url === 'postSite') {
return `${SERVER_ADDRESS}/api/config`;
}

return `${SERVER_ADDRESS}/api/delegate/message`;
};
6 changes: 5 additions & 1 deletion view/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPl

const pkg = require('./package');

const {
DIST_DIR,
} = process.env;

module.exports = (env, argv) => {
const isProduction = argv.mode === 'production';

Expand All @@ -27,7 +31,7 @@ module.exports = (env, argv) => {
},

output: {
path: path.join(__dirname, '..', 'app', 'public'),
path: DIST_DIR ? path.resolve(DIST_DIR) : path.join(__dirname, '..', 'app', 'public'),
publicPath: 'public',
filename: '[name].js',
},
Expand Down

0 comments on commit e61a704

Please sign in to comment.