Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added weeknumber with label #326

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/ionic-datepicker.bundle.min.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/ionic-datepicker-modal.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ion-modal-view class="ionic_datepicker_modal">
<ion-header-bar class="header">
<h1 class="title">{{mainObj.titleLabel || selctedDateEpoch | date : mainObj.dateFormat}}</h1>
<h1 class="title">{{mainObj.titleLabel || data.currentMonth + " " + data.currentYear}}</h1>
</ion-header-bar>
<ion-content class="ionic_datepicker_modal_content">
<div class="">
Expand Down Expand Up @@ -46,11 +46,12 @@ <h1 class="title">{{mainObj.titleLabel || selctedDateEpoch | date : mainObj.date
<div>
<div class="row text-center padding_top_zero" ng-repeat="row in rows track by $index">
<div class="col padding_zero date_col" ng-repeat="col in cols track by $index"
ng-class="{'selected_date': (dayList[row + $index].epoch === selctedDateEpoch),
ng-class="{'selected_date': (dayList[row + $index].epoch === today),
'today' : (dayList[row + $index].epoch == today),
'pointer_events_none':((disabledDates.indexOf(dayList[row + $index].epoch) >= 0) || (dayList[row + $index].disabled))}"
'pointer_events_none':((disabledDates.indexOf(dayList[row + $index].epoch) >= 0) || (dayList[row + $index].disabled)),
'empty_cell' : (!dayList[row + col].date)}"
ng-click="dateSelected(dayList[row + $index])">
<div class="date_cell">
<div class="date_cell"><span ng-if="mainObj.enableWeekNumber" class="weeknumber">{{dayList[row + col].weekNumber}}</span>
{{dayList[row + col].date}}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/ionic-datepicker-popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<div>
<div class="row text-center padding_zero" ng-repeat="row in rows track by $index">
<div class="col no_padding date_col" ng-repeat="col in cols track by $index"
ng-class="{'selected_date': (dayList[row + $index].epoch === selctedDateEpoch),
ng-class="{'selected_date': (dayList[row + $index].epoch === today),
'today' : (dayList[row + $index].epoch == today),
'pointer_events_none':((disabledDates.indexOf(dayList[row + $index].epoch) >= 0) || dayList[row + $index].disabled)}"
ng-click="dateSelected(dayList[row + $index])">
Expand Down
36 changes: 29 additions & 7 deletions src/ionic-datepicker.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ angular.module('ionic-datepicker.provider', [])
templateType: 'popup',
showTodayButton: false,
closeOnSelect: false,
disableWeekdays: []
disableWeekdays: [],
enableWeekNumber: false,
weekNumberLabel: 'CW'
};

this.configDatePicker = function (inputObj) {
angular.extend(config, inputObj);
};

