Skip to content

Commit

Permalink
refactoring complet
Browse files Browse the repository at this point in the history
  • Loading branch information
adessilly committed Nov 10, 2017
1 parent 1c7ea0a commit a012ca5
Show file tree
Hide file tree
Showing 31 changed files with 5,655 additions and 915 deletions.
4,937 changes: 4,937 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,28 @@
},
"private": false,
"dependencies": {
"@angular/compiler": "^5.0.0",
"@angular/animations": "^5.0.0",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/platform-server": "^5.0.0",
"@angular/router": "^5.0.0",
"@types/bootstrap": "^3.3.36",
"@types/jquery": "^3.2.16",
"bootstrap": "^3.3.7",
"bootstrap-daterangepicker": "^2.1.25",
"bootstrap-switch": "^3.3.4",
"core-js": "^2.5.1",
"eonasdan-bootstrap-datetimepicker": "^4.17.47",
"font-awesome": "^4.7.0",
"icheck": "1.0.2",
"inputmask": "^3.3.10",
"ionicons": "3.0.0",
"jquery": "3.2.1",
"jquery.inputmask": "^3.3.4",
"moment": "^2.19.1",
"rxjs": "^5.5.2",
"select2": "^4.0.6-rc.0",
Expand Down
19 changes: 7 additions & 12 deletions src/app/box/box.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Input, OnInit} from "@angular/core";
import {Component, Input, OnInit} from '@angular/core';
/**
@author phw
*/
Expand All @@ -8,21 +8,16 @@ import {Component, Input, OnInit} from "@angular/core";
})
export class BoxComponent implements OnInit{

@Input()
title: string;
@Input() title: string;
@Input() boxOpen = true;
@Input() boxStyle = 'box-default';

@Input()
boxOpen:boolean = true;
public arrowOpen = true;

@Input()
boxStyle:string = "box-default";

arrowOpen:boolean = true;

constructor() {
}
constructor() {}

ngOnInit() {
this.arrowOpen = this.boxOpen;
}

}
70 changes: 28 additions & 42 deletions src/app/check/checkbox.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
Component, Input, Output, EventEmitter, AfterContentInit, QueryList, ViewChildren,
ElementRef, AfterViewInit, DoCheck, forwardRef, ViewChild
Component, Input, AfterContentInit,
AfterViewInit, DoCheck, forwardRef, ViewChild
} from '@angular/core';
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from "@angular/forms";

declare var $: any;
import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';

