Commit 4dd80b5d authored by zhiyan's avatar zhiyan

增加淘车站点

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