161 lines
4.4 KiB
TypeScript
161 lines
4.4 KiB
TypeScript
import { Component, OnInit } from "@angular/core";
|
|
import { JsonrpcService, RpcService } from "src/app/services/jsonrpc.service";
|
|
import { MessageService } from "primeng/api";
|
|
import { Areas } from "src/app/interface/data";
|
|
import { ConfirmationService } from 'primeng/api';
|
|
|
|
|
|
@Component({
|
|
selector: 'app-areas',
|
|
templateUrl: './areas.component.html',
|
|
styleUrls: ['./areas.component.scss']
|
|
})
|
|
export class AreasComponent implements OnInit {
|
|
public areas: Areas[] = [];
|
|
public new_ar = true;
|
|
public choose = this.jsonRpcService.ClientChoose;
|
|
public create = false;
|
|
public chooseName!: string;
|
|
|
|
constructor(
|
|
private jsonRpcService: JsonrpcService,
|
|
private messageService: MessageService,
|
|
private confirmationService: ConfirmationService
|
|
) { }
|
|
|
|
ngOnInit(): void {
|
|
if (this.choose) { this.getAreas() };
|
|
}
|
|
|
|
async getAreas() {
|
|
this.create = false;
|
|
this.new_ar = true;
|
|
await this.jsonRpcService.rpc2({
|
|
method: 'getAreas',
|
|
params: {
|
|
"client_id": this.choose
|
|
}
|
|
}, RpcService.authService, false)
|
|
.subscribe({
|
|
next: (result) => {
|
|
let data = result.result;
|
|
this.areas = data;
|
|
document.getElementsByTagName('thead')[0].style.display = 'table';
|
|
document.getElementsByTagName('thead')[0].style.width = '100%';
|
|
document.getElementsByTagName('thead')[0].style.tableLayout = 'fixed';
|
|
document.getElementsByTagName('tbody')[0].style.display = 'block';
|
|
document.getElementsByTagName('tbody')[0].style.maxHeight = 'calc(100vh - 290px)';
|
|
document.getElementsByTagName('tbody')[0].style.overflowY = 'scroll';
|
|
},
|
|
error: (err) => {
|
|
console.log('ERROR: ', err)
|
|
this.messageService.add({
|
|
severity: 'error',
|
|
summary: 'Произошла ошибка!',
|
|
})
|
|
}
|
|
});
|
|
this.chooseName = this.jsonRpcService.ClientChooseName;
|
|
}
|
|
|
|
updateArea1(id: any, name: any) {
|
|
this.new_ar = false;
|
|
setTimeout(() => document.getElementsByTagName("input")[0].value = name, 100);
|
|
this.jsonRpcService.changeId = id
|
|
}
|
|
|
|
updateArea() {
|
|
let name_n = document.getElementsByTagName("input")[0].value
|
|
this.jsonRpcService.rpc2({
|
|
method: 'updateArea',
|
|
params: {
|
|
"client_id": this.choose,
|
|
"area_id": this.jsonRpcService.changeId,
|
|
"name": name_n
|
|
}
|
|
}, RpcService.authService, false)
|
|
.subscribe({
|
|
next: (result) => {
|
|
let data = result.result;
|
|
/*this.clients = data;*/
|
|
},
|
|
error: (err) => {
|
|
console.log('ERROR: ', err)
|
|
this.messageService.add({
|
|
severity: 'error',
|
|
summary: 'Произошла ошибка!',
|
|
})
|
|
}
|
|
});
|
|
this.new_ar = true;
|
|
this.jsonRpcService.changeId = "";
|
|
setTimeout(() => this.getAreas(), 100);
|
|
}
|
|
|
|
deleteArea(id: any) {
|
|
this.jsonRpcService.rpc2({
|
|
method: 'deleteArea',
|
|
params: {
|
|
"client_id": this.choose,
|
|
"area_id": id
|
|
}
|
|
}, RpcService.authService, false)
|
|
.subscribe({
|
|
next: (result) => {
|
|
let data = result.result;
|
|
/*this.clients = data;*/
|
|
},
|
|
error: (err) => {
|
|
console.log('ERROR: ', err)
|
|
this.messageService.add({
|
|
severity: 'error',
|
|
summary: 'Произошла ошибка!',
|
|
})
|
|
}
|
|
});
|
|
setTimeout(() => this.getAreas(), 100);
|
|
}
|
|
|
|
|
|
createArea() {
|
|
this.new_ar = false;
|
|
this.create = true;
|
|
}
|
|
|
|
createArea2() {
|
|
let name = document.getElementsByTagName("input")[0].value
|
|
this.jsonRpcService.rpc2({
|
|
method: 'createArea',
|
|
params: {
|
|
"name": name,
|
|
"client_id": this.choose
|
|
}
|
|
}, RpcService.authService, false)
|
|
.subscribe({
|
|
next: (result) => {
|
|
let data = result.result;
|
|
/*this.clients = data;*/
|
|
},
|
|
error: (err) => {
|
|
console.log('ERROR: ', err)
|
|
this.messageService.add({
|
|
severity: 'error',
|
|
summary: 'Произошла ошибка!',
|
|
})
|
|
}
|
|
});
|
|
setTimeout(() => this.getAreas(), 100);
|
|
|
|
}
|
|
|
|
confirm(id: any) {
|
|
this.confirmationService.confirm({
|
|
message: 'Вы действительно хотите удалить элемент?',
|
|
accept: () => {
|
|
this.deleteArea(id)
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|