Skip to content

Commit

Permalink
feat(dashboard): wish happy birthday
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
  • Loading branch information
kesselb committed Dec 9, 2024
1 parent 6f3ee6b commit 66f369e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions apps/dashboard/lib/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function index(): TemplateResponse {
$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', [
Expand Down
22 changes: 22 additions & 0 deletions apps/dashboard/lib/Service/DashboardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
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,
) {

}
Expand Down Expand Up @@ -42,4 +47,21 @@ public function getStatuses() {
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);
$account = $this->accountManager->getAccount($user);

try {
$birthdate = $account->getProperty(IAccountManager::PROPERTY_BIRTHDATE);
} catch (PropertyDoesNotExistException $e) {
return '';
}

return $birthdate->getValue();
}
}
13 changes: 12 additions & 1 deletion apps/dashboard/src/DashboardApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dist/dashboard-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dashboard-main.js.map

Large diffs are not rendered by default.

0 comments on commit 66f369e

Please sign in to comment.