Skip to content

Commit

Permalink
chore: clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
heliomarpm committed Oct 14, 2023
1 parent 674ce0c commit 5494013
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 161 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ export class HomePage {
| weekStart | number | `0` | set week start day `0` of sundaty, `1` of monday
| IDayConfig | Array<**_IDayConfig_**> | `[]` | days configuration
| displayMode | string | `month` | 'month', 'week'
| showAdjacentMonthDay | boolean | `true` | show days of other months if `displayMode:month`
| showMonthSubtitle | boolean | `false` | show the month in the subtitle if `displayMode:week`
| showAdjacentMonthDay | boolean | `true` | show days of adjacent months when `displayMode: 'month'`
| showMonthAdjacentDays | boolean | `false` | show the month on days adjacent to the selected month when `displayMode: 'week'`
| weeks | number | `1` | number of week to show in week display mode
| locale | ICalendarLocale | {locale: 'en', weekdays: 'initial' } | change calendar locale and set default name to weeks

Expand Down
15 changes: 4 additions & 11 deletions projects/demo/src/app/demos/demo-basic/demo-basic.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ export class DemoBasicComponent {
}


onChangeWeekStart(weekStart: string) {
onChangeWeekStart(weekStart: 0 | 1) {
this.options = {
...this.options,
weekStart: parseInt(weekStart, 10),
weekStart: weekStart,
};
}

Expand All @@ -251,24 +251,17 @@ export class DemoBasicComponent {
}
}

onChangeContinuous(continuous: boolean) {
this.options = {
...this.options,
continuous
};
}

onChangeShowAdjacentMonthDay(showAdjacentMonthDay: boolean) {
this.options = {
...this.options,
showAdjacentMonthDay
};
}

onChangeShowMonthSubtitle(showMonthSubtitle: boolean) {
onChangeShowMonthAdjacentDays(showMonthAdjacentDays: boolean) {
this.options = {
...this.options,
showMonthSubtitle
showMonthAdjacentDays
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component } from '@angular/core';
import { ModalController } from '@ionic/angular';
import * as luxon from 'luxon';

import { CalendarModalComponent, ICalendarModalOptions } from '@heliomarpm/ion-calendar';

Expand Down
8 changes: 5 additions & 3 deletions projects/ion-calendar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ import { IonCalendarModule } from '@heliomarpm/ion-calendar';
imports: [
...,
IonicModule.forRoot(),
// See IICalendarComponentOptions for options
// See ICalendarComponentOptions for options
IonCalendarModule.forRoot({
doneLabel: 'Confirm',
closeIcon: true
Expand Down Expand Up @@ -219,7 +219,8 @@ export class HomePage {
| - | - | - | -
| from | Date | `new Date()` | start date
| to | Date | 0 (Infinite) | end date
| color | string | `'primary'` | 'primary', 'secondary', 'danger', 'light', 'dark'
| color | string | `'primary'` | 'primary', 'secondary','tertiary', 'success', 'warning', 'danger', 'dark', 'medium', 'light', 'custom', 'transparent'
| colorSubtitle | string | `undefined` | 'primary', 'secondary','tertiary', 'success', 'warning', 'danger', 'dark', 'medium', 'light', 'custom', 'transparent'
| pickMode | string | `single` | 'multi', 'range', 'single'
| showToggleButtons | boolean | `true` | show toggle buttons
| monthsTitle | Array<string> | `['JAN', 'FEB', ..., 'NOV', 'DEC']` | month picker format
Expand All @@ -232,8 +233,9 @@ export class HomePage {
| weekdays | Array<string> | `['S', 'M', 'T', 'W', 'T', 'F', 'S']` | weeks text
| weekStart | number | `0` | set week start day `0` of sundaty, `1` of monday
| IDayConfig | Array<**_IDayConfig_**> | `[]` | days configuration
| showAdjacentMonthDay | boolean | `true` | show days of other months
| displayMode | string | `month` | 'month', 'week'
| showAdjacentMonthDay | boolean | `true` | show days of adjacent months when `displayMode: 'month'`
| showMonthAdjacentDays | boolean | `false` | show the month on days adjacent to the selected month when `displayMode: 'week'`
| weeks | number | `1` | number of week to show in week display mode
| locale | ICalendarLocale | {locale: 'en', weekdays: 'initial' } | change calendar locale and set default name to weeks

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import {
Component,
ViewChild,
ElementRef,
ChangeDetectorRef,
Renderer2,
OnInit,
Input,
AfterViewInit,
HostBinding,
Component, ViewChild, ElementRef, ChangeDetectorRef, Renderer2, OnInit, Input, AfterViewInit
} from '@angular/core';
import { NavParams, ModalController, IonContent } from '@ionic/angular';

Expand Down Expand Up @@ -54,7 +46,7 @@ export class CalendarModalComponent implements OnInit, AfterViewInit {
public calSvc: IonCalendarService
) {
// console.log("CalendarModalComponent.constructor");
}
}

ngOnInit(): void {
this.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@ ion-note {

.last-month-day,
.next-month-day {
color: var(--color, #000);

&[disabled] p {
opacity: .165;
}

p {
// color: rgba(0, 0, 0, 0.25);
color: var(--color, #000);
opacity: 0.3;
opacity: .35;
}

}

.today p {
Expand Down Expand Up @@ -191,7 +196,7 @@ ion-note {
&[disabled] p {
// color: rgba(0, 0, 0, 0.3);
color: var(--color, #000);
opacity: 0.3;
opacity: 0.165;
}

&.on-selected ion-note {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,17 @@ export class CalendarWeekComponent {
}

private adjustSort(weekStart: number): void {
if (weekStart === this._weekStart && this.isEquals(this._weekDays, this._weekDaysOld)) return;
if (weekStart == this._weekStart && this.isEquals(this._weekDays, this._weekDaysOld)) return;

if (weekStart === 1) {
if (weekStart == 1) {
const cacheWeekArray = [...this._weekDays];
cacheWeekArray.push(cacheWeekArray.shift()!);
this.displayWeekDays = [...cacheWeekArray];

} else if (weekStart === 0) {
} else {
this.displayWeekDays = [...this._weekDays];
}
else {
return;
}

this._weekDaysOld = Array.from(this._weekDays);
this._weekStart = weekStart;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,6 @@ export class CalendarComponent implements ControlValueAccessor, OnInit {
let newWeek = this.calSvc.multiFormat(nextTime);
const oldWeek = this.calSvc.multiFormat(this.monthOpt.original.time);

if (oldWeek.month != newWeek.month && !this.def.continuous) {
nextTime = DateTime.fromMillis(nextTime).set({ day: 1 }).valueOf();
newWeek = this.calSvc.multiFormat(nextTime);
}

this.monthOpt = this.createWeek(nextTime);
this.onWeekChange.emit({ oldWeek: oldWeek, newWeek: this.calSvc.multiFormat(this.monthOpt.original.time), });

Expand All @@ -214,7 +209,7 @@ export class CalendarComponent implements ControlValueAccessor, OnInit {
if (!this.def.to || this.view !== 'days') return true;

const toDate = DateTimeHelper.parse(this.def.to);
return this.monthOpt.original.lastDay < toDate.toMillis();
return this.monthOpt.original.lastDayOfMonth < toDate.toMillis();
}

private backMonth(): void {
Expand All @@ -231,26 +226,6 @@ export class CalendarComponent implements ControlValueAccessor, OnInit {
let newWeek = this.calSvc.multiFormat(backTime);
const oldWeek = this.calSvc.multiFormat(this.monthOpt.original.time);

if (oldWeek.month != newWeek.month && !this.def.continuous) {
const start = new Date(this.monthOpt.original.time);
let dayToSubstrac = start.getDay();
if (this.options.weekStart === 1) {
dayToSubstrac--;
if (dayToSubstrac < 0) {
dayToSubstrac = 6;
}
}

const firstDayMonth = new Date(start.getFullYear(), start.getMonth(), 1).getTime();
let momentBackTime = DateTime.fromMillis(firstDayMonth);
if (start.getDate() - dayToSubstrac <= 1) {
momentBackTime = momentBackTime.minus({ days: 1 });
}
backTime = momentBackTime.valueOf();

newWeek = this.calSvc.multiFormat(backTime);
}

this.onWeekChange.emit({ oldWeek: oldWeek, newWeek: newWeek, });

if (oldWeek.month != newWeek.month) {
Expand Down Expand Up @@ -449,7 +424,7 @@ export class CalendarComponent implements ControlValueAccessor, OnInit {
}
}

writeValue(obj: any): void {
writeValue(obj: CalendarComponentOnChangeType): void {
this._writeValue(obj);
if (obj) {
if (this.calendarMonthValue[0]) {
Expand All @@ -463,11 +438,11 @@ export class CalendarComponent implements ControlValueAccessor, OnInit {
}
}

registerOnChange(fn: () => {}): void {
registerOnChange(fn: Function): void {
this._onChanged = fn;
}

registerOnTouched(fn: () => {}): void {
registerOnTouched(fn: Function): void {
this._onTouched = fn;
}

Expand Down
Loading

0 comments on commit 5494013

Please sign in to comment.