better fold mechanism

This commit is contained in:
Kacper Donat 2018-09-13 18:43:00 +02:00
parent af573b4901
commit c3c8bd0e80
9 changed files with 67 additions and 18 deletions

View File

@ -1,6 +1,8 @@
<div class="collapse" :class="{'show': visible}"> <div class="fold">
<lazy v-if="lazy" :activate="visible"> <div class="fold__inner" ref="inner">
<slot></slot> <lazy v-if="lazy" :activate="visible">
</lazy> <slot></slot>
<slot v-else></slot> </lazy>
<slot v-else></slot>
</div>
</div> </div>

View File

@ -30,8 +30,13 @@
} }
} }
.collapse { .fold {
padding-bottom: .5rem; overflow-y: hidden;
overflow-x: hidden;
transition: height 250ms ease;
will-change: height;
box-sizing: padding-box;
} }
.flex { .flex {

View File

@ -17,6 +17,7 @@
.stop__details { .stop__details {
flex-basis: 100%; flex-basis: 100%;
.fold__inner { padding-bottom: .75rem; }
} }
.stop-group__name { .stop-group__name {

View File

@ -42,16 +42,33 @@ export class PopperComponent extends Vue {
@Component({ template: collapse }) @Component({ template: collapse })
export class FoldComponent extends Vue { export class FoldComponent extends Vue {
private observer: MutationObserver;
@Prop(Boolean) @Prop(Boolean)
public visible: boolean; public visible: boolean;
@Prop(Boolean) @Prop(Boolean)
public lazy: boolean; public lazy: boolean;
mounted() {
this.resize();
this.observer = new MutationObserver(() => this.resize());
this.observer.observe(this.$refs['inner'] as Node, {
characterData: true,
subtree: true,
childList: true
});
}
destroyed() {
this.observer.disconnect();
}
@Watch('visible') @Watch('visible')
private onVisibilityChange(value) { private resize() {
const action = () => $(this.$el).collapse(value ? 'show' : 'hide'); const inner = this.$refs['inner'] as HTMLDivElement;
setTimeout(action); this.$el.style.height = `${(this.visible && inner) ? inner.clientHeight : 0}px`;
} }
} }

View File

@ -10,5 +10,11 @@ export interface Departure {
line: Line; line: Line;
delay: number; delay: number;
vehicle?: string; vehicle?: Vehicle;
}
export interface Vehicle {
id: string;
// todo: ???
} }

View File

@ -22,7 +22,7 @@ class Departure implements Fillable
/** /**
* Vehicle identification * Vehicle identification
* @var string|null * @var Vehicle|null
*/ */
private $vehicle; private $vehicle;
@ -54,12 +54,12 @@ class Departure implements Fillable
$this->line = $line; $this->line = $line;
} }
public function getVehicle(): ?string public function getVehicle(): ?Vehicle
{ {
return $this->vehicle; return $this->vehicle;
} }
public function setVehicle(?string $vehicle): void public function setVehicle(?Vehicle $vehicle): void
{ {
$this->vehicle = $vehicle; $this->vehicle = $vehicle;
} }

10
src/Model/Vehicle.php Normal file
View File

@ -0,0 +1,10 @@
<?php
namespace App\Model;
class Vehicle implements Referable, Fillable
{
use ReferableTrait, FillTrait;
// todo: what attributes? AC, USB, GPS, seat count, length, manufacturer...?
}

View File

@ -4,8 +4,10 @@ namespace App\Provider\ZtmGdansk;
use App\Model\Departure; use App\Model\Departure;
use App\Model\Stop; use App\Model\Stop;
use App\Model\Vehicle;
use App\Provider\DepartureRepository; use App\Provider\DepartureRepository;
use App\Provider\LineRepository; use App\Provider\LineRepository;
use App\Service\Proxy\ReferenceFactory;
use Carbon\Carbon; use Carbon\Carbon;
use Tightenco\Collect\Support\Collection; use Tightenco\Collect\Support\Collection;
use Kadet\Functional\Transforms as t; use Kadet\Functional\Transforms as t;
@ -17,12 +19,16 @@ class ZtmGdanskDepartureRepository implements DepartureRepository
/** @var LineRepository */ /** @var LineRepository */
private $lines; private $lines;
/** @var ReferenceFactory */
private $reference;
/** /**
* @param LineRepository $lines * @param LineRepository $lines
*/ */
public function __construct(LineRepository $lines) public function __construct(LineRepository $lines, ReferenceFactory $reference)
{ {
$this->lines = $lines; $this->lines = $lines;
$this->reference = $reference;
} }
public function getForStop(Stop $stop): Collection public function getForStop(Stop $stop): Collection
@ -42,7 +48,7 @@ class ZtmGdanskDepartureRepository implements DepartureRepository
'estimated' => $estimated, 'estimated' => $estimated,
'stop' => $stop, 'stop' => $stop,
'display' => trim($delay['headsign']), 'display' => trim($delay['headsign']),
'vehicle' => $delay['vehicleCode'], 'vehicle' => $this->reference->get(Vehicle::class, $delay['vehicleCode']),
'line' => $lines->get($delay['routeId']), 'line' => $lines->get($delay['routeId']),
]); ]);
})->values(); })->values();

View File

@ -8,6 +8,7 @@ use App\Provider\Database\GenericLineRepository;
use App\Provider\Database\GenericStopRepository; use App\Provider\Database\GenericStopRepository;
use App\Provider\Database\GenericTrackRepository; use App\Provider\Database\GenericTrackRepository;
use App\Provider\ZtmGdansk\{ZtmGdanskDepartureRepository, ZtmGdanskMessageRepository}; use App\Provider\ZtmGdansk\{ZtmGdanskDepartureRepository, ZtmGdanskMessageRepository};
use App\Service\Proxy\ReferenceFactory;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
class ZtmGdanskProvider implements Provider class ZtmGdanskProvider implements Provider
@ -33,7 +34,8 @@ class ZtmGdanskProvider implements Provider
GenericLineRepository $lines, GenericLineRepository $lines,
GenericStopRepository $stops, GenericStopRepository $stops,
GenericTrackRepository $tracks, GenericTrackRepository $tracks,
ZtmGdanskMessageRepository $messages ZtmGdanskMessageRepository $messages,
ReferenceFactory $referenceFactory
) { ) {
$provider = $em->getReference(ProviderEntity::class, $this->getIdentifier()); $provider = $em->getReference(ProviderEntity::class, $this->getIdentifier());
@ -42,7 +44,7 @@ class ZtmGdanskProvider implements Provider
$tracks = $tracks->withProvider($provider); $tracks = $tracks->withProvider($provider);
$this->lines = $lines; $this->lines = $lines;
$this->departures = new ZtmGdanskDepartureRepository($lines); $this->departures = new ZtmGdanskDepartureRepository($lines, $referenceFactory);
$this->stops = $stops; $this->stops = $stops;
$this->messages = $messages; $this->messages = $messages;
$this->tracks = $tracks; $this->tracks = $tracks;