mirror of
https://github.com/turt2live/matrix-dimension.git
synced 2024-10-01 01:05:53 -04:00
4954de2a96
This is a very big commit that does an initial job of upgrading everything to the latest version. TSLint gets replaced by ESLint. Instead of plain node, now ts-node is being used. Old modules also get replaced with new ones (mostly ng2 to ngx). Also obsolete configs have been replaced with how it's used today with Angular. This includes: * Upgrade to: ** Angular 12 ** Typescript 4 ** ESLint 7 and replace TSLint ** Bootstrap 5 ** Eerything connected to these * Run with ts-node * Convert wepack config to angular config * Remove typescript-ioc * Update tsconfigs * Run a git command instead of using a library for sshort hash * Move assets to a new location align with default Angular settings * Database migration for new avatarUrl locations * Simplify Model extension align with newest sequelize version * Remove breadcrumb hack * Fix homeserver typo * A few general fixes that are necessary with newest Typescript rules * Define Express.User interface
74 lines
3.0 KiB
TypeScript
74 lines
3.0 KiB
TypeScript
import { Inject, Injectable, OnDestroy, OnInit } from "@angular/core";
|
|
import { FE_ComplexBot } from "../../shared/models/integration";
|
|
import { ActivatedRoute } from "@angular/router";
|
|
import { Subscription } from "rxjs/Subscription";
|
|
import { IntegrationsApiService } from "../../shared/services/integrations/integrations-api.service";
|
|
import { ToasterService } from "angular2-toaster";
|
|
import { ServiceLocator } from "../../shared/registry/locator.service";
|
|
import { ScalarClientApiService } from "../../shared/services/scalar/scalar-client-api.service";
|
|
import { TranslateService } from "@ngx-translate/core";
|
|
|
|
@Injectable()
|
|
export class ComplexBotComponent<T> implements OnInit, OnDestroy {
|
|
|
|
public isLoading = true;
|
|
public isUpdating = false;
|
|
public bot: FE_ComplexBot<T>;
|
|
public newConfig: T;
|
|
public roomId: string;
|
|
|
|
private routeQuerySubscription: Subscription;
|
|
|
|
protected toaster = ServiceLocator.injector.get(ToasterService);
|
|
protected integrationsApi = ServiceLocator.injector.get(IntegrationsApiService);
|
|
protected route = ServiceLocator.injector.get(ActivatedRoute);
|
|
protected scalarClientApi = ServiceLocator.injector.get(ScalarClientApiService);
|
|
|
|
constructor(@Inject(String) private integrationType: string, public translate: TranslateService) {
|
|
this.translate = translate;
|
|
this.isLoading = true;
|
|
this.isUpdating = false;
|
|
}
|
|
|
|
public ngOnInit(): void {
|
|
this.routeQuerySubscription = this.route.queryParams.subscribe(params => {
|
|
this.roomId = params['roomId'];
|
|
this.loadBot();
|
|
});
|
|
}
|
|
|
|
public ngOnDestroy(): void {
|
|
if (this.routeQuerySubscription) this.routeQuerySubscription.unsubscribe();
|
|
}
|
|
|
|
private loadBot() {
|
|
this.isLoading = true;
|
|
this.isUpdating = false;
|
|
|
|
this.newConfig = <T>{};
|
|
|
|
this.integrationsApi.getIntegrationInRoom("complex-bot", this.integrationType, this.roomId).then(i => {
|
|
this.bot = <FE_ComplexBot<T>>i;
|
|
this.newConfig = JSON.parse(JSON.stringify(this.bot.config));
|
|
this.isLoading = false;
|
|
}).catch(err => {
|
|
console.error(err);
|
|
this.translate.get("Failed to load configuration").subscribe((res: string) => {this.toaster.pop("error", res); });
|
|
});
|
|
}
|
|
|
|
public save(): void {
|
|
this.isUpdating = true;
|
|
this.integrationsApi.setIntegrationConfiguration("complex-bot", this.integrationType, this.roomId, this.newConfig).then(() => {
|
|
this.translate.get("Configuration updated").subscribe((res: string) => {this.toaster.pop("success", res); });
|
|
this.bot.config = this.newConfig;
|
|
this.newConfig = JSON.parse(JSON.stringify(this.bot.config));
|
|
this.isUpdating = false;
|
|
}).catch(err => {
|
|
console.error(err);
|
|
this.translate.get("Error updating configuration").subscribe((res: string) => {this.toaster.pop("error", res); });
|
|
this.isUpdating = false;
|
|
});
|
|
}
|
|
}
|