Allow multiple custom JS files

This commit is contained in:
Robin McCorkell 2016-02-08 13:16:00 +00:00 committed by Robin McCorkell
parent 06293783e0
commit de98a6e54c
8 changed files with 32 additions and 18 deletions

View file

@ -46,7 +46,7 @@ class OAuth1 extends AuthMechanism {
(new DefinitionParameter('token_secret', 'token_secret'))
->setType(DefinitionParameter::VALUE_HIDDEN),
])
->setCustomJs('oauth1')
->addCustomJs('oauth1')
;
}

View file

@ -44,7 +44,7 @@ class OAuth2 extends AuthMechanism {
(new DefinitionParameter('token', 'token'))
->setType(DefinitionParameter::VALUE_HIDDEN),
])
->setCustomJs('oauth2')
->addCustomJs('oauth2')
;
}

View file

@ -52,7 +52,7 @@ class RSA extends AuthMechanism {
(new DefinitionParameter('private_key', 'private_key'))
->setType(DefinitionParameter::VALUE_HIDDEN),
])
->setCustomJs('public_key')
->addCustomJs('public_key')
;
}

View file

@ -84,7 +84,7 @@ class LegacyBackend extends Backend {
$this->setPriority($definition['priority']);
}
if (isset($definition['custom'])) {
$this->setCustomJs($definition['custom']);
$this->addCustomJs($definition['custom']);
}
if (isset($definition['has_dependencies']) && $definition['has_dependencies']) {
$this->hasDependencies = true;

View file

@ -36,8 +36,8 @@ trait FrontendDefinitionTrait {
/** @var DefinitionParameter[] parameters for mechanism */
private $parameters = [];
/** @var string|null custom JS */
private $customJs = null;
/** @var string[] custom JS */
private $customJs = [];
/**
* @return string
@ -92,7 +92,7 @@ trait FrontendDefinitionTrait {
}
/**
* @return string|null
* @return string[]
*/
public function getCustomJs() {
return $this->customJs;
@ -102,8 +102,18 @@ trait FrontendDefinitionTrait {
* @param string $custom
* @return self
*/
public function addCustomJs($custom) {
$this->customJs[] = $custom;
return $this;
}
/**
* @param string $custom
* @return self
* @deprecated 9.1.0, use addCustomJs() instead
*/
public function setCustomJs($custom) {
$this->customJs = $custom;
$this->customJs = [$custom];
return $this;
}
@ -121,10 +131,8 @@ trait FrontendDefinitionTrait {
$data = [
'name' => $this->getText(),
'configuration' => $configuration,
'custom' => $this->getCustomJs(),
];
if (isset($this->customJs)) {
$data['custom'] = $this->getCustomJs();
}
return $data;
}

View file

@ -1,5 +1,6 @@
<?php
use \OCA\Files_External\Lib\Backend\Backend;
use \OCA\Files_External\Lib\Auth\AuthMechanism;
use \OCA\Files_External\Lib\DefinitionParameter;
use \OCA\Files_External\Service\BackendService;
@ -16,13 +17,16 @@
// load custom JS
foreach ($_['backends'] as $backend) {
/** @var Backend $backend */
if ($backend->getCustomJs()) {
script('files_external', $backend->getCustomJs());
$scripts = $backend->getCustomJs();
foreach ($scripts as $script) {
script('files_external', $script);
}
}
foreach ($_['authMechanisms'] as $authMechanism) {
if ($authMechanism->getCustomJs()) {
script('files_external', $authMechanism->getCustomJs());
/** @var AuthMechanism $authMechanism */
$scripts = $authMechanism->getCustomJs();
foreach ($scripts as $script) {
script('files_external', $script);
}
}

View file

@ -62,7 +62,7 @@ class LegacyBackendTest extends \Test\TestCase {
$this->assertEquals('\OCA\Files_External\Tests\Backend\LegacyBackendTest', $backend->getStorageClass());
$this->assertEquals('Backend text', $backend->getText());
$this->assertEquals(123, $backend->getPriority());
$this->assertEquals('foo/bar.js', $backend->getCustomJs());
$this->assertContains('foo/bar.js', $backend->getCustomJs());
$this->assertArrayHasKey('builtin', $backend->getAuthSchemes());
$this->assertEquals($auth, $backend->getLegacyAuthMechanism());

View file

@ -33,12 +33,14 @@ class FrontendDefinitionTraitTest extends \Test\TestCase {
$trait = $this->getMockForTrait('\OCA\Files_External\Lib\FrontendDefinitionTrait');
$trait->setText('test');
$trait->addParameters([$param]);
$trait->setCustomJs('foo/bar.js');
$trait->addCustomJs('foo/bar.js');
$trait->addCustomJs('bar/foo.js');
$json = $trait->jsonSerializeDefinition();
$this->assertEquals('test', $json['name']);
$this->assertEquals('foo/bar.js', $json['custom']);
$this->assertContains('foo/bar.js', $json['custom']);
$this->assertContains('bar/foo.js', $json['custom']);
$configuration = $json['configuration'];
$this->assertArrayHasKey('foo', $configuration);