Skip to content

Commit

Permalink
feat(datepicker): Add initial view setting
Browse files Browse the repository at this point in the history
  • Loading branch information
trevordaniels committed Aug 8, 2017
1 parent 6974405 commit 27674ee
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
25 changes: 24 additions & 1 deletion demo/src/app/pages/modules/datepicker/datepicker.page.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component } from "@angular/core";
import { ApiDefinition } from "../../../components/api/api.component";
import { DatepickerMode } from "../../../../../../src/public";
import { DatepickerMode, CalendarViewType } from "../../../../../../src/public";

const exampleStandardTemplate = `
<div class="ui form">
Expand All @@ -11,6 +11,7 @@ const exampleStandardTemplate = `
<input suiDatepicker
[(ngModel)]="date"
[pickerMode]="mode"
[pickerInitialView]="initialView"
[pickerFirstDayOfWeek]="firstDayOfWeek"
[pickerUseNativeOnMobile]="false">
</div>
Expand All @@ -21,6 +22,12 @@ const exampleStandardTemplate = `
<sui-select-option *ngFor="let m of modes.availableOptions" [value]="m"></sui-select-option>
</sui-select>
</div>
<div class="field">
<label>Initial View</label>
<sui-select class="selection" [(ngModel)]="initialView" [options]="calendarViews" labelField="label" valueField="value" #views>
<sui-select-option *ngFor="let m of views.availableOptions" [value]="m"></sui-select-option>
</sui-select>
</div>
<div class="field">
<label>First Day of the Week</label>
<input type="number" [(ngModel)]="firstDayOfWeek" min="0" max="6">
Expand Down Expand Up @@ -111,6 +118,13 @@ export class DatepickerPage {
"Can be from <code>0</code> (Sunday) to <code>6</code> (Saturday).",
defaultValue: "0"
},
{
name: "pickerInitialView",
type: "CalendarViewType",
description: "Specifies the initial view for the datepicker. Options are: <code>CalendarViewType.Year</code>, " +
"<code>CalendarViewType.Month</code>, <code>CalendarViewType.Date</code>, " +
"<code>CalendarViewType.Hour</code> & <code>CalendarViewType.Minute</code>."
},
{
name: "pickerPlacement",
type: "PopupPlacement",
Expand Down Expand Up @@ -184,6 +198,15 @@ export class DatepickerExampleStandard {
public datepickerModes:string[] = ["datetime", "date", "time", "month", "year"];
public mode:DatepickerMode = DatepickerMode.Datetime;
public date:Date;

public calendarViews:{ label:string; value:CalendarViewType }[] = [
{ label: "year", value: CalendarViewType.Year },
{ label: "month", value: CalendarViewType.Month },
{ label: "date", value: CalendarViewType.Date },
{ label: "hour", value: CalendarViewType.Hour },
{ label: "minute", value: CalendarViewType.Minute }
];
public initialView:CalendarViewType = CalendarViewType.Date;
}

@Component({
Expand Down
17 changes: 17 additions & 0 deletions src/modules/datepicker/directives/datepicker.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { IDatepickerLocaleValues, RecursivePartial, SuiLocalizationService } fro
import { SuiPopupComponentController, PopupAfterOpen, PopupConfig, PopupTrigger } from "../../popup";
import { SuiDatepicker, DatepickerMode } from "../components/datepicker";
import { CalendarConfig, YearConfig, MonthConfig, DatetimeConfig, TimeConfig, DateConfig } from "../classes/calendar-config";
import { CalendarViewType } from "../views/calendar-view";

@Directive({
selector: "[suiDatepicker]",
Expand All @@ -32,6 +33,19 @@ export class SuiDatepickerDirective
this.onSelectedDateChange.emit(date);
}

private _initialView:CalendarViewType;

@Input("pickerInitialView")
public get initialView():CalendarViewType {
return this._initialView;
}
public set initialView(view:CalendarViewType) {
this._initialView = view;
if (this.config) {
this.config.mappings.initialView = view;
}
}

private _mode:DatepickerMode;
public config:CalendarConfig;

Expand Down Expand Up @@ -60,6 +74,9 @@ export class SuiDatepickerDirective
this.config = new TimeConfig();
break;
}
if (this._initialView != undefined) {
this.config.mappings.initialView = this._initialView;
}
this.writeValue(this.selectedDate);
}

Expand Down
3 changes: 2 additions & 1 deletion src/modules/datepicker/public.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export {
SuiDatepickerModule,
DatepickerMode
DatepickerMode,
CalendarViewType
} from "./index";

0 comments on commit 27674ee

Please sign in to comment.