Skip to content

Commit

Permalink
Merge branch 'master' into use-assertSame
Browse files Browse the repository at this point in the history
  • Loading branch information
lehecht authored Aug 22, 2024
2 parents 93554c6 + 99bbd57 commit 894c8f3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 15 deletions.
10 changes: 9 additions & 1 deletion app/Http/Controllers/Views/Admin/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class UsersController extends Controller
*/
public function get(Request $request)
{
$users = User::select('id', 'firstname', 'lastname', 'email', 'login_at', 'role_id', 'affiliation')
$users = User::select('id', 'firstname', 'lastname', 'email', 'login_at', 'created_at', 'role_id', 'affiliation')
->when($request->has('q'), function ($query) use ($request) {
$q = $request->get('q');
$query->where(function ($query) use ($q) {
Expand All @@ -32,6 +32,10 @@ public function get(Request $request)
->orWhere('email', 'ilike', "%$q%");
});
})
->when(
$request->get('recent'),
fn ($query) => $query->where('created_at', '>=', now()->subWeek())
)
// Orders by login_at in descending order (most recent first) but puts
// users with login_at=NULL at the end.
->orderByRaw('login_at IS NULL, login_at DESC')
Expand All @@ -44,11 +48,15 @@ public function get(Request $request)
Role::guestId() => 'Guest',
];

$usersCount = User::whereDate('created_at', '>=', now()->subWeek())
->count();

return view('admin.users', [
'users' => $users,
'roleClass' => $this->roleClassMap(),
'roleNames' => $roleNames,
'query' => $request->get('q'),
'usersCount' => $usersCount
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import Keyboard from '../../../core/keyboard';
import Styles from '../../stores/styles';
import { shiftKeyOnly } from '@biigle/ol/events/condition';
import snapInteraction from '../../snapInteraction.vue';
import { Point } from '@biigle/ol/geom';
function computeDistance(point1, point2) {
let p1=point1.getCoordinates();
let p2=point2.getCoordinates();
return Math.sqrt(Math.pow(p2[0] - p1[0], 2) + Math.pow(p2[1] - p1[1], 2));
}
/**
* Mixin for the annotationCanvas component that contains logic for the draw interactions.
Expand All @@ -13,6 +21,9 @@ import snapInteraction from '../../snapInteraction.vue';
let drawInteraction;
const POINT_CLICK_COOLDOWN = 400;
const POINT_CLICK_DISTANCE = 5;
// Custom OpenLayers freehandCondition that is true if a pen is used for input or
// if Shift is pressed otherwise.
let penOrShift = function (mapBrowserEvent) {
Expand All @@ -30,6 +41,8 @@ export default {
data() {
return {
drawEnded: true,
lastDrawnPoint: new Point(0, 0),
lastDrawnPointTime: 0,
}
},
computed: {
Expand Down Expand Up @@ -104,15 +117,34 @@ export default {
});
drawInteraction.on('drawend', (e) => {
this.handleNewFeature(e);
this.drawEnded = true;
if (this.isDrawingPoint) {
if (this.isPointDoubleClick(e)) {
// The feature is added to the source only after this event
// is handled, so removel has to happen after the addfeature
// event.
this.annotationSource.once('addfeature', function () {
this.removeFeature(e.feature);
});
return;
}
this.lastDrawnPointTime = new Date().getTime();
this.lastDrawnPoint = e.feature.getGeometry();
}
this.handleNewFeature(e);
});
drawInteraction.on('drawabort', () => {
this.drawEnded = true;
});
this.drawEnded = true;
});
}
},
isPointDoubleClick(e) {
return new Date().getTime() - this.lastDrawnPointTime < POINT_CLICK_COOLDOWN
&& computeDistance(this.lastDrawnPoint,e.feature.getGeometry()) < POINT_CLICK_DISTANCE;
},
},
watch: {
selectedLabel(label) {
Expand Down
20 changes: 13 additions & 7 deletions resources/views/admin/users.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
The user was deleted.
</div>
@endif
<a href="{{route('admin-users-new')}}" class="btn btn-default" title="Create a new user">New user</a>
<form class="form-inline inline-block-form" action="{{route('admin-users')}}" method="get">
<input class="form-control" type="text" name="q" placeholder="Search users" value="{{$query}}">
</form>
@if ($query)
<a href="{{route('admin-users')}}" class="btn btn-info" title="Clear filtering"><i class="fas fa-times"></i></a>
@endif
<div class="clearfix">
<form class="form-inline inline-block-form" action="{{route('admin-users')}}" method="get">
<input class="form-control" type="text" name="q" placeholder="Search users" value="{{$query}}">
</form>
@if ($query)
<a href="{{route('admin-users')}}" class="btn btn-info" title="Clear filtering"><i class="fas fa-times"></i></a>
@endif
<a @if (request('recent')) href="{{route('admin-users')}}" class="btn btn-info active" @else href="{{route('admin-users')}}?recent=1" class="btn btn-default" @endif title="Show users who joined within the last 7 days">
Recently joined
<span class="badge">{{$usersCount}}</span>
</a>
<a href="{{route('admin-users-new')}}" class="btn btn-default pull-right" title="Create a new user">New user</a>
</div>
<table class="table table-hover">
<thead>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/annotations/show/tabs/settings.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

<div class="sidebar-tab__section">
<h5 title="Set the opacity of annotations on the map">Annotation Opacity (<span v-text="annotationOpacity"></span>)</h5>
<input type="range" min="0" max="1" step="0.1" v-model="annotationOpacity">
<input type="range" min="0" max="1" step="0.1" v-model="annotationOpacity" onmouseup="this.blur()">
</div>

<div class="sidebar-tab__section">
<h5 title="Set the number of caches images ">Cached Images (<span v-text="cachedImagesCount"></span>)</h5>
<input type="range" min="1" max="50" step="1" v-model="cachedImagesCount">
<input type="range" min="1" max="50" step="1" v-model="cachedImagesCount" onmouseup="this.blur()">
</div>

<div class="sidebar-tab__section">
Expand Down
5 changes: 3 additions & 2 deletions tests/php/LabelTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,9 @@ public function testScopeAccessibleBy()
$project = ProjectTest::create(['creator_id' => $user->id]);
$project->labelTrees()->attach($tree3);

$ids = LabelTree::accessibleBy($user)->pluck('id')->toArray();
$this->assertSame([$tree->id, $tree2->id, $tree3->id], $ids);
$ids = LabelTree::accessibleBy($user)->orderBy('id')->pluck('id')->toArray();
$this->assertEquals([$tree->id, $tree2->id, $tree3->id], $ids);

}

public function testScopeAccessibleByAdmin()
Expand Down

0 comments on commit 894c8f3

Please sign in to comment.