-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:truenas/webui into NAS-133262
# Conflicts: # src/assets/i18n/ko.json
- Loading branch information
Showing
161 changed files
with
1,227 additions
and
668 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
src/app/modules/dates/pipes/schedule-description/schedule-description.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import { | ||
createServiceFactory, | ||
mockProvider, | ||
SpectatorService, | ||
} from '@ngneat/spectator/jest'; | ||
import { ScheduleDescriptionPipe } from 'app/modules/dates/pipes/schedule-description/schedule-description.pipe'; | ||
import { LanguageService } from 'app/services/language.service'; | ||
import { LocaleService } from 'app/services/locale.service'; | ||
|
||
describe('ScheduleDescriptionPipe', () => { | ||
let spectator: SpectatorService<ScheduleDescriptionPipe>; | ||
|
||
const createPipe = createServiceFactory({ | ||
service: ScheduleDescriptionPipe, | ||
providers: [ | ||
mockProvider(LocaleService, { | ||
getShortTimeFormat: () => 'HH:mm', | ||
getPreferredTimeFormat: () => 'HH:mm:ss', | ||
}), | ||
mockProvider(LanguageService, { | ||
currentLanguage: 'en', | ||
}), | ||
], | ||
}); | ||
|
||
it('describes schedule without `begin` and `end` fields', () => { | ||
spectator = createPipe(); | ||
|
||
expect(spectator.service.transform({ | ||
minute: '0', | ||
hour: '0', | ||
dom: '*', | ||
month: '*', | ||
dow: '*', | ||
})).toBe('At 00:00, every day'); | ||
|
||
expect(spectator.service.transform({ | ||
minute: '0', | ||
hour: '0', | ||
dom: '*', | ||
month: '*', | ||
dow: '1', | ||
})).toBe('At 00:00, only on Monday'); | ||
|
||
expect(spectator.service.transform({ | ||
minute: '0', | ||
hour: '0', | ||
dom: '1', | ||
month: '*', | ||
dow: '*', | ||
})).toBe('At 00:00, on day 1 of the month'); | ||
|
||
expect(spectator.service.transform({ | ||
minute: '0', | ||
hour: '0', | ||
dom: '*', | ||
month: '1', | ||
dow: '*', | ||
})).toBe('At 00:00, every day, only in January'); | ||
|
||
expect(spectator.service.transform({ | ||
minute: '20', | ||
hour: '*/2', | ||
dom: '*', | ||
month: '*', | ||
dow: '1,2,3,4,5', | ||
})).toBe('At 20 minutes past the hour, every 2 hours, only on Monday, Tuesday, Wednesday, Thursday, and Friday'); | ||
}); | ||
|
||
it("uses user's language when describing the schedule", () => { | ||
spectator = createPipe({ | ||
providers: [ | ||
mockProvider(LanguageService, { | ||
currentLanguage: 'uk', | ||
}), | ||
], | ||
}); | ||
|
||
expect(spectator.service.transform({ | ||
minute: '0', | ||
hour: '0', | ||
dom: '*', | ||
month: '*', | ||
dow: '*', | ||
})).toBe('О 00:00, щоденно'); | ||
|
||
expect(spectator.service.transform({ | ||
minute: '20', | ||
hour: '*/2', | ||
dom: '*', | ||
month: '*', | ||
dow: '1,2', | ||
})).toBe('О 20 хвилині, кожні 2 годин, тільки в понеділок та вівторок'); | ||
}); | ||
|
||
it("uses user's time 12/24h time format preference when describing the schedule", () => { | ||
spectator = createPipe({ | ||
providers: [ | ||
mockProvider(LocaleService, { | ||
getPreferredTimeFormat: () => 'hh:mm:ss', | ||
}), | ||
], | ||
}); | ||
|
||
expect(spectator.service.transform({ | ||
minute: '45', | ||
hour: '14', | ||
dom: '*', | ||
month: '*', | ||
dow: '*', | ||
})).toBe('At 02:45 PM, every day'); | ||
}); | ||
|
||
it('returns an empty string when invalid schedule is provided and logs console error', () => { | ||
spectator = createPipe(); | ||
jest.spyOn(console, 'error').mockImplementation(); | ||
|
||
expect(spectator.service.transform({})).toBe(''); | ||
expect(spectator.service.transform(undefined)).toBe(''); | ||
expect(spectator.service.transform(null)).toBe(''); | ||
|
||
expect(console.error).toHaveBeenCalledTimes(3); | ||
}); | ||
|
||
describe('when `begin` and `end` are set', () => { | ||
it('describes schedule with `begin` and `end` fields', () => { | ||
spectator = createPipe(); | ||
|
||
expect(spectator.service.transform({ | ||
minute: '0', | ||
hour: '*', | ||
dom: '*', | ||
month: '*', | ||
dow: '*', | ||
begin: '02:15', | ||
end: '23:00', | ||
})).toBe('Every hour, every day, from 02:15 to 23:00'); | ||
}); | ||
|
||
it("uses user's time 12/24h time format preference for schedule with `begin` and `end`", () => { | ||
spectator = createPipe({ | ||
providers: [ | ||
mockProvider(LocaleService, { | ||
getShortTimeFormat: () => 'hh:mm aa', | ||
getPreferredTimeFormat: () => 'hh:mm:ss aa', | ||
}), | ||
], | ||
}); | ||
|
||
expect(spectator.service.transform({ | ||
minute: '0', | ||
hour: '*', | ||
dom: '*', | ||
month: '*', | ||
dow: '*', | ||
begin: '02:15', | ||
end: '23:00', | ||
})).toBe('Every hour, every day, from 02:15 AM to 11:00 PM'); | ||
}); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
src/app/modules/dates/pipes/schedule-description/schedule-description.pipe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
import { TranslateService } from '@ngx-translate/core'; | ||
import cronstrue from 'cronstrue/i18n'; | ||
import { format, parse } from 'date-fns'; | ||
import { Schedule } from 'app/interfaces/schedule.interface'; | ||
import { scheduleToCrontab } from 'app/modules/scheduler/utils/schedule-to-crontab.utils'; | ||
import { LanguageService } from 'app/services/language.service'; | ||
import { LocaleService } from 'app/services/locale.service'; | ||
|
||
@Pipe({ | ||
name: 'scheduleDescription', | ||
}) | ||
export class ScheduleDescriptionPipe implements PipeTransform { | ||
constructor( | ||
private localeService: LocaleService, | ||
private language: LanguageService, | ||
private translate: TranslateService, | ||
) {} | ||
|
||
transform(schedule: Schedule): string { | ||
try { | ||
const crontab = scheduleToCrontab(schedule); | ||
const cronstrueOptions = { | ||
use24HourTimeFormat: this.localeService.getPreferredTimeFormat() === 'HH:mm:ss', | ||
verbose: true, | ||
locale: this.language.currentLanguage, | ||
}; | ||
|
||
const description = cronstrue.toString(crontab, cronstrueOptions); | ||
|
||
if ('begin' in schedule && 'end' in schedule) { | ||
return this.translate.instant('{crontabDescription}, from {startHour} to {endHour}', { | ||
crontabDescription: description, | ||
startHour: this.formatTime(schedule.begin), | ||
endHour: this.formatTime(schedule.end), | ||
}); | ||
} | ||
|
||
return description; | ||
} catch (error: unknown) { | ||
console.error(error); | ||
return ''; | ||
} | ||
} | ||
|
||
private formatTime(time: string): string { | ||
const parsedDate = parse(time, 'HH:mm', new Date()); | ||
|
||
return format(parsedDate, this.localeService.getShortTimeFormat()); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
.../ix-table/components/ix-table-body/cells/ix-cell-schedule/ix-cell-schedule.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<span | ||
[matTooltip]="value | scheduleDescription" | ||
[ixTest]="[title, uniqueRowTag(row()), 'row-schedule']" | ||
>{{ value | scheduleToCrontab }}</span> | ||
>{{ value | scheduleDescription }}</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
...es/ix-table/components/ix-table-body/cells/ix-cell-schedule/ix-cell-schedule.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.