OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
email reminder settings component - without backend support
ulfertsbc3244342885
diff --git a/config/locales/js-en.yml b/config/locales/js-en.ymlindex 65a9478fa1a..9ef346e0449 100644--- a/config/locales/js-en.yml+++ b/config/locales/js-en.yml@@ -630,9 +630,11 @@ en:reminders:settings:daily:- title: 'Send me daily email reminders for unread notifications'+ add_time: 'Add time'+ enable: 'Enable daily email reminders'explanation: 'You will receive these reminders only for unread notifications and only at hours you specify.'- label: 'Time %{counter}'+ time_label: 'Time %{counter}:'+ title: 'Send me daily email reminders for unread notifications'title: 'Email reminders'diff --git a/frontend/src/app/core/i18n/i18n.service.ts b/frontend/src/app/core/i18n/i18n.service.tsindex 2a28687e00e..a537f9ca753 100644--- a/frontend/src/app/core/i18n/i18n.service.ts+++ b/frontend/src/app/core/i18n/i18n.service.ts@@ -18,6 +18,8 @@ export interface GlobalI18n {toHumanSize(num:number, options?:ToHumanSizeOptions):string;+ toTime(format:string, date:Date):string;+locale:string;firstDayOfWeek:number;pluralization:any;@@ -58,6 +60,10 @@ export class I18nService {return this._i18n.lookup(translateId);}+ public toTime(format:string, date:Date):string {+ return this._i18n.toTime(format, date);+ }+public toNumber = this._i18n.toNumber.bind(this._i18n);public toPercentage = this._i18n.toPercentage.bind(this._i18n);diff --git a/frontend/src/app/features/user-preferences/reminder-settings/page/reminder-settings-page.component.ts b/frontend/src/app/features/user-preferences/reminder-settings/page/reminder-settings-page.component.tsindex eacbe2f035c..ab31d0ad393 100644--- a/frontend/src/app/features/user-preferences/reminder-settings/page/reminder-settings-page.component.ts+++ b/frontend/src/app/features/user-preferences/reminder-settings/page/reminder-settings-page.component.ts@@ -37,13 +37,12 @@ export class ReminderSettingsPageComponent implements OnInit {}ngOnInit():void {- this.userId = this.userId || this.uiRouterGlobals.params.userId;this.currentUserService.user$.pipe(take(1)).subscribe((user) => {- this.userId = this.userId || user.id!;+ this.userId = (this.userId || this.uiRouterGlobals.params.userId) as string || user.id!;this.stateService.get(this.userId);});}diff --git a/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.html b/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.htmlindex 5b3e178fa6a..fc7a28e5a7e 100644--- a/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.html+++ b/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.html@@ -1,20 +1,54 @@-<label- *ngFor="let time of dailyReminderTimes; index as i"- class="form--label-with-check-box">- <div class="form--check-box-container">- <input type="checkbox" class="form--check-box" checked>- </div>- {{text.label(i + 1)}}- <div class="form--field -no-label">- <div class="form--field-container">- <div class="form--text-field-container">- <input- type="time"- [value]="time"- step="1800"- required- attr.data-qa-selector="op-settings-daily-time--time-{{i + 1}}">- </div>- </div>- </div>-</label>+<div+ class="op-reminder-settings-daily-time--enable">+ <input+ [(ngModel)]="enabled"+ type="checkbox"+ id="op-reminder-settings-daily-time--enable">+ <label+ for="op-reminder-settings-daily-time--enable"+ [textContent]="text.enable">+ </label>+</div>++<div *ngFor="let time of selectedTimes; index as i; trackBy: indexTracker"+ class="op-reminder-settings-daily-time--row">+ <input+ type="checkbox"+ [(ngModel)]="selectedTimes[i].active"+ [disabled]="isActiveDisabled"+ class="op-reminder-settings-daily-time--active"+ attr.data-qa-selector="op-settings-daily-time--active-{{i + 1}}">+ <label+ class="op-reminder-settings-daily-time--label"+ [textContent]="text.timeLabel(i + 1)"+ attr.for="op-reminder-settings-daily-time-{{i + 1}}--time">+ </label>+ <select+ [(ngModel)]="selectedTimes[i]"+ [disabled]="!enabled"+ class="op-reminder-settings-daily-time--time form--select -narrow"+ attr.id="op-reminder-settings-daily-time-{{i + 1}}--time"+ required="true">+ <option+ *ngFor="let time of availableTimes"+ [ngValue]="time"+ [disabled]="isOptionDisabled(time, selectedTimes[i])">+ {{time.label}}+ </option>+ </select>+ <button+ class="op-link op-reminder-settings-daily-time--remove"+ type="button"+ *ngIf="isRemovable"+ (click)="removeTime(i)">+ <op-icon icon-classes="icon-small icon-remove icon4"></op-icon>+ </button>+</div>++<button+ class="button op-reminder-settings-daily-time--add"+ [disabled]="nonAddable"+ (click)="addTime()">+ <i class="button--icon icon-add"></i>+ <span class="button--text">{{text.addTime}}</span>+</button>diff --git a/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.sass b/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.sassnew file mode 100644index 00000000000..af2b77d7b6d--- /dev/null+++ b/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.sass@@ -0,0 +1,36 @@+@import "helpers"++.op-reminder-settings-daily-time+ &--enable+ display: flex+ align-items: center+ margin-top: 30px+ margin-bottom: 10px++ &--row+ margin-left: 40px+ line-height: 45px+ display: flex+ align-items: center++ &:nth-of-type(1)+ margin-top: 10px++ &--active+ flex: 0 0 25px++ &--label+ flex: 0 0 60px+ margin-bottom: 0+ @include text-shortener++ &--time+ height: 32px+ width: 150px++ &--remove+ padding-left: 10px++ &--add+ margin-top: 20px+ margin-left: 40pxdiff --git a/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.ts b/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.tsindex 72944ba93d5..22794e54151 100644--- a/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.ts+++ b/frontend/src/app/features/user-preferences/reminder-settings/reminder-time/reminder-settings-daily-time.component.ts@@ -1,30 +1,119 @@-import { Component, Input, OnInit } from "@angular/core";-import { ChangeDetectionStrategy } from "@angular/core";+import { Component, ChangeDetectionStrategy } from '@angular/core';import { I18nService } from 'core-app/core/i18n/i18n.service';-import { UserPreferencesStore } from 'core-app/features/user-preferences/state/user-preferences.store';++interface ReminderTime {+ label:string+ time:string+ active:boolean,+ suggested:boolean+}@Component({selector: 'op-reminder-settings-daily-time',templateUrl: './reminder-settings-daily-time.component.html',+ styleUrls: ['./reminder-settings-daily-time.component.sass'],changeDetection: ChangeDetectionStrategy.OnPush,})-export class ReminderSettingsDailyTimeComponent implements OnInit {- public dailyReminderTimes = ["08:00", "12:00", "16:00"]+export class ReminderSettingsDailyTimeComponent {+ public selectedTimes:Array<ReminderTime> = [];++ public availableTimes:Array<ReminderTime> = [];++ public enabled = true;text = {- label: (counter:number):string => this.I18n.t('js.reminders.settings.daily.label', { counter: counter }),+ timeLabel: (counter:number):string => this.I18n.t('js.reminders.settings.daily.time_label', { counter }),+ addTime: this.I18n.t('js.reminders.settings.daily.add_time'),+ enable: this.I18n.t('js.reminders.settings.daily.enable'),};constructor(private I18n:I18nService,- private store:UserPreferencesStore,) {+ this.setupAvailableTimes();+ this.setupSelectedTimes();+ }++ get nonAddable():boolean {+ return !this.enabled || this.selectedTimes.length === this.availableTimes.length;+ }++ indexTracker(index:number):number {+ return index;+ }++ addTime():void {+ if (this.nonAddable) {+ return;+ }++ const time = this.firstAvailableSuggested() || this.firstAfterSelected();++ if (time) {+ this+ .selectedTimes+ .push(time);+ }+ }++ isOptionDisabled(time:ReminderTime, self:ReminderTime):boolean {+ return time !== self && this.selectedTimes.includes(time);+ }++ get isActiveDisabled():boolean {+ return !this.enabled || this.selectedTimes.length === 1;+ }++ get isRemovable():boolean {+ return this.enabled && this.selectedTimes.length > 1;+ }++ removeTime(index:number):void {+ this.selectedTimes.splice(index, 1);++ if (this.selectedTimes.length === 1) {+ this.selectedTimes[0].active = true;+ }}- ngOnInit():void {+ private setupAvailableTimes() {+ const date = new Date();++ for (let i = 0; i < 24; i++) {+ date.setTime(1000 * 60 * 60 * (i - 1));+ this.availableTimes.push(this.toAvailableTime(date));+ }+ }+ private setupSelectedTimes() {+ // TODO: fetch selectedTimes from user preferences+ this.selectedTimes = [this.availableTimes[8]];}- public saveChanges():void {+ private firstAvailableSuggested() {+ return this.availableTimes.filter((v) => v.suggested && !this.selectedTimes.includes(v))[0];+ }++ private firstAfterSelected() {+ const indexLastSelected = this.availableTimes.indexOf(this.selectedTimes[this.selectedTimes.length - 1]);++ for (let i = indexLastSelected; i < 24 + indexLastSelected; i++) {+ if (!this.selectedTimes.includes(this.availableTimes[i % 24])) {+ return this.availableTimes[i % 24];+ }+ }++ return null;+ }++ private toAvailableTime(date:Date) {+ const time = date.toLocaleTimeString('en-US', { hour12: false, hour: 'numeric', minute: 'numeric' });++ return {+ label: this.I18n.toTime('time.formats.time', date),+ time,+ active: true,+ suggested: ['08:00', '12:00', '15:00', '18:00'].includes(time),+ };}}diff --git a/frontend/src/app/features/user-preferences/user-preferences.module.ts b/frontend/src/app/features/user-preferences/user-preferences.module.tsindex b65caa0559e..f2e623432ec 100644--- a/frontend/src/app/features/user-preferences/user-preferences.module.ts+++ b/frontend/src/app/features/user-preferences/user-preferences.module.ts@@ -29,7 +29,7 @@ import { ReminderSettingsDailyTimeComponent } from 'core-app/features/user-prefeNotificationsSettingsToolbarComponent,NotificationSettingsTableComponent,ReminderSettingsPageComponent,- ReminderSettingsDailyTimeComponent+ ReminderSettingsDailyTimeComponent,],imports: [CommonModule,diff --git a/frontend/src/test/i18n-shim.ts b/frontend/src/test/i18n-shim.tsindex c3c1054101a..8f46c8ea11c 100644--- a/frontend/src/test/i18n-shim.ts+++ b/frontend/src/test/i18n-shim.ts@@ -31,4 +31,7 @@ export class I18nShim implements GlobalI18n {public strftime = _.identity;public toHumanSize = _.identity;++ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment+ public toTime = _.identity;}diff --git a/spec/features/notifications/reminder_mail_spec.rb b/spec/features/notifications/reminder_mail_spec.rbindex e33935e933c..226cb1257fb 100644--- a/spec/features/notifications/reminder_mail_spec.rb+++ b/spec/features/notifications/reminder_mail_spec.rb@@ -14,16 +14,6 @@ describe "Reminder email", type: :feature, js: true docurrent_user doFactoryBot.create :user,notification_settings: [- FactoryBot.build(:mail_notification_setting,- involved: false,- watched: false,- mentioned: false,- work_package_commented: false,- work_package_created: false,- work_package_processed: false,- work_package_prioritized: false,- work_package_scheduled: false,- all: false),FactoryBot.build(:in_app_notification_setting,involved: false,watched: false,@@ -33,16 +23,6 @@ describe "Reminder email", type: :feature, js: true dowork_package_processed: false,work_package_prioritized: false,work_package_scheduled: false,- all: false),- FactoryBot.build(:mail_digest_notification_setting,- involved: true,- watched: true,- mentioned: true,- work_package_commented: true,- work_package_created: true,- work_package_processed: true,- work_package_prioritized: true,- work_package_scheduled: true,all: false)]end@@ -60,6 +40,11 @@ describe "Reminder email", type: :feature, js: true doreminders_settings_page.visit!# By default a reminder timed for 8:00 should be configured- reminders_settings_page.expect_active_daily_times("08:00")+ reminders_settings_page.expect_active_daily_times("08:00 am")++ reminders_settings_page.add_time++ # The next suggested time is taken: 12:00+ reminders_settings_page.expect_active_daily_times("08:00 am", "12:00 pm")endenddiff --git a/spec/support/pages/reminders/settings.rb b/spec/support/pages/reminders/settings.rbindex 747993ae8f0..b317a74d72a 100644--- a/spec/support/pages/reminders/settings.rb+++ b/spec/support/pages/reminders/settings.rb@@ -42,23 +42,24 @@ module Pagesedit_user_path(user, tab: :reminders)end+ def add_time+ page+ .click_button 'Add time'+ end+def expect_active_daily_times(*times)times.each_with_index do |time, index|expect(page)- .to have_checked_field "Time #{index + 1}"+ .to have_css("input[data-qa-selector='op-settings-daily-time--active-#{index + 1}']:checked")expect(page)- .to have_css("input[data-qa-selector='op-settings-daily-time--time-#{index + 1}']")-- expect(page.find("input[data-qa-selector='op-settings-daily-time--time-#{index + 1}']").value)- .to eql(time)+ .to have_field("Time #{index + 1}", text: time)endenddef saveclick_button 'Save'end-endendend