Skip to content

Commit

Permalink
Merge pull request #41 from LibreCodeCoop/feature/make-compatible-wit…
Browse files Browse the repository at this point in the history
…h-nextcloud-27

Make compatible with nextcloud 27
  • Loading branch information
vitormattos authored Sep 1, 2023
2 parents 65171c7 + 6e1cf37 commit 90fc5e7
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 37 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<bugs>https://github.com/librecodecoop/my_company/issues</bugs>
<repository type="git">https://github.com/librecodecoop/my_company</repository>
<dependencies>
<nextcloud min-version="28" max-version="28"/>
<nextcloud min-version="27" max-version="27"/>
</dependencies>

<repair-steps>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8",
"nextcloud/ocp": "dev-master",
"nextcloud/ocp": "dev-stable27",
"roave/security-advisories": "dev-master"
},
"config": {
Expand Down
19 changes: 9 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions css/filesIndex.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,28 @@
display: none;
}

#app-content-vue .files-list__row-name {
padding-left: 15px;
#app-content-files .fileactions {
display: none;
}

#app-content-vue .files-list__row-actions {
#app-content-files .column-selection {
display: none;
}

#app-content-vue .files-list__header {

#app-content-files .files-fileList .selection {
display: none;
}


#app-content-vue .files-list .files-list__row-checkbox {
#app-content-files .files-controls {
display: none;
}

#app-content-files .files-filestable thead {
top: unset;
}

#body-user .toast-error {
display: none;
#app-content #view-toggle {
position: fixed;
}
93 changes: 86 additions & 7 deletions lib/Controller/FolderSectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public function section(string $fileid): TemplateResponse {
}

private function showFileList($dir = '', $view = '', $fileNotFound = false) {
$nav = new \OCP\Template('files', 'appnavigation', '');

// Load the files we need
\OCP\Util::addStyle('my_company', 'filesIndex');
\OCP\Util::addStyle('files', 'merged');
Expand All @@ -112,6 +114,46 @@ private function showFileList($dir = '', $view = '', $fileNotFound = false) {
$favElements['folders'] = [];
}

$collapseClasses = '';
if (count($favElements['folders']) > 0) {
$collapseClasses = 'collapsible';
}

$favoritesSublistArray = [];

$navBarPositionPosition = 6;
foreach ($favElements['folders'] as $favElement) {
$element = [
'id' => str_replace('/', '-', $favElement),
'dir' => $favElement,
'order' => $navBarPositionPosition,
'name' => basename($favElement),
'icon' => 'folder',
'params' => [
'view' => 'files',
'dir' => $favElement,
],
];

array_push($favoritesSublistArray, $element);
$navBarPositionPosition++;
}

$navItems = \OCA\Files\App::getNavigationManager()->getAll();

// add the favorites entry in menu
$navItems['favorites']['sublist'] = $favoritesSublistArray;
$navItems['favorites']['classes'] = $collapseClasses;

// parse every menu and add the expanded user value
foreach ($navItems as $key => $item) {
$navItems[$key]['expanded'] = $this->config->getUserValue($userId, 'files', 'show_' . $item['id'], '0') === '1';
}

$nav->assign('navigationItems', $navItems);

$contentItems = [];

try {
// If view is files, we use the directory, otherwise we use the root storage
$storageInfo = $this->getStorageInfo(($view === 'files' && $dir) ? $dir : '/');
Expand All @@ -120,19 +162,44 @@ private function showFileList($dir = '', $view = '', $fileNotFound = false) {
}

$this->initialState->provideInitialState(FilesAppInfoApplication::APP_ID, 'storageStats', $storageInfo);
$this->initialState->provideInitialState(FilesAppInfoApplication::APP_ID, 'navigation', $navItems);
$this->initialState->provideInitialState(FilesAppInfoApplication::APP_ID, 'config', [
'show_hidden' => false
]);
$this->initialState->provideInitialState(FilesAppInfoApplication::APP_ID, 'viewConfigs', []);
$this->initialState->provideInitialState(FilesAppInfoApplication::APP_ID, 'favoriteFolders', $favElements['folders'] ?? []);

// File sorting user config
$filesSortingConfig = json_decode($this->config->getUserValue($userId, 'files', 'files_sorting_configs', '{}'), true);
$this->initialState->provideInitialState(FilesAppInfoApplication::APP_ID, 'filesSortingConfig', $filesSortingConfig);

// render the container content for every navigation item
foreach ($navItems as $item) {
$content = '';
if (isset($item['script'])) {
$content = $this->renderScript($item['appname'], $item['script']);
}
// parse submenus
if (isset($item['sublist'])) {
foreach ($item['sublist'] as $subitem) {
$subcontent = '';
if (isset($subitem['script'])) {
$subcontent = $this->renderScript($subitem['appname'], $subitem['script']);
}
$contentItems[$subitem['id']] = [
'id' => $subitem['id'],
'content' => $subcontent
];
}
}
$contentItems[$item['id']] = [
'id' => $item['id'],
'content' => $content
];
}

$this->eventDispatcher->dispatchTyped(new ResourcesLoadAdditionalScriptsEvent());
$event = new LoadAdditionalScriptsEvent();
$this->eventDispatcher->dispatchTyped($event);
$this->eventDispatcher->dispatchTyped(new ResourcesLoadAdditionalScriptsEvent());
$this->eventDispatcher->dispatchTyped(new LoadSidebar());
// Load Viewer scripts
if (class_exists(LoadViewer::class)) {
Expand All @@ -142,9 +209,23 @@ private function showFileList($dir = '', $view = '', $fileNotFound = false) {
$this->initialState->provideInitialState(FilesAppInfoApplication::APP_ID, 'templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false);
$this->initialState->provideInitialState(FilesAppInfoApplication::APP_ID, 'templates', $this->templateManager->listCreators());

$params = [
'fileNotFound' => $fileNotFound ? 1 : 0
];
$params = [];
$params['usedSpacePercent'] = (int) $storageInfo['relative'];
$params['owner'] = $storageInfo['owner'] ?? '';
$params['ownerDisplayName'] = $storageInfo['ownerDisplayName'] ?? '';
$params['isPublic'] = false;
$params['allowShareWithLink'] = $this->shareManager->shareApiAllowLinks() ? 'yes' : 'no';
$params['defaultFileSorting'] = $filesSortingConfig['files']['sorting_mode'] ?? 'basename';
$params['defaultFileSortingDirection'] = $filesSortingConfig['files']['sorting_direction'] ?? 'asc';
$params['showgridview'] = $this->config->getUserValue($userId, 'files', 'show_grid', false);
$showHidden = (bool) $this->config->getUserValue($userId, 'files', 'show_hidden', false);
$params['showHiddenFiles'] = $showHidden ? 1 : 0;
$cropImagePreviews = (bool) $this->config->getUserValue($userId, 'files', 'crop_image_previews', true);
$params['cropImagePreviews'] = $cropImagePreviews ? 1 : 0;
$params['fileNotFound'] = $fileNotFound ? 1 : 0;
$params['appNavigation'] = $nav;
$params['appContents'] = $contentItems;
$params['hiddenFields'] = $event->getHiddenFields();

$response = new TemplateResponse(
FilesAppInfoApplication::APP_ID,
Expand All @@ -153,8 +234,6 @@ private function showFileList($dir = '', $view = '', $fileNotFound = false) {
);
$policy = new ContentSecurityPolicy();
$policy->addAllowedFrameDomain('\'self\'');
// Allow preview service worker
$policy->addAllowedWorkerSrcDomain('\'self\'');
$response->setContentSecurityPolicy($policy);

return $response;
Expand Down
14 changes: 3 additions & 11 deletions tests/psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.14.1@b9d355e0829c397b9b3b47d0c0ed042a8a70284d">
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<file src="lib/AppInfo/Application.php">
<UndefinedClass>
<code>PublicShareTemplateProvider</code>
Expand All @@ -12,20 +12,12 @@
<MissingDependency>
<code><![CDATA[$this->rootFolder]]></code>
<code><![CDATA[$this->rootFolder]]></code>
<code>\OCP\Template</code>
<code>private</code>
</MissingDependency>
<UndefinedClass>
<code><![CDATA[$this->activityHelper]]></code>
<code>FilesAppInfoApplication</code>
<code>FilesAppInfoApplication</code>
<code>FilesAppInfoApplication</code>
<code>FilesAppInfoApplication</code>
<code>FilesAppInfoApplication</code>
<code>FilesAppInfoApplication</code>
<code>FilesAppInfoApplication</code>
<code>FilesAppInfoApplication</code>
<code>LoadAdditionalScriptsEvent</code>
<code>LoadSidebar</code>
<code>\OCA\Files\App</code>
<code>\OC_App</code>
<code>\OC_Helper</code>
<code>private</code>
Expand Down

0 comments on commit 90fc5e7

Please sign in to comment.