Skip to content

Commit

Permalink
Adding list of workshop functionaries to the home page (#384)
Browse files Browse the repository at this point in the history
* Initial version; functioning, but ugly

* Changed the button to a link

* Improving appearance

* Generalising arrow dropdowns; moving logic to controller

* Addressing failing tests

* Addressing requests

---------

Co-authored-by: Katkó Dominik <56202545+kdmnk@users.noreply.github.com>
  • Loading branch information
viktorcsimma and kdmnk authored Jan 3, 2024
1 parent 5149ff9 commit 50ec1d5
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 43 deletions.
9 changes: 9 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Models\RoleObject;
use App\Models\RoleUser;
use App\Models\User;
use App\Models\Workshop;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\File;
Expand Down Expand Up @@ -218,7 +219,15 @@ private function getHomePageContacts(): array
Role::BOARD_OF_TRUSTEES_MEMBER => User::boardOfTrusteesMembers(),
Role::ETHICS_COMMISSIONER => User::ethicsCommissioners(),
]);

$contacts['workshops'] = Workshop::all()->flatMap(fn ($workshop) => [
$workshop->name => [
'leaders' => $workshop->leaders->pluck('name')->implode(', '),
'administrators' => $workshop->administrators->pluck('name')->implode(', ')
]
]);
}

return $contacts;
}
}
104 changes: 62 additions & 42 deletions app/Models/Workshop.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use App\Models\Role;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
Expand Down Expand Up @@ -61,25 +63,79 @@ class Workshop extends Model
self::TORTENESZ,
];

public function users()
public const COLORS = [
self::ANGOL => 'deep-purple lighten-3',
self::BIOLOGIA => 'green lighten-2',
self::BOLLOK => 'teal lighten-2',
self::FILOZOFIA => 'teal accent-4',
self::AURELION => 'lime darken-2',
self::GAZDALKODASTUDOMANYI => 'brown lighten-2',
self::GERMANISZTIKA => 'blue-grey lighten-2',
self::INFORMATIKA => 'light-blue darken-4',
self::MAGYAR => 'red lighten-2',
self::MATEMATIKA => 'blue darken-2',
self::MENDOL => 'cyan darken-2',
self::OLASZ => 'red accent-3',
self::ORIENTALISZTIKA => 'amber lighten-1',
self::SKANDINAVISZTIKA => 'deep-orange lighten-3',
self::SPANYOL => 'deep-purple darken-2',
self::SZLAVISZTIKA => 'light-blue lighten-2',
self::TARSADALOMTUDOMANYI => 'purple lighten-1',
self::TORTENESZ => 'teal darken-4',
];

/**
* Defines the BelongsToMany connection to users.
*/
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class, 'workshop_users');
}

/**
* Returns a collection containing the residents in the workshop.
*/
public function residents()
{
return $this->users->filter(function ($user, $key) {
return $user->isResident();
});
}

/**
* Returns a collection containing the externs in the workshop.
*/
public function externs()
{
return $this->users->filter(function ($user, $key) {
return $user->isExtern();
});
}

/**
* Returns a collection with all functionaries of the workshop in it.
*/
public function functionaries(): BelongsToMany
{
return $this->belongsToMany(User::class, 'role_users');
}

/**
* Filters functionaries to only include workshop administrators.
*/
public function administrators(): BelongsToMany
{
return $this->functionaries()->wherePivot('role_id', Role::get(Role::WORKSHOP_ADMINISTRATOR)->id);
}

/**
* Filters functionaries to only include workshop leaders.
*/
public function leaders(): BelongsToMany
{
return $this->functionaries()->wherePivot('role_id', Role::get(Role::WORKSHOP_LEADER)->id);
}

/**
* Returns all the balances the workshop has had in different semesters.
*/
Expand All @@ -97,47 +153,11 @@ public function balance(int $semester = null): ?WorkshopBalance
return $this->balances()->firstWhere('semester_id', $semester ?? Semester::current()->id);
}

