Skip to content

Commit

Permalink
Refresh UI specifically for depicts..
Browse files Browse the repository at this point in the history
  • Loading branch information
addshore committed Jul 28, 2024
1 parent d6b7137 commit cf595d4
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 13 deletions.
98 changes: 97 additions & 1 deletion app/Http/Controllers/QuestionGroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,109 @@
class QuestionGroupController extends Controller
{

private $depictsGroups = [
'animals' => [ 'Q144', 'Q146', 'Q3736439'],
'food' => [ 'Q44', 'Q6663', 'Q13233', 'Q1421401' ],
'landmarks' => [ 'Q243', 'Q9202' ],
'music' => [ 'Q6607', 'Q46185', 'Q20850569', 'Q685206' ],
'people' => [ 'Q6279', 'Q1124', 'Q23505', 'Q207', 'Q76', 'Q22686' ],
'sport' => [ 'Q7291', 'Q18629677', 'Q12100', 'Q1455', 'Q41466', 'Q1748406', 'Q1002954', 'Q12252328' ],
'transport' => [ 'Q34486', 'Q206592', 'Q115940', 'Q2165278', 'Q133585', 'Q11442', 'Q870', 'Q171043', 'Q3407658' ],
];

private function stringEndsWithOneOf( $string, $endStrings ) {
foreach( $endStrings as $endString ) {
if( $this->stringEndsWith( $string, $endString ) ) {
return true;
}
}
return false;
}

private function stringEndsWith( $string, $endString ) {
$len = strlen($endString);
if ($len == 0) {
return true;
}
return (substr($string, -$len) === $endString);
}

public function getTopLevelGroups() {
return QuestionGroup::whereNull('parent')->with(['subGroups' => function($query){
$groups = QuestionGroup::whereNull('parent')->with(['subGroups' => function($query){
$query->withCount(['question as unanswered' => function($query){
$query->doesntHave('answer');
}])
->having('unanswered', '>', 0);
}])->get();

// Filter out anything that doesnt have "depicts" at the start of the name
// As right now we still have "alias" questions and we don't want to show them..
$groups = $groups->filter(function($group){
return strpos($group->name, 'depicts') === 0;
});

$newManualGroups = [];
for ($i = 0; $i < count($groups); $i++) {
$gameGroup = $groups[$i];
$jIgnore = [];
for ($j = 0; $j < count($gameGroup->subGroups); $j++) {
$game = $gameGroup->subGroups[$j];
// Separate out the depict-refine names
if (strpos($game->name, 'depicts-refine') === 0) {
if (!isset($newManualGroups['refinement'])) {
$newManualGroups['refinement'] = (object) [
'display_name' => "Refinement",
'display_description' => "Refine the depiction of images",
'subGroups' => [],
];
}
$newManualGroups['refinement']->subGroups[] = $game;
$jIgnore[] = $j;
continue;
}
foreach ($this->depictsGroups as $depictsGroup => $depictsIds) {
if ($this->stringEndsWithOneOf($game->name, $depictsIds)) {
if (!isset($newManualGroups[$depictsGroup])) {
$newManualGroups[$depictsGroup] = (object) [
'display_name' => ucfirst($depictsGroup),
'subGroups' => [],
];
}
$newManualGroups[$depictsGroup]->subGroups[] = $game;
$jIgnore[] = $j;
}
}
}
for ($j = 0; $j < count($jIgnore); $j++) {
unset($gameGroup->subGroups[$jIgnore[$j]]);
}
}
// If anything is left over, add it to an "Other" group
$newManualGroups['other'] = (object) [
'display_name' => 'Other',
'display_description' => 'Other ungrouped images',
'subGroups' => [],
];
foreach ($groups as $gameGroup) {
foreach ($gameGroup->subGroups as $game) {
$newManualGroups['other']->subGroups[] = $game;
}
}

// Remove the other group if it is empty
if (count($newManualGroups['other']->subGroups) == 0) {
unset($newManualGroups['other']);
}

// Move the `refinement` group to the end
$refinement = $newManualGroups['refinement'];
unset($newManualGroups['refinement']);
$newManualGroups['refinement'] = $refinement;


// And then totally restructure the groups, to focus on depicts, and the types of depicts we are doing ;D

return $newManualGroups;
}

public function showTopLevelGroups()
Expand Down
14 changes: 8 additions & 6 deletions resources/views/groups.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>WikiCrowd</title>
<title>WikiCrowd (Depicts)</title>
<link href="/css/app.css" rel="stylesheet">
</head>
<body class="antialiased">
Expand All @@ -12,12 +12,12 @@

<div class="max-w-6xl mx-auto sm:px-6 lg:px-8">
<div class="flex justify-center pt-8 sm:justify-start sm:pt-0">
<div class="text-lg leading-7 font-semibold"><span class="text-gray-900 dark:text-white">WikiCrowd</span></div>
<div class="text-lg leading-7 font-semibold"><span class="text-gray-900 dark:text-white">WikiCrowd (Depicts)</span></div>
</div>

<div class="flex">
<div class="text-sm text-gray-500">
Quick and easy micro contributions to the wiki space.<br>
Quick and easy micro contributions to the wiki space, showing what images depict.<br>
Using this tool will result in edits being made for your account.
</div>
</div>
Expand All @@ -28,9 +28,11 @@
<div class="flex items-center">
<div class="ml-4 text-lg leading-7 font-semibold"><span class="text-gray-900 dark:text-white">{{$group->display_name}}</span></div>
</div>
<div class="flex items-center">
<div class="ml-4 text-sm"><span class="text-gray-900 dark:text-white">{{$group->display_description}}</span></div>
</div>
<?php if (isset($group->display_description)): ?>
<div class="flex items-center">
<div class="ml-4 text-sm"><span class="text-gray-900 dark:text-white">{{$group->display_description}}</span></div>
</div>
<?php endif; ?>

@forelse ($group->subGroups as $subGroup)
<div class="ml-12">
Expand Down
2 changes: 1 addition & 1 deletion resources/views/image-focus.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>WikiCrowd</title>
<title>WikiCrowd (Depicts)</title>
<link href="/css/app.css" rel="stylesheet">
<link rel="prefetch" href="{{ $qu->properties['img_url'] }}" />
@if ($next != null)
Expand Down
2 changes: 1 addition & 1 deletion resources/views/no-question.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>WikiCrowd</title>
<title>WikiCrowd (Depicts)</title>
<link href="/css/app.css" rel="stylesheet">
</head>
<body class="antialiased">
Expand Down
4 changes: 0 additions & 4 deletions spec/depicts/musical/string.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@




- depictsId: Q6607
name: Guitar
limit: 250
Expand Down

0 comments on commit cf595d4

Please sign in to comment.