Skip to content

Commit

Permalink
added missing parts for translation
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Borysenko <andrey18106x@gmail.com>
  • Loading branch information
andrey18106 committed Feb 20, 2024
1 parent d851058 commit bb8b9fa
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 70 deletions.
7 changes: 5 additions & 2 deletions lib/Notifications/ExAppNotifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct(
private readonly IFactory $factory,
private readonly IURLGenerator $url,
private readonly ExAppService $service,
private readonly IFactory $l10nFactory
) {
}

Expand All @@ -40,17 +41,19 @@ public function prepare(INotification $notification, string $languageCode): INot
throw new InvalidArgumentException('ExApp is disabled');
}

$l = $this->l10nFactory->get($notification->getApp(), $languageCode);

$parameters = $notification->getSubjectParameters();
if (isset($parameters['link']) && $parameters['link'] !== '') {
$notification->setLink($parameters['link']);
}
$notification->setIcon($this->url->imagePath(Application::APP_ID, 'app-dark.svg'));

if (isset($parameters['rich_subject']) && isset($parameters['rich_subject_params'])) {
$notification->setRichSubject($parameters['rich_subject'], $parameters['rich_subject_params']);
$notification->setRichSubject($l->t($parameters['rich_subject']), $parameters['rich_subject_params']);
}
if (isset($parameters['rich_message']) && isset($parameters['rich_message_params'])) {
$notification->setRichMessage($parameters['rich_message'], $parameters['rich_message_params']);
$notification->setRichMessage($l->t($parameters['rich_message']), $parameters['rich_message_params']);
}

return $notification;
Expand Down
98 changes: 50 additions & 48 deletions src/filesplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,58 @@ function generateAppAPIProxyUrl(appId, route) {
return generateUrl(`/apps/app_api/proxy/${appId}/${route}`)
}

