Skip to content

Commit

Permalink
Initial import with the first alpha version of the sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
Albert Nadal Garriga committed Mar 6, 2017
1 parent e0dce07 commit a2e2fec
Show file tree
Hide file tree
Showing 20 changed files with 1,280 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Angular 2 Material Daterange picker

A minimalist daterange picker library for Angular 2

### Installation
```
npm install ng2-daterange-picker
```

### License
MIT
22 changes: 22 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<html>
<head>
<title>Angular QuickStart</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('demo').catch(function(err){ console.error(err); });
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
1 change: 1 addition & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './src/daterange.picker.module';
75 changes: 75 additions & 0 deletions karma-test-shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
Error.stackTraceLimit = 0; // "No stacktrace"" is usually best for app testing.

// Uncomment to get full stacktrace output. Sometimes helpful, usually not.
// Error.stackTraceLimit = Infinity; //

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;

var builtPath = '/base/src/';

__karma__.loaded = function () { };

function isJsFile(path) {
return path.slice(-3) === '.js';
}

function isSpecFile(path) {
return /\.spec\.(.*\.)?js$/.test(path);
}

function isBuiltFile(path) {
return isJsFile(path) && (path.substr(0, builtPath.length) === builtPath);
}

var allSpecFiles = Object.keys(window.__karma__.files)
.filter(isSpecFile)
.filter(isBuiltFile);

System.config({
baseURL: 'base',
// Extend usual application package list with test folder
packages: { 'testing': { main: 'index.js', defaultExtension: 'js' } },

// Assume npm: is set in `paths` in systemjs.config
// Map the angular testing umd bundles
map: {
'@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
'@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
'@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
'@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
'@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
'@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
'@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',
'@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js'
}
});

System.import('systemjs.config.js')
.then(initTestBed)
.then(initTesting);

function initTestBed(){
return Promise.all([
System.import('@angular/core/testing'),
System.import('@angular/platform-browser-dynamic/testing')
])

.then(function (providers) {
var coreTesting = providers[0];
var browserTesting = providers[1];

coreTesting.TestBed.initTestEnvironment(
browserTesting.BrowserDynamicTestingModule,
browserTesting.platformBrowserDynamicTesting());
})
}

