2026_08_31
This commit is contained in:
commit
73015386e9
2320 files changed
+80291
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { Body, Controller, Get, Param, Patch } from '@nestjs/common';
|
||||
import { ViewsService } from './views.service';
|
||||
import { ProConViewDto } from 'src/_dto/proConVisuAgg.dto';
|
||||
|
||||
|
||||
@Controller('procon/views')
|
||||
export class ViewsController {
|
||||
constructor(private readonly service: ViewsService) { }
|
||||
|
||||
@Get('/pfeilSickness')
|
||||
changePfeilSickness() {
|
||||
console.log("changeSickness")
|
||||
return this.service.updateAllPfeileSickness();
|
||||
}
|
||||
|
||||
@Get('/:id')
|
||||
getViewById(@Param('id') id: string) {
|
||||
return this.service.getViewById(id);
|
||||
}
|
||||
|
||||
|
||||
@Get('/xaml/:id')
|
||||
getXamlCode(@Param('id') id: string) {
|
||||
return this.service.getXamlCode(id);
|
||||
}
|
||||
|
||||
@Get('/color/:id/:color')
|
||||
changeColor(@Param('id') id: string,@Param('color') color: string) {
|
||||
return this.service.doChangeColor(id,color);
|
||||
}
|
||||
|
||||
@Patch('/xaml/:id')
|
||||
async update(@Param('id') id: string, @Body() dto:{xamlBase64: string}) {
|
||||
console.log(dto);
|
||||
let result = await this.service.updateXAML(id, dto.xamlBase64);
|
||||
let r2 = await fetch('http://wsrksl01:3001/click', { method: 'POST',});
|
||||
console.log(r2);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ViewsService } from './views.service';
|
||||
import { SqlModule } from 'src/infrastructure/sql/sql.module';
|
||||
import { ViewsRepository } from './views.repository';
|
||||
import { ViewsController } from './views.controller';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
SqlModule
|
||||
],
|
||||
providers: [ViewsService,ViewsRepository],
|
||||
exports:[ViewsService],
|
||||
controllers: [ViewsController]
|
||||
|
||||
})
|
||||
export class ViewsModule {}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { ProConViewsEntity } from "src/_sql/procon.Views.entity";
|
||||
import { SqlError } from "src/_sql/sql.types";
|
||||
import { SqlService } from "src/infrastructure/sql/sql.service";
|
||||
import * as sql from 'mssql';
|
||||
|
||||
interface RetValue {
|
||||
succeed: boolean,
|
||||
id: string,
|
||||
xaml_base64: string,
|
||||
xaml: string,
|
||||
}
|
||||
interface RetError {
|
||||
succeed: boolean,
|
||||
id: string,
|
||||
error: string
|
||||
}
|
||||
@Injectable()
|
||||
export class ViewsRepository {
|
||||
constructor(
|
||||
private readonly db: SqlService,
|
||||
) { }
|
||||
|
||||
table = "Views";
|
||||
|
||||
async findById(anlageId: string, id: string): Promise<ProConViewsEntity | undefined> {
|
||||
const pool = await this.db.getPool(anlageId);
|
||||
let where = `Id = '${id}'`
|
||||
|
||||
const result = await pool
|
||||
.request()
|
||||
.query(`
|
||||
SELECT *
|
||||
FROM ${this.table}
|
||||
WHERE ${where}
|
||||
`);
|
||||
|
||||
//if (!result || !result.recordset || result.recordset.length < 1) return { id: id, error: 'Nicht gefunden' }
|
||||
|
||||
const x: ProConViewsEntity = result.recordset[0];
|
||||
return x;
|
||||
|
||||
}
|
||||
|
||||
async findByIdWhereIncludeString(anlage: string, includeStr: string): Promise<ProConViewsEntity[]> {
|
||||
const pool = await this.db.getPool(anlage);
|
||||
const result = await pool.request().query(`SELECT * FROM Views WHERE Id LIKE '${includeStr}' `);
|
||||
return result.recordset;
|
||||
}
|
||||
|
||||
async update(anlage: string, id: string, data: Partial<ProConViewsEntity>): Promise<ProConViewsEntity[]> {
|
||||
const pool = await this.db.getPool(anlage);
|
||||
//let updateData = '';
|
||||
//if(data.Data) updateData += ` Data = ${data.Data}`;
|
||||
|
||||
const resultUpdate =
|
||||
await pool.request()
|
||||
.input('id', sql.NVarChar, id)
|
||||
.input('data', sql.NVarChar, data.Data)
|
||||
.query(`
|
||||
UPDATE Views
|
||||
SET Data = @data
|
||||
WHERE Id = @id
|
||||
`);
|
||||
|
||||
|
||||
return resultUpdate;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { ViewsRepository } from './views.repository';
|
||||
import { ProConViewsEntity } from 'src/_sql/procon.Views.entity';
|
||||
import { SqlError } from 'src/_sql/sql.types';
|
||||
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class ViewsService {
|
||||
anlage = 'testXXX';
|
||||
|
||||
constructor(
|
||||
private readonly repo: ViewsRepository
|
||||
) { }
|
||||
|
||||
|
||||
//--- Get View By ID
|
||||
async getViewById(id: string): Promise<ProConViewsEntity | undefined> {
|
||||
return await this.repo.findById(this.anlage, id);
|
||||
}
|
||||
|
||||
|
||||
//--- Get XAML Code of View
|
||||
async getXamlCode(viewId: string) {
|
||||
|
||||
const view = await this.repo.findById(this.anlage, viewId);
|
||||
if (!view) throw new BadRequestException('ViewId not found');
|
||||
|
||||
return this.base64_to_string(view.Data);
|
||||
}
|
||||
|
||||
//--- Update View
|
||||
async updateView(viewId: string, xamlStr: string) {
|
||||
const base64Str = this.string_to_base64(xamlStr);
|
||||
const result = await this.repo.update(this.anlage, viewId, { Data: base64Str });
|
||||
console.log(result);
|
||||
};
|
||||
|
||||
//--- Update XAML
|
||||
async updateXAML(id: string, xamlBase64: string) {
|
||||
//const base64Str = this.string_to_base64(xamlStr);
|
||||
const result = await this.repo.update(this.anlage, id, { Data: xamlBase64 });
|
||||
console.log(result);
|
||||
return result;
|
||||
};
|
||||
|
||||
//--- Update all Sickness Lines of all pfeile
|
||||
async updateAllPfeileSickness() {
|
||||
// %Pfeil%
|
||||
const viewPeile = await this.repo.findByIdWhereIncludeString(this.anlage, '%Pfeil%');
|
||||
|
||||
let changedData = viewPeile.map((row) => (
|
||||
{
|
||||
...row,
|
||||
Data: this.string_to_base64(this.changeSickness(this.base64_to_string(row.Data), 2, 3))
|
||||
}
|
||||
))
|
||||
|
||||
for (const data of changedData) {
|
||||
const result = await this.repo.update(this.anlage, data.Id, { Data: data.Data });
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
return changedData;
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Change Color of Found Views
|
||||
async doChangeColor(viewSearchStr: string, color: string) {
|
||||
|
||||
const views = await this.repo.findByIdWhereIncludeString(this.anlage, `%${viewSearchStr}%`);
|
||||
|
||||
let changedData = views.map((row) => (
|
||||
{
|
||||
...row,
|
||||
Data: this.string_to_base64(this.changeColor(this.base64_to_string(row.Data), color))
|
||||
}
|
||||
))
|
||||
|
||||
//console.log((this.changeColor(this.base64_to_string(changedData[0].Data), color)))
|
||||
//console.log(changedData[0].Id)
|
||||
|
||||
for (const data of changedData) {
|
||||
const result = await this.repo.update(this.anlage, data.Id, { Data: data.Data });
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
return changedData
|
||||
}
|
||||
|
||||
|
||||
//--- View Helpers
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
//--- Convert Base64 to String
|
||||
private base64_to_string(base64string: string) {
|
||||
let decoded = Buffer.from(base64string, "base64").toString("utf-8");
|
||||
return decoded;
|
||||
}
|
||||
|
||||
|
||||
//--- Convert String to Base64
|
||||
private string_to_base64(text: string) {
|
||||
return Buffer.from(text, "utf-8").toString("base64");
|
||||
}
|
||||
|
||||
|
||||
//--- Breite Eigenschaft ändern
|
||||
private changeSickness(text: string, from: number, to: number) {
|
||||
|
||||
const re = new RegExp(`StrokeThickness="${from}"`, "g");
|
||||
|
||||
text = text.replace(re, `StrokeThickness="${to}"`);
|
||||
text = text.replace(re, `Y`);
|
||||
return text;
|
||||
}
|
||||
|
||||
//--- Farbe Eigenschaft ändern
|
||||
private changeColor(text: string, color: string) {
|
||||
|
||||
const result = text.replace(
|
||||
/(Stroke|Fill)="#(?:[0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|gemisch)"/g,
|
||||
`$1="#${color}"`
|
||||
)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user