Browse Source

feat(dashboard): wish happy birthday

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
pull/49730/head
Daniel Kesselberg 11 months ago
parent
commit
4df99d5ef4
No known key found for this signature in database GPG Key ID: 4A81C29F63464E8F
  1. 1
      apps/dashboard/lib/Controller/DashboardController.php
  2. 26
      apps/dashboard/lib/Service/DashboardService.php
  3. 13
      apps/dashboard/src/DashboardApp.vue
  4. 100
      apps/dashboard/tests/DashboardServiceTest.php
  5. 4
      dist/dashboard-main.js
  6. 2
      dist/dashboard-main.js.map

1
apps/dashboard/lib/Controller/DashboardController.php

@ -68,6 +68,7 @@ class DashboardController extends Controller {
$this->initialState->provideInitialState('layout', $this->service->getLayout());
$this->initialState->provideInitialState('appStoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
$this->initialState->provideInitialState('firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1');
$this->initialState->provideInitialState('birthdate', $this->service->getBirthdate());
$this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0');
$response = new TemplateResponse('dashboard', 'index', [

26
apps/dashboard/lib/Service/DashboardService.php

@ -9,12 +9,17 @@ declare(strict_types=1);
namespace OCA\Dashboard\Service;
use JsonException;
use OCP\Accounts\IAccountManager;
use OCP\Accounts\PropertyDoesNotExistException;
use OCP\IConfig;
use OCP\IUserManager;
class DashboardService {
public function __construct(
private IConfig $config,
private ?string $userId,
private IUserManager $userManager,
private IAccountManager $accountManager,
) {
}
@ -42,4 +47,25 @@ class DashboardService {
return array_values(array_filter(explode(',', $configStatuses), fn (string $value) => $value !== ''));
}
}
public function getBirthdate(): string {
if ($this->userId === null) {
return '';
}
$user = $this->userManager->get($this->userId);
if ($user === null) {
return '';
}
$account = $this->accountManager->getAccount($user);
try {
$birthdate = $account->getProperty(IAccountManager::PROPERTY_BIRTHDATE);
} catch (PropertyDoesNotExistException) {
return '';
}
return $birthdate->getValue();
}
}

13
apps/dashboard/src/DashboardApp.vue

@ -147,6 +147,7 @@ import ApiDashboardWidget from './components/ApiDashboardWidget.vue'
const panels = loadState('dashboard', 'panels')
const firstRun = loadState('dashboard', 'firstRun')
const birthdate = new Date(loadState('dashboard', 'birthdate'))
const statusInfo = {
weather: {
@ -194,15 +195,21 @@ export default {
apiWidgets: [],
apiWidgetItems: {},
loadingItems: true,
birthdate,
}
},
computed: {
greeting() {
const time = this.timer.getHours()
const isBirthday = this.birthdate instanceof Date
&& this.birthdate.getMonth() === this.timer.getMonth()
&& this.birthdate.getDate() === this.timer.getDate()
// Determine part of the day
let partOfDay
if (time >= 22 || time < 5) {
if (isBirthday) {
partOfDay = 'birthday'
} else if (time >= 22 || time < 5) {
partOfDay = 'night'
} else if (time >= 18) {
partOfDay = 'evening'
@ -231,6 +238,10 @@ export default {
generic: t('dashboard', 'Hello'),
withName: t('dashboard', 'Hello, {name}', { name: this.displayName }, undefined, { escape: false }),
},
birthday: {
generic: t('dashboard', 'Happy birthday 🥳🤩🎂🎉'),
withName: t('dashboard', 'Happy birthday, {name} 🥳🤩🎂🎉', { name: this.displayName }, undefined, { escape: false }),
},
}
// Figure out which greeting to show

100
apps/dashboard/tests/DashboardServiceTest.php

@ -0,0 +1,100 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Dashboard\Tests;
use OC\Accounts\Account;
use OCA\Dashboard\Service\DashboardService;
use OCP\Accounts\IAccountManager;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;
class DashboardServiceTest extends TestCase {
private IConfig&MockObject $config;
private IUserManager&MockObject $userManager;
private IAccountManager&MockObject $accountManager;
private DashboardService $service;
protected function setUp(): void {
parent::setUp();
$this->config = $this->createMock(IConfig::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->accountManager = $this->createMock(IAccountManager::class);
$this->service = new DashboardService(
$this->config,
'alice',
$this->userManager,
$this->accountManager,
);
}
public function testGetBirthdate() {
$user = $this->createMock(IUser::class);
$this->userManager->method('get')
->willReturn($user);
$account = new Account($user);
$account->setProperty(
IAccountManager::PROPERTY_BIRTHDATE,
'2024-12-10T00:00:00.000Z',
IAccountManager::SCOPE_LOCAL,
IAccountManager::VERIFIED,
);
$this->accountManager->method('getAccount')
->willReturn($account);
$birthdate = $this->service->getBirthdate();
$this->assertEquals('2024-12-10T00:00:00.000Z', $birthdate);
}
public function testGetBirthdatePropertyDoesNotExist() {
$user = $this->createMock(IUser::class);
$this->userManager->method('get')
->willReturn($user);
$account = new Account($user);
$this->accountManager->method('getAccount')
->willReturn($account);
$birthdate = $this->service->getBirthdate();
$this->assertEquals('', $birthdate);
}
public function testGetBirthdateUserNotFound() {
$this->userManager->method('get')
->willReturn(null);
$birthdate = $this->service->getBirthdate();
$this->assertEquals('', $birthdate);
}
public function testGetBirthdateNoUserId() {
$service = new DashboardService(
$this->config,
null,
$this->userManager,
$this->accountManager,
);
$birthdate = $service->getBirthdate();
$this->assertEquals('', $birthdate);
}
}

4
dist/dashboard-main.js
File diff suppressed because it is too large
View File

2
dist/dashboard-main.js.map
File diff suppressed because it is too large
View File

Loading…
Cancel
Save