this.$get = ['$rootScope', '$ionicPopup', '$ionicModal', 'IonicDatepickerService', function ($rootScope, $ionicPopup, $ionicModal, IonicDatepickerService) {
this.$get = ['$rootScope', '$ionicPopup', '$ionicModal', 'IonicDatepickerService' , '$filter', function ($rootScope, $ionicPopup, $ionicModal, IonicDatepickerService, $filter) {

var provider = {};

Expand Down Expand Up @@ -56,12 +58,10 @@ angular.module('ionic-datepicker.provider', [])
if ($scope.currentDate.getMonth() === 11) {
$scope.currentDate.setFullYear($scope.currentDate.getFullYear());
}
$scope.currentDate.setDate(1);
$scope.currentDate.setMonth($scope.currentDate.getMonth() + 1);
$scope.data.currentMonth = $scope.mainObj.monthsList[$scope.currentDate.getMonth()];
$scope.data.currentYear = $scope.currentDate.getFullYear();
$scope.monthChanged($scope.currentDate.getMonth());
refreshDateList(new Date());
refreshDateList($scope.currentDate);
changeDaySelected();
};

Expand All @@ -78,7 +78,7 @@ angular.module('ionic-datepicker.provider', [])
if (!selectedDate || Object.keys(selectedDate).length === 0) return;
$scope.selctedDateEpoch = selectedDate.epoch;
if ($scope.mainObj.closeOnSelect) {
$scope.mainObj.callback($scope.selctedDateEpoch);
$scope.mainObj.callback($scope.selctedDateEpoch,'closed');
if ($scope.mainObj.templateType.toLowerCase() == 'popup') {
$scope.popup.close();
} else {
Expand Down Expand Up @@ -140,6 +140,7 @@ angular.module('ionic-datepicker.provider', [])

$scope.dayList.push({
date: tempDate.getDate(),
weekNumber: weekNumber(tempDate),
month: tempDate.getMonth(),
year: tempDate.getFullYear(),
day: tempDate.getDay(),
Expand Down Expand Up @@ -183,6 +184,25 @@ angular.module('ionic-datepicker.provider', [])
changeDaySelected();
};

// set weeknumber
function weekNumber(myDate) {
if ($scope.mainObj.enableWeekNumber) {
return $scope.mainObj.weekNumberLabel + ' ' + ISO8601_week_no(myDate);
}
}
function ISO8601_week_no(dt) {
var tdt = new Date(dt.valueOf());
var dayn = (dt.getDay() + 6) % 7;
tdt.setDate(tdt.getDate() - dayn + 3);
var firstThursday = tdt.valueOf();
tdt.setMonth(0, 1);
if (tdt.getDay() !== 4)
{
tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7);
}
return 1 + Math.ceil((firstThursday - tdt) / 604800000);
}

//Setting up the initial object
function setInitialObj(ipObj) {
$scope.mainObj = angular.copy(ipObj);
Expand All @@ -197,6 +217,7 @@ angular.module('ionic-datepicker.provider', [])
$scope.weeksList.push($scope.mainObj.weeksList.shift());
}
$scope.disableWeekdays = $scope.mainObj.disableWeekdays;
$scope.enableWeekNumber = $scope.mainObj.enableWeekNumber;

refreshDateList($scope.mainObj.inputDate);
setDisabledDates($scope.mainObj);
Expand Down Expand Up @@ -242,6 +263,7 @@ angular.module('ionic-datepicker.provider', [])
if (ipObj.disableWeekdays && config.disableWeekdays) {
$scope.mainObj.disableWeekdays = ipObj.disableWeekdays.concat(config.disableWeekdays);
}

setInitialObj($scope.mainObj);

if (!$scope.mainObj.closeOnSelect) {
Expand Down Expand Up @@ -269,7 +291,7 @@ angular.module('ionic-datepicker.provider', [])
disabled: false
};
$scope.dateSelected(today_obj);

refreshDateList(new Date());
$scope.selctedDateEpoch = resetHMSM(today).getTime();
$scope.mainObj.callback($scope.selctedDateEpoch);
Expand Down
32 changes: 18 additions & 14 deletions src/ionic-datepicker.service.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@


angular.module('ionic-datepicker.service', [])

.service('IonicDatepickerService', function () {
.service('IonicDatepickerService', function () {

this.monthsList = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

this.getYearsList = function (from, to) {
var yearsList = [];
var minYear = 1900;
var maxYear = 2100;

this.monthsList = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
minYear = from ? new Date(from).getFullYear() : minYear;
maxYear = to ? new Date(to).getFullYear() : maxYear;

this.getYearsList = function (from, to) {
var yearsList = [];
var minYear = 1900;
var maxYear = 2100;
for (var i = minYear; i <= maxYear; i++) {
yearsList.push(i);
}

minYear = from ? new Date(from).getFullYear() : minYear;
maxYear = to ? new Date(to).getFullYear() : maxYear;
return yearsList;
};
});

for (var i = minYear; i <= maxYear; i++) {
yearsList.push(i);
}

return yearsList;
};
});
13 changes: 13 additions & 0 deletions src/scss/ionic-datepicker.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,19 @@
left: 5%;
}

.ionic_datepicker_modal {
.date_cell {
position: relative;
.weeknumber {
position: absolute;
top: -15px;
right: 1px;
font-weight: normal;
font-size: 9px;
}
}
}

.date_col {
cursor: pointer;
}