Commit 4dd80b5d authored by zhiyan's avatar zhiyan

增加淘车站点

parent 675debe8
'use strict';
const fs = require('fs')
const express = require('express')
const bodyParser = require('body-parser')
const low = require('lowdb')
const exec = require('child_process').exec
const db = low('./usage.json')
const usageFilePath = './usage.json'
try {
fs.statSync(usageFilePath).isFile()
} catch (e) {
fs.writeFileSync(usageFilePath, fs.readFileSync(usageFilePath.replace('.json', '_default.json')))
}
const db = low(usageFilePath)
const app = express()
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
......@@ -41,12 +48,13 @@ app.all('/wiki/update', function(req, res){
})
app.post('/register', function(req, res){
const site = req.body.site
const machine = req.body.machine
const branch = req.body.branch
const project = req.body.project
if(machine && machine.length){
machine.forEach(machine => {
const source = db.get('machine').find({name: machine}).get('inUse')
const source = db.get('machine').get(site).find({name: machine}).get('inUse')
const item = source.find({branch})
if(item.value()){
......@@ -61,8 +69,9 @@ app.post('/register', function(req, res){
})
app.post('/unregister', function(req, res){
const site = req.body.site
const branch = req.body.branch
const machines = db.get('machine')
const machines = db.get('machine').get(site)
if(branch){
machines.value().forEach(machine => {
const source = machines.find({name: machine.name}).get('inUse')
......
{"machine":{"taoche":[{"name":"dev1","inUse":[]},{"name":"dev2","inUse":[]},{"name":"beta1","inUse":[]},{"name":"beta2","inUse":[]}],"daikuan":[{"name":"dev1","inUse":[]},{"name":"dev2","inUse":[]},{"name":"beta1","inUse":[]},{"name":"beta2","inUse":[]}]}}
\ No newline at end of file
......@@ -12,6 +12,10 @@
padding:20px 0;
font-size:30px;
}
body > h3{
width: 800px;
margin:40px auto 10px;
}
form,table{
width: 800px;
margin:0 auto;
......@@ -40,6 +44,16 @@
<form class="pure-form pure-form-stacked">
<fieldset>
<div class="pure-g">
<div class="pure-u-1 pure-u-md-1-3">
<label for="site">站点</label>
<label for="taoche" class="inline">
<input id="taoche" type="radio" name="site" class="site" checked value="taoche"> taoche
</label>
<label for="daikuan" class="inline">
<input id="daikuan" type="radio" name="site" class="site" value="daikuan"> daikuan
</label>
</div>
<div class="pure-u-1 pure-u-md-1-3">
<label for="branch">分支</label>
<input id="branch" class="pure-u-23-24" type="text" placeholder="master">
......@@ -74,6 +88,7 @@
</fieldset>
</form>
<h3>淘车</h3>
<table class="pure-table">
<thead>
<tr>
......@@ -83,7 +98,21 @@
</tr>
</thead>
<tbody id="list">
<tbody id="taoche-list">
</tbody>
</table>
<h3>贷款</h3>
<table class="pure-table">
<thead>
<tr>
<th width="100">测试机</th>
<th width="200">分支</th>
<th>项目</th>
</tr>
</thead>
<tbody id="daikuan-list">
</tbody>
</table>
......@@ -93,8 +122,6 @@
<script>
const getList = () => {
$.getJSON('/usage', res => {
let html = ''
const format = R.reduce((res, value) => `${res}<p>${value}</p>`, '')
const getBranches = R.pipe(
......@@ -108,17 +135,16 @@
format
)
res.machine.map((item, key) => {
html += `
const buildHtml = (item, key) => `
<tr class="${key%2 === 0 ? 'pure-table-odd' : ''}">
<td>${item.name}</td>
<td>${getBranches(item.inUse)}</td>
<td>${getProjects(item.inUse)}</td>
</tr>
`
})
$('#list').html(html)
$('#taoche-list').html(res.machine.taoche.reduce((html, item, key) => html + buildHtml(item, key), ''))
$('#daikuan-list').html(res.machine.daikuan.reduce((html, item, key) => html + buildHtml(item, key),''))
})
}
......@@ -128,7 +154,8 @@
return {
branch : $('#branch').val(),
project: ($('#project').val() || '').split('+'),
machine: R.reduce((res, input) => res.concat(input.name),[])($('.machine:checked'))
machine: R.reduce((res, input) => res.concat(input.name),[])($('.machine:checked')),
site: $('.site:checked').val()
}
}
......@@ -141,7 +168,7 @@
$.post('/register', params, res=>{
if(res.ret){
swal('注册使用成功', `分支: ${params.branch}\n项目: ${$('#project').val() || ''}`)
swal('注册使用成功', `站点: ${params.site}\n分支: ${params.branch}\n项目: ${$('#project').val() || ''}`)
getList()
}
})
......@@ -157,7 +184,7 @@
$.post('/unregister', params, res=>{
if(res.ret){
swal('解除使用成功', `分支: ${params.branch}`)
swal('解除使用成功', `站点: ${params.site}\n分支: ${params.branch}`)
getList()
}
})
......
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 to comment