public function color()
/**
* Associates each workshop with a fixed color.
*/
public function color(): string
{
switch ($this->name) {
case self::ANGOL:
return 'deep-purple lighten-3';
case self::BIOLOGIA:
return 'green lighten-2';
case self::BOLLOK:
return 'teal lighten-2';
case self::FILOZOFIA:
return 'teal accent-4';
case self::AURELION:
return 'lime darken-2';
case self::GAZDALKODASTUDOMANYI:
return 'brown lighten-2';
case self::GERMANISZTIKA:
return 'blue-grey lighten-2';
case self::INFORMATIKA:
return 'light-blue darken-4';
case self::MAGYAR:
return 'red lighten-2';
case self::MATEMATIKA:
return 'blue darken-2';
case self::MENDOL:
return 'cyan darken-2';
case self::OLASZ:
return 'red accent-3';
case self::ORIENTALISZTIKA:
return 'amber lighten-1';
case self::SKANDINAVISZTIKA:
return 'deep-orange lighten-3';
case self::SPANYOL:
return 'deep-purple darken-2';
case self::SZLAVISZTIKA:
return 'light-blue lighten-2';
case self::TARSADALOMTUDOMANYI:
return 'purple lighten-1';
case self::TORTENESZ:
return 'teal darken-4';
default:
return 'black';
}
return isset(self::COLORS[$this->name]) ? self::COLORS[$this->name] : 'black';
}
}
1 change: 1 addition & 0 deletions resources/lang/en/role.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@
'tenant' => 'Tenant',
'workshop-administrator' => 'Workshop administrator',
'workshop-leader' => 'Workshop leader',
'workshop-functionaries' => 'Workshop functionaries',
];
1 change: 1 addition & 0 deletions resources/lang/hu/role.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@
'tenant' => 'Vendég',
'workshop-administrator' => 'Műhelytitkár',
'workshop-leader' => 'Műhelyvezető',
'workshop-functionaries' => 'A műhelyek tisztségviselői',
];
28 changes: 28 additions & 0 deletions resources/sass/materialize.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,34 @@ span.badge.tag {
float: none;
}

// for our custom arrow dropdowns
// (e.g. for the workshop functionaries on the home page)
.arrow-dropdown .arrow-dropdown-title a {
color: inherit;
text-decoration: inherit;
cursor: pointer;
}
.arrow-dropdown .arrow-dropdown-title.closed::after {
content: '';
display: inline-block;
font-size: 0.6em;
transform: translateY(-0.4em);
}
.arrow-dropdown .arrow-dropdown-title.open::after {
content: '';
display: inline-block;
font-size: 0.6em;
transform: translateY(-0.3em);
}
.arrow-dropdown .arrow-dropdown-content ul li ul {
margin: 0 0 10px 20px;
}
.arrow-dropdown > .arrow-dropdown-title.closed + .arrow-dropdown-content ul {
display: none;
}
.arrow-dropdown > .arrow-dropdown-title.open + .arrow-dropdown-content ul {
display: block;
}

//enable multiline buttons if the text does not fit in
.btn,
Expand Down
25 changes: 24 additions & 1 deletion resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,29 @@
@endif
@endforeach

<!-- Workshop functionaries -->
<div class="arrow-dropdown">
<h5 class="arrow-dropdown-title" class="closed"><a>
@lang('role.workshop-functionaries')
</a></h5>
<div class="arrow-dropdown-content">
<ul>
@foreach($contacts['workshops'] as $name => $functionaries)
<li>
<b>{{$name}}</b>
<ul>
<li>@lang('role.'.\App\Models\Role::WORKSHOP_LEADER):
<i>{{$functionaries['leaders']}}</i>
</li>
<li>@lang('role.'.\App\Models\Role::WORKSHOP_ADMINISTRATOR):
<i>{{$functionaries['administrators']}}</i>
</li>
</ul>
</li>
@endforeach
</ul>
</div>
</div>

@endif
<!-- Admins -->
Expand Down Expand Up @@ -167,6 +190,6 @@ function standby(id) {
}
$(document).ready(function(){
$('.materialboxed').materialbox();
});
});
</script>
@endpush
20 changes: 20 additions & 0 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@ function toggleColorMode() {
url: "{{ route('set-color-mode', [':mode']) }}".replace(':mode', mode),
});
}
// for our custom arrow dropdowns
// (e.g. the dropdown of workshop secretaries)
function toggleCollContent(title) {
return function() {
if (title.is(".closed")) {
title.removeClass("closed");
title.addClass("open");
// the rest is done by CSS rules
} else {
title.removeClass("open");
title.addClass("closed");
}
}
}
titles = $(".arrow-dropdown .arrow-dropdown-title");
titles.on('click', toggleCollContent(titles));
// initialize them as closed:
titles.addClass('closed');
</script>
@endpush

Expand Down

0 comments on commit 50ec1d5

Please sign in to comment.