// Import all spec files and start karma
function initTesting () {
return Promise.all(
allSpecFiles.map(function (moduleName) {
return System.import(moduleName);
})
)
.then(__karma__.start, __karma__.error);
}
102 changes: 102 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
module.exports = function(config) {

var appBase = 'src/'; // transpiled app JS and map files
var appSrcBase = 'src/'; // app source TS files
var appAssets = 'base/src/'; // component assets fetched by Angular's compiler

var testBase = 'testing/'; // transpiled test JS and map files
var testSrcBase = 'testing/'; // test source TS files

var configuration = {
basePath: '',
frameworks: ['jasmine'],
plugins: [
'karma-jasmine',
'karma-chrome-launcher',
'karma-jasmine-html-reporter',
'karma-htmlfile-reporter'
],
customLaunchers: {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
files: [
// System.js for module loading
'node_modules/systemjs/dist/system.src.js',

// Polyfills
'node_modules/core-js/client/shim.js',
'node_modules/reflect-metadata/Reflect.js',

// zone.js
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/long-stack-trace-zone.js',
'node_modules/zone.js/dist/proxy.js',
'node_modules/zone.js/dist/sync-test.js',
'node_modules/zone.js/dist/jasmine-patch.js',
'node_modules/zone.js/dist/async-test.js',
'node_modules/zone.js/dist/fake-async-test.js',

// MomentJs for dates
'node_modules/moment/moment.js',

// RxJs
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },

// Paths loaded via module imports:
// Angular itself
{ pattern: 'node_modules/@angular/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false },

{ pattern: 'systemjs.config.js', included: false, watched: false },
'karma-test-shim.js',

// transpiled application & spec code paths loaded via module imports
{ pattern: appBase + '**/*.js', included: false, watched: true },
{ pattern: testBase + '**/*.js', included: false, watched: true },

// Paths for debugging with source maps in dev tools
{ pattern: appSrcBase + '**/*.ts', included: false, watched: false },
{ pattern: appBase + '**/*.js.map', included: false, watched: false },
{ pattern: testSrcBase + '**/*.ts', included: false, watched: false },
{ pattern: testBase + '**/*.js.map', included: false, watched: false }
],

// Proxied base paths for loading assets
proxies: {
// required for component assets fetched by Angular's compiler
"/src/": appAssets
},

exclude: [],
preprocessors: {},
// disabled HtmlReporter; suddenly crashing w/ strange socket error
reporters: ['progress', 'kjhtml'],//'html'],

// HtmlReporter configuration
htmlReporter: {
// Open this file to see results in browser
outputFile: '_test-output/tests.html',

// Optional
pageTitle: 'Unit Tests',
subPageTitle: __dirname
},

port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: true
};

if (process.env.TRAVIS) {
configuration.browsers = ['Chrome_travis_ci'];
}

config.set(configuration)
}
61 changes: 61 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "ng2-daterange-picker",
"version": "1.0.0-alpha.1",
"author": "Albert Nadal Garriga",
"license": "MIT",
"keywords": [
"angular2",
"angular 2",
"ng2",
"daterange",
"datepicker",
"picker",
"material"
],
"devDependencies": {
"@angular/common": "~2.2.1",
"@angular/compiler": "~2.2.1",
"@angular/compiler-cli": "~2.2.1",
"@angular/core": "~2.2.1",
"@angular/forms": "~2.2.1",
"@angular/material": "^2.0.0-beta.2",
"@angular/platform-browser": "~2.2.1",
"@angular/platform-browser-dynamic": "~2.2.1",
"@angular/platform-server": "~2.2.1",
"@types/es6-shim": "^0.31.32",
"@types/jasmine": "^2.5.38",
"concurrently": "^3.0.0",
"core-js": "^2.4.1",
"es6-shim": "^0.35.1",
"jasmine-core": "~2.4.1",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-htmlfile-reporter": "^0.3.4",
"karma-jasmine": "^1.0.2",
"karma-jasmine-html-reporter": "^0.2.2",
"lite-server": "^2.2.2",
"reflect-metadata": "^0.1.8",
"systemjs": "0.19.39",
"tslint": "^4.0.2",
"typescript": "^2.0.10",
"zone.js": "^0.6.25"
},
"repository": {
"type": "git",
"url": "https://github.com/albertnadal/ng2-daterange-picker"
},
"scripts": {
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
"lint": "tslint ./src/datepicker.*.ts -t verbose",
"lite": "lite-server",
"test": "tsc && karma start karma.conf.js",
"tsc": "tsc",
"tsc:w": "tsc -w",
"ngc": "node_modules/.bin/ngc -p tsconfig-aot.json && rm integration-test/*.metadata.json"
},
"dependencies": {
"moment": "^2.17.1",
"rxjs": "5.0.0-beta.12"
}
}
72 changes: 72 additions & 0 deletions src/ang.calendar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
export class Calendar {
firstWeekDay: number;

constructor(firstWeekDay = 0) {
this.firstWeekDay = firstWeekDay; // 0 = Sunday
}

weekStartDate(date: any) {
var startDate = new Date(date.getTime());
while (startDate.getDay() !== this.firstWeekDay) {
startDate.setDate(startDate.getDate() - 1);
}
return startDate;
}

monthDates(year: any, month: any, dayFormatter:any = null, weekFormatter:any = null) {
if ((typeof year !== "number") || (year < 1970)) {
throw ('year must be a number >= 1970');
};
if ((typeof month !== "number") || (month < 0) || (month > 11)) {
throw ('month must be a number (Jan is 0)');
};
var weeks: Array<any> = [],
week: Array<any> = [],
i = 0,
date = this.weekStartDate(new Date(year, month, 1));
do {
for (i=0; i<7; i++) {
week.push(dayFormatter ? dayFormatter(date) : date);
date = new Date(date.getTime());
date.setDate(date.getDate() + 1);
}
weeks.push(weekFormatter ? weekFormatter(week) : week);
week = [];
} while ((date.getMonth()<=month) && (date.getFullYear()===year));
return weeks;
}

monthDays(year: any, month: any) {
var getDayOrZero = function getDayOrZero(date: any) {
return date.getMonth() === month ? date : 0;
};
return this.monthDates(year, month, getDayOrZero);
}

monthText(year: any, month: any) {
if (typeof year === "undefined") {
var now = new Date();
year = now.getFullYear();
month = now.getMonth();
};
var getDayOrBlank = function getDayOrBlank(date: any) {
var s = date.getMonth() === month ? date.getDate().toString() : " ";
while (s.length < 2) s = " "+s;
return s;
};
var weeks = this.monthDates(year, month, getDayOrBlank,
function (week: any) { return week.join(" ") });
return weeks.join("\n");
}
}

const months = "JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC".split(" ");
for (var i=0; i<months.length; i++) {
Calendar[months[i]] = i;
}

/*!
* calendar: a port of the calendar module from Python
* Copyright(c) 2011 Luciano Ramalho <luciano@ramalho.org>
* MIT Licensed
*/
Loading

0 comments on commit a2e2fec

Please sign in to comment.