Skip to content

Commit

Permalink
Adapt react print to changes in ecamp#2571
Browse files Browse the repository at this point in the history
Fixes the open todo from
ecamp#2571 (comment)
  • Loading branch information
carlobeltrame committed May 4, 2022
1 parent 820059b commit 0059b58
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 15 deletions.
17 changes: 17 additions & 0 deletions api/src/Entity/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,23 @@ public function removeScheduleEntry(ScheduleEntry $scheduleEntry): self {
return $this;
}

/**
* All the content nodes used in some activity which is carried out (has a schedule entry) in this period.
*
* @return ContentNode[]
*/
#[ApiProperty(writable: false, example: '["/content_nodes/1a2b3c4d"]')]
#[RelatedCollectionLink(ContentNode::class, ['period' => '$this'])]
#[Groups(['read'])]
public function getContentNodes(): array {
return array_values(array_unique(array_merge(...array_map(
function (ScheduleEntry $scheduleEntry) {
return $scheduleEntry->activity->getRootContentNode()->getRootDescendants();
},
$this->getScheduleEntries()
)), SORT_REGULAR));
}

/**
* @return MaterialItem[]
*/
Expand Down
40 changes: 40 additions & 0 deletions api/tests/Entity/PeriodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace App\Tests\Entity;

use App\Entity\Activity;
use App\Entity\Camp;
use App\Entity\ContentNode\ColumnLayout;
use App\Entity\ContentNode\SingleText;
use App\Entity\Day;
use App\Entity\Period;
use App\Entity\ScheduleEntry;
use DateTime;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -33,4 +37,40 @@ public function testFirstDayNumberInPeriod() {
$this->assertEquals(3, $period1->getFirstDayNumber());
$this->assertEquals(1, $period2->getFirstDayNumber());
}

public function testGetContentNodes() {
$camp = new Camp();

$period = new Period();
$period->start = new DateTime('2020-09-14');
$camp->addPeriod($period);
$scheduleEntry1 = new ScheduleEntry();
$scheduleEntry2 = new ScheduleEntry();
$scheduleEntry3 = new ScheduleEntry();
$period->addScheduleEntry($scheduleEntry1);
$period->addScheduleEntry($scheduleEntry2);
$period->addScheduleEntry($scheduleEntry3);

$activity1 = new Activity();
$columnLayout1 = new ColumnLayout();
$singleText1 = new SingleText();
$columnLayout1->addRootDescendant($singleText1);
$columnLayout1->addChild($singleText1);
$activity1->setRootContentNode($columnLayout1);
$scheduleEntry1->activity = $activity1;
$scheduleEntry2->activity = $activity1;

$activity2 = new Activity();
$columnLayout2 = new ColumnLayout();
$singleText2 = new SingleText();
$columnLayout2->addRootDescendant($singleText2);
$columnLayout2->addChild($singleText2);
$activity2->setRootContentNode($columnLayout2);
$scheduleEntry3->activity = $activity2;

$this->assertEquals(
[$singleText1, $columnLayout1, $singleText2, $columnLayout2],
$period->getContentNodes()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ function ColumnLayout (props) {
const columns = props.contentNode.columns
const firstSlot = columns.length ? columns[0].slot : '1'
const lastSlot = columns.length ? columns[columns.length - 1].slot : '1'
const children = props.contentNode.owner().contentNodes().items.filter(contentNode => {
return contentNode.parent && contentNode.parent()._meta.self === props.contentNode._meta.self
})

return <View style={{ display: 'flex', flexDirection: 'row' }}>
{ columns.map(({ slot, width }) => {
Expand All @@ -18,7 +15,7 @@ function ColumnLayout (props) {
padding: '2pt ' + (slot === lastSlot ? '0' : '1%') + ' 2pt ' + (slot === firstSlot ? '0' : '1%'),
flexBasis: (width * 1000) + 'pt'
}}>
{ children
{ props.contentNode.children().items
.filter(child => child.slot === slot)
.sort((child1, child2) => parseInt(child1.position) - parseInt(child2.position))
.map(child => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ const picassoData = (config) => {
camp.categories().$loadItems(),
camp.activities().$loadItems().then(activities => {
return Promise.all(activities.items.map(activity => {
return Promise.all([
activity.activityResponsibles().$loadItems(),
activity.contentNodes().$loadItems()
])
return activity.activityResponsibles().$loadItems()
}))
}),
camp.campCollaborations().$loadItems().then(campCollaboration => {
return campCollaboration.user ? campCollaboration.user()._meta.load : Promise.resolve()
}),
camp.periods().$loadItems().then(periods => {
return Promise.all(periods.items.map(period => {
return period.scheduleEntries().$loadItems()
return Promise.all([
period.scheduleEntries().$loadItems(),
period.contentNodes().$loadItems()
])
}))
})
]
Expand All @@ -39,18 +39,18 @@ const activityData = (config) => {
camp.categories().$loadItems(),
camp.activities().$loadItems().then(activities => {
return Promise.all(activities.items.map(activity => {
return Promise.all([
activity.activityResponsibles().$loadItems(),
activity.contentNodes().$loadItems()
])
return activity.activityResponsibles().$loadItems()
}))
}),
camp.campCollaborations().$loadItems().then(campCollaboration => {
return campCollaboration.user ? campCollaboration.user()._meta.load : Promise.resolve()
}),
camp.periods().$loadItems().then(periods => {
return Promise.all(periods.items.map(period => {
return period.scheduleEntries().$loadItems()
return Promise.all([
period.scheduleEntries().$loadItems(),
period.contentNodes().$loadItems()
])
}))
}),
camp.materialLists().$loadItems(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ function isCollection (object) {

function isEntityReference (object) {
if (!object) return false
return isEqualIgnoringOrder(Object.keys(object), ['href'])
return isEqualIgnoringOrder(Object.keys(object), ['href']) || isVirtualLink(object)
}

function isTemplatedLink (object) {
if (!object) return false
return isEqualIgnoringOrder(Object.keys(object), ['href', 'templated']) && (object.templated === true)
}

function isVirtualLink (object) {
if (!object) return false
return isEqualIgnoringOrder(Object.keys(object), ['href', 'virtual']) && (object.virtual === true)
}

function normalizeEntityUri (uriOrEntity) {
if (typeof uriOrEntity === 'function') {
uriOrEntity = uriOrEntity()
Expand Down

0 comments on commit 0059b58

Please sign in to comment.