FEATURE: User Directory, with sorting and time period filter

This commit is contained in:
Robin Ward
2015-03-16 15:14:33 -04:00
parent 6b85d5582c
commit 3d2d224312
47 changed files with 684 additions and 146 deletions

File diff suppressed because one or more lines are too long

View File

@@ -7,6 +7,10 @@ function parsePostData(query) {
return result;
}
function clone(obj) {
return JSON.parse(JSON.stringify(obj));
}
function response(code, obj) {
if (typeof code === "object") {
obj = code;
@@ -24,6 +28,11 @@ const _widgets = [
{id: 124, name: 'Evil Repellant'}
];
const _moreWidgets = [
{id: 223, name: 'Bass Lure'},
{id: 224, name: 'Good Repellant'}
];
export default function() {
const server = new Pretender(function() {
@@ -101,12 +110,23 @@ export default function() {
this.put('/widgets/:widget_id', function(request) {
const w = _widgets.findBy('id', parseInt(request.params.widget_id));
const cloned = JSON.parse(JSON.stringify(w));
return response({ widget: cloned });
return response({ widget: clone(w) });
});
this.get('/widgets', function() {
return response({ widgets: _widgets });
this.get('/widgets', function(request) {
let result = _widgets;
const qp = request.queryParams;
if (qp) {
if (qp.name) { result = result.filterBy('name', qp.name); }
if (qp.id) { result = result.filterBy('id', parseInt(qp.id)); }
}
return response({ widgets: result, total_rows_widgets: 4, load_more_widgets: '/load-more-widgets' });
});
this.get('/load-more-widgets', function() {
return response({ widgets: _moreWidgets, total_rows_widgets: 4, load_more_widgets: '/load-more-widgets' });
});
this.delete('/widgets/:widget_id', success);

View File

@@ -0,0 +1,8 @@
integration("User Directory");
test("Visit Page", function() {
visit("/directory/all");
andThen(function() {
ok(exists('.directory table tr'), "has a list of users");
});
});

View File

@@ -0,0 +1,28 @@
module('result-set');
import ResultSet from 'discourse/models/result-set';
import createStore from 'helpers/create-store';
test('defaults', function() {
const rs = ResultSet.create({ content: [] });
equal(rs.get('length'), 0);
equal(rs.get('totalRows'), 0);
ok(!rs.get('loadMoreUrl'));
ok(!rs.get('loading'));
ok(!rs.get('loadingMore'));
});
test('pagination support', function() {
const store = createStore();
store.findAll('widget').then(function(rs) {
equal(rs.get('length'), 2);
equal(rs.get('totalRows'), 4);
ok(rs.get('loadMoreUrl'), 'has a url to load more');
rs.loadMore().then(function() {
equal(rs.get('length'), 4);
ok(!rs.get('loadMoreUrl'));
});
});
});

View File

@@ -19,7 +19,20 @@ test('find', function() {
store.find('widget', 123).then(function(w2) {
equal(w, w2);
});
});
});
test('find with object id', function() {
const store = createStore();
store.find('widget', {id: 123}).then(function(w) {
equal(w.get('firstObject.name'), 'Trout Lure');
});
});
test('find with query param', function() {
const store = createStore();
store.find('widget', {name: 'Trout Lure'}).then(function(w) {
equal(w.get('firstObject.id'), 123);
});
});
@@ -33,7 +46,7 @@ test('update', function() {
test('findAll', function() {
const store = createStore();
store.findAll('widget').then(function(result) {
equal(result.length, 2);
equal(result.get('length'), 2);
const w = result.findBy('id', 124);
equal(w.get('name'), 'Evil Repellant');
});