Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Binary file added assets/drawing.otg
Binary file not shown.
Binary file added assets/odgtemplate.otg
Binary file not shown.
6 changes: 5 additions & 1 deletion css/viewer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
background-image: url('../img/x-office-spreadsheet.svg');
}

.icon-filetype-presentation{
.icon-filetype-presentation {
background-image: url('../img/x-office-presentation.svg');
}

.icon-filetype-draw {
background-image: url('../img/x-office-drawing.svg');
}

.icon-collabora {
opacity: 0.6;
&:hover {
Expand Down
1 change: 1 addition & 0 deletions img/x-office-drawing.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 16 additions & 9 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ public function boot(IBootContext $context): void {
\OCP\Util::addScript('richdocuments', 'richdocuments-viewer');
});

$context->injectFn(function(ITemplateManager $templateManager, IL10N $l10n, IConfig $config) {
$context->injectFn(function(ITemplateManager $templateManager, IL10N $l10n, IConfig $config, CapabilitiesService $capabilitiesService) {
if (empty($capabilitiesService->getCapabilities())) {
return;
}
$ooxml = $config->getAppValue(self::APPNAME, 'doc_format', '') === 'ooxml';
$templateManager->registerTemplateFileCreator(function () use ($l10n, $ooxml) {
$odtType = new TemplateFileCreator('richdocuments', $l10n->t('New document'), ($ooxml ? '.docx' : '.odt'));
Expand Down Expand Up @@ -125,6 +128,18 @@ public function boot(IBootContext $context): void {
$odpType->setRatio(16/9);
return $odpType;
});

if (!$capabilitiesService->hasDrawSupport()) {
return;
}
$templateManager->registerTemplateFileCreator(function () use ($l10n, $ooxml) {
$odpType = new TemplateFileCreator('richdocuments', $l10n->t('New graphic'), '.odg');
$odpType->addMimetype('application/vnd.oasis.opendocument.graphics');
$odpType->addMimetype('application/vnd.oasis.opendocument.graphics-template');
$odpType->setIconClass('icon-filetype-draw');
$odpType->setRatio(16/9);
return $odpType;
});
});

$context->injectFn(function (SymfonyAdapter $eventDispatcher) {
Expand Down Expand Up @@ -159,14 +174,6 @@ function() {
public function registerProvider() {
$container = $this->getContainer();

// Register mimetypes
/** @var Detection $detector */
$detector = $container->query(\OCP\Files\IMimeTypeDetector::class);
$detector->getAllMappings();
$detector->registerType('ott','application/vnd.oasis.opendocument.text-template');
$detector->registerType('ots', 'application/vnd.oasis.opendocument.spreadsheet-template');
$detector->registerType('otp', 'application/vnd.oasis.opendocument.presentation-template');

/** @var IPreview $previewManager */
$previewManager = $container->query(IPreview::class);

Expand Down
10 changes: 9 additions & 1 deletion lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,18 @@ public function __construct(IL10N $l10n, AppConfig $config, CapabilitiesService
public function getCapabilities() {
if (!$this->capabilities) {
$collaboraCapabilities = $this->capabilitiesService->getCapabilities();
$filteredMimetypes = self::MIMETYPES;
// If version is too old, draw is not supported
if (!$this->capabilitiesService->hasDrawSupport()) {
$filteredMimetypes = array_diff($filteredMimetypes, [
'application/vnd.oasis.opendocument.graphics',
'application/vnd.oasis.opendocument.graphics-flat-xml',
]);
}
$this->capabilities = [
'richdocuments' => [
'version' => \OC::$server->getAppManager()->getAppVersion('richdocuments'),
'mimetypes' => self::MIMETYPES,
'mimetypes' => $filteredMimetypes,
'mimetypesNoDefaultOpen' => self::MIMETYPES_OPTIONAL,
'collabora' => $collaboraCapabilities,
'direct_editing' => isset($collaboraCapabilities['hasMobileSupport']) ?: false,
Expand Down
15 changes: 10 additions & 5 deletions lib/Service/CapabilitiesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,27 @@ public function getCapabilities() {
return $this->capabilities;
}

public function hasTemplateSaveAs() {
public function hasDrawSupport(): bool {
$productVersion = $this->getCapabilities()['productVersion'] ?? '0.0.0.0';
return version_compare($productVersion, '6.4.7', '>=');
}

public function hasTemplateSaveAs(): bool {
return $this->getCapabilities()['hasTemplateSaveAs'] ?? false;
}

public function hasTemplateSource() {
public function hasTemplateSource(): bool {
return $this->getCapabilities()['hasTemplateSource'] ?? false;
}

public function clear() {
public function clear(): void {
$this->cache->remove('capabilities');
}

public function refetch() {
public function refetch(): void {
$remoteHost = $this->config->getAppValue('richdocuments', 'wopi_url');
if ($remoteHost === '') {
return [];
return;
}
$capabilitiesEndpoint = rtrim($remoteHost, '/') . '/hosting/capabilities';

Expand Down
6 changes: 4 additions & 2 deletions lib/Template/CollaboraTemplateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public function getTemplateType(): string {
public function getCustomTemplates(string $mimetype): array {
if (in_array($mimetype, TemplateManager::MIMES_DOCUMENTS)) {
$type = 'document';
} else if (in_array($mimetype, TemplateManager::MIMES_SHEETS)) {
} elseif (in_array($mimetype, TemplateManager::MIMES_SHEETS)) {
$type = 'spreadsheet';
} else if (in_array($mimetype, TemplateManager::MIMES_PRESENTATIONS)) {
} elseif (in_array($mimetype, TemplateManager::MIMES_PRESENTATIONS)) {
$type = 'presentation';
} elseif (in_array($mimetype, TemplateManager::MIMES_DRAWINGS)) {
$type = 'drawing';
} else {
return [];
}
Expand Down
30 changes: 12 additions & 18 deletions lib/TemplateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,30 @@ class TemplateManager {
'application/vnd.openxmlformats-officedocument.presentationml.template',
'application/vnd.ms-powerpoint'
];
const MIMES_DRAWINGS = [
'application/vnd.oasis.opendocument.graphics-template',
];

/** @var array Template mime types match */
static public $tplTypes = [
'document' => self::MIMES_DOCUMENTS,
'spreadsheet' => self::MIMES_SHEETS,
'presentation' => self::MIMES_PRESENTATIONS
'presentation' => self::MIMES_PRESENTATIONS,
'drawing' => self::MIMES_DRAWINGS,
];

const TYPE_EXTENTION = [
'document' => 'odt',
'spreadsheet' => 'ods',
'presentation' => 'odp'
'presentation' => 'odp',
'drawing' => 'odg',
];

const TYPE_EXTENSION_OOXML = [
'document' => 'docx',
'spreadsheet' => 'xlsx',
'presentation' => 'pptx'
];

const EMPTY_TEMPLATE_ID_TYPE = [
-1 => 'document',
-2 => 'spreadsheet',
-3 => 'presentation',
'presentation' => 'pptx',
];
const EMPTY_TEMPLATE_TYPE_ID = [
'document' => -1,
'spreadsheet' => -2,
'presentation' => -3,
];


/**
* Template manager
Expand Down Expand Up @@ -218,6 +211,7 @@ private function getEmpty($type = null) {
'document.ott',
'spreadsheet.ots',
'presentation.otp',
'drawing.otg',
];

foreach ($templates as $template) {
Expand Down Expand Up @@ -451,7 +445,7 @@ public function formatNodeReturn(File $template) {
'preview' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.getPreview', ['fileId' => $template->getId()]),
'type' => $this->flipTypes()[$template->getMimeType()],
'delete' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.templates.delete', ['fileId' => $template->getId()]),
'extension' => $ooxml ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType],
'extension' => ($ooxml && isset(self::TYPE_EXTENSION_OOXML[$documentType])) ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType],
];
}

Expand All @@ -478,13 +472,13 @@ public function formatEmpty(File $template) {
'id' => $template->getId(),
'name' => $this->l->t('Empty'),
'type' => $this->flipTypes()[$template->getMimeType()],
'extension' => $ooxml ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType],
'extension' => ($ooxml && isset(self::TYPE_EXTENSION_OOXML[$documentType])) ? self::TYPE_EXTENSION_OOXML[$documentType] : self::TYPE_EXTENTION[$documentType],
];
}

public function isValidTemplateMime($mime, $type = null) {
if ($type === null) {
$allMimes = array_merge(self::$tplTypes['document'], self::$tplTypes['spreadsheet'], self::$tplTypes['presentation']);
$allMimes = array_merge(self::$tplTypes['document'], self::$tplTypes['spreadsheet'], self::$tplTypes['presentation'], self::$tplTypes['drawing']);
if (!in_array($mime, $allMimes)) {
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ $(document).ready(function() {
}
}

OC.MimeType._mimeTypeIcons['application/vnd.oasis.opendocument.graphics'] = OC.imagePath('richdocuments', 'x-office-draw')

// Open the template picker if there was a create parameter detected on load
if (Preload.create && Preload.create.type && Preload.create.filename) {
FilesAppIntegration.preloadCreate()
Expand Down