Merge pull request #9979 from nextcloud/chore/remove-dead-dashboard-code
chore(dashboard): remove obsolete js widget
This commit is contained in:
Коммит
b0ea83024c
|
@ -21,9 +21,7 @@ use OCA\Mail\Contracts\IMailTransmission;
|
|||
use OCA\Mail\Contracts\ITrustedSenderService;
|
||||
use OCA\Mail\Contracts\IUserPreferences;
|
||||
use OCA\Mail\Dashboard\ImportantMailWidget;
|
||||
use OCA\Mail\Dashboard\ImportantMailWidgetV2;
|
||||
use OCA\Mail\Dashboard\UnreadMailWidget;
|
||||
use OCA\Mail\Dashboard\UnreadMailWidgetV2;
|
||||
use OCA\Mail\Events\BeforeImapClientCreated;
|
||||
use OCA\Mail\Events\DraftMessageCreatedEvent;
|
||||
use OCA\Mail\Events\DraftSavedEvent;
|
||||
|
@ -70,7 +68,6 @@ use OCP\AppFramework\App;
|
|||
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||
use OCP\Dashboard\IAPIWidgetV2;
|
||||
use OCP\DB\Events\AddMissingIndicesEvent;
|
||||
use OCP\IServerContainer;
|
||||
use OCP\Search\IFilteringProvider;
|
||||
|
@ -150,13 +147,8 @@ class Application extends App implements IBootstrap {
|
|||
$context->registerMiddleWare(ErrorMiddleware::class);
|
||||
$context->registerMiddleWare(ProvisioningMiddleware::class);
|
||||
|
||||
if (interface_exists(IAPIWidgetV2::class)) {
|
||||
$context->registerDashboardWidget(ImportantMailWidgetV2::class);
|
||||
$context->registerDashboardWidget(UnreadMailWidgetV2::class);
|
||||
} else {
|
||||
$context->registerDashboardWidget(ImportantMailWidget::class);
|
||||
$context->registerDashboardWidget(UnreadMailWidget::class);
|
||||
}
|
||||
$context->registerDashboardWidget(ImportantMailWidget::class);
|
||||
$context->registerDashboardWidget(UnreadMailWidget::class);
|
||||
|
||||
if (interface_exists(IFilteringProvider::class)) {
|
||||
$context->registerSearchProvider(FilteringProvider::class);
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Mail\Dashboard;
|
||||
|
||||
/**
|
||||
* Requires Nextcloud >= 27.1.0
|
||||
*/
|
||||
class ImportantMailWidgetV2 extends MailWidgetV2 {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getId(): string {
|
||||
return 'mail';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTitle(): string {
|
||||
return $this->l10n->t('Important mail');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSearchFilter(): string {
|
||||
return 'is:important';
|
||||
}
|
||||
}
|
|
@ -17,16 +17,19 @@ use OCA\Mail\Exception\ServiceException;
|
|||
use OCA\Mail\Service\AccountService;
|
||||
use OCP\AppFramework\Services\IInitialState;
|
||||
use OCP\Dashboard\IAPIWidget;
|
||||
use OCP\Dashboard\IAPIWidgetV2;
|
||||
use OCP\Dashboard\IButtonWidget;
|
||||
use OCP\Dashboard\IIconWidget;
|
||||
use OCP\Dashboard\IOptionWidget;
|
||||
use OCP\Dashboard\Model\WidgetButton;
|
||||
use OCP\Dashboard\Model\WidgetItem;
|
||||
use OCP\Dashboard\Model\WidgetItems;
|
||||
use OCP\Dashboard\Model\WidgetOptions;
|
||||
use OCP\IL10N;
|
||||
use OCP\IURLGenerator;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Util;
|
||||
|
||||
abstract class MailWidget implements IAPIWidget, IIconWidget, IOptionWidget {
|
||||
abstract class MailWidget implements IAPIWidget, IAPIWidgetV2, IIconWidget, IOptionWidget, IButtonWidget {
|
||||
protected IURLGenerator $urlGenerator;
|
||||
protected IUserManager $userManager;
|
||||
protected AccountService $accountService;
|
||||
|
@ -85,12 +88,7 @@ abstract class MailWidget implements IAPIWidget, IIconWidget, IOptionWidget {
|
|||
* @inheritDoc
|
||||
*/
|
||||
public function load(): void {
|
||||
Util::addScript(Application::APP_ID, 'dashboard');
|
||||
|
||||
$this->initialState->provideInitialState(
|
||||
'mail-accounts',
|
||||
$this->accountService->findByUserId($this->userId)
|
||||
);
|
||||
// No assets need to be loaded anymore as the widget is rendered from the API
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,10 +152,41 @@ abstract class MailWidget implements IAPIWidget, IIconWidget, IOptionWidget {
|
|||
}, $emails);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems {
|
||||
$items = $this->getItems($userId, $since, $limit);
|
||||
return new WidgetItems(
|
||||
$items,
|
||||
empty($items) ? $this->l10n->t('No message found yet') : '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getWidgetOptions(): WidgetOptions {
|
||||
return new WidgetOptions(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getWidgetButtons(string $userId): array {
|
||||
$buttons = [];
|
||||
|
||||
if ($this->userId !== null) {
|
||||
$accounts = $this->accountService->findByUserId($this->userId);
|
||||
if (empty($accounts)) {
|
||||
$buttons[] = new WidgetButton(
|
||||
WidgetButton::TYPE_SETUP,
|
||||
$this->urlGenerator->linkToRouteAbsolute('mail.page.setup'),
|
||||
$this->l10n->t('Set up an account'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Mail\Dashboard;
|
||||
|
||||
use OCP\Dashboard\IAPIWidgetV2;
|
||||
use OCP\Dashboard\IButtonWidget;
|
||||
use OCP\Dashboard\Model\WidgetButton;
|
||||
use OCP\Dashboard\Model\WidgetItems;
|
||||
|
||||
/**
|
||||
* Requires Nextcloud >= 27.1.0
|
||||
*/
|
||||
abstract class MailWidgetV2 extends MailWidget implements IAPIWidgetV2, IButtonWidget {
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems {
|
||||
$items = $this->getItems($userId, $since, $limit);
|
||||
return new WidgetItems(
|
||||
$items,
|
||||
empty($items) ? $this->l10n->t('No message found yet') : '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function load(): void {
|
||||
// No assets need to be loaded anymore as the widget is rendered from the API
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getWidgetButtons(string $userId): array {
|
||||
$buttons = [];
|
||||
|
||||
if ($this->userId !== null) {
|
||||
$accounts = $this->accountService->findByUserId($this->userId);
|
||||
if (empty($accounts)) {
|
||||
$buttons[] = new WidgetButton(
|
||||
WidgetButton::TYPE_SETUP,
|
||||
$this->urlGenerator->linkToRouteAbsolute('mail.page.setup'),
|
||||
$this->l10n->t('Set up an account'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $buttons;
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace OCA\Mail\Dashboard;
|
||||
|
||||
/**
|
||||
* Requires Nextcloud >= 27.1.0
|
||||
*/
|
||||
class UnreadMailWidgetV2 extends MailWidgetV2 {
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getId(): string {
|
||||
return 'mail-unread';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTitle(): string {
|
||||
return $this->l10n->t('Unread mail');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSearchFilter(): string {
|
||||
return 'is:unread';
|
||||
}
|
||||
}
|
|
@ -1,150 +0,0 @@
|
|||
<!--
|
||||
- SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
||||
- SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
-->
|
||||
|
||||
<template>
|
||||
<DashboardWidget :items="importantMessages"
|
||||
:show-more-url="''"
|
||||
:loading="loading">
|
||||
<template #default="{ item }">
|
||||
<DashboardWidgetItem :class="{unread: itemUnread(item)}"
|
||||
:target-url="itemTargetUrl(item)"
|
||||
:main-text="itemMainText(item)"
|
||||
:sub-text="itemSubText(item)">
|
||||
<template #avatar>
|
||||
<Avatar v-if="item.from && item.from.length"
|
||||
:email="item.from[0].email"
|
||||
:display-name="item.from[0].label"
|
||||
:disable-tooltip="true"
|
||||
:size="44" />
|
||||
</template>
|
||||
</DashboardWidgetItem>
|
||||
</template>
|
||||
<template #empty-content>
|
||||
<EmptyContent id="mail--empty-content" :name="t('mail', 'No message found yet')">
|
||||
<template #icon>
|
||||
<IconCheck :size="65" />
|
||||
</template>
|
||||
<template #action>
|
||||
<div class="no-account">
|
||||
<a v-if="accounts.length === 0" :href="accountSetupUrl" class="button">{{ t('mail', 'Set up an account') }}</a>
|
||||
</div>
|
||||
</template>
|
||||
</EmptyContent>
|
||||
</template>
|
||||
</DashboardWidget>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { loadState } from '@nextcloud/initial-state'
|
||||
import { generateUrl, imagePath } from '@nextcloud/router'
|
||||
import DashboardWidget from '@nextcloud/vue/dist/Components/NcDashboardWidget.js'
|
||||
import DashboardWidgetItem from '@nextcloud/vue/dist/Components/NcDashboardWidgetItem.js'
|
||||
import orderBy from 'lodash/fp/orderBy.js'
|
||||
import prop from 'lodash/fp/prop.js'
|
||||
import EmptyContent from '@nextcloud/vue/dist/Components/NcEmptyContent.js'
|
||||
import IconCheck from 'vue-material-design-icons/Check.vue'
|
||||
|
||||
import Avatar from '../components/Avatar.vue'
|
||||
import { fetchEnvelopes } from '../service/MessageService.js'
|
||||
import logger from '../logger.js'
|
||||
import { fetchAll } from '../service/MailboxService.js'
|
||||
|
||||
const accounts = loadState('mail', 'mail-accounts')
|
||||
const orderByDateInt = orderBy(prop('dateInt'), 'desc')
|
||||
|
||||
export default {
|
||||
name: 'Dashboard',
|
||||
components: {
|
||||
Avatar,
|
||||
DashboardWidget,
|
||||
DashboardWidgetItem,
|
||||
EmptyContent,
|
||||
IconCheck,
|
||||
},
|
||||
props: {
|
||||
query: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
messages: [],
|
||||
accounts,
|
||||
loading: true,
|
||||
fetchedAccounts: 0,
|
||||
emptyImage: imagePath('mail', 'newsletter.svg'),
|
||||
accountSetupUrl: generateUrl('/apps/mail/#/setup'),
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
importantMessages() {
|
||||
if (!this.messages) {
|
||||
return []
|
||||
}
|
||||
return orderByDateInt(this.messages).slice(0, 7)
|
||||
},
|
||||
},
|
||||
async mounted() {
|
||||
const accountInboxes = await Promise.all(this.accounts.map(async (account) => {
|
||||
logger.debug('account', {
|
||||
account,
|
||||
})
|
||||
|
||||
const mailboxes = await fetchAll(account.accountId)
|
||||
|
||||
logger.debug('mailboxes', {
|
||||
mailboxes,
|
||||
})
|
||||
|
||||
return mailboxes.filter(mb => mb.specialRole === 'inbox')
|
||||
}))
|
||||
const inboxes = accountInboxes.flat()
|
||||
|
||||
logger.debug(`found ${inboxes.length} inboxes`, {
|
||||
inboxes,
|
||||
})
|
||||
|
||||
await Promise.all(inboxes.map(async (mailbox) => {
|
||||
const messages = await fetchEnvelopes(mailbox.accountId, mailbox.databaseId, this.query, undefined, 10)
|
||||
messages.forEach(message => { message.id = message.databaseId })
|
||||
this.messages = this.messages !== null ? [...this.messages, ...messages] : messages
|
||||
this.fetchedAccounts++
|
||||
}))
|
||||
|
||||
this.loading = false
|
||||
},
|
||||
methods: {
|
||||
itemMainText(item) {
|
||||
return item.from && item.from.length ? item.from[0].label : ''
|
||||
},
|
||||
itemSubText(item) {
|
||||
return item.subject
|
||||
},
|
||||
itemTargetUrl(item) {
|
||||
return generateUrl(`/apps/mail/box/priority/thread/${item.databaseId}`)
|
||||
},
|
||||
itemUnread(item) {
|
||||
return !item.flags.seen
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
#mail--empty-content {
|
||||
text-align: center;
|
||||
margin-top: 5vh;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
}
|
||||
.no-account {
|
||||
margin-top: 5vh;
|
||||
margin-right: 5px;
|
||||
}
|
||||
.unread :deep(.item__details) {
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
|
@ -1,33 +0,0 @@
|
|||
/**
|
||||
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import Vue from 'vue'
|
||||
import { getRequestToken } from '@nextcloud/auth'
|
||||
import { generateFilePath } from '@nextcloud/router'
|
||||
|
||||
import Nextcloud from './mixins/Nextcloud.js'
|
||||
import DashboardImportant from './views/DashboardImportant.vue'
|
||||
import DashboardUnread from './views/DashboardUnread.vue'
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
__webpack_nonce__ = btoa(getRequestToken())
|
||||
// eslint-disable-next-line camelcase
|
||||
__webpack_public_path__ = generateFilePath('mail', '', 'js/')
|
||||
|
||||
Vue.mixin(Nextcloud)
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const register = OCA?.Dashboard?.register || (() => {})
|
||||
|
||||
register('mail', (el) => {
|
||||
const View = Vue.extend(DashboardImportant)
|
||||
new View().$mount(el)
|
||||
})
|
||||
|
||||
register('mail-unread', (el) => {
|
||||
const View = Vue.extend(DashboardUnread)
|
||||
new View().$mount(el)
|
||||
})
|
||||
})
|
|
@ -1,19 +0,0 @@
|
|||
<!--
|
||||
- SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
||||
- SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
-->
|
||||
|
||||
<template>
|
||||
<Dashboard query="is:important" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Dashboard from '../components/Dashboard.vue'
|
||||
|
||||
export default {
|
||||
name: 'DashboardImportant',
|
||||
components: {
|
||||
Dashboard,
|
||||
},
|
||||
}
|
||||
</script>
|
|
@ -1,19 +0,0 @@
|
|||
<!--
|
||||
- SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
||||
- SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
-->
|
||||
|
||||
<template>
|
||||
<Dashboard query="is:unread" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Dashboard from '../components/Dashboard.vue'
|
||||
|
||||
export default {
|
||||
name: 'DashboardUnread',
|
||||
components: {
|
||||
Dashboard,
|
||||
},
|
||||
}
|
||||
</script>
|
|
@ -42,7 +42,6 @@ const plugins = [
|
|||
module.exports = {
|
||||
entry: {
|
||||
autoredirect: path.join(__dirname, 'src/autoredirect.js'),
|
||||
dashboard: path.join(__dirname, 'src/main-dashboard.js'),
|
||||
mail: path.join(__dirname, 'src/main.js'),
|
||||
oauthpopup: path.join(__dirname, 'src/main-oauth-popup.js'),
|
||||
settings: path.join(__dirname, 'src/main-settings'),
|
||||
|
|
Загрузка…
Ссылка в новой задаче