Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Extend ext storage params to contain default value
Extend the external storage configuration parameters definition to allow
to specify a default value

Signed-off-by: Vincent Petry <[email protected]>
  • Loading branch information
PVince81 committed Jan 16, 2023
commit 6fc54ba54ca873d4be0703abc0519caca0b2022b
8 changes: 8 additions & 0 deletions apps/files_external/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,14 @@ MountConfigListView.prototype = _.extend({
newElement = $('<input type="text" class="'+classes.join(' ')+'" data-parameter="'+parameter+'" placeholder="'+ trimmedPlaceholder+'" />');
}

if (placeholder.defaultValue) {
if (placeholder.type === MountConfigListView.ParameterTypes.BOOLEAN) {
newElement.find('input').prop('checked', placeholder.defaultValue);
} else {
newElement.val(placeholder.defaultValue);
}
}

if (placeholder.tooltip) {
newElement.attr('title', placeholder.tooltip);
}
Expand Down
34 changes: 30 additions & 4 deletions apps/files_external/lib/Lib/DefinitionParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,18 @@ class DefinitionParameter implements \JsonSerializable {
/** @var int flags, see self::FLAG_* constants */
private $flags = self::FLAG_NONE;

/** @var mixed */
private $defaultValue;

/**
* @param string $name
* @param string $text
* @param string $name parameter name
* @param string $text parameter description
* @param mixed $defaultValue default value
*/
public function __construct($name, $text) {
public function __construct($name, $text, $defaultValue = null) {
$this->name = $name;
$this->text = $text;
$this->defaultValue = $defaultValue;
}

/**
Expand Down Expand Up @@ -100,6 +105,22 @@ public function setType($type) {
return $this;
}

/**
* @return mixed default value
*/
public function getDefaultValue() {
return $this->defaultValue;
}

/**
* @param mixed $defaultValue default value
* @return self
*/
public function setDefaultValue($defaultValue) {
$this->defaultValue = $defaultValue;
return $this;
}

/**
* @return string
*/
Expand Down Expand Up @@ -171,12 +192,17 @@ public function setTooltip(string $tooltip) {
* @return string
*/
public function jsonSerialize() {
return [
$result = [
'value' => $this->getText(),
'flags' => $this->getFlags(),
'type' => $this->getType(),
'tooltip' => $this->getTooltip(),
];
$defaultValue = $this->getDefaultValue();
if ($defaultValue) {
$result['defaultValue'] = $defaultValue;
}
return $result;

Check notice

Code scanning / Psalm

InvalidReturnStatement

The inferred type 'array{defaultValue?: non-empty-mixed, flags: int, tooltip: string, type: int, value: string}' does not match the declared return type 'string' for OCA\Files_External\Lib\DefinitionParameter::jsonSerialize
}

public function isOptional() {
Expand Down
2 changes: 2 additions & 0 deletions apps/files_external/tests/DefinitionParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ public function testJsonSerialization() {
], $param->jsonSerialize());

$param->setType(Param::VALUE_BOOLEAN);
$param->setDefaultValue(true);
$this->assertEquals([
'value' => 'bar',
'flags' => 0,
'type' => Param::VALUE_BOOLEAN,
'tooltip' => '',
'defaultValue' => true,
], $param->jsonSerialize());

$param->setType(Param::VALUE_PASSWORD);
Expand Down