/**
@author phw
Expand All @@ -20,41 +18,32 @@ declare var $: any;
})
export class CheckboxComponent implements AfterContentInit, AfterViewInit, DoCheck, ControlValueAccessor {

@Input()
id:string='';

@Input()
width:string = "12";
@Input()
placeholder:string;
@Input()
label:string;
@Input()
readonly:boolean = false;
@Input()
hasError:boolean = false;
@Input()
message:string;
@Input() id = '';
@Input() width = '12';
@Input() placeholder: string;
@Input() label: string;
@Input() readonly = false;
@Input() hasError = false;
@Input() message: string;

@ViewChild('icheckElement')
icheckChildren:any;
icheckElement:any = null;
icheckChildren: any;
icheckElement: any = null;

public onChangeCallback: any;
public onTouchedCallback: any;
public ngValue:boolean;
public ngValue: boolean;

public simpleMode: boolean = true;
public simpleMode = true;

constructor() {
}
constructor() {}

setValueFromComponent(v:boolean) {
setValueFromComponent(v: boolean) {
this.ngValue = v;
this.onChangeCallback(v);
}

setValueFromParent(v:boolean) {
setValueFromParent(v: boolean) {
this.ngValue = v;
this.ngDoCheck();
}
Expand All @@ -75,7 +64,7 @@ export class CheckboxComponent implements AfterContentInit, AfterViewInit, DoChe
}

ngAfterContentInit() {
if (this.width && this.width.substring(0, 3) == "col") {
if (this.width && this.width.substring(0, 3) === 'col') {
this.simpleMode = false;
}

Expand All @@ -84,46 +73,43 @@ export class CheckboxComponent implements AfterContentInit, AfterViewInit, DoChe
};
}

ngAfterViewInit(){
ngAfterViewInit() {
this.createICheck();
}

getICheckElement(){
return $([this.icheckChildren.nativeElement]);
getICheckElement() {
return jQuery([this.icheckChildren.nativeElement]);
}

createICheck() {
this.icheckElement = this.getICheckElement();

var elem:any = this.icheckElement;
var self = this;
const elem: any = this.icheckElement;
const self = this;

elem.iCheck({
checkboxClass: 'icheckbox_square-blue',
radioClass: 'iradio_square-blue',
increaseArea: '20%'
}).on('ifToggled', function(event){
}).on('ifToggled', function(event) {
self.switchValue();
});
}

//le OnChanges intervient trop tôt, utiliser le DoCheck
// le OnChanges intervient trop tôt, utiliser le DoCheck
ngDoCheck() {
if (this.icheckElement){
if (this.icheckElement) {
this.icheckElement.iCheck('update');
}
}

switchValue(){
if (this.ngValue == true){
switchValue() {
if (this.ngValue === true) {
this.ngValue = false;
} else {
this.ngValue = true;
}
this.setValueFromComponent(this.ngValue);
}

log(info){
console.log(info);
}
}
12 changes: 3 additions & 9 deletions src/app/date/date.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import {

import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';

declare var moment: any;
declare var $: any;

/*
@author Adrien DESSILLY
*/
Expand Down Expand Up @@ -35,7 +32,7 @@ export class DateComponent implements AfterContentInit, ControlValueAccessor {

public innerDate: Date;
public onChangeCallback: any;
public onTouchedCallback : any;
public onTouchedCallback: any;
public simpleMode = true;

constructor(private element: ElementRef) {}
Expand All @@ -46,20 +43,18 @@ export class DateComponent implements AfterContentInit, ControlValueAccessor {

// Ici, il faut setter la date et notifier le datepicker
setValueFromParent(v: Date) {
//console.log('setValueFromParent', v);
this.innerDate = v;
}

// Ici, il faut setter la date et notifier le parent
setValueFromDatepicker(v: Date) {
//console.log('setValueFromDatepicker', this.innerDate);
if(this.onChangeCallback) {
if (this.onChangeCallback) {
this.onChangeCallback(this.innerDate);
}
}

ngAfterContentInit() {
if (this.width && this.width.substring(0, 3) == 'col') {
if (this.width && this.width.substring(0, 3) === 'col') {
this.simpleMode = false;
}
}
Expand All @@ -70,7 +65,6 @@ export class DateComponent implements AfterContentInit, ControlValueAccessor {

// @Override ControlValueAccessor
writeValue(v: any) {
//console.log('writeValue', v);
this.setValueFromParent(v);
}

Expand Down
33 changes: 17 additions & 16 deletions src/app/date/datePicker.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {
Component, Input, Output, EventEmitter, ElementRef, SimpleChanges,
ViewChild, ViewChildren, QueryList, forwardRef, AfterViewInit
Component, Input, Output, EventEmitter,
ViewChild, forwardRef, AfterViewInit
} from '@angular/core';

import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms';

declare var moment: any;
declare var $: any;

/*
@author Adrien DESSILLY
Expand Down Expand Up @@ -44,37 +43,39 @@ export class DatePickerComponent implements AfterViewInit, ControlValueAccessor
// Ici, il faut setter la date et notifier le datepicker
setValueFromParent(v: Date) {
this.innerDate = this.convertToDate(v);
if(this.datepicker) {
this.datepicker.data("DateTimePicker").date( this.innerDate );
if (this.datepicker) {
this.datepicker.data('DateTimePicker').date( this.innerDate );
}
}

// Ici, il faut setter la date et notifier le parent
setValueFromDatepicker(v: Date) {
this.innerDate = this.convertToDate(v);
if(this.onChangeCallback) {
if (this.onChangeCallback) {
this.onChangeCallback(this.innerDate);
}
}

ngAfterViewInit(){
ngAfterViewInit() {
this.createDatepickerBootstrap();

let i=0;
let i = 0;
this.datePickerChild.nativeElement.onblur = () => {
// On va deux fois dedans à cause du datetimetpicker
// mais on ne veut pas être notifié deux fois
if(i++%2 == 1) return;
if (i++ % 2 === 1) {
return;
}
this.touchedChange.emit(true);
this.onTouchedCallback();
};
}

createDatepickerBootstrap() {
this.datepicker = $([this.datePickerChild.nativeElement]);
this.datepicker = jQuery([this.datePickerChild.nativeElement]);
this.datepicker.datetimepicker({
locale: 'fr',
minDate: moment('19100101','YYYYMMDD'),
minDate: moment('19100101', 'YYYYMMDD'),
keepOpen: false, // ok
sideBySide: true,
viewMode: 'days',
Expand All @@ -83,25 +84,25 @@ export class DatePickerComponent implements AfterViewInit, ControlValueAccessor
horizontal: 'left',
vertical: 'auto'
},
format: this.month ? 'MM/YYYY': (this.time ? 'DD/MM/YYYY HH: mm' : 'DD/MM/YYYY'),
format: this.month ? 'MM/YYYY' : (this.time ? 'DD/MM/YYYY HH: mm' : 'DD/MM/YYYY'),
date : this.innerDate // IMPORTANT sinon bug au démarrage, datepicker non setté
}).on('dp.change', eventDate => {
this.setValueFromDatepicker( eventDate.date === false ? null : eventDate.date.toDate() );
});
}

convertToDate(value){
if (value == undefined){
convertToDate(value) {
if (value === undefined) {
value = null;
}
if (value && !(value instanceof Date)){
if (value && !(value instanceof Date)) {
value = new Date(value);
}
return value;
}

togglePopup() {
//this.datepicker.data("DateTimePicker").show();
// this.datepicker.data('DateTimePicker').show();
}

// @Override ControlValueAccessor
Expand Down
Loading

0 comments on commit a012ca5

Please sign in to comment.