UNPKG

@cause-911/material

Version:

Run `npm install @cause-911/material --save` to add this library to your project

718 lines (705 loc) 26.3 kB
import { Component, Inject, ElementRef, Input, HostListener, Injectable, ɵɵdefineInjectable, EventEmitter, ViewChild, Output, NgModule } from '@angular/core'; import { MatDialogRef, MAT_DIALOG_DATA, MatDialog, MatButtonModule, MatFormFieldModule, MatIconModule, MatInputModule, MatTabsModule } from '@angular/material'; import { CommonModule } from '@angular/common'; import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { FormControl, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'; import { TranslateService, CoreService, CauseCoreModule } from '@cause-911/core'; import { trigger, state, style, transition, animate } from '@angular/animations'; import { NavigationEnd, Router } from '@angular/router'; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class SimpleDialogData { constructor() { this.buttons = []; } } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class SimpleDialogComponent { /** * @param {?} dialogRef * @param {?} data */ constructor(dialogRef, data) { this.dialogRef = dialogRef; this.data = data; } /** * @return {?} */ ngOnInit() { } /** * @param {?} buttonIndex * @return {?} */ onClick(buttonIndex) { this.dialogRef.close(buttonIndex); } } SimpleDialogComponent.decorators = [ { type: Component, args: [{ selector: 'cause-simple-dialog', template: "<h1 mat-dialog-title>{{data.title}}</h1>\n<div mat-dialog-content>\n <div [innerHTML]=\"data.message\"></div>\n</div>\n<div mat-dialog-actions *ngIf=\"data.buttons\">\n <button *ngFor=\"let label of data.buttons; let i = index\" mat-raised-button (click)=\"onClick(i)\">{{label}}</button>\n</div>", styles: ["div[mat-dialog-actions]{margin-top:20px;text-align:center}"] }] } ]; /** @nocollapse */ SimpleDialogComponent.ctorParameters = () => [ { type: MatDialogRef }, { type: SimpleDialogData, decorators: [{ type: Inject, args: [MAT_DIALOG_DATA,] }] } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class MenuSidebarComponent { /** * @param {?} element */ constructor(element) { this.menuItems = []; this.version = ''; this.keepMenuExpanded = false; this.hostElement = (/** @type {?} */ (element.nativeElement)); this.hostElement.addEventListener('mouseover', (/** * @param {?} e * @return {?} */ (e) => this.onMouseOver(e))); this.hostElement.addEventListener('mouseout', (/** * @param {?} e * @return {?} */ (e) => this.onMouseOut(e))); this.setDisplayMenu(); } /** * @return {?} */ ngOnInit() { } /** * @param {?} e * @return {?} */ onResize(e) { this.setDisplayMenu(); } /** * @return {?} */ onMenuItemClick() { if (window.innerWidth < 1000) { this.hideOnMobile(); } } /** * @return {?} */ hideOnMobile() { this.hostElement.classList.remove('mobile'); this.hostElement.classList.add('hidden'); } /** * @return {?} */ showOnMobile() { this.hostElement.classList.remove('hidden'); this.hostElement.classList.add('mobile'); } /** * @return {?} */ onToggleCollapse() { if (this.keepMenuExpanded) { this.onCollpseMenu(); this.hostElement.classList.remove('keepExpanded'); } else { this.onExpandedMenu(); this.hostElement.classList.add('keepExpanded'); } this.keepMenuExpanded = !this.keepMenuExpanded; localStorage.setItem('cause-menu-status', this.keepMenuExpanded ? 'expanded' : 'collapsed'); } /** * @private * @return {?} */ setDisplayMenu() { this.hostElement.className = ''; if (window.innerWidth < 1000) { this.hostElement.classList.add('hidden'); } else { if (localStorage.getItem('cause-menu-status') === 'expanded') { this.keepMenuExpanded = true; this.hostElement.classList.add('keepExpanded'); } this.hostElement.classList.add(this.keepMenuExpanded ? 'expanded' : 'collapsed'); } } /** * @private * @param {?} e * @return {?} */ onMouseOver(e) { if (!this.keepMenuExpanded) { this.onExpandedMenu(); } e.stopPropagation(); } /** * @private * @param {?} e * @return {?} */ onMouseOut(e) { if (!this.keepMenuExpanded) { this.onCollpseMenu(); } e.stopPropagation(); } /** * @private * @return {?} */ onExpandedMenu() { if (window.innerWidth >= 1000) { this.hostElement.classList.remove('collapsed'); this.hostElement.classList.add('expanded'); } } /** * @private * @return {?} */ onCollpseMenu() { if (window.innerWidth >= 1000) { this.hostElement.classList.remove('expanded'); this.hostElement.classList.add('collapsed'); } } } MenuSidebarComponent.decorators = [ { type: Component, args: [{ selector: 'cause-menu-sidebar', template: "<div>\n <button mat-icon-button class=\"close\" (click)=\"hideOnMobile()\">\n <mat-icon>clear</mat-icon>\n </button>\n <ng-content select=\"[header]\"></ng-content>\n</div>\n<div>\n <ng-content select=\"[beforeMenu]\"></ng-content>\n <cause-menu-vertical #menu [menuItems]=\"menuItems\" (itemClick)=\"onMenuItemClick()\"></cause-menu-vertical>\n <ng-content select=\"[afterMenu]\"></ng-content>\n</div>\n<div *ngIf=\"version\" class=\"version\">\n <div class=\"double-arrow\" (click)=\"onToggleCollapse()\"></div>\n <span class=\"full\">{{'material.version' | translate}} {{version}}</span>\n <span class=\"abbr\">{{version}}</span>\n</div>\n", styles: [":host{height:100%;flex-direction:column;display:flex;transition:.1s ease-out;overflow:hidden;scrollbar-width:5px;scrollbar-color:rgba(0,0,0,.1) rgba(0,0,0,.2)}::-webkit-scrollbar{width:5px}::-webkit-scrollbar-track{border-radius:5px;-webkit-box-shadow:inset 0 0 6px rgba(0,0,0,.1)}::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(0,0,0,.2);outline:#708090 solid 1px}:host>div{flex:1}:host>div:first-child{flex:0 0 auto}:host>div:nth-child(2){flex-grow:1;overflow:hidden auto}:host>div:last-child{max-height:1em}:host.hidden{width:0;min-width:0;max-width:0}:host.mobile{width:275px;min-width:275px;max-width:275px;position:absolute;z-index:10}:host.collapsed{width:75px;min-width:75px;max-width:75px}:host.expanded{width:275px;min-width:275px;max-width:275px}:host .close{display:none}:host.mobile .close{right:0;display:inline-block;position:absolute}.double-arrow{height:2.9em;line-height:2.9em;cursor:pointer;position:absolute;opacity:.25;margin-top:-1em}.double-arrow:hover{opacity:1}:host.collapsed .double-arrow:before,:host.expanded .double-arrow:before{font-family:\"Material Icons\";content:\"double_arrow\";font-size:2.9em;text-align:right}:host.collapsed .double-arrow{margin-left:10px}:host.expanded .double-arrow{margin-left:200px}:host.collapsed ::ng-deep .menu-caption,:host.collapsed ::ng-deep .submenu{display:none}:host.keepExpanded .double-arrow{transform:rotate(180deg);opacity:1}.version{bottom:0;padding:1em}.abbr,.full{display:none}:host.collapsed .abbr{display:inline}:host.expanded .full,:host.mobile .full{display:inline}@media only screen and (max-width:1000px){.double-arrow{display:none}}"] }] } ]; /** @nocollapse */ MenuSidebarComponent.ctorParameters = () => [ { type: ElementRef } ]; MenuSidebarComponent.propDecorators = { menuItems: [{ type: Input }], version: [{ type: Input }], onResize: [{ type: HostListener, args: ['window:resize', ['$event'],] }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class MenuItem { /** * @param {?} label * @param {?} path * @param {?=} icon */ constructor(label, path, icon = '') { this.label = label; this.path = path; this.icon = icon; this.childs = []; } } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class MaterialService { constructor() { } } MaterialService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ MaterialService.ctorParameters = () => []; /** @nocollapse */ MaterialService.ngInjectableDef = ɵɵdefineInjectable({ factory: function MaterialService_Factory() { return new MaterialService(); }, token: MaterialService, providedIn: "root" }); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class MaterialComponent { constructor() { } /** * @return {?} */ ngOnInit() { } } MaterialComponent.decorators = [ { type: Component, args: [{ selector: 'cause-material', template: "<div>{{'core.noGenericComponentOnThisLibrary' | translate}}</div>" }] } ]; /** @nocollapse */ MaterialComponent.ctorParameters = () => []; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class InputFileComponent { /** * @param {?} translateService * @param {?} dialog */ constructor(translateService, dialog) { this.translateService = translateService; this.dialog = dialog; this.readend = new EventEmitter(); this.accept = ''; this.multiple = false; this.icon = ''; this.text = ''; this.labels = {}; } /** * @return {?} */ ngOnInit() { if (!this.icon && !this.text) { this.translateService.get(['material.select', 'material.dialogTitle', 'material.dialogMessage']).subscribe((/** * @param {?} labels * @return {?} */ labels => { this.labels = labels; this.text = labels['material.select']; })); } } /** * @param {?} e * @return {?} */ onSelectFile(e) { for (let i = 0, j = e.target.files.length; i < j; i++) { /** @type {?} */ const file = e.target.files[i]; /** @type {?} */ const reader = new FileReader(); reader.onerror = ((/** * @param {?} error * @return {?} */ error => this.onError(error))); reader.onload = ((/** * @param {?} event * @return {?} */ event => this.onReadEnd(file, event))); reader.readAsDataURL(file); } if (e.target.files.length) { this.dialog.open(SimpleDialogComponent, { width: '250px', disableClose: true, data: { title: this.labels['material.dialogTitle'], message: this.labels['material.dialogMessage'] } }); } } /** * @param {?} event * @return {?} */ openDialog(event) { if (this.file) { this.file.nativeElement.click(); } event.stopPropagation(); } /** * @private * @param {?} error * @return {?} */ onError(error) { throw error; } /** * @private * @param {?} file * @param {?} e * @return {?} */ onReadEnd(file, e) { this.dialog.closeAll(); this.readend.emit({ name: file.name, size: file.size, type: file.type, lastModifiedDate: file.lastModifiedDate, content: e.target['result'], file: file, }); } } InputFileComponent.decorators = [ { type: Component, args: [{ selector: 'cause-input-file', template: "<button mat-raised-button (click)=\"openDialog($event)\">\n <mat-icon *ngIf=\"icon\">{{icon}}</mat-icon>\n <span *ngIf=\"text\">{{text}}</span>\n</button>\n<ng-container *ngIf=\"multiple; else notMultipleInput\">\n <input #file type=\"file\" (change)=\"onSelectFile($event)\" [accept]=\"accept\" multiple=\"multiple\" />\n</ng-container>\n\n<ng-template #notMultipleInput>\n <input #file type=\"file\" (change)=\"onSelectFile($event)\" [accept]=\"accept\" />\n</ng-template>", styles: [":host input{display:none}"] }] } ]; /** @nocollapse */ InputFileComponent.ctorParameters = () => [ { type: TranslateService }, { type: MatDialog } ]; InputFileComponent.propDecorators = { file: [{ type: ViewChild, args: ['file', { static: false },] }], readend: [{ type: Output }], accept: [{ type: Input }], multiple: [{ type: Input }], icon: [{ type: Input }], text: [{ type: Input }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class InputMultipleLangueComponent { /** * @param {?} coreService * @param {?} translate */ constructor(coreService, translate) { this.translate = translate; this.value = []; this.forms = []; this.labels = []; this.selectedIndex = 0; this.config = coreService.getConfig(); } /** * @return {?} */ ngOnInit() { this.translate.get(this.config.languages).subscribe((/** * @param {?} labels * @return {?} */ labels => { for (const i in labels) { if (labels[i]) { this.labels.push(labels[i]); } } this.initializeForms(); })); } /** * @param {?} tabIndex * @return {?} */ onTagChanged(tabIndex) { console.log('cause-material', tabIndex); console.log('cause-material', this.value); console.log('cause-material', this.forms); } /** * @param {?} index * @return {?} */ getErrorMessage(index) { return this.forms[index].hasError('required') ? 'error.required' : ''; } /** * @private * @return {?} */ initializeForms() { this.labels.forEach((/** * @param {?} item * @param {?} index * @return {?} */ (item, index) => { this.forms[index] = new FormControl('', [Validators.required]); this.forms[index].setValue(this.value[index] || ''); })); } } InputMultipleLangueComponent.decorators = [ { type: Component, args: [{ selector: 'cause-input-multiple-langue', template: "<mat-tab-group [selectedIndex]=\"selectedIndex\" (selectedIndexChange)=\"onTagChanged($event)\">\n <mat-tab *ngFor=\"let lang of labels; let i = index\" [label]=\"lang\">\n <mat-form-field hideRequiredMarker=\"never\">\n <input matInput [placeholder]=\"lang\" [formControl]=\"forms[i]\" required=\"required\">\n <mat-error *ngIf=\"forms[i].invalid\">{{getErrorMessage(i) | translate}}</mat-error>\n </mat-form-field>\n </mat-tab>\n</mat-tab-group>", styles: [".mat-form-field{width:100%}"] }] } ]; /** @nocollapse */ InputMultipleLangueComponent.ctorParameters = () => [ { type: CoreService }, { type: TranslateService } ]; InputMultipleLangueComponent.propDecorators = { value: [{ type: Input }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class SlideshowComponent { constructor() { this.height = '150px'; this.autoPlay = true; this.timer = null; this.items = []; this.states = []; this.selectedIndex = 0; } /** * @param {?} list * @return {?} */ set images(list) { this.items = list; this.restart(); } /** * @return {?} */ get images() { return this.items; } /** * @return {?} */ ngOnInit() { this.container.nativeElement.style.height = this.height; this.container.nativeElement.style.width = '100%'; } /** * @param {?} index * @return {?} */ getState(index) { if (this.states[index]) { return this.states[index]; } return (this.selectedIndex === index ? 'in' : 'out'); } /** * @return {?} */ restart() { if (this.timer) { window.clearInterval(this.timer); } if (this.images && this.images.length) { this.timer = window.setInterval((/** * @return {?} */ () => this.changed('next')), 5000); } } /** * @return {?} */ next() { if (this.selectedIndex < this.items.length - 1) { this.selectedIndex++; } else { this.selectedIndex = 0; } } /** * @private * @param {?} action * @return {?} */ changed(action) { this.states[this.selectedIndex] = 'out'; this[action](); this.states[this.selectedIndex] = 'in'; } } SlideshowComponent.decorators = [ { type: Component, args: [{ selector: 'cause-slideshow', template: "<div #container class=\"slideshow\">\n <div *ngFor=\"let url of images; let index = index;\" [@slideLeftRight]=\"getState(index)\">\n <img [src]=\"url\" />\n </div>\n</div>", animations: [ trigger('slideUpDown', [ state('in', style({ transform: 'translateY(0%)' })), state('out', style({ transform: 'translateY(-100%)' })), transition('in => out', [ animate('500ms ease-in') ]), transition('out => in', [ style({ transform: 'translateY(100%)' }), animate('500ms ease-in') ]), ]), trigger('slideLeftRight', [ state('in', style({ transform: 'translateX(0%)' })), state('out', style({ transform: 'translateX(-100%)' })), transition('in => out', [ animate('500ms ease-in') ]), transition('out => in', [ style({ transform: 'translateX(100%)' }), animate('500ms ease-in') ]), ]), ], styles: [".slideshow{margin:0 auto;position:relative;overflow:hidden}.slideshow>div{width:100%;height:100%;position:absolute}img{max-height:100%;max-width:100%;margin:0 auto;display:block}"] }] } ]; /** @nocollapse */ SlideshowComponent.ctorParameters = () => []; SlideshowComponent.propDecorators = { container: [{ type: ViewChild, args: ['container', { static: true },] }], height: [{ type: Input }], autoPlay: [{ type: Input }], images: [{ type: Input }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class MenuVerticalComponent { /** * @param {?} router */ constructor(router) { this.router = router; this.itemClick = new EventEmitter(); this.menuItems = []; this.router.events.subscribe((/** * @param {?} route * @return {?} */ (route) => { if (route instanceof NavigationEnd) { this.selectActiveRoute(route); } })); } /** * @return {?} */ ngOnInit() { } /** * @param {?} path * @param {?} e * @return {?} */ goTo(path, e) { this.router.navigate([path]); this.itemClick.emit(); e.stopPropagation(); } /** * @private * @param {?} route * @return {?} */ selectActiveRoute(route) { this.menuItems.forEach((/** * @param {?} menu * @return {?} */ menu => { if (route.url) { menu.activated = (route.url === menu.path || (menu.childs.length && route.url.indexOf(menu.path) > -1)); } menu.childs.forEach((/** * @param {?} submenu * @return {?} */ submenu => { if (route.url) { submenu.activated = (route.url === submenu.path || route.urlAfterRedirects === submenu.path); } })); })); } } MenuVerticalComponent.decorators = [ { type: Component, args: [{ selector: 'cause-menu-vertical', template: "<h4 *ngFor=\"let menu of menuItems\" [class]=\"menu.activated ? 'selected' : ''\">\n <div (click)=\"goTo(menu.path, $event)\" class=\"menu\">\n <div *ngIf=\"menu.icon\" class=\"menu-icon\">\n <fa-icon *ngIf=\"menu.icon.filter !== undefined\" [icon]=\"menu.icon\"></fa-icon>\n <img *ngIf=\"menu.icon.filter === undefined\" [src]=\"menu.icon\" />\n </div>\n <div *ngIf=\"menu.label\" class=\"menu-caption\">\n <span>{{menu.label | translate}}</span>\n </div>\n </div>\n <div *ngIf=\"menu.childs.length && menu.activated\" class=\"submenu\">\n <div\n *ngFor=\"let submenu of menu.childs\"\n [class]=\"submenu.activated ? 'menu selected' : 'menu'\"\n (click)=\"goTo(submenu.path, $event)\">\n <div *ngIf=\"!submenu.icon\" class=\"menu-dot\">&bull;</div>\n <div *ngIf=\"submenu.icon\" class=\"menu-icon\">\n <fa-icon *ngIf=\"submenu.icon.filter !== undefined\" [icon]=\"submenu.icon\"></fa-icon>\n <img *ngIf=\"submenu.icon.filter === undefined\" [src]=\"submenu.icon\" />\n </div>\n <div *ngIf=\"submenu.label\" class=\"menu-caption\">\n <span>{{submenu.label | translate}}</span>\n </div>\n </div>\n </div>\n</h4>\n", styles: [".menu,.submenu{cursor:pointer}h4{margin:0;padding:0}h4 .menu{padding:1em 0;display:flex;flex-direction:row}h4 .menu>div{flex:1 1 auto;-ms-grid-row-align:center;align-self:center}.menu-dot{max-width:1.1em;text-align:center;margin-right:.5em;font-size:2em}.menu-icon{max-width:60px;text-align:center;margin-right:.5em}.submenu{margin-left:1em}.submenu .menu{padding:0;font-size:.9em;line-height:2.2em}.submenu .menu::before{content:\"\";margin-left:1.1em;width:.1em;height:2.5em;position:relative;background:#fff;margin-right:-1.17em}"] }] } ]; /** @nocollapse */ MenuVerticalComponent.ctorParameters = () => [ { type: Router } ]; MenuVerticalComponent.propDecorators = { itemClick: [{ type: Output }], menuItems: [{ type: Input }] }; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class CauseMaterialModule { } CauseMaterialModule.decorators = [ { type: NgModule, args: [{ declarations: [ MaterialComponent, InputFileComponent, InputMultipleLangueComponent, MenuSidebarComponent, MenuVerticalComponent, SimpleDialogComponent, SlideshowComponent, ], entryComponents: [ SimpleDialogComponent ], exports: [ MaterialComponent, InputFileComponent, InputMultipleLangueComponent, MenuSidebarComponent, SimpleDialogComponent, SlideshowComponent, ], imports: [ BrowserModule, BrowserAnimationsModule, CommonModule, FormsModule, ReactiveFormsModule, MatButtonModule, MatFormFieldModule, MatIconModule, MatInputModule, MatTabsModule, FontAwesomeModule, CauseCoreModule, ], },] } ]; export { CauseMaterialModule, MaterialComponent, MaterialService, MenuItem, MenuSidebarComponent, SimpleDialogComponent, SimpleDialogData as ɵa, InputFileComponent as ɵb, InputMultipleLangueComponent as ɵc, MenuVerticalComponent as ɵd, SlideshowComponent as ɵe }; //# sourceMappingURL=cause-911-material.js.map