Files
mowesta/web-angular/src/elements/search/search.module.ts
T
Marcus Handte 63b23ef902
LocationBasedServices/mowesta/pipeline/head There was a failure building this commit
Update angular.
2024-03-05 07:04:40 +01:00

88 lines
3.1 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule, Injector } from '@angular/core';
import { APP_BASE_HREF} from '@angular/common';
import { createCustomElement } from '@angular/elements';
import { RouterModule } from '@angular/router';
import { HttpClientModule } from '@angular/common/http';
import { ReactiveFormsModule } from '@angular/forms';
import { MatIconModule } from '@angular/material/icon';
import { MatProgressBarModule } from '@angular/material/progress-bar';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { MatOptionModule } from '@angular/material/core';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { WeatherSearchElement } from './search.component';
import { SearchFieldComponent } from '../../app/widgets-common/search-field.component';
import { LocationAutocompleteComponent } from '../../app/widgets-common/location-autocomplete.component';
import { LocalNamePipe, LocationIconPipe } from '../../app/pipes/location.pipes';
import { ResourceService } from '../../app/services/resource.service';
import { DefaultService } from '../../api/api/default.service';
import { MoWeStaConfiguration } from '../../api/configuration';
/**
* Computes the api domain from the browser location.
*/
const apidomain = (): { http: string, ws: string } => {
const host = document.location.hostname;
const port = document.location.port;
const protocol = document.location.protocol;
let hostportpath = '';
if (port.length > 0) {
hostportpath = '://' + host + ':' + port + '/api';
} else {
hostportpath = '://' + host + '/api';
}
const secure = (protocol !== 'http:') ? 's' : '';
return { http: 'http' + secure + hostportpath, ws: 'ws' + secure + hostportpath };
};
@NgModule({
declarations: [
WeatherSearchElement,
SearchFieldComponent,
LocationAutocompleteComponent,
LocalNamePipe,
LocationIconPipe
],
imports: [
BrowserModule,
BrowserAnimationsModule,
RouterModule.forRoot([], {}),
HttpClientModule,
ReactiveFormsModule,
MatIconModule,
MatProgressBarModule,
MatInputModule,
MatSelectModule,
MatOptionModule,
MatFormFieldModule,
MatAutocompleteModule,
MatSelectModule
],
providers: [
// Injection token for http client
{ provide: MoWeStaConfiguration, useValue: new MoWeStaConfiguration({ basePath: apidomain().http }) },
{ provide: 'wsdomain', useValue: apidomain().ws },
// Injection toke for the router. Needs to be provided even though router is not used.
{ provide: APP_BASE_HREF, useValue : '/' },
ResourceService,
DefaultService
],
})
export class SearchModule {
constructor(private injector: Injector) { }
ngDoBootstrap() {
const el = createCustomElement(WeatherSearchElement, { injector: this.injector });
    // @ts-ignore
    customElements.define('mowesta-search', el);
}
}