Skip to content

Fixes LRS sorting. #585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions app/controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,12 @@ public function getGraphData(){
*/
public function lrs(){
$opts = ['user' => \Auth::user()];
$lrs = $this->lrs->index($opts);
if ($lrs) {
foreach ($lrs as $l) {
$l->statement_total = $this->statement->count($l->_id);
}
}
return Response::json($lrs);

$lrss = $this->lrs->index($opts);

return Response::json(array_map(function ($lrs) {
$lrs->statement_total = $this->statement->count($lrs->_id);
return $lrs;
}, $lrss));
}

public function apps() {
Expand Down
23 changes: 17 additions & 6 deletions app/locker/repository/Lrs/EloquentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ protected function validateData(array $data) {
* @return Model
*/
protected function constructStore(Model $model, array $data, array $opts) {
\Auth::user();
// Merges and validates data with defaults.
$data = array_merge(array_merge($this->defaults, $data), [
'api' => [
'basic_key' => Helpers::getRandomValue(),
'basic_secret' => Helpers::getRandomValue()
],
'owner' => [['_id'] => $opts['user']->_id],
'owner' => ['_id' => $opts['user']->_id],
'users' => [[
'_id' => $opts['user']->_id,
'email' => $opts['user']->email,
Expand All @@ -80,7 +79,7 @@ protected function constructStore(Model $model, array $data, array $opts) {
$model->owner = $data['owner'];
$model->users = $data['users'];

Event::fire('user.create_lrs', array('user' => $user));
Event::fire('user.create_lrs', ['user' => $opts['user']]);

return $model;
}
Expand Down Expand Up @@ -109,13 +108,25 @@ protected function constructUpdate(Model $model, array $data, array $opts) {
*/
public function index(array $opts) {
if ($opts['user']->role === 'super') {
return parent::index($opts);
$query = $this->where($opts);
} else {
$query = $this->where('users._id', $opts['user']->_id)->remember(10);
}

$query = $this->where('users._id', $opts['user']->_id)->remember(10);
return $query->get()->each(function (Model $model) {
$obj_result = $query->get()->sortBy(function (Model $model) {
return strtolower($model->title);
})->each(function (Model $model) {
return $this->format($model);
});

// Annoying hack to convert stupid Laravel collection object to an array
// WITHOUT converting the models to associative arrays!!!
$result = [];
foreach ($obj_result->getIterator() as $model) {
$result[] = $model;
}

return $result;
}

/**
Expand Down
9 changes: 8 additions & 1 deletion public/assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ table.break-words td, table.break-words th {
max-width: 100%;
}


/* Bootstrap extensions (note: looks like we're not using LESS?)
--------------------------------------------------------------*/
@media(max-width: 480px){
Expand All @@ -219,6 +218,14 @@ table.break-words td, table.break-words th {
}
}

@media(min-width: 768px) {
.nav .dropdown-menu {
max-height: 400px;
overflow-y: scroll;
overflow-x: hidden;
}
}