Skip to content

Commit

Permalink
add usingDuration filed
Browse files Browse the repository at this point in the history
  • Loading branch information
codeskyblue committed Apr 11, 2019
1 parent eca5092 commit 598addb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
16 changes: 13 additions & 3 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
</el-table-column>
<!-- <el-table-column prop="platform" label="类型"></el-table-column> -->
<el-table-column label="设备名" prop="prop_name"></el-table-column>
<el-table-column label="资产编号">
<el-table-column prop="prop_propertyId" sortable label="资产编号">
<template slot-scope="scope">
<!-- <el-input size="mini"></el-input> -->
<atx-edit-inline :readonly="!user.admin" :value="scope.row.prop_propertyId"
Expand All @@ -111,8 +111,13 @@
</template>
</template>
</el-table-column>
<el-table-column prop="prop_brand" label="品牌"></el-table-column>
<el-table-column prop="prop_version" label="Version"></el-table-column>
<!-- <el-table-column prop="prop_brand" label="品牌"></el-table-column> -->
<el-table-column prop="prop_version" sortable label="Version"></el-table-column>
<el-table-column prop="usingDuration" sortable label="使用时长">
<template slot-scope="scope">
{{!scope.row.usingDuration | formatDuration}}
</template>
</el-table-column>
</el-table>
</div>
{% end %}
Expand Down Expand Up @@ -235,6 +240,11 @@
fromNow(value) {
return moment(value).fromNow();
},
formatDuration(value) {
console.log(value)
let duration = moment.duration(value, "seconds")
return moment.utc(duration.asMilliseconds()).format("HH:mm:ss")
},
shortString(value) {
if (value.length > 16) {
return value.slice(0, 15) + "..."
Expand Down
14 changes: 11 additions & 3 deletions web/views/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class ReleaseError(Exception):

class APIDeviceListHandler(CorsMixin, BaseRequestHandler):
async def get(self):
reql = db.table_devices.without("sources", "source").order_by(
r.desc("createdAt"))
reql = db.table_devices.without("sources",
"source").order_by(r.desc("createdAt"))
if self.get_argument("platform", ""):
reql = reql.filter({"platform": self.get_argument("platform")})
if self.get_argument("usable", None): # 只查找能用的设备
Expand Down Expand Up @@ -427,8 +427,16 @@ async def release(self, email: Union[str, None]):
raise ReleaseError("device not exist")
if email and device.get('userId') != email:
raise ReleaseError("device is not owned by you")

# Update database
await self.update({
"using": False,
"userId": None,
"colding": True,
"usingDuration": r.row["usingDuration"].default(0).add(r.now().sub(r.row["usingBeganAt"]))
}) # yapf: disable

# 设备先要冷却一下(Provider清理并检查设备)
await self.update({"using": False, "userId": None, "colding": True})
source = device2source(device)
if not source: # 设备离线了
return
Expand Down

0 comments on commit 598addb

Please sign in to comment.