Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions api/migrations/schema/Version20240928090159.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

require_once __DIR__.'/checklists/helpers.php';

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240928090159 extends AbstractMigration {
public function getDescription(): string {
return 'Insert PBS-Checklist';
}

public function up(Schema $schema): void {
$statements = getStatementsForMigrationFile(__DIR__.'/checklists/pbs-checklist.sql');
foreach ($statements as $statement) {
if (trim($statement)) {
$this->addSql($statement);
}
}
}

public function down(Schema $schema): void {}
}
48 changes: 48 additions & 0 deletions api/migrations/schema/Version20240928105306.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240928105306 extends AbstractMigration {
public function getDescription(): string {
return 'checklistitem_checklistid_parentid_position_unique deferrable';
}

public function up(Schema $schema): void {
$this->addSql(
<<<'EOF'
drop index checklistitem_checklistid_parentid_position_unique
EOF
);
$this->addSql(
<<<'EOF'
alter table checklist_item
add constraint checklistitem_checklistid_parentid_position_unique
unique (checklistid, parentid, position)
deferrable initially deferred
EOF
);
}

public function down(Schema $schema): void {
$this->addSql(
<<<'EOF'
alter table checklist_item
drop constraint checklistitem_checklistid_parentid_position_unique
EOF
);
$this->addSql(
<<<'EOF'
CREATE UNIQUE INDEX checklistitem_checklistid_parentid_position_unique
ON checklist_item (checklistid, parentid, position)
EOF
);
}
}
15 changes: 15 additions & 0 deletions api/migrations/schema/checklists/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace DoctrineMigrations;

use PhpMyAdmin\SqlParser\Parser;
use PhpMyAdmin\SqlParser\Statement;

function getStatementsForMigrationFile(string $sqlFile): array {
$sql = file_get_contents($sqlFile);

$parser = new Parser($sql);
$parsed_statements = array_map(fn (Statement $statement) => $statement->build(), $parser->statements);

return str_replace('`', '"', $parsed_statements);
}
177 changes: 177 additions & 0 deletions api/migrations/schema/checklists/pbs-checklist.sql

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions api/src/Entity/Checklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
normalizationContext: ['groups' => ['read']],
order: ['camp.id', 'name'],
)]
#[ApiFilter(filterClass: SearchFilter::class, properties: ['camp'])]
#[ApiFilter(filterClass: SearchFilter::class, properties: ['camp', 'isPrototype'])]
#[ORM\Entity(repositoryClass: ChecklistRepository::class)]
class Checklist extends BaseEntity implements BelongsToCampInterface, CopyFromPrototypeInterface {
public const CAMP_SUBRESOURCE_URI_TEMPLATE = '/camps/{campId}/checklists{._format}';
Expand Down Expand Up @@ -166,7 +166,7 @@ public function copyFromPrototype($prototype, $entityMap): void {
$entityMap->add($prototype, $this);

// copy Checklist base properties
$this->name = $prototype->name;
$this->name ??= $prototype->name;

// deep copy ChecklistItems
foreach ($prototype->getChecklistItems() as $checklistItemPrototype) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24354,6 +24354,18 @@ paths:
schema:
type: string
style: form
-
allowEmptyValue: true
allowReserved: false
deprecated: false
description: ''
explode: false
in: query
name: isPrototype
required: false
schema:
type: boolean
style: form
-
allowEmptyValue: true
allowReserved: false
Expand All @@ -24368,6 +24380,20 @@ paths:
type: string
type: array
style: form
-
allowEmptyValue: true
allowReserved: false
deprecated: false
description: ''
explode: true
in: query
name: 'isPrototype[]'
required: false
schema:
items:
type: boolean
type: array
style: form
responses:
200:
content:
Expand Down Expand Up @@ -25076,6 +25102,18 @@ paths:
schema:
type: string
style: form
-
allowEmptyValue: true
allowReserved: false
deprecated: false
description: ''
explode: false
in: query
name: isPrototype
required: false
schema:
type: boolean
style: form
-
allowEmptyValue: true
allowReserved: false
Expand All @@ -25090,6 +25128,20 @@ paths:
type: string
type: array
style: form
-
allowEmptyValue: true
allowReserved: false
deprecated: false
description: ''
explode: true
in: query
name: 'isPrototype[]'
required: false
schema:
items:
type: boolean
type: array
style: form
responses:
200:
content:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"templated": true
},
"checklists": {
"href": "\/checklists{\/id}{?camp,camp[]}",
"href": "\/checklists{\/id}{?camp,camp[],isPrototype,isPrototype[]}",
"templated": true
},
"columnLayouts": {
Expand Down
3 changes: 2 additions & 1 deletion common/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@
},
"checklist": {
"fields": {
"name": "Name"
"name": "Name",
"copyChecklistSource": "Vorlage"
},
"name": "Checkliste | Checklisten"
},
Expand Down
3 changes: 2 additions & 1 deletion common/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@
},
"checklist": {
"fields": {
"name": "Name"
"name": "Name",
"copyChecklistSource": "Prototype"
},
"name": "Checklist | Checklists"
},
Expand Down
23 changes: 21 additions & 2 deletions frontend/src/components/checklist/ChecklistCreate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
path="name"
vee-rules="required"
/>

<e-select
v-model="entityData.copyChecklistSource"
path="copyChecklistSource"
:items="prototypeChecklists"
/>
</DetailPane>
</template>

Expand All @@ -50,16 +56,29 @@ export default {
},
data() {
return {
entityProperties: ['camp', 'name'],
entityProperties: ['camp', 'name', 'copyChecklistSource'],
entityUri: '',
}
},
computed: {
prototypeChecklists() {
return this.api
.get()
.checklists({ isPrototype: true })
.items.map((c) => ({
value: c._meta.self,
text: c.name,
object: c,
}))
},
},
watch: {
showDialog: function (showDialog) {
if (showDialog) {
this.setEntityData({
name: '',
camp: this.camp._meta.self,
name: '',
copyChecklistSource: null,
})
} else {
// clear form on exit
Expand Down
Loading