Skip to content

Commit

Permalink
#5: adds highlighting to reminders (#42)
Browse files Browse the repository at this point in the history
Co-authored-by: Dirk Peter <dirk.peter@softwareg.com>
  • Loading branch information
dirk-peter-c8y and Dirk Peter authored Aug 30, 2024
1 parent 697f924 commit 4013d01
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ <h2 translate>Reminder</h2>

<!-- single reminder item template -->
<ng-template #reminderItem let-reminder="reminder">
<li class="reminder-item" [class.text-muted]="reminder.status !== reminderStatus.active">
<li class="reminder-item" [ngClass]="{
'text-muted': reminder.status !== reminderStatus.active,
'changed': reminder.changed
}">
<header>
<i
class="status-icon"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,24 @@ aside {
overflow: hidden;
box-shadow: inset 0 -1px 0 var(--c8y-component-border-color, var(--c8y-root-component-border-color));

&::after {
content: '';
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: block;
opacity: 0;
pointer-events: none;
transition: all .3s ease-in-out;
box-shadow: inset 0 0 10px var(--c8y-brand-primary);
}

&.changed::after {
opacity: 1;
}

.btn-hollow {
background-color: transparent !important;
color: @color-gray-4;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import {
ReminderStatus,
ReminderType,
REMINDER_DRAWER_OPEN_CLASS,
REMINDER_HIGHLIGHT_DURATION_SECONDS,
REMINDER_LOCAL_STORAGE_DEFAULT_CONFIG,
REMINDER_MAIN_HEADER_CLASS
REMINDER_MAIN_HEADER_CLASS,
} from '../../reminder.model';
import { ReminderService } from '../../services/reminder.service';
import { ReminderModalComponent } from '../reminder-modal/reminder-modal.component';
Expand Down Expand Up @@ -52,6 +53,7 @@ export class ReminderDrawerComponent implements OnDestroy {
private rightDrawerOpen = false;
private updateTimer?: NodeJS.Timeout;
private _open = false;
private _previousState: Reminder['id'][][] = [];

constructor(
private alertService: AlertService,
Expand Down Expand Up @@ -118,6 +120,8 @@ export class ReminderDrawerComponent implements OnDestroy {
this.reminders = reminders;
this.lastUpdate = new Date();
this.reminderGroups = this.reminderService.groupReminders(reminders);

if (reminders.length) this.highlightChanges();
}

private getReminderTypes(): void {
Expand All @@ -128,7 +132,7 @@ export class ReminderDrawerComponent implements OnDestroy {
}

private handleConfigChange(config: ReminderConfig): void {
if (this.reminderTypeFilter !== config.filter.reminderType) {
if (this.reminderTypeFilter !== config.filter?.reminderType) {
this.reminderTypeFilter = config.filter.reminderType;
this.filterByType();
}
Expand All @@ -137,6 +141,28 @@ export class ReminderDrawerComponent implements OnDestroy {
this.browserNotificationsEnabled = config.browser;
}

private highlightChanges(): void {
if (!this._previousState.length) return;

// check if a reminder is new in a group
this.reminderGroups.forEach((group, index) => {
group.reminders.forEach((reminder) => {
if (!this._previousState[index].includes(reminder.id)) {
reminder.changed = true;
setTimeout(
() => delete reminder.changed,
REMINDER_HIGHLIGHT_DURATION_SECONDS * 1000
);
}
});
});

// store current state for future comparison
this._previousState = this.reminderGroups.map((group) => {
return group.reminders.map((reminder) => reminder.id);
});
}

private initSubscriptions(): void {
// check if the actual drawer was opened
this.subscriptions.add(
Expand Down
1 change: 1 addition & 0 deletions src/app/reminder-plugin/reminder.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const REMINDER_DRAWER_OPEN_CLASS = 'drawerOpen';
export const REMINDER_MAIN_HEADER_CLASS = 'app-main-header';
export const REMINDER_MAX_COUNTER = 10;
export const REMINDER_TEXT_LENGTH = 100;
export const REMINDER_HIGHLIGHT_DURATION_SECONDS = 5;
export const REMINDER_TENENAT_OPTION_CATEGORY: ITenantOption['category'] = 'c8y.reminder';
export const REMINDER_TENENAT_OPTION_TYPE_KEY: ITenantOption['key'] = 'types';
export const REMINDER_LOCAL_STORAGE_FILTER = 'c8y_rpFilter';
Expand Down

0 comments on commit 4013d01

Please sign in to comment.