Skip to content

Commit

Permalink
better load of libs
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Jul 19, 2021
1 parent 3ae1816 commit a4d8572
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 41 deletions.
27 changes: 16 additions & 11 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
use OCP\FullTextSearch\IFullTextSearchManager;
use OCP\INavigationManager;
use OCP\IServerContainer;
use OCP\IURLGenerator;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Throwable;

require_once __DIR__ . '/../../vendor/autoload.php';
Expand All @@ -54,7 +56,8 @@
class Application extends App implements IBootstrap {


const APP_NAME = 'fulltextsearch';
const APP_ID = 'fulltextsearch';
const APP_NAME = 'FullTextSearch';


/**
Expand All @@ -63,7 +66,7 @@ class Application extends App implements IBootstrap {
* @param array $params
*/
public function __construct(array $params = []) {
parent::__construct(self::APP_NAME, $params);
parent::__construct(self::APP_ID, $params);
}


Expand Down Expand Up @@ -117,25 +120,27 @@ protected function registerNavigation(IServerContainer $container) {
return;
}

$container->get(INavigationManager::class)
->add($this->fullTextSearchNavigation());
try {
$container->get(INavigationManager::class)
->add($this->fullTextSearchNavigation());
} catch (RouteNotFoundException $e) {
}
}


/**
* @return array
*/
private function fullTextSearchNavigation(): array {
$urlGen = OC::$server->getURLGenerator();
$navName = OC::$server->getL10N(self::APP_NAME)
->t('Search');
/** @var IURLGenerator $urlGen */
$urlGen = OC::$server->get(IURLGenerator::class);

return [
'id' => self::APP_NAME,
'id' => self::APP_ID,
'order' => 5,
'href' => $urlGen->linkToRoute('fulltextsearch.Navigation.navigate'),
'icon' => $urlGen->imagePath(self::APP_NAME, 'fulltextsearch.svg'),
'name' => $navName
'href' => $urlGen->linkToRoute(self::APP_ID . '.Navigation.navigate'),
'icon' => $urlGen->imagePath(self::APP_ID, 'fulltextsearch.svg'),
'name' => 'Search'
];
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(
IRequest $request, ConfigService $configService, SearchService $searchService,
MiscService $miscService
) {
parent::__construct(Application::APP_NAME, $request);
parent::__construct(Application::APP_ID, $request);
$this->searchService = $searchService;
$this->configService = $configService;
$this->miscService = $miscService;
Expand Down
4 changes: 2 additions & 2 deletions lib/Controller/NavigationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function __construct(
IRequest $request, IConfig $config, IFullTextSearchManager $fullTextSearchManager,
ConfigService $configService, MiscService $miscService
) {
parent::__construct(Application::APP_NAME, $request);
parent::__construct(Application::APP_ID, $request);
$this->config = $config;
$this->fullTextSearchManager = $fullTextSearchManager;
$this->configService = $configService;
Expand All @@ -96,7 +96,7 @@ public function navigate(): TemplateResponse {

$this->fullTextSearchManager->addJavascriptAPI();

return new TemplateResponse(Application::APP_NAME, 'navigate', $data);
return new TemplateResponse(Application::APP_ID, 'navigate', $data);
}

}
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct(
IRequest $request, ConfigService $configService, SettingsService $settingsService,
MiscService $miscService
) {
parent::__construct(Application::APP_NAME, $request);
parent::__construct(Application::APP_ID, $request);
$this->configService = $configService;
$this->settingsService = $settingsService;
$this->miscService = $miscService;
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/TemplatesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function __construct(
IRequest $request, IConfig $config, ConfigService $configService,
ProviderService $providerService, MiscService $miscService
) {
parent::__construct(Application::APP_NAME, $request);
parent::__construct(Application::APP_ID, $request);
$this->config = $config;
$this->configService = $configService;
$this->providerService = $providerService;
Expand Down
14 changes: 7 additions & 7 deletions lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function getAppValue(string $key): string {
$defaultValue = $this->defaults[$key];
}

return $this->config->getAppValue(Application::APP_NAME, $key, $defaultValue);
return $this->config->getAppValue(Application::APP_ID, $key, $defaultValue);
}

/**
Expand All @@ -150,7 +150,7 @@ public function getAppValue(string $key): string {
* @param string $value
*/
public function setAppValue(string $key, string $value) {
$this->config->setAppValue(Application::APP_NAME, $key, $value);
$this->config->setAppValue(Application::APP_ID, $key, $value);
}

/**
Expand All @@ -159,7 +159,7 @@ public function setAppValue(string $key, string $value) {
* @param string $key
*/
public function deleteAppValue(string $key) {
$this->config->deleteAppValue(Application::APP_NAME, $key);
$this->config->deleteAppValue(Application::APP_ID, $key);
}

/**
Expand All @@ -176,7 +176,7 @@ public function getUserValue(string $key): string {
}

return $this->config->getUserValue(
$this->userId, Application::APP_NAME, $key, $defaultValue
$this->userId, Application::APP_ID, $key, $defaultValue
);
}

Expand All @@ -189,7 +189,7 @@ public function getUserValue(string $key): string {
* @throws PreConditionNotMetException
*/
public function setUserValue(string $key, string $value) {
$this->config->setUserValue($this->userId, Application::APP_NAME, $key, $value);
$this->config->setUserValue($this->userId, Application::APP_ID, $key, $value);
}

/**
Expand All @@ -201,7 +201,7 @@ public function setUserValue(string $key, string $value) {
* @return string
*/
public function getValueForUser(string $userId, string $key) {
return $this->config->getUserValue($userId, Application::APP_NAME, $key);
return $this->config->getUserValue($userId, Application::APP_ID, $key);
}

/**
Expand All @@ -214,7 +214,7 @@ public function getValueForUser(string $userId, string $key) {
* @throws PreConditionNotMetException
*/
public function setValueForUser(string $userId, string $key, string $value) {
$this->config->setUserValue($userId, Application::APP_NAME, $key, $value);
$this->config->setUserValue($userId, Application::APP_ID, $key, $value);
}


Expand Down
2 changes: 1 addition & 1 deletion lib/Service/MiscService.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(ILogger $logger) {
*/
public function log(string $message, int $level = 2) {
$data = array(
'app' => Application::APP_NAME,
'app' => Application::APP_ID,
'level' => $level
);

Expand Down
14 changes: 7 additions & 7 deletions lib/Service/ProviderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,13 @@ public function serialize(array $providers): array {
*
*/
public function addJavascriptAPI() {
Util::addStyle(Application::APP_NAME, 'fulltextsearch');
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.api');
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.settings');
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.searchbox');
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.result');
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1.navigation');
Util::addScript(Application::APP_NAME, 'fulltextsearch.v1');
Util::addStyle(Application::APP_ID, 'fulltextsearch');
Util::addScript(Application::APP_ID, 'fulltextsearch.v1.api');
Util::addScript(Application::APP_ID, 'fulltextsearch.v1.settings');
Util::addScript(Application::APP_ID, 'fulltextsearch.v1.searchbox');
Util::addScript(Application::APP_ID, 'fulltextsearch.v1.result');
Util::addScript(Application::APP_ID, 'fulltextsearch.v1.navigation');
Util::addScript(Application::APP_ID, 'fulltextsearch.v1');
}


Expand Down
4 changes: 2 additions & 2 deletions lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ public function __construct(
* @throws Exception
*/
public function getForm(): TemplateResponse {
return new TemplateResponse(Application::APP_NAME, 'settings.admin', []);
return new TemplateResponse(Application::APP_ID, 'settings.admin', []);
}


/**
* @return string the section ID, e.g. 'sharing'
*/
public function getSection(): string {
return Application::APP_NAME;
return Application::APP_ID;
}


Expand Down
4 changes: 2 additions & 2 deletions lib/Settings/AdminSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(IL10N $l10n, IURLGenerator $urlGenerator) {
* {@inheritdoc}
*/
public function getID(): string {
return Application::APP_NAME;
return Application::APP_ID;
}

/**
Expand All @@ -86,6 +86,6 @@ public function getPriority(): int {
* {@inheritdoc}
*/
public function getIcon(): string {
return $this->urlGenerator->imagePath(Application::APP_NAME, 'fulltextsearch_black.svg');
return $this->urlGenerator->imagePath(Application::APP_ID, 'fulltextsearch_black.svg');
}
}
4 changes: 2 additions & 2 deletions templates/navigate.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
use OCA\FullTextSearch\AppInfo\Application;
use OCP\Util;

Util::addScript(Application::APP_NAME, 'navigate');
Util::addStyle(Application::APP_NAME, 'navigate');
Util::addScript(Application::APP_ID, 'navigate');
Util::addStyle(Application::APP_ID, 'navigate');

?>

Expand Down
8 changes: 4 additions & 4 deletions templates/settings.admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
use OCP\Util;


Util::addScript(Application::APP_NAME, 'admin.elements');
Util::addScript(Application::APP_NAME, 'admin.settings');
Util::addScript(Application::APP_NAME, 'admin');
Util::addScript(Application::APP_ID, 'admin.elements');
Util::addScript(Application::APP_ID, 'admin.settings');
Util::addScript(Application::APP_ID, 'admin');

Util::addStyle(Application::APP_NAME, 'admin');
Util::addStyle(Application::APP_ID, 'admin');

?>

Expand Down

0 comments on commit a4d8572

Please sign in to comment.