if (OCA.Files && OCA.Files.fileActions) { // NC 27
state.fileActions.forEach(fileAction => {
const mimes = fileAction.mime.split(',').map(mime => mime.trim()) // multiple mimes are separated by comma
document.addEventListener('DOMContentLoaded', () => {
if (OCA.Files && OCA.Files.fileActions) { // NC 27
state.fileActions.forEach(fileAction => {
const mimes = fileAction.mime.split(',').map(mime => mime.trim()) // multiple mimes are separated by comma

const actionHandler = (fileName, context) => {
const file = context.$file[0]
const exAppFileActionHandler = generateAppAPIProxyUrl(fileAction.appid, fileAction.action_handler)
axios.post(exAppFileActionHandler, {
fileId: Number(file.dataset.id),
name: fileName,
directory: file.dataset.path,
etag: file.dataset.etag,
mime: file.dataset.mime,
favorite: file.dataset.favorite || 'false',
permissions: Number(file.dataset.permissions),
fileType: file.dataset.type,
size: Number(file.dataset.size),
mtime: Number(file.dataset.mtime) / 1000, // convert ms to s
shareTypes: file.dataset?.shareTypes || null,
shareAttributes: file.dataset?.shareAttributes || null,
sharePermissions: file.dataset?.sharePermissions || null,
shareOwner: file.dataset?.shareOwner || null,
shareOwnerId: file.dataset?.shareOwnerId || null,
userId: getCurrentUser().uid,
instanceId: state.instanceId,
}).then((response) => {
if (response.status === 200) {
OC.dialogs.info(t('app_api', 'Action request sent to ExApp'), t(fileAction.appid, fileAction.display_name))
} else {
console.debug(response)
const actionHandler = (fileName, context) => {
const file = context.$file[0]
const exAppFileActionHandler = generateAppAPIProxyUrl(fileAction.appid, fileAction.action_handler)
axios.post(exAppFileActionHandler, {
fileId: Number(file.dataset.id),
name: fileName,
directory: file.dataset.path,
etag: file.dataset.etag,
mime: file.dataset.mime,
favorite: file.dataset.favorite || 'false',
permissions: Number(file.dataset.permissions),
fileType: file.dataset.type,
size: Number(file.dataset.size),
mtime: Number(file.dataset.mtime) / 1000, // convert ms to s
shareTypes: file.dataset?.shareTypes || null,
shareAttributes: file.dataset?.shareAttributes || null,
sharePermissions: file.dataset?.sharePermissions || null,
shareOwner: file.dataset?.shareOwner || null,
shareOwnerId: file.dataset?.shareOwnerId || null,
userId: getCurrentUser().uid,
instanceId: state.instanceId,
}).then((response) => {
if (response.status === 200) {
OC.dialogs.info(t('app_api', 'Action request sent to ExApp'), t(fileAction.appid, fileAction.display_name))
} else {
console.debug(response)
OC.dialogs.info(t('app_api', 'Error while sending File action request to ExApp'), t(fileAction.appid, fileAction.display_name))
}
}).catch((error) => {
console.error('error', error)
OC.dialogs.info(t('app_api', 'Error while sending File action request to ExApp'), t(fileAction.appid, fileAction.display_name))
})
}

mimes.forEach((mimeType) => {
const action = {
name: fileAction.name,
displayName: t(fileAction.appid, fileAction.display_name),
mime: mimeType,
permissions: Number(fileAction.permissions),
order: Number(fileAction.order),
icon: fileAction.icon !== '' ? generateAppAPIProxyUrl(fileAction.appid, fileAction.icon) : null,
iconClass: fileAction.icon === '' ? 'icon-app-api' : '',
actionHandler,
}
}).catch((error) => {
console.error('error', error)
OC.dialogs.info(t('app_api', 'Error while sending File action request to ExApp'), t(fileAction.appid, fileAction.display_name))
OCA.Files.fileActions.registerAction(action)
})
}

mimes.forEach((mimeType) => {
const action = {
name: fileAction.name,
displayName: t(fileAction.appid, fileAction.display_name),
mime: mimeType,
permissions: Number(fileAction.permissions),
order: Number(fileAction.order),
icon: fileAction.icon !== '' ? generateAppAPIProxyUrl(fileAction.appid, fileAction.icon) : null,
iconClass: fileAction.icon === '' ? 'icon-app-api' : '',
actionHandler,
}
OCA.Files.fileActions.registerAction(action)
})
})
}
}
})
43 changes: 23 additions & 20 deletions src/filesplugin28.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { generateUrl } from '@nextcloud/router'
import { loadState } from '@nextcloud/initial-state'
import { registerFileAction, FileAction } from '@nextcloud/files'
import { getCurrentUser } from '@nextcloud/auth'
import { translate as t } from '@nextcloud/l10n'

const state = loadState('app_api', 'ex_files_actions_menu')

Expand All @@ -28,29 +29,10 @@ function generateAppAPIProxyUrl(appId, route) {
return generateUrl(`/apps/app_api/proxy/${appId}/${route}`)
}

state.fileActions.forEach(fileAction => {
if (fileAction.icon === '') {
const inlineSvgIcon = loadStaticAppAPIInlineSvgIcon()
registerFileAction28(fileAction, inlineSvgIcon)
} else {
loadExAppInlineSvgIcon(fileAction.appid, fileAction.icon).then((svg) => {
if (svg !== null) {
// Set css filter for theming
const parser = new DOMParser()
const icon = parser.parseFromString(svg, 'image/svg+xml')
icon.documentElement.setAttribute('style', 'filter: var(--background-invert-if-dark);')
// Convert back to inline string
const inlineSvgIcon = icon.documentElement.outerHTML
registerFileAction28(fileAction, inlineSvgIcon)
}
})
}
})

function registerFileAction28(fileAction, inlineSvgIcon) {
const action = new FileAction({
id: fileAction.name,
displayName: () => fileAction.display_name,
displayName: () => t(fileAction.appid, fileAction.display_name),
iconSvgInline: () => inlineSvgIcon,
order: Number(fileAction.order),
enabled(files, view) {
Expand Down Expand Up @@ -112,3 +94,24 @@ function registerFileAction28(fileAction, inlineSvgIcon) {
})
registerFileAction(action)
}

document.addEventListener('DOMContentLoaded', () => {
state.fileActions.forEach(fileAction => {
if (fileAction.icon === '') {
const inlineSvgIcon = loadStaticAppAPIInlineSvgIcon()
registerFileAction28(fileAction, inlineSvgIcon)
} else {
loadExAppInlineSvgIcon(fileAction.appid, fileAction.icon).then((svg) => {
if (svg !== null) {
// Set css filter for theming
const parser = new DOMParser()
const icon = parser.parseFromString(svg, 'image/svg+xml')
icon.documentElement.setAttribute('style', 'filter: var(--background-invert-if-dark);')
// Convert back to inline string
const inlineSvgIcon = icon.documentElement.outerHTML
registerFileAction28(fileAction, inlineSvgIcon)
}
})
}
})
})

0 comments on commit bb8b9fa

Please sign in to comment.