-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47290 from nextcloud/feat/checkbox-template-field…
…-type feat(templates): checkbox field type
- Loading branch information
Showing
18 changed files
with
253 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
apps/files/src/components/TemplateFiller/TemplateCheckboxField.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<!-- | ||
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
- SPDX-License-Identifier: AGPL-3.0-or-later | ||
--> | ||
|
||
<template> | ||
<div class="template-field__checkbox"> | ||
<NcCheckboxRadioSwitch :id="fieldId" | ||
:checked.sync="value" | ||
type="switch" | ||
@update:checked="input"> | ||
{{ fieldLabel }} | ||
</NcCheckboxRadioSwitch> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from 'vue' | ||
import { NcCheckboxRadioSwitch } from '@nextcloud/vue' | ||
export default defineComponent({ | ||
name: 'TemplateCheckboxField', | ||
components: { | ||
NcCheckboxRadioSwitch, | ||
}, | ||
props: { | ||
field: { | ||
type: Object, | ||
default: () => {}, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
value: this.field.checked ?? false, | ||
} | ||
}, | ||
computed: { | ||
fieldLabel() { | ||
const label = this.field.name ?? this.field.alias ?? 'Unknown field' | ||
return label.charAt(0).toUpperCase() + label.slice(1) | ||
}, | ||
fieldId() { | ||
return 'checkbox-field' + this.field.index | ||
}, | ||
}, | ||
methods: { | ||
input() { | ||
this.$emit('input', { | ||
index: this.field.index, | ||
property: 'checked', | ||
value: this.value, | ||
}) | ||
}, | ||
}, | ||
}) | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.template-field__checkbox { | ||
margin: 20px 0; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3235-3235.js.license |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCP\Files\Template; | ||
|
||
use OCP\Files\Template\Fields\CheckBoxField; | ||
use OCP\Files\Template\Fields\RichTextField; | ||
|
||
/** | ||
* @since 30.0.0 | ||
*/ | ||
class FieldFactory { | ||
/** | ||
* @since 30.0.0 | ||
*/ | ||
public static function createField( | ||
string $index, | ||
FieldType $type | ||
): Field { | ||
return match ($type) { | ||
FieldType::RichText => new RichTextField($index, $type), | ||
FieldType::CheckBox => new CheckBoxField($index, $type), | ||
default => throw new InvalidFieldTypeException(), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCP\Files\Template\Fields; | ||
|
||
use OCP\Files\Template\Field; | ||
use OCP\Files\Template\FieldType; | ||
|
||
/** | ||
* @since 30.0.0 | ||
*/ | ||
class CheckBoxField extends Field { | ||
private bool $checked = false; | ||
|
||
/** | ||
* @since 30.0.0 | ||
*/ | ||
public function __construct(string $index, FieldType $type) { | ||
parent::__construct($index, $type); | ||
} | ||
|
||
/** | ||
* @since 30.0.0 | ||
*/ | ||
public function setValue(mixed $value): void { | ||
if (!is_bool($value)) { | ||
throw new \Exception('Invalid value for checkbox field type'); | ||
} | ||
|
||
$this->checked = $value; | ||
} | ||
|
||
/** | ||
* @since 30.0.0 | ||
*/ | ||
public function jsonSerialize(): array { | ||
$jsonProperties = parent::jsonSerialize(); | ||
|
||
return array_merge($jsonProperties, ['checked' => $this->checked]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCP\Files\Template\Fields; | ||
|
||
use OCP\Files\Template\Field; | ||
use OCP\Files\Template\FieldType; | ||
|
||
/** | ||
* @since 30.0.0 | ||
*/ | ||
class RichTextField extends Field { | ||
private string $content = ''; | ||
|
||
/** | ||
* @since 30.0.0 | ||
*/ | ||
public function __construct(string $index, FieldType $type) { | ||
parent::__construct($index, $type); | ||
} | ||
|
||
/** | ||
* @since 30.0.0 | ||
*/ | ||
public function setValue(mixed $value): void { | ||
if (!is_string($value)) { | ||
throw new \Exception('Invalid value for rich-text field type'); | ||
} | ||
|
||
$this->content = $value; | ||
} | ||
|
||
/** | ||
* @since 30.0.0 | ||
*/ | ||
public function jsonSerialize(): array { | ||
$jsonProperties = parent::jsonSerialize(); | ||
|
||
return array_merge($jsonProperties, ['content' => $this->content]); | ||
} | ||
} |