Skip to content
This repository has been archived by the owner on Apr 1, 2022. It is now read-only.

Commit

Permalink
purify data in _mockData, in-out
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Berkeley committed Jun 6, 2017
1 parent b635c41 commit b4d9e2a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions examples/dist/client.dc2c7a28.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion examples/dist/client.ed009e18.css

This file was deleted.

4 changes: 2 additions & 2 deletions examples/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<title>Vue 2 Datatable Examples</title>
<link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<link href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="client.ed009e18.css" rel="stylesheet"></head>
<link href="client.dc2c7a28.css" rel="stylesheet"></head>
<body>

<div id="app"></div>

<script src="//cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script type="text/javascript" src="client.d8db49e4.js"></script></body>
<script type="text/javascript" src="client.e3ba39eb.js"></script></body>
</html>
17 changes: 17 additions & 0 deletions examples/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
</div>
</div>
</div>

<footer>
Open Devtools - Console to see what Datatable send and receive
</footer>
</div>
</template>
<script>
Expand All @@ -65,6 +69,19 @@ export default {
}
</script>
<style>
html {
position: relative;
min-height: 100%;
}
footer {
position: absolute;
left: 0;
right: 0;
bottom: 0;
padding: 5px 0;
text-align: center;
color: #afafaf;
}
.m-t-10 {
margin-top: 10px;
}
Expand Down
13 changes: 7 additions & 6 deletions examples/src/_mockData/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import moment from 'moment'
import orderBy from 'lodash/orderBy'
import users from './dataSource'
const typeOf = o => Object.prototype.toString.call(o).slice(8, -1).toLowerCase()
const purify = o => JSON.parse(JSON.stringify(o)) // purify data

/**
* mockData - simulate Ajax request and respond
* @param {Object} query
* @resolve {Object}
*/
export default function mockData(query) {
// default query fields
const { limit = 10, offset = 0, sort = '', order = 'asc' } = query
query = purify(query)
const { limit = 10, offset = 0, sort = '', order = '' } = query

let rows = users;

Expand All @@ -33,18 +34,18 @@ export default function mockData(query) {
if (sort) rows = orderBy(rows, sort, order)

const res = {
rows: JSON.parse(JSON.stringify(rows.slice(offset, offset + limit))), // purify data
rows: rows.slice(offset, offset + limit),
total: rows.length,
summary: {
name: rows.length,
age: rows.length && ~~(rows.map(({ age }) => age).reduce((sum, cur) => sum + cur) / rows.length) // average age
}
}

const consoleGroupName = 'Mock data generator - ' + moment().format('YYYY-MM-DD HH:mm:ss')
const consoleGroupName = 'Mock data - ' + moment().format('YYYY-MM-DD HH:mm:ss')
console.group(consoleGroupName)
console.info('Receive:', JSON.stringify(query))
console.info('Receive:', query)
console.info('Respond:', res)
console.groupEnd(consoleGroupName)
return Promise.resolve(res)
return Promise.resolve(purify(res))
}

0 comments on commit b4d9e2a

Please sign in to comment.