hslayers-ng
Version:
HSLayers-NG mapping library
229 lines (219 loc) • 19.4 kB
JavaScript
import * as i0 from '@angular/core';
import { Injectable, inject, ViewContainerRef, Directive, DestroyRef, ViewChild, Component } from '@angular/core';
import { ReplaySubject, Subject } from 'rxjs';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { TranslatePipe } from '@ngx-translate/core';
import * as i1 from '@angular/forms';
import { FormsModule } from '@angular/forms';
class HsDialogItem {
waitResult() {
const promise = new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
});
return promise;
}
constructor(component, data) {
this.component = component;
this.data = data;
}
}
class HsDialogContainerService {
constructor() {
this.dialogs = [];
this.dialogObserver = new ReplaySubject();
this.dialogDestroyObserver = new Subject();
}
cleanup() {
this.dialogObserver.complete();
this.dialogObserver = new ReplaySubject();
}
create(component, data) {
const item = new HsDialogItem(component, data);
this.dialogObserver.next(item);
return item;
}
destroy(component) {
if (component.cleanup) {
component.cleanup();
}
const dialogCollection = this.dialogs;
const dialogIx = dialogCollection.findIndex((d) => d == component);
if (dialogIx > -1) {
dialogCollection.splice(dialogIx, 1);
}
this.dialogDestroyObserver.next(component);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.3", ngImport: i0, type: HsDialogContainerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.2.3", ngImport: i0, type: HsDialogContainerService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.3", ngImport: i0, type: HsDialogContainerService, decorators: [{
type: Injectable,
args: [{
providedIn: 'root',
}]
}], ctorParameters: () => [] });
class HsDialogHostDirective {
constructor() {
this.viewContainerRef = inject(ViewContainerRef);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.3", ngImport: i0, type: HsDialogHostDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.2.3", type: HsDialogHostDirective, isStandalone: true, selector: "[hsDialogHost]", ngImport: i0 }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.3", ngImport: i0, type: HsDialogHostDirective, decorators: [{
type: Directive,
args: [{
selector: '[hsDialogHost]',
standalone: true,
}]
}] });
class HsDialogContainerComponent {
constructor() {
this.hsDialogContainerService = inject(HsDialogContainerService);
this.destroyRef = inject(DestroyRef);
}
ngOnDestroy() {
this.hsDialogContainerService.cleanup();
}
ngOnInit() {
this.hsDialogContainerService.dialogObserver
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((item) => {
this.loadDialog(item);
});
this.hsDialogContainerService.dialogDestroyObserver
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((item) => {
this.destroyDialog(item);
});
}
destroyDialog(dialog) {
const viewContainerRef = this.dialogHost.viewContainerRef;
const index = viewContainerRef.indexOf(dialog.viewRef);
if (index > -1) {
viewContainerRef.remove(index);
}
}
loadDialog(dialogItem) {
const viewContainerRef = this.dialogHost.viewContainerRef;
// viewContainerRef.clear();
const componentRef = viewContainerRef.createComponent(dialogItem.component);
componentRef.instance.viewRef = componentRef.hostView;
/**
* Quick workaround for possiblity to use singal input in dialogs.
* To achieve so wrap data into a another object {data: originalData, signalInput: true}
*/
if (dialogItem.data.signalInput) {
componentRef.setInput('data', dialogItem.data.data);
}
else {
componentRef.instance.data = dialogItem.data;
}
componentRef.instance.dialogItem = dialogItem;
this.hsDialogContainerService.dialogs.push(componentRef.instance);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.3", ngImport: i0, type: HsDialogContainerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.2.3", type: HsDialogContainerComponent, isStandalone: true, selector: "hs-dialog-container", viewQueries: [{ propertyName: "dialogHost", first: true, predicate: HsDialogHostDirective, descendants: true, static: true }], ngImport: i0, template: "<div>\n <ng-template hsDialogHost></ng-template>\n</div>\n", dependencies: [{ kind: "directive", type: HsDialogHostDirective, selector: "[hsDialogHost]" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.3", ngImport: i0, type: HsDialogContainerComponent, decorators: [{
type: Component,
args: [{ selector: 'hs-dialog-container', imports: [HsDialogHostDirective], template: "<div>\n <ng-template hsDialogHost></ng-template>\n</div>\n" }]
}], propDecorators: { dialogHost: [{
type: ViewChild,
args: [HsDialogHostDirective, { static: true }]
}] } });
class HsRenameLayerDialogComponent {
constructor() {
this.hsDialogContainerService = inject(HsDialogContainerService);
}
ngOnInit() {
this.newLayerName = this.data.currentName;
}
/**
* Close the dialog
*/
close() {
this.hsDialogContainerService.destroy(this);
this.dialogItem.resolve(false);
}
/**
* Continue with the new layer name from user's input
*/
continue() {
this.hsDialogContainerService.destroy(this);
this.dialogItem.resolve(this.newLayerName);
}
handleKeyUp(e) {
if (e.key == 'Enter') {
this.continue();
}
else if (e.key == 'Escape') {
this.close();
}
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.3", ngImport: i0, type: HsRenameLayerDialogComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.2.3", type: HsRenameLayerDialogComponent, isStandalone: true, selector: "hs-rename-layer-dialog", ngImport: i0, template: "<div class=\"modal in hs-layer-overwrite-dialog\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\">\n <div class=\"modal-dialog\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h4 class=\"modal-title\">{{'COMMON.renameLayer' | translate}}</h4>\n <button type=\"button\" (click)=\"close()\" class=\"btn-close\" data-dismiss=\"modal\"\n [attr.aria-label]=\"'COMMON.close' | translate \">\n </button>\n </div>\n <div class=\"modal-body\" style=\"overflow-y:auto\">\n <div class=\"form-floating m-2\">\n <input class=\"form-control\" name=\"name\" [(ngModel)]=\"newLayerName\" [placeholder]=\"'COMMON.name' | translate\"\n (keyup)=\"handleKeyUp($event)\" />\n <label for=\"name\" class=\"capabilities_label control-label\">{{'COMMON.name' | translate}}</label>\n </div>\n </div>\n <div class=\"modal-footer\">\n <button type=\"button\" class=\"btn btn-primary compositions-btn-overwrite\" (click)=\"continue()\"\n data-dismiss=\"modal\" [disabled]=\"!newLayerName\">{{'COMMON.continue' | translate }}</button>\n\n <button type=\"button\" class=\"btn btn-secondary compositions-btn-cancel\" (click)=\"close()\"\n data-dismiss=\"modal\">{{'COMMON.cancel' | translate }}</button>\n </div>\n </div>\n </div>\n</div>\n", dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "pipe", type: TranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.3", ngImport: i0, type: HsRenameLayerDialogComponent, decorators: [{
type: Component,
args: [{ selector: 'hs-rename-layer-dialog', imports: [TranslatePipe, FormsModule], template: "<div class=\"modal in hs-layer-overwrite-dialog\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\">\n <div class=\"modal-dialog\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h4 class=\"modal-title\">{{'COMMON.renameLayer' | translate}}</h4>\n <button type=\"button\" (click)=\"close()\" class=\"btn-close\" data-dismiss=\"modal\"\n [attr.aria-label]=\"'COMMON.close' | translate \">\n </button>\n </div>\n <div class=\"modal-body\" style=\"overflow-y:auto\">\n <div class=\"form-floating m-2\">\n <input class=\"form-control\" name=\"name\" [(ngModel)]=\"newLayerName\" [placeholder]=\"'COMMON.name' | translate\"\n (keyup)=\"handleKeyUp($event)\" />\n <label for=\"name\" class=\"capabilities_label control-label\">{{'COMMON.name' | translate}}</label>\n </div>\n </div>\n <div class=\"modal-footer\">\n <button type=\"button\" class=\"btn btn-primary compositions-btn-overwrite\" (click)=\"continue()\"\n data-dismiss=\"modal\" [disabled]=\"!newLayerName\">{{'COMMON.continue' | translate }}</button>\n\n <button type=\"button\" class=\"btn btn-secondary compositions-btn-cancel\" (click)=\"close()\"\n data-dismiss=\"modal\">{{'COMMON.cancel' | translate }}</button>\n </div>\n </div>\n </div>\n</div>\n" }]
}] });
class HsLayerOverwriteDialogComponent {
constructor() {
this.hsDialogContainerService = inject(HsDialogContainerService);
}
/**
* Close the dialog
*/
close() {
this.hsDialogContainerService.destroy(this);
this.dialogItem.resolve('cancel');
}
/**
* Overwrite the existing layer with current layer data
*/
overwrite() {
this.hsDialogContainerService.destroy(this);
this.dialogItem.resolve('overwrite');
}
async renameAndAdd() {
const renameDialogRef = this.hsDialogContainerService.create(HsRenameLayerDialogComponent, {
currentName: this.data.dataObj.name,
});
const result = await renameDialogRef.waitResult();
if (!result) {
//Do nothing
}
else {
this.data.dataObj.name = result;
this.data.dataObj.title = result;
this.hsDialogContainerService.destroy(this);
this.dialogItem.resolve('add');
}
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.3", ngImport: i0, type: HsLayerOverwriteDialogComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.2.3", type: HsLayerOverwriteDialogComponent, isStandalone: true, selector: "hs-layer-overwrite-dialog", ngImport: i0, template: "<div class=\"modal in hs-layer-overwrite-dialog\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\">\n <div class=\"modal-dialog\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h4 class=\"modal-title\">{{'ADDDATA.dialogOverWrite.overwriteExistingLayer' | translate}}</h4>\n <button type=\"button\" (click)=\"close()\" class=\"btn-close\" data-dismiss=\"modal\"\n [attr.aria-label]=\"'COMMON.close' | translate \">\n </button>\n </div>\n <div class=\"modal-body\" style=\"overflow-y:auto\">\n <p class=\"fw-bold h6\">{{'ADDDATA.dialogOverWrite.doYouWishToOverwrite' | translate }}\n {{data.dataObj.name}}?</p>\n @if (data.repetive) {\n <p class=\"h6 small\">{{'ADDDATA.dialogOverWrite.noteForRepetiveDialog' | translate}}</p>\n }\n </div>\n <div class=\"modal-footer\">\n <button type=\"button\" class=\"btn btn-primary compositions-btn-overwrite\" (click)=\"overwrite()\"\n data-dismiss=\"modal\">{{'SAVECOMPOSITION.form.overwrite' | translate }}</button>\n <button type=\"button\" class=\"btn btn-secondary compositions-btn-cancel\" (click)=\"renameAndAdd()\"\n data-dismiss=\"modal\">{{'COMMON.renameLayer' | translate }}</button>\n <button type=\"button\" class=\"btn btn-secondary compositions-btn-cancel\" (click)=\"close()\"\n data-dismiss=\"modal\">{{'COMMON.cancel' | translate }}</button>\n </div>\n </div>\n </div>\n</div>\n", dependencies: [{ kind: "pipe", type: TranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.3", ngImport: i0, type: HsLayerOverwriteDialogComponent, decorators: [{
type: Component,
args: [{ selector: 'hs-layer-overwrite-dialog', imports: [TranslatePipe], template: "<div class=\"modal in hs-layer-overwrite-dialog\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\">\n <div class=\"modal-dialog\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h4 class=\"modal-title\">{{'ADDDATA.dialogOverWrite.overwriteExistingLayer' | translate}}</h4>\n <button type=\"button\" (click)=\"close()\" class=\"btn-close\" data-dismiss=\"modal\"\n [attr.aria-label]=\"'COMMON.close' | translate \">\n </button>\n </div>\n <div class=\"modal-body\" style=\"overflow-y:auto\">\n <p class=\"fw-bold h6\">{{'ADDDATA.dialogOverWrite.doYouWishToOverwrite' | translate }}\n {{data.dataObj.name}}?</p>\n @if (data.repetive) {\n <p class=\"h6 small\">{{'ADDDATA.dialogOverWrite.noteForRepetiveDialog' | translate}}</p>\n }\n </div>\n <div class=\"modal-footer\">\n <button type=\"button\" class=\"btn btn-primary compositions-btn-overwrite\" (click)=\"overwrite()\"\n data-dismiss=\"modal\">{{'SAVECOMPOSITION.form.overwrite' | translate }}</button>\n <button type=\"button\" class=\"btn btn-secondary compositions-btn-cancel\" (click)=\"renameAndAdd()\"\n data-dismiss=\"modal\">{{'COMMON.renameLayer' | translate }}</button>\n <button type=\"button\" class=\"btn btn-secondary compositions-btn-cancel\" (click)=\"close()\"\n data-dismiss=\"modal\">{{'COMMON.cancel' | translate }}</button>\n </div>\n </div>\n </div>\n</div>\n" }]
}] });
class HsCompositionsWarningDialogComponent {
constructor() {
this.hsDialogContainerService = inject(HsDialogContainerService);
}
close() {
this.hsDialogContainerService.destroy(this);
}
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.3", ngImport: i0, type: HsCompositionsWarningDialogComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.2.3", type: HsCompositionsWarningDialogComponent, isStandalone: true, selector: "hs-compositions-warning-dialog", ngImport: i0, template: "<div class=\"modal in hs-composition-warning-dialog\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\">\n <div class=\"modal-dialog\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h4 class=\"modal-title\">{{'COMMON.warning' | translate }}</h4>\n <button type=\"button\" (click)=\"close()\" class=\"btn-close\" data-dismiss=\"modal\"\n [attr.aria-label]=\"'COMMON.close' | translate\">\n </button>\n </div>\n <div class=\"modal-body\" style=\"max-height: 600px; overflow-y: auto\">\n <br>{{'COMMON.name' | translate }}: <b>{{data.composition_title}}</b>\n <hr>\n <br>{{data.message | translate }}\n <br>{{'COMPOSITIONS.dialogWarning.toContinue' | translate }}\n </div>\n <div class=\"modal-footer\">\n <button type=\"button\" class=\"btn btn-primary compositions-btn-warning\" (click)=\"close()\"\n data-dismiss=\"modal\">{{'COMMON.ignoreAndContinue' | translate }}</button>\n </div>\n </div>\n </div>\n</div>\n", dependencies: [{ kind: "pipe", type: TranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.3", ngImport: i0, type: HsCompositionsWarningDialogComponent, decorators: [{
type: Component,
args: [{ selector: 'hs-compositions-warning-dialog', imports: [TranslatePipe], template: "<div class=\"modal in hs-composition-warning-dialog\" tabindex=\"-1\" role=\"dialog\" aria-hidden=\"true\">\n <div class=\"modal-dialog\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h4 class=\"modal-title\">{{'COMMON.warning' | translate }}</h4>\n <button type=\"button\" (click)=\"close()\" class=\"btn-close\" data-dismiss=\"modal\"\n [attr.aria-label]=\"'COMMON.close' | translate\">\n </button>\n </div>\n <div class=\"modal-body\" style=\"max-height: 600px; overflow-y: auto\">\n <br>{{'COMMON.name' | translate }}: <b>{{data.composition_title}}</b>\n <hr>\n <br>{{data.message | translate }}\n <br>{{'COMPOSITIONS.dialogWarning.toContinue' | translate }}\n </div>\n <div class=\"modal-footer\">\n <button type=\"button\" class=\"btn btn-primary compositions-btn-warning\" (click)=\"close()\"\n data-dismiss=\"modal\">{{'COMMON.ignoreAndContinue' | translate }}</button>\n </div>\n </div>\n </div>\n</div>\n" }]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { HsCompositionsWarningDialogComponent, HsDialogContainerComponent, HsDialogContainerService, HsDialogHostDirective, HsDialogItem, HsLayerOverwriteDialogComponent, HsRenameLayerDialogComponent };
//# sourceMappingURL=hslayers-ng-common-dialogs.mjs.map