-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sharing support, optimize code structur
- Loading branch information
Showing
9 changed files
with
112 additions
and
36 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
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OCA\Files_MindMap\Listener; | ||
|
||
use OCA\Files_MindMap\AppInfo\Application; | ||
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; | ||
use OCP\AppFramework\Http\TemplateResponse; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Util; | ||
|
||
/** | ||
* @template-implements IEventListener<BeforeTemplateRenderedEvent> | ||
*/ | ||
class LoadPublicViewerListener implements IEventListener { | ||
public function handle(Event $event): void { | ||
if (!$event instanceof BeforeTemplateRenderedEvent) { | ||
return; | ||
} | ||
// Make sure we are on a public page rendering | ||
if ($event->getResponse()->getRenderAs() !== TemplateResponse::RENDER_AS_PUBLIC) { | ||
return; | ||
} | ||
Util::addScript(Application::APPNAME, 'files_mindmap-public'); | ||
} | ||
} |
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,9 @@ | ||
import { getLoggerBuilder } from '@nextcloud/logger' | ||
|
||
|
||
const logger = getLoggerBuilder() | ||
.setApp('Files_MindMap') | ||
.detectUser() | ||
.build() | ||
|
||
export default logger |
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,45 @@ | ||
import FilesMindMap from './mindmap' | ||
import logger from './logger' | ||
|
||
import { getSharingToken, isPublicShare } from '@nextcloud/sharing/public' | ||
|
||
if (isPublicShare()) { | ||
OCA.FilesMindMap = FilesMindMap; | ||
FilesMindMap.init(); | ||
|
||
if (FilesMindMap.isMindmapPublic()) { | ||
window.addEventListener('DOMContentLoaded', function() { | ||
var sharingToken = getSharingToken(); | ||
var downloadUrl = OC.generateUrl('/s/{token}/download', {token: sharingToken}); | ||
var viewer = OCA.FilesMindMap; | ||
|
||
|
||
const contentElmt = document.getElementById('files-public-content'); | ||
const footerElmt = document.querySelector('body > footer') || document.querySelector('#app-content > footer'); | ||
if (contentElmt) { | ||
if (OCA.Viewer) { | ||
contentElmt.innerHTML = ''; | ||
OCA.Viewer.setRootElement('#files-public-content') | ||
OCA.Viewer.open({ path: '/' }); | ||
|
||
footerElmt.style.display = 'none'; | ||
|
||
// This is an ugly implementation, need to remove the top margin after viewer creates the iframe | ||
setTimeout(() => { | ||
const frameElmt = document.querySelector('#viewer > iframe'); | ||
if (frameElmt) { | ||
frameElmt.style.marginTop = '0'; | ||
} | ||
}, 1000); | ||
|
||
} else { | ||
logger.error('Viewer is not available, cannot preview mindmap'); | ||
} | ||
} | ||
|
||
}); | ||
} | ||
|
||
|
||
console.log('files_mindmap public.js loaded'); | ||